zyzz 0.0.28 → 0.0.30
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/binding/wasi/wasi-worker.mjs +186 -0
- package/binding/wasi/zyzz.wasi.cjs +2302 -0
- package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
- package/binding/zyzz.linux-x64-gnu.node +0 -0
- package/dist/babel/index.d.ts.map +1 -1
- package/dist/babel/index.js +2 -4
- package/dist/babel/index.js.map +1 -1
- package/dist/babel/internal/Compilation.d.ts +0 -1
- package/dist/babel/internal/Compilation.d.ts.map +1 -1
- package/dist/compiler/Graph.d.ts +14 -11
- package/dist/compiler/Graph.d.ts.map +1 -1
- package/dist/compiler/Graph.js +57 -1442
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Native.d.ts +7 -9
- package/dist/compiler/Native.d.ts.map +1 -1
- package/dist/compiler/Native.js +12 -716
- package/dist/compiler/Native.js.map +1 -1
- package/dist/compiler/Source.d.ts +122 -24
- package/dist/compiler/Source.d.ts.map +1 -1
- package/dist/compiler/Source.js +10 -1267
- package/dist/compiler/Source.js.map +1 -1
- package/dist/compiler/Transform.d.ts +4 -3
- package/dist/compiler/Transform.d.ts.map +1 -1
- package/dist/compiler/Transform.js +13 -961
- package/dist/compiler/Transform.js.map +1 -1
- package/dist/compiler/internal/AtRules.d.ts +5 -1
- package/dist/compiler/internal/AtRules.d.ts.map +1 -1
- package/dist/compiler/internal/AtRules.js +12 -106
- package/dist/compiler/internal/AtRules.js.map +1 -1
- package/dist/compiler/internal/Context.d.ts +11 -0
- package/dist/compiler/internal/Context.d.ts.map +1 -0
- package/dist/compiler/internal/Context.js +11 -0
- package/dist/compiler/internal/Context.js.map +1 -0
- package/dist/compiler/internal/Results.d.ts +148 -0
- package/dist/compiler/internal/Results.d.ts.map +1 -0
- package/dist/compiler/internal/Results.js +259 -0
- package/dist/compiler/internal/Results.js.map +1 -0
- package/dist/compiler/internal/Syntax.d.ts +0 -2
- package/dist/compiler/internal/Syntax.d.ts.map +1 -1
- package/dist/compiler/internal/Syntax.js +0 -2
- package/dist/compiler/internal/Syntax.js.map +1 -1
- package/dist/compiler/internal/Wire.d.ts +17 -0
- package/dist/compiler/internal/Wire.d.ts.map +1 -0
- package/dist/compiler/internal/Wire.js +795 -0
- package/dist/compiler/internal/Wire.js.map +1 -0
- package/dist/internal/Addon.d.ts +28 -0
- package/dist/internal/Addon.d.ts.map +1 -0
- package/dist/internal/Addon.js +87 -0
- package/dist/internal/Addon.js.map +1 -0
- package/dist/internal/Literal.d.ts +4 -1
- package/dist/internal/Literal.d.ts.map +1 -1
- package/dist/internal/Literal.js +4 -2
- package/dist/internal/Literal.js.map +1 -1
- package/dist/internal/Token.d.ts +2 -1
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js +2 -2
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Vlq.d.ts +14 -0
- package/dist/internal/Vlq.d.ts.map +1 -0
- package/dist/internal/Vlq.js +47 -0
- package/dist/internal/Vlq.js.map +1 -0
- package/dist/internal/Wasm.d.ts +22 -0
- package/dist/internal/Wasm.d.ts.map +1 -0
- package/dist/internal/Wasm.js +83 -0
- package/dist/internal/Wasm.js.map +1 -0
- package/dist/metro/Graph.d.ts +0 -1
- package/dist/metro/Graph.d.ts.map +1 -1
- package/dist/metro/transformer.d.ts.map +1 -1
- package/dist/metro/transformer.js +0 -1
- package/dist/metro/transformer.js.map +1 -1
- package/dist/next/internal/Project.d.ts.map +1 -1
- package/dist/next/internal/Project.js +2 -5
- package/dist/next/internal/Project.js.map +1 -1
- package/dist/node/Host.d.ts.map +1 -1
- package/dist/node/Host.js +0 -2
- package/dist/node/Host.js.map +1 -1
- package/dist/node/internal/Contracts.d.ts.map +1 -1
- package/dist/node/internal/Contracts.js +3 -7
- package/dist/node/internal/Contracts.js.map +1 -1
- package/dist/node/internal/Snapshot.d.ts +0 -1
- package/dist/node/internal/Snapshot.d.ts.map +1 -1
- package/dist/node/internal/Snapshot.js +0 -6
- package/dist/node/internal/Snapshot.js.map +1 -1
- package/dist/runtime/Composition.d.ts +2 -3
- package/dist/runtime/Composition.d.ts.map +1 -1
- package/dist/runtime/Composition.js +51 -30
- package/dist/runtime/Composition.js.map +1 -1
- package/dist/runtime/Recipe.d.ts.map +1 -1
- package/dist/runtime/Recipe.js +16 -12
- package/dist/runtime/Recipe.js.map +1 -1
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +3 -6
- package/dist/unplugin/index.js.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +696 -201
- package/dist/vite/index.js.map +1 -1
- package/dist/web/Css.d.ts +8 -3
- package/dist/web/Css.d.ts.map +1 -1
- package/dist/web/Css.js +5 -721
- package/dist/web/Css.js.map +1 -1
- package/dist/web/internal/Block.d.ts +0 -2
- package/dist/web/internal/Block.d.ts.map +1 -1
- package/dist/web/internal/Block.js +1 -12
- package/dist/web/internal/Block.js.map +1 -1
- package/dist/web/internal/ClassName.d.ts +23 -18
- package/dist/web/internal/ClassName.d.ts.map +1 -1
- package/dist/web/internal/ClassName.js +26 -55
- package/dist/web/internal/ClassName.js.map +1 -1
- package/dist/web/internal/Contributions.d.ts +3 -5
- package/dist/web/internal/Contributions.d.ts.map +1 -1
- package/dist/web/internal/Contributions.js +0 -45
- package/dist/web/internal/Contributions.js.map +1 -1
- package/dist/web/internal/Engine.browser.d.ts +8 -0
- package/dist/web/internal/Engine.browser.d.ts.map +1 -0
- package/dist/web/internal/Engine.browser.js +42 -0
- package/dist/web/internal/Engine.browser.js.map +1 -0
- package/dist/web/internal/Engine.d.ts +9 -0
- package/dist/web/internal/Engine.d.ts.map +1 -0
- package/dist/web/internal/Engine.js +14 -0
- package/dist/web/internal/Engine.js.map +1 -0
- package/dist/web/internal/Themes.d.ts +1 -9
- package/dist/web/internal/Themes.d.ts.map +1 -1
- package/dist/web/internal/Themes.js +3 -221
- package/dist/web/internal/Themes.js.map +1 -1
- package/dist/web/internal/Wasm.generated.d.ts +4 -0
- package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
- package/dist/web/internal/Wasm.generated.js +4 -0
- package/dist/web/internal/Wasm.generated.js.map +1 -0
- package/dist/web/internal/Wire.d.ts +19 -0
- package/dist/web/internal/Wire.d.ts.map +1 -0
- package/dist/web/internal/Wire.js +387 -0
- package/dist/web/internal/Wire.js.map +1 -0
- package/package.json +20 -1
- package/src/babel/index.ts +2 -5
- package/src/babel/internal/Compilation.ts +0 -1
- package/src/compiler/Graph.ts +89 -1930
- package/src/compiler/Native.ts +18 -871
- package/src/compiler/Source.ts +144 -1803
- package/src/compiler/Transform.ts +16 -1315
- package/src/compiler/internal/AtRules.ts +27 -115
- package/src/compiler/internal/Context.ts +11 -0
- package/src/compiler/internal/Results.ts +406 -0
- package/src/compiler/internal/Syntax.ts +0 -3
- package/src/compiler/internal/Wire.ts +1045 -0
- package/src/internal/Addon.ts +118 -0
- package/src/internal/Literal.ts +4 -2
- package/src/internal/Token.ts +2 -2
- package/src/internal/Vlq.ts +59 -0
- package/src/internal/Wasm.ts +111 -0
- package/src/metro/transformer.ts +0 -1
- package/src/next/internal/Project.ts +2 -9
- package/src/node/Host.ts +0 -2
- package/src/node/internal/Contracts.ts +3 -7
- package/src/node/internal/Snapshot.ts +0 -8
- package/src/runtime/Composition.ts +48 -25
- package/src/runtime/Recipe.ts +21 -14
- package/src/unplugin/index.ts +6 -6
- package/src/vite/index.ts +922 -221
- package/src/web/Css.ts +12 -908
- package/src/web/internal/Block.ts +0 -14
- package/src/web/internal/ClassName.ts +52 -85
- package/src/web/internal/Contributions.ts +3 -59
- package/src/web/internal/Engine.browser.ts +51 -0
- package/src/web/internal/Engine.ts +17 -0
- package/src/web/internal/Themes.ts +3 -279
- package/src/web/internal/Wasm.generated.ts +3 -0
- package/src/web/internal/Wire.ts +466 -0
- package/src/web/internal/wasm.d.ts +9 -0
- package/dist/compiler/internal/Applications.d.ts +0 -55
- package/dist/compiler/internal/Applications.d.ts.map +0 -1
- package/dist/compiler/internal/Applications.js +0 -393
- package/dist/compiler/internal/Applications.js.map +0 -1
- package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
- package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
- package/dist/compiler/internal/ColorProfiles.js +0 -84
- package/dist/compiler/internal/ColorProfiles.js.map +0 -1
- package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
- package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
- package/dist/compiler/internal/CompositionBindings.js +0 -89
- package/dist/compiler/internal/CompositionBindings.js.map +0 -1
- package/dist/compiler/internal/Compositions.d.ts +0 -37
- package/dist/compiler/internal/Compositions.d.ts.map +0 -1
- package/dist/compiler/internal/Compositions.js +0 -494
- package/dist/compiler/internal/Compositions.js.map +0 -1
- package/dist/compiler/internal/Configurations.d.ts +0 -26
- package/dist/compiler/internal/Configurations.d.ts.map +0 -1
- package/dist/compiler/internal/Configurations.js +0 -259
- package/dist/compiler/internal/Configurations.js.map +0 -1
- package/dist/compiler/internal/Contract.d.ts +0 -30
- package/dist/compiler/internal/Contract.d.ts.map +0 -1
- package/dist/compiler/internal/Contract.js +0 -753
- package/dist/compiler/internal/Contract.js.map +0 -1
- package/dist/compiler/internal/Contributions.d.ts +0 -54
- package/dist/compiler/internal/Contributions.d.ts.map +0 -1
- package/dist/compiler/internal/Contributions.js +0 -1151
- package/dist/compiler/internal/Contributions.js.map +0 -1
- package/dist/compiler/internal/Descriptors.d.ts +0 -15
- package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
- package/dist/compiler/internal/Descriptors.js +0 -192
- package/dist/compiler/internal/Descriptors.js.map +0 -1
- package/dist/compiler/internal/Dynamic.d.ts +0 -14
- package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
- package/dist/compiler/internal/Dynamic.js +0 -175
- package/dist/compiler/internal/Dynamic.js.map +0 -1
- package/dist/compiler/internal/Expression.d.ts +0 -19
- package/dist/compiler/internal/Expression.d.ts.map +0 -1
- package/dist/compiler/internal/Expression.js +0 -164
- package/dist/compiler/internal/Expression.js.map +0 -1
- package/dist/compiler/internal/Functions.d.ts +0 -5
- package/dist/compiler/internal/Functions.d.ts.map +0 -1
- package/dist/compiler/internal/Functions.js +0 -191
- package/dist/compiler/internal/Functions.js.map +0 -1
- package/dist/compiler/internal/Keyframes.d.ts +0 -5
- package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
- package/dist/compiler/internal/Keyframes.js +0 -51
- package/dist/compiler/internal/Keyframes.js.map +0 -1
- package/dist/compiler/internal/Names.d.ts +0 -5
- package/dist/compiler/internal/Names.d.ts.map +0 -1
- package/dist/compiler/internal/Names.js +0 -37
- package/dist/compiler/internal/Names.js.map +0 -1
- package/dist/compiler/internal/NativeBindings.d.ts +0 -72
- package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
- package/dist/compiler/internal/NativeBindings.js +0 -171
- package/dist/compiler/internal/NativeBindings.js.map +0 -1
- package/dist/compiler/internal/NativeMedia.d.ts +0 -14
- package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
- package/dist/compiler/internal/NativeMedia.js +0 -287
- package/dist/compiler/internal/NativeMedia.js.map +0 -1
- package/dist/compiler/internal/NativeVars.d.ts +0 -28
- package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
- package/dist/compiler/internal/NativeVars.js +0 -160
- package/dist/compiler/internal/NativeVars.js.map +0 -1
- package/dist/compiler/internal/PackedStyles.d.ts +0 -37
- package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
- package/dist/compiler/internal/PackedStyles.js +0 -344
- package/dist/compiler/internal/PackedStyles.js.map +0 -1
- package/dist/compiler/internal/Properties.d.ts +0 -5
- package/dist/compiler/internal/Properties.d.ts.map +0 -1
- package/dist/compiler/internal/Properties.js +0 -82
- package/dist/compiler/internal/Properties.js.map +0 -1
- package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
- package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
- package/dist/compiler/internal/RecipeConditions.js +0 -82
- package/dist/compiler/internal/RecipeConditions.js.map +0 -1
- package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
- package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
- package/dist/compiler/internal/RecipePayloads.js +0 -99
- package/dist/compiler/internal/RecipePayloads.js.map +0 -1
- package/dist/compiler/internal/Recipes.d.ts +0 -32
- package/dist/compiler/internal/Recipes.d.ts.map +0 -1
- package/dist/compiler/internal/Recipes.js +0 -339
- package/dist/compiler/internal/Recipes.js.map +0 -1
- package/dist/compiler/internal/Selectors.d.ts +0 -13
- package/dist/compiler/internal/Selectors.d.ts.map +0 -1
- package/dist/compiler/internal/Selectors.js +0 -280
- package/dist/compiler/internal/Selectors.js.map +0 -1
- package/dist/compiler/internal/Static.d.ts +0 -39
- package/dist/compiler/internal/Static.d.ts.map +0 -1
- package/dist/compiler/internal/Static.js +0 -534
- package/dist/compiler/internal/Static.js.map +0 -1
- package/dist/compiler/internal/Themes.d.ts +0 -190
- package/dist/compiler/internal/Themes.d.ts.map +0 -1
- package/dist/compiler/internal/Themes.js +0 -1577
- package/dist/compiler/internal/Themes.js.map +0 -1
- package/dist/compiler/internal/Vars.d.ts +0 -33
- package/dist/compiler/internal/Vars.d.ts.map +0 -1
- package/dist/compiler/internal/Vars.js +0 -387
- package/dist/compiler/internal/Vars.js.map +0 -1
- package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
- package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
- package/dist/compiler/internal/ViewTransitions.js +0 -68
- package/dist/compiler/internal/ViewTransitions.js.map +0 -1
- package/dist/internal/Cascade.d.ts +0 -74
- package/dist/internal/Cascade.d.ts.map +0 -1
- package/dist/internal/Cascade.js +0 -210
- package/dist/internal/Cascade.js.map +0 -1
- package/src/compiler/internal/Applications.ts +0 -610
- package/src/compiler/internal/ColorProfiles.ts +0 -93
- package/src/compiler/internal/CompositionBindings.ts +0 -120
- package/src/compiler/internal/Compositions.ts +0 -678
- package/src/compiler/internal/Configurations.ts +0 -349
- package/src/compiler/internal/Contract.ts +0 -1028
- package/src/compiler/internal/Contributions.ts +0 -1561
- package/src/compiler/internal/Descriptors.ts +0 -242
- package/src/compiler/internal/Dynamic.ts +0 -275
- package/src/compiler/internal/Expression.ts +0 -218
- package/src/compiler/internal/Functions.ts +0 -206
- package/src/compiler/internal/Keyframes.ts +0 -62
- package/src/compiler/internal/Names.ts +0 -48
- package/src/compiler/internal/NativeBindings.ts +0 -235
- package/src/compiler/internal/NativeMedia.ts +0 -342
- package/src/compiler/internal/NativeVars.ts +0 -231
- package/src/compiler/internal/PackedStyles.ts +0 -473
- package/src/compiler/internal/Properties.ts +0 -121
- package/src/compiler/internal/RecipeConditions.ts +0 -139
- package/src/compiler/internal/RecipePayloads.ts +0 -132
- package/src/compiler/internal/Recipes.ts +0 -531
- package/src/compiler/internal/Selectors.ts +0 -353
- package/src/compiler/internal/Static.ts +0 -784
- package/src/compiler/internal/Themes.ts +0 -2398
- package/src/compiler/internal/Vars.ts +0 -516
- package/src/compiler/internal/ViewTransitions.ts +0 -82
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Rewrites extracted style calls into executable modules with CSS and source maps.
|
|
3
|
+
* The Rust compiler performs the rewrite through the native addon.
|
|
3
4
|
* @module
|
|
4
5
|
*/
|
|
5
6
|
import * as Edits from './internal/Edits.js';
|
|
6
|
-
import * as Token from '../internal/Token.js';
|
|
7
|
-
import * as Applications from './internal/Applications.js';
|
|
8
|
-
import * as Css from '../web/Css.js';
|
|
9
7
|
import * as ClassName from '../web/internal/ClassName.js';
|
|
10
|
-
import * as
|
|
11
|
-
import * as Identity from '../internal/Identity.js';
|
|
12
|
-
import MagicString from 'magic-string';
|
|
13
|
-
import * as Mapping from '@jridgewell/gen-mapping';
|
|
14
|
-
import * as Namespaces from './internal/Namespaces.js';
|
|
15
|
-
import * as Scheme from '../internal/Scheme.js';
|
|
16
|
-
import * as Syntax from './internal/Syntax.js';
|
|
17
|
-
import * as Source from './Source.js';
|
|
8
|
+
import * as Results from './internal/Results.js';
|
|
18
9
|
import * as ThemeRules from '../web/internal/Themes.js';
|
|
19
|
-
import * as Themes from './internal/Themes.js';
|
|
20
|
-
import * as Walker from 'oxc-walker';
|
|
21
10
|
/**
|
|
22
11
|
* Rewrites literal web styles and local themes without evaluation or file access.
|
|
23
12
|
* Direct no-argument applications become props; other definitions become callables.
|
|
@@ -28,956 +17,19 @@ import * as Walker from 'oxc-walker';
|
|
|
28
17
|
* @throws {Css.CompileError} If literal CSS compilation fails.
|
|
29
18
|
*/
|
|
30
19
|
export function compile(options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const extracted = options[Themes.context]?.extracted ?? Source.extract(options);
|
|
34
|
-
const portable = options.compiler === false;
|
|
35
|
-
const portableNames = {};
|
|
36
|
-
if (portable) {
|
|
37
|
-
for (const call of extracted.calls) {
|
|
38
|
-
if (!call.portable)
|
|
39
|
-
throw new Error('CSS-only output requires an explicit id for dynamic styles, variants, and compositions.');
|
|
40
|
-
portableNames[call.name] = call.portable;
|
|
41
|
-
}
|
|
42
|
-
for (const [name, theme] of Object.entries(extracted.vars))
|
|
43
|
-
if ((Object.keys(theme[Token.definition].values).length ||
|
|
44
|
-
extracted.themeCalls.some((call) => (call.name === name ||
|
|
45
|
-
Object.values(call.members ?? {}).includes(name)) &&
|
|
46
|
-
(!call.options ||
|
|
47
|
-
Object.hasOwn(call.options, 'themes') ||
|
|
48
|
-
Object.hasOwn(call.options, 'theme')))) &&
|
|
49
|
-
!theme[Token.definition].contract[Token.identity]?.startsWith('id-'))
|
|
50
|
-
throw new Error('CSS-only themes require an explicit id on Config.create or Vars.define.');
|
|
51
|
-
for (const call of extracted.contributionCalls ?? [])
|
|
52
|
-
if (call.name &&
|
|
53
|
-
!/^(?:--)?z-(?:k|counterstyle|positiontry|colorprofile|fontpalettevalues|custommedia|cssfunction)id-/.test(call.name))
|
|
54
|
-
throw new Error('CSS-only named stylesheet declarations require an explicit id.');
|
|
55
|
-
for (const call of extracted.variableCalls ?? [])
|
|
56
|
-
if (!call.explicit)
|
|
57
|
-
throw new Error('CSS-only output requires an explicit variable id.');
|
|
58
|
-
}
|
|
59
|
-
if (portable) {
|
|
60
|
-
function selectors(style) {
|
|
61
|
-
for (const rule of style.rules ?? []) {
|
|
62
|
-
if (rule.condition &&
|
|
63
|
-
!rule.condition.startsWith('@') &&
|
|
64
|
-
/\.z-style-(?!id-)/.test(rule.condition))
|
|
65
|
-
throw new Error('CSS-only selector references require an explicit style id.');
|
|
66
|
-
selectors(rule.style);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
for (const style of extracted.styles.styles)
|
|
70
|
-
selectors(style);
|
|
71
|
-
}
|
|
72
|
-
const module = new MagicString(options.source);
|
|
73
|
-
const program = (options[Themes.context]?.parsed ?? Syntax.parse(options))
|
|
74
|
-
.program;
|
|
75
|
-
for (const call of extracted.contributionCalls ?? [])
|
|
76
|
-
module.overwrite(call.start, call.end, (() => {
|
|
77
|
-
const typed = /\.[cm]?tsx?$/.test(options.moduleId);
|
|
78
|
-
if (call.kind === 'cssFunction')
|
|
79
|
-
return `((...args${typed ? ': readonly (string | number)[]' : ''}) => ${JSON.stringify(call.name + '(')} + args.map(value => typeof value === 'string' && value.includes(',') && !value.trimStart().startsWith('{') ? '{' + value + '}' : value).join(',') + ')')${typed ? ` as import('zyzz/web').cssFunction.Reference<${JSON.stringify(call.function?.parameters ?? [])}, ${JSON.stringify(call.function?.returns ?? '*')}>` : ''}`;
|
|
80
|
-
if (call.kind === 'customMedia')
|
|
81
|
-
return `${JSON.stringify(`@media (${call.name})`)}${typed ? ` as unknown as import('zyzz/web').customMedia.Reference` : ''}`;
|
|
82
|
-
if (!call.name)
|
|
83
|
-
return 'void 0';
|
|
84
|
-
return `${JSON.stringify(call.name)}${call.kind === 'keyframes' || !typed ? '' : ` as import('zyzz/web').${call.kind}.Reference`}`;
|
|
85
|
-
})());
|
|
86
|
-
const applications = new Map();
|
|
87
|
-
const calls = new Map(extracted.calls.map((call) => [call.start, call]));
|
|
88
|
-
const definitions = new Map();
|
|
89
|
-
const unusedSelections = new Set();
|
|
90
|
-
const identifiers = new Map();
|
|
91
|
-
const localApplications = Applications.create(program, extracted.calls);
|
|
92
|
-
Walker.walk(program, {
|
|
93
|
-
enter(node, parent) {
|
|
94
|
-
localApplications?.enter(node, parent);
|
|
95
|
-
if (node.type === 'VariableDeclarator' &&
|
|
96
|
-
node.init &&
|
|
97
|
-
node.id.type === 'ObjectPattern' &&
|
|
98
|
-
node.id.properties.every((property) => property.type === 'Property' &&
|
|
99
|
-
(property.key.type === 'Identifier'
|
|
100
|
-
? property.key.name
|
|
101
|
-
: property.key.type === 'Literal'
|
|
102
|
-
? property.key.value
|
|
103
|
-
: undefined) !== 'themes' &&
|
|
104
|
-
(property.key.type !== 'Identifier' ||
|
|
105
|
-
property.key.name !== 'variables')))
|
|
106
|
-
unusedSelections.add(Expression.unwrap(node.init).start);
|
|
107
|
-
if (node.type === 'Identifier') {
|
|
108
|
-
const references = identifiers.get(node.name) ?? [];
|
|
109
|
-
references.push(node);
|
|
110
|
-
identifiers.set(node.name, references);
|
|
111
|
-
}
|
|
112
|
-
if (node.type !== 'CallExpression')
|
|
113
|
-
return;
|
|
114
|
-
const call = calls.get(node.start);
|
|
115
|
-
if (!call || node.end !== call.end)
|
|
116
|
-
return;
|
|
117
|
-
const folded = !!call.composition ||
|
|
118
|
-
(!call.recipe &&
|
|
119
|
-
!call.slots &&
|
|
120
|
-
parent?.type === 'CallExpression' &&
|
|
121
|
-
parent.callee === node &&
|
|
122
|
-
!parent.optional &&
|
|
123
|
-
parent.arguments.length === 0);
|
|
124
|
-
applications.set(call.start, {
|
|
125
|
-
end: folded && !call.composition ? parent.end : call.end,
|
|
126
|
-
folded,
|
|
127
|
-
});
|
|
128
|
-
let argument = node.arguments[0]
|
|
129
|
-
? Expression.unwrap(node.arguments[0])
|
|
130
|
-
: undefined;
|
|
131
|
-
if (argument?.type === 'ArrowFunctionExpression')
|
|
132
|
-
argument = Expression.unwrap(argument.body);
|
|
133
|
-
if (call.body)
|
|
134
|
-
definitions.set(call.start, call.body);
|
|
135
|
-
else if (argument?.type === 'ObjectExpression')
|
|
136
|
-
definitions.set(call.start, argument);
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
const found = localApplications?.find() ?? [];
|
|
140
|
-
// Compositions supersede their inputs' classes, so those reads stay unfolded.
|
|
141
|
-
const composing = (application) => extracted.calls.some((call) => (call.composition || call.runtimeComposition) &&
|
|
142
|
-
call.start < application.start &&
|
|
143
|
-
application.end <= call.end);
|
|
144
|
-
const folded = new Set(found.filter((application) => !composing(application) &&
|
|
145
|
-
!extracted.calls.some((call) => call.output === 'html' &&
|
|
146
|
-
call.runtimeComposition?.some((input) => input.applicationStart === application.start))));
|
|
147
|
-
const local = portable || options.development
|
|
148
|
-
? undefined
|
|
149
|
-
: localApplications?.definitions();
|
|
150
|
-
// Styles applied only alone to DOM elements, or inside cx, never meet another
|
|
151
|
-
// style's classes. Atomic ones share rules like independent styles.
|
|
152
|
-
const standalone = new Set([...(local?.values.keys() ?? [])].filter((name) => found.every((application) => application.name !== name ||
|
|
153
|
-
application.terminal ||
|
|
154
|
-
composing(application))));
|
|
155
|
-
// Scheme rules accompany modules whose runtime helpers can apply a scheme class.
|
|
156
|
-
const schemes = options.schemes ??
|
|
157
|
-
Boolean(extracted.themeAppearances?.length ||
|
|
158
|
-
extracted.themeScripts?.length ||
|
|
159
|
-
extracted.themeSelections?.length);
|
|
160
|
-
const emitted = Css.compile({
|
|
161
|
-
[ThemeRules.shared]: options[ThemeRules.shared],
|
|
162
|
-
development: options.development,
|
|
163
|
-
[ClassName.labels]: extracted.styles[ClassName.labels],
|
|
164
|
-
[ClassName.units]: options[ClassName.units] ??
|
|
165
|
-
ClassName.registry().scope({
|
|
166
|
-
owner: options.moduleId,
|
|
167
|
-
qualifier: Identity.compact(options.moduleId).slice(-6),
|
|
168
|
-
}),
|
|
20
|
+
const input = {
|
|
21
|
+
compiler: options.compiler,
|
|
169
22
|
composition: options.composition,
|
|
170
23
|
cssOutput: options.cssOutput,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (portable || options.development)
|
|
177
|
-
return extracted.styles;
|
|
178
|
-
const dead = localApplications?.dead();
|
|
179
|
-
if (!dead?.size && !standalone.size)
|
|
180
|
-
return extracted.styles;
|
|
181
|
-
return {
|
|
182
|
-
styles: extracted.styles.styles.map((style) => {
|
|
183
|
-
if (dead?.has(style.name))
|
|
184
|
-
return {
|
|
185
|
-
cssOutput: style.cssOutput,
|
|
186
|
-
declarations: [],
|
|
187
|
-
name: style.name,
|
|
188
|
-
};
|
|
189
|
-
// Grouped output keeps one class per style.
|
|
190
|
-
return standalone.has(style.name) &&
|
|
191
|
-
(style.cssOutput ?? options.cssOutput ?? 'atomic') === 'atomic'
|
|
192
|
-
? { ...style, composition: 'independent' }
|
|
193
|
-
: style;
|
|
194
|
-
}),
|
|
195
|
-
};
|
|
196
|
-
})(),
|
|
197
|
-
contributions: extracted.contributions,
|
|
198
|
-
vars: Object.keys(extracted.vars).length ? extracted.vars : undefined,
|
|
199
|
-
});
|
|
200
|
-
let runtime = '__zyzzProps';
|
|
201
|
-
while (identifiers.has(runtime))
|
|
202
|
-
runtime += '_';
|
|
203
|
-
let html = '__zyzzHtml';
|
|
204
|
-
while (identifiers.has(html))
|
|
205
|
-
html += '_';
|
|
206
|
-
let usesHtml = false;
|
|
207
|
-
let conditionalRecipe = '__zyzzConditionalRecipe';
|
|
208
|
-
while (identifiers.has(conditionalRecipe))
|
|
209
|
-
conditionalRecipe += '_';
|
|
210
|
-
let usesConditionalRecipe = false;
|
|
211
|
-
let payloadRecipe = '__zyzzPayloadRecipe';
|
|
212
|
-
while (identifiers.has(payloadRecipe))
|
|
213
|
-
payloadRecipe += '_';
|
|
214
|
-
let usesPayloadRecipe = false;
|
|
215
|
-
let recipe = '__zyzzRecipe';
|
|
216
|
-
while (identifiers.has(recipe))
|
|
217
|
-
recipe += '_';
|
|
218
|
-
let usesRecipe = false;
|
|
219
|
-
let compositionHtml = '__zyzzCompositionHtml';
|
|
220
|
-
while (identifiers.has(compositionHtml))
|
|
221
|
-
compositionHtml += '_';
|
|
222
|
-
let usesCompositionHtml = false;
|
|
223
|
-
const preparedHtml = new Set(extracted.calls.flatMap((call) => call.output === 'html'
|
|
224
|
-
? (call.runtimeComposition ?? []).map((input) => input.name)
|
|
225
|
-
: []));
|
|
226
|
-
function prepareExport(link) {
|
|
227
|
-
if (link.style?.output === 'html') {
|
|
228
|
-
const call = extracted.calls.find((call) => call.identity === link.binding);
|
|
229
|
-
if (call)
|
|
230
|
-
preparedHtml.add(call.name);
|
|
231
|
-
}
|
|
232
|
-
for (const member of Object.values(link.members ?? {}))
|
|
233
|
-
prepareExport(member);
|
|
234
|
-
}
|
|
235
|
-
for (const link of Object.values(extracted.themeExports ?? {}))
|
|
236
|
-
prepareExport(link);
|
|
237
|
-
let composition = '__zyzzComposition';
|
|
238
|
-
while (identifiers.has(composition))
|
|
239
|
-
composition += '_';
|
|
240
|
-
let usesComposition = false;
|
|
241
|
-
const compositions = [];
|
|
242
|
-
const compositionArguments = new Map();
|
|
243
|
-
let appearance = '__zyzzAppearance';
|
|
244
|
-
while (identifiers.has(appearance))
|
|
245
|
-
appearance += '_';
|
|
246
|
-
let usesAppearance = false;
|
|
247
|
-
let selection = '__zyzzSelection';
|
|
248
|
-
while (identifiers.has(selection))
|
|
249
|
-
selection += '_';
|
|
250
|
-
let usesSelection = false;
|
|
251
|
-
let variables = '__zyzzVariable';
|
|
252
|
-
while (identifiers.has(variables))
|
|
253
|
-
variables += '_';
|
|
254
|
-
for (const call of extracted.variableCalls ?? [])
|
|
255
|
-
module.overwrite(call.start, call.end, `${variables}.create(${JSON.stringify(call.slots.value)})`);
|
|
256
|
-
const identities = new Map(extracted.calls
|
|
257
|
-
.filter((call) => call.identity)
|
|
258
|
-
.map((call) => [call.name, call.identity]));
|
|
259
|
-
const classes = Object.freeze(Object.fromEntries(Object.entries(emitted.classes).map(([name, value]) => [
|
|
260
|
-
name,
|
|
261
|
-
[
|
|
262
|
-
...new Set([
|
|
263
|
-
...value.split(' ').filter(Boolean),
|
|
264
|
-
...(identities.has(name) &&
|
|
265
|
-
(!portable || portableNames[name]?.startsWith('z-compose-'))
|
|
266
|
-
? [
|
|
267
|
-
portable
|
|
268
|
-
? identities
|
|
269
|
-
.get(name)
|
|
270
|
-
.split(' ')
|
|
271
|
-
.filter((name) => name.startsWith('z-style-id-'))
|
|
272
|
-
.join(' ')
|
|
273
|
-
: identities.get(name),
|
|
274
|
-
]
|
|
275
|
-
: []),
|
|
276
|
-
]),
|
|
277
|
-
].join(' '),
|
|
278
|
-
])));
|
|
279
|
-
// Definitions read only through folded applications need no class list of
|
|
280
|
-
// their own. True marks definitions whose every read follows initialization.
|
|
281
|
-
const unread = new Map([...(local?.values ?? [])].filter(([name]) => found.every((application) => application.name !== name || folded.has(application))));
|
|
282
|
-
const namespaces = (local?.namespaces ?? []).filter((namespace) => [...namespace.ends.keys()].every((name) => unread.get(name)));
|
|
283
|
-
const erased = new Map(namespaces.flatMap((namespace) => [...namespace.ends]));
|
|
284
|
-
// An ambient namespace keeps member types without runtime initialization.
|
|
285
|
-
for (const namespace of namespaces)
|
|
286
|
-
module.prependRight(namespace.start, 'declare ');
|
|
287
|
-
for (const call of extracted.calls) {
|
|
288
|
-
const end = erased.get(call.name);
|
|
289
|
-
if (end !== undefined)
|
|
290
|
-
module.overwrite(end, call.start, `: import('zyzz').style.ReturnType${call.output === 'html' ? "<'html'>" : ''}`);
|
|
291
|
-
}
|
|
292
|
-
let callable = false;
|
|
293
|
-
const composed = (node) => extracted.calls.some((call) => call.composition && call.start < node.start && node.end <= call.end);
|
|
294
|
-
// Rewrite contained expressions before their enclosing composition reads them.
|
|
295
|
-
const rewrites = [...extracted.calls].sort((a, b) => a.start < b.start && a.end >= b.end
|
|
296
|
-
? 1
|
|
297
|
-
: b.start < a.start && b.end >= a.end
|
|
298
|
-
? -1
|
|
299
|
-
: a.start - b.start);
|
|
300
|
-
for (const call of rewrites) {
|
|
301
|
-
if (call.compositionCase || composed(call))
|
|
302
|
-
continue;
|
|
303
|
-
const application = applications.get(call.start);
|
|
304
|
-
const props = `{${call.output === 'html' ? 'class' : 'className'}:${JSON.stringify(classes[call.name])}}`;
|
|
305
|
-
const composeHtml = call.output === 'html' && preparedHtml.has(call.name);
|
|
306
|
-
if (composeHtml)
|
|
307
|
-
usesCompositionHtml = true;
|
|
308
|
-
const replacement = (() => {
|
|
309
|
-
if (call.runtimeComposition) {
|
|
310
|
-
const helper = call.output === 'html' ? compositionHtml : composition;
|
|
311
|
-
if (call.output === 'html')
|
|
312
|
-
usesCompositionHtml = true;
|
|
313
|
-
else
|
|
314
|
-
usesComposition = true;
|
|
315
|
-
let factory = `${composition}${call.start}`;
|
|
316
|
-
while (identifiers.has(factory))
|
|
317
|
-
factory += '_';
|
|
318
|
-
const inputs = call.runtimeComposition.map((input) => ({
|
|
319
|
-
className: classes[input.name] ??
|
|
320
|
-
options[Themes.context]?.styleClasses?.[input.name] ??
|
|
321
|
-
'',
|
|
322
|
-
condition: input.condition,
|
|
323
|
-
owners: input.owners,
|
|
324
|
-
}));
|
|
325
|
-
compositions.push(`const ${factory}=/*#__PURE__*/${helper}.create(${JSON.stringify({ className: classes[call.name], cases: call.compositionCases?.map((name) => classes[name]), inputs })});`);
|
|
326
|
-
return `${factory}(${call.runtimeComposition
|
|
327
|
-
.map((input) => {
|
|
328
|
-
const key = `${input.start}:${input.end}`;
|
|
329
|
-
const value = compositionArguments.get(key) ??
|
|
330
|
-
module.slice(input.start, input.end);
|
|
331
|
-
compositionArguments.set(key, value);
|
|
332
|
-
return value;
|
|
333
|
-
})
|
|
334
|
-
.join(',')})`;
|
|
335
|
-
}
|
|
336
|
-
if (call.composition)
|
|
337
|
-
return call.composition.reduceRight((result, guard) => `((${guard}${/\.[cm]?tsx?$/.test(options.moduleId) ? ' as unknown' : ''})?${result}:${guard}())`, composeHtml
|
|
338
|
-
? `${compositionHtml}.from({className:${JSON.stringify(classes[call.name])}})`
|
|
339
|
-
: `(${props})`);
|
|
340
|
-
if (call.recipe) {
|
|
341
|
-
const helper = call.recipe.conditions?.length
|
|
342
|
-
? conditionalRecipe
|
|
343
|
-
: recipe;
|
|
344
|
-
if (call.recipe.conditions?.length)
|
|
345
|
-
usesConditionalRecipe = true;
|
|
346
|
-
else
|
|
347
|
-
usesRecipe = true;
|
|
348
|
-
const payload = !!call.recipe.payloads?.length;
|
|
349
|
-
if (payload)
|
|
350
|
-
usesPayloadRecipe = true;
|
|
351
|
-
const selection = `${helper}.create(${JSON.stringify({ axes: call.recipe.axes, defaults: call.recipe.defaults, conditions: call.recipe.conditions, className: classes[call.name], ...(!payload && call.output === 'html' && !composeHtml ? { html: true } : {}) })})`;
|
|
352
|
-
const value = payload
|
|
353
|
-
? `${payloadRecipe}.create({...${JSON.stringify({ ...call.recipe, html: call.output === 'html' && !composeHtml })},select:${selection}})`
|
|
354
|
-
: selection;
|
|
355
|
-
const bound = composeHtml ? `${compositionHtml}.bind(${value})` : value;
|
|
356
|
-
const axes = Object.entries(call.recipe.axes)
|
|
357
|
-
.map(([axis, choices]) => `${JSON.stringify(axis)}:{${choices.map((choice) => `${JSON.stringify(choice)}:${call.recipeTypes?.[axis]?.[choice] ? `(values:${call.recipeTypes[axis][choice]})=>{}` : '{}'}`).join(';')}}`)
|
|
358
|
-
.join(';');
|
|
359
|
-
const conditions = call.recipe.conditions
|
|
360
|
-
?.map((name) => `${JSON.stringify(name)}:unknown`)
|
|
361
|
-
.join(';');
|
|
362
|
-
const type = `import('zyzz').variants.ReturnType<{variants:{${axes}}${conditions ? `;conditions:{${conditions}}` : ''}}${call.output === 'html' ? ',"html"' : ''}>`;
|
|
363
|
-
return /\.[cm]?tsx?$/.test(options.moduleId)
|
|
364
|
-
? `(${bound} as ${type})`
|
|
365
|
-
: bound;
|
|
366
|
-
}
|
|
367
|
-
if (call.slots) {
|
|
368
|
-
const type = `import('zyzz').style.Dynamic<${call.valuesType}${call.output === 'html' ? ',"html"' : ''}>`;
|
|
369
|
-
const typed = /\.[cm]?tsx?$/.test(options.moduleId);
|
|
370
|
-
const slots = Object.entries(call.slots);
|
|
371
|
-
const reads = slots
|
|
372
|
-
.map(([key], index) => `const v${index}=input[${JSON.stringify(key)}]${typed ? ' as string | number' : ''};`)
|
|
373
|
-
.join('');
|
|
374
|
-
const assignments = slots
|
|
375
|
-
.map(([, slot], index) => `${JSON.stringify(slot.name)}:v${index}===''?' ':v${index}`)
|
|
376
|
-
.join(',');
|
|
377
|
-
const className = JSON.stringify(classes[call.name]);
|
|
378
|
-
const value = `(input${typed ? `:Parameters<${type}>[0]` : ''})=>{${reads}const external=input.className;const style=input.style;return {className:external?${className}+" "+external:${className},style:{...input.vars,...style,${assignments}}}}`;
|
|
379
|
-
const result = composeHtml
|
|
380
|
-
? `${compositionHtml}.bind(${value})`
|
|
381
|
-
: call.output === 'html'
|
|
382
|
-
? `${html}.bind(${value})`
|
|
383
|
-
: `(${value})`;
|
|
384
|
-
if (call.output === 'html' && !composeHtml)
|
|
385
|
-
usesHtml = true;
|
|
386
|
-
return typed ? `(${result} as ${type})` : result;
|
|
387
|
-
}
|
|
388
|
-
const initialized = unread.get(call.name);
|
|
389
|
-
if (initialized !== undefined) {
|
|
390
|
-
if (erased.has(call.name))
|
|
391
|
-
return '';
|
|
392
|
-
// Guards read only truthiness, and failures before initialization still call it.
|
|
393
|
-
const value = initialized ? 'void 0' : '1';
|
|
394
|
-
return /\.[cm]?tsx?$/.test(options.moduleId)
|
|
395
|
-
? `(${value} as unknown as import('zyzz').style.ReturnType${call.output === 'html' ? "<'html'>" : ''})`
|
|
396
|
-
: value;
|
|
397
|
-
}
|
|
398
|
-
if (application.folded)
|
|
399
|
-
return composeHtml
|
|
400
|
-
? `${compositionHtml}.from({className:${JSON.stringify(classes[call.name])}})`
|
|
401
|
-
: `(${props})`;
|
|
402
|
-
if (call.output === 'html') {
|
|
403
|
-
if (composeHtml) {
|
|
404
|
-
callable = true;
|
|
405
|
-
return `(${compositionHtml}.bind(${runtime}.create({className:${JSON.stringify(classes[call.name])}}))${/\.[cm]?tsx?$/.test(options.moduleId) ? " as import('zyzz').style.ReturnType<'html'>" : ''})`;
|
|
406
|
-
}
|
|
407
|
-
usesHtml = true;
|
|
408
|
-
return `${html}.create({className:${JSON.stringify(classes[call.name])}})`;
|
|
409
|
-
}
|
|
410
|
-
return `${runtime}.create(${props})`;
|
|
411
|
-
})();
|
|
412
|
-
module.overwrite(call.start, application.end, replacement);
|
|
413
|
-
if (!call.recipe &&
|
|
414
|
-
!call.slots &&
|
|
415
|
-
!call.runtimeComposition &&
|
|
416
|
-
!application.folded &&
|
|
417
|
-
!unread.has(call.name) &&
|
|
418
|
-
call.output !== 'html')
|
|
419
|
-
callable = true;
|
|
420
|
-
}
|
|
421
|
-
for (const application of folded) {
|
|
422
|
-
const className = JSON.stringify(classes[application.name]);
|
|
423
|
-
const key = extracted.calls.find((call) => call.name === application.name)?.output ===
|
|
424
|
-
'html'
|
|
425
|
-
? 'class'
|
|
426
|
-
: 'className';
|
|
427
|
-
const callee = options.source.slice(application.start, application.calleeEnd);
|
|
428
|
-
module.overwrite(application.start, application.end, application.initialized
|
|
429
|
-
? `({${key}:${className}})`
|
|
430
|
-
: // Keep a callable guard so bundlers also retain failures before initialization.
|
|
431
|
-
`(${callee}?{${key}:${className}}:${callee}())`);
|
|
432
|
-
}
|
|
433
|
-
for (const call of extracted.themeCalls) {
|
|
434
|
-
const scope = (name) => ({ className: emitted.vars[name] });
|
|
435
|
-
const props = (() => {
|
|
436
|
-
if (call.variableSet)
|
|
437
|
-
return '{}';
|
|
438
|
-
if (!call.members)
|
|
439
|
-
return `{className:${JSON.stringify(emitted.vars[call.name])}}`;
|
|
440
|
-
const script = extracted.themeScripts?.includes(call.name);
|
|
441
|
-
const root = extracted.themeAppearances?.includes(call.name);
|
|
442
|
-
if (script || root)
|
|
443
|
-
usesAppearance = true;
|
|
444
|
-
// Helpers are emitted only when referenced; both share the configured storage key.
|
|
445
|
-
const storage = call.options?.storageKey;
|
|
446
|
-
const helpers = (entries, defaultTheme) => {
|
|
447
|
-
const scriptOptions = storage
|
|
448
|
-
? `,${JSON.stringify({ storageKey: storage })}`
|
|
449
|
-
: '';
|
|
450
|
-
const rootOptions = storage || defaultTheme
|
|
451
|
-
? `,${JSON.stringify({ ...(defaultTheme ? { defaultVars: defaultTheme } : {}), ...(storage ? { storageKey: storage } : {}) })}`
|
|
452
|
-
: '';
|
|
453
|
-
return `${root ? `appearance:${appearance}.root(${entries}${rootOptions}),` : ''}${script ? `script:${appearance}.create(${entries}${scriptOptions}),` : ''}`;
|
|
454
|
-
};
|
|
455
|
-
if (call.variableConfig) {
|
|
456
|
-
const selected = extracted.themeSelections?.includes(call.name) ||
|
|
457
|
-
Object.values(extracted.themeExports ?? {}).some((link) => link.call.name === call.name &&
|
|
458
|
-
link.kind === 'config' &&
|
|
459
|
-
!link.call.initialization &&
|
|
460
|
-
!link.call.root);
|
|
461
|
-
const entries = call.options?.themes
|
|
462
|
-
? Object.entries(call.members)
|
|
463
|
-
.filter(([key]) => {
|
|
464
|
-
const path = JSON.parse(key);
|
|
465
|
-
return path[0] === 'themes' && path.length === 2;
|
|
466
|
-
})
|
|
467
|
-
.map(([key, name]) => [
|
|
468
|
-
JSON.parse(key)[1],
|
|
469
|
-
emitted.vars[name],
|
|
470
|
-
])
|
|
471
|
-
: [['default', emitted.vars[call.name]]];
|
|
472
|
-
const fallback = call.options?.defaultTheme ?? 'default';
|
|
473
|
-
if (!selected)
|
|
474
|
-
return `{${helpers(JSON.stringify(call.options?.themes ? entries : []), call.options?.themes ? String(fallback) : undefined).replace(/,$/, '')}}`;
|
|
475
|
-
usesSelection = true;
|
|
476
|
-
const selector = `${selection}.create(${JSON.stringify(entries)},${call.options?.output === 'html'},'set',${JSON.stringify(fallback)})`;
|
|
477
|
-
// Rollup drops required selectors when a pure call initializes a destructured object property.
|
|
478
|
-
return `{${helpers(JSON.stringify(call.options?.themes ? entries : []), call.options?.themes ? String(fallback) : undefined)}vars:${selector}}`;
|
|
479
|
-
}
|
|
480
|
-
if (call.options?.themes) {
|
|
481
|
-
const catalog = Object.fromEntries(Object.entries(call.members)
|
|
482
|
-
.filter(([key]) => JSON.parse(key).length === 2)
|
|
483
|
-
.map(([key, name]) => [
|
|
484
|
-
JSON.parse(key)[1],
|
|
485
|
-
emitted.vars[name],
|
|
486
|
-
]));
|
|
487
|
-
const entries = JSON.stringify(Object.entries(catalog));
|
|
488
|
-
const defaultTheme = typeof call.options.defaultTheme === 'string'
|
|
489
|
-
? call.options.defaultTheme
|
|
490
|
-
: undefined;
|
|
491
|
-
if (unusedSelections.has(call.start))
|
|
492
|
-
return `{${helpers(entries, defaultTheme)}theme:${JSON.stringify(scope(call.members['["theme"]']))}}`;
|
|
493
|
-
usesSelection = true;
|
|
494
|
-
return `{${helpers(entries, defaultTheme)}theme:${JSON.stringify(scope(call.members['["theme"]']))},themes:/*#__PURE__*/${selection}.create(${entries},${call.options.output === 'html'})}`;
|
|
495
|
-
}
|
|
496
|
-
if (Object.hasOwn(call.members, '["theme"]'))
|
|
497
|
-
return `{${helpers('[]')}theme:${JSON.stringify(scope(call.members['["theme"]']))}}`;
|
|
498
|
-
return script || root ? `{${helpers('[]').slice(0, -1)}}` : '{}';
|
|
499
|
-
})();
|
|
500
|
-
const assertion = /\.[cm]?tsx?$/.test(options.moduleId)
|
|
501
|
-
? ` as ${call.type ?? `import('zyzz').Vars.Definition<${call.tokenType}>`}`
|
|
502
|
-
: '';
|
|
503
|
-
module.overwrite(call.start, call.end, `(${props}${assertion})`);
|
|
504
|
-
}
|
|
505
|
-
for (const alias of extracted.themeAliases) {
|
|
506
|
-
if (alias.retained) {
|
|
507
|
-
if (/\.[cm]?tsx?$/.test(options.moduleId))
|
|
508
|
-
module.overwrite(alias.start, alias.end, `(${options.source.slice(alias.start, alias.end)} as ${alias.type ?? `import('zyzz').Vars.Definition<${alias.tokenType}>`})`);
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
const member = alias.recipe ? 'variants' : 'style';
|
|
512
|
-
const members = [...new Set(alias.bindings ?? [member])];
|
|
513
|
-
const value = alias.destructured
|
|
514
|
-
? `{${members.map((member) => `${member}:undefined`).join(',')}}`
|
|
515
|
-
: 'undefined';
|
|
516
|
-
const type = alias.type ?? `import('zyzz').Vars.Definition<${alias.tokenType}>`;
|
|
517
|
-
const assertion = /\.[cm]?tsx?$/.test(options.moduleId)
|
|
518
|
-
? ` as unknown as ${alias.destructured ? `{${members.map((member) => `readonly ${member}:${type}['${member}']`).join(';')}}` : `${type}['${member}']`}`
|
|
519
|
-
: '';
|
|
520
|
-
module.overwrite(alias.start, alias.end, `(${value}${assertion})`);
|
|
521
|
-
}
|
|
522
|
-
const replacements = [
|
|
523
|
-
...extracted.calls.map((call) => ({
|
|
524
|
-
end: applications.get(call.start).end,
|
|
525
|
-
start: call.start,
|
|
526
|
-
})),
|
|
527
|
-
...(extracted.contributionCalls ?? []),
|
|
528
|
-
...(extracted.variableCalls ?? []),
|
|
529
|
-
...extracted.themeAliases,
|
|
530
|
-
...extracted.themeCalls,
|
|
531
|
-
].sort((a, b) => a.start - b.start);
|
|
532
|
-
function replaced(reference) {
|
|
533
|
-
let low = 0;
|
|
534
|
-
let high = replacements.length;
|
|
535
|
-
while (low < high) {
|
|
536
|
-
const middle = (low + high) >>> 1;
|
|
537
|
-
if (replacements[middle].start <= reference.start)
|
|
538
|
-
low = middle + 1;
|
|
539
|
-
else
|
|
540
|
-
high = middle;
|
|
541
|
-
}
|
|
542
|
-
const call = replacements[low - 1];
|
|
543
|
-
return call !== undefined && reference.end <= call.end;
|
|
544
|
-
}
|
|
545
|
-
for (const reference of extracted.staticThemeReferences ?? [])
|
|
546
|
-
if (!replaced(reference))
|
|
547
|
-
module.overwrite(reference.start, reference.end, JSON.stringify(reference.value));
|
|
548
|
-
for (const reference of extracted.themeReferences)
|
|
549
|
-
if (!replaced(reference))
|
|
550
|
-
module.overwrite(reference.start, reference.end, JSON.stringify(emitted.vars[reference.name]));
|
|
551
|
-
replacements.push(...extracted.themeReferences, ...(extracted.staticThemeReferences ?? []));
|
|
552
|
-
replacements.sort((a, b) => a.start - b.start);
|
|
553
|
-
for (const node of program.body) {
|
|
554
|
-
if (node.type !== 'ImportDeclaration' ||
|
|
555
|
-
!['zyzz', 'zyzz/web'].includes(node.source.value))
|
|
556
|
-
continue;
|
|
557
|
-
const removed = new Set();
|
|
558
|
-
for (const specifier of node.specifiers) {
|
|
559
|
-
if (node.importKind === 'type' ||
|
|
560
|
-
specifier.type !== 'ImportSpecifier' ||
|
|
561
|
-
specifier.importKind === 'type' ||
|
|
562
|
-
!(node.source.value === 'zyzz'
|
|
563
|
-
? [
|
|
564
|
-
'Config',
|
|
565
|
-
'cx',
|
|
566
|
-
'defineConfig',
|
|
567
|
-
'defineVars',
|
|
568
|
-
'extendVars',
|
|
569
|
-
'style',
|
|
570
|
-
'Vars',
|
|
571
|
-
'variable',
|
|
572
|
-
'variants',
|
|
573
|
-
]
|
|
574
|
-
: [
|
|
575
|
-
'Css',
|
|
576
|
-
'cssFunction',
|
|
577
|
-
'customMedia',
|
|
578
|
-
'importCss',
|
|
579
|
-
'namespace',
|
|
580
|
-
'colorProfile',
|
|
581
|
-
'counterStyle',
|
|
582
|
-
'fontPaletteValues',
|
|
583
|
-
'fontFeatureValues',
|
|
584
|
-
'page',
|
|
585
|
-
'property',
|
|
586
|
-
'viewTransition',
|
|
587
|
-
'global',
|
|
588
|
-
'fontFace',
|
|
589
|
-
'keyframes',
|
|
590
|
-
'layers',
|
|
591
|
-
'positionTry',
|
|
592
|
-
]).includes(specifier.imported.type === 'Identifier'
|
|
593
|
-
? specifier.imported.name
|
|
594
|
-
: specifier.imported.value))
|
|
595
|
-
continue;
|
|
596
|
-
// Conservative retention also protects type queries and shadowed references.
|
|
597
|
-
const remaining = identifiers
|
|
598
|
-
.get(specifier.local.name)
|
|
599
|
-
?.some((reference) => !(reference.start >= node.start && reference.end <= node.end) &&
|
|
600
|
-
!replaced(reference));
|
|
601
|
-
if (!remaining)
|
|
602
|
-
removed.add(specifier);
|
|
603
|
-
}
|
|
604
|
-
if (!removed.size)
|
|
605
|
-
continue;
|
|
606
|
-
const retained = node.specifiers.filter((specifier) => !removed.has(specifier));
|
|
607
|
-
if (!retained.length)
|
|
608
|
-
module.remove(node.start, node.end);
|
|
609
|
-
else if (retained.every((specifier) => specifier.type !== 'ImportSpecifier')) {
|
|
610
|
-
module.overwrite(node.start, node.source.start, `import ${retained.map((specifier) => options.source.slice(specifier.start, specifier.end)).join(', ')} from `);
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
// Preserve the import source, attributes, and untouched specifier spelling.
|
|
614
|
-
for (let index = 0; index < node.specifiers.length; index++) {
|
|
615
|
-
const specifier = node.specifiers[index];
|
|
616
|
-
if (!removed.has(specifier))
|
|
617
|
-
continue;
|
|
618
|
-
const next = node.specifiers[index + 1];
|
|
619
|
-
const previous = node.specifiers[index - 1];
|
|
620
|
-
if (next)
|
|
621
|
-
module.remove(specifier.start, next.start);
|
|
622
|
-
else if (previous)
|
|
623
|
-
module.remove(previous.end, specifier.end);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
if (callable ||
|
|
628
|
-
usesRecipe ||
|
|
629
|
-
usesComposition ||
|
|
630
|
-
usesCompositionHtml ||
|
|
631
|
-
usesConditionalRecipe ||
|
|
632
|
-
usesPayloadRecipe ||
|
|
633
|
-
usesHtml ||
|
|
634
|
-
usesSelection ||
|
|
635
|
-
usesAppearance ||
|
|
636
|
-
extracted.variableCalls?.length) {
|
|
637
|
-
// Insertion after a hashbang keeps executable module syntax intact.
|
|
638
|
-
let offset = options.source.startsWith('#!')
|
|
639
|
-
? options.source.indexOf('\n') + 1
|
|
640
|
-
: 0;
|
|
641
|
-
for (const node of program.body) {
|
|
642
|
-
if (node.type !== 'ExpressionStatement' || !node.directive)
|
|
643
|
-
break;
|
|
644
|
-
offset = node.end;
|
|
645
|
-
}
|
|
646
|
-
if (compositions.length)
|
|
647
|
-
module.appendLeft(offset, '\n' + compositions.join('\n') + '\n');
|
|
648
|
-
module.appendLeft(offset, `\nimport { ${[usesAppearance ? `Appearance as ${appearance}` : '', usesComposition ? `Composition as ${composition}` : '', usesCompositionHtml ? `CompositionHtml as ${compositionHtml}` : '', usesConditionalRecipe ? `ConditionalRecipe as ${conditionalRecipe}` : '', usesHtml ? `Html as ${html}` : '', usesPayloadRecipe ? `PayloadRecipe as ${payloadRecipe}` : '', callable ? `Props as ${runtime}` : '', usesRecipe ? `Recipe as ${recipe}` : '', usesSelection ? `Selection as ${selection}` : '', extracted.variableCalls?.length ? `Variable as ${variables}` : ''].filter(Boolean).join(', ')} } from 'zyzz/runtime';\n`);
|
|
649
|
-
}
|
|
650
|
-
const cssMap = new Mapping.GenMapping({ file: `${options.moduleId}.css` });
|
|
651
|
-
Mapping.setSourceContent(cssMap, options.moduleId, options.source);
|
|
652
|
-
const lines = [0];
|
|
653
|
-
for (let index = 0; index < options.source.length; index++)
|
|
654
|
-
if (options.source[index] === '\n')
|
|
655
|
-
lines.push(index + 1);
|
|
656
|
-
function position(offset) {
|
|
657
|
-
let low = 0;
|
|
658
|
-
let high = lines.length;
|
|
659
|
-
while (low + 1 < high) {
|
|
660
|
-
const middle = (low + high) >>> 1;
|
|
661
|
-
if (lines[middle] <= offset)
|
|
662
|
-
low = middle;
|
|
663
|
-
else
|
|
664
|
-
high = middle;
|
|
665
|
-
}
|
|
666
|
-
return { column: offset - lines[low], line: low + 1 };
|
|
667
|
-
}
|
|
668
|
-
const owners = new Map();
|
|
669
|
-
for (const call of extracted.calls)
|
|
670
|
-
for (const name of emitted.classes[call.name].split(' '))
|
|
671
|
-
if (!owners.has(name))
|
|
672
|
-
owners.set(name, call);
|
|
673
|
-
const styles = new Map(extracted.styles.styles.map((style) => [style.name, style]));
|
|
674
|
-
const themeOwners = new Map(extracted.themeCalls.flatMap((call) => [...new Set([call.name, ...Object.values(call.members ?? {})])].map((name) => [emitted.vars[name], { ...call, name }])));
|
|
675
|
-
const linkedOwners = new Map(Object.entries(options[Themes.context]?.owners ?? {}).map(([key, owner]) => [emitted.vars[key], owner]));
|
|
676
|
-
// Literal and scalar-theme rules each occupy one line at this boundary.
|
|
677
|
-
const prefix = emitted.contributionCss ?? '';
|
|
678
|
-
const contributions = (extracted.contributions ?? []).map((definition, index) => ({
|
|
679
|
-
definition,
|
|
680
|
-
start: extracted.contributionStarts?.[index],
|
|
681
|
-
}));
|
|
682
|
-
const rank = (kind) => kind === 'import' ? 0 : kind === 'namespace' ? 1 : 2;
|
|
683
|
-
const layered = contributions.find((value) => value.definition.kind === 'layers' && value.definition.names.length > 0);
|
|
684
|
-
let contributionLine = 1;
|
|
685
|
-
if (layered) {
|
|
686
|
-
if (layered.start !== undefined)
|
|
687
|
-
Mapping.addMapping(cssMap, {
|
|
688
|
-
generated: { line: contributionLine, column: 0 },
|
|
689
|
-
original: position(layered.start),
|
|
690
|
-
source: options.moduleId,
|
|
691
|
-
});
|
|
692
|
-
contributionLine++;
|
|
693
|
-
}
|
|
694
|
-
for (const contribution of contributions.toSorted((a, b) => rank(a.definition.kind) - rank(b.definition.kind))) {
|
|
695
|
-
if (contribution.definition.kind === 'layers')
|
|
696
|
-
continue;
|
|
697
|
-
const rendered = Css.compile({
|
|
698
|
-
styles: { styles: [] },
|
|
699
|
-
contributions: [contribution.definition],
|
|
700
|
-
vars: Object.keys(extracted.vars).length ? extracted.vars : undefined,
|
|
701
|
-
}).contributionCss ?? '';
|
|
702
|
-
if (!rendered)
|
|
703
|
-
continue;
|
|
704
|
-
for (const _ of rendered.split('\n')) {
|
|
705
|
-
if (contribution.start !== undefined)
|
|
706
|
-
Mapping.addMapping(cssMap, {
|
|
707
|
-
generated: { line: contributionLine, column: 0 },
|
|
708
|
-
original: position(contribution.start),
|
|
709
|
-
source: options.moduleId,
|
|
710
|
-
});
|
|
711
|
-
contributionLine++;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
const declarationOwners = new Map();
|
|
715
|
-
const scoped = emitted.scopedCss ?? emitted.css;
|
|
716
|
-
const css = [
|
|
717
|
-
prefix,
|
|
718
|
-
(scoped ? scoped.split('\n') : [])
|
|
719
|
-
.map((rule, index) => {
|
|
720
|
-
const line = index + 1 + (prefix ? prefix.split('\n').length : 0);
|
|
721
|
-
const openers = new Map();
|
|
722
|
-
const conditionStarts = declarationStarts(rule, true, openers);
|
|
723
|
-
const selectorStart = conditionStarts.find((start) => rule[start] === '.') ?? 0;
|
|
724
|
-
const brace = openers.get(selectorStart) ?? rule.indexOf('{');
|
|
725
|
-
const name = rule
|
|
726
|
-
.slice(selectorStart + 1, brace)
|
|
727
|
-
.replace(/\\([0-9a-f]+) ?/gi, (_, code) => String.fromCodePoint(Number.parseInt(code, 16)));
|
|
728
|
-
const linkedOwner = linkedOwners.get(name);
|
|
729
|
-
if (linkedOwner) {
|
|
730
|
-
const lines = linkedOwner.source
|
|
731
|
-
.slice(0, linkedOwner.call.start)
|
|
732
|
-
.split('\n');
|
|
733
|
-
Mapping.setSourceContent(cssMap, linkedOwner.moduleId, linkedOwner.source);
|
|
734
|
-
Mapping.addMapping(cssMap, {
|
|
735
|
-
generated: { column: 0, line },
|
|
736
|
-
name: linkedOwner.call.name,
|
|
737
|
-
original: { line: lines.length, column: lines.at(-1).length },
|
|
738
|
-
source: linkedOwner.moduleId,
|
|
739
|
-
});
|
|
740
|
-
return rule;
|
|
741
|
-
}
|
|
742
|
-
const themeOwner = themeOwners.get(name);
|
|
743
|
-
if (themeOwner) {
|
|
744
|
-
Mapping.addMapping(cssMap, {
|
|
745
|
-
generated: { column: 0, line },
|
|
746
|
-
name: themeOwner.name,
|
|
747
|
-
original: position(themeOwner.start),
|
|
748
|
-
source: options.moduleId,
|
|
749
|
-
});
|
|
750
|
-
return rule;
|
|
751
|
-
}
|
|
752
|
-
if (Object.values(emitted.vars).includes(name)) {
|
|
753
|
-
// Packed theme declarations have no authored source in this graph.
|
|
754
|
-
Mapping.addMapping(cssMap, { generated: { column: 0, line } });
|
|
755
|
-
return rule;
|
|
756
|
-
}
|
|
757
|
-
if (Object.values(Scheme.classes).includes(name)) {
|
|
758
|
-
// Scheme selection rules accompany the scopes and have no authored source.
|
|
759
|
-
Mapping.addMapping(cssMap, { generated: { column: 0, line } });
|
|
760
|
-
return rule;
|
|
761
|
-
}
|
|
762
|
-
if (rule.startsWith(':root{') ||
|
|
763
|
-
rule.startsWith(':where(*){--z-') ||
|
|
764
|
-
(rule.startsWith('@media ') &&
|
|
765
|
-
(rule.includes(':root{') ||
|
|
766
|
-
rule.includes(':where(*){--z-') ||
|
|
767
|
-
Object.values(emitted.vars).some((name) => rule.includes(`.${name}{`))))) {
|
|
768
|
-
Mapping.addMapping(cssMap, { generated: { column: 0, line } });
|
|
769
|
-
return rule;
|
|
770
|
-
}
|
|
771
|
-
const selector = `.${ClassName.selector(name)}`;
|
|
772
|
-
const call = owners.get(name);
|
|
773
|
-
Mapping.addMapping(cssMap, {
|
|
774
|
-
generated: { column: selectorStart, line },
|
|
775
|
-
name: call.name,
|
|
776
|
-
original: position(call.start),
|
|
777
|
-
source: options.moduleId,
|
|
778
|
-
});
|
|
779
|
-
const body = rule.slice(brace);
|
|
780
|
-
const style = styles.get(call.name);
|
|
781
|
-
function declarations(style) {
|
|
782
|
-
return style.rules
|
|
783
|
-
? style.rules.flatMap((rule) => declarations(rule.style))
|
|
784
|
-
: style.declarations;
|
|
785
|
-
}
|
|
786
|
-
const conditionNodes = [];
|
|
787
|
-
function locations(node) {
|
|
788
|
-
return node.properties.flatMap((property) => {
|
|
789
|
-
if (property.type !== 'Property')
|
|
790
|
-
return [];
|
|
791
|
-
const value = Expression.unwrap(property.value);
|
|
792
|
-
if (value.type === 'ObjectExpression') {
|
|
793
|
-
const key = property.key.type === 'Identifier'
|
|
794
|
-
? property.key.name
|
|
795
|
-
: property.key.type === 'Literal'
|
|
796
|
-
? property.key.value
|
|
797
|
-
: undefined;
|
|
798
|
-
if (key !== 'selectors')
|
|
799
|
-
conditionNodes.push(property);
|
|
800
|
-
return locations(value);
|
|
801
|
-
}
|
|
802
|
-
const key = property.key.type === 'Identifier'
|
|
803
|
-
? property.key.name
|
|
804
|
-
: property.key.type === 'Literal'
|
|
805
|
-
? String(property.key.value)
|
|
806
|
-
: '';
|
|
807
|
-
if (key === 'typography' && call.typography?.has(property.start)) {
|
|
808
|
-
conditionNodes.push(...Array.from({ length: call.typographyQueries?.get(property.start) ?? 0 }, () => property));
|
|
809
|
-
return Array.from({ length: call.typography.get(property.start) }, () => property);
|
|
810
|
-
}
|
|
811
|
-
const authoredLocations = value.type === 'ArrayExpression'
|
|
812
|
-
? value.elements.filter((node) => node !== null)
|
|
813
|
-
: [property];
|
|
814
|
-
return (call.shorthands?.[key] ?? [key]).flatMap(() => authoredLocations);
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
const ordered = declarations(style);
|
|
818
|
-
const authored = locations(call.body ?? definitions.get(call.start));
|
|
819
|
-
const conditions = [];
|
|
820
|
-
function collectConditions(style) {
|
|
821
|
-
for (const rule of style.rules ?? []) {
|
|
822
|
-
if (rule.condition !== undefined)
|
|
823
|
-
conditions.push(rule.condition);
|
|
824
|
-
collectConditions(rule.style);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
collectConditions(style);
|
|
828
|
-
const mappedConditions = new Set();
|
|
829
|
-
for (const start of conditionStarts) {
|
|
830
|
-
const condition = rule.slice(start, openers.get(start));
|
|
831
|
-
const index = conditions.findIndex((value, index) => value === condition && !mappedConditions.has(index));
|
|
832
|
-
const node = conditionNodes[index];
|
|
833
|
-
if (!node)
|
|
834
|
-
continue;
|
|
835
|
-
mappedConditions.add(index);
|
|
836
|
-
Mapping.addMapping(cssMap, {
|
|
837
|
-
generated: {
|
|
838
|
-
column: start +
|
|
839
|
-
(start > brace ? selector.length - (brace - selectorStart) : 0),
|
|
840
|
-
line,
|
|
841
|
-
},
|
|
842
|
-
name: options.source.slice(node.key.start, node.key.end),
|
|
843
|
-
original: position(node.key.start),
|
|
844
|
-
source: options.moduleId,
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
const starts = declarationStarts(body);
|
|
848
|
-
const used = declarationOwners.get(call.name) ?? new Set();
|
|
849
|
-
declarationOwners.set(call.name, used);
|
|
850
|
-
let cursor = 1;
|
|
851
|
-
for (let propertyIndex = 0; propertyIndex < ordered.length; propertyIndex++) {
|
|
852
|
-
if (used.has(propertyIndex))
|
|
853
|
-
continue;
|
|
854
|
-
const declaration = ordered[propertyIndex];
|
|
855
|
-
const text = `${declaration.property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}:`;
|
|
856
|
-
const start = starts.find((start) => start >= cursor && body.startsWith(text, start)) ?? -1;
|
|
857
|
-
if (start < 0)
|
|
858
|
-
continue;
|
|
859
|
-
// Composed packed entries can expand differently from the composite's shorthands.
|
|
860
|
-
const location = authored[propertyIndex];
|
|
861
|
-
if (!location)
|
|
862
|
-
continue;
|
|
863
|
-
used.add(propertyIndex);
|
|
864
|
-
Mapping.addMapping(cssMap, {
|
|
865
|
-
generated: {
|
|
866
|
-
column: selectorStart + selector.length + start,
|
|
867
|
-
line,
|
|
868
|
-
},
|
|
869
|
-
name: declaration.property,
|
|
870
|
-
original: position(location.start),
|
|
871
|
-
source: options.moduleId,
|
|
872
|
-
});
|
|
873
|
-
cursor = start + text.length;
|
|
874
|
-
}
|
|
875
|
-
return rule.slice(0, selectorStart) + selector + body;
|
|
876
|
-
})
|
|
877
|
-
.join('\n'),
|
|
878
|
-
]
|
|
879
|
-
.filter(Boolean)
|
|
880
|
-
.join('\n');
|
|
881
|
-
const map = (portable ? new MagicString(options.source) : module).generateMap({
|
|
882
|
-
hires: true,
|
|
883
|
-
includeContent: true,
|
|
884
|
-
source: options.moduleId,
|
|
885
|
-
});
|
|
886
|
-
const namespaced = Namespaces.rewrite(css, extracted.namespaces ?? [], Mapping.toEncodedMap(cssMap), true);
|
|
887
|
-
const result = {
|
|
888
|
-
...(emitted[ThemeRules.shared]
|
|
889
|
-
? { [ThemeRules.shared]: emitted[ThemeRules.shared] }
|
|
890
|
-
: {}),
|
|
891
|
-
[ClassName.rules]: emitted[ClassName.rules],
|
|
892
|
-
[ClassName.units]: emitted[ClassName.units],
|
|
893
|
-
classes,
|
|
894
|
-
code: portable ? options.source : module.toString(),
|
|
895
|
-
css: namespaced.css,
|
|
896
|
-
cssMap: namespaced.map ?? Mapping.toEncodedMap(cssMap),
|
|
897
|
-
map: {
|
|
898
|
-
file: options.moduleId,
|
|
899
|
-
mappings: map.mappings,
|
|
900
|
-
names: map.names,
|
|
901
|
-
sources: map.sources,
|
|
902
|
-
sourcesContent: map.sourcesContent,
|
|
903
|
-
version: 3,
|
|
904
|
-
},
|
|
905
|
-
vars: emitted.vars,
|
|
24
|
+
development: options.development,
|
|
25
|
+
moduleId: options.moduleId,
|
|
26
|
+
schemes: options.schemes,
|
|
27
|
+
shared: options[ThemeRules.shared],
|
|
28
|
+
target: options.target,
|
|
906
29
|
};
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
/** Locates emitted declarations while skipping selectors, conditions, and quoted CSS data. */
|
|
912
|
-
function declarationStarts(body, conditions = false, openers) {
|
|
913
|
-
const starts = [];
|
|
914
|
-
let start = 0;
|
|
915
|
-
let depth = 0;
|
|
916
|
-
let blocks = 0;
|
|
917
|
-
let custom = false;
|
|
918
|
-
let quote = '';
|
|
919
|
-
for (let index = 0; index < body.length; index++) {
|
|
920
|
-
const char = body[index];
|
|
921
|
-
if (char === '\\') {
|
|
922
|
-
index++;
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
if (quote) {
|
|
926
|
-
if (char === quote)
|
|
927
|
-
quote = '';
|
|
928
|
-
continue;
|
|
929
|
-
}
|
|
930
|
-
if (char === '"' || char === "'") {
|
|
931
|
-
quote = char;
|
|
932
|
-
continue;
|
|
933
|
-
}
|
|
934
|
-
if (char === '/' && body[index + 1] === '*') {
|
|
935
|
-
const end = body.indexOf('*/', index + 2);
|
|
936
|
-
if (end < 0)
|
|
937
|
-
break;
|
|
938
|
-
index = end + 1;
|
|
939
|
-
continue;
|
|
940
|
-
}
|
|
941
|
-
if (char === '(' || char === '[') {
|
|
942
|
-
depth++;
|
|
943
|
-
continue;
|
|
944
|
-
}
|
|
945
|
-
if (char === ')' || char === ']') {
|
|
946
|
-
depth--;
|
|
947
|
-
continue;
|
|
948
|
-
}
|
|
949
|
-
if (depth)
|
|
950
|
-
continue;
|
|
951
|
-
if (char === ':' && body.slice(start, index).trimStart().startsWith('--'))
|
|
952
|
-
custom = true;
|
|
953
|
-
if (char === '{') {
|
|
954
|
-
if (custom)
|
|
955
|
-
blocks++;
|
|
956
|
-
else {
|
|
957
|
-
if (conditions && index > start) {
|
|
958
|
-
starts.push(start);
|
|
959
|
-
openers?.set(start, index);
|
|
960
|
-
}
|
|
961
|
-
start = index + 1;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
else if (char === '}') {
|
|
965
|
-
if (blocks)
|
|
966
|
-
blocks--;
|
|
967
|
-
else {
|
|
968
|
-
start = index + 1;
|
|
969
|
-
custom = false;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
else if (char === ';' && !blocks) {
|
|
973
|
-
while (/\s/.test(body[start] ?? '') && start < index)
|
|
974
|
-
start++;
|
|
975
|
-
if (!conditions)
|
|
976
|
-
starts.push(start);
|
|
977
|
-
start = index + 1;
|
|
978
|
-
custom = false;
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
return starts;
|
|
30
|
+
// Untyped callers can pass other values, which the engine reads from JSON as before.
|
|
31
|
+
if (typeof options.source !== 'string')
|
|
32
|
+
return Results.transform({ ...input, source: options.source });
|
|
33
|
+
return Results.transform(input, options.source);
|
|
982
34
|
}
|
|
983
35
|
//# sourceMappingURL=Transform.js.map
|