@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
|
@@ -69,6 +69,13 @@ const CSS_CONFIG = globalData("config.css", () => ({ ...CSS_CONFIG_DEFAULT }));
|
|
|
69
69
|
function isStyleLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
70
70
|
return typeof layer === "boolean" ? layer : layer.style ?? true;
|
|
71
71
|
}
|
|
72
|
+
function isSheetLayerOption(value) {
|
|
73
|
+
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);
|
|
74
|
+
}
|
|
75
|
+
function resolveSheetLayerOption(layer, namespace) {
|
|
76
|
+
if (typeof layer !== "string") return layer ? "sheet" : false;
|
|
77
|
+
return { name: layer.startsWith(".") ? namespace ? namespace + layer : layer.slice(1) : layer };
|
|
78
|
+
}
|
|
72
79
|
function isSheetLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
73
80
|
return typeof layer === "object" && (layer.sheet ?? false);
|
|
74
81
|
}
|
|
@@ -119,7 +126,7 @@ function compareLayerPriority(p1, p2) {
|
|
|
119
126
|
}
|
|
120
127
|
function flattenCssLayers(layers, layerNames) {
|
|
121
128
|
const names = typeof layerNames === "string" ? [layerNames] : layerNames;
|
|
122
|
-
return layers.flatMap((layer) => layer === "$layer" ? names : layer).filter(Boolean);
|
|
129
|
+
return [...new Set(layers.flatMap((layer) => layer === "$layer" ? names.filter((name) => !layers.includes(name)) : layer).filter(Boolean))];
|
|
123
130
|
}
|
|
124
131
|
const LayerDefaultPriority = [
|
|
125
132
|
0,
|
|
@@ -206,6 +213,7 @@ const FN_CREATE_EXTRACTED_SHEET = "createExtractedSheet";
|
|
|
206
213
|
const FN_CREATE_EXTRACTED_SLOT = "createExtractedSlot";
|
|
207
214
|
const FN_CREATE_EXTRACTED_SCOPE = "createExtractedScope";
|
|
208
215
|
const FN_CREATE_EXTRACTED_TOKEN = "createExtractedToken";
|
|
216
|
+
const FN_CREATE_EXTRACTED_VALUES = "createExtractedValues";
|
|
209
217
|
const FN_CREATE_EXTRACTED_THEME = "createExtractedTheme";
|
|
210
218
|
const FN_CREATE_EXTRACTED_STYLE_MERGE = "createExtractedStyleMerge";
|
|
211
219
|
const FN_WITH_TOKENS = "withTokens";
|
|
@@ -221,8 +229,9 @@ function getExtractedCssItems(items, args) {
|
|
|
221
229
|
const seen = /* @__PURE__ */ new Set();
|
|
222
230
|
const css = [];
|
|
223
231
|
for (const item of sortedItems) {
|
|
224
|
-
|
|
225
|
-
seen.
|
|
232
|
+
const key = JSON.stringify([item.layer, item.css]);
|
|
233
|
+
if (seen.has(key)) continue;
|
|
234
|
+
seen.add(key);
|
|
226
235
|
css.push(item);
|
|
227
236
|
}
|
|
228
237
|
if (!css.length) return "";
|
|
@@ -232,21 +241,25 @@ function getExtractedCssItems(items, args) {
|
|
|
232
241
|
const styleLayer = isStyleLayerEnabled(args.layer ?? defaults.layer);
|
|
233
242
|
const sheetLayerName = layerNamespace ? layerNamespace + ".sheet" : "sheet";
|
|
234
243
|
const styleItems = [];
|
|
235
|
-
const sheetItems =
|
|
244
|
+
const sheetItems = /* @__PURE__ */ new Map();
|
|
236
245
|
const unlayeredItems = [];
|
|
237
246
|
for (let i = 0, len = css.length; i < len; i++) {
|
|
238
247
|
const item = css[i];
|
|
239
|
-
if (item.layer === "sheet"
|
|
240
|
-
|
|
248
|
+
if (item.layer === "sheet" || typeof item.layer === "object") {
|
|
249
|
+
const name = typeof item.layer === "object" ? item.layer.name : sheetLayerName;
|
|
250
|
+
const rules = sheetItems.get(name) ?? [];
|
|
251
|
+
rules.push(item.css);
|
|
252
|
+
sheetItems.set(name, rules);
|
|
253
|
+
} else if (item.layer === false || !styleLayer) unlayeredItems.push(item.css);
|
|
241
254
|
else styleItems.push(item.css);
|
|
242
255
|
}
|
|
243
|
-
const styleLayerName = sheetItems.
|
|
244
|
-
const layerNames = [styleItems.length ? styleLayerName : "", sheetItems.
|
|
256
|
+
const styleLayerName = [...sheetItems.keys()].some((name) => name.startsWith(layerNamespace + ".")) && layerNamespace ? layerNamespace + ".style" : layerNamespace;
|
|
257
|
+
const layerNames = [styleItems.length ? styleLayerName : "", ...sheetItems.keys()].filter(Boolean);
|
|
245
258
|
const output = [];
|
|
246
259
|
const layerOrder = getLayerOrderCss(layers, layerNames);
|
|
247
260
|
if (layerOrder) output.push(layerOrder);
|
|
248
261
|
if (styleItems.length) output.push(getLayerBlockCss(styleLayerName, "\n" + styleItems.join("\n") + "\n"));
|
|
249
|
-
|
|
262
|
+
for (const [name, rules] of sheetItems) output.push(getLayerBlockCss(name, "\n" + rules.join("\n") + "\n"));
|
|
250
263
|
output.push(...unlayeredItems);
|
|
251
264
|
return output.join("\n");
|
|
252
265
|
}
|
|
@@ -836,6 +849,9 @@ function getStyleTokenId(token) {
|
|
|
836
849
|
function getStyleTokenName(token) {
|
|
837
850
|
return token[TOKEN_NAME] ?? null;
|
|
838
851
|
}
|
|
852
|
+
function getStyleTokenVarName(token) {
|
|
853
|
+
return token[TOKEN_VAR_NAME] ?? null;
|
|
854
|
+
}
|
|
839
855
|
//#endregion
|
|
840
856
|
//#region builder/token/name.ts
|
|
841
857
|
function getStyleTokenNameFromId(id) {
|
|
@@ -895,12 +911,14 @@ function createStyleTokenOverride(token, value, debug) {
|
|
|
895
911
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
896
912
|
[TOKEN_OVERRIDE]: true,
|
|
897
913
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
914
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
898
915
|
value: value.value,
|
|
899
916
|
ref: value
|
|
900
917
|
} : {
|
|
901
918
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
902
919
|
[TOKEN_OVERRIDE]: true,
|
|
903
920
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
921
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
904
922
|
value,
|
|
905
923
|
ref: null
|
|
906
924
|
};
|
|
@@ -1734,6 +1752,8 @@ function escapeCssValue(value) {
|
|
|
1734
1752
|
}
|
|
1735
1753
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1736
1754
|
function getTokenVarName(token, format) {
|
|
1755
|
+
const explicitName = getStyleTokenVarName(token);
|
|
1756
|
+
if (explicitName) return explicitName;
|
|
1737
1757
|
const id = getStyleTokenId(token);
|
|
1738
1758
|
const debugName = getStyleTokenName(token);
|
|
1739
1759
|
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
@@ -2116,7 +2136,7 @@ function assertManualSelectorSyntax(selector) {
|
|
|
2116
2136
|
function setSheetSelectorOptions(selector, options) {
|
|
2117
2137
|
if (options.weight === void 0 && options.layer === void 0) return selector;
|
|
2118
2138
|
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
2119
|
-
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.weight ?? "") + ":" + (options.layer === void 0 ? "" : options.layer ? "1" : "0")) + "\0" + text.slice(6);
|
|
2139
|
+
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);
|
|
2120
2140
|
return Array.isArray(selector) ? [weighted, selector[1]] : weighted;
|
|
2121
2141
|
}
|
|
2122
2142
|
function normalizeManualSelector(selector, assertManualSelector) {
|
|
@@ -3984,8 +4004,9 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
3984
4004
|
//#region dialect/namedTokens.ts
|
|
3985
4005
|
const ROOT = Symbol("fluentic.namedTokens.root");
|
|
3986
4006
|
function createNamedToken(id, value) {
|
|
3987
|
-
const
|
|
3988
|
-
token
|
|
4007
|
+
const tokenId = createNamedTokenId(id);
|
|
4008
|
+
const token = createStyleToken(value, tokenId);
|
|
4009
|
+
token[TOKEN_VAR_NAME] = "--token-" + tokenId;
|
|
3989
4010
|
return token;
|
|
3990
4011
|
}
|
|
3991
4012
|
function createNamedTokens(namespace, values) {
|
|
@@ -3997,7 +4018,10 @@ function createNamedTokens(namespace, values) {
|
|
|
3997
4018
|
}, []);
|
|
3998
4019
|
}
|
|
3999
4020
|
function createNamedTokenId(id) {
|
|
4000
|
-
return
|
|
4021
|
+
return id.split(".").map(encodeNamedTokenSegment).join("-");
|
|
4022
|
+
}
|
|
4023
|
+
function encodeNamedTokenSegment(segment) {
|
|
4024
|
+
return segment.replace(/[^a-zA-Z0-9]/gu, (char) => "_x" + char.codePointAt(0).toString(16) + "_");
|
|
4001
4025
|
}
|
|
4002
4026
|
function createNamedTokenProxy(root, path) {
|
|
4003
4027
|
return new Proxy(noop, {
|
|
@@ -4019,11 +4043,13 @@ function createNamedTokenProxy(root, path) {
|
|
|
4019
4043
|
});
|
|
4020
4044
|
}
|
|
4021
4045
|
function getNamedTokenAtPath(root, path) {
|
|
4022
|
-
const key =
|
|
4046
|
+
const key = JSON.stringify(path);
|
|
4023
4047
|
const cached = root.cache.get(key);
|
|
4024
4048
|
if (cached) return cached;
|
|
4025
4049
|
const value = getValueAtPath(root.values, path);
|
|
4026
|
-
const
|
|
4050
|
+
const id = root.namespace.split(".").concat(path).map(encodeNamedTokenSegment).join("-");
|
|
4051
|
+
const token = createStyleToken(value, id);
|
|
4052
|
+
token[TOKEN_VAR_NAME] = "--token-" + id;
|
|
4027
4053
|
root.cache.set(key, token);
|
|
4028
4054
|
return token;
|
|
4029
4055
|
}
|
|
@@ -4060,6 +4086,7 @@ function exposeStyleValue(value) {
|
|
|
4060
4086
|
//#region compiler/transform/evaluator/evaluator.ts
|
|
4061
4087
|
const STYLE_IMPORT_PATHS = new Set(IMPORT_PATHS);
|
|
4062
4088
|
const COMPILED_RUNTIME_VALUE = Symbol();
|
|
4089
|
+
const COMPILED_TOKEN_REFERENCE = Symbol();
|
|
4063
4090
|
const COMPILED_STYLE_OBJECT_LOCATIONS = Symbol();
|
|
4064
4091
|
const COMPILED_TOKEN_FACTORY = Symbol();
|
|
4065
4092
|
function evalOk(value) {
|
|
@@ -4082,11 +4109,11 @@ function evaluateNode(node, scope) {
|
|
|
4082
4109
|
case "BooleanLiteral": return evalOk(node.value);
|
|
4083
4110
|
case "NullLiteral": return evalOk(null);
|
|
4084
4111
|
case "TemplateLiteral": return evaluateTemplate(node, scope);
|
|
4085
|
-
case "Identifier": return evaluateIdentifier(node, scope);
|
|
4086
|
-
case "MemberExpression": return evaluateMember(node, scope);
|
|
4112
|
+
case "Identifier": return referenceResult(evaluateIdentifier(node, scope), node, scope);
|
|
4113
|
+
case "MemberExpression": return referenceResult(evaluateMember(node, scope), node, scope);
|
|
4087
4114
|
case "ObjectExpression": return evaluateObject(node, scope);
|
|
4088
4115
|
case "ArrayExpression": return evaluateArray(node, scope);
|
|
4089
|
-
case "CallExpression": return evaluateCall(node, scope);
|
|
4116
|
+
case "CallExpression": return referenceCallResult(evaluateCall(node, scope), node, scope);
|
|
4090
4117
|
case "BinaryExpression": return evaluateBinary(node, scope);
|
|
4091
4118
|
case "UnaryExpression": return evaluateUnary(node, scope);
|
|
4092
4119
|
case "ParenthesizedExpression":
|
|
@@ -4410,7 +4437,7 @@ function evaluateCall(node, scope) {
|
|
|
4410
4437
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "getToken") {
|
|
4411
4438
|
const value = evaluateNode(node.arguments[0], scope);
|
|
4412
4439
|
if (!value.ok) return value;
|
|
4413
|
-
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, CSS_CONFIG.tokenNameFormat || null));
|
|
4440
|
+
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, scope.tokenNameFormat === void 0 ? CSS_CONFIG.tokenNameFormat || null : scope.tokenNameFormat));
|
|
4414
4441
|
return evalOk(value.value);
|
|
4415
4442
|
}
|
|
4416
4443
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
@@ -4448,7 +4475,7 @@ function evaluateCall(node, scope) {
|
|
|
4448
4475
|
if (!provide.ok) return provide;
|
|
4449
4476
|
return evalOk(createCompiledTokenOverride(target, provide.value, node));
|
|
4450
4477
|
}
|
|
4451
|
-
return evalOk(withRuntimeValue(node, target));
|
|
4478
|
+
return referenceResult(evalOk(withRuntimeValue(node, target)), node, scope);
|
|
4452
4479
|
}
|
|
4453
4480
|
}
|
|
4454
4481
|
if (node.callee.type === "MemberExpression") {
|
|
@@ -4466,7 +4493,7 @@ function evaluateCall(node, scope) {
|
|
|
4466
4493
|
if (!stableId.ok) return stableId;
|
|
4467
4494
|
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, frames.value);
|
|
4468
4495
|
const meta = scope.styleMetas?.get(node.callee.object.name);
|
|
4469
|
-
const transformedFrames = transformKeyframes(frames.value, meta?.transform ?? scope.styleTransform ?? null);
|
|
4496
|
+
const transformedFrames = transformKeyframes(frames.value, (meta?.mode === "StyleObject" ? meta.transform : null) ?? scope.styleTransform ?? null);
|
|
4470
4497
|
const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
|
|
4471
4498
|
return evalOk(createCompiledAtRuleRef({
|
|
4472
4499
|
value: formatKeyFramesName(format, stable.id, { name: stable.name }),
|
|
@@ -4522,6 +4549,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4522
4549
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4523
4550
|
[TOKEN_OVERRIDE]: true,
|
|
4524
4551
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4552
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4525
4553
|
value: value.value,
|
|
4526
4554
|
ref: value
|
|
4527
4555
|
});
|
|
@@ -4529,6 +4557,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4529
4557
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4530
4558
|
[TOKEN_OVERRIDE]: true,
|
|
4531
4559
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4560
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4532
4561
|
value,
|
|
4533
4562
|
ref: null
|
|
4534
4563
|
});
|
|
@@ -4587,6 +4616,7 @@ function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stab
|
|
|
4587
4616
|
}
|
|
4588
4617
|
}
|
|
4589
4618
|
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
4619
|
+
if (!values.length) throw new Error("[Style.values] NO_VALUES");
|
|
4590
4620
|
const tokens = /* @__PURE__ */ new Map();
|
|
4591
4621
|
const groupName = getStyleTokenNameFromId(stableId);
|
|
4592
4622
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
@@ -4603,7 +4633,7 @@ function parseCompiledValue(value, isNumber) {
|
|
|
4603
4633
|
value = String(value).split(/[;|]/)[0].trim();
|
|
4604
4634
|
if (!isNumber) return value;
|
|
4605
4635
|
const number = Number(value);
|
|
4606
|
-
if (!Number.isFinite(number))
|
|
4636
|
+
if (!Number.isFinite(number)) throw new Error(`[Style.values] INVALID_NUMBER_VALUE: ${String(value)}`);
|
|
4607
4637
|
return number;
|
|
4608
4638
|
}
|
|
4609
4639
|
function isCompiledTokenFactory(value) {
|
|
@@ -4651,9 +4681,14 @@ function sanitizeTokenDebugName(value) {
|
|
|
4651
4681
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
4652
4682
|
}
|
|
4653
4683
|
function withRuntimeValue(runtimeValue, token) {
|
|
4684
|
+
if (typeof token === "function") return new Proxy(token, { get(target, key) {
|
|
4685
|
+
if (key === COMPILED_RUNTIME_VALUE) return runtimeValue;
|
|
4686
|
+
return Reflect.get(target, key);
|
|
4687
|
+
} });
|
|
4654
4688
|
return Object.assign({}, token, {
|
|
4655
4689
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4656
4690
|
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
4691
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4657
4692
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
4658
4693
|
});
|
|
4659
4694
|
}
|
|
@@ -4684,6 +4719,34 @@ function evaluateUnary(node, scope) {
|
|
|
4684
4719
|
default: return evalFail(`Unsupported unary operator: ${node.operator}`);
|
|
4685
4720
|
}
|
|
4686
4721
|
}
|
|
4722
|
+
function referenceResult(result, expression, scope) {
|
|
4723
|
+
if (!result.ok) return result;
|
|
4724
|
+
return evalOk(referenceValue(result.value, expression, scope));
|
|
4725
|
+
}
|
|
4726
|
+
function referenceValue(value, expression, scope, nested = false) {
|
|
4727
|
+
if (isStyleTokenData(value) || isStyleTokenOverrideData(value)) {
|
|
4728
|
+
if (nested && value[COMPILED_TOKEN_REFERENCE]?.filePath === scope.filePath) return value;
|
|
4729
|
+
const reference = {
|
|
4730
|
+
expression,
|
|
4731
|
+
filePath: scope.filePath
|
|
4732
|
+
};
|
|
4733
|
+
if (typeof value === "function") return new Proxy(value, { get(target, key) {
|
|
4734
|
+
if (key === COMPILED_TOKEN_REFERENCE) return reference;
|
|
4735
|
+
return Reflect.get(target, key);
|
|
4736
|
+
} });
|
|
4737
|
+
return Object.assign(withRuntimeValue(value[COMPILED_RUNTIME_VALUE] ?? expression, value), { [COMPILED_TOKEN_REFERENCE]: reference });
|
|
4738
|
+
}
|
|
4739
|
+
if (!value || typeof value !== "object" || isCompiledTokenFactory(value)) return value;
|
|
4740
|
+
if (Object.getOwnPropertySymbols(value).some((key) => key !== COMPILED_STYLE_OBJECT_LOCATIONS)) return value;
|
|
4741
|
+
const result = Object.defineProperties(Array.isArray(value) ? [] : {}, Object.getOwnPropertyDescriptors(value));
|
|
4742
|
+
for (const key of Object.keys(value)) result[key] = referenceValue(value[key], _babel_core.types.memberExpression(expression, _babel_core.types.stringLiteral(key), true), scope, true);
|
|
4743
|
+
return result;
|
|
4744
|
+
}
|
|
4745
|
+
function referenceCallResult(result, node, scope) {
|
|
4746
|
+
const imp = node.callee.type === "Identifier" ? scope.imports.get(node.callee.name) : void 0;
|
|
4747
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source)) return result;
|
|
4748
|
+
return result.ok && (isStyleTokenData(result.value) || isStyleTokenOverrideData(result.value)) ? referenceResult(result, node, scope) : result;
|
|
4749
|
+
}
|
|
4687
4750
|
//#endregion
|
|
4688
4751
|
//#region compiler/transform/syntax/isStaticStyleValue.ts
|
|
4689
4752
|
function isStaticStyleValue(value) {
|
|
@@ -5862,6 +5925,14 @@ const STATIC_MERGE_METHOD = "$$style.merge";
|
|
|
5862
5925
|
function extractStyleChain(node, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
5863
5926
|
if (node.type !== "CallExpression") return null;
|
|
5864
5927
|
const callee = node.callee;
|
|
5928
|
+
if (callee.type === "CallExpression") {
|
|
5929
|
+
const target = extractStyleChain(callee, styleNames, sheetNames);
|
|
5930
|
+
if (target?.kind !== "selector" || target.baseArgs.length !== 1 || target.methods.length !== 0 || node.arguments.length > 1) return null;
|
|
5931
|
+
return {
|
|
5932
|
+
...target,
|
|
5933
|
+
baseArgs: [...target.baseArgs, ...node.arguments]
|
|
5934
|
+
};
|
|
5935
|
+
}
|
|
5865
5936
|
if (callee.type === "Identifier" && styleNames.has(callee.name)) return {
|
|
5866
5937
|
kind: "style",
|
|
5867
5938
|
rootName: callee.name,
|
|
@@ -6052,7 +6123,7 @@ function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
|
6052
6123
|
const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
|
|
6053
6124
|
if (sheetItems && !compileSheetItemsArg(sheetItems, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return null;
|
|
6054
6125
|
const sheetLayer = sheetOptions.layer ?? isSheetLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer);
|
|
6055
|
-
for (let i = 0, len = rules.length; i < len; i++) rules[i].layer = sheetLayer
|
|
6126
|
+
for (let i = 0, len = rules.length; i < len; i++) rules[i].layer = resolveSheetLayerOption(sheetLayer, options.css?.layerNamespace ?? DEFAULT_CONFIG.layerNamespace ?? "");
|
|
6056
6127
|
return {
|
|
6057
6128
|
type: "sheet",
|
|
6058
6129
|
items,
|
|
@@ -6065,7 +6136,7 @@ function evaluateCreateSheetOptions(node, scope) {
|
|
|
6065
6136
|
if (!result.ok || !result.value || typeof result.value !== "object" || Array.isArray(result.value)) return null;
|
|
6066
6137
|
const value = result.value;
|
|
6067
6138
|
if (Object.keys(value).some((key) => key !== "layer" && key !== "weight")) return null;
|
|
6068
|
-
if (value.layer
|
|
6139
|
+
if (!isSheetLayerOption(value.layer)) return null;
|
|
6069
6140
|
if (value.weight !== void 0 && (!Number.isInteger(value.weight) || value.weight < 1)) return null;
|
|
6070
6141
|
return {
|
|
6071
6142
|
layer: value.layer,
|
|
@@ -7432,12 +7503,15 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7432
7503
|
if (spec.type !== "ExportSpecifier") continue;
|
|
7433
7504
|
const local = spec.local.name;
|
|
7434
7505
|
const exported = spec.exported.type === "Identifier" ? spec.exported.name : spec.exported.value;
|
|
7435
|
-
if (stmt.source)
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7506
|
+
if (stmt.source) {
|
|
7507
|
+
imports.set(exported, {
|
|
7508
|
+
source: stmt.source.value,
|
|
7509
|
+
name: local
|
|
7510
|
+
});
|
|
7511
|
+
rawBindings.set(exported, t.identifier(exported));
|
|
7512
|
+
} else if (rawBindings.has(local)) rawBindings.set(exported, rawBindings.get(local));
|
|
7440
7513
|
else if (bindings.has(local)) bindings.set(exported, bindings.get(local));
|
|
7514
|
+
else if (imports.has(local)) rawBindings.set(exported, t.identifier(local));
|
|
7441
7515
|
}
|
|
7442
7516
|
continue;
|
|
7443
7517
|
}
|
|
@@ -7450,6 +7524,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7450
7524
|
if (stmt.type === "ExportDefaultDeclaration") rawBindings.set("default", stmt.declaration);
|
|
7451
7525
|
}
|
|
7452
7526
|
const scope = {
|
|
7527
|
+
tokenNameFormat: options.css?.tokenNameFormat ?? null,
|
|
7453
7528
|
bindings,
|
|
7454
7529
|
imports,
|
|
7455
7530
|
styleNames,
|
|
@@ -7757,7 +7832,12 @@ function isExtractRuntimeImportSpecifier(spec) {
|
|
|
7757
7832
|
return EXTRACT_RUNTIME_IMPORT_NAMES.has(imported);
|
|
7758
7833
|
}
|
|
7759
7834
|
function isCompilerHandledImport(source, name) {
|
|
7760
|
-
return IMPORT_PATHS.includes(source) &&
|
|
7835
|
+
return IMPORT_PATHS.includes(source) && [
|
|
7836
|
+
"createTheme",
|
|
7837
|
+
"createToken",
|
|
7838
|
+
"createTokens",
|
|
7839
|
+
"createValues"
|
|
7840
|
+
].includes(name);
|
|
7761
7841
|
}
|
|
7762
7842
|
//#endregion
|
|
7763
7843
|
//#region compiler/transform/extract/utils/replacement.ts
|
|
@@ -7784,7 +7864,7 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
7784
7864
|
function buildSheetOptions(t, chain) {
|
|
7785
7865
|
const options = chain.sheetOptions ?? {};
|
|
7786
7866
|
const properties = [];
|
|
7787
|
-
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), t.booleanLiteral(options.layer)));
|
|
7867
|
+
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), typeof options.layer === "string" ? t.stringLiteral(options.layer) : t.booleanLiteral(options.layer)));
|
|
7788
7868
|
if (options.weight !== void 0) properties.push(t.objectProperty(t.identifier("weight"), t.numericLiteral(options.weight)));
|
|
7789
7869
|
return t.objectExpression(properties);
|
|
7790
7870
|
}
|
|
@@ -7896,7 +7976,11 @@ function buildAtRuleRefExpression(t, ref, state) {
|
|
|
7896
7976
|
}
|
|
7897
7977
|
function buildVariableValueExpression(t, value, state, item, options) {
|
|
7898
7978
|
if (isStyleTokenData(value)) {
|
|
7899
|
-
|
|
7979
|
+
const reference = value[COMPILED_TOKEN_REFERENCE];
|
|
7980
|
+
if (reference?.filePath === state.filePath) {
|
|
7981
|
+
const runtimeToken = options.getRuntimeToken?.(item, reference.expression);
|
|
7982
|
+
if (runtimeToken) return runtimeToken;
|
|
7983
|
+
}
|
|
7900
7984
|
return buildExtractedTokenExpression(t, value, state);
|
|
7901
7985
|
}
|
|
7902
7986
|
const valueNode = item.valueNode;
|
|
@@ -7904,7 +7988,9 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
7904
7988
|
if (runtimeToken) return runtimeToken;
|
|
7905
7989
|
return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
|
|
7906
7990
|
}
|
|
7907
|
-
function buildExtractedTokenExpression(t, token, state) {
|
|
7991
|
+
function buildExtractedTokenExpression(t, token, state, preserveReference = true) {
|
|
7992
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
7993
|
+
if (preserveReference && reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7908
7994
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7909
7995
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7910
7996
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7916,6 +8002,8 @@ function buildExtractedTokenExpression(t, token, state) {
|
|
|
7916
8002
|
]);
|
|
7917
8003
|
}
|
|
7918
8004
|
function buildExtractedTokenOverrideExpression(t, token, state) {
|
|
8005
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
8006
|
+
if (reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7919
8007
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7920
8008
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7921
8009
|
const extractedToken = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7932,7 +8020,7 @@ function literalExpression(t, value) {
|
|
|
7932
8020
|
if (typeof value === "number") return t.numericLiteral(value);
|
|
7933
8021
|
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
7934
8022
|
if (value === null || value === void 0) return t.nullLiteral();
|
|
7935
|
-
return t.
|
|
8023
|
+
return t.valueToNode(value);
|
|
7936
8024
|
}
|
|
7937
8025
|
//#endregion
|
|
7938
8026
|
//#region compiler/transform/extract/utils/slot.ts
|
|
@@ -8051,7 +8139,8 @@ function getEvalScope(state) {
|
|
|
8051
8139
|
sheetNames: state.sheetNames,
|
|
8052
8140
|
styleMetas: state.styleMetas,
|
|
8053
8141
|
bindingNodes: state.bindingNodes,
|
|
8054
|
-
runtimeMode: state.runtimeMode
|
|
8142
|
+
runtimeMode: state.runtimeMode,
|
|
8143
|
+
tokenNameFormat: state.options.css?.tokenNameFormat ?? null
|
|
8055
8144
|
};
|
|
8056
8145
|
}
|
|
8057
8146
|
//#endregion
|
|
@@ -8097,6 +8186,62 @@ function compileThemeCall(path, state, opts) {
|
|
|
8097
8186
|
};
|
|
8098
8187
|
}
|
|
8099
8188
|
//#endregion
|
|
8189
|
+
//#region compiler/transform/extract/utils/token.ts
|
|
8190
|
+
function compileTokenFactory(node, state, t) {
|
|
8191
|
+
if (node.callee.type !== "Identifier") return null;
|
|
8192
|
+
const imp = state.imports.get(node.callee.name);
|
|
8193
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source)) return null;
|
|
8194
|
+
if (![
|
|
8195
|
+
"createToken",
|
|
8196
|
+
"createTokens",
|
|
8197
|
+
"createValues"
|
|
8198
|
+
].includes(imp.name)) return null;
|
|
8199
|
+
const inputValue = evaluateNode(node.arguments[0], getEvalScope(state));
|
|
8200
|
+
if (inputValue.ok && hasUnresolvedValue(inputValue.value)) throw new Error(`Cannot extract ${imp.name}: factory inputs must be statically resolvable`);
|
|
8201
|
+
const result = evaluateNode(node, getEvalScope(state));
|
|
8202
|
+
if (!result.ok) throw new Error(`Cannot extract ${imp.name}: ${result.reason}`);
|
|
8203
|
+
if (isCompiledTokenFactory(result.value)) {
|
|
8204
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_VALUES);
|
|
8205
|
+
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)])))]);
|
|
8206
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8207
|
+
return expression;
|
|
8208
|
+
}
|
|
8209
|
+
const input = node.arguments[0];
|
|
8210
|
+
if (imp.name === "createToken") return buildGroup(result.value, input);
|
|
8211
|
+
const raw = evaluateNode(input, getEvalScope(state));
|
|
8212
|
+
const array = raw.ok && Array.isArray(raw.value) ? raw.value : null;
|
|
8213
|
+
if (array) return t.objectExpression(Object.entries(result.value).map(([key, token]) => {
|
|
8214
|
+
let index = array.length - 1;
|
|
8215
|
+
while (index >= 0 && String(array[index]) !== key) index--;
|
|
8216
|
+
return t.objectProperty(t.stringLiteral(key), buildGroup(token, member(input, String(index))), key === "__proto__");
|
|
8217
|
+
}));
|
|
8218
|
+
return buildGroup(result.value, input);
|
|
8219
|
+
function buildGroup(value, source) {
|
|
8220
|
+
if (isStyleTokenData(value)) {
|
|
8221
|
+
const expression = buildExtractedTokenExpression(t, value, state, false);
|
|
8222
|
+
if (!value.ref) expression.arguments[1] = t.cloneNode(source, true);
|
|
8223
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8224
|
+
return expression;
|
|
8225
|
+
}
|
|
8226
|
+
if (!value || typeof value !== "object") throw new Error(`Invalid ${imp.name} token group`);
|
|
8227
|
+
return t.objectExpression(Object.entries(value).map(([key, child]) => t.objectProperty(t.stringLiteral(key), buildGroup(child, member(source, key)), key === "__proto__")));
|
|
8228
|
+
}
|
|
8229
|
+
function member(source, key) {
|
|
8230
|
+
if (source.type === "ObjectExpression") for (let index = source.properties.length - 1; index >= 0; index--) {
|
|
8231
|
+
const property = source.properties[index];
|
|
8232
|
+
if (property.type !== "ObjectProperty" || property.computed) break;
|
|
8233
|
+
if (getObjectPropertyKey$1(property) === key) return property.value;
|
|
8234
|
+
}
|
|
8235
|
+
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)];
|
|
8236
|
+
return t.memberExpression(t.cloneNode(source, true), t.stringLiteral(key), true);
|
|
8237
|
+
}
|
|
8238
|
+
}
|
|
8239
|
+
function hasUnresolvedValue(value) {
|
|
8240
|
+
if (!value || typeof value !== "object" || isStyleTokenData(value)) return false;
|
|
8241
|
+
if (value[COMPILED_RUNTIME_VALUE]) return true;
|
|
8242
|
+
return Object.values(value).some(hasUnresolvedValue);
|
|
8243
|
+
}
|
|
8244
|
+
//#endregion
|
|
8100
8245
|
//#region compiler/transform/extract/plugin.ts
|
|
8101
8246
|
function createExtractPlugin(args) {
|
|
8102
8247
|
const { options } = args;
|
|
@@ -8105,6 +8250,7 @@ function createExtractPlugin(args) {
|
|
|
8105
8250
|
const { types: t } = babel;
|
|
8106
8251
|
return {
|
|
8107
8252
|
pre() {
|
|
8253
|
+
this.tokenFactoryReplacements = /* @__PURE__ */ new Map();
|
|
8108
8254
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
8109
8255
|
this.sheetNames = /* @__PURE__ */ new Set();
|
|
8110
8256
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
@@ -8189,6 +8335,12 @@ function createExtractPlugin(args) {
|
|
|
8189
8335
|
state.bindings.set(name, evaluateEnumDeclaration(path.node, scope));
|
|
8190
8336
|
},
|
|
8191
8337
|
CallExpression(path, state) {
|
|
8338
|
+
if (mode === "extract") try {
|
|
8339
|
+
const tokenFactory = compileTokenFactory(path.node, state, t);
|
|
8340
|
+
if (tokenFactory) state.tokenFactoryReplacements.set(path.node, tokenFactory);
|
|
8341
|
+
} catch (error) {
|
|
8342
|
+
throw path.buildCodeFrameError(error instanceof Error ? error.message : String(error));
|
|
8343
|
+
}
|
|
8192
8344
|
if (path.parent.type === "MemberExpression" && !path.parent.computed) return;
|
|
8193
8345
|
const theme = compileThemeCall(path, state, options);
|
|
8194
8346
|
if (theme) {
|
|
@@ -8245,6 +8397,13 @@ function createExtractPlugin(args) {
|
|
|
8245
8397
|
},
|
|
8246
8398
|
Program: { exit(path, state) {
|
|
8247
8399
|
if (mode === "collect") return;
|
|
8400
|
+
path.traverse({ CallExpression(factoryPath) {
|
|
8401
|
+
const replacement = state.tokenFactoryReplacements.get(factoryPath.node);
|
|
8402
|
+
if (!replacement) return;
|
|
8403
|
+
factoryPath.replaceWith(replacement);
|
|
8404
|
+
factoryPath.skip();
|
|
8405
|
+
state.needsExtractImport = true;
|
|
8406
|
+
} });
|
|
8248
8407
|
pruneUnusedStyleInputDeclarations(path, state);
|
|
8249
8408
|
pruneUnusedStyleImports(path, state);
|
|
8250
8409
|
if (!state.needsExtractImport) return;
|
|
@@ -8345,7 +8504,8 @@ function createRuntimeTokenCollector(args) {
|
|
|
8345
8504
|
return {
|
|
8346
8505
|
overrides,
|
|
8347
8506
|
addOverride(item) {
|
|
8348
|
-
|
|
8507
|
+
const reference = item.value[COMPILED_TOKEN_REFERENCE];
|
|
8508
|
+
overrides.push(args.t.cloneNode(reference?.filePath === args.state.filePath ? reference.expression : item.valueNode, true));
|
|
8349
8509
|
},
|
|
8350
8510
|
add(item, valueNode) {
|
|
8351
8511
|
if (canHoistRuntimeValue(args.path, valueNode)) return null;
|
|
@@ -9350,4 +9510,4 @@ Object.defineProperty(exports, "writeParcelVirtualRuntimeFile", {
|
|
|
9350
9510
|
}
|
|
9351
9511
|
});
|
|
9352
9512
|
|
|
9353
|
-
//# sourceMappingURL=shared-
|
|
9513
|
+
//# sourceMappingURL=shared-C9XQd8p_.cjs.map
|