@plumeria/unplugin 13.2.2 → 14.0.0
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/core.js +69 -6
- package/dist/core.mjs +69 -6
- package/package.json +2 -2
package/dist/core.js
CHANGED
|
@@ -118,6 +118,25 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
118
118
|
const sourceBuffer = Buffer.from(source, 'utf-8');
|
|
119
119
|
const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
|
|
120
120
|
const baseByteOffset = ast.span.start - leadingBytes;
|
|
121
|
+
const throwCompilationError = (message, node) => {
|
|
122
|
+
let suffix = '';
|
|
123
|
+
if (node) {
|
|
124
|
+
const offset = node.span.start - baseByteOffset;
|
|
125
|
+
let line = 1;
|
|
126
|
+
let colStart = 0;
|
|
127
|
+
for (let i = 0; i < offset && i < sourceBuffer.length; i++) {
|
|
128
|
+
if (sourceBuffer[i] === 10) {
|
|
129
|
+
line++;
|
|
130
|
+
colStart = i + 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const col = offset - colStart + 1;
|
|
134
|
+
suffix = ` (${path.basename(resourcePath)}:${line}:${col})`;
|
|
135
|
+
}
|
|
136
|
+
const err = new Error(`${message}${suffix}`);
|
|
137
|
+
err.stack = err.message;
|
|
138
|
+
throw err;
|
|
139
|
+
};
|
|
121
140
|
for (const node of ast.body) {
|
|
122
141
|
if (node.type === 'ImportDeclaration') {
|
|
123
142
|
const sourcePath = node.source.value;
|
|
@@ -306,7 +325,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
306
325
|
if ((localCreateStyles[varName] &&
|
|
307
326
|
localCreateStyles[varName].type === 'variant') ||
|
|
308
327
|
mergedVariantsTable[varName]) {
|
|
309
|
-
|
|
328
|
+
throwCompilationError(`Plumeria: Assigning the return value of css.variants() to a variable is not supported.\nPlease pass the variant function directly to styleName or css.use(). Found assignment to: ${utils_1.t.isIdentifier(decl.id) ? decl.id.value : 'unknown'}`, init);
|
|
310
329
|
}
|
|
311
330
|
}
|
|
312
331
|
};
|
|
@@ -458,10 +477,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
458
477
|
selector = selectorExpr.value;
|
|
459
478
|
}
|
|
460
479
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
461
|
-
|
|
480
|
+
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
462
481
|
}
|
|
463
482
|
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
464
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
483
|
+
const hash = (0, zss_engine_1.genBase36Hash)({ _themeSelector: selector, ...obj }, 1, 8);
|
|
465
484
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
466
485
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
467
486
|
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
@@ -640,10 +659,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
640
659
|
selector = selectorExpr.value;
|
|
641
660
|
}
|
|
642
661
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
643
|
-
|
|
662
|
+
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
644
663
|
}
|
|
645
664
|
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
646
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
665
|
+
const hash = (0, zss_engine_1.genBase36Hash)({ _themeSelector: selector, ...obj }, 1, 8);
|
|
647
666
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
648
667
|
if (scannedTables.createThemeSelectorTable) {
|
|
649
668
|
scannedTables.createThemeSelectorTable[hash] = selector;
|
|
@@ -721,6 +740,24 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
721
740
|
let groupIdCounter = 0;
|
|
722
741
|
let baseStyle = {};
|
|
723
742
|
let isOptimizable = true;
|
|
743
|
+
const getRootIdentifier = (node) => {
|
|
744
|
+
if (utils_1.t.isIdentifier(node)) {
|
|
745
|
+
return node.value;
|
|
746
|
+
}
|
|
747
|
+
if (utils_1.t.isMemberExpression(node)) {
|
|
748
|
+
return getRootIdentifier(node.object);
|
|
749
|
+
}
|
|
750
|
+
if (utils_1.t.isCallExpression(node)) {
|
|
751
|
+
const callee = node.callee;
|
|
752
|
+
if (callee.type !== 'Super' && callee.type !== 'Import') {
|
|
753
|
+
return getRootIdentifier(callee);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (node.type === 'ParenthesisExpression') {
|
|
757
|
+
return getRootIdentifier(node.expression);
|
|
758
|
+
}
|
|
759
|
+
return null;
|
|
760
|
+
};
|
|
724
761
|
const collectConditions = (node, currentTestStrings = []) => {
|
|
725
762
|
const staticStyle = resolveStyleObject(node);
|
|
726
763
|
if (staticStyle) {
|
|
@@ -792,6 +829,21 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
792
829
|
variantObj = localCreateStyles[varName].obj;
|
|
793
830
|
if (variantObj) {
|
|
794
831
|
const callArgs = expr.arguments;
|
|
832
|
+
const hasSpread = callArgs.some((a) => {
|
|
833
|
+
if (a.spread)
|
|
834
|
+
return true;
|
|
835
|
+
if (a.expression.type === 'ObjectExpression') {
|
|
836
|
+
return a.expression.properties.some((p) => p.type === 'SpreadElement');
|
|
837
|
+
}
|
|
838
|
+
return false;
|
|
839
|
+
});
|
|
840
|
+
if (hasSpread) {
|
|
841
|
+
throwCompilationError(`Plumeria: Spread operator in ${getSource(expr)} is not supported. ` +
|
|
842
|
+
`Please pass specific variant options directly.`, expr);
|
|
843
|
+
}
|
|
844
|
+
if (callArgs.length !== 1) {
|
|
845
|
+
throwCompilationError(`Plumeria: Variant function "${varName}" expects exactly 1 argument, found ${callArgs.length}.`, expr);
|
|
846
|
+
}
|
|
795
847
|
if (callArgs.length === 1 && !callArgs[0].spread) {
|
|
796
848
|
const arg = callArgs[0].expression;
|
|
797
849
|
if (arg.type === 'ObjectExpression') {
|
|
@@ -898,6 +950,17 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
898
950
|
const handled = collectConditions(expr);
|
|
899
951
|
if (handled)
|
|
900
952
|
continue;
|
|
953
|
+
if (utils_1.t.isMemberExpression(expr) || utils_1.t.isIdentifier(expr)) {
|
|
954
|
+
const rootId = getRootIdentifier(expr);
|
|
955
|
+
const isPlumeriaStyle = rootId &&
|
|
956
|
+
((localCreateStyles[rootId] !== undefined &&
|
|
957
|
+
localCreateStyles[rootId].type !== 'constant') ||
|
|
958
|
+
mergedCreateTable[rootId] !== undefined ||
|
|
959
|
+
mergedVariantsTable[rootId] !== undefined);
|
|
960
|
+
if (!isPlumeriaStyle) {
|
|
961
|
+
throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
901
964
|
isOptimizable = false;
|
|
902
965
|
break;
|
|
903
966
|
}
|
|
@@ -1462,7 +1525,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1462
1525
|
const propKey = callee.property.value;
|
|
1463
1526
|
const styleInfo = localCreateStyles[varName];
|
|
1464
1527
|
if (styleInfo?.functions?.[propKey]) {
|
|
1465
|
-
|
|
1528
|
+
throwCompilationError(`Plumeria: css.use(${getSource(expr)}) does not support dynamic function keys.`, expr);
|
|
1466
1529
|
}
|
|
1467
1530
|
}
|
|
1468
1531
|
const { classParts, isOptimizable, baseStyle } = buildClassParts(args);
|
package/dist/core.mjs
CHANGED
|
@@ -82,6 +82,25 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
82
82
|
const sourceBuffer = Buffer.from(source, 'utf-8');
|
|
83
83
|
const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
|
|
84
84
|
const baseByteOffset = ast.span.start - leadingBytes;
|
|
85
|
+
const throwCompilationError = (message, node) => {
|
|
86
|
+
let suffix = '';
|
|
87
|
+
if (node) {
|
|
88
|
+
const offset = node.span.start - baseByteOffset;
|
|
89
|
+
let line = 1;
|
|
90
|
+
let colStart = 0;
|
|
91
|
+
for (let i = 0; i < offset && i < sourceBuffer.length; i++) {
|
|
92
|
+
if (sourceBuffer[i] === 10) {
|
|
93
|
+
line++;
|
|
94
|
+
colStart = i + 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const col = offset - colStart + 1;
|
|
98
|
+
suffix = ` (${path.basename(resourcePath)}:${line}:${col})`;
|
|
99
|
+
}
|
|
100
|
+
const err = new Error(`${message}${suffix}`);
|
|
101
|
+
err.stack = err.message;
|
|
102
|
+
throw err;
|
|
103
|
+
};
|
|
85
104
|
for (const node of ast.body) {
|
|
86
105
|
if (node.type === 'ImportDeclaration') {
|
|
87
106
|
const sourcePath = node.source.value;
|
|
@@ -270,7 +289,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
270
289
|
if ((localCreateStyles[varName] &&
|
|
271
290
|
localCreateStyles[varName].type === 'variant') ||
|
|
272
291
|
mergedVariantsTable[varName]) {
|
|
273
|
-
|
|
292
|
+
throwCompilationError(`Plumeria: Assigning the return value of css.variants() to a variable is not supported.\nPlease pass the variant function directly to styleName or css.use(). Found assignment to: ${t.isIdentifier(decl.id) ? decl.id.value : 'unknown'}`, init);
|
|
274
293
|
}
|
|
275
294
|
}
|
|
276
295
|
};
|
|
@@ -422,10 +441,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
422
441
|
selector = selectorExpr.value;
|
|
423
442
|
}
|
|
424
443
|
if (selector.startsWith('@') && !isAtRule(selector)) {
|
|
425
|
-
|
|
444
|
+
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
426
445
|
}
|
|
427
446
|
const obj = objectExpressionToObject(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
428
|
-
const hash = genBase36Hash(obj, 1, 8);
|
|
447
|
+
const hash = genBase36Hash({ _themeSelector: selector, ...obj }, 1, 8);
|
|
429
448
|
if (t.isIdentifier(node.id)) {
|
|
430
449
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
431
450
|
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
@@ -604,10 +623,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
604
623
|
selector = selectorExpr.value;
|
|
605
624
|
}
|
|
606
625
|
if (selector.startsWith('@') && !isAtRule(selector)) {
|
|
607
|
-
|
|
626
|
+
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
608
627
|
}
|
|
609
628
|
const obj = objectExpressionToObject(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
610
|
-
const hash = genBase36Hash(obj, 1, 8);
|
|
629
|
+
const hash = genBase36Hash({ _themeSelector: selector, ...obj }, 1, 8);
|
|
611
630
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
612
631
|
if (scannedTables.createThemeSelectorTable) {
|
|
613
632
|
scannedTables.createThemeSelectorTable[hash] = selector;
|
|
@@ -685,6 +704,24 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
685
704
|
let groupIdCounter = 0;
|
|
686
705
|
let baseStyle = {};
|
|
687
706
|
let isOptimizable = true;
|
|
707
|
+
const getRootIdentifier = (node) => {
|
|
708
|
+
if (t.isIdentifier(node)) {
|
|
709
|
+
return node.value;
|
|
710
|
+
}
|
|
711
|
+
if (t.isMemberExpression(node)) {
|
|
712
|
+
return getRootIdentifier(node.object);
|
|
713
|
+
}
|
|
714
|
+
if (t.isCallExpression(node)) {
|
|
715
|
+
const callee = node.callee;
|
|
716
|
+
if (callee.type !== 'Super' && callee.type !== 'Import') {
|
|
717
|
+
return getRootIdentifier(callee);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (node.type === 'ParenthesisExpression') {
|
|
721
|
+
return getRootIdentifier(node.expression);
|
|
722
|
+
}
|
|
723
|
+
return null;
|
|
724
|
+
};
|
|
688
725
|
const collectConditions = (node, currentTestStrings = []) => {
|
|
689
726
|
const staticStyle = resolveStyleObject(node);
|
|
690
727
|
if (staticStyle) {
|
|
@@ -756,6 +793,21 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
756
793
|
variantObj = localCreateStyles[varName].obj;
|
|
757
794
|
if (variantObj) {
|
|
758
795
|
const callArgs = expr.arguments;
|
|
796
|
+
const hasSpread = callArgs.some((a) => {
|
|
797
|
+
if (a.spread)
|
|
798
|
+
return true;
|
|
799
|
+
if (a.expression.type === 'ObjectExpression') {
|
|
800
|
+
return a.expression.properties.some((p) => p.type === 'SpreadElement');
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
});
|
|
804
|
+
if (hasSpread) {
|
|
805
|
+
throwCompilationError(`Plumeria: Spread operator in ${getSource(expr)} is not supported. ` +
|
|
806
|
+
`Please pass specific variant options directly.`, expr);
|
|
807
|
+
}
|
|
808
|
+
if (callArgs.length !== 1) {
|
|
809
|
+
throwCompilationError(`Plumeria: Variant function "${varName}" expects exactly 1 argument, found ${callArgs.length}.`, expr);
|
|
810
|
+
}
|
|
759
811
|
if (callArgs.length === 1 && !callArgs[0].spread) {
|
|
760
812
|
const arg = callArgs[0].expression;
|
|
761
813
|
if (arg.type === 'ObjectExpression') {
|
|
@@ -862,6 +914,17 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
862
914
|
const handled = collectConditions(expr);
|
|
863
915
|
if (handled)
|
|
864
916
|
continue;
|
|
917
|
+
if (t.isMemberExpression(expr) || t.isIdentifier(expr)) {
|
|
918
|
+
const rootId = getRootIdentifier(expr);
|
|
919
|
+
const isPlumeriaStyle = rootId &&
|
|
920
|
+
((localCreateStyles[rootId] !== undefined &&
|
|
921
|
+
localCreateStyles[rootId].type !== 'constant') ||
|
|
922
|
+
mergedCreateTable[rootId] !== undefined ||
|
|
923
|
+
mergedVariantsTable[rootId] !== undefined);
|
|
924
|
+
if (!isPlumeriaStyle) {
|
|
925
|
+
throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
865
928
|
isOptimizable = false;
|
|
866
929
|
break;
|
|
867
930
|
}
|
|
@@ -1426,7 +1489,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
|
|
|
1426
1489
|
const propKey = callee.property.value;
|
|
1427
1490
|
const styleInfo = localCreateStyles[varName];
|
|
1428
1491
|
if (styleInfo?.functions?.[propKey]) {
|
|
1429
|
-
|
|
1492
|
+
throwCompilationError(`Plumeria: css.use(${getSource(expr)}) does not support dynamic function keys.`, expr);
|
|
1430
1493
|
}
|
|
1431
1494
|
}
|
|
1432
1495
|
const { classParts, isOptimizable, baseStyle } = buildClassParts(args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/unplugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "Universal Plumeria plugin for various build tools",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@rollup/pluginutils": "^5.4.0",
|
|
91
91
|
"unplugin": "^3.0.0",
|
|
92
|
-
"@plumeria/utils": "^
|
|
92
|
+
"@plumeria/utils": "^14.0.0"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@swc/core": "1.15.41",
|