@elastic/distillate 0.0.0 → 0.1.0

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 (285) hide show
  1. package/LICENSE.txt +93 -0
  2. package/NOTICE.txt +30 -0
  3. package/README.md +142 -0
  4. package/THIRD_PARTY_LICENSES.md +768 -0
  5. package/dist/cjs/collector.js +420 -0
  6. package/dist/cjs/collector.js.map +1 -0
  7. package/dist/cjs/css_scan.js +186 -0
  8. package/dist/cjs/css_scan.js.map +1 -0
  9. package/dist/cjs/dom_sink.js +40 -0
  10. package/dist/cjs/dom_sink.js.map +1 -0
  11. package/dist/cjs/emotion.js +189 -0
  12. package/dist/cjs/emotion.js.map +1 -0
  13. package/dist/cjs/engine.js +79 -0
  14. package/dist/cjs/engine.js.map +1 -0
  15. package/dist/cjs/environment.js +9 -0
  16. package/dist/cjs/environment.js.map +1 -0
  17. package/dist/cjs/hash.js +86 -0
  18. package/dist/cjs/hash.js.map +1 -0
  19. package/dist/cjs/idents.js +23 -0
  20. package/dist/cjs/idents.js.map +1 -0
  21. package/dist/cjs/index.js +42 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/instance.js +34 -0
  24. package/dist/cjs/instance.js.map +1 -0
  25. package/dist/cjs/local_vars.js +100 -0
  26. package/dist/cjs/local_vars.js.map +1 -0
  27. package/dist/cjs/minify.js +77 -0
  28. package/dist/cjs/minify.js.map +1 -0
  29. package/dist/cjs/names.js +77 -0
  30. package/dist/cjs/names.js.map +1 -0
  31. package/dist/cjs/nesting.js +406 -0
  32. package/dist/cjs/nesting.js.map +1 -0
  33. package/dist/cjs/package.json +3 -0
  34. package/dist/cjs/runtime.js +257 -0
  35. package/dist/cjs/runtime.js.map +1 -0
  36. package/dist/cjs/styles/authoring.js +169 -0
  37. package/dist/cjs/styles/authoring.js.map +1 -0
  38. package/dist/cjs/styles/declarations.js +139 -0
  39. package/dist/cjs/styles/declarations.js.map +1 -0
  40. package/dist/cjs/styles/index.js +32 -0
  41. package/dist/cjs/styles/index.js.map +1 -0
  42. package/dist/cjs/styles/module.js +233 -0
  43. package/dist/cjs/styles/module.js.map +1 -0
  44. package/dist/cjs/styles/registry.js +187 -0
  45. package/dist/cjs/styles/registry.js.map +1 -0
  46. package/dist/cjs/styles/types.js +9 -0
  47. package/dist/cjs/styles/types.js.map +1 -0
  48. package/dist/cjs/testing.js +37 -0
  49. package/dist/cjs/testing.js.map +1 -0
  50. package/dist/cjs/theme.js +249 -0
  51. package/dist/cjs/theme.js.map +1 -0
  52. package/dist/cjs/tokens/contextual_var.js +39 -0
  53. package/dist/cjs/tokens/contextual_var.js.map +1 -0
  54. package/dist/cjs/tokens/index.js +24 -0
  55. package/dist/cjs/tokens/index.js.map +1 -0
  56. package/dist/cjs/tokens/kind.js +14 -0
  57. package/dist/cjs/tokens/kind.js.map +1 -0
  58. package/dist/cjs/tokens/light_dark.js +42 -0
  59. package/dist/cjs/tokens/light_dark.js.map +1 -0
  60. package/dist/cjs/tokens/scale_token.js +28 -0
  61. package/dist/cjs/tokens/scale_token.js.map +1 -0
  62. package/dist/cjs/tokens/theme_token.js +28 -0
  63. package/dist/cjs/tokens/theme_token.js.map +1 -0
  64. package/dist/cjs/var_invariant.js +115 -0
  65. package/dist/cjs/var_invariant.js.map +1 -0
  66. package/dist/collector.d.ts +84 -0
  67. package/dist/collector.d.ts.map +1 -0
  68. package/dist/collector.js +416 -0
  69. package/dist/collector.js.map +1 -0
  70. package/dist/css_scan.d.ts +57 -0
  71. package/dist/css_scan.d.ts.map +1 -0
  72. package/dist/css_scan.js +180 -0
  73. package/dist/css_scan.js.map +1 -0
  74. package/dist/dom_sink.d.ts +27 -0
  75. package/dist/dom_sink.d.ts.map +1 -0
  76. package/dist/dom_sink.js +36 -0
  77. package/dist/dom_sink.js.map +1 -0
  78. package/dist/emotion.d.ts +47 -0
  79. package/dist/emotion.d.ts.map +1 -0
  80. package/dist/emotion.js +184 -0
  81. package/dist/emotion.js.map +1 -0
  82. package/dist/engine.d.ts +41 -0
  83. package/dist/engine.d.ts.map +1 -0
  84. package/dist/engine.js +75 -0
  85. package/dist/engine.js.map +1 -0
  86. package/dist/environment.d.ts +43 -0
  87. package/dist/environment.d.ts.map +1 -0
  88. package/dist/environment.js +8 -0
  89. package/dist/environment.js.map +1 -0
  90. package/dist/hash.d.ts +2 -0
  91. package/dist/hash.d.ts.map +1 -0
  92. package/dist/hash.js +82 -0
  93. package/dist/hash.js.map +1 -0
  94. package/dist/idents.d.ts +9 -0
  95. package/dist/idents.d.ts.map +1 -0
  96. package/dist/idents.js +19 -0
  97. package/dist/idents.js.map +1 -0
  98. package/dist/index.d.ts +9 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +14 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/instance.d.ts +16 -0
  103. package/dist/instance.d.ts.map +1 -0
  104. package/dist/instance.js +30 -0
  105. package/dist/instance.js.map +1 -0
  106. package/dist/local_vars.d.ts +75 -0
  107. package/dist/local_vars.d.ts.map +1 -0
  108. package/dist/local_vars.js +92 -0
  109. package/dist/local_vars.js.map +1 -0
  110. package/dist/minify.d.ts +11 -0
  111. package/dist/minify.d.ts.map +1 -0
  112. package/dist/minify.js +73 -0
  113. package/dist/minify.js.map +1 -0
  114. package/dist/names.d.ts +39 -0
  115. package/dist/names.d.ts.map +1 -0
  116. package/dist/names.js +70 -0
  117. package/dist/names.js.map +1 -0
  118. package/dist/nesting.d.ts +59 -0
  119. package/dist/nesting.d.ts.map +1 -0
  120. package/dist/nesting.js +400 -0
  121. package/dist/nesting.js.map +1 -0
  122. package/dist/runtime.d.ts +36 -0
  123. package/dist/runtime.d.ts.map +1 -0
  124. package/dist/runtime.js +252 -0
  125. package/dist/runtime.js.map +1 -0
  126. package/dist/styles/authoring.d.ts +59 -0
  127. package/dist/styles/authoring.d.ts.map +1 -0
  128. package/dist/styles/authoring.js +155 -0
  129. package/dist/styles/authoring.js.map +1 -0
  130. package/dist/styles/declarations.d.ts +10 -0
  131. package/dist/styles/declarations.d.ts.map +1 -0
  132. package/dist/styles/declarations.js +132 -0
  133. package/dist/styles/declarations.js.map +1 -0
  134. package/dist/styles/index.d.ts +7 -0
  135. package/dist/styles/index.d.ts.map +1 -0
  136. package/dist/styles/index.js +12 -0
  137. package/dist/styles/index.js.map +1 -0
  138. package/dist/styles/module.d.ts +5 -0
  139. package/dist/styles/module.d.ts.map +1 -0
  140. package/dist/styles/module.js +229 -0
  141. package/dist/styles/module.js.map +1 -0
  142. package/dist/styles/registry.d.ts +48 -0
  143. package/dist/styles/registry.d.ts.map +1 -0
  144. package/dist/styles/registry.js +182 -0
  145. package/dist/styles/registry.js.map +1 -0
  146. package/dist/styles/types.d.ts +211 -0
  147. package/dist/styles/types.d.ts.map +1 -0
  148. package/dist/styles/types.js +8 -0
  149. package/dist/styles/types.js.map +1 -0
  150. package/dist/testing.d.ts +10 -0
  151. package/dist/testing.d.ts.map +1 -0
  152. package/dist/testing.js +31 -0
  153. package/dist/testing.js.map +1 -0
  154. package/dist/theme.d.ts +85 -0
  155. package/dist/theme.d.ts.map +1 -0
  156. package/dist/theme.js +240 -0
  157. package/dist/theme.js.map +1 -0
  158. package/dist/tokens/contextual_var.d.ts +35 -0
  159. package/dist/tokens/contextual_var.d.ts.map +1 -0
  160. package/dist/tokens/contextual_var.js +33 -0
  161. package/dist/tokens/contextual_var.js.map +1 -0
  162. package/dist/tokens/index.d.ts +5 -0
  163. package/dist/tokens/index.d.ts.map +1 -0
  164. package/dist/tokens/index.js +11 -0
  165. package/dist/tokens/index.js.map +1 -0
  166. package/dist/tokens/kind.d.ts +2 -0
  167. package/dist/tokens/kind.d.ts.map +1 -0
  168. package/dist/tokens/kind.js +10 -0
  169. package/dist/tokens/kind.js.map +1 -0
  170. package/dist/tokens/light_dark.d.ts +20 -0
  171. package/dist/tokens/light_dark.d.ts.map +1 -0
  172. package/dist/tokens/light_dark.js +37 -0
  173. package/dist/tokens/light_dark.js.map +1 -0
  174. package/dist/tokens/scale_token.d.ts +20 -0
  175. package/dist/tokens/scale_token.d.ts.map +1 -0
  176. package/dist/tokens/scale_token.js +23 -0
  177. package/dist/tokens/scale_token.js.map +1 -0
  178. package/dist/tokens/theme_token.d.ts +20 -0
  179. package/dist/tokens/theme_token.d.ts.map +1 -0
  180. package/dist/tokens/theme_token.js +23 -0
  181. package/dist/tokens/theme_token.js.map +1 -0
  182. package/dist/var_invariant.d.ts +25 -0
  183. package/dist/var_invariant.d.ts.map +1 -0
  184. package/dist/var_invariant.js +108 -0
  185. package/dist/var_invariant.js.map +1 -0
  186. package/docs/concepts/authoring.md +115 -0
  187. package/docs/concepts/collection.md +66 -0
  188. package/docs/concepts/distillery.md +47 -0
  189. package/docs/concepts/index.md +18 -0
  190. package/docs/concepts/naming-and-output.md +123 -0
  191. package/docs/concepts/ordering.md +61 -0
  192. package/docs/concepts/single-copy.md +103 -0
  193. package/docs/concepts/tokens.md +99 -0
  194. package/docs/docset.yml +53 -0
  195. package/docs/examples/01-stylesheet.ts +20 -0
  196. package/docs/examples/02-artifact.ts +26 -0
  197. package/docs/examples/03-variants.ts +40 -0
  198. package/docs/examples/04-emotion.ts +33 -0
  199. package/docs/examples/05-var-invariant.ts +31 -0
  200. package/docs/examples/06-payload.ts +85 -0
  201. package/docs/examples/fixture.ts +22 -0
  202. package/docs/getting-started/index.md +14 -0
  203. package/docs/getting-started/installation.md +30 -0
  204. package/docs/getting-started/quick-start.md +61 -0
  205. package/docs/getting-started/your-first-stylesheet.md +57 -0
  206. package/docs/guides/compact-artifacts.md +87 -0
  207. package/docs/guides/emotion-migration.md +60 -0
  208. package/docs/guides/index.md +17 -0
  209. package/docs/guides/name-collisions.md +37 -0
  210. package/docs/guides/non-css-surfaces.md +73 -0
  211. package/docs/guides/react-renderer.md +158 -0
  212. package/docs/guides/theming.md +107 -0
  213. package/docs/guides/var-invariant.md +24 -0
  214. package/docs/guides/vs-emotion.md +61 -0
  215. package/docs/index.md +73 -0
  216. package/docs/logo.svg +7 -0
  217. package/docs/playground/index.html +12 -0
  218. package/docs/playground/package.json +23 -0
  219. package/docs/playground/src/app/app.tsx +109 -0
  220. package/docs/playground/src/app/css_panel.tsx +119 -0
  221. package/docs/playground/src/app/editor_panel.tsx +87 -0
  222. package/docs/playground/src/app/index.ts +8 -0
  223. package/docs/playground/src/app/monaco_css_editor.tsx +84 -0
  224. package/docs/playground/src/app/monaco_source_editor.tsx +132 -0
  225. package/docs/playground/src/app/preview_panel.tsx +99 -0
  226. package/docs/playground/src/app/tokens_panel.tsx +117 -0
  227. package/docs/playground/src/app/types.ts +10 -0
  228. package/docs/playground/src/examples/snippets.test.ts +28 -0
  229. package/docs/playground/src/examples/snippets.ts +418 -0
  230. package/docs/playground/src/lib/compile.test.ts +157 -0
  231. package/docs/playground/src/lib/compile.ts +242 -0
  232. package/docs/playground/src/lib/demo_environment.test.ts +123 -0
  233. package/docs/playground/src/lib/demo_environment.ts +140 -0
  234. package/docs/playground/src/lib/editor_lib.test.ts +39 -0
  235. package/docs/playground/src/lib/editor_lib.ts +142 -0
  236. package/docs/playground/src/lib/format_css.test.ts +41 -0
  237. package/docs/playground/src/lib/format_css.ts +71 -0
  238. package/docs/playground/src/main.tsx +25 -0
  239. package/docs/playground/src/setup/chrome.test.ts +47 -0
  240. package/docs/playground/src/setup/chrome.ts +365 -0
  241. package/docs/playground/src/setup/monaco_env.ts +64 -0
  242. package/docs/playground/tsconfig.json +22 -0
  243. package/docs/playground/vite.config.ts +37 -0
  244. package/docs/playground/vitest.config.ts +35 -0
  245. package/docs/playground.md +28 -0
  246. package/docs/reference/api/emotion.md +372 -0
  247. package/docs/reference/api/index-1.md +2180 -0
  248. package/docs/reference/api/index.md +9 -0
  249. package/docs/reference/api/testing.md +92 -0
  250. package/docs/reference/api.md +12 -0
  251. package/docs/reference/entry-points.md +125 -0
  252. package/docs/reference/environment.md +60 -0
  253. package/docs/reference/index.md +11 -0
  254. package/docs/reference/okf-map.md +92 -0
  255. package/package.json +127 -4
  256. package/src/collector.ts +526 -0
  257. package/src/css_scan.ts +263 -0
  258. package/src/dom_sink.ts +65 -0
  259. package/src/emotion.ts +311 -0
  260. package/src/engine.ts +191 -0
  261. package/src/environment.ts +56 -0
  262. package/src/hash.ts +111 -0
  263. package/src/idents.ts +21 -0
  264. package/src/index.ts +93 -0
  265. package/src/instance.ts +49 -0
  266. package/src/local_vars.ts +220 -0
  267. package/src/minify.ts +87 -0
  268. package/src/names.ts +129 -0
  269. package/src/nesting.ts +596 -0
  270. package/src/runtime.ts +428 -0
  271. package/src/styles/authoring.ts +244 -0
  272. package/src/styles/declarations.ts +172 -0
  273. package/src/styles/index.ts +58 -0
  274. package/src/styles/module.ts +396 -0
  275. package/src/styles/registry.ts +261 -0
  276. package/src/styles/types.ts +283 -0
  277. package/src/testing.ts +48 -0
  278. package/src/theme.ts +454 -0
  279. package/src/tokens/contextual_var.ts +72 -0
  280. package/src/tokens/index.ts +17 -0
  281. package/src/tokens/kind.ts +13 -0
  282. package/src/tokens/light_dark.ts +58 -0
  283. package/src/tokens/scale_token.ts +41 -0
  284. package/src/tokens/theme_token.ts +42 -0
  285. package/src/var_invariant.ts +147 -0
package/dist/theme.js ADDED
@@ -0,0 +1,240 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { cssVarName } from './names.js';
8
+ import { isScaleToken, isSchemePair, lightDark, themeToken, } from './tokens/index.js';
9
+ /** Theme-tree keys omit `-` so hyphen-joined custom properties reverse uniquely. */
10
+ const THEME_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
11
+ /**
12
+ * Folds two per-scheme trees into one authoring tree. Equal string leaves stay bare; differing strings become {@link lightDark}. {@link ScaleToken} leaves must agree.
13
+ *
14
+ * @param light Light-scheme value tree.
15
+ * @param dark Dark-scheme value tree.
16
+ * @throws If shapes, leaf kinds, or scale values disagree, or if a differing string pair is not a CSS `<color>`.
17
+ */
18
+ export const zipSchemes = (light, dark) => zipNode(light, dark, '');
19
+ /** Walks `theme` into a {@link CssToken} / {@link ScaleToken} tree and a `themeVars` registry. */
20
+ export const deriveTheme = (prefix, theme) => {
21
+ const themeVars = dict();
22
+ const tokens = walk(theme, '', prefix, themeVars);
23
+ return { tokens, themeVars };
24
+ };
25
+ /**
26
+ * Nested literal values for one scheme. Walks `theme` so {@link ScaleToken} leaves resolve to `.value`.
27
+ *
28
+ * @param theme Authoring tree that produced `themeVars`.
29
+ * @param themeVars Base registry from {@link Distillery.themeVars}.
30
+ * @param scheme Which side of each {@link ThemeVarDefinition} to read.
31
+ * @param variation When set, overridden paths come from `variation.diffs`; everything else stays on `themeVars`.
32
+ */
33
+ export const resolveThemeValues = (theme, themeVars, scheme, variation) => {
34
+ const vars = variation
35
+ ? Object.assign(dict(), themeVars, variation.diffs)
36
+ : themeVars;
37
+ return walkValues(theme, '', vars, scheme);
38
+ };
39
+ /** Looks up a declared variation. @throws If `name` is not in `variations`. */
40
+ export const requireThemeVariation = (variations, name) => {
41
+ const resolved = variations && Object.hasOwn(variations, name)
42
+ ? variations[name]
43
+ : undefined;
44
+ if (!resolved) {
45
+ const declared = Object.keys(variations ?? {});
46
+ const suffix = declared.length > 0
47
+ ? ` Declared: ${declared.join(', ')}.`
48
+ : ' No variations were declared.';
49
+ throw new Error(`Unknown variation "${name}".${suffix}`);
50
+ }
51
+ return resolved;
52
+ };
53
+ /** Serialized `light` / `light-dark(light, dark)` form used in emission and diffs. */
54
+ export const serializedThemeValue = ({ light, dark, }) => light === dark ? light : `light-dark(${light},${dark})`;
55
+ /**
56
+ * Resolves named `variations` against `base`. Variations extend the base only (no chains).
57
+ *
58
+ * @throws If a variation introduces an unknown path, a leaf-kind mismatch, or a diverging {@link ScaleToken}.
59
+ */
60
+ export const resolveThemeVariations = (prefix, base, baseVars, variations) => {
61
+ if (!variations) {
62
+ return {};
63
+ }
64
+ const out = dict();
65
+ for (const [name, declaration] of Object.entries(variations)) {
66
+ const { media, variation } = unwrapThemeVariation(declaration, name);
67
+ const merged = applyVariation(base, variation, name, '');
68
+ const { themeVars } = deriveTheme(prefix, merged);
69
+ const diffs = dict();
70
+ for (const [path, definition] of Object.entries(themeVars)) {
71
+ const baseDefinition = baseVars[path];
72
+ if (!baseDefinition ||
73
+ serializedThemeValue(definition) !==
74
+ serializedThemeValue(baseDefinition)) {
75
+ diffs[path] = definition;
76
+ }
77
+ }
78
+ out[name] = Object.freeze({
79
+ name,
80
+ themeVars: Object.freeze(themeVars),
81
+ diffs: Object.freeze(diffs),
82
+ ...(media ? { media } : {}),
83
+ });
84
+ }
85
+ return Object.freeze(out);
86
+ };
87
+ const unwrapThemeVariation = (declaration, name) => {
88
+ if (!isMediaThemeVariation(declaration)) {
89
+ return { variation: declaration };
90
+ }
91
+ const extra = Object.keys(declaration).filter((key) => key !== 'media' && key !== 'variation');
92
+ if (extra.length > 0) {
93
+ throw new Error(`Variation "${name}" media declaration cannot include keys ${extra.map((key) => `"${key}"`).join(', ')}.`);
94
+ }
95
+ if (declaration.media.trim().length === 0) {
96
+ throw new Error(`Variation "${name}" has an empty media query.`);
97
+ }
98
+ return { media: declaration.media, variation: declaration.variation };
99
+ };
100
+ const isMediaThemeVariation = (value) => {
101
+ if (!isPlainObject(value)) {
102
+ return false;
103
+ }
104
+ const candidate = value;
105
+ return (typeof candidate.media === 'string' && isPlainObject(candidate.variation));
106
+ };
107
+ const applyVariation = (base, variation, variationName, path) => {
108
+ if (variation === undefined) {
109
+ return base;
110
+ }
111
+ if (isScaleToken(base) || isScaleToken(variation)) {
112
+ if (!isScaleToken(base) || !isScaleToken(variation)) {
113
+ throw new Error(`Variation "${variationName}": "${path}" is a ScaleToken in one tree and not the other.`);
114
+ }
115
+ if (base.value !== variation.value || base.cq !== variation.cq) {
116
+ throw new Error(`Variation "${variationName}": ScaleToken at "${path}" disagrees with the base (scale tokens inline and cannot vary by variation).`);
117
+ }
118
+ return base;
119
+ }
120
+ if (isSchemePair(variation) || typeof variation === 'string') {
121
+ if (typeof base !== 'string' && !isSchemePair(base)) {
122
+ throw new Error(`Variation "${variationName}": "${path}" is a leaf in the variation and a group in the base.`);
123
+ }
124
+ return variation;
125
+ }
126
+ if (isThemeGroup(variation) && isThemeGroup(base)) {
127
+ const out = Object.assign(dict(), base);
128
+ for (const [key, child] of Object.entries(variation)) {
129
+ if (!Object.hasOwn(base, key)) {
130
+ throw new Error(`Variation "${variationName}": unknown path "${childPath(path, key)}".`);
131
+ }
132
+ out[key] = applyVariation(base[key], child, variationName, childPath(path, key));
133
+ }
134
+ return out;
135
+ }
136
+ throw new Error(`Variation "${variationName}": "${path || '(root)'}" is not a valid partial.`);
137
+ };
138
+ const isThemeGroup = (value) => isPlainObject(value) && !isSchemePair(value) && !isScaleToken(value);
139
+ const walkValues = (node, path, themeVars, scheme) => {
140
+ if (isScaleToken(node)) {
141
+ assertNotRoot(path);
142
+ return node.value;
143
+ }
144
+ if (isSchemePair(node) || typeof node === 'string') {
145
+ assertNotRoot(path);
146
+ const definition = themeVars[path];
147
+ if (!definition) {
148
+ throw new Error(`No theme var for "${path}".`);
149
+ }
150
+ return definition[scheme];
151
+ }
152
+ if (isPlainObject(node)) {
153
+ const out = dict();
154
+ for (const [key, child] of Object.entries(node)) {
155
+ out[key] = walkValues(child, childPath(path, key), themeVars, scheme);
156
+ }
157
+ return Object.freeze(out);
158
+ }
159
+ const label = path === '' ? 'theme root' : `"${path}"`;
160
+ throw new Error(`Theme leaf at ${label} must be a string, lightDark(...), or ScaleToken.`);
161
+ };
162
+ const walk = (node, path, prefix, themeVars) => {
163
+ if (isScaleToken(node)) {
164
+ assertNotRoot(path);
165
+ return node;
166
+ }
167
+ if (isSchemePair(node)) {
168
+ assertNotRoot(path);
169
+ return registerCssToken(path, prefix, node.light, node.dark, themeVars);
170
+ }
171
+ if (typeof node === 'string') {
172
+ assertNotRoot(path);
173
+ return registerCssToken(path, prefix, node, node, themeVars);
174
+ }
175
+ if (isPlainObject(node)) {
176
+ const out = dict();
177
+ for (const [key, child] of Object.entries(node)) {
178
+ assertThemeKey(key);
179
+ const childPath = path === '' ? key : `${path}/${key}`;
180
+ out[key] = walk(child, childPath, prefix, themeVars);
181
+ }
182
+ return Object.freeze(out);
183
+ }
184
+ const label = path === '' ? 'theme root' : `"${path}"`;
185
+ throw new Error(`Theme leaf at ${label} must be a string, lightDark(...), or ScaleToken.`);
186
+ };
187
+ const registerCssToken = (path, prefix, light, dark, themeVars) => {
188
+ const cssVar = cssVarName(prefix, path);
189
+ themeVars[path] = { path, cssVar, light, dark };
190
+ return themeToken(path, cssVar);
191
+ };
192
+ const zipNode = (light, dark, path) => {
193
+ if (isScaleToken(light) || isScaleToken(dark)) {
194
+ if (!isScaleToken(light) || !isScaleToken(dark)) {
195
+ throw new Error(`zipSchemes: "${path}" is a ScaleToken in one scheme and not the other.`);
196
+ }
197
+ if (light.value !== dark.value || light.cq !== dark.cq) {
198
+ throw new Error(`zipSchemes: ScaleToken at "${path}" disagrees across schemes.`);
199
+ }
200
+ return light;
201
+ }
202
+ if (typeof light === 'string' || typeof dark === 'string') {
203
+ if (typeof light !== 'string' || typeof dark !== 'string') {
204
+ throw new Error(`zipSchemes: "${path}" is a string in one scheme and not the other.`);
205
+ }
206
+ return light === dark ? light : lightDark(light, dark);
207
+ }
208
+ if (isPlainObject(light) && isPlainObject(dark)) {
209
+ for (const key of Object.keys(light)) {
210
+ if (!Object.hasOwn(dark, key)) {
211
+ throw new Error(`zipSchemes: "${childPath(path, key)}" is missing in the dark tree.`);
212
+ }
213
+ }
214
+ for (const key of Object.keys(dark)) {
215
+ if (!Object.hasOwn(light, key)) {
216
+ throw new Error(`zipSchemes: "${childPath(path, key)}" is missing in the light tree.`);
217
+ }
218
+ }
219
+ const out = dict();
220
+ for (const key of Object.keys(light)) {
221
+ out[key] = zipNode(light[key], dark[key], childPath(path, key));
222
+ }
223
+ return out;
224
+ }
225
+ throw new Error(`zipSchemes: "${path || '(root)'}" must be a string, ScaleToken, or nested object.`);
226
+ };
227
+ const childPath = (path, key) => path === '' ? key : `${path}/${key}`;
228
+ const assertNotRoot = (path) => {
229
+ if (path === '') {
230
+ throw new Error('Theme root must be an object.');
231
+ }
232
+ };
233
+ const assertThemeKey = (key) => {
234
+ if (!THEME_KEY_RE.test(key)) {
235
+ throw new Error(`Theme key "${key}" must match /^[A-Za-z_][A-Za-z0-9_]*$/ (hyphens are rejected so path segments reverse uniquely).`);
236
+ }
237
+ };
238
+ const dict = () => Object.create(null);
239
+ const isPlainObject = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
240
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAEL,YAAY,EACZ,YAAY,EACZ,SAAS,EAGT,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,oFAAoF;AACpF,MAAM,YAAY,GAAG,0BAA0B,CAAC;AA2FhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAQ,EACR,IAAO,EACI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAc,CAAC;AAEtD,kGAAkG;AAClG,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAc,EACd,KAAQ,EACgE,EAAE;IAC1E,MAAM,SAAS,GAAG,IAAI,EAAsB,CAAC;IAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,CAAgB,CAAC;IACjE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GA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Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ThemeVarDefinition } from './environment';\nimport { cssVarName } from './names';\nimport {\n type CssToken,\n isScaleToken,\n isSchemePair,\n lightDark,\n type ScaleToken,\n type SchemePair,\n themeToken,\n} from './tokens';\n\n/** Theme-tree keys omit `-` so hyphen-joined custom properties reverse uniquely. */\nconst THEME_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** One authoring leaf: invariant string, {@link lightDark} pair, or {@link ScaleToken}. */\nexport type ThemeLeaf = string | SchemePair | ScaleToken;\n\n/** Nested authoring tree. Keys must match `/^[A-Za-z_][A-Za-z0-9_]*$/`. */\nexport type ThemeTree = {\n readonly [key: string]: ThemeLeaf | ThemeTree;\n};\n\n/** Per-scheme value tree accepted by {@link zipSchemes}. */\nexport type SchemeValueTree = {\n readonly [key: string]: string | ScaleToken | SchemeValueTree;\n};\n\n/** Token tree derived from an authoring {@link ThemeTree}. */\nexport type TokensOf<T> = T extends ScaleToken\n ? ScaleToken\n : T extends SchemePair | string\n ? CssToken\n : T extends object\n ? { readonly [K in keyof T]: TokensOf<T[K]> }\n : never;\n\n/** Literal-value tree for one scheme. {@link ScaleToken} leaves use `.value`. */\nexport type ValuesOf<T> = T extends ScaleToken\n ? string\n : T extends SchemePair | string\n ? string\n : T extends object\n ? { readonly [K in keyof T]: ValuesOf<T[K]> }\n : never;\n\n/** Slash-delimited theme-var paths (excludes {@link ScaleToken} leaves). */\nexport type PathsOf<T, Prefix extends string = ''> = T extends ScaleToken\n ? never\n : T extends SchemePair | string\n ? Prefix extends ''\n ? never\n : Prefix\n : T extends object\n ? {\n [K in keyof T & string]: PathsOf<\n T[K],\n Prefix extends '' ? K : `${Prefix}/${K}`\n >;\n }[keyof T & string]\n : never;\n\n/** {@link zipSchemes} output: equal strings collapse; differing strings become {@link SchemePair}. */\nexport type Zipped<T> = T extends ScaleToken\n ? ScaleToken\n : T extends string\n ? string | SchemePair\n : T extends object\n ? { readonly [K in keyof T]: Zipped<T[K]> }\n : never;\n\n/** Partial variation of a {@link ThemeTree}. Leaves may change kind between `string` and {@link SchemePair}. */\nexport type DeepPartialTheme<T> = T extends ScaleToken\n ? ScaleToken\n : T extends SchemePair | string\n ? string | SchemePair\n : T extends object\n ? { readonly [K in keyof T]?: DeepPartialTheme<T[K]> }\n : never;\n\n/** Media-conditioned variation. `media` is intrinsic; it is not a selector. */\nexport interface MediaThemeVariation<T extends ThemeTree = ThemeTree> {\n /** Media query wrapping this variation's emitted diffs. */\n readonly media: string;\n /** Partial variation of the base theme. */\n readonly variation: DeepPartialTheme<T>;\n}\n\n/** Named variation: a partial of the base, or a media-conditioned partial. */\nexport type ThemeVariation<T extends ThemeTree = ThemeTree> =\n DeepPartialTheme<T> | MediaThemeVariation<T>;\n\n/** One named variation resolved against the base at construction. */\nexport interface ResolvedThemeVariation {\n /** Name passed in `variations`. */\n readonly name: string;\n /** Intrinsic media query, when declared. */\n readonly media?: string;\n /** Base theme vars with this variation applied. */\n readonly themeVars: Readonly<Record<string, ThemeVarDefinition>>;\n /** Paths whose serialized value differs from the base. */\n readonly diffs: Readonly<Record<string, ThemeVarDefinition>>;\n}\n\n/**\n * Folds two per-scheme trees into one authoring tree. Equal string leaves stay bare; differing strings become {@link lightDark}. {@link ScaleToken} leaves must agree.\n *\n * @param light Light-scheme value tree.\n * @param dark Dark-scheme value tree.\n * @throws If shapes, leaf kinds, or scale values disagree, or if a differing string pair is not a CSS `<color>`.\n */\nexport const zipSchemes = <T extends SchemeValueTree>(\n light: T,\n dark: T\n): Zipped<T> => zipNode(light, dark, '') as Zipped<T>;\n\n/** Walks `theme` into a {@link CssToken} / {@link ScaleToken} tree and a `themeVars` registry. */\nexport const deriveTheme = <T extends ThemeTree>(\n prefix: string,\n theme: T\n): { tokens: TokensOf<T>; themeVars: Record<string, ThemeVarDefinition> } => {\n const themeVars = dict<ThemeVarDefinition>();\n const tokens = walk(theme, '', prefix, themeVars) as TokensOf<T>;\n return { tokens, themeVars };\n};\n\n/**\n * Nested literal values for one scheme. Walks `theme` so {@link ScaleToken} leaves resolve to `.value`.\n *\n * @param theme Authoring tree that produced `themeVars`.\n * @param themeVars Base registry from {@link Distillery.themeVars}.\n * @param scheme Which side of each {@link ThemeVarDefinition} to read.\n * @param variation When set, overridden paths come from `variation.diffs`; everything else stays on `themeVars`.\n */\nexport const resolveThemeValues = <T extends ThemeTree>(\n theme: T,\n themeVars: Readonly<Record<string, ThemeVarDefinition>>,\n scheme: 'light' | 'dark',\n variation?: ResolvedThemeVariation\n): ValuesOf<T> => {\n const vars = variation\n ? Object.assign(dict<ThemeVarDefinition>(), themeVars, variation.diffs)\n : themeVars;\n return walkValues(theme, '', vars, scheme) as ValuesOf<T>;\n};\n\n/** Looks up a declared variation. @throws If `name` is not in `variations`. */\nexport const requireThemeVariation = (\n variations: Readonly<Record<string, ResolvedThemeVariation>> | undefined,\n name: string\n): ResolvedThemeVariation => {\n const resolved =\n variations && Object.hasOwn(variations, name)\n ? variations[name]\n : undefined;\n if (!resolved) {\n const declared = Object.keys(variations ?? {});\n const suffix =\n declared.length > 0\n ? ` Declared: ${declared.join(', ')}.`\n : ' No variations were declared.';\n throw new Error(`Unknown variation \"${name}\".${suffix}`);\n }\n return resolved;\n};\n\n/** Serialized `light` / `light-dark(light, dark)` form used in emission and diffs. */\nexport const serializedThemeValue = ({\n light,\n dark,\n}: ThemeVarDefinition): string =>\n light === dark ? light : `light-dark(${light},${dark})`;\n\n/**\n * Resolves named `variations` against `base`. Variations extend the base only (no chains).\n *\n * @throws If a variation introduces an unknown path, a leaf-kind mismatch, or a diverging {@link ScaleToken}.\n */\nexport const resolveThemeVariations = (\n prefix: string,\n base: ThemeTree,\n baseVars: Readonly<Record<string, ThemeVarDefinition>>,\n variations: Readonly<Record<string, ThemeVariation>> | undefined\n): Readonly<Record<string, ResolvedThemeVariation>> => {\n if (!variations) {\n return {};\n }\n const out = dict<ResolvedThemeVariation>();\n for (const [name, declaration] of Object.entries(variations)) {\n const { media, variation } = unwrapThemeVariation(declaration, name);\n const merged = applyVariation(base, variation, name, '') as ThemeTree;\n const { themeVars } = deriveTheme(prefix, merged);\n const diffs = dict<ThemeVarDefinition>();\n for (const [path, definition] of Object.entries(themeVars)) {\n const baseDefinition = baseVars[path];\n if (\n !baseDefinition ||\n serializedThemeValue(definition) !==\n serializedThemeValue(baseDefinition)\n ) {\n diffs[path] = definition;\n }\n }\n out[name] = Object.freeze({\n name,\n themeVars: Object.freeze(themeVars),\n diffs: Object.freeze(diffs),\n ...(media ? { media } : {}),\n });\n }\n return Object.freeze(out);\n};\n\nconst unwrapThemeVariation = (\n declaration: ThemeVariation,\n name: string\n): { media?: string; variation: DeepPartialTheme<ThemeTree> } => {\n if (!isMediaThemeVariation(declaration)) {\n return { variation: declaration };\n }\n const extra = Object.keys(declaration).filter(\n (key) => key !== 'media' && key !== 'variation'\n );\n if (extra.length > 0) {\n throw new Error(\n `Variation \"${name}\" media declaration cannot include keys ${extra.map((key) => `\"${key}\"`).join(', ')}.`\n );\n }\n if (declaration.media.trim().length === 0) {\n throw new Error(`Variation \"${name}\" has an empty media query.`);\n }\n return { media: declaration.media, variation: declaration.variation };\n};\n\nconst isMediaThemeVariation = (\n value: ThemeVariation\n): value is MediaThemeVariation => {\n if (!isPlainObject(value)) {\n return false;\n }\n const candidate = value;\n return (\n typeof candidate.media === 'string' && isPlainObject(candidate.variation)\n );\n};\n\nconst applyVariation = (\n base: unknown,\n variation: unknown,\n variationName: string,\n path: string\n): unknown => {\n if (variation === undefined) {\n return base;\n }\n if (isScaleToken(base) || isScaleToken(variation)) {\n if (!isScaleToken(base) || !isScaleToken(variation)) {\n throw new Error(\n `Variation \"${variationName}\": \"${path}\" is a ScaleToken in one tree and not the other.`\n );\n }\n if (base.value !== variation.value || base.cq !== variation.cq) {\n throw new Error(\n `Variation \"${variationName}\": ScaleToken at \"${path}\" disagrees with the base (scale tokens inline and cannot vary by variation).`\n );\n }\n return base;\n }\n if (isSchemePair(variation) || typeof variation === 'string') {\n if (typeof base !== 'string' && !isSchemePair(base)) {\n throw new Error(\n `Variation \"${variationName}\": \"${path}\" is a leaf in the variation and a group in the base.`\n );\n }\n return variation;\n }\n if (isThemeGroup(variation) && isThemeGroup(base)) {\n const out = Object.assign(dict<unknown>(), base);\n for (const [key, child] of Object.entries(variation)) {\n if (!Object.hasOwn(base, key)) {\n throw new Error(\n `Variation \"${variationName}\": unknown path \"${childPath(path, key)}\".`\n );\n }\n out[key] = applyVariation(\n base[key],\n child,\n variationName,\n childPath(path, key)\n );\n }\n return out;\n }\n throw new Error(\n `Variation \"${variationName}\": \"${path || '(root)'}\" is not a valid partial.`\n );\n};\n\nconst isThemeGroup = (value: unknown): value is Record<string, unknown> =>\n isPlainObject(value) && !isSchemePair(value) && !isScaleToken(value);\n\nconst walkValues = (\n node: unknown,\n path: string,\n themeVars: Readonly<Record<string, ThemeVarDefinition>>,\n scheme: 'light' | 'dark'\n): unknown => {\n if (isScaleToken(node)) {\n assertNotRoot(path);\n return node.value;\n }\n if (isSchemePair(node) || typeof node === 'string') {\n assertNotRoot(path);\n const definition = themeVars[path];\n if (!definition) {\n throw new Error(`No theme var for \"${path}\".`);\n }\n return definition[scheme];\n }\n if (isPlainObject(node)) {\n const out = dict<unknown>();\n for (const [key, child] of Object.entries(node)) {\n out[key] = walkValues(child, childPath(path, key), themeVars, scheme);\n }\n return Object.freeze(out);\n }\n const label = path === '' ? 'theme root' : `\"${path}\"`;\n throw new Error(\n `Theme leaf at ${label} must be a string, lightDark(...), or ScaleToken.`\n );\n};\n\nconst walk = (\n node: unknown,\n path: string,\n prefix: string,\n themeVars: Record<string, ThemeVarDefinition>\n): unknown => {\n if (isScaleToken(node)) {\n assertNotRoot(path);\n return node;\n }\n if (isSchemePair(node)) {\n assertNotRoot(path);\n return registerCssToken(path, prefix, node.light, node.dark, themeVars);\n }\n if (typeof node === 'string') {\n assertNotRoot(path);\n return registerCssToken(path, prefix, node, node, themeVars);\n }\n if (isPlainObject(node)) {\n const out = dict<unknown>();\n for (const [key, child] of Object.entries(node)) {\n assertThemeKey(key);\n const childPath = path === '' ? key : `${path}/${key}`;\n out[key] = walk(child, childPath, prefix, themeVars);\n }\n return Object.freeze(out);\n }\n const label = path === '' ? 'theme root' : `\"${path}\"`;\n throw new Error(\n `Theme leaf at ${label} must be a string, lightDark(...), or ScaleToken.`\n );\n};\n\nconst registerCssToken = (\n path: string,\n prefix: string,\n light: string,\n dark: string,\n themeVars: Record<string, ThemeVarDefinition>\n): CssToken => {\n const cssVar = cssVarName(prefix, path);\n themeVars[path] = { path, cssVar, light, dark };\n return themeToken(path, cssVar);\n};\n\nconst zipNode = (light: unknown, dark: unknown, path: string): unknown => {\n if (isScaleToken(light) || isScaleToken(dark)) {\n if (!isScaleToken(light) || !isScaleToken(dark)) {\n throw new Error(\n `zipSchemes: \"${path}\" is a ScaleToken in one scheme and not the other.`\n );\n }\n if (light.value !== dark.value || light.cq !== dark.cq) {\n throw new Error(\n `zipSchemes: ScaleToken at \"${path}\" disagrees across schemes.`\n );\n }\n return light;\n }\n if (typeof light === 'string' || typeof dark === 'string') {\n if (typeof light !== 'string' || typeof dark !== 'string') {\n throw new Error(\n `zipSchemes: \"${path}\" is a string in one scheme and not the other.`\n );\n }\n return light === dark ? light : lightDark(light, dark);\n }\n if (isPlainObject(light) && isPlainObject(dark)) {\n for (const key of Object.keys(light)) {\n if (!Object.hasOwn(dark, key)) {\n throw new Error(\n `zipSchemes: \"${childPath(path, key)}\" is missing in the dark tree.`\n );\n }\n }\n for (const key of Object.keys(dark)) {\n if (!Object.hasOwn(light, key)) {\n throw new Error(\n `zipSchemes: \"${childPath(path, key)}\" is missing in the light tree.`\n );\n }\n }\n const out = dict<unknown>();\n for (const key of Object.keys(light)) {\n out[key] = zipNode(light[key], dark[key], childPath(path, key));\n }\n return out;\n }\n throw new Error(\n `zipSchemes: \"${path || '(root)'}\" must be a string, ScaleToken, or nested object.`\n );\n};\n\nconst childPath = (path: string, key: string): string =>\n path === '' ? key : `${path}/${key}`;\n\nconst assertNotRoot = (path: string): void => {\n if (path === '') {\n throw new Error('Theme root must be an object.');\n }\n};\n\nconst assertThemeKey = (key: string): void => {\n if (!THEME_KEY_RE.test(key)) {\n throw new Error(\n `Theme key \"${key}\" must match /^[A-Za-z_][A-Za-z0-9_]*$/ (hyphens are rejected so path segments reverse uniquely).`\n );\n }\n};\n\nconst dict = <T>(): Record<string, T> =>\n Object.create(null) as Record<string, T>;\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n"]}
@@ -0,0 +1,35 @@
1
+ /** Represents a contextual CSS variable name. Stringifies to its custom property name. */
2
+ export interface ContextualCssVarName {
3
+ /** Brand for {@link isContextualCssVarName}. */
4
+ readonly __kind: 'contextual-var-name';
5
+ /** Group/key path for this variable. */
6
+ readonly path: `vars/${string}`;
7
+ /** Actual emitted CSS custom property name. */
8
+ readonly name: `--${string}`;
9
+ /** Stringifies to {@link ContextualCssVarName.name}. */
10
+ toString(): string;
11
+ /** Template interpolation; same as {@link ContextualCssVarName.toString}. */
12
+ [Symbol.toPrimitive](hint: string): string;
13
+ }
14
+ /** Represents a contextual CSS variable. Stringifies to `var(--...)`. */
15
+ export interface ContextualCssVar {
16
+ /** Brand for {@link isContextualCssVar}. */
17
+ readonly __kind: 'contextual-var';
18
+ /** Group/key path for this variable. */
19
+ readonly path: `vars/${string}`;
20
+ /** Wrapper yielding just the custom property name. */
21
+ readonly name: ContextualCssVarName;
22
+ /** Usable CSS `var(...)` reference string. */
23
+ readonly ref: `var(--${string})`;
24
+ /** Stringifies to {@link ContextualCssVar.ref}. */
25
+ toString(): string;
26
+ /** Template interpolation; same as {@link ContextualCssVar.toString}. */
27
+ [Symbol.toPrimitive](hint: string): string;
28
+ }
29
+ /** Shared contextual var. Stringifies to `var(<prop>)`; `.name` is the ident. */
30
+ export declare const contextualVar: (path: `vars/${string}`, prop: `--${string}`) => ContextualCssVar;
31
+ /** `true` when `value` is a {@link ContextualCssVar}. @param value Value to test. */
32
+ export declare const isContextualCssVar: (value: unknown) => value is ContextualCssVar;
33
+ /** `true` when `value` is a {@link ContextualCssVarName}. @param value Value to test. */
34
+ export declare const isContextualCssVarName: (value: unknown) => value is ContextualCssVarName;
35
+ //# sourceMappingURL=contextual_var.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextual_var.d.ts","sourceRoot":"","sources":["../../src/tokens/contextual_var.ts"],"names":[],"mappings":"AASA,0FAA0F;AAC1F,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,QAAQ,MAAM,EAAE,CAAC;IAChC,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,IAAI,MAAM,CAAC;IACnB,6EAA6E;IAC7E,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5C;AAED,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,QAAQ,MAAM,EAAE,CAAC;IAChC,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,GAAG,CAAC;IACjC,mDAAmD;IACnD,QAAQ,IAAI,MAAM,CAAC;IACnB,yEAAyE;IACzE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5C;AAED,iFAAiF;AACjF,eAAO,MAAM,aAAa,GACxB,MAAM,QAAQ,MAAM,EAAE,EACtB,MAAM,KAAK,MAAM,EAAE,KAClB,gBAmBF,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,gBAC3B,CAAC;AAEnC,yFAAyF;AACzF,eAAO,MAAM,sBAAsB,GACjC,OAAO,OAAO,KACb,KAAK,IAAI,oBAA6D,CAAC"}
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { hasKind } from './kind.js';
8
+ /** Shared contextual var. Stringifies to `var(<prop>)`; `.name` is the ident. */
9
+ export const contextualVar = (path, prop) => {
10
+ const ref = `var(${prop})`;
11
+ const propToString = () => prop;
12
+ const refToString = () => ref;
13
+ const name = {
14
+ __kind: 'contextual-var-name',
15
+ path,
16
+ name: prop,
17
+ toString: propToString,
18
+ [Symbol.toPrimitive]: propToString,
19
+ };
20
+ return {
21
+ __kind: 'contextual-var',
22
+ path,
23
+ name,
24
+ ref,
25
+ toString: refToString,
26
+ [Symbol.toPrimitive]: refToString,
27
+ };
28
+ };
29
+ /** `true` when `value` is a {@link ContextualCssVar}. @param value Value to test. */
30
+ export const isContextualCssVar = (value) => hasKind(value, 'contextual-var');
31
+ /** `true` when `value` is a {@link ContextualCssVarName}. @param value Value to test. */
32
+ export const isContextualCssVarName = (value) => hasKind(value, 'contextual-var-name');
33
+ //# sourceMappingURL=contextual_var.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextual_var.js","sourceRoot":"","sources":["../../src/tokens/contextual_var.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAgCjC,iFAAiF;AACjF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,IAAsB,EACtB,IAAmB,EACD,EAAE;IACpB,MAAM,GAAG,GAAuB,OAAO,IAAI,GAAG,CAAC;IAC/C,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC;IACxC,MAAM,WAAW,GAAG,GAAW,EAAE,CAAC,GAAG,CAAC;IACtC,MAAM,IAAI,GAAyB;QACjC,MAAM,EAAE,qBAAqB;QAC7B,IAAI;QACJ,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,YAAY;QACtB,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,YAAY;KACnC,CAAC;IACF,OAAO;QACL,MAAM,EAAE,gBAAgB;QACxB,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,QAAQ,EAAE,WAAW;QACrB,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,WAAW;KAClC,CAAC;AACJ,CAAC,CAAC;AAEF,qFAAqF;AACrF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAA6B,EAAE,CAC9E,OAAO,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;AAEnC,yFAAyF;AACzF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,KAAc,EACiB,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { hasKind } from './kind';\n\n/** Represents a contextual CSS variable name. Stringifies to its custom property name. */\nexport interface ContextualCssVarName {\n /** Brand for {@link isContextualCssVarName}. */\n readonly __kind: 'contextual-var-name';\n /** Group/key path for this variable. */\n readonly path: `vars/${string}`;\n /** Actual emitted CSS custom property name. */\n readonly name: `--${string}`;\n /** Stringifies to {@link ContextualCssVarName.name}. */\n toString(): string;\n /** Template interpolation; same as {@link ContextualCssVarName.toString}. */\n [Symbol.toPrimitive](hint: string): string;\n}\n\n/** Represents a contextual CSS variable. Stringifies to `var(--...)`. */\nexport interface ContextualCssVar {\n /** Brand for {@link isContextualCssVar}. */\n readonly __kind: 'contextual-var';\n /** Group/key path for this variable. */\n readonly path: `vars/${string}`;\n /** Wrapper yielding just the custom property name. */\n readonly name: ContextualCssVarName;\n /** Usable CSS `var(...)` reference string. */\n readonly ref: `var(--${string})`;\n /** Stringifies to {@link ContextualCssVar.ref}. */\n toString(): string;\n /** Template interpolation; same as {@link ContextualCssVar.toString}. */\n [Symbol.toPrimitive](hint: string): string;\n}\n\n/** Shared contextual var. Stringifies to `var(<prop>)`; `.name` is the ident. */\nexport const contextualVar = (\n path: `vars/${string}`,\n prop: `--${string}`\n): ContextualCssVar => {\n const ref: `var(--${string})` = `var(${prop})`;\n const propToString = (): string => prop;\n const refToString = (): string => ref;\n const name: ContextualCssVarName = {\n __kind: 'contextual-var-name',\n path,\n name: prop,\n toString: propToString,\n [Symbol.toPrimitive]: propToString,\n };\n return {\n __kind: 'contextual-var',\n path,\n name,\n ref,\n toString: refToString,\n [Symbol.toPrimitive]: refToString,\n };\n};\n\n/** `true` when `value` is a {@link ContextualCssVar}. @param value Value to test. */\nexport const isContextualCssVar = (value: unknown): value is ContextualCssVar =>\n hasKind(value, 'contextual-var');\n\n/** `true` when `value` is a {@link ContextualCssVarName}. @param value Value to test. */\nexport const isContextualCssVarName = (\n value: unknown\n): value is ContextualCssVarName => hasKind(value, 'contextual-var-name');\n"]}
@@ -0,0 +1,5 @@
1
+ export { type ContextualCssVar, type ContextualCssVarName, contextualVar, isContextualCssVar, isContextualCssVarName, } from './contextual_var.js';
2
+ export { type SchemePair, isSchemePair, lightDark } from './light_dark.js';
3
+ export { type ScaleToken, cq, isScaleToken, scaleToken } from './scale_token.js';
4
+ export { type CssToken, isCssToken, themeToken } from './theme_token.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,KAAK,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,KAAK,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ export { contextualVar, isContextualCssVar, isContextualCssVarName, } from './contextual_var.js';
8
+ export { isSchemePair, lightDark } from './light_dark.js';
9
+ export { cq, isScaleToken, scaleToken } from './scale_token.js';
10
+ export { isCssToken, themeToken } from './theme_token.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAGL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAmB,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAmB,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAiB,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport {\n type ContextualCssVar,\n type ContextualCssVarName,\n contextualVar,\n isContextualCssVar,\n isContextualCssVarName,\n} from './contextual_var';\nexport { type SchemePair, isSchemePair, lightDark } from './light_dark';\nexport { type ScaleToken, cq, isScaleToken, scaleToken } from './scale_token';\nexport { type CssToken, isCssToken, themeToken } from './theme_token';\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const hasKind: (value: unknown, kind: string) => boolean;
2
+ //# sourceMappingURL=kind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kind.d.ts","sourceRoot":"","sources":["../../src/tokens/kind.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,EAAE,MAAM,MAAM,KAAG,OAKpD,CAAC"}
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ export const hasKind = (value, kind) => Boolean(value &&
8
+ typeof value === 'object' &&
9
+ value.__kind === kind);
10
+ //# sourceMappingURL=kind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kind.js","sourceRoot":"","sources":["../../src/tokens/kind.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,IAAY,EAAW,EAAE,CAC/D,OAAO,CACL,KAAK;IACL,OAAO,KAAK,KAAK,QAAQ;IACxB,KAA6B,CAAC,MAAM,KAAK,IAAI,CAC/C,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nexport const hasKind = (value: unknown, kind: string): boolean =>\n Boolean(\n value &&\n typeof value === 'object' &&\n (value as { __kind?: string }).__kind === kind\n );\n"]}
@@ -0,0 +1,20 @@
1
+ /** Scheme-varying color pair. Compiles to `light-dark(light, dark)`. */
2
+ export interface SchemePair {
3
+ /** Brand for {@link isSchemePair}. */
4
+ readonly __kind: 'scheme-pair';
5
+ /** Light color-scheme value. Must be a CSS `<color>`. */
6
+ readonly light: string;
7
+ /** Dark color-scheme value. Must be a CSS `<color>`. */
8
+ readonly dark: string;
9
+ }
10
+ /** `true` when `value` is a {@link SchemePair}. @param value Value to test. */
11
+ export declare const isSchemePair: (value: unknown) => value is SchemePair;
12
+ /**
13
+ * Scheme-varying color pair. Both sides must be CSS `<color>` values.
14
+ *
15
+ * @param light Light color-scheme value.
16
+ * @param dark Dark color-scheme value.
17
+ * @throws If either value is not a CSS `<color>`.
18
+ */
19
+ export declare const lightDark: (light: string, dark: string) => SchemePair;
20
+ //# sourceMappingURL=light_dark.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light_dark.d.ts","sourceRoot":"","sources":["../../src/tokens/light_dark.ts"],"names":[],"mappings":"AASA,wEAAwE;AACxE,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,+EAA+E;AAC/E,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UACxB,CAAC;AAEhC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,KAAG,UAIvD,CAAC"}
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { hasKind } from './kind.js';
8
+ /** `true` when `value` is a {@link SchemePair}. @param value Value to test. */
9
+ export const isSchemePair = (value) => hasKind(value, 'scheme-pair');
10
+ /**
11
+ * Scheme-varying color pair. Both sides must be CSS `<color>` values.
12
+ *
13
+ * @param light Light color-scheme value.
14
+ * @param dark Dark color-scheme value.
15
+ * @throws If either value is not a CSS `<color>`.
16
+ */
17
+ export const lightDark = (light, dark) => {
18
+ assertCssColor(light, 'light');
19
+ assertCssColor(dark, 'dark');
20
+ return { __kind: 'scheme-pair', light, dark };
21
+ };
22
+ const isCssColor = (value) => {
23
+ const trimmed = value.trim();
24
+ if (/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(trimmed)) {
25
+ return true;
26
+ }
27
+ if (/^(?:transparent|currentcolor)$/i.test(trimmed)) {
28
+ return true;
29
+ }
30
+ return (/^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color-mix|color)\(/i.test(trimmed) && trimmed.endsWith(')'));
31
+ };
32
+ const assertCssColor = (value, side) => {
33
+ if (!isCssColor(value)) {
34
+ throw new Error(`lightDark() ${side} value "${value}" is not a CSS <color>; light-dark() would be dropped by the browser.`);
35
+ }
36
+ };
37
+ //# sourceMappingURL=light_dark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light_dark.js","sourceRoot":"","sources":["../../src/tokens/light_dark.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAYjC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuB,EAAE,CAClE,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,IAAY,EAAc,EAAE;IACnE,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/B,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,KAAa,EAAW,EAAE;IAC5C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,qDAAqD,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CACL,6DAA6D,CAAC,IAAI,CAChE,OAAO,CACR,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAC3B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,IAAsB,EAAQ,EAAE;IACrE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,eAAe,IAAI,WAAW,KAAK,uEAAuE,CAC3G,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { hasKind } from './kind';\n\n/** Scheme-varying color pair. Compiles to `light-dark(light, dark)`. */\nexport interface SchemePair {\n /** Brand for {@link isSchemePair}. */\n readonly __kind: 'scheme-pair';\n /** Light color-scheme value. Must be a CSS `<color>`. */\n readonly light: string;\n /** Dark color-scheme value. Must be a CSS `<color>`. */\n readonly dark: string;\n}\n\n/** `true` when `value` is a {@link SchemePair}. @param value Value to test. */\nexport const isSchemePair = (value: unknown): value is SchemePair =>\n hasKind(value, 'scheme-pair');\n\n/**\n * Scheme-varying color pair. Both sides must be CSS `<color>` values.\n *\n * @param light Light color-scheme value.\n * @param dark Dark color-scheme value.\n * @throws If either value is not a CSS `<color>`.\n */\nexport const lightDark = (light: string, dark: string): SchemePair => {\n assertCssColor(light, 'light');\n assertCssColor(dark, 'dark');\n return { __kind: 'scheme-pair', light, dark };\n};\n\nconst isCssColor = (value: string): boolean => {\n const trimmed = value.trim();\n if (/^#(?:[\\da-f]{3}|[\\da-f]{4}|[\\da-f]{6}|[\\da-f]{8})$/i.test(trimmed)) {\n return true;\n }\n if (/^(?:transparent|currentcolor)$/i.test(trimmed)) {\n return true;\n }\n return (\n /^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color-mix|color)\\(/i.test(\n trimmed\n ) && trimmed.endsWith(')')\n );\n};\n\nconst assertCssColor = (value: string, side: 'light' | 'dark'): void => {\n if (!isCssColor(value)) {\n throw new Error(\n `lightDark() ${side} value \"${value}\" is not a CSS <color>; light-dark() would be dropped by the browser.`\n );\n }\n};\n"]}
@@ -0,0 +1,20 @@
1
+ /** Represents a CSS scale size token. Stringifies to its literal value. */
2
+ export interface ScaleToken {
3
+ /** Brand for {@link isScaleToken}. */
4
+ readonly __kind: 'scale-token';
5
+ /** Literal CSS value, inlined into declarations. */
6
+ readonly value: string;
7
+ /** Container-query-relative variant of `value`. */
8
+ readonly cq: string;
9
+ /** Stringifies to {@link ScaleToken.value}. */
10
+ toString(): string;
11
+ /** Template interpolation; same as {@link ScaleToken.toString}. */
12
+ [Symbol.toPrimitive](hint: string): string;
13
+ }
14
+ /** Literal size token. Stringifies to `value`; `cq` is the container-relative variant. */
15
+ export declare const scaleToken: (value: string, cq: string) => ScaleToken;
16
+ /** Alias of {@link scaleToken} for theme-tree authoring. */
17
+ export declare const cq: (value: string, cq: string) => ScaleToken;
18
+ /** `true` when `value` is a {@link ScaleToken}. @param value Value to test. */
19
+ export declare const isScaleToken: (value: unknown) => value is ScaleToken;
20
+ //# sourceMappingURL=scale_token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale_token.d.ts","sourceRoot":"","sources":["../../src/tokens/scale_token.ts"],"names":[],"mappings":"AASA,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,QAAQ,IAAI,MAAM,CAAC;IACnB,mEAAmE;IACnE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5C;AAED,0FAA0F;AAC1F,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,EAAE,IAAI,MAAM,KAAG,UAStD,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,EAAE,UAZmB,MAAM,MAAM,MAAM,KAAG,UAY3B,CAAC;AAE7B,+EAA+E;AAC/E,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UACxB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { hasKind } from './kind.js';
8
+ /** Literal size token. Stringifies to `value`; `cq` is the container-relative variant. */
9
+ export const scaleToken = (value, cq) => {
10
+ const valueToString = () => value;
11
+ return {
12
+ __kind: 'scale-token',
13
+ value,
14
+ cq,
15
+ toString: valueToString,
16
+ [Symbol.toPrimitive]: valueToString,
17
+ };
18
+ };
19
+ /** Alias of {@link scaleToken} for theme-tree authoring. */
20
+ export const cq = scaleToken;
21
+ /** `true` when `value` is a {@link ScaleToken}. @param value Value to test. */
22
+ export const isScaleToken = (value) => hasKind(value, 'scale-token');
23
+ //# sourceMappingURL=scale_token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale_token.js","sourceRoot":"","sources":["../../src/tokens/scale_token.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAgBjC,0FAA0F;AAC1F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAU,EAAc,EAAE;IAClE,MAAM,aAAa,GAAG,GAAW,EAAE,CAAC,KAAK,CAAC;IAC1C,OAAO;QACL,MAAM,EAAE,aAAa;QACrB,KAAK;QACL,EAAE;QACF,QAAQ,EAAE,aAAa;QACvB,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,aAAa;KACpC,CAAC;AACJ,CAAC,CAAC;AAEF,4DAA4D;AAC5D,MAAM,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;AAE7B,+EAA+E;AAC/E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuB,EAAE,CAClE,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { hasKind } from './kind';\n\n/** Represents a CSS scale size token. Stringifies to its literal value. */\nexport interface ScaleToken {\n /** Brand for {@link isScaleToken}. */\n readonly __kind: 'scale-token';\n /** Literal CSS value, inlined into declarations. */\n readonly value: string;\n /** Container-query-relative variant of `value`. */\n readonly cq: string;\n /** Stringifies to {@link ScaleToken.value}. */\n toString(): string;\n /** Template interpolation; same as {@link ScaleToken.toString}. */\n [Symbol.toPrimitive](hint: string): string;\n}\n\n/** Literal size token. Stringifies to `value`; `cq` is the container-relative variant. */\nexport const scaleToken = (value: string, cq: string): ScaleToken => {\n const valueToString = (): string => value;\n return {\n __kind: 'scale-token',\n value,\n cq,\n toString: valueToString,\n [Symbol.toPrimitive]: valueToString,\n };\n};\n\n/** Alias of {@link scaleToken} for theme-tree authoring. */\nexport const cq = scaleToken;\n\n/** `true` when `value` is a {@link ScaleToken}. @param value Value to test. */\nexport const isScaleToken = (value: unknown): value is ScaleToken =>\n hasKind(value, 'scale-token');\n"]}
@@ -0,0 +1,20 @@
1
+ /** Represents a CSS theme token. Stringifies to `var(--...)`. */
2
+ export interface CssToken {
3
+ /** Brand for {@link isCssToken}. */
4
+ readonly __kind: 'theme-token';
5
+ /** Path string mapping to this token in the environment. */
6
+ readonly path: string;
7
+ /** Actual emitted CSS custom property name. */
8
+ readonly cssVar: `--${string}`;
9
+ /** Usable CSS `var(...)` reference string. */
10
+ readonly ref: `var(--${string})`;
11
+ /** Stringifies to {@link CssToken.ref}. */
12
+ toString(): string;
13
+ /** Template interpolation; same as {@link CssToken.toString}. */
14
+ [Symbol.toPrimitive](hint: string): string;
15
+ }
16
+ /** Theme token that stringifies to `var(<cssVar>)`. */
17
+ export declare const themeToken: (path: string, cssVar: `--${string}`) => CssToken;
18
+ /** `true` when `value` is a {@link CssToken}. @param value Value to test. */
19
+ export declare const isCssToken: (value: unknown) => value is CssToken;
20
+ //# sourceMappingURL=theme_token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme_token.d.ts","sourceRoot":"","sources":["../../src/tokens/theme_token.ts"],"names":[],"mappings":"AASA,iEAAiE;AACjE,MAAM,WAAW,QAAQ;IACvB,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;IAC/B,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,GAAG,CAAC;IACjC,2CAA2C;IAC3C,QAAQ,IAAI,MAAM,CAAC;IACnB,iEAAiE;IACjE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5C;AAED,uDAAuD;AACvD,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,QAAQ,KAAK,MAAM,EAAE,KAAG,QAWhE,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QACtB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { hasKind } from './kind.js';
8
+ /** Theme token that stringifies to `var(<cssVar>)`. */
9
+ export const themeToken = (path, cssVar) => {
10
+ const ref = `var(${cssVar})`;
11
+ const refToString = () => ref;
12
+ return {
13
+ __kind: 'theme-token',
14
+ path,
15
+ cssVar,
16
+ ref,
17
+ toString: refToString,
18
+ [Symbol.toPrimitive]: refToString,
19
+ };
20
+ };
21
+ /** `true` when `value` is a {@link CssToken}. @param value Value to test. */
22
+ export const isCssToken = (value) => hasKind(value, 'theme-token');
23
+ //# sourceMappingURL=theme_token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme_token.js","sourceRoot":"","sources":["../../src/tokens/theme_token.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAkBjC,uDAAuD;AACvD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,MAAqB,EAAY,EAAE;IAC1E,MAAM,GAAG,GAAuB,OAAO,MAAM,GAAG,CAAC;IACjD,MAAM,WAAW,GAAG,GAAW,EAAE,CAAC,GAAG,CAAC;IACtC,OAAO;QACL,MAAM,EAAE,aAAa;QACrB,IAAI;QACJ,MAAM;QACN,GAAG;QACH,QAAQ,EAAE,WAAW;QACrB,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,WAAW;KAClC,CAAC;AACJ,CAAC,CAAC;AAEF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAqB,EAAE,CAC9D,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { hasKind } from './kind';\n\n/** Represents a CSS theme token. Stringifies to `var(--...)`. */\nexport interface CssToken {\n /** Brand for {@link isCssToken}. */\n readonly __kind: 'theme-token';\n /** Path string mapping to this token in the environment. */\n readonly path: string;\n /** Actual emitted CSS custom property name. */\n readonly cssVar: `--${string}`;\n /** Usable CSS `var(...)` reference string. */\n readonly ref: `var(--${string})`;\n /** Stringifies to {@link CssToken.ref}. */\n toString(): string;\n /** Template interpolation; same as {@link CssToken.toString}. */\n [Symbol.toPrimitive](hint: string): string;\n}\n\n/** Theme token that stringifies to `var(<cssVar>)`. */\nexport const themeToken = (path: string, cssVar: `--${string}`): CssToken => {\n const ref: `var(--${string})` = `var(${cssVar})`;\n const refToString = (): string => ref;\n return {\n __kind: 'theme-token',\n path,\n cssVar,\n ref,\n toString: refToString,\n [Symbol.toPrimitive]: refToString,\n };\n};\n\n/** `true` when `value` is a {@link CssToken}. @param value Value to test. */\nexport const isCssToken = (value: unknown): value is CssToken =>\n hasKind(value, 'theme-token');\n"]}