zyzz 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) 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 +15 -12
  7. package/dist/Style.d.ts.map +1 -1
  8. package/dist/Style.js +51 -26
  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 +8 -6
  21. package/dist/compiler/Source.d.ts.map +1 -1
  22. package/dist/compiler/Source.js +47 -14
  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 +58 -22
  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 +155 -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 +147 -2562
  72. package/dist/default.d.ts.map +1 -1
  73. package/dist/default.js +85 -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/{Theme.d.ts → internal/Theme.d.ts} +15 -13
  102. package/dist/internal/Theme.d.ts.map +1 -0
  103. package/dist/{Theme.js → internal/Theme.js} +39 -12
  104. package/dist/internal/Theme.js.map +1 -0
  105. package/dist/internal/Token.d.ts +46 -16
  106. package/dist/internal/Token.d.ts.map +1 -1
  107. package/dist/internal/Token.js +89 -5
  108. package/dist/internal/Token.js.map +1 -1
  109. package/dist/internal/Typography.d.ts +13 -5
  110. package/dist/internal/Typography.d.ts.map +1 -1
  111. package/dist/internal/Typography.js +42 -6
  112. package/dist/internal/Typography.js.map +1 -1
  113. package/dist/internal/Value.d.ts +6 -1
  114. package/dist/internal/Value.d.ts.map +1 -1
  115. package/dist/internal/Value.js.map +1 -1
  116. package/dist/internal/VariableSets.d.ts +20 -0
  117. package/dist/internal/VariableSets.d.ts.map +1 -0
  118. package/dist/internal/VariableSets.js +317 -0
  119. package/dist/internal/VariableSets.js.map +1 -0
  120. package/dist/next/loader.js +15 -5
  121. package/dist/next/loader.js.map +1 -1
  122. package/dist/node/Host.d.ts.map +1 -1
  123. package/dist/node/Host.js +1 -1
  124. package/dist/node/Host.js.map +1 -1
  125. package/dist/react-native/Host.d.ts +2 -2
  126. package/dist/react-native/Host.d.ts.map +1 -1
  127. package/dist/react-native/Host.js +4 -4
  128. package/dist/react-native/Host.js.map +1 -1
  129. package/dist/react-native/StyleSheet.d.ts +9 -8
  130. package/dist/react-native/StyleSheet.d.ts.map +1 -1
  131. package/dist/react-native/StyleSheet.js +29 -23
  132. package/dist/react-native/StyleSheet.js.map +1 -1
  133. package/dist/react-native/Variants.d.ts +3 -3
  134. package/dist/react-native/Variants.d.ts.map +1 -1
  135. package/dist/react-native/Variants.js +2 -2
  136. package/dist/react-native/react.d.ts +1 -1
  137. package/dist/react-native/react.d.ts.map +1 -1
  138. package/dist/react-native/react.js +5 -5
  139. package/dist/react-native/react.js.map +1 -1
  140. package/dist/rollup/index.d.ts +3 -0
  141. package/dist/rollup/index.d.ts.map +1 -0
  142. package/dist/rollup/index.js +5 -0
  143. package/dist/rollup/index.js.map +1 -0
  144. package/dist/runtime/Appearance.d.ts +7 -7
  145. package/dist/runtime/Appearance.d.ts.map +1 -1
  146. package/dist/runtime/Appearance.js +15 -15
  147. package/dist/runtime/Appearance.js.map +1 -1
  148. package/dist/runtime/Dynamic.d.ts.map +1 -1
  149. package/dist/runtime/Dynamic.js +4 -1
  150. package/dist/runtime/Dynamic.js.map +1 -1
  151. package/dist/runtime/NativeContext.d.ts +4 -4
  152. package/dist/runtime/NativeContext.d.ts.map +1 -1
  153. package/dist/runtime/NativeContext.js +5 -5
  154. package/dist/runtime/NativeContext.js.map +1 -1
  155. package/dist/runtime/NativeDynamic.d.ts +1 -1
  156. package/dist/runtime/NativeDynamic.d.ts.map +1 -1
  157. package/dist/runtime/NativeDynamic.js.map +1 -1
  158. package/dist/runtime/Props.d.ts +1 -1
  159. package/dist/runtime/Props.js +3 -3
  160. package/dist/runtime/Props.js.map +1 -1
  161. package/dist/runtime/Selection.d.ts +14 -10
  162. package/dist/runtime/Selection.d.ts.map +1 -1
  163. package/dist/runtime/Selection.js +19 -18
  164. package/dist/runtime/Selection.js.map +1 -1
  165. package/dist/styleFunction.d.ts +14 -14
  166. package/dist/styleFunction.d.ts.map +1 -1
  167. package/dist/styleFunction.js.map +1 -1
  168. package/dist/unplugin/index.d.ts +20 -0
  169. package/dist/unplugin/index.d.ts.map +1 -0
  170. package/dist/unplugin/index.js +498 -0
  171. package/dist/unplugin/index.js.map +1 -0
  172. package/dist/variants.d.ts +3 -3
  173. package/dist/variants.d.ts.map +1 -1
  174. package/dist/variants.js.map +1 -1
  175. package/dist/vite/index.d.ts.map +1 -1
  176. package/dist/vite/index.js +6 -3
  177. package/dist/vite/index.js.map +1 -1
  178. package/dist/web/Css.d.ts +4 -3
  179. package/dist/web/Css.d.ts.map +1 -1
  180. package/dist/web/Css.js +4 -4
  181. package/dist/web/Css.js.map +1 -1
  182. package/dist/web/internal/Themes.d.ts +3 -2
  183. package/dist/web/internal/Themes.d.ts.map +1 -1
  184. package/dist/web/internal/Themes.js +42 -6
  185. package/dist/web/internal/Themes.js.map +1 -1
  186. package/dist/webpack/index.d.ts +3 -0
  187. package/dist/webpack/index.d.ts.map +1 -0
  188. package/dist/webpack/index.js +5 -0
  189. package/dist/webpack/index.js.map +1 -0
  190. package/package.json +23 -2
  191. package/src/Config.ts +43 -685
  192. package/src/Style.ts +97 -34
  193. package/src/Vars.ts +299 -0
  194. package/src/compiler/Graph.ts +14 -9
  195. package/src/compiler/Native.ts +29 -32
  196. package/src/compiler/Source.ts +59 -21
  197. package/src/compiler/Transform.ts +73 -23
  198. package/src/compiler/internal/Compositions.ts +36 -3
  199. package/src/compiler/internal/Configurations.ts +83 -11
  200. package/src/compiler/internal/Contract.ts +207 -15
  201. package/src/compiler/internal/Contributions.ts +1 -1
  202. package/src/compiler/internal/Dynamic.ts +1 -1
  203. package/src/compiler/internal/Expression.ts +26 -0
  204. package/src/compiler/internal/Identifiers.ts +2 -1
  205. package/src/compiler/internal/NativeBindings.ts +3 -3
  206. package/src/compiler/internal/PackedStyles.ts +22 -26
  207. package/src/compiler/internal/Recipes.ts +1 -1
  208. package/src/compiler/internal/Selectors.ts +1 -1
  209. package/src/compiler/internal/Themes.ts +266 -57
  210. package/src/compiler/internal/{Variables.ts → Vars.ts} +2 -2
  211. package/src/default.ts +173 -154
  212. package/src/esbuild/index.ts +5 -0
  213. package/src/index.ts +4 -4
  214. package/src/internal/Authoring.ts +5 -7
  215. package/src/internal/Binding.ts +1 -1
  216. package/src/internal/Completion.ts +42 -0
  217. package/src/internal/Condition.ts +31 -1
  218. package/src/internal/Configuration.ts +970 -0
  219. package/src/{Theme.ts → internal/Theme.ts} +75 -20
  220. package/src/internal/Token.ts +258 -85
  221. package/src/internal/Typography.ts +71 -16
  222. package/src/internal/Value.ts +45 -26
  223. package/src/internal/VariableSets.ts +458 -0
  224. package/src/next/loader.ts +19 -5
  225. package/src/node/Host.ts +1 -2
  226. package/src/react-native/Host.ts +6 -6
  227. package/src/react-native/StyleSheet.ts +49 -42
  228. package/src/react-native/Variants.ts +3 -3
  229. package/src/react-native/react.ts +6 -6
  230. package/src/rollup/index.ts +5 -0
  231. package/src/runtime/Appearance.ts +20 -20
  232. package/src/runtime/Dynamic.ts +4 -1
  233. package/src/runtime/NativeContext.ts +8 -8
  234. package/src/runtime/NativeDynamic.ts +2 -4
  235. package/src/runtime/Props.ts +3 -3
  236. package/src/runtime/Selection.ts +44 -33
  237. package/src/styleFunction.ts +22 -19
  238. package/src/unplugin/index.ts +600 -0
  239. package/src/variants.ts +7 -5
  240. package/src/vite/index.ts +5 -4
  241. package/src/web/Css.ts +10 -7
  242. package/src/web/internal/Themes.ts +52 -9
  243. package/src/webpack/index.ts +5 -0
  244. package/dist/Theme.d.ts.map +0 -1
  245. package/dist/Theme.js.map +0 -1
  246. package/dist/compiler/internal/Variables.d.ts.map +0 -1
  247. package/dist/compiler/internal/Variables.js.map +0 -1
@@ -1,75 +1,86 @@
1
- /** Selects compiler-owned theme classes without evaluating authoring code. @module */
1
+ /** Selects compiler-owned variable scope classes without evaluating authoring code. @module */
2
2
  import * as Scheme from '../internal/Scheme.js'
3
+ import * as Html from './CompositionHtml.js'
3
4
 
4
5
  /**
5
- * Creates a validated selector with the compatible named theme catalog.
6
+ * Creates a validated selector with the compatible named set catalog.
6
7
  * A selected scheme adds its stylesheet class beside the scope class and an inline `color-scheme`.
7
- * @param entries Compatible theme names paired with compiler-owned scope classes.
8
+ * @param entries Compatible set names paired with compiler-owned scope classes.
8
9
  * @param html Whether selection returns HTML class/serialized-style props. Defaults to false (React className/object-style props).
9
- * @returns A callable selector with catalog members exposing their scope class names.
10
+ * @returns A callable selector returning scope props.
10
11
  * @throws {TypeError} When selection names, schemes, or option keys are invalid.
11
12
  */
12
13
  export function create<
13
14
  const entries extends readonly (readonly [string, string])[],
14
15
  const html extends boolean = false,
15
16
  >(entries: entries, html?: html): create.ReturnType<entries[number][0], html>
17
+ export function create(
18
+ entries: readonly (readonly [string, string])[],
19
+ html: boolean,
20
+ key: 'set',
21
+ defaultSet?: string,
22
+ ): (input?: { set?: string | undefined; colorScheme?: string | undefined }) => {
23
+ className?: string
24
+ class?: string
25
+ style?: unknown
26
+ }
16
27
  export function create(
17
28
  entries: readonly (readonly [string, string])[],
18
29
  html = false,
19
- ) {
30
+ key: 'set' = 'set',
31
+ defaultSet?: string,
32
+ ): unknown {
20
33
  const catalog = Object.fromEntries(entries)
21
34
 
22
- const select = (input: { theme: string; colorScheme?: string }) => {
35
+ const select = (
36
+ input: {
37
+ set?: string | undefined
38
+ colorScheme?: string | undefined
39
+ } = {},
40
+ ) => {
41
+ const selected =
42
+ input && typeof input === 'object'
43
+ ? (input[key] ?? defaultSet)
44
+ : undefined
23
45
  if (
24
46
  !input ||
25
47
  typeof input !== 'object' ||
26
48
  Array.isArray(input) ||
27
- !Object.hasOwn(input, 'theme') ||
28
- typeof input.theme !== 'string' ||
29
- !Object.hasOwn(catalog, input.theme) ||
49
+ (!Object.hasOwn(input, key) && defaultSet === undefined) ||
50
+ typeof selected !== 'string' ||
51
+ !Object.hasOwn(catalog, selected!) ||
30
52
  Object.keys(input).some(
31
- (key) => key !== 'theme' && key !== 'colorScheme',
53
+ (field) => field !== key && field !== 'colorScheme',
32
54
  ) ||
33
55
  (input.colorScheme !== undefined &&
34
56
  !['light', 'dark', 'light dark'].includes(input.colorScheme))
35
57
  )
36
- throw new TypeError('Invalid theme selection.')
58
+ throw new TypeError('Invalid variable selection.')
37
59
 
38
60
  const scheme = input.colorScheme as Scheme.Name | undefined
39
61
 
40
- return {
41
- [html ? 'class' : 'className']: scheme
42
- ? `${catalog[input.theme]} ${Scheme.classes[scheme]}`
43
- : catalog[input.theme],
44
- ...(scheme
45
- ? {
46
- style: html ? `color-scheme:${scheme}` : { colorScheme: scheme },
47
- }
48
- : {}),
62
+ const props = {
63
+ className: scheme
64
+ ? `${catalog[selected!]} ${Scheme.classes[scheme]}`
65
+ : catalog[selected!]!,
66
+ ...(scheme ? { style: { colorScheme: scheme } } : {}),
49
67
  }
68
+ return html ? Html.from(props) : props
50
69
  }
51
70
 
52
- return Object.defineProperties(
53
- select,
54
- Object.getOwnPropertyDescriptors(
55
- Object.fromEntries(
56
- entries.map(([name, className]) => [name, { className }]),
57
- ),
58
- ),
59
- ) as unknown as create.ReturnType<string, boolean>
71
+ return select as create.ReturnType<string, boolean>
60
72
  }
61
73
 
62
- /** Typed compiler-owned selection and compatible catalog members. */
74
+ /** Typed compiler-owned scope selection. */
63
75
  export declare namespace create {
64
76
  type ReturnType<name extends string, html extends boolean = false> = {
65
77
  <
66
78
  const input extends {
67
- readonly theme: name
79
+ readonly set: name
68
80
  readonly colorScheme?: 'light' | 'dark' | 'light dark' | undefined
69
81
  },
70
82
  >(
71
- input: input &
72
- Record<Exclude<keyof input, 'theme' | 'colorScheme'>, never>,
83
+ input: input & Record<Exclude<keyof input, 'set' | 'colorScheme'>, never>,
73
84
  ): html extends true
74
85
  ? { readonly class: string; readonly style?: string | undefined }
75
86
  : {
@@ -78,5 +89,5 @@ export declare namespace create {
78
89
  | { readonly colorScheme: 'light' | 'dark' | 'light dark' }
79
90
  | undefined
80
91
  }
81
- } & { readonly [key in name]: { readonly className: string } }
92
+ }
82
93
  }
@@ -4,25 +4,22 @@
4
4
  */
5
5
  import * as Authoring from './internal/Authoring.js'
6
6
  import type * as Binding from './internal/Binding.js'
7
+ import type * as Completion from './internal/Completion.js'
7
8
  import type * as Literal from './internal/Literal.js'
8
9
  import type * as Style from './Style.js'
9
10
 
10
- /** Restricts callback hints to inferred declarations instead of expanding every property grammar. */
11
- type CompletionProperties<styles = Record<string, unknown>> = {
12
- readonly [property in keyof typeof Literal.rules & keyof styles]?:
13
- | Literal.Properties[property]
14
- | (string & {})
15
- | number
16
- | object
17
- }
18
-
19
11
  type Keys<value> = value extends unknown ? keyof value : never
20
12
 
13
+ // Keep named and custom-property instantiations separate so framework interfaces need no index signature.
14
+ type InlineProperties<properties extends string> = {
15
+ readonly [property in properties]?: string | number | undefined
16
+ }
17
+
21
18
  type VariableOptions<input> = input extends {
22
- readonly variables: infer variables
19
+ readonly vars: infer variables
23
20
  }
24
21
  ? {
25
- readonly variables: {
22
+ readonly vars: {
26
23
  readonly [key in keyof variables]: string extends key
27
24
  ? variables[key]
28
25
  : key extends `--${string}`
@@ -49,7 +46,7 @@ export function style<
49
46
  values: values,
50
47
  ) => styles &
51
48
  NoInfer<Style.Accepted<styles, {}, true> & Binding.Checked<styles>>) &
52
- CompletionProperties<NoInfer<styles>>,
49
+ Completion.Properties<{}, NoInfer<styles>>,
53
50
  // Exclude invalid callbacks by arity so they cannot mask object-property diagnostics.
54
51
  ...options: Parameters<callback> extends [Record<string, string | number>]
55
52
  ? values extends Binding.Inputs<values>
@@ -60,7 +57,7 @@ export function style<
60
57
  export function style<const styles extends Record<string, unknown>>(
61
58
  styles: styles &
62
59
  NoInfer<Style.Accepted<styles, {}, true>> &
63
- CompletionProperties,
60
+ Completion.Properties,
64
61
  options?: style.DefinitionOptions,
65
62
  ): style.ReturnType
66
63
  export function style(
@@ -80,7 +77,7 @@ export declare namespace style {
80
77
  type DefinitionOptions = { readonly id?: string | undefined }
81
78
  /** Callable compiled bindings with required scalar inputs and styling overrides. */
82
79
  type Dynamic<values, output extends Output = 'react'> = Reference &
83
- (<const input extends values & Options>(
80
+ (<const input extends values & Options<output>>(
84
81
  input: input &
85
82
  VariableOptions<input> &
86
83
  Record<Exclude<keyof input, keyof values | keyof Options>, never>,
@@ -90,13 +87,19 @@ export declare namespace style {
90
87
  type ErrorType = Error
91
88
 
92
89
  /** Styling overrides consumed by a transformed definition. */
93
- type Options = {
90
+ type Options<output extends Output = 'react'> = {
94
91
  /** External class names appended to the generated classes. */
95
92
  readonly className?: string | undefined
96
- /** Literal inline styling overrides. */
97
- readonly style?: Literal.Properties | undefined
93
+ /** Inline overrides. React accepts scalar values, while HTML requires CSS units. */
94
+ readonly style?:
95
+ | (output extends 'html'
96
+ ? Literal.Properties
97
+ :
98
+ | InlineProperties<keyof typeof Literal.rules>
99
+ | InlineProperties<keyof Literal.Properties>)
100
+ | undefined
98
101
  /** Inline custom-property assignments, merged before explicit style overrides. */
99
- readonly variables?:
102
+ readonly vars?:
100
103
  | Readonly<Record<`--${string}`, string | number | undefined>>
101
104
  | undefined
102
105
  }
@@ -118,7 +121,7 @@ export declare namespace style {
118
121
 
119
122
  /** Callable definition; source rewriting supplies its implementation. */
120
123
  type ReturnType<output extends Output = 'react'> = Reference &
121
- (<const options extends Options = Options>(
124
+ (<const options extends Options<output> = Options<output>>(
122
125
  options?: options &
123
126
  VariableOptions<options> &
124
127
  Record<Exclude<Keys<options>, keyof Options>, never>,