@fluentic/style 0.1.0-beta.14 → 0.1.0-beta.15
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 +12 -0
- package/atomic/className.ts +4 -0
- package/atomic/rule.ts +15 -7
- package/atomic/utils/selector.ts +12 -3
- package/builder/classname/class_name_builder.ts +1 -1
- package/builder/data/const.ts +2 -0
- package/builder/data/data.ts +1 -1
- package/builder/data/merge/scope.ts +7 -0
- package/builder/data/merge/style.ts +12 -3
- package/builder/data/state.ts +1 -0
- package/builder/selector_override.ts +1 -1
- package/builder/selector_override_core.ts +17 -3
- package/builder/types/alias.ts +1 -1
- package/compiler/extract/extract.ts +21 -75
- package/compiler/extract/types.ts +4 -1
- package/compiler/transform/debug/plugin.ts +22 -0
- package/compiler/transform/evaluator/evaluator.ts +4 -1
- package/compiler/transform/extract/chain/chain.ts +82 -22
- package/compiler/transform/extract/chain/extract_chain.ts +2 -0
- package/compiler/transform/extract/plugin.ts +51 -25
- package/compiler/transform/extract/utils/imports.ts +4 -1
- package/compiler/transform/extract/utils/replacement.ts +2 -2
- package/compiler/transform/utils/babel.ts +1 -1
- package/compiler/utils/constants.ts +1 -0
- package/config/config/css.ts +5 -3
- package/config/configure.ts +4 -0
- package/config/document.ts +23 -0
- package/css/globalSheet.ts +66 -0
- package/css/index.ts +4 -1
- package/css/sheet.ts +34 -14
- package/dist/{className-yhJCGT0F.js → className-CC5PHcXI.js} +9 -2
- package/dist/className-CC5PHcXI.js.map +1 -0
- package/dist/{combine-CC9bY-hu.js → combine-BpOQWCtM.js} +5 -5
- package/dist/combine-BpOQWCtM.js.map +1 -0
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-Ct5xGIeu.mjs → compiler-AOb_VaKQ.mjs} +464 -166
- package/dist/compiler-AOb_VaKQ.mjs.map +1 -0
- package/dist/config/index.js +2 -2
- package/dist/{config-CCgsVvyR.js → config-B70LIQhi.js} +2 -2
- package/dist/{config-CCgsVvyR.js.map → config-B70LIQhi.js.map} +1 -1
- package/dist/{config-DZKR6gH1.js → config-BF-mxuPk.js} +4 -4
- package/dist/{config-DZKR6gH1.js.map → config-BF-mxuPk.js.map} +1 -1
- package/dist/{config-BiiMS4rU.js → config-B_OQYZSm.js} +25 -4
- package/dist/config-B_OQYZSm.js.map +1 -0
- package/dist/{css-WaHZ6gxv.js → css-C7tcD3IO.js} +611 -213
- package/dist/css-C7tcD3IO.js.map +1 -0
- package/dist/css-Cdxkur4h.js +414 -0
- package/dist/css-Cdxkur4h.js.map +1 -0
- package/dist/{css-IecKRNxs.js → css-RohOR3Vq.js} +112 -73
- package/dist/css-RohOR3Vq.js.map +1 -0
- package/dist/css.js +2 -2
- package/dist/css_extra-BC1Z_hDy.js +8 -0
- package/dist/{css_extra-DDeJc2Cu.js.map → css_extra-BC1Z_hDy.js.map} +1 -1
- package/dist/{css_extra-DDeJc2Cu.js → css_extra-CuzJtAR_.js} +2 -2
- package/dist/css_extra-CuzJtAR_.js.map +1 -0
- package/dist/{data-BgZmL55Y.js → data-Bw3Xod5J.js} +28 -19
- package/dist/data-Bw3Xod5J.js.map +1 -0
- package/dist/{debug-D-1hhd0G.js → debug-CVO3xx4C.js} +6 -9
- package/dist/debug-CVO3xx4C.js.map +1 -0
- package/dist/dev/rsc.js +134 -25
- package/dist/dev/rsc.js.map +1 -1
- package/dist/{dev-CBRbVaeq.js → dev-BnQXPLQB.js} +6 -6
- package/dist/{dev-CBRbVaeq.js.map → dev-BnQXPLQB.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-CJcfpKL1.js → elementMarker-BrHXg161.js} +334 -53
- package/dist/elementMarker-BrHXg161.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 +3 -3
- 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/adapter/preact.js +1 -1
- package/dist/entry/prod/adapter/react.js +1 -1
- package/dist/entry/prod/adapter/solid.js +1 -1
- package/dist/entry/prod/css.js +3 -3
- package/dist/entry/prod/extract.js.map +1 -1
- package/dist/entry/prod.js +3 -3
- 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 +4 -3
- package/dist/entry/rsc-dev/dev.js +129 -24
- package/dist/entry/rsc-dev/dev.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +5 -4
- package/dist/entry/rsc-dev/jsx-dev-runtime.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +8 -7
- package/dist/entry/rsc-dev.js.map +1 -1
- package/dist/entry/rsc-prod/css.js +4 -4
- package/dist/entry/rsc-prod.js +4 -4
- package/dist/{rules-Dz-szpPu.js → env-D6daex-9.js} +64 -19
- package/dist/env-D6daex-9.js.map +1 -0
- package/dist/{getClassName-DtkplEIt.js → getClassName-5yYUibKw.js} +2 -2
- package/dist/{getClassName-DtkplEIt.js.map → getClassName-5yYUibKw.js.map} +1 -1
- package/dist/getClassName-9CsXbNls.js.map +1 -1
- package/dist/{getClassName-CeoxISNW.js → getClassName-B3azD1TO.js} +6 -4
- package/dist/getClassName-B3azD1TO.js.map +1 -0
- package/dist/{getClassName-BNe3Ycyy.js → getClassName-m5DOkMFQ.js} +4 -4
- package/dist/{getClassName-BNe3Ycyy.js.map → getClassName-m5DOkMFQ.js.map} +1 -1
- package/dist/{global-UOHFwqHN.js → global-DeIYtcdl.js} +5 -2
- package/dist/{global-UOHFwqHN.js.map → global-DeIYtcdl.js.map} +1 -1
- package/dist/{css-BhoclXaw.js → globalSheet-CdgVpvCb.js} +185 -426
- package/dist/globalSheet-CdgVpvCb.js.map +1 -0
- package/dist/{hash-DlXmmPPm.js → hash-DCJkLls_.js} +4 -4
- package/dist/hash-DCJkLls_.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 +3 -3
- package/dist/jsx/jsx-dev-runtime.server.js.map +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.server.js +4 -4
- package/dist/jsx/jsx-runtime.server.js.map +1 -1
- package/dist/{jsx-8TwYuvgM.js → jsx-CvloSSpb.js} +4 -4
- package/dist/{jsx-8TwYuvgM.js.map → jsx-CvloSSpb.js.map} +1 -1
- package/dist/jsx_runtime-pt7DOZOE.js +13 -0
- package/dist/jsx_runtime-pt7DOZOE.js.map +1 -0
- package/dist/{loader-BVebGteg.mjs → loader-fAuIjIik.mjs} +3 -3
- package/dist/{loader-BVebGteg.mjs.map → loader-fAuIjIik.mjs.map} +1 -1
- package/dist/{misc-Bs2DgdG7.mjs → misc-CyZgGtc9.mjs} +3 -3
- package/dist/{misc-Bs2DgdG7.mjs.map → misc-CyZgGtc9.mjs.map} +1 -1
- package/dist/{namedTokens-CwniouKk.js → namedTokens-DwgmUMBM.js} +2 -2
- package/dist/{namedTokens-CwniouKk.js.map → namedTokens-DwgmUMBM.js.map} +1 -1
- package/dist/plugin/farm/index.mjs +3 -3
- package/dist/plugin/nextjs/index.mjs +4 -4
- package/dist/plugin/nextjs/loader.mjs +7 -5
- package/dist/plugin/nextjs/loader.mjs.map +1 -1
- 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-D1n78rd7.mjs → registry-BMijh1CM.mjs} +2 -2
- package/dist/{registry-D1n78rd7.mjs.map → registry-BMijh1CM.mjs.map} +1 -1
- package/dist/{resolveClassNameRuntime-BJcykzdl.js → resolveClassNameRuntime-B6vKNL5y.js} +2 -2
- package/dist/{resolveClassNameRuntime-BJcykzdl.js.map → resolveClassNameRuntime-B6vKNL5y.js.map} +1 -1
- package/dist/server.js +87 -17
- package/dist/server.js.map +1 -1
- package/dist/{shared-D4-AKGn6.mjs → shared-BfASWZo1.mjs} +4 -4
- package/dist/{shared-D4-AKGn6.mjs.map → shared-BfASWZo1.mjs.map} +1 -1
- package/dist/{shared-C9XQd8p_.cjs → shared-DY0kuBcN.cjs} +460 -162
- package/dist/shared-DY0kuBcN.cjs.map +1 -0
- package/dist/sheet-B-5idGtZ.js +9 -0
- package/dist/sheet-B-5idGtZ.js.map +1 -0
- package/dist/{config-TyjNpRrV.js → sheet-C6ymGhKV.js} +23 -2
- package/dist/sheet-C6ymGhKV.js.map +1 -0
- package/dist/sheet-D4f9KYPf.js +1 -0
- package/dist/{sidecar-CZTYX2vA.mjs → sidecar-cCzTDkzg.mjs} +3 -3
- package/dist/{sidecar-CZTYX2vA.mjs.map → sidecar-cCzTDkzg.mjs.map} +1 -1
- package/dist/{style-CmXHCPF4.js → style-a6ccye6R.js} +12 -12
- package/dist/style-a6ccye6R.js.map +1 -0
- package/dist/styleStore-Ceoaqa5U.js +45 -0
- package/dist/styleStore-Ceoaqa5U.js.map +1 -0
- package/dist/{env-C8TRVSyb.js → styleStore-D1IEmq1v.js} +435 -63
- package/dist/styleStore-D1IEmq1v.js.map +1 -0
- package/dist/{token-DMrBbat8.js → token-Ci73NE6h.js} +2 -2
- package/dist/{token-DMrBbat8.js.map → token-Ci73NE6h.js.map} +1 -1
- package/dist/{trace-C7EzEj2Q.js → trace-DDsvwdF0.js} +3 -3
- package/dist/{trace-C7EzEj2Q.js.map → trace-DDsvwdF0.js.map} +1 -1
- package/dist/{trace-DzCntvK4.js → trace-uHVvnYiw.js} +2 -2
- package/dist/{trace-DzCntvK4.js.map → trace-uHVvnYiw.js.map} +1 -1
- package/dist/{transform-CSZMklMb.js → transform-BkxIouPX.js} +2 -2
- package/dist/{transform-CSZMklMb.js.map → transform-BkxIouPX.js.map} +1 -1
- package/dist/types/atomic/className.d.ts +2 -2
- package/dist/types/atomic/utils/selector.d.ts +2 -1
- package/dist/types/builder/data/const.d.ts +1 -0
- package/dist/types/builder/data/data.d.ts +1 -1
- package/dist/types/builder/data/state.d.ts +1 -0
- package/dist/types/builder/selector_override.d.ts +1 -1
- package/dist/types/builder/selector_override_core.d.ts +2 -0
- package/dist/types/builder/types/alias.d.ts +2 -2
- package/dist/types/compiler/extract/types.d.ts +7 -1
- package/dist/types/compiler/transform/extract/chain/extract_chain.d.ts +2 -0
- package/dist/types/compiler/utils/constants.d.ts +1 -0
- package/dist/types/config/config/css.d.ts +2 -1
- package/dist/types/config/configure.d.ts +2 -0
- package/dist/types/config/document.d.ts +3 -0
- package/dist/types/css/globalSheet.d.ts +24 -0
- package/dist/types/css/index.d.ts +4 -1
- package/dist/types/css/sheet.d.ts +3 -2
- package/dist/types/entry/rsc_dev/css.d.ts +1 -0
- package/dist/types/runtime/rsc/constants.d.ts +2 -0
- package/dist/types/runtime/rsc/dev.d.ts +5 -0
- package/dist/types/runtime/rsc/getClassName.d.ts +3 -0
- package/dist/types/runtime/rsc/globalSheet.d.ts +22 -0
- package/dist/types/runtime/rsc/observer.d.ts +5 -0
- package/dist/types/runtime/rsc/styleStore.d.ts +2 -0
- package/dist/types/runtime/sheet/document.d.ts +3 -0
- package/dist/types/sheet/ordered.d.ts +4 -0
- package/dist/types/sheet/ordering.d.ts +15 -0
- package/dist/types/sheet/types.d.ts +7 -0
- package/dist/types/style/important.d.ts +2 -1
- package/dist/types/style/style.d.ts +2 -2
- package/dist/{utils-CoMwEfhG.mjs → utils-BO6Ix8t5.mjs} +4 -4
- package/dist/{utils-CoMwEfhG.mjs.map → utils-BO6Ix8t5.mjs.map} +1 -1
- package/dist/{utils-B7QcJ-Yw.js → utils-CB70kIh6.js} +3 -3
- package/dist/{utils-B7QcJ-Yw.js.map → utils-CB70kIh6.js.map} +1 -1
- package/dist/{utils-BYpkJ-uE.mjs → utils-EG9gh2g3.mjs} +3 -3
- package/dist/{utils-BYpkJ-uE.mjs.map → utils-EG9gh2g3.mjs.map} +1 -1
- package/dist/{utils-D4KMqCu2.js → utils-sG7IWYP6.js} +1089 -646
- package/dist/utils-sG7IWYP6.js.map +1 -0
- package/dist/utils.js +3 -3
- package/dist/{value-yd2SZ1XQ.js → value-B-ThmbY-.js} +16 -9
- package/dist/value-B-ThmbY-.js.map +1 -0
- package/dist/{webpack-B6z1UHh9.mjs → webpack-WXAJ3IYn.mjs} +5 -5
- package/dist/{webpack-B6z1UHh9.mjs.map → webpack-WXAJ3IYn.mjs.map} +1 -1
- package/entry/dev/sheet.ts +4 -1
- package/entry/rsc_dev/css.ts +2 -0
- package/jsx/rsc/jsx_dev_runtime.ts +11 -2
- package/jsx/rsc/jsx_runtime.ts +14 -3
- package/package.json +1 -1
- package/plugin/nextjs/loader.ts +18 -2
- package/runtime/core/elementMarker.ts +9 -3
- package/runtime/rsc/constants.ts +3 -0
- package/runtime/rsc/dev.ts +31 -15
- package/runtime/rsc/getClassName.ts +6 -0
- package/runtime/rsc/globalSheet.ts +130 -0
- package/runtime/rsc/observer.ts +118 -15
- package/runtime/rsc/styleStore.ts +12 -36
- package/runtime/sheet/document.ts +28 -0
- package/runtime/sheet/global-prod.ts +3 -5
- package/runtime/sheet/global.ts +3 -5
- package/runtime/sheet/rule.ts +4 -2
- package/runtime/sheet/rules.ts +3 -0
- package/sheet/dev/dev_sort.ts +5 -1
- package/sheet/dev/index.ts +23 -3
- package/sheet/ordered.ts +188 -0
- package/sheet/ordering.ts +138 -0
- package/sheet/prod.ts +17 -5
- package/sheet/types.ts +4 -0
- package/style/important.ts +3 -1
- package/style/style.ts +1 -1
- package/utils/trace.ts +1 -0
- package/dist/className-yhJCGT0F.js.map +0 -1
- package/dist/combine-CC9bY-hu.js.map +0 -1
- package/dist/compiler-Ct5xGIeu.mjs.map +0 -1
- package/dist/config-BiiMS4rU.js.map +0 -1
- package/dist/config-TyjNpRrV.js.map +0 -1
- package/dist/createTransformElement-BGznW-Mu.js +0 -34
- package/dist/createTransformElement-BGznW-Mu.js.map +0 -1
- package/dist/css-BhoclXaw.js.map +0 -1
- package/dist/css-IecKRNxs.js.map +0 -1
- package/dist/css-WaHZ6gxv.js.map +0 -1
- package/dist/data-BgZmL55Y.js.map +0 -1
- package/dist/debug-D-1hhd0G.js.map +0 -1
- package/dist/elementMarker-CJcfpKL1.js.map +0 -1
- package/dist/env-C8TRVSyb.js.map +0 -1
- package/dist/getClassName-CeoxISNW.js.map +0 -1
- package/dist/global-CWYOol4o.js +0 -14
- package/dist/global-CWYOol4o.js.map +0 -1
- package/dist/hash-DlXmmPPm.js.map +0 -1
- package/dist/jsx_runtime-CPojW0KD.js +0 -12
- package/dist/jsx_runtime-CPojW0KD.js.map +0 -1
- package/dist/rules-Dz-szpPu.js.map +0 -1
- package/dist/shared-C9XQd8p_.cjs.map +0 -1
- package/dist/sheet-LU89fcH_.js +0 -7
- package/dist/sheet-LU89fcH_.js.map +0 -1
- package/dist/style-CmXHCPF4.js.map +0 -1
- package/dist/styleStore-B0x4Ahpx.js +0 -60
- package/dist/styleStore-B0x4Ahpx.js.map +0 -1
- package/dist/styleStore-BrpgLNgc.js +0 -57
- package/dist/styleStore-BrpgLNgc.js.map +0 -1
- package/dist/utils-D4KMqCu2.js.map +0 -1
- package/dist/value-yd2SZ1XQ.js.map +0 -1
|
@@ -35,8 +35,12 @@ import type {
|
|
|
35
35
|
RuntimeSlotOverrideItem,
|
|
36
36
|
RuntimeStyleItem,
|
|
37
37
|
} from '../../../../builder/data/state';
|
|
38
|
-
import {
|
|
39
|
-
|
|
38
|
+
import {
|
|
39
|
+
normalizeManualSelectors,
|
|
40
|
+
setGlobalSheetSelectorOptions,
|
|
41
|
+
setSheetSelectorOptions,
|
|
42
|
+
} from '../../../../builder/selector_override';
|
|
43
|
+
import { isSheetLayerOption, isStyleLayerEnabled, resolveSheetLayerOption } from '../../../../config/config/css';
|
|
40
44
|
import type { ClassNameFormat, TokenNameFormat, TransformClassNameFormat } from '../../../../config/types';
|
|
41
45
|
import type { Selector } from '../../../../selector/types';
|
|
42
46
|
import { importantValue, isStyleImportantValue } from '../../../../style/important';
|
|
@@ -376,10 +380,14 @@ function compileSheetChain(
|
|
|
376
380
|
const items: CompiledItem[] = [];
|
|
377
381
|
const rules: CssExtractRule[] = [];
|
|
378
382
|
const hasOptions = chain.baseArgs.length === 2;
|
|
379
|
-
const sheetOptions = hasOptions
|
|
380
|
-
? evaluateCreateSheetOptions(chain.baseArgs[0], scope)
|
|
383
|
+
const sheetOptions: (CreateSheetOptions & { global?: boolean; order?: number; }) | null = hasOptions
|
|
384
|
+
? evaluateCreateSheetOptions(chain.baseArgs[0], scope, chain.global)
|
|
381
385
|
: {};
|
|
382
386
|
if (!sheetOptions) return null;
|
|
387
|
+
if (chain.global) {
|
|
388
|
+
if (sheetOptions.specificity !== undefined) throw new Error('createGlobalSheet does not support specificity');
|
|
389
|
+
sheetOptions.global = true;
|
|
390
|
+
}
|
|
383
391
|
|
|
384
392
|
const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
|
|
385
393
|
|
|
@@ -390,12 +398,15 @@ function compileSheetChain(
|
|
|
390
398
|
return null;
|
|
391
399
|
}
|
|
392
400
|
|
|
393
|
-
const sheetLayer = sheetOptions.layer ??
|
|
401
|
+
const sheetLayer = sheetOptions.layer ?? false;
|
|
394
402
|
for (let i = 0, len = rules.length; i < len; i++) {
|
|
395
403
|
rules[i].layer = resolveSheetLayerOption(
|
|
396
404
|
sheetLayer,
|
|
397
405
|
options.css?.layerNamespace ?? DEFAULT_CONFIG.layerNamespace ?? '',
|
|
406
|
+
isStyleLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer),
|
|
398
407
|
);
|
|
408
|
+
rules[i].sheet = true;
|
|
409
|
+
if (chain.global) rules[i].globalSheet = { id: chain.sheetId ?? fileId, order: sheetOptions.order ?? 0 };
|
|
399
410
|
}
|
|
400
411
|
|
|
401
412
|
return { type: 'sheet', items, rules, sheetOptions };
|
|
@@ -404,19 +415,26 @@ function compileSheetChain(
|
|
|
404
415
|
function evaluateCreateSheetOptions(
|
|
405
416
|
node: BabelTypes.Node,
|
|
406
417
|
scope: EvalScope,
|
|
407
|
-
|
|
418
|
+
global = false,
|
|
419
|
+
): (CreateSheetOptions & { order?: number; }) | null {
|
|
408
420
|
const result = evaluateNode(node, scope);
|
|
409
421
|
if (!result.ok || !result.value || typeof result.value !== 'object' || Array.isArray(result.value)) return null;
|
|
410
|
-
|
|
411
422
|
const value = result.value as Record<string, unknown>;
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
423
|
+
if (hasGlobalRuntimeValue(value)) return null;
|
|
424
|
+
const allowed = global ? ['layer', 'order'] : ['layer', 'specificity'];
|
|
425
|
+
if (Object.keys(value).some((key) => !allowed.includes(key))) {
|
|
426
|
+
throw new Error(
|
|
427
|
+
global ? 'createGlobalSheet only supports layer and order' : 'createSheet only supports layer and specificity',
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
if (!isSheetLayerOption(value.layer)) throw new Error('invalid sheet layer');
|
|
431
|
+
if (value.specificity !== undefined && (!Number.isInteger(value.specificity) || (value.specificity as number) < 0)) {
|
|
432
|
+
throw new Error('specificity must be a non-negative integer');
|
|
433
|
+
}
|
|
434
|
+
if (value.order !== undefined && (typeof value.order !== 'number' || !Number.isFinite(value.order))) {
|
|
435
|
+
throw new Error('order must be a finite number');
|
|
436
|
+
}
|
|
437
|
+
return value as CreateSheetOptions & { order?: number; };
|
|
420
438
|
}
|
|
421
439
|
|
|
422
440
|
function compileSheetItemsArg(
|
|
@@ -427,7 +445,7 @@ function compileSheetItemsArg(
|
|
|
427
445
|
options: CompilerOptions,
|
|
428
446
|
items: CompiledItem[],
|
|
429
447
|
rules: CssExtractRule[],
|
|
430
|
-
sheetOptions: CreateSheetOptions,
|
|
448
|
+
sheetOptions: CreateSheetOptions & { global?: boolean; order?: number; },
|
|
431
449
|
): boolean {
|
|
432
450
|
if (node.type === 'ArrayExpression') {
|
|
433
451
|
for (const element of node.elements) {
|
|
@@ -440,7 +458,9 @@ function compileSheetItemsArg(
|
|
|
440
458
|
}
|
|
441
459
|
|
|
442
460
|
const tokenOverride = evaluateNode(node, scope);
|
|
461
|
+
if (tokenOverride.ok && !tokenOverride.value) return true;
|
|
443
462
|
if (tokenOverride.ok && isStyleTokenOverrideData(tokenOverride.value)) {
|
|
463
|
+
if (sheetOptions.global) throw new Error('createGlobalSheet requires token overrides inside an explicit selector');
|
|
444
464
|
addCompiledTokenItem(
|
|
445
465
|
getStyleTokenId(tokenOverride.value),
|
|
446
466
|
tokenOverride.value,
|
|
@@ -455,6 +475,9 @@ function compileSheetItemsArg(
|
|
|
455
475
|
const item = tokenOverride.value[i];
|
|
456
476
|
if (!item) continue;
|
|
457
477
|
if (!isStyleTokenOverrideData(item)) return false;
|
|
478
|
+
if (sheetOptions.global) {
|
|
479
|
+
throw new Error('createGlobalSheet requires token overrides inside an explicit selector');
|
|
480
|
+
}
|
|
458
481
|
|
|
459
482
|
addCompiledTokenItem(
|
|
460
483
|
getStyleTokenId(item),
|
|
@@ -505,10 +528,22 @@ function compileSelectorOverrideChain(
|
|
|
505
528
|
options: CompilerOptions,
|
|
506
529
|
items: CompiledItem[],
|
|
507
530
|
rules: CssExtractRule[],
|
|
508
|
-
sheetOptions: CreateSheetOptions,
|
|
531
|
+
sheetOptions: CreateSheetOptions & { global?: boolean; order?: number; },
|
|
509
532
|
): boolean {
|
|
510
533
|
if (chain.baseArgs.length === 0 || chain.baseArgs.length > 2) return false;
|
|
511
534
|
|
|
535
|
+
// Unlike attached sheets, globals have no runtime replacement to supply dynamic values.
|
|
536
|
+
// Only erase the call when every selector/style argument is statically evaluable.
|
|
537
|
+
if (sheetOptions.global) {
|
|
538
|
+
const args = [...chain.baseArgs, ...chain.methods.flatMap((method) => method.args)];
|
|
539
|
+
if (
|
|
540
|
+
args.some((arg) => {
|
|
541
|
+
const result = evaluateNode(arg, scope);
|
|
542
|
+
return !result.ok || hasGlobalRuntimeValue(result.value);
|
|
543
|
+
})
|
|
544
|
+
) return false;
|
|
545
|
+
}
|
|
546
|
+
|
|
512
547
|
const selectorArg = evaluateNode(chain.baseArgs[0], scope);
|
|
513
548
|
if (!selectorArg.ok) return false;
|
|
514
549
|
|
|
@@ -531,7 +566,9 @@ function compileSelectorOverrideChain(
|
|
|
531
566
|
options,
|
|
532
567
|
items,
|
|
533
568
|
rules,
|
|
534
|
-
|
|
569
|
+
sheetOptions.global
|
|
570
|
+
? setGlobalSheetSelectorOptions(manualSelectors[i], sheetOptions)
|
|
571
|
+
: setSheetSelectorOptions(manualSelectors[i], sheetOptions),
|
|
535
572
|
)
|
|
536
573
|
) {
|
|
537
574
|
return false;
|
|
@@ -1173,7 +1210,7 @@ function decorateClassNameValue(
|
|
|
1173
1210
|
if (isClassNameValue(value)) return value;
|
|
1174
1211
|
|
|
1175
1212
|
if (isStyleImportantValue(value)) {
|
|
1176
|
-
return importantValue(decorateClassNameValue(value.value, className));
|
|
1213
|
+
return importantValue(decorateClassNameValue(value.value, className), value.native);
|
|
1177
1214
|
}
|
|
1178
1215
|
|
|
1179
1216
|
if (isStyleWeightValue(value)) {
|
|
@@ -2751,6 +2788,7 @@ function addSlotOverrideDataItems(
|
|
|
2751
2788
|
property: overrideItem.property,
|
|
2752
2789
|
weight: overrideItem.weight,
|
|
2753
2790
|
important: overrideItem.important,
|
|
2791
|
+
importantNative: overrideItem.importantNative,
|
|
2754
2792
|
value: overrideItem.value,
|
|
2755
2793
|
variable: overrideItem.variable,
|
|
2756
2794
|
token: overrideItem.token,
|
|
@@ -2854,6 +2892,7 @@ function addRuntimeScopeItem(
|
|
|
2854
2892
|
sourceItem.selector,
|
|
2855
2893
|
itemParentSelector,
|
|
2856
2894
|
itemAtRules,
|
|
2895
|
+
sourceItem.importantNative,
|
|
2857
2896
|
);
|
|
2858
2897
|
|
|
2859
2898
|
const className = getAtomicClassName(
|
|
@@ -2872,6 +2911,7 @@ function addRuntimeScopeItem(
|
|
|
2872
2911
|
cssConfig.transformClassNameFormat,
|
|
2873
2912
|
cssConfig.sheetClassNameFormat,
|
|
2874
2913
|
cssConfig.hashLength,
|
|
2914
|
+
sourceItem.importantNative,
|
|
2875
2915
|
);
|
|
2876
2916
|
|
|
2877
2917
|
const item: CompiledItem = createCompiledItem(
|
|
@@ -2910,6 +2950,7 @@ function addRuntimeScopeItem(
|
|
|
2910
2950
|
css,
|
|
2911
2951
|
priority: layerPriority,
|
|
2912
2952
|
important,
|
|
2953
|
+
importantNative: sourceItem.importantNative,
|
|
2913
2954
|
trace: traceCallsite
|
|
2914
2955
|
? {
|
|
2915
2956
|
filePath: traceCallsite.filePath ?? fileId,
|
|
@@ -3094,6 +3135,7 @@ function addRuntimeStyleItem(
|
|
|
3094
3135
|
itemSelector,
|
|
3095
3136
|
parentSelector,
|
|
3096
3137
|
itemAtRules,
|
|
3138
|
+
sourceItem.importantNative,
|
|
3097
3139
|
);
|
|
3098
3140
|
|
|
3099
3141
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
@@ -3114,6 +3156,7 @@ function addRuntimeStyleItem(
|
|
|
3114
3156
|
cssConfig.transformClassNameFormat,
|
|
3115
3157
|
cssConfig.sheetClassNameFormat,
|
|
3116
3158
|
cssConfig.hashLength,
|
|
3159
|
+
sourceItem.importantNative,
|
|
3117
3160
|
);
|
|
3118
3161
|
|
|
3119
3162
|
const item: CompiledItem = createCompiledItem(
|
|
@@ -3158,6 +3201,7 @@ function addRuntimeStyleItem(
|
|
|
3158
3201
|
css,
|
|
3159
3202
|
priority: layerPriority,
|
|
3160
3203
|
important,
|
|
3204
|
+
importantNative: sourceItem.importantNative,
|
|
3161
3205
|
trace: traceCallsite
|
|
3162
3206
|
? {
|
|
3163
3207
|
filePath: traceCallsite.filePath ?? fileId,
|
|
@@ -3271,10 +3315,11 @@ function addStyleItems(
|
|
|
3271
3315
|
|
|
3272
3316
|
let weight: number | null = null;
|
|
3273
3317
|
let important = false;
|
|
3318
|
+
let importantNative = false;
|
|
3274
3319
|
let value: unknown = rawValue;
|
|
3275
3320
|
let transformClassName: string | null = null;
|
|
3276
3321
|
|
|
3277
|
-
[value, weight, important] = unwrapStaticStyleValue(value);
|
|
3322
|
+
[value, weight, important, importantNative] = unwrapStaticStyleValue(value);
|
|
3278
3323
|
|
|
3279
3324
|
if (isClassNameValue(value)) {
|
|
3280
3325
|
transformClassName = value.className;
|
|
@@ -3336,6 +3381,7 @@ function addStyleItems(
|
|
|
3336
3381
|
selector,
|
|
3337
3382
|
parentSelector,
|
|
3338
3383
|
atRules,
|
|
3384
|
+
importantNative,
|
|
3339
3385
|
);
|
|
3340
3386
|
|
|
3341
3387
|
const className = getAtomicClassName(
|
|
@@ -3354,6 +3400,7 @@ function addStyleItems(
|
|
|
3354
3400
|
cssConfig.transformClassNameFormat,
|
|
3355
3401
|
cssConfig.sheetClassNameFormat,
|
|
3356
3402
|
cssConfig.hashLength,
|
|
3403
|
+
importantNative,
|
|
3357
3404
|
);
|
|
3358
3405
|
|
|
3359
3406
|
const item: CompiledItem = createCompiledItem(
|
|
@@ -3422,6 +3469,7 @@ function addStyleItems(
|
|
|
3422
3469
|
css,
|
|
3423
3470
|
priority: layerPriority,
|
|
3424
3471
|
important,
|
|
3472
|
+
importantNative,
|
|
3425
3473
|
trace: propertyCallsite
|
|
3426
3474
|
? {
|
|
3427
3475
|
filePath: propertyCallsite.filePath ?? fileId,
|
|
@@ -3454,13 +3502,17 @@ function addStyleItems(
|
|
|
3454
3502
|
return true;
|
|
3455
3503
|
}
|
|
3456
3504
|
|
|
3457
|
-
function unwrapStaticStyleValue(
|
|
3505
|
+
function unwrapStaticStyleValue(
|
|
3506
|
+
value: unknown,
|
|
3507
|
+
): [value: unknown, weight: number | null, important: boolean, native: boolean] {
|
|
3458
3508
|
let weight: number | null = null;
|
|
3459
3509
|
let important = false;
|
|
3510
|
+
let native = false;
|
|
3460
3511
|
|
|
3461
3512
|
while (true) {
|
|
3462
3513
|
if (isStyleImportantValue(value)) {
|
|
3463
3514
|
important = true;
|
|
3515
|
+
native ||= value.native === true;
|
|
3464
3516
|
value = value.value;
|
|
3465
3517
|
continue;
|
|
3466
3518
|
}
|
|
@@ -3474,7 +3526,7 @@ function unwrapStaticStyleValue(value: unknown): [value: unknown, weight: number
|
|
|
3474
3526
|
break;
|
|
3475
3527
|
}
|
|
3476
3528
|
|
|
3477
|
-
return [value, weight, important];
|
|
3529
|
+
return [value, weight, important, native];
|
|
3478
3530
|
}
|
|
3479
3531
|
|
|
3480
3532
|
function throwIfRequiredStaticStyleValue(result: EvalResult) {
|
|
@@ -3552,3 +3604,11 @@ function getCompiledRuntimeValue(value: unknown): BabelTypes.Expression | undefi
|
|
|
3552
3604
|
if (!value || typeof value !== 'object') return undefined;
|
|
3553
3605
|
return (value as CompiledRuntimeValue)[COMPILED_RUNTIME_VALUE];
|
|
3554
3606
|
}
|
|
3607
|
+
|
|
3608
|
+
function hasGlobalRuntimeValue(value: unknown, seen = new Set<object>()): boolean {
|
|
3609
|
+
if (!value || typeof value !== 'object' || isStyleTokenData(value) || isAtRuleRef(value)) return false;
|
|
3610
|
+
if (getCompiledRuntimeValue(value)) return true;
|
|
3611
|
+
if (seen.has(value)) return false;
|
|
3612
|
+
seen.add(value);
|
|
3613
|
+
return Object.values(value).some((item) => hasGlobalRuntimeValue(item, seen));
|
|
3614
|
+
}
|
|
@@ -6,6 +6,7 @@ import type { CompilerCssCollector } from '../../extract/collector';
|
|
|
6
6
|
import {
|
|
7
7
|
FN_CREATE_EXTRACTED_THEME,
|
|
8
8
|
FN_CREATE_EXTRACTED_TOKEN,
|
|
9
|
+
FN_CREATE_GLOBAL_SHEET,
|
|
9
10
|
FN_CREATE_SHEET,
|
|
10
11
|
FN_STYLE_PLAIN,
|
|
11
12
|
FN_STYLE_RAW,
|
|
@@ -117,7 +118,10 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
117
118
|
state.styleMetas.set(spec.local.name, meta);
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
if (
|
|
121
|
+
if (
|
|
122
|
+
sourceName === STYLE_CSS_IMPORT_PATH &&
|
|
123
|
+
(imported === FN_CREATE_SHEET || imported === FN_CREATE_GLOBAL_SHEET)
|
|
124
|
+
) {
|
|
121
125
|
state.sheetNames.add(spec.local.name);
|
|
122
126
|
}
|
|
123
127
|
});
|
|
@@ -208,6 +212,8 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
208
212
|
|
|
209
213
|
const chain = extractStyleChain(path.node, state.styleNames, state.sheetNames);
|
|
210
214
|
if (!chain) return;
|
|
215
|
+
chain.global = chain.kind === 'sheet' && state.imports.get(chain.rootName)?.name === FN_CREATE_GLOBAL_SHEET;
|
|
216
|
+
if (chain.global) chain.sheetId = state.fileId + ':' + path.node.start;
|
|
211
217
|
|
|
212
218
|
if (
|
|
213
219
|
chain.kind === 'slot' &&
|
|
@@ -256,6 +262,13 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
256
262
|
return;
|
|
257
263
|
}
|
|
258
264
|
|
|
265
|
+
if (chain.global) {
|
|
266
|
+
if (path.parentPath.isExpressionStatement()) path.parentPath.remove();
|
|
267
|
+
else path.replaceWith(t.unaryExpression('void', t.numericLiteral(0)));
|
|
268
|
+
path.skip();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
259
272
|
const replacement = createChainReplacement({
|
|
260
273
|
t,
|
|
261
274
|
path,
|
|
@@ -350,30 +363,37 @@ function pruneUnusedStyleInputDeclarations(
|
|
|
350
363
|
path: BabelCore.NodePath<BabelTypes.Program>,
|
|
351
364
|
state: PluginState,
|
|
352
365
|
) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
declaratorPath.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
366
|
+
const dependencies = new Set<BabelTypes.VariableDeclarator>();
|
|
367
|
+
let changed: boolean;
|
|
368
|
+
do {
|
|
369
|
+
changed = false;
|
|
370
|
+
path.scope.crawl();
|
|
371
|
+
path.traverse({
|
|
372
|
+
VariableDeclarator(declaratorPath) {
|
|
373
|
+
const node = declaratorPath.node;
|
|
374
|
+
if (declaratorPath.parentPath?.parentPath?.isExportNamedDeclaration()) return;
|
|
375
|
+
if (node.id.type !== 'Identifier') return;
|
|
376
|
+
const binding = declaratorPath.scope.getBinding(node.id.name);
|
|
377
|
+
if (!binding || !binding.constant || binding.referencePaths.length) return;
|
|
378
|
+
if (
|
|
379
|
+
!isStyleInputCall(node.init, state) &&
|
|
380
|
+
!(dependencies.has(node) && declaratorPath.get('init').isPure())
|
|
381
|
+
) return;
|
|
382
|
+
|
|
383
|
+
declaratorPath.get('init').traverse({
|
|
384
|
+
ReferencedIdentifier(reference) {
|
|
385
|
+
const dependency = reference.scope.getBinding(reference.node.name);
|
|
386
|
+
if (dependency?.path.isVariableDeclarator()) dependencies.add(dependency.path.node);
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
const declarationPath = declaratorPath.parentPath;
|
|
390
|
+
if (!declarationPath?.isVariableDeclaration()) return;
|
|
391
|
+
if (declarationPath.node.declarations.length > 1) declaratorPath.remove();
|
|
392
|
+
else declarationPath.remove();
|
|
393
|
+
changed = true;
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
} while (changed);
|
|
377
397
|
path.scope.crawl();
|
|
378
398
|
}
|
|
379
399
|
|
|
@@ -383,6 +403,12 @@ function isStyleInputCall(
|
|
|
383
403
|
) {
|
|
384
404
|
if (!node || node.type !== 'CallExpression') return false;
|
|
385
405
|
|
|
406
|
+
const selectorChain = extractStyleChain(node, state.styleNames, state.sheetNames);
|
|
407
|
+
if (selectorChain?.kind === 'selector') {
|
|
408
|
+
return selectorChain.baseArgs.every((arg) => evaluateNode(arg, getEvalScope(state)).ok) &&
|
|
409
|
+
selectorChain.methods.every((method) => method.args.every((arg) => evaluateNode(arg, getEvalScope(state)).ok));
|
|
410
|
+
}
|
|
411
|
+
|
|
386
412
|
const callee = node.callee;
|
|
387
413
|
if (callee.type !== 'MemberExpression' || callee.computed) return false;
|
|
388
414
|
if (callee.object.type !== 'Identifier') return false;
|
|
@@ -2,6 +2,8 @@ import {
|
|
|
2
2
|
FN_BIND_SCOPE,
|
|
3
3
|
FN_COMBINE_SCOPE,
|
|
4
4
|
FN_COMBINE_STYLE,
|
|
5
|
+
FN_CREATE_GLOBAL_SHEET,
|
|
6
|
+
FN_CREATE_SHEET,
|
|
5
7
|
FN_CREATE_THEME,
|
|
6
8
|
FN_CREATE_TOKEN,
|
|
7
9
|
FN_CREATE_TOKENS,
|
|
@@ -132,5 +134,6 @@ function isCompilerHandledImport(
|
|
|
132
134
|
name: string,
|
|
133
135
|
) {
|
|
134
136
|
return IMPORT_PATHS.includes(source) &&
|
|
135
|
-
[FN_CREATE_THEME, FN_CREATE_TOKEN, FN_CREATE_TOKENS, FN_CREATE_VALUES]
|
|
137
|
+
[FN_CREATE_THEME, FN_CREATE_TOKEN, FN_CREATE_TOKENS, FN_CREATE_VALUES, FN_CREATE_SHEET, FN_CREATE_GLOBAL_SHEET]
|
|
138
|
+
.includes(name);
|
|
136
139
|
}
|
|
@@ -112,8 +112,8 @@ function buildSheetOptions(
|
|
|
112
112
|
),
|
|
113
113
|
);
|
|
114
114
|
}
|
|
115
|
-
if (options.
|
|
116
|
-
properties.push(t.objectProperty(t.identifier('
|
|
115
|
+
if (options.specificity !== undefined) {
|
|
116
|
+
properties.push(t.objectProperty(t.identifier('specificity'), t.numericLiteral(options.specificity)));
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
return t.objectExpression(properties);
|
|
@@ -61,6 +61,7 @@ export const FN_CREATE_COUNTER_STYLE = 'createCounterStyle';
|
|
|
61
61
|
export const FN_CREATE_PROPERTY = 'createProperty';
|
|
62
62
|
export const FN_FONT_SRC = 'fontSrc';
|
|
63
63
|
export const FN_CREATE_SHEET = 'createSheet';
|
|
64
|
+
export const FN_CREATE_GLOBAL_SHEET = 'createGlobalSheet';
|
|
64
65
|
|
|
65
66
|
export const FN_CREATE_EXTRACTED_STYLE = 'createExtractedStyle';
|
|
66
67
|
export const FN_CREATE_EXTRACTED_SHEET = 'createExtractedSheet';
|
package/config/config/css.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
|
|
12
12
|
export type CssLayerTargets = {
|
|
13
13
|
style?: boolean;
|
|
14
|
+
/** @deprecated Set layer on each sheet; this legacy field is ignored. */
|
|
14
15
|
sheet?: boolean;
|
|
15
16
|
};
|
|
16
17
|
|
|
@@ -58,9 +59,10 @@ export function isSheetLayerOption(value: unknown): value is boolean | string |
|
|
|
58
59
|
export function resolveSheetLayerOption(
|
|
59
60
|
layer: boolean | string,
|
|
60
61
|
namespace: string,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
mainLayerEnabled = isStyleLayerEnabled(),
|
|
63
|
+
): 'style' | false | NamedSheetLayer {
|
|
64
|
+
if (typeof layer !== 'string') return layer && mainLayerEnabled ? 'style' : false;
|
|
65
|
+
return { name: layer.startsWith('.') ? (mainLayerEnabled && namespace ? namespace + layer : layer.slice(1)) : layer };
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
export function isSheetLayerEnabled(layer: CssConfig['layer'] = CSS_CONFIG.layer) {
|
package/config/configure.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { setStyleCheckOptions, type StyleCheckOptions } from './config/check';
|
|
|
3
3
|
import { CSS_CONFIG, type CssConfig } from './config/css';
|
|
4
4
|
import { setDebugClassNameEnabled } from './config/debug';
|
|
5
5
|
import { RUNTIME_CONFIG } from './config/runtime';
|
|
6
|
+
import { setRuntimeDocument } from './document';
|
|
6
7
|
import { getCacheTTL } from './utils';
|
|
7
8
|
|
|
8
9
|
export type { CheckImportantOptions, StyleCheckLevel, StyleCheckOptions } from './config/check';
|
|
@@ -12,12 +13,15 @@ export type RuntimeCssOptions = Partial<CssConfig> & {
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export type ConfigureStyleRuntimeOptions = {
|
|
16
|
+
/** false disables stylesheet injection; true uses the global document (default). */
|
|
17
|
+
document?: boolean | Document;
|
|
15
18
|
css?: RuntimeCssOptions;
|
|
16
19
|
check?: StyleCheckOptions;
|
|
17
20
|
cacheTTL?: boolean | number;
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
export function configureStyleRuntime(options: ConfigureStyleRuntimeOptions = {}) {
|
|
24
|
+
if (options.document !== undefined) setRuntimeDocument(options.document);
|
|
21
25
|
if (options.css) {
|
|
22
26
|
checkBuildConfig('css');
|
|
23
27
|
const { debugClassName, ...css } = options.css;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { globalData } from '../utils/global';
|
|
2
|
+
|
|
3
|
+
const state = globalData<{
|
|
4
|
+
target: boolean | Document;
|
|
5
|
+
listeners: Set<() => void>;
|
|
6
|
+
}>('config.document', () => ({ target: true, listeners: new Set() }));
|
|
7
|
+
|
|
8
|
+
export function getRuntimeDocument(documentOverride?: Document): Document | null {
|
|
9
|
+
if (state.target === false) return null;
|
|
10
|
+
if (state.target !== true) return state.target;
|
|
11
|
+
if (documentOverride) return documentOverride;
|
|
12
|
+
return typeof globalThis.document === 'undefined' ? null : globalThis.document;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function setRuntimeDocument(target: boolean | Document) {
|
|
16
|
+
if (state.target === target) return;
|
|
17
|
+
state.target = target;
|
|
18
|
+
state.listeners.forEach((listener) => listener());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function onRuntimeDocumentChange(listener: () => void) {
|
|
22
|
+
state.listeners.add(listener);
|
|
23
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type DebugData, isDebugData, type SelectorData, type SelectorOverrideData } from '../builder/data';
|
|
2
|
+
import { BUILDER_CALLSITE } from '../builder/data';
|
|
3
|
+
import { CSS_CONFIG, CSS_CONFIG_DEFAULT } from '../config/config/css';
|
|
4
|
+
import { collectStylePropSheetRules, getGlobalSheet } from '../runtime/sheet';
|
|
5
|
+
import { hashString } from '../utils/hash';
|
|
6
|
+
import { buildSheet } from './sheet';
|
|
7
|
+
|
|
8
|
+
export type CreateGlobalSheetOptions = { layer?: boolean | string; order?: number; };
|
|
9
|
+
export type GlobalSheetItem<Style = unknown> =
|
|
10
|
+
| false
|
|
11
|
+
| null
|
|
12
|
+
| undefined
|
|
13
|
+
| SelectorData<Style>
|
|
14
|
+
| SelectorOverrideData<Style>
|
|
15
|
+
| readonly GlobalSheetItem<Style>[];
|
|
16
|
+
|
|
17
|
+
export function createGlobalSheet<Style = unknown>(items?: GlobalSheetItem<Style>): void;
|
|
18
|
+
export function createGlobalSheet<Style = unknown>(
|
|
19
|
+
options: CreateGlobalSheetOptions,
|
|
20
|
+
items: GlobalSheetItem<Style>,
|
|
21
|
+
): void;
|
|
22
|
+
export function createGlobalSheet<Style = unknown>(
|
|
23
|
+
optionsOrItems?: CreateGlobalSheetOptions | GlobalSheetItem<Style>,
|
|
24
|
+
items?: GlobalSheetItem<Style> | DebugData,
|
|
25
|
+
debug?: DebugData,
|
|
26
|
+
): void {
|
|
27
|
+
const rules = buildGlobalSheetRules(optionsOrItems, items, debug, arguments.length >= 2 && !isDebugData(items));
|
|
28
|
+
const sheet = getGlobalSheet();
|
|
29
|
+
sheet.updateLayers(CSS_CONFIG.layers ?? CSS_CONFIG_DEFAULT.layers ?? []);
|
|
30
|
+
for (const rule of rules) sheet.insert(rule);
|
|
31
|
+
sheet.flush();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function buildGlobalSheetRules<Style>(
|
|
35
|
+
optionsOrItems?: CreateGlobalSheetOptions | GlobalSheetItem<Style>,
|
|
36
|
+
items?: GlobalSheetItem<Style> | DebugData,
|
|
37
|
+
debug?: DebugData,
|
|
38
|
+
hasOptions = arguments.length >= 2 && !isDebugData(items),
|
|
39
|
+
) {
|
|
40
|
+
const options = hasOptions ? optionsOrItems as CreateGlobalSheetOptions : {};
|
|
41
|
+
if (
|
|
42
|
+
!options || typeof options !== 'object' || Object.keys(options).some((key) => key !== 'layer' && key !== 'order')
|
|
43
|
+
) {
|
|
44
|
+
throw new Error('createGlobalSheet only supports layer and order options');
|
|
45
|
+
}
|
|
46
|
+
if (options.order !== undefined && !Number.isFinite(options.order)) {
|
|
47
|
+
throw new Error('createGlobalSheet order must be a finite number');
|
|
48
|
+
}
|
|
49
|
+
const data = buildSheet(
|
|
50
|
+
{ layer: options.layer },
|
|
51
|
+
hasOptions ? items as GlobalSheetItem<Style> : optionsOrItems as GlobalSheetItem<Style>,
|
|
52
|
+
isDebugData(items) ? items : debug,
|
|
53
|
+
true,
|
|
54
|
+
);
|
|
55
|
+
const rules = collectStylePropSheetRules(data);
|
|
56
|
+
// Only injected debug locations reliably identify a callsite in bundled code.
|
|
57
|
+
const site = (isDebugData(items) || debug) ? data[BUILDER_CALLSITE] : null;
|
|
58
|
+
const id = hashString(
|
|
59
|
+
JSON.stringify(site ? [site.filePath, site.line, site.column] : [options, rules.map((rule) => rule.css)]),
|
|
60
|
+
);
|
|
61
|
+
const globals = [];
|
|
62
|
+
for (const rule of rules) {
|
|
63
|
+
globals.push({ ...rule, key: id + ':' + rule.key, globalSheet: { id, order: options.order ?? 0 } });
|
|
64
|
+
}
|
|
65
|
+
return globals;
|
|
66
|
+
}
|
package/css/index.ts
CHANGED
|
@@ -3,8 +3,11 @@ export type { CSS, CSSProperties, CSSPropertyName } from '../atomic/utils/types'
|
|
|
3
3
|
export * from './counterStyle';
|
|
4
4
|
export * from './fontFace';
|
|
5
5
|
export * from './fontPaletteValues';
|
|
6
|
+
export { createGlobalSheet } from './globalSheet';
|
|
7
|
+
export type { CreateGlobalSheetOptions, GlobalSheetItem } from './globalSheet';
|
|
6
8
|
export * from './keyframes';
|
|
7
9
|
export * from './positionTry';
|
|
8
10
|
export * from './property';
|
|
9
|
-
export
|
|
11
|
+
export { createSheet } from './sheet';
|
|
12
|
+
export type { CreateSheetOptions, SheetBuilder } from './sheet';
|
|
10
13
|
export * from './styleTarget';
|