zyzz 0.0.3 → 0.0.5
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/README.md +34 -19
- package/dist/Config.d.ts +16 -167
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +7 -246
- package/dist/Config.js.map +1 -1
- package/dist/Style.d.ts +15 -12
- package/dist/Style.d.ts.map +1 -1
- package/dist/Style.js +51 -26
- package/dist/Style.js.map +1 -1
- package/dist/Vars.d.ts +114 -0
- package/dist/Vars.d.ts.map +1 -0
- package/dist/Vars.js +42 -0
- package/dist/Vars.js.map +1 -0
- package/dist/compiler/Graph.js +11 -8
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Native.d.ts +5 -5
- package/dist/compiler/Native.d.ts.map +1 -1
- package/dist/compiler/Native.js +21 -21
- package/dist/compiler/Native.js.map +1 -1
- package/dist/compiler/Source.d.ts +8 -6
- package/dist/compiler/Source.d.ts.map +1 -1
- package/dist/compiler/Source.js +47 -14
- package/dist/compiler/Source.js.map +1 -1
- package/dist/compiler/Transform.d.ts +1 -1
- package/dist/compiler/Transform.d.ts.map +1 -1
- package/dist/compiler/Transform.js +58 -22
- package/dist/compiler/Transform.js.map +1 -1
- package/dist/compiler/internal/Compositions.d.ts +5 -0
- package/dist/compiler/internal/Compositions.d.ts.map +1 -1
- package/dist/compiler/internal/Compositions.js +22 -3
- package/dist/compiler/internal/Compositions.js.map +1 -1
- package/dist/compiler/internal/Configurations.d.ts.map +1 -1
- package/dist/compiler/internal/Configurations.js +73 -12
- package/dist/compiler/internal/Configurations.js.map +1 -1
- package/dist/compiler/internal/Contract.d.ts +1 -1
- package/dist/compiler/internal/Contract.d.ts.map +1 -1
- package/dist/compiler/internal/Contract.js +155 -13
- package/dist/compiler/internal/Contract.js.map +1 -1
- package/dist/compiler/internal/Contributions.js +1 -1
- package/dist/compiler/internal/Contributions.js.map +1 -1
- package/dist/compiler/internal/Dynamic.js +1 -1
- package/dist/compiler/internal/Dynamic.js.map +1 -1
- package/dist/compiler/internal/Expression.d.ts +3 -0
- package/dist/compiler/internal/Expression.d.ts.map +1 -1
- package/dist/compiler/internal/Expression.js +21 -0
- package/dist/compiler/internal/Expression.js.map +1 -1
- package/dist/compiler/internal/Identifiers.d.ts +1 -1
- package/dist/compiler/internal/Identifiers.d.ts.map +1 -1
- package/dist/compiler/internal/Identifiers.js +2 -2
- package/dist/compiler/internal/Identifiers.js.map +1 -1
- package/dist/compiler/internal/NativeBindings.d.ts +1 -1
- package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
- package/dist/compiler/internal/NativeBindings.js +3 -3
- package/dist/compiler/internal/NativeBindings.js.map +1 -1
- package/dist/compiler/internal/PackedStyles.d.ts +1 -1
- package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
- package/dist/compiler/internal/PackedStyles.js +15 -25
- package/dist/compiler/internal/PackedStyles.js.map +1 -1
- package/dist/compiler/internal/Recipes.js +1 -1
- package/dist/compiler/internal/Recipes.js.map +1 -1
- package/dist/compiler/internal/Selectors.js +1 -1
- package/dist/compiler/internal/Selectors.js.map +1 -1
- package/dist/compiler/internal/Themes.d.ts +12 -3
- package/dist/compiler/internal/Themes.d.ts.map +1 -1
- package/dist/compiler/internal/Themes.js +192 -52
- package/dist/compiler/internal/Themes.js.map +1 -1
- package/dist/compiler/internal/{Variables.d.ts → Vars.d.ts} +1 -1
- package/dist/compiler/internal/Vars.d.ts.map +1 -0
- package/dist/compiler/internal/{Variables.js → Vars.js} +3 -3
- package/dist/compiler/internal/Vars.js.map +1 -0
- package/dist/default.d.ts +147 -2562
- package/dist/default.d.ts.map +1 -1
- package/dist/default.js +85 -80
- package/dist/default.js.map +2 -2
- package/dist/default.js.zyzz.json +1 -1
- package/dist/esbuild/index.d.ts +3 -0
- package/dist/esbuild/index.d.ts.map +1 -0
- package/dist/esbuild/index.js +5 -0
- package/dist/esbuild/index.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/Authoring.d.ts +1 -1
- package/dist/internal/Authoring.d.ts.map +1 -1
- package/dist/internal/Authoring.js +4 -4
- package/dist/internal/Authoring.js.map +1 -1
- package/dist/internal/Binding.d.ts +1 -1
- package/dist/internal/Binding.d.ts.map +1 -1
- package/dist/internal/Completion.d.ts +19 -0
- package/dist/internal/Completion.d.ts.map +1 -0
- package/dist/internal/Completion.js +2 -0
- package/dist/internal/Completion.js.map +1 -0
- package/dist/internal/Condition.d.ts +3 -1
- package/dist/internal/Condition.d.ts.map +1 -1
- package/dist/internal/Condition.js.map +1 -1
- package/dist/internal/Configuration.d.ts +248 -0
- package/dist/internal/Configuration.d.ts.map +1 -0
- package/dist/internal/Configuration.js +343 -0
- package/dist/internal/Configuration.js.map +1 -0
- package/dist/{Theme.d.ts → internal/Theme.d.ts} +15 -13
- package/dist/internal/Theme.d.ts.map +1 -0
- package/dist/{Theme.js → internal/Theme.js} +39 -12
- package/dist/internal/Theme.js.map +1 -0
- package/dist/internal/Token.d.ts +46 -16
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js +89 -5
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Typography.d.ts +13 -5
- package/dist/internal/Typography.d.ts.map +1 -1
- package/dist/internal/Typography.js +42 -6
- package/dist/internal/Typography.js.map +1 -1
- package/dist/internal/Value.d.ts +6 -1
- package/dist/internal/Value.d.ts.map +1 -1
- package/dist/internal/Value.js.map +1 -1
- package/dist/internal/VariableSets.d.ts +20 -0
- package/dist/internal/VariableSets.d.ts.map +1 -0
- package/dist/internal/VariableSets.js +317 -0
- package/dist/internal/VariableSets.js.map +1 -0
- package/dist/next/loader.js +15 -5
- package/dist/next/loader.js.map +1 -1
- package/dist/node/Host.d.ts.map +1 -1
- package/dist/node/Host.js +1 -1
- package/dist/node/Host.js.map +1 -1
- package/dist/react-native/Host.d.ts +2 -2
- package/dist/react-native/Host.d.ts.map +1 -1
- package/dist/react-native/Host.js +4 -4
- package/dist/react-native/Host.js.map +1 -1
- package/dist/react-native/StyleSheet.d.ts +9 -8
- package/dist/react-native/StyleSheet.d.ts.map +1 -1
- package/dist/react-native/StyleSheet.js +29 -23
- package/dist/react-native/StyleSheet.js.map +1 -1
- package/dist/react-native/Variants.d.ts +3 -3
- package/dist/react-native/Variants.d.ts.map +1 -1
- package/dist/react-native/Variants.js +2 -2
- package/dist/react-native/react.d.ts +1 -1
- package/dist/react-native/react.d.ts.map +1 -1
- package/dist/react-native/react.js +5 -5
- package/dist/react-native/react.js.map +1 -1
- package/dist/rollup/index.d.ts +3 -0
- package/dist/rollup/index.d.ts.map +1 -0
- package/dist/rollup/index.js +5 -0
- package/dist/rollup/index.js.map +1 -0
- package/dist/runtime/Appearance.d.ts +7 -7
- package/dist/runtime/Appearance.d.ts.map +1 -1
- package/dist/runtime/Appearance.js +15 -15
- package/dist/runtime/Appearance.js.map +1 -1
- package/dist/runtime/Dynamic.d.ts.map +1 -1
- package/dist/runtime/Dynamic.js +4 -1
- package/dist/runtime/Dynamic.js.map +1 -1
- package/dist/runtime/NativeContext.d.ts +4 -4
- package/dist/runtime/NativeContext.d.ts.map +1 -1
- package/dist/runtime/NativeContext.js +5 -5
- package/dist/runtime/NativeContext.js.map +1 -1
- package/dist/runtime/NativeDynamic.d.ts +1 -1
- package/dist/runtime/NativeDynamic.d.ts.map +1 -1
- package/dist/runtime/NativeDynamic.js.map +1 -1
- package/dist/runtime/Props.d.ts +1 -1
- package/dist/runtime/Props.js +3 -3
- package/dist/runtime/Props.js.map +1 -1
- package/dist/runtime/Selection.d.ts +14 -10
- package/dist/runtime/Selection.d.ts.map +1 -1
- package/dist/runtime/Selection.js +19 -18
- package/dist/runtime/Selection.js.map +1 -1
- package/dist/styleFunction.d.ts +14 -14
- package/dist/styleFunction.d.ts.map +1 -1
- package/dist/styleFunction.js.map +1 -1
- package/dist/unplugin/index.d.ts +20 -0
- package/dist/unplugin/index.d.ts.map +1 -0
- package/dist/unplugin/index.js +498 -0
- package/dist/unplugin/index.js.map +1 -0
- package/dist/variants.d.ts +3 -3
- package/dist/variants.d.ts.map +1 -1
- package/dist/variants.js.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +6 -3
- package/dist/vite/index.js.map +1 -1
- package/dist/web/Css.d.ts +4 -3
- package/dist/web/Css.d.ts.map +1 -1
- package/dist/web/Css.js +4 -4
- package/dist/web/Css.js.map +1 -1
- package/dist/web/internal/Themes.d.ts +3 -2
- package/dist/web/internal/Themes.d.ts.map +1 -1
- package/dist/web/internal/Themes.js +42 -6
- package/dist/web/internal/Themes.js.map +1 -1
- package/dist/webpack/index.d.ts +3 -0
- package/dist/webpack/index.d.ts.map +1 -0
- package/dist/webpack/index.js +5 -0
- package/dist/webpack/index.js.map +1 -0
- package/package.json +23 -2
- package/src/Config.ts +43 -685
- package/src/Style.ts +97 -34
- package/src/Vars.ts +299 -0
- package/src/compiler/Graph.ts +14 -9
- package/src/compiler/Native.ts +29 -32
- package/src/compiler/Source.ts +59 -21
- package/src/compiler/Transform.ts +73 -23
- package/src/compiler/internal/Compositions.ts +36 -3
- package/src/compiler/internal/Configurations.ts +83 -11
- package/src/compiler/internal/Contract.ts +207 -15
- package/src/compiler/internal/Contributions.ts +1 -1
- package/src/compiler/internal/Dynamic.ts +1 -1
- package/src/compiler/internal/Expression.ts +26 -0
- package/src/compiler/internal/Identifiers.ts +2 -1
- package/src/compiler/internal/NativeBindings.ts +3 -3
- package/src/compiler/internal/PackedStyles.ts +22 -26
- package/src/compiler/internal/Recipes.ts +1 -1
- package/src/compiler/internal/Selectors.ts +1 -1
- package/src/compiler/internal/Themes.ts +266 -57
- package/src/compiler/internal/{Variables.ts → Vars.ts} +2 -2
- package/src/default.ts +173 -154
- package/src/esbuild/index.ts +5 -0
- package/src/index.ts +4 -4
- package/src/internal/Authoring.ts +5 -7
- package/src/internal/Binding.ts +1 -1
- package/src/internal/Completion.ts +42 -0
- package/src/internal/Condition.ts +31 -1
- package/src/internal/Configuration.ts +970 -0
- package/src/{Theme.ts → internal/Theme.ts} +75 -20
- package/src/internal/Token.ts +258 -85
- package/src/internal/Typography.ts +71 -16
- package/src/internal/Value.ts +45 -26
- package/src/internal/VariableSets.ts +458 -0
- package/src/next/loader.ts +19 -5
- package/src/node/Host.ts +1 -2
- package/src/react-native/Host.ts +6 -6
- package/src/react-native/StyleSheet.ts +49 -42
- package/src/react-native/Variants.ts +3 -3
- package/src/react-native/react.ts +6 -6
- package/src/rollup/index.ts +5 -0
- package/src/runtime/Appearance.ts +20 -20
- package/src/runtime/Dynamic.ts +4 -1
- package/src/runtime/NativeContext.ts +8 -8
- package/src/runtime/NativeDynamic.ts +2 -4
- package/src/runtime/Props.ts +3 -3
- package/src/runtime/Selection.ts +44 -33
- package/src/styleFunction.ts +22 -19
- package/src/unplugin/index.ts +600 -0
- package/src/variants.ts +7 -5
- package/src/vite/index.ts +5 -4
- package/src/web/Css.ts +10 -7
- package/src/web/internal/Themes.ts +52 -9
- package/src/webpack/index.ts +5 -0
- package/dist/Theme.d.ts.map +0 -1
- package/dist/Theme.js.map +0 -1
- package/dist/compiler/internal/Variables.d.ts.map +0 -1
- package/dist/compiler/internal/Variables.js.map +0 -1
package/src/next/loader.ts
CHANGED
|
@@ -90,10 +90,11 @@ async function compile(context: Context, source: string) {
|
|
|
90
90
|
|
|
91
91
|
const specifier = node.source.value
|
|
92
92
|
links[specifier] = null
|
|
93
|
+
// Next owns this virtual module, which has no physical stylesheet contract.
|
|
94
|
+
if (specifier === 'next/root-params') continue
|
|
93
95
|
if (
|
|
94
96
|
specifier === 'zyzz' ||
|
|
95
|
-
(specifier.startsWith('zyzz/') &&
|
|
96
|
-
specifier !== 'zyzz/default') ||
|
|
97
|
+
(specifier.startsWith('zyzz/') && specifier !== 'zyzz/default') ||
|
|
97
98
|
specifier.startsWith('node:')
|
|
98
99
|
)
|
|
99
100
|
continue
|
|
@@ -288,15 +289,28 @@ async function compile(context: Context, source: string) {
|
|
|
288
289
|
)
|
|
289
290
|
.split(Path.sep)
|
|
290
291
|
.join('/')
|
|
292
|
+
// Turbopack appends the output extension to loader-transformed resource paths.
|
|
293
|
+
const resource = await Fs.stat(context.resourcePath).then(
|
|
294
|
+
() => context.resourcePath,
|
|
295
|
+
async (error: NodeJS.ErrnoException) => {
|
|
296
|
+
if (error.code !== 'ENOENT') throw error
|
|
297
|
+
const original = context.resourcePath.slice(
|
|
298
|
+
0,
|
|
299
|
+
-Path.extname(context.resourcePath).length,
|
|
300
|
+
)
|
|
301
|
+
await Fs.access(original)
|
|
302
|
+
return original
|
|
303
|
+
},
|
|
304
|
+
)
|
|
291
305
|
const requests = [
|
|
292
306
|
...(graph.sharedCss
|
|
293
307
|
? [
|
|
294
|
-
`import ${JSON.stringify(sharedFile.startsWith('
|
|
308
|
+
`import ${JSON.stringify(sharedFile.startsWith('../') ? sharedFile : `./${sharedFile}`)};`,
|
|
295
309
|
]
|
|
296
310
|
: []),
|
|
297
311
|
...(output.css
|
|
298
312
|
? [
|
|
299
|
-
`import ${JSON.stringify(`./${Path.basename(
|
|
313
|
+
`import ${JSON.stringify(`./${Path.basename(resource)}?zyzz-style`)};`,
|
|
300
314
|
]
|
|
301
315
|
: []),
|
|
302
316
|
]
|
|
@@ -326,7 +340,7 @@ async function compile(context: Context, source: string) {
|
|
|
326
340
|
.split(Path.sep)
|
|
327
341
|
.join('/')
|
|
328
342
|
requests.push(
|
|
329
|
-
`import ${JSON.stringify(relative.startsWith('
|
|
343
|
+
`import ${JSON.stringify(relative.startsWith('../') ? relative : `./${relative}`)};`,
|
|
330
344
|
)
|
|
331
345
|
}
|
|
332
346
|
|
package/src/node/Host.ts
CHANGED
|
@@ -54,8 +54,7 @@ export async function create(options: create.Options): Promise<Runtime> {
|
|
|
54
54
|
fonts:
|
|
55
55
|
options.native.fonts && Object.freeze({ ...options.native.fonts }),
|
|
56
56
|
// Theme definitions are immutable. Only the caller-owned catalog needs copying.
|
|
57
|
-
|
|
58
|
-
options.native.themes && Object.freeze({ ...options.native.themes }),
|
|
57
|
+
vars: options.native.vars && Object.freeze({ ...options.native.vars }),
|
|
59
58
|
units:
|
|
60
59
|
options.native.units && Object.freeze({ ...options.native.units }),
|
|
61
60
|
})
|
package/src/react-native/Host.ts
CHANGED
|
@@ -28,7 +28,7 @@ export function create<
|
|
|
28
28
|
'highContrast',
|
|
29
29
|
'reducedMotion',
|
|
30
30
|
'rtl',
|
|
31
|
-
'
|
|
31
|
+
'set',
|
|
32
32
|
] as const
|
|
33
33
|
const bindings = new Set<(context: Snapshot) => () => void>()
|
|
34
34
|
const listeners = new Set<(context: Snapshot) => void>()
|
|
@@ -45,8 +45,8 @@ export function create<
|
|
|
45
45
|
(key) => !keys.includes(key as (typeof keys)[number]),
|
|
46
46
|
) ||
|
|
47
47
|
(values.colorScheme !== 'light' && values.colorScheme !== 'dark') ||
|
|
48
|
-
typeof values.
|
|
49
|
-
!values.
|
|
48
|
+
typeof values.set !== 'string' ||
|
|
49
|
+
!values.set.trim() ||
|
|
50
50
|
typeof values.density !== 'number' ||
|
|
51
51
|
!Number.isFinite(values.density) ||
|
|
52
52
|
values.density <= 0 ||
|
|
@@ -58,7 +58,7 @@ export function create<
|
|
|
58
58
|
typeof values.rtl !== 'boolean'
|
|
59
59
|
)
|
|
60
60
|
throw new InputError(
|
|
61
|
-
'Provide a
|
|
61
|
+
'Provide a set, resolved scheme, positive finite scales, and boolean accessibility inputs.',
|
|
62
62
|
)
|
|
63
63
|
const hairlineWidth =
|
|
64
64
|
Math.round(0.4 * values.density) / values.density || 1 / values.density
|
|
@@ -265,8 +265,8 @@ export type Inputs = {
|
|
|
265
265
|
readonly reducedMotion: boolean
|
|
266
266
|
/** Whether layout follows a right-to-left direction. */
|
|
267
267
|
readonly rtl: boolean
|
|
268
|
-
/** Compiled
|
|
269
|
-
readonly
|
|
268
|
+
/** Compiled set label selected by binding factories. */
|
|
269
|
+
readonly set: string
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
/** An operation attempted to change a disposed or currently updating host. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
/** Compiles portable declarations into immutable native
|
|
1
|
+
/** Compiles portable declarations into immutable native set tables. @module */
|
|
2
2
|
import type * as Style from '../Style.js'
|
|
3
|
-
import type * as
|
|
3
|
+
import type * as Vars from '../Vars.js'
|
|
4
|
+
import type * as Theme from '../internal/Theme.js'
|
|
4
5
|
import * as Token from '../internal/Token.js'
|
|
5
6
|
import type * as Native from '../internal/NativeProperties.js'
|
|
6
7
|
import * as Values from './internal/Values.js'
|
|
@@ -18,7 +19,7 @@ export const absoluteFill = Object.freeze({
|
|
|
18
19
|
top: 0,
|
|
19
20
|
} as const)
|
|
20
21
|
|
|
21
|
-
/** Explicit
|
|
22
|
+
/** Explicit set alternative, never inferred from a device. */
|
|
22
23
|
export type ColorScheme = 'dark' | 'light'
|
|
23
24
|
|
|
24
25
|
/** Failure to represent the supplied definitions on the native target. */
|
|
@@ -46,7 +47,7 @@ export class CompileError extends Error {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
|
-
* Resolves portable tokens into two static scheme tables per supplied
|
|
50
|
+
* Resolves portable tokens into two static scheme tables per supplied set.
|
|
50
51
|
* px defaults to one native logical unit. rem and font families require mappings.
|
|
51
52
|
* No device state, CSS parser, stylesheet registration, or runtime binding is used.
|
|
52
53
|
* @throws {CompileError} For unsupported semantics or invalid conversion inputs.
|
|
@@ -63,7 +64,7 @@ export function compile<
|
|
|
63
64
|
},
|
|
64
65
|
): compile.ReturnType<name, themeName, definition, platform> {
|
|
65
66
|
for (const key of Object.keys(options))
|
|
66
|
-
if (!['fonts', 'platform', 'styles', '
|
|
67
|
+
if (!['fonts', 'platform', 'styles', 'vars', 'units'].includes(key))
|
|
67
68
|
fail('invalid_options', 'Unknown native compiler option.', [key])
|
|
68
69
|
|
|
69
70
|
if (
|
|
@@ -137,15 +138,18 @@ export function compile<
|
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
const
|
|
141
|
-
|
|
141
|
+
const vars: readonly (readonly [
|
|
142
|
+
string,
|
|
143
|
+
Theme.Definition | Vars.Definition | undefined,
|
|
144
|
+
])[] =
|
|
145
|
+
options.vars === undefined
|
|
142
146
|
? [['default', undefined]]
|
|
143
|
-
: Object.entries(options.
|
|
144
|
-
if (!
|
|
147
|
+
: Object.entries(options.vars)
|
|
148
|
+
if (!vars.length)
|
|
145
149
|
fail(
|
|
146
150
|
'invalid_options',
|
|
147
|
-
'Supply at least one
|
|
148
|
-
['
|
|
151
|
+
'Supply at least one set, or omit vars for a default table.',
|
|
152
|
+
['vars'],
|
|
149
153
|
)
|
|
150
154
|
|
|
151
155
|
const tables: Record<
|
|
@@ -156,23 +160,19 @@ export function compile<
|
|
|
156
160
|
const diagnostics: Diagnostic[] = []
|
|
157
161
|
let independent: Readonly<Record<string, NativeStyle>> | undefined
|
|
158
162
|
|
|
159
|
-
for (const [label,
|
|
163
|
+
for (const [label, set] of vars) {
|
|
160
164
|
if (!label)
|
|
161
|
-
fail('invalid_options', 'Theme labels must be nonempty.', [
|
|
162
|
-
'themes',
|
|
163
|
-
label,
|
|
164
|
-
])
|
|
165
|
+
fail('invalid_options', 'Theme labels must be nonempty.', ['vars', label])
|
|
165
166
|
const metadata =
|
|
166
|
-
|
|
167
|
-
(Object.getOwnPropertyDescriptor(
|
|
167
|
+
set &&
|
|
168
|
+
(Object.getOwnPropertyDescriptor(set, Token.definition)?.value as
|
|
168
169
|
| Token.Metadata
|
|
169
170
|
| undefined)
|
|
170
|
-
if (options.
|
|
171
|
-
fail(
|
|
172
|
-
'
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
171
|
+
if (options.vars !== undefined && !metadata)
|
|
172
|
+
fail('invalid_options', 'Expected a Theme.define or Config set handle.', [
|
|
173
|
+
'vars',
|
|
174
|
+
label,
|
|
175
|
+
])
|
|
176
176
|
|
|
177
177
|
const schemes = {} as Record<
|
|
178
178
|
ColorScheme,
|
|
@@ -387,7 +387,9 @@ export declare namespace compile {
|
|
|
387
387
|
/** Immutable shared definitions, also accepted by Css.compile. */
|
|
388
388
|
readonly styles: Style.Definition<name>
|
|
389
389
|
/** Explicit output labels. Omission creates the token-fallback default table. */
|
|
390
|
-
readonly
|
|
390
|
+
readonly vars?:
|
|
391
|
+
| Readonly<Record<themeName, Theme.Definition | Vars.Definition>>
|
|
392
|
+
| undefined
|
|
391
393
|
/** Positive logical-unit scales. px defaults to one, rem has no default. */
|
|
392
394
|
readonly units?:
|
|
393
395
|
| { readonly px?: number | undefined; readonly rem?: number | undefined }
|
|
@@ -514,7 +516,7 @@ type Compiled<definition, platform, name extends string> =
|
|
|
514
516
|
|
|
515
517
|
/** Optional native authoring constraint used with satisfies before Style.define. */
|
|
516
518
|
export type Properties = {
|
|
517
|
-
/** Portable literals or property-compatible scalar
|
|
519
|
+
/** Portable literals or property-compatible scalar set references. */
|
|
518
520
|
readonly [property in keyof typeof properties]?:
|
|
519
521
|
| Atom<(typeof properties)[property]>
|
|
520
522
|
| Reference<property>
|
|
@@ -522,7 +524,7 @@ export type Properties = {
|
|
|
522
524
|
|
|
523
525
|
/**
|
|
524
526
|
* Looks up an existing table without allocating or resolving device state.
|
|
525
|
-
* @throws {SelectionError} For unknown own
|
|
527
|
+
* @throws {SelectionError} For unknown own set labels or color schemes.
|
|
526
528
|
*/
|
|
527
529
|
export function select<const tables extends Tables>(
|
|
528
530
|
styles: tables,
|
|
@@ -536,12 +538,12 @@ export function select<name extends string, themeName extends string>(
|
|
|
536
538
|
!styles ||
|
|
537
539
|
!options ||
|
|
538
540
|
(options.colorScheme !== 'light' && options.colorScheme !== 'dark') ||
|
|
539
|
-
!Object.hasOwn(styles, options.
|
|
541
|
+
!Object.hasOwn(styles, options.set)
|
|
540
542
|
)
|
|
541
543
|
throw new SelectionError(
|
|
542
|
-
'Select an existing
|
|
544
|
+
'Select an existing set label and light or dark colorScheme.',
|
|
543
545
|
)
|
|
544
|
-
return styles[options.
|
|
546
|
+
return styles[options.set][options.colorScheme]
|
|
545
547
|
}
|
|
546
548
|
|
|
547
549
|
/** Native lookup options. */
|
|
@@ -551,7 +553,7 @@ export declare namespace select {
|
|
|
551
553
|
/** Precompiled color scheme. */
|
|
552
554
|
readonly colorScheme: ColorScheme
|
|
553
555
|
/** Own label in the compiled tables. */
|
|
554
|
-
readonly
|
|
556
|
+
readonly set: themeName
|
|
555
557
|
}
|
|
556
558
|
}
|
|
557
559
|
|
|
@@ -771,23 +773,28 @@ function resolve(
|
|
|
771
773
|
(metadata.contract === value.contract ||
|
|
772
774
|
(metadata.contract[Token.identity] !== undefined &&
|
|
773
775
|
metadata.contract[Token.identity] === value.contract[Token.identity]))
|
|
774
|
-
|
|
776
|
+
let resolved = shared
|
|
775
777
|
? Object.hasOwn(metadata.values, value.path)
|
|
776
778
|
? metadata.values[value.path]
|
|
777
779
|
: undefined
|
|
778
780
|
: value.value
|
|
779
781
|
if (resolved === undefined)
|
|
780
782
|
fail('unsupported_value', 'Theme is missing a live token.', path)
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
783
|
+
while (typeof resolved === 'object') {
|
|
784
|
+
if (Token.is(resolved)) {
|
|
785
|
+
resolved = resolved.value
|
|
786
|
+
continue
|
|
787
|
+
}
|
|
788
|
+
if ('default' in resolved)
|
|
789
|
+
fail(
|
|
790
|
+
'unsupported_feature',
|
|
791
|
+
'Media-conditioned variables require a web target.',
|
|
792
|
+
path,
|
|
793
|
+
)
|
|
794
|
+
if (resolved.light !== resolved.dark) resolution.schemeIndependent = false
|
|
795
|
+
resolved = resolved[scheme]
|
|
796
|
+
}
|
|
797
|
+
return resolved
|
|
791
798
|
}
|
|
792
799
|
|
|
793
800
|
type TransformValues = {
|
|
@@ -20,8 +20,8 @@ export type Definition<
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Compiles every finite selection, including omitted axes, before application.
|
|
23
|
-
* @param options - Static recipe,
|
|
24
|
-
* @returns Immutable native tables with at most 256 selections per
|
|
23
|
+
* @param options - Static recipe, vars, and explicit native destination inputs.
|
|
24
|
+
* @returns Immutable native tables with at most 256 selections per set and scheme.
|
|
25
25
|
* @throws {CompileError} When recipe data is invalid or exceeds the selection budget.
|
|
26
26
|
* @throws {StyleSheet.CompileError} When selected declarations cannot compile for native.
|
|
27
27
|
*/
|
|
@@ -108,7 +108,7 @@ export declare namespace compile {
|
|
|
108
108
|
/** Validated static recipe retained by Source.extract. */
|
|
109
109
|
readonly recipe: recipe
|
|
110
110
|
}
|
|
111
|
-
/** Immutable tables retaining recipe metadata and
|
|
111
|
+
/** Immutable tables retaining recipe metadata and set labels. */
|
|
112
112
|
type ReturnType<
|
|
113
113
|
recipe extends Recipe.Definition = Recipe.Definition,
|
|
114
114
|
themeName extends string = string,
|
|
@@ -4,19 +4,19 @@ import * as NativeContext from '../runtime/NativeContext.js'
|
|
|
4
4
|
|
|
5
5
|
const context = React.createContext(styles(undefined))
|
|
6
6
|
|
|
7
|
-
/** Supplies
|
|
7
|
+
/** Supplies set and resolved device appearance to compiled native components. */
|
|
8
8
|
export function Provider(props: Provider.Props) {
|
|
9
9
|
if (
|
|
10
10
|
(props.colorScheme !== 'light' && props.colorScheme !== 'dark') ||
|
|
11
|
-
(props.
|
|
12
|
-
(typeof props.
|
|
11
|
+
(props.set !== undefined &&
|
|
12
|
+
(typeof props.set !== 'string' || !props.set.trim()))
|
|
13
13
|
)
|
|
14
14
|
throw new Error(
|
|
15
|
-
'Native appearance requires a resolved light/dark scheme and a nonempty
|
|
15
|
+
'Native appearance requires a resolved light/dark scheme and a nonempty set name.',
|
|
16
16
|
)
|
|
17
17
|
const value = React.useMemo(
|
|
18
|
-
() => styles({ colorScheme: props.colorScheme,
|
|
19
|
-
[props.colorScheme, props.
|
|
18
|
+
() => styles({ colorScheme: props.colorScheme, set: props.set }),
|
|
19
|
+
[props.colorScheme, props.set],
|
|
20
20
|
)
|
|
21
21
|
return React.createElement(context.Provider, { value }, props.children)
|
|
22
22
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as Scheme from '../internal/Scheme.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Binds an HTML-safe script factory to compiled named
|
|
5
|
+
* Binds an HTML-safe script factory to compiled named set classes.
|
|
6
6
|
* The factory is server-safe; only its returned JavaScript accesses the DOM.
|
|
7
7
|
* A saved scheme swaps the stylesheet scheme class and sets the inline `color-scheme`;
|
|
8
8
|
* a saved `null` scheme removes both so a cleared selection survives reloads.
|
|
@@ -19,7 +19,7 @@ export function create(
|
|
|
19
19
|
const key = serialize(options.storageKey ?? 'zyzz')
|
|
20
20
|
const schemes = serialize(Object.entries(Scheme.classes))
|
|
21
21
|
|
|
22
|
-
return `(()=>{try{const value=JSON.parse(localStorage.getItem(${key})||"null");if(!value||typeof value!=="object"||Array.isArray(value))return;const root=document.documentElement;const catalog=new Map(${catalog});if(Object.hasOwn(value,"
|
|
22
|
+
return `(()=>{try{const value=JSON.parse(localStorage.getItem(${key})||"null");if(!value||typeof value!=="object"||Array.isArray(value))return;const root=document.documentElement;const catalog=new Map(${catalog});if(Object.hasOwn(value,"set")&&typeof value.set==="string"&&catalog.has(value.set)){root.classList.remove(...catalog.values());root.classList.add(catalog.get(value.set))}const schemes=new Map(${schemes});if(Object.hasOwn(value,"colorScheme")){if(value.colorScheme===null){root.classList.remove(...schemes.values());root.style.removeProperty("color-scheme")}else if(schemes.has(value.colorScheme)){root.classList.remove(...schemes.values());root.classList.add(schemes.get(value.colorScheme));root.style.colorScheme=value.colorScheme}}}catch{}})();`
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -33,11 +33,11 @@ export declare namespace create {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Binds root selection controls to compiled named
|
|
36
|
+
* Binds root selection controls to compiled named set classes.
|
|
37
37
|
* Creation touches no browser state; `get` and `set` read and write
|
|
38
38
|
* `document.documentElement` and the record the initialization script restores.
|
|
39
39
|
* @param entries - Catalog names paired with compiled scope classes.
|
|
40
|
-
* @param options - Default
|
|
40
|
+
* @param options - Default set reported without a root class and the storage key.
|
|
41
41
|
* @returns Controls reading the applied root selection and applying saved changes.
|
|
42
42
|
* @throws {TypeError} If a named catalog receives no default or one outside its entries.
|
|
43
43
|
*/
|
|
@@ -49,24 +49,24 @@ export function root<const name extends string>(
|
|
|
49
49
|
const key = options.storageKey ?? 'zyzz'
|
|
50
50
|
const schemes = Object.entries(Scheme.classes) as [Scheme.Name, string][]
|
|
51
51
|
|
|
52
|
-
// Named catalogs always report a
|
|
52
|
+
// Named catalogs always report a set, so the fallback must be one of them.
|
|
53
53
|
if (
|
|
54
54
|
catalog.size &&
|
|
55
|
-
(options.
|
|
55
|
+
(options.defaultVars === undefined || !catalog.has(options.defaultVars))
|
|
56
56
|
)
|
|
57
|
-
throw new TypeError('
|
|
57
|
+
throw new TypeError('defaultVars must name a catalog set.')
|
|
58
58
|
|
|
59
59
|
function get(): Selection<name> {
|
|
60
60
|
const classes = document.documentElement.classList
|
|
61
|
-
const
|
|
61
|
+
const set =
|
|
62
62
|
[...catalog].find(([, className]) => classes.contains(className))?.[0] ??
|
|
63
|
-
options.
|
|
63
|
+
options.defaultVars
|
|
64
64
|
const colorScheme = schemes.find(([, className]) =>
|
|
65
65
|
classes.contains(className),
|
|
66
66
|
)?.[0]
|
|
67
67
|
|
|
68
68
|
return {
|
|
69
|
-
...(
|
|
69
|
+
...(set === undefined ? {} : { set }),
|
|
70
70
|
...(colorScheme === undefined ? {} : { colorScheme }),
|
|
71
71
|
} as Selection<name>
|
|
72
72
|
}
|
|
@@ -75,20 +75,20 @@ export function root<const name extends string>(
|
|
|
75
75
|
const element = document.documentElement
|
|
76
76
|
const next = { ...get(), ...selection } as {
|
|
77
77
|
colorScheme?: Scheme.Name | undefined
|
|
78
|
-
|
|
78
|
+
set?: string | undefined
|
|
79
79
|
}
|
|
80
80
|
const scopeClass =
|
|
81
|
-
next.
|
|
81
|
+
next.set === undefined ? undefined : catalog.get(next.set)
|
|
82
82
|
|
|
83
83
|
// Rejected input leaves the document and the saved record untouched.
|
|
84
|
-
if (next.
|
|
85
|
-
throw new TypeError('Invalid
|
|
84
|
+
if (next.set !== undefined && scopeClass === undefined)
|
|
85
|
+
throw new TypeError('Invalid set selection.')
|
|
86
86
|
|
|
87
87
|
if (
|
|
88
88
|
next.colorScheme !== undefined &&
|
|
89
89
|
!Object.hasOwn(Scheme.classes, next.colorScheme)
|
|
90
90
|
)
|
|
91
|
-
throw new TypeError('Invalid
|
|
91
|
+
throw new TypeError('Invalid set selection.')
|
|
92
92
|
|
|
93
93
|
element.classList.remove(
|
|
94
94
|
...catalog.values(),
|
|
@@ -105,7 +105,7 @@ export function root<const name extends string>(
|
|
|
105
105
|
// The record mirrors the applied root, so a cleared scheme saves as null
|
|
106
106
|
// and the script removes a server-rendered scheme on the next load.
|
|
107
107
|
const record = {
|
|
108
|
-
...(next.
|
|
108
|
+
...(next.set === undefined ? {} : { set: next.set }),
|
|
109
109
|
colorScheme: next.colorScheme ?? null,
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -124,7 +124,7 @@ export declare namespace root {
|
|
|
124
124
|
/** Catalog defaults and storage settings. */
|
|
125
125
|
type Options<name extends string = string> = {
|
|
126
126
|
/** Theme reported by `get` when the root carries no catalog class; required with a named catalog. */
|
|
127
|
-
readonly
|
|
127
|
+
readonly defaultVars?: NoInfer<name> | undefined
|
|
128
128
|
/** localStorage key shared with the initialization script; defaults to zyzz. */
|
|
129
129
|
readonly storageKey?: string | undefined
|
|
130
130
|
}
|
|
@@ -132,18 +132,18 @@ export declare namespace root {
|
|
|
132
132
|
|
|
133
133
|
/** Live root selection controls. */
|
|
134
134
|
export type Root<name extends string> = {
|
|
135
|
-
/** Reads the
|
|
135
|
+
/** Reads the set and scheme classes the root carries. */
|
|
136
136
|
readonly get: () => Selection<name>
|
|
137
137
|
/** Applies fields over the current selection and saves the result. */
|
|
138
138
|
readonly set: (selection: Partial<Selection<name>>) => void
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
/** A catalog
|
|
141
|
+
/** A catalog set with an optional scheme; an omitted scheme inherits. Token-free and single-set configurations select only a scheme. */
|
|
142
142
|
export type Selection<name extends string> = [name] extends [never]
|
|
143
143
|
? { readonly colorScheme?: Scheme.Name | undefined }
|
|
144
144
|
: {
|
|
145
145
|
readonly colorScheme?: Scheme.Name | undefined
|
|
146
|
-
readonly
|
|
146
|
+
readonly set: name
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
function serialize(value: unknown): string {
|
package/src/runtime/Dynamic.ts
CHANGED
|
@@ -15,7 +15,10 @@ export function create(
|
|
|
15
15
|
return value === '' ? ' ' : value
|
|
16
16
|
})
|
|
17
17
|
const external = input.className
|
|
18
|
-
const style
|
|
18
|
+
const style: Record<string, string | number | undefined> = {
|
|
19
|
+
...input.vars,
|
|
20
|
+
...input.style,
|
|
21
|
+
}
|
|
19
22
|
|
|
20
23
|
for (let index = 0; index < slots.length; index++)
|
|
21
24
|
style[slots[index]![1].name] = values[index]!
|
|
@@ -3,12 +3,12 @@ import type * as Native from './Native.js'
|
|
|
3
3
|
|
|
4
4
|
const binding = Symbol('zyzz.native.context')
|
|
5
5
|
|
|
6
|
-
/** Render-local
|
|
6
|
+
/** Render-local set and resolved appearance. */
|
|
7
7
|
export type Context = {
|
|
8
8
|
/** Resolved system appearance or an explicit override. */
|
|
9
9
|
readonly colorScheme: 'dark' | 'light'
|
|
10
|
-
/** Named compiled
|
|
11
|
-
readonly
|
|
10
|
+
/** Named compiled set; omission uses each configuration default. */
|
|
11
|
+
readonly set?: string | undefined
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
type Callable = (input: never) => Native.Props<object>
|
|
@@ -19,17 +19,17 @@ type Tables = Readonly<
|
|
|
19
19
|
/** Retains compiled alternatives without selecting a device context at module evaluation. */
|
|
20
20
|
export function create<const tables extends Tables>(
|
|
21
21
|
tables: tables,
|
|
22
|
-
|
|
22
|
+
defaultVars: keyof tables & string,
|
|
23
23
|
): tables[keyof tables]['light'] {
|
|
24
24
|
const fallback =
|
|
25
|
-
Object.keys(tables).length === 1 &&
|
|
25
|
+
Object.keys(tables).length === 1 && defaultVars === 'default'
|
|
26
26
|
? tables.default
|
|
27
27
|
: undefined
|
|
28
28
|
|
|
29
29
|
function select(context: Context, input?: never) {
|
|
30
|
-
const
|
|
31
|
-
const table = tables[
|
|
32
|
-
if (!table) throw new Error(`Unknown native
|
|
30
|
+
const set = context.set ?? defaultVars
|
|
31
|
+
const table = tables[set] ?? fallback
|
|
32
|
+
if (!table) throw new Error(`Unknown native set: ${set}.`)
|
|
33
33
|
return table[context.colorScheme](input!).style
|
|
34
34
|
}
|
|
35
35
|
function props(input?: never) {
|
|
@@ -27,10 +27,8 @@ export type RecipeCallable<input> = <
|
|
|
27
27
|
/** Adapts a published web callable's payload to native styling overrides. */
|
|
28
28
|
export type From<fn> = fn extends (...args: infer args) => unknown
|
|
29
29
|
? [] extends args
|
|
30
|
-
? RecipeCallable<
|
|
31
|
-
|
|
32
|
-
>
|
|
33
|
-
: Callable<Omit<NonNullable<args[0]>, 'style' | 'className' | 'variables'>>
|
|
30
|
+
? RecipeCallable<Omit<NonNullable<args[0]>, 'style' | 'className' | 'vars'>>
|
|
31
|
+
: Callable<Omit<NonNullable<args[0]>, 'style' | 'className' | 'vars'>>
|
|
34
32
|
: never
|
|
35
33
|
|
|
36
34
|
/** Ordered static and dynamic assignments selected by finite recipe choices. */
|
package/src/runtime/Props.ts
CHANGED
|
@@ -8,14 +8,14 @@ import type { style } from '../styleFunction.js'
|
|
|
8
8
|
* Binds compiled classes to the web styling override contract.
|
|
9
9
|
* Returns fresh props; without variable assignments, inline styles retain their identity.
|
|
10
10
|
* Never generates rules or changes the supplied overrides.
|
|
11
|
-
* @returns A callable accepting className, style, and
|
|
11
|
+
* @returns A callable accepting className, style, and vars.
|
|
12
12
|
*/
|
|
13
13
|
export function create({ className }: create.Options): style.ReturnType {
|
|
14
14
|
return ((overrides?: style.Options) => {
|
|
15
15
|
if (!overrides) return { className }
|
|
16
16
|
|
|
17
|
-
const { className: external, style,
|
|
18
|
-
const inline =
|
|
17
|
+
const { className: external, style, vars } = overrides
|
|
18
|
+
const inline = vars ? { ...vars, ...style } : style
|
|
19
19
|
const merged =
|
|
20
20
|
className && external ? `${className} ${external}` : external || className
|
|
21
21
|
|