@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 @@
|
|
|
1
|
+
{"version":3,"file":"recipe.d.ts","sourceRoot":"","sources":["../../src/theme/recipe.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAsB,KAAK,aAAa,EAAE,KAAK,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE7F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,KAAK,aAAa,EAA4C,MAAM,SAAS,CAAC;AAEvF,sBAAsB;AACtB,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,2CAA2C;IAC3C,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,GAA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.js";
|
|
3
|
+
import { oklchToHex, toOklch } from "./oklch.js";
|
|
4
|
+
import { lazyPalettes, stockPalette, trustPalette } from "./theme.js";
|
|
5
|
+
const registry = new Map();
|
|
6
|
+
function registerRecipe(recipe) {
|
|
7
|
+
if (!recipe.name) throw new G9Error('theme-recipe-name', 'A recipe needs a name.');
|
|
8
|
+
registry.set(recipe.name, recipe);
|
|
9
|
+
}
|
|
10
|
+
function getRecipe(name) {
|
|
11
|
+
const recipe = registry.get(name);
|
|
12
|
+
if (!recipe) throw new G9Error('theme-unknown-recipe', `No theme recipe "${name}". Known: ${[
|
|
13
|
+
...registry.keys()
|
|
14
|
+
].join(', ')}.`);
|
|
15
|
+
return recipe;
|
|
16
|
+
}
|
|
17
|
+
const listRecipes = ()=>[
|
|
18
|
+
...registry.values()
|
|
19
|
+
];
|
|
20
|
+
const MADE = new Map();
|
|
21
|
+
const MADE_LIMIT = 24;
|
|
22
|
+
function recipePalette(name, brand, scheme) {
|
|
23
|
+
const recipe = getRecipe(name);
|
|
24
|
+
const key = `${name}|${scheme}|${JSON.stringify(brand)}`;
|
|
25
|
+
const hit = MADE.get(key);
|
|
26
|
+
if (hit) {
|
|
27
|
+
MADE.delete(key);
|
|
28
|
+
MADE.set(key, hit);
|
|
29
|
+
return hit;
|
|
30
|
+
}
|
|
31
|
+
const made = recipe.palette(brand, scheme);
|
|
32
|
+
const p = trustPalette(Object.isFrozen(made) ? made : Object.freeze({
|
|
33
|
+
...made
|
|
34
|
+
}));
|
|
35
|
+
MADE.set(key, p);
|
|
36
|
+
if (MADE.size > MADE_LIMIT) MADE.delete(MADE.keys().next().value);
|
|
37
|
+
return p;
|
|
38
|
+
}
|
|
39
|
+
function recipePalettes(name, brand) {
|
|
40
|
+
getRecipe(name);
|
|
41
|
+
const p = lazyPalettes((scheme)=>recipePalette(name, brand, scheme));
|
|
42
|
+
return p;
|
|
43
|
+
}
|
|
44
|
+
function brandRecipe(name, options, extra = {}) {
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
...extra,
|
|
48
|
+
palette: (brand, scheme)=>createBrandPalette(brand, scheme, options)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function designedRecipe(name, designed, options = {}) {
|
|
52
|
+
const { tint, contrast, keepBrand, ...extra } = options;
|
|
53
|
+
const brandOptions = {
|
|
54
|
+
...void 0 !== tint ? {
|
|
55
|
+
tint
|
|
56
|
+
} : {},
|
|
57
|
+
...void 0 !== contrast ? {
|
|
58
|
+
contrast
|
|
59
|
+
} : {},
|
|
60
|
+
...void 0 !== keepBrand ? {
|
|
61
|
+
keepBrand
|
|
62
|
+
} : {}
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
name,
|
|
66
|
+
...extra,
|
|
67
|
+
palette (brand, scheme) {
|
|
68
|
+
const base = createBrandPalette(brand, scheme, brandOptions);
|
|
69
|
+
const over = designed[scheme];
|
|
70
|
+
const next = {
|
|
71
|
+
...base
|
|
72
|
+
};
|
|
73
|
+
for (const [token, value] of Object.entries(over))if (void 0 !== value) next[token] = value;
|
|
74
|
+
return Object.freeze(next);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
registerRecipe({
|
|
79
|
+
name: 'stock',
|
|
80
|
+
title: {
|
|
81
|
+
en: 'Stock',
|
|
82
|
+
fa: 'پیشفرض'
|
|
83
|
+
},
|
|
84
|
+
palette: (_b, scheme)=>stockPalette(scheme)
|
|
85
|
+
});
|
|
86
|
+
registerRecipe(brandRecipe('tonal', {
|
|
87
|
+
tint: 0.35
|
|
88
|
+
}, {
|
|
89
|
+
title: {
|
|
90
|
+
en: 'Tonal',
|
|
91
|
+
fa: 'همرنگ'
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
registerRecipe(brandRecipe('neutral', {
|
|
95
|
+
tint: 0
|
|
96
|
+
}, {
|
|
97
|
+
title: {
|
|
98
|
+
en: 'Neutral',
|
|
99
|
+
fa: 'خنثی'
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
registerRecipe(brandRecipe('tinted', {
|
|
103
|
+
tint: 1
|
|
104
|
+
}, {
|
|
105
|
+
title: {
|
|
106
|
+
en: 'Tinted',
|
|
107
|
+
fa: 'رنگین'
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
110
|
+
registerRecipe(brandRecipe('contrast', {
|
|
111
|
+
tint: 0.2,
|
|
112
|
+
contrast: 'AAA',
|
|
113
|
+
keepBrand: false
|
|
114
|
+
}, {
|
|
115
|
+
title: {
|
|
116
|
+
en: 'High contrast',
|
|
117
|
+
fa: 'کنتراست بالا'
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
registerRecipe({
|
|
121
|
+
name: 'midnight',
|
|
122
|
+
title: {
|
|
123
|
+
en: 'Midnight',
|
|
124
|
+
fa: 'نیمهشب'
|
|
125
|
+
},
|
|
126
|
+
defaultScheme: 'dark',
|
|
127
|
+
palette (brand, scheme) {
|
|
128
|
+
const base = createBrandPalette(brand, scheme, {
|
|
129
|
+
tint: 1
|
|
130
|
+
});
|
|
131
|
+
if ('light' === scheme) return base;
|
|
132
|
+
const { h } = toOklch(brand.primary);
|
|
133
|
+
const deep = (l)=>oklchToHex({
|
|
134
|
+
l,
|
|
135
|
+
c: 0.035,
|
|
136
|
+
h
|
|
137
|
+
});
|
|
138
|
+
return Object.freeze({
|
|
139
|
+
...base,
|
|
140
|
+
Background: deep(0.14),
|
|
141
|
+
SurfaceContainerLowest: deep(0.12),
|
|
142
|
+
SurfaceDim: deep(0.14),
|
|
143
|
+
Surface: deep(0.19),
|
|
144
|
+
CardBackground: deep(0.19),
|
|
145
|
+
InputBackground: deep(0.19),
|
|
146
|
+
SurfaceContainerLow: deep(0.21),
|
|
147
|
+
SurfaceContainer: deep(0.23),
|
|
148
|
+
SurfaceVariant: deep(0.25),
|
|
149
|
+
SurfaceContainerHigh: deep(0.27),
|
|
150
|
+
SurfaceContainerHighest: deep(0.3)
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
export { brandRecipe, designedRecipe, getRecipe, listRecipes, recipePalette, recipePalettes, registerRecipe };
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=recipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme/recipe.js","sources":["../../src/theme/recipe.ts"],"sourcesContent":["// Theme recipes: named ways of turning a brand into palettes (and optionally a shape). The library ships a few; an app\n// registers its own (ShopManager's store templates `tazeh`, `gozar`, `abgineh`…, G9Hub's built-in themes) and then\n// every control follows the chosen recipe through the theme store. A recipe is pure data → palette, so it also runs on\n// a server or in the Svelte web app (foundation has no Lynx dependency).\nimport { G9Error } from '../errors';\nimport type { G9ColorToken, G9PaletteValues } from '../tokens/generated/palettes';\nimport type { G9ShapeSet } from '../tokens/shape';\nimport { createBrandPalette, type G9BrandColors, type G9BrandPaletteOptions } from './brand';\nimport { oklchToHex, toOklch } from './oklch';\nimport type { G9PaletteOverrides } from './theme';\nimport { type G9ColorScheme, lazyPalettes, stockPalette, trustPalette } from './theme';\n\n/** A named recipe. */\nexport interface G9ThemeRecipe {\n readonly name: string;\n /** Human name per language (`{ fa: 'تازه', en: 'Fresh' }`). */\n readonly title?: Readonly<Record<string, string>>;\n /** The palette of `scheme` for `brand`. */\n palette(brand: G9BrandColors, scheme: G9ColorScheme): G9PaletteValues;\n /** The recipe's shape (radii, type roles, control heights); default: the library's. */\n readonly shape?: Partial<G9ShapeSet>;\n /** The scheme the recipe looks best in when the user has not chosen (`'light'` default). */\n readonly defaultScheme?: G9ColorScheme;\n}\n\nconst registry = new Map<string, G9ThemeRecipe>();\n\n/** Adds or replaces a recipe. */\nexport function registerRecipe(recipe: G9ThemeRecipe): void {\n if (!recipe.name) throw new G9Error('theme-recipe-name', 'A recipe needs a name.');\n registry.set(recipe.name, recipe);\n}\n\n/** The recipe called `name`. @throws {G9Error} `theme-unknown-recipe`. */\nexport function getRecipe(name: string): G9ThemeRecipe {\n const recipe = registry.get(name);\n if (!recipe) {\n throw new G9Error('theme-unknown-recipe', `No theme recipe \"${name}\". Known: ${[...registry.keys()].join(', ')}.`);\n }\n return recipe;\n}\n\n/** Every registered recipe, in registration order. */\nexport const listRecipes = (): readonly G9ThemeRecipe[] => [...registry.values()];\n\n// The palettes recipes made, by recipe, scheme and brand: switching back to a theme costs nothing.\nconst MADE = new Map<string, G9PaletteValues>();\nconst MADE_LIMIT = 24;\n\n/** One scheme of a recipe for a brand (cached). */\nexport function recipePalette(name: string, brand: G9BrandColors, scheme: G9ColorScheme): G9PaletteValues {\n const recipe = getRecipe(name);\n const key = `${name}|${scheme}|${JSON.stringify(brand)}`;\n const hit = MADE.get(key);\n if (hit) {\n // most recently used last\n MADE.delete(key);\n MADE.set(key, hit);\n return hit;\n }\n const made = recipe.palette(brand, scheme);\n const p = trustPalette(Object.isFrozen(made) ? made : Object.freeze({ ...made }));\n MADE.set(key, p);\n if (MADE.size > MADE_LIMIT) MADE.delete(MADE.keys().next().value as string);\n return p;\n}\n\n/**\n * The palettes a recipe makes for a brand, both schemes (a theme store's `palettes` option): each scheme is built when\n * first read and cached, so the store only builds the one it paints.\n */\nexport function recipePalettes(name: string, brand: G9BrandColors) {\n getRecipe(name);\n const p = lazyPalettes((scheme) => recipePalette(name, brand, scheme));\n return p as { readonly light: G9PaletteValues; readonly dark: G9PaletteValues };\n}\n\n/** A recipe built on the brand generator with fixed options. */\nexport function brandRecipe(\n name: string,\n options: G9BrandPaletteOptions,\n extra: Partial<G9ThemeRecipe> = {},\n): G9ThemeRecipe {\n return { name, ...extra, palette: (brand, scheme) => createBrandPalette(brand, scheme, options) };\n}\n\n/**\n * A designer's recipe: hand-picked tokens per scheme over a generated base (ShopManager's `designedRecipe`). Tokens not\n * listed come from the brand generator, so a designed theme stays complete when the token set grows.\n */\nexport function designedRecipe(\n name: string,\n designed: { readonly light: G9PaletteOverrides; readonly dark: G9PaletteOverrides },\n options: G9BrandPaletteOptions & Partial<Omit<G9ThemeRecipe, 'name' | 'palette'>> = {},\n): G9ThemeRecipe {\n const { tint, contrast, keepBrand, ...extra } = options;\n const brandOptions: G9BrandPaletteOptions = {\n ...(tint !== undefined ? { tint } : {}),\n ...(contrast !== undefined ? { contrast } : {}),\n ...(keepBrand !== undefined ? { keepBrand } : {}),\n };\n return {\n name,\n ...extra,\n palette(brand, scheme) {\n const base = createBrandPalette(brand, scheme, brandOptions);\n const over = designed[scheme];\n const next: Record<string, string> = { ...base };\n for (const [token, value] of Object.entries(over)) if (value !== undefined) next[token as G9ColorToken] = value;\n return Object.freeze(next) as unknown as G9PaletteValues;\n },\n };\n}\n\n// ---- built-in recipes -------------------------------------------------------------------------------------------------\n\n/** The stock MAUI palettes, whatever the brand (the 1.x look). */\nregisterRecipe({ name: 'stock', title: { en: 'Stock', fa: 'پیشفرض' }, palette: (_b, scheme) => stockPalette(scheme) });\n/** The brand generator with balanced greys. */\nregisterRecipe(brandRecipe('tonal', { tint: 0.35 }, { title: { en: 'Tonal', fa: 'همرنگ' } }));\n/** Pure greys, the brand only where it acts (a calm, editorial look). */\nregisterRecipe(brandRecipe('neutral', { tint: 0 }, { title: { en: 'Neutral', fa: 'خنثی' } }));\n/** Surfaces washed in the brand hue (a playful, branded look). */\nregisterRecipe(brandRecipe('tinted', { tint: 1 }, { title: { en: 'Tinted', fa: 'رنگین' } }));\n/** AAA contrast everywhere (accessibility first). */\nregisterRecipe(\n brandRecipe(\n 'contrast',\n { tint: 0.2, contrast: 'AAA', keepBrand: false },\n { title: { en: 'High contrast', fa: 'کنتراست بالا' } },\n ),\n);\n/** A dark-first look: deep brand-tinted surfaces, brand fills lightened (Riskara's \"mission control\"). */\nregisterRecipe({\n name: 'midnight',\n title: { en: 'Midnight', fa: 'نیمهشب' },\n defaultScheme: 'dark',\n palette(brand, scheme) {\n const base = createBrandPalette(brand, scheme, { tint: 1 });\n if (scheme === 'light') return base;\n const { h } = toOklch(brand.primary);\n const deep = (l: number) => oklchToHex({ l, c: 0.035, h });\n return Object.freeze({\n ...base,\n Background: deep(0.14),\n SurfaceContainerLowest: deep(0.12),\n SurfaceDim: deep(0.14),\n Surface: deep(0.19),\n CardBackground: deep(0.19),\n InputBackground: deep(0.19),\n SurfaceContainerLow: deep(0.21),\n SurfaceContainer: deep(0.23),\n SurfaceVariant: deep(0.25),\n SurfaceContainerHigh: deep(0.27),\n SurfaceContainerHighest: deep(0.3),\n }) as G9PaletteValues;\n },\n});\n"],"names":["registry","Map","registerRecipe","recipe","G9Error","getRecipe","name","listRecipes","MADE","MADE_LIMIT","recipePalette","brand","scheme","key","JSON","hit","made","p","trustPalette","Object","recipePalettes","lazyPalettes","brandRecipe","options","extra","createBrandPalette","designedRecipe","designed","tint","contrast","keepBrand","brandOptions","undefined","base","over","next","token","value","_b","stockPalette","h","toOklch","deep","l","oklchToHex"],"mappings":";;;;AAyBA,MAAMA,WAAW,IAAIC;AAGd,SAASC,eAAeC,MAAqB;IAClD,IAAI,CAACA,OAAO,IAAI,EAAE,MAAM,IAAIC,QAAQ,qBAAqB;IACzDJ,SAAS,GAAG,CAACG,OAAO,IAAI,EAAEA;AAC5B;AAGO,SAASE,UAAUC,IAAY;IACpC,MAAMH,SAASH,SAAS,GAAG,CAACM;IAC5B,IAAI,CAACH,QACH,MAAM,IAAIC,QAAQ,wBAAwB,CAAC,iBAAiB,EAAEE,KAAK,UAAU,EAAE;WAAIN,SAAS,IAAI;KAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEnH,OAAOG;AACT;AAGO,MAAMI,cAAc,IAAgC;WAAIP,SAAS,MAAM;KAAG;AAGjF,MAAMQ,OAAO,IAAIP;AACjB,MAAMQ,aAAa;AAGZ,SAASC,cAAcJ,IAAY,EAAEK,KAAoB,EAAEC,MAAqB;IACrF,MAAMT,SAASE,UAAUC;IACzB,MAAMO,MAAM,GAAGP,KAAK,CAAC,EAAEM,OAAO,CAAC,EAAEE,KAAK,SAAS,CAACH,QAAQ;IACxD,MAAMI,MAAMP,KAAK,GAA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B,YAAYA,KAAK;YACjB,SAASA,KAAK;YACd,gBAAgBA,KAAK;YACrB,iBAAiBA,KAAK;YACtB,qBAAqBA,KAAK;YAC1B,kBAAkBA,KAAK;YACvB,gBAAgBA,KAAK;YACrB,sBAAsBA,KAAK;YAC3B,yBAAyBA,KAAK;QAChC;IACF;AACF"}
|
package/dist/theme/theme.d.ts
CHANGED
|
@@ -5,8 +5,21 @@ export declare const G9ThemeMode: {
|
|
|
5
5
|
readonly System: "system";
|
|
6
6
|
readonly Light: "light";
|
|
7
7
|
readonly Dark: "dark";
|
|
8
|
+
readonly Scheduled: "scheduled";
|
|
8
9
|
};
|
|
9
10
|
export type G9ThemeMode = (typeof G9ThemeMode)[keyof typeof G9ThemeMode];
|
|
11
|
+
/**
|
|
12
|
+
* When `'scheduled'` paints dark: from `darkFrom` (hour, 0–23) to `darkTo` (exclusive), across midnight when
|
|
13
|
+
* `darkFrom > darkTo`. Default 18 → 7 (Riskara's evening theme).
|
|
14
|
+
*/
|
|
15
|
+
export interface G9ThemeSchedule {
|
|
16
|
+
readonly darkFrom: number;
|
|
17
|
+
readonly darkTo: number;
|
|
18
|
+
}
|
|
19
|
+
/** The default dark span of the scheduled mode: from 18:00 to 07:00. */
|
|
20
|
+
export declare const g9DefaultThemeSchedule: G9ThemeSchedule;
|
|
21
|
+
/** True when `hour` falls in the schedule's dark span. */
|
|
22
|
+
export declare function isScheduledDark(hour: number, schedule?: G9ThemeSchedule): boolean;
|
|
10
23
|
/** The scheme actually painted. */
|
|
11
24
|
export declare const G9ColorScheme: {
|
|
12
25
|
readonly Light: "light";
|
|
@@ -32,6 +45,10 @@ export interface G9ThemeOptions {
|
|
|
32
45
|
readonly palettes?: G9CustomPalettes;
|
|
33
46
|
/** Last layer, applied whatever the scheme (e.g. a brand colour). */
|
|
34
47
|
readonly overrides?: G9PaletteOverrides;
|
|
48
|
+
/** The local hour (0–23) for `'scheduled'`. Default 12 (light). The provider keeps it current. */
|
|
49
|
+
readonly hour?: number;
|
|
50
|
+
/** The dark span for `'scheduled'`. */
|
|
51
|
+
readonly schedule?: G9ThemeSchedule;
|
|
35
52
|
}
|
|
36
53
|
/** A resolved theme: what is painted and why. Frozen. */
|
|
37
54
|
export interface G9ResolvedTheme {
|
|
@@ -40,10 +57,20 @@ export interface G9ResolvedTheme {
|
|
|
40
57
|
readonly scheme: G9ColorScheme;
|
|
41
58
|
readonly palette: G9PaletteValues;
|
|
42
59
|
}
|
|
43
|
-
/**
|
|
44
|
-
|
|
60
|
+
/**
|
|
61
|
+
* `'light'`/`'dark'` pick that scheme; `'system'` follows `systemScheme` (MAUI `G9Theme.ApplyCurrent`);
|
|
62
|
+
* `'scheduled'` is dark during the schedule's span at `hour`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveColorScheme(mode: G9ThemeMode, systemScheme: G9ColorScheme, hour?: number, schedule?: G9ThemeSchedule): G9ColorScheme;
|
|
45
65
|
/** The stock palette of a scheme (MAUI `G9ThemeLight` / `G9ThemeDark`). */
|
|
46
66
|
export declare const stockPalette: (scheme: G9ColorScheme) => G9PaletteValues;
|
|
67
|
+
/** Marks a complete, generated palette as valid (internal: recipes and the brand generator). */
|
|
68
|
+
export declare function trustPalette<T extends G9PaletteValues>(palette: T): T;
|
|
69
|
+
/**
|
|
70
|
+
* Palettes per scheme, each built on first read and kept (a recipe's dark palette costs nothing until the app turns
|
|
71
|
+
* dark). Internal: `recipePalettes`, `applyThemeDefinition`.
|
|
72
|
+
*/
|
|
73
|
+
export declare function lazyPalettes(build: (scheme: G9ColorScheme) => G9PaletteValues): G9CustomPalettes;
|
|
47
74
|
/**
|
|
48
75
|
* Validates a complete palette (every token, every value a readable colour) and returns a frozen copy in token order.
|
|
49
76
|
* @throws {G9Error} `theme-incomplete-palette` / `theme-unknown-token`, or {@link G9ColorFormatError}.
|
|
@@ -73,6 +100,20 @@ export interface G9ThemeStore {
|
|
|
73
100
|
setPalettes(palettes: G9CustomPalettes | undefined): void;
|
|
74
101
|
/** Replace the override layer. */
|
|
75
102
|
setOverrides(overrides: G9PaletteOverrides | undefined): void;
|
|
103
|
+
/**
|
|
104
|
+
* The live-design layer, above everything (G9AppPilot `design.set` through {@link createDesignRegistry}): a
|
|
105
|
+
* designer's change on the running app that never touches the app's own palettes or overrides.
|
|
106
|
+
*/
|
|
107
|
+
setDesignOverrides(overrides: G9PaletteOverrides | undefined): void;
|
|
108
|
+
/** The local hour (0–23), for the `'scheduled'` mode; repaints only when it crosses the schedule. */
|
|
109
|
+
setHour(hour: number): void;
|
|
110
|
+
/** The dark span of the `'scheduled'` mode. */
|
|
111
|
+
setSchedule(schedule: G9ThemeSchedule): void;
|
|
112
|
+
/** The current hour and schedule (what `'scheduled'` reads). */
|
|
113
|
+
getSchedule(): {
|
|
114
|
+
readonly hour: number;
|
|
115
|
+
readonly schedule: G9ThemeSchedule;
|
|
116
|
+
};
|
|
76
117
|
/**
|
|
77
118
|
* Paint `values` as the complete palette (MAUI `G9Palette.Apply`) until the next mode or scheme change re-resolves
|
|
78
119
|
* the theme, as the next `G9Theme.ApplyCurrent` did. The override layer still applies on top.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EAIrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,SAAS,CAAC;AAEnD,oGAAoG;AACpG,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EAIrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,OAAO,EAAc,MAAM,SAAS,CAAC;AAEnD,oGAAoG;AACpG,eAAO,MAAM,WAAW;;;;;CAAsF,CAAC;AAC/G,MAAM,MAAM,WAA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AQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1D,kCAAkC;IAClC,YAAY,CAAC,SAAS,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAAC;IAC9D;;;OAGG;IACH,kBAAkB,CAAC,SAAS,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAAC;IACpE,qGAAqG;IACrG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,+CAA+C;IAC/C,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC7C,gEAAgE;IAChE,WAAW,IAAI;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;KAAE,CAAC;IAC7E;;;OAGG;IACH,KAAK,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACrC,iGAAiG;IACjG,UAAU,IAAI,IAAI,CAAC;IACnB,gGAAgG;IAChG,QAAQ,IAAI,IAAI,CAAC;CAClB;AAmCD,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,cAAmB,GAAG,YAAY,CA8G3E"}
|
package/dist/theme/theme.js
CHANGED
|
@@ -4,8 +4,18 @@ import { parseColor } from "./color.js";
|
|
|
4
4
|
const G9ThemeMode = {
|
|
5
5
|
System: 'system',
|
|
6
6
|
Light: 'light',
|
|
7
|
-
Dark: 'dark'
|
|
7
|
+
Dark: 'dark',
|
|
8
|
+
Scheduled: 'scheduled'
|
|
8
9
|
};
|
|
10
|
+
const g9DefaultThemeSchedule = Object.freeze({
|
|
11
|
+
darkFrom: 18,
|
|
12
|
+
darkTo: 7
|
|
13
|
+
});
|
|
14
|
+
function isScheduledDark(hour, schedule = g9DefaultThemeSchedule) {
|
|
15
|
+
const { darkFrom, darkTo } = schedule;
|
|
16
|
+
if (darkFrom === darkTo) return false;
|
|
17
|
+
return darkFrom < darkTo ? hour >= darkFrom && hour < darkTo : hour >= darkFrom || hour < darkTo;
|
|
18
|
+
}
|
|
9
19
|
const G9ColorScheme = {
|
|
10
20
|
Light: 'light',
|
|
11
21
|
Dark: 'dark'
|
|
@@ -13,7 +23,8 @@ const G9ColorScheme = {
|
|
|
13
23
|
const MODES = [
|
|
14
24
|
'system',
|
|
15
25
|
'light',
|
|
16
|
-
'dark'
|
|
26
|
+
'dark',
|
|
27
|
+
'scheduled'
|
|
17
28
|
];
|
|
18
29
|
const SCHEMES = [
|
|
19
30
|
'light',
|
|
@@ -22,15 +33,44 @@ const SCHEMES = [
|
|
|
22
33
|
function check(kind, value) {
|
|
23
34
|
if (!('mode' === kind ? MODES : SCHEMES).includes(value)) throw new G9Error(`theme-invalid-${kind}`, `"${value}" is not a theme ${kind}.`);
|
|
24
35
|
}
|
|
25
|
-
function resolveColorScheme(mode, systemScheme) {
|
|
36
|
+
function resolveColorScheme(mode, systemScheme, hour = 12, schedule = g9DefaultThemeSchedule) {
|
|
26
37
|
check('mode', mode);
|
|
27
38
|
check('scheme', systemScheme);
|
|
39
|
+
if ('scheduled' === mode) return isScheduledDark(hour, schedule) ? 'dark' : 'light';
|
|
28
40
|
return 'system' === mode ? systemScheme : mode;
|
|
29
41
|
}
|
|
30
42
|
const stockPalette = (scheme)=>'dark' === scheme ? g9DarkPalette : g9LightPalette;
|
|
31
43
|
const known = new Set(g9ColorTokens);
|
|
44
|
+
const trusted = new WeakSet();
|
|
45
|
+
const lazy = new WeakSet();
|
|
46
|
+
function trustPalette(palette) {
|
|
47
|
+
trusted.add(palette);
|
|
48
|
+
return palette;
|
|
49
|
+
}
|
|
50
|
+
function lazyPalettes(build) {
|
|
51
|
+
const made = {};
|
|
52
|
+
const get = (scheme)=>{
|
|
53
|
+
const hit = made[scheme];
|
|
54
|
+
if (hit) return hit;
|
|
55
|
+
const p = trustPalette(build(scheme));
|
|
56
|
+
made[scheme] = p;
|
|
57
|
+
return p;
|
|
58
|
+
};
|
|
59
|
+
const out = {};
|
|
60
|
+
Object.defineProperty(out, 'light', {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: ()=>get('light')
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(out, 'dark', {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: ()=>get('dark')
|
|
67
|
+
});
|
|
68
|
+
lazy.add(out);
|
|
69
|
+
return Object.freeze(out);
|
|
70
|
+
}
|
|
32
71
|
function theme_layer(base, overrides) {
|
|
33
72
|
if (!overrides) return base;
|
|
73
|
+
if (trusted.has(overrides)) return overrides;
|
|
34
74
|
const next = {
|
|
35
75
|
...base
|
|
36
76
|
};
|
|
@@ -53,9 +93,9 @@ function resolveTheme(options = {}) {
|
|
|
53
93
|
var _options_palettes, _options_palettes1;
|
|
54
94
|
const mode = null != (_options_mode = options.mode) ? _options_mode : 'system';
|
|
55
95
|
const systemScheme = null != (_options_systemScheme = options.systemScheme) ? _options_systemScheme : 'light';
|
|
56
|
-
const scheme = resolveColorScheme(mode, systemScheme);
|
|
96
|
+
const scheme = resolveColorScheme(mode, systemScheme, options.hour, options.schedule);
|
|
57
97
|
const inactive = 'dark' === scheme ? 'light' : 'dark';
|
|
58
|
-
theme_layer(stockPalette(inactive), null == (_options_palettes = options.palettes) ? void 0 : _options_palettes[inactive]);
|
|
98
|
+
if (!(options.palettes && lazy.has(options.palettes))) theme_layer(stockPalette(inactive), null == (_options_palettes = options.palettes) ? void 0 : _options_palettes[inactive]);
|
|
59
99
|
const custom = theme_layer(stockPalette(scheme), null == (_options_palettes1 = options.palettes) ? void 0 : _options_palettes1[scheme]);
|
|
60
100
|
const palette = Object.freeze(theme_layer(custom, options.overrides));
|
|
61
101
|
return Object.freeze({
|
|
@@ -73,6 +113,8 @@ function resolveState(state) {
|
|
|
73
113
|
const next = resolveTheme({
|
|
74
114
|
mode: state.mode,
|
|
75
115
|
systemScheme: state.systemScheme,
|
|
116
|
+
hour: state.hour,
|
|
117
|
+
schedule: state.schedule,
|
|
76
118
|
...palettes ? {
|
|
77
119
|
palettes
|
|
78
120
|
} : {},
|
|
@@ -80,19 +122,26 @@ function resolveState(state) {
|
|
|
80
122
|
overrides
|
|
81
123
|
} : {}
|
|
82
124
|
});
|
|
83
|
-
|
|
125
|
+
const painted = state.applied ? Object.freeze({
|
|
84
126
|
...next,
|
|
85
127
|
palette: Object.freeze(theme_layer(state.applied, overrides))
|
|
86
128
|
}) : next;
|
|
129
|
+
return state.design ? Object.freeze({
|
|
130
|
+
...painted,
|
|
131
|
+
palette: Object.freeze(theme_layer(painted.palette, state.design))
|
|
132
|
+
}) : painted;
|
|
87
133
|
}
|
|
88
134
|
function createThemeStore(options = {}) {
|
|
89
|
-
var _options_mode, _options_systemScheme;
|
|
135
|
+
var _options_mode, _options_systemScheme, _options_hour, _options_schedule;
|
|
90
136
|
let state = {
|
|
91
137
|
mode: null != (_options_mode = options.mode) ? _options_mode : 'system',
|
|
92
138
|
systemScheme: null != (_options_systemScheme = options.systemScheme) ? _options_systemScheme : 'light',
|
|
93
139
|
palettes: options.palettes,
|
|
94
140
|
overrides: options.overrides,
|
|
95
|
-
applied: void 0
|
|
141
|
+
applied: void 0,
|
|
142
|
+
hour: null != (_options_hour = options.hour) ? _options_hour : 12,
|
|
143
|
+
schedule: null != (_options_schedule = options.schedule) ? _options_schedule : g9DefaultThemeSchedule,
|
|
144
|
+
design: void 0
|
|
96
145
|
};
|
|
97
146
|
let snapshot = resolveState(state);
|
|
98
147
|
let notified = snapshot;
|
|
@@ -170,6 +219,33 @@ function createThemeStore(options = {}) {
|
|
|
170
219
|
overrides
|
|
171
220
|
});
|
|
172
221
|
},
|
|
222
|
+
setDesignOverrides (design) {
|
|
223
|
+
commit({
|
|
224
|
+
design
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
setHour (hour) {
|
|
228
|
+
if (!Number.isInteger(hour) || hour < 0 || hour > 23) throw new G9Error('theme-invalid-hour', `${hour} is not an hour (0–23).`);
|
|
229
|
+
const before = isScheduledDark(state.hour, state.schedule);
|
|
230
|
+
const crosses = 'scheduled' === state.mode && isScheduledDark(hour, state.schedule) !== before;
|
|
231
|
+
commit(crosses ? {
|
|
232
|
+
hour,
|
|
233
|
+
applied: void 0
|
|
234
|
+
} : {
|
|
235
|
+
hour
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
setSchedule (schedule) {
|
|
239
|
+
commit({
|
|
240
|
+
schedule: Object.freeze({
|
|
241
|
+
...schedule
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
getSchedule: ()=>({
|
|
246
|
+
hour: state.hour,
|
|
247
|
+
schedule: state.schedule
|
|
248
|
+
}),
|
|
173
249
|
apply (values) {
|
|
174
250
|
commit({
|
|
175
251
|
applied: createPalette(values)
|
|
@@ -185,6 +261,6 @@ function createThemeStore(options = {}) {
|
|
|
185
261
|
}
|
|
186
262
|
};
|
|
187
263
|
}
|
|
188
|
-
export { G9ColorScheme, G9ThemeMode, createPalette, createThemeStore, resolveColorScheme, resolveTheme, stockPalette };
|
|
264
|
+
export { G9ColorScheme, G9ThemeMode, createPalette, createThemeStore, g9DefaultThemeSchedule, isScheduledDark, lazyPalettes, resolveColorScheme, resolveTheme, stockPalette, trustPalette };
|
|
189
265
|
|
|
190
266
|
//# sourceMappingURL=theme.js.map
|
package/dist/theme/theme.js.map
CHANGED
|
@@ -1 +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,MAAM,IAAIC,OAAO,OAAO,CAACJ,WAC1C,IAAIG,AAAUE,WAAVF;QACJ,IAAI,CAACR,MAAM,GAAG,CAACO,QAAQ,MAAM,IA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ACjBA,SAAS;YACTM;QACF;IACF;AACF"}
|
|
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', Scheduled: 'scheduled' } as const;\nexport type G9ThemeMode = (typeof G9ThemeMode)[keyof typeof G9ThemeMode];\n\n/**\n * When `'scheduled'` paints dark: from `darkFrom` (hour, 0–23) to `darkTo` (exclusive), across midnight when\n * `darkFrom > darkTo`. Default 18 → 7 (Riskara's evening theme).\n */\nexport interface G9ThemeSchedule {\n readonly darkFrom: number;\n readonly darkTo: number;\n}\n\n/** The default dark span of the scheduled mode: from 18:00 to 07:00. */\nexport const g9DefaultThemeSchedule: G9ThemeSchedule = Object.freeze({ darkFrom: 18, darkTo: 7 });\n\n/** True when `hour` falls in the schedule's dark span. */\nexport function isScheduledDark(hour: number, schedule: G9ThemeSchedule = g9DefaultThemeSchedule): boolean {\n const { darkFrom, darkTo } = schedule;\n if (darkFrom === darkTo) return false;\n return darkFrom < darkTo ? hour >= darkFrom && hour < darkTo : hour >= darkFrom || hour < darkTo;\n}\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 /** The local hour (0–23) for `'scheduled'`. Default 12 (light). The provider keeps it current. */\n readonly hour?: number;\n /** The dark span for `'scheduled'`. */\n readonly schedule?: G9ThemeSchedule;\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', 'scheduled'];\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/**\n * `'light'`/`'dark'` pick that scheme; `'system'` follows `systemScheme` (MAUI `G9Theme.ApplyCurrent`);\n * `'scheduled'` is dark during the schedule's span at `hour`.\n */\nexport function resolveColorScheme(\n mode: G9ThemeMode,\n systemScheme: G9ColorScheme,\n hour = 12,\n schedule: G9ThemeSchedule = g9DefaultThemeSchedule,\n): G9ColorScheme {\n check('mode', mode);\n check('scheme', systemScheme);\n if (mode === 'scheduled') return isScheduledDark(hour, schedule) ? 'dark' : 'light';\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\n/** Complete palettes the library made itself (recipes, the brand generator): already valid, never re-parsed. */\nconst trusted = new WeakSet<object>();\n/** `palettes` objects whose schemes are built on first read (recipes): the inactive one is not built to be checked. */\nconst lazy = new WeakSet<object>();\n\n/** Marks a complete, generated palette as valid (internal: recipes and the brand generator). */\nexport function trustPalette<T extends G9PaletteValues>(palette: T): T {\n trusted.add(palette);\n return palette;\n}\n\n/**\n * Palettes per scheme, each built on first read and kept (a recipe's dark palette costs nothing until the app turns\n * dark). Internal: `recipePalettes`, `applyThemeDefinition`.\n */\nexport function lazyPalettes(build: (scheme: G9ColorScheme) => G9PaletteValues): G9CustomPalettes {\n const made: Partial<Record<G9ColorScheme, G9PaletteValues>> = {};\n const get = (scheme: G9ColorScheme) => {\n const hit = made[scheme];\n if (hit) return hit;\n const p = trustPalette(build(scheme));\n made[scheme] = p;\n return p;\n };\n const out = {} as G9CustomPalettes;\n Object.defineProperty(out, 'light', { enumerable: true, get: () => get('light') });\n Object.defineProperty(out, 'dark', { enumerable: true, get: () => get('dark') });\n lazy.add(out);\n return Object.freeze(out);\n}\n\nfunction layer(base: G9PaletteValues, overrides: G9PaletteOverrides | undefined): G9PaletteValues {\n if (!overrides) return base;\n if (trusted.has(overrides)) return overrides as G9PaletteValues;\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, options.hour, options.schedule);\n // Validate the inactive scheme's palette too, so a typo surfaces now rather than on the next theme switch — unless the\n // palettes are a recipe's, built on demand and valid by construction.\n const inactive: G9ColorScheme = scheme === 'dark' ? 'light' : 'dark';\n if (!(options.palettes && lazy.has(options.palettes))) 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 * The live-design layer, above everything (G9AppPilot `design.set` through {@link createDesignRegistry}): a\n * designer's change on the running app that never touches the app's own palettes or overrides.\n */\n setDesignOverrides(overrides: G9PaletteOverrides | undefined): void;\n /** The local hour (0–23), for the `'scheduled'` mode; repaints only when it crosses the schedule. */\n setHour(hour: number): void;\n /** The dark span of the `'scheduled'` mode. */\n setSchedule(schedule: G9ThemeSchedule): void;\n /** The current hour and schedule (what `'scheduled'` reads). */\n getSchedule(): { readonly hour: number; readonly schedule: G9ThemeSchedule };\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 readonly hour: number;\n readonly schedule: G9ThemeSchedule;\n readonly design: G9PaletteOverrides | 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 hour: state.hour,\n schedule: state.schedule,\n ...(palettes ? { palettes } : {}),\n ...(overrides ? { overrides } : {}),\n });\n const painted = state.applied\n ? Object.freeze({ ...next, palette: Object.freeze(layer(state.applied, overrides)) })\n : next;\n return state.design\n ? Object.freeze({ ...painted, palette: Object.freeze(layer(painted.palette, state.design)) })\n : painted;\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 hour: options.hour ?? 12,\n schedule: options.schedule ?? g9DefaultThemeSchedule,\n design: 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 setDesignOverrides(design) {\n commit({ design });\n },\n setHour(hour) {\n if (!Number.isInteger(hour) || hour < 0 || hour > 23)\n throw new G9Error('theme-invalid-hour', `${hour} is not an hour (0–23).`);\n const before = isScheduledDark(state.hour, state.schedule);\n const crosses = state.mode === 'scheduled' && isScheduledDark(hour, state.schedule) !== before;\n commit(crosses ? { hour, applied: undefined } : { hour });\n },\n setSchedule(schedule) {\n commit({ schedule: Object.freeze({ ...schedule }) });\n },\n getSchedule: () => ({ hour: state.hour, schedule: state.schedule }),\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","g9DefaultThemeSchedule","Object","isScheduledDark","hour","schedule","darkFrom","darkTo","G9ColorScheme","MODES","SCHEMES","check","kind","value","G9Error","resolveColorScheme","mode","systemScheme","stockPalette","scheme","g9DarkPalette","g9LightPalette","known","Set","g9ColorTokens","trusted","WeakSet","lazy","trustPalette","palette","lazyPalettes","build","made","get","hit","p","out","layer","base","overrides","next","token","color","undefined","parseColor","createPalette","values","missing","ordered","resolveTheme","options","_options_mode","_options_systemScheme","_options_palettes","_options_palettes1","inactive","custom","samePalette","a","b","resolveState","state","palettes","painted","createThemeStore","_options_hour","_options_schedule","snapshot","notified","listeners","depth","notifying","commit","patch","nextState","changed","flush","failure","failed","current","listener","Array","error","repaint","design","Number","before","crosses"],"mappings":";;;AAWO,MAAMA,cAAc;IAAE,QAAQ;IAAU,OAAO;IAAS,MAAM;IAAQ,WAAW;AAAY;AAa7F,MAAMC,yBAA0CC,OAAO,MAAM,CAAC;IAAE,UAAU;IAAI,QAAQ;AAAE;AAGxF,SAASC,gBAAgBC,IAAY,EAAEC,WAA4BJ,sBAAsB;IAC9F,MAAM,EAAEK,QAAQ,EAAEC,MAAM,EAAE,GAAGF;IAC7B,IAAIC,aAAaC,QAAQ,OAAO;IAChC,OAAOD,WAAWC,SAASH,QAAQE,YAAYF,OAAOG,SAASH,QAAQE,YAAYF,OAAOG;AAC5F;AAGO,MAAMC,gBAAgB;IAAE,OAAO;IAAS,MAAM;AAAO;AAoC5D,MAAMC,QAA2B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C,QAAQ;YAClBmE,OAAO;gBAAE,UAAUtE,OAAO,MAAM,CAAC;oBAAE,GAAGG,QAAQ;gBAAC;YAAG;QACpD;QACA,aAAa,IAAO;gBAAE,MAAMwD,MAAM,IAAI;gBAAE,UAAUA,MAAM,QAAQ;YAAC;QACjE,OAAMf,MAAM;YACV0B,OAAO;gBAAE,SAAS3B,cAAcC;YAAQ;QAC1C;QACA;YACEwB,SAAS;QACX;QACA;YACE,IAAIA,AAAU,MAAVA,OAAa;YACjBA,SAAS;YACTM;QACF;IACF;AACF"}
|
package/dist/theme/variants.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { G9ButtonVariant, G9ProgressType } from '../enums/index.js';
|
|
2
|
+
import { type G9GradientToken } from '../tokens/derived.js';
|
|
2
3
|
import type { G9PaletteValues } from '../tokens/generated/palettes.js';
|
|
3
4
|
import { type G9Color } from './color.js';
|
|
4
5
|
/**
|
|
@@ -23,6 +24,15 @@ export type G9ButtonVisualResult = G9VariantColors;
|
|
|
23
24
|
* MAUI switch's default arm did.
|
|
24
25
|
*/
|
|
25
26
|
export declare function resolveButtonVariant(variant: G9ButtonVariant, palette: G9PaletteValues): G9VariantColors;
|
|
27
|
+
/** A variant painted with CSS variables: the same colours as {@link resolveButtonVariant}, following the theme with no
|
|
28
|
+
* script (the provider writes the variables). `gradient` names the token whose gradient a solid fill uses. */
|
|
29
|
+
export interface G9VariantVars extends G9VariantColors {
|
|
30
|
+
readonly gradient: G9GradientToken | null;
|
|
31
|
+
}
|
|
32
|
+
/** {@link resolveButtonVariant} as `var(--g9-…)` references (no palette read; cached per variant). */
|
|
33
|
+
export declare function resolveButtonVariantVars(variant: G9ButtonVariant): G9VariantVars;
|
|
34
|
+
/** {@link resolveProgressColor} as a `var(--g9-…)` reference. */
|
|
35
|
+
export declare function resolveProgressColorVar(type: G9ProgressType): string;
|
|
26
36
|
/** Fill colour of a progress indicator (MAUI `G9Visuals.ResolveProgressColor`); unrecognised types use `Primary`. */
|
|
27
37
|
export declare function resolveProgressColor(type: G9ProgressType, palette: G9PaletteValues): G9Color;
|
|
28
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/theme/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../src/theme/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEhE,OAAO,EAAE,KAAK,eAAe,EAAa,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAe,KAAK,OAAO,EAAa,MAAM,SAAS,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAOnD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,GAAG,eAAe,CAoCxG;AAED;8GAC8G;AAC9G,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;CAC3C;AAOD,sGAAsG;AACtG,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa,CAqDhF;AAED,iEAAiE;AACjE,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAIpE;AAED,q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