@plumeria/utils 2.2.2 → 2.2.4
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/transform.d.ts +3 -3
- package/dist/transform.js +44 -35
- package/package.json +2 -2
package/dist/transform.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CSSProperties, CreateStyleType, CreateTheme, CreateValues } from 'zss-engine';
|
|
2
|
-
declare function createCSS<T extends Record<string, CSSProperties>>(
|
|
3
|
-
declare const createVars: <const T extends CreateValues>(
|
|
4
|
-
declare const createTheme: <const T extends CreateTheme>(
|
|
2
|
+
declare function createCSS<T extends Record<string, CSSProperties>>(rule: CreateStyleType<T>): string;
|
|
3
|
+
declare const createVars: <const T extends CreateValues>(rule: T) => Record<string, CreateValues>;
|
|
4
|
+
declare const createTheme: <const T extends CreateTheme>(rule: T) => Record<string, Record<string, string | number | Record<string, string | number>>>;
|
|
5
5
|
export { createCSS, createVars, createTheme };
|
package/dist/transform.js
CHANGED
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createTheme = exports.createVars = void 0;
|
|
4
4
|
exports.createCSS = createCSS;
|
|
5
5
|
const zss_engine_1 = require("zss-engine");
|
|
6
|
-
function compileToSingleCSS(
|
|
6
|
+
function compileToSingleCSS(rule) {
|
|
7
7
|
const baseSheets = [];
|
|
8
8
|
const querySheets = [];
|
|
9
9
|
const processedHashes = new Set();
|
|
10
|
-
Object.entries(
|
|
10
|
+
Object.entries(rule).forEach(([key, styleRule]) => {
|
|
11
11
|
const flat = {};
|
|
12
12
|
const nonFlat = {};
|
|
13
|
-
(0, zss_engine_1.splitAtomicAndNested)(
|
|
13
|
+
(0, zss_engine_1.splitAtomicAndNested)(styleRule, flat, nonFlat);
|
|
14
14
|
const finalFlat = (0, zss_engine_1.overrideLonghand)(flat);
|
|
15
15
|
const records = [];
|
|
16
16
|
Object.entries(finalFlat).forEach(([prop, value]) => {
|
|
@@ -62,23 +62,28 @@ function compileToSingleCSS(object) {
|
|
|
62
62
|
nonFlatBase[atRule] = nestedObj;
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return;
|
|
68
|
-
const nonFlatObj = { [key]: targetNonFlat };
|
|
65
|
+
Object.entries(nonFlatBase).forEach(([selector, style]) => {
|
|
66
|
+
const nonFlatObj = { [key]: { [selector]: style } };
|
|
69
67
|
const nonFlatHash = (0, zss_engine_1.genBase36Hash)(nonFlatObj, 1, 7);
|
|
70
68
|
const { styleSheet } = (0, zss_engine_1.transpile)(nonFlatObj, nonFlatHash);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
: styleSheet
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
records.push({
|
|
70
|
+
key: selector,
|
|
71
|
+
hash: nonFlatHash,
|
|
72
|
+
sheet: styleSheet,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
Object.entries(nonFlatQuery).forEach(([atRule, nestedStyles]) => {
|
|
76
|
+
Object.entries(nestedStyles).forEach(([pseudoSelector, style]) => {
|
|
77
|
+
const nonFlatObj = {
|
|
78
|
+
[key]: { [atRule]: { [pseudoSelector]: style } },
|
|
79
|
+
};
|
|
80
|
+
const nonFlatHash = (0, zss_engine_1.genBase36Hash)(nonFlatObj, 1, 7);
|
|
81
|
+
const { styleSheet } = (0, zss_engine_1.transpile)(nonFlatObj, nonFlatHash);
|
|
82
|
+
const finalSheet = styleSheet.replace(`.${nonFlatHash}`, `.${nonFlatHash}:not(#\\#):not(#\\#)`);
|
|
83
|
+
records.push({
|
|
84
|
+
key: atRule + pseudoSelector,
|
|
85
|
+
hash: nonFlatHash,
|
|
86
|
+
sheet: finalSheet,
|
|
82
87
|
});
|
|
83
88
|
});
|
|
84
89
|
});
|
|
@@ -97,37 +102,41 @@ function compileToSingleCSS(object) {
|
|
|
97
102
|
});
|
|
98
103
|
return [...baseSheets, ...querySheets].filter(Boolean).join('');
|
|
99
104
|
}
|
|
100
|
-
function createCSS(
|
|
101
|
-
const compiledCSS = compileToSingleCSS(
|
|
105
|
+
function createCSS(rule) {
|
|
106
|
+
const compiledCSS = compileToSingleCSS(rule);
|
|
102
107
|
return compiledCSS;
|
|
103
108
|
}
|
|
104
|
-
const createVars = (
|
|
109
|
+
const createVars = (rule) => {
|
|
105
110
|
const styles = {
|
|
106
111
|
':root': {},
|
|
107
112
|
};
|
|
108
|
-
Object.entries(
|
|
113
|
+
Object.entries(rule).forEach(([key, value]) => {
|
|
109
114
|
styles[':root'][`--${key}`] = value;
|
|
110
115
|
});
|
|
111
116
|
return styles;
|
|
112
117
|
};
|
|
113
118
|
exports.createVars = createVars;
|
|
114
|
-
const createTheme = (
|
|
119
|
+
const createTheme = (rule) => {
|
|
115
120
|
const styles = {};
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
for (const key in rule) {
|
|
122
|
+
const varKey = `--${(0, zss_engine_1.camelToKebabCase)(key)}`;
|
|
123
|
+
const themeMap = rule[key];
|
|
124
|
+
for (const themeKey in themeMap) {
|
|
125
|
+
const value = themeMap[themeKey];
|
|
126
|
+
const isQuery = themeKey.startsWith('@media') || themeKey.startsWith('@container');
|
|
127
|
+
const selector = isQuery || themeKey === 'default'
|
|
128
|
+
? ':root'
|
|
129
|
+
: `:root[data-theme="${themeKey}"]`;
|
|
130
|
+
const target = (styles[selector] ||= {});
|
|
131
|
+
if (isQuery) {
|
|
132
|
+
const queryObj = (target[themeKey] ||= {});
|
|
133
|
+
queryObj[varKey] = value;
|
|
123
134
|
}
|
|
124
135
|
else {
|
|
125
|
-
|
|
126
|
-
styles[themeSelector] ||= {};
|
|
127
|
-
styles[themeSelector][`--${kebabKey}`] = subValue;
|
|
136
|
+
target[varKey] = value;
|
|
128
137
|
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
131
140
|
return styles;
|
|
132
141
|
};
|
|
133
142
|
exports.createTheme = createTheme;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/utils",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "Plumeria Utils",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@swc/core": "1.15.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"zss-engine": "
|
|
27
|
+
"zss-engine": "2.0.0"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public",
|