@plumeria/compiler 18.3.16 → 18.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +54 -12
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -103,19 +103,58 @@ const namedParamsOf = (params, defaults) => {
|
|
|
103
103
|
}
|
|
104
104
|
return named.length > 0 ? named : undefined;
|
|
105
105
|
};
|
|
106
|
+
const isUnitlessProp = (prop) => zss_engine_1.exceptionCamelCase.includes(prop) || prop.startsWith('--');
|
|
107
|
+
const collectVarProps = (style, cssVar, props) => {
|
|
108
|
+
const reference = `var(${cssVar})`;
|
|
109
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
110
|
+
if (typeof value === 'string' && value.includes(reference))
|
|
111
|
+
props.push(prop);
|
|
112
|
+
else if (value !== null && typeof value === 'object')
|
|
113
|
+
collectVarProps(value, cssVar, props);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const retargetVar = (style, cssVar, next, unitless) => {
|
|
117
|
+
const reference = `var(${cssVar})`;
|
|
118
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
119
|
+
if (typeof value === 'string' && value.includes(reference)) {
|
|
120
|
+
if (isUnitlessProp(prop) === unitless)
|
|
121
|
+
style[prop] = value
|
|
122
|
+
.split(reference)
|
|
123
|
+
.join(`var(${next})`);
|
|
124
|
+
}
|
|
125
|
+
else if (value !== null && typeof value === 'object') {
|
|
126
|
+
retargetVar(value, cssVar, next, unitless);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const splitVarByUnit = (style, cssVar) => {
|
|
131
|
+
const props = [];
|
|
132
|
+
collectVarProps(style, cssVar, props);
|
|
133
|
+
if (props.length === 0)
|
|
134
|
+
return [];
|
|
135
|
+
const lead = props[0];
|
|
136
|
+
const split = props.find((prop) => isUnitlessProp(prop) !== isUnitlessProp(lead));
|
|
137
|
+
if (!split)
|
|
138
|
+
return [{ cssVar, prop: lead }];
|
|
139
|
+
const splitVar = `${cssVar}-${(0, zss_engine_1.camelToKebabCase)(split).replace(/^-+/, '')}`;
|
|
140
|
+
retargetVar(style, cssVar, splitVar, isUnitlessProp(split));
|
|
141
|
+
return [
|
|
142
|
+
{ cssVar, prop: lead },
|
|
143
|
+
{ cssVar: splitVar, prop: split },
|
|
144
|
+
];
|
|
145
|
+
};
|
|
106
146
|
const applyVarFallback = (style, cssVar, literal) => {
|
|
147
|
+
const reference = `var(${cssVar})`;
|
|
107
148
|
for (const [prop, value] of Object.entries(style)) {
|
|
108
|
-
if (typeof value === 'string' && value.includes(
|
|
109
|
-
style[prop] =
|
|
110
|
-
|
|
111
|
-
|
|
149
|
+
if (typeof value === 'string' && value.includes(reference)) {
|
|
150
|
+
style[prop] = value
|
|
151
|
+
.split(reference)
|
|
152
|
+
.join(`var(${cssVar}, ${(0, zss_engine_1.applyCssValue)(literal, (0, zss_engine_1.camelToKebabCase)(prop))})`);
|
|
112
153
|
}
|
|
113
|
-
if (value !== null && typeof value === 'object') {
|
|
114
|
-
|
|
115
|
-
return true;
|
|
154
|
+
else if (value !== null && typeof value === 'object') {
|
|
155
|
+
applyVarFallback(value, cssVar, literal);
|
|
116
156
|
}
|
|
117
157
|
}
|
|
118
|
-
return false;
|
|
119
158
|
};
|
|
120
159
|
const styleFunctionsOf = (objExpr) => {
|
|
121
160
|
const styleFunctions = {};
|
|
@@ -701,16 +740,19 @@ function compileCSS(options) {
|
|
|
701
740
|
const style = (0, utils_1.objectExpressionToObject)(func.body, tempStaticTable, ctx.mergedKeyframesTable, ctx.mergedViewTransitionTable, ctx.mergedCreateThemeHashTable, ctx.scannedTables.createThemeObjectTable, ctx.mergedCreateTable, ctx.mergedCreateStaticHashTable, ctx.scannedTables.createStaticObjectTable, ctx.mergedVariantsTable);
|
|
702
741
|
if (!style)
|
|
703
742
|
return null;
|
|
704
|
-
|
|
743
|
+
const varGroups = new Map();
|
|
744
|
+
varParams.forEach((param) => {
|
|
705
745
|
const cssVar = cssVars[param];
|
|
706
|
-
if (
|
|
707
|
-
|
|
746
|
+
if (cssVar)
|
|
747
|
+
varGroups.set(param, splitVarByUnit(style, cssVar));
|
|
748
|
+
});
|
|
749
|
+
withDefault.forEach(([param, expr]) => {
|
|
708
750
|
const literal = expr.type === 'StringLiteral' || expr.type === 'NumericLiteral'
|
|
709
751
|
? expr.value
|
|
710
752
|
: undefined;
|
|
711
753
|
if (literal === undefined)
|
|
712
754
|
return;
|
|
713
|
-
applyVarFallback(style, cssVar, literal);
|
|
755
|
+
(varGroups.get(param) ?? []).forEach(({ cssVar }) => applyVarFallback(style, cssVar, literal));
|
|
714
756
|
});
|
|
715
757
|
return style;
|
|
716
758
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "18.3.
|
|
3
|
+
"version": "18.3.18",
|
|
4
4
|
"description": "Plumeria swc based compiler for statically extracting css",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist/"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@plumeria/utils": "^18.3.
|
|
24
|
+
"@plumeria/utils": "^18.3.18"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@rust-gear/glob": "1.1.1",
|