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
|
@@ -0,0 +1,795 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes Rust `source.extract` results into the frozen data `Source.extract` returns.
|
|
3
|
+
* The format is documented in `crates/compiler/src/compiler/internal/wire.rs`.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as Authoring from '../../internal/Authoring.js';
|
|
7
|
+
import * as Binding from '../../internal/Binding.js';
|
|
8
|
+
import * as ClassName from '../../web/internal/ClassName.js';
|
|
9
|
+
import * as Configuration from '../../internal/Configuration.js';
|
|
10
|
+
import * as Identity from '../../internal/Identity.js';
|
|
11
|
+
import { MissingTransformError } from '../../styleFunction.js';
|
|
12
|
+
import * as Source from '../Source.js';
|
|
13
|
+
import * as Style from '../../Style.js';
|
|
14
|
+
import * as Theme from '../../internal/Theme.js';
|
|
15
|
+
import * as Token from '../../internal/Token.js';
|
|
16
|
+
import * as Vars from '../../Vars.js';
|
|
17
|
+
/**
|
|
18
|
+
* Decodes one extraction result, or throws the error the extraction failed with.
|
|
19
|
+
* @param text - JSON text returned by the `source.extract` operation.
|
|
20
|
+
* @returns Frozen calls, styles, theme data, and contributions.
|
|
21
|
+
* @throws {Source.ExtractError} With every source diagnostic of a failed extraction.
|
|
22
|
+
*/
|
|
23
|
+
export function decode(text, options = {}) {
|
|
24
|
+
const output = JSON.parse(text);
|
|
25
|
+
if (output.error)
|
|
26
|
+
throw failure(output.error);
|
|
27
|
+
const contracts = (output.contracts ?? []).map(contract);
|
|
28
|
+
const decoder = create(contracts, options);
|
|
29
|
+
return decoder.result(output.result ?? {});
|
|
30
|
+
}
|
|
31
|
+
/** Reconstructs the error class a TypeScript extraction throws. */
|
|
32
|
+
function failure(error) {
|
|
33
|
+
switch (error.name) {
|
|
34
|
+
case 'Source.ExtractError':
|
|
35
|
+
return new Source.ExtractError((error.diagnostics ?? []).map((diagnostic) => Object.freeze({
|
|
36
|
+
code: diagnostic.code,
|
|
37
|
+
end: diagnostic.end,
|
|
38
|
+
message: diagnostic.message,
|
|
39
|
+
source: diagnostic.source,
|
|
40
|
+
start: diagnostic.start,
|
|
41
|
+
})));
|
|
42
|
+
case 'Config.InvalidError':
|
|
43
|
+
return new Configuration.InvalidError(error.message);
|
|
44
|
+
case 'Theme.InvalidError':
|
|
45
|
+
return new Theme.InvalidError(error.path ?? [], error.reason ?? error.message);
|
|
46
|
+
case 'Vars.InvalidError':
|
|
47
|
+
return new Vars.InvalidError(error.path ?? [], error.reason ?? error.message);
|
|
48
|
+
case 'Style.InvalidError':
|
|
49
|
+
return new Style.InvalidError((error.diagnostics ?? []).map((diagnostic) => {
|
|
50
|
+
const location = diagnostic.location;
|
|
51
|
+
return Object.freeze({
|
|
52
|
+
code: diagnostic.code,
|
|
53
|
+
...(location
|
|
54
|
+
? {
|
|
55
|
+
location: Object.freeze({
|
|
56
|
+
end: location.end,
|
|
57
|
+
path: Object.freeze([...location.path]),
|
|
58
|
+
source: location.source,
|
|
59
|
+
start: location.start,
|
|
60
|
+
}),
|
|
61
|
+
}
|
|
62
|
+
: {}),
|
|
63
|
+
message: diagnostic.message,
|
|
64
|
+
path: Object.freeze([...diagnostic.path]),
|
|
65
|
+
});
|
|
66
|
+
}));
|
|
67
|
+
case 'MissingTransformError':
|
|
68
|
+
return new MissingTransformError();
|
|
69
|
+
default:
|
|
70
|
+
return new Error(error.message);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Rebuilds a contract with its enumerable properties in creation order. */
|
|
74
|
+
function contract(input) {
|
|
75
|
+
const value = {};
|
|
76
|
+
for (const key of input.keys) {
|
|
77
|
+
if (key === 'variableSet')
|
|
78
|
+
value.variableSet = true;
|
|
79
|
+
else if (key === 'mappings')
|
|
80
|
+
value.mappings = (() => {
|
|
81
|
+
if (input.mappings === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
if (input.mappings === false)
|
|
84
|
+
return false;
|
|
85
|
+
return properties(input.mappings);
|
|
86
|
+
})();
|
|
87
|
+
else if (key === 'shorthands')
|
|
88
|
+
value.shorthands = shorthands(input.shorthands);
|
|
89
|
+
else
|
|
90
|
+
value[key] = input[key];
|
|
91
|
+
}
|
|
92
|
+
if (input.identity !== null)
|
|
93
|
+
value[Token.identity] = input.identity;
|
|
94
|
+
if (input.complete)
|
|
95
|
+
value[Token.complete] = true;
|
|
96
|
+
return Object.freeze(value);
|
|
97
|
+
}
|
|
98
|
+
/** Shorthand mappings are frozen null-prototype records, as `Shorthands.read` returns them. */
|
|
99
|
+
function shorthands(input) {
|
|
100
|
+
return Object.freeze(lookup(input, strings));
|
|
101
|
+
}
|
|
102
|
+
/** A frozen record of frozen string lists. */
|
|
103
|
+
function properties(input) {
|
|
104
|
+
return Object.freeze(Object.fromEntries(input.map(([key, value]) => [
|
|
105
|
+
key,
|
|
106
|
+
Object.freeze([...value]),
|
|
107
|
+
])));
|
|
108
|
+
}
|
|
109
|
+
function number(input) {
|
|
110
|
+
if (typeof input === 'number')
|
|
111
|
+
return input;
|
|
112
|
+
const tag = input.n;
|
|
113
|
+
if (tag === 'NaN')
|
|
114
|
+
return Number.NaN;
|
|
115
|
+
if (tag === 'Infinity')
|
|
116
|
+
return Number.POSITIVE_INFINITY;
|
|
117
|
+
if (tag === '-Infinity')
|
|
118
|
+
return Number.NEGATIVE_INFINITY;
|
|
119
|
+
return -0;
|
|
120
|
+
}
|
|
121
|
+
function isNumber(input) {
|
|
122
|
+
return (typeof input === 'number' ||
|
|
123
|
+
(typeof input === 'object' &&
|
|
124
|
+
input !== null &&
|
|
125
|
+
!Array.isArray(input) &&
|
|
126
|
+
'n' in input));
|
|
127
|
+
}
|
|
128
|
+
function strings(input) {
|
|
129
|
+
return Object.freeze([...input]);
|
|
130
|
+
}
|
|
131
|
+
function record(input, decode) {
|
|
132
|
+
return Object.freeze(Object.fromEntries(input.map(([key, value]) => [key, decode(value)])));
|
|
133
|
+
}
|
|
134
|
+
/** Authored container names are frozen copies, and an omitted list is a fresh array. */
|
|
135
|
+
function containerNames(input) {
|
|
136
|
+
const names = input;
|
|
137
|
+
return names.length ? Object.freeze([...names]) : [];
|
|
138
|
+
}
|
|
139
|
+
/** A mutable null-prototype record. */
|
|
140
|
+
function lookup(input, decode) {
|
|
141
|
+
return Object.assign(Object.create(null), Object.fromEntries(input.map(([key, value]) => [key, decode(value)])));
|
|
142
|
+
}
|
|
143
|
+
/** Creates a decoder that shares one contract table. */
|
|
144
|
+
function create(contracts, options) {
|
|
145
|
+
function binding(input) {
|
|
146
|
+
const value = {
|
|
147
|
+
name: input.name,
|
|
148
|
+
type: input.type,
|
|
149
|
+
...(input.zero ? { zero: true } : {}),
|
|
150
|
+
variable: true,
|
|
151
|
+
};
|
|
152
|
+
return Object.freeze(input.dynamic
|
|
153
|
+
? Object.defineProperty(value, Binding.dynamic, { value: true })
|
|
154
|
+
: value);
|
|
155
|
+
}
|
|
156
|
+
function reference(input) {
|
|
157
|
+
const value = Token.create({
|
|
158
|
+
contract: contracts[input.c],
|
|
159
|
+
group: input.g,
|
|
160
|
+
path: input.p,
|
|
161
|
+
value: tokenValue(input.v),
|
|
162
|
+
});
|
|
163
|
+
return input.w
|
|
164
|
+
? Object.freeze({
|
|
165
|
+
...value,
|
|
166
|
+
[Token.web]: true,
|
|
167
|
+
})
|
|
168
|
+
: value;
|
|
169
|
+
}
|
|
170
|
+
function expression(input) {
|
|
171
|
+
const parts = Object.freeze(input.parts.map((part) => {
|
|
172
|
+
if (typeof part === 'string')
|
|
173
|
+
return part;
|
|
174
|
+
const fields = part;
|
|
175
|
+
if ('binding' in fields)
|
|
176
|
+
return binding(fields.binding);
|
|
177
|
+
return reference(fields.ref);
|
|
178
|
+
}));
|
|
179
|
+
return Object.freeze(input.group === null
|
|
180
|
+
? { [Token.expression]: true, parts }
|
|
181
|
+
: { [Token.expression]: true, group: input.group, parts });
|
|
182
|
+
}
|
|
183
|
+
function tokenValue(input) {
|
|
184
|
+
if (typeof input === 'string')
|
|
185
|
+
return input;
|
|
186
|
+
if (isNumber(input))
|
|
187
|
+
return number(input);
|
|
188
|
+
const fields = input;
|
|
189
|
+
if ('ref' in fields)
|
|
190
|
+
return reference(fields.ref);
|
|
191
|
+
if ('expr' in fields)
|
|
192
|
+
return expression(fields.expr);
|
|
193
|
+
return record(fields.obj, tokenValue);
|
|
194
|
+
}
|
|
195
|
+
function data(input) {
|
|
196
|
+
if (input === undefined)
|
|
197
|
+
return undefined;
|
|
198
|
+
if (input === null ||
|
|
199
|
+
typeof input === 'string' ||
|
|
200
|
+
typeof input === 'boolean')
|
|
201
|
+
return input;
|
|
202
|
+
if (typeof input === 'number')
|
|
203
|
+
return input;
|
|
204
|
+
if (Array.isArray(input))
|
|
205
|
+
return Object.freeze(input.map(data));
|
|
206
|
+
const fields = input;
|
|
207
|
+
if ('n' in fields)
|
|
208
|
+
return number(fields);
|
|
209
|
+
if ('$' in fields)
|
|
210
|
+
return undefined;
|
|
211
|
+
if ('ref' in fields)
|
|
212
|
+
return reference(fields.ref);
|
|
213
|
+
if ('expr' in fields)
|
|
214
|
+
return expression(fields.expr);
|
|
215
|
+
if ('binding' in fields)
|
|
216
|
+
return binding(fields.binding);
|
|
217
|
+
if ('theme' in fields)
|
|
218
|
+
return definition(fields.theme);
|
|
219
|
+
return record(fields.obj, data);
|
|
220
|
+
}
|
|
221
|
+
// Authored configuration literals are mutable, and their objects have no prototype.
|
|
222
|
+
function authored(input) {
|
|
223
|
+
if (Array.isArray(input))
|
|
224
|
+
return input.map(authored);
|
|
225
|
+
if (input === null || typeof input !== 'object')
|
|
226
|
+
return data(input);
|
|
227
|
+
const fields = input;
|
|
228
|
+
if (!('obj' in fields))
|
|
229
|
+
return data(input);
|
|
230
|
+
return lookup(fields.obj, authored);
|
|
231
|
+
}
|
|
232
|
+
// Theme values flatten token groups into mutable records around the frozen token values.
|
|
233
|
+
// A group is never a value, so an object with scheme or condition keys is one.
|
|
234
|
+
function tree(input) {
|
|
235
|
+
const fields = input;
|
|
236
|
+
const entries = fields !== null && typeof fields === 'object'
|
|
237
|
+
? fields.obj
|
|
238
|
+
: undefined;
|
|
239
|
+
if (!entries ||
|
|
240
|
+
entries.some(([key]) => key === 'default' || key === 'light' || key === 'dark'))
|
|
241
|
+
return data(input);
|
|
242
|
+
return Object.fromEntries(entries.map(([key, value]) => [key, tree(value)]));
|
|
243
|
+
}
|
|
244
|
+
// Query metadata spreads over the token values of each configured theme.
|
|
245
|
+
function themeValues(input) {
|
|
246
|
+
return Object.fromEntries(input.obj.map(([key, value]) => {
|
|
247
|
+
if (key === 'breakpoint' || key === 'container')
|
|
248
|
+
return [key, Object.freeze(lookup(value.obj, String))];
|
|
249
|
+
if (key === 'containerNames')
|
|
250
|
+
return [key, containerNames(value)];
|
|
251
|
+
return [key, tree(value)];
|
|
252
|
+
}));
|
|
253
|
+
}
|
|
254
|
+
// Normalized configuration options keep authored literals beside the flattened themes.
|
|
255
|
+
function configOptions(input) {
|
|
256
|
+
return Object.fromEntries(input.obj.map(([key, value]) => {
|
|
257
|
+
if (key === 'theme')
|
|
258
|
+
return [key, themeValues(value)];
|
|
259
|
+
if (key === 'themes')
|
|
260
|
+
return [
|
|
261
|
+
key,
|
|
262
|
+
Object.fromEntries(value.obj.map(([name, theme]) => [
|
|
263
|
+
name,
|
|
264
|
+
themeValues(theme),
|
|
265
|
+
])),
|
|
266
|
+
];
|
|
267
|
+
return [key, authored(value)];
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
function definition(input) {
|
|
271
|
+
const contract = contracts[input.contract];
|
|
272
|
+
const queries = input.queries;
|
|
273
|
+
const metadata = Object.freeze({
|
|
274
|
+
contract,
|
|
275
|
+
...(input.cssName !== null ? { cssName: input.cssName } : {}),
|
|
276
|
+
...(input.paths !== null
|
|
277
|
+
? { paths: properties(input.paths) }
|
|
278
|
+
: {}),
|
|
279
|
+
values: record(input.values, tokenValue),
|
|
280
|
+
// Variable sets always record their query metadata, even when it is empty.
|
|
281
|
+
...(contract.variableSet && !queries ? { queries: undefined } : {}),
|
|
282
|
+
...(queries
|
|
283
|
+
? {
|
|
284
|
+
queries: Object.freeze({
|
|
285
|
+
breakpoint: Object.freeze(lookup(queries.breakpoint, String)),
|
|
286
|
+
containerNames: containerNames(queries.containerNames),
|
|
287
|
+
container: Object.freeze(lookup(queries.container, String)),
|
|
288
|
+
}),
|
|
289
|
+
}
|
|
290
|
+
: {}),
|
|
291
|
+
});
|
|
292
|
+
const className = input.className;
|
|
293
|
+
const value = Object.freeze(Object.defineProperty({
|
|
294
|
+
get className() {
|
|
295
|
+
if ('ok' in className)
|
|
296
|
+
return className.ok;
|
|
297
|
+
if (className.error === new MissingTransformError().message)
|
|
298
|
+
throw new MissingTransformError();
|
|
299
|
+
throw new Error(className.error);
|
|
300
|
+
},
|
|
301
|
+
style: (styles, options = {}) => {
|
|
302
|
+
if (!contract[Token.identity])
|
|
303
|
+
Identity.requireId(undefined, 'Theme.define');
|
|
304
|
+
return Authoring.create(styles, {
|
|
305
|
+
...options,
|
|
306
|
+
theme: value,
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
tokens: data(input.tokens),
|
|
310
|
+
variants: (styles, options = {}) => Authoring.variants(styles, options),
|
|
311
|
+
vars: data(input.vars),
|
|
312
|
+
}, Token.definition, { value: metadata }));
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
function declarationValue(input) {
|
|
316
|
+
return data(input);
|
|
317
|
+
}
|
|
318
|
+
function style(input) {
|
|
319
|
+
const declarations = Object.freeze(input.declarations.map(([property, value, important]) => Object.freeze({
|
|
320
|
+
...(important ? { important: true } : {}),
|
|
321
|
+
property: property,
|
|
322
|
+
value: declarationValue(value),
|
|
323
|
+
})));
|
|
324
|
+
const rules = input.rules;
|
|
325
|
+
const targets = input.targets;
|
|
326
|
+
const body = rules
|
|
327
|
+
? {
|
|
328
|
+
name: input.name,
|
|
329
|
+
declarations,
|
|
330
|
+
rules: Object.freeze(rules.map(([condition, child]) => Object.freeze({
|
|
331
|
+
...(condition !== null
|
|
332
|
+
? { condition: condition }
|
|
333
|
+
: {}),
|
|
334
|
+
style: style(child),
|
|
335
|
+
}))),
|
|
336
|
+
}
|
|
337
|
+
: { declarations, name: input.name };
|
|
338
|
+
return Object.freeze({
|
|
339
|
+
...body,
|
|
340
|
+
...(targets
|
|
341
|
+
? {
|
|
342
|
+
targets: Object.freeze({
|
|
343
|
+
...(targets.native !== undefined
|
|
344
|
+
? { native: target(targets.native) }
|
|
345
|
+
: {}),
|
|
346
|
+
...(targets.ios !== undefined
|
|
347
|
+
? { ios: target(targets.ios) }
|
|
348
|
+
: {}),
|
|
349
|
+
...(targets.android !== undefined
|
|
350
|
+
? { android: target(targets.android) }
|
|
351
|
+
: {}),
|
|
352
|
+
...(targets.web !== undefined
|
|
353
|
+
? { web: style(targets.web) }
|
|
354
|
+
: {}),
|
|
355
|
+
}),
|
|
356
|
+
}
|
|
357
|
+
: {}),
|
|
358
|
+
...(input.composition !== undefined
|
|
359
|
+
? { composition: input.composition }
|
|
360
|
+
: {}),
|
|
361
|
+
...(input.cssOutput !== undefined ? { cssOutput: input.cssOutput } : {}),
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
// Native target data is copied into frozen null-prototype records, as `Targets.copy` does.
|
|
365
|
+
function target(input) {
|
|
366
|
+
if (Array.isArray(input))
|
|
367
|
+
return Object.freeze(input.map(target));
|
|
368
|
+
if (input === null || typeof input !== 'object' || !('obj' in input))
|
|
369
|
+
return data(input);
|
|
370
|
+
return Object.freeze(lookup(input.obj, target));
|
|
371
|
+
}
|
|
372
|
+
function styles(input) {
|
|
373
|
+
return Object.freeze({
|
|
374
|
+
styles: Object.freeze(input.styles.map(style)),
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
// Compositions copy the styles they combine, and a copy differs from its source in content.
|
|
378
|
+
function composed(input, sources) {
|
|
379
|
+
const decoded = style(input);
|
|
380
|
+
const rules = input.rules;
|
|
381
|
+
const name = input.name;
|
|
382
|
+
if (!rules || !decoded.rules)
|
|
383
|
+
return decoded;
|
|
384
|
+
const copied = (child) => sources.get(child.name) !== JSON.stringify(child);
|
|
385
|
+
// Runtime compositions copy each conditional rule with the output mode of its source.
|
|
386
|
+
if (name.startsWith('composition-'))
|
|
387
|
+
return Object.freeze({
|
|
388
|
+
...decoded,
|
|
389
|
+
rules: Object.freeze(decoded.rules.map((rule, index) => {
|
|
390
|
+
const child = rules[index][1];
|
|
391
|
+
return copied(child) && !('cssOutput' in rule.style)
|
|
392
|
+
? Object.freeze({
|
|
393
|
+
...rule,
|
|
394
|
+
style: Object.freeze({ ...rule.style, cssOutput: undefined }),
|
|
395
|
+
})
|
|
396
|
+
: rule;
|
|
397
|
+
})),
|
|
398
|
+
});
|
|
399
|
+
// Static compositions copy referenced styles mutably beside their inline parts.
|
|
400
|
+
if (decoded.declarations.length ||
|
|
401
|
+
rules.some(([condition]) => condition !== null))
|
|
402
|
+
return decoded;
|
|
403
|
+
return Object.freeze({
|
|
404
|
+
...decoded,
|
|
405
|
+
rules: Object.freeze(decoded.rules.map((rule) => rule.style.name === name
|
|
406
|
+
? rule
|
|
407
|
+
: Object.freeze({ ...rule, style: { ...rule.style } }))),
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
function labelled(input) {
|
|
411
|
+
const inputs = input.styles;
|
|
412
|
+
const sources = new Map(inputs.map((entry) => [entry.name, JSON.stringify(entry)]));
|
|
413
|
+
const definition = {
|
|
414
|
+
styles: Object.freeze(inputs.map((entry) => composed(entry, sources))),
|
|
415
|
+
};
|
|
416
|
+
const labels = input.labels;
|
|
417
|
+
if (labels)
|
|
418
|
+
Object.defineProperty(definition, ClassName.labels, {
|
|
419
|
+
value: Object.freeze(Object.fromEntries(labels.map(([name, label, namespace]) => [
|
|
420
|
+
name,
|
|
421
|
+
{ name: label, namespace: namespace ?? undefined },
|
|
422
|
+
]))),
|
|
423
|
+
});
|
|
424
|
+
return Object.freeze(definition);
|
|
425
|
+
}
|
|
426
|
+
// A call's lowered recipe shares the axes and defaults of its recipe metadata.
|
|
427
|
+
function staticRecipe(input, shared) {
|
|
428
|
+
return {
|
|
429
|
+
axes: shared?.axes ??
|
|
430
|
+
lookup(input.axes, (choices) => [...choices]),
|
|
431
|
+
defaults: shared?.defaults ?? lookup(input.defaults, (value) => value),
|
|
432
|
+
rules: input.rules.map((rule) => ({
|
|
433
|
+
matches: rule.matches.map(([axis, choices]) => [
|
|
434
|
+
axis,
|
|
435
|
+
[...choices],
|
|
436
|
+
]),
|
|
437
|
+
value: styles(rule.value),
|
|
438
|
+
})),
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
// Recipe metadata is mutable and keyed by null-prototype records, as `Recipes.expand` builds it.
|
|
442
|
+
function recipe(input) {
|
|
443
|
+
return {
|
|
444
|
+
axes: lookup(input.axes, (choices) => [...choices]),
|
|
445
|
+
defaults: lookup(input.defaults, (value) => value),
|
|
446
|
+
...(input.payloads !== undefined
|
|
447
|
+
? {
|
|
448
|
+
payloads: input.payloads.map((payload) => ({
|
|
449
|
+
axis: payload.axis,
|
|
450
|
+
choice: payload.choice,
|
|
451
|
+
slots: payload.slots.map((slots) => Object.fromEntries(slots)),
|
|
452
|
+
})),
|
|
453
|
+
defaultPayloads: lookup(input.defaultPayloads, (fields) => lookup(fields, (value) => isNumber(value) ? number(value) : value)),
|
|
454
|
+
}
|
|
455
|
+
: {}),
|
|
456
|
+
...(input.conditions !== undefined
|
|
457
|
+
? { conditions: [...input.conditions] }
|
|
458
|
+
: {}),
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function slots(input) {
|
|
462
|
+
return record(input, (value) => binding(value));
|
|
463
|
+
}
|
|
464
|
+
// Callback slots are null-prototype records, so field names never meet inherited keys.
|
|
465
|
+
function fields(input) {
|
|
466
|
+
return Object.freeze(Object.assign(Object.create(null), Object.fromEntries(input.map(([key, value]) => [
|
|
467
|
+
key,
|
|
468
|
+
binding(value),
|
|
469
|
+
]))));
|
|
470
|
+
}
|
|
471
|
+
function nativeContext(input) {
|
|
472
|
+
return Object.freeze({
|
|
473
|
+
defaultVars: input.defaultVars,
|
|
474
|
+
vars: record(input.vars, (value) => definition(value)),
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function owner(input) {
|
|
478
|
+
return Object.freeze({
|
|
479
|
+
attributes: strings(input.attributes),
|
|
480
|
+
identity: input.identity,
|
|
481
|
+
slots: strings(input.slots),
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function counts(input) {
|
|
485
|
+
return new Map(input.map(([start, count]) => [start, count]));
|
|
486
|
+
}
|
|
487
|
+
function call(input) {
|
|
488
|
+
const value = {};
|
|
489
|
+
const shared = input.recipe !== undefined ? recipe(input.recipe) : undefined;
|
|
490
|
+
// Without source rewriting, every definition call records its portable identity, if any.
|
|
491
|
+
if (options.compiler === false &&
|
|
492
|
+
input.composition === undefined &&
|
|
493
|
+
input.runtimeComposition === undefined &&
|
|
494
|
+
input.compositionCase === undefined)
|
|
495
|
+
value.portable = undefined;
|
|
496
|
+
for (const [key, entry] of Object.entries(input)) {
|
|
497
|
+
switch (key) {
|
|
498
|
+
case 'nativeContext':
|
|
499
|
+
value[key] = nativeContext(entry);
|
|
500
|
+
break;
|
|
501
|
+
case 'cssNamespace':
|
|
502
|
+
value[key] = entry ?? undefined;
|
|
503
|
+
break;
|
|
504
|
+
case 'portable':
|
|
505
|
+
value[key] = entry ?? undefined;
|
|
506
|
+
break;
|
|
507
|
+
// Composition metadata is assembled as mutable lists.
|
|
508
|
+
case 'portableInputs':
|
|
509
|
+
case 'compositionCases':
|
|
510
|
+
case 'composition':
|
|
511
|
+
value[key] = [...entry];
|
|
512
|
+
break;
|
|
513
|
+
case 'ownership':
|
|
514
|
+
value[key] = owner(entry);
|
|
515
|
+
break;
|
|
516
|
+
case 'runtimeComposition':
|
|
517
|
+
value[key] = entry.map((input) => ({
|
|
518
|
+
...(input.applicationStart !== undefined
|
|
519
|
+
? { applicationStart: input.applicationStart }
|
|
520
|
+
: {}),
|
|
521
|
+
...(input.condition !== undefined
|
|
522
|
+
? { condition: input.condition }
|
|
523
|
+
: {}),
|
|
524
|
+
end: input.end,
|
|
525
|
+
name: input.name,
|
|
526
|
+
owners: input.owners.map((owner) => ({
|
|
527
|
+
attributes: [...owner.attributes],
|
|
528
|
+
identity: owner.identity,
|
|
529
|
+
slots: [...owner.slots],
|
|
530
|
+
})),
|
|
531
|
+
start: input.start,
|
|
532
|
+
}));
|
|
533
|
+
break;
|
|
534
|
+
case 'recipe':
|
|
535
|
+
value[key] = shared;
|
|
536
|
+
break;
|
|
537
|
+
case 'dynamicRecipe':
|
|
538
|
+
case 'staticRecipe':
|
|
539
|
+
value[key] = staticRecipe(entry, shared);
|
|
540
|
+
break;
|
|
541
|
+
case 'recipeTypes':
|
|
542
|
+
value[key] = lookup(entry, (choices) => lookup(choices, String));
|
|
543
|
+
break;
|
|
544
|
+
case 'shorthands':
|
|
545
|
+
value[key] = shorthands(entry);
|
|
546
|
+
break;
|
|
547
|
+
case 'typography':
|
|
548
|
+
case 'typographyQueries':
|
|
549
|
+
value[key] = counts(entry);
|
|
550
|
+
break;
|
|
551
|
+
case 'slots':
|
|
552
|
+
value[key] = fields(entry);
|
|
553
|
+
break;
|
|
554
|
+
default:
|
|
555
|
+
value[key] = entry;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return Object.freeze(value);
|
|
559
|
+
}
|
|
560
|
+
function signature(input) {
|
|
561
|
+
return {
|
|
562
|
+
// Parameters are the evaluated literal records, which have no prototype.
|
|
563
|
+
parameters: input.parameters.map((parameter) => Object.assign(Object.create(null), {
|
|
564
|
+
...(parameter.default !== undefined
|
|
565
|
+
? {
|
|
566
|
+
default: isNumber(parameter.default)
|
|
567
|
+
? number(parameter.default)
|
|
568
|
+
: parameter.default,
|
|
569
|
+
}
|
|
570
|
+
: {}),
|
|
571
|
+
name: parameter.name,
|
|
572
|
+
...(parameter.syntax !== undefined
|
|
573
|
+
? { syntax: parameter.syntax }
|
|
574
|
+
: {}),
|
|
575
|
+
})),
|
|
576
|
+
returns: input.returns,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
// Authored variable mappings stay the mutable null-prototype literal the configuration read.
|
|
580
|
+
function mappings(input) {
|
|
581
|
+
if (input === null || input === undefined)
|
|
582
|
+
return undefined;
|
|
583
|
+
if (input === false)
|
|
584
|
+
return false;
|
|
585
|
+
return lookup(input, (properties) => [
|
|
586
|
+
...properties,
|
|
587
|
+
]);
|
|
588
|
+
}
|
|
589
|
+
// Configuration calls carry `appearance` and stay mutable. Factory calls are frozen.
|
|
590
|
+
function themeCall(input) {
|
|
591
|
+
const value = {};
|
|
592
|
+
for (const [key, entry] of Object.entries(input)) {
|
|
593
|
+
// Variable configurations always record their mappings, even when none were authored.
|
|
594
|
+
if (key === 'variableMappings' &&
|
|
595
|
+
(input.variableConfig || entry === false)) {
|
|
596
|
+
value[key] = mappings(entry);
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
if (entry === null || entry === false)
|
|
600
|
+
continue;
|
|
601
|
+
switch (key) {
|
|
602
|
+
case 'function':
|
|
603
|
+
value[key] = signature(entry);
|
|
604
|
+
break;
|
|
605
|
+
case 'members':
|
|
606
|
+
value[key] = input.appearance
|
|
607
|
+
? Object.fromEntries(entry)
|
|
608
|
+
: record(entry, String);
|
|
609
|
+
break;
|
|
610
|
+
case 'options':
|
|
611
|
+
value[key] = configOptions(entry);
|
|
612
|
+
break;
|
|
613
|
+
case 'variables':
|
|
614
|
+
value[key] = slots(entry);
|
|
615
|
+
break;
|
|
616
|
+
default:
|
|
617
|
+
value[key] = entry;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return (input.appearance ? value : Object.freeze(value));
|
|
621
|
+
}
|
|
622
|
+
function alias(input) {
|
|
623
|
+
const call = input.call;
|
|
624
|
+
// A style alias copies a fixed set of the theme call's fields, defined or not.
|
|
625
|
+
if (input.bindings !== null)
|
|
626
|
+
return {
|
|
627
|
+
recipe: call.recipe,
|
|
628
|
+
destructured: input.destructured,
|
|
629
|
+
end: call.end,
|
|
630
|
+
name: call.name,
|
|
631
|
+
start: call.start,
|
|
632
|
+
tokenType: call.tokenType,
|
|
633
|
+
type: (call.type ?? undefined),
|
|
634
|
+
options: call.options === null ? undefined : configOptions(call.options),
|
|
635
|
+
variableConfig: call.variableConfig ? true : undefined,
|
|
636
|
+
variableMappings: mappings(call.variableMappings),
|
|
637
|
+
output: (call.output ?? undefined),
|
|
638
|
+
bindings: [...input.bindings],
|
|
639
|
+
};
|
|
640
|
+
return {
|
|
641
|
+
...themeCall(call),
|
|
642
|
+
destructured: input.destructured,
|
|
643
|
+
...(input.retained ? { retained: true } : {}),
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
function varsRead(input) {
|
|
647
|
+
return {
|
|
648
|
+
defaultVars: input.defaultVars,
|
|
649
|
+
end: input.end,
|
|
650
|
+
owner: input.owner,
|
|
651
|
+
start: input.start,
|
|
652
|
+
unnamed: input.unnamed,
|
|
653
|
+
vars: Object.fromEntries(input.vars.map(([key, value]) => [
|
|
654
|
+
key,
|
|
655
|
+
definition(value),
|
|
656
|
+
])),
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
// Contribution data is mutable. Only the styles `Style.define` produces inside it are frozen.
|
|
660
|
+
function entry(input) {
|
|
661
|
+
if (input.kind === 'block')
|
|
662
|
+
return {
|
|
663
|
+
kind: 'block',
|
|
664
|
+
header: input.header,
|
|
665
|
+
entries: input.entries.map(entry),
|
|
666
|
+
};
|
|
667
|
+
if (input.kind === 'descriptor')
|
|
668
|
+
return {
|
|
669
|
+
kind: 'descriptor',
|
|
670
|
+
name: input.name,
|
|
671
|
+
value: (isNumber(input.value) ? number(input.value) : input.value),
|
|
672
|
+
};
|
|
673
|
+
return { kind: 'style', style: style(input.style) };
|
|
674
|
+
}
|
|
675
|
+
function scalarRecord(input) {
|
|
676
|
+
return Object.fromEntries(input.map(([key, value]) => [
|
|
677
|
+
key,
|
|
678
|
+
isNumber(value) ? number(value) : value,
|
|
679
|
+
]));
|
|
680
|
+
}
|
|
681
|
+
// Grouping rules nest plain `global` styles around the defined styles of their selectors.
|
|
682
|
+
function ruleStyle(input) {
|
|
683
|
+
if (input.name !== 'global')
|
|
684
|
+
return style(input);
|
|
685
|
+
return {
|
|
686
|
+
name: 'global',
|
|
687
|
+
declarations: [],
|
|
688
|
+
rules: (input.rules ?? []).map(([condition, child]) => ({
|
|
689
|
+
condition: condition,
|
|
690
|
+
style: ruleStyle(child),
|
|
691
|
+
})),
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
function contribution(input) {
|
|
695
|
+
const value = (() => {
|
|
696
|
+
switch (input.kind) {
|
|
697
|
+
case 'block':
|
|
698
|
+
return {
|
|
699
|
+
kind: 'block',
|
|
700
|
+
header: input.header,
|
|
701
|
+
entries: input.entries.map(entry),
|
|
702
|
+
};
|
|
703
|
+
case 'descriptor':
|
|
704
|
+
return {
|
|
705
|
+
kind: 'descriptor',
|
|
706
|
+
rule: input.rule,
|
|
707
|
+
name: input.name,
|
|
708
|
+
declarations: scalarRecord(input.declarations),
|
|
709
|
+
};
|
|
710
|
+
case 'font-face':
|
|
711
|
+
return {
|
|
712
|
+
kind: 'font-face',
|
|
713
|
+
declarations: scalarRecord(input.declarations),
|
|
714
|
+
};
|
|
715
|
+
case 'keyframes':
|
|
716
|
+
return {
|
|
717
|
+
kind: 'keyframes',
|
|
718
|
+
name: input.name,
|
|
719
|
+
frames: input.frames.map((frame) => ({
|
|
720
|
+
stop: frame.stop,
|
|
721
|
+
style: style(frame.style),
|
|
722
|
+
})),
|
|
723
|
+
};
|
|
724
|
+
case 'layers':
|
|
725
|
+
return { kind: 'layers', names: [...input.names] };
|
|
726
|
+
case 'rule':
|
|
727
|
+
return {
|
|
728
|
+
kind: 'rule',
|
|
729
|
+
selector: input.selector,
|
|
730
|
+
style: ruleStyle(input.style),
|
|
731
|
+
};
|
|
732
|
+
default:
|
|
733
|
+
return Object.fromEntries(Object.entries(input).filter(([key]) => key !== 'within'));
|
|
734
|
+
}
|
|
735
|
+
})();
|
|
736
|
+
return (input.within !== undefined
|
|
737
|
+
? { ...value, within: [...input.within] }
|
|
738
|
+
: value);
|
|
739
|
+
}
|
|
740
|
+
function contributionCall(input) {
|
|
741
|
+
return {
|
|
742
|
+
kind: input.kind,
|
|
743
|
+
start: input.start,
|
|
744
|
+
end: input.end,
|
|
745
|
+
...(input.function !== undefined
|
|
746
|
+
? { function: signature(input.function) }
|
|
747
|
+
: {}),
|
|
748
|
+
...(input.name !== undefined ? { name: input.name } : {}),
|
|
749
|
+
...(input.binding !== undefined ? { binding: input.binding } : {}),
|
|
750
|
+
...(input.exported !== undefined ? { exported: input.exported } : {}),
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function result(input) {
|
|
754
|
+
const contributions = (input.contributions ?? []).map(contribution);
|
|
755
|
+
// Namespaces are the namespace contributions themselves, as a filtered list.
|
|
756
|
+
const value = {
|
|
757
|
+
namespaces: contributions.filter((entry) => entry.kind === 'namespace'),
|
|
758
|
+
};
|
|
759
|
+
if (input.contributions !== undefined) {
|
|
760
|
+
value.contributions = contributions;
|
|
761
|
+
value.contributionStarts = [...input.contributionStarts];
|
|
762
|
+
}
|
|
763
|
+
if (input.contributionCalls !== undefined)
|
|
764
|
+
value.contributionCalls = input.contributionCalls.map(contributionCall);
|
|
765
|
+
value.calls = Object.freeze(input.calls.map(call));
|
|
766
|
+
value.styles = labelled(input.styles);
|
|
767
|
+
if (input.variableCalls !== undefined)
|
|
768
|
+
value.variableCalls = Object.freeze(input.variableCalls.map((entry) => Object.freeze({
|
|
769
|
+
explicit: entry.explicit,
|
|
770
|
+
start: entry.start,
|
|
771
|
+
end: entry.end,
|
|
772
|
+
slots: slots(entry.slots),
|
|
773
|
+
})));
|
|
774
|
+
value.themeAliases = Object.freeze(input.themeAliases.map(alias));
|
|
775
|
+
for (const key of ['themeAppearances', 'themeScripts', 'themeSelections'])
|
|
776
|
+
if (input[key] !== undefined)
|
|
777
|
+
value[key] = strings(input[key]);
|
|
778
|
+
value.themeCalls = Object.freeze(input.themeCalls.map(themeCall));
|
|
779
|
+
if (input.staticThemeReferences !== undefined)
|
|
780
|
+
value.staticThemeReferences = Object.freeze(input.staticThemeReferences.map((entry) => ({
|
|
781
|
+
...entry,
|
|
782
|
+
})));
|
|
783
|
+
value.themeReferences = Object.freeze(input.themeReferences.map((entry) => Object.freeze({ ...entry })));
|
|
784
|
+
// Collected themes are keyed by a null-prototype record. A module without theme
|
|
785
|
+
// imports collects none and returns an ordinary empty record.
|
|
786
|
+
value.vars = Object.freeze(input.collectedThemes
|
|
787
|
+
? lookup(input.vars, (entry) => definition(entry))
|
|
788
|
+
: {});
|
|
789
|
+
if (input.nativeVars !== undefined)
|
|
790
|
+
value.nativeVars = Object.freeze(input.nativeVars.map(varsRead));
|
|
791
|
+
return Object.freeze(value);
|
|
792
|
+
}
|
|
793
|
+
return { result };
|
|
794
|
+
}
|
|
795
|
+
//# sourceMappingURL=Wire.js.map
|