@elmethis/core 0.24.0 → 0.24.1

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.
package/dist/index.mjs CHANGED
@@ -561,8 +561,15 @@ function inlineZod(schema) {
561
561
  });
562
562
  return rest;
563
563
  }
564
- const FINGERPRINT_TO_REF = /* @__PURE__ */ new Map();
565
- for (const [name, schema] of COMMON_BY_REF) FINGERPRINT_TO_REF.set(fingerprint(inlineZod(schema)), name);
564
+ let fingerprintToRef;
565
+ function getFingerprintToRef() {
566
+ if (fingerprintToRef === void 0) {
567
+ const refs = /* @__PURE__ */ new Map();
568
+ for (const [name, schema] of COMMON_BY_REF) refs.set(fingerprint(inlineZod(schema)), name);
569
+ fingerprintToRef = refs;
570
+ }
571
+ return fingerprintToRef;
572
+ }
566
573
  /**
567
574
  * Walks a JSON Schema subtree. Whenever it finds a node whose structural
568
575
  * fingerprint matches a registered common type, it replaces that node with
@@ -574,7 +581,7 @@ function collapseCommonRefs(node) {
574
581
  if (Array.isArray(node)) return node.map(collapseCommonRefs);
575
582
  if (!node || typeof node !== "object") return node;
576
583
  const obj = node;
577
- const refName = FINGERPRINT_TO_REF.get(fingerprint(obj));
584
+ const refName = getFingerprintToRef().get(fingerprint(obj));
578
585
  if (refName !== void 0) {
579
586
  const description = obj.description;
580
587
  return description !== void 0 ? {
@@ -588,7 +595,8 @@ function collapseCommonRefs(node) {
588
595
  }
589
596
  const FACTORED_OUT_KEYS = /* @__PURE__ */ new Set(["accessibility", "weight"]);
590
597
  function buildComponentSchema(api) {
591
- const inner = zodToJsonSchema(z.object({ x: api.schema }), {
598
+ const wrapped = z.object({ x: api.schema });
599
+ const inner = zodToJsonSchema(wrapped, {
592
600
  $refStrategy: "none",
593
601
  target: "jsonSchema7"
594
602
  }).properties?.x ?? {};
@@ -643,13 +651,14 @@ function assembleCatalog(envelope, components) {
643
651
  /**
644
652
  * Method A — runtime catalog constant.
645
653
  *
646
- * Assembles the Notion block catalog from the `*Api` Zod definitions into a
647
- * freestanding A2UI v0.9 catalog JSON Schema document. Consumers that want
648
- * the catalog at runtime (e.g. to feed into an LLM system prompt or to
649
- * validate an inbound A2UI message) import `notionBlockCatalogJson` directly.
654
+ * Exposes the Notion block catalog as a freestanding A2UI v0.9 JSON Schema
655
+ * document. Assembly is deferred until `components` or `$defs` is accessed,
656
+ * so consumers importing only metadata do not run schema generation.
657
+ * Consumers that need the schema at runtime (e.g. for an LLM system prompt
658
+ * or inbound message validation) can serialize this object normally.
650
659
  *
651
660
  * Consumers that want the document as a hostable artifact use Method B:
652
- * `dist/a2ui/notion_block_catalog.json` is emitted at build time from this
661
+ * `dist/a2ui/v0_9/notion_block_catalog.json` is emitted at build time from this
653
662
  * same constant and is served at the URL identified by
654
663
  * `NOTION_BLOCK_CATALOG_ID`.
655
664
  */
@@ -659,11 +668,7 @@ function assembleCatalog(envelope, components) {
659
668
  * third-party agents and validators that look up `catalogId`.
660
669
  */
661
670
  const NOTION_BLOCK_CATALOG_ID = "https://46ki75.github.io/elmethis/a2ui/v0_9/notion_block_catalog.json";
662
- const notionBlockCatalogJson = assembleCatalog({
663
- id: NOTION_BLOCK_CATALOG_ID,
664
- title: "Elmethis Notion Block Catalog",
665
- description: "Notion block-level A2UI components used by the @elmethis renderers (typography, media, code, math, table, tabs). Extends — does not replace — the A2UI Basic Catalog."
666
- }, [
671
+ const NOTION_BLOCK_CATALOG_COMPONENTS = [
667
672
  RichTextApi,
668
673
  LinkTextApi,
669
674
  IconApi,
@@ -694,7 +699,35 @@ const notionBlockCatalogJson = assembleCatalog({
694
699
  TableRowApi,
695
700
  TableCellApi,
696
701
  UnsupportedApi
697
- ]);
702
+ ];
703
+ const envelope = {
704
+ id: NOTION_BLOCK_CATALOG_ID,
705
+ title: "Elmethis Notion Block Catalog",
706
+ description: "Notion block-level A2UI components used by the @elmethis renderers (typography, media, code, math, table, tabs). Extends — does not replace — the A2UI Basic Catalog."
707
+ };
708
+ let assembledCatalog;
709
+ function getCatalog() {
710
+ return assembledCatalog ??= assembleCatalog(envelope, NOTION_BLOCK_CATALOG_COMPONENTS);
711
+ }
712
+ const notionBlockCatalogJson = {
713
+ $schema: "https://json-schema.org/draft/2020-12/schema",
714
+ $id: envelope.id,
715
+ catalogId: envelope.id,
716
+ title: envelope.title,
717
+ description: envelope.description,
718
+ get components() {
719
+ return getCatalog().components;
720
+ },
721
+ set components(value) {
722
+ getCatalog().components = value;
723
+ },
724
+ get $defs() {
725
+ return getCatalog().$defs;
726
+ },
727
+ set $defs(value) {
728
+ getCatalog().$defs = value;
729
+ }
730
+ };
698
731
  //#endregion
699
732
  //#region src/icon/languages/registry.ts
700
733
  /**
package/dist/tokens.cjs CHANGED
@@ -1,47 +1,76 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/style/color-scale.ts
3
+ const parseHex = (hex) => {
4
+ if (!/^#[\da-f]{6}$/i.test(hex)) throw new Error(`Expected a six-digit hex color, received ${hex}`);
5
+ return [
6
+ Number.parseInt(hex.slice(1, 3), 16) / 255,
7
+ Number.parseInt(hex.slice(3, 5), 16) / 255,
8
+ Number.parseInt(hex.slice(5, 7), 16) / 255
9
+ ];
10
+ };
11
+ const srgbToLinear = (channel) => channel <= .04045 ? channel / 12.92 : ((channel + .055) / 1.055) ** 2.4;
12
+ const linearToSrgb = (channel) => channel <= .0031308 ? channel * 12.92 : 1.055 * channel ** (1 / 2.4) - .055;
13
+ const hexToOklab = (hex) => {
14
+ const [encodedRed, encodedGreen, encodedBlue] = parseHex(hex);
15
+ const red = srgbToLinear(encodedRed);
16
+ const green = srgbToLinear(encodedGreen);
17
+ const blue = srgbToLinear(encodedBlue);
18
+ const lightness = Math.cbrt(.4122214708 * red + .5363325363 * green + .0514459929 * blue);
19
+ const medium = Math.cbrt(.2119034982 * red + .6806995451 * green + .1073969566 * blue);
20
+ const short = Math.cbrt(.0883024619 * red + .2817188376 * green + .6299787005 * blue);
21
+ return [
22
+ .2104542553 * lightness + .793617785 * medium - .0040720468 * short,
23
+ 1.9779984951 * lightness - 2.428592205 * medium + .4505937099 * short,
24
+ .0259040371 * lightness + .7827717662 * medium - .808675766 * short
25
+ ];
26
+ };
27
+ const oklabToHex = ([lightness, a, b]) => {
28
+ const light = (lightness + .3963377774 * a + .2158037573 * b) ** 3;
29
+ const medium = (lightness - .1055613458 * a - .0638541728 * b) ** 3;
30
+ const short = (lightness - .0894841775 * a - 1.291485548 * b) ** 3;
31
+ return `#${[
32
+ 4.0767416621 * light - 3.3077115913 * medium + .2309699292 * short,
33
+ -1.2684380046 * light + 2.6097574011 * medium - .3413193965 * short,
34
+ -.0041960863 * light - .7034186147 * medium + 1.707614701 * short
35
+ ].map(linearToSrgb).map((channel) => Math.min(1, Math.max(0, channel))).map((channel) => Math.round(channel * 255).toString(16).padStart(2, "0")).join("")}`;
36
+ };
37
+ const interpolateOklab = (start, end, amount) => oklabToHex([
38
+ start[0] + (end[0] - start[0]) * amount,
39
+ start[1] + (end[1] - start[1]) * amount,
40
+ start[2] + (end[2] - start[2]) * amount
41
+ ]);
42
+ /**
43
+ * Expands the authored 100/500/900 anchors into a perceptually even ramp.
44
+ * OKLab avoids the muddy midpoints produced by interpolating encoded sRGB.
45
+ */
46
+ const createColorScale = (light, middle, dark) => {
47
+ const lightOklab = hexToOklab(light);
48
+ const middleOklab = hexToOklab(middle);
49
+ const darkOklab = hexToOklab(dark);
50
+ return {
51
+ 100: light.toLowerCase(),
52
+ 200: interpolateOklab(lightOklab, middleOklab, .25),
53
+ 300: interpolateOklab(lightOklab, middleOklab, .5),
54
+ 400: interpolateOklab(lightOklab, middleOklab, .75),
55
+ 500: middle.toLowerCase(),
56
+ 600: interpolateOklab(middleOklab, darkOklab, .25),
57
+ 700: interpolateOklab(middleOklab, darkOklab, .5),
58
+ 800: interpolateOklab(middleOklab, darkOklab, .75),
59
+ 900: dark.toLowerCase()
60
+ };
61
+ };
62
+ //#endregion
2
63
  //#region src/style/token.ts
3
64
  const PRIMITIVE_VALUES = {
4
65
  color: {
5
- red: {
6
- 100: "#e9dddd",
7
- 500: "#ae6e6e",
8
- 900: "#291313"
9
- },
10
- orange: {
11
- 100: "#ebdfdb",
12
- 500: "#b8816e",
13
- 900: "#3f251c"
14
- },
15
- yellow: {
16
- 100: "#ebe6db",
17
- 500: "#b09a66",
18
- 900: "#332b19"
19
- },
20
- green: {
21
- 100: "#dde9e2",
22
- 500: "#659878",
23
- 900: "#15281d"
24
- },
25
- cyan: {
26
- 100: "#dde9e7",
27
- 500: "#6091a0",
28
- 900: "#203b37"
29
- },
30
- blue: {
31
- 100: "#dde2e9",
32
- 500: "#68779f",
33
- 900: "#242d3e"
34
- },
35
- purple: {
36
- 100: "#e3dde9",
37
- 500: "#8d799f",
38
- 900: "#271836"
39
- },
40
- magenta: {
41
- 100: "#eadce4",
42
- 500: "#b17396",
43
- 900: "#3c1f2f"
44
- },
66
+ red: createColorScale("#e9dddd", "#ae6e6e", "#291313"),
67
+ orange: createColorScale("#ebdfdb", "#b8816e", "#3f251c"),
68
+ yellow: createColorScale("#ebe6db", "#b09a66", "#332b19"),
69
+ green: createColorScale("#dde9e2", "#659878", "#15281d"),
70
+ cyan: createColorScale("#dde9e7", "#6091a0", "#203b37"),
71
+ blue: createColorScale("#dde2e9", "#68779f", "#242d3e"),
72
+ purple: createColorScale("#e3dde9", "#8d799f", "#271836"),
73
+ magenta: createColorScale("#eadce4", "#b17396", "#3c1f2f"),
45
74
  slate: {
46
75
  100: "#d7d9e1",
47
76
  200: "#b0b5be",
package/dist/tokens.css CHANGED
@@ -1,27 +1,75 @@
1
1
  :root {
2
2
  --elmethis-primitive-color-red-100: #e9dddd;
3
+ --elmethis-primitive-color-red-200: #dbc1c0;
4
+ --elmethis-primitive-color-red-300: #cda5a4;
5
+ --elmethis-primitive-color-red-400: #be8989;
3
6
  --elmethis-primitive-color-red-500: #ae6e6e;
7
+ --elmethis-primitive-color-red-600: #8a5555;
8
+ --elmethis-primitive-color-red-700: #683e3e;
9
+ --elmethis-primitive-color-red-800: #472727;
4
10
  --elmethis-primitive-color-red-900: #291313;
5
11
  --elmethis-primitive-color-orange-100: #ebdfdb;
12
+ --elmethis-primitive-color-orange-200: #dfc7bf;
13
+ --elmethis-primitive-color-orange-300: #d2afa3;
14
+ --elmethis-primitive-color-orange-400: #c59888;
6
15
  --elmethis-primitive-color-orange-500: #b8816e;
16
+ --elmethis-primitive-color-orange-600: #986858;
17
+ --elmethis-primitive-color-orange-700: #795143;
18
+ --elmethis-primitive-color-orange-800: #5b3a2f;
7
19
  --elmethis-primitive-color-orange-900: #3f251c;
8
20
  --elmethis-primitive-color-yellow-100: #ebe6db;
21
+ --elmethis-primitive-color-yellow-200: #dcd3be;
22
+ --elmethis-primitive-color-yellow-300: #cdc0a0;
23
+ --elmethis-primitive-color-yellow-400: #bfad83;
9
24
  --elmethis-primitive-color-yellow-500: #b09a66;
25
+ --elmethis-primitive-color-yellow-600: #8e7c51;
26
+ --elmethis-primitive-color-yellow-700: #6e603d;
27
+ --elmethis-primitive-color-yellow-800: #50442b;
10
28
  --elmethis-primitive-color-yellow-900: #332b19;
11
29
  --elmethis-primitive-color-green-100: #dde9e2;
30
+ --elmethis-primitive-color-green-200: #bfd4c7;
31
+ --elmethis-primitive-color-green-300: #a1c0ac;
32
+ --elmethis-primitive-color-green-400: #83ac92;
12
33
  --elmethis-primitive-color-green-500: #659878;
34
+ --elmethis-primitive-color-green-600: #4f7a5f;
35
+ --elmethis-primitive-color-green-700: #3b5d48;
36
+ --elmethis-primitive-color-green-800: #274232;
13
37
  --elmethis-primitive-color-green-900: #15281d;
14
38
  --elmethis-primitive-color-cyan-100: #dde9e7;
39
+ --elmethis-primitive-color-cyan-200: #bdd2d5;
40
+ --elmethis-primitive-color-cyan-300: #9ebcc3;
41
+ --elmethis-primitive-color-cyan-400: #7fa6b1;
15
42
  --elmethis-primitive-color-cyan-500: #6091a0;
43
+ --elmethis-primitive-color-cyan-600: #4f7a84;
44
+ --elmethis-primitive-color-cyan-700: #3f6469;
45
+ --elmethis-primitive-color-cyan-800: #2f4f4f;
16
46
  --elmethis-primitive-color-cyan-900: #203b37;
17
47
  --elmethis-primitive-color-blue-100: #dde2e9;
48
+ --elmethis-primitive-color-blue-200: #bec6d6;
49
+ --elmethis-primitive-color-blue-300: #a1abc4;
50
+ --elmethis-primitive-color-blue-400: #8491b2;
18
51
  --elmethis-primitive-color-blue-500: #68779f;
52
+ --elmethis-primitive-color-blue-600: #566385;
53
+ --elmethis-primitive-color-blue-700: #45516d;
54
+ --elmethis-primitive-color-blue-800: #343e55;
19
55
  --elmethis-primitive-color-blue-900: #242d3e;
20
56
  --elmethis-primitive-color-purple-100: #e3dde9;
57
+ --elmethis-primitive-color-purple-200: #cdc3d6;
58
+ --elmethis-primitive-color-purple-300: #b7aac4;
59
+ --elmethis-primitive-color-purple-400: #a291b1;
21
60
  --elmethis-primitive-color-purple-500: #8d799f;
61
+ --elmethis-primitive-color-purple-600: #725f83;
62
+ --elmethis-primitive-color-purple-700: #574668;
63
+ --elmethis-primitive-color-purple-800: #3e2e4f;
22
64
  --elmethis-primitive-color-purple-900: #271836;
23
65
  --elmethis-primitive-color-magenta-100: #eadce4;
66
+ --elmethis-primitive-color-magenta-200: #dcc1d0;
67
+ --elmethis-primitive-color-magenta-300: #cea7bc;
68
+ --elmethis-primitive-color-magenta-400: #c08da9;
24
69
  --elmethis-primitive-color-magenta-500: #b17396;
70
+ --elmethis-primitive-color-magenta-600: #925d7a;
71
+ --elmethis-primitive-color-magenta-700: #744760;
72
+ --elmethis-primitive-color-magenta-800: #573247;
25
73
  --elmethis-primitive-color-magenta-900: #3c1f2f;
26
74
  --elmethis-primitive-color-slate-100: #d7d9e1;
27
75
  --elmethis-primitive-color-slate-200: #b0b5be;
package/dist/tokens.d.cts CHANGED
@@ -1,3 +1,6 @@
1
+ //#region src/style/color-scale.d.ts
2
+ type ColorStep = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
3
+ //#endregion
1
4
  //#region src/style/token.d.ts
2
5
  /**
3
6
  * Design tokens for `@elmethis/core` — the single source of truth that the
@@ -6,7 +9,7 @@
6
9
  * and a semantic layer that references it, themed natively via `light-dark()`.
7
10
  */
8
11
  /** A primitive token knows the custom property that defines it. */
9
- interface PrimitiveToken {
12
+ export interface PrimitiveToken {
10
13
  /** e.g. `--elmethis-primitive-color-blue-500` */
11
14
  readonly property: string;
12
15
  /** the literal value, e.g. `#68779f` */
@@ -15,7 +18,7 @@ interface PrimitiveToken {
15
18
  readonly ref: string;
16
19
  }
17
20
  /** A semantic token is either theme-independent or a `light-dark()` pair. */
18
- type SemanticValue = {
21
+ export type SemanticValue = {
19
22
  readonly common: string;
20
23
  } | {
21
24
  readonly light: string;
@@ -23,46 +26,14 @@ type SemanticValue = {
23
26
  };
24
27
  declare const PRIMITIVE_VALUES: {
25
28
  readonly color: {
26
- readonly red: {
27
- readonly 100: "#e9dddd";
28
- readonly 500: "#ae6e6e";
29
- readonly 900: "#291313";
30
- };
31
- readonly orange: {
32
- readonly 100: "#ebdfdb";
33
- readonly 500: "#b8816e";
34
- readonly 900: "#3f251c";
35
- };
36
- readonly yellow: {
37
- readonly 100: "#ebe6db";
38
- readonly 500: "#b09a66";
39
- readonly 900: "#332b19";
40
- };
41
- readonly green: {
42
- readonly 100: "#dde9e2";
43
- readonly 500: "#659878";
44
- readonly 900: "#15281d";
45
- };
46
- readonly cyan: {
47
- readonly 100: "#dde9e7";
48
- readonly 500: "#6091a0";
49
- readonly 900: "#203b37";
50
- };
51
- readonly blue: {
52
- readonly 100: "#dde2e9";
53
- readonly 500: "#68779f";
54
- readonly 900: "#242d3e";
55
- };
56
- readonly purple: {
57
- readonly 100: "#e3dde9";
58
- readonly 500: "#8d799f";
59
- readonly 900: "#271836";
60
- };
61
- readonly magenta: {
62
- readonly 100: "#eadce4";
63
- readonly 500: "#b17396";
64
- readonly 900: "#3c1f2f";
65
- };
29
+ readonly red: Readonly<Record<ColorStep, string>>;
30
+ readonly orange: Readonly<Record<ColorStep, string>>;
31
+ readonly yellow: Readonly<Record<ColorStep, string>>;
32
+ readonly green: Readonly<Record<ColorStep, string>>;
33
+ readonly cyan: Readonly<Record<ColorStep, string>>;
34
+ readonly blue: Readonly<Record<ColorStep, string>>;
35
+ readonly purple: Readonly<Record<ColorStep, string>>;
36
+ readonly magenta: Readonly<Record<ColorStep, string>>;
66
37
  readonly slate: {
67
38
  readonly 100: "#d7d9e1";
68
39
  readonly 200: "#b0b5be";
@@ -95,7 +66,7 @@ declare const PRIMITIVE_VALUES: {
95
66
  };
96
67
  type PrimitiveTree<T> = { readonly [K in keyof T]: T[K] extends string ? PrimitiveToken : PrimitiveTree<T[K]>; };
97
68
  /** Primitive tokens, addressable as `primitive.color.blue[500]`. */
98
- declare const primitive: PrimitiveTree<typeof PRIMITIVE_VALUES>;
69
+ export declare const primitive: PrimitiveTree<typeof PRIMITIVE_VALUES>;
99
70
  /**
100
71
  * Semantic tokens, keyed by the full kebab suffix that follows `--elmethis-`
101
72
  * (so `"color-accent-info-surface"` emits `--elmethis-color-accent-info-surface`).
@@ -105,7 +76,7 @@ declare const primitive: PrimitiveTree<typeof PRIMITIVE_VALUES>;
105
76
  * `color-neutral` coexisting with `color-neutral-weak`. References to the
106
77
  * primitive layer are symbolic (`PrimitiveToken.ref`), never resolved values.
107
78
  */
108
- declare const semanticTokens: {
79
+ export declare const semanticTokens: {
109
80
  /**
110
81
  * Vertical rhythm between stacked blocks. Applied as `gap` on an explicit
111
82
  * flex-column "stack" container (e.g. each framework's `ElmA2ui` surface,
@@ -166,5 +137,4 @@ declare const semanticTokens: {
166
137
  "color-display-magenta": SemanticValue;
167
138
  "color-display-magenta-surface": SemanticValue;
168
139
  };
169
- //#endregion
170
- export { PrimitiveToken, SemanticValue, primitive, semanticTokens };
140
+ //#endregion
package/dist/tokens.d.mts CHANGED
@@ -1,3 +1,6 @@
1
+ //#region src/style/color-scale.d.ts
2
+ type ColorStep = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
3
+ //#endregion
1
4
  //#region src/style/token.d.ts
2
5
  /**
3
6
  * Design tokens for `@elmethis/core` — the single source of truth that the
@@ -6,7 +9,7 @@
6
9
  * and a semantic layer that references it, themed natively via `light-dark()`.
7
10
  */
8
11
  /** A primitive token knows the custom property that defines it. */
9
- interface PrimitiveToken {
12
+ export interface PrimitiveToken {
10
13
  /** e.g. `--elmethis-primitive-color-blue-500` */
11
14
  readonly property: string;
12
15
  /** the literal value, e.g. `#68779f` */
@@ -15,7 +18,7 @@ interface PrimitiveToken {
15
18
  readonly ref: string;
16
19
  }
17
20
  /** A semantic token is either theme-independent or a `light-dark()` pair. */
18
- type SemanticValue = {
21
+ export type SemanticValue = {
19
22
  readonly common: string;
20
23
  } | {
21
24
  readonly light: string;
@@ -23,46 +26,14 @@ type SemanticValue = {
23
26
  };
24
27
  declare const PRIMITIVE_VALUES: {
25
28
  readonly color: {
26
- readonly red: {
27
- readonly 100: "#e9dddd";
28
- readonly 500: "#ae6e6e";
29
- readonly 900: "#291313";
30
- };
31
- readonly orange: {
32
- readonly 100: "#ebdfdb";
33
- readonly 500: "#b8816e";
34
- readonly 900: "#3f251c";
35
- };
36
- readonly yellow: {
37
- readonly 100: "#ebe6db";
38
- readonly 500: "#b09a66";
39
- readonly 900: "#332b19";
40
- };
41
- readonly green: {
42
- readonly 100: "#dde9e2";
43
- readonly 500: "#659878";
44
- readonly 900: "#15281d";
45
- };
46
- readonly cyan: {
47
- readonly 100: "#dde9e7";
48
- readonly 500: "#6091a0";
49
- readonly 900: "#203b37";
50
- };
51
- readonly blue: {
52
- readonly 100: "#dde2e9";
53
- readonly 500: "#68779f";
54
- readonly 900: "#242d3e";
55
- };
56
- readonly purple: {
57
- readonly 100: "#e3dde9";
58
- readonly 500: "#8d799f";
59
- readonly 900: "#271836";
60
- };
61
- readonly magenta: {
62
- readonly 100: "#eadce4";
63
- readonly 500: "#b17396";
64
- readonly 900: "#3c1f2f";
65
- };
29
+ readonly red: Readonly<Record<ColorStep, string>>;
30
+ readonly orange: Readonly<Record<ColorStep, string>>;
31
+ readonly yellow: Readonly<Record<ColorStep, string>>;
32
+ readonly green: Readonly<Record<ColorStep, string>>;
33
+ readonly cyan: Readonly<Record<ColorStep, string>>;
34
+ readonly blue: Readonly<Record<ColorStep, string>>;
35
+ readonly purple: Readonly<Record<ColorStep, string>>;
36
+ readonly magenta: Readonly<Record<ColorStep, string>>;
66
37
  readonly slate: {
67
38
  readonly 100: "#d7d9e1";
68
39
  readonly 200: "#b0b5be";
@@ -95,7 +66,7 @@ declare const PRIMITIVE_VALUES: {
95
66
  };
96
67
  type PrimitiveTree<T> = { readonly [K in keyof T]: T[K] extends string ? PrimitiveToken : PrimitiveTree<T[K]>; };
97
68
  /** Primitive tokens, addressable as `primitive.color.blue[500]`. */
98
- declare const primitive: PrimitiveTree<typeof PRIMITIVE_VALUES>;
69
+ export declare const primitive: PrimitiveTree<typeof PRIMITIVE_VALUES>;
99
70
  /**
100
71
  * Semantic tokens, keyed by the full kebab suffix that follows `--elmethis-`
101
72
  * (so `"color-accent-info-surface"` emits `--elmethis-color-accent-info-surface`).
@@ -105,7 +76,7 @@ declare const primitive: PrimitiveTree<typeof PRIMITIVE_VALUES>;
105
76
  * `color-neutral` coexisting with `color-neutral-weak`. References to the
106
77
  * primitive layer are symbolic (`PrimitiveToken.ref`), never resolved values.
107
78
  */
108
- declare const semanticTokens: {
79
+ export declare const semanticTokens: {
109
80
  /**
110
81
  * Vertical rhythm between stacked blocks. Applied as `gap` on an explicit
111
82
  * flex-column "stack" container (e.g. each framework's `ElmA2ui` surface,
@@ -166,5 +137,4 @@ declare const semanticTokens: {
166
137
  "color-display-magenta": SemanticValue;
167
138
  "color-display-magenta-surface": SemanticValue;
168
139
  };
169
- //#endregion
170
- export { PrimitiveToken, SemanticValue, primitive, semanticTokens };
140
+ //#endregion
package/dist/tokens.mjs CHANGED
@@ -1,46 +1,75 @@
1
+ //#region src/style/color-scale.ts
2
+ const parseHex = (hex) => {
3
+ if (!/^#[\da-f]{6}$/i.test(hex)) throw new Error(`Expected a six-digit hex color, received ${hex}`);
4
+ return [
5
+ Number.parseInt(hex.slice(1, 3), 16) / 255,
6
+ Number.parseInt(hex.slice(3, 5), 16) / 255,
7
+ Number.parseInt(hex.slice(5, 7), 16) / 255
8
+ ];
9
+ };
10
+ const srgbToLinear = (channel) => channel <= .04045 ? channel / 12.92 : ((channel + .055) / 1.055) ** 2.4;
11
+ const linearToSrgb = (channel) => channel <= .0031308 ? channel * 12.92 : 1.055 * channel ** (1 / 2.4) - .055;
12
+ const hexToOklab = (hex) => {
13
+ const [encodedRed, encodedGreen, encodedBlue] = parseHex(hex);
14
+ const red = srgbToLinear(encodedRed);
15
+ const green = srgbToLinear(encodedGreen);
16
+ const blue = srgbToLinear(encodedBlue);
17
+ const lightness = Math.cbrt(.4122214708 * red + .5363325363 * green + .0514459929 * blue);
18
+ const medium = Math.cbrt(.2119034982 * red + .6806995451 * green + .1073969566 * blue);
19
+ const short = Math.cbrt(.0883024619 * red + .2817188376 * green + .6299787005 * blue);
20
+ return [
21
+ .2104542553 * lightness + .793617785 * medium - .0040720468 * short,
22
+ 1.9779984951 * lightness - 2.428592205 * medium + .4505937099 * short,
23
+ .0259040371 * lightness + .7827717662 * medium - .808675766 * short
24
+ ];
25
+ };
26
+ const oklabToHex = ([lightness, a, b]) => {
27
+ const light = (lightness + .3963377774 * a + .2158037573 * b) ** 3;
28
+ const medium = (lightness - .1055613458 * a - .0638541728 * b) ** 3;
29
+ const short = (lightness - .0894841775 * a - 1.291485548 * b) ** 3;
30
+ return `#${[
31
+ 4.0767416621 * light - 3.3077115913 * medium + .2309699292 * short,
32
+ -1.2684380046 * light + 2.6097574011 * medium - .3413193965 * short,
33
+ -.0041960863 * light - .7034186147 * medium + 1.707614701 * short
34
+ ].map(linearToSrgb).map((channel) => Math.min(1, Math.max(0, channel))).map((channel) => Math.round(channel * 255).toString(16).padStart(2, "0")).join("")}`;
35
+ };
36
+ const interpolateOklab = (start, end, amount) => oklabToHex([
37
+ start[0] + (end[0] - start[0]) * amount,
38
+ start[1] + (end[1] - start[1]) * amount,
39
+ start[2] + (end[2] - start[2]) * amount
40
+ ]);
41
+ /**
42
+ * Expands the authored 100/500/900 anchors into a perceptually even ramp.
43
+ * OKLab avoids the muddy midpoints produced by interpolating encoded sRGB.
44
+ */
45
+ const createColorScale = (light, middle, dark) => {
46
+ const lightOklab = hexToOklab(light);
47
+ const middleOklab = hexToOklab(middle);
48
+ const darkOklab = hexToOklab(dark);
49
+ return {
50
+ 100: light.toLowerCase(),
51
+ 200: interpolateOklab(lightOklab, middleOklab, .25),
52
+ 300: interpolateOklab(lightOklab, middleOklab, .5),
53
+ 400: interpolateOklab(lightOklab, middleOklab, .75),
54
+ 500: middle.toLowerCase(),
55
+ 600: interpolateOklab(middleOklab, darkOklab, .25),
56
+ 700: interpolateOklab(middleOklab, darkOklab, .5),
57
+ 800: interpolateOklab(middleOklab, darkOklab, .75),
58
+ 900: dark.toLowerCase()
59
+ };
60
+ };
61
+ //#endregion
1
62
  //#region src/style/token.ts
2
63
  const PRIMITIVE_VALUES = {
3
64
  color: {
4
- red: {
5
- 100: "#e9dddd",
6
- 500: "#ae6e6e",
7
- 900: "#291313"
8
- },
9
- orange: {
10
- 100: "#ebdfdb",
11
- 500: "#b8816e",
12
- 900: "#3f251c"
13
- },
14
- yellow: {
15
- 100: "#ebe6db",
16
- 500: "#b09a66",
17
- 900: "#332b19"
18
- },
19
- green: {
20
- 100: "#dde9e2",
21
- 500: "#659878",
22
- 900: "#15281d"
23
- },
24
- cyan: {
25
- 100: "#dde9e7",
26
- 500: "#6091a0",
27
- 900: "#203b37"
28
- },
29
- blue: {
30
- 100: "#dde2e9",
31
- 500: "#68779f",
32
- 900: "#242d3e"
33
- },
34
- purple: {
35
- 100: "#e3dde9",
36
- 500: "#8d799f",
37
- 900: "#271836"
38
- },
39
- magenta: {
40
- 100: "#eadce4",
41
- 500: "#b17396",
42
- 900: "#3c1f2f"
43
- },
65
+ red: createColorScale("#e9dddd", "#ae6e6e", "#291313"),
66
+ orange: createColorScale("#ebdfdb", "#b8816e", "#3f251c"),
67
+ yellow: createColorScale("#ebe6db", "#b09a66", "#332b19"),
68
+ green: createColorScale("#dde9e2", "#659878", "#15281d"),
69
+ cyan: createColorScale("#dde9e7", "#6091a0", "#203b37"),
70
+ blue: createColorScale("#dde2e9", "#68779f", "#242d3e"),
71
+ purple: createColorScale("#e3dde9", "#8d799f", "#271836"),
72
+ magenta: createColorScale("#eadce4", "#b17396", "#3c1f2f"),
44
73
  slate: {
45
74
  100: "#d7d9e1",
46
75
  200: "#b0b5be",