@g9tm/lynxcontrols-foundation 0.0.0-stage → 1.4.2

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 (164) hide show
  1. package/README.md +4 -2
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/collections.d.ts +16 -0
  4. package/dist/collections.d.ts.map +1 -0
  5. package/dist/collections.js +40 -0
  6. package/dist/collections.js.map +1 -0
  7. package/dist/culture/calendar.d.ts +122 -0
  8. package/dist/culture/calendar.d.ts.map +1 -0
  9. package/dist/culture/calendar.js +379 -0
  10. package/dist/culture/calendar.js.map +1 -0
  11. package/dist/culture/culture.d.ts +91 -0
  12. package/dist/culture/culture.d.ts.map +1 -0
  13. package/dist/culture/culture.js +173 -0
  14. package/dist/culture/culture.js.map +1 -0
  15. package/dist/culture/date-format.d.ts +19 -0
  16. package/dist/culture/date-format.d.ts.map +1 -0
  17. package/dist/culture/date-format.js +101 -0
  18. package/dist/culture/date-format.js.map +1 -0
  19. package/dist/culture/digits.d.ts +29 -0
  20. package/dist/culture/digits.d.ts.map +1 -0
  21. package/dist/culture/digits.js +43 -0
  22. package/dist/culture/digits.js.map +1 -0
  23. package/dist/culture/duration.d.ts +38 -0
  24. package/dist/culture/duration.d.ts.map +1 -0
  25. package/dist/culture/duration.js +41 -0
  26. package/dist/culture/duration.js.map +1 -0
  27. package/dist/culture/index.d.ts +9 -0
  28. package/dist/culture/index.d.ts.map +1 -0
  29. package/dist/culture/index.js +8 -0
  30. package/dist/culture/numbers.d.ts +38 -0
  31. package/dist/culture/numbers.d.ts.map +1 -0
  32. package/dist/culture/numbers.js +64 -0
  33. package/dist/culture/numbers.js.map +1 -0
  34. package/dist/culture/relative-time.d.ts +50 -0
  35. package/dist/culture/relative-time.d.ts.map +1 -0
  36. package/dist/culture/relative-time.js +63 -0
  37. package/dist/culture/relative-time.js.map +1 -0
  38. package/dist/culture/strings.d.ts +145 -0
  39. package/dist/culture/strings.d.ts.map +1 -0
  40. package/dist/culture/strings.js +345 -0
  41. package/dist/culture/strings.js.map +1 -0
  42. package/dist/enums/index.d.ts +195 -0
  43. package/dist/enums/index.d.ts.map +1 -0
  44. package/dist/enums/index.js +130 -0
  45. package/dist/enums/index.js.map +1 -0
  46. package/dist/errors.d.ts +10 -0
  47. package/dist/errors.d.ts.map +1 -0
  48. package/dist/errors.js +21 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/exec/diagnostics.d.ts +74 -0
  51. package/dist/exec/diagnostics.d.ts.map +1 -0
  52. package/dist/exec/diagnostics.js +73 -0
  53. package/dist/exec/diagnostics.js.map +1 -0
  54. package/dist/exec/index.d.ts +5 -0
  55. package/dist/exec/index.d.ts.map +1 -0
  56. package/dist/exec/index.js +4 -0
  57. package/dist/exec/options.d.ts +75 -0
  58. package/dist/exec/options.d.ts.map +1 -0
  59. package/dist/exec/options.js +107 -0
  60. package/dist/exec/options.js.map +1 -0
  61. package/dist/exec/safe-executor.d.ts +138 -0
  62. package/dist/exec/safe-executor.d.ts.map +1 -0
  63. package/dist/exec/safe-executor.js +401 -0
  64. package/dist/exec/safe-executor.js.map +1 -0
  65. package/dist/exec/trace.d.ts +59 -0
  66. package/dist/exec/trace.d.ts.map +1 -0
  67. package/dist/exec/trace.js +108 -0
  68. package/dist/exec/trace.js.map +1 -0
  69. package/dist/icons/generated/glyph-svg.d.ts +37 -0
  70. package/dist/icons/generated/glyph-svg.d.ts.map +1 -0
  71. package/dist/icons/generated/glyph-svg.js +33 -0
  72. package/dist/icons/generated/glyph-svg.js.map +1 -0
  73. package/dist/icons/glyph-slots.d.ts +79 -0
  74. package/dist/icons/glyph-slots.d.ts.map +1 -0
  75. package/dist/icons/glyph-slots.js +50 -0
  76. package/dist/icons/glyph-slots.js.map +1 -0
  77. package/dist/icons/glyph.d.ts +76 -0
  78. package/dist/icons/glyph.d.ts.map +1 -0
  79. package/dist/icons/glyph.js +42 -0
  80. package/dist/icons/glyph.js.map +1 -0
  81. package/dist/icons/icon-fonts.d.ts +55 -0
  82. package/dist/icons/icon-fonts.d.ts.map +1 -0
  83. package/dist/icons/icon-fonts.js +74 -0
  84. package/dist/icons/icon-fonts.js.map +1 -0
  85. package/dist/icons/icon.d.ts +102 -0
  86. package/dist/icons/icon.d.ts.map +1 -0
  87. package/dist/icons/icon.js +132 -0
  88. package/dist/icons/icon.js.map +1 -0
  89. package/dist/icons/index.d.ts +7 -0
  90. package/dist/icons/index.d.ts.map +1 -0
  91. package/dist/icons/index.js +6 -0
  92. package/dist/icons/svg.d.ts +28 -0
  93. package/dist/icons/svg.d.ts.map +1 -0
  94. package/dist/icons/svg.js +59 -0
  95. package/dist/icons/svg.js.map +1 -0
  96. package/dist/index.d.ts +10 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +9 -0
  99. package/dist/services/abort.d.ts +31 -0
  100. package/dist/services/abort.d.ts.map +1 -0
  101. package/dist/services/abort.js +47 -0
  102. package/dist/services/abort.js.map +1 -0
  103. package/dist/services/clock.d.ts +35 -0
  104. package/dist/services/clock.d.ts.map +1 -0
  105. package/dist/services/clock.js +37 -0
  106. package/dist/services/clock.js.map +1 -0
  107. package/dist/services/contracts.d.ts +200 -0
  108. package/dist/services/contracts.d.ts.map +1 -0
  109. package/dist/services/contracts.js +37 -0
  110. package/dist/services/contracts.js.map +1 -0
  111. package/dist/services/index.d.ts +5 -0
  112. package/dist/services/index.d.ts.map +1 -0
  113. package/dist/services/index.js +4 -0
  114. package/dist/services/preferences.d.ts +105 -0
  115. package/dist/services/preferences.d.ts.map +1 -0
  116. package/dist/services/preferences.js +253 -0
  117. package/dist/services/preferences.js.map +1 -0
  118. package/dist/theme/color.d.ts +94 -0
  119. package/dist/theme/color.d.ts.map +1 -0
  120. package/dist/theme/color.js +150 -0
  121. package/dist/theme/color.js.map +1 -0
  122. package/dist/theme/control-colors.d.ts +46 -0
  123. package/dist/theme/control-colors.d.ts.map +1 -0
  124. package/dist/theme/control-colors.js +46 -0
  125. package/dist/theme/control-colors.js.map +1 -0
  126. package/dist/theme/index.d.ts +5 -0
  127. package/dist/theme/index.d.ts.map +1 -0
  128. package/dist/theme/index.js +4 -0
  129. package/dist/theme/theme.d.ts +88 -0
  130. package/dist/theme/theme.d.ts.map +1 -0
  131. package/dist/theme/theme.js +190 -0
  132. package/dist/theme/theme.js.map +1 -0
  133. package/dist/theme/variants.d.ts +33 -0
  134. package/dist/theme/variants.d.ts.map +1 -0
  135. package/dist/theme/variants.js +53 -0
  136. package/dist/theme/variants.js.map +1 -0
  137. package/dist/tokens/css-vars.d.ts +41 -0
  138. package/dist/tokens/css-vars.d.ts.map +1 -0
  139. package/dist/tokens/css-vars.js +55 -0
  140. package/dist/tokens/css-vars.js.map +1 -0
  141. package/dist/tokens/generated/metrics.d.ts +184 -0
  142. package/dist/tokens/generated/metrics.d.ts.map +1 -0
  143. package/dist/tokens/generated/metrics.js +349 -0
  144. package/dist/tokens/generated/metrics.js.map +1 -0
  145. package/dist/tokens/generated/palettes.d.ts +113 -0
  146. package/dist/tokens/generated/palettes.d.ts.map +1 -0
  147. package/dist/tokens/generated/palettes.js +391 -0
  148. package/dist/tokens/generated/palettes.js.map +1 -0
  149. package/dist/tokens/index.d.ts +5 -0
  150. package/dist/tokens/index.d.ts.map +1 -0
  151. package/dist/tokens/index.js +4 -0
  152. package/dist/tokens/layout-metrics.d.ts +120 -0
  153. package/dist/tokens/layout-metrics.d.ts.map +1 -0
  154. package/dist/tokens/layout-metrics.js +111 -0
  155. package/dist/tokens/layout-metrics.js.map +1 -0
  156. package/docs/api.md +369 -0
  157. package/docs/foundation.md +370 -0
  158. package/docs/migration/Core.Controls.Shared.md +475 -0
  159. package/docs/migration/Core.Helpers.md +132 -0
  160. package/docs/migration/Core.Icons.md +135 -0
  161. package/docs/migration/Core.Localization.md +118 -0
  162. package/docs/migration/Core.Storage.md +54 -0
  163. package/docs/migration/Core.Theming.md +328 -0
  164. package/package.json +59 -4
@@ -0,0 +1,150 @@
1
+ import { G9Error } from "../errors.js";
2
+ function _define_property(obj, key, value) {
3
+ if (key in obj) Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ else obj[key] = value;
10
+ return obj;
11
+ }
12
+ class G9ColorFormatError extends G9Error {
13
+ constructor(input, accepted){
14
+ super('color-format', `"${input}" is not a supported colour. Accepted: ${accepted}.`), _define_property(this, "input", void 0);
15
+ this.name = 'G9ColorFormatError';
16
+ this.input = input;
17
+ }
18
+ }
19
+ const CSS_FORMATS = '#rgb, #rgba, #rrggbb, #rrggbbaa, rgb(r, g, b), rgba(r, g, b, a), transparent';
20
+ const MAUI_FORMATS = '#rgb, #argb, #rrggbb, #aarrggbb (MAUI ARGB order)';
21
+ const clamp01 = (value)=>value < 0 ? 0 : value > 1 ? 1 : value;
22
+ function rgba(r, g, b, a = 1) {
23
+ return {
24
+ r: Math.fround(clamp01(r)),
25
+ g: Math.fround(clamp01(g)),
26
+ b: Math.fround(clamp01(b)),
27
+ a: Math.fround(clamp01(a))
28
+ };
29
+ }
30
+ const fromBytes = (r, g, b, a)=>rgba(r / 255, g / 255, b / 255, a / 255);
31
+ const HEX = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
32
+ function hexBytes(digits) {
33
+ const pairs = digits.length <= 4 ? digits.split('').map((d)=>d + d) : digits.match(/../g);
34
+ return pairs.map((pair)=>Number.parseInt(pair, 16));
35
+ }
36
+ function parseMauiColor(hex) {
37
+ const match = HEX.exec(hex.trim());
38
+ if (!match) throw new G9ColorFormatError(hex, MAUI_FORMATS);
39
+ const bytes = hexBytes(match[1]);
40
+ const [a, r, g, b] = 4 === bytes.length ? bytes : [
41
+ 255,
42
+ ...bytes
43
+ ];
44
+ return fromBytes(r, g, b, a);
45
+ }
46
+ const NUMBER = '\\s*([+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?%?)\\s*';
47
+ const RGB = new RegExp(`^rgba?\\(${NUMBER},${NUMBER},${NUMBER}(?:,${NUMBER})?\\)$`, 'i');
48
+ function channel(text, scale) {
49
+ return text.endsWith('%') ? Number(text.slice(0, -1)) / 100 : Number(text) / scale;
50
+ }
51
+ function parseColor(value) {
52
+ const text = value.trim();
53
+ const hex = HEX.exec(text);
54
+ if (hex) {
55
+ const bytes = hexBytes(hex[1]);
56
+ const [r, g, b, a = 255] = bytes;
57
+ return fromBytes(r, g, b, a);
58
+ }
59
+ if ('transparent' === text.toLowerCase()) return rgba(0, 0, 0, 0);
60
+ const fn = RGB.exec(text);
61
+ const isRgba = /^rgba/i.test(text);
62
+ if (fn && isRgba === (void 0 !== fn[4])) {
63
+ const alpha = void 0 === fn[4] ? 1 : channel(fn[4], 1);
64
+ return rgba(channel(fn[1], 255), channel(fn[2], 255), channel(fn[3], 255), alpha);
65
+ }
66
+ throw new G9ColorFormatError(value, CSS_FORMATS);
67
+ }
68
+ function tryParseColor(value) {
69
+ try {
70
+ return parseColor(value);
71
+ } catch {
72
+ return;
73
+ }
74
+ }
75
+ function toRgba(color) {
76
+ return 'string' == typeof color ? parseColor(color) : rgba(color.r, color.g, color.b, color.a);
77
+ }
78
+ const color_byte = (value)=>Math.round(255 * clamp01(value));
79
+ const hex2 = (value)=>(value < 16 ? '0' : '') + value.toString(16).toUpperCase();
80
+ function shortestFloat32(value) {
81
+ for(let digits = 1; digits < 9; digits++){
82
+ const text = String(Number(value.toPrecision(digits)));
83
+ if (Math.fround(Number(text)) === value) return text;
84
+ }
85
+ return String(Number(value.toPrecision(9)));
86
+ }
87
+ function formatColor(color) {
88
+ const c = toRgba(color);
89
+ if (1 === c.a) return `#${hex2(color_byte(c.r))}${hex2(color_byte(c.g))}${hex2(color_byte(c.b))}`;
90
+ return `rgba(${color_byte(c.r)}, ${color_byte(c.g)}, ${color_byte(c.b)}, ${shortestFloat32(clamp01(c.a))})`;
91
+ }
92
+ function toHex(color) {
93
+ const c = toRgba(color);
94
+ const truncated = (v)=>Math.trunc(Math.fround(255 * v));
95
+ return `#${hex2(truncated(c.r))}${hex2(truncated(c.g))}${hex2(truncated(c.b))}`;
96
+ }
97
+ function withAlpha(color, alpha) {
98
+ const c = toRgba(color);
99
+ return rgba(c.r, c.g, c.b, Math.fround(alpha));
100
+ }
101
+ const FLOAT_TEXT = /^\s*[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?\s*$/i;
102
+ function withOpacity(color, opacity) {
103
+ if (null == opacity) return toRgba(color);
104
+ let value = 1;
105
+ if ('number' == typeof opacity) value = opacity;
106
+ else if (FLOAT_TEXT.test(opacity)) value = Number(opacity);
107
+ return withAlpha(color, Number.isNaN(value) ? 1 : clamp01(value));
108
+ }
109
+ function applyAlpha(color, alpha) {
110
+ return 'number' == typeof alpha ? withAlpha(color, clamp01(alpha)) : toRgba(color);
111
+ }
112
+ function darken(color, percentage) {
113
+ const c = toRgba(color);
114
+ const k = 1 - clamp01(percentage);
115
+ return rgba(Math.fround(c.r * k), Math.fround(c.g * k), Math.fround(c.b * k), c.a);
116
+ }
117
+ function lighten(color, percentage) {
118
+ const c = toRgba(color);
119
+ const p = clamp01(percentage);
120
+ const up = (v)=>Math.fround(v + (1 - v) * p);
121
+ return rgba(up(c.r), up(c.g), up(c.b), c.a);
122
+ }
123
+ function mix(first, second, ratio) {
124
+ const c1 = toRgba(first);
125
+ const c2 = toRgba(second);
126
+ const t = clamp01(ratio);
127
+ const lerp = (x, y)=>Math.fround(x * (1 - t) + y * t);
128
+ return rgba(lerp(c1.r, c2.r), lerp(c1.g, c2.g), lerp(c1.b, c2.b), lerp(c1.a, c2.a));
129
+ }
130
+ const createBorderColor = (base)=>darken(base, 0.15);
131
+ const createHoverColor = (base)=>darken(base, 0.08);
132
+ const createPressedColor = (base)=>darken(base, 0.2);
133
+ const linear = (v)=>v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
134
+ function getLuminance(color) {
135
+ const c = toRgba(color);
136
+ return 0.2126 * linear(c.r) + 0.7152 * linear(c.g) + 0.0722 * linear(c.b);
137
+ }
138
+ function getContrastingTextColor(background) {
139
+ return getLuminance(background) > 0.5 ? rgba(0, 0, 0, 1) : rgba(1, 1, 1, 1);
140
+ }
141
+ function getContrastRatio(first, second) {
142
+ const l1 = getLuminance(first);
143
+ const l2 = getLuminance(second);
144
+ return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
145
+ }
146
+ const meetsWcagAA = (foreground, background)=>getContrastRatio(foreground, background) >= 4.5;
147
+ const meetsWcagAAA = (foreground, background)=>getContrastRatio(foreground, background) >= 7;
148
+ export { G9ColorFormatError, applyAlpha, createBorderColor, createHoverColor, createPressedColor, darken, formatColor, getContrastRatio, getContrastingTextColor, getLuminance, lighten, meetsWcagAA, meetsWcagAAA, mix, parseColor, parseMauiColor, rgba, toHex, toRgba, tryParseColor, withAlpha, withOpacity };
149
+
150
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme/color.js","sources":["../../src/theme/color.ts"],"sourcesContent":["import { G9Error } from '../errors';\n\n/**\n * A CSS colour string, the value type every G9 colour prop takes (plan/specs/03-API-Conventions.md §2). Use\n * {@link g9Token} for a theme token reference such as `var(--g9-primary)`.\n */\nexport type G9Color = string;\n\n/**\n * A colour as four channels in `0..1`, stored at float32 precision exactly like MAUI `Color`. Colour arithmetic\n * (darken, mix, contrast) runs on this shape so its results match the original helpers bit for bit; format with\n * {@link formatColor} to get a CSS string back.\n */\nexport interface G9Rgba {\n readonly r: number;\n readonly g: number;\n readonly b: number;\n readonly a: number;\n}\n\n/** Anything the colour helpers accept: a CSS colour string or channels. */\nexport type G9ColorInput = G9Color | G9Rgba;\n\n/** Thrown when a string is not a colour this library can read. */\nexport class G9ColorFormatError extends G9Error {\n /** The rejected input. */\n readonly input: string;\n\n constructor(input: string, accepted: string) {\n super('color-format', `\"${input}\" is not a supported colour. Accepted: ${accepted}.`);\n this.name = 'G9ColorFormatError';\n this.input = input;\n }\n}\n\nconst CSS_FORMATS = '#rgb, #rgba, #rrggbb, #rrggbbaa, rgb(r, g, b), rgba(r, g, b, a), transparent';\nconst MAUI_FORMATS = '#rgb, #argb, #rrggbb, #aarrggbb (MAUI ARGB order)';\n\nconst clamp01 = (value: number): number => (value < 0 ? 0 : value > 1 ? 1 : value);\n\n/**\n * Builds channels the way the MAUI `Color(float, float, float, float)` constructor does: each channel is clamped to\n * `0..1` and stored as float32. `NaN` stays `NaN`, as it does in .NET.\n */\nexport function rgba(r: number, g: number, b: number, a = 1): G9Rgba {\n return {\n r: Math.fround(clamp01(r)),\n g: Math.fround(clamp01(g)),\n b: Math.fround(clamp01(b)),\n a: Math.fround(clamp01(a)),\n };\n}\n\nconst fromBytes = (r: number, g: number, b: number, a: number): G9Rgba => rgba(r / 255, g / 255, b / 255, a / 255);\n\nconst HEX = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\n\nfunction hexBytes(digits: string): number[] {\n const pairs = digits.length <= 4 ? digits.split('').map((d) => d + d) : (digits.match(/../g) as string[]);\n return pairs.map((pair) => Number.parseInt(pair, 16));\n}\n\n/**\n * Parses a colour written the MAUI way: `#rgb`, `#argb`, `#rrggbb` or `#aarrggbb`. Note the **alpha-first** order\n * for 4 and 8 digits, unlike CSS. This is how the MAUI theme dictionaries and `golden/theme-palettes.json` spell\n * colours.\n */\nexport function parseMauiColor(hex: string): G9Rgba {\n const match = HEX.exec(hex.trim());\n if (!match) throw new G9ColorFormatError(hex, MAUI_FORMATS);\n const bytes = hexBytes(match[1] as string);\n const [a, r, g, b] = bytes.length === 4 ? bytes : [255, ...bytes];\n return fromBytes(r as number, g as number, b as number, a as number);\n}\n\nconst NUMBER = '\\\\s*([+-]?(?:\\\\d+\\\\.?\\\\d*|\\\\.\\\\d+)(?:e[+-]?\\\\d+)?%?)\\\\s*';\nconst RGB = new RegExp(`^rgba?\\\\(${NUMBER},${NUMBER},${NUMBER}(?:,${NUMBER})?\\\\)$`, 'i');\n\nfunction channel(text: string, scale: number): number {\n return text.endsWith('%') ? Number(text.slice(0, -1)) / 100 : Number(text) / scale;\n}\n\n/**\n * Parses a CSS colour: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` (CSS order, alpha last), `rgb(r, g, b)`,\n * `rgba(r, g, b, a)` (channels 0–255 or percentages, alpha 0–1 or a percentage) and `transparent`.\n * Named colours other than `transparent` are not accepted: the palette tokens are the names.\n *\n * @throws {G9ColorFormatError} for anything else.\n */\nexport function parseColor(value: string): G9Rgba {\n const text = value.trim();\n const hex = HEX.exec(text);\n if (hex) {\n const bytes = hexBytes(hex[1] as string);\n const [r, g, b, a = 255] = bytes;\n return fromBytes(r as number, g as number, b as number, a);\n }\n if (text.toLowerCase() === 'transparent') return rgba(0, 0, 0, 0);\n const fn = RGB.exec(text);\n const isRgba = /^rgba/i.test(text);\n if (fn && isRgba === (fn[4] !== undefined)) {\n const alpha = fn[4] === undefined ? 1 : channel(fn[4], 1);\n return rgba(channel(fn[1] as string, 255), channel(fn[2] as string, 255), channel(fn[3] as string, 255), alpha);\n }\n throw new G9ColorFormatError(value, CSS_FORMATS);\n}\n\n/** {@link parseColor} that returns `undefined` instead of throwing. */\nexport function tryParseColor(value: string): G9Rgba | undefined {\n try {\n return parseColor(value);\n } catch {\n return undefined;\n }\n}\n\n/** Normalises a helper input to channels. Strings go through {@link parseColor}. */\nexport function toRgba(color: G9ColorInput): G9Rgba {\n return typeof color === 'string' ? parseColor(color) : rgba(color.r, color.g, color.b, color.a);\n}\n\nconst byte = (value: number): number => Math.round(clamp01(value) * 255);\nconst hex2 = (value: number): string => (value < 16 ? '0' : '') + value.toString(16).toUpperCase();\n\n/**\n * The shortest decimal that reads back as the same float32 (what .NET's round-trip format prints for a `float`), so\n * a formatted alpha parses back to exactly the stored channel.\n */\nfunction shortestFloat32(value: number): string {\n for (let digits = 1; digits < 9; digits++) {\n const text = String(Number(value.toPrecision(digits)));\n if (Math.fround(Number(text)) === value) return text;\n }\n return String(Number(value.toPrecision(9)));\n}\n\n/**\n * Formats a colour as CSS: `#RRGGBB` when opaque, otherwise `rgba(R, G, B, A)`. Channels are rounded to the nearest\n * byte; the alpha is printed with the fewest digits that parse back to the same float32 value, so\n * `parseColor(formatColor(c))` reproduces the alpha exactly.\n */\nexport function formatColor(color: G9ColorInput): G9Color {\n const c = toRgba(color);\n if (c.a === 1) return `#${hex2(byte(c.r))}${hex2(byte(c.g))}${hex2(byte(c.b))}`;\n return `rgba(${byte(c.r)}, ${byte(c.g)}, ${byte(c.b)}, ${shortestFloat32(clamp01(c.a))})`;\n}\n\n/**\n * MAUI `G9ColorHelper.ToHex`: `#RRGGBB` without alpha, each channel **truncated** after a float32 multiply by 255 —\n * the original's exact arithmetic, kept so derived colours print the same hex as before.\n */\nexport function toHex(color: G9ColorInput): string {\n const c = toRgba(color);\n const truncated = (v: number): number => Math.trunc(Math.fround(v * 255));\n return `#${hex2(truncated(c.r))}${hex2(truncated(c.g))}${hex2(truncated(c.b))}`;\n}\n\n/** The same colour with a new alpha (`MAUI Color.WithAlpha`); `alpha` is clamped to `0..1`. */\nexport function withAlpha(color: G9ColorInput, alpha: number): G9Rgba {\n const c = toRgba(color);\n return rgba(c.r, c.g, c.b, Math.fround(alpha));\n}\n\nconst FLOAT_TEXT = /^\\s*[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?\\s*$/i;\n\n/**\n * MAUI `G9ColorHelper.WithOpacity`. `null`/`undefined` returns the colour unchanged; a number or an invariant-culture\n * numeric string sets the alpha, clamped to `0..1`; an unreadable string means opacity `1`.\n */\nexport function withOpacity(color: G9ColorInput, opacity: number | string | null | undefined): G9Rgba {\n if (opacity === null || opacity === undefined) return toRgba(color);\n let value = 1;\n if (typeof opacity === 'number') value = opacity;\n else if (FLOAT_TEXT.test(opacity)) value = Number(opacity);\n return withAlpha(color, Number.isNaN(value) ? 1 : clamp01(value));\n}\n\n/**\n * MAUI `G9AlphaConverter.Convert`: applies `alpha` (clamped to `0..1`) when it is a number, otherwise returns the\n * colour unchanged. `ConvertBack` had no behaviour (it threw) and has no counterpart.\n */\nexport function applyAlpha(color: G9ColorInput, alpha: number | null | undefined): G9Rgba {\n return typeof alpha === 'number' ? withAlpha(color, clamp01(alpha)) : toRgba(color);\n}\n\n/** Darkens each RGB channel by `percentage` (`0..1`, clamped); alpha is kept. MAUI `G9ColorHelper.Darken`. */\nexport function darken(color: G9ColorInput, percentage: number): G9Rgba {\n const c = toRgba(color);\n const k = 1 - clamp01(percentage);\n return rgba(Math.fround(c.r * k), Math.fround(c.g * k), Math.fround(c.b * k), c.a);\n}\n\n/** Moves each RGB channel towards white by `percentage` (`0..1`, clamped). MAUI `G9ColorHelper.Lighten`. */\nexport function lighten(color: G9ColorInput, percentage: number): G9Rgba {\n const c = toRgba(color);\n const p = clamp01(percentage);\n const up = (v: number): number => Math.fround(v + (1 - v) * p);\n return rgba(up(c.r), up(c.g), up(c.b), c.a);\n}\n\n/** Linear mix of all four channels: `ratio` 0 is all `first`, 1 is all `second` (clamped). MAUI `Mix`. */\nexport function mix(first: G9ColorInput, second: G9ColorInput, ratio: number): G9Rgba {\n const c1 = toRgba(first);\n const c2 = toRgba(second);\n const t = clamp01(ratio);\n const lerp = (x: number, y: number): number => Math.fround(x * (1 - t) + y * t);\n return rgba(lerp(c1.r, c2.r), lerp(c1.g, c2.g), lerp(c1.b, c2.b), lerp(c1.a, c2.a));\n}\n\n/** 15 % darker: the stock border recipe. MAUI `G9ColorHelper.CreateBorderColor`. */\nexport const createBorderColor = (base: G9ColorInput): G9Rgba => darken(base, 0.15);\n/** 8 % darker: the stock hover recipe. MAUI `G9ColorHelper.CreateHoverColor`. */\nexport const createHoverColor = (base: G9ColorInput): G9Rgba => darken(base, 0.08);\n/** 20 % darker: the stock pressed recipe. MAUI `G9ColorHelper.CreatePressedColor`. */\nexport const createPressedColor = (base: G9ColorInput): G9Rgba => darken(base, 0.2);\n\nconst linear = (v: number): number => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);\n\n/** WCAG relative luminance, `0` (black) to `1` (white). Alpha is ignored, as in MAUI. */\nexport function getLuminance(color: G9ColorInput): number {\n const c = toRgba(color);\n return 0.2126 * linear(c.r) + 0.7152 * linear(c.g) + 0.0722 * linear(c.b);\n}\n\n/** Black on light backgrounds (luminance above 0.5), white otherwise. MAUI `GetContrastingTextColor`. */\nexport function getContrastingTextColor(background: G9ColorInput): G9Rgba {\n return getLuminance(background) > 0.5 ? rgba(0, 0, 0, 1) : rgba(1, 1, 1, 1);\n}\n\n/** WCAG contrast ratio, `1` to `21`. */\nexport function getContrastRatio(first: G9ColorInput, second: G9ColorInput): number {\n const l1 = getLuminance(first);\n const l2 = getLuminance(second);\n return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);\n}\n\n/** Contrast of at least 4.5:1 (WCAG AA, normal text). */\nexport const meetsWcagAA = (foreground: G9ColorInput, background: G9ColorInput): boolean =>\n getContrastRatio(foreground, background) >= 4.5;\n\n/** Contrast of at least 7:1 (WCAG AAA, normal text). */\nexport const meetsWcagAAA = (foreground: G9ColorInput, background: G9ColorInput): boolean =>\n getContrastRatio(foreground, background) >= 7;\n"],"names":["G9ColorFormatError","G9Error","input","accepted","CSS_FORMATS","MAUI_FORMATS","clamp01","value","rgba","r","g","b","a","Math","fromBytes","HEX","hexBytes","digits","pairs","d","pair","Number","parseMauiColor","hex","match","bytes","NUMBER","RGB","RegExp","channel","text","scale","parseColor","fn","isRgba","undefined","alpha","tryParseColor","toRgba","color","byte","hex2","shortestFloat32","String","formatColor","c","toHex","truncated","v","withAlpha","FLOAT_TEXT","withOpacity","opacity","applyAlpha","darken","percentage","k","lighten","p","up","mix","first","second","ratio","c1","c2","t","lerp","x","y","createBorderColor","base","createHoverColor","createPressedColor","linear","getLuminance","getContrastingTextColor","background","getContrastRatio","l1","l2","meetsWcagAA","foreground","meetsWcagAAA"],"mappings":";;;;;;;;;;;AAwBO,MAAMA,2B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AAKL,aAAab;IACxB,OAAQjD,AAAAA,CAAAA,KAAK,GAAG,CAACkE,IAAIC,MAAM,IAAG,IAAMnE,CAAAA,KAAK,GAAG,CAACkE,IAAIC,MAAM,IAAG;AAC5D;AAGO,MAAMC,cAAc,CAACC,YAA0BL,aACpDC,iBAAiBI,YAAYL,eAAe;AAGvC,MAAMM,eAAe,CAACD,YAA0BL,aACrDC,iBAAiBI,YAAYL,eAAe"}
@@ -0,0 +1,46 @@
1
+ import { type G9Color, type G9ColorInput } from './color.js';
2
+ import type { G9ResolvedTheme } from './theme.js';
3
+ /** Alpha recipes the G9 controls paint with (MAUI `G9Colors` constants). */
4
+ export declare const G9Colors: {
5
+ readonly InsetHighlightTopAlpha: 0.2;
6
+ readonly InsetHighlightBottomAlpha: 0.1;
7
+ /** Ink ripple under leading/trailing field icons: legible on a sunlit OLED without muddying the glyph. */
8
+ readonly IconRippleAlpha: 0.32;
9
+ readonly SliderTooltipAlphaActive: 0.1;
10
+ readonly SliderTooltipBorderAlpha: 1;
11
+ /** Peak alpha of the check-box press halo, painted in `Primary`. */
12
+ readonly CheckBoxHaloAlpha: 0.14;
13
+ /** Alpha of a disabled check box's unchecked outline (light `Outline` and `TextDisabled` are the same grey). */
14
+ readonly CheckBoxDisabledOutlineAlpha: 0.55;
15
+ };
16
+ /** Switch track when off: `SurfaceContainerHighest` in dark, `OutlineVariant` in light. */
17
+ export declare const switchOffTrack: (theme: G9ResolvedTheme) => G9Color;
18
+ /** Switch track when on: `Primary`. */
19
+ export declare const switchOnTrack: (theme: G9ResolvedTheme) => G9Color;
20
+ /** Switch thumb when off: `OnSurfaceVariant` in dark, `Surface` in light. */
21
+ export declare const switchThumbOff: (theme: G9ResolvedTheme) => G9Color;
22
+ /** Switch thumb when on: `OnPrimaryContainer` in dark, `OnPrimary` in light. */
23
+ export declare const switchThumbOn: (theme: G9ResolvedTheme) => G9Color;
24
+ /** Check mark / indeterminate bar on a filled box: `OnPrimary` (the one place the mark colour is decided). */
25
+ export declare const checkBoxMark: (theme: G9ResolvedTheme) => G9Color;
26
+ /** A gradient stop: colour at `offset` (`0..1`). */
27
+ export interface G9GradientStop {
28
+ readonly color: G9Color;
29
+ readonly offset: number;
30
+ }
31
+ /** A fill: a solid colour, or a top-to-bottom linear gradient. */
32
+ export type G9Fill = {
33
+ readonly kind: 'solid';
34
+ readonly color: G9Color;
35
+ } | {
36
+ readonly kind: 'verticalGradient';
37
+ readonly stops: readonly G9GradientStop[];
38
+ };
39
+ /**
40
+ * MAUI `G9Colors.BuildSolidOrGradient`: the solid colour, or a vertical gradient from 8 % lighter (top) through the
41
+ * colour (middle) to 8 % darker (bottom).
42
+ */
43
+ export declare function buildSolidOrGradient(base: G9ColorInput, useGradient: boolean): G9Fill;
44
+ /** A fill as a CSS `background` value: the colour, or `linear-gradient(to bottom, …)`. */
45
+ export declare function fillToCss(fill: G9Fill): string;
46
+ //# sourceMappingURL=control-colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-colors.d.ts","sourceRoot":"","sources":["../../src/theme/control-colors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,OAAO,EAAE,KAAK,YAAY,EAAW,MAAM,SAAS,CAAC;AACxF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,4EAA4E;AAC5E,eAAO,MAAM,QAAQ;;;IAGnB,0GAA0G;;;;IAI1G,oEAAoE;;IAEpE,gHAAgH;;CAExG,CAAC;AAEX,2FAA2F;AAC3F,eAAO,MAAM,cAAc,GAAI,OAAO,eAAe,KAAG,OACwC,CAAC;AAEjG,uCAAuC;AACvC,eAAO,MAAM,aAAa,GAAI,OAAO,eAAe,KAAG,OAAgC,CAAC;AAExF,6EAA6E;AAC7E,eAAO,MAAM,cAAc,GAAI,OAAO,eAAe,KAAG,OAC0B,CAAC;AAEnF,gFAAgF;AAChF,eAAO,MAAM,aAAa,GAAI,OAAO,eAAe,KAAG,OAC+B,CAAC;AAEvF,8GAA8G;AAC9G,eAAO,MAAM,YAAY,GAAI,OAAO,eAAe,KAAG,OAAkC,CAAC;AAEzF,oDAAoD;AACpD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,kEAAkE;AAClE,MAAM,MAAM,MAAM,GACd;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,CAAC;AAErF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CAWrF;AAED,0FAA0F;AAC1F,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9C"}
@@ -0,0 +1,46 @@
1
+ import { darken, formatColor, lighten } from "./color.js";
2
+ const G9Colors = {
3
+ InsetHighlightTopAlpha: 0.2,
4
+ InsetHighlightBottomAlpha: 0.1,
5
+ IconRippleAlpha: 0.32,
6
+ SliderTooltipAlphaActive: 0.1,
7
+ SliderTooltipBorderAlpha: 1,
8
+ CheckBoxHaloAlpha: 0.14,
9
+ CheckBoxDisabledOutlineAlpha: 0.55
10
+ };
11
+ const switchOffTrack = (theme)=>'dark' === theme.scheme ? theme.palette.SurfaceContainerHighest : theme.palette.OutlineVariant;
12
+ const switchOnTrack = (theme)=>theme.palette.Primary;
13
+ const switchThumbOff = (theme)=>'dark' === theme.scheme ? theme.palette.OnSurfaceVariant : theme.palette.Surface;
14
+ const switchThumbOn = (theme)=>'dark' === theme.scheme ? theme.palette.OnPrimaryContainer : theme.palette.OnPrimary;
15
+ const checkBoxMark = (theme)=>theme.palette.OnPrimary;
16
+ function buildSolidOrGradient(base, useGradient) {
17
+ const color = formatColor(base);
18
+ if (!useGradient) return {
19
+ kind: 'solid',
20
+ color
21
+ };
22
+ return {
23
+ kind: 'verticalGradient',
24
+ stops: [
25
+ {
26
+ color: formatColor(lighten(base, 0.08)),
27
+ offset: 0
28
+ },
29
+ {
30
+ color,
31
+ offset: 0.5
32
+ },
33
+ {
34
+ color: formatColor(darken(base, 0.08)),
35
+ offset: 1
36
+ }
37
+ ]
38
+ };
39
+ }
40
+ function fillToCss(fill) {
41
+ if ('solid' === fill.kind) return fill.color;
42
+ return `linear-gradient(to bottom, ${fill.stops.map((s)=>`${s.color} ${100 * s.offset}%`).join(', ')})`;
43
+ }
44
+ export { G9Colors, buildSolidOrGradient, checkBoxMark, fillToCss, switchOffTrack, switchOnTrack, switchThumbOff, switchThumbOn };
45
+
46
+ //# sourceMappingURL=control-colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme/control-colors.js","sources":["../../src/theme/control-colors.ts"],"sourcesContent":["import { darken, formatColor, type G9Color, type G9ColorInput, lighten } from './color';\nimport type { G9ResolvedTheme } from './theme';\n\n/** Alpha recipes the G9 controls paint with (MAUI `G9Colors` constants). */\nexport const G9Colors = {\n InsetHighlightTopAlpha: 0.2,\n InsetHighlightBottomAlpha: 0.1,\n /** Ink ripple under leading/trailing field icons: legible on a sunlit OLED without muddying the glyph. */\n IconRippleAlpha: 0.32,\n SliderTooltipAlphaActive: 0.1,\n SliderTooltipBorderAlpha: 1,\n /** Peak alpha of the check-box press halo, painted in `Primary`. */\n CheckBoxHaloAlpha: 0.14,\n /** Alpha of a disabled check box's unchecked outline (light `Outline` and `TextDisabled` are the same grey). */\n CheckBoxDisabledOutlineAlpha: 0.55,\n} as const;\n\n/** Switch track when off: `SurfaceContainerHighest` in dark, `OutlineVariant` in light. */\nexport const switchOffTrack = (theme: G9ResolvedTheme): G9Color =>\n theme.scheme === 'dark' ? theme.palette.SurfaceContainerHighest : theme.palette.OutlineVariant;\n\n/** Switch track when on: `Primary`. */\nexport const switchOnTrack = (theme: G9ResolvedTheme): G9Color => theme.palette.Primary;\n\n/** Switch thumb when off: `OnSurfaceVariant` in dark, `Surface` in light. */\nexport const switchThumbOff = (theme: G9ResolvedTheme): G9Color =>\n theme.scheme === 'dark' ? theme.palette.OnSurfaceVariant : theme.palette.Surface;\n\n/** Switch thumb when on: `OnPrimaryContainer` in dark, `OnPrimary` in light. */\nexport const switchThumbOn = (theme: G9ResolvedTheme): G9Color =>\n theme.scheme === 'dark' ? theme.palette.OnPrimaryContainer : theme.palette.OnPrimary;\n\n/** Check mark / indeterminate bar on a filled box: `OnPrimary` (the one place the mark colour is decided). */\nexport const checkBoxMark = (theme: G9ResolvedTheme): G9Color => theme.palette.OnPrimary;\n\n/** A gradient stop: colour at `offset` (`0..1`). */\nexport interface G9GradientStop {\n readonly color: G9Color;\n readonly offset: number;\n}\n\n/** A fill: a solid colour, or a top-to-bottom linear gradient. */\nexport type G9Fill =\n | { readonly kind: 'solid'; readonly color: G9Color }\n | { readonly kind: 'verticalGradient'; readonly stops: readonly G9GradientStop[] };\n\n/**\n * MAUI `G9Colors.BuildSolidOrGradient`: the solid colour, or a vertical gradient from 8 % lighter (top) through the\n * colour (middle) to 8 % darker (bottom).\n */\nexport function buildSolidOrGradient(base: G9ColorInput, useGradient: boolean): G9Fill {\n const color = formatColor(base);\n if (!useGradient) return { kind: 'solid', color };\n return {\n kind: 'verticalGradient',\n stops: [\n { color: formatColor(lighten(base, 0.08)), offset: 0 },\n { color, offset: 0.5 },\n { color: formatColor(darken(base, 0.08)), offset: 1 },\n ],\n };\n}\n\n/** A fill as a CSS `background` value: the colour, or `linear-gradient(to bottom, …)`. */\nexport function fillToCss(fill: G9Fill): string {\n if (fill.kind === 'solid') return fill.color;\n return `linear-gradient(to bottom, ${fill.stops.map((s) => `${s.color} ${s.offset * 100}%`).join(', ')})`;\n}\n"],"names":["G9Colors","switchOffTrack","theme","switchOnTrack","switchThumbOff","switchThumbOn","checkBoxMark","build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C,EAAEA,AAAW,MAAXA,EAAE,MAAM,CAAO,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3G"}
@@ -0,0 +1,5 @@
1
+ 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';
2
+ 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';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,4 @@
1
+ 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";
2
+ 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";
@@ -0,0 +1,88 @@
1
+ import { type G9ColorToken, type G9PaletteValues } from '../tokens/generated/palettes.js';
2
+ import { type G9Color } from './color.js';
3
+ /** Which theme the user chose (MAUI `AppTheme`: `Unspecified` is `system`, follow the platform). */
4
+ export declare const G9ThemeMode: {
5
+ readonly System: "system";
6
+ readonly Light: "light";
7
+ readonly Dark: "dark";
8
+ };
9
+ export type G9ThemeMode = (typeof G9ThemeMode)[keyof typeof G9ThemeMode];
10
+ /** The scheme actually painted. */
11
+ export declare const G9ColorScheme: {
12
+ readonly Light: "light";
13
+ readonly Dark: "dark";
14
+ };
15
+ export type G9ColorScheme = (typeof G9ColorScheme)[keyof typeof G9ColorScheme];
16
+ /** Some tokens replaced by CSS colours. */
17
+ export type G9PaletteOverrides = {
18
+ readonly [K in G9ColorToken]?: G9Color | undefined;
19
+ };
20
+ /** App palettes replacing (all or some of) the stock light and dark palettes. */
21
+ export interface G9CustomPalettes {
22
+ readonly light?: G9PaletteOverrides;
23
+ readonly dark?: G9PaletteOverrides;
24
+ }
25
+ /** Inputs of theme resolution. */
26
+ export interface G9ThemeOptions {
27
+ /** The user's choice. Default `'system'`. */
28
+ readonly mode?: G9ThemeMode;
29
+ /** What the platform currently asks for. Default `'light'`. */
30
+ readonly systemScheme?: G9ColorScheme;
31
+ /** App palettes layered over the stock ones, per scheme. */
32
+ readonly palettes?: G9CustomPalettes;
33
+ /** Last layer, applied whatever the scheme (e.g. a brand colour). */
34
+ readonly overrides?: G9PaletteOverrides;
35
+ }
36
+ /** A resolved theme: what is painted and why. Frozen. */
37
+ export interface G9ResolvedTheme {
38
+ readonly mode: G9ThemeMode;
39
+ readonly systemScheme: G9ColorScheme;
40
+ readonly scheme: G9ColorScheme;
41
+ readonly palette: G9PaletteValues;
42
+ }
43
+ /** `'light'`/`'dark'` pick that scheme; `'system'` follows `systemScheme` (MAUI `G9Theme.ApplyCurrent`). */
44
+ export declare function resolveColorScheme(mode: G9ThemeMode, systemScheme: G9ColorScheme): G9ColorScheme;
45
+ /** The stock palette of a scheme (MAUI `G9ThemeLight` / `G9ThemeDark`). */
46
+ export declare const stockPalette: (scheme: G9ColorScheme) => G9PaletteValues;
47
+ /**
48
+ * Validates a complete palette (every token, every value a readable colour) and returns a frozen copy in token order.
49
+ * @throws {G9Error} `theme-incomplete-palette` / `theme-unknown-token`, or {@link G9ColorFormatError}.
50
+ */
51
+ export declare function createPalette(values: G9PaletteValues): G9PaletteValues;
52
+ /**
53
+ * Resolves the painted theme: the stock palette of the effective scheme, then the app palette for that scheme, then
54
+ * `overrides`. Every supplied value is validated; nothing invalid is silently kept.
55
+ */
56
+ export declare function resolveTheme(options?: G9ThemeOptions): G9ResolvedTheme;
57
+ /** Listener of {@link G9ThemeStore}; receives the snapshot taken at notify time. */
58
+ export type G9ThemeListener = (theme: G9ResolvedTheme) => void;
59
+ /**
60
+ * The live theme (MAUI `G9Palette.Current` + `G9Theme`): one snapshot, replaced on every change, and listeners told
61
+ * once per change. Works with `useSyncExternalStore` (`subscribe` / `getSnapshot`).
62
+ */
63
+ export interface G9ThemeStore {
64
+ /** The current theme; the same object until something visible changes. */
65
+ getSnapshot(): G9ResolvedTheme;
66
+ /** Adds a listener; returns its unsubscribe function. */
67
+ subscribe(listener: G9ThemeListener): () => void;
68
+ /** The user's choice (MAUI `G9Theme.ChangeTheme`). Persisting it is the caller's job (see the guide). */
69
+ setMode(mode: G9ThemeMode): void;
70
+ /** Report the platform scheme (MAUI `RequestedThemeChanged`); repaints only while the mode is `'system'`. */
71
+ setSystemScheme(scheme: G9ColorScheme): void;
72
+ /** Replace the app palettes. */
73
+ setPalettes(palettes: G9CustomPalettes | undefined): void;
74
+ /** Replace the override layer. */
75
+ setOverrides(overrides: G9PaletteOverrides | undefined): void;
76
+ /**
77
+ * Paint `values` as the complete palette (MAUI `G9Palette.Apply`) until the next mode or scheme change re-resolves
78
+ * the theme, as the next `G9Theme.ApplyCurrent` did. The override layer still applies on top.
79
+ */
80
+ apply(values: G9PaletteValues): void;
81
+ /** Open a batch: changes inside are notified once, by the outermost `endBatch`. Batches nest. */
82
+ beginBatch(): void;
83
+ /** Close a batch; the outermost close notifies once, and only if the theme actually changed. */
84
+ endBatch(): void;
85
+ }
86
+ /** Creates a {@link G9ThemeStore}. Options are validated like {@link resolveTheme}. */
87
+ export declare function createThemeStore(options?: G9ThemeOptions): G9ThemeStore;
88
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,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+ import { parseColor } from "./color.js";
4
+ const G9ThemeMode = {
5
+ System: 'system',
6
+ Light: 'light',
7
+ Dark: 'dark'
8
+ };
9
+ const G9ColorScheme = {
10
+ Light: 'light',
11
+ Dark: 'dark'
12
+ };
13
+ const MODES = [
14
+ 'system',
15
+ 'light',
16
+ 'dark'
17
+ ];
18
+ const SCHEMES = [
19
+ 'light',
20
+ 'dark'
21
+ ];
22
+ function check(kind, value) {
23
+ if (!('mode' === kind ? MODES : SCHEMES).includes(value)) throw new G9Error(`theme-invalid-${kind}`, `"${value}" is not a theme ${kind}.`);
24
+ }
25
+ function resolveColorScheme(mode, systemScheme) {
26
+ check('mode', mode);
27
+ check('scheme', systemScheme);
28
+ return 'system' === mode ? systemScheme : mode;
29
+ }
30
+ const stockPalette = (scheme)=>'dark' === scheme ? g9DarkPalette : g9LightPalette;
31
+ const known = new Set(g9ColorTokens);
32
+ function theme_layer(base, overrides) {
33
+ if (!overrides) return base;
34
+ const next = {
35
+ ...base
36
+ };
37
+ for (const [token, color] of Object.entries(overrides))if (void 0 !== color) {
38
+ if (!known.has(token)) throw new G9Error('theme-unknown-token', `"${token}" is not a G9ColorToken.`);
39
+ parseColor(color);
40
+ next[token] = color;
41
+ }
42
+ return next;
43
+ }
44
+ function createPalette(values) {
45
+ const missing = g9ColorTokens.filter((token)=>'string' != typeof values[token]);
46
+ if (missing.length) throw new G9Error('theme-incomplete-palette', `Palette is missing: ${missing.join(', ')}.`);
47
+ const ordered = {};
48
+ for (const token of g9ColorTokens)ordered[token] = values[token];
49
+ return Object.freeze(theme_layer(ordered, values));
50
+ }
51
+ function resolveTheme(options = {}) {
52
+ var _options_mode, _options_systemScheme;
53
+ var _options_palettes, _options_palettes1;
54
+ const mode = null != (_options_mode = options.mode) ? _options_mode : 'system';
55
+ const systemScheme = null != (_options_systemScheme = options.systemScheme) ? _options_systemScheme : 'light';
56
+ const scheme = resolveColorScheme(mode, systemScheme);
57
+ const inactive = 'dark' === scheme ? 'light' : 'dark';
58
+ theme_layer(stockPalette(inactive), null == (_options_palettes = options.palettes) ? void 0 : _options_palettes[inactive]);
59
+ const custom = theme_layer(stockPalette(scheme), null == (_options_palettes1 = options.palettes) ? void 0 : _options_palettes1[scheme]);
60
+ const palette = Object.freeze(theme_layer(custom, options.overrides));
61
+ return Object.freeze({
62
+ mode,
63
+ systemScheme,
64
+ scheme,
65
+ palette
66
+ });
67
+ }
68
+ function samePalette(a, b) {
69
+ return g9ColorTokens.every((token)=>a[token] === b[token]);
70
+ }
71
+ function resolveState(state) {
72
+ const { palettes, overrides } = state;
73
+ const next = resolveTheme({
74
+ mode: state.mode,
75
+ systemScheme: state.systemScheme,
76
+ ...palettes ? {
77
+ palettes
78
+ } : {},
79
+ ...overrides ? {
80
+ overrides
81
+ } : {}
82
+ });
83
+ return state.applied ? Object.freeze({
84
+ ...next,
85
+ palette: Object.freeze(theme_layer(state.applied, overrides))
86
+ }) : next;
87
+ }
88
+ function createThemeStore(options = {}) {
89
+ var _options_mode, _options_systemScheme;
90
+ let state = {
91
+ mode: null != (_options_mode = options.mode) ? _options_mode : 'system',
92
+ systemScheme: null != (_options_systemScheme = options.systemScheme) ? _options_systemScheme : 'light',
93
+ palettes: options.palettes,
94
+ overrides: options.overrides,
95
+ applied: void 0
96
+ };
97
+ let snapshot = resolveState(state);
98
+ let notified = snapshot;
99
+ const listeners = new Set();
100
+ let depth = 0;
101
+ let notifying = false;
102
+ function commit(patch) {
103
+ const nextState = {
104
+ ...state,
105
+ ...patch
106
+ };
107
+ const next = resolveState(nextState);
108
+ state = nextState;
109
+ const changed = next.mode !== snapshot.mode || next.systemScheme !== snapshot.systemScheme || next.scheme !== snapshot.scheme || !samePalette(next.palette, snapshot.palette);
110
+ if (changed) snapshot = next;
111
+ flush();
112
+ }
113
+ function flush() {
114
+ if (depth > 0 || notifying) return;
115
+ notifying = true;
116
+ let failure;
117
+ let failed = false;
118
+ try {
119
+ while(notified !== snapshot){
120
+ notified = snapshot;
121
+ const current = snapshot;
122
+ for (const listener of Array.from(listeners))if (listeners.has(listener)) try {
123
+ listener(current);
124
+ } catch (error) {
125
+ if (!failed) {
126
+ failed = true;
127
+ failure = error;
128
+ }
129
+ }
130
+ }
131
+ } finally{
132
+ notifying = false;
133
+ }
134
+ if (failed) throw failure;
135
+ }
136
+ return {
137
+ getSnapshot: ()=>snapshot,
138
+ subscribe (listener) {
139
+ listeners.add(listener);
140
+ return ()=>{
141
+ listeners.delete(listener);
142
+ };
143
+ },
144
+ setMode (mode) {
145
+ check('mode', mode);
146
+ commit(mode === state.mode ? {
147
+ mode
148
+ } : {
149
+ mode,
150
+ applied: void 0
151
+ });
152
+ },
153
+ setSystemScheme (systemScheme) {
154
+ check('scheme', systemScheme);
155
+ const repaint = systemScheme !== state.systemScheme && 'system' === state.mode;
156
+ commit(repaint ? {
157
+ systemScheme,
158
+ applied: void 0
159
+ } : {
160
+ systemScheme
161
+ });
162
+ },
163
+ setPalettes (palettes) {
164
+ commit({
165
+ palettes
166
+ });
167
+ },
168
+ setOverrides (overrides) {
169
+ commit({
170
+ overrides
171
+ });
172
+ },
173
+ apply (values) {
174
+ commit({
175
+ applied: createPalette(values)
176
+ });
177
+ },
178
+ beginBatch () {
179
+ depth += 1;
180
+ },
181
+ endBatch () {
182
+ if (0 === depth) return;
183
+ depth -= 1;
184
+ flush();
185
+ }
186
+ };
187
+ }
188
+ export { G9ColorScheme, G9ThemeMode, createPalette, createThemeStore, resolveColorScheme, resolveTheme, stockPalette };
189
+
190
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme/theme.js","sources":["../../src/theme/theme.ts"],"sourcesContent":["import { G9Error } from '../errors';\nimport {\n type G9ColorToken,\n type G9PaletteValues,\n g9ColorTokens,\n g9DarkPalette,\n g9LightPalette,\n} from '../tokens/generated/palettes';\nimport { type G9Color, parseColor } from './color';\n\n/** Which theme the user chose (MAUI `AppTheme`: `Unspecified` is `system`, follow the platform). */\nexport const G9ThemeMode = { System: 'system', Light: 'light', Dark: 'dark' } as const;\nexport type G9ThemeMode = (typeof G9ThemeMode)[keyof typeof G9ThemeMode];\n\n/** The scheme actually painted. */\nexport const G9ColorScheme = { Light: 'light', Dark: 'dark' } as const;\nexport type G9ColorScheme = (typeof G9ColorScheme)[keyof typeof G9ColorScheme];\n\n/** Some tokens replaced by CSS colours. */\nexport type G9PaletteOverrides = { readonly [K in G9ColorToken]?: G9Color | undefined };\n\n/** App palettes replacing (all or some of) the stock light and dark palettes. */\nexport interface G9CustomPalettes {\n readonly light?: G9PaletteOverrides;\n readonly dark?: G9PaletteOverrides;\n}\n\n/** Inputs of theme resolution. */\nexport interface G9ThemeOptions {\n /** The user's choice. Default `'system'`. */\n readonly mode?: G9ThemeMode;\n /** What the platform currently asks for. Default `'light'`. */\n readonly systemScheme?: G9ColorScheme;\n /** App palettes layered over the stock ones, per scheme. */\n readonly palettes?: G9CustomPalettes;\n /** Last layer, applied whatever the scheme (e.g. a brand colour). */\n readonly overrides?: G9PaletteOverrides;\n}\n\n/** A resolved theme: what is painted and why. Frozen. */\nexport interface G9ResolvedTheme {\n readonly mode: G9ThemeMode;\n readonly systemScheme: G9ColorScheme;\n readonly scheme: G9ColorScheme;\n readonly palette: G9PaletteValues;\n}\n\nconst MODES: readonly string[] = ['system', 'light', 'dark'];\nconst SCHEMES: readonly string[] = ['light', 'dark'];\n\nfunction check(kind: 'mode' | 'scheme', value: string): void {\n if (!(kind === 'mode' ? MODES : SCHEMES).includes(value)) {\n throw new G9Error(`theme-invalid-${kind}`, `\"${value}\" is not a theme ${kind}.`);\n }\n}\n\n/** `'light'`/`'dark'` pick that scheme; `'system'` follows `systemScheme` (MAUI `G9Theme.ApplyCurrent`). */\nexport function resolveColorScheme(mode: G9ThemeMode, systemScheme: G9ColorScheme): G9ColorScheme {\n check('mode', mode);\n check('scheme', systemScheme);\n return mode === 'system' ? systemScheme : mode;\n}\n\n/** The stock palette of a scheme (MAUI `G9ThemeLight` / `G9ThemeDark`). */\nexport const stockPalette = (scheme: G9ColorScheme): G9PaletteValues =>\n scheme === 'dark' ? g9DarkPalette : g9LightPalette;\n\nconst known = new Set<string>(g9ColorTokens);\n\nfunction layer(base: G9PaletteValues, overrides: G9PaletteOverrides | undefined): G9PaletteValues {\n if (!overrides) return base;\n const next: Record<string, string> = { ...base };\n for (const [token, color] of Object.entries(overrides)) {\n if (color === undefined) continue;\n if (!known.has(token)) throw new G9Error('theme-unknown-token', `\"${token}\" is not a G9ColorToken.`);\n parseColor(color);\n next[token] = color;\n }\n return next as G9PaletteValues;\n}\n\n/**\n * Validates a complete palette (every token, every value a readable colour) and returns a frozen copy in token order.\n * @throws {G9Error} `theme-incomplete-palette` / `theme-unknown-token`, or {@link G9ColorFormatError}.\n */\nexport function createPalette(values: G9PaletteValues): G9PaletteValues {\n const missing = g9ColorTokens.filter((token) => typeof values[token] !== 'string');\n if (missing.length) {\n throw new G9Error('theme-incomplete-palette', `Palette is missing: ${missing.join(', ')}.`);\n }\n const ordered: Record<string, string> = {};\n for (const token of g9ColorTokens) ordered[token] = values[token];\n return Object.freeze(layer(ordered as G9PaletteValues, values));\n}\n\n/**\n * Resolves the painted theme: the stock palette of the effective scheme, then the app palette for that scheme, then\n * `overrides`. Every supplied value is validated; nothing invalid is silently kept.\n */\nexport function resolveTheme(options: G9ThemeOptions = {}): G9ResolvedTheme {\n const mode = options.mode ?? 'system';\n const systemScheme = options.systemScheme ?? 'light';\n const scheme = resolveColorScheme(mode, systemScheme);\n // Validate the inactive scheme's palette too, so a typo surfaces now rather than on the next theme switch.\n const inactive: G9ColorScheme = scheme === 'dark' ? 'light' : 'dark';\n layer(stockPalette(inactive), options.palettes?.[inactive]);\n const custom = layer(stockPalette(scheme), options.palettes?.[scheme]);\n const palette = Object.freeze(layer(custom, options.overrides));\n return Object.freeze({ mode, systemScheme, scheme, palette });\n}\n\n/** Listener of {@link G9ThemeStore}; receives the snapshot taken at notify time. */\nexport type G9ThemeListener = (theme: G9ResolvedTheme) => void;\n\n/**\n * The live theme (MAUI `G9Palette.Current` + `G9Theme`): one snapshot, replaced on every change, and listeners told\n * once per change. Works with `useSyncExternalStore` (`subscribe` / `getSnapshot`).\n */\nexport interface G9ThemeStore {\n /** The current theme; the same object until something visible changes. */\n getSnapshot(): G9ResolvedTheme;\n /** Adds a listener; returns its unsubscribe function. */\n subscribe(listener: G9ThemeListener): () => void;\n /** The user's choice (MAUI `G9Theme.ChangeTheme`). Persisting it is the caller's job (see the guide). */\n setMode(mode: G9ThemeMode): void;\n /** Report the platform scheme (MAUI `RequestedThemeChanged`); repaints only while the mode is `'system'`. */\n setSystemScheme(scheme: G9ColorScheme): void;\n /** Replace the app palettes. */\n setPalettes(palettes: G9CustomPalettes | undefined): void;\n /** Replace the override layer. */\n setOverrides(overrides: G9PaletteOverrides | undefined): void;\n /**\n * Paint `values` as the complete palette (MAUI `G9Palette.Apply`) until the next mode or scheme change re-resolves\n * the theme, as the next `G9Theme.ApplyCurrent` did. The override layer still applies on top.\n */\n apply(values: G9PaletteValues): void;\n /** Open a batch: changes inside are notified once, by the outermost `endBatch`. Batches nest. */\n beginBatch(): void;\n /** Close a batch; the outermost close notifies once, and only if the theme actually changed. */\n endBatch(): void;\n}\n\nfunction samePalette(a: G9PaletteValues, b: G9PaletteValues): boolean {\n return g9ColorTokens.every((token) => a[token] === b[token]);\n}\n\ninterface StoreState {\n readonly mode: G9ThemeMode;\n readonly systemScheme: G9ColorScheme;\n readonly palettes: G9CustomPalettes | undefined;\n readonly overrides: G9PaletteOverrides | undefined;\n readonly applied: G9PaletteValues | undefined;\n}\n\nfunction resolveState(state: StoreState): G9ResolvedTheme {\n const { palettes, overrides } = state;\n const next = resolveTheme({\n mode: state.mode,\n systemScheme: state.systemScheme,\n ...(palettes ? { palettes } : {}),\n ...(overrides ? { overrides } : {}),\n });\n return state.applied ? Object.freeze({ ...next, palette: Object.freeze(layer(state.applied, overrides)) }) : next;\n}\n\n/** Creates a {@link G9ThemeStore}. Options are validated like {@link resolveTheme}. */\nexport function createThemeStore(options: G9ThemeOptions = {}): G9ThemeStore {\n let state: StoreState = {\n mode: options.mode ?? 'system',\n systemScheme: options.systemScheme ?? 'light',\n palettes: options.palettes,\n overrides: options.overrides,\n applied: undefined,\n };\n let snapshot = resolveState(state);\n let notified = snapshot;\n const listeners = new Set<G9ThemeListener>();\n let depth = 0;\n let notifying = false;\n\n // Resolve first, commit second: an invalid input throws and leaves the store untouched.\n function commit(patch: Partial<StoreState>): void {\n const nextState = { ...state, ...patch };\n const next = resolveState(nextState);\n state = nextState;\n const changed =\n next.mode !== snapshot.mode ||\n next.systemScheme !== snapshot.systemScheme ||\n next.scheme !== snapshot.scheme ||\n !samePalette(next.palette, snapshot.palette);\n if (changed) snapshot = next;\n flush();\n }\n\n function flush(): void {\n // Re-entrant changes made by a listener are delivered after the current round, with the then-current snapshot\n // (MAUI ApplyCurrent remembered a request made mid-switch and ran it afterwards).\n if (depth > 0 || notifying) return;\n notifying = true;\n let failure: unknown;\n let failed = false;\n try {\n while (notified !== snapshot) {\n notified = snapshot;\n const current = snapshot;\n for (const listener of Array.from(listeners)) {\n if (!listeners.has(listener)) continue;\n try {\n listener(current);\n } catch (error) {\n if (!failed) {\n failed = true;\n failure = error;\n }\n }\n }\n }\n } finally {\n notifying = false;\n }\n if (failed) throw failure;\n }\n\n return {\n getSnapshot: () => snapshot,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n setMode(mode) {\n check('mode', mode);\n // A different choice re-resolves the theme, dropping a palette painted with apply().\n commit(mode === state.mode ? { mode } : { mode, applied: undefined });\n },\n setSystemScheme(systemScheme) {\n check('scheme', systemScheme);\n const repaint = systemScheme !== state.systemScheme && state.mode === 'system';\n commit(repaint ? { systemScheme, applied: undefined } : { systemScheme });\n },\n setPalettes(palettes) {\n commit({ palettes });\n },\n setOverrides(overrides) {\n commit({ overrides });\n },\n apply(values) {\n commit({ applied: createPalette(values) });\n },\n beginBatch() {\n depth += 1;\n },\n endBatch() {\n if (depth === 0) return;\n depth -= 1;\n flush();\n },\n };\n}\n"],"names":["G9ThemeMode","G9ColorScheme","MODES","SCHEMES","check","kind","value","G9Error","resolveColorScheme","mode","systemScheme","stockPalette","scheme","g9DarkPalette","g9LightPalette","known","Set","g9ColorTokens","layer","base","overrides","next","token","color","Object","undefined","parseColor","createPalette","values","missing","ordered","resolveTheme","options","_options_mode","_options_systemScheme","_options_palettes","_options_palettes1","inactive","custom","palette","samePalette","a","b","resolveState","state","palettes","createThemeStore","snapshot","notified","listeners","depth","notifying","commit","patch","nextState","changed","flush","failure","failed","current","listener","Array","error","repaint"],"mappings":";;;AAWO,MAAMA,cAAc;IAAE,QAAQ;IAAU,OAAO;IAAS,MAAM;AAAO;AAIrE,MAAMC,gBAAgB;IAAE,OAAO;IAAS,MAAM;AAAO;AAgC5D,MAAMC,QAA2B;IAAC;IAAU;IAAS;CAAO;AAC5D,MAAMC,UAA6B;IAAC;IAAS;CAAO;AAEpD,SAASC,MAAMC,IAAuB,EAAEC,KAAa;IACnD,IAAI,CAAED,AAAAA,CAAAA,AAAS,WAATA,OAAkBH,QAAQC,OAAM,EAAG,QAAQ,CAACG,QAChD,MAAM,IAAIC,QAAQ,CAAC,cAAc,EAAEF,MAAM,EAAE,CAAC,CAAC,EAAEC,MAAM,iBAAiB,EAAED,KAAK,CAAC,CAAC;AAEnF;AAGO,SAASG,mBAAmBC,IAAiB,EAAEC,YAA2B;IAC/EN,MAAM,QAAQK;IACdL,MAAM,UAAUM;IAChB,OAAOD,AAAS,aAATA,OAAoBC,eAAeD;AAC5C;AAGO,MAAME,eAAe,CAACC,SAC3BA,AAAW,WAAXA,SAAoBC,gBAAgBC;AAEtC,MAAMC,QAAQ,IAAIC,IAAYC;AAE9B,SAASC,YAAMC,IAAqB,EAAEC,SAAyC;IAC7E,IAAI,CAACA,WAAW,OAAOD;IACvB,MAAME,OAA+B;QAAE,GAAGF,IAAI;IAAC;IAC/C,KAAK,MAAM,CAACG,OAAOC,MAA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