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,753 +0,0 @@
|
|
|
1
|
-
import * as Config from '../../internal/Configuration.js';
|
|
2
|
-
import * as Configurations from './Configurations.js';
|
|
3
|
-
import * as FunctionSyntax from '../../internal/FunctionSyntax.js';
|
|
4
|
-
import * as Identifiers from './Identifiers.js';
|
|
5
|
-
import * as PackedStyles from './PackedStyles.js';
|
|
6
|
-
import * as Shorthands from '../../internal/Shorthands.js';
|
|
7
|
-
import * as Stylesheets from './Stylesheets.js';
|
|
8
|
-
import * as Theme from '../../internal/Theme.js';
|
|
9
|
-
import * as VariableSets from '../../internal/VariableSets.js';
|
|
10
|
-
import * as Vars from '../../Vars.js';
|
|
11
|
-
import * as Token from '../../internal/Token.js';
|
|
12
|
-
/** Reads versioned JSON as validated data; never evaluates package code. */
|
|
13
|
-
export function read(source, identities, moduleId = '') {
|
|
14
|
-
const data = record(JSON.parse(source));
|
|
15
|
-
if (![
|
|
16
|
-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
|
|
17
|
-
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
|
|
18
|
-
].includes(data.version))
|
|
19
|
-
throw new Error('Unsupported Zyzz contract version.');
|
|
20
|
-
// Root controls arrived with version 18; older readers must treat them as absent.
|
|
21
|
-
const rootControls = data.version >= 18;
|
|
22
|
-
const legacyModes = new Map();
|
|
23
|
-
if (data.version < 17) {
|
|
24
|
-
function collect(value) {
|
|
25
|
-
const entry = record(value);
|
|
26
|
-
if (entry.options !== undefined && entry.theme !== undefined) {
|
|
27
|
-
const options = record(entry.options);
|
|
28
|
-
if (options.cssOutput !== undefined) {
|
|
29
|
-
if (options.cssOutput !== 'atomic' && options.cssOutput !== 'grouped')
|
|
30
|
-
throw new Error('Invalid packed CSS output mode.');
|
|
31
|
-
const theme = record(record(data.themes)[string(entry.theme)]);
|
|
32
|
-
const identity = string(theme.identity);
|
|
33
|
-
const previous = legacyModes.get(identity);
|
|
34
|
-
if (previous !== undefined && previous !== options.cssOutput)
|
|
35
|
-
throw new Error('Conflicting packed CSS output modes for one theme identity.');
|
|
36
|
-
legacyModes.set(identity, options.cssOutput);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
for (const member of Object.values(record(entry.members ?? {})))
|
|
40
|
-
collect(member);
|
|
41
|
-
}
|
|
42
|
-
for (const entry of Object.values(record(data.exports)))
|
|
43
|
-
collect(entry);
|
|
44
|
-
}
|
|
45
|
-
function validateVariables(entry) {
|
|
46
|
-
if (data.version < 31 || entry.variableNaming !== undefined)
|
|
47
|
-
throw new Error('Legacy packed variable names are unsupported. Rebuild the library with the current version of Zyzz.');
|
|
48
|
-
}
|
|
49
|
-
function decode(value) {
|
|
50
|
-
if (!value || typeof value !== 'object')
|
|
51
|
-
return value;
|
|
52
|
-
if (Array.isArray(value))
|
|
53
|
-
return value.map(decode);
|
|
54
|
-
const fields = record(value);
|
|
55
|
-
if (Object.hasOwn(fields, '$object'))
|
|
56
|
-
return Object.fromEntries(Object.entries(record(fields.$object)).map(([key, value]) => [
|
|
57
|
-
key,
|
|
58
|
-
decode(value),
|
|
59
|
-
]));
|
|
60
|
-
if (Object.hasOwn(fields, '$composition')) {
|
|
61
|
-
if (data.version < 29)
|
|
62
|
-
throw new Error('Composed variables require contract version 29 or later.');
|
|
63
|
-
const composition = record(fields.$composition);
|
|
64
|
-
if ((composition.group !== 'color' && composition.group !== 'spacing') ||
|
|
65
|
-
!Array.isArray(composition.parts))
|
|
66
|
-
throw new Error('Invalid packed variable composition.');
|
|
67
|
-
return Vars.compose(composition.group, composition.parts.map(decode));
|
|
68
|
-
}
|
|
69
|
-
if (Object.hasOwn(fields, '$variable')) {
|
|
70
|
-
const reference = record(fields.$variable);
|
|
71
|
-
const identity = string(reference.identity);
|
|
72
|
-
validateVariables(reference);
|
|
73
|
-
let contract = identities.get(identity);
|
|
74
|
-
if (contract && !contract.variableSet)
|
|
75
|
-
throw new Error('Conflicting packed variable-set modes for one identity.');
|
|
76
|
-
if (!contract) {
|
|
77
|
-
contract = Object.freeze({
|
|
78
|
-
variableSet: true,
|
|
79
|
-
[Token.identity]: identity,
|
|
80
|
-
});
|
|
81
|
-
identities.set(identity, contract);
|
|
82
|
-
}
|
|
83
|
-
const resolved = decode(reference.value);
|
|
84
|
-
return Token.create({
|
|
85
|
-
contract,
|
|
86
|
-
group: VariableSets.domain(resolved),
|
|
87
|
-
path: string(reference.path),
|
|
88
|
-
value: resolved,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return Object.fromEntries(Object.entries(fields).map(([key, value]) => [key, decode(value)]));
|
|
92
|
-
}
|
|
93
|
-
const themes = Object.create(null);
|
|
94
|
-
const types = Object.create(null);
|
|
95
|
-
for (const [name, value] of Object.entries(record(data.themes))) {
|
|
96
|
-
const entry = record(value);
|
|
97
|
-
const identity = string(entry.identity);
|
|
98
|
-
if (Object.keys(record(entry.tokens)).length ||
|
|
99
|
-
entry.variableNaming !== undefined)
|
|
100
|
-
validateVariables(entry);
|
|
101
|
-
if (entry.variableSet === true && data.version < 28)
|
|
102
|
-
throw new Error('Vars contracts require contract version 28 or later.');
|
|
103
|
-
const mappings = VariableSets.mappings(entry.mappings);
|
|
104
|
-
if (entry.cssOutput !== undefined &&
|
|
105
|
-
entry.cssOutput !== 'atomic' &&
|
|
106
|
-
entry.cssOutput !== 'grouped')
|
|
107
|
-
throw new Error('Invalid packed CSS output mode.');
|
|
108
|
-
const cssOutput = (entry.cssOutput ?? legacyModes.get(identity));
|
|
109
|
-
if (entry.composition !== undefined) {
|
|
110
|
-
if (data.version < 34)
|
|
111
|
-
throw new Error('Composition modes require contract version 34 or later.');
|
|
112
|
-
if (entry.composition !== 'independent' &&
|
|
113
|
-
entry.composition !== 'ordered')
|
|
114
|
-
throw new Error('Invalid packed composition mode.');
|
|
115
|
-
}
|
|
116
|
-
const composition = entry.composition;
|
|
117
|
-
if (entry.defaultLayer !== undefined) {
|
|
118
|
-
if (data.version < 27)
|
|
119
|
-
throw new Error('Default layers require contract version 27 or later.');
|
|
120
|
-
Config.create({ defaultLayer: entry.defaultLayer });
|
|
121
|
-
}
|
|
122
|
-
const defaultLayer = entry.defaultLayer;
|
|
123
|
-
const shorthands = entry.shorthands !== undefined
|
|
124
|
-
? Shorthands.read(entry.shorthands)
|
|
125
|
-
: undefined;
|
|
126
|
-
let contract = identities.get(identity);
|
|
127
|
-
if (contract &&
|
|
128
|
-
Boolean(contract.variableSet) !== (entry.variableSet === true))
|
|
129
|
-
throw new Error('Conflicting packed variable-set modes for one identity.');
|
|
130
|
-
if (contract &&
|
|
131
|
-
JSON.stringify(contract.mappings ?? {}) !== JSON.stringify(mappings ?? {}))
|
|
132
|
-
throw new Error('Conflicting packed variable mappings for one identity.');
|
|
133
|
-
if (contract &&
|
|
134
|
-
Shorthands.signature(contract.shorthands) !==
|
|
135
|
-
Shorthands.signature(shorthands))
|
|
136
|
-
throw new Error('Conflicting packed shorthand mappings for one theme identity.');
|
|
137
|
-
if (contract &&
|
|
138
|
-
(contract.composition ?? 'ordered') !== (composition ?? 'ordered'))
|
|
139
|
-
throw new Error('Conflicting packed composition modes for one theme identity.');
|
|
140
|
-
if (contract &&
|
|
141
|
-
(contract.cssOutput ?? 'atomic') !== (cssOutput ?? 'atomic'))
|
|
142
|
-
throw new Error('Conflicting packed CSS output modes for one theme identity.');
|
|
143
|
-
if (contract && contract.defaultLayer !== defaultLayer)
|
|
144
|
-
throw new Error('Conflicting packed default layers for one theme identity.');
|
|
145
|
-
if (!contract) {
|
|
146
|
-
contract = Object.freeze({
|
|
147
|
-
...(entry.variableSet === true
|
|
148
|
-
? {
|
|
149
|
-
variableSet: true,
|
|
150
|
-
mappings,
|
|
151
|
-
}
|
|
152
|
-
: {}),
|
|
153
|
-
...(entry.shorthands !== undefined
|
|
154
|
-
? { shorthands: Shorthands.read(entry.shorthands) }
|
|
155
|
-
: {}),
|
|
156
|
-
...(composition ? { composition } : {}),
|
|
157
|
-
...(cssOutput ? { cssOutput } : {}),
|
|
158
|
-
...(defaultLayer !== undefined ? { defaultLayer } : {}),
|
|
159
|
-
[Token.complete]: true,
|
|
160
|
-
[Token.identity]: identity,
|
|
161
|
-
});
|
|
162
|
-
identities.set(identity, contract);
|
|
163
|
-
}
|
|
164
|
-
const definition = entry.variableSet === true
|
|
165
|
-
? VariableSets.theme(Vars.define(decode(entry.tokens)), mappings)
|
|
166
|
-
: Theme.define(record(entry.tokens));
|
|
167
|
-
if (data.version < 24 &&
|
|
168
|
-
Object.hasOwn(definition.tokens, 'typography'))
|
|
169
|
-
throw new Error('Packed typography sets require contract version 24 or later.');
|
|
170
|
-
if (data.version < 25 &&
|
|
171
|
-
(definition[Token.definition].paths ||
|
|
172
|
-
Object.hasOwn(definition.tokens, 'borderWidth')))
|
|
173
|
-
throw new Error('Packed responsive typography and border widths require contract version 25 or later.');
|
|
174
|
-
themes[name] = Token.bind(definition, contract, entry.cssName === undefined ? undefined : string(entry.cssName));
|
|
175
|
-
types[name] = type(input(definition));
|
|
176
|
-
}
|
|
177
|
-
function link(value) {
|
|
178
|
-
const raw = record(value);
|
|
179
|
-
if (raw.nativeProvider !== undefined && data.version < 32)
|
|
180
|
-
throw new Error('Native providers require contract version 32 or later.');
|
|
181
|
-
// Contracts before version 19 record style authoring exports as `css`.
|
|
182
|
-
const entry = raw.kind === 'css' && data.version < 19
|
|
183
|
-
? { ...raw, kind: 'style' }
|
|
184
|
-
: raw;
|
|
185
|
-
if (entry.kind === 'variables') {
|
|
186
|
-
if (data.version < 14)
|
|
187
|
-
throw new Error('Legacy variable contracts require recompilation with variable().');
|
|
188
|
-
const names = new Set();
|
|
189
|
-
const slots = Object.fromEntries(Object.entries(record(entry.variables)).map(([key, value]) => {
|
|
190
|
-
const slot = record(value);
|
|
191
|
-
if (key === 'set' ||
|
|
192
|
-
key === '__proto__' ||
|
|
193
|
-
names.has(string(slot.name)) ||
|
|
194
|
-
!/^--z-[a-zA-Z0-9_-]+$/.test(string(slot.name)) ||
|
|
195
|
-
![
|
|
196
|
-
'*',
|
|
197
|
-
'color',
|
|
198
|
-
'length',
|
|
199
|
-
'number',
|
|
200
|
-
'percentage',
|
|
201
|
-
'signedLength',
|
|
202
|
-
'signedPercentage',
|
|
203
|
-
].includes(String(slot.type)))
|
|
204
|
-
throw new Error('Invalid packed variable contract.');
|
|
205
|
-
names.add(string(slot.name));
|
|
206
|
-
return [
|
|
207
|
-
key,
|
|
208
|
-
Object.freeze({
|
|
209
|
-
name: slot.name,
|
|
210
|
-
type: slot.type,
|
|
211
|
-
variable: true,
|
|
212
|
-
}),
|
|
213
|
-
];
|
|
214
|
-
}));
|
|
215
|
-
const binding = string(entry.binding);
|
|
216
|
-
return {
|
|
217
|
-
binding,
|
|
218
|
-
kind: 'variables',
|
|
219
|
-
...(entry.members
|
|
220
|
-
? {
|
|
221
|
-
members: Object.fromEntries(Object.entries(record(entry.members)).map(([name, value]) => [
|
|
222
|
-
name,
|
|
223
|
-
link(value),
|
|
224
|
-
])),
|
|
225
|
-
}
|
|
226
|
-
: {}),
|
|
227
|
-
definition: Theme.define({}),
|
|
228
|
-
call: {
|
|
229
|
-
start: -1,
|
|
230
|
-
end: -1,
|
|
231
|
-
name: binding,
|
|
232
|
-
tokenType: '{}',
|
|
233
|
-
variables: Object.freeze(slots),
|
|
234
|
-
...(entry.source !== undefined
|
|
235
|
-
? {
|
|
236
|
-
variableOwner: Stylesheets.resolve(moduleId, string(entry.source)),
|
|
237
|
-
}
|
|
238
|
-
: {}),
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (entry.kind === 'rule-reference') {
|
|
243
|
-
const name = string(entry.name);
|
|
244
|
-
const reference = string(entry.reference);
|
|
245
|
-
if (![
|
|
246
|
-
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
|
247
|
-
27, 28, 29, 30, 31, 32, 33, 34,
|
|
248
|
-
].includes(data.version) ||
|
|
249
|
-
![
|
|
250
|
-
'cssFunction',
|
|
251
|
-
'customMedia',
|
|
252
|
-
'colorProfile',
|
|
253
|
-
'counterStyle',
|
|
254
|
-
'fontPaletteValues',
|
|
255
|
-
'positionTry',
|
|
256
|
-
].includes(reference) ||
|
|
257
|
-
!/^(?:--)?z-[a-zA-Z0-9_-]+$/.test(name) ||
|
|
258
|
-
!name.startsWith(`${reference === 'counterStyle' ? '' : '--'}z-${reference.toLowerCase()}`) ||
|
|
259
|
-
entry.binding !== name)
|
|
260
|
-
throw new Error('Invalid named stylesheet identity.');
|
|
261
|
-
return {
|
|
262
|
-
binding: string(entry.binding),
|
|
263
|
-
kind: 'rule-reference',
|
|
264
|
-
definition: Theme.define({}),
|
|
265
|
-
call: {
|
|
266
|
-
start: -1,
|
|
267
|
-
end: -1,
|
|
268
|
-
name,
|
|
269
|
-
tokenType: '{}',
|
|
270
|
-
reference: reference,
|
|
271
|
-
...(reference === 'cssFunction'
|
|
272
|
-
? { function: signature(entry.function, data.version) }
|
|
273
|
-
: {}),
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
if (entry.kind === 'animation') {
|
|
278
|
-
const name = string(entry.name);
|
|
279
|
-
if (!/^z-k[a-zA-Z0-9_-]+$/.test(name))
|
|
280
|
-
throw new Error('Invalid animation identity.');
|
|
281
|
-
return {
|
|
282
|
-
binding: string(entry.binding),
|
|
283
|
-
kind: 'animation',
|
|
284
|
-
definition: Theme.define({}),
|
|
285
|
-
call: { start: -1, end: -1, name, tokenType: '{}' },
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
if (entry.kind === 'style-reference') {
|
|
289
|
-
if (entry.style !== undefined && data.version < 16)
|
|
290
|
-
throw new Error('Packed callable styles require contract version 16 or later.');
|
|
291
|
-
const binding = string(entry.binding);
|
|
292
|
-
if (!/^z-style-[a-zA-Z0-9_-]+$/.test(binding))
|
|
293
|
-
throw new Error('Invalid style reference identity.');
|
|
294
|
-
const members = entry.members === undefined
|
|
295
|
-
? undefined
|
|
296
|
-
: Object.fromEntries(Object.entries(record(entry.members)).map(([key, value]) => {
|
|
297
|
-
const member = link(value);
|
|
298
|
-
if (member.kind !== 'style-reference' ||
|
|
299
|
-
(member.members && data.version < 22))
|
|
300
|
-
throw new Error('Invalid style reference member.');
|
|
301
|
-
return [key, member];
|
|
302
|
-
}));
|
|
303
|
-
const nativeContext = (() => {
|
|
304
|
-
if (entry.nativeContext === undefined)
|
|
305
|
-
return undefined;
|
|
306
|
-
if (data.version < 33)
|
|
307
|
-
throw new Error('Native style catalogs require contract version 33 or later.');
|
|
308
|
-
if (entry.style === undefined)
|
|
309
|
-
throw new Error('Native style catalogs require a packed style.');
|
|
310
|
-
const context = record(entry.nativeContext);
|
|
311
|
-
const vars = Object.fromEntries(Object.entries(record(context.vars)).map((entry) => {
|
|
312
|
-
const [name, value] = entry;
|
|
313
|
-
const theme = themes[string(value)];
|
|
314
|
-
if (!name || !theme)
|
|
315
|
-
throw new Error('Unknown packed native style catalog.');
|
|
316
|
-
return [name, theme];
|
|
317
|
-
}));
|
|
318
|
-
const defaultVars = string(context.defaultVars);
|
|
319
|
-
if (!Object.hasOwn(vars, defaultVars))
|
|
320
|
-
throw new Error('Invalid packed native style default.');
|
|
321
|
-
const identities = new Set(Object.values(vars).map((theme) => theme[Token.definition].contract));
|
|
322
|
-
if (identities.size !== 1)
|
|
323
|
-
throw new Error('Incompatible packed native style catalog.');
|
|
324
|
-
return { defaultVars, vars };
|
|
325
|
-
})();
|
|
326
|
-
return {
|
|
327
|
-
binding,
|
|
328
|
-
call: {
|
|
329
|
-
start: -1,
|
|
330
|
-
end: -1,
|
|
331
|
-
name: members ? '' : binding,
|
|
332
|
-
tokenType: '{}',
|
|
333
|
-
},
|
|
334
|
-
definition: Theme.define({}),
|
|
335
|
-
kind: 'style-reference',
|
|
336
|
-
...(entry.style === undefined
|
|
337
|
-
? {}
|
|
338
|
-
: {
|
|
339
|
-
style: {
|
|
340
|
-
...PackedStyles.read(entry.style, themes, data.version),
|
|
341
|
-
...(nativeContext ? { nativeContext } : {}),
|
|
342
|
-
},
|
|
343
|
-
}),
|
|
344
|
-
...(members ? { members } : {}),
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
if (entry.output !== undefined && entry.output !== 'html')
|
|
348
|
-
throw new Error('Invalid theme output.');
|
|
349
|
-
if (entry.recipe !== undefined &&
|
|
350
|
-
(entry.recipe !== true ||
|
|
351
|
-
data.version < 15 ||
|
|
352
|
-
entry.kind !== 'style'))
|
|
353
|
-
throw new Error('Invalid bound recipe contract.');
|
|
354
|
-
const theme = string(entry.theme);
|
|
355
|
-
const definition = themes[theme];
|
|
356
|
-
if (!definition ||
|
|
357
|
-
!['config', 'style', 'theme'].includes(String(entry.kind)))
|
|
358
|
-
throw new Error('Invalid Zyzz contract export.');
|
|
359
|
-
const members = entry.kind === 'config'
|
|
360
|
-
? Object.fromEntries(Object.entries(record(entry.members)).map(([key, value]) => [
|
|
361
|
-
key,
|
|
362
|
-
link(value),
|
|
363
|
-
]))
|
|
364
|
-
: undefined;
|
|
365
|
-
const options = entry.options === undefined ? undefined : record(decode(entry.options));
|
|
366
|
-
if (options) {
|
|
367
|
-
if (entry.variableConfig === true &&
|
|
368
|
-
JSON.stringify(VariableSets.mappings(entry.variableMappings) ?? {}) !==
|
|
369
|
-
JSON.stringify(definition[Token.definition].contract.mappings ?? {}))
|
|
370
|
-
throw new Error('Configuration mappings disagree with linked variable metadata.');
|
|
371
|
-
if (entry.variableConfig === true)
|
|
372
|
-
Config.create(variableOptions(options, entry.variableMappings));
|
|
373
|
-
else
|
|
374
|
-
Config.create(options);
|
|
375
|
-
if (data.version >= 17 &&
|
|
376
|
-
(options.cssOutput ?? 'atomic') !==
|
|
377
|
-
(definition[Token.definition].contract.cssOutput ?? 'atomic'))
|
|
378
|
-
throw new Error('Configuration CSS output disagrees with linked theme metadata.');
|
|
379
|
-
if ((options.composition ?? 'ordered') !==
|
|
380
|
-
(definition[Token.definition].contract.composition ?? 'ordered'))
|
|
381
|
-
throw new Error('Configuration composition disagrees with linked theme metadata.');
|
|
382
|
-
if (options.defaultLayer !==
|
|
383
|
-
definition[Token.definition].contract.defaultLayer)
|
|
384
|
-
throw new Error('Configuration default layer disagrees with linked theme metadata.');
|
|
385
|
-
if (Shorthands.signature(options.shorthands) !==
|
|
386
|
-
Shorthands.signature(definition[Token.definition].contract.shorthands))
|
|
387
|
-
throw new Error('Configuration mappings disagree with linked theme metadata.');
|
|
388
|
-
}
|
|
389
|
-
const catalogOnly = !!options?.themes &&
|
|
390
|
-
(data.version < 4 || entry.catalogOnly === true);
|
|
391
|
-
const fullConfigType = options
|
|
392
|
-
? entry.nativeProvider === true
|
|
393
|
-
? `import('zyzz/react-native/react').defineConfig.ReturnType<${Configurations.type(entry.variableConfig === true ? variableOptions(options, entry.variableMappings) : options)}>`
|
|
394
|
-
: entry.variableConfig === true
|
|
395
|
-
? `import('zyzz').Config.VariableConfig<${Configurations.type(variableOptions(options, entry.variableMappings))}>`
|
|
396
|
-
: `import('zyzz').Config.create.ReturnType<${Configurations.type(options)}>`
|
|
397
|
-
: '';
|
|
398
|
-
// Helpers a legacy library did not compile are hidden from its consumers' types.
|
|
399
|
-
const hidden = [
|
|
400
|
-
...(rootControls && entry.appearance === true ? [] : ["'appearance'"]),
|
|
401
|
-
...(entry.script === true ? [] : ["'script'"]),
|
|
402
|
-
];
|
|
403
|
-
const configType = hidden.length
|
|
404
|
-
? `{readonly [key in keyof ${fullConfigType} as key extends ${hidden.join(' | ')} ? never : key]:${fullConfigType}[key]}`
|
|
405
|
-
: fullConfigType;
|
|
406
|
-
const outputType = catalogOnly
|
|
407
|
-
? `({readonly [key in keyof ${configType} as key extends 'themes' ? never : key]:${configType}[key]} & {readonly themes:{readonly [key in keyof ${configType}['themes']]:${configType}['themes'][key]}})`
|
|
408
|
-
: configType;
|
|
409
|
-
if (entry.kind === 'config' && !options)
|
|
410
|
-
throw new Error('Missing configuration options.');
|
|
411
|
-
return {
|
|
412
|
-
binding: string(entry.binding),
|
|
413
|
-
call: {
|
|
414
|
-
...(entry.nativeProvider === true ? { nativeProvider: true } : {}),
|
|
415
|
-
...(entry.variableSet === true
|
|
416
|
-
? {
|
|
417
|
-
variableSet: true,
|
|
418
|
-
type: `import('zyzz').Vars.Definition<${types[theme]}>`,
|
|
419
|
-
}
|
|
420
|
-
: {}),
|
|
421
|
-
...(entry.directVariables === true
|
|
422
|
-
? {
|
|
423
|
-
directVariables: true,
|
|
424
|
-
type: `import('zyzz').Vars.${entry.variableSet === true ? 'Definition' : 'References'}<${types[theme]}>`,
|
|
425
|
-
}
|
|
426
|
-
: {}),
|
|
427
|
-
...(entry.variableConfig === true
|
|
428
|
-
? {
|
|
429
|
-
variableConfig: true,
|
|
430
|
-
variableMappings: entry.variableMappings,
|
|
431
|
-
}
|
|
432
|
-
: {}),
|
|
433
|
-
...(entry.recipe === true ? { recipe: true } : {}),
|
|
434
|
-
...(entry.output === 'html' ? { output: 'html' } : {}),
|
|
435
|
-
...(catalogOnly ? { catalogOnly: true } : {}),
|
|
436
|
-
...(entry.script === true ? { script: true } : {}),
|
|
437
|
-
...(rootControls && entry.appearance === true
|
|
438
|
-
? { appearance: true }
|
|
439
|
-
: {}),
|
|
440
|
-
...(rootControls && entry.root === true ? { root: true } : {}),
|
|
441
|
-
end: -1,
|
|
442
|
-
name: theme,
|
|
443
|
-
start: -1,
|
|
444
|
-
tokenType: types[theme],
|
|
445
|
-
...(definition[Token.definition].contract.shorthands ||
|
|
446
|
-
entry.output === 'html'
|
|
447
|
-
? {
|
|
448
|
-
type: `import('zyzz').Config.create.ReturnType<{theme:${types[theme]};${entry.output === 'html' ? "output:'html';" : ''}shorthands:${Configurations.type(definition[Token.definition].contract.shorthands ?? {})}}>['theme']`,
|
|
449
|
-
}
|
|
450
|
-
: {}),
|
|
451
|
-
...(entry.selection === true ? { selection: true } : {}),
|
|
452
|
-
...(entry.initialization === true ? { initialization: true } : {}),
|
|
453
|
-
...(options
|
|
454
|
-
? {
|
|
455
|
-
options,
|
|
456
|
-
type: `${outputType}${entry.initialization === true ? "['script']" : entry.root === true ? "['appearance']" : entry.selection === true ? (entry.variableConfig === true ? "['vars']" : "['themes']") : ''}`,
|
|
457
|
-
}
|
|
458
|
-
: {}),
|
|
459
|
-
...(members
|
|
460
|
-
? {
|
|
461
|
-
members: Object.fromEntries(Object.entries(members).map(([key, member]) => [
|
|
462
|
-
key,
|
|
463
|
-
member.call.name,
|
|
464
|
-
])),
|
|
465
|
-
}
|
|
466
|
-
: {}),
|
|
467
|
-
},
|
|
468
|
-
definition,
|
|
469
|
-
kind: entry.kind,
|
|
470
|
-
...(members ? { members } : {}),
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
const links = Object.fromEntries(Object.entries(record(data.exports)).map(([name, value]) => [
|
|
474
|
-
name,
|
|
475
|
-
link(value),
|
|
476
|
-
]));
|
|
477
|
-
const classRules = Object.fromEntries(Object.entries(data.classRules === undefined ? {} : record(data.classRules)).map(([name, body]) => {
|
|
478
|
-
if (!name || /\s/.test(name))
|
|
479
|
-
throw new Error('Invalid packed class name.');
|
|
480
|
-
return [name, string(body)];
|
|
481
|
-
}));
|
|
482
|
-
return {
|
|
483
|
-
classRules,
|
|
484
|
-
links,
|
|
485
|
-
themes,
|
|
486
|
-
stylesheets: Stylesheets.read(data.stylesheets),
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
function record(value) {
|
|
490
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
491
|
-
throw new Error('Expected a Zyzz contract record.');
|
|
492
|
-
return value;
|
|
493
|
-
}
|
|
494
|
-
function string(value) {
|
|
495
|
-
if (typeof value !== 'string' || !value)
|
|
496
|
-
throw new Error('Expected a nonempty Zyzz contract identity.');
|
|
497
|
-
return value;
|
|
498
|
-
}
|
|
499
|
-
function input(theme) {
|
|
500
|
-
return { ...tokens(theme.tokens), ...theme[Token.definition].queries };
|
|
501
|
-
}
|
|
502
|
-
function tokens(tree) {
|
|
503
|
-
return Object.fromEntries(Object.entries(tree).map(([name, value]) => [
|
|
504
|
-
name,
|
|
505
|
-
Token.is(value)
|
|
506
|
-
? value.value
|
|
507
|
-
: tokens(value),
|
|
508
|
-
]));
|
|
509
|
-
}
|
|
510
|
-
function type(value) {
|
|
511
|
-
if (Token.is(value) || Token.isExpression(value))
|
|
512
|
-
return Configurations.type(value);
|
|
513
|
-
if (Array.isArray(value))
|
|
514
|
-
return `readonly [${value.map(type).join(',')}]`;
|
|
515
|
-
if (!value || typeof value !== 'object')
|
|
516
|
-
return JSON.stringify(value);
|
|
517
|
-
return `{${Object.entries(value)
|
|
518
|
-
.map(([key, value]) => `readonly ${JSON.stringify(key)}:${type(value)}`)
|
|
519
|
-
.join(';')}}`;
|
|
520
|
-
}
|
|
521
|
-
/** Emits compiler-only metadata without adding it to the runtime module. */
|
|
522
|
-
export function write(links, themes, stylesheets = [], moduleId = '', configurations = [], classRules = {}) {
|
|
523
|
-
function entry(link) {
|
|
524
|
-
if (link.kind === 'variables')
|
|
525
|
-
return {
|
|
526
|
-
binding: link.binding,
|
|
527
|
-
kind: link.kind,
|
|
528
|
-
variables: link.call.variables,
|
|
529
|
-
...(link.members
|
|
530
|
-
? {
|
|
531
|
-
members: Object.fromEntries(Object.entries(link.members).map(([name, member]) => [
|
|
532
|
-
name,
|
|
533
|
-
entry(member),
|
|
534
|
-
])),
|
|
535
|
-
}
|
|
536
|
-
: {}),
|
|
537
|
-
...(link.call.variableOwner
|
|
538
|
-
? { source: Stylesheets.relative(moduleId, link.call.variableOwner) }
|
|
539
|
-
: {}),
|
|
540
|
-
};
|
|
541
|
-
if (link.kind === 'rule-reference')
|
|
542
|
-
return {
|
|
543
|
-
binding: link.binding,
|
|
544
|
-
kind: link.kind,
|
|
545
|
-
name: link.call.name,
|
|
546
|
-
reference: link.call.reference,
|
|
547
|
-
...(link.call.function ? { function: link.call.function } : {}),
|
|
548
|
-
};
|
|
549
|
-
if (link.kind === 'animation')
|
|
550
|
-
return { binding: link.binding, kind: link.kind, name: link.call.name };
|
|
551
|
-
if (link.kind === 'style-reference')
|
|
552
|
-
return {
|
|
553
|
-
binding: link.binding,
|
|
554
|
-
kind: link.kind,
|
|
555
|
-
...(link.style?.nativeContext
|
|
556
|
-
? {
|
|
557
|
-
nativeContext: {
|
|
558
|
-
defaultVars: link.style.nativeContext.defaultVars,
|
|
559
|
-
vars: Object.fromEntries(Object.entries(link.style.nativeContext.vars).map((entry) => {
|
|
560
|
-
const [name, definition] = entry;
|
|
561
|
-
const theme = Object.entries(themes).find((candidate) => candidate[1][Token.definition].contract ===
|
|
562
|
-
definition[Token.definition].contract &&
|
|
563
|
-
JSON.stringify(input(candidate[1])) ===
|
|
564
|
-
JSON.stringify(input(definition)));
|
|
565
|
-
if (!theme)
|
|
566
|
-
throw new Error('Missing packed native style catalog.');
|
|
567
|
-
return [name, theme[0]];
|
|
568
|
-
})),
|
|
569
|
-
},
|
|
570
|
-
}
|
|
571
|
-
: {}),
|
|
572
|
-
...(link.style ? { style: PackedStyles.write(link.style) } : {}),
|
|
573
|
-
...(link.members
|
|
574
|
-
? {
|
|
575
|
-
members: Object.fromEntries(Object.entries(link.members).map(([name, value]) => [
|
|
576
|
-
name,
|
|
577
|
-
entry(value),
|
|
578
|
-
])),
|
|
579
|
-
}
|
|
580
|
-
: {}),
|
|
581
|
-
};
|
|
582
|
-
return {
|
|
583
|
-
...(link.call.variableSet ? { variableSet: true } : {}),
|
|
584
|
-
...(link.call.nativeProvider ? { nativeProvider: true } : {}),
|
|
585
|
-
...(link.call.directVariables ? { directVariables: true } : {}),
|
|
586
|
-
...(link.call.variableConfig
|
|
587
|
-
? { variableConfig: true, variableMappings: link.call.variableMappings }
|
|
588
|
-
: {}),
|
|
589
|
-
...(link.call.recipe ? { recipe: true } : {}),
|
|
590
|
-
...(link.call.output ? { output: link.call.output } : {}),
|
|
591
|
-
...(link.call.script &&
|
|
592
|
-
(link.kind === 'config' || link.call.initialization)
|
|
593
|
-
? { script: true }
|
|
594
|
-
: {}),
|
|
595
|
-
...(link.call.appearance && (link.kind === 'config' || link.call.root)
|
|
596
|
-
? { appearance: true }
|
|
597
|
-
: {}),
|
|
598
|
-
binding: link.binding,
|
|
599
|
-
kind: link.kind,
|
|
600
|
-
theme: link.call.name,
|
|
601
|
-
...(link.call.catalogOnly ? { catalogOnly: true } : {}),
|
|
602
|
-
...(link.call.selection ? { selection: true } : {}),
|
|
603
|
-
...(link.call.initialization ? { initialization: true } : {}),
|
|
604
|
-
...(link.call.root ? { root: true } : {}),
|
|
605
|
-
...(link.call.options ? { options: encode(link.call.options) } : {}),
|
|
606
|
-
...(link.members
|
|
607
|
-
? {
|
|
608
|
-
members: Object.fromEntries(Object.entries(link.members).map(([key, link]) => [
|
|
609
|
-
key,
|
|
610
|
-
entry(link),
|
|
611
|
-
])),
|
|
612
|
-
}
|
|
613
|
-
: {}),
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
return JSON.stringify({
|
|
617
|
-
...(Object.keys(classRules).length ? { classRules } : {}),
|
|
618
|
-
...(stylesheets.length
|
|
619
|
-
? { stylesheets: Stylesheets.write(stylesheets) }
|
|
620
|
-
: {}),
|
|
621
|
-
// Local configurations publish their catalogs so documents restore
|
|
622
|
-
// selections for modules that export styles but not the configuration.
|
|
623
|
-
...(configurations.length ? { configurations } : {}),
|
|
624
|
-
exports: Object.fromEntries(Object.entries(links).map(([name, link]) => [name, entry(link)])),
|
|
625
|
-
themes: Object.fromEntries(Object.entries(themes).map(([name, theme]) => [
|
|
626
|
-
name,
|
|
627
|
-
{
|
|
628
|
-
...(theme[Token.definition].cssName !== undefined
|
|
629
|
-
? { cssName: theme[Token.definition].cssName }
|
|
630
|
-
: {}),
|
|
631
|
-
...(theme[Token.definition].contract.shorthands
|
|
632
|
-
? { shorthands: theme[Token.definition].contract.shorthands }
|
|
633
|
-
: {}),
|
|
634
|
-
...(theme[Token.definition].contract.defaultLayer !== undefined
|
|
635
|
-
? { defaultLayer: theme[Token.definition].contract.defaultLayer }
|
|
636
|
-
: {}),
|
|
637
|
-
...(theme[Token.definition].contract.composition
|
|
638
|
-
? { composition: theme[Token.definition].contract.composition }
|
|
639
|
-
: {}),
|
|
640
|
-
...(theme[Token.definition].contract.cssOutput
|
|
641
|
-
? { cssOutput: theme[Token.definition].contract.cssOutput }
|
|
642
|
-
: {}),
|
|
643
|
-
...(theme[Token.definition].contract.variableSet
|
|
644
|
-
? {
|
|
645
|
-
variableSet: true,
|
|
646
|
-
mappings: theme[Token.definition].contract.mappings,
|
|
647
|
-
}
|
|
648
|
-
: {}),
|
|
649
|
-
identity: theme[Token.definition].contract[Token.identity],
|
|
650
|
-
tokens: encode(input(theme)),
|
|
651
|
-
},
|
|
652
|
-
])),
|
|
653
|
-
version: (() => {
|
|
654
|
-
if (Object.values(themes).some((theme) => theme[Token.definition].contract.composition) ||
|
|
655
|
-
Object.values(links).some(composed))
|
|
656
|
-
return 34;
|
|
657
|
-
if (Object.values(links).some(nativeCatalog))
|
|
658
|
-
return 33;
|
|
659
|
-
if (Object.values(links).some(nativeProvider))
|
|
660
|
-
return 32;
|
|
661
|
-
return 31;
|
|
662
|
-
})(),
|
|
663
|
-
});
|
|
664
|
-
function composed(link) {
|
|
665
|
-
return (Boolean(link.style?.style.composition) ||
|
|
666
|
-
Object.values(link.members ?? {}).some(composed));
|
|
667
|
-
}
|
|
668
|
-
function nativeProvider(link) {
|
|
669
|
-
return (link.call.nativeProvider === true ||
|
|
670
|
-
Object.values(link.members ?? {}).some(nativeProvider));
|
|
671
|
-
}
|
|
672
|
-
function nativeCatalog(link) {
|
|
673
|
-
return (Boolean(link.style?.nativeContext) ||
|
|
674
|
-
Object.values(link.members ?? {}).some(nativeCatalog));
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
function signature(input, version) {
|
|
678
|
-
const value = record(input);
|
|
679
|
-
if (!FunctionSyntax.accepts(string(value.returns)) ||
|
|
680
|
-
!Array.isArray(value.parameters))
|
|
681
|
-
throw new Error('Invalid packed CSS function signature.');
|
|
682
|
-
if (version < 12 &&
|
|
683
|
-
(/[\\\u0080-\uffff]/.test(String(value.returns)) ||
|
|
684
|
-
value.parameters.some((input) => {
|
|
685
|
-
const parameter = record(input);
|
|
686
|
-
return /[\\\u0080-\uffff]/.test(string(parameter.name) + string(parameter.syntax ?? '*'));
|
|
687
|
-
})))
|
|
688
|
-
throw new Error('Extended CSS function signatures require contract version 12.');
|
|
689
|
-
const names = new Set();
|
|
690
|
-
const parameters = value.parameters.map((input) => {
|
|
691
|
-
const parameter = record(input);
|
|
692
|
-
const name = string(parameter.name);
|
|
693
|
-
if (!Identifiers.read(name)?.startsWith('--') ||
|
|
694
|
-
Identifiers.read(name) === '--' ||
|
|
695
|
-
names.has(Identifiers.read(name)) ||
|
|
696
|
-
(parameter.syntax !== undefined &&
|
|
697
|
-
!FunctionSyntax.accepts(string(parameter.syntax))) ||
|
|
698
|
-
(parameter.default !== undefined &&
|
|
699
|
-
typeof parameter.default !== 'number' &&
|
|
700
|
-
typeof parameter.default !== 'string'))
|
|
701
|
-
throw new Error('Invalid packed CSS function parameter.');
|
|
702
|
-
names.add(Identifiers.read(name));
|
|
703
|
-
return {
|
|
704
|
-
name: name,
|
|
705
|
-
...(parameter.syntax !== undefined
|
|
706
|
-
? {
|
|
707
|
-
syntax: parameter.syntax,
|
|
708
|
-
}
|
|
709
|
-
: {}),
|
|
710
|
-
...(parameter.default !== undefined
|
|
711
|
-
? { default: parameter.default }
|
|
712
|
-
: {}),
|
|
713
|
-
};
|
|
714
|
-
});
|
|
715
|
-
return {
|
|
716
|
-
parameters,
|
|
717
|
-
returns: value.returns,
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
function encode(value) {
|
|
721
|
-
if (Token.isExpression(value) && 'group' in value)
|
|
722
|
-
return {
|
|
723
|
-
$composition: { group: value.group, parts: value.parts.map(encode) },
|
|
724
|
-
};
|
|
725
|
-
if (Token.is(value))
|
|
726
|
-
return {
|
|
727
|
-
$variable: {
|
|
728
|
-
identity: value.contract[Token.identity],
|
|
729
|
-
path: value.path,
|
|
730
|
-
value: encode(value.value),
|
|
731
|
-
},
|
|
732
|
-
};
|
|
733
|
-
if (Array.isArray(value))
|
|
734
|
-
return value.map(encode);
|
|
735
|
-
if (!value || typeof value !== 'object')
|
|
736
|
-
return value;
|
|
737
|
-
const fields = Object.fromEntries(Object.entries(value).map(([key, value]) => [key, encode(value)]));
|
|
738
|
-
return Object.hasOwn(fields, '$composition') ||
|
|
739
|
-
Object.hasOwn(fields, '$variable') ||
|
|
740
|
-
Object.hasOwn(fields, '$object')
|
|
741
|
-
? { $object: fields }
|
|
742
|
-
: fields;
|
|
743
|
-
}
|
|
744
|
-
function variableOptions(options, mappings) {
|
|
745
|
-
const { theme, themes, defaultTheme, ...rest } = options;
|
|
746
|
-
return {
|
|
747
|
-
...rest,
|
|
748
|
-
vars: (themes ?? theme),
|
|
749
|
-
...(themes ? { defaultVars: String(defaultTheme) } : {}),
|
|
750
|
-
...(mappings !== undefined ? { mappings } : {}),
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
//# sourceMappingURL=Contract.js.map
|