Skip to content

Commit b49540a

Browse files
authored
feat: cssinjs add MULTI_VALUE key (#6770)
1 parent 37059c3 commit b49540a

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

Diff for: components/_util/cssinjs/hooks/useStyleRegister.tsx

+38-24
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type { VueNode } from '../../type';
2828
const isClientSide = canUseDom();
2929

3030
const SKIP_CHECK = '_skip_check_';
31-
31+
const MULTI_VALUE = '_multi_value_';
3232
export type CSSProperties = Omit<CSS.PropertiesFallback<number | string>, 'animationName'> & {
3333
animationName?: CSS.PropertiesFallback<number | string>['animationName'] | Keyframes;
3434
};
@@ -39,6 +39,7 @@ export type CSSPropertiesWithMultiValues = {
3939
| Extract<CSSProperties[K], string>[]
4040
| {
4141
[SKIP_CHECK]: boolean;
42+
[MULTI_VALUE]?: boolean;
4243
value: CSSProperties[K] | Extract<CSSProperties[K], string>[];
4344
};
4445
};
@@ -65,7 +66,7 @@ export function normalizeStyle(styleStr: string) {
6566
}
6667

6768
function isCompoundCSSProperty(value: CSSObject[string]) {
68-
return typeof value === 'object' && value && SKIP_CHECK in value;
69+
return typeof value === 'object' && value && (SKIP_CHECK in value || MULTI_VALUE in value);
6970
}
7071

7172
// 注入 hash 值
@@ -224,32 +225,45 @@ export const parseStyle = (
224225

225226
styleStr += `${mergedKey}${parsedStr}`;
226227
} else {
227-
const actualValue = (value as any)?.value ?? value;
228-
if (
229-
process.env.NODE_ENV !== 'production' &&
230-
(typeof value !== 'object' || !(value as any)?.[SKIP_CHECK])
231-
) {
232-
[contentQuotesLinter, hashedAnimationLinter, ...linters].forEach(linter =>
233-
linter(key, actualValue, { path, hashId, parentSelectors }),
234-
);
235-
}
228+
function appendStyle(cssKey: string, cssValue: any) {
229+
if (
230+
process.env.NODE_ENV !== 'production' &&
231+
(typeof value !== 'object' || !(value as any)?.[SKIP_CHECK])
232+
) {
233+
[contentQuotesLinter, hashedAnimationLinter, ...linters].forEach(linter =>
234+
linter(cssKey, cssValue, { path, hashId, parentSelectors }),
235+
);
236+
}
236237

237-
// 如果是样式则直接插入
238-
const styleName = key.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`);
238+
// 如果是样式则直接插入
239+
const styleName = cssKey.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`);
239240

240-
// Auto suffix with px
241-
let formatValue = actualValue;
242-
if (!unitless[key] && typeof formatValue === 'number' && formatValue !== 0) {
243-
formatValue = `${formatValue}px`;
244-
}
241+
// Auto suffix with px
242+
let formatValue = cssValue;
243+
if (!unitless[cssKey] && typeof formatValue === 'number' && formatValue !== 0) {
244+
formatValue = `${formatValue}px`;
245+
}
245246

246-
// handle animationName & Keyframe value
247-
if (key === 'animationName' && (value as Keyframes)?._keyframe) {
248-
parseKeyframes(value as Keyframes);
249-
formatValue = (value as Keyframes).getName(hashId);
250-
}
247+
// handle animationName & Keyframe value
248+
if (cssKey === 'animationName' && (cssValue as Keyframes)?._keyframe) {
249+
parseKeyframes(cssValue as Keyframes);
250+
formatValue = (cssValue as Keyframes).getName(hashId);
251+
}
251252

252-
styleStr += `${styleName}:${formatValue};`;
253+
styleStr += `${styleName}:${formatValue};`;
254+
}
255+
const actualValue = (value as any)?.value ?? value;
256+
if (
257+
typeof value === 'object' &&
258+
(value as any)?.[MULTI_VALUE] &&
259+
Array.isArray(actualValue)
260+
) {
261+
actualValue.forEach(item => {
262+
appendStyle(key, item);
263+
});
264+
} else {
265+
appendStyle(key, actualValue);
266+
}
253267
}
254268
});
255269
}

Diff for: components/style/roundedArrow.ts

+24-14
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,33 @@ export const roundedArrow = (
1010
): CSSObject => {
1111
const unitWidth = width / 2;
1212

13-
const ax = unitWidth - outerRadius * (Math.sqrt(2) - 1);
13+
const ax = 0;
1414
const ay = unitWidth;
15-
const bx = unitWidth + outerRadius * (1 - 1 / Math.sqrt(2));
15+
const bx = (outerRadius * 1) / Math.sqrt(2);
1616
const by = unitWidth - outerRadius * (1 - 1 / Math.sqrt(2));
17-
const cx = 2 * unitWidth - innerRadius * (1 / Math.sqrt(2));
18-
const cy = innerRadius * (1 / Math.sqrt(2));
19-
const dx = 4 * unitWidth - cx;
17+
const cx = unitWidth - innerRadius * (1 / Math.sqrt(2));
18+
const cy = outerRadius * (Math.sqrt(2) - 1) + innerRadius * (1 / Math.sqrt(2));
19+
const dx = 2 * unitWidth - cx;
2020
const dy = cy;
21-
const ex = 4 * unitWidth - bx;
21+
const ex = 2 * unitWidth - bx;
2222
const ey = by;
23-
const fx = 4 * unitWidth - ax;
23+
const fx = 2 * unitWidth - ax;
2424
const fy = ay;
2525

26+
const shadowWidth = unitWidth * Math.sqrt(2) + outerRadius * (Math.sqrt(2) - 2);
27+
const polygonOffset = outerRadius * (Math.sqrt(2) - 1);
28+
2629
return {
27-
borderRadius: { _skip_check_: true, value: `0 0 ${innerRadius}px` },
2830
pointerEvents: 'none',
29-
width: width * 2,
30-
height: width * 2,
31+
width,
32+
height: width,
3133
overflow: 'hidden',
3234

3335
'&::after': {
3436
content: '""',
3537
position: 'absolute',
36-
width: width / Math.sqrt(2),
37-
height: width / Math.sqrt(2),
38+
width: shadowWidth,
39+
height: shadowWidth,
3840
bottom: 0,
3941
insetInline: 0,
4042
margin: 'auto',
@@ -52,10 +54,18 @@ export const roundedArrow = (
5254
position: 'absolute',
5355
bottom: 0,
5456
insetInlineStart: 0,
55-
width: width * 2,
57+
width,
5658
height: width / 2,
5759
background: bgColor,
58-
clipPath: `path('M ${ax} ${ay} A ${outerRadius} ${outerRadius} 0 0 0 ${bx} ${by} L ${cx} ${cy} A ${innerRadius} ${innerRadius} 0 0 1 ${dx} ${dy} L ${ex} ${ey} A ${outerRadius} ${outerRadius} 0 0 0 ${fx} ${fy} Z')`,
60+
clipPath: {
61+
_multi_value_: true,
62+
value: [
63+
`polygon(${polygonOffset}px 100%, 50% ${polygonOffset}px, ${
64+
2 * unitWidth - polygonOffset
65+
}px 100%, ${polygonOffset}px 100%)`,
66+
`path('M ${ax} ${ay} A ${outerRadius} ${outerRadius} 0 0 0 ${bx} ${by} L ${cx} ${cy} A ${innerRadius} ${innerRadius} 0 0 1 ${dx} ${dy} L ${ex} ${ey} A ${outerRadius} ${outerRadius} 0 0 0 ${fx} ${fy} Z')`,
67+
],
68+
} as any,
5969
content: '""',
6070
},
6171
};

0 commit comments

Comments
 (0)