@plumeria/utils 12.0.8 → 13.0.1
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/create.d.ts +1 -1
- package/dist/create.js +2 -2
- package/dist/createTheme.d.ts +5 -1
- package/dist/createTheme.js +27 -22
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +41 -17
- package/dist/types.d.ts +8 -1
- package/package.json +2 -2
package/dist/create.d.ts
CHANGED
package/dist/create.js
CHANGED
|
@@ -10,7 +10,7 @@ function getStyleRecords(styleRule) {
|
|
|
10
10
|
const finalFlat = (0, zss_engine_1.overrideLonghand)(flat);
|
|
11
11
|
const records = [];
|
|
12
12
|
Object.entries(finalFlat).forEach(([prop, value]) => {
|
|
13
|
-
if (
|
|
13
|
+
if ((0, zss_engine_1.isAtRule)(prop)) {
|
|
14
14
|
Object.entries(value).forEach(([innerProp, innerValue]) => {
|
|
15
15
|
const atomicMap = new Map();
|
|
16
16
|
const notSuffix = innerProp.startsWith('--') ? '' : notNormalize;
|
|
@@ -49,7 +49,7 @@ function getStyleRecords(styleRule) {
|
|
|
49
49
|
const nonFlatBase = {};
|
|
50
50
|
const nonFlatQuery = {};
|
|
51
51
|
Object.entries(nonFlat).forEach(([atRule, nestedObj]) => {
|
|
52
|
-
if (
|
|
52
|
+
if ((0, zss_engine_1.isAtRule)(atRule)) {
|
|
53
53
|
nonFlatQuery[atRule] = nestedObj;
|
|
54
54
|
}
|
|
55
55
|
else {
|
package/dist/createTheme.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { CreateTheme } from './types';
|
|
2
|
-
declare const createTheme: <const T extends CreateTheme>(
|
|
2
|
+
declare const createTheme: <const T extends CreateTheme>(themeSelector: string, rule: T) => {
|
|
3
|
+
':where(:root)': {
|
|
4
|
+
[x: string]: string | number | Record<string, string | number>;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
3
7
|
export { createTheme };
|
package/dist/createTheme.js
CHANGED
|
@@ -2,29 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTheme = void 0;
|
|
4
4
|
const zss_engine_1 = require("zss-engine");
|
|
5
|
-
const createTheme = (
|
|
6
|
-
const
|
|
5
|
+
const createTheme = (themeSelector, rule) => {
|
|
6
|
+
const rootTarget = {};
|
|
7
|
+
const themeTarget = {};
|
|
7
8
|
for (const key in rule) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const value = themeMap[themeKey];
|
|
14
|
-
const isQuery = themeKey.startsWith('@media') || themeKey.startsWith('@container');
|
|
15
|
-
const selector = isQuery || themeKey === 'default'
|
|
16
|
-
? ':root'
|
|
17
|
-
: `:root[data-theme="${themeKey}"]`;
|
|
18
|
-
const target = (styles[selector] ||= {});
|
|
19
|
-
if (isQuery) {
|
|
20
|
-
const queryObj = (target[themeKey] ||= {});
|
|
21
|
-
queryObj[varKey] = value;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
target[varKey] = value;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
9
|
+
const valueObj = rule[key];
|
|
10
|
+
const hash = (0, zss_engine_1.genBase36Hash)({ [key]: valueObj }, 1, 8);
|
|
11
|
+
const cssVarName = `--${hash}-${(0, zss_engine_1.camelToKebabCase)(key)}`;
|
|
12
|
+
rootTarget[cssVarName] = valueObj.default;
|
|
13
|
+
themeTarget[cssVarName] = valueObj.theme;
|
|
27
14
|
}
|
|
28
|
-
|
|
15
|
+
if ((0, zss_engine_1.isAtRule)(themeSelector)) {
|
|
16
|
+
return {
|
|
17
|
+
':where(:root)': {
|
|
18
|
+
...rootTarget,
|
|
19
|
+
[themeSelector]: themeTarget,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const formattedSelector = themeSelector.startsWith('@') ||
|
|
24
|
+
themeSelector.startsWith('.') ||
|
|
25
|
+
themeSelector.startsWith('#') ||
|
|
26
|
+
themeSelector.startsWith(':') ||
|
|
27
|
+
themeSelector.startsWith('[')
|
|
28
|
+
? themeSelector
|
|
29
|
+
: '.' + themeSelector;
|
|
30
|
+
return {
|
|
31
|
+
':where(:root)': rootTarget,
|
|
32
|
+
[formattedSelector]: themeTarget,
|
|
33
|
+
};
|
|
29
34
|
};
|
|
30
35
|
exports.createTheme = createTheme;
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CSSObject, Tables, StaticTable, KeyframesHashTable, ViewTransitionHashTable,
|
|
1
|
+
import type { CSSObject, Tables, StaticTable, KeyframesHashTable, ViewTransitionHashTable, CreateHashTable, VariantsHashTable, CreateThemeHashTable, CreateThemeObjectTable, CreateStaticHashTable, CreateStaticObjectTable } from './types';
|
|
2
2
|
import { Module, CallExpression, Identifier, KeyValueProperty, StringLiteral, NumericLiteral, BooleanLiteral, ObjectExpression, MemberExpression, TemplateLiteral, BinaryExpression, UnaryExpression, VariableDeclaration, VariableDeclarator, ExportDeclaration, ConditionalExpression } from '@swc/core';
|
|
3
3
|
export declare const t: {
|
|
4
4
|
isObjectExpression: (node: any) => node is ObjectExpression;
|
package/dist/parser.js
CHANGED
|
@@ -511,8 +511,10 @@ function resolveCreateThemeTableMemberExpressionByNode(node, createThemeHashTabl
|
|
|
511
511
|
key = node.property.expression.value;
|
|
512
512
|
}
|
|
513
513
|
if (key && themeObj[key] !== undefined) {
|
|
514
|
+
const value = themeObj[key];
|
|
515
|
+
const atomicHash = (0, zss_engine_1.genBase36Hash)({ [key]: value }, 1, 8);
|
|
514
516
|
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
515
|
-
return `var(--${
|
|
517
|
+
return `var(--${atomicHash}-${cssVarName})`;
|
|
516
518
|
}
|
|
517
519
|
}
|
|
518
520
|
}
|
|
@@ -555,6 +557,7 @@ function scanAll() {
|
|
|
555
557
|
viewTransitionHashTable: {},
|
|
556
558
|
viewTransitionObjectTable: {},
|
|
557
559
|
createThemeObjectTable: {},
|
|
560
|
+
createThemeSelectorTable: {},
|
|
558
561
|
createHashTable: {},
|
|
559
562
|
createObjectTable: {},
|
|
560
563
|
createAtomicMapTable: {},
|
|
@@ -600,6 +603,10 @@ function scanAll() {
|
|
|
600
603
|
localTables.createThemeObjectTable[key] =
|
|
601
604
|
cached.createThemeObjectTable[key];
|
|
602
605
|
}
|
|
606
|
+
for (const key of Object.keys(cached.createThemeSelectorTable)) {
|
|
607
|
+
localTables.createThemeSelectorTable[key] =
|
|
608
|
+
cached.createThemeSelectorTable[key];
|
|
609
|
+
}
|
|
603
610
|
for (const key of Object.keys(cached.createStaticHashTable)) {
|
|
604
611
|
localTables.createStaticHashTable[`${filePath}-${key}`] =
|
|
605
612
|
cached.createStaticHashTable[key];
|
|
@@ -651,6 +658,7 @@ function scanAll() {
|
|
|
651
658
|
viewTransitionHashTable: {},
|
|
652
659
|
viewTransitionObjectTable: {},
|
|
653
660
|
createThemeHashTable: {},
|
|
661
|
+
createThemeSelectorTable: {},
|
|
654
662
|
createThemeObjectTable: {},
|
|
655
663
|
createHashTable: {},
|
|
656
664
|
createObjectTable: {},
|
|
@@ -683,6 +691,7 @@ function scanAll() {
|
|
|
683
691
|
const localViewTransitionHashTable = {};
|
|
684
692
|
const localViewTransitionObjectTable = {};
|
|
685
693
|
const localCreateThemeObjectTable = {};
|
|
694
|
+
const localCreateThemeSelectorTable = {};
|
|
686
695
|
const localCreateHashTable = {};
|
|
687
696
|
const localCreateObjectTable = {};
|
|
688
697
|
const localCreateAtomicMapTable = {};
|
|
@@ -797,9 +806,14 @@ function scanAll() {
|
|
|
797
806
|
method = originalName;
|
|
798
807
|
}
|
|
799
808
|
}
|
|
809
|
+
const isCreateTheme = method === 'createTheme';
|
|
800
810
|
if (method &&
|
|
801
811
|
decl.init.arguments.length > 0 &&
|
|
802
|
-
|
|
812
|
+
((!isCreateTheme &&
|
|
813
|
+
exports.t.isObjectExpression(decl.init.arguments[0].expression)) ||
|
|
814
|
+
(isCreateTheme &&
|
|
815
|
+
decl.init.arguments.length >= 2 &&
|
|
816
|
+
exports.t.isObjectExpression(decl.init.arguments[1].expression)))) {
|
|
803
817
|
const name = decl.id.value;
|
|
804
818
|
const init = decl.init;
|
|
805
819
|
const resolveVariable = (name) => {
|
|
@@ -809,7 +823,10 @@ function scanAll() {
|
|
|
809
823
|
}
|
|
810
824
|
return undefined;
|
|
811
825
|
};
|
|
812
|
-
const
|
|
826
|
+
const objExpression = isCreateTheme
|
|
827
|
+
? init.arguments[1].expression
|
|
828
|
+
: init.arguments[0].expression;
|
|
829
|
+
const obj = objectExpressionToObject(objExpression, localStaticTable, localKeyframesHashTable, localViewTransitionHashTable, localCreateThemeHashTable, localCreateThemeObjectTable, localCreateHashTable, localCreateStaticHashTable, localCreateStaticObjectTable, localVariantsHashTable, resolveVariable);
|
|
813
830
|
const uniqueKey = `${filePath}-${name}`;
|
|
814
831
|
const isPassOneMethod = method === 'createStatic' ||
|
|
815
832
|
method === 'createTheme' ||
|
|
@@ -843,16 +860,23 @@ function scanAll() {
|
|
|
843
860
|
localViewTransitionObjectTable[hash] = obj;
|
|
844
861
|
}
|
|
845
862
|
else if (method === 'createTheme') {
|
|
863
|
+
let selector = '';
|
|
864
|
+
const selectorExpr = init.arguments[0].expression;
|
|
865
|
+
if (exports.t.isStringLiteral(selectorExpr)) {
|
|
866
|
+
selector = selectorExpr.value;
|
|
867
|
+
}
|
|
846
868
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
847
869
|
localTables.createThemeObjectTable[hash] = obj;
|
|
848
870
|
localCreateThemeObjectTable[hash] = obj;
|
|
849
871
|
localCreateThemeHashTable[name] = hash;
|
|
850
872
|
localTables.createThemeHashTable[uniqueKey] = hash;
|
|
851
|
-
|
|
873
|
+
localCreateThemeSelectorTable[hash] = selector;
|
|
874
|
+
localTables.createThemeSelectorTable[hash] = selector;
|
|
852
875
|
const hashMap = {};
|
|
853
|
-
for (const [key] of Object.entries(obj)) {
|
|
876
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
877
|
+
const atomicHash = (0, zss_engine_1.genBase36Hash)({ [key]: value }, 1, 8);
|
|
854
878
|
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
855
|
-
hashMap[key] = `var(--${
|
|
879
|
+
hashMap[key] = `var(--${atomicHash}-${cssVarName})`;
|
|
856
880
|
}
|
|
857
881
|
localCreateAtomicMapTable[hash] = hashMap;
|
|
858
882
|
localTables.createAtomicMapTable[hash] = hashMap;
|
|
@@ -893,6 +917,7 @@ function scanAll() {
|
|
|
893
917
|
viewTransitionHashTable: localViewTransitionHashTable,
|
|
894
918
|
viewTransitionObjectTable: localViewTransitionObjectTable,
|
|
895
919
|
createThemeHashTable: localCreateThemeHashTable,
|
|
920
|
+
createThemeSelectorTable: localCreateThemeSelectorTable,
|
|
896
921
|
createThemeObjectTable: localCreateThemeObjectTable,
|
|
897
922
|
createHashTable: localCreateHashTable,
|
|
898
923
|
createObjectTable: localCreateObjectTable,
|
|
@@ -1014,21 +1039,20 @@ function extractOndemandStyles(obj, extractedSheets, t) {
|
|
|
1014
1039
|
.forEach((themeVarName) => {
|
|
1015
1040
|
const hash = t.createThemeHashTable[themeVarName];
|
|
1016
1041
|
const definition = t.createThemeObjectTable[hash];
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
let hasUsed = false;
|
|
1042
|
+
const selector = t.createThemeSelectorTable[hash];
|
|
1043
|
+
if (definition && typeof definition === 'object' && selector) {
|
|
1020
1044
|
Object.keys(definition).forEach((key) => {
|
|
1021
|
-
const
|
|
1045
|
+
const value = definition[key];
|
|
1046
|
+
const atomicHash = (0, zss_engine_1.genBase36Hash)({ [key]: value }, 1, 8);
|
|
1047
|
+
const varName = `--${atomicHash}-${(0, zss_engine_1.camelToKebabCase)(key)}`;
|
|
1022
1048
|
if (usedVariables.has(varName)) {
|
|
1023
|
-
|
|
1024
|
-
|
|
1049
|
+
const styles = (0, createTheme_1.createTheme)(selector, {
|
|
1050
|
+
[key]: value,
|
|
1051
|
+
});
|
|
1052
|
+
const { styleSheet } = (0, zss_engine_1.transpile)(styles, undefined, '--global');
|
|
1053
|
+
addSheet(styleSheet);
|
|
1025
1054
|
}
|
|
1026
1055
|
});
|
|
1027
|
-
if (hasUsed) {
|
|
1028
|
-
const styles = (0, createTheme_1.createTheme)(filteredDefinition, hash);
|
|
1029
|
-
const { styleSheet } = (0, zss_engine_1.transpile)(styles, undefined, '--global');
|
|
1030
|
-
addSheet(styleSheet);
|
|
1031
|
-
}
|
|
1032
1056
|
}
|
|
1033
1057
|
});
|
|
1034
1058
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type CreateAtomicMapTable = Record<string, Record<string, Record<string,
|
|
|
18
18
|
export type CreateStaticHashTable = Record<string, string>;
|
|
19
19
|
export type CreateStaticObjectTable = Record<string, CSSObject>;
|
|
20
20
|
export type CreateThemeHashTable = Record<string, string>;
|
|
21
|
+
export type CreateThemeSelectorTable = Record<string, string>;
|
|
21
22
|
export interface Tables {
|
|
22
23
|
staticTable: StaticTable;
|
|
23
24
|
keyframesHashTable: KeyframesHashTable;
|
|
@@ -25,6 +26,7 @@ export interface Tables {
|
|
|
25
26
|
viewTransitionHashTable: ViewTransitionHashTable;
|
|
26
27
|
viewTransitionObjectTable: ViewTransitionObjectTable;
|
|
27
28
|
createThemeHashTable: CreateThemeHashTable;
|
|
29
|
+
createThemeSelectorTable: CreateThemeSelectorTable;
|
|
28
30
|
createThemeObjectTable: CreateThemeObjectTable;
|
|
29
31
|
createHashTable: CreateHashTable;
|
|
30
32
|
createObjectTable: CreateObjectTable;
|
|
@@ -34,7 +36,12 @@ export interface Tables {
|
|
|
34
36
|
variantsHashTable: VariantsHashTable;
|
|
35
37
|
variantsObjectTable: VariantsObjectTable;
|
|
36
38
|
}
|
|
37
|
-
export type CreateTheme =
|
|
39
|
+
export type CreateTheme = {
|
|
40
|
+
[key: string]: {
|
|
41
|
+
default: string | number;
|
|
42
|
+
theme: string | number;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
38
45
|
export type ViewTransition = {
|
|
39
46
|
group?: CSSProperties;
|
|
40
47
|
imagePair?: CSSProperties;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.1",
|
|
4
4
|
"description": "Plumeria Utils",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"lightningcss": "^1.32.0",
|
|
27
27
|
"postcss": "8.5.15",
|
|
28
28
|
"postcss-combine-media-query": "^2.1.0",
|
|
29
|
-
"zss-engine": "2.
|
|
29
|
+
"zss-engine": "2.3.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public",
|