@elastic/distillate 0.0.0 → 0.2.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 (292) 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 +491 -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 +95 -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 +44 -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/sink.js +9 -0
  37. package/dist/cjs/sink.js.map +1 -0
  38. package/dist/cjs/styles/authoring.js +169 -0
  39. package/dist/cjs/styles/authoring.js.map +1 -0
  40. package/dist/cjs/styles/declarations.js +139 -0
  41. package/dist/cjs/styles/declarations.js.map +1 -0
  42. package/dist/cjs/styles/index.js +32 -0
  43. package/dist/cjs/styles/index.js.map +1 -0
  44. package/dist/cjs/styles/module.js +233 -0
  45. package/dist/cjs/styles/module.js.map +1 -0
  46. package/dist/cjs/styles/registry.js +187 -0
  47. package/dist/cjs/styles/registry.js.map +1 -0
  48. package/dist/cjs/styles/types.js +9 -0
  49. package/dist/cjs/styles/types.js.map +1 -0
  50. package/dist/cjs/testing.js +37 -0
  51. package/dist/cjs/testing.js.map +1 -0
  52. package/dist/cjs/theme.js +249 -0
  53. package/dist/cjs/theme.js.map +1 -0
  54. package/dist/cjs/tokens/contextual_var.js +39 -0
  55. package/dist/cjs/tokens/contextual_var.js.map +1 -0
  56. package/dist/cjs/tokens/index.js +24 -0
  57. package/dist/cjs/tokens/index.js.map +1 -0
  58. package/dist/cjs/tokens/kind.js +14 -0
  59. package/dist/cjs/tokens/kind.js.map +1 -0
  60. package/dist/cjs/tokens/light_dark.js +42 -0
  61. package/dist/cjs/tokens/light_dark.js.map +1 -0
  62. package/dist/cjs/tokens/scale_token.js +28 -0
  63. package/dist/cjs/tokens/scale_token.js.map +1 -0
  64. package/dist/cjs/tokens/theme_token.js +28 -0
  65. package/dist/cjs/tokens/theme_token.js.map +1 -0
  66. package/dist/cjs/var_invariant.js +115 -0
  67. package/dist/cjs/var_invariant.js.map +1 -0
  68. package/dist/collector.d.ts +101 -0
  69. package/dist/collector.d.ts.map +1 -0
  70. package/dist/collector.js +487 -0
  71. package/dist/collector.js.map +1 -0
  72. package/dist/css_scan.d.ts +57 -0
  73. package/dist/css_scan.d.ts.map +1 -0
  74. package/dist/css_scan.js +180 -0
  75. package/dist/css_scan.js.map +1 -0
  76. package/dist/dom_sink.d.ts +23 -0
  77. package/dist/dom_sink.d.ts.map +1 -0
  78. package/dist/dom_sink.js +36 -0
  79. package/dist/dom_sink.js.map +1 -0
  80. package/dist/emotion.d.ts +44 -0
  81. package/dist/emotion.d.ts.map +1 -0
  82. package/dist/emotion.js +184 -0
  83. package/dist/emotion.js.map +1 -0
  84. package/dist/engine.d.ts +66 -0
  85. package/dist/engine.d.ts.map +1 -0
  86. package/dist/engine.js +91 -0
  87. package/dist/engine.js.map +1 -0
  88. package/dist/environment.d.ts +43 -0
  89. package/dist/environment.d.ts.map +1 -0
  90. package/dist/environment.js +8 -0
  91. package/dist/environment.js.map +1 -0
  92. package/dist/hash.d.ts +2 -0
  93. package/dist/hash.d.ts.map +1 -0
  94. package/dist/hash.js +82 -0
  95. package/dist/hash.js.map +1 -0
  96. package/dist/idents.d.ts +9 -0
  97. package/dist/idents.d.ts.map +1 -0
  98. package/dist/idents.js +19 -0
  99. package/dist/idents.js.map +1 -0
  100. package/dist/index.d.ts +11 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +15 -0
  103. package/dist/index.js.map +1 -0
  104. package/dist/instance.d.ts +16 -0
  105. package/dist/instance.d.ts.map +1 -0
  106. package/dist/instance.js +30 -0
  107. package/dist/instance.js.map +1 -0
  108. package/dist/local_vars.d.ts +75 -0
  109. package/dist/local_vars.d.ts.map +1 -0
  110. package/dist/local_vars.js +92 -0
  111. package/dist/local_vars.js.map +1 -0
  112. package/dist/minify.d.ts +11 -0
  113. package/dist/minify.d.ts.map +1 -0
  114. package/dist/minify.js +73 -0
  115. package/dist/minify.js.map +1 -0
  116. package/dist/names.d.ts +39 -0
  117. package/dist/names.d.ts.map +1 -0
  118. package/dist/names.js +70 -0
  119. package/dist/names.js.map +1 -0
  120. package/dist/nesting.d.ts +59 -0
  121. package/dist/nesting.d.ts.map +1 -0
  122. package/dist/nesting.js +400 -0
  123. package/dist/nesting.js.map +1 -0
  124. package/dist/runtime.d.ts +36 -0
  125. package/dist/runtime.d.ts.map +1 -0
  126. package/dist/runtime.js +252 -0
  127. package/dist/runtime.js.map +1 -0
  128. package/dist/sink.d.ts +16 -0
  129. package/dist/sink.d.ts.map +1 -0
  130. package/dist/sink.js +8 -0
  131. package/dist/sink.js.map +1 -0
  132. package/dist/styles/authoring.d.ts +59 -0
  133. package/dist/styles/authoring.d.ts.map +1 -0
  134. package/dist/styles/authoring.js +155 -0
  135. package/dist/styles/authoring.js.map +1 -0
  136. package/dist/styles/declarations.d.ts +10 -0
  137. package/dist/styles/declarations.d.ts.map +1 -0
  138. package/dist/styles/declarations.js +132 -0
  139. package/dist/styles/declarations.js.map +1 -0
  140. package/dist/styles/index.d.ts +7 -0
  141. package/dist/styles/index.d.ts.map +1 -0
  142. package/dist/styles/index.js +12 -0
  143. package/dist/styles/index.js.map +1 -0
  144. package/dist/styles/module.d.ts +5 -0
  145. package/dist/styles/module.d.ts.map +1 -0
  146. package/dist/styles/module.js +229 -0
  147. package/dist/styles/module.js.map +1 -0
  148. package/dist/styles/registry.d.ts +48 -0
  149. package/dist/styles/registry.d.ts.map +1 -0
  150. package/dist/styles/registry.js +182 -0
  151. package/dist/styles/registry.js.map +1 -0
  152. package/dist/styles/types.d.ts +211 -0
  153. package/dist/styles/types.d.ts.map +1 -0
  154. package/dist/styles/types.js +8 -0
  155. package/dist/styles/types.js.map +1 -0
  156. package/dist/testing.d.ts +10 -0
  157. package/dist/testing.d.ts.map +1 -0
  158. package/dist/testing.js +31 -0
  159. package/dist/testing.js.map +1 -0
  160. package/dist/theme.d.ts +85 -0
  161. package/dist/theme.d.ts.map +1 -0
  162. package/dist/theme.js +240 -0
  163. package/dist/theme.js.map +1 -0
  164. package/dist/tokens/contextual_var.d.ts +35 -0
  165. package/dist/tokens/contextual_var.d.ts.map +1 -0
  166. package/dist/tokens/contextual_var.js +33 -0
  167. package/dist/tokens/contextual_var.js.map +1 -0
  168. package/dist/tokens/index.d.ts +5 -0
  169. package/dist/tokens/index.d.ts.map +1 -0
  170. package/dist/tokens/index.js +11 -0
  171. package/dist/tokens/index.js.map +1 -0
  172. package/dist/tokens/kind.d.ts +2 -0
  173. package/dist/tokens/kind.d.ts.map +1 -0
  174. package/dist/tokens/kind.js +10 -0
  175. package/dist/tokens/kind.js.map +1 -0
  176. package/dist/tokens/light_dark.d.ts +20 -0
  177. package/dist/tokens/light_dark.d.ts.map +1 -0
  178. package/dist/tokens/light_dark.js +37 -0
  179. package/dist/tokens/light_dark.js.map +1 -0
  180. package/dist/tokens/scale_token.d.ts +20 -0
  181. package/dist/tokens/scale_token.d.ts.map +1 -0
  182. package/dist/tokens/scale_token.js +23 -0
  183. package/dist/tokens/scale_token.js.map +1 -0
  184. package/dist/tokens/theme_token.d.ts +20 -0
  185. package/dist/tokens/theme_token.d.ts.map +1 -0
  186. package/dist/tokens/theme_token.js +23 -0
  187. package/dist/tokens/theme_token.js.map +1 -0
  188. package/dist/var_invariant.d.ts +25 -0
  189. package/dist/var_invariant.d.ts.map +1 -0
  190. package/dist/var_invariant.js +108 -0
  191. package/dist/var_invariant.js.map +1 -0
  192. package/docs/concepts/authoring.md +115 -0
  193. package/docs/concepts/collection.md +66 -0
  194. package/docs/concepts/distillery.md +47 -0
  195. package/docs/concepts/index.md +18 -0
  196. package/docs/concepts/naming-and-output.md +123 -0
  197. package/docs/concepts/ordering.md +61 -0
  198. package/docs/concepts/single-copy.md +103 -0
  199. package/docs/concepts/tokens.md +99 -0
  200. package/docs/docset.yml +53 -0
  201. package/docs/examples/01-stylesheet.ts +20 -0
  202. package/docs/examples/02-artifact.ts +26 -0
  203. package/docs/examples/03-variants.ts +40 -0
  204. package/docs/examples/04-emotion.ts +33 -0
  205. package/docs/examples/05-var-invariant.ts +31 -0
  206. package/docs/examples/06-payload.ts +85 -0
  207. package/docs/examples/fixture.ts +22 -0
  208. package/docs/getting-started/index.md +14 -0
  209. package/docs/getting-started/installation.md +30 -0
  210. package/docs/getting-started/quick-start.md +61 -0
  211. package/docs/getting-started/your-first-stylesheet.md +57 -0
  212. package/docs/guides/compact-artifacts.md +87 -0
  213. package/docs/guides/emotion-migration.md +60 -0
  214. package/docs/guides/index.md +17 -0
  215. package/docs/guides/name-collisions.md +37 -0
  216. package/docs/guides/non-css-surfaces.md +73 -0
  217. package/docs/guides/react-renderer.md +202 -0
  218. package/docs/guides/theming.md +107 -0
  219. package/docs/guides/var-invariant.md +24 -0
  220. package/docs/guides/vs-emotion.md +61 -0
  221. package/docs/index.md +73 -0
  222. package/docs/logo.svg +7 -0
  223. package/docs/playground/index.html +12 -0
  224. package/docs/playground/package.json +23 -0
  225. package/docs/playground/src/app/app.tsx +109 -0
  226. package/docs/playground/src/app/css_panel.tsx +119 -0
  227. package/docs/playground/src/app/editor_panel.tsx +87 -0
  228. package/docs/playground/src/app/index.ts +8 -0
  229. package/docs/playground/src/app/monaco_css_editor.tsx +84 -0
  230. package/docs/playground/src/app/monaco_source_editor.tsx +132 -0
  231. package/docs/playground/src/app/preview_panel.tsx +99 -0
  232. package/docs/playground/src/app/tokens_panel.tsx +117 -0
  233. package/docs/playground/src/app/types.ts +10 -0
  234. package/docs/playground/src/examples/snippets.test.ts +28 -0
  235. package/docs/playground/src/examples/snippets.ts +418 -0
  236. package/docs/playground/src/lib/compile.test.ts +157 -0
  237. package/docs/playground/src/lib/compile.ts +242 -0
  238. package/docs/playground/src/lib/demo_environment.test.ts +123 -0
  239. package/docs/playground/src/lib/demo_environment.ts +140 -0
  240. package/docs/playground/src/lib/editor_lib.test.ts +39 -0
  241. package/docs/playground/src/lib/editor_lib.ts +142 -0
  242. package/docs/playground/src/lib/format_css.test.ts +41 -0
  243. package/docs/playground/src/lib/format_css.ts +71 -0
  244. package/docs/playground/src/main.tsx +25 -0
  245. package/docs/playground/src/setup/chrome.test.ts +47 -0
  246. package/docs/playground/src/setup/chrome.ts +365 -0
  247. package/docs/playground/src/setup/monaco_env.ts +64 -0
  248. package/docs/playground/tsconfig.json +22 -0
  249. package/docs/playground/vite.config.ts +37 -0
  250. package/docs/playground/vitest.config.ts +35 -0
  251. package/docs/playground.md +28 -0
  252. package/docs/reference/api/emotion.md +290 -0
  253. package/docs/reference/api/index-1.md +2387 -0
  254. package/docs/reference/api/index.md +9 -0
  255. package/docs/reference/api/testing.md +92 -0
  256. package/docs/reference/api.md +12 -0
  257. package/docs/reference/entry-points.md +139 -0
  258. package/docs/reference/environment.md +60 -0
  259. package/docs/reference/index.md +11 -0
  260. package/docs/reference/okf-map.md +93 -0
  261. package/package.json +127 -4
  262. package/src/collector.ts +612 -0
  263. package/src/css_scan.ts +263 -0
  264. package/src/dom_sink.ts +64 -0
  265. package/src/emotion.ts +308 -0
  266. package/src/engine.ts +241 -0
  267. package/src/environment.ts +56 -0
  268. package/src/hash.ts +111 -0
  269. package/src/idents.ts +21 -0
  270. package/src/index.ts +106 -0
  271. package/src/instance.ts +49 -0
  272. package/src/local_vars.ts +220 -0
  273. package/src/minify.ts +87 -0
  274. package/src/names.ts +129 -0
  275. package/src/nesting.ts +596 -0
  276. package/src/runtime.ts +428 -0
  277. package/src/sink.ts +25 -0
  278. package/src/styles/authoring.ts +244 -0
  279. package/src/styles/declarations.ts +172 -0
  280. package/src/styles/index.ts +58 -0
  281. package/src/styles/module.ts +396 -0
  282. package/src/styles/registry.ts +261 -0
  283. package/src/styles/types.ts +283 -0
  284. package/src/testing.ts +48 -0
  285. package/src/theme.ts +454 -0
  286. package/src/tokens/contextual_var.ts +72 -0
  287. package/src/tokens/index.ts +17 -0
  288. package/src/tokens/kind.ts +13 -0
  289. package/src/tokens/light_dark.ts +58 -0
  290. package/src/tokens/scale_token.ts +41 -0
  291. package/src/tokens/theme_token.ts +42 -0
  292. package/src/var_invariant.ts +147 -0
package/dist/engine.js ADDED
@@ -0,0 +1,91 @@
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 { StylesCollector } from './collector.js';
8
+ import { assertCssIdentSegment } from './idents.js';
9
+ import { createStyleNameResolver, } from './names.js';
10
+ import { renderStyles } from './runtime.js';
11
+ import { createStyleModuleWithEnvironment, readableVarOwnersFromEnvironment, StyleRegistry, } from './styles/index.js';
12
+ import { deriveTheme, requireThemeVariation, resolveThemeValues, resolveThemeVariations, } from './theme.js';
13
+ /**
14
+ * Binds the engine to one library's prefix and theme tree.
15
+ *
16
+ * @param options Brand prefix, theme scope, and authoring theme tree.
17
+ * @throws If `prefix` is not a CSS identifier segment, if a theme key contains a hyphen, if a `lightDark` value is not a CSS `<color>`, if a named variation disagrees with the base, or if `themeVars` / `sharedVars` claim the same readable custom-property name.
18
+ */
19
+ export const createDistillery = (options) => {
20
+ const { prefix, themeScope, theme, sharedVars: sharedVarList, variations, dev = false, } = options;
21
+ assertCssIdentSegment(prefix, 'Distillery prefix');
22
+ const { tokens, themeVars } = deriveTheme(prefix, theme);
23
+ const sharedVars = sharedVarList
24
+ ? Object.freeze(new Set(sharedVarList))
25
+ : undefined;
26
+ const resolvedVariations = resolveThemeVariations(prefix, theme, themeVars, variations);
27
+ const environment = {
28
+ prefix,
29
+ themeScope,
30
+ themeVars: Object.freeze(themeVars),
31
+ tokens,
32
+ ...(sharedVars ? { sharedVars } : {}),
33
+ ...(Object.keys(resolvedVariations).length > 0
34
+ ? { variations: resolvedVariations }
35
+ : {}),
36
+ };
37
+ const registry = new StyleRegistry(prefix, readableVarOwnersFromEnvironment(environment), sharedVars ?? new Set());
38
+ const artifactCollector = (names, collectorOptions) => new StylesCollector({
39
+ target: 'artifact',
40
+ names,
41
+ registry,
42
+ prefix,
43
+ dev,
44
+ ...(collectorOptions?.warn ? { warn: collectorOptions.warn } : {}),
45
+ });
46
+ return {
47
+ environment,
48
+ tokens,
49
+ themeVars: environment.themeVars,
50
+ resolveValues: (scheme, variation) => resolveThemeValues(theme, themeVars, scheme, variation === undefined
51
+ ? undefined
52
+ : requireThemeVariation(environment.variations, variation)),
53
+ registry,
54
+ dev,
55
+ createStyleModule: (name, factory) => createStyleModuleWithEnvironment(environment, registry, name, factory),
56
+ primitiveStyles: (name, factory) => createStyleModuleWithEnvironment(environment, registry, name, ({ css: style, tokens: moduleTokens }) => factory({ style, tokens: moduleTokens })),
57
+ artifactCollector,
58
+ stylesheetCollector: (names = 'readable', options) => {
59
+ const collector = new StylesCollector({
60
+ target: 'stylesheet',
61
+ names,
62
+ registry,
63
+ prefix,
64
+ dev,
65
+ ...(options?.warn ? { warn: options.warn } : {}),
66
+ });
67
+ for (const module of registry.modules) {
68
+ collector.useAllEntries(module);
69
+ }
70
+ return collector;
71
+ },
72
+ liveCollection: ({ sink, render, warn } = {}) => {
73
+ const collector = artifactCollector('readable', warn ? { warn } : {});
74
+ const css = () => renderStyles(environment, collector, undefined, render);
75
+ if (sink) {
76
+ collector.subscribe(() => sink.invalidate(css));
77
+ }
78
+ return {
79
+ collector,
80
+ resolveClassName: (...handles) => collector
81
+ .useHandles(handles)
82
+ .map((handle) => handle.readableName)
83
+ .join(' '),
84
+ css,
85
+ };
86
+ },
87
+ renderStyles: (collector, resolver, renderOptions) => renderStyles(environment, collector, resolver, renderOptions),
88
+ createNameResolver: (resolverOptions) => createStyleNameResolver({ ...resolverOptions, prefix }),
89
+ };
90
+ };
91
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAA+B,MAAM,aAAa,CAAC;AAM3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EACL,uBAAuB,GAIxB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAA4B,MAAM,WAAW,CAAC;AAEnE,OAAO,EACL,gCAAgC,EAEhC,gCAAgC,EAIhC,aAAa,GAGd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,GAIvB,MAAM,SAAS,CAAC;AAgFjB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAAkC,E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C,CAAC;YAClC,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE;YAC9C,MAAM,SAAS,GAAG,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACtE,MAAM,GAAG,GAAG,GAAW,EAAE,CACvB,YAAY,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YAC1D,IAAI,IAAI,EAAE,CAAC;gBACT,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YAClD,CAAC;YACD,OAAO;gBACL,SAAS;gBACT,gBAAgB,EAAE,CAAC,GAAG,OAAO,EAAE,EAAE,CAC/B,SAAS;qBACN,UAAU,CAAC,OAAO,CAAC;qBACnB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC;qBACpC,IAAI,CAAC,GAAG,CAAC;gBACd,GAAG;aACJ,CAAC;QACJ,CAAC;QACD,YAAY,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,CACnD,YAAY,CAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC;QAC/D,kBAAkB,EAAE,CAAC,eAAe,EAAE,EAAE,CACtC,uBAAuB,CAAC,EAAE,GAAG,eAAe,EAAE,MAAM,EAAE,CAAC;KAC1D,CAAC;AACJ,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 { StylesCollector, type StylesCollectorOptions } from './collector';\nimport type {\n DistilleryEnvironment,\n DistilleryOptions,\n ThemeVarDefinition,\n} from './environment';\nimport { assertCssIdentSegment } from './idents';\nimport {\n createStyleNameResolver,\n type StyleNameMode,\n type StyleNameResolver,\n type StyleNameResolverOptions,\n} from './names';\nimport { renderStyles, type RenderStylesOptions } from './runtime';\nimport type { StyleSink } from './sink';\nimport {\n createStyleModuleWithEnvironment,\n type PrimitiveStyleAuthoringApi,\n readableVarOwnersFromEnvironment,\n type ResolvedStyles,\n type StyleAuthoringApi,\n type StyleHandle,\n StyleRegistry,\n type StylesModule,\n type StylesObject,\n} from './styles';\nimport {\n deriveTheme,\n requireThemeVariation,\n resolveThemeValues,\n resolveThemeVariations,\n type ThemeTree,\n type TokensOf,\n type ValuesOf,\n} from './theme';\n\n/** Sink, render options, and warning sink for {@link Distillery.liveCollection}. */\nexport interface LiveCollectionOptions {\n /** Invalidated whenever the collection grows. Nothing is written before the first handle. */\n sink?: StyleSink;\n /** Options forwarded to `renderStyles` by `css()`. */\n render?: RenderStylesOptions;\n /** Warning sink for no-op handles. Used only when the distillery has `dev: true`. */\n warn?: (message: string) => void;\n}\n\n/**\n * Readable collection filled by one live render.\n *\n * Readable only: compact names depend on the complete collected set and need two passes.\n */\nexport interface LiveCollection {\n /** Underlying readable artifact collector. Mutations here (e.g. `use(globalModule)`, `useThemeVar`) also invalidate the sink. */\n readonly collector: StylesCollector;\n /** Collects `handles` and returns their readable class names, space-separated. */\n readonly resolveClassName: (...handles: StyleHandle[]) => string;\n /** Renders the CSS collected so far. */\n readonly css: () => string;\n}\n\n/** One component library's binding: environment, registry, and pre-bound operations. Destructure-safe (no `this`). */\nexport interface Distillery<\n TTokens = unknown,\n TTheme extends ThemeTree = ThemeTree,\n> {\n /** Resolved environment (tokens, prefix, derived theme vars). */\n readonly environment: DistilleryEnvironment<TTokens>;\n /** Derived token tree, same object as `environment.tokens`. */\n readonly tokens: TTokens;\n /** Derived theme-var registry, same object as `environment.themeVars`. */\n readonly themeVars: Readonly<Record<string, ThemeVarDefinition>>;\n /** Nested literal values for one scheme. Optional `variation` is a name from `variations`. */\n readonly resolveValues: (\n scheme: 'light' | 'dark',\n variation?: string\n ) => ValuesOf<TTheme>;\n /** The module registry accumulating collected handles and rules. */\n readonly registry: StyleRegistry;\n /** When `true`, collectors warn about no-op handles. */\n readonly dev: boolean;\n /** Named handle tree plus tokens. */\n readonly createStyleModule: <TStyles extends StylesObject>(\n name: string,\n factory: (api: StyleAuthoringApi<TTokens>) => TStyles\n ) => StylesModule<ResolvedStyles<TStyles>>;\n /** Named handles plus tokens only. */\n readonly primitiveStyles: <TStyles extends StylesObject>(\n name: string,\n factory: (api: PrimitiveStyleAuthoringApi<TTokens>) => TStyles\n ) => StylesModule<ResolvedStyles<TStyles>>;\n /** Collector for one render. Class-name resolution collects as a side effect. No-op warnings require `dev: true`; pass `{ warn }` to capture them. */\n readonly artifactCollector: (\n names: StyleNameMode,\n options?: Pick<StylesCollectorOptions, 'warn'>\n ) => StylesCollector;\n /** Collector preloaded with every registered module. No-op warnings require `dev: true`; pass `{ warn }` to capture them. */\n readonly stylesheetCollector: (\n names?: StyleNameMode,\n options?: Pick<StylesCollectorOptions, 'warn'>\n ) => StylesCollector;\n /** Readable collection for one live render; keeps `sink` current as handles resolve. */\n readonly liveCollection: (options?: LiveCollectionOptions) => LiveCollection;\n /** Emits collected CSS for this environment. */\n readonly renderStyles: (\n collector: StylesCollector,\n resolver?: StyleNameResolver,\n options?: RenderStylesOptions\n ) => string;\n /** Creates a standalone name resolver using this distillery's prefix. */\n readonly createNameResolver: (\n options: Omit<StyleNameResolverOptions, 'prefix'>\n ) => StyleNameResolver;\n}\n\n/**\n * Binds the engine to one library's prefix and theme tree.\n *\n * @param options Brand prefix, theme scope, and authoring theme tree.\n * @throws If `prefix` is not a CSS identifier segment, if a theme key contains a hyphen, if a `lightDark` value is not a CSS `<color>`, if a named variation disagrees with the base, or if `themeVars` / `sharedVars` claim the same readable custom-property name.\n */\nexport const createDistillery = <const TTheme extends ThemeTree>(\n options: DistilleryOptions<TTheme>\n): Distillery<TokensOf<TTheme>, TTheme> => {\n const {\n prefix,\n themeScope,\n theme,\n sharedVars: sharedVarList,\n variations,\n dev = false,\n } = options;\n assertCssIdentSegment(prefix, 'Distillery prefix');\n const { tokens, themeVars } = deriveTheme(prefix, theme);\n const sharedVars = sharedVarList\n ? Object.freeze(new Set(sharedVarList))\n : undefined;\n const resolvedVariations = resolveThemeVariations(\n prefix,\n theme,\n themeVars,\n variations\n );\n const environment: DistilleryEnvironment<TokensOf<TTheme>> = {\n prefix,\n themeScope,\n themeVars: Object.freeze(themeVars),\n tokens,\n ...(sharedVars ? { sharedVars } : {}),\n ...(Object.keys(resolvedVariations).length > 0\n ? { variations: resolvedVariations }\n : {}),\n };\n const registry = new StyleRegistry(\n prefix,\n readableVarOwnersFromEnvironment(environment),\n sharedVars ?? new Set()\n );\n\n const artifactCollector = (\n names: StyleNameMode,\n collectorOptions?: Pick<StylesCollectorOptions, 'warn'>\n ): StylesCollector =>\n new StylesCollector({\n target: 'artifact',\n names,\n registry,\n prefix,\n dev,\n ...(collectorOptions?.warn ? { warn: collectorOptions.warn } : {}),\n });\n\n return {\n environment,\n tokens,\n themeVars: environment.themeVars,\n resolveValues: (scheme, variation) =>\n resolveThemeValues(\n theme,\n themeVars,\n scheme,\n variation === undefined\n ? undefined\n : requireThemeVariation(environment.variations, variation)\n ),\n registry,\n dev,\n createStyleModule: (name, factory) =>\n createStyleModuleWithEnvironment(environment, registry, name, factory),\n primitiveStyles: (name, factory) =>\n createStyleModuleWithEnvironment(\n environment,\n registry,\n name,\n ({ css: style, tokens: moduleTokens }) =>\n factory({ style, tokens: moduleTokens })\n ),\n artifactCollector,\n stylesheetCollector: (names = 'readable', options) => {\n const collector = new StylesCollector({\n target: 'stylesheet',\n names,\n registry,\n prefix,\n dev,\n ...(options?.warn ? { warn: options.warn } : {}),\n });\n for (const module of registry.modules) {\n collector.useAllEntries(module);\n }\n return collector;\n },\n liveCollection: ({ sink, render, warn } = {}) => {\n const collector = artifactCollector('readable', warn ? { warn } : {});\n const css = (): string =>\n renderStyles(environment, collector, undefined, render);\n if (sink) {\n collector.subscribe(() => sink.invalidate(css));\n }\n return {\n collector,\n resolveClassName: (...handles) =>\n collector\n .useHandles(handles)\n .map((handle) => handle.readableName)\n .join(' '),\n css,\n };\n },\n renderStyles: (collector, resolver, renderOptions) =>\n renderStyles(environment, collector, resolver, renderOptions),\n createNameResolver: (resolverOptions) =>\n createStyleNameResolver({ ...resolverOptions, prefix }),\n };\n};\n"]}
@@ -0,0 +1,43 @@
1
+ import type { ResolvedThemeVariation, ThemeTree, ThemeVariation } from './theme.js';
2
+ /** One theme CSS variable. Differing `light`/`dark` fold into `light-dark(...)`. */
3
+ export interface ThemeVarDefinition {
4
+ /** Theme-tree path this definition was derived from. */
5
+ readonly path: string;
6
+ /** Emitted CSS custom property name. Equal to `cssVarName(prefix, path)`. */
7
+ readonly cssVar: `--${string}`;
8
+ /** Value for light color scheme. */
9
+ readonly light: string;
10
+ /** Value for dark color scheme. Equal to `light` for scheme-invariant tokens. */
11
+ readonly dark: string;
12
+ }
13
+ /** Authoring input to `createDistillery`. */
14
+ export interface DistilleryOptions<TTheme extends ThemeTree = ThemeTree> {
15
+ /** Brand identifier used in readable class and CSS-variable names. Must be a CSS identifier segment. */
16
+ readonly prefix: string;
17
+ /** Selector wrapping emitted theme-var declarations. */
18
+ readonly themeScope: string;
19
+ /** Nested value tree. Strings and `lightDark` leaves become theme vars; `ScaleToken` leaves inline. */
20
+ readonly theme: TTheme;
21
+ /** Named partial variations of `theme`. Declaring a variation does not emit it; name it at `renderStyles`. */
22
+ readonly variations?: Readonly<Record<string, ThemeVariation<TTheme>>>;
23
+ /** Cross-module contextual-var paths. Names are `cssVarName(prefix, path)`. Module-local `vars(...)` groups are not listed here. */
24
+ readonly sharedVars?: readonly `vars/${string}`[];
25
+ /** When `true`, collectors warn about no-op handles. Default `false`. Does not affect the single-copy guard. */
26
+ readonly dev?: boolean;
27
+ }
28
+ /** Resolved environment: derived `themeVars` / `tokens` plus the bind-time prefix and scope. */
29
+ export interface DistilleryEnvironment<TTokens = unknown> {
30
+ /** Brand identifier used in readable class and CSS-variable names. Must be a CSS identifier segment. */
31
+ readonly prefix: string;
32
+ /** Selector wrapping emitted theme-var declarations. */
33
+ readonly themeScope: string;
34
+ /** Theme token path → definition. Emission sorts paths. */
35
+ readonly themeVars: Readonly<Record<string, ThemeVarDefinition>>;
36
+ /** Cross-module contextual-var paths. Module-local `vars(...)` groups are not listed here. */
37
+ readonly sharedVars?: ReadonlySet<`vars/${string}`>;
38
+ /** Typed token tree, surfaced as `tokens` on the authoring API. */
39
+ readonly tokens: TTokens;
40
+ /** Named variations resolved against `themeVars`. Absent when no `variations` were declared. */
41
+ readonly variations?: Readonly<Record<string, ResolvedThemeVariation>>;
42
+ }
43
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,sBAAsB,EACtB,SAAS,EACT,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;IAC/B,oCAAoC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IACrE,wGAAwG;IACxG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uGAAuG;IACvG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,8GAA8G;IAC9G,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvE,oIAAoI;IACpI,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,QAAQ,MAAM,EAAE,EAAE,CAAC;IAClD,gHAAgH;IAChH,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,gGAAgG;AAChG,MAAM,WAAW,qBAAqB,CAAC,OAAO,GAAG,OAAO;IACtD,wGAAwG;IACxG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACjE,8FAA8F;IAC9F,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,QAAQ,MAAM,EAAE,CAAC,CAAC;IACpD,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,gGAAgG;IAChG,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;CACxE"}
@@ -0,0 +1,8 @@
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 {};
8
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","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 type {\n ResolvedThemeVariation,\n ThemeTree,\n ThemeVariation,\n} from './theme';\n\n/** One theme CSS variable. Differing `light`/`dark` fold into `light-dark(...)`. */\nexport interface ThemeVarDefinition {\n /** Theme-tree path this definition was derived from. */\n readonly path: string;\n /** Emitted CSS custom property name. Equal to `cssVarName(prefix, path)`. */\n readonly cssVar: `--${string}`;\n /** Value for light color scheme. */\n readonly light: string;\n /** Value for dark color scheme. Equal to `light` for scheme-invariant tokens. */\n readonly dark: string;\n}\n\n/** Authoring input to `createDistillery`. */\nexport interface DistilleryOptions<TTheme extends ThemeTree = ThemeTree> {\n /** Brand identifier used in readable class and CSS-variable names. Must be a CSS identifier segment. */\n readonly prefix: string;\n /** Selector wrapping emitted theme-var declarations. */\n readonly themeScope: string;\n /** Nested value tree. Strings and `lightDark` leaves become theme vars; `ScaleToken` leaves inline. */\n readonly theme: TTheme;\n /** Named partial variations of `theme`. Declaring a variation does not emit it; name it at `renderStyles`. */\n readonly variations?: Readonly<Record<string, ThemeVariation<TTheme>>>;\n /** Cross-module contextual-var paths. Names are `cssVarName(prefix, path)`. Module-local `vars(...)` groups are not listed here. */\n readonly sharedVars?: readonly `vars/${string}`[];\n /** When `true`, collectors warn about no-op handles. Default `false`. Does not affect the single-copy guard. */\n readonly dev?: boolean;\n}\n\n/** Resolved environment: derived `themeVars` / `tokens` plus the bind-time prefix and scope. */\nexport interface DistilleryEnvironment<TTokens = unknown> {\n /** Brand identifier used in readable class and CSS-variable names. Must be a CSS identifier segment. */\n readonly prefix: string;\n /** Selector wrapping emitted theme-var declarations. */\n readonly themeScope: string;\n /** Theme token path → definition. Emission sorts paths. */\n readonly themeVars: Readonly<Record<string, ThemeVarDefinition>>;\n /** Cross-module contextual-var paths. Module-local `vars(...)` groups are not listed here. */\n readonly sharedVars?: ReadonlySet<`vars/${string}`>;\n /** Typed token tree, surfaced as `tokens` on the authoring API. */\n readonly tokens: TTokens;\n /** Named variations resolved against `themeVars`. Absent when no `variations` were declared. */\n readonly variations?: Readonly<Record<string, ResolvedThemeVariation>>;\n}\n"]}
package/dist/hash.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const contentHash64: (strings: readonly string[], values: readonly unknown[]) => string;
2
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAyCA,eAAO,MAAM,aAAa,GACxB,SAAS,SAAS,MAAM,EAAE,EAC1B,QAAQ,SAAS,OAAO,EAAE,KACzB,MAMF,CAAC"}
package/dist/hash.js ADDED
@@ -0,0 +1,82 @@
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 { isLocalVarMarker } from './local_vars.js';
8
+ import { isLocalVarRef } from './local_vars.js';
9
+ import { isHandleLike } from './nesting.js';
10
+ import { isContextualCssVar, isContextualCssVarName, isCssToken, isScaleToken, } from './tokens/index.js';
11
+ const FNV_PRIME = 0x01000193;
12
+ const FNV_OFFSET_A = 0x811c9dc5;
13
+ // A second basis derived from the golden-ratio constant so the two passes
14
+ // disagree, widening the effective hash to 64 bits.
15
+ const FNV_OFFSET_B = (0x811c9dc5 ^ 0x9e3779b9) >>> 0;
16
+ const fnv1a = (input, offset) => {
17
+ let hash = offset;
18
+ for (let i = 0; i < input.length; i += 1) {
19
+ hash ^= input.charCodeAt(i);
20
+ hash = Math.imul(hash, FNV_PRIME);
21
+ }
22
+ return hash >>> 0;
23
+ };
24
+ const base36 = (value) => value.toString(36).padStart(7, '0');
25
+ export const contentHash64 = (strings, values) => {
26
+ const canonical = canonicalize(strings, values);
27
+ return (base36(fnv1a(canonical, FNV_OFFSET_A)) +
28
+ base36(fnv1a(canonical, FNV_OFFSET_B)));
29
+ };
30
+ // Canonical, injective-enough serialization. Template strings and tagged
31
+ // values are interleaved and joined with a NUL sentinel that cannot appear in
32
+ // authored CSS, so distinct templates cannot collide by concatenation.
33
+ const canonicalize = (strings, values) => {
34
+ const segments = [];
35
+ strings.forEach((part, index) => {
36
+ segments.push(part);
37
+ if (index < values.length) {
38
+ segments.push(tagValue(values[index]));
39
+ }
40
+ });
41
+ return segments.join('\u0000');
42
+ };
43
+ const tagValue = (value) => {
44
+ if (typeof value === 'string' || typeof value === 'number') {
45
+ return `r:${value}`;
46
+ }
47
+ if (isCssToken(value)) {
48
+ return `t:${value.path}`;
49
+ }
50
+ if (isContextualCssVar(value)) {
51
+ return `v:${value.path}`;
52
+ }
53
+ if (isContextualCssVarName(value)) {
54
+ return `n:${value.path}`;
55
+ }
56
+ if (isLocalVarRef(value)) {
57
+ return `l:${value.path}`;
58
+ }
59
+ if (isScaleToken(value)) {
60
+ return `s:${value.value}`;
61
+ }
62
+ if (isLocalVarMarker(value)) {
63
+ return tagMarker(value);
64
+ }
65
+ if (isHandleLike(value)) {
66
+ return `h:${value.key}`;
67
+ }
68
+ throw new Error(`Unsupported interpolation in css template. Interpolate a theme token, scale token, contextual var, local var (ref/marker), string, number, or a style handle.`);
69
+ };
70
+ const tagMarker = (marker) => {
71
+ if (marker.__kind === 'local-var-default-marker') {
72
+ const entries = marker.defaults
73
+ .map((item) => `${item.key}=${tagValue(item.value)}`)
74
+ .sort();
75
+ return `m:default:${marker.groupId}:${entries.join(',')}`;
76
+ }
77
+ const entries = marker.overrides
78
+ .map((item) => `${item.key}=${tagValue(item.value)}`)
79
+ .sort();
80
+ return `m:override:${marker.groupId}:${entries.join(',')}`;
81
+ };
82
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAA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AAC;IAC5B,CAAC;IACD,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,IAAI,KAAK,CACb,+JAA+J,CAChK,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,MAAsB,EAAU,EAAE;IACnD,IAAI,MAAM,CAAC,MAAM,KAAK,0BAA0B,EAAE,CAAC;QACjD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ;aAC5B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;aACpD,IAAI,EAAE,CAAC;QACV,OAAO,aAAa,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC5D,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS;SAC7B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;SACpD,IAAI,EAAE,CAAC;IACV,OAAO,cAAc,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC7D,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\n// Content hashing for anonymous emotion `css`/`injectGlobal` modules.\n//\n// Deterministic 64-bit FNV-1a (two 32-bit passes with distinct offset bases)\n// over a canonical serialization of the authored template. Determinism lets\n// server-rendered and client-rendered class names agree without coordination.\n\nimport type { LocalVarMarker } from './local_vars';\nimport { isLocalVarMarker } from './local_vars';\nimport { isLocalVarRef } from './local_vars';\nimport { isHandleLike } from './nesting';\nimport {\n isContextualCssVar,\n isContextualCssVarName,\n isCssToken,\n isScaleToken,\n} from './tokens';\n\nconst FNV_PRIME = 0x01000193;\nconst FNV_OFFSET_A = 0x811c9dc5;\n// A second basis derived from the golden-ratio constant so the two passes\n// disagree, widening the effective hash to 64 bits.\nconst FNV_OFFSET_B = (0x811c9dc5 ^ 0x9e3779b9) >>> 0;\n\nconst fnv1a = (input: string, offset: number): number => {\n let hash = offset;\n for (let i = 0; i < input.length; i += 1) {\n hash ^= input.charCodeAt(i);\n hash = Math.imul(hash, FNV_PRIME);\n }\n return hash >>> 0;\n};\n\nconst base36 = (value: number): string => value.toString(36).padStart(7, '0');\n\nexport const contentHash64 = (\n strings: readonly string[],\n values: readonly unknown[]\n): string => {\n const canonical = canonicalize(strings, values);\n return (\n base36(fnv1a(canonical, FNV_OFFSET_A)) +\n base36(fnv1a(canonical, FNV_OFFSET_B))\n );\n};\n\n// Canonical, injective-enough serialization. Template strings and tagged\n// values are interleaved and joined with a NUL sentinel that cannot appear in\n// authored CSS, so distinct templates cannot collide by concatenation.\nconst canonicalize = (\n strings: readonly string[],\n values: readonly unknown[]\n): string => {\n const segments: string[] = [];\n strings.forEach((part, index) => {\n segments.push(part);\n if (index < values.length) {\n segments.push(tagValue(values[index]));\n }\n });\n return segments.join('\\u0000');\n};\n\nconst tagValue = (value: unknown): string => {\n if (typeof value === 'string' || typeof value === 'number') {\n return `r:${value}`;\n }\n if (isCssToken(value)) {\n return `t:${value.path}`;\n }\n if (isContextualCssVar(value)) {\n return `v:${value.path}`;\n }\n if (isContextualCssVarName(value)) {\n return `n:${value.path}`;\n }\n if (isLocalVarRef(value)) {\n return `l:${value.path}`;\n }\n if (isScaleToken(value)) {\n return `s:${value.value}`;\n }\n if (isLocalVarMarker(value)) {\n return tagMarker(value);\n }\n if (isHandleLike(value)) {\n return `h:${value.key}`;\n }\n throw new Error(\n `Unsupported interpolation in css template. Interpolate a theme token, scale token, contextual var, local var (ref/marker), string, number, or a style handle.`\n );\n};\n\nconst tagMarker = (marker: LocalVarMarker): string => {\n if (marker.__kind === 'local-var-default-marker') {\n const entries = marker.defaults\n .map((item) => `${item.key}=${tagValue(item.value)}`)\n .sort();\n return `m:default:${marker.groupId}:${entries.join(',')}`;\n }\n const entries = marker.overrides\n .map((item) => `${item.key}=${tagValue(item.value)}`)\n .sort();\n return `m:override:${marker.groupId}:${entries.join(',')}`;\n};\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Throws if `segment` is not a valid CSS identifier segment.
3
+ *
4
+ * @param segment Value to validate.
5
+ * @param role Human-readable label for the error message (e.g. `'Distillery prefix'`).
6
+ * @throws If `segment` contains characters outside `[A-Za-z_][A-Za-z0-9_-]*`.
7
+ */
8
+ export declare const assertCssIdentSegment: (segment: string, role: string) => void;
9
+ //# sourceMappingURL=idents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idents.d.ts","sourceRoot":"","sources":["../src/idents.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,KAAG,IAMrE,CAAC"}
package/dist/idents.js ADDED
@@ -0,0 +1,19 @@
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
+ /**
8
+ * Throws if `segment` is not a valid CSS identifier segment.
9
+ *
10
+ * @param segment Value to validate.
11
+ * @param role Human-readable label for the error message (e.g. `'Distillery prefix'`).
12
+ * @throws If `segment` contains characters outside `[A-Za-z_][A-Za-z0-9_-]*`.
13
+ */
14
+ export const assertCssIdentSegment = (segment, role) => {
15
+ if (!/^[A-Za-z_][A-Za-z0-9_-]*$/.test(segment)) {
16
+ throw new Error(`${role} "${segment}" is not a CSS identifier segment. Use a letter or underscore, then letters, digits, hyphens, or underscores.`);
17
+ }
18
+ };
19
+ //# sourceMappingURL=idents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idents.js","sourceRoot":"","sources":["../src/idents.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAE,IAAY,EAAQ,EAAE;IAC3E,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,KAAK,OAAO,+GAA+G,CACnI,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\n/**\n * Throws if `segment` is not a valid CSS identifier segment.\n *\n * @param segment Value to validate.\n * @param role Human-readable label for the error message (e.g. `'Distillery prefix'`).\n * @throws If `segment` contains characters outside `[A-Za-z_][A-Za-z0-9_-]*`.\n */\nexport const assertCssIdentSegment = (segment: string, role: string): void => {\n if (!/^[A-Za-z_][A-Za-z0-9_-]*$/.test(segment)) {\n throw new Error(\n `${role} \"${segment}\" is not a CSS identifier segment. Use a letter or underscore, then letters, digits, hyphens, or underscores.`\n );\n }\n};\n"]}
@@ -0,0 +1,11 @@
1
+ export { createDistillery, type Distillery, type LiveCollection, type LiveCollectionOptions, } from './engine.js';
2
+ export { createDomSink, type CreateDomSinkOptions, type DocumentLike, type StyleElementLike, type StyleParentLike, } from './dom_sink.js';
3
+ export type { StyleSink } from './sink.js';
4
+ export { type DistilleryEnvironment, type DistilleryOptions, type ThemeVarDefinition, } from './environment.js';
5
+ export { resolveThemeValues, zipSchemes, type DeepPartialTheme, type MediaThemeVariation, type PathsOf, type ResolvedThemeVariation, type SchemeValueTree, type ThemeTree, type ThemeVariation, type TokensOf, type ValuesOf, type Zipped, } from './theme.js';
6
+ export { contextualVar, cq, isContextualCssVar, isContextualCssVarName, isCssToken, isScaleToken, lightDark, scaleToken, themeToken, type ContextualCssVar, type ContextualCssVarName, type CssToken, type ScaleToken, type SchemePair, } from './tokens/index.js';
7
+ export { createStyleNameResolver, cssVarName, type StyleNameMode, type StyleNameResolver, type StyleNameResolverOptions, type StyleTarget, } from './names.js';
8
+ export { StylesCollector, type StylesCollectorOptions } from './collector.js';
9
+ export { renderStyles, type RenderStylesOptions, type ThemeAlternate, } from './runtime.js';
10
+ export { combineClassNames, container, css, decls, mapDomain, media, rule, StyleRegistry, variants, type ContextualVarPath, type CssValue, type CssVarPath, type Declarations, type DeclarationSegment, type DefaultGroupDeps, type DefaultKeyDeps, type LocalVarDefaultMarker, type LocalVarGroup, type LocalVarMarker, type LocalVarOverrideMarker, type LocalVarRef, type PrimitiveStyleAuthoringApi, type ResolvedStyles, type RuleOptions, type StyleAuthoringApi, type StyleDeps, type StyleEntry, type StyleHandle, type StyleMedia, type StyleRegistrySnapshot, type StyleRule, type StylesModule, type StylesObject, type StyleSelectorResolver, } from './styles/index.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EACL,KAAK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Ac,EACnB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,qBAAqB,GAC3B,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
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 { createDistillery, } from './engine.js';
8
+ export { createDomSink, } from './dom_sink.js';
9
+ export { resolveThemeValues, zipSchemes, } from './theme.js';
10
+ export { contextualVar, cq, isContextualCssVar, isContextualCssVarName, isCssToken, isScaleToken, lightDark, scaleToken, themeToken, } from './tokens/index.js';
11
+ export { createStyleNameResolver, cssVarName, } from './names.js';
12
+ export { StylesCollector } from './collector.js';
13
+ export { renderStyles, } from './runtime.js';
14
+ export { combineClassNames, container, css, decls, mapDomain, media, rule, StyleRegistry, variants, } from './styles/index.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,gBAAgB,GAIjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,aAAa,GAKd,MAAM,YAAY,CAAC;AAOpB,OAAO,EACL,kBAAkB,EAClB,UAAU,GAWX,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,aAAa,EACb,EAAE,EACF,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,EACV,UAAU,GAMX,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,uBAAuB,EACvB,UAAU,GAKX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAA+B,MAAM,aAAa,CAAC;AAC3E,OAAO,EACL,YAAY,GAGb,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,GAAG,EACH,KAAK,EACL,SAAS,EACT,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,GA0BT,MAAM,UAAU,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 createDistillery,\n type Distillery,\n type LiveCollection,\n type LiveCollectionOptions,\n} from './engine';\nexport {\n createDomSink,\n type CreateDomSinkOptions,\n type DocumentLike,\n type StyleElementLike,\n type StyleParentLike,\n} from './dom_sink';\nexport type { StyleSink } from './sink';\nexport {\n type DistilleryEnvironment,\n type DistilleryOptions,\n type ThemeVarDefinition,\n} from './environment';\nexport {\n resolveThemeValues,\n zipSchemes,\n type DeepPartialTheme,\n type MediaThemeVariation,\n type PathsOf,\n type ResolvedThemeVariation,\n type SchemeValueTree,\n type ThemeTree,\n type ThemeVariation,\n type TokensOf,\n type ValuesOf,\n type Zipped,\n} from './theme';\nexport {\n contextualVar,\n cq,\n isContextualCssVar,\n isContextualCssVarName,\n isCssToken,\n isScaleToken,\n lightDark,\n scaleToken,\n themeToken,\n type ContextualCssVar,\n type ContextualCssVarName,\n type CssToken,\n type ScaleToken,\n type SchemePair,\n} from './tokens';\nexport {\n createStyleNameResolver,\n cssVarName,\n type StyleNameMode,\n type StyleNameResolver,\n type StyleNameResolverOptions,\n type StyleTarget,\n} from './names';\nexport { StylesCollector, type StylesCollectorOptions } from './collector';\nexport {\n renderStyles,\n type RenderStylesOptions,\n type ThemeAlternate,\n} from './runtime';\nexport {\n combineClassNames,\n container,\n css,\n decls,\n mapDomain,\n media,\n rule,\n StyleRegistry,\n variants,\n type ContextualVarPath,\n type CssValue,\n type CssVarPath,\n type Declarations,\n type DeclarationSegment,\n type DefaultGroupDeps,\n type DefaultKeyDeps,\n type LocalVarDefaultMarker,\n type LocalVarGroup,\n type LocalVarMarker,\n type LocalVarOverrideMarker,\n type LocalVarRef,\n type PrimitiveStyleAuthoringApi,\n type ResolvedStyles,\n type RuleOptions,\n type StyleAuthoringApi,\n type StyleDeps,\n type StyleEntry,\n type StyleHandle,\n type StyleMedia,\n type StyleRegistrySnapshot,\n type StyleRule,\n type StylesModule,\n type StylesObject,\n type StyleSelectorResolver,\n} from './styles';\n"]}
@@ -0,0 +1,16 @@
1
+ /** `globalThis` key for the loaded copy's identity. See the README. */
2
+ export declare const INSTANCE_KEY: unique symbol;
3
+ /** Object that may hold the Distillate instance identity, normally `globalThis`. */
4
+ export interface InstanceHost {
5
+ /** Identity token of the first Distillate copy that registered. */
6
+ [INSTANCE_KEY]?: string;
7
+ }
8
+ /**
9
+ * Records this copy's identity and warns if a different token is already registered.
10
+ *
11
+ * @param host Object carrying the marker, normally `globalThis`.
12
+ * @param instanceId This copy's identity token.
13
+ * @param warn Injected so tests need not intercept the console.
14
+ */
15
+ export declare const registerDistillateInstance: (host: InstanceHost, instanceId: string, warn?: (message: string) => void) => void;
16
+ //# sourceMappingURL=instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAOA,uEAAuE;AACvE,eAAO,MAAM,YAAY,EAAE,OAAO,MAEjC,CAAC;AAEF,oFAAoF;AACpF,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,MAAM,YAAY,EAClB,YAAY,MAAM,EAClB,OAAM,CAAC,OAAO,EAAE,MAAM,KAAK,IAAyC,KACnE,IAcF,CAAC"}
@@ -0,0 +1,30 @@
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
+ /** `globalThis` key for the loaded copy's identity. See the README. */
8
+ export const INSTANCE_KEY = Symbol.for('elastic.distillate.instance');
9
+ /**
10
+ * Records this copy's identity and warns if a different token is already registered.
11
+ *
12
+ * @param host Object carrying the marker, normally `globalThis`.
13
+ * @param instanceId This copy's identity token.
14
+ * @param warn Injected so tests need not intercept the console.
15
+ */
16
+ export const registerDistillateInstance = (host, instanceId, warn = (message) => console.warn(message)) => {
17
+ const registered = host[INSTANCE_KEY];
18
+ if (registered === undefined) {
19
+ host[INSTANCE_KEY] = instanceId;
20
+ return;
21
+ }
22
+ if (registered === instanceId) {
23
+ return;
24
+ }
25
+ warn(`@elastic/distillate: a second copy loaded (${instanceId}; already registered ${registered}). ` +
26
+ 'The engine keeps module-scope state, so two copies silently break `variants(...)` tree-shaking ' +
27
+ 'and inflate emitted CSS. Externalize @elastic/distillate in your bundler so exactly one copy loads.');
28
+ };
29
+ registerDistillateInstance(globalThis, `@elastic/distillate/instance#${Math.random().toString(36).slice(2)}`);
30
+ //# sourceMappingURL=instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.js","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,YAAY,GAAkB,MAAM,CAAC,GAAG,CACnD,6BAA6B,CAC9B,CAAC;AAQF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,IAAkB,EAClB,UAAkB,EAClB,OAAkC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAC9D,EAAE;IACR,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IACtC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC;QAChC,OAAO;IACT,CAAC;IACD,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO;IACT,CAAC;IACD,IAAI,CACF,8CAA8C,UAAU,wBAAwB,UAAU,KAAK;QAC7F,iGAAiG;QACjG,qGAAqG,CACxG,CAAC;AACJ,CAAC,CAAC;AAEF,0BAA0B,CACxB,UAA0B,EAC1B,gCAAgC,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CACtE,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\n/** `globalThis` key for the loaded copy's identity. See the README. */\nexport const INSTANCE_KEY: unique symbol = Symbol.for(\n 'elastic.distillate.instance'\n);\n\n/** Object that may hold the Distillate instance identity, normally `globalThis`. */\nexport interface InstanceHost {\n /** Identity token of the first Distillate copy that registered. */\n [INSTANCE_KEY]?: string;\n}\n\n/**\n * Records this copy's identity and warns if a different token is already registered.\n *\n * @param host Object carrying the marker, normally `globalThis`.\n * @param instanceId This copy's identity token.\n * @param warn Injected so tests need not intercept the console.\n */\nexport const registerDistillateInstance = (\n host: InstanceHost,\n instanceId: string,\n warn: (message: string) => void = (message) => console.warn(message)\n): void => {\n const registered = host[INSTANCE_KEY];\n if (registered === undefined) {\n host[INSTANCE_KEY] = instanceId;\n return;\n }\n if (registered === instanceId) {\n return;\n }\n warn(\n `@elastic/distillate: a second copy loaded (${instanceId}; already registered ${registered}). ` +\n 'The engine keeps module-scope state, so two copies silently break `variants(...)` tree-shaking ' +\n 'and inflate emitted CSS. Externalize @elastic/distillate in your bundler so exactly one copy loads.'\n );\n};\n\nregisterDistillateInstance(\n globalThis as InstanceHost,\n `@elastic/distillate/instance#${Math.random().toString(36).slice(2)}`\n);\n"]}
@@ -0,0 +1,75 @@
1
+ import type { ContextualVarPath, CssValue } from './styles/types.js';
2
+ /** Reference to a local CSS variable. Stringifies to `var(--...)`. */
3
+ export interface LocalVarRef {
4
+ /** Brand distinguishing a local-var ref from other interpolations. */
5
+ readonly __kind: 'local-var-ref';
6
+ /** Canonical group/key path. */
7
+ readonly path: ContextualVarPath;
8
+ /** Actual emitted CSS custom property name. */
9
+ readonly propName: `--${string}`;
10
+ /** Usable CSS `var(...)` reference string. */
11
+ readonly ref: `var(--${string})`;
12
+ /** Stringifies to {@link LocalVarRef.ref}. */
13
+ toString(): string;
14
+ /** Template interpolation; same as {@link LocalVarRef.toString}. */
15
+ [Symbol.toPrimitive](hint: string): string;
16
+ }
17
+ /** Interpolation marker representing `.set(...)` overrides. */
18
+ export interface LocalVarOverrideMarker {
19
+ /** Brand distinguishing a `.set(...)` override marker. */
20
+ readonly __kind: 'local-var-override-marker';
21
+ /** Unique ID for the group. */
22
+ readonly groupId: string;
23
+ /** Ordered list of variable overrides. */
24
+ readonly overrides: ReadonlyArray<{
25
+ /** Variable key within the group. */
26
+ readonly key: string;
27
+ /** Canonical group/key path. */
28
+ readonly path: ContextualVarPath;
29
+ /** Actual emitted CSS custom property name. */
30
+ readonly propName: `--${string}`;
31
+ /** Override value written at this interpolation site. */
32
+ readonly value: CssValue;
33
+ }>;
34
+ }
35
+ /** Interpolation marker representing `${group}` defaults. */
36
+ export interface LocalVarDefaultMarker {
37
+ /** Brand distinguishing a `${group}` default marker. */
38
+ readonly __kind: 'local-var-default-marker';
39
+ /** Unique ID for the group. */
40
+ readonly groupId: string;
41
+ /** Group prefix path. */
42
+ readonly groupPath: `vars/${string}`;
43
+ /** Ordered list of variable defaults. */
44
+ readonly defaults: ReadonlyArray<{
45
+ /** Variable key within the group. */
46
+ readonly key: string;
47
+ /** Canonical group/key path. */
48
+ readonly path: ContextualVarPath;
49
+ /** Actual emitted CSS custom property name. */
50
+ readonly propName: `--${string}`;
51
+ /** Default value emitted when this key is reachable. */
52
+ readonly value: CssValue;
53
+ }>;
54
+ }
55
+ /** Interpolation marker: `${group}` defaults or `${group.set(...)}` overrides. */
56
+ export type LocalVarMarker = LocalVarOverrideMarker | LocalVarDefaultMarker;
57
+ /**
58
+ * Value returned by `t.vars(...)`. Interpolate `${group}`, `${group.key}`, or `${group.set({...})}`.
59
+ */
60
+ export type LocalVarGroup<TKey extends string> = {
61
+ readonly [P in TKey]: LocalVarRef;
62
+ } & {
63
+ /** Builds a marker that writes the given keys at the interpolation site. */
64
+ set(overrides: Partial<Record<TKey, CssValue>>): LocalVarOverrideMarker;
65
+ };
66
+ /** `true` when `value` is a {@link LocalVarRef}. */
67
+ export declare const isLocalVarRef: (value: unknown) => value is LocalVarRef;
68
+ /** `true` when `value` is a {@link LocalVarDefaultMarker}. */
69
+ export declare const isLocalVarDefaultMarker: (value: unknown) => value is LocalVarDefaultMarker;
70
+ /** `true` when `value` is a {@link LocalVarOverrideMarker}. */
71
+ export declare const isLocalVarOverrideMarker: (value: unknown) => value is LocalVarOverrideMarker;
72
+ /** `true` when `value` is a {@link LocalVarDefaultMarker} or {@link LocalVarOverrideMarker}. */
73
+ export declare const isLocalVarMarker: (value: unknown) => value is LocalVarMarker;
74
+ export declare const createLocalVarGroup: <TKey extends string>(prefix: string, moduleName: string, group: string, defaults: Record<TKey, CssValue>) => LocalVarGroup<TKey>;
75
+ //# sourceMappingURL=local_vars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_vars.d.ts","sourceRoot":"","sources":["../src/local_vars.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAOlE,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAC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Q,EAAE,KAAK,MAAM,EAAE,CAAC;QACjC,wDAAwD;QACxD,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;KAC1B,CAAC,CAAC;CACJ;AAED,kFAAkF;AAClF,MAAM,MAAM,cAAc,GAAG,sBAAsB,GAAG,qBAAqB,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,IAAI,SAAS,MAAM,IAAI;IAC/C,QAAQ,EAAE,CAAC,IAAI,IAAI,GAAG,WAAW;CAClC,GAAG;IACF,4EAA4E;IAC5E,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,sBAAsB,CAAC;CACzE,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,WAKrD,CAAC;AAEJ,8DAA8D;AAC9D,eAAO,MAAM,uBAAuB,GAClC,OAAO,OAAO,KACb,KAAK,IAAI,qBAKT,CAAC;AAEJ,+DAA+D;AAC/D,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb,KAAK,IAAI,sBAKT,CAAC;AAEJ,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,cACQ,CAAC;AA6BpE,eAAO,MAAM,mBAAmB,GAAI,IAAI,SAAS,MAAM,EACrD,QAAQ,MAAM,EACd,YAAY,MAAM,EAClB,OAAO,MAAM,EACb,UAAU,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,KAC/B,aAAa,CAAC,IAAI,CAsEpB,CAAC"}
@@ -0,0 +1,92 @@
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 { assertCssIdentSegment } from './idents.js';
8
+ import { cssVarName } from './names.js';
9
+ const RESERVED_DEFAULT_KEYS = new Set(['set', 'toString', 'valueOf', 'toJSON']);
10
+ const isReservedKey = (key) => RESERVED_DEFAULT_KEYS.has(key) || key.startsWith('__');
11
+ /** `true` when `value` is a {@link LocalVarRef}. */
12
+ export const isLocalVarRef = (value) => Boolean(value &&
13
+ typeof value === 'object' &&
14
+ value.__kind === 'local-var-ref');
15
+ /** `true` when `value` is a {@link LocalVarDefaultMarker}. */
16
+ export const isLocalVarDefaultMarker = (value) => Boolean(value &&
17
+ typeof value === 'object' &&
18
+ value.__kind === 'local-var-default-marker');
19
+ /** `true` when `value` is a {@link LocalVarOverrideMarker}. */
20
+ export const isLocalVarOverrideMarker = (value) => Boolean(value &&
21
+ typeof value === 'object' &&
22
+ value.__kind === 'local-var-override-marker');
23
+ /** `true` when `value` is a {@link LocalVarDefaultMarker} or {@link LocalVarOverrideMarker}. */
24
+ export const isLocalVarMarker = (value) => isLocalVarDefaultMarker(value) || isLocalVarOverrideMarker(value);
25
+ const cssVarPath = (moduleName, group, key) => `vars/${moduleName}/${group}/${key}`;
26
+ const buildLocalVarRef = (path, propName) => {
27
+ const ref = `var(${propName})`;
28
+ const refToString = () => ref;
29
+ return {
30
+ __kind: 'local-var-ref',
31
+ path,
32
+ propName,
33
+ ref,
34
+ toString: refToString,
35
+ [Symbol.toPrimitive]: refToString,
36
+ };
37
+ };
38
+ const reservedKeyError = (key) => new Error(`t.vars(...) defaults key "${key}" is reserved. Reserved: ${[...RESERVED_DEFAULT_KEYS].join(', ')} plus any "__"-prefixed key.`);
39
+ export const createLocalVarGroup = (prefix, moduleName, group, defaults) => {
40
+ assertCssIdentSegment(group, 't.vars(...) group');
41
+ const groupId = `${moduleName}/${group}`;
42
+ const groupPath = `vars/${groupId}`;
43
+ const refs = new Map();
44
+ const defaultsList = [];
45
+ for (const [key, value] of Object.entries(defaults)) {
46
+ if (isReservedKey(key)) {
47
+ throw reservedKeyError(key);
48
+ }
49
+ assertCssIdentSegment(key, `t.vars("${group}") key`);
50
+ const path = cssVarPath(moduleName, group, key);
51
+ const propName = cssVarName(prefix, path);
52
+ refs.set(key, buildLocalVarRef(path, propName));
53
+ defaultsList.push({ key, path, propName, value });
54
+ }
55
+ const setOverrides = (overrides) => {
56
+ const list = [];
57
+ for (const [key, value] of Object.entries(overrides)) {
58
+ if (value === undefined) {
59
+ continue;
60
+ }
61
+ const ref = refs.get(key);
62
+ if (!ref) {
63
+ throw new Error(`t.vars("${group}").set: unknown key "${key}". Declared keys: ${defaultsList
64
+ .map((entry) => entry.key)
65
+ .join(', ')}.`);
66
+ }
67
+ list.push({ key, path: ref.path, propName: ref.propName, value });
68
+ }
69
+ return {
70
+ __kind: 'local-var-override-marker',
71
+ groupId,
72
+ overrides: list,
73
+ };
74
+ };
75
+ const group_ = {
76
+ __kind: 'local-var-default-marker',
77
+ groupId,
78
+ groupPath,
79
+ defaults: defaultsList,
80
+ set: setOverrides,
81
+ };
82
+ for (const [key, ref] of refs) {
83
+ Object.defineProperty(group_, key, {
84
+ value: ref,
85
+ enumerable: true,
86
+ writable: false,
87
+ configurable: false,
88
+ });
89
+ }
90
+ return group_;
91
+ };
92
+ //# sourceMappingURL=local_vars.js.map