@fluentic/style 0.1.0-beta.13 → 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 +10 -0
- package/README.md +3 -2
- package/atomic/token.ts +10 -1
- package/builder/extract/token.ts +10 -0
- package/compiler/transform/evaluator/evaluator.ts +83 -9
- package/compiler/transform/evaluator/tracer.ts +4 -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 +15 -3
- 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/dialect/namedTokens.ts +13 -8
- package/dist/{combine-yuoQ_qpx.js → combine-CC9bY-hu.js} +2 -2
- package/dist/{combine-yuoQ_qpx.js.map → combine-CC9bY-hu.js.map} +1 -1
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-BEHxZYjz.mjs → compiler-Ct5xGIeu.mjs} +164 -24
- package/dist/compiler-Ct5xGIeu.mjs.map +1 -0
- package/dist/config/index.js +2 -2
- package/dist/{config-DggQEE-4.js → config-BiiMS4rU.js} +3 -3
- package/dist/{config-DggQEE-4.js.map → config-BiiMS4rU.js.map} +1 -1
- package/dist/{config-B5nEd-TV.js → config-CCgsVvyR.js} +2 -2
- package/dist/{config-B5nEd-TV.js.map → config-CCgsVvyR.js.map} +1 -1
- package/dist/{config-BWGBkVrM.js → config-DZKR6gH1.js} +4 -4
- package/dist/{config-BWGBkVrM.js.map → config-DZKR6gH1.js.map} +1 -1
- package/dist/{config-Bqe8Y-4_.js → config-TyjNpRrV.js} +2 -2
- package/dist/{config-Bqe8Y-4_.js.map → config-TyjNpRrV.js.map} +1 -1
- package/dist/{createTransformElement-B2jSnugo.js → createTransformElement-BGznW-Mu.js} +2 -2
- package/dist/{createTransformElement-B2jSnugo.js.map → createTransformElement-BGznW-Mu.js.map} +1 -1
- package/dist/{css-CGMAis1n.js → css-BhoclXaw.js} +5 -5
- package/dist/{css-CGMAis1n.js.map → css-BhoclXaw.js.map} +1 -1
- package/dist/{css-p_5ZNny_.js → css-IecKRNxs.js} +11 -11
- package/dist/{css-p_5ZNny_.js.map → css-IecKRNxs.js.map} +1 -1
- package/dist/{css-BQRIvzwZ.js → css-WaHZ6gxv.js} +6 -2
- package/dist/css-WaHZ6gxv.js.map +1 -0
- package/dist/css.js +1 -1
- package/dist/{css_extra-DuVzUIYx.js → css_extra-DDeJc2Cu.js} +2 -2
- package/dist/{css_extra-DuVzUIYx.js.map → css_extra-DDeJc2Cu.js.map} +1 -1
- package/dist/{data-QXDBLlWs.js → data-BgZmL55Y.js} +7 -8
- package/dist/{data-QXDBLlWs.js.map → data-BgZmL55Y.js.map} +1 -1
- package/dist/{debug-CkgcZDaX.js → debug-D-1hhd0G.js} +27 -3
- package/dist/debug-D-1hhd0G.js.map +1 -0
- package/dist/dev/rsc.js +6 -6
- package/dist/{dev-DocaGP3_.js → dev-CBRbVaeq.js} +6 -7
- package/dist/{dev-DocaGP3_.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-DZjd1NuA.js → elementMarker-CJcfpKL1.js} +5 -6
- package/dist/{elementMarker-DZjd1NuA.js.map → elementMarker-CJcfpKL1.js.map} +1 -1
- 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 +5 -5
- 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-DJyXPJ9q.js → env-C8TRVSyb.js} +5 -1
- package/dist/env-C8TRVSyb.js.map +1 -0
- package/dist/getClassName-9CsXbNls.js.map +1 -1
- package/dist/{getClassName-BB_L7U_v.js → getClassName-BNe3Ycyy.js} +4 -5
- package/dist/{getClassName-BB_L7U_v.js.map → getClassName-BNe3Ycyy.js.map} +1 -1
- package/dist/{getClassName-BIqt1S41.js → getClassName-CeoxISNW.js} +4 -4
- package/dist/{getClassName-BIqt1S41.js.map → getClassName-CeoxISNW.js.map} +1 -1
- package/dist/getClassName-DtkplEIt.js.map +1 -1
- package/dist/{global-CBQGormL.js → global-CWYOol4o.js} +2 -2
- package/dist/{global-CBQGormL.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-0iaVEC7z.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-BCufpzdb.js → jsx-8TwYuvgM.js} +4 -4
- package/dist/{jsx-BCufpzdb.js.map → jsx-8TwYuvgM.js.map} +1 -1
- package/dist/{jsx_runtime-Bu_A8mr4.js → jsx_runtime-CPojW0KD.js} +2 -2
- package/dist/{jsx_runtime-Bu_A8mr4.js.map → jsx_runtime-CPojW0KD.js.map} +1 -1
- package/dist/{loader-vMHuD1zT.mjs → loader-BVebGteg.mjs} +3 -3
- package/dist/{loader-vMHuD1zT.mjs.map → loader-BVebGteg.mjs.map} +1 -1
- package/dist/{misc-9EGKYkZo.mjs → misc-Bs2DgdG7.mjs} +2 -2
- package/dist/{misc-9EGKYkZo.mjs.map → misc-Bs2DgdG7.mjs.map} +1 -1
- package/dist/{namedTokens-DnpyC5XT.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-DVB7n6V-.mjs → registry-D1n78rd7.mjs} +2 -2
- package/dist/{registry-DVB7n6V-.mjs.map → registry-D1n78rd7.mjs.map} +1 -1
- package/dist/{resolveClassNameRuntime-DvH6j_4N.js → resolveClassNameRuntime-BJcykzdl.js} +2 -2
- package/dist/{resolveClassNameRuntime-DvH6j_4N.js.map → resolveClassNameRuntime-BJcykzdl.js.map} +1 -1
- package/dist/{rules-znG9bsKI.js → rules-Dz-szpPu.js} +7 -8
- package/dist/{rules-znG9bsKI.js.map → rules-Dz-szpPu.js.map} +1 -1
- package/dist/server.js +13 -13
- package/dist/{shared-DaEDCb8I.cjs → shared-C9XQd8p_.cjs} +164 -24
- package/dist/shared-C9XQd8p_.cjs.map +1 -0
- package/dist/{shared-O-5Fcsxa.mjs → shared-D4-AKGn6.mjs} +4 -4
- package/dist/{shared-O-5Fcsxa.mjs.map → shared-D4-AKGn6.mjs.map} +1 -1
- package/dist/sheet-LU89fcH_.js +7 -0
- package/dist/{sheet-SlZRjOmw.js.map → sheet-LU89fcH_.js.map} +1 -1
- package/dist/{sidecar-DiYLwXbk.mjs → sidecar-CZTYX2vA.mjs} +3 -3
- package/dist/{sidecar-DiYLwXbk.mjs.map → sidecar-CZTYX2vA.mjs.map} +1 -1
- package/dist/{style-CtXEZqgx.js → style-CmXHCPF4.js} +10 -11
- package/dist/{style-CtXEZqgx.js.map → style-CmXHCPF4.js.map} +1 -1
- package/dist/{styleStore-CBan0gHQ.js → styleStore-B0x4Ahpx.js} +5 -5
- package/dist/{styleStore-CBan0gHQ.js.map → styleStore-B0x4Ahpx.js.map} +1 -1
- package/dist/{styleStore-BImBZdt6.js → styleStore-BrpgLNgc.js} +2 -2
- package/dist/{styleStore-BImBZdt6.js.map → styleStore-BrpgLNgc.js.map} +1 -1
- package/dist/{token-DyLO6Hnf.js → token-DMrBbat8.js} +5 -33
- package/dist/token-DMrBbat8.js.map +1 -0
- package/dist/{trace-C1_6fM21.js → trace-C7EzEj2Q.js} +3 -3
- package/dist/{trace-C1_6fM21.js.map → trace-C7EzEj2Q.js.map} +1 -1
- package/dist/{trace-Bsh-Kkg_.js → trace-DzCntvK4.js} +2 -2
- package/dist/{trace-Bsh-Kkg_.js.map → trace-DzCntvK4.js.map} +1 -1
- package/dist/{transform-8TIMiF5A.js → transform-CSZMklMb.js} +2 -2
- package/dist/{transform-8TIMiF5A.js.map → transform-CSZMklMb.js.map} +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/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/transform/utils/selector.d.ts +1 -1
- package/dist/types/compiler/utils/constants.d.ts +1 -0
- package/dist/types/compiler/utils/import_source.d.ts +8 -2
- 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/style/style.d.ts +93 -93
- package/dist/{utils-DoKJnvxk.js → utils-B7QcJ-Yw.js} +3 -3
- package/dist/{utils-DoKJnvxk.js.map → utils-B7QcJ-Yw.js.map} +1 -1
- package/dist/{utils-Bjh9pO87.mjs → utils-BYpkJ-uE.mjs} +3 -3
- package/dist/{utils-Bjh9pO87.mjs.map → utils-BYpkJ-uE.mjs.map} +1 -1
- package/dist/{utils-BBN9msTv.mjs → utils-CoMwEfhG.mjs} +4 -4
- package/dist/{utils-BBN9msTv.mjs.map → utils-CoMwEfhG.mjs.map} +1 -1
- package/dist/{utils-10MTZOuB.js → utils-D4KMqCu2.js} +7 -2
- package/dist/utils-D4KMqCu2.js.map +1 -0
- package/dist/utils.js +3 -3
- package/dist/{value-Dg6ALjjj.js → value-yd2SZ1XQ.js} +37 -3
- package/dist/value-yd2SZ1XQ.js.map +1 -0
- package/dist/{webpack-C1j49Psk.mjs → webpack-B6z1UHh9.mjs} +5 -5
- package/dist/{webpack-C1j49Psk.mjs.map → webpack-B6z1UHh9.mjs.map} +1 -1
- package/package.json +5 -4
- package/runtime/extract/getClassName.ts +1 -1
- package/style/token.ts +2 -0
- package/dist/compiler-BEHxZYjz.mjs.map +0 -1
- package/dist/css-BQRIvzwZ.js.map +0 -1
- package/dist/css-D7eTqvMH.js +0 -57
- package/dist/css-D7eTqvMH.js.map +0 -1
- package/dist/debug-0iaVEC7z.js.map +0 -1
- package/dist/debug-CkgcZDaX.js.map +0 -1
- package/dist/env-DJyXPJ9q.js.map +0 -1
- package/dist/hash-Cr-LCWDt.js +0 -166
- package/dist/hash-Cr-LCWDt.js.map +0 -1
- package/dist/namedTokens-DnpyC5XT.js.map +0 -1
- package/dist/shared-DaEDCb8I.cjs.map +0 -1
- package/dist/sheet-SlZRjOmw.js +0 -7
- package/dist/token-DyLO6Hnf.js.map +0 -1
- package/dist/utils-10MTZOuB.js.map +0 -1
- package/dist/value-Dg6ALjjj.js.map +0 -1
|
@@ -213,6 +213,7 @@ const FN_CREATE_EXTRACTED_SHEET = "createExtractedSheet";
|
|
|
213
213
|
const FN_CREATE_EXTRACTED_SLOT = "createExtractedSlot";
|
|
214
214
|
const FN_CREATE_EXTRACTED_SCOPE = "createExtractedScope";
|
|
215
215
|
const FN_CREATE_EXTRACTED_TOKEN = "createExtractedToken";
|
|
216
|
+
const FN_CREATE_EXTRACTED_VALUES = "createExtractedValues";
|
|
216
217
|
const FN_CREATE_EXTRACTED_THEME = "createExtractedTheme";
|
|
217
218
|
const FN_CREATE_EXTRACTED_STYLE_MERGE = "createExtractedStyleMerge";
|
|
218
219
|
const FN_WITH_TOKENS = "withTokens";
|
|
@@ -848,6 +849,9 @@ function getStyleTokenId(token) {
|
|
|
848
849
|
function getStyleTokenName(token) {
|
|
849
850
|
return token[TOKEN_NAME] ?? null;
|
|
850
851
|
}
|
|
852
|
+
function getStyleTokenVarName(token) {
|
|
853
|
+
return token[TOKEN_VAR_NAME] ?? null;
|
|
854
|
+
}
|
|
851
855
|
//#endregion
|
|
852
856
|
//#region builder/token/name.ts
|
|
853
857
|
function getStyleTokenNameFromId(id) {
|
|
@@ -907,12 +911,14 @@ function createStyleTokenOverride(token, value, debug) {
|
|
|
907
911
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
908
912
|
[TOKEN_OVERRIDE]: true,
|
|
909
913
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
914
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
910
915
|
value: value.value,
|
|
911
916
|
ref: value
|
|
912
917
|
} : {
|
|
913
918
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
914
919
|
[TOKEN_OVERRIDE]: true,
|
|
915
920
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
921
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
916
922
|
value,
|
|
917
923
|
ref: null
|
|
918
924
|
};
|
|
@@ -1746,6 +1752,8 @@ function escapeCssValue(value) {
|
|
|
1746
1752
|
}
|
|
1747
1753
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1748
1754
|
function getTokenVarName(token, format) {
|
|
1755
|
+
const explicitName = getStyleTokenVarName(token);
|
|
1756
|
+
if (explicitName) return explicitName;
|
|
1749
1757
|
const id = getStyleTokenId(token);
|
|
1750
1758
|
const debugName = getStyleTokenName(token);
|
|
1751
1759
|
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
@@ -3996,8 +4004,9 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
3996
4004
|
//#region dialect/namedTokens.ts
|
|
3997
4005
|
const ROOT = Symbol("fluentic.namedTokens.root");
|
|
3998
4006
|
function createNamedToken(id, value) {
|
|
3999
|
-
const
|
|
4000
|
-
token
|
|
4007
|
+
const tokenId = createNamedTokenId(id);
|
|
4008
|
+
const token = createStyleToken(value, tokenId);
|
|
4009
|
+
token[TOKEN_VAR_NAME] = "--token-" + tokenId;
|
|
4001
4010
|
return token;
|
|
4002
4011
|
}
|
|
4003
4012
|
function createNamedTokens(namespace, values) {
|
|
@@ -4009,7 +4018,10 @@ function createNamedTokens(namespace, values) {
|
|
|
4009
4018
|
}, []);
|
|
4010
4019
|
}
|
|
4011
4020
|
function createNamedTokenId(id) {
|
|
4012
|
-
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) + "_");
|
|
4013
4025
|
}
|
|
4014
4026
|
function createNamedTokenProxy(root, path) {
|
|
4015
4027
|
return new Proxy(noop, {
|
|
@@ -4031,11 +4043,13 @@ function createNamedTokenProxy(root, path) {
|
|
|
4031
4043
|
});
|
|
4032
4044
|
}
|
|
4033
4045
|
function getNamedTokenAtPath(root, path) {
|
|
4034
|
-
const key =
|
|
4046
|
+
const key = JSON.stringify(path);
|
|
4035
4047
|
const cached = root.cache.get(key);
|
|
4036
4048
|
if (cached) return cached;
|
|
4037
4049
|
const value = getValueAtPath(root.values, path);
|
|
4038
|
-
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;
|
|
4039
4053
|
root.cache.set(key, token);
|
|
4040
4054
|
return token;
|
|
4041
4055
|
}
|
|
@@ -4072,6 +4086,7 @@ function exposeStyleValue(value) {
|
|
|
4072
4086
|
//#region compiler/transform/evaluator/evaluator.ts
|
|
4073
4087
|
const STYLE_IMPORT_PATHS = new Set(IMPORT_PATHS);
|
|
4074
4088
|
const COMPILED_RUNTIME_VALUE = Symbol();
|
|
4089
|
+
const COMPILED_TOKEN_REFERENCE = Symbol();
|
|
4075
4090
|
const COMPILED_STYLE_OBJECT_LOCATIONS = Symbol();
|
|
4076
4091
|
const COMPILED_TOKEN_FACTORY = Symbol();
|
|
4077
4092
|
function evalOk(value) {
|
|
@@ -4094,11 +4109,11 @@ function evaluateNode(node, scope) {
|
|
|
4094
4109
|
case "BooleanLiteral": return evalOk(node.value);
|
|
4095
4110
|
case "NullLiteral": return evalOk(null);
|
|
4096
4111
|
case "TemplateLiteral": return evaluateTemplate(node, scope);
|
|
4097
|
-
case "Identifier": return evaluateIdentifier(node, scope);
|
|
4098
|
-
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);
|
|
4099
4114
|
case "ObjectExpression": return evaluateObject(node, scope);
|
|
4100
4115
|
case "ArrayExpression": return evaluateArray(node, scope);
|
|
4101
|
-
case "CallExpression": return evaluateCall(node, scope);
|
|
4116
|
+
case "CallExpression": return referenceCallResult(evaluateCall(node, scope), node, scope);
|
|
4102
4117
|
case "BinaryExpression": return evaluateBinary(node, scope);
|
|
4103
4118
|
case "UnaryExpression": return evaluateUnary(node, scope);
|
|
4104
4119
|
case "ParenthesizedExpression":
|
|
@@ -4422,7 +4437,7 @@ function evaluateCall(node, scope) {
|
|
|
4422
4437
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "getToken") {
|
|
4423
4438
|
const value = evaluateNode(node.arguments[0], scope);
|
|
4424
4439
|
if (!value.ok) return value;
|
|
4425
|
-
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));
|
|
4426
4441
|
return evalOk(value.value);
|
|
4427
4442
|
}
|
|
4428
4443
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
@@ -4460,7 +4475,7 @@ function evaluateCall(node, scope) {
|
|
|
4460
4475
|
if (!provide.ok) return provide;
|
|
4461
4476
|
return evalOk(createCompiledTokenOverride(target, provide.value, node));
|
|
4462
4477
|
}
|
|
4463
|
-
return evalOk(withRuntimeValue(node, target));
|
|
4478
|
+
return referenceResult(evalOk(withRuntimeValue(node, target)), node, scope);
|
|
4464
4479
|
}
|
|
4465
4480
|
}
|
|
4466
4481
|
if (node.callee.type === "MemberExpression") {
|
|
@@ -4478,7 +4493,7 @@ function evaluateCall(node, scope) {
|
|
|
4478
4493
|
if (!stableId.ok) return stableId;
|
|
4479
4494
|
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, frames.value);
|
|
4480
4495
|
const meta = scope.styleMetas?.get(node.callee.object.name);
|
|
4481
|
-
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);
|
|
4482
4497
|
const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
|
|
4483
4498
|
return evalOk(createCompiledAtRuleRef({
|
|
4484
4499
|
value: formatKeyFramesName(format, stable.id, { name: stable.name }),
|
|
@@ -4534,6 +4549,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4534
4549
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4535
4550
|
[TOKEN_OVERRIDE]: true,
|
|
4536
4551
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4552
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4537
4553
|
value: value.value,
|
|
4538
4554
|
ref: value
|
|
4539
4555
|
});
|
|
@@ -4541,6 +4557,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4541
4557
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4542
4558
|
[TOKEN_OVERRIDE]: true,
|
|
4543
4559
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4560
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4544
4561
|
value,
|
|
4545
4562
|
ref: null
|
|
4546
4563
|
});
|
|
@@ -4599,6 +4616,7 @@ function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stab
|
|
|
4599
4616
|
}
|
|
4600
4617
|
}
|
|
4601
4618
|
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
4619
|
+
if (!values.length) throw new Error("[Style.values] NO_VALUES");
|
|
4602
4620
|
const tokens = /* @__PURE__ */ new Map();
|
|
4603
4621
|
const groupName = getStyleTokenNameFromId(stableId);
|
|
4604
4622
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
@@ -4615,7 +4633,7 @@ function parseCompiledValue(value, isNumber) {
|
|
|
4615
4633
|
value = String(value).split(/[;|]/)[0].trim();
|
|
4616
4634
|
if (!isNumber) return value;
|
|
4617
4635
|
const number = Number(value);
|
|
4618
|
-
if (!Number.isFinite(number))
|
|
4636
|
+
if (!Number.isFinite(number)) throw new Error(`[Style.values] INVALID_NUMBER_VALUE: ${String(value)}`);
|
|
4619
4637
|
return number;
|
|
4620
4638
|
}
|
|
4621
4639
|
function isCompiledTokenFactory(value) {
|
|
@@ -4663,9 +4681,14 @@ function sanitizeTokenDebugName(value) {
|
|
|
4663
4681
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
4664
4682
|
}
|
|
4665
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
|
+
} });
|
|
4666
4688
|
return Object.assign({}, token, {
|
|
4667
4689
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4668
4690
|
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
4691
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4669
4692
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
4670
4693
|
});
|
|
4671
4694
|
}
|
|
@@ -4696,6 +4719,34 @@ function evaluateUnary(node, scope) {
|
|
|
4696
4719
|
default: return evalFail(`Unsupported unary operator: ${node.operator}`);
|
|
4697
4720
|
}
|
|
4698
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
|
+
}
|
|
4699
4750
|
//#endregion
|
|
4700
4751
|
//#region compiler/transform/syntax/isStaticStyleValue.ts
|
|
4701
4752
|
function isStaticStyleValue(value) {
|
|
@@ -7452,12 +7503,15 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7452
7503
|
if (spec.type !== "ExportSpecifier") continue;
|
|
7453
7504
|
const local = spec.local.name;
|
|
7454
7505
|
const exported = spec.exported.type === "Identifier" ? spec.exported.name : spec.exported.value;
|
|
7455
|
-
if (stmt.source)
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
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));
|
|
7460
7513
|
else if (bindings.has(local)) bindings.set(exported, bindings.get(local));
|
|
7514
|
+
else if (imports.has(local)) rawBindings.set(exported, t.identifier(local));
|
|
7461
7515
|
}
|
|
7462
7516
|
continue;
|
|
7463
7517
|
}
|
|
@@ -7470,6 +7524,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7470
7524
|
if (stmt.type === "ExportDefaultDeclaration") rawBindings.set("default", stmt.declaration);
|
|
7471
7525
|
}
|
|
7472
7526
|
const scope = {
|
|
7527
|
+
tokenNameFormat: options.css?.tokenNameFormat ?? null,
|
|
7473
7528
|
bindings,
|
|
7474
7529
|
imports,
|
|
7475
7530
|
styleNames,
|
|
@@ -7777,7 +7832,12 @@ function isExtractRuntimeImportSpecifier(spec) {
|
|
|
7777
7832
|
return EXTRACT_RUNTIME_IMPORT_NAMES.has(imported);
|
|
7778
7833
|
}
|
|
7779
7834
|
function isCompilerHandledImport(source, name) {
|
|
7780
|
-
return IMPORT_PATHS.includes(source) &&
|
|
7835
|
+
return IMPORT_PATHS.includes(source) && [
|
|
7836
|
+
"createTheme",
|
|
7837
|
+
"createToken",
|
|
7838
|
+
"createTokens",
|
|
7839
|
+
"createValues"
|
|
7840
|
+
].includes(name);
|
|
7781
7841
|
}
|
|
7782
7842
|
//#endregion
|
|
7783
7843
|
//#region compiler/transform/extract/utils/replacement.ts
|
|
@@ -7916,7 +7976,11 @@ function buildAtRuleRefExpression(t, ref, state) {
|
|
|
7916
7976
|
}
|
|
7917
7977
|
function buildVariableValueExpression(t, value, state, item, options) {
|
|
7918
7978
|
if (isStyleTokenData(value)) {
|
|
7919
|
-
|
|
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
|
+
}
|
|
7920
7984
|
return buildExtractedTokenExpression(t, value, state);
|
|
7921
7985
|
}
|
|
7922
7986
|
const valueNode = item.valueNode;
|
|
@@ -7924,7 +7988,9 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
7924
7988
|
if (runtimeToken) return runtimeToken;
|
|
7925
7989
|
return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
|
|
7926
7990
|
}
|
|
7927
|
-
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);
|
|
7928
7994
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7929
7995
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7930
7996
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7936,6 +8002,8 @@ function buildExtractedTokenExpression(t, token, state) {
|
|
|
7936
8002
|
]);
|
|
7937
8003
|
}
|
|
7938
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);
|
|
7939
8007
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7940
8008
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7941
8009
|
const extractedToken = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7952,7 +8020,7 @@ function literalExpression(t, value) {
|
|
|
7952
8020
|
if (typeof value === "number") return t.numericLiteral(value);
|
|
7953
8021
|
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
7954
8022
|
if (value === null || value === void 0) return t.nullLiteral();
|
|
7955
|
-
return t.
|
|
8023
|
+
return t.valueToNode(value);
|
|
7956
8024
|
}
|
|
7957
8025
|
//#endregion
|
|
7958
8026
|
//#region compiler/transform/extract/utils/slot.ts
|
|
@@ -8071,7 +8139,8 @@ function getEvalScope(state) {
|
|
|
8071
8139
|
sheetNames: state.sheetNames,
|
|
8072
8140
|
styleMetas: state.styleMetas,
|
|
8073
8141
|
bindingNodes: state.bindingNodes,
|
|
8074
|
-
runtimeMode: state.runtimeMode
|
|
8142
|
+
runtimeMode: state.runtimeMode,
|
|
8143
|
+
tokenNameFormat: state.options.css?.tokenNameFormat ?? null
|
|
8075
8144
|
};
|
|
8076
8145
|
}
|
|
8077
8146
|
//#endregion
|
|
@@ -8117,6 +8186,62 @@ function compileThemeCall(path, state, opts) {
|
|
|
8117
8186
|
};
|
|
8118
8187
|
}
|
|
8119
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
|
|
8120
8245
|
//#region compiler/transform/extract/plugin.ts
|
|
8121
8246
|
function createExtractPlugin(args) {
|
|
8122
8247
|
const { options } = args;
|
|
@@ -8125,6 +8250,7 @@ function createExtractPlugin(args) {
|
|
|
8125
8250
|
const { types: t } = babel;
|
|
8126
8251
|
return {
|
|
8127
8252
|
pre() {
|
|
8253
|
+
this.tokenFactoryReplacements = /* @__PURE__ */ new Map();
|
|
8128
8254
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
8129
8255
|
this.sheetNames = /* @__PURE__ */ new Set();
|
|
8130
8256
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
@@ -8209,6 +8335,12 @@ function createExtractPlugin(args) {
|
|
|
8209
8335
|
state.bindings.set(name, evaluateEnumDeclaration(path.node, scope));
|
|
8210
8336
|
},
|
|
8211
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
|
+
}
|
|
8212
8344
|
if (path.parent.type === "MemberExpression" && !path.parent.computed) return;
|
|
8213
8345
|
const theme = compileThemeCall(path, state, options);
|
|
8214
8346
|
if (theme) {
|
|
@@ -8265,6 +8397,13 @@ function createExtractPlugin(args) {
|
|
|
8265
8397
|
},
|
|
8266
8398
|
Program: { exit(path, state) {
|
|
8267
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
|
+
} });
|
|
8268
8407
|
pruneUnusedStyleInputDeclarations(path, state);
|
|
8269
8408
|
pruneUnusedStyleImports(path, state);
|
|
8270
8409
|
if (!state.needsExtractImport) return;
|
|
@@ -8365,7 +8504,8 @@ function createRuntimeTokenCollector(args) {
|
|
|
8365
8504
|
return {
|
|
8366
8505
|
overrides,
|
|
8367
8506
|
addOverride(item) {
|
|
8368
|
-
|
|
8507
|
+
const reference = item.value[COMPILED_TOKEN_REFERENCE];
|
|
8508
|
+
overrides.push(args.t.cloneNode(reference?.filePath === args.state.filePath ? reference.expression : item.valueNode, true));
|
|
8369
8509
|
},
|
|
8370
8510
|
add(item, valueNode) {
|
|
8371
8511
|
if (canHoistRuntimeValue(args.path, valueNode)) return null;
|
|
@@ -9370,4 +9510,4 @@ Object.defineProperty(exports, "writeParcelVirtualRuntimeFile", {
|
|
|
9370
9510
|
}
|
|
9371
9511
|
});
|
|
9372
9512
|
|
|
9373
|
-
//# sourceMappingURL=shared-
|
|
9513
|
+
//# sourceMappingURL=shared-C9XQd8p_.cjs.map
|