@g9tm/lynxcontrols-foundation 1.7.3 → 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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/culture/bidi.d.ts +8 -0
- package/dist/culture/bidi.d.ts.map +1 -0
- package/dist/culture/bidi.js +16 -0
- package/dist/culture/bidi.js.map +1 -0
- package/dist/culture/coordinates.d.ts +17 -0
- package/dist/culture/coordinates.d.ts.map +1 -0
- package/dist/culture/coordinates.js +18 -0
- package/dist/culture/coordinates.js.map +1 -0
- package/dist/culture/index.d.ts +4 -0
- package/dist/culture/index.d.ts.map +1 -1
- package/dist/culture/index.js +4 -0
- package/dist/culture/natural-date.d.ts +9 -0
- package/dist/culture/natural-date.d.ts.map +1 -0
- package/dist/culture/natural-date.js +208 -0
- package/dist/culture/natural-date.js.map +1 -0
- package/dist/culture/text.d.ts +73 -0
- package/dist/culture/text.d.ts.map +1 -0
- package/dist/culture/text.js +213 -0
- package/dist/culture/text.js.map +1 -0
- package/dist/enums/index.d.ts +6 -0
- package/dist/enums/index.d.ts.map +1 -1
- package/dist/enums/index.js +4 -1
- package/dist/enums/index.js.map +1 -1
- package/dist/icons/index.d.ts +2 -1
- package/dist/icons/index.d.ts.map +1 -1
- package/dist/icons/index.js +2 -1
- package/dist/icons/packs.d.ts +34 -0
- package/dist/icons/packs.d.ts.map +1 -0
- package/dist/icons/packs.js +70 -0
- package/dist/icons/packs.js.map +1 -0
- package/dist/icons/svg.d.ts +9 -2
- package/dist/icons/svg.d.ts.map +1 -1
- package/dist/icons/svg.js +13 -2
- package/dist/icons/svg.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/layout/index.d.ts +43 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +31 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/services/contracts.d.ts +32 -0
- package/dist/services/contracts.d.ts.map +1 -1
- package/dist/services/contracts.js.map +1 -1
- package/dist/services/feedback.d.ts +28 -0
- package/dist/services/feedback.d.ts.map +1 -0
- package/dist/services/feedback.js +27 -0
- package/dist/services/feedback.js.map +1 -0
- package/dist/services/index.d.ts +3 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +2 -0
- package/dist/services/keys.d.ts +39 -0
- package/dist/services/keys.d.ts.map +1 -0
- package/dist/services/keys.js +96 -0
- package/dist/services/keys.js.map +1 -0
- package/dist/theme/aliases.d.ts +73 -0
- package/dist/theme/aliases.d.ts.map +1 -0
- package/dist/theme/aliases.js +76 -0
- package/dist/theme/aliases.js.map +1 -0
- package/dist/theme/appearance.d.ts +57 -0
- package/dist/theme/appearance.d.ts.map +1 -0
- package/dist/theme/appearance.js +275 -0
- package/dist/theme/appearance.js.map +1 -0
- package/dist/theme/brand.d.ts +40 -0
- package/dist/theme/brand.d.ts.map +1 -0
- package/dist/theme/brand.js +181 -0
- package/dist/theme/brand.js.map +1 -0
- package/dist/theme/contrast.d.ts +19 -0
- package/dist/theme/contrast.d.ts.map +1 -0
- package/dist/theme/contrast.js +119 -0
- package/dist/theme/contrast.js.map +1 -0
- package/dist/theme/css-color.d.ts +20 -0
- package/dist/theme/css-color.d.ts.map +1 -0
- package/dist/theme/css-color.js +149 -0
- package/dist/theme/css-color.js.map +1 -0
- package/dist/theme/design.d.ts +33 -0
- package/dist/theme/design.d.ts.map +1 -0
- package/dist/theme/design.js +162 -0
- package/dist/theme/design.js.map +1 -0
- package/dist/theme/index.d.ts +10 -2
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +10 -2
- package/dist/theme/oklch.d.ts +63 -0
- package/dist/theme/oklch.d.ts.map +1 -0
- package/dist/theme/oklch.js +258 -0
- package/dist/theme/oklch.js.map +1 -0
- package/dist/theme/recipe.d.ts +44 -0
- package/dist/theme/recipe.d.ts.map +1 -0
- package/dist/theme/recipe.js +156 -0
- package/dist/theme/recipe.js.map +1 -0
- package/dist/theme/theme.d.ts +43 -2
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +85 -9
- package/dist/theme/theme.js.map +1 -1
- package/dist/theme/variants.d.ts +10 -0
- package/dist/theme/variants.d.ts.map +1 -1
- package/dist/theme/variants.js +74 -1
- package/dist/theme/variants.js.map +1 -1
- package/dist/tokens/derived.d.ts +31 -0
- package/dist/tokens/derived.d.ts.map +1 -0
- package/dist/tokens/derived.js +42 -0
- package/dist/tokens/derived.js.map +1 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +2 -0
- package/dist/tokens/shape.d.ts +46 -0
- package/dist/tokens/shape.d.ts.map +1 -0
- package/dist/tokens/shape.js +95 -0
- package/dist/tokens/shape.js.map +1 -0
- package/docs/api.md +135 -2
- package/package.json +6 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { formatColor, getContrastRatio, mix, withAlpha } from "./color.js";
|
|
2
|
+
import { ensureContrast, neutralScale, oklchToHex, toOklch, tonalScale } from "./oklch.js";
|
|
3
|
+
const STATUS_HUE = {
|
|
4
|
+
error: 25,
|
|
5
|
+
warning: 70,
|
|
6
|
+
success: 150,
|
|
7
|
+
info: 245
|
|
8
|
+
};
|
|
9
|
+
function hueColor(h, like, l = 0.6) {
|
|
10
|
+
const c = Math.max(0.1, Math.min(0.17, toOklch(like).c || 0.13));
|
|
11
|
+
return oklchToHex({
|
|
12
|
+
l,
|
|
13
|
+
c,
|
|
14
|
+
h
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function rotate(color, degrees, chromaScale) {
|
|
18
|
+
const x = toOklch(color);
|
|
19
|
+
return oklchToHex({
|
|
20
|
+
l: x.l,
|
|
21
|
+
c: x.c * chromaScale,
|
|
22
|
+
h: (x.h + degrees + 360) % 360
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const hex = (c)=>formatColor(c);
|
|
26
|
+
const alpha = (c, a)=>formatColor(withAlpha(c, a));
|
|
27
|
+
function role(base, scheme, min, keep) {
|
|
28
|
+
const scale = tonalScale(base);
|
|
29
|
+
const dark = 'dark' === scheme;
|
|
30
|
+
let fill = dark ? toOklch(base).l > 0.62 ? hex(base) : scale[400] : ensureContrast(base, '#FFFFFF', 3);
|
|
31
|
+
let on = pickOn(fill, scale, dark);
|
|
32
|
+
if (getContrastRatio(on, fill) < min && !keep) {
|
|
33
|
+
on = dark ? scale[950] : '#FFFFFF';
|
|
34
|
+
fill = ensureContrast(fill, on, min);
|
|
35
|
+
}
|
|
36
|
+
if (getContrastRatio(on, fill) < min) on = ensureContrast(on, fill, min);
|
|
37
|
+
const container = dark ? scale[900] : scale[100];
|
|
38
|
+
const onContainer = ensureContrast(dark ? scale[100] : scale[900], container, min);
|
|
39
|
+
const border = dark ? scale[600] : scale[700];
|
|
40
|
+
const hover = hex(mix(fill, on, 0.08));
|
|
41
|
+
const pressed = hex(mix(fill, on, 0.16));
|
|
42
|
+
return {
|
|
43
|
+
fill,
|
|
44
|
+
on,
|
|
45
|
+
container,
|
|
46
|
+
onContainer,
|
|
47
|
+
border,
|
|
48
|
+
hover,
|
|
49
|
+
pressed
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function pickOn(fill, scale, dark) {
|
|
53
|
+
const light = '#FFFFFF';
|
|
54
|
+
const deep = scale[950];
|
|
55
|
+
const a = getContrastRatio(light, fill);
|
|
56
|
+
const b = getContrastRatio(deep, fill);
|
|
57
|
+
if (dark) return b >= 0.8 * a ? deep : light;
|
|
58
|
+
return a >= b ? light : deep;
|
|
59
|
+
}
|
|
60
|
+
function createBrandPalette(brand, scheme, options = {}) {
|
|
61
|
+
var _brand_neutral, _options_tint, _brand_secondary, _brand_tertiary, _brand_quaternary, _brand_error, _brand_warning, _brand_success, _brand_info;
|
|
62
|
+
const dark = 'dark' === scheme;
|
|
63
|
+
const min = 'AAA' === options.contrast ? 7 : 4.5;
|
|
64
|
+
const keep = false !== options.keepBrand;
|
|
65
|
+
const primary = brand.primary;
|
|
66
|
+
const n = neutralScale(null != (_brand_neutral = brand.neutral) ? _brand_neutral : primary, null != (_options_tint = options.tint) ? _options_tint : 0.35);
|
|
67
|
+
const secondary = null != (_brand_secondary = brand.secondary) ? _brand_secondary : rotate(primary, 30, 0.55);
|
|
68
|
+
const tertiary = null != (_brand_tertiary = brand.tertiary) ? _brand_tertiary : rotate(primary, 120, 0.8);
|
|
69
|
+
const quaternary = null != (_brand_quaternary = brand.quaternary) ? _brand_quaternary : rotate(primary, -70, 0.75);
|
|
70
|
+
const roles = {
|
|
71
|
+
Primary: role(primary, scheme, min, keep),
|
|
72
|
+
Secondary: role(secondary, scheme, min, false),
|
|
73
|
+
Tertiary: role(tertiary, scheme, min, false),
|
|
74
|
+
Quaternary: role(quaternary, scheme, min, false),
|
|
75
|
+
Error: role(null != (_brand_error = brand.error) ? _brand_error : hueColor(STATUS_HUE.error, primary, 0.55), scheme, min, false),
|
|
76
|
+
Warning: role(null != (_brand_warning = brand.warning) ? _brand_warning : hueColor(STATUS_HUE.warning, primary, 0.66), scheme, min, false),
|
|
77
|
+
Success: role(null != (_brand_success = brand.success) ? _brand_success : hueColor(STATUS_HUE.success, primary, 0.56), scheme, min, false),
|
|
78
|
+
Info: role(null != (_brand_info = brand.info) ? _brand_info : hueColor(STATUS_HUE.info, primary, 0.55), scheme, min, false)
|
|
79
|
+
};
|
|
80
|
+
const surface = dark ? oklchToHex({
|
|
81
|
+
...toOklch(n[950]),
|
|
82
|
+
l: 0.2
|
|
83
|
+
}) : '#FFFFFF';
|
|
84
|
+
const background = dark ? oklchToHex({
|
|
85
|
+
...toOklch(n[950]),
|
|
86
|
+
l: 0.16
|
|
87
|
+
}) : n[50];
|
|
88
|
+
const textPrimary = ensureContrast(dark ? n[50] : n[950], surface, Math.max(min, 7));
|
|
89
|
+
const textSecondary = ensureContrast(dark ? n[300] : n[700], surface, min);
|
|
90
|
+
const textTertiary = ensureContrast(dark ? n[400] : n[600], surface, 3);
|
|
91
|
+
const textDisabled = dark ? n[700] : n[300];
|
|
92
|
+
const container = (step)=>oklchToHex({
|
|
93
|
+
...toOklch(n[950]),
|
|
94
|
+
l: 0.2 + 0.035 * step
|
|
95
|
+
});
|
|
96
|
+
const out = {};
|
|
97
|
+
for (const [name, r] of Object.entries(roles)){
|
|
98
|
+
out[name] = r.fill;
|
|
99
|
+
out[`On${name}`] = r.on;
|
|
100
|
+
out[`${name}Container`] = r.container;
|
|
101
|
+
out[`On${name}Container`] = r.onContainer;
|
|
102
|
+
out[`${name}Border`] = r.border;
|
|
103
|
+
if ('Primary' === name) {
|
|
104
|
+
out.PrimaryHover = r.hover;
|
|
105
|
+
out.PrimaryPressed = r.pressed;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const outline = dark ? n[700] : n[300];
|
|
109
|
+
const outlineVariant = dark ? n[800] : n[200];
|
|
110
|
+
Object.assign(out, {
|
|
111
|
+
Outline: outline,
|
|
112
|
+
OutlineVariant: outlineVariant,
|
|
113
|
+
OutlineBorder: dark ? n[600] : n[400],
|
|
114
|
+
Background: background,
|
|
115
|
+
OnBackground: textPrimary,
|
|
116
|
+
BackgroundSecondary: dark ? container(0) : n[100],
|
|
117
|
+
Surface: surface,
|
|
118
|
+
OnSurface: textPrimary,
|
|
119
|
+
SurfaceVariant: dark ? container(2) : n[100],
|
|
120
|
+
OnSurfaceVariant: textSecondary,
|
|
121
|
+
SurfaceBorder: outlineVariant,
|
|
122
|
+
InverseSurface: dark ? n[50] : n[900],
|
|
123
|
+
InverseOnSurface: dark ? n[900] : n[50],
|
|
124
|
+
InversePrimary: dark ? tonalScale(primary)[700] : tonalScale(primary)[300],
|
|
125
|
+
SurfaceContainerHighest: dark ? container(4) : n[200],
|
|
126
|
+
SurfaceContainerHigh: dark ? container(3) : oklchToHex({
|
|
127
|
+
...toOklch(n[100]),
|
|
128
|
+
l: 0.93
|
|
129
|
+
}),
|
|
130
|
+
SurfaceContainer: dark ? container(2) : n[100],
|
|
131
|
+
SurfaceContainerLow: dark ? container(1) : n[50],
|
|
132
|
+
SurfaceContainerLowest: dark ? oklchToHex({
|
|
133
|
+
...toOklch(n[950]),
|
|
134
|
+
l: 0.13
|
|
135
|
+
}) : '#FFFFFF',
|
|
136
|
+
SurfaceBright: dark ? container(4) : '#FFFFFF',
|
|
137
|
+
SurfaceDim: dark ? background : n[200],
|
|
138
|
+
Scrim: alpha('#000000', dark ? 0.8 : 0.6),
|
|
139
|
+
ScrimLight: alpha('#000000', dark ? 0.6 : 0.4),
|
|
140
|
+
Overlay: alpha('#000000', dark ? 0.2 : 0.078431375),
|
|
141
|
+
OverlayLight: alpha('#000000', dark ? 0.101960786 : 0.039215688),
|
|
142
|
+
TextPrimary: textPrimary,
|
|
143
|
+
TextSecondary: textSecondary,
|
|
144
|
+
TextTertiary: textTertiary,
|
|
145
|
+
TextDisabled: textDisabled,
|
|
146
|
+
White: '#FFFFFF',
|
|
147
|
+
Black: '#000000',
|
|
148
|
+
Light: '#EEEEEE',
|
|
149
|
+
Dark: '#222222',
|
|
150
|
+
Divider: dark ? container(1) : n[100],
|
|
151
|
+
DividerStrong: outlineVariant,
|
|
152
|
+
Focus: roles.Primary.fill,
|
|
153
|
+
FocusVisible: alpha(roles.Primary.fill, dark ? 0.4 : 0.34901962),
|
|
154
|
+
Disabled: textDisabled,
|
|
155
|
+
DisabledContainer: dark ? container(2) : n[100],
|
|
156
|
+
CardBackground: surface,
|
|
157
|
+
CardBorder: outlineVariant,
|
|
158
|
+
CardElevated: dark ? container(2) : '#FFFFFF',
|
|
159
|
+
Default: dark ? container(3) : n[100],
|
|
160
|
+
OnDefault: textPrimary,
|
|
161
|
+
DefaultContainer: dark ? container(4) : n[200],
|
|
162
|
+
OnDefaultContainer: textPrimary,
|
|
163
|
+
DefaultBorder: outline,
|
|
164
|
+
DefaultHover: dark ? container(4) : n[200],
|
|
165
|
+
DefaultPressed: outline,
|
|
166
|
+
InputBackground: surface,
|
|
167
|
+
InputBorder: outline,
|
|
168
|
+
InputBorderFocused: roles.Primary.fill,
|
|
169
|
+
InputPlaceholder: ensureContrast(dark ? n[500] : n[500], surface, 3)
|
|
170
|
+
});
|
|
171
|
+
return Object.freeze(out);
|
|
172
|
+
}
|
|
173
|
+
function createBrandPalettes(brand, options = {}) {
|
|
174
|
+
return {
|
|
175
|
+
light: createBrandPalette(brand, 'light', options),
|
|
176
|
+
dark: createBrandPalette(brand, 'dark', options)
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export { createBrandPalette, createBrandPalettes };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=brand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme/brand.js","sources":["../../src/theme/brand.ts"],"sourcesContent":["// A complete G9 palette (every G9ColorToken) from a few brand colours: tonal scales in OKLCH, roles placed on the steps a\n// Material-style theme uses, and every text-on-fill pair repaired to the requested contrast. This replaces the\n// hand-tuned palettes of each app (SAC `tokens(branding, night)`, ShopManager recipes, G9Hub accent themes): one brand\n// colour in, a light and a dark palette out, both legible by construction.\n\nimport type { G9PaletteValues } from '../tokens/generated/palettes';\nimport { formatColor, type G9ColorInput, getContrastRatio, mix, withAlpha } from './color';\nimport { ensureContrast, type G9TonalScale, neutralScale, oklchToHex, tonalScale, toOklch } from './oklch';\nimport type { G9ColorScheme } from './theme';\n\n/** The colours a brand gives. Only `primary` is required; the rest are derived when missing. */\nexport interface G9BrandColors {\n readonly primary: G9ColorInput;\n readonly secondary?: G9ColorInput;\n readonly tertiary?: G9ColorInput;\n readonly quaternary?: G9ColorInput;\n /** Status colours; derived from fixed hues tuned to the brand's chroma when missing. */\n readonly error?: G9ColorInput;\n readonly warning?: G9ColorInput;\n readonly success?: G9ColorInput;\n readonly info?: G9ColorInput;\n /** The grey's hue source (default: primary). */\n readonly neutral?: G9ColorInput;\n}\n\n/** How {@link createBrandPalette} builds a palette from a brand colour: grey tint, contrast target and whether the brand colour is kept as is. */\nexport interface G9BrandPaletteOptions {\n /** How much of the brand hue the greys carry, 0 (pure grey) … 1. Default 0.35. */\n readonly tint?: number;\n /** Minimum contrast for text on its fill: `'AA'` 4.5 (default) or `'AAA'` 7. */\n readonly contrast?: 'AA' | 'AAA';\n /**\n * Keep the brand colour itself as `Primary` (default true): the fill is the exact brand colour and its `On` colour is\n * chosen for contrast. False lets the generator move the fill too when neither black nor white reaches the contrast.\n */\n readonly keepBrand?: boolean;\n}\n\nconst STATUS_HUE = { error: 25, warning: 70, success: 150, info: 245 } as const;\n\nfunction hueColor(h: number, like: G9ColorInput, l = 0.6): string {\n const c = Math.max(0.1, Math.min(0.17, toOklch(like).c || 0.13));\n return oklchToHex({ l, c, h });\n}\n\nfunction rotate(color: G9ColorInput, degrees: number, chromaScale: number): string {\n const x = toOklch(color);\n return oklchToHex({ l: x.l, c: x.c * chromaScale, h: (x.h + degrees + 360) % 360 });\n}\n\nconst hex = (c: G9ColorInput): string => formatColor(c);\nconst alpha = (c: G9ColorInput, a: number): string => formatColor(withAlpha(c, a));\n\ninterface Role {\n readonly fill: string;\n readonly on: string;\n readonly container: string;\n readonly onContainer: string;\n readonly border: string;\n readonly hover: string;\n readonly pressed: string;\n}\n\n/** The seven tokens of a colour role, for one scheme. */\nfunction role(base: G9ColorInput, scheme: G9ColorScheme, min: number, keep: boolean): Role {\n const scale: G9TonalScale = tonalScale(base);\n const dark = scheme === 'dark';\n // Dark schemes use a lighter tone of the brand as the fill (Material's tone 80 rule): the exact brand on near-black\n // glares and its dark text pair reads badly. Light schemes keep the brand itself.\n // In light schemes the brand stays itself when it reads on white as a UI colour (3:1, WCAG 1.4.11); a pale brand\n // (teal, yellow) is deepened along its own hue just enough — the fill is also used as text and focus rings.\n let fill = dark ? (toOklch(base).l > 0.62 ? hex(base) : scale[400]) : ensureContrast(base, '#FFFFFF', 3);\n let on = pickOn(fill, scale, dark);\n if (getContrastRatio(on, fill) < min && !keep) {\n // Move the fill, not the text: in light schemes deepen it under white text (it then also reads on the white page),\n // in dark schemes lighten it under the deep tone (it then reads on the dark page).\n on = dark ? scale[950] : '#FFFFFF';\n fill = ensureContrast(fill, on, min);\n }\n if (getContrastRatio(on, fill) < min) on = ensureContrast(on, fill, min);\n const container = dark ? scale[900] : scale[100];\n const onContainer = ensureContrast(dark ? scale[100] : scale[900], container, min);\n const border = dark ? scale[600] : scale[700];\n const hover = hex(mix(fill, on, 0.08));\n const pressed = hex(mix(fill, on, 0.16));\n return { fill, on, container, onContainer, border, hover, pressed };\n}\n\n/** Text on a fill: a near-white or a near-black of the fill's own hue, whichever reads better. */\nfunction pickOn(fill: string, scale: G9TonalScale, dark: boolean): string {\n const light = '#FFFFFF';\n const deep = scale[950];\n const a = getContrastRatio(light, fill);\n const b = getContrastRatio(deep, fill);\n // In dark schemes prefer the deep tone (Material's on-color), unless white is clearly better.\n if (dark) return b >= a * 0.8 ? deep : light;\n return a >= b ? light : deep;\n}\n\n/**\n * The full palette for `scheme`. Pure and deterministic: the same brand gives the same palette everywhere (app, web,\n * server-side previews), so it can be computed at build time or on the device.\n */\nexport function createBrandPalette(\n brand: G9BrandColors,\n scheme: G9ColorScheme,\n options: G9BrandPaletteOptions = {},\n): G9PaletteValues {\n const dark = scheme === 'dark';\n const min = options.contrast === 'AAA' ? 7 : 4.5;\n const keep = options.keepBrand !== false;\n const primary = brand.primary;\n const n = neutralScale(brand.neutral ?? primary, options.tint ?? 0.35);\n const secondary = brand.secondary ?? rotate(primary, 30, 0.55);\n const tertiary = brand.tertiary ?? rotate(primary, 120, 0.8);\n const quaternary = brand.quaternary ?? rotate(primary, -70, 0.75);\n const roles = {\n Primary: role(primary, scheme, min, keep),\n Secondary: role(secondary, scheme, min, false),\n Tertiary: role(tertiary, scheme, min, false),\n Quaternary: role(quaternary, scheme, min, false),\n Error: role(brand.error ?? hueColor(STATUS_HUE.error, primary, 0.55), scheme, min, false),\n Warning: role(brand.warning ?? hueColor(STATUS_HUE.warning, primary, 0.66), scheme, min, false),\n Success: role(brand.success ?? hueColor(STATUS_HUE.success, primary, 0.56), scheme, min, false),\n Info: role(brand.info ?? hueColor(STATUS_HUE.info, primary, 0.55), scheme, min, false),\n };\n\n // Neutral ladder: light schemes go up from a near-white page, dark ones down from a near-black page.\n const surface = dark ? oklchToHex({ ...toOklch(n[950]), l: 0.2 }) : '#FFFFFF';\n const background = dark ? oklchToHex({ ...toOklch(n[950]), l: 0.16 }) : n[50];\n const textPrimary = ensureContrast(dark ? n[50] : n[950], surface, Math.max(min, 7));\n const textSecondary = ensureContrast(dark ? n[300] : n[700], surface, min);\n const textTertiary = ensureContrast(dark ? n[400] : n[600], surface, 3);\n const textDisabled = dark ? n[700] : n[300];\n const container = (step: number) => oklchToHex({ ...toOklch(n[950]), l: 0.2 + step * 0.035 });\n const out: Record<string, string> = {};\n for (const [name, r] of Object.entries(roles)) {\n out[name] = r.fill;\n out[`On${name}`] = r.on;\n out[`${name}Container`] = r.container;\n out[`On${name}Container`] = r.onContainer;\n out[`${name}Border`] = r.border;\n if (name === 'Primary') {\n out.PrimaryHover = r.hover;\n out.PrimaryPressed = r.pressed;\n }\n }\n const outline = dark ? n[700] : n[300];\n const outlineVariant = dark ? n[800] : n[200];\n Object.assign(out, {\n Outline: outline,\n OutlineVariant: outlineVariant,\n OutlineBorder: dark ? n[600] : n[400],\n Background: background,\n OnBackground: textPrimary,\n BackgroundSecondary: dark ? container(0) : n[100],\n Surface: surface,\n OnSurface: textPrimary,\n SurfaceVariant: dark ? container(2) : n[100],\n OnSurfaceVariant: textSecondary,\n SurfaceBorder: outlineVariant,\n InverseSurface: dark ? n[50] : n[900],\n InverseOnSurface: dark ? n[900] : n[50],\n InversePrimary: dark ? tonalScale(primary)[700] : tonalScale(primary)[300],\n SurfaceContainerHighest: dark ? container(4) : n[200],\n SurfaceContainerHigh: dark ? container(3) : oklchToHex({ ...toOklch(n[100]), l: 0.93 }),\n SurfaceContainer: dark ? container(2) : n[100],\n SurfaceContainerLow: dark ? container(1) : n[50],\n SurfaceContainerLowest: dark ? oklchToHex({ ...toOklch(n[950]), l: 0.13 }) : '#FFFFFF',\n SurfaceBright: dark ? container(4) : '#FFFFFF',\n SurfaceDim: dark ? background : n[200],\n Scrim: alpha('#000000', dark ? 0.8 : 0.6),\n ScrimLight: alpha('#000000', dark ? 0.6 : 0.4),\n Overlay: alpha('#000000', dark ? 0.2 : 0.078431375),\n OverlayLight: alpha('#000000', dark ? 0.101960786 : 0.039215688),\n TextPrimary: textPrimary,\n TextSecondary: textSecondary,\n TextTertiary: textTertiary,\n TextDisabled: textDisabled,\n White: '#FFFFFF',\n Black: '#000000',\n Light: '#EEEEEE',\n Dark: '#222222',\n Divider: dark ? container(1) : n[100],\n DividerStrong: outlineVariant,\n Focus: roles.Primary.fill,\n FocusVisible: alpha(roles.Primary.fill, dark ? 0.4 : 0.34901962),\n Disabled: textDisabled,\n DisabledContainer: dark ? container(2) : n[100],\n CardBackground: surface,\n CardBorder: outlineVariant,\n CardElevated: dark ? container(2) : '#FFFFFF',\n Default: dark ? container(3) : n[100],\n OnDefault: textPrimary,\n DefaultContainer: dark ? container(4) : n[200],\n OnDefaultContainer: textPrimary,\n DefaultBorder: outline,\n DefaultHover: dark ? container(4) : n[200],\n DefaultPressed: outline,\n InputBackground: surface,\n InputBorder: outline,\n InputBorderFocused: roles.Primary.fill,\n InputPlaceholder: ensureContrast(dark ? n[500] : n[500], surface, 3),\n });\n return Object.freeze(out) as unknown as G9PaletteValues;\n}\n\n/** Both schemes at once (what a theme store's `palettes` option takes). */\nexport function createBrandPalettes(brand: G9BrandColors, options: G9BrandPaletteOptions = {}) {\n return { light: createBrandPalette(brand, 'light', options), dark: createBrandPalette(brand, 'dark', options) };\n}\n"],"names":["STATUS_HUE","hueColor","h","like","l","c","Math","toOklch","oklchToHex","rotate","color","degrees","chromaScale","x","hex","formatColor","alpha","a","withAlpha","role","base","scheme","min","keep","scale","tonalScale","dark","fill","ensureContrast","on","pickOn","getContrastRatio","container","onContainer","border","hover","mix","pressed","light","deep","b","createBrandPalette","brand","options","_brand_neutral","_options_tint","_brand_secondary","_brand_tertiary","_brand_quaternary","_brand_error","_brand_warning","_brand_success","_brand_info","primary","n","neutralScale","secondary","tertiary","quaternary","roles","surface","background","textPrimary","textSecondary","textTertiary","textDisabled","step","out","name","r","Object","outline","outlineVariant","createBrandPalettes"],"mappings":";;AAsCA,MAAMA,aAAa;IAAE,OAAO;IAAI,SAAS;IAAI,SAAS;IAAK,MAAM;AAAI;AAErE,SAASC,SAASC,CAAS,EAAEC,IAAkB,EAAEC,IAAI,GAAG;IACtD,MAAMC,IAAIC,KAAK,GAAG,CAAC,KAAKA,KAAK,GAAG,CAAC,MAAMC,QAAQJ,MAAM,CAAC,IAAI;IAC1D,OAAOK,WAAW;QAAEJ;QAAGC;QAAGH;IAAE;AAC9B;AAEA,SAASO,OAAOC,KAAmB,EAAEC,OAAe,EAAEC,WAAmB;IACvE,MAAMC,IAAIN,QAAQG;IAClB,OAAOF,WAAW;QAAE,GAAGK,EAAE,CAAC;QAAE,GAAGA,EAAE,CAAC,GAAGD;QAAa,GAAIC,AAAAA,CAAAA,EAAE,CAAC,GAAGF,UAAU,GAAE,IAAK;IAAI;AACnF;AAEA,MAAMG,MAAM,CAACT,IAA4BU,YAAYV;AACrD,MAAMW,QAAQ,CAACX,GAAiBY,IAAsBF,YAAYG,UAAUb,GAAGY;AAa/E,SAASE,KAAKC,IAAkB,EAAEC,MAAqB,EAAEC,GAAW,EAAEC,IAAa;IACjF,MAAMC,QAAsBC,WAAWL;IACvC,MAAMM,OAAOL,AAAW,WAAXA;IAKb,IAAIM,OAAOD,OAAQnB,QAAQa,MAAM,CAAC,GAAG,OAAON,IAAIM,QAAQI,KAAK,CAAC,IAAI,GAAII,eAAeR,MAAM,WAAW;IACtG,IAAIS,KAAKC,OAAOH,MAAMH,OAAOE;IAC7B,IAAIK,iBAAiBF,IAAIF,QAAQL,OAAO,CAACC,MAAM;QAG7CM,KAAKH,OAAOF,KAAK,CAAC,IA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,OAAO,cAAc;QACpD,aAAaoC;QACb,eAAeC;QACf,cAAcC;QACd,cAAcC;QACd,OAAO;QACP,OAAO;QACP,OAAO;QACP,MAAM;QACN,SAASvC,OAAOM,UAAU,KAAKsB,CAAC,CAAC,IAAI;QACrC,eAAekB;QACf,OAAOb,MAAM,OAAO,CAAC,IAAI;QACzB,cAAc3C,MAAM2C,MAAM,OAAO,CAAC,IAAI,EAAEjC,OAAO,MAAM;QACrD,UAAUuC;QACV,mBAAmBvC,OAAOM,UAAU,KAAKsB,CAAC,CAAC,IAAI;QAC/C,gBAAgBM;QAChB,YAAYY;QACZ,cAAc9C,OAAOM,UAAU,KAAK;QACpC,SAASN,OAAOM,UAAU,KAAKsB,CAAC,CAAC,IAAI;QACrC,WAAWQ;QACX,kBAAkBpC,OAAOM,UAAU,KAAKsB,CAAC,CAAC,IAAI;QAC9C,oBAAoBQ;QACpB,eAAeS;QACf,cAAc7C,OAAOM,UAAU,KAAKsB,CAAC,CAAC,IAAI;QAC1C,gBAAgBiB;QAChB,iBAAiBX;QACjB,aAAaW;QACb,oBAAoBZ,MAAM,OAAO,CAAC,IAAI;QACtC,kBAAkB/B,eAAeF,OAAO4B,CAAC,CAAC,IAAI,GAAGA,CAAC,CAAC,IAAI,EAAEM,SAAS;IACpE;IACA,OAAOU,OAAO,MAAM,CAACH;AACvB;AAGO,SAASM,oBAAoB/B,KAAoB,EAAEC,UAAiC,CAAC,CAAC;IAC3F,OAAO;QAAE,OAAOF,mBAAmBC,OAAO,SAASC;QAAU,MAAMF,mBAAmBC,OAAO,QAAQC;IAAS;AAChH"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { G9ColorToken, G9PaletteValues } from '../tokens/generated/palettes.js';
|
|
2
|
+
/** `[foreground, background, minimum]`. 4.5 = body text (WCAG AA), 3 = large text, icons and borders that carry meaning. */
|
|
3
|
+
export type G9ContrastRule = readonly [G9ColorToken, G9ColorToken, number];
|
|
4
|
+
/** The rules every palette must pass. */
|
|
5
|
+
export declare const g9ContrastRules: readonly G9ContrastRule[];
|
|
6
|
+
/** One rule's outcome. */
|
|
7
|
+
export interface G9ContrastResult {
|
|
8
|
+
readonly foreground: G9ColorToken;
|
|
9
|
+
readonly background: G9ColorToken;
|
|
10
|
+
readonly required: number;
|
|
11
|
+
/** The measured ratio, 2 decimals. NaN when a colour cannot be read (a CSS variable, say). */
|
|
12
|
+
readonly ratio: number;
|
|
13
|
+
readonly pass: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Checks `palette` against `rules` (default {@link g9ContrastRules}); failures first. */
|
|
16
|
+
export declare function contrastReport(palette: G9PaletteValues, rules?: readonly G9ContrastRule[]): readonly G9ContrastResult[];
|
|
17
|
+
/** Only the failures. */
|
|
18
|
+
export declare const contrastFailures: (palette: G9PaletteValues, rules?: readonly G9ContrastRule[]) => G9ContrastResult[];
|
|
19
|
+
//# sourceMappingURL=contrast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contrast.d.ts","sourceRoot":"","sources":["../../src/theme/contrast.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAGlF,4HAA4H;AAC5H,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AAI3E,yCAAyC;AACzC,eAAO,MAAM,eAAe,EAAE,SAAS,cAAc,EAoB/B,CAAC;AAEvB,0BAA0B;AAC1B,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,0FAA0F;AAC1F,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,KAAK,GAAE,SAAS,cAAc,EAAoB,GACjD,SAAS,gBAAgB,EAAE,CAQ7B;AAED,yBAAyB;AACzB,eAAO,MAAM,gBAAgB,GAAI,SAAS,eAAe,EAAE,QAAQ,SAAS,cAAc,EAAE,uBACrC,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { getContrastRatio, tryParseColor } from "./color.js";
|
|
2
|
+
const ROLES = [
|
|
3
|
+
'Primary',
|
|
4
|
+
'Secondary',
|
|
5
|
+
'Tertiary',
|
|
6
|
+
'Quaternary',
|
|
7
|
+
'Error',
|
|
8
|
+
'Warning',
|
|
9
|
+
'Success',
|
|
10
|
+
'Info'
|
|
11
|
+
];
|
|
12
|
+
const g9ContrastRules = Object.freeze([
|
|
13
|
+
...ROLES.flatMap((r)=>[
|
|
14
|
+
[
|
|
15
|
+
`On${r}`,
|
|
16
|
+
r,
|
|
17
|
+
4.5
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
`On${r}Container`,
|
|
21
|
+
`${r}Container`,
|
|
22
|
+
4.5
|
|
23
|
+
]
|
|
24
|
+
]),
|
|
25
|
+
[
|
|
26
|
+
'TextPrimary',
|
|
27
|
+
'Surface',
|
|
28
|
+
7
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
'TextPrimary',
|
|
32
|
+
'Background',
|
|
33
|
+
7
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
'TextSecondary',
|
|
37
|
+
'Surface',
|
|
38
|
+
4.5
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
'TextSecondary',
|
|
42
|
+
'Background',
|
|
43
|
+
4.5
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
'TextTertiary',
|
|
47
|
+
'Surface',
|
|
48
|
+
3
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
'OnSurface',
|
|
52
|
+
'Surface',
|
|
53
|
+
7
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
'OnSurfaceVariant',
|
|
57
|
+
'SurfaceVariant',
|
|
58
|
+
4.5
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
'OnBackground',
|
|
62
|
+
'Background',
|
|
63
|
+
7
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
'InverseOnSurface',
|
|
67
|
+
'InverseSurface',
|
|
68
|
+
4.5
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
'OnDefault',
|
|
72
|
+
'Default',
|
|
73
|
+
4.5
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
'OnDefaultContainer',
|
|
77
|
+
'DefaultContainer',
|
|
78
|
+
4.5
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
'InputPlaceholder',
|
|
82
|
+
'InputBackground',
|
|
83
|
+
3
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
'InputBorderFocused',
|
|
87
|
+
'InputBackground',
|
|
88
|
+
3
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
'Primary',
|
|
92
|
+
'Surface',
|
|
93
|
+
3
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
'Error',
|
|
97
|
+
'Surface',
|
|
98
|
+
3
|
|
99
|
+
]
|
|
100
|
+
]);
|
|
101
|
+
function contrastReport(palette, rules = g9ContrastRules) {
|
|
102
|
+
const out = rules.map(([fg, bg, required])=>{
|
|
103
|
+
const a = tryParseColor(palette[fg]);
|
|
104
|
+
const b = tryParseColor(palette[bg]);
|
|
105
|
+
const ratio = a && b ? Math.round(100 * getContrastRatio(a, b)) / 100 : 0 / 0;
|
|
106
|
+
return {
|
|
107
|
+
foreground: fg,
|
|
108
|
+
background: bg,
|
|
109
|
+
required,
|
|
110
|
+
ratio,
|
|
111
|
+
pass: ratio >= required
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
return out.sort((x, y)=>Number(x.pass) - Number(y.pass));
|
|
115
|
+
}
|
|
116
|
+
const contrastFailures = (palette, rules)=>contrastReport(palette, rules).filter((r)=>!r.pass);
|
|
117
|
+
export { contrastFailures, contrastReport, g9ContrastRules };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=contrast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme/contrast.js","sources":["../../src/theme/contrast.ts"],"sourcesContent":["// The contrast contract of a G9 palette: which token is read on which, and how much contrast that needs. A palette that\n// breaks a rule is a bug in a theme, not a matter of taste — `contrastReport` is run by the tests of every recipe and by\n// an app's own theme tests (ShopManager's CONTRAST_RULES, G9Hub's ContrastPanel, SAC's palette tests in one place).\nimport type { G9ColorToken, G9PaletteValues } from '../tokens/generated/palettes';\nimport { getContrastRatio, tryParseColor } from './color';\n\n/** `[foreground, background, minimum]`. 4.5 = body text (WCAG AA), 3 = large text, icons and borders that carry meaning. */\nexport type G9ContrastRule = readonly [G9ColorToken, G9ColorToken, number];\n\nconst ROLES = ['Primary', 'Secondary', 'Tertiary', 'Quaternary', 'Error', 'Warning', 'Success', 'Info'] as const;\n\n/** The rules every palette must pass. */\nexport const g9ContrastRules: readonly G9ContrastRule[] = Object.freeze([\n ...ROLES.flatMap((r): G9ContrastRule[] => [\n [`On${r}` as G9ColorToken, r as G9ColorToken, 4.5],\n [`On${r}Container` as G9ColorToken, `${r}Container` as G9ColorToken, 4.5],\n ]),\n ['TextPrimary', 'Surface', 7],\n ['TextPrimary', 'Background', 7],\n ['TextSecondary', 'Surface', 4.5],\n ['TextSecondary', 'Background', 4.5],\n ['TextTertiary', 'Surface', 3],\n ['OnSurface', 'Surface', 7],\n ['OnSurfaceVariant', 'SurfaceVariant', 4.5],\n ['OnBackground', 'Background', 7],\n ['InverseOnSurface', 'InverseSurface', 4.5],\n ['OnDefault', 'Default', 4.5],\n ['OnDefaultContainer', 'DefaultContainer', 4.5],\n ['InputPlaceholder', 'InputBackground', 3],\n ['InputBorderFocused', 'InputBackground', 3],\n ['Primary', 'Surface', 3],\n ['Error', 'Surface', 3],\n] as G9ContrastRule[]);\n\n/** One rule's outcome. */\nexport interface G9ContrastResult {\n readonly foreground: G9ColorToken;\n readonly background: G9ColorToken;\n readonly required: number;\n /** The measured ratio, 2 decimals. NaN when a colour cannot be read (a CSS variable, say). */\n readonly ratio: number;\n readonly pass: boolean;\n}\n\n/** Checks `palette` against `rules` (default {@link g9ContrastRules}); failures first. */\nexport function contrastReport(\n palette: G9PaletteValues,\n rules: readonly G9ContrastRule[] = g9ContrastRules,\n): readonly G9ContrastResult[] {\n const out = rules.map(([fg, bg, required]): G9ContrastResult => {\n const a = tryParseColor(palette[fg]);\n const b = tryParseColor(palette[bg]);\n const ratio = a && b ? Math.round(getContrastRatio(a, b) * 100) / 100 : Number.NaN;\n return { foreground: fg, background: bg, required, ratio, pass: ratio >= required };\n });\n return out.sort((x, y) => Number(x.pass) - Number(y.pass));\n}\n\n/** Only the failures. */\nexport const contrastFailures = (palette: G9PaletteValues, rules?: readonly G9ContrastRule[]) =>\n contrastReport(palette, rules).filter((r) => !r.pass);\n"],"names":["ROLES","g9ContrastRules","Object","r","contrastReport","palette","rules","out","fg","bg","required","a","tryParseColor","b","ratio","Math","getContrastRatio","Number","x","y","contrastFailures"],"mappings":";AASA,MAAMA,QAAQ;IAAC;IAAW;IAAa;IAAY;IAAc;IAAS;IAAW;IAAW;CAAO;AAGhG,MAAMC,kBAA6CC,OAAO,MAAM,CAAC;OACnEF,MAAM,OAAO,CAAC,CAACG,IAAwB;YACxC;gBAAC,CAAC,EAAE,EAAEA,GAAG;gBAAkBA;gBAAmB;aAAI;YAClD;gBAAC,CAAC,EAAE,EAAEA,EAAE,SAAS,CAAC;gBAAkB,GAAGA,EAAE,SAAS,CAAC;gBAAkB;aAAI;SAC1E;IACD;QAAC;QAAe;QAAW;KAAE;IAC7B;QAAC;QAAe;QAAc;KAAE;IAChC;QAAC;QAAiB;QAAW;KAAI;IACjC;QAAC;QAAiB;QAAc;KAAI;IACpC;QAAC;QAAgB;QAAW;KAAE;IAC9B;QAAC;QAAa;QAAW;KAAE;IAC3B;QAAC;QAAoB;QAAkB;KAAI;IAC3C;QAAC;QAAgB;QAAc;KAAE;IACjC;QAAC;QAAoB;QAAkB;KAAI;IAC3C;QAAC;QAAa;QAAW;KAAI;IAC7B;QAAC;QAAsB;QAAoB;KAAI;IAC/C;QAAC;QAAoB;QAAmB;KAAE;IAC1C;QAAC;QAAsB;QAAmB;KAAE;IAC5C;QAAC;QAAW;QAAW;KAAE;IACzB;QAAC;QAAS;QAAW;KAAE;CACxB;AAaM,SAASC,eACdC,OAAwB,EACxBC,QAAmCL,eAAe;IAElD,MAAMM,MAAMD,MAAM,GAAG,CAAC,CAAC,CAACE,IAAIC,IAAIC,SAAS;QACvC,MAAMC,IAAIC,cAAcP,OAAO,CAACG,GAAG;QACnC,MAAMK,IAAID,cAAcP,OAAO,CAACI,GAAG;QACnC,MAAMK,QAAQH,KAAKE,IAAIE,KAAK,KAAK,CAACC,AAAyB,MAAzBA,iBAAiBL,GAAGE,MAAY,MAAMI,KAAU;QAClF,OAAO;YAAE,YAAYT;YAAI,YAAYC;YAAIC;YAAUI;YAAO,MAAMA,SAASJ;QAAS;IACpF;IACA,OAAOH,IAAI,IAAI,CAAC,CAACW,GAAGC,IAAMF,OAAOC,EAAE,IAAI,IAAID,OAAOE,EAAE,IAAI;AAC1D;AAGO,MAAMC,mBAAmB,CAACf,SAA0BC,QACzDF,eAAeC,SAASC,OAAO,MAAM,CAAC,CAACH,IAAM,CAACA,EAAE,IAAI"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type G9Rgba } from './color.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses any colour Lynx might be handed by a design tool or a web theme: hex, rgb/rgba, hsl/hsla, oklch, oklab,
|
|
4
|
+
* color-mix (in srgb, oklch or oklab, with percentages), a few named colours. Returns channels, or `undefined`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseCssColor(input: string): G9Rgba | undefined;
|
|
7
|
+
/** A colour Lynx can paint (`#RRGGBB` or `rgba(…)`), or the input unchanged when it is not a colour (a `var(--x)`). */
|
|
8
|
+
export declare function resolveCssColor(input: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Every colour function inside a CSS value replaced by a paintable colour
|
|
11
|
+
* (`'1px solid color-mix(in oklch, #f00 30%, white)'` → `'1px solid #FFB3A7'`), for shorthands and gradients.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveColorFunctions(value: string): string;
|
|
14
|
+
/** Named easings as cubic-bezier (Lynx reads cubic-bezier, linear, ease, ease-in, ease-out, ease-in-out). */
|
|
15
|
+
export declare const g9Easings: Readonly<Record<string, string>>;
|
|
16
|
+
/** A named easing as Lynx-readable CSS, or the input when it already is one. */
|
|
17
|
+
export declare const resolveEasing: (name: string) => string;
|
|
18
|
+
/** Lightness 0..1 of any parsable colour (for "is this a dark surface?" decisions). */
|
|
19
|
+
export declare const lightnessOf: (color: string) => number | undefined;
|
|
20
|
+
//# sourceMappingURL=css-color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-color.d.ts","sourceRoot":"","sources":["../../src/theme/css-color.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,KAAK,MAAM,EAAmD,MAAM,SAAS,CAAC;AA2DpG;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAoF/D;AAED,uHAAuH;AACvH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED,6GAA6G;AAC7G,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUrD,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAAiC,CAAC;AAE/E,uFAAuF;AACvF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,GAAG,SAGpD,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { formatColor, mix, parseColor, rgba, tryParseColor, withAlpha } from "./color.js";
|
|
2
|
+
import { fromOklch, mixOklch, toOklch } from "./oklch.js";
|
|
3
|
+
const NAMED = {
|
|
4
|
+
black: '#000000',
|
|
5
|
+
white: '#FFFFFF',
|
|
6
|
+
red: '#FF0000',
|
|
7
|
+
green: '#008000',
|
|
8
|
+
blue: '#0000FF',
|
|
9
|
+
yellow: '#FFFF00',
|
|
10
|
+
orange: '#FFA500',
|
|
11
|
+
purple: '#800080',
|
|
12
|
+
gray: '#808080',
|
|
13
|
+
grey: '#808080',
|
|
14
|
+
silver: '#C0C0C0',
|
|
15
|
+
navy: '#000080',
|
|
16
|
+
teal: '#008080',
|
|
17
|
+
transparent: 'rgba(0, 0, 0, 0)',
|
|
18
|
+
currentcolor: ''
|
|
19
|
+
};
|
|
20
|
+
const num = (t, percentScale = 1)=>t.endsWith('%') ? Number(t.slice(0, -1)) / 100 * percentScale : Number(t);
|
|
21
|
+
function splitArgs(text, by = /,/) {
|
|
22
|
+
const out = [];
|
|
23
|
+
let depth = 0;
|
|
24
|
+
let cur = '';
|
|
25
|
+
for (const ch of text){
|
|
26
|
+
if ('(' === ch) depth++;
|
|
27
|
+
if (')' === ch) depth--;
|
|
28
|
+
if (0 === depth && by.test(ch)) {
|
|
29
|
+
out.push(cur.trim());
|
|
30
|
+
cur = '';
|
|
31
|
+
} else cur += ch;
|
|
32
|
+
}
|
|
33
|
+
if (cur.trim()) out.push(cur.trim());
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function hslToRgba(h, s, l, a) {
|
|
37
|
+
const k = (n)=>(n + h / 30) % 12;
|
|
38
|
+
const f = (n)=>l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
|
39
|
+
return rgba(f(0), f(8), f(4), a);
|
|
40
|
+
}
|
|
41
|
+
function channels(body) {
|
|
42
|
+
const [main, a] = body.split('/');
|
|
43
|
+
return {
|
|
44
|
+
parts: (null != main ? main : '').trim().split(/[\s,]+/).filter(Boolean),
|
|
45
|
+
alpha: a ? num(a.trim()) : 1
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function parseCssColor(input) {
|
|
49
|
+
const text = input.trim();
|
|
50
|
+
const lower = text.toLowerCase();
|
|
51
|
+
if (lower in NAMED) return NAMED[lower] ? parseColor(NAMED[lower]) : void 0;
|
|
52
|
+
const direct = tryParseColor(text);
|
|
53
|
+
if (direct) return direct;
|
|
54
|
+
const m = /^([a-z-]+)\((.*)\)$/is.exec(text);
|
|
55
|
+
if (!m) return;
|
|
56
|
+
const fn = m[1].toLowerCase();
|
|
57
|
+
const body = m[2];
|
|
58
|
+
if ('rgb' === fn || 'rgba' === fn) {
|
|
59
|
+
const { parts, alpha } = channels(body);
|
|
60
|
+
if (parts.length < 3) return;
|
|
61
|
+
return rgba(num(parts[0], 255) / 255, num(parts[1], 255) / 255, num(parts[2], 255) / 255, alpha);
|
|
62
|
+
}
|
|
63
|
+
if ('hsl' === fn || 'hsla' === fn) {
|
|
64
|
+
const { parts, alpha } = channels(body);
|
|
65
|
+
if (parts.length < 3) return;
|
|
66
|
+
const h = Number.parseFloat(parts[0]);
|
|
67
|
+
return hslToRgba((h % 360 + 360) % 360, num(parts[1]), num(parts[2]), parts[3] ? num(parts[3]) : alpha);
|
|
68
|
+
}
|
|
69
|
+
if ('oklch' === fn) {
|
|
70
|
+
const { parts, alpha } = channels(body);
|
|
71
|
+
if (parts.length < 3) return;
|
|
72
|
+
return fromOklch({
|
|
73
|
+
l: num(parts[0]),
|
|
74
|
+
c: num(parts[1], 0.4),
|
|
75
|
+
h: Number.parseFloat(parts[2]) || 0,
|
|
76
|
+
alpha
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if ('oklab' === fn) {
|
|
80
|
+
const { parts, alpha } = channels(body);
|
|
81
|
+
if (parts.length < 3) return;
|
|
82
|
+
const L = num(parts[0]);
|
|
83
|
+
const a = num(parts[1], 0.4);
|
|
84
|
+
const b = num(parts[2], 0.4);
|
|
85
|
+
let h = 180 * Math.atan2(b, a) / Math.PI;
|
|
86
|
+
if (h < 0) h += 360;
|
|
87
|
+
return fromOklch({
|
|
88
|
+
l: L,
|
|
89
|
+
c: Math.hypot(a, b),
|
|
90
|
+
h,
|
|
91
|
+
alpha
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if ('color-mix' === fn) {
|
|
95
|
+
var _args_, _args_1, _args_2;
|
|
96
|
+
const args = splitArgs(body);
|
|
97
|
+
const space = (null != (_args_ = args[0]) ? _args_ : '').replace(/^in\s+/i, '').trim().toLowerCase();
|
|
98
|
+
const parse = (arg)=>{
|
|
99
|
+
var _ref;
|
|
100
|
+
const pm = /^(.*?)(?:\s+(\d+(?:\.\d+)?)%)?$/s.exec(arg.trim());
|
|
101
|
+
return {
|
|
102
|
+
color: parseCssColor((null != (_ref = null == pm ? void 0 : pm[1]) ? _ref : arg).trim()),
|
|
103
|
+
pct: (null == pm ? void 0 : pm[2]) !== void 0 ? Number(pm[2]) / 100 : void 0
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
const a = parse(null != (_args_1 = args[1]) ? _args_1 : '');
|
|
107
|
+
const b = parse(null != (_args_2 = args[2]) ? _args_2 : '');
|
|
108
|
+
if (!a.color || !b.color) return;
|
|
109
|
+
let pa = a.pct;
|
|
110
|
+
let pb = b.pct;
|
|
111
|
+
if (void 0 === pa && void 0 === pb) pa = pb = 0.5;
|
|
112
|
+
else if (void 0 === pa) pa = 1 - pb;
|
|
113
|
+
else if (void 0 === pb) pb = 1 - pa;
|
|
114
|
+
const total = pa + pb;
|
|
115
|
+
const t = pb / (total || 1);
|
|
116
|
+
const alphaScale = Math.min(1, total);
|
|
117
|
+
const mixed = space.startsWith('oklch') || space.startsWith('oklab') ? parseColor(mixOklch(a.color, b.color, t).replace(/^#/, '#')) : mix(a.color, b.color, t);
|
|
118
|
+
return alphaScale < 1 ? withAlpha(mixed, mixed.a * alphaScale) : mixed;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function resolveCssColor(input) {
|
|
122
|
+
const parsed = parseCssColor(input);
|
|
123
|
+
return parsed ? formatColor(parsed) : input;
|
|
124
|
+
}
|
|
125
|
+
function resolveColorFunctions(value) {
|
|
126
|
+
return value.replace(/\b(color-mix|oklch|oklab|hsla?)\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)/gi, (match)=>resolveCssColor(match));
|
|
127
|
+
}
|
|
128
|
+
const g9Easings = Object.freeze({
|
|
129
|
+
standard: 'cubic-bezier(0.2, 0, 0, 1)',
|
|
130
|
+
emphasized: 'cubic-bezier(0.2, 0, 0, 1)',
|
|
131
|
+
decelerate: 'cubic-bezier(0, 0, 0, 1)',
|
|
132
|
+
accelerate: 'cubic-bezier(0.3, 0, 1, 1)',
|
|
133
|
+
'ease-out-expo': 'cubic-bezier(0.16, 1, 0.3, 1)',
|
|
134
|
+
'ease-out-quint': 'cubic-bezier(0.22, 1, 0.36, 1)',
|
|
135
|
+
'ease-in-out-cubic': 'cubic-bezier(0.65, 0, 0.35, 1)',
|
|
136
|
+
ios: 'cubic-bezier(0.32, 0.72, 0, 1)',
|
|
137
|
+
spring: 'cubic-bezier(0.34, 1.56, 0.64, 1)'
|
|
138
|
+
});
|
|
139
|
+
const resolveEasing = (name)=>{
|
|
140
|
+
var _g9Easings_name;
|
|
141
|
+
return null != (_g9Easings_name = g9Easings[name]) ? _g9Easings_name : name;
|
|
142
|
+
};
|
|
143
|
+
const lightnessOf = (color)=>{
|
|
144
|
+
const c = parseCssColor(color);
|
|
145
|
+
return c ? toOklch(c).l : void 0;
|
|
146
|
+
};
|
|
147
|
+
export { g9Easings, lightnessOf, parseCssColor, resolveColorFunctions, resolveCssColor, resolveEasing };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=css-color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme/css-color.js","sources":["../../src/theme/css-color.ts"],"sourcesContent":["// Lynx's CSS engine reads hex, rgb()/rgba() and a few keywords; it does not read color-mix(), oklch(), oklab() or hsl()\n// (G9Hub resolved them by hand in lynxcolor.ts). These helpers turn any of those into a colour Lynx can paint, once, when\n// the theme is built — never per frame. Also the named easings Lynx lacks (`ease-out-expo` …) as cubic-bezier().\nimport { formatColor, type G9Rgba, mix, parseColor, rgba, tryParseColor, withAlpha } from './color';\nimport { fromOklch, mixOklch, toOklch } from './oklch';\n\nconst NAMED: Readonly<Record<string, string>> = {\n black: '#000000',\n white: '#FFFFFF',\n red: '#FF0000',\n green: '#008000',\n blue: '#0000FF',\n yellow: '#FFFF00',\n orange: '#FFA500',\n purple: '#800080',\n gray: '#808080',\n grey: '#808080',\n silver: '#C0C0C0',\n navy: '#000080',\n teal: '#008080',\n transparent: 'rgba(0, 0, 0, 0)',\n currentcolor: '',\n};\n\nconst num = (t: string, percentScale = 1): number =>\n t.endsWith('%') ? (Number(t.slice(0, -1)) / 100) * percentScale : Number(t);\n\n/** Splits a function's arguments at top-level commas (nested functions stay whole). */\nfunction splitArgs(text: string, by: RegExp = /,/): string[] {\n const out: string[] = [];\n let depth = 0;\n let cur = '';\n for (const ch of text) {\n if (ch === '(') depth++;\n if (ch === ')') depth--;\n if (depth === 0 && by.test(ch)) {\n out.push(cur.trim());\n cur = '';\n } else cur += ch;\n }\n if (cur.trim()) out.push(cur.trim());\n return out;\n}\n\nfunction hslToRgba(h: number, s: number, l: number, a: number): G9Rgba {\n const k = (n: number) => (n + h / 30) % 12;\n const f = (n: number) => l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));\n return rgba(f(0), f(8), f(4), a);\n}\n\n/** Space-separated channel syntax `L C H / A`. */\nfunction channels(body: string): { parts: string[]; alpha: number } {\n const [main, a] = body.split('/');\n return {\n parts: (main ?? '')\n .trim()\n .split(/[\\s,]+/)\n .filter(Boolean),\n alpha: a ? num(a.trim()) : 1,\n };\n}\n\n/**\n * Parses any colour Lynx might be handed by a design tool or a web theme: hex, rgb/rgba, hsl/hsla, oklch, oklab,\n * color-mix (in srgb, oklch or oklab, with percentages), a few named colours. Returns channels, or `undefined`.\n */\nexport function parseCssColor(input: string): G9Rgba | undefined {\n const text = input.trim();\n const lower = text.toLowerCase();\n if (lower in NAMED) return NAMED[lower] ? parseColor(NAMED[lower] as string) : undefined;\n const direct = tryParseColor(text);\n if (direct) return direct;\n const m = /^([a-z-]+)\\((.*)\\)$/is.exec(text);\n if (!m) return undefined;\n const fn = (m[1] as string).toLowerCase();\n const body = m[2] as string;\n if (fn === 'rgb' || fn === 'rgba') {\n // modern space syntax: rgb(255 0 0 / 50%)\n const { parts, alpha } = channels(body);\n if (parts.length < 3) return undefined;\n return rgba(\n num(parts[0] as string, 255) / 255,\n num(parts[1] as string, 255) / 255,\n num(parts[2] as string, 255) / 255,\n alpha,\n );\n }\n if (fn === 'hsl' || fn === 'hsla') {\n const { parts, alpha } = channels(body);\n if (parts.length < 3) return undefined;\n const h = Number.parseFloat(parts[0] as string);\n return hslToRgba(\n ((h % 360) + 360) % 360,\n num(parts[1] as string),\n num(parts[2] as string),\n parts[3] ? num(parts[3]) : alpha,\n );\n }\n if (fn === 'oklch') {\n const { parts, alpha } = channels(body);\n if (parts.length < 3) return undefined;\n return fromOklch({\n l: num(parts[0] as string),\n c: num(parts[1] as string, 0.4),\n h: Number.parseFloat(parts[2] as string) || 0,\n alpha,\n });\n }\n if (fn === 'oklab') {\n const { parts, alpha } = channels(body);\n if (parts.length < 3) return undefined;\n const L = num(parts[0] as string);\n const a = num(parts[1] as string, 0.4);\n const b = num(parts[2] as string, 0.4);\n let h = (Math.atan2(b, a) * 180) / Math.PI;\n if (h < 0) h += 360;\n return fromOklch({ l: L, c: Math.hypot(a, b), h, alpha });\n }\n if (fn === 'color-mix') {\n const args = splitArgs(body);\n const space = (args[0] ?? '')\n .replace(/^in\\s+/i, '')\n .trim()\n .toLowerCase();\n const parse = (arg: string) => {\n const pm = /^(.*?)(?:\\s+(\\d+(?:\\.\\d+)?)%)?$/s.exec(arg.trim());\n return {\n color: parseCssColor((pm?.[1] ?? arg).trim()),\n pct: pm?.[2] !== undefined ? Number(pm[2]) / 100 : undefined,\n };\n };\n const a = parse(args[1] ?? '');\n const b = parse(args[2] ?? '');\n if (!a.color || !b.color) return undefined;\n let pa = a.pct;\n let pb = b.pct;\n if (pa === undefined && pb === undefined) pa = pb = 0.5;\n else if (pa === undefined) pa = 1 - (pb as number);\n else if (pb === undefined) pb = 1 - pa;\n const total = (pa as number) + (pb as number);\n const t = (pb as number) / (total || 1);\n // the spec: a total under 100% scales alpha down\n const alphaScale = Math.min(1, total);\n const mixed =\n space.startsWith('oklch') || space.startsWith('oklab')\n ? parseColor(mixOklch(a.color, b.color, t).replace(/^#/, '#'))\n : mix(a.color, b.color, t);\n return alphaScale < 1 ? withAlpha(mixed, mixed.a * alphaScale) : mixed;\n }\n return undefined;\n}\n\n/** A colour Lynx can paint (`#RRGGBB` or `rgba(…)`), or the input unchanged when it is not a colour (a `var(--x)`). */\nexport function resolveCssColor(input: string): string {\n const parsed = parseCssColor(input);\n return parsed ? formatColor(parsed) : input;\n}\n\n/**\n * Every colour function inside a CSS value replaced by a paintable colour\n * (`'1px solid color-mix(in oklch, #f00 30%, white)'` → `'1px solid #FFB3A7'`), for shorthands and gradients.\n */\nexport function resolveColorFunctions(value: string): string {\n return value.replace(/\\b(color-mix|oklch|oklab|hsla?)\\((?:[^()]|\\((?:[^()]|\\([^()]*\\))*\\))*\\)/gi, (match) =>\n resolveCssColor(match),\n );\n}\n\n/** Named easings as cubic-bezier (Lynx reads cubic-bezier, linear, ease, ease-in, ease-out, ease-in-out). */\nexport const g9Easings: Readonly<Record<string, string>> = Object.freeze({\n standard: 'cubic-bezier(0.2, 0, 0, 1)',\n emphasized: 'cubic-bezier(0.2, 0, 0, 1)',\n decelerate: 'cubic-bezier(0, 0, 0, 1)',\n accelerate: 'cubic-bezier(0.3, 0, 1, 1)',\n 'ease-out-expo': 'cubic-bezier(0.16, 1, 0.3, 1)',\n 'ease-out-quint': 'cubic-bezier(0.22, 1, 0.36, 1)',\n 'ease-in-out-cubic': 'cubic-bezier(0.65, 0, 0.35, 1)',\n ios: 'cubic-bezier(0.32, 0.72, 0, 1)',\n spring: 'cubic-bezier(0.34, 1.56, 0.64, 1)',\n});\n\n/** A named easing as Lynx-readable CSS, or the input when it already is one. */\nexport const resolveEasing = (name: string): string => g9Easings[name] ?? name;\n\n/** Lightness 0..1 of any parsable colour (for \"is this a dark surface?\" decisions). */\nexport const lightnessOf = (color: string): number | undefined => {\n const c = parseCssColor(color);\n return c ? toOklch(c).l : undefined;\n};\n"],"names":["NAMED","num","t","percentScale","Number","splitArgs","text","by","out","depth","cur","ch","hslToRgba","h","s","l","a","k","n","f","Math","rgba","channels","body","main","Boolean","parseCssColor","input","lower","parseColor","undefined","direct","tryParseColor","m","fn","parts","alpha","fromOklch","L","b","_args_","_args_1","_args_2","args","space","parse","arg","pm","pa","pb","total","alphaScale","mixed","mixOklch","mix","withAlpha","resolveCssColor","parsed","formatColor","resolveColorFunctions","value","match","g9Easings","Object","resolveEasing","name","_g9Easings_name","lightnessOf","color","c","toOklch"],"mappings":";;AAMA,MAAMA,QAA0C;IAC9C,OAAO;IACP,OAAO;IACP,KAAK;IACL,OAAO;IACP,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,MAAM;IACN,MAAM;IACN,aAAa;IACb,cAAc;AAChB;AAEA,MAAMC,MAAM,CAACC,GAAWC,eAAe,CAAC,GACtCD,EAAE,QAAQ,CAAC,OAAQE,OAAOF,EAAE,KAAK,CAAC,GAAG,OAAO,MAAOC,eAAeC,OAAOF;A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AAK,AAAD,IAAdC,kBAAmBD;;AAGnE,MAAME,cAAc,CAACC;IAC1B,MAAMC,IAAI3C,cAAc0C;IACxB,OAAOC,IAAIC,QAAQD,GAAG,CAAC,GAAGvC;AAC5B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type G9ShapeSet } from '../tokens/shape.js';
|
|
2
|
+
import type { G9ThemeStore } from './theme.js';
|
|
3
|
+
/** One token as Pilot reads it. */
|
|
4
|
+
export interface G9DesignToken {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly value: number | string;
|
|
7
|
+
readonly defaultValue: number | string;
|
|
8
|
+
/** DTCG `$type`: `color`, `dimension`, `number`, `fontWeight`. */
|
|
9
|
+
readonly type: string | null;
|
|
10
|
+
readonly description?: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** Pilot's `DesignRegistry`. */
|
|
13
|
+
export interface G9DesignRegistry {
|
|
14
|
+
tokens(): readonly G9DesignToken[];
|
|
15
|
+
set(id: string, value: number | string): void;
|
|
16
|
+
reset(id?: string): void;
|
|
17
|
+
}
|
|
18
|
+
/** What {@link createDesignRegistry} edits live: the theme store and, when the app allows it, the shape. */
|
|
19
|
+
export interface G9DesignRegistryOptions {
|
|
20
|
+
readonly theme: G9ThemeStore;
|
|
21
|
+
/** The live shape, when the app lets designers change it (the provider supplies this). */
|
|
22
|
+
readonly shape?: {
|
|
23
|
+
get(): G9ShapeSet;
|
|
24
|
+
set(shape: G9ShapeSet): void;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates the registry. Colour ids are `color.<Token>` (`color.Primary`); shape ids are `shape.radius.card`,
|
|
29
|
+
* `shape.height.md`, `shape.type.body.size`, `shape.touchTarget`. A change is an override layered over the app's own
|
|
30
|
+
* overrides, so a reset returns exactly to what the app painted.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createDesignRegistry(options: G9DesignRegistryOptions): G9DesignRegistry;
|
|
33
|
+
//# sourceMappingURL=design.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design.d.ts","sourceRoot":"","sources":["../../src/theme/design.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,iBAAiB,CAAC;AAGhE,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,SAAS,CAAC;AAEhE,mCAAmC;AACnC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC,kEAAkE;IAClE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,gCAAgC;AAChC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,IAAI,SAAS,aAAa,EAAE,CAAC;IACnC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9C,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,4GAA4G;AAC5G,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,0FAA0F;IAC1F,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,GAAG,IAAI,UAAU,CAAC;QAAC,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAA;KAAE,CAAC;CACtE;AAKD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CA2HvF"}
|