@fluentic/style 0.1.0-beta.12 → 0.1.0-beta.14
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/CHANGELOG.md +20 -0
- package/README.md +3 -2
- package/atomic/layer/layer.ts +7 -3
- package/atomic/token.ts +10 -1
- package/builder/data/data.ts +1 -1
- package/builder/extract/token.ts +10 -0
- package/builder/selector_override_core.ts +7 -1
- package/compiler/extract/extract.ts +14 -9
- package/compiler/extract/types.ts +2 -1
- package/compiler/transform/evaluator/evaluator.ts +83 -9
- package/compiler/transform/evaluator/tracer.ts +4 -0
- package/compiler/transform/extract/chain/chain.ts +7 -4
- package/compiler/transform/extract/chain/extract_chain.ts +14 -0
- package/compiler/transform/extract/plugin.ts +30 -4
- package/compiler/transform/extract/utils/imports.ts +5 -1
- package/compiler/transform/extract/utils/replacement.ts +21 -4
- package/compiler/transform/extract/utils/state.ts +2 -0
- package/compiler/transform/extract/utils/token.ts +107 -0
- package/compiler/utils/constants.ts +1 -0
- package/config/config/css.ts +19 -0
- package/css/sheet.ts +3 -2
- package/dialect/namedTokens.ts +13 -8
- package/dist/{combine-Bww7VnSr.js → combine-CC9bY-hu.js} +2 -2
- package/dist/{combine-Bww7VnSr.js.map → combine-CC9bY-hu.js.map} +1 -1
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-mCfMhtX4.mjs → compiler-Ct5xGIeu.mjs} +197 -37
- package/dist/compiler-Ct5xGIeu.mjs.map +1 -0
- package/dist/config/index.js +2 -2
- package/dist/{config-DNEnHEf3.js → config-BiiMS4rU.js} +3 -3
- package/dist/{config-DNEnHEf3.js.map → config-BiiMS4rU.js.map} +1 -1
- package/dist/{config-CDjbHwb-.js → config-CCgsVvyR.js} +2 -2
- package/dist/{config-CDjbHwb-.js.map → config-CCgsVvyR.js.map} +1 -1
- package/dist/{config-C5VWvTav.js → config-DZKR6gH1.js} +4 -4
- package/dist/{config-C5VWvTav.js.map → config-DZKR6gH1.js.map} +1 -1
- package/dist/{config-BKP5LOkt.js → config-TyjNpRrV.js} +2 -2
- package/dist/{config-BKP5LOkt.js.map → config-TyjNpRrV.js.map} +1 -1
- package/dist/{createTransformElement-D8fXZ3wA.js → createTransformElement-BGznW-Mu.js} +2 -2
- package/dist/{createTransformElement-D8fXZ3wA.js.map → createTransformElement-BGznW-Mu.js.map} +1 -1
- package/dist/{css-BDn0epJ8.js → css-BhoclXaw.js} +7 -7
- package/dist/css-BhoclXaw.js.map +1 -0
- package/dist/{css-DEYgrj76.js → css-IecKRNxs.js} +13 -13
- package/dist/css-IecKRNxs.js.map +1 -0
- package/dist/{css-CFxNrYt3.js → css-WaHZ6gxv.js} +46 -21
- package/dist/css-WaHZ6gxv.js.map +1 -0
- package/dist/css.js +1 -1
- package/dist/{css_extra-nTq_Gw0E.js → css_extra-DDeJc2Cu.js} +2 -2
- package/dist/{css_extra-nTq_Gw0E.js.map → css_extra-DDeJc2Cu.js.map} +1 -1
- package/dist/{data-CDrS1Bq4.js → data-BgZmL55Y.js} +7 -8
- package/dist/{data-CDrS1Bq4.js.map → data-BgZmL55Y.js.map} +1 -1
- package/dist/{debug-BkVbf0Cz.js → debug-D-1hhd0G.js} +27 -3
- package/dist/debug-D-1hhd0G.js.map +1 -0
- package/dist/dev/rsc.js +7 -7
- package/dist/dev/rsc.js.map +1 -1
- package/dist/{dev-0imWmSVb.js → dev-CBRbVaeq.js} +6 -7
- package/dist/{dev-0imWmSVb.js.map → dev-CBRbVaeq.js.map} +1 -1
- package/dist/dev.js +1 -1
- package/dist/dialect/extracted/index.js +1 -1
- package/dist/dialect/index.js +1 -1
- package/dist/{elementMarker-kvpMjB49.js → elementMarker-CJcfpKL1.js} +35 -22
- package/dist/elementMarker-CJcfpKL1.js.map +1 -0
- package/dist/entry/dev/adapter/preact.js +1 -1
- package/dist/entry/dev/adapter/react.js +1 -1
- package/dist/entry/dev/adapter/solid.js +1 -1
- package/dist/entry/dev/css.js +2 -2
- package/dist/entry/dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/dev/jsx-runtime.js +2 -2
- package/dist/entry/dev.js +11 -11
- package/dist/entry/prod/css.js +2 -2
- package/dist/entry/prod/extract.js +10 -1
- package/dist/entry/prod/extract.js.map +1 -1
- package/dist/entry/prod.js +2 -2
- package/dist/entry/rsc-dev/adapter/preact.js +1 -1
- package/dist/entry/rsc-dev/adapter/react.js +1 -1
- package/dist/entry/rsc-dev/adapter/solid.js +1 -1
- package/dist/entry/rsc-dev/css.js +2 -2
- package/dist/entry/rsc-dev/dev.js +6 -6
- package/dist/entry/rsc-dev/dev.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +5 -5
- package/dist/entry/rsc-prod/css.js +2 -2
- package/dist/entry/rsc-prod.js +12 -3
- package/dist/entry/rsc-prod.js.map +1 -1
- package/dist/{env-Cz8frh6e.js → env-C8TRVSyb.js} +44 -19
- package/dist/env-C8TRVSyb.js.map +1 -0
- package/dist/getClassName-9CsXbNls.js.map +1 -1
- package/dist/{getClassName-DGm-VNDo.js → getClassName-BNe3Ycyy.js} +4 -5
- package/dist/{getClassName-DGm-VNDo.js.map → getClassName-BNe3Ycyy.js.map} +1 -1
- package/dist/{getClassName-Dtc4yyYI.js → getClassName-CeoxISNW.js} +4 -4
- package/dist/{getClassName-Dtc4yyYI.js.map → getClassName-CeoxISNW.js.map} +1 -1
- package/dist/getClassName-DtkplEIt.js.map +1 -1
- package/dist/{global-CAc9OjKx.js → global-CWYOol4o.js} +2 -2
- package/dist/{global-CAc9OjKx.js.map → global-CWYOol4o.js.map} +1 -1
- package/dist/global-UOHFwqHN.js +33 -0
- package/dist/global-UOHFwqHN.js.map +1 -0
- package/dist/{debug-YuhEIQVO.js → hash-DlXmmPPm.js} +167 -5
- package/dist/hash-DlXmmPPm.js.map +1 -0
- package/dist/index.js +9 -9
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/jsx/jsx-dev-runtime.server.js +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.server.js +1 -1
- package/dist/{jsx-CVxpkS04.js → jsx-8TwYuvgM.js} +4 -4
- package/dist/{jsx-CVxpkS04.js.map → jsx-8TwYuvgM.js.map} +1 -1
- package/dist/{jsx_runtime-6Qa1lmz2.js → jsx_runtime-CPojW0KD.js} +2 -2
- package/dist/{jsx_runtime-6Qa1lmz2.js.map → jsx_runtime-CPojW0KD.js.map} +1 -1
- package/dist/{loader-DUS2i9Zb.mjs → loader-BVebGteg.mjs} +3 -3
- package/dist/{loader-DUS2i9Zb.mjs.map → loader-BVebGteg.mjs.map} +1 -1
- package/dist/{misc-vGtt_SX7.mjs → misc-Bs2DgdG7.mjs} +2 -2
- package/dist/{misc-vGtt_SX7.mjs.map → misc-Bs2DgdG7.mjs.map} +1 -1
- package/dist/{namedTokens-5AayGokX.js → namedTokens-CwniouKk.js} +13 -9
- package/dist/namedTokens-CwniouKk.js.map +1 -0
- package/dist/plugin/farm/index.mjs +3 -3
- package/dist/plugin/nextjs/index.mjs +4 -4
- package/dist/plugin/nextjs/loader.mjs +4 -4
- package/dist/plugin/parcel/index.cjs +1 -1
- package/dist/plugin/parcel/index.mjs +2 -2
- package/dist/plugin/parcel/optimizer.cjs +1 -1
- package/dist/plugin/parcel/optimizer.mjs +2 -2
- package/dist/plugin/parcel/resolver.cjs +1 -1
- package/dist/plugin/parcel/resolver.mjs +2 -2
- package/dist/plugin/parcel/runtime.cjs +1 -1
- package/dist/plugin/parcel/runtime.mjs +1 -1
- package/dist/plugin/parcel/transformer.cjs +1 -1
- package/dist/plugin/parcel/transformer.mjs +2 -2
- package/dist/plugin/rspack/index.mjs +2 -2
- package/dist/plugin/vite/index.mjs +3 -3
- package/dist/plugin/webpack/index.mjs +2 -2
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/presets/tailwind/index.js +3 -3
- package/dist/{registry-BJqMbdMu.mjs → registry-D1n78rd7.mjs} +2 -2
- package/dist/{registry-BJqMbdMu.mjs.map → registry-D1n78rd7.mjs.map} +1 -1
- package/dist/{resolveClassNameRuntime-CJjlUP93.js → resolveClassNameRuntime-BJcykzdl.js} +2 -2
- package/dist/{resolveClassNameRuntime-CJjlUP93.js.map → resolveClassNameRuntime-BJcykzdl.js.map} +1 -1
- package/dist/{rules-DaMaMHgb.js → rules-Dz-szpPu.js} +8 -9
- package/dist/{rules-DaMaMHgb.js.map → rules-Dz-szpPu.js.map} +1 -1
- package/dist/server.js +13 -13
- package/dist/{shared-BRUPuZdH.cjs → shared-C9XQd8p_.cjs} +197 -37
- package/dist/shared-C9XQd8p_.cjs.map +1 -0
- package/dist/{shared-DDzZd0tM.mjs → shared-D4-AKGn6.mjs} +4 -4
- package/dist/{shared-DDzZd0tM.mjs.map → shared-D4-AKGn6.mjs.map} +1 -1
- package/dist/sheet-LU89fcH_.js +7 -0
- package/dist/{sheet-CxkO1Hwt.js.map → sheet-LU89fcH_.js.map} +1 -1
- package/dist/{sidecar-BTT0veLU.mjs → sidecar-CZTYX2vA.mjs} +3 -3
- package/dist/{sidecar-BTT0veLU.mjs.map → sidecar-CZTYX2vA.mjs.map} +1 -1
- package/dist/{style-CAhAnRni.js → style-CmXHCPF4.js} +10 -11
- package/dist/{style-CAhAnRni.js.map → style-CmXHCPF4.js.map} +1 -1
- package/dist/{styleStore-DaIJ4OPV.js → styleStore-B0x4Ahpx.js} +9 -7
- package/dist/styleStore-B0x4Ahpx.js.map +1 -0
- package/dist/{styleStore-BzLZwpwy.js → styleStore-BrpgLNgc.js} +6 -4
- package/dist/styleStore-BrpgLNgc.js.map +1 -0
- package/dist/{token-D33mKTka.js → token-DMrBbat8.js} +5 -33
- package/dist/token-DMrBbat8.js.map +1 -0
- package/dist/{trace-B3dpTRJp.js → trace-C7EzEj2Q.js} +3 -3
- package/dist/{trace-B3dpTRJp.js.map → trace-C7EzEj2Q.js.map} +1 -1
- package/dist/{trace-c2WmBbmX.js → trace-DzCntvK4.js} +2 -2
- package/dist/{trace-c2WmBbmX.js.map → trace-DzCntvK4.js.map} +1 -1
- package/dist/{transform-DSpimwwC.js → transform-CSZMklMb.js} +2 -2
- package/dist/{transform-DSpimwwC.js.map → transform-CSZMklMb.js.map} +1 -1
- package/dist/types/builder/data/data.d.ts +1 -1
- package/dist/types/builder/data/merge/utils.d.ts +6 -1
- package/dist/types/builder/data/state.d.ts +16 -2
- package/dist/types/builder/extract/token.d.ts +6 -1
- package/dist/types/builder/style_fns.d.ts +1 -1
- package/dist/types/builder/utils.d.ts +1 -1
- package/dist/types/compiler/extract/types.d.ts +2 -1
- package/dist/types/compiler/transform/evaluator/evaluator.d.ts +18 -1
- package/dist/types/compiler/transform/extract/utils/replacement.d.ts +2 -0
- package/dist/types/compiler/transform/extract/utils/state.d.ts +1 -0
- package/dist/types/compiler/transform/extract/utils/token.d.ts +3 -0
- package/dist/types/compiler/utils/constants.d.ts +1 -0
- package/dist/types/compiler/utils/import_source.d.ts +8 -2
- package/dist/types/config/config/css.d.ts +5 -0
- package/dist/types/plugin/bundler/farm/plugin.d.ts +8 -2
- package/dist/types/presets/tailwind/selectors.d.ts +24 -24
- package/dist/types/presets/tailwind/theme.d.ts +361 -361
- package/dist/types/runtime/core/cache/itemWithResolver.d.ts +1 -1
- package/dist/types/runtime/core/cache/stateItem.d.ts +8 -2
- package/dist/types/runtime/types.d.ts +4 -1
- package/dist/types/selector/presets/default.d.ts +28 -28
- package/dist/types/selector/presets/minimal.d.ts +10 -10
- package/dist/types/selector/selector.d.ts +15 -2
- package/dist/types/sheet/types.d.ts +2 -1
- package/dist/types/sheet/utils/layer.d.ts +1 -1
- package/dist/types/style/style.d.ts +93 -93
- package/dist/{utils-DZK0mfmY.js → utils-B7QcJ-Yw.js} +3 -3
- package/dist/{utils-DZK0mfmY.js.map → utils-B7QcJ-Yw.js.map} +1 -1
- package/dist/{utils-D4UympcZ.mjs → utils-BYpkJ-uE.mjs} +3 -3
- package/dist/{utils-D4UympcZ.mjs.map → utils-BYpkJ-uE.mjs.map} +1 -1
- package/dist/{utils-D75HPJWv.mjs → utils-CoMwEfhG.mjs} +4 -4
- package/dist/{utils-D75HPJWv.mjs.map → utils-CoMwEfhG.mjs.map} +1 -1
- package/dist/{utils-H1VInWpd.js → utils-D4KMqCu2.js} +37 -16
- package/dist/utils-D4KMqCu2.js.map +1 -0
- package/dist/utils.js +3 -3
- package/dist/{value-CK0-Xbov.js → value-yd2SZ1XQ.js} +37 -3
- package/dist/value-yd2SZ1XQ.js.map +1 -0
- package/dist/{webpack-_BpgAUEy.mjs → webpack-B6z1UHh9.mjs} +5 -5
- package/dist/{webpack-_BpgAUEy.mjs.map → webpack-B6z1UHh9.mjs.map} +1 -1
- package/package.json +5 -4
- package/runtime/extract/getClassName.ts +1 -1
- package/runtime/rsc/observer.ts +4 -1
- package/runtime/rsc/styleStore.ts +6 -2
- package/runtime/sheet/rule.ts +2 -2
- package/sheet/dev/dev_layer.ts +7 -3
- package/sheet/dev/dev_sort.ts +18 -11
- package/sheet/prod.ts +7 -3
- package/sheet/types.ts +2 -1
- package/sheet/utils/layer.ts +2 -1
- package/style/token.ts +2 -0
- package/dist/compiler-mCfMhtX4.mjs.map +0 -1
- package/dist/css-BDn0epJ8.js.map +0 -1
- package/dist/css-CFxNrYt3.js.map +0 -1
- package/dist/css-DEYgrj76.js.map +0 -1
- package/dist/css-DWBWsyxZ.js +0 -50
- package/dist/css-DWBWsyxZ.js.map +0 -1
- package/dist/debug-BkVbf0Cz.js.map +0 -1
- package/dist/debug-YuhEIQVO.js.map +0 -1
- package/dist/elementMarker-kvpMjB49.js.map +0 -1
- package/dist/env-Cz8frh6e.js.map +0 -1
- package/dist/hash-Cr-LCWDt.js +0 -166
- package/dist/hash-Cr-LCWDt.js.map +0 -1
- package/dist/namedTokens-5AayGokX.js.map +0 -1
- package/dist/shared-BRUPuZdH.cjs.map +0 -1
- package/dist/sheet-CxkO1Hwt.js +0 -7
- package/dist/styleStore-BzLZwpwy.js.map +0 -1
- package/dist/styleStore-DaIJ4OPV.js.map +0 -1
- package/dist/token-D33mKTka.js.map +0 -1
- package/dist/utils-H1VInWpd.js.map +0 -1
- package/dist/value-CK0-Xbov.js.map +0 -1
|
@@ -132,6 +132,13 @@ const CSS_CONFIG = globalData("config.css", () => ({ ...CSS_CONFIG_DEFAULT }));
|
|
|
132
132
|
function isStyleLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
133
133
|
return typeof layer === "boolean" ? layer : layer.style ?? true;
|
|
134
134
|
}
|
|
135
|
+
function isSheetLayerOption(value) {
|
|
136
|
+
return value === void 0 || typeof value === "boolean" || typeof value === "string" && /^\.?(?:--|-?[a-zA-Z_\u0080-\uFFFF])[\w\u0080-\uFFFF-]*(?:\.(?:--|-?[a-zA-Z_\u0080-\uFFFF])[\w\u0080-\uFFFF-]*)*$/.test(value);
|
|
137
|
+
}
|
|
138
|
+
function resolveSheetLayerOption(layer, namespace) {
|
|
139
|
+
if (typeof layer !== "string") return layer ? "sheet" : false;
|
|
140
|
+
return { name: layer.startsWith(".") ? namespace ? namespace + layer : layer.slice(1) : layer };
|
|
141
|
+
}
|
|
135
142
|
function isSheetLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
136
143
|
return typeof layer === "object" && (layer.sheet ?? false);
|
|
137
144
|
}
|
|
@@ -182,7 +189,7 @@ function compareLayerPriority(p1, p2) {
|
|
|
182
189
|
}
|
|
183
190
|
function flattenCssLayers(layers, layerNames) {
|
|
184
191
|
const names = typeof layerNames === "string" ? [layerNames] : layerNames;
|
|
185
|
-
return layers.flatMap((layer) => layer === "$layer" ? names : layer).filter(Boolean);
|
|
192
|
+
return [...new Set(layers.flatMap((layer) => layer === "$layer" ? names.filter((name) => !layers.includes(name)) : layer).filter(Boolean))];
|
|
186
193
|
}
|
|
187
194
|
const LayerDefaultPriority = [
|
|
188
195
|
0,
|
|
@@ -250,6 +257,7 @@ const FN_CREATE_EXTRACTED_SHEET = "createExtractedSheet";
|
|
|
250
257
|
const FN_CREATE_EXTRACTED_SLOT = "createExtractedSlot";
|
|
251
258
|
const FN_CREATE_EXTRACTED_SCOPE = "createExtractedScope";
|
|
252
259
|
const FN_CREATE_EXTRACTED_TOKEN = "createExtractedToken";
|
|
260
|
+
const FN_CREATE_EXTRACTED_VALUES = "createExtractedValues";
|
|
253
261
|
const FN_CREATE_EXTRACTED_THEME = "createExtractedTheme";
|
|
254
262
|
const FN_CREATE_EXTRACTED_STYLE_MERGE = "createExtractedStyleMerge";
|
|
255
263
|
const FN_WITH_TOKENS = "withTokens";
|
|
@@ -265,8 +273,9 @@ function getExtractedCssItems(items, args) {
|
|
|
265
273
|
const seen = /* @__PURE__ */ new Set();
|
|
266
274
|
const css = [];
|
|
267
275
|
for (const item of sortedItems) {
|
|
268
|
-
|
|
269
|
-
seen.
|
|
276
|
+
const key = JSON.stringify([item.layer, item.css]);
|
|
277
|
+
if (seen.has(key)) continue;
|
|
278
|
+
seen.add(key);
|
|
270
279
|
css.push(item);
|
|
271
280
|
}
|
|
272
281
|
if (!css.length) return "";
|
|
@@ -276,21 +285,25 @@ function getExtractedCssItems(items, args) {
|
|
|
276
285
|
const styleLayer = isStyleLayerEnabled(args.layer ?? defaults.layer);
|
|
277
286
|
const sheetLayerName = layerNamespace ? layerNamespace + ".sheet" : "sheet";
|
|
278
287
|
const styleItems = [];
|
|
279
|
-
const sheetItems =
|
|
288
|
+
const sheetItems = /* @__PURE__ */ new Map();
|
|
280
289
|
const unlayeredItems = [];
|
|
281
290
|
for (let i = 0, len = css.length; i < len; i++) {
|
|
282
291
|
const item = css[i];
|
|
283
|
-
if (item.layer === "sheet"
|
|
284
|
-
|
|
292
|
+
if (item.layer === "sheet" || typeof item.layer === "object") {
|
|
293
|
+
const name = typeof item.layer === "object" ? item.layer.name : sheetLayerName;
|
|
294
|
+
const rules = sheetItems.get(name) ?? [];
|
|
295
|
+
rules.push(item.css);
|
|
296
|
+
sheetItems.set(name, rules);
|
|
297
|
+
} else if (item.layer === false || !styleLayer) unlayeredItems.push(item.css);
|
|
285
298
|
else styleItems.push(item.css);
|
|
286
299
|
}
|
|
287
|
-
const styleLayerName = sheetItems.
|
|
288
|
-
const layerNames = [styleItems.length ? styleLayerName : "", sheetItems.
|
|
300
|
+
const styleLayerName = [...sheetItems.keys()].some((name) => name.startsWith(layerNamespace + ".")) && layerNamespace ? layerNamespace + ".style" : layerNamespace;
|
|
301
|
+
const layerNames = [styleItems.length ? styleLayerName : "", ...sheetItems.keys()].filter(Boolean);
|
|
289
302
|
const output = [];
|
|
290
303
|
const layerOrder = getLayerOrderCss(layers, layerNames);
|
|
291
304
|
if (layerOrder) output.push(layerOrder);
|
|
292
305
|
if (styleItems.length) output.push(getLayerBlockCss(styleLayerName, "\n" + styleItems.join("\n") + "\n"));
|
|
293
|
-
|
|
306
|
+
for (const [name, rules] of sheetItems) output.push(getLayerBlockCss(name, "\n" + rules.join("\n") + "\n"));
|
|
294
307
|
output.push(...unlayeredItems);
|
|
295
308
|
return output.join("\n");
|
|
296
309
|
}
|
|
@@ -685,6 +698,9 @@ function getStyleTokenId(token) {
|
|
|
685
698
|
function getStyleTokenName(token) {
|
|
686
699
|
return token[TOKEN_NAME] ?? null;
|
|
687
700
|
}
|
|
701
|
+
function getStyleTokenVarName(token) {
|
|
702
|
+
return token[TOKEN_VAR_NAME] ?? null;
|
|
703
|
+
}
|
|
688
704
|
//#endregion
|
|
689
705
|
//#region builder/token/name.ts
|
|
690
706
|
function getStyleTokenNameFromId(id) {
|
|
@@ -744,12 +760,14 @@ function createStyleTokenOverride(token, value, debug) {
|
|
|
744
760
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
745
761
|
[TOKEN_OVERRIDE]: true,
|
|
746
762
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
763
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
747
764
|
value: value.value,
|
|
748
765
|
ref: value
|
|
749
766
|
} : {
|
|
750
767
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
751
768
|
[TOKEN_OVERRIDE]: true,
|
|
752
769
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
770
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
753
771
|
value,
|
|
754
772
|
ref: null
|
|
755
773
|
};
|
|
@@ -1583,6 +1601,8 @@ function escapeCssValue(value) {
|
|
|
1583
1601
|
}
|
|
1584
1602
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1585
1603
|
function getTokenVarName(token, format) {
|
|
1604
|
+
const explicitName = getStyleTokenVarName(token);
|
|
1605
|
+
if (explicitName) return explicitName;
|
|
1586
1606
|
const id = getStyleTokenId(token);
|
|
1587
1607
|
const debugName = getStyleTokenName(token);
|
|
1588
1608
|
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
@@ -1965,7 +1985,7 @@ function assertManualSelectorSyntax(selector) {
|
|
|
1965
1985
|
function setSheetSelectorOptions(selector, options) {
|
|
1966
1986
|
if (options.weight === void 0 && options.layer === void 0) return selector;
|
|
1967
1987
|
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
1968
|
-
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.weight ?? "") + ":" + (options.layer === void 0 ? "" : options.layer ? "1" : "0")) + "\0" + text.slice(6);
|
|
1988
|
+
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.weight ?? "") + ":" + (typeof options.layer === "string" ? JSON.stringify(options.layer) : options.layer === void 0 ? "" : options.layer ? "1" : "0")) + "\0" + text.slice(6);
|
|
1969
1989
|
return Array.isArray(selector) ? [weighted, selector[1]] : weighted;
|
|
1970
1990
|
}
|
|
1971
1991
|
function normalizeManualSelector(selector, assertManualSelector) {
|
|
@@ -3833,8 +3853,9 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
3833
3853
|
//#region dialect/namedTokens.ts
|
|
3834
3854
|
const ROOT = Symbol("fluentic.namedTokens.root");
|
|
3835
3855
|
function createNamedToken(id, value) {
|
|
3836
|
-
const
|
|
3837
|
-
token
|
|
3856
|
+
const tokenId = createNamedTokenId(id);
|
|
3857
|
+
const token = createStyleToken(value, tokenId);
|
|
3858
|
+
token[TOKEN_VAR_NAME] = "--token-" + tokenId;
|
|
3838
3859
|
return token;
|
|
3839
3860
|
}
|
|
3840
3861
|
function createNamedTokens(namespace, values) {
|
|
@@ -3846,7 +3867,10 @@ function createNamedTokens(namespace, values) {
|
|
|
3846
3867
|
}, []);
|
|
3847
3868
|
}
|
|
3848
3869
|
function createNamedTokenId(id) {
|
|
3849
|
-
return
|
|
3870
|
+
return id.split(".").map(encodeNamedTokenSegment).join("-");
|
|
3871
|
+
}
|
|
3872
|
+
function encodeNamedTokenSegment(segment) {
|
|
3873
|
+
return segment.replace(/[^a-zA-Z0-9]/gu, (char) => "_x" + char.codePointAt(0).toString(16) + "_");
|
|
3850
3874
|
}
|
|
3851
3875
|
function createNamedTokenProxy(root, path) {
|
|
3852
3876
|
return new Proxy(noop, {
|
|
@@ -3868,11 +3892,13 @@ function createNamedTokenProxy(root, path) {
|
|
|
3868
3892
|
});
|
|
3869
3893
|
}
|
|
3870
3894
|
function getNamedTokenAtPath(root, path) {
|
|
3871
|
-
const key =
|
|
3895
|
+
const key = JSON.stringify(path);
|
|
3872
3896
|
const cached = root.cache.get(key);
|
|
3873
3897
|
if (cached) return cached;
|
|
3874
3898
|
const value = getValueAtPath(root.values, path);
|
|
3875
|
-
const
|
|
3899
|
+
const id = root.namespace.split(".").concat(path).map(encodeNamedTokenSegment).join("-");
|
|
3900
|
+
const token = createStyleToken(value, id);
|
|
3901
|
+
token[TOKEN_VAR_NAME] = "--token-" + id;
|
|
3876
3902
|
root.cache.set(key, token);
|
|
3877
3903
|
return token;
|
|
3878
3904
|
}
|
|
@@ -3909,6 +3935,7 @@ function exposeStyleValue(value) {
|
|
|
3909
3935
|
//#region compiler/transform/evaluator/evaluator.ts
|
|
3910
3936
|
const STYLE_IMPORT_PATHS = new Set(IMPORT_PATHS);
|
|
3911
3937
|
const COMPILED_RUNTIME_VALUE = Symbol();
|
|
3938
|
+
const COMPILED_TOKEN_REFERENCE = Symbol();
|
|
3912
3939
|
const COMPILED_STYLE_OBJECT_LOCATIONS = Symbol();
|
|
3913
3940
|
const COMPILED_TOKEN_FACTORY = Symbol();
|
|
3914
3941
|
function evalOk(value) {
|
|
@@ -3931,11 +3958,11 @@ function evaluateNode(node, scope) {
|
|
|
3931
3958
|
case "BooleanLiteral": return evalOk(node.value);
|
|
3932
3959
|
case "NullLiteral": return evalOk(null);
|
|
3933
3960
|
case "TemplateLiteral": return evaluateTemplate(node, scope);
|
|
3934
|
-
case "Identifier": return evaluateIdentifier(node, scope);
|
|
3935
|
-
case "MemberExpression": return evaluateMember(node, scope);
|
|
3961
|
+
case "Identifier": return referenceResult(evaluateIdentifier(node, scope), node, scope);
|
|
3962
|
+
case "MemberExpression": return referenceResult(evaluateMember(node, scope), node, scope);
|
|
3936
3963
|
case "ObjectExpression": return evaluateObject(node, scope);
|
|
3937
3964
|
case "ArrayExpression": return evaluateArray(node, scope);
|
|
3938
|
-
case "CallExpression": return evaluateCall(node, scope);
|
|
3965
|
+
case "CallExpression": return referenceCallResult(evaluateCall(node, scope), node, scope);
|
|
3939
3966
|
case "BinaryExpression": return evaluateBinary(node, scope);
|
|
3940
3967
|
case "UnaryExpression": return evaluateUnary(node, scope);
|
|
3941
3968
|
case "ParenthesizedExpression":
|
|
@@ -4259,7 +4286,7 @@ function evaluateCall(node, scope) {
|
|
|
4259
4286
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "getToken") {
|
|
4260
4287
|
const value = evaluateNode(node.arguments[0], scope);
|
|
4261
4288
|
if (!value.ok) return value;
|
|
4262
|
-
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, CSS_CONFIG.tokenNameFormat || null));
|
|
4289
|
+
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, scope.tokenNameFormat === void 0 ? CSS_CONFIG.tokenNameFormat || null : scope.tokenNameFormat));
|
|
4263
4290
|
return evalOk(value.value);
|
|
4264
4291
|
}
|
|
4265
4292
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
@@ -4297,7 +4324,7 @@ function evaluateCall(node, scope) {
|
|
|
4297
4324
|
if (!provide.ok) return provide;
|
|
4298
4325
|
return evalOk(createCompiledTokenOverride(target, provide.value, node));
|
|
4299
4326
|
}
|
|
4300
|
-
return evalOk(withRuntimeValue(node, target));
|
|
4327
|
+
return referenceResult(evalOk(withRuntimeValue(node, target)), node, scope);
|
|
4301
4328
|
}
|
|
4302
4329
|
}
|
|
4303
4330
|
if (node.callee.type === "MemberExpression") {
|
|
@@ -4315,7 +4342,7 @@ function evaluateCall(node, scope) {
|
|
|
4315
4342
|
if (!stableId.ok) return stableId;
|
|
4316
4343
|
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, frames.value);
|
|
4317
4344
|
const meta = scope.styleMetas?.get(node.callee.object.name);
|
|
4318
|
-
const transformedFrames = transformKeyframes(frames.value, meta?.transform ?? scope.styleTransform ?? null);
|
|
4345
|
+
const transformedFrames = transformKeyframes(frames.value, (meta?.mode === "StyleObject" ? meta.transform : null) ?? scope.styleTransform ?? null);
|
|
4319
4346
|
const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
|
|
4320
4347
|
return evalOk(createCompiledAtRuleRef({
|
|
4321
4348
|
value: formatKeyFramesName(format, stable.id, { name: stable.name }),
|
|
@@ -4371,6 +4398,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4371
4398
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4372
4399
|
[TOKEN_OVERRIDE]: true,
|
|
4373
4400
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4401
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4374
4402
|
value: value.value,
|
|
4375
4403
|
ref: value
|
|
4376
4404
|
});
|
|
@@ -4378,6 +4406,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4378
4406
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4379
4407
|
[TOKEN_OVERRIDE]: true,
|
|
4380
4408
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4409
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4381
4410
|
value,
|
|
4382
4411
|
ref: null
|
|
4383
4412
|
});
|
|
@@ -4436,6 +4465,7 @@ function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stab
|
|
|
4436
4465
|
}
|
|
4437
4466
|
}
|
|
4438
4467
|
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
4468
|
+
if (!values.length) throw new Error("[Style.values] NO_VALUES");
|
|
4439
4469
|
const tokens = /* @__PURE__ */ new Map();
|
|
4440
4470
|
const groupName = getStyleTokenNameFromId(stableId);
|
|
4441
4471
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
@@ -4452,7 +4482,7 @@ function parseCompiledValue(value, isNumber) {
|
|
|
4452
4482
|
value = String(value).split(/[;|]/)[0].trim();
|
|
4453
4483
|
if (!isNumber) return value;
|
|
4454
4484
|
const number = Number(value);
|
|
4455
|
-
if (!Number.isFinite(number))
|
|
4485
|
+
if (!Number.isFinite(number)) throw new Error(`[Style.values] INVALID_NUMBER_VALUE: ${String(value)}`);
|
|
4456
4486
|
return number;
|
|
4457
4487
|
}
|
|
4458
4488
|
function isCompiledTokenFactory(value) {
|
|
@@ -4500,9 +4530,14 @@ function sanitizeTokenDebugName(value) {
|
|
|
4500
4530
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
4501
4531
|
}
|
|
4502
4532
|
function withRuntimeValue(runtimeValue, token) {
|
|
4533
|
+
if (typeof token === "function") return new Proxy(token, { get(target, key) {
|
|
4534
|
+
if (key === COMPILED_RUNTIME_VALUE) return runtimeValue;
|
|
4535
|
+
return Reflect.get(target, key);
|
|
4536
|
+
} });
|
|
4503
4537
|
return Object.assign({}, token, {
|
|
4504
4538
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4505
4539
|
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
4540
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4506
4541
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
4507
4542
|
});
|
|
4508
4543
|
}
|
|
@@ -4533,6 +4568,34 @@ function evaluateUnary(node, scope) {
|
|
|
4533
4568
|
default: return evalFail(`Unsupported unary operator: ${node.operator}`);
|
|
4534
4569
|
}
|
|
4535
4570
|
}
|
|
4571
|
+
function referenceResult(result, expression, scope) {
|
|
4572
|
+
if (!result.ok) return result;
|
|
4573
|
+
return evalOk(referenceValue(result.value, expression, scope));
|
|
4574
|
+
}
|
|
4575
|
+
function referenceValue(value, expression, scope, nested = false) {
|
|
4576
|
+
if (isStyleTokenData(value) || isStyleTokenOverrideData(value)) {
|
|
4577
|
+
if (nested && value[COMPILED_TOKEN_REFERENCE]?.filePath === scope.filePath) return value;
|
|
4578
|
+
const reference = {
|
|
4579
|
+
expression,
|
|
4580
|
+
filePath: scope.filePath
|
|
4581
|
+
};
|
|
4582
|
+
if (typeof value === "function") return new Proxy(value, { get(target, key) {
|
|
4583
|
+
if (key === COMPILED_TOKEN_REFERENCE) return reference;
|
|
4584
|
+
return Reflect.get(target, key);
|
|
4585
|
+
} });
|
|
4586
|
+
return Object.assign(withRuntimeValue(value[COMPILED_RUNTIME_VALUE] ?? expression, value), { [COMPILED_TOKEN_REFERENCE]: reference });
|
|
4587
|
+
}
|
|
4588
|
+
if (!value || typeof value !== "object" || isCompiledTokenFactory(value)) return value;
|
|
4589
|
+
if (Object.getOwnPropertySymbols(value).some((key) => key !== COMPILED_STYLE_OBJECT_LOCATIONS)) return value;
|
|
4590
|
+
const result = Object.defineProperties(Array.isArray(value) ? [] : {}, Object.getOwnPropertyDescriptors(value));
|
|
4591
|
+
for (const key of Object.keys(value)) result[key] = referenceValue(value[key], BabelCore.types.memberExpression(expression, BabelCore.types.stringLiteral(key), true), scope, true);
|
|
4592
|
+
return result;
|
|
4593
|
+
}
|
|
4594
|
+
function referenceCallResult(result, node, scope) {
|
|
4595
|
+
const imp = node.callee.type === "Identifier" ? scope.imports.get(node.callee.name) : void 0;
|
|
4596
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source)) return result;
|
|
4597
|
+
return result.ok && (isStyleTokenData(result.value) || isStyleTokenOverrideData(result.value)) ? referenceResult(result, node, scope) : result;
|
|
4598
|
+
}
|
|
4536
4599
|
//#endregion
|
|
4537
4600
|
//#region compiler/transform/syntax/isStaticStyleValue.ts
|
|
4538
4601
|
function isStaticStyleValue(value) {
|
|
@@ -5748,6 +5811,14 @@ const STATIC_MERGE_METHOD = "$$style.merge";
|
|
|
5748
5811
|
function extractStyleChain(node, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
5749
5812
|
if (node.type !== "CallExpression") return null;
|
|
5750
5813
|
const callee = node.callee;
|
|
5814
|
+
if (callee.type === "CallExpression") {
|
|
5815
|
+
const target = extractStyleChain(callee, styleNames, sheetNames);
|
|
5816
|
+
if (target?.kind !== "selector" || target.baseArgs.length !== 1 || target.methods.length !== 0 || node.arguments.length > 1) return null;
|
|
5817
|
+
return {
|
|
5818
|
+
...target,
|
|
5819
|
+
baseArgs: [...target.baseArgs, ...node.arguments]
|
|
5820
|
+
};
|
|
5821
|
+
}
|
|
5751
5822
|
if (callee.type === "Identifier" && styleNames.has(callee.name)) return {
|
|
5752
5823
|
kind: "style",
|
|
5753
5824
|
rootName: callee.name,
|
|
@@ -5938,7 +6009,7 @@ function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
|
5938
6009
|
const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
|
|
5939
6010
|
if (sheetItems && !compileSheetItemsArg(sheetItems, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return null;
|
|
5940
6011
|
const sheetLayer = sheetOptions.layer ?? isSheetLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer);
|
|
5941
|
-
for (let i = 0, len = rules.length; i < len; i++) rules[i].layer = sheetLayer
|
|
6012
|
+
for (let i = 0, len = rules.length; i < len; i++) rules[i].layer = resolveSheetLayerOption(sheetLayer, options.css?.layerNamespace ?? DEFAULT_CONFIG.layerNamespace ?? "");
|
|
5942
6013
|
return {
|
|
5943
6014
|
type: "sheet",
|
|
5944
6015
|
items,
|
|
@@ -5951,7 +6022,7 @@ function evaluateCreateSheetOptions(node, scope) {
|
|
|
5951
6022
|
if (!result.ok || !result.value || typeof result.value !== "object" || Array.isArray(result.value)) return null;
|
|
5952
6023
|
const value = result.value;
|
|
5953
6024
|
if (Object.keys(value).some((key) => key !== "layer" && key !== "weight")) return null;
|
|
5954
|
-
if (value.layer
|
|
6025
|
+
if (!isSheetLayerOption(value.layer)) return null;
|
|
5955
6026
|
if (value.weight !== void 0 && (!Number.isInteger(value.weight) || value.weight < 1)) return null;
|
|
5956
6027
|
return {
|
|
5957
6028
|
layer: value.layer,
|
|
@@ -7318,12 +7389,15 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7318
7389
|
if (spec.type !== "ExportSpecifier") continue;
|
|
7319
7390
|
const local = spec.local.name;
|
|
7320
7391
|
const exported = spec.exported.type === "Identifier" ? spec.exported.name : spec.exported.value;
|
|
7321
|
-
if (stmt.source)
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7392
|
+
if (stmt.source) {
|
|
7393
|
+
imports.set(exported, {
|
|
7394
|
+
source: stmt.source.value,
|
|
7395
|
+
name: local
|
|
7396
|
+
});
|
|
7397
|
+
rawBindings.set(exported, t.identifier(exported));
|
|
7398
|
+
} else if (rawBindings.has(local)) rawBindings.set(exported, rawBindings.get(local));
|
|
7326
7399
|
else if (bindings.has(local)) bindings.set(exported, bindings.get(local));
|
|
7400
|
+
else if (imports.has(local)) rawBindings.set(exported, t.identifier(local));
|
|
7327
7401
|
}
|
|
7328
7402
|
continue;
|
|
7329
7403
|
}
|
|
@@ -7336,6 +7410,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7336
7410
|
if (stmt.type === "ExportDefaultDeclaration") rawBindings.set("default", stmt.declaration);
|
|
7337
7411
|
}
|
|
7338
7412
|
const scope = {
|
|
7413
|
+
tokenNameFormat: options.css?.tokenNameFormat ?? null,
|
|
7339
7414
|
bindings,
|
|
7340
7415
|
imports,
|
|
7341
7416
|
styleNames,
|
|
@@ -7643,7 +7718,12 @@ function isExtractRuntimeImportSpecifier(spec) {
|
|
|
7643
7718
|
return EXTRACT_RUNTIME_IMPORT_NAMES.has(imported);
|
|
7644
7719
|
}
|
|
7645
7720
|
function isCompilerHandledImport(source, name) {
|
|
7646
|
-
return IMPORT_PATHS.includes(source) &&
|
|
7721
|
+
return IMPORT_PATHS.includes(source) && [
|
|
7722
|
+
"createTheme",
|
|
7723
|
+
"createToken",
|
|
7724
|
+
"createTokens",
|
|
7725
|
+
"createValues"
|
|
7726
|
+
].includes(name);
|
|
7647
7727
|
}
|
|
7648
7728
|
//#endregion
|
|
7649
7729
|
//#region compiler/transform/extract/utils/replacement.ts
|
|
@@ -7670,7 +7750,7 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
7670
7750
|
function buildSheetOptions(t, chain) {
|
|
7671
7751
|
const options = chain.sheetOptions ?? {};
|
|
7672
7752
|
const properties = [];
|
|
7673
|
-
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), t.booleanLiteral(options.layer)));
|
|
7753
|
+
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), typeof options.layer === "string" ? t.stringLiteral(options.layer) : t.booleanLiteral(options.layer)));
|
|
7674
7754
|
if (options.weight !== void 0) properties.push(t.objectProperty(t.identifier("weight"), t.numericLiteral(options.weight)));
|
|
7675
7755
|
return t.objectExpression(properties);
|
|
7676
7756
|
}
|
|
@@ -7782,7 +7862,11 @@ function buildAtRuleRefExpression(t, ref, state) {
|
|
|
7782
7862
|
}
|
|
7783
7863
|
function buildVariableValueExpression(t, value, state, item, options) {
|
|
7784
7864
|
if (isStyleTokenData(value)) {
|
|
7785
|
-
|
|
7865
|
+
const reference = value[COMPILED_TOKEN_REFERENCE];
|
|
7866
|
+
if (reference?.filePath === state.filePath) {
|
|
7867
|
+
const runtimeToken = options.getRuntimeToken?.(item, reference.expression);
|
|
7868
|
+
if (runtimeToken) return runtimeToken;
|
|
7869
|
+
}
|
|
7786
7870
|
return buildExtractedTokenExpression(t, value, state);
|
|
7787
7871
|
}
|
|
7788
7872
|
const valueNode = item.valueNode;
|
|
@@ -7790,7 +7874,9 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
7790
7874
|
if (runtimeToken) return runtimeToken;
|
|
7791
7875
|
return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
|
|
7792
7876
|
}
|
|
7793
|
-
function buildExtractedTokenExpression(t, token, state) {
|
|
7877
|
+
function buildExtractedTokenExpression(t, token, state, preserveReference = true) {
|
|
7878
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
7879
|
+
if (preserveReference && reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7794
7880
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7795
7881
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7796
7882
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7802,6 +7888,8 @@ function buildExtractedTokenExpression(t, token, state) {
|
|
|
7802
7888
|
]);
|
|
7803
7889
|
}
|
|
7804
7890
|
function buildExtractedTokenOverrideExpression(t, token, state) {
|
|
7891
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
7892
|
+
if (reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7805
7893
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7806
7894
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7807
7895
|
const extractedToken = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7818,7 +7906,7 @@ function literalExpression(t, value) {
|
|
|
7818
7906
|
if (typeof value === "number") return t.numericLiteral(value);
|
|
7819
7907
|
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
7820
7908
|
if (value === null || value === void 0) return t.nullLiteral();
|
|
7821
|
-
return t.
|
|
7909
|
+
return t.valueToNode(value);
|
|
7822
7910
|
}
|
|
7823
7911
|
//#endregion
|
|
7824
7912
|
//#region compiler/transform/extract/utils/slot.ts
|
|
@@ -7937,7 +8025,8 @@ function getEvalScope(state) {
|
|
|
7937
8025
|
sheetNames: state.sheetNames,
|
|
7938
8026
|
styleMetas: state.styleMetas,
|
|
7939
8027
|
bindingNodes: state.bindingNodes,
|
|
7940
|
-
runtimeMode: state.runtimeMode
|
|
8028
|
+
runtimeMode: state.runtimeMode,
|
|
8029
|
+
tokenNameFormat: state.options.css?.tokenNameFormat ?? null
|
|
7941
8030
|
};
|
|
7942
8031
|
}
|
|
7943
8032
|
//#endregion
|
|
@@ -7983,6 +8072,62 @@ function compileThemeCall(path, state, opts) {
|
|
|
7983
8072
|
};
|
|
7984
8073
|
}
|
|
7985
8074
|
//#endregion
|
|
8075
|
+
//#region compiler/transform/extract/utils/token.ts
|
|
8076
|
+
function compileTokenFactory(node, state, t) {
|
|
8077
|
+
if (node.callee.type !== "Identifier") return null;
|
|
8078
|
+
const imp = state.imports.get(node.callee.name);
|
|
8079
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source)) return null;
|
|
8080
|
+
if (![
|
|
8081
|
+
"createToken",
|
|
8082
|
+
"createTokens",
|
|
8083
|
+
"createValues"
|
|
8084
|
+
].includes(imp.name)) return null;
|
|
8085
|
+
const inputValue = evaluateNode(node.arguments[0], getEvalScope(state));
|
|
8086
|
+
if (inputValue.ok && hasUnresolvedValue(inputValue.value)) throw new Error(`Cannot extract ${imp.name}: factory inputs must be statically resolvable`);
|
|
8087
|
+
const result = evaluateNode(node, getEvalScope(state));
|
|
8088
|
+
if (!result.ok) throw new Error(`Cannot extract ${imp.name}: ${result.reason}`);
|
|
8089
|
+
if (isCompiledTokenFactory(result.value)) {
|
|
8090
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_VALUES);
|
|
8091
|
+
const expression = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_VALUES), [t.arrayExpression([...result.value.tokens].map(([key, token]) => t.arrayExpression([t.valueToNode(key), buildExtractedTokenExpression(t, token, state, false)])))]);
|
|
8092
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8093
|
+
return expression;
|
|
8094
|
+
}
|
|
8095
|
+
const input = node.arguments[0];
|
|
8096
|
+
if (imp.name === "createToken") return buildGroup(result.value, input);
|
|
8097
|
+
const raw = evaluateNode(input, getEvalScope(state));
|
|
8098
|
+
const array = raw.ok && Array.isArray(raw.value) ? raw.value : null;
|
|
8099
|
+
if (array) return t.objectExpression(Object.entries(result.value).map(([key, token]) => {
|
|
8100
|
+
let index = array.length - 1;
|
|
8101
|
+
while (index >= 0 && String(array[index]) !== key) index--;
|
|
8102
|
+
return t.objectProperty(t.stringLiteral(key), buildGroup(token, member(input, String(index))), key === "__proto__");
|
|
8103
|
+
}));
|
|
8104
|
+
return buildGroup(result.value, input);
|
|
8105
|
+
function buildGroup(value, source) {
|
|
8106
|
+
if (isStyleTokenData(value)) {
|
|
8107
|
+
const expression = buildExtractedTokenExpression(t, value, state, false);
|
|
8108
|
+
if (!value.ref) expression.arguments[1] = t.cloneNode(source, true);
|
|
8109
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8110
|
+
return expression;
|
|
8111
|
+
}
|
|
8112
|
+
if (!value || typeof value !== "object") throw new Error(`Invalid ${imp.name} token group`);
|
|
8113
|
+
return t.objectExpression(Object.entries(value).map(([key, child]) => t.objectProperty(t.stringLiteral(key), buildGroup(child, member(source, key)), key === "__proto__")));
|
|
8114
|
+
}
|
|
8115
|
+
function member(source, key) {
|
|
8116
|
+
if (source.type === "ObjectExpression") for (let index = source.properties.length - 1; index >= 0; index--) {
|
|
8117
|
+
const property = source.properties[index];
|
|
8118
|
+
if (property.type !== "ObjectProperty" || property.computed) break;
|
|
8119
|
+
if (getObjectPropertyKey$1(property) === key) return property.value;
|
|
8120
|
+
}
|
|
8121
|
+
if (source.type === "ArrayExpression" && !source.elements.some((item) => item?.type === "SpreadElement") && source.elements[Number(key)] && t.isExpression(source.elements[Number(key)])) return source.elements[Number(key)];
|
|
8122
|
+
return t.memberExpression(t.cloneNode(source, true), t.stringLiteral(key), true);
|
|
8123
|
+
}
|
|
8124
|
+
}
|
|
8125
|
+
function hasUnresolvedValue(value) {
|
|
8126
|
+
if (!value || typeof value !== "object" || isStyleTokenData(value)) return false;
|
|
8127
|
+
if (value[COMPILED_RUNTIME_VALUE]) return true;
|
|
8128
|
+
return Object.values(value).some(hasUnresolvedValue);
|
|
8129
|
+
}
|
|
8130
|
+
//#endregion
|
|
7986
8131
|
//#region compiler/transform/extract/plugin.ts
|
|
7987
8132
|
function createExtractPlugin(args) {
|
|
7988
8133
|
const { options } = args;
|
|
@@ -7991,6 +8136,7 @@ function createExtractPlugin(args) {
|
|
|
7991
8136
|
const { types: t } = babel;
|
|
7992
8137
|
return {
|
|
7993
8138
|
pre() {
|
|
8139
|
+
this.tokenFactoryReplacements = /* @__PURE__ */ new Map();
|
|
7994
8140
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
7995
8141
|
this.sheetNames = /* @__PURE__ */ new Set();
|
|
7996
8142
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
@@ -8075,6 +8221,12 @@ function createExtractPlugin(args) {
|
|
|
8075
8221
|
state.bindings.set(name, evaluateEnumDeclaration(path.node, scope));
|
|
8076
8222
|
},
|
|
8077
8223
|
CallExpression(path, state) {
|
|
8224
|
+
if (mode === "extract") try {
|
|
8225
|
+
const tokenFactory = compileTokenFactory(path.node, state, t);
|
|
8226
|
+
if (tokenFactory) state.tokenFactoryReplacements.set(path.node, tokenFactory);
|
|
8227
|
+
} catch (error) {
|
|
8228
|
+
throw path.buildCodeFrameError(error instanceof Error ? error.message : String(error));
|
|
8229
|
+
}
|
|
8078
8230
|
if (path.parent.type === "MemberExpression" && !path.parent.computed) return;
|
|
8079
8231
|
const theme = compileThemeCall(path, state, options);
|
|
8080
8232
|
if (theme) {
|
|
@@ -8131,6 +8283,13 @@ function createExtractPlugin(args) {
|
|
|
8131
8283
|
},
|
|
8132
8284
|
Program: { exit(path, state) {
|
|
8133
8285
|
if (mode === "collect") return;
|
|
8286
|
+
path.traverse({ CallExpression(factoryPath) {
|
|
8287
|
+
const replacement = state.tokenFactoryReplacements.get(factoryPath.node);
|
|
8288
|
+
if (!replacement) return;
|
|
8289
|
+
factoryPath.replaceWith(replacement);
|
|
8290
|
+
factoryPath.skip();
|
|
8291
|
+
state.needsExtractImport = true;
|
|
8292
|
+
} });
|
|
8134
8293
|
pruneUnusedStyleInputDeclarations(path, state);
|
|
8135
8294
|
pruneUnusedStyleImports(path, state);
|
|
8136
8295
|
if (!state.needsExtractImport) return;
|
|
@@ -8231,7 +8390,8 @@ function createRuntimeTokenCollector(args) {
|
|
|
8231
8390
|
return {
|
|
8232
8391
|
overrides,
|
|
8233
8392
|
addOverride(item) {
|
|
8234
|
-
|
|
8393
|
+
const reference = item.value[COMPILED_TOKEN_REFERENCE];
|
|
8394
|
+
overrides.push(args.t.cloneNode(reference?.filePath === args.state.filePath ? reference.expression : item.valueNode, true));
|
|
8235
8395
|
},
|
|
8236
8396
|
add(item, valueNode) {
|
|
8237
8397
|
if (canHoistRuntimeValue(args.path, valueNode)) return null;
|
|
@@ -8545,4 +8705,4 @@ const CssPropPresets = {
|
|
|
8545
8705
|
//#endregion
|
|
8546
8706
|
export { getDefaultSourcemapUrl as a, getStyleFnMeta as c, babelTransform as d, extractCss as f, createCompilerCache as g, globalData as h, CompilerRuntimeMode as i, isPromiseLike as l, SIDECAR_URL_GLOBAL_SYMBOL as m, createCompiler as n, normalizeSourcemapSourcePath as o, compareLayerPriority as p, getStyleRuntimeImportPath as r, normalizePath as s, CssPropPresets as t, babelPlugin as u };
|
|
8547
8707
|
|
|
8548
|
-
//# sourceMappingURL=compiler-
|
|
8708
|
+
//# sourceMappingURL=compiler-Ct5xGIeu.mjs.map
|