@plumeria/webpack-plugin 0.18.5 → 0.19.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/create.d.ts +3 -3
- package/dist/create.js +3 -3
- package/dist/index.js +16 -13
- package/dist/types.d.ts +4 -3
- package/dist/virtual-css-loader.d.ts +1 -1
- package/dist/virtual-css-loader.js +100 -103
- package/package.json +2 -2
package/dist/create.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CSSProperties, CreateStyleType,
|
|
1
|
+
import type { CSSProperties, CreateStyleType, CreateTokens, CreateValues } from 'zss-engine';
|
|
2
2
|
declare function createCSS<T extends Record<string, CSSProperties>>(object: CreateStyleType<T>): string;
|
|
3
3
|
declare const createVars: <const T extends CreateValues>(object: T) => Record<string, CreateValues>;
|
|
4
|
-
declare const
|
|
5
|
-
export { createCSS, createVars,
|
|
4
|
+
declare const createTokens: <const T extends CreateTokens>(object: T) => Record<string, Record<string, string | number | object>>;
|
|
5
|
+
export { createCSS, createVars, createTokens };
|
package/dist/create.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createTokens = exports.createVars = void 0;
|
|
4
4
|
exports.createCSS = createCSS;
|
|
5
5
|
const zss_engine_1 = require("zss-engine");
|
|
6
6
|
function compileToSingleCSS(object) {
|
|
@@ -83,7 +83,7 @@ const createVars = (object) => {
|
|
|
83
83
|
return styles;
|
|
84
84
|
};
|
|
85
85
|
exports.createVars = createVars;
|
|
86
|
-
const
|
|
86
|
+
const createTokens = (object) => {
|
|
87
87
|
const styles = {};
|
|
88
88
|
Object.entries(object).forEach(([key, value]) => {
|
|
89
89
|
Object.entries(value).forEach(([subKey, subValue]) => {
|
|
@@ -101,4 +101,4 @@ const createTheme = (object) => {
|
|
|
101
101
|
});
|
|
102
102
|
return styles;
|
|
103
103
|
};
|
|
104
|
-
exports.
|
|
104
|
+
exports.createTokens = createTokens;
|
package/dist/index.js
CHANGED
|
@@ -61,9 +61,8 @@ class PlumeriaPlugin {
|
|
|
61
61
|
const prev = this.stylesByFile.get(absPath) || {
|
|
62
62
|
filePath,
|
|
63
63
|
keyframeStyles: '',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
globalStyles: '',
|
|
64
|
+
viewTransitionStyles: '',
|
|
65
|
+
tokenStyles: '',
|
|
67
66
|
baseStyles: '',
|
|
68
67
|
};
|
|
69
68
|
const isCurrentPage = this.isCurrentPageFile(absPath);
|
|
@@ -82,25 +81,29 @@ class PlumeriaPlugin {
|
|
|
82
81
|
}
|
|
83
82
|
generateOrderedCSS() {
|
|
84
83
|
const allStyles = Array.from(this.stylesByFile.values());
|
|
84
|
+
if (allStyles.length === 0) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
85
87
|
const sortedStyles = allStyles.sort((a, b) => (b.lastAccessed || 0) - (a.lastAccessed || 0));
|
|
88
|
+
const latestStyles = sortedStyles[0];
|
|
86
89
|
const keyframeStylesSet = new Set();
|
|
87
|
-
const
|
|
88
|
-
const
|
|
90
|
+
const viewTransitionStylesSet = new Set();
|
|
91
|
+
const tokenStylesSet = new Set();
|
|
89
92
|
const baseStylesSet = new Set();
|
|
93
|
+
if (latestStyles.keyframeStyles?.trim().length > 0)
|
|
94
|
+
keyframeStylesSet.add(latestStyles.keyframeStyles);
|
|
95
|
+
if (latestStyles.viewTransitionStyles?.trim().length > 0)
|
|
96
|
+
viewTransitionStylesSet.add(latestStyles.viewTransitionStyles);
|
|
97
|
+
if (latestStyles.tokenStyles?.trim().length > 0)
|
|
98
|
+
tokenStylesSet.add(latestStyles.tokenStyles);
|
|
90
99
|
for (const s of sortedStyles) {
|
|
91
|
-
if (s.keyframeStyles?.trim().length > 0)
|
|
92
|
-
keyframeStylesSet.add(s.keyframeStyles);
|
|
93
|
-
if (s.varStyles?.trim().length > 0)
|
|
94
|
-
varStylesSet.add(s.varStyles);
|
|
95
|
-
if (s.themeStyles?.trim().length > 0)
|
|
96
|
-
themeStylesSet.add(s.themeStyles);
|
|
97
100
|
if (s.baseStyles?.trim().length > 0)
|
|
98
101
|
baseStylesSet.add(s.baseStyles);
|
|
99
102
|
}
|
|
100
103
|
return [
|
|
101
104
|
...Array.from(keyframeStylesSet),
|
|
102
|
-
...Array.from(
|
|
103
|
-
...Array.from(
|
|
105
|
+
...Array.from(viewTransitionStylesSet),
|
|
106
|
+
...Array.from(tokenStylesSet),
|
|
104
107
|
...Array.from(baseStylesSet),
|
|
105
108
|
]
|
|
106
109
|
.filter(Boolean)
|
package/dist/types.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export type CSSObject = {
|
|
|
6
6
|
};
|
|
7
7
|
export type ConstTable = Record<string, CSSObject | string>;
|
|
8
8
|
export type VariableTable = Record<string, CSSObject>;
|
|
9
|
-
export type
|
|
9
|
+
export type TokensTable = Record<string, CSSObject>;
|
|
10
10
|
export type KeyframesHashTable = Record<string, string>;
|
|
11
11
|
export type KeyframesObjectTable = Record<string, CSSObject>;
|
|
12
|
-
export type
|
|
13
|
-
export type
|
|
12
|
+
export type ViewTransitionHashTable = Record<string, string>;
|
|
13
|
+
export type ViewTransitionObjectTable = Record<string, CSSObject>;
|
|
14
|
+
export type DefineTokensObjectTable = Record<string, CSSObject>;
|
|
14
15
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { LoaderContext } from 'webpack';
|
|
2
|
-
export default function loader(this: LoaderContext<unknown>, source: string):
|
|
2
|
+
export default function loader(this: LoaderContext<unknown>, source: string): void;
|
|
@@ -51,33 +51,33 @@ const GLOB_OPTIONS = {
|
|
|
51
51
|
cwd: PROJECT_ROOT,
|
|
52
52
|
};
|
|
53
53
|
let constTable = {};
|
|
54
|
-
let
|
|
55
|
-
let themeTable = {};
|
|
54
|
+
let tokensTable = {};
|
|
56
55
|
let keyframesHashTable = {};
|
|
57
56
|
let keyframesObjectTable = {};
|
|
58
|
-
let
|
|
59
|
-
let
|
|
60
|
-
|
|
57
|
+
let viewTransitionHashTable = {};
|
|
58
|
+
let viewTransitionObjectTable = {};
|
|
59
|
+
let defineTokensObjectTable = {};
|
|
60
|
+
function objectExpressionToObject(node, constTable, keyframesHashTable, viewTransitionHashTable, tokensTable) {
|
|
61
61
|
const obj = {};
|
|
62
62
|
node.properties.forEach((prop) => {
|
|
63
63
|
if (!t.isObjectProperty(prop))
|
|
64
64
|
return;
|
|
65
|
-
const key = getPropertyKey(prop.key, constTable
|
|
65
|
+
const key = getPropertyKey(prop.key, constTable);
|
|
66
66
|
if (!key)
|
|
67
67
|
return;
|
|
68
68
|
const val = prop.value;
|
|
69
69
|
if (t.isIdentifier(val) || t.isMemberExpression(val)) {
|
|
70
70
|
const resolvedKeyframe = resolveKeyframesTableMemberExpression(val, keyframesHashTable);
|
|
71
71
|
if (resolvedKeyframe !== undefined) {
|
|
72
|
-
obj[key] = resolvedKeyframe;
|
|
72
|
+
obj[key] = 'kf-' + resolvedKeyframe;
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
obj[key] =
|
|
75
|
+
const resolvedViewTransitioin = resolveViewTransitionTableMemberExpression(val, viewTransitionHashTable);
|
|
76
|
+
if (resolvedViewTransitioin !== undefined) {
|
|
77
|
+
obj[key] = 'vt-' + resolvedViewTransitioin;
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
const resolvedTheme =
|
|
80
|
+
const resolvedTheme = resolveTokensTableMemberExpressionByNode(val, tokensTable);
|
|
81
81
|
if (resolvedTheme !== undefined) {
|
|
82
82
|
obj[key] = resolvedTheme;
|
|
83
83
|
return;
|
|
@@ -92,7 +92,7 @@ function objectExpressionToObject(node, constTable, keyframesHashTable, variable
|
|
|
92
92
|
obj[key] = evaluateUnaryExpression(val);
|
|
93
93
|
}
|
|
94
94
|
else if (t.isObjectExpression(val)) {
|
|
95
|
-
obj[key] = objectExpressionToObject(val, constTable, keyframesHashTable,
|
|
95
|
+
obj[key] = objectExpressionToObject(val, constTable, keyframesHashTable, viewTransitionHashTable, tokensTable);
|
|
96
96
|
}
|
|
97
97
|
else if (t.isMemberExpression(val)) {
|
|
98
98
|
const resolved = resolveConstTableMemberExpression(val, constTable);
|
|
@@ -126,7 +126,7 @@ function collectLocalConsts(ast) {
|
|
|
126
126
|
});
|
|
127
127
|
return localConsts;
|
|
128
128
|
}
|
|
129
|
-
function getPropertyKey(node, constTable
|
|
129
|
+
function getPropertyKey(node, constTable) {
|
|
130
130
|
if (t.isIdentifier(node)) {
|
|
131
131
|
if (constTable[node.name] && typeof constTable[node.name] === 'string') {
|
|
132
132
|
return constTable[node.name];
|
|
@@ -142,34 +142,34 @@ function getPropertyKey(node, constTable, variableTable) {
|
|
|
142
142
|
throw new Error(`Resolved key is not a string: ${JSON.stringify(result)}`);
|
|
143
143
|
}
|
|
144
144
|
if (t.isTemplateLiteral(node)) {
|
|
145
|
-
return evaluateTemplateLiteral(node, constTable
|
|
145
|
+
return evaluateTemplateLiteral(node, constTable);
|
|
146
146
|
}
|
|
147
147
|
if (t.isBinaryExpression(node)) {
|
|
148
|
-
return evaluateBinaryExpression(node, constTable
|
|
148
|
+
return evaluateBinaryExpression(node, constTable);
|
|
149
149
|
}
|
|
150
150
|
throw new Error(`Unsupported property key type: ${node.type}`);
|
|
151
151
|
}
|
|
152
|
-
function evaluateTemplateLiteral(node, constTable
|
|
152
|
+
function evaluateTemplateLiteral(node, constTable) {
|
|
153
153
|
let result = '';
|
|
154
154
|
for (let i = 0; i < node.quasis.length; i++) {
|
|
155
155
|
result += node.quasis[i].value.cooked || node.quasis[i].value.raw;
|
|
156
156
|
if (i < node.expressions.length) {
|
|
157
157
|
const expr = node.expressions[i];
|
|
158
|
-
const evaluatedExpr = evaluateExpression(expr, constTable
|
|
158
|
+
const evaluatedExpr = evaluateExpression(expr, constTable);
|
|
159
159
|
result += String(evaluatedExpr);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
return result;
|
|
163
163
|
}
|
|
164
|
-
function evaluateBinaryExpression(node, constTable
|
|
165
|
-
const left = evaluateExpression(node.left, constTable
|
|
166
|
-
const right = evaluateExpression(node.right, constTable
|
|
164
|
+
function evaluateBinaryExpression(node, constTable) {
|
|
165
|
+
const left = evaluateExpression(node.left, constTable);
|
|
166
|
+
const right = evaluateExpression(node.right, constTable);
|
|
167
167
|
if (node.operator === '+') {
|
|
168
168
|
return String(left) + String(right);
|
|
169
169
|
}
|
|
170
170
|
throw new Error(`Unsupported binary operator: ${node.operator}`);
|
|
171
171
|
}
|
|
172
|
-
function evaluateExpression(node, constTable
|
|
172
|
+
function evaluateExpression(node, constTable) {
|
|
173
173
|
if (t.isStringLiteral(node)) {
|
|
174
174
|
return node.value;
|
|
175
175
|
}
|
|
@@ -189,6 +189,9 @@ function evaluateExpression(node, constTable, variableTable) {
|
|
|
189
189
|
if (keyframesHashTable[node.name] !== undefined) {
|
|
190
190
|
return keyframesHashTable[node.name];
|
|
191
191
|
}
|
|
192
|
+
if (viewTransitionHashTable[node.name] !== undefined) {
|
|
193
|
+
return viewTransitionHashTable[node.name];
|
|
194
|
+
}
|
|
192
195
|
return `[unresolved: ${node.name}]`;
|
|
193
196
|
}
|
|
194
197
|
if (t.isMemberExpression(node)) {
|
|
@@ -196,21 +199,17 @@ function evaluateExpression(node, constTable, variableTable) {
|
|
|
196
199
|
if (resolved !== undefined) {
|
|
197
200
|
return resolved;
|
|
198
201
|
}
|
|
199
|
-
const
|
|
200
|
-
if (resolvedVar !== undefined) {
|
|
201
|
-
return resolvedVar;
|
|
202
|
-
}
|
|
203
|
-
const resolvedTheme = resolveThemeTableMemberExpressionByNode(node, themeTable);
|
|
202
|
+
const resolvedTheme = resolveTokensTableMemberExpressionByNode(node, tokensTable);
|
|
204
203
|
if (resolvedTheme !== undefined) {
|
|
205
204
|
return resolvedTheme;
|
|
206
205
|
}
|
|
207
206
|
return `[unresolved member expression]`;
|
|
208
207
|
}
|
|
209
208
|
if (t.isBinaryExpression(node)) {
|
|
210
|
-
return evaluateBinaryExpression(node, constTable
|
|
209
|
+
return evaluateBinaryExpression(node, constTable);
|
|
211
210
|
}
|
|
212
211
|
if (t.isTemplateLiteral(node)) {
|
|
213
|
-
return evaluateTemplateLiteral(node, constTable
|
|
212
|
+
return evaluateTemplateLiteral(node, constTable);
|
|
214
213
|
}
|
|
215
214
|
if (t.isUnaryExpression(node)) {
|
|
216
215
|
return evaluateUnaryExpression(node);
|
|
@@ -244,6 +243,17 @@ function resolveKeyframesTableMemberExpression(node, keyframesHashTable) {
|
|
|
244
243
|
}
|
|
245
244
|
return undefined;
|
|
246
245
|
}
|
|
246
|
+
function resolveViewTransitionTableMemberExpression(node, viewTransitionHashTable) {
|
|
247
|
+
if (t.isIdentifier(node)) {
|
|
248
|
+
return viewTransitionHashTable[node.name];
|
|
249
|
+
}
|
|
250
|
+
if (t.isMemberExpression(node)) {
|
|
251
|
+
if (t.isIdentifier(node.object)) {
|
|
252
|
+
return viewTransitionHashTable[node.object.name];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
247
257
|
function resolveConstTableMemberExpression(node, constTable) {
|
|
248
258
|
if (t.isIdentifier(node.object) && t.isIdentifier(node.property)) {
|
|
249
259
|
const varName = node.object.name;
|
|
@@ -258,10 +268,10 @@ function resolveConstTableMemberExpression(node, constTable) {
|
|
|
258
268
|
}
|
|
259
269
|
return undefined;
|
|
260
270
|
}
|
|
261
|
-
function
|
|
271
|
+
function resolveTokensTableMemberExpressionByNode(node, tokensTable, asObject = false) {
|
|
262
272
|
if (t.isIdentifier(node)) {
|
|
263
|
-
if (asObject && typeof
|
|
264
|
-
return { ...
|
|
273
|
+
if (asObject && typeof tokensTable[node.name] === 'object') {
|
|
274
|
+
return { ...tokensTable[node.name] };
|
|
265
275
|
}
|
|
266
276
|
const cssVarName = (0, zss_engine_1.camelToKebabCase)(node.name);
|
|
267
277
|
return `var(--${cssVarName})`;
|
|
@@ -276,37 +286,10 @@ function resolveVariableTableMemberExpressionByNode(node, variableTable, asObjec
|
|
|
276
286
|
key = node.property.value;
|
|
277
287
|
}
|
|
278
288
|
if (key &&
|
|
279
|
-
|
|
280
|
-
|
|
289
|
+
tokensTable[varName] &&
|
|
290
|
+
tokensTable[varName][key] !== undefined) {
|
|
281
291
|
if (asObject) {
|
|
282
|
-
return { [key]:
|
|
283
|
-
}
|
|
284
|
-
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
285
|
-
return `var(--${cssVarName})`;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return undefined;
|
|
289
|
-
}
|
|
290
|
-
function resolveThemeTableMemberExpressionByNode(node, themeTable, asObject = false) {
|
|
291
|
-
if (t.isIdentifier(node)) {
|
|
292
|
-
if (asObject && typeof themeTable[node.name] === 'object') {
|
|
293
|
-
return { ...themeTable[node.name] };
|
|
294
|
-
}
|
|
295
|
-
const cssVarName = (0, zss_engine_1.camelToKebabCase)(node.name);
|
|
296
|
-
return `var(--${cssVarName})`;
|
|
297
|
-
}
|
|
298
|
-
if (t.isMemberExpression(node) && t.isIdentifier(node.object)) {
|
|
299
|
-
const varName = node.object.name;
|
|
300
|
-
let key;
|
|
301
|
-
if (t.isIdentifier(node.property)) {
|
|
302
|
-
key = node.property.name;
|
|
303
|
-
}
|
|
304
|
-
else if (t.isStringLiteral(node.property)) {
|
|
305
|
-
key = node.property.value;
|
|
306
|
-
}
|
|
307
|
-
if (key && themeTable[varName] && themeTable[varName][key] !== undefined) {
|
|
308
|
-
if (asObject) {
|
|
309
|
-
return { [key]: themeTable[varName][key] };
|
|
292
|
+
return { [key]: tokensTable[varName][key] };
|
|
310
293
|
}
|
|
311
294
|
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
312
295
|
return `var(--${cssVarName})`;
|
|
@@ -349,7 +332,7 @@ function scanForDefineConsts() {
|
|
|
349
332
|
t.isIdentifier(decl.init.callee.property, { name: 'defineConsts' }) &&
|
|
350
333
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
351
334
|
const varName = decl.id.name;
|
|
352
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable,
|
|
335
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable, viewTransitionHashTable, tokensTable);
|
|
353
336
|
constTableLocal[varName] = obj;
|
|
354
337
|
}
|
|
355
338
|
}
|
|
@@ -393,7 +376,7 @@ function scanForKeyframes() {
|
|
|
393
376
|
t.isIdentifier(decl.init.callee.property, { name: 'keyframes' }) &&
|
|
394
377
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
395
378
|
const varName = decl.id.name;
|
|
396
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal,
|
|
379
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal, viewTransitionHashTable, tokensTable);
|
|
397
380
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
398
381
|
keyframesHashTableLocal[varName] = hash;
|
|
399
382
|
keyframesObjectTableLocal[hash] = obj;
|
|
@@ -406,12 +389,12 @@ function scanForKeyframes() {
|
|
|
406
389
|
keyframesObjectTableLocal,
|
|
407
390
|
};
|
|
408
391
|
}
|
|
409
|
-
function
|
|
410
|
-
const
|
|
411
|
-
const
|
|
392
|
+
function scanForDefineTokens() {
|
|
393
|
+
const tokensTableLocal = {};
|
|
394
|
+
const defineTokensObjectTableLocal = {};
|
|
412
395
|
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
413
396
|
for (const filePath of files) {
|
|
414
|
-
if (!isCSSDefineFile(filePath, '
|
|
397
|
+
if (!isCSSDefineFile(filePath, 'defineTokens'))
|
|
415
398
|
continue;
|
|
416
399
|
this.addDependency(filePath);
|
|
417
400
|
const source = fs_1.default.readFileSync(filePath, 'utf8');
|
|
@@ -439,24 +422,24 @@ function scanForDefineVars() {
|
|
|
439
422
|
t.isCallExpression(decl.init) &&
|
|
440
423
|
t.isMemberExpression(decl.init.callee) &&
|
|
441
424
|
t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
|
|
442
|
-
t.isIdentifier(decl.init.callee.property, { name: '
|
|
425
|
+
t.isIdentifier(decl.init.callee.property, { name: 'defineTokens' }) &&
|
|
443
426
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
444
427
|
const varName = decl.id.name;
|
|
445
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable,
|
|
446
|
-
|
|
447
|
-
|
|
428
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTable, tokensTableLocal);
|
|
429
|
+
tokensTableLocal[varName] = obj;
|
|
430
|
+
defineTokensObjectTableLocal[varName] = obj;
|
|
448
431
|
}
|
|
449
432
|
}
|
|
450
433
|
}
|
|
451
434
|
}
|
|
452
|
-
return {
|
|
435
|
+
return { tokensTableLocal, defineTokensObjectTableLocal };
|
|
453
436
|
}
|
|
454
|
-
function
|
|
455
|
-
const
|
|
456
|
-
const
|
|
437
|
+
function scanForViewTransition() {
|
|
438
|
+
const viewTransitionHashTableLocal = {};
|
|
439
|
+
const viewTransitionObjectTableLocal = {};
|
|
457
440
|
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
458
441
|
for (const filePath of files) {
|
|
459
|
-
if (!isCSSDefineFile(filePath, '
|
|
442
|
+
if (!isCSSDefineFile(filePath, 'viewTransition'))
|
|
460
443
|
continue;
|
|
461
444
|
this.addDependency(filePath);
|
|
462
445
|
const source = fs_1.default.readFileSync(filePath, 'utf8');
|
|
@@ -484,17 +467,23 @@ function scanForDefineTheme() {
|
|
|
484
467
|
t.isCallExpression(decl.init) &&
|
|
485
468
|
t.isMemberExpression(decl.init.callee) &&
|
|
486
469
|
t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
|
|
487
|
-
t.isIdentifier(decl.init.callee.property, {
|
|
470
|
+
t.isIdentifier(decl.init.callee.property, {
|
|
471
|
+
name: 'viewTransition',
|
|
472
|
+
}) &&
|
|
488
473
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
489
474
|
const varName = decl.id.name;
|
|
490
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable,
|
|
491
|
-
|
|
492
|
-
|
|
475
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTableLocal, tokensTable);
|
|
476
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
477
|
+
viewTransitionHashTableLocal[varName] = hash;
|
|
478
|
+
viewTransitionObjectTableLocal[hash] = obj;
|
|
493
479
|
}
|
|
494
480
|
}
|
|
495
481
|
}
|
|
496
482
|
}
|
|
497
|
-
return {
|
|
483
|
+
return {
|
|
484
|
+
viewTransitionHashTableLocal,
|
|
485
|
+
viewTransitionObjectTableLocal,
|
|
486
|
+
};
|
|
498
487
|
}
|
|
499
488
|
function isCSSDefineFile(filePath, target) {
|
|
500
489
|
if (fs_1.default.statSync(filePath).isDirectory())
|
|
@@ -532,19 +521,24 @@ function isCSSDefineFile(filePath, target) {
|
|
|
532
521
|
return found;
|
|
533
522
|
}
|
|
534
523
|
function loader(source) {
|
|
524
|
+
const callback = this.async();
|
|
525
|
+
const useClientDirective = /^\s*['"]use client['"]/;
|
|
526
|
+
if (useClientDirective.test(source)) {
|
|
527
|
+
callback(null, source);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
535
530
|
this.clearDependencies();
|
|
536
531
|
this.addDependency(this.resourcePath);
|
|
537
|
-
const callback = this.async();
|
|
538
532
|
constTable = scanForDefineConsts.call(this);
|
|
539
533
|
const { keyframesHashTableLocal, keyframesObjectTableLocal } = scanForKeyframes.call(this);
|
|
540
534
|
keyframesHashTable = keyframesHashTableLocal;
|
|
541
535
|
keyframesObjectTable = keyframesObjectTableLocal;
|
|
542
|
-
const {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
536
|
+
const { viewTransitionHashTableLocal, viewTransitionObjectTableLocal } = scanForViewTransition.call(this);
|
|
537
|
+
viewTransitionHashTable = viewTransitionHashTableLocal;
|
|
538
|
+
viewTransitionObjectTable = viewTransitionObjectTableLocal;
|
|
539
|
+
const { tokensTableLocal, defineTokensObjectTableLocal } = scanForDefineTokens.call(this);
|
|
540
|
+
tokensTable = tokensTableLocal;
|
|
541
|
+
defineTokensObjectTable = defineTokensObjectTableLocal;
|
|
548
542
|
let extractedObject = null;
|
|
549
543
|
let ast;
|
|
550
544
|
try {
|
|
@@ -557,10 +551,13 @@ function loader(source) {
|
|
|
557
551
|
}
|
|
558
552
|
catch (err) {
|
|
559
553
|
console.log(err);
|
|
560
|
-
|
|
554
|
+
callback(null, source);
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (!ast) {
|
|
558
|
+
callback(null, source);
|
|
559
|
+
return;
|
|
561
560
|
}
|
|
562
|
-
if (!ast)
|
|
563
|
-
return callback(null, source);
|
|
564
561
|
const localConsts = collectLocalConsts(ast);
|
|
565
562
|
Object.assign(constTable, localConsts);
|
|
566
563
|
const pluginAst = {
|
|
@@ -574,7 +571,7 @@ function loader(source) {
|
|
|
574
571
|
if (callee.property.name === 'create' &&
|
|
575
572
|
args.length === 1 &&
|
|
576
573
|
t.isObjectExpression(args[0])) {
|
|
577
|
-
extractedObject = objectExpressionToObject(args[0], constTable, keyframesHashTable,
|
|
574
|
+
extractedObject = objectExpressionToObject(args[0], constTable, keyframesHashTable, viewTransitionHashTable, tokensTable);
|
|
578
575
|
}
|
|
579
576
|
}
|
|
580
577
|
},
|
|
@@ -593,19 +590,21 @@ function loader(source) {
|
|
|
593
590
|
}
|
|
594
591
|
if (Object.keys(keyframesObjectTable).length > 0) {
|
|
595
592
|
fileStyles.keyframeStyles = Object.entries(keyframesObjectTable)
|
|
596
|
-
.map(([hash, obj]) => (0, zss_engine_1.transpile)({ [`@keyframes
|
|
593
|
+
.map(([hash, obj]) => (0, zss_engine_1.transpile)({ [`@keyframes kf-${hash}`]: obj }, undefined, '--global')
|
|
597
594
|
.styleSheet)
|
|
598
595
|
.join('\n');
|
|
599
596
|
}
|
|
600
|
-
if (Object.keys(
|
|
601
|
-
fileStyles.
|
|
602
|
-
.map((obj) => (0, zss_engine_1.transpile)(
|
|
603
|
-
.
|
|
597
|
+
if (Object.keys(viewTransitionObjectTable).length > 0) {
|
|
598
|
+
fileStyles.viewTransitionStyles = Object.entries(viewTransitionObjectTable)
|
|
599
|
+
.map(([hash, obj]) => (0, zss_engine_1.transpile)({
|
|
600
|
+
[`::view-transition-old(vt-${hash})`]: obj.old,
|
|
601
|
+
[`::view-transition-new(vt-${hash})`]: obj.new,
|
|
602
|
+
}, undefined, '--global').styleSheet)
|
|
604
603
|
.join('\n');
|
|
605
604
|
}
|
|
606
|
-
if (Object.keys(
|
|
607
|
-
fileStyles.
|
|
608
|
-
.map((obj) => (0, zss_engine_1.transpile)((0, create_1.
|
|
605
|
+
if (Object.keys(defineTokensObjectTable).length > 0) {
|
|
606
|
+
fileStyles.tokenStyles = Object.values(defineTokensObjectTable)
|
|
607
|
+
.map((obj) => (0, zss_engine_1.transpile)((0, create_1.createTokens)(obj), undefined, '--global')
|
|
609
608
|
.styleSheet)
|
|
610
609
|
.join('\n');
|
|
611
610
|
}
|
|
@@ -639,7 +638,5 @@ function loader(source) {
|
|
|
639
638
|
pluginInstance.registerFileStyles(fileKey, fileStyles);
|
|
640
639
|
}
|
|
641
640
|
}
|
|
642
|
-
|
|
643
|
-
callback(null, source + postfix);
|
|
644
|
-
return source + postfix;
|
|
641
|
+
callback(null, source + postfix);
|
|
645
642
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Plumeria Webpack plugin",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@rust-gear/glob": "^0.2.2",
|
|
25
25
|
"@types/babel__core": "^7.20.5",
|
|
26
26
|
"webpack": "^5.101.0",
|
|
27
|
-
"zss-engine": "^0.2.
|
|
27
|
+
"zss-engine": "^0.2.87"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|