zyzz 0.0.3 → 0.0.6
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/babel/index.d.ts +2 -0
- package/dist/babel/index.d.ts.map +1 -1
- package/dist/babel/index.js +10 -1
- package/dist/babel/index.js.map +1 -1
- package/dist/compiler/Graph.d.ts +2 -0
- package/dist/compiler/Graph.d.ts.map +1 -1
- package/dist/compiler/Graph.js +30 -9
- 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 +52 -16
- 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.d.ts +1 -1
- package/dist/compiler/internal/Contributions.d.ts.map +1 -1
- package/dist/compiler/internal/Contributions.js +6 -4
- 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/Static.d.ts.map +1 -1
- package/dist/compiler/internal/Static.js +2 -0
- package/dist/compiler/internal/Static.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/index.d.ts +8 -3
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +21 -10
- package/dist/next/index.js.map +1 -1
- package/dist/next/loader.d.ts +1 -0
- package/dist/next/loader.d.ts.map +1 -1
- package/dist/next/loader.js +25 -6
- 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/node/Reset.d.ts +3 -0
- package/dist/node/Reset.d.ts.map +1 -0
- package/dist/node/Reset.js +7 -0
- package/dist/node/Reset.js.map +1 -0
- 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 +22 -0
- package/dist/unplugin/index.d.ts.map +1 -0
- package/dist/unplugin/index.js +500 -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 +2 -0
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +44 -12
- 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/babel/index.ts +23 -1
- package/src/compiler/Graph.ts +36 -9
- package/src/compiler/Native.ts +29 -32
- package/src/compiler/Source.ts +64 -22
- 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 +6 -3
- 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/Static.ts +1 -0
- 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/index.ts +34 -12
- package/src/next/loader.ts +35 -6
- package/src/node/Host.ts +1 -2
- package/src/node/Reset.ts +7 -0
- 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 +604 -0
- package/src/variants.ts +7 -5
- package/src/vite/index.ts +48 -18
- 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/README.md
CHANGED
|
@@ -43,6 +43,8 @@ export function Card() {
|
|
|
43
43
|
- **Minimal.** Small, composable APIs keep configuration and dependencies optional.
|
|
44
44
|
- **Compiled.** Rules compile ahead of time into compact output with readable class names on web.
|
|
45
45
|
|
|
46
|
+
Read [Thinking in Zyzz](docs/introduction/thinking-in-zyzz.md) for co-location, composition, and styling conventions.
|
|
47
|
+
|
|
46
48
|
## Features
|
|
47
49
|
|
|
48
50
|
- [**Typed Styles**](#typed-styles): familiar CSS with property and value inference, inline or reusable.
|
|
@@ -69,6 +71,7 @@ Choose an integration or compile styles with the CLI or compiler API:
|
|
|
69
71
|
- [Vite](#vite)
|
|
70
72
|
- [Next.js](#nextjs)
|
|
71
73
|
- [React Native](#react-native)
|
|
74
|
+
- [Other Bundlers](#other-bundlers)
|
|
72
75
|
- [CLI](#cli)
|
|
73
76
|
- [Compiler API](#compiler-api)
|
|
74
77
|
|
|
@@ -119,6 +122,18 @@ export default zyzz(getDefaultConfig(import.meta.dirname), {
|
|
|
119
122
|
|
|
120
123
|
Metro compiles styles during iOS and Android bundling. Connect the [React provider](docs/api/react-native/react.md) above the application for theme and color scheme selection. See [Metro Setup](docs/api/metro/README.md) and the [Expo example](examples/react-native).
|
|
121
124
|
|
|
125
|
+
### Other Bundlers
|
|
126
|
+
|
|
127
|
+
Use the unplugin adapters with Rollup, Webpack, or esbuild:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { zyzz } from 'zyzz/unplugin'
|
|
131
|
+
|
|
132
|
+
const plugins = [zyzz.esbuild()] // or zyzz.rollup() / zyzz.webpack()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The adapters emit `zyzz.css` and `zyzz.js` beside the JavaScript bundle. Load these files in the application document. See [Bundler Setup](docs/api/unplugin/README.md) for configuration and output requirements.
|
|
136
|
+
|
|
122
137
|
### CLI
|
|
123
138
|
|
|
124
139
|
Build or watch source files:
|
|
@@ -187,7 +202,7 @@ Token names infer by property, and compatible theme scopes change inherited valu
|
|
|
187
202
|
|
|
188
203
|
#### Default Theme
|
|
189
204
|
|
|
190
|
-
The `zyzz/default` entrypoint provides inferred colors, typography, spacing, and radius tokens through bound `style` and `variants`, plus `
|
|
205
|
+
The `zyzz/default` entrypoint provides inferred colors, typography, spacing, and radius tokens through bound `style` and `variants`, plus `vars`, raw `tokens`, `appearance` controls, and a `script()` helper for restoring saved color-scheme preferences. Scales use conventional named steps, and colors ship as light/dark pairs.
|
|
191
206
|
|
|
192
207
|
```ts
|
|
193
208
|
import { style } from 'zyzz/default'
|
|
@@ -197,15 +212,15 @@ namespace styles {
|
|
|
197
212
|
}
|
|
198
213
|
```
|
|
199
214
|
|
|
200
|
-
Extend the default theme with [`
|
|
215
|
+
Extend the default theme with [`Vars.extend`](docs/api/core/Vars/README.md) to override existing tokens while retaining all other values and the same token contract.
|
|
201
216
|
|
|
202
217
|
```ts
|
|
203
218
|
// zyzz.config.ts
|
|
204
|
-
import { Config,
|
|
205
|
-
import {
|
|
219
|
+
import { Config, Vars } from 'zyzz'
|
|
220
|
+
import { vars as defaultVars } from 'zyzz/default'
|
|
206
221
|
|
|
207
|
-
export const { style,
|
|
208
|
-
|
|
222
|
+
export const { style, vars, variants } = Config.create({
|
|
223
|
+
vars: Vars.extend(defaultVars, {
|
|
209
224
|
color: { blue: { 700: '#175' } },
|
|
210
225
|
}),
|
|
211
226
|
})
|
|
@@ -227,8 +242,8 @@ Export named config helpers with an application's own tokens. Colors accept a sh
|
|
|
227
242
|
// zyzz.config.ts
|
|
228
243
|
import { Config } from 'zyzz'
|
|
229
244
|
|
|
230
|
-
export const { style,
|
|
231
|
-
|
|
245
|
+
export const { style, vars, variants } = Config.create({
|
|
246
|
+
vars: {
|
|
232
247
|
color: { brand: '#06c', text: { dark: '#eee', light: '#111' } },
|
|
233
248
|
spacing: { md: '1rem', sm: '0.5rem' },
|
|
234
249
|
},
|
|
@@ -243,14 +258,14 @@ namespace styles {
|
|
|
243
258
|
}
|
|
244
259
|
```
|
|
245
260
|
|
|
246
|
-
Use [`
|
|
261
|
+
Use [`Vars.define`](docs/api/core/Vars/README.md) for reusable definitions outside config. See [Themes & Tokens](docs/guides/themes.md) for nested scopes and named alternatives.
|
|
247
262
|
|
|
248
263
|
### Color Schemes (Light/Dark Mode)
|
|
249
264
|
|
|
250
265
|
Apply the theme to `<html>` and select a color scheme through its callable props:
|
|
251
266
|
|
|
252
267
|
```tsx
|
|
253
|
-
import { style,
|
|
268
|
+
import { style, vars } from './zyzz.config.js'
|
|
254
269
|
|
|
255
270
|
namespace styles {
|
|
256
271
|
export const card = style({ color: 'text', padding: 'sm' })
|
|
@@ -258,7 +273,7 @@ namespace styles {
|
|
|
258
273
|
|
|
259
274
|
export function Document() {
|
|
260
275
|
return (
|
|
261
|
-
<html {...
|
|
276
|
+
<html {...vars({ colorScheme: 'light dark' })}>
|
|
262
277
|
<head>
|
|
263
278
|
<title>My App</title>
|
|
264
279
|
</head>
|
|
@@ -270,11 +285,11 @@ export function Document() {
|
|
|
270
285
|
}
|
|
271
286
|
```
|
|
272
287
|
|
|
273
|
-
The theme returns its generated `className`, including a compiled scheme class, and `style.colorScheme`. Use `'light'` or `'dark'` for an explicit scheme, or `'light dark'` for system preference. Named themes use `
|
|
288
|
+
The theme returns its generated `className`, including a compiled scheme class, and `style.colorScheme`. Use `'light'` or `'dark'` for an explicit scheme, or `'light dark'` for system preference. Named themes use `vars({ set: 'mint', colorScheme: 'dark' })`.
|
|
274
289
|
|
|
275
290
|
Color pairs compile to `light-dark()`; the custom theme's `text` token resolves to `#111` in light mode and `#eee` in dark mode. Nested theme calls can scope a subtree independently.
|
|
276
291
|
|
|
277
|
-
For saved preferences, `script()` generates an optional [initialization script](docs/guides/themes.md#restore-preferences) for `<head>`. It restores the theme and scheme from localStorage before first paint, and `appearance.set({
|
|
292
|
+
For saved preferences, `script()` generates an optional [initialization script](docs/guides/themes.md#restore-preferences) for `<head>`. It restores the theme and scheme from localStorage before first paint, and `appearance.set({ set: 'mint', colorScheme: 'dark' })` applies and saves a change from the client. System preference needs no script or provider.
|
|
278
293
|
|
|
279
294
|
### Variants
|
|
280
295
|
|
|
@@ -306,7 +321,7 @@ const example = <Button size="sm" />
|
|
|
306
321
|
|
|
307
322
|
### Dynamic Styles
|
|
308
323
|
|
|
309
|
-
Mix static declarations with typed runtime values in the same callback. Call the style with those values and optional `className`/`style`/`
|
|
324
|
+
Mix static declarations with typed runtime values in the same callback. Call the style with those values and optional `className`/`style`/`vars` overrides; consumed values become CSS variable assignments. Other component props stay on the component. CSS rules stay static.
|
|
310
325
|
|
|
311
326
|
```tsx
|
|
312
327
|
import { style } from 'zyzz'
|
|
@@ -332,24 +347,24 @@ export function Bar() {
|
|
|
332
347
|
|
|
333
348
|
### Value Syntax
|
|
334
349
|
|
|
335
|
-
Use the suffix ` !important` for importance and arrays for ordered fallbacks. `
|
|
350
|
+
Use the suffix ` !important` for importance and arrays for ordered fallbacks. `vars` provides typed references for declarations and CSS expressions.
|
|
336
351
|
|
|
337
352
|
```ts
|
|
338
|
-
import { style,
|
|
353
|
+
import { style, vars } from './zyzz.config.js'
|
|
339
354
|
|
|
340
355
|
namespace styles {
|
|
341
356
|
export const panel = style({
|
|
342
357
|
display: ['block', 'grid'],
|
|
343
358
|
color: 'brand !important',
|
|
344
|
-
borderColor:
|
|
345
|
-
width: `calc(100% - ${
|
|
359
|
+
borderColor: vars.color.brand,
|
|
360
|
+
width: `calc(100% - ${vars.spacing.md})`,
|
|
346
361
|
})
|
|
347
362
|
}
|
|
348
363
|
```
|
|
349
364
|
|
|
350
365
|
### Composition
|
|
351
366
|
|
|
352
|
-
Prefer state attributes for conditional styling. Calls accept `className`, `style`, and `
|
|
367
|
+
Prefer state attributes for conditional styling. Calls accept `className`, `style`, and `vars` overrides. Classes are retained and inline styles merge. Other props stay on the component. Use `cx` for explicit overrides between generated styles in matching selector and condition contexts.
|
|
353
368
|
|
|
354
369
|
```tsx
|
|
355
370
|
import { cx, style } from 'zyzz'
|
package/dist/Config.d.ts
CHANGED
|
@@ -1,170 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import type * as Literal from './internal/Literal.js';
|
|
9
|
-
import type { style } from './styleFunction.js';
|
|
10
|
-
import { variants } from './variants.js';
|
|
11
|
-
import * as Shorthands from './internal/Shorthands.js';
|
|
12
|
-
import type * as Style from './Style.js';
|
|
13
|
-
import * as Theme from './Theme.js';
|
|
14
|
-
import * as Token from './internal/Token.js';
|
|
15
|
-
/** Creates token-free authoring without a configuration file or global state. */
|
|
16
|
-
export declare function create(): create.ReturnType<{}>;
|
|
17
|
-
/**
|
|
18
|
-
* Binds inline or reusable themes to an isolated configuration contract.
|
|
19
|
-
* Named themes require an explicit default and identical token paths/domains.
|
|
20
|
-
* Bound helpers reference extracted CSS; this factory emits no CSS rules.
|
|
21
|
-
* @throws {InvalidError} If options, themes, defaults, or layer names are invalid.
|
|
22
|
-
*/
|
|
23
|
-
export declare function create<const options extends create.Options>(options: options & NoInfer<Validated<options>>): create.ReturnType<options>;
|
|
24
|
-
/** Configuration inputs and inferred results. */
|
|
25
|
-
export declare namespace create {
|
|
26
|
-
/** Optional layer names and mutually exclusive theme modes. */
|
|
27
|
-
type Options = {
|
|
28
|
-
/** CSS representation inherited by bound helpers; atomic by default. */
|
|
29
|
-
readonly cssOutput?: 'atomic' | 'grouped' | undefined;
|
|
30
|
-
/** Stable theme identity required without source rewriting. */
|
|
31
|
-
readonly id?: string | undefined;
|
|
32
|
-
/** Explicit ordered property aliases; none are installed by default. */
|
|
33
|
-
readonly shorthands?: Shorthands.Map | undefined;
|
|
34
|
-
/** Renderer props format; React is the default. */
|
|
35
|
-
readonly output?: style.Output | undefined;
|
|
36
|
-
/** Ordered plain or dotted CSS layer names; emission follows source integration. */
|
|
37
|
-
readonly layers?: readonly string[] | undefined;
|
|
38
|
-
/** localStorage key shared by `script()` and `appearance`; zyzz by default. */
|
|
39
|
-
readonly storageKey?: string | undefined;
|
|
40
|
-
} & ({
|
|
41
|
-
/** Single inline or reusable theme. */ readonly theme: Input;
|
|
42
|
-
/** Named mode is excluded. */ readonly themes?: never;
|
|
43
|
-
/** Only named catalogs use defaults. */ readonly defaultTheme?: never;
|
|
44
|
-
} | {
|
|
45
|
-
/** Explicit catalog key. */ readonly defaultTheme: string;
|
|
46
|
-
/** Single mode is excluded. */ readonly theme?: never;
|
|
47
|
-
/** Complete named theme alternatives. */ readonly themes: Readonly<Record<string, Input>>;
|
|
48
|
-
} | {
|
|
49
|
-
/** Only named catalogs use defaults. */ readonly defaultTheme?: never;
|
|
50
|
-
/** Omit themes for token-free authoring. */ readonly theme?: never;
|
|
51
|
-
/** Omit themes for token-free authoring. */ readonly themes?: never;
|
|
52
|
-
});
|
|
53
|
-
/** Bound authoring and the handles corresponding to the selected theme mode. */
|
|
54
|
-
type ReturnType<options extends Options = Options> = {
|
|
55
|
-
/** Reads and persists the root theme and scheme selection on the document element. */
|
|
56
|
-
readonly appearance: Appearance.Root<options extends {
|
|
57
|
-
themes: infer catalog;
|
|
58
|
-
} ? keyof catalog & string : never>;
|
|
59
|
-
/** Generates synchronous HTML-safe root preference restoration. */
|
|
60
|
-
readonly script: () => string;
|
|
61
|
-
/** Inferred callable authoring; execution requires a source transform. */
|
|
62
|
-
readonly style: StyleFactory<Tokens<options>, options extends {
|
|
63
|
-
layers: readonly (infer name extends string)[];
|
|
64
|
-
} ? name : never, options extends {
|
|
65
|
-
output: infer output extends style.Output;
|
|
66
|
-
} ? output : 'react', Mappings<options>>;
|
|
67
|
-
/** Theme-, layer-, and mapping-aware recipe authoring. */
|
|
68
|
-
readonly variants: variants.Bound<Tokens<options>, options extends {
|
|
69
|
-
output: infer output extends style.Output;
|
|
70
|
-
} ? output : 'react', options extends {
|
|
71
|
-
layers: readonly (infer name extends string)[];
|
|
72
|
-
} ? name : never, Mappings<options>>;
|
|
73
|
-
} & (options extends {
|
|
74
|
-
theme: infer input;
|
|
75
|
-
} ? {
|
|
76
|
-
/** Isolated single-theme contract. */ readonly theme: Handle<ExtractTokens<input>, Mappings<options>, options extends {
|
|
77
|
-
output: infer output extends style.Output;
|
|
78
|
-
} ? output : 'react'>;
|
|
79
|
-
} : options extends {
|
|
80
|
-
themes: infer catalog;
|
|
81
|
-
} ? {
|
|
82
|
-
/** Shared default token and variable contract. */ readonly theme: Handle<Tokens<options>, Mappings<options>, options extends {
|
|
83
|
-
output: infer output extends style.Output;
|
|
84
|
-
} ? output : 'react'>;
|
|
85
|
-
/** Selects a compiled named scope; catalog members retain compatibility. */ readonly themes: (<const selection extends {
|
|
86
|
-
readonly colorScheme?: 'dark' | 'light' | 'light dark' | undefined;
|
|
87
|
-
readonly theme: keyof catalog & string;
|
|
88
|
-
}>(options: selection & Record<Exclude<keyof selection, 'theme' | 'colorScheme'>, never>) => style.Props<options extends {
|
|
89
|
-
output: infer output extends style.Output;
|
|
90
|
-
} ? output : 'react'>) & {
|
|
91
|
-
readonly [name in keyof catalog]: Handle<ExtractTokens<catalog[name]>, Mappings<options>, options extends {
|
|
92
|
-
output: infer output extends style.Output;
|
|
93
|
-
} ? output : 'react'>;
|
|
94
|
-
};
|
|
95
|
-
} : {});
|
|
96
|
-
}
|
|
97
|
-
type Mappings<options> = options extends {
|
|
1
|
+
/** Binds shared vars, property mappings, and scoped alternatives to authoring. @module */
|
|
2
|
+
import type * as Shorthands from './internal/Shorthands.js';
|
|
3
|
+
import * as Configuration from './internal/Configuration.js';
|
|
4
|
+
export { InvalidError } from './internal/Configuration.js';
|
|
5
|
+
export type { Body, StyleFactory, VariableConfig, VariableOptions, VariableScope, } from './internal/Configuration.js';
|
|
6
|
+
/** Creates isolated authoring with optional vars and named alternatives. */
|
|
7
|
+
export declare function create<const options extends create.Options = {}>(options?: options & NoInfer<options extends Configuration.VariableOptions ? Configuration.VariableValidation<options> : Record<Exclude<keyof options, keyof create.Options>, never> & (options extends {
|
|
98
8
|
shorthands: infer map extends Shorthands.Map;
|
|
99
|
-
} ? string extends keyof map ? {} : map : {};
|
|
100
|
-
/** Theme handle retaining configured shorthands and renderer output in emitted declarations. */
|
|
101
|
-
export type Handle<tokens extends Theme.Tokens, mappings extends Shorthands.Map, output extends style.Output> = Omit<Theme.Definition<tokens>, 'style' | 'variants'> & {
|
|
102
|
-
/** Style factory bound to this handle. */
|
|
103
|
-
readonly style: StyleFactory<tokens, never, output, mappings>;
|
|
104
|
-
/** Variant factory bound to this handle. */
|
|
105
|
-
readonly variants: variants.Bound<tokens, output, never, mappings>;
|
|
106
|
-
};
|
|
107
|
-
/** Configured style factory with a portable name for library declaration emission. */
|
|
108
|
-
export type StyleFactory<tokens extends Theme.Tokens, layers extends string, output extends style.Output, mappings extends Shorthands.Map> = {
|
|
109
|
-
(): style.ReturnType<output>;
|
|
110
|
-
<const values extends Record<string, string | number>, const styles extends Record<string, unknown>, const callback extends (...args: never[]) => unknown>(styles: callback & ((values: values) => styles & NoInfer<Body<styles, tokens, layers, mappings> & Binding.Checked<styles>>) & CompletionProperties<tokens, NoInfer<styles>>, ...options: Parameters<callback> extends [Record<string, string | number>] ? values extends Binding.Inputs<values> ? [options?: style.DefinitionOptions] : [invalid: never, unavailable: never] : [invalid: never, unavailable: never]): style.Dynamic<values, output>;
|
|
111
|
-
<const styles extends Record<string, unknown>>(styles: styles & NoInfer<Body<styles, tokens, layers, mappings>> & CompletionProperties<tokens>, options?: style.DefinitionOptions): style.ReturnType<output>;
|
|
112
|
-
};
|
|
113
|
-
type Keys<styles> = styles extends unknown ? keyof styles : never;
|
|
114
|
-
/** Keeps completion hints separate from inferred declaration validation. */
|
|
115
|
-
type CompletionProperties<tokens, styles = Record<string, unknown>> = {
|
|
116
|
-
readonly [property in keyof Literal.Properties & keyof styles]?: (string extends Literal.Properties[property] ? never : Literal.Properties[property]) | Token.Names<tokens, property> | (string & {}) | number | object;
|
|
117
|
-
};
|
|
118
|
-
/** Checked declaration body shared by configured styles and recipe choices. */
|
|
119
|
-
export type Body<styles, tokens extends Theme.Tokens, layers extends string, mappings extends Shorthands.Map, targets extends boolean = true> = Record<Exclude<Keys<styles>, keyof mappings | 'selectors' | 'targets' | 'typography' | 'variables' | keyof Style.DeclarationProperties | Exclude<Condition.Keys<tokens, Keys<styles>>, `@layer${string}`> | '@layer' | `@layer ${layers}`>, never> & (styles extends unknown ? {
|
|
120
|
-
[key in keyof styles]: key extends 'targets' ? targets extends false ? never : styles[key] extends undefined ? undefined : {
|
|
121
|
-
[target in keyof styles[key]]: target extends 'web' ? Body<NonNullable<styles[key][target]>, tokens, layers, mappings, false> | Extract<styles[key][target], undefined> : Style.Accepted<{
|
|
122
|
-
targets: Pick<styles[key], target>;
|
|
123
|
-
}, tokens>['targets'][target];
|
|
124
|
-
} : key extends 'selectors' ? styles[key] extends Record<string, unknown> ? {
|
|
125
|
-
[selector in keyof styles[key]]: styles[key][selector] extends Record<string, unknown> ? Body<styles[key][selector], tokens, layers, mappings, targets> : never;
|
|
126
|
-
} : never : key extends Exclude<Condition.Keys<tokens, key>, `@layer${string}`> | '@layer' | `@layer ${layers}` ? styles[key] extends Record<string, unknown> ? Body<styles[key], tokens, layers, mappings, targets> : never : key extends keyof mappings ? {
|
|
127
|
-
[target in mappings[key][number]]: styles[key] extends Style.Accepted<Record<target, styles[key]>, tokens>[target] & Binding.Checked<Record<target, styles[key]>>[target] ? never : target;
|
|
128
|
-
}[mappings[key][number]] extends never ? styles[key] : never : Style.Accepted<Pick<styles, key>, tokens>[key];
|
|
129
|
-
} : never);
|
|
130
|
-
type ExtractTokens<input> = input extends Theme.Definition<infer tokens> ? tokens : input extends Theme.Tokens ? input : never;
|
|
131
|
-
type Input = Theme.Definition | Theme.Tokens;
|
|
132
|
-
/** Invalid options or incompatible named themes. */
|
|
133
|
-
export declare class InvalidError extends Error {
|
|
134
|
-
/** Creates a configuration diagnostic without generating styles. */
|
|
135
|
-
constructor(message: string);
|
|
136
|
-
/** Stable namespaced error identifier. */
|
|
137
|
-
name: string;
|
|
138
|
-
}
|
|
139
|
-
type Tokens<options> = options extends {
|
|
140
|
-
theme: infer input;
|
|
141
|
-
} ? ExtractTokens<input> : options extends {
|
|
142
|
-
themes: infer catalog;
|
|
143
|
-
defaultTheme: infer key;
|
|
144
|
-
} ? key extends keyof catalog ? ExtractTokens<catalog[key]> : never : {};
|
|
145
|
-
type ValidInput<input> = input extends Theme.Definition ? input : input extends Theme.Tokens ? Parameters<typeof Theme.define<input>>[0] : never;
|
|
146
|
-
type Match<input, base> = base extends string | number | {
|
|
147
|
-
light: string;
|
|
148
|
-
dark: string;
|
|
149
|
-
} ? input : {
|
|
150
|
-
[key in keyof input | keyof base]: key extends keyof input ? key extends keyof base ? key extends 'containerNames' ? input[key] extends readonly string[] ? base[key] extends readonly string[] ? Exclude<input[key][number], base[key][number]> | Exclude<base[key][number], input[key][number]> extends never ? input[key] : never : never : never : Match<input[key], base[key]> : never : never;
|
|
151
|
-
};
|
|
152
|
-
type Validated<options> = Record<Exclude<keyof options, keyof create.Options>, never> & (options extends {
|
|
153
|
-
shorthands: infer mappings extends Shorthands.Map;
|
|
154
|
-
} ? {
|
|
155
|
-
shorthands: Shorthands.Validated<mappings>;
|
|
156
|
-
} : {}) & (options extends {
|
|
157
|
-
theme: infer input;
|
|
158
9
|
} ? {
|
|
159
|
-
|
|
160
|
-
} : options
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
} : {});
|
|
169
|
-
export {};
|
|
10
|
+
shorthands: Shorthands.Validated<map>;
|
|
11
|
+
} : {})>): create.ReturnType<options>;
|
|
12
|
+
/** Configuration input and inferred helpers. */
|
|
13
|
+
export declare namespace create {
|
|
14
|
+
/** Variable sets and optional authoring settings. */
|
|
15
|
+
type Options = Configuration.VariableOptions | Omit<Configuration.VariableOptions, 'vars' | 'defaultVars' | 'mappings'>;
|
|
16
|
+
/** Typed helpers selected by the supplied variable contract. */
|
|
17
|
+
type ReturnType<options extends Options = Options> = options extends Configuration.VariableOptions ? Configuration.VariableConfig<options> : Configuration.create.ReturnType<Extract<options, Configuration.create.Options>>;
|
|
18
|
+
}
|
|
170
19
|
//# sourceMappingURL=Config.d.ts.map
|
package/dist/Config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../src/Config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAA;AAIrD,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,KAAK,SAAS,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,UAAU,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAE5C,iFAAiF;AACjF,wBAAgB,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;AAC/C;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,OAAO,EACzD,OAAO,EAAE,OAAO,GAAG,OA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B,CAAC,OAAO,CAAC,GACzC,MAAM,CAAC,OAAO,CAAC,MAAM,OAAO,EAAE,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,GACzD,CAAC,OAAO,SAAS;IAAE,UAAU,EAAE,MAAM,GAAG,SAAS,UAAU,CAAC,GAAG,CAAA;CAAE,GAC7D;IAAE,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;CAAE,GACzC,EAAE,CAAC,CACA,GAChB,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAS5B;AAED,gDAAgD;AAChD,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,qDAAqD;IACrD,KAAK,OAAO,GACR,aAAa,CAAC,eAAe,GAC7B,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,MAAM,GAAG,aAAa,GAAG,UAAU,CAAC,CAAA;IAC5E,gEAAgE;IAChE,KAAK,UAAU,CAAC,OAAO,SAAS,OAAO,GAAG,OAAO,IAC/C,OAAO,SAAS,aAAa,CAAC,eAAe,GACzC,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,GACrC,aAAa,CAAC,MAAM,CAAC,UAAU,CAC7B,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAC/C,CAAA;CACR"}
|
package/dist/Config.js
CHANGED
|
@@ -1,249 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
import * as Appearance from './runtime/Appearance.js';
|
|
6
|
-
import * as Authoring from './internal/Authoring.js';
|
|
7
|
-
import * as Html from './runtime/CompositionHtml.js';
|
|
8
|
-
import * as Identity from './internal/Identity.js';
|
|
9
|
-
import { variants } from './variants.js';
|
|
10
|
-
import * as Scheme from './internal/Scheme.js';
|
|
11
|
-
import * as Shorthands from './internal/Shorthands.js';
|
|
12
|
-
import * as Theme from './Theme.js';
|
|
13
|
-
import * as Token from './internal/Token.js';
|
|
1
|
+
import * as Configuration from './internal/Configuration.js';
|
|
2
|
+
export { InvalidError } from './internal/Configuration.js';
|
|
3
|
+
/** Creates isolated authoring with optional vars and named alternatives. */
|
|
14
4
|
export function create(options = {}) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
'id',
|
|
20
|
-
'defaultTheme',
|
|
21
|
-
'layers',
|
|
22
|
-
'output',
|
|
23
|
-
'shorthands',
|
|
24
|
-
'storageKey',
|
|
25
|
-
'theme',
|
|
26
|
-
'themes',
|
|
27
|
-
].includes(key))
|
|
28
|
-
throw new InvalidError(`Unknown configuration option: ${key}`);
|
|
29
|
-
if (input.storageKey !== undefined &&
|
|
30
|
-
(typeof input.storageKey !== 'string' || !input.storageKey))
|
|
31
|
-
throw new InvalidError('storageKey must be a nonempty string.');
|
|
32
|
-
// Validated above; the record type erases the literal narrowing.
|
|
33
|
-
const storageKey = input.storageKey;
|
|
34
|
-
if (input.output !== undefined &&
|
|
35
|
-
input.output !== 'html' &&
|
|
36
|
-
input.output !== 'react')
|
|
37
|
-
throw new InvalidError('output must be html or react.');
|
|
38
|
-
if (input.cssOutput !== undefined &&
|
|
39
|
-
input.cssOutput !== 'atomic' &&
|
|
40
|
-
input.cssOutput !== 'grouped')
|
|
41
|
-
throw new InvalidError('cssOutput must be atomic or grouped.');
|
|
42
|
-
if (input.theme !== undefined && input.themes !== undefined)
|
|
43
|
-
throw new InvalidError('Use either theme or themes, not both.');
|
|
44
|
-
if (input.layers !== undefined) {
|
|
45
|
-
if (!Array.isArray(input.layers))
|
|
46
|
-
throw new InvalidError('layers must be an array.');
|
|
47
|
-
const seen = new Set();
|
|
48
|
-
for (const layer of input.layers) {
|
|
49
|
-
if (typeof layer !== 'string' ||
|
|
50
|
-
!/^(?:--|-?[_a-zA-Z])[\w-]*(?:\.(?:--|-?[_a-zA-Z])[\w-]*)*$/.test(layer) ||
|
|
51
|
-
layer
|
|
52
|
-
.split('.')
|
|
53
|
-
.some((part) => [
|
|
54
|
-
'default',
|
|
55
|
-
'inherit',
|
|
56
|
-
'initial',
|
|
57
|
-
'revert',
|
|
58
|
-
'revert-layer',
|
|
59
|
-
'unset',
|
|
60
|
-
].includes(part.toLowerCase())))
|
|
61
|
-
throw new InvalidError('Layer names must be plain CSS identifiers, optionally dotted.');
|
|
62
|
-
if (seen.has(layer))
|
|
63
|
-
throw new InvalidError(`Duplicate layer: ${layer}`);
|
|
64
|
-
seen.add(layer);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const shorthands = (() => {
|
|
68
|
-
if (input.shorthands === undefined)
|
|
69
|
-
return undefined;
|
|
70
|
-
try {
|
|
71
|
-
return Shorthands.read(input.shorthands);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
throw new InvalidError(error.message);
|
|
75
|
-
}
|
|
76
|
-
})();
|
|
77
|
-
const contract = Object.freeze({
|
|
78
|
-
cssOutput: input.cssOutput ?? 'atomic',
|
|
79
|
-
...(shorthands ? { shorthands } : {}),
|
|
80
|
-
...(typeof input.id === 'string'
|
|
81
|
-
? {
|
|
82
|
-
[Token.identity]: Identity.requireId(input.id, 'Config.create'),
|
|
83
|
-
[Token.complete]: true,
|
|
84
|
-
}
|
|
85
|
-
: {}),
|
|
86
|
-
});
|
|
87
|
-
function boundStyle(theme) {
|
|
88
|
-
return (styles, options = {}) => {
|
|
89
|
-
if (theme &&
|
|
90
|
-
Object.keys(theme[Token.definition].values).length &&
|
|
91
|
-
!contract[Token.identity])
|
|
92
|
-
Identity.requireId(undefined, 'Config.create');
|
|
93
|
-
return Authoring.create(styles, {
|
|
94
|
-
...options,
|
|
95
|
-
theme,
|
|
96
|
-
output: input.output,
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function boundVariants(definition, options = {}) {
|
|
101
|
-
return Authoring.variants(definition, {
|
|
102
|
-
...options,
|
|
103
|
-
output: input.output,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function handle(theme, name) {
|
|
107
|
-
const original = Token.bind(theme, contract);
|
|
108
|
-
const className = () => `z_theme-${Identity.requireId(typeof input.id === 'string' ? input.id : undefined, 'Config.create')}-${name.replace(/[^a-zA-Z0-9-]/g, (character) => `_${character.charCodeAt(0).toString(16)}_`)}`;
|
|
109
|
-
const select = (options = {}) => {
|
|
110
|
-
const scheme = options.colorScheme;
|
|
111
|
-
const selection = scheme !== undefined && Object.hasOwn(Scheme.classes, scheme)
|
|
112
|
-
? ` ${Scheme.classes[scheme]}`
|
|
113
|
-
: '';
|
|
114
|
-
const result = {
|
|
115
|
-
className: `${className()}${selection}`,
|
|
116
|
-
...(scheme ? { style: { colorScheme: scheme } } : {}),
|
|
117
|
-
};
|
|
118
|
-
return input.output === 'html' ? Html.from(result) : result;
|
|
119
|
-
};
|
|
120
|
-
const descriptors = Object.getOwnPropertyDescriptors(original);
|
|
121
|
-
delete descriptors.className;
|
|
122
|
-
delete descriptors.style;
|
|
123
|
-
delete descriptors.variants;
|
|
124
|
-
Object.defineProperties(select, descriptors);
|
|
125
|
-
Object.defineProperty(select, 'className', {
|
|
126
|
-
get: className,
|
|
127
|
-
configurable: true,
|
|
128
|
-
});
|
|
129
|
-
Object.assign(select, {
|
|
130
|
-
style: boundStyle(original),
|
|
131
|
-
variants: boundVariants,
|
|
132
|
-
});
|
|
133
|
-
return select;
|
|
134
|
-
}
|
|
135
|
-
if (input.themes !== undefined) {
|
|
136
|
-
const catalog = record(input.themes);
|
|
137
|
-
if (typeof input.defaultTheme !== 'string' ||
|
|
138
|
-
!Object.hasOwn(catalog, input.defaultTheme))
|
|
139
|
-
throw new InvalidError('defaultTheme must name a theme in the catalog.');
|
|
140
|
-
const defaultTheme = input.defaultTheme;
|
|
141
|
-
const definitions = Object.fromEntries(Object.entries(catalog).map(([name, value]) => {
|
|
142
|
-
if (!name)
|
|
143
|
-
throw new InvalidError('Theme names must be nonempty.');
|
|
144
|
-
return [name, definition(value)];
|
|
145
|
-
}));
|
|
146
|
-
const base = definitions[input.defaultTheme];
|
|
147
|
-
const paths = Object.keys(base[Token.definition].values).sort();
|
|
148
|
-
function queries(theme) {
|
|
149
|
-
const data = theme[Token.definition].queries;
|
|
150
|
-
return JSON.stringify({
|
|
151
|
-
breakpoints: Object.keys(data?.breakpoints ?? {}).sort(),
|
|
152
|
-
containers: Object.keys(data?.containers ?? {}).sort(),
|
|
153
|
-
containerNames: [...(data?.containerNames ?? [])].sort(),
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
for (const [name, value] of Object.entries(definitions)) {
|
|
157
|
-
const candidate = Object.keys(value[Token.definition].values).sort();
|
|
158
|
-
if (queries(base) !== queries(value) ||
|
|
159
|
-
paths.length !== candidate.length ||
|
|
160
|
-
paths.some((path, index) => path !== candidate[index]))
|
|
161
|
-
throw new InvalidError(`Theme ${JSON.stringify(name)} must have the default theme's complete token paths and domains.`);
|
|
162
|
-
}
|
|
163
|
-
const bound = Object.fromEntries(Object.entries(definitions).map(([name, value]) => [
|
|
164
|
-
name,
|
|
165
|
-
handle(value, name),
|
|
166
|
-
]));
|
|
167
|
-
const select = (options) => bound[options.theme](options);
|
|
168
|
-
Object.defineProperties(select, Object.getOwnPropertyDescriptors(bound));
|
|
169
|
-
const entries = () => Object.entries(bound).map(([name, value]) => [
|
|
170
|
-
name,
|
|
171
|
-
value.className,
|
|
172
|
-
]);
|
|
173
|
-
// Class names require an identity, so the compiler's collection pass must
|
|
174
|
-
// not read them; root controls resolve their entries on first use.
|
|
175
|
-
const appearance = (() => {
|
|
176
|
-
let root;
|
|
177
|
-
const resolve = () => (root ??= Appearance.root(entries(), { defaultTheme, storageKey }));
|
|
178
|
-
return {
|
|
179
|
-
get: () => resolve().get(),
|
|
180
|
-
set: (selection) => resolve().set(selection),
|
|
181
|
-
};
|
|
182
|
-
})();
|
|
183
|
-
return Object.freeze({
|
|
184
|
-
appearance,
|
|
185
|
-
script: () => Appearance.create(entries(), { storageKey })(),
|
|
186
|
-
style: boundStyle(bound[input.defaultTheme]),
|
|
187
|
-
theme: bound[input.defaultTheme],
|
|
188
|
-
themes: Object.freeze(select),
|
|
189
|
-
variants: boundVariants,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
if (input.defaultTheme !== undefined)
|
|
193
|
-
throw new InvalidError('defaultTheme requires a named themes catalog.');
|
|
194
|
-
if (input.theme !== undefined) {
|
|
195
|
-
const theme = handle(definition(input.theme), 'theme');
|
|
196
|
-
return Object.freeze({
|
|
197
|
-
appearance: Appearance.root([], { storageKey }),
|
|
198
|
-
script: Appearance.create([], { storageKey }),
|
|
199
|
-
style: boundStyle(theme),
|
|
200
|
-
theme,
|
|
201
|
-
variants: boundVariants,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
const theme = shorthands ? Token.bind(Theme.define({}), contract) : undefined;
|
|
205
|
-
return Object.freeze({
|
|
206
|
-
appearance: Appearance.root([], { storageKey }),
|
|
207
|
-
script: Appearance.create([], { storageKey }),
|
|
208
|
-
style: boundStyle(theme),
|
|
209
|
-
variants: boundVariants,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
function definition(value) {
|
|
213
|
-
try {
|
|
214
|
-
if (value &&
|
|
215
|
-
typeof value === 'object' &&
|
|
216
|
-
Object.getOwnPropertyDescriptor(value, Token.definition)?.value)
|
|
217
|
-
return value;
|
|
218
|
-
return Theme.define(record(value));
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
if (error instanceof InvalidError)
|
|
222
|
-
throw error;
|
|
223
|
-
throw new InvalidError(error.message);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/** Invalid options or incompatible named themes. */
|
|
227
|
-
export class InvalidError extends Error {
|
|
228
|
-
/** Creates a configuration diagnostic without generating styles. */
|
|
229
|
-
constructor(message) {
|
|
230
|
-
super(message);
|
|
231
|
-
}
|
|
232
|
-
/** Stable namespaced error identifier. */
|
|
233
|
-
name = 'Config.InvalidError';
|
|
234
|
-
}
|
|
235
|
-
function record(value) {
|
|
236
|
-
if (!value ||
|
|
237
|
-
typeof value !== 'object' ||
|
|
238
|
-
Array.isArray(value) ||
|
|
239
|
-
![null, Object.prototype].includes(Object.getPrototypeOf(value)))
|
|
240
|
-
throw new InvalidError('Expected a plain configuration record.');
|
|
241
|
-
const result = Object.create(null);
|
|
242
|
-
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
243
|
-
if (!('value' in descriptor))
|
|
244
|
-
throw new InvalidError('Configuration records cannot contain accessors.');
|
|
245
|
-
result[key] = descriptor.value;
|
|
246
|
-
}
|
|
247
|
-
return result;
|
|
5
|
+
for (const key of ['theme', 'themes', 'defaultTheme'])
|
|
6
|
+
if (Object.hasOwn(options, key))
|
|
7
|
+
throw new Configuration.InvalidError(`Use vars and defaultVars instead of ${key}.`);
|
|
8
|
+
return Configuration.create(options);
|
|
248
9
|
}
|
|
249
10
|
//# sourceMappingURL=Config.js.map
|