@elastic/distillate 0.1.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 (49) hide show
  1. package/dist/cjs/collector.js +129 -58
  2. package/dist/cjs/collector.js.map +1 -1
  3. package/dist/cjs/dom_sink.js +2 -2
  4. package/dist/cjs/dom_sink.js.map +1 -1
  5. package/dist/cjs/emotion.js.map +1 -1
  6. package/dist/cjs/engine.js +24 -8
  7. package/dist/cjs/engine.js.map +1 -1
  8. package/dist/cjs/index.js +3 -1
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/sink.js +9 -0
  11. package/dist/cjs/sink.js.map +1 -0
  12. package/dist/collector.d.ts +18 -1
  13. package/dist/collector.d.ts.map +1 -1
  14. package/dist/collector.js +129 -58
  15. package/dist/collector.js.map +1 -1
  16. package/dist/dom_sink.d.ts +8 -12
  17. package/dist/dom_sink.d.ts.map +1 -1
  18. package/dist/dom_sink.js +2 -2
  19. package/dist/dom_sink.js.map +1 -1
  20. package/dist/emotion.d.ts +3 -6
  21. package/dist/emotion.d.ts.map +1 -1
  22. package/dist/emotion.js.map +1 -1
  23. package/dist/engine.d.ts +26 -1
  24. package/dist/engine.d.ts.map +1 -1
  25. package/dist/engine.js +24 -8
  26. package/dist/engine.js.map +1 -1
  27. package/dist/index.d.ts +3 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +2 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/sink.d.ts +16 -0
  32. package/dist/sink.d.ts.map +1 -0
  33. package/dist/sink.js +8 -0
  34. package/dist/sink.js.map +1 -0
  35. package/docs/concepts/collection.md +1 -1
  36. package/docs/getting-started/installation.md +5 -5
  37. package/docs/guides/react-renderer.md +45 -1
  38. package/docs/reference/api/emotion.md +58 -140
  39. package/docs/reference/api/index-1.md +452 -245
  40. package/docs/reference/api/testing.md +6 -6
  41. package/docs/reference/entry-points.md +18 -4
  42. package/docs/reference/okf-map.md +2 -1
  43. package/package.json +1 -1
  44. package/src/collector.ts +145 -59
  45. package/src/dom_sink.ts +9 -10
  46. package/src/emotion.ts +3 -6
  47. package/src/engine.ts +59 -9
  48. package/src/index.ts +14 -1
  49. package/src/sink.ts +25 -0
@@ -1,27 +1,23 @@
1
- import type { StyleSink } from './emotion.js';
2
- /** Minimal interface for a DOM `<style>` element. */
3
- export interface StyleElementLike {
4
- /** Current stylesheet text, or `null` before the first flush. */
5
- textContent: string | null;
6
- }
1
+ import type { StyleElementLike, StyleParentLike, StyleSink } from './sink.js';
2
+ export type { StyleElementLike, StyleParentLike } from './sink.js';
7
3
  /** Minimal interface for a DOM `Document` able to create and append style tags. */
8
4
  export interface DocumentLike {
9
5
  /** Creates a `<style>` element. */
10
6
  createElement(tagName: 'style'): StyleElementLike;
11
- /** Node that receives the created style element. */
12
- readonly head: {
13
- appendChild(node: StyleElementLike): void;
14
- };
7
+ /** Default parent for the created style element. */
8
+ readonly head: StyleParentLike;
15
9
  }
16
10
  /** Host document and optional flush scheduler for a `<style>` sink. */
17
11
  export interface CreateDomSinkOptions {
18
- /** The host document where the style element will be appended. */
12
+ /** Document that creates the style element. */
19
13
  document: DocumentLike;
14
+ /** Node that receives the style element, e.g. a `ShadowRoot`. Defaults to `document.head`. */
15
+ parent?: StyleParentLike;
20
16
  /** Defers the flush. Defaults to `queueMicrotask`. */
21
17
  schedule?: (flush: () => void) => void;
22
18
  }
23
19
  /**
24
20
  * One managed `<style>` element, rewritten on each flush.
25
21
  */
26
- export declare const createDomSink: ({ document, schedule, }: CreateDomSinkOptions) => StyleSink;
22
+ export declare const createDomSink: ({ document, parent, schedule, }: CreateDomSinkOptions) => StyleSink;
27
23
  //# sourceMappingURL=dom_sink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom_sink.d.ts","sourceRoot":"","sources":["../src/dom_sink.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,q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ACH,eAAO,MAAM,aAAa,GAAI,iCAI3B,oBAAoB,KAAG,SA2BzB,CAAC"}
package/dist/dom_sink.js CHANGED
@@ -7,7 +7,7 @@
7
7
  /**
8
8
  * One managed `<style>` element, rewritten on each flush.
9
9
  */
10
- export const createDomSink = ({ document, schedule = queueMicrotask, }) => {
10
+ export const createDomSink = ({ document, parent, schedule = queueMicrotask, }) => {
11
11
  let element = null;
12
12
  let dirty = false;
13
13
  let latestRender = null;
@@ -18,7 +18,7 @@ export const createDomSink = ({ document, schedule = queueMicrotask, }) => {
18
18
  }
19
19
  if (!element) {
20
20
  element = document.createElement('style');
21
- document.head.appendChild(element);
21
+ (parent ?? document.head).appendChild(element);
22
22
  }
23
23
  element.textContent = latestRender();
24
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"dom_sink.js","sourceRoot":"","sources":["../src/dom_sink.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0BH;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,QAAQ,EACR,QAAQ,GAAG,cAAc,GACJ,EAAa,EAAE;IACpC,IAAI,OAAO,GAA4B,IAAI,CAAC;IAC5C,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,YAAY,GAA0B,IAAI,CAAC;IAE/C,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,KAAK,GAAG,KAAK,CAAC;QACd,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC1C,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,CAAC,WAAW,GAAG,YAAY,EAAE,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,CAAC,MAAM;YACf,YAAY,GAAG,MAAM,CAAC;YACtB,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO;YACT,CAAC;YACD,KAAK,GAAG,IAAI,CAAC;YACb,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;KACF,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 type { StyleSink } from './emotion';\n\n/** Minimal interface for a DOM `<style>` element. */\nexport interface StyleElementLike {\n /** Current stylesheet text, or `null` before the first flush. */\n textContent: string | null;\n}\n\n/** Minimal interface for a DOM `Document` able to create and append style tags. */\nexport interface DocumentLike {\n /** Creates a `<style>` element. */\n createElement(tagName: 'style'): StyleElementLike;\n /** Node that receives the created style element. */\n readonly head: { appendChild(node: StyleElementLike): void };\n}\n\n/** Host document and optional flush scheduler for a `<style>` sink. */\nexport interface CreateDomSinkOptions {\n /** The host document where the style element will be appended. */\n document: DocumentLike;\n /** Defers the flush. Defaults to `queueMicrotask`. */\n schedule?: (flush: () => void) => void;\n}\n\n/**\n * One managed `<style>` element, rewritten on each flush.\n */\nexport const createDomSink = ({\n document,\n schedule = queueMicrotask,\n}: CreateDomSinkOptions): StyleSink => {\n let element: StyleElementLike | null = null;\n let dirty = false;\n let latestRender: (() => string) | null = null;\n\n const flush = (): void => {\n dirty = false;\n if (!latestRender) {\n return;\n }\n if (!element) {\n element = document.createElement('style');\n document.head.appendChild(element);\n }\n element.textContent = latestRender();\n };\n\n return {\n invalidate(render) {\n latestRender = render;\n if (dirty) {\n return;\n }\n dirty = true;\n schedule(flush);\n },\n };\n};\n"]}
1
+ {"version":3,"file":"dom_sink.js","sourceRoot":"","sources":["../src/dom_sink.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,QAAQ,EACR,MAAM,EACN,QAAQ,GAAG,cAAc,GACJ,EAAa,EAAE;IACpC,IAAI,OAAO,GAA4B,IAAI,CAAC;IAC5C,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,YAAY,GAA0B,IAAI,CAAC;IAE/C,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,KAAK,GAAG,KAAK,CAAC;QACd,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC1C,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,CAAC,WAAW,GAAG,YAAY,EAAE,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,CAAC,MAAM;YACf,YAAY,GAAG,MAAM,CAAC;YACtB,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO;YACT,CAAC;YACD,KAAK,GAAG,IAAI,CAAC;YACb,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;KACF,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 type { StyleElementLike, StyleParentLike, StyleSink } from './sink';\n\nexport type { StyleElementLike, StyleParentLike } from './sink';\n\n/** Minimal interface for a DOM `Document` able to create and append style tags. */\nexport interface DocumentLike {\n /** Creates a `<style>` element. */\n createElement(tagName: 'style'): StyleElementLike;\n /** Default parent for the created style element. */\n readonly head: StyleParentLike;\n}\n\n/** Host document and optional flush scheduler for a `<style>` sink. */\nexport interface CreateDomSinkOptions {\n /** Document that creates the style element. */\n document: DocumentLike;\n /** Node that receives the style element, e.g. a `ShadowRoot`. Defaults to `document.head`. */\n parent?: StyleParentLike;\n /** Defers the flush. Defaults to `queueMicrotask`. */\n schedule?: (flush: () => void) => void;\n}\n\n/**\n * One managed `<style>` element, rewritten on each flush.\n */\nexport const createDomSink = ({\n document,\n parent,\n schedule = queueMicrotask,\n}: CreateDomSinkOptions): StyleSink => {\n let element: StyleElementLike | null = null;\n let dirty = false;\n let latestRender: (() => string) | null = null;\n\n const flush = (): void => {\n dirty = false;\n if (!latestRender) {\n return;\n }\n if (!element) {\n element = document.createElement('style');\n (parent ?? document.head).appendChild(element);\n }\n element.textContent = latestRender();\n };\n\n return {\n invalidate(render) {\n latestRender = render;\n if (dirty) {\n return;\n }\n dirty = true;\n schedule(flush);\n },\n };\n};\n"]}
package/dist/emotion.d.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  import type { Distillery } from './engine.js';
2
+ import type { StyleSink } from './sink.js';
2
3
  import { type StyleHandle, type StylesModule } from './styles/index.js';
3
- export { createDomSink, type CreateDomSinkOptions, type DocumentLike, type StyleElementLike, } from './dom_sink.js';
4
- /** Receives stylesheet invalidation from Emotion compat modules. */
5
- export interface StyleSink {
6
- /** Marks the sink dirty. `render` produces the current stylesheet when it flushes. */
7
- invalidate(render: () => string): void;
8
- }
4
+ export { createDomSink, type CreateDomSinkOptions, type DocumentLike, type StyleElementLike, type StyleParentLike, } from './dom_sink.js';
5
+ export type { StyleSink } from './sink.js';
9
6
  /** Shared sink for Emotion compat modules on one registry. */
10
7
  export interface CreateEmotionOptions {
11
8
  /** Notified when a compat module registers. Shared across `createEmotion` calls on the same registry. */
@@ -1 +1 @@
1
- {"version":3,"file":"emotion.d.ts","sourceRoot":"","sources":["../src/emotion.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EAGL,KAAK,WAAW,EAEhB,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,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,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACjC,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 type { Distillery } from './engine';\nimport { contentHash64 } from './hash';\nimport { flattenTemplate, isHandleLike, type TemplateSlice } from './nesting';\nimport {\n globalStylesFromFlattened,\n pendingHandleFromFlattened,\n type StyleHandle,\n type StyleRegistry,\n type StylesModule,\n} from './styles';\n\nexport {\n createDomSink,\n type CreateDomSinkOptions,\n type DocumentLike,\n type StyleElementLike,\n} from './dom_sink';\n\n/** Receives stylesheet invalidation from Emotion compat modules. */\nexport interface StyleSink {\n /** Marks the sink dirty. `render` produces the current stylesheet when it flushes. */\n invalidate(render: () => string): void;\n}\n\n/** Shared sink for Emotion compat modules on one registry. */\nexport interface CreateEmotionOptions {\n /** Notified when a compat module registers. Shared across `createEmotion` calls on the same registry. */\n sink?: StyleSink;\n}\n\n/** Style handle that stringifies to its readable class name. */\nexport interface EmotionCss extends StyleHandle {\n /** Stringifies to the readable class name. */\n toString(): string;\n /** Template interpolation; same as {@link EmotionCss.toString}. */\n [Symbol.toPrimitive](hint: string): string;\n}\n\n/** One `cx(...)` argument: a class, handle, list, or truthy map. */\nexport type ClassNameArg =\n | string\n | number\n | false\n | null\n | undefined\n | EmotionCss\n | StyleHandle\n | ClassNameArg[]\n | { readonly [className: string]: boolean };\n\n/** Emotion-shaped authoring API bound to one Distillery registry. */\nexport interface Emotion {\n /** Authors styles and returns a handle that can be used directly or passed to `cx`. */\n css(strings: TemplateStringsArray, ...values: readonly unknown[]): EmotionCss;\n /** Combines handles, conditional classes, and plain strings into a space-separated string. */\n cx(...args: readonly ClassNameArg[]): string;\n /** Defines styles that apply globally (e.g. `body`, `html`). */\n injectGlobal(\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n ): void;\n /** Emits the full CSS for all generated emotion styles. */\n stylesheet(): string;\n /** Returns the underlying modules backing `injectGlobal` calls. */\n globalModules(): readonly StylesModule[];\n}\n\n/** Per-registry Emotion compat cache. */\ninterface EmotionState {\n /** `css` handles keyed by source hash. */\n readonly wrappers: Map<string, EmotionCss>;\n /** Original templates for inlining nested compat handles. */\n readonly rawSources: Map<string, TemplateSlice>;\n /** Module name → canonical source hash. */\n readonly canonicalByModule: Map<string, string>;\n /** Modules produced by `injectGlobal`. */\n readonly globals: StylesModule[];\n /** Handles created by this registry's Emotion instance. */\n readonly brand: WeakSet<object>;\n /** Sinks notified when a compat module registers. */\n readonly sinks: Set<StyleSink>;\n}\n\nconst stateByRegistry = new WeakMap<StyleRegistry, EmotionState>();\n\nconst stateFor = (registry: StyleRegistry): EmotionState => {\n let state = stateByRegistry.get(registry);\n if (!state) {\n state = {\n wrappers: new Map(),\n rawSources: new Map(),\n canonicalByModule: new Map(),\n globals: [],\n brand: new WeakSet(),\n sinks: new Set(),\n };\n stateByRegistry.set(registry, state);\n }\n return state;\n};\n\n/**\n * `@emotion/css`-shaped API over a distillery.\n *\n * `String(css\\`...\\`)` is the readable class name and does not collect. Passing the wrapper through `resolveClassName` collects and compacts like a native handle.\n *\n * @param distillery Bound distillery that owns the underlying registry.\n * @param options Optional sink for DOM injection.\n */\nexport const createEmotion = <TTokens>(\n distillery: Distillery<TTokens>,\n options: CreateEmotionOptions = {}\n): Emotion => {\n const { registry } = distillery;\n const state = stateFor(registry);\n\n const stylesheet = (): string =>\n distillery.renderStyles(distillery.stylesheetCollector('readable'));\n\n const invalidateSinks = (): void => {\n for (const sink of state.sinks) {\n sink.invalidate(stylesheet);\n }\n };\n\n if (options.sink) {\n state.sinks.add(options.sink);\n // Catch a late-attached sink up to styles already registered on this\n // registry: cached `css`/`injectGlobal` calls return early without\n // invalidating, so without this the managed `<style>` would miss every\n // style registered before the sink was attached.\n options.sink.invalidate(stylesheet);\n }\n\n const inlineValue = (\n value: unknown,\n position: 'selector' | 'statement'\n ): TemplateSlice | null => {\n if (position !== 'statement' || !isBranded(state, value)) {\n return null;\n }\n return state.rawSources.get((value as StyleHandle).key) ?? null;\n };\n\n const css = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n ): EmotionCss => {\n assertTemplate(strings, 'css');\n const hash = contentHash64(strings, values);\n const cached = state.wrappers.get(hash);\n if (cached) {\n return cached;\n }\n const moduleName = `css-${hash}`;\n const canonical = canonicalKey(strings, values);\n detectCollision(state, moduleName, canonical);\n\n const flat = flattenTemplate(strings, values, {\n mode: 'self',\n inlineValue,\n });\n const pending = pendingHandleFromFlattened(flat);\n const module = distillery.createStyleModule(moduleName, () => ({\n root: pending,\n }));\n const handle = module.handles.root;\n\n state.rawSources.set(handle.key, {\n strings: [...strings],\n values: [...values],\n });\n const wrapper = makeWrapper(handle);\n state.brand.add(wrapper);\n state.wrappers.set(hash, wrapper);\n state.canonicalByModule.set(moduleName, canonical);\n invalidateSinks();\n return wrapper;\n };\n\n const injectGlobal = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n ): void => {\n assertTemplate(strings, 'injectGlobal');\n const hash = contentHash64(strings, values);\n const moduleName = `global-${hash}`;\n if (registry.module(moduleName)) {\n return;\n }\n const canonical = canonicalKey(strings, values);\n detectCollision(state, moduleName, canonical);\n\n const flat = flattenTemplate(strings, values, {\n mode: 'global',\n inlineValue,\n });\n const module = distillery.createStyleModule(moduleName, () =>\n globalStylesFromFlattened(flat)\n );\n state.canonicalByModule.set(moduleName, canonical);\n state.globals.push(module);\n invalidateSinks();\n };\n\n const cx = (...args: readonly ClassNameArg[]): string => {\n const classes: string[] = [];\n const walk = (arg: ClassNameArg): void => {\n if (!arg) {\n return;\n }\n if (typeof arg === 'string') {\n classes.push(arg);\n return;\n }\n if (typeof arg === 'number') {\n classes.push(String(arg));\n return;\n }\n if (Array.isArray(arg)) {\n arg.forEach(walk);\n return;\n }\n if (isBranded(state, arg)) {\n classes.push(String(arg));\n return;\n }\n if (isHandleLike(arg)) {\n classes.push(arg.readableName);\n return;\n }\n for (const [className, enabled] of Object.entries(arg)) {\n if (enabled) {\n classes.push(className);\n }\n }\n };\n args.forEach(walk);\n return classes.join(' ');\n };\n\n return {\n css,\n cx,\n injectGlobal,\n stylesheet,\n globalModules: () => [...state.globals],\n };\n};\n\nconst makeWrapper = (handle: StyleHandle): EmotionCss => {\n const readable = handle.readableName;\n const asString = (): string => readable;\n // Spread copy keeps `resolveClassName` (closed over the original handle) and\n // `key` intact so collector dedupe and compaction work unchanged.\n const wrapper = { ...handle } as EmotionCss & {\n toString: () => string;\n [Symbol.toPrimitive]: () => string;\n };\n wrapper.toString = asString;\n wrapper[Symbol.toPrimitive] = asString;\n return wrapper;\n};\n\nconst isBranded = (state: EmotionState, value: unknown): value is EmotionCss =>\n Boolean(value && typeof value === 'object' && state.brand.has(value));\n\nconst assertTemplate = (strings: unknown, fn: string): void => {\n if (!Array.isArray(strings) || !('raw' in (strings as object))) {\n throw new Error(\n `${fn} is a template tag; object styles (${fn}({...})) are not supported.`\n );\n }\n};\n\nconst detectCollision = (\n state: EmotionState,\n moduleName: string,\n canonical: string\n): void => {\n const prior = state.canonicalByModule.get(moduleName);\n if (prior !== undefined && prior !== canonical) {\n throw new Error(\n `Content-hash collision for \"${moduleName}\"; two distinct templates hashed to the same name.`\n );\n }\n};\n\n// A cheap, exact collision tripwire independent of the (lossy) hash. NUL-joins\n// strings and String()s values — good enough because it is only ever compared\n// against another canonical string for the same module name.\nconst canonicalKey = (\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(String(values[index]));\n }\n });\n return segments.join('\\u0000');\n};\n"]}
1
+ {"version":3,"file":"emotion.js","sourceRoot":"","sources":["../src/emotion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA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C,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CACb,GAAG,EAAE,sCAAsC,EAAE,6BAA6B,CAC3E,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,KAAmB,EACnB,UAAkB,EAClB,SAAiB,EACX,EAAE;IACR,MAAM,KAAK,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACtD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACb,+BAA+B,UAAU,oDAAoD,CAC9F,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,+EAA+E;AAC/E,8EAA8E;AAC9E,6DAA6D;AAC7D,MAAM,YAAY,GAAG,CACnB,OAA0B,EAC1B,MAA0B,EAClB,EAAE;IACV,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC9B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACjC,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 type { Distillery } from './engine';\nimport { contentHash64 } from './hash';\nimport { flattenTemplate, isHandleLike, type TemplateSlice } from './nesting';\nimport type { StyleSink } from './sink';\nimport {\n globalStylesFromFlattened,\n pendingHandleFromFlattened,\n type StyleHandle,\n type StyleRegistry,\n type StylesModule,\n} from './styles';\n\nexport {\n createDomSink,\n type CreateDomSinkOptions,\n type DocumentLike,\n type StyleElementLike,\n type StyleParentLike,\n} from './dom_sink';\nexport type { StyleSink } from './sink';\n\n/** Shared sink for Emotion compat modules on one registry. */\nexport interface CreateEmotionOptions {\n /** Notified when a compat module registers. Shared across `createEmotion` calls on the same registry. */\n sink?: StyleSink;\n}\n\n/** Style handle that stringifies to its readable class name. */\nexport interface EmotionCss extends StyleHandle {\n /** Stringifies to the readable class name. */\n toString(): string;\n /** Template interpolation; same as {@link EmotionCss.toString}. */\n [Symbol.toPrimitive](hint: string): string;\n}\n\n/** One `cx(...)` argument: a class, handle, list, or truthy map. */\nexport type ClassNameArg =\n | string\n | number\n | false\n | null\n | undefined\n | EmotionCss\n | StyleHandle\n | ClassNameArg[]\n | { readonly [className: string]: boolean };\n\n/** Emotion-shaped authoring API bound to one Distillery registry. */\nexport interface Emotion {\n /** Authors styles and returns a handle that can be used directly or passed to `cx`. */\n css(strings: TemplateStringsArray, ...values: readonly unknown[]): EmotionCss;\n /** Combines handles, conditional classes, and plain strings into a space-separated string. */\n cx(...args: readonly ClassNameArg[]): string;\n /** Defines styles that apply globally (e.g. `body`, `html`). */\n injectGlobal(\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n ): void;\n /** Emits the full CSS for all generated emotion styles. */\n stylesheet(): string;\n /** Returns the underlying modules backing `injectGlobal` calls. */\n globalModules(): readonly StylesModule[];\n}\n\n/** Per-registry Emotion compat cache. */\ninterface EmotionState {\n /** `css` handles keyed by source hash. */\n readonly wrappers: Map<string, EmotionCss>;\n /** Original templates for inlining nested compat handles. */\n readonly rawSources: Map<string, TemplateSlice>;\n /** Module name → canonical source hash. */\n readonly canonicalByModule: Map<string, string>;\n /** Modules produced by `injectGlobal`. */\n readonly globals: StylesModule[];\n /** Handles created by this registry's Emotion instance. */\n readonly brand: WeakSet<object>;\n /** Sinks notified when a compat module registers. */\n readonly sinks: Set<StyleSink>;\n}\n\nconst stateByRegistry = new WeakMap<StyleRegistry, EmotionState>();\n\nconst stateFor = (registry: StyleRegistry): EmotionState => {\n let state = stateByRegistry.get(registry);\n if (!state) {\n state = {\n wrappers: new Map(),\n rawSources: new Map(),\n canonicalByModule: new Map(),\n globals: [],\n brand: new WeakSet(),\n sinks: new Set(),\n };\n stateByRegistry.set(registry, state);\n }\n return state;\n};\n\n/**\n * `@emotion/css`-shaped API over a distillery.\n *\n * `String(css\\`...\\`)` is the readable class name and does not collect. Passing the wrapper through `resolveClassName` collects and compacts like a native handle.\n *\n * @param distillery Bound distillery that owns the underlying registry.\n * @param options Optional sink for DOM injection.\n */\nexport const createEmotion = <TTokens>(\n distillery: Distillery<TTokens>,\n options: CreateEmotionOptions = {}\n): Emotion => {\n const { registry } = distillery;\n const state = stateFor(registry);\n\n const stylesheet = (): string =>\n distillery.renderStyles(distillery.stylesheetCollector('readable'));\n\n const invalidateSinks = (): void => {\n for (const sink of state.sinks) {\n sink.invalidate(stylesheet);\n }\n };\n\n if (options.sink) {\n state.sinks.add(options.sink);\n // Catch a late-attached sink up to styles already registered on this\n // registry: cached `css`/`injectGlobal` calls return early without\n // invalidating, so without this the managed `<style>` would miss every\n // style registered before the sink was attached.\n options.sink.invalidate(stylesheet);\n }\n\n const inlineValue = (\n value: unknown,\n position: 'selector' | 'statement'\n ): TemplateSlice | null => {\n if (position !== 'statement' || !isBranded(state, value)) {\n return null;\n }\n return state.rawSources.get((value as StyleHandle).key) ?? null;\n };\n\n const css = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n ): EmotionCss => {\n assertTemplate(strings, 'css');\n const hash = contentHash64(strings, values);\n const cached = state.wrappers.get(hash);\n if (cached) {\n return cached;\n }\n const moduleName = `css-${hash}`;\n const canonical = canonicalKey(strings, values);\n detectCollision(state, moduleName, canonical);\n\n const flat = flattenTemplate(strings, values, {\n mode: 'self',\n inlineValue,\n });\n const pending = pendingHandleFromFlattened(flat);\n const module = distillery.createStyleModule(moduleName, () => ({\n root: pending,\n }));\n const handle = module.handles.root;\n\n state.rawSources.set(handle.key, {\n strings: [...strings],\n values: [...values],\n });\n const wrapper = makeWrapper(handle);\n state.brand.add(wrapper);\n state.wrappers.set(hash, wrapper);\n state.canonicalByModule.set(moduleName, canonical);\n invalidateSinks();\n return wrapper;\n };\n\n const injectGlobal = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n ): void => {\n assertTemplate(strings, 'injectGlobal');\n const hash = contentHash64(strings, values);\n const moduleName = `global-${hash}`;\n if (registry.module(moduleName)) {\n return;\n }\n const canonical = canonicalKey(strings, values);\n detectCollision(state, moduleName, canonical);\n\n const flat = flattenTemplate(strings, values, {\n mode: 'global',\n inlineValue,\n });\n const module = distillery.createStyleModule(moduleName, () =>\n globalStylesFromFlattened(flat)\n );\n state.canonicalByModule.set(moduleName, canonical);\n state.globals.push(module);\n invalidateSinks();\n };\n\n const cx = (...args: readonly ClassNameArg[]): string => {\n const classes: string[] = [];\n const walk = (arg: ClassNameArg): void => {\n if (!arg) {\n return;\n }\n if (typeof arg === 'string') {\n classes.push(arg);\n return;\n }\n if (typeof arg === 'number') {\n classes.push(String(arg));\n return;\n }\n if (Array.isArray(arg)) {\n arg.forEach(walk);\n return;\n }\n if (isBranded(state, arg)) {\n classes.push(String(arg));\n return;\n }\n if (isHandleLike(arg)) {\n classes.push(arg.readableName);\n return;\n }\n for (const [className, enabled] of Object.entries(arg)) {\n if (enabled) {\n classes.push(className);\n }\n }\n };\n args.forEach(walk);\n return classes.join(' ');\n };\n\n return {\n css,\n cx,\n injectGlobal,\n stylesheet,\n globalModules: () => [...state.globals],\n };\n};\n\nconst makeWrapper = (handle: StyleHandle): EmotionCss => {\n const readable = handle.readableName;\n const asString = (): string => readable;\n // Spread copy keeps `resolveClassName` (closed over the original handle) and\n // `key` intact so collector dedupe and compaction work unchanged.\n const wrapper = { ...handle } as EmotionCss & {\n toString: () => string;\n [Symbol.toPrimitive]: () => string;\n };\n wrapper.toString = asString;\n wrapper[Symbol.toPrimitive] = asString;\n return wrapper;\n};\n\nconst isBranded = (state: EmotionState, value: unknown): value is EmotionCss =>\n Boolean(value && typeof value === 'object' && state.brand.has(value));\n\nconst assertTemplate = (strings: unknown, fn: string): void => {\n if (!Array.isArray(strings) || !('raw' in (strings as object))) {\n throw new Error(\n `${fn} is a template tag; object styles (${fn}({...})) are not supported.`\n );\n }\n};\n\nconst detectCollision = (\n state: EmotionState,\n moduleName: string,\n canonical: string\n): void => {\n const prior = state.canonicalByModule.get(moduleName);\n if (prior !== undefined && prior !== canonical) {\n throw new Error(\n `Content-hash collision for \"${moduleName}\"; two distinct templates hashed to the same name.`\n );\n }\n};\n\n// A cheap, exact collision tripwire independent of the (lossy) hash. NUL-joins\n// strings and String()s values — good enough because it is only ever compared\n// against another canonical string for the same module name.\nconst canonicalKey = (\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(String(values[index]));\n }\n });\n return segments.join('\\u0000');\n};\n"]}
package/dist/engine.d.ts CHANGED
@@ -2,8 +2,31 @@ import { StylesCollector, type StylesCollectorOptions } from './collector.js';
2
2
  import type { DistilleryEnvironment, DistilleryOptions, ThemeVarDefinition } from './environment.js';
3
3
  import { type StyleNameMode, type StyleNameResolver, type StyleNameResolverOptions } from './names.js';
4
4
  import { type RenderStylesOptions } from './runtime.js';
5
- import { type PrimitiveStyleAuthoringApi, type ResolvedStyles, type StyleAuthoringApi, StyleRegistry, type StylesModule, type StylesObject } from './styles/index.js';
5
+ import type { StyleSink } from './sink.js';
6
+ import { type PrimitiveStyleAuthoringApi, type ResolvedStyles, type StyleAuthoringApi, type StyleHandle, StyleRegistry, type StylesModule, type StylesObject } from './styles/index.js';
6
7
  import { type ThemeTree, type TokensOf, type ValuesOf } from './theme.js';
8
+ /** Sink, render options, and warning sink for {@link Distillery.liveCollection}. */
9
+ export interface LiveCollectionOptions {
10
+ /** Invalidated whenever the collection grows. Nothing is written before the first handle. */
11
+ sink?: StyleSink;
12
+ /** Options forwarded to `renderStyles` by `css()`. */
13
+ render?: RenderStylesOptions;
14
+ /** Warning sink for no-op handles. Used only when the distillery has `dev: true`. */
15
+ warn?: (message: string) => void;
16
+ }
17
+ /**
18
+ * Readable collection filled by one live render.
19
+ *
20
+ * Readable only: compact names depend on the complete collected set and need two passes.
21
+ */
22
+ export interface LiveCollection {
23
+ /** Underlying readable artifact collector. Mutations here (e.g. `use(globalModule)`, `useThemeVar`) also invalidate the sink. */
24
+ readonly collector: StylesCollector;
25
+ /** Collects `handles` and returns their readable class names, space-separated. */
26
+ readonly resolveClassName: (...handles: StyleHandle[]) => string;
27
+ /** Renders the CSS collected so far. */
28
+ readonly css: () => string;
29
+ }
7
30
  /** One component library's binding: environment, registry, and pre-bound operations. Destructure-safe (no `this`). */
8
31
  export interface Distillery<TTokens = unknown, TTheme extends ThemeTree = ThemeTree> {
9
32
  /** Resolved environment (tokens, prefix, derived theme vars). */
@@ -26,6 +49,8 @@ export interface Distillery<TTokens = unknown, TTheme extends ThemeTree = ThemeT
26
49
  readonly artifactCollector: (names: StyleNameMode, options?: Pick<StylesCollectorOptions, 'warn'>) => StylesCollector;
27
50
  /** Collector preloaded with every registered module. No-op warnings require `dev: true`; pass `{ warn }` to capture them. */
28
51
  readonly stylesheetCollector: (names?: StyleNameMode, options?: Pick<StylesCollectorOptions, 'warn'>) => StylesCollector;
52
+ /** Readable collection for one live render; keeps `sink` current as handles resolve. */
53
+ readonly liveCollection: (options?: LiveCollectionOptions) => LiveCollection;
29
54
  /** Emits collected CSS for this environment. */
30
55
  readonly renderStyles: (collector: StylesCollector, resolver?: StyleNameResolver, options?: RenderStylesOptions) => string;
31
56
  /** Creates a standalone name resolver using this distillery's prefix. */
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,K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KAC3C,eAAe,CAAC;IACrB,wFAAwF;IACxF,QAAQ,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,qBAAqB,KAAK,cAAc,CAAC;IAC7E,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,CACrB,SAAS,EAAE,eAAe,EAC1B,QAAQ,CAAC,EAAE,iBAAiB,EAC5B,OAAO,CAAC,EAAE,mBAAmB,KAC1B,MAAM,CAAC;IACZ,yEAAyE;IACzE,QAAQ,CAAC,kBAAkB,EAAE,CAC3B,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,QAAQ,CAAC,KAC9C,iBAAiB,CAAC;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,CAAC,MAAM,SAAS,SAAS,EAC7D,SAAS,iBAAiB,CAAC,MAAM,CAAC,KACjC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CA+GrC,CAAC"}
package/dist/engine.js CHANGED
@@ -35,6 +35,14 @@ export const createDistillery = (options) => {
35
35
  : {}),
36
36
  };
37
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
+ });
38
46
  return {
39
47
  environment,
40
48
  tokens,
@@ -46,14 +54,7 @@ export const createDistillery = (options) => {
46
54
  dev,
47
55
  createStyleModule: (name, factory) => createStyleModuleWithEnvironment(environment, registry, name, factory),
48
56
  primitiveStyles: (name, factory) => createStyleModuleWithEnvironment(environment, registry, name, ({ css: style, tokens: moduleTokens }) => factory({ style, tokens: moduleTokens })),
49
- artifactCollector: (names, options) => new StylesCollector({
50
- target: 'artifact',
51
- names,
52
- registry,
53
- prefix,
54
- dev,
55
- ...(options?.warn ? { warn: options.warn } : {}),
56
- }),
57
+ artifactCollector,
57
58
  stylesheetCollector: (names = 'readable', options) => {
58
59
  const collector = new StylesCollector({
59
60
  target: 'stylesheet',
@@ -68,6 +69,21 @@ export const createDistillery = (options) => {
68
69
  }
69
70
  return collector;
70
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
+ },
71
87
  renderStyles: (collector, resolver, renderOptions) => renderStyles(environment, collector, resolver, renderOptions),
72
88
  createNameResolver: (resolverOptions) => createStyleNameResolver({ ...resolverOptions, prefix }),
73
89
  };
@@ -1 +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;AACnE,OAAO,EACL,gCAAgC,EAEhC,gCAAgC,EAGhC,aAAa,GAGd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,GAIvB,MAAM,SAAS,CAAC;AAsDjB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAAkC,EACI,EAAE;IACxC,MAAM,EACJ,MAAM,EACN,UAAU,EACV,KAAK,EACL,UAAU,EAAE,aAAa,EACzB,UAAU,EACV,GAAG,GAAG,KAAK,GACZ,GAAG,OAAO,CAAC;IACZ,qB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a,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 {\n createStyleModuleWithEnvironment,\n type PrimitiveStyleAuthoringApi,\n readableVarOwnersFromEnvironment,\n type ResolvedStyles,\n type StyleAuthoringApi,\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/** 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 /** 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 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: (names, options) =>\n new StylesCollector({\n target: 'artifact',\n names,\n registry,\n prefix,\n dev,\n ...(options?.warn ? { warn: options.warn } : {}),\n }),\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 renderStyles: (collector, resolver, renderOptions) =>\n renderStyles(environment, collector, resolver, renderOptions),\n createNameResolver: (resolverOptions) =>\n createStyleNameResolver({ ...resolverOptions, prefix }),\n };\n};\n"]}
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,E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AAE,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"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export { createDistillery, type Distillery } from './engine.js';
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';
2
4
  export { type DistilleryEnvironment, type DistilleryOptions, type ThemeVarDefinition, } from './environment.js';
3
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';
4
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';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","s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,KAAK,UAAU,EACf,KAAK,UAAU,GAChB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,WAAW,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,cAAc,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,GAAG,EACH,KAAK,EACL,SAAS,EACT,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,0BAA0B,EAC/B,KAAK,cAAc,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 CHANGED
@@ -4,7 +4,8 @@
4
4
  * 2.0; you may not use this file except in compliance with the Elastic License
5
5
  * 2.0.
6
6
  */
7
- export { createDistillery } from './engine.js';
7
+ export { createDistillery, } from './engine.js';
8
+ export { createDomSink, } from './dom_sink.js';
8
9
  export { resolveThemeValues, zipSchemes, } from './theme.js';
9
10
  export { contextualVar, cq, isContextualCssVar, isContextualCssVarName, isCssToken, isScaleToken, lightDark, scaleToken, themeToken, } from './tokens/index.js';
10
11
  export { createStyleNameResolver, cssVarName, } from './names.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAmB,MAAM,UAAU,CAAC;AAM7D,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 { createDistillery, type Distillery } from './engine';\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"]}
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"]}
package/dist/sink.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /** Receives stylesheet invalidation from a live collection or Emotion compat modules. */
2
+ export interface StyleSink {
3
+ /** Marks the sink dirty. `render` produces the current stylesheet when it flushes. */
4
+ invalidate(render: () => string): void;
5
+ }
6
+ /** Minimal interface for a DOM `<style>` element. */
7
+ export interface StyleElementLike {
8
+ /** Current stylesheet text, or `null` before the first flush. */
9
+ textContent: string | null;
10
+ }
11
+ /** Node that receives a managed `<style>` element, e.g. `document.head` or a `ShadowRoot`. */
12
+ export interface StyleParentLike {
13
+ /** Appends the managed style element. */
14
+ appendChild(node: StyleElementLike): void;
15
+ }
16
+ //# sourceMappingURL=sink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../src/sink.ts"],"names":[],"mappings":"AAOA,yFAAyF;AACzF,MAAM,WAAW,SAAS;IACxB,sFAAsF;IACtF,UAAU,CAAC,MAAM,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,iEAAiE;IACjE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,8FAA8F;AAC9F,MAAM,WAAW,eAAe;IAE9B,yCAAyC;IACzC,WAAW,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAC3C"}
package/dist/sink.js ADDED
@@ -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=sink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sink.js","sourceRoot":"","sources":["../src/sink.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\n/** Receives stylesheet invalidation from a live collection or Emotion compat modules. */\nexport interface StyleSink {\n /** Marks the sink dirty. `render` produces the current stylesheet when it flushes. */\n invalidate(render: () => string): void;\n}\n\n/** Minimal interface for a DOM `<style>` element. */\nexport interface StyleElementLike {\n /** Current stylesheet text, or `null` before the first flush. */\n textContent: string | null;\n}\n\n/** Node that receives a managed `<style>` element, e.g. `document.head` or a `ShadowRoot`. */\nexport interface StyleParentLike {\n // Method syntax (bivariant) so DOM `Node.appendChild<T extends Node>` assigns.\n /** Appends the managed style element. */\n appendChild(node: StyleElementLike): void;\n}\n"]}
@@ -23,7 +23,7 @@ const css = distillery.renderStyles(collector);
23
23
  | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
24
24
  | `use(module)` | Non-variant entries on the module. Variants stay out. |
25
25
  | `use(entry)` | One handle, rule, or media block. |
26
- | `useHandles(handles)` | Those handles, then any `auto` rule or media-inner-rule whose selector deps are all present. Media blocks include only the live inner rules. |
26
+ | `useHandles(handles)` | Those handles, then any `auto` rule or media-inner-rule whose deps are all present. Media blocks keep inner rules collected earlier. |
27
27
  | `useAllEntries(module)` | Every entry, including variants. Used by the stylesheet target. |
28
28
  | `useThemeVar(path)` | Marks a theme token path reachable even if no collected declaration reads it. |
29
29
 
@@ -17,11 +17,11 @@ The primary build is ESM (`"type": "module"`), reached through the `import` expo
17
17
 
18
18
  ## Entry points
19
19
 
20
- | Specifier | Use |
21
- | ----------------------------- | ------------------------------------------------ |
22
- | `@elastic/distillate` | Engine, authoring, tokens, collector, renderer. |
23
- | `@elastic/distillate/emotion` | `createEmotion`, `createDomSink`. |
24
- | `@elastic/distillate/testing` | Var-invariant helpers. Does not import `stylis`. |
20
+ | Specifier | Use |
21
+ | ----------------------------- | ---------------------------------------------------------------- |
22
+ | `@elastic/distillate` | Engine, authoring, tokens, collector, renderer, `createDomSink`. |
23
+ | `@elastic/distillate/emotion` | `createEmotion`, `createDomSink`. |
24
+ | `@elastic/distillate/testing` | Var-invariant helpers. Does not import `stylis`. |
25
25
 
26
26
  The root and emotion entries both reach `stylis@4.4.0`. Do not hoist a different stylis version; nested templates walk a pinned `compile()` tree shape.
27
27
 
@@ -135,7 +135,7 @@ export const renderArtifact = (
135
135
  renderArtifact(<Button>Hello</Button>, distillery);
136
136
  ```
137
137
 
138
- A readable artifact (`artifactCollector('readable')`) can skip the emitting pass because `handle.readableName` does not depend on the collected set. See [Ship a compact artifact](compact-artifacts.md).
138
+ A readable artifact can skip the emitting pass because `handle.readableName` does not depend on the collected set. For a live tree, use [a live readable collection](#live-readable-collection-shadow-root). See [Ship a compact artifact](compact-artifacts.md).
139
139
 
140
140
  ### Include `injectGlobal` styles
141
141
 
@@ -156,3 +156,47 @@ renderArtifact(<Button>Hello</Button>, distillery, globalModules());
156
156
  ```
157
157
 
158
158
  Do not mix a compact stylesheet with markup that used `readableName`. The DOM will carry `.button-root` while the `<style>` contains `.a`.
159
+
160
+ ## Live readable collection (shadow root)
161
+
162
+ A host that renders into a shadow root, or any isolated root, needs only the CSS that tree resolves. Readable names do not depend on the collected set, so one live render is enough. `distillery.liveCollection()` returns `{ resolveClassName, css, collector }`, which already fits the class-name context above:
163
+
164
+ ```tsx
165
+ import { createDomSink } from '@elastic/distillate';
166
+ import { useState } from 'react';
167
+ import { createPortal } from 'react-dom';
168
+
169
+ export const ShadowStyles = ({
170
+ root,
171
+ children,
172
+ }: {
173
+ root: ShadowRoot;
174
+ children: ReactNode;
175
+ }) => {
176
+ const [live] = useState(() =>
177
+ distillery.liveCollection({
178
+ sink: createDomSink({ document: root.ownerDocument, parent: root }),
179
+ })
180
+ );
181
+ return (
182
+ <StyleContext.Provider value={live}>
183
+ {createPortal(children, root)}
184
+ </StyleContext.Provider>
185
+ );
186
+ };
187
+ ```
188
+
189
+ Every handle, rule, or theme var the collection has not seen invalidates the sink. The sink rewrites its one `<style>` in a microtask, which lands before paint. A subtree that suspends and resolves later adds its handles and triggers another flush, so there is no "collection finished" moment to guess.
190
+
191
+ Add globals and extra theme vars through `live.collector`; they invalidate the sink the same way:
192
+
193
+ ```tsx
194
+ for (const module of globalModules()) {
195
+ live.collector.use(module);
196
+ }
197
+ live.collector.useThemeVar('colors/ink');
198
+ ```
199
+
200
+ `css()` returns the CSS collected so far, for a host that writes it elsewhere. Pass `{ render }` to forward `renderStyles` options such as `scheme` or `alternates`.
201
+
202
+ The collection only grows. A render React discards may leave extra CSS, never missing CSS. Compact names depend on the complete collected set, so a live collection is readable only; compact artifacts still [render twice](#render-twice).