@g9tm/lynxcontrols-foundation 1.7.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/culture/bidi.d.ts +8 -0
  3. package/dist/culture/bidi.d.ts.map +1 -0
  4. package/dist/culture/bidi.js +16 -0
  5. package/dist/culture/bidi.js.map +1 -0
  6. package/dist/culture/coordinates.d.ts +17 -0
  7. package/dist/culture/coordinates.d.ts.map +1 -0
  8. package/dist/culture/coordinates.js +18 -0
  9. package/dist/culture/coordinates.js.map +1 -0
  10. package/dist/culture/index.d.ts +4 -0
  11. package/dist/culture/index.d.ts.map +1 -1
  12. package/dist/culture/index.js +4 -0
  13. package/dist/culture/natural-date.d.ts +9 -0
  14. package/dist/culture/natural-date.d.ts.map +1 -0
  15. package/dist/culture/natural-date.js +208 -0
  16. package/dist/culture/natural-date.js.map +1 -0
  17. package/dist/culture/text.d.ts +73 -0
  18. package/dist/culture/text.d.ts.map +1 -0
  19. package/dist/culture/text.js +213 -0
  20. package/dist/culture/text.js.map +1 -0
  21. package/dist/enums/index.d.ts +6 -0
  22. package/dist/enums/index.d.ts.map +1 -1
  23. package/dist/enums/index.js +4 -1
  24. package/dist/enums/index.js.map +1 -1
  25. package/dist/icons/index.d.ts +2 -1
  26. package/dist/icons/index.d.ts.map +1 -1
  27. package/dist/icons/index.js +2 -1
  28. package/dist/icons/packs.d.ts +34 -0
  29. package/dist/icons/packs.d.ts.map +1 -0
  30. package/dist/icons/packs.js +70 -0
  31. package/dist/icons/packs.js.map +1 -0
  32. package/dist/icons/svg.d.ts +9 -2
  33. package/dist/icons/svg.d.ts.map +1 -1
  34. package/dist/icons/svg.js +13 -2
  35. package/dist/icons/svg.js.map +1 -1
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -0
  39. package/dist/layout/index.d.ts +43 -0
  40. package/dist/layout/index.d.ts.map +1 -0
  41. package/dist/layout/index.js +31 -0
  42. package/dist/layout/index.js.map +1 -0
  43. package/dist/services/contracts.d.ts +32 -0
  44. package/dist/services/contracts.d.ts.map +1 -1
  45. package/dist/services/contracts.js.map +1 -1
  46. package/dist/services/feedback.d.ts +28 -0
  47. package/dist/services/feedback.d.ts.map +1 -0
  48. package/dist/services/feedback.js +27 -0
  49. package/dist/services/feedback.js.map +1 -0
  50. package/dist/services/index.d.ts +3 -1
  51. package/dist/services/index.d.ts.map +1 -1
  52. package/dist/services/index.js +2 -0
  53. package/dist/services/keys.d.ts +39 -0
  54. package/dist/services/keys.d.ts.map +1 -0
  55. package/dist/services/keys.js +96 -0
  56. package/dist/services/keys.js.map +1 -0
  57. package/dist/theme/aliases.d.ts +73 -0
  58. package/dist/theme/aliases.d.ts.map +1 -0
  59. package/dist/theme/aliases.js +76 -0
  60. package/dist/theme/aliases.js.map +1 -0
  61. package/dist/theme/appearance.d.ts +57 -0
  62. package/dist/theme/appearance.d.ts.map +1 -0
  63. package/dist/theme/appearance.js +275 -0
  64. package/dist/theme/appearance.js.map +1 -0
  65. package/dist/theme/brand.d.ts +40 -0
  66. package/dist/theme/brand.d.ts.map +1 -0
  67. package/dist/theme/brand.js +181 -0
  68. package/dist/theme/brand.js.map +1 -0
  69. package/dist/theme/contrast.d.ts +19 -0
  70. package/dist/theme/contrast.d.ts.map +1 -0
  71. package/dist/theme/contrast.js +119 -0
  72. package/dist/theme/contrast.js.map +1 -0
  73. package/dist/theme/css-color.d.ts +20 -0
  74. package/dist/theme/css-color.d.ts.map +1 -0
  75. package/dist/theme/css-color.js +149 -0
  76. package/dist/theme/css-color.js.map +1 -0
  77. package/dist/theme/design.d.ts +33 -0
  78. package/dist/theme/design.d.ts.map +1 -0
  79. package/dist/theme/design.js +162 -0
  80. package/dist/theme/design.js.map +1 -0
  81. package/dist/theme/index.d.ts +10 -2
  82. package/dist/theme/index.d.ts.map +1 -1
  83. package/dist/theme/index.js +10 -2
  84. package/dist/theme/oklch.d.ts +63 -0
  85. package/dist/theme/oklch.d.ts.map +1 -0
  86. package/dist/theme/oklch.js +258 -0
  87. package/dist/theme/oklch.js.map +1 -0
  88. package/dist/theme/recipe.d.ts +44 -0
  89. package/dist/theme/recipe.d.ts.map +1 -0
  90. package/dist/theme/recipe.js +156 -0
  91. package/dist/theme/recipe.js.map +1 -0
  92. package/dist/theme/theme.d.ts +43 -2
  93. package/dist/theme/theme.d.ts.map +1 -1
  94. package/dist/theme/theme.js +85 -9
  95. package/dist/theme/theme.js.map +1 -1
  96. package/dist/theme/variants.d.ts +10 -0
  97. package/dist/theme/variants.d.ts.map +1 -1
  98. package/dist/theme/variants.js +74 -1
  99. package/dist/theme/variants.js.map +1 -1
  100. package/dist/tokens/derived.d.ts +31 -0
  101. package/dist/tokens/derived.d.ts.map +1 -0
  102. package/dist/tokens/derived.js +42 -0
  103. package/dist/tokens/derived.js.map +1 -0
  104. package/dist/tokens/index.d.ts +2 -0
  105. package/dist/tokens/index.d.ts.map +1 -1
  106. package/dist/tokens/index.js +2 -0
  107. package/dist/tokens/shape.d.ts +46 -0
  108. package/dist/tokens/shape.d.ts.map +1 -0
  109. package/dist/tokens/shape.js +95 -0
  110. package/dist/tokens/shape.js.map +1 -0
  111. package/docs/api.md +135 -2
  112. package/package.json +6 -1
@@ -0,0 +1,162 @@
1
+ import { g9ColorTokens } from "../tokens/generated/palettes.js";
2
+ import { resolveShape } from "../tokens/shape.js";
3
+ import { formatColor } from "./color.js";
4
+ import { parseCssColor } from "./css-color.js";
5
+ const COLOR = 'color.';
6
+ const SHAPE = 'shape.';
7
+ function createDesignRegistry(options) {
8
+ const { theme, shape } = options;
9
+ let designColors = {};
10
+ const defaultShape = null == shape ? void 0 : shape.get();
11
+ let shapeChanges = {};
12
+ let defaultColors = {};
13
+ const push = ()=>theme.setDesignOverrides(Object.keys(designColors).length ? designColors : void 0);
14
+ function shapeTokens() {
15
+ if (!shape || !defaultShape) return [];
16
+ const now = shape.get();
17
+ const out = [];
18
+ for (const [k, v] of Object.entries(now.radii))out.push({
19
+ id: `${SHAPE}radius.${k}`,
20
+ value: v,
21
+ defaultValue: defaultShape.radii[k],
22
+ type: 'dimension'
23
+ });
24
+ for (const [k, v] of Object.entries(now.heights))out.push({
25
+ id: `${SHAPE}height.${k}`,
26
+ value: v,
27
+ defaultValue: defaultShape.heights[k],
28
+ type: 'dimension'
29
+ });
30
+ for (const [role, t] of Object.entries(now.type)){
31
+ const d = defaultShape.type[role];
32
+ out.push({
33
+ id: `${SHAPE}type.${role}.size`,
34
+ value: t.size,
35
+ defaultValue: d.size,
36
+ type: 'dimension'
37
+ });
38
+ out.push({
39
+ id: `${SHAPE}type.${role}.lineHeight`,
40
+ value: t.lineHeight,
41
+ defaultValue: d.lineHeight,
42
+ type: 'dimension'
43
+ });
44
+ out.push({
45
+ id: `${SHAPE}type.${role}.weight`,
46
+ value: t.weight,
47
+ defaultValue: d.weight,
48
+ type: 'fontWeight'
49
+ });
50
+ }
51
+ out.push({
52
+ id: `${SHAPE}touchTarget`,
53
+ value: now.touchTarget,
54
+ defaultValue: defaultShape.touchTarget,
55
+ type: 'dimension'
56
+ });
57
+ return out;
58
+ }
59
+ function applyShape() {
60
+ if (!shape || !defaultShape) return;
61
+ let next = defaultShape;
62
+ for (const [id, value] of Object.entries(shapeChanges)){
63
+ const path = id.slice(SHAPE.length).split('.');
64
+ if ('radius' === path[0]) next = resolveShape({
65
+ radii: {
66
+ ...next.radii,
67
+ [path[1]]: value
68
+ }
69
+ }, next);
70
+ else if ('height' === path[0]) next = resolveShape({
71
+ heights: {
72
+ ...next.heights,
73
+ [path[1]]: value
74
+ }
75
+ }, next);
76
+ else if ('touchTarget' === path[0]) next = resolveShape({
77
+ touchTarget: value
78
+ }, next);
79
+ else if ('type' === path[0]) {
80
+ const role = path[1];
81
+ const field = path[2];
82
+ next = resolveShape({
83
+ type: {
84
+ ...next.type,
85
+ [role]: {
86
+ ...next.type[role],
87
+ [field]: value
88
+ }
89
+ }
90
+ }, next);
91
+ }
92
+ }
93
+ shape.set(next);
94
+ }
95
+ return {
96
+ tokens () {
97
+ const palette = theme.getSnapshot().palette;
98
+ const colors = g9ColorTokens.map((token)=>{
99
+ var _defaultColors_token;
100
+ return {
101
+ id: `${COLOR}${token}`,
102
+ value: palette[token],
103
+ defaultValue: void 0 !== designColors[token] ? null != (_defaultColors_token = defaultColors[token]) ? _defaultColors_token : palette[token] : palette[token],
104
+ type: 'color'
105
+ };
106
+ });
107
+ return [
108
+ ...colors,
109
+ ...shapeTokens()
110
+ ];
111
+ },
112
+ set (id, value) {
113
+ if (id.startsWith(COLOR)) {
114
+ const token = id.slice(COLOR.length);
115
+ if (!g9ColorTokens.includes(token)) throw new RangeError(`No colour token ${token}.`);
116
+ const parsed = 'string' == typeof value ? parseCssColor(value) : void 0;
117
+ if (!parsed) throw new TypeError(`${id} needs a colour (got ${JSON.stringify(value)}).`);
118
+ if (void 0 === designColors[token]) defaultColors[token] = theme.getSnapshot().palette[token];
119
+ designColors = {
120
+ ...designColors,
121
+ [token]: formatColor(parsed)
122
+ };
123
+ push();
124
+ return;
125
+ }
126
+ if (id.startsWith(SHAPE) && shape) {
127
+ if ('number' != typeof value || !Number.isFinite(value) || value < 0) throw new TypeError(`${id} needs a number ≥ 0.`);
128
+ shapeChanges = {
129
+ ...shapeChanges,
130
+ [id]: value
131
+ };
132
+ applyShape();
133
+ return;
134
+ }
135
+ throw new RangeError(`No design token ${id}.`);
136
+ },
137
+ reset (id) {
138
+ if (!id) {
139
+ designColors = {};
140
+ defaultColors = {};
141
+ shapeChanges = {};
142
+ push();
143
+ applyShape();
144
+ return;
145
+ }
146
+ if (id.startsWith(COLOR)) {
147
+ const token = id.slice(COLOR.length);
148
+ const { [token]: _gone, ...rest } = designColors;
149
+ designColors = rest;
150
+ delete defaultColors[token];
151
+ push();
152
+ } else if (id.startsWith(SHAPE)) {
153
+ const { [id]: _gone, ...rest } = shapeChanges;
154
+ shapeChanges = rest;
155
+ applyShape();
156
+ }
157
+ }
158
+ };
159
+ }
160
+ export { createDesignRegistry };
161
+
162
+ //# sourceMappingURL=design.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme/design.js","sources":["../../src/theme/design.ts"],"sourcesContent":["// The theme as a live design registry — the shape G9AppPilot's `installDesign(registry)` takes (design.tokens / design.set\n// / design.reset / design.snapshot): a controller (an agent, the studio) reads every colour and shape token of the\n// running app and changes one; the screen follows at once through the theme store and the CSS variables. Nothing is\n// saved: a restart forgets it. Structural types only — foundation does not depend on Pilot.\nimport { type G9ColorToken, g9ColorTokens } from '../tokens/generated/palettes';\nimport { type G9ShapeSet, resolveShape } from '../tokens/shape';\nimport { formatColor } from './color';\nimport { parseCssColor } from './css-color';\nimport type { G9PaletteOverrides, G9ThemeStore } from './theme';\n\n/** One token as Pilot reads it. */\nexport interface G9DesignToken {\n readonly id: string;\n readonly value: number | string;\n readonly defaultValue: number | string;\n /** DTCG `$type`: `color`, `dimension`, `number`, `fontWeight`. */\n readonly type: string | null;\n readonly description?: string | null;\n}\n\n/** Pilot's `DesignRegistry`. */\nexport interface G9DesignRegistry {\n tokens(): readonly G9DesignToken[];\n set(id: string, value: number | string): void;\n reset(id?: string): void;\n}\n\n/** What {@link createDesignRegistry} edits live: the theme store and, when the app allows it, the shape. */\nexport interface G9DesignRegistryOptions {\n readonly theme: G9ThemeStore;\n /** The live shape, when the app lets designers change it (the provider supplies this). */\n readonly shape?: { get(): G9ShapeSet; set(shape: G9ShapeSet): void };\n}\n\nconst COLOR = 'color.';\nconst SHAPE = 'shape.';\n\n/**\n * Creates the registry. Colour ids are `color.<Token>` (`color.Primary`); shape ids are `shape.radius.card`,\n * `shape.height.md`, `shape.type.body.size`, `shape.touchTarget`. A change is an override layered over the app's own\n * overrides, so a reset returns exactly to what the app painted.\n */\nexport function createDesignRegistry(options: G9DesignRegistryOptions): G9DesignRegistry {\n const { theme, shape } = options;\n let designColors: Record<string, string> = {};\n const defaultShape = shape?.get();\n let shapeChanges: Record<string, number> = {};\n // What the app paints for a token (the value before any design change), kept from the first change on.\n let defaultColors: Record<string, string> = {};\n const push = () =>\n theme.setDesignOverrides(Object.keys(designColors).length ? (designColors as G9PaletteOverrides) : undefined);\n\n function shapeTokens(): G9DesignToken[] {\n if (!shape || !defaultShape) return [];\n const now = shape.get();\n const out: G9DesignToken[] = [];\n for (const [k, v] of Object.entries(now.radii)) {\n out.push({\n id: `${SHAPE}radius.${k}`,\n value: v,\n defaultValue: defaultShape.radii[k as keyof G9ShapeSet['radii']],\n type: 'dimension',\n });\n }\n for (const [k, v] of Object.entries(now.heights)) {\n out.push({\n id: `${SHAPE}height.${k}`,\n value: v,\n defaultValue: defaultShape.heights[k as keyof G9ShapeSet['heights']],\n type: 'dimension',\n });\n }\n for (const [role, t] of Object.entries(now.type)) {\n const d = defaultShape.type[role as keyof G9ShapeSet['type']];\n out.push({ id: `${SHAPE}type.${role}.size`, value: t.size, defaultValue: d.size, type: 'dimension' });\n out.push({\n id: `${SHAPE}type.${role}.lineHeight`,\n value: t.lineHeight,\n defaultValue: d.lineHeight,\n type: 'dimension',\n });\n out.push({ id: `${SHAPE}type.${role}.weight`, value: t.weight, defaultValue: d.weight, type: 'fontWeight' });\n }\n out.push({\n id: `${SHAPE}touchTarget`,\n value: now.touchTarget,\n defaultValue: defaultShape.touchTarget,\n type: 'dimension',\n });\n return out;\n }\n\n function applyShape(): void {\n if (!shape || !defaultShape) return;\n let next: G9ShapeSet = defaultShape;\n for (const [id, value] of Object.entries(shapeChanges)) {\n const path = id.slice(SHAPE.length).split('.');\n if (path[0] === 'radius') next = resolveShape({ radii: { ...next.radii, [path[1] as string]: value } }, next);\n else if (path[0] === 'height')\n next = resolveShape({ heights: { ...next.heights, [path[1] as string]: value } }, next);\n else if (path[0] === 'touchTarget') next = resolveShape({ touchTarget: value }, next);\n else if (path[0] === 'type') {\n const role = path[1] as keyof G9ShapeSet['type'];\n const field = path[2] as 'size' | 'lineHeight' | 'weight';\n next = resolveShape({ type: { ...next.type, [role]: { ...next.type[role], [field]: value } } }, next);\n }\n }\n shape.set(next);\n }\n\n return {\n tokens() {\n const palette = theme.getSnapshot().palette;\n const colors = g9ColorTokens.map(\n (token): G9DesignToken => ({\n id: `${COLOR}${token}`,\n value: palette[token],\n defaultValue: designColors[token] !== undefined ? (defaultColors[token] ?? palette[token]) : palette[token],\n type: 'color',\n }),\n );\n return [...colors, ...shapeTokens()];\n },\n set(id, value) {\n if (id.startsWith(COLOR)) {\n const token = id.slice(COLOR.length) as G9ColorToken;\n if (!(g9ColorTokens as readonly string[]).includes(token)) throw new RangeError(`No colour token ${token}.`);\n const parsed = typeof value === 'string' ? parseCssColor(value) : undefined;\n if (!parsed) throw new TypeError(`${id} needs a colour (got ${JSON.stringify(value)}).`);\n if (designColors[token] === undefined) defaultColors[token] = theme.getSnapshot().palette[token];\n designColors = { ...designColors, [token]: formatColor(parsed) };\n push();\n return;\n }\n if (id.startsWith(SHAPE) && shape) {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)\n throw new TypeError(`${id} needs a number ≥ 0.`);\n shapeChanges = { ...shapeChanges, [id]: value };\n applyShape();\n return;\n }\n throw new RangeError(`No design token ${id}.`);\n },\n reset(id) {\n if (!id) {\n designColors = {};\n defaultColors = {};\n shapeChanges = {};\n push();\n applyShape();\n return;\n }\n if (id.startsWith(COLOR)) {\n const token = id.slice(COLOR.length);\n const { [token]: _gone, ...rest } = designColors;\n designColors = rest;\n delete defaultColors[token];\n push();\n } else if (id.startsWith(SHAPE)) {\n const { [id]: _gone, ...rest } = shapeChanges;\n shapeChanges = rest;\n applyShape();\n }\n },\n };\n}\n"],"names":["COLOR","SHAPE","createDesignRegistry","options","theme","shape","designColors","defaultShape","shapeChanges","defaultColors","push","Object","undefined","shapeTokens","now","out","k","v","role","t","d","applyShape","next","id","value","path","resolveShape","field","palette","colors","g9ColorTokens","token","_defaultColors_token","RangeError","parsed","parseCssColor","TypeError","JSON","formatColor","Number","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AM,EAAEO,YAAYJ;gBAAQ;gBAC/DxB;gBACA;YACF;YACA,IAAIa,GAAG,UAAU,CAACtB,UAAUI,OAAO;gBACjC,IAAI,AAAiB,YAAjB,OAAOmB,SAAsB,CAACe,OAAO,QAAQ,CAACf,UAAUA,QAAQ,GAClE,MAAM,IAAIY,UAAU,GAAGb,GAAG,oBAAoB,CAAC;gBACjDf,eAAe;oBAAE,GAAGA,YAAY;oBAAE,CAACe,GAAG,EAAEC;gBAAM;gBAC9CH;gBACA;YACF;YACA,MAAM,IAAIY,WAAW,CAAC,gBAAgB,EAAEV,GAAG,CAAC,CAAC;QAC/C;QACA,OAAMA,EAAE;YACN,IAAI,CAACA,IAAI;gBACPjB,eAAe,CAAC;gBAChBG,gBAAgB,CAAC;gBACjBD,eAAe,CAAC;gBAChBE;gBACAW;gBACA;YACF;YACA,IAAIE,GAAG,UAAU,CAACvB,QAAQ;gBACxB,MAAM+B,QAAQR,GAAG,KAAK,CAACvB,MAAM,MAAM;gBACnC,MAAM,EAAE,CAAC+B,MAAM,EAAES,KAAK,EAAE,GAAGC,MAAM,GAAGnC;gBACpCA,eAAemC;gBACf,OAAOhC,aAAa,CAACsB,MAAM;gBAC3BrB;YACF,OAAO,IAAIa,GAAG,UAAU,CAACtB,QAAQ;gBAC/B,MAAM,EAAE,CAACsB,GAAG,EAAEiB,KAAK,EAAE,GAAGC,MAAM,GAAGjC;gBACjCA,eAAeiC;gBACfpB;YACF;QACF;IACF;AACF"}
@@ -1,5 +1,13 @@
1
+ export { aliasCssVariables, aliasPalette, type G9TokenAliasMap, g9AliasPresets } from './aliases.js';
2
+ export { applyThemeDefinition, exportTheme, type G9ThemeDefinition, type G9ThemeSource, g9AccentPresets, g9BuiltInThemes, importTheme, overriddenTokens, previewThemeDefinition, themeName, } from './appearance.js';
3
+ export { createBrandPalette, createBrandPalettes, type G9BrandColors, type G9BrandPaletteOptions } from './brand.js';
1
4
  export { applyAlpha, createBorderColor, createHoverColor, createPressedColor, darken, formatColor, type G9Color, G9ColorFormatError, type G9ColorInput, type G9Rgba, getContrastingTextColor, getContrastRatio, getLuminance, lighten, meetsWcagAA, meetsWcagAAA, mix, parseColor, parseMauiColor, rgba, toHex, toRgba, tryParseColor, withAlpha, withOpacity, } from './color.js';
5
+ export { contrastFailures, contrastReport, type G9ContrastResult, type G9ContrastRule, g9ContrastRules, } from './contrast.js';
2
6
  export { buildSolidOrGradient, checkBoxMark, fillToCss, G9Colors, type G9Fill, type G9GradientStop, switchOffTrack, switchOnTrack, switchThumbOff, switchThumbOn, } from './control-colors.js';
3
- export { createPalette, createThemeStore, G9ColorScheme, type G9CustomPalettes, type G9PaletteOverrides, type G9ResolvedTheme, type G9ThemeListener, G9ThemeMode, type G9ThemeOptions, type G9ThemeStore, resolveColorScheme, resolveTheme, stockPalette, } from './theme.js';
4
- export { type G9ButtonVisualResult, type G9VariantColors, hasSwatch, resolveButtonVariant, resolveProgressColor, } from './variants.js';
7
+ export { g9Easings, lightnessOf, parseCssColor, resolveColorFunctions, resolveCssColor, resolveEasing, } from './css-color.js';
8
+ export { createDesignRegistry, type G9DesignRegistry, type G9DesignRegistryOptions, type G9DesignToken, } from './design.js';
9
+ export { chartPalette, colorDistance, ensureContrast, fromOklch, type G9Oklch, type G9TonalScale, type G9TonalStep, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, tonalScale, toOklch, } from './oklch.js';
10
+ export { brandRecipe, designedRecipe, type G9ThemeRecipe, getRecipe, listRecipes, recipePalettes, registerRecipe, } from './recipe.js';
11
+ export { createPalette, createThemeStore, G9ColorScheme, type G9CustomPalettes, type G9PaletteOverrides, type G9ResolvedTheme, type G9ThemeListener, G9ThemeMode, type G9ThemeOptions, type G9ThemeSchedule, type G9ThemeStore, g9DefaultThemeSchedule, isScheduledDark, resolveColorScheme, resolveTheme, stockPalette, } from './theme.js';
12
+ export { type G9ButtonVisualResult, type G9VariantColors, type G9VariantVars, hasSwatch, resolveButtonVariant, resolveButtonVariantVars, resolveProgressColor, resolveProgressColorVar, } from './variants.js';
5
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,EACN,WAAW,EACX,KAAK,OAAO,EACZ,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,uBAAuB,EACvB,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,WAAW,EACX,YAAY,EACZ,GAAG,EACH,UAAU,EACV,cAAc,EACd,IAAI,EACJ,KAAK,EACL,MAAM,EACN,aAAa,EACb,SAAS,EACT,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,kBAAkB,EAClB,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,SAAS,EACT,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAClG,OAAO,EACL,oBAAoB,EACpB,W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EACb,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,GACR,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,WAAW,EACX,cAAc,EACd,KAAK,aAAa,EAClB,SAAS,EACT,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,SAAS,EACT,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,YAAY,CAAC"}
@@ -1,4 +1,12 @@
1
+ export { aliasCssVariables, aliasPalette, g9AliasPresets } from "./aliases.js";
2
+ export { applyThemeDefinition, exportTheme, g9AccentPresets, g9BuiltInThemes, importTheme, overriddenTokens, previewThemeDefinition, themeName } from "./appearance.js";
3
+ export { createBrandPalette, createBrandPalettes } from "./brand.js";
1
4
  export { G9ColorFormatError, applyAlpha, createBorderColor, createHoverColor, createPressedColor, darken, formatColor, getContrastRatio, getContrastingTextColor, getLuminance, lighten, meetsWcagAA, meetsWcagAAA, mix, parseColor, parseMauiColor, rgba, toHex, toRgba, tryParseColor, withAlpha, withOpacity } from "./color.js";
5
+ export { contrastFailures, contrastReport, g9ContrastRules } from "./contrast.js";
2
6
  export { G9Colors, buildSolidOrGradient, checkBoxMark, fillToCss, switchOffTrack, switchOnTrack, switchThumbOff, switchThumbOn } from "./control-colors.js";
3
- export { G9ColorScheme, G9ThemeMode, createPalette, createThemeStore, resolveColorScheme, resolveTheme, stockPalette } from "./theme.js";
4
- export { hasSwatch, resolveButtonVariant, resolveProgressColor } from "./variants.js";
7
+ export { g9Easings, lightnessOf, parseCssColor, resolveColorFunctions, resolveCssColor, resolveEasing } from "./css-color.js";
8
+ export { createDesignRegistry } from "./design.js";
9
+ export { chartPalette, colorDistance, ensureContrast, fromOklch, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, toOklch, tonalScale } from "./oklch.js";
10
+ export { brandRecipe, designedRecipe, getRecipe, listRecipes, recipePalettes, registerRecipe } from "./recipe.js";
11
+ export { G9ColorScheme, G9ThemeMode, createPalette, createThemeStore, g9DefaultThemeSchedule, isScheduledDark, resolveColorScheme, resolveTheme, stockPalette } from "./theme.js";
12
+ export { hasSwatch, resolveButtonVariant, resolveButtonVariantVars, resolveProgressColor, resolveProgressColorVar } from "./variants.js";
@@ -0,0 +1,63 @@
1
+ import { type G9ColorInput, type G9Rgba } from './color.js';
2
+ /** A colour in OKLCH. `alpha` 0..1 (default 1). */
3
+ export interface G9Oklch {
4
+ readonly l: number;
5
+ readonly c: number;
6
+ readonly h: number;
7
+ readonly alpha?: number;
8
+ }
9
+ /** A colour in OKLCH (lightness, chroma, hue): the perceptual space the brand palettes and tonal scales are built in. Cached per string. */
10
+ export declare function toOklch(color: G9ColorInput): G9Oklch;
11
+ /** True when the OKLCH colour is inside sRGB. */
12
+ export declare const isInSrgbGamut: (x: G9Oklch) => boolean;
13
+ /**
14
+ * OKLCH → sRGB (`G9Rgba`, channels 0..1). Out-of-gamut colours keep L and H and lose chroma until they fit (binary
15
+ * search, 18 steps ≈ 1e-6 chroma), so a vivid brand never shifts hue when it is darkened or lightened.
16
+ */
17
+ export declare function fromOklch(x: G9Oklch): G9Rgba;
18
+ /** OKLCH → `#RRGGBB` (or `#RRGGBBAA` with alpha < 1). */
19
+ export declare const oklchToHex: (x: G9Oklch) => string;
20
+ /** Steps of a tonal scale (Tailwind-like names: 50 lightest … 950 darkest). */
21
+ export declare const g9TonalSteps: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
22
+ /** A step of a tonal scale: 50, 100, 200 … 900, 950. */
23
+ export type G9TonalStep = (typeof g9TonalSteps)[number];
24
+ /** A colour's tonal scale: one hex colour per step (50 lightest … 950 darkest). */
25
+ export type G9TonalScale = {
26
+ readonly [K in G9TonalStep]: string;
27
+ };
28
+ /** The step whose lightness is nearest to `color`'s. */
29
+ export declare function nearestTonalStep(color: G9ColorInput): G9TonalStep;
30
+ /**
31
+ * A tonal scale from one colour: same hue, lightness from the step table, chroma scaled from the source's. The source
32
+ * itself is placed exactly at its nearest step, so the brand colour always appears in its own scale unchanged.
33
+ */
34
+ export declare function tonalScale(color: G9ColorInput): G9TonalScale;
35
+ /**
36
+ * A neutral scale tinted by `color`: the brand's hue at a whisper of chroma (`tint` 0 = pure grey, 1 = 0.02 C, the
37
+ * strongest tint that still reads as grey), so surfaces and text belong to the brand without looking coloured.
38
+ */
39
+ export declare function neutralScale(color: G9ColorInput, tint?: number): G9TonalScale;
40
+ /** Perceptual distance (ΔE in OKLab, ×100: about 2 is just noticeable). */
41
+ export declare function colorDistance(a: G9ColorInput, b: G9ColorInput): number;
42
+ /**
43
+ * `fg` moved in lightness (hue and chroma kept) until its WCAG contrast with `bg` is at least `min`. Goes darker on a
44
+ * light background and lighter on a dark one; returns `fg` unchanged when it already passes. If no lightness of this hue
45
+ * reaches `min`, returns black or white, whichever contrasts more.
46
+ */
47
+ export declare function ensureContrast(fg: G9ColorInput, bg: G9ColorInput, min: number): string;
48
+ /** Black or white text, whichever contrasts more with `bg`, nudged toward `tint`'s hue when given. */
49
+ export declare function readableOn(bg: G9ColorInput, tint?: G9ColorInput): string;
50
+ /** Linear interpolation in OKLCH (shorter hue arc). `t` 0..1. */
51
+ export declare function mixOklch(a: G9ColorInput, b: G9ColorInput, t: number): string;
52
+ /**
53
+ * A colour at `t` (0..1) along several stops, mixed in OKLCH — e.g. Riskara's risk spectrum
54
+ * (`interpolateStops([calm, lime, amber, coral], score / 100)`).
55
+ */
56
+ export declare function interpolateStops(stops: readonly G9ColorInput[], t: number): string;
57
+ /**
58
+ * `n` chart colours that start at `primary` and step around the hue circle by the golden angle (137.5°), each at a
59
+ * lightness that reads on `background` (contrast ≥ 3, WCAG for graphics) and a chroma the scheme can carry. Neighbours
60
+ * stay distinguishable for n ≤ 10; the same inputs always give the same palette.
61
+ */
62
+ export declare function chartPalette(primary: G9ColorInput, background: G9ColorInput, n?: number): string[];
63
+ //# sourceMappingURL=oklch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oklch.d.ts","sourceRoot":"","sources":["../../src/theme/oklch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,MAAM,EAAgD,MAAM,SAAS,CAAC;AAEpH,mDAAmD;AACnD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAuCD,4IAA4I;AAC5I,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAUpD;AAoBD,iDAAiD;AACjD,eAAO,MAAM,aAAa,GAAI,GAAG,OAAO,KAAG,OAA+B,CAAC;AAE3E;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAiB5C;AAED,yDAAyD;AACzD,eAAO,MAAM,UAAU,GAAI,GAAG,OAAO,KAAG,MAAmC,CAAC;AAK5E,+EAA+E;AAC/E,eAAO,MAAM,YAAY,iEAAkE,CAAC;AAC5F,wDAAwD;AACxD,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACxD,mFAAmF;AACnF,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,WAAW,GAAG,MAAM;CAAE,CAAC;AA+BnE,wDAAwD;AACxD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAKjE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,CAS5D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,SAAM,GAAG,YAAY,CAM1E;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAMtE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAgCtF;AAED,sGAAsG;AACtG,wBAAgB,UAAU,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,MAAM,CAKxE;AAED,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAmB5E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAMlF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,SAAI,GAAG,MAAM,EAAE,CAa7F"}
@@ -0,0 +1,258 @@
1
+ import { formatColor, getContrastRatio, getLuminance, rgba, toRgba } from "./color.js";
2
+ const toLinear = (x)=>x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
3
+ const fromLinear = (v)=>v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;
4
+ function linearToOklab(r, g, b) {
5
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
6
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
7
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
8
+ return [
9
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
10
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
11
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
12
+ ];
13
+ }
14
+ function oklabToLinear(L, a, b) {
15
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
16
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
17
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
18
+ return [
19
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
20
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
21
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
22
+ ];
23
+ }
24
+ const OKLCH_CACHE = new Map();
25
+ function toOklch(color) {
26
+ if ('string' == typeof color) {
27
+ const hit = OKLCH_CACHE.get(color);
28
+ if (hit) return hit;
29
+ const x = Object.freeze(toOklchUncached(color));
30
+ if (OKLCH_CACHE.size > 512) OKLCH_CACHE.clear();
31
+ OKLCH_CACHE.set(color, x);
32
+ return x;
33
+ }
34
+ return toOklchUncached(color);
35
+ }
36
+ function toOklchUncached(color) {
37
+ const { r, g, b, a } = toRgba(color);
38
+ const [L, A, B] = linearToOklab(toLinear(r), toLinear(g), toLinear(b));
39
+ const c = Math.hypot(A, B);
40
+ let h = 180 * Math.atan2(B, A) / Math.PI;
41
+ if (h < 0) h += 360;
42
+ return {
43
+ l: L,
44
+ c: c < 1e-4 ? 0 : c,
45
+ h: c < 1e-4 ? 0 : h,
46
+ alpha: a
47
+ };
48
+ }
49
+ const EPS = 1e-6;
50
+ const inGamut = (rgb)=>rgb.every((v)=>v >= -EPS && v <= 1 + EPS);
51
+ function linearOf(x) {
52
+ const rad = x.h * Math.PI / 180;
53
+ return oklabToLinear(x.l, x.c * Math.cos(rad), x.c * Math.sin(rad));
54
+ }
55
+ const isInSrgbGamut = (x)=>inGamut(linearOf(x));
56
+ function fromOklch(x) {
57
+ var _x_alpha;
58
+ const l = Math.min(1, Math.max(0, x.l));
59
+ let probe = {
60
+ l,
61
+ c: Math.max(0, x.c),
62
+ h: x.h
63
+ };
64
+ if (!isInSrgbGamut(probe)) {
65
+ let lo = 0;
66
+ let hi = probe.c;
67
+ for(let i = 0; i < 12; i++){
68
+ const mid = (lo + hi) / 2;
69
+ if (isInSrgbGamut({
70
+ l,
71
+ c: mid,
72
+ h: x.h
73
+ })) lo = mid;
74
+ else hi = mid;
75
+ }
76
+ probe = {
77
+ l,
78
+ c: lo,
79
+ h: x.h
80
+ };
81
+ }
82
+ const [r, g, b] = linearOf(probe);
83
+ const ch = (v)=>fromLinear(Math.min(1, Math.max(0, v)));
84
+ return rgba(ch(r), ch(g), ch(b), null != (_x_alpha = x.alpha) ? _x_alpha : 1);
85
+ }
86
+ const oklchToHex = (x)=>formatColor(fromOklch(x));
87
+ const opaque = (color)=>formatColor({
88
+ ...toRgba(color),
89
+ a: 1
90
+ });
91
+ const g9TonalSteps = [
92
+ 50,
93
+ 100,
94
+ 200,
95
+ 300,
96
+ 400,
97
+ 500,
98
+ 600,
99
+ 700,
100
+ 800,
101
+ 900,
102
+ 950
103
+ ];
104
+ const STEP_L = {
105
+ 50: 0.975,
106
+ 100: 0.945,
107
+ 200: 0.89,
108
+ 300: 0.815,
109
+ 400: 0.72,
110
+ 500: 0.63,
111
+ 600: 0.55,
112
+ 700: 0.47,
113
+ 800: 0.39,
114
+ 900: 0.3,
115
+ 950: 0.22
116
+ };
117
+ const STEP_C = {
118
+ 50: 0.14,
119
+ 100: 0.28,
120
+ 200: 0.5,
121
+ 300: 0.72,
122
+ 400: 0.9,
123
+ 500: 1,
124
+ 600: 1,
125
+ 700: 0.92,
126
+ 800: 0.8,
127
+ 900: 0.66,
128
+ 950: 0.52
129
+ };
130
+ function nearestTonalStep(color) {
131
+ const { l } = toOklch(color);
132
+ let best = 500;
133
+ for (const step of g9TonalSteps)if (Math.abs(STEP_L[step] - l) < Math.abs(STEP_L[best] - l)) best = step;
134
+ return best;
135
+ }
136
+ function tonalScale(color) {
137
+ const src = toOklch(color);
138
+ const exact = nearestTonalStep(color);
139
+ const peak = src.c / STEP_C[exact];
140
+ const out = {};
141
+ for (const step of g9TonalSteps)out[step] = step === exact ? opaque(color) : oklchToHex({
142
+ l: STEP_L[step],
143
+ c: peak * STEP_C[step],
144
+ h: src.h
145
+ });
146
+ return out;
147
+ }
148
+ function neutralScale(color, tint = 0.5) {
149
+ const { h } = toOklch(color);
150
+ const c = 0.02 * Math.min(1, Math.max(0, tint));
151
+ const out = {};
152
+ for (const step of g9TonalSteps)out[step] = oklchToHex({
153
+ l: STEP_L[step],
154
+ c,
155
+ h
156
+ });
157
+ return out;
158
+ }
159
+ function colorDistance(a, b) {
160
+ const x = toOklch(a);
161
+ const y = toOklch(b);
162
+ const ra = x.h * Math.PI / 180;
163
+ const rb = y.h * Math.PI / 180;
164
+ return 100 * Math.hypot(x.l - y.l, x.c * Math.cos(ra) - y.c * Math.cos(rb), x.c * Math.sin(ra) - y.c * Math.sin(rb));
165
+ }
166
+ function ensureContrast(fg, bg, min) {
167
+ if (getContrastRatio(fg, bg) >= min) return opaque(fg);
168
+ const src = toOklch(fg);
169
+ const bgL = getLuminance(bg);
170
+ const ratio = (c)=>{
171
+ const l = getLuminance(c);
172
+ return (Math.max(l, bgL) + 0.05) / (Math.min(l, bgL) + 0.05);
173
+ };
174
+ const darker = toOklch(bg).l > 0.6;
175
+ let lo = darker ? 0 : src.l;
176
+ let hi = darker ? src.l : 1;
177
+ let found = null;
178
+ for(let i = 0; i < 14; i++){
179
+ const mid = (lo + hi) / 2;
180
+ if (ratio(fromOklch({
181
+ l: mid,
182
+ c: src.c,
183
+ h: src.h
184
+ })) >= min) {
185
+ found = mid;
186
+ if (darker) lo = mid;
187
+ else hi = mid;
188
+ } else if (darker) hi = mid;
189
+ else lo = mid;
190
+ }
191
+ if (null !== found) for(let k = 0; k < 8; k++){
192
+ const hex = oklchToHex({
193
+ l: found,
194
+ c: src.c,
195
+ h: src.h
196
+ });
197
+ if (getContrastRatio(hex, bg) >= min) return hex;
198
+ found = Math.min(1, Math.max(0, found + (darker ? -0.002 : 0.002)));
199
+ }
200
+ return getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg) ? '#000000' : '#FFFFFF';
201
+ }
202
+ function readableOn(bg, tint) {
203
+ const dark = getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg);
204
+ if (!tint) return dark ? '#000000' : '#FFFFFF';
205
+ const { h, c } = toOklch(tint);
206
+ return ensureContrast(oklchToHex({
207
+ l: dark ? 0.2 : 0.98,
208
+ c: Math.min(c, 0.04),
209
+ h
210
+ }), bg, 4.5);
211
+ }
212
+ function mixOklch(a, b, t) {
213
+ var _x_alpha, _y_alpha, _x_alpha1;
214
+ const x = toOklch(a);
215
+ const y = toOklch(b);
216
+ let h;
217
+ if (0 === x.c) h = y.h;
218
+ else if (0 === y.c) h = x.h;
219
+ else {
220
+ let dh = y.h - x.h;
221
+ if (dh > 180) dh -= 360;
222
+ if (dh < -180) dh += 360;
223
+ h = (x.h + dh * t + 360) % 360;
224
+ }
225
+ return oklchToHex({
226
+ l: x.l + (y.l - x.l) * t,
227
+ c: x.c + (y.c - x.c) * t,
228
+ h,
229
+ alpha: (null != (_x_alpha = x.alpha) ? _x_alpha : 1) + ((null != (_y_alpha = y.alpha) ? _y_alpha : 1) - (null != (_x_alpha1 = x.alpha) ? _x_alpha1 : 1)) * t
230
+ });
231
+ }
232
+ function interpolateStops(stops, t) {
233
+ if (0 === stops.length) throw new RangeError('interpolateStops needs at least one stop.');
234
+ if (1 === stops.length) return formatColor(stops[0]);
235
+ const x = Math.min(1, Math.max(0, t)) * (stops.length - 1);
236
+ const i = Math.min(stops.length - 2, Math.floor(x));
237
+ return mixOklch(stops[i], stops[i + 1], x - i);
238
+ }
239
+ function chartPalette(primary, background, n = 8) {
240
+ const p = toOklch(primary);
241
+ const dark = toOklch(background).l < 0.5;
242
+ const l = dark ? 0.74 : 0.58;
243
+ const c = Math.max(0.09, Math.min(0.17, p.c || 0.12));
244
+ const out = [];
245
+ for(let i = 0; i < n; i++){
246
+ const h = (p.h + 137.508 * i) % 360;
247
+ const li = l + (i % 2 === 0 ? 0 : dark ? -0.06 : 0.07);
248
+ out.push(ensureContrast(0 === i ? opaque(primary) : oklchToHex({
249
+ l: li,
250
+ c,
251
+ h
252
+ }), background, 3));
253
+ }
254
+ return out;
255
+ }
256
+ export { chartPalette, colorDistance, ensureContrast, fromOklch, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, toOklch, tonalScale };
257
+
258
+ //# sourceMappingURL=oklch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme/oklch.js","sources":["../../src/theme/oklch.ts"],"sourcesContent":["// OKLCH colour science for themes: perceptual lightness (L 0..1), chroma (C ≥ 0) and hue (H degrees). Brand palettes,\n// tonal scales, chart palettes and contrast repair all work here, because equal steps of L look equal to a person and\n// keeping H keeps a brand recognisable — something HSL lightening never did (a darkened yellow turns olive in HSL).\n// Björn Ottosson's OKLab (2020) matrices; gamut mapping by reducing chroma at constant L and H (CSS Color 4's idea).\nimport { formatColor, type G9ColorInput, type G9Rgba, getContrastRatio, getLuminance, rgba, toRgba } from './color';\n\n/** A colour in OKLCH. `alpha` 0..1 (default 1). */\nexport interface G9Oklch {\n readonly l: number;\n readonly c: number;\n readonly h: number;\n readonly alpha?: number;\n}\n\n// Channels are 0..1 (the library's G9Rgba).\nconst toLinear = (x: number): number => {\n return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;\n};\nconst fromLinear = (v: number): number => {\n return v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;\n};\n\n/** Linear sRGB (0..1 each) → OKLab. */\nfunction linearToOklab(r: number, g: number, b: number): [number, number, number] {\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);\n return [\n 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n ];\n}\n\n/** OKLab → linear sRGB (may fall outside 0..1: out of gamut). */\nfunction oklabToLinear(L: number, a: number, b: number): [number, number, number] {\n const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;\n const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;\n const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;\n return [\n 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n ];\n}\n\n/** Any colour → OKLCH. */\n// Palette generation converts the same few strings hundreds of times (a brand, its scale, white, black): on PrimJS (no\n// JIT, Galaxy A21s) one brand palette cost ~60 ms before these caches (2026-11-18).\nconst OKLCH_CACHE = new Map<string, G9Oklch>();\n\n/** A colour in OKLCH (lightness, chroma, hue): the perceptual space the brand palettes and tonal scales are built in. Cached per string. */\nexport function toOklch(color: G9ColorInput): G9Oklch {\n if (typeof color === 'string') {\n const hit = OKLCH_CACHE.get(color);\n if (hit) return hit;\n const x = Object.freeze(toOklchUncached(color));\n if (OKLCH_CACHE.size > 512) OKLCH_CACHE.clear();\n OKLCH_CACHE.set(color, x);\n return x;\n }\n return toOklchUncached(color);\n}\n\nfunction toOklchUncached(color: G9ColorInput): G9Oklch {\n const { r, g, b, a } = toRgba(color);\n const [L, A, B] = linearToOklab(toLinear(r), toLinear(g), toLinear(b));\n const c = Math.hypot(A, B);\n let h = (Math.atan2(B, A) * 180) / Math.PI;\n if (h < 0) h += 360;\n // A grey has no hue: keep 0 so equality checks and interpolation stay stable.\n return { l: L, c: c < 1e-4 ? 0 : c, h: c < 1e-4 ? 0 : h, alpha: a };\n}\n\nconst EPS = 1e-6;\nconst inGamut = (rgb: readonly number[]): boolean => rgb.every((v) => v >= -EPS && v <= 1 + EPS);\n\nfunction linearOf(x: G9Oklch): [number, number, number] {\n const rad = (x.h * Math.PI) / 180;\n return oklabToLinear(x.l, x.c * Math.cos(rad), x.c * Math.sin(rad));\n}\n\n/** True when the OKLCH colour is inside sRGB. */\nexport const isInSrgbGamut = (x: G9Oklch): boolean => inGamut(linearOf(x));\n\n/**\n * OKLCH → sRGB (`G9Rgba`, channels 0..1). Out-of-gamut colours keep L and H and lose chroma until they fit (binary\n * search, 18 steps ≈ 1e-6 chroma), so a vivid brand never shifts hue when it is darkened or lightened.\n */\nexport function fromOklch(x: G9Oklch): G9Rgba {\n const l = Math.min(1, Math.max(0, x.l));\n let probe: G9Oklch = { l, c: Math.max(0, x.c), h: x.h };\n if (!isInSrgbGamut(probe)) {\n let lo = 0;\n let hi = probe.c;\n // 12 halvings: chroma to ~1e-4, finer than one step of a hex channel\n for (let i = 0; i < 12; i++) {\n const mid = (lo + hi) / 2;\n if (isInSrgbGamut({ l, c: mid, h: x.h })) lo = mid;\n else hi = mid;\n }\n probe = { l, c: lo, h: x.h };\n }\n const [r, g, b] = linearOf(probe);\n const ch = (v: number) => fromLinear(Math.min(1, Math.max(0, v)));\n return rgba(ch(r), ch(g), ch(b), x.alpha ?? 1);\n}\n\n/** OKLCH → `#RRGGBB` (or `#RRGGBBAA` with alpha < 1). */\nexport const oklchToHex = (x: G9Oklch): string => formatColor(fromOklch(x));\n\n/** A colour as opaque `#RRGGBB` (rounded), whatever its input form. */\nconst opaque = (color: G9ColorInput): string => formatColor({ ...toRgba(color), a: 1 });\n\n/** Steps of a tonal scale (Tailwind-like names: 50 lightest … 950 darkest). */\nexport const g9TonalSteps = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] as const;\n/** A step of a tonal scale: 50, 100, 200 … 900, 950. */\nexport type G9TonalStep = (typeof g9TonalSteps)[number];\n/** A colour's tonal scale: one hex colour per step (50 lightest … 950 darkest). */\nexport type G9TonalScale = { readonly [K in G9TonalStep]: string };\n\n/** Target lightness of each step (perceptually even, darker at the end like the projects' scales). */\nconst STEP_L: Record<G9TonalStep, number> = {\n 50: 0.975,\n 100: 0.945,\n 200: 0.89,\n 300: 0.815,\n 400: 0.72,\n 500: 0.63,\n 600: 0.55,\n 700: 0.47,\n 800: 0.39,\n 900: 0.3,\n 950: 0.22,\n};\n/** Chroma kept at each step relative to the source (pale and deep tones carry less colour). */\nconst STEP_C: Record<G9TonalStep, number> = {\n 50: 0.14,\n 100: 0.28,\n 200: 0.5,\n 300: 0.72,\n 400: 0.9,\n 500: 1,\n 600: 1,\n 700: 0.92,\n 800: 0.8,\n 900: 0.66,\n 950: 0.52,\n};\n\n/** The step whose lightness is nearest to `color`'s. */\nexport function nearestTonalStep(color: G9ColorInput): G9TonalStep {\n const { l } = toOklch(color);\n let best: G9TonalStep = 500;\n for (const step of g9TonalSteps) if (Math.abs(STEP_L[step] - l) < Math.abs(STEP_L[best] - l)) best = step;\n return best;\n}\n\n/**\n * A tonal scale from one colour: same hue, lightness from the step table, chroma scaled from the source's. The source\n * itself is placed exactly at its nearest step, so the brand colour always appears in its own scale unchanged.\n */\nexport function tonalScale(color: G9ColorInput): G9TonalScale {\n const src = toOklch(color);\n const exact = nearestTonalStep(color);\n const peak = src.c / STEP_C[exact];\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) {\n out[step] = step === exact ? opaque(color) : oklchToHex({ l: STEP_L[step], c: peak * STEP_C[step], h: src.h });\n }\n return out;\n}\n\n/**\n * A neutral scale tinted by `color`: the brand's hue at a whisper of chroma (`tint` 0 = pure grey, 1 = 0.02 C, the\n * strongest tint that still reads as grey), so surfaces and text belong to the brand without looking coloured.\n */\nexport function neutralScale(color: G9ColorInput, tint = 0.5): G9TonalScale {\n const { h } = toOklch(color);\n const c = 0.02 * Math.min(1, Math.max(0, tint));\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) out[step] = oklchToHex({ l: STEP_L[step], c, h });\n return out;\n}\n\n/** Perceptual distance (ΔE in OKLab, ×100: about 2 is just noticeable). */\nexport function colorDistance(a: G9ColorInput, b: G9ColorInput): number {\n const x = toOklch(a);\n const y = toOklch(b);\n const ra = (x.h * Math.PI) / 180;\n const rb = (y.h * Math.PI) / 180;\n return Math.hypot(x.l - y.l, x.c * Math.cos(ra) - y.c * Math.cos(rb), x.c * Math.sin(ra) - y.c * Math.sin(rb)) * 100;\n}\n\n/**\n * `fg` moved in lightness (hue and chroma kept) until its WCAG contrast with `bg` is at least `min`. Goes darker on a\n * light background and lighter on a dark one; returns `fg` unchanged when it already passes. If no lightness of this hue\n * reaches `min`, returns black or white, whichever contrasts more.\n */\nexport function ensureContrast(fg: G9ColorInput, bg: G9ColorInput, min: number): string {\n if (getContrastRatio(fg, bg) >= min) return opaque(fg);\n const src = toOklch(fg);\n const bgL = getLuminance(bg);\n const ratio = (c: G9Rgba) => {\n const l = getLuminance(c);\n return (Math.max(l, bgL) + 0.05) / (Math.min(l, bgL) + 0.05);\n };\n const darker = toOklch(bg).l > 0.6;\n let lo = darker ? 0 : src.l;\n let hi = darker ? src.l : 1;\n let found: number | null = null;\n // 14 halvings: lightness to ~6e-5, below one step of a hex channel; compared in numbers, formatted once\n for (let i = 0; i < 14; i++) {\n const mid = (lo + hi) / 2;\n if (ratio(fromOklch({ l: mid, c: src.c, h: src.h })) >= min) {\n found = mid;\n // keep as close to the original lightness as passing allows\n if (darker) lo = mid;\n else hi = mid;\n } else if (darker) hi = mid;\n else lo = mid;\n }\n if (found !== null) {\n // the hex rounds: step on toward the safe side until the written colour itself passes\n for (let k = 0; k < 8; k++) {\n const hex = oklchToHex({ l: found, c: src.c, h: src.h });\n if (getContrastRatio(hex, bg) >= min) return hex;\n found = Math.min(1, Math.max(0, found + (darker ? -0.002 : 0.002)));\n }\n }\n return getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg) ? '#000000' : '#FFFFFF';\n}\n\n/** Black or white text, whichever contrasts more with `bg`, nudged toward `tint`'s hue when given. */\nexport function readableOn(bg: G9ColorInput, tint?: G9ColorInput): string {\n const dark = getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg);\n if (!tint) return dark ? '#000000' : '#FFFFFF';\n const { h, c } = toOklch(tint);\n return ensureContrast(oklchToHex({ l: dark ? 0.2 : 0.98, c: Math.min(c, 0.04), h }), bg, 4.5);\n}\n\n/** Linear interpolation in OKLCH (shorter hue arc). `t` 0..1. */\nexport function mixOklch(a: G9ColorInput, b: G9ColorInput, t: number): string {\n const x = toOklch(a);\n const y = toOklch(b);\n // A grey end has no hue: it takes the other end's, so grey → blue never sweeps through red. Otherwise the shorter arc.\n let h: number;\n if (x.c === 0) h = y.h;\n else if (y.c === 0) h = x.h;\n else {\n let dh = y.h - x.h;\n if (dh > 180) dh -= 360;\n if (dh < -180) dh += 360;\n h = (x.h + dh * t + 360) % 360;\n }\n return oklchToHex({\n l: x.l + (y.l - x.l) * t,\n c: x.c + (y.c - x.c) * t,\n h,\n alpha: (x.alpha ?? 1) + ((y.alpha ?? 1) - (x.alpha ?? 1)) * t,\n });\n}\n\n/**\n * A colour at `t` (0..1) along several stops, mixed in OKLCH — e.g. Riskara's risk spectrum\n * (`interpolateStops([calm, lime, amber, coral], score / 100)`).\n */\nexport function interpolateStops(stops: readonly G9ColorInput[], t: number): string {\n if (stops.length === 0) throw new RangeError('interpolateStops needs at least one stop.');\n if (stops.length === 1) return formatColor(stops[0] as G9ColorInput);\n const x = Math.min(1, Math.max(0, t)) * (stops.length - 1);\n const i = Math.min(stops.length - 2, Math.floor(x));\n return mixOklch(stops[i] as G9ColorInput, stops[i + 1] as G9ColorInput, x - i);\n}\n\n/**\n * `n` chart colours that start at `primary` and step around the hue circle by the golden angle (137.5°), each at a\n * lightness that reads on `background` (contrast ≥ 3, WCAG for graphics) and a chroma the scheme can carry. Neighbours\n * stay distinguishable for n ≤ 10; the same inputs always give the same palette.\n */\nexport function chartPalette(primary: G9ColorInput, background: G9ColorInput, n = 8): string[] {\n const p = toOklch(primary);\n const dark = toOklch(background).l < 0.5;\n const l = dark ? 0.74 : 0.58;\n const c = Math.max(0.09, Math.min(0.17, p.c || 0.12));\n const out: string[] = [];\n for (let i = 0; i < n; i++) {\n const h = (p.h + i * 137.508) % 360;\n // alternate the lightness a little so neighbours in a stacked chart separate\n const li = l + (i % 2 === 0 ? 0 : dark ? -0.06 : 0.07);\n out.push(ensureContrast(i === 0 ? opaque(primary) : oklchToHex({ l: li, c, h }), background, 3));\n }\n return out;\n}\n"],"names":["toLinear","x","fromLinear","v","linearToOklab","r","g","b","l","Math","m","s","oklabToLinear","L","a","OKLCH_CACHE","Map","toOklch","color","hit","Object","toOklchUncached","toRgba","A","B","c","h","EPS","inGamut","rgb","linearOf","rad","isInSrgbGamut","fromOklch","_x_alpha","probe","lo","hi","i","mid","ch","rgba","oklchToHex","formatColor","opaque","g9TonalSteps","STEP_L","STEP_C","nearestTonalStep","best","step","tonalScale","src","exact","peak","out","neutralScale","tint","colorDistance","y","ra","rb","ensureContrast","fg","bg","min","getContrastRatio","bgL","getLuminance","ratio","darker","found","k","hex","readableOn","dark","mixOklch","t","_y_alpha","_x_alpha1","dh","interpolateStops","stops","RangeError","chartPalette","primary","background","n","p","li"],"mappings":";AAeA,MAAMA,WAAW,CAACC,IACTA,KAAK,UAAUA,IAAI,QAAS,AAACA,CAAAA,CAAAA,IAAI,KAAI,IAAK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AA,IAAI,MAAM,IAAI,IAAIqC,OAAO,QAAQ,IAAG;QACpDpB,IAAI,IAAI,CAACO,eAAexB,AAAM,MAANA,IAAUM,OAAOyC,WAAW3C,WAAW;YAAE,GAAG+C;YAAIhE;YAAGC;QAAE,IAAI4D,YAAY;IAC/F;IACA,OAAO/B;AACT"}
@@ -0,0 +1,44 @@
1
+ import type { G9PaletteValues } from '../tokens/generated/palettes.js';
2
+ import type { G9ShapeSet } from '../tokens/shape.js';
3
+ import { type G9BrandColors, type G9BrandPaletteOptions } from './brand.js';
4
+ import type { G9PaletteOverrides } from './theme.js';
5
+ import { type G9ColorScheme } from './theme.js';
6
+ /** A named recipe. */
7
+ export interface G9ThemeRecipe {
8
+ readonly name: string;
9
+ /** Human name per language (`{ fa: 'تازه', en: 'Fresh' }`). */
10
+ readonly title?: Readonly<Record<string, string>>;
11
+ /** The palette of `scheme` for `brand`. */
12
+ palette(brand: G9BrandColors, scheme: G9ColorScheme): G9PaletteValues;
13
+ /** The recipe's shape (radii, type roles, control heights); default: the library's. */
14
+ readonly shape?: Partial<G9ShapeSet>;
15
+ /** The scheme the recipe looks best in when the user has not chosen (`'light'` default). */
16
+ readonly defaultScheme?: G9ColorScheme;
17
+ }
18
+ /** Adds or replaces a recipe. */
19
+ export declare function registerRecipe(recipe: G9ThemeRecipe): void;
20
+ /** The recipe called `name`. @throws {G9Error} `theme-unknown-recipe`. */
21
+ export declare function getRecipe(name: string): G9ThemeRecipe;
22
+ /** Every registered recipe, in registration order. */
23
+ export declare const listRecipes: () => readonly G9ThemeRecipe[];
24
+ /** One scheme of a recipe for a brand (cached). */
25
+ export declare function recipePalette(name: string, brand: G9BrandColors, scheme: G9ColorScheme): G9PaletteValues;
26
+ /**
27
+ * The palettes a recipe makes for a brand, both schemes (a theme store's `palettes` option): each scheme is built when
28
+ * first read and cached, so the store only builds the one it paints.
29
+ */
30
+ export declare function recipePalettes(name: string, brand: G9BrandColors): {
31
+ readonly light: G9PaletteValues;
32
+ readonly dark: G9PaletteValues;
33
+ };
34
+ /** A recipe built on the brand generator with fixed options. */
35
+ export declare function brandRecipe(name: string, options: G9BrandPaletteOptions, extra?: Partial<G9ThemeRecipe>): G9ThemeRecipe;
36
+ /**
37
+ * A designer's recipe: hand-picked tokens per scheme over a generated base (ShopManager's `designedRecipe`). Tokens not
38
+ * listed come from the brand generator, so a designed theme stays complete when the token set grows.
39
+ */
40
+ export declare function designedRecipe(name: string, designed: {
41
+ readonly light: G9PaletteOverrides;
42
+ readonly dark: G9PaletteOverrides;
43
+ }, options?: G9BrandPaletteOptions & Partial<Omit<G9ThemeRecipe, 'name' | 'palette'>>): G9ThemeRecipe;
44
+ //# sourceMappingURL=recipe.d.ts.map