zyzz 0.0.2 → 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.
Files changed (252) hide show
  1. package/README.md +34 -19
  2. package/dist/Config.d.ts +16 -167
  3. package/dist/Config.d.ts.map +1 -1
  4. package/dist/Config.js +7 -246
  5. package/dist/Config.js.map +1 -1
  6. package/dist/Style.d.ts +19 -13
  7. package/dist/Style.d.ts.map +1 -1
  8. package/dist/Style.js +73 -7
  9. package/dist/Style.js.map +1 -1
  10. package/dist/Vars.d.ts +114 -0
  11. package/dist/Vars.d.ts.map +1 -0
  12. package/dist/Vars.js +42 -0
  13. package/dist/Vars.js.map +1 -0
  14. package/dist/compiler/Graph.js +11 -8
  15. package/dist/compiler/Graph.js.map +1 -1
  16. package/dist/compiler/Native.d.ts +5 -5
  17. package/dist/compiler/Native.d.ts.map +1 -1
  18. package/dist/compiler/Native.js +21 -21
  19. package/dist/compiler/Native.js.map +1 -1
  20. package/dist/compiler/Source.d.ts +10 -6
  21. package/dist/compiler/Source.d.ts.map +1 -1
  22. package/dist/compiler/Source.js +66 -11
  23. package/dist/compiler/Source.js.map +1 -1
  24. package/dist/compiler/Transform.d.ts +1 -1
  25. package/dist/compiler/Transform.d.ts.map +1 -1
  26. package/dist/compiler/Transform.js +59 -21
  27. package/dist/compiler/Transform.js.map +1 -1
  28. package/dist/compiler/internal/Compositions.d.ts +5 -0
  29. package/dist/compiler/internal/Compositions.d.ts.map +1 -1
  30. package/dist/compiler/internal/Compositions.js +22 -3
  31. package/dist/compiler/internal/Compositions.js.map +1 -1
  32. package/dist/compiler/internal/Configurations.d.ts.map +1 -1
  33. package/dist/compiler/internal/Configurations.js +73 -12
  34. package/dist/compiler/internal/Configurations.js.map +1 -1
  35. package/dist/compiler/internal/Contract.d.ts +1 -1
  36. package/dist/compiler/internal/Contract.d.ts.map +1 -1
  37. package/dist/compiler/internal/Contract.js +162 -13
  38. package/dist/compiler/internal/Contract.js.map +1 -1
  39. package/dist/compiler/internal/Contributions.js +1 -1
  40. package/dist/compiler/internal/Contributions.js.map +1 -1
  41. package/dist/compiler/internal/Dynamic.js +1 -1
  42. package/dist/compiler/internal/Dynamic.js.map +1 -1
  43. package/dist/compiler/internal/Expression.d.ts +3 -0
  44. package/dist/compiler/internal/Expression.d.ts.map +1 -1
  45. package/dist/compiler/internal/Expression.js +21 -0
  46. package/dist/compiler/internal/Expression.js.map +1 -1
  47. package/dist/compiler/internal/Identifiers.d.ts +1 -1
  48. package/dist/compiler/internal/Identifiers.d.ts.map +1 -1
  49. package/dist/compiler/internal/Identifiers.js +2 -2
  50. package/dist/compiler/internal/Identifiers.js.map +1 -1
  51. package/dist/compiler/internal/NativeBindings.d.ts +1 -1
  52. package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
  53. package/dist/compiler/internal/NativeBindings.js +3 -3
  54. package/dist/compiler/internal/NativeBindings.js.map +1 -1
  55. package/dist/compiler/internal/PackedStyles.d.ts +1 -1
  56. package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
  57. package/dist/compiler/internal/PackedStyles.js +15 -25
  58. package/dist/compiler/internal/PackedStyles.js.map +1 -1
  59. package/dist/compiler/internal/Recipes.js +1 -1
  60. package/dist/compiler/internal/Recipes.js.map +1 -1
  61. package/dist/compiler/internal/Selectors.js +1 -1
  62. package/dist/compiler/internal/Selectors.js.map +1 -1
  63. package/dist/compiler/internal/Themes.d.ts +12 -3
  64. package/dist/compiler/internal/Themes.d.ts.map +1 -1
  65. package/dist/compiler/internal/Themes.js +192 -52
  66. package/dist/compiler/internal/Themes.js.map +1 -1
  67. package/dist/compiler/internal/{Variables.d.ts → Vars.d.ts} +1 -1
  68. package/dist/compiler/internal/Vars.d.ts.map +1 -0
  69. package/dist/compiler/internal/{Variables.js → Vars.js} +3 -3
  70. package/dist/compiler/internal/Vars.js.map +1 -0
  71. package/dist/default.d.ts +451 -1649
  72. package/dist/default.d.ts.map +1 -1
  73. package/dist/default.js +389 -80
  74. package/dist/default.js.map +2 -2
  75. package/dist/default.js.zyzz.json +1 -1
  76. package/dist/esbuild/index.d.ts +3 -0
  77. package/dist/esbuild/index.d.ts.map +1 -0
  78. package/dist/esbuild/index.js +5 -0
  79. package/dist/esbuild/index.js.map +1 -0
  80. package/dist/index.d.ts +4 -4
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +4 -4
  83. package/dist/index.js.map +1 -1
  84. package/dist/internal/Authoring.d.ts +1 -1
  85. package/dist/internal/Authoring.d.ts.map +1 -1
  86. package/dist/internal/Authoring.js +4 -4
  87. package/dist/internal/Authoring.js.map +1 -1
  88. package/dist/internal/Binding.d.ts +1 -1
  89. package/dist/internal/Binding.d.ts.map +1 -1
  90. package/dist/internal/Completion.d.ts +19 -0
  91. package/dist/internal/Completion.d.ts.map +1 -0
  92. package/dist/internal/Completion.js +2 -0
  93. package/dist/internal/Completion.js.map +1 -0
  94. package/dist/internal/Condition.d.ts +3 -1
  95. package/dist/internal/Condition.d.ts.map +1 -1
  96. package/dist/internal/Condition.js.map +1 -1
  97. package/dist/internal/Configuration.d.ts +248 -0
  98. package/dist/internal/Configuration.d.ts.map +1 -0
  99. package/dist/internal/Configuration.js +343 -0
  100. package/dist/internal/Configuration.js.map +1 -0
  101. package/dist/internal/Shorthands.d.ts +1 -1
  102. package/dist/internal/Shorthands.d.ts.map +1 -1
  103. package/dist/internal/Shorthands.js +1 -0
  104. package/dist/internal/Shorthands.js.map +1 -1
  105. package/dist/{Theme.d.ts → internal/Theme.d.ts} +24 -19
  106. package/dist/internal/Theme.d.ts.map +1 -0
  107. package/dist/{Theme.js → internal/Theme.js} +57 -14
  108. package/dist/internal/Theme.js.map +1 -0
  109. package/dist/internal/Token.d.ts +46 -16
  110. package/dist/internal/Token.d.ts.map +1 -1
  111. package/dist/internal/Token.js +89 -5
  112. package/dist/internal/Token.js.map +1 -1
  113. package/dist/internal/Typography.d.ts +31 -0
  114. package/dist/internal/Typography.d.ts.map +1 -0
  115. package/dist/internal/Typography.js +54 -0
  116. package/dist/internal/Typography.js.map +1 -0
  117. package/dist/internal/Value.d.ts +6 -1
  118. package/dist/internal/Value.d.ts.map +1 -1
  119. package/dist/internal/Value.js.map +1 -1
  120. package/dist/internal/VariableSets.d.ts +20 -0
  121. package/dist/internal/VariableSets.d.ts.map +1 -0
  122. package/dist/internal/VariableSets.js +317 -0
  123. package/dist/internal/VariableSets.js.map +1 -0
  124. package/dist/next/loader.js +15 -5
  125. package/dist/next/loader.js.map +1 -1
  126. package/dist/node/Host.d.ts.map +1 -1
  127. package/dist/node/Host.js +1 -1
  128. package/dist/node/Host.js.map +1 -1
  129. package/dist/react-native/Host.d.ts +2 -2
  130. package/dist/react-native/Host.d.ts.map +1 -1
  131. package/dist/react-native/Host.js +4 -4
  132. package/dist/react-native/Host.js.map +1 -1
  133. package/dist/react-native/StyleSheet.d.ts +9 -8
  134. package/dist/react-native/StyleSheet.d.ts.map +1 -1
  135. package/dist/react-native/StyleSheet.js +29 -23
  136. package/dist/react-native/StyleSheet.js.map +1 -1
  137. package/dist/react-native/Variants.d.ts +3 -3
  138. package/dist/react-native/Variants.d.ts.map +1 -1
  139. package/dist/react-native/Variants.js +2 -2
  140. package/dist/react-native/react.d.ts +1 -1
  141. package/dist/react-native/react.d.ts.map +1 -1
  142. package/dist/react-native/react.js +5 -5
  143. package/dist/react-native/react.js.map +1 -1
  144. package/dist/rollup/index.d.ts +3 -0
  145. package/dist/rollup/index.d.ts.map +1 -0
  146. package/dist/rollup/index.js +5 -0
  147. package/dist/rollup/index.js.map +1 -0
  148. package/dist/runtime/Appearance.d.ts +7 -7
  149. package/dist/runtime/Appearance.d.ts.map +1 -1
  150. package/dist/runtime/Appearance.js +15 -15
  151. package/dist/runtime/Appearance.js.map +1 -1
  152. package/dist/runtime/Dynamic.d.ts.map +1 -1
  153. package/dist/runtime/Dynamic.js +4 -1
  154. package/dist/runtime/Dynamic.js.map +1 -1
  155. package/dist/runtime/NativeContext.d.ts +4 -4
  156. package/dist/runtime/NativeContext.d.ts.map +1 -1
  157. package/dist/runtime/NativeContext.js +5 -5
  158. package/dist/runtime/NativeContext.js.map +1 -1
  159. package/dist/runtime/NativeDynamic.d.ts +1 -1
  160. package/dist/runtime/NativeDynamic.d.ts.map +1 -1
  161. package/dist/runtime/NativeDynamic.js.map +1 -1
  162. package/dist/runtime/Props.d.ts +1 -1
  163. package/dist/runtime/Props.js +3 -3
  164. package/dist/runtime/Props.js.map +1 -1
  165. package/dist/runtime/Selection.d.ts +14 -10
  166. package/dist/runtime/Selection.d.ts.map +1 -1
  167. package/dist/runtime/Selection.js +19 -18
  168. package/dist/runtime/Selection.js.map +1 -1
  169. package/dist/styleFunction.d.ts +14 -14
  170. package/dist/styleFunction.d.ts.map +1 -1
  171. package/dist/styleFunction.js.map +1 -1
  172. package/dist/unplugin/index.d.ts +20 -0
  173. package/dist/unplugin/index.d.ts.map +1 -0
  174. package/dist/unplugin/index.js +498 -0
  175. package/dist/unplugin/index.js.map +1 -0
  176. package/dist/variants.d.ts +3 -3
  177. package/dist/variants.d.ts.map +1 -1
  178. package/dist/variants.js.map +1 -1
  179. package/dist/vite/index.d.ts.map +1 -1
  180. package/dist/vite/index.js +6 -3
  181. package/dist/vite/index.js.map +1 -1
  182. package/dist/web/Css.d.ts +4 -3
  183. package/dist/web/Css.d.ts.map +1 -1
  184. package/dist/web/Css.js +4 -4
  185. package/dist/web/Css.js.map +1 -1
  186. package/dist/web/internal/Themes.d.ts +3 -2
  187. package/dist/web/internal/Themes.d.ts.map +1 -1
  188. package/dist/web/internal/Themes.js +42 -6
  189. package/dist/web/internal/Themes.js.map +1 -1
  190. package/dist/webpack/index.d.ts +3 -0
  191. package/dist/webpack/index.d.ts.map +1 -0
  192. package/dist/webpack/index.js +5 -0
  193. package/dist/webpack/index.js.map +1 -0
  194. package/package.json +23 -2
  195. package/src/Config.ts +43 -684
  196. package/src/Style.ts +167 -40
  197. package/src/Vars.ts +299 -0
  198. package/src/compiler/Graph.ts +14 -9
  199. package/src/compiler/Native.ts +29 -32
  200. package/src/compiler/Source.ts +85 -18
  201. package/src/compiler/Transform.ts +78 -22
  202. package/src/compiler/internal/Compositions.ts +36 -3
  203. package/src/compiler/internal/Configurations.ts +83 -11
  204. package/src/compiler/internal/Contract.ts +223 -17
  205. package/src/compiler/internal/Contributions.ts +1 -1
  206. package/src/compiler/internal/Dynamic.ts +1 -1
  207. package/src/compiler/internal/Expression.ts +26 -0
  208. package/src/compiler/internal/Identifiers.ts +2 -1
  209. package/src/compiler/internal/NativeBindings.ts +3 -3
  210. package/src/compiler/internal/PackedStyles.ts +22 -26
  211. package/src/compiler/internal/Recipes.ts +1 -1
  212. package/src/compiler/internal/Selectors.ts +1 -1
  213. package/src/compiler/internal/Themes.ts +266 -57
  214. package/src/compiler/internal/{Variables.ts → Vars.ts} +2 -2
  215. package/src/default.ts +868 -156
  216. package/src/esbuild/index.ts +5 -0
  217. package/src/index.ts +4 -4
  218. package/src/internal/Authoring.ts +5 -7
  219. package/src/internal/Binding.ts +1 -1
  220. package/src/internal/Completion.ts +42 -0
  221. package/src/internal/Condition.ts +31 -1
  222. package/src/internal/Configuration.ts +970 -0
  223. package/src/internal/Shorthands.ts +2 -0
  224. package/src/{Theme.ts → internal/Theme.ts} +174 -48
  225. package/src/internal/Token.ts +258 -85
  226. package/src/internal/Typography.ts +106 -0
  227. package/src/internal/Value.ts +45 -26
  228. package/src/internal/VariableSets.ts +458 -0
  229. package/src/next/loader.ts +19 -5
  230. package/src/node/Host.ts +1 -2
  231. package/src/react-native/Host.ts +6 -6
  232. package/src/react-native/StyleSheet.ts +49 -42
  233. package/src/react-native/Variants.ts +3 -3
  234. package/src/react-native/react.ts +6 -6
  235. package/src/rollup/index.ts +5 -0
  236. package/src/runtime/Appearance.ts +20 -20
  237. package/src/runtime/Dynamic.ts +4 -1
  238. package/src/runtime/NativeContext.ts +8 -8
  239. package/src/runtime/NativeDynamic.ts +2 -4
  240. package/src/runtime/Props.ts +3 -3
  241. package/src/runtime/Selection.ts +44 -33
  242. package/src/styleFunction.ts +22 -19
  243. package/src/unplugin/index.ts +600 -0
  244. package/src/variants.ts +7 -5
  245. package/src/vite/index.ts +5 -4
  246. package/src/web/Css.ts +10 -7
  247. package/src/web/internal/Themes.ts +52 -9
  248. package/src/webpack/index.ts +5 -0
  249. package/dist/Theme.d.ts.map +0 -1
  250. package/dist/Theme.js.map +0 -1
  251. package/dist/compiler/internal/Variables.d.ts.map +0 -1
  252. 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 `theme`, 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.
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 [`Theme.extend`](docs/api/core/Theme/extend.md) to override existing tokens while retaining all other values and the same token contract.
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, Theme } from 'zyzz'
205
- import { theme as defaultTheme } from 'zyzz/default'
219
+ import { Config, Vars } from 'zyzz'
220
+ import { vars as defaultVars } from 'zyzz/default'
206
221
 
207
- export const { style, theme, variants } = Config.create({
208
- theme: Theme.extend(defaultTheme, {
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, theme, variants } = Config.create({
231
- theme: {
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 [`Theme.define`](docs/api/core/Theme/define.md) for reusable definitions outside config. See [Themes & Tokens](docs/guides/themes.md) for nested scopes and named alternatives.
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, theme } from './zyzz.config.js'
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 {...theme({ colorScheme: 'light dark' })}>
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 `themes({ theme: 'mint', colorScheme: 'dark' })`.
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({ theme: 'mint', colorScheme: 'dark' })` applies and saves a change from the client. System preference needs no script or provider.
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`/`variables` overrides; consumed values become CSS variable assignments. Other component props stay on the component. CSS rules stay static.
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. `theme.vars` provides typed CSS variable references for ordinary CSS expressions; `theme.tokens` provides portable token references.
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, theme } from './zyzz.config.js'
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: theme.vars.color.brand,
345
- width: `calc(100% - ${theme.vars.spacing.md})`,
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 `variables` 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.
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
- * Normalizes explicit configuration into isolated typed authoring contracts.
3
- * @module
4
- */
5
- import * as Appearance from './runtime/Appearance.js';
6
- import type * as Binding from './internal/Binding.js';
7
- import type * as Condition from './internal/Condition.js';
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' | '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
- theme: ValidInput<input>;
160
- } : options extends {
161
- themes: infer catalog;
162
- defaultTheme: infer key;
163
- } ? {
164
- defaultTheme: keyof catalog;
165
- themes: {
166
- [name in keyof catalog]: ValidInput<catalog[name]> & (key extends keyof catalog ? catalog[name] extends Theme.Definition ? Theme.Definition<ExtractTokens<catalog[name]> & Match<ExtractTokens<catalog[name]>, ExtractTokens<catalog[key]>>> : Match<ExtractTokens<catalog[name]>, ExtractTokens<catalog[key]>> : never);
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
@@ -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,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,GAC7C,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;AA4Q7B,iDAAiD;AACjD,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,+DAA+D;IAC/D,KAAK,OAAO,GAAG;QACb,wEAAwE;QACxE,QAAQ,CAAC,SAAS,CAAC,EA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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
- * Normalizes explicit configuration into isolated typed authoring contracts.
3
- * @module
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 input = record(options);
16
- for (const key of Object.keys(input))
17
- if (![
18
- 'cssOutput',
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