@g9tm/lynxcontrols-foundation 2.5.1 → 2.5.3
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/catalog/catalog.json +71 -7
- package/catalog/index.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/theme/__tests__/sine-curve.vectors.js +5 -0
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +1 -1
- package/dist/theme/oklch.d.ts +26 -3
- package/dist/theme/oklch.d.ts.map +1 -1
- package/dist/theme/oklch.js +128 -4
- package/dist/theme/oklch.js.map +1 -1
- package/dist/tokens/index.d.ts +1 -1
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +1 -1
- package/dist/tokens/shape.d.ts +32 -2
- package/dist/tokens/shape.d.ts.map +1 -1
- package/dist/tokens/shape.js +49 -5
- package/dist/tokens/shape.js.map +1 -1
- package/docs/api.md +9 -1
- package/package.json +1 -1
package/dist/theme/oklch.js
CHANGED
|
@@ -133,7 +133,8 @@ function nearestTonalStep(color) {
|
|
|
133
133
|
for (const step of g9TonalSteps)if (Math.abs(STEP_L[step] - l) < Math.abs(STEP_L[best] - l)) best = step;
|
|
134
134
|
return best;
|
|
135
135
|
}
|
|
136
|
-
function tonalScale(color) {
|
|
136
|
+
function tonalScale(color, options) {
|
|
137
|
+
if ((null == options ? void 0 : options.curve) === 'sine') return sineTonalScale(color);
|
|
137
138
|
const src = toOklch(color);
|
|
138
139
|
const exact = nearestTonalStep(color);
|
|
139
140
|
const peak = src.c / STEP_C[exact];
|
|
@@ -145,7 +146,8 @@ function tonalScale(color) {
|
|
|
145
146
|
});
|
|
146
147
|
return out;
|
|
147
148
|
}
|
|
148
|
-
function neutralScale(color, tint = 0.5) {
|
|
149
|
+
function neutralScale(color, tint = 0.5, options) {
|
|
150
|
+
if ((null == options ? void 0 : options.curve) === 'sine') return sineNeutralScale(color, tint);
|
|
149
151
|
const { h } = toOklch(color);
|
|
150
152
|
const c = 0.02 * Math.min(1, Math.max(0, tint));
|
|
151
153
|
const out = {};
|
|
@@ -163,7 +165,8 @@ function colorDistance(a, b) {
|
|
|
163
165
|
const rb = y.h * Math.PI / 180;
|
|
164
166
|
return 100 * Math.hypot(x.l - y.l, x.c * Math.cos(ra) - y.c * Math.cos(rb), x.c * Math.sin(ra) - y.c * Math.sin(rb));
|
|
165
167
|
}
|
|
166
|
-
function ensureContrast(fg, bg, min) {
|
|
168
|
+
function ensureContrast(fg, bg, min, options) {
|
|
169
|
+
if ((null == options ? void 0 : options.method) === 'steps') return stepContrast(fg, bg, min);
|
|
167
170
|
if (getContrastRatio(fg, bg) >= min) return opaque(fg);
|
|
168
171
|
const src = toOklch(fg);
|
|
169
172
|
const bgL = getLuminance(bg);
|
|
@@ -253,6 +256,127 @@ function chartPalette(primary, background, n = 8) {
|
|
|
253
256
|
}
|
|
254
257
|
return out;
|
|
255
258
|
}
|
|
256
|
-
|
|
259
|
+
const SINE_L = {
|
|
260
|
+
50: 0.975,
|
|
261
|
+
100: 0.945,
|
|
262
|
+
200: 0.89,
|
|
263
|
+
300: 0.81,
|
|
264
|
+
400: 0.715,
|
|
265
|
+
500: 0.625,
|
|
266
|
+
600: 0.54,
|
|
267
|
+
700: 0.455,
|
|
268
|
+
800: 0.375,
|
|
269
|
+
900: 0.295,
|
|
270
|
+
950: 0.225
|
|
271
|
+
};
|
|
272
|
+
function sineOklch(color) {
|
|
273
|
+
const { r, g, b } = toRgba(color);
|
|
274
|
+
const [L, A, B] = linearToOklab(toLinear(r), toLinear(g), toLinear(b));
|
|
275
|
+
const c = Math.sqrt(A * A + B * B);
|
|
276
|
+
return {
|
|
277
|
+
l: L,
|
|
278
|
+
c,
|
|
279
|
+
h: c < 1e-5 ? 0 : (180 * Math.atan2(B, A) / Math.PI + 360) % 360
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function sineHex(x) {
|
|
283
|
+
const fits = (lin)=>lin.every((v)=>v >= -0.0001 && v <= 1.0001);
|
|
284
|
+
let c = x.c;
|
|
285
|
+
let lin = linearOf({
|
|
286
|
+
l: x.l,
|
|
287
|
+
c,
|
|
288
|
+
h: x.h
|
|
289
|
+
});
|
|
290
|
+
for(let i = 0; i < 24 && !fits(lin); i++){
|
|
291
|
+
c *= 0.9;
|
|
292
|
+
lin = linearOf({
|
|
293
|
+
l: x.l,
|
|
294
|
+
c,
|
|
295
|
+
h: x.h
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const ch = (v)=>fromLinear(Math.min(1, Math.max(0, v)));
|
|
299
|
+
return formatColor(rgba(ch(lin[0]), ch(lin[1]), ch(lin[2]), 1));
|
|
300
|
+
}
|
|
301
|
+
function sineBase(color) {
|
|
302
|
+
try {
|
|
303
|
+
return sineOklch(color);
|
|
304
|
+
} catch {
|
|
305
|
+
return {
|
|
306
|
+
l: 0.55,
|
|
307
|
+
c: 0.15,
|
|
308
|
+
h: 280
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function sineStep(l) {
|
|
313
|
+
let best = 500;
|
|
314
|
+
let distance = 1 / 0;
|
|
315
|
+
for (const step of g9TonalSteps){
|
|
316
|
+
const d = Math.abs(SINE_L[step] - l);
|
|
317
|
+
if (d < distance) {
|
|
318
|
+
distance = d;
|
|
319
|
+
best = step;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return best;
|
|
323
|
+
}
|
|
324
|
+
function sineTonalScale(color) {
|
|
325
|
+
const base = sineBase(color);
|
|
326
|
+
const out = {};
|
|
327
|
+
for (const step of g9TonalSteps){
|
|
328
|
+
const l = SINE_L[step];
|
|
329
|
+
const curve = Math.sin(Math.PI * Math.min(1, Math.max(0, (l - 0.12) / 0.9)));
|
|
330
|
+
out[step] = sineHex({
|
|
331
|
+
l,
|
|
332
|
+
c: base.c * (0.25 + 0.75 * curve),
|
|
333
|
+
h: base.h
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
out[sineStep(base.l)] = sineHex(base);
|
|
337
|
+
return out;
|
|
338
|
+
}
|
|
339
|
+
function sineNeutralScale(color, tint) {
|
|
340
|
+
const base = sineBase(color);
|
|
341
|
+
const c = Math.min(0.03, 0.2 * base.c) * Math.min(1, Math.max(0, tint));
|
|
342
|
+
const out = {};
|
|
343
|
+
for (const step of g9TonalSteps)out[step] = sineHex({
|
|
344
|
+
l: SINE_L[step],
|
|
345
|
+
c,
|
|
346
|
+
h: base.h
|
|
347
|
+
});
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
350
|
+
function fixedNeutralScale(hue, chroma) {
|
|
351
|
+
const out = {};
|
|
352
|
+
for (const step of g9TonalSteps)out[step] = sineHex({
|
|
353
|
+
l: SINE_L[step],
|
|
354
|
+
c: chroma,
|
|
355
|
+
h: hue
|
|
356
|
+
});
|
|
357
|
+
return out;
|
|
358
|
+
}
|
|
359
|
+
function stepContrast(fg, bg, min) {
|
|
360
|
+
if (getContrastRatio(fg, bg) >= min) return opaque(fg);
|
|
361
|
+
let base;
|
|
362
|
+
try {
|
|
363
|
+
base = sineOklch(fg);
|
|
364
|
+
} catch {
|
|
365
|
+
return 'string' == typeof fg ? fg : opaque(fg);
|
|
366
|
+
}
|
|
367
|
+
const darker = getLuminance(bg) > 0.18;
|
|
368
|
+
let best = opaque(fg);
|
|
369
|
+
for(let i = 1; i <= 40; i++){
|
|
370
|
+
const l = Math.min(1, Math.max(0, base.l + (darker ? -1 : 1) * i * 0.02));
|
|
371
|
+
best = sineHex({
|
|
372
|
+
l,
|
|
373
|
+
c: base.c,
|
|
374
|
+
h: base.h
|
|
375
|
+
});
|
|
376
|
+
if (getContrastRatio(best, bg) >= min) break;
|
|
377
|
+
}
|
|
378
|
+
return best;
|
|
379
|
+
}
|
|
380
|
+
export { chartPalette, colorDistance, ensureContrast, fixedNeutralScale, fromOklch, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, toOklch, tonalScale };
|
|
257
381
|
|
|
258
382
|
//# sourceMappingURL=oklch.js.map
|
package/dist/theme/oklch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme/oklch.js","sources":["../../src/theme/oklch.ts"],"sourcesContent":["// OKLCH colour science for themes: perceptual lightness (L 0..1), chroma (C ≥ 0) and hue (H degrees). Brand palettes,\n// tonal scales, chart palettes and contrast repair all work here, because equal steps of L look equal to a person and\n// keeping H keeps a brand recognisable — something HSL lightening never did (a darkened yellow turns olive in HSL).\n// Björn Ottosson's OKLab (2020) matrices; gamut mapping by reducing chroma at constant L and H (CSS Color 4's idea).\nimport { formatColor, type G9ColorInput, type G9Rgba, getContrastRatio, getLuminance, rgba, toRgba } from './color';\n\n/** A colour in OKLCH. `alpha` 0..1 (default 1). */\nexport interface G9Oklch {\n readonly l: number;\n readonly c: number;\n readonly h: number;\n readonly alpha?: number;\n}\n\n// Channels are 0..1 (the library's G9Rgba).\nconst toLinear = (x: number): number => {\n return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;\n};\nconst fromLinear = (v: number): number => {\n return v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;\n};\n\n/** Linear sRGB (0..1 each) → OKLab. */\nfunction linearToOklab(r: number, g: number, b: number): [number, number, number] {\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);\n return [\n 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n ];\n}\n\n/** OKLab → linear sRGB (may fall outside 0..1: out of gamut). */\nfunction oklabToLinear(L: number, a: number, b: number): [number, number, number] {\n const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;\n const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;\n const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;\n return [\n 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n ];\n}\n\n/** Any colour → OKLCH. */\n// Palette generation converts the same few strings hundreds of times (a brand, its scale, white, black): on PrimJS (no\n// JIT, Galaxy A21s) one brand palette cost ~60 ms before these caches (2026-11-18).\nconst OKLCH_CACHE = new Map<string, G9Oklch>();\n\n/** A colour in OKLCH (lightness, chroma, hue): the perceptual space the brand palettes and tonal scales are built in. Cached per string. */\nexport function toOklch(color: G9ColorInput): G9Oklch {\n if (typeof color === 'string') {\n const hit = OKLCH_CACHE.get(color);\n if (hit) return hit;\n const x = Object.freeze(toOklchUncached(color));\n if (OKLCH_CACHE.size > 512) OKLCH_CACHE.clear();\n OKLCH_CACHE.set(color, x);\n return x;\n }\n return toOklchUncached(color);\n}\n\nfunction toOklchUncached(color: G9ColorInput): G9Oklch {\n const { r, g, b, a } = toRgba(color);\n const [L, A, B] = linearToOklab(toLinear(r), toLinear(g), toLinear(b));\n const c = Math.hypot(A, B);\n let h = (Math.atan2(B, A) * 180) / Math.PI;\n if (h < 0) h += 360;\n // A grey has no hue: keep 0 so equality checks and interpolation stay stable.\n return { l: L, c: c < 1e-4 ? 0 : c, h: c < 1e-4 ? 0 : h, alpha: a };\n}\n\nconst EPS = 1e-6;\nconst inGamut = (rgb: readonly number[]): boolean => rgb.every((v) => v >= -EPS && v <= 1 + EPS);\n\nfunction linearOf(x: G9Oklch): [number, number, number] {\n const rad = (x.h * Math.PI) / 180;\n return oklabToLinear(x.l, x.c * Math.cos(rad), x.c * Math.sin(rad));\n}\n\n/** True when the OKLCH colour is inside sRGB. */\nexport const isInSrgbGamut = (x: G9Oklch): boolean => inGamut(linearOf(x));\n\n/**\n * OKLCH → sRGB (`G9Rgba`, channels 0..1). Out-of-gamut colours keep L and H and lose chroma until they fit (binary\n * search, 18 steps ≈ 1e-6 chroma), so a vivid brand never shifts hue when it is darkened or lightened.\n */\nexport function fromOklch(x: G9Oklch): G9Rgba {\n const l = Math.min(1, Math.max(0, x.l));\n let probe: G9Oklch = { l, c: Math.max(0, x.c), h: x.h };\n if (!isInSrgbGamut(probe)) {\n let lo = 0;\n let hi = probe.c;\n // 12 halvings: chroma to ~1e-4, finer than one step of a hex channel\n for (let i = 0; i < 12; i++) {\n const mid = (lo + hi) / 2;\n if (isInSrgbGamut({ l, c: mid, h: x.h })) lo = mid;\n else hi = mid;\n }\n probe = { l, c: lo, h: x.h };\n }\n const [r, g, b] = linearOf(probe);\n const ch = (v: number) => fromLinear(Math.min(1, Math.max(0, v)));\n return rgba(ch(r), ch(g), ch(b), x.alpha ?? 1);\n}\n\n/** OKLCH → `#RRGGBB` (or `#RRGGBBAA` with alpha < 1). */\nexport const oklchToHex = (x: G9Oklch): string => formatColor(fromOklch(x));\n\n/** A colour as opaque `#RRGGBB` (rounded), whatever its input form. */\nconst opaque = (color: G9ColorInput): string => formatColor({ ...toRgba(color), a: 1 });\n\n/** Steps of a tonal scale (Tailwind-like names: 50 lightest … 950 darkest). */\nexport const g9TonalSteps = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] as const;\n/** A step of a tonal scale: 50, 100, 200 … 900, 950. */\nexport type G9TonalStep = (typeof g9TonalSteps)[number];\n/** A colour's tonal scale: one hex colour per step (50 lightest … 950 darkest). */\nexport type G9TonalScale = { readonly [K in G9TonalStep]: string };\n\n/** Target lightness of each step (perceptually even, darker at the end like the projects' scales). */\nconst STEP_L: Record<G9TonalStep, number> = {\n 50: 0.975,\n 100: 0.945,\n 200: 0.89,\n 300: 0.815,\n 400: 0.72,\n 500: 0.63,\n 600: 0.55,\n 700: 0.47,\n 800: 0.39,\n 900: 0.3,\n 950: 0.22,\n};\n/** Chroma kept at each step relative to the source (pale and deep tones carry less colour). */\nconst STEP_C: Record<G9TonalStep, number> = {\n 50: 0.14,\n 100: 0.28,\n 200: 0.5,\n 300: 0.72,\n 400: 0.9,\n 500: 1,\n 600: 1,\n 700: 0.92,\n 800: 0.8,\n 900: 0.66,\n 950: 0.52,\n};\n\n/** The step whose lightness is nearest to `color`'s. */\nexport function nearestTonalStep(color: G9ColorInput): G9TonalStep {\n const { l } = toOklch(color);\n let best: G9TonalStep = 500;\n for (const step of g9TonalSteps) if (Math.abs(STEP_L[step] - l) < Math.abs(STEP_L[best] - l)) best = step;\n return best;\n}\n\n/**\n * A tonal scale from one colour: same hue, lightness from the step table, chroma scaled from the source's. The source\n * itself is placed exactly at its nearest step, so the brand colour always appears in its own scale unchanged.\n */\nexport function tonalScale(color: G9ColorInput): G9TonalScale {\n const src = toOklch(color);\n const exact = nearestTonalStep(color);\n const peak = src.c / STEP_C[exact];\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) {\n out[step] = step === exact ? opaque(color) : oklchToHex({ l: STEP_L[step], c: peak * STEP_C[step], h: src.h });\n }\n return out;\n}\n\n/**\n * A neutral scale tinted by `color`: the brand's hue at a whisper of chroma (`tint` 0 = pure grey, 1 = 0.02 C, the\n * strongest tint that still reads as grey), so surfaces and text belong to the brand without looking coloured.\n */\nexport function neutralScale(color: G9ColorInput, tint = 0.5): G9TonalScale {\n const { h } = toOklch(color);\n const c = 0.02 * Math.min(1, Math.max(0, tint));\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) out[step] = oklchToHex({ l: STEP_L[step], c, h });\n return out;\n}\n\n/** Perceptual distance (ΔE in OKLab, ×100: about 2 is just noticeable). */\nexport function colorDistance(a: G9ColorInput, b: G9ColorInput): number {\n const x = toOklch(a);\n const y = toOklch(b);\n const ra = (x.h * Math.PI) / 180;\n const rb = (y.h * Math.PI) / 180;\n return Math.hypot(x.l - y.l, x.c * Math.cos(ra) - y.c * Math.cos(rb), x.c * Math.sin(ra) - y.c * Math.sin(rb)) * 100;\n}\n\n/**\n * `fg` moved in lightness (hue and chroma kept) until its WCAG contrast with `bg` is at least `min`. Goes darker on a\n * light background and lighter on a dark one; returns `fg` unchanged when it already passes. If no lightness of this hue\n * reaches `min`, returns black or white, whichever contrasts more.\n */\nexport function ensureContrast(fg: G9ColorInput, bg: G9ColorInput, min: number): string {\n if (getContrastRatio(fg, bg) >= min) return opaque(fg);\n const src = toOklch(fg);\n const bgL = getLuminance(bg);\n const ratio = (c: G9Rgba) => {\n const l = getLuminance(c);\n return (Math.max(l, bgL) + 0.05) / (Math.min(l, bgL) + 0.05);\n };\n const darker = toOklch(bg).l > 0.6;\n let lo = darker ? 0 : src.l;\n let hi = darker ? src.l : 1;\n let found: number | null = null;\n // 14 halvings: lightness to ~6e-5, below one step of a hex channel; compared in numbers, formatted once\n for (let i = 0; i < 14; i++) {\n const mid = (lo + hi) / 2;\n if (ratio(fromOklch({ l: mid, c: src.c, h: src.h })) >= min) {\n found = mid;\n // keep as close to the original lightness as passing allows\n if (darker) lo = mid;\n else hi = mid;\n } else if (darker) hi = mid;\n else lo = mid;\n }\n if (found !== null) {\n // the hex rounds: step on toward the safe side until the written colour itself passes\n for (let k = 0; k < 8; k++) {\n const hex = oklchToHex({ l: found, c: src.c, h: src.h });\n if (getContrastRatio(hex, bg) >= min) return hex;\n found = Math.min(1, Math.max(0, found + (darker ? -0.002 : 0.002)));\n }\n }\n return getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg) ? '#000000' : '#FFFFFF';\n}\n\n/** Black or white text, whichever contrasts more with `bg`, nudged toward `tint`'s hue when given. */\nexport function readableOn(bg: G9ColorInput, tint?: G9ColorInput): string {\n const dark = getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg);\n if (!tint) return dark ? '#000000' : '#FFFFFF';\n const { h, c } = toOklch(tint);\n return ensureContrast(oklchToHex({ l: dark ? 0.2 : 0.98, c: Math.min(c, 0.04), h }), bg, 4.5);\n}\n\n/** Linear interpolation in OKLCH (shorter hue arc). `t` 0..1. */\nexport function mixOklch(a: G9ColorInput, b: G9ColorInput, t: number): string {\n const x = toOklch(a);\n const y = toOklch(b);\n // A grey end has no hue: it takes the other end's, so grey → blue never sweeps through red. Otherwise the shorter arc.\n let h: number;\n if (x.c === 0) h = y.h;\n else if (y.c === 0) h = x.h;\n else {\n let dh = y.h - x.h;\n if (dh > 180) dh -= 360;\n if (dh < -180) dh += 360;\n h = (x.h + dh * t + 360) % 360;\n }\n return oklchToHex({\n l: x.l + (y.l - x.l) * t,\n c: x.c + (y.c - x.c) * t,\n h,\n alpha: (x.alpha ?? 1) + ((y.alpha ?? 1) - (x.alpha ?? 1)) * t,\n });\n}\n\n/**\n * A colour at `t` (0..1) along several stops, mixed in OKLCH — e.g. Riskara's risk spectrum\n * (`interpolateStops([calm, lime, amber, coral], score / 100)`).\n */\nexport function interpolateStops(stops: readonly G9ColorInput[], t: number): string {\n if (stops.length === 0) throw new RangeError('interpolateStops needs at least one stop.');\n if (stops.length === 1) return formatColor(stops[0] as G9ColorInput);\n const x = Math.min(1, Math.max(0, t)) * (stops.length - 1);\n const i = Math.min(stops.length - 2, Math.floor(x));\n return mixOklch(stops[i] as G9ColorInput, stops[i + 1] as G9ColorInput, x - i);\n}\n\n/**\n * `n` chart colours that start at `primary` and step around the hue circle by the golden angle (137.5°), each at a\n * lightness that reads on `background` (contrast ≥ 3, WCAG for graphics) and a chroma the scheme can carry. Neighbours\n * stay distinguishable for n ≤ 10; the same inputs always give the same palette.\n */\nexport function chartPalette(primary: G9ColorInput, background: G9ColorInput, n = 8): string[] {\n const p = toOklch(primary);\n const dark = toOklch(background).l < 0.5;\n const l = dark ? 0.74 : 0.58;\n const c = Math.max(0.09, Math.min(0.17, p.c || 0.12));\n const out: string[] = [];\n for (let i = 0; i < n; i++) {\n const h = (p.h + i * 137.508) % 360;\n // alternate the lightness a little so neighbours in a stacked chart separate\n const li = l + (i % 2 === 0 ? 0 : dark ? -0.06 : 0.07);\n out.push(ensureContrast(i === 0 ? opaque(primary) : oklchToHex({ l: li, c, h }), background, 3));\n }\n return out;\n}\n"],"names":["toLinear","x","fromLinear","v","linearToOklab","r","g","b","l","Math","m","s","oklabToLinear","L","a","OKLCH_CACHE","Map","toOklch","color","hit","Object","toOklchUncached","toRgba","A","B","c","h","EPS","inGamut","rgb","linearOf","rad","isInSrgbGamut","fromOklch","_x_alpha","probe","lo","hi","i","mid","ch","rgba","oklchToHex","formatColor","opaque","g9TonalSteps","STEP_L","STEP_C","nearestTonalStep","best","step","tonalScale","src","exact","peak","out","neutralScale","tint","colorDistance","y","ra","rb","ensureContrast","fg","bg","min","getContrastRatio","bgL","getLuminance","ratio","darker","found","k","hex","readableOn","dark","mixOklch","t","_y_alpha","_x_alpha1","dh","interpolateStops","stops","RangeError","chartPalette","primary","background","n","p","li"],"mappings":";AAeA,MAAMA,WAAW,CAACC,IACTA,KAAK,UAAUA,IAAI,QAAS,AAACA,CAAAA,CAAAA,IAAI,KAAI,IAAK,KAAI,KAAM;AAE7D,MAAMC,aAAa,CAACC,IACXA,KAAK,YAAY,QAAQA,IAAI,QAAQA,KAAM,KAAI,GAAE,IAAK;AAI/D,SAASC,cAAcC,CAAS,EAAEC,CAAS,EAAEC,CAAS;IACpD,MAAMC,IAAIC,KAAK,IAAI,CAAC,eAAeJ,IAAI,eAAeC,IAAI,eAAeC;IACzE,MAAMG,IAAID,KAAK,IAAI,CAAC,eAAeJ,IAAI,eAAeC,IAAI,eAAeC;IACzE,MAAMI,IAAIF,KAAK,IAAI,CAAC,eAAeJ,IAAI,eAAeC,IAAI,eAAeC;IACzE,OAAO;QACL,eAAeC,IAAI,cAAcE,IAAI,eAAeC;QACpD,eAAeH,IAAI,cAAcE,IAAI,eAAeC;QACpD,eAAeH,IAAI,eAAeE,IAAI,cAAcC;KACrD;AACH;AAGA,SAASC,cAAcC,CAAS,EAAEC,CAAS,EAAEP,CAAS;IACpD,MAAMC,IAAKK,A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I7B,KAAK,GAAG,CAACyE,MAAM,MAAM,GAAG,GAAGzE,KAAK,KAAK,CAACR;IAChD,OAAO2E,SAASM,KAAK,CAAC5C,EAAE,EAAkB4C,KAAK,CAAC5C,IAAI,EAAE,EAAkBrC,IAAIqC;AAC9E;AAOO,SAAS8C,aAAaC,OAAqB,EAAEC,UAAwB,EAAEC,IAAI,CAAC;IACjF,MAAMC,IAAIvE,QAAQoE;IAClB,MAAMV,OAAO1D,QAAQqE,YAAY,CAAC,GAAG;IACrC,MAAM9E,IAAImE,OAAO,OAAO;IACxB,MAAMlD,IAAIhB,KAAK,GAAG,CAAC,MAAMA,KAAK,GAAG,CAAC,MAAM+E,EAAE,CAAC,IAAI;IAC/C,MAAMjC,MAAgB,EAAE;IACxB,IAAK,IAAIjB,IAAI,GAAGA,IAAIiD,GAAGjD,IAAK;QAC1B,MAAMZ,IAAK8D,AAAAA,CAAAA,EAAE,CAAC,GAAGlD,AAAI,UAAJA,CAAU,IAAK;QAEhC,MAAMmD,KAAKjF,IAAK8B,CAAAA,IAAI,MAAM,IAAI,IAAIqC,OAAO,QAAQ,IAAG;QACpDpB,IAAI,IAAI,CAACO,eAAexB,AAAM,MAANA,IAAUM,OAAOyC,WAAW3C,WAAW;YAAE,GAAG+C;YAAIhE;YAAGC;QAAE,IAAI4D,YAAY;IAC/F;IACA,OAAO/B;AACT"}
|
|
1
|
+
{"version":3,"file":"theme/oklch.js","sources":["../../src/theme/oklch.ts"],"sourcesContent":["// OKLCH colour science for themes: perceptual lightness (L 0..1), chroma (C ≥ 0) and hue (H degrees). Brand palettes,\n// tonal scales, chart palettes and contrast repair all work here, because equal steps of L look equal to a person and\n// keeping H keeps a brand recognisable — something HSL lightening never did (a darkened yellow turns olive in HSL).\n// Björn Ottosson's OKLab (2020) matrices; gamut mapping by reducing chroma at constant L and H (CSS Color 4's idea).\nimport { formatColor, type G9ColorInput, type G9Rgba, getContrastRatio, getLuminance, rgba, toRgba } from './color';\n\n/** A colour in OKLCH. `alpha` 0..1 (default 1). */\nexport interface G9Oklch {\n readonly l: number;\n readonly c: number;\n readonly h: number;\n readonly alpha?: number;\n}\n\n// Channels are 0..1 (the library's G9Rgba).\nconst toLinear = (x: number): number => {\n return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;\n};\nconst fromLinear = (v: number): number => {\n return v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055;\n};\n\n/** Linear sRGB (0..1 each) → OKLab. */\nfunction linearToOklab(r: number, g: number, b: number): [number, number, number] {\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);\n return [\n 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n ];\n}\n\n/** OKLab → linear sRGB (may fall outside 0..1: out of gamut). */\nfunction oklabToLinear(L: number, a: number, b: number): [number, number, number] {\n const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;\n const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;\n const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;\n return [\n 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n ];\n}\n\n/** Any colour → OKLCH. */\n// Palette generation converts the same few strings hundreds of times (a brand, its scale, white, black): on PrimJS (no\n// JIT, Galaxy A21s) one brand palette cost ~60 ms before these caches (2026-11-18).\nconst OKLCH_CACHE = new Map<string, G9Oklch>();\n\n/** A colour in OKLCH (lightness, chroma, hue): the perceptual space the brand palettes and tonal scales are built in. Cached per string. */\nexport function toOklch(color: G9ColorInput): G9Oklch {\n if (typeof color === 'string') {\n const hit = OKLCH_CACHE.get(color);\n if (hit) return hit;\n const x = Object.freeze(toOklchUncached(color));\n if (OKLCH_CACHE.size > 512) OKLCH_CACHE.clear();\n OKLCH_CACHE.set(color, x);\n return x;\n }\n return toOklchUncached(color);\n}\n\nfunction toOklchUncached(color: G9ColorInput): G9Oklch {\n const { r, g, b, a } = toRgba(color);\n const [L, A, B] = linearToOklab(toLinear(r), toLinear(g), toLinear(b));\n const c = Math.hypot(A, B);\n let h = (Math.atan2(B, A) * 180) / Math.PI;\n if (h < 0) h += 360;\n // A grey has no hue: keep 0 so equality checks and interpolation stay stable.\n return { l: L, c: c < 1e-4 ? 0 : c, h: c < 1e-4 ? 0 : h, alpha: a };\n}\n\nconst EPS = 1e-6;\nconst inGamut = (rgb: readonly number[]): boolean => rgb.every((v) => v >= -EPS && v <= 1 + EPS);\n\nfunction linearOf(x: G9Oklch): [number, number, number] {\n const rad = (x.h * Math.PI) / 180;\n return oklabToLinear(x.l, x.c * Math.cos(rad), x.c * Math.sin(rad));\n}\n\n/** True when the OKLCH colour is inside sRGB. */\nexport const isInSrgbGamut = (x: G9Oklch): boolean => inGamut(linearOf(x));\n\n/**\n * OKLCH → sRGB (`G9Rgba`, channels 0..1). Out-of-gamut colours keep L and H and lose chroma until they fit (binary\n * search, 18 steps ≈ 1e-6 chroma), so a vivid brand never shifts hue when it is darkened or lightened.\n */\nexport function fromOklch(x: G9Oklch): G9Rgba {\n const l = Math.min(1, Math.max(0, x.l));\n let probe: G9Oklch = { l, c: Math.max(0, x.c), h: x.h };\n if (!isInSrgbGamut(probe)) {\n let lo = 0;\n let hi = probe.c;\n // 12 halvings: chroma to ~1e-4, finer than one step of a hex channel\n for (let i = 0; i < 12; i++) {\n const mid = (lo + hi) / 2;\n if (isInSrgbGamut({ l, c: mid, h: x.h })) lo = mid;\n else hi = mid;\n }\n probe = { l, c: lo, h: x.h };\n }\n const [r, g, b] = linearOf(probe);\n const ch = (v: number) => fromLinear(Math.min(1, Math.max(0, v)));\n return rgba(ch(r), ch(g), ch(b), x.alpha ?? 1);\n}\n\n/** OKLCH → `#RRGGBB` (or `#RRGGBBAA` with alpha < 1). */\nexport const oklchToHex = (x: G9Oklch): string => formatColor(fromOklch(x));\n\n/** A colour as opaque `#RRGGBB` (rounded), whatever its input form. */\nconst opaque = (color: G9ColorInput): string => formatColor({ ...toRgba(color), a: 1 });\n\n/** Steps of a tonal scale (Tailwind-like names: 50 lightest … 950 darkest). */\nexport const g9TonalSteps = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] as const;\n/** A step of a tonal scale: 50, 100, 200 … 900, 950. */\nexport type G9TonalStep = (typeof g9TonalSteps)[number];\n/** A colour's tonal scale: one hex colour per step (50 lightest … 950 darkest). */\nexport type G9TonalScale = { readonly [K in G9TonalStep]: string };\n\n/** Target lightness of each step (perceptually even, darker at the end like the projects' scales). */\nconst STEP_L: Record<G9TonalStep, number> = {\n 50: 0.975,\n 100: 0.945,\n 200: 0.89,\n 300: 0.815,\n 400: 0.72,\n 500: 0.63,\n 600: 0.55,\n 700: 0.47,\n 800: 0.39,\n 900: 0.3,\n 950: 0.22,\n};\n/** Chroma kept at each step relative to the source (pale and deep tones carry less colour). */\nconst STEP_C: Record<G9TonalStep, number> = {\n 50: 0.14,\n 100: 0.28,\n 200: 0.5,\n 300: 0.72,\n 400: 0.9,\n 500: 1,\n 600: 1,\n 700: 0.92,\n 800: 0.8,\n 900: 0.66,\n 950: 0.52,\n};\n\n/** The step whose lightness is nearest to `color`'s. */\nexport function nearestTonalStep(color: G9ColorInput): G9TonalStep {\n const { l } = toOklch(color);\n let best: G9TonalStep = 500;\n for (const step of g9TonalSteps) if (Math.abs(STEP_L[step] - l) < Math.abs(STEP_L[best] - l)) best = step;\n return best;\n}\n\n/**\n * A tonal scale from one colour: same hue, lightness from the step table, chroma scaled from the source's. The source\n * itself is placed exactly at its nearest step, so the brand colour always appears in its own scale unchanged.\n */\nexport function tonalScale(color: G9ColorInput, options?: G9ScaleOptions): G9TonalScale {\n if (options?.curve === 'sine') return sineTonalScale(color);\n const src = toOklch(color);\n const exact = nearestTonalStep(color);\n const peak = src.c / STEP_C[exact];\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) {\n out[step] = step === exact ? opaque(color) : oklchToHex({ l: STEP_L[step], c: peak * STEP_C[step], h: src.h });\n }\n return out;\n}\n\n/**\n * A neutral scale tinted by `color`: the brand's hue at a whisper of chroma (`tint` 0 = pure grey, 1 = 0.02 C, the\n * strongest tint that still reads as grey), so surfaces and text belong to the brand without looking coloured.\n */\nexport function neutralScale(color: G9ColorInput, tint = 0.5, options?: G9ScaleOptions): G9TonalScale {\n if (options?.curve === 'sine') return sineNeutralScale(color, tint);\n const { h } = toOklch(color);\n const c = 0.02 * Math.min(1, Math.max(0, tint));\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) out[step] = oklchToHex({ l: STEP_L[step], c, h });\n return out;\n}\n\n/** Perceptual distance (ΔE in OKLab, ×100: about 2 is just noticeable). */\nexport function colorDistance(a: G9ColorInput, b: G9ColorInput): number {\n const x = toOklch(a);\n const y = toOklch(b);\n const ra = (x.h * Math.PI) / 180;\n const rb = (y.h * Math.PI) / 180;\n return Math.hypot(x.l - y.l, x.c * Math.cos(ra) - y.c * Math.cos(rb), x.c * Math.sin(ra) - y.c * Math.sin(rb)) * 100;\n}\n\n/**\n * `fg` moved in lightness (hue and chroma kept) until its WCAG contrast with `bg` is at least `min`. Goes darker on a\n * light background and lighter on a dark one; returns `fg` unchanged when it already passes. If no lightness of this hue\n * reaches `min`, returns black or white, whichever contrasts more.\n */\nexport function ensureContrast(\n fg: G9ColorInput,\n bg: G9ColorInput,\n min: number,\n options?: G9EnsureContrastOptions,\n): string {\n if (options?.method === 'steps') return stepContrast(fg, bg, min);\n if (getContrastRatio(fg, bg) >= min) return opaque(fg);\n const src = toOklch(fg);\n const bgL = getLuminance(bg);\n const ratio = (c: G9Rgba) => {\n const l = getLuminance(c);\n return (Math.max(l, bgL) + 0.05) / (Math.min(l, bgL) + 0.05);\n };\n const darker = toOklch(bg).l > 0.6;\n let lo = darker ? 0 : src.l;\n let hi = darker ? src.l : 1;\n let found: number | null = null;\n // 14 halvings: lightness to ~6e-5, below one step of a hex channel; compared in numbers, formatted once\n for (let i = 0; i < 14; i++) {\n const mid = (lo + hi) / 2;\n if (ratio(fromOklch({ l: mid, c: src.c, h: src.h })) >= min) {\n found = mid;\n // keep as close to the original lightness as passing allows\n if (darker) lo = mid;\n else hi = mid;\n } else if (darker) hi = mid;\n else lo = mid;\n }\n if (found !== null) {\n // the hex rounds: step on toward the safe side until the written colour itself passes\n for (let k = 0; k < 8; k++) {\n const hex = oklchToHex({ l: found, c: src.c, h: src.h });\n if (getContrastRatio(hex, bg) >= min) return hex;\n found = Math.min(1, Math.max(0, found + (darker ? -0.002 : 0.002)));\n }\n }\n return getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg) ? '#000000' : '#FFFFFF';\n}\n\n/** Black or white text, whichever contrasts more with `bg`, nudged toward `tint`'s hue when given. */\nexport function readableOn(bg: G9ColorInput, tint?: G9ColorInput): string {\n const dark = getContrastRatio('#000000', bg) >= getContrastRatio('#FFFFFF', bg);\n if (!tint) return dark ? '#000000' : '#FFFFFF';\n const { h, c } = toOklch(tint);\n return ensureContrast(oklchToHex({ l: dark ? 0.2 : 0.98, c: Math.min(c, 0.04), h }), bg, 4.5);\n}\n\n/** Linear interpolation in OKLCH (shorter hue arc). `t` 0..1. */\nexport function mixOklch(a: G9ColorInput, b: G9ColorInput, t: number): string {\n const x = toOklch(a);\n const y = toOklch(b);\n // A grey end has no hue: it takes the other end's, so grey → blue never sweeps through red. Otherwise the shorter arc.\n let h: number;\n if (x.c === 0) h = y.h;\n else if (y.c === 0) h = x.h;\n else {\n let dh = y.h - x.h;\n if (dh > 180) dh -= 360;\n if (dh < -180) dh += 360;\n h = (x.h + dh * t + 360) % 360;\n }\n return oklchToHex({\n l: x.l + (y.l - x.l) * t,\n c: x.c + (y.c - x.c) * t,\n h,\n alpha: (x.alpha ?? 1) + ((y.alpha ?? 1) - (x.alpha ?? 1)) * t,\n });\n}\n\n/**\n * A colour at `t` (0..1) along several stops, mixed in OKLCH — e.g. Riskara's risk spectrum\n * (`interpolateStops([calm, lime, amber, coral], score / 100)`).\n */\nexport function interpolateStops(stops: readonly G9ColorInput[], t: number): string {\n if (stops.length === 0) throw new RangeError('interpolateStops needs at least one stop.');\n if (stops.length === 1) return formatColor(stops[0] as G9ColorInput);\n const x = Math.min(1, Math.max(0, t)) * (stops.length - 1);\n const i = Math.min(stops.length - 2, Math.floor(x));\n return mixOklch(stops[i] as G9ColorInput, stops[i + 1] as G9ColorInput, x - i);\n}\n\n/**\n * `n` chart colours that start at `primary` and step around the hue circle by the golden angle (137.5°), each at a\n * lightness that reads on `background` (contrast ≥ 3, WCAG for graphics) and a chroma the scheme can carry. Neighbours\n * stay distinguishable for n ≤ 10; the same inputs always give the same palette.\n */\nexport function chartPalette(primary: G9ColorInput, background: G9ColorInput, n = 8): string[] {\n const p = toOklch(primary);\n const dark = toOklch(background).l < 0.5;\n const l = dark ? 0.74 : 0.58;\n const c = Math.max(0.09, Math.min(0.17, p.c || 0.12));\n const out: string[] = [];\n for (let i = 0; i < n; i++) {\n const h = (p.h + i * 137.508) % 360;\n // alternate the lightness a little so neighbours in a stacked chart separate\n const li = l + (i % 2 === 0 ? 0 : dark ? -0.06 : 0.07);\n out.push(ensureContrast(i === 0 ? opaque(primary) : oklchToHex({ l: li, c, h }), background, 3));\n }\n return out;\n}\n\n// ------------------------------------------------------------------------------- the sine curve (ShopManager's)\n\n/** Options of {@link tonalScale} and {@link neutralScale}. */\nexport interface G9ScaleOptions {\n /**\n * `'even'` (default): the library's step table, chroma scaled per step from the source. `'sine'`: a lighter, cleaner\n * table whose chroma falls off along a sine towards white and black (ShopManager's `@g9/tokens` curve, reproduced to\n * the hex), with gamut mapping by 10 % chroma steps, as that design system measured its recipes against it.\n */\n readonly curve?: 'even' | 'sine';\n}\n\n/** Options of {@link ensureContrast}. */\nexport interface G9EnsureContrastOptions {\n /**\n * `'search'` (default): the closest passing lightness (a binary search), else black or white. `'steps'`: lightness\n * moved in 0.02 steps (darker on a background whose luminance is over 0.18), the first passing step, else the 40th\n * (ShopManager's `@g9/tokens` contrast repair, reproduced to the hex).\n */\n readonly method?: 'search' | 'steps';\n}\n\n/** The sine curve's lightness per step. */\nconst SINE_L: Record<G9TonalStep, number> = {\n 50: 0.975,\n 100: 0.945,\n 200: 0.89,\n 300: 0.81,\n 400: 0.715,\n 500: 0.625,\n 600: 0.54,\n 700: 0.455,\n 800: 0.375,\n 900: 0.295,\n 950: 0.225,\n};\n\n/** The sine curve's colour → OKLCH: a hue below 1e-5 chroma reads as 0, as in the curve's source. */\nfunction sineOklch(color: G9ColorInput): G9Oklch {\n const { r, g, b } = toRgba(color);\n const [L, A, B] = linearToOklab(toLinear(r), toLinear(g), toLinear(b));\n const c = Math.sqrt(A * A + B * B);\n return { l: L, c, h: c < 1e-5 ? 0 : ((Math.atan2(B, A) * 180) / Math.PI + 360) % 360 };\n}\n\n/** The sine curve's OKLCH → `#RRGGBB`: chroma cut by 10 % at a time (at most 24) until inside sRGB (±1e-4). */\nfunction sineHex(x: G9Oklch): string {\n const fits = (lin: readonly number[]) => lin.every((v) => v >= -1e-4 && v <= 1 + 1e-4);\n let c = x.c;\n let lin = linearOf({ l: x.l, c, h: x.h });\n for (let i = 0; i < 24 && !fits(lin); i++) {\n c *= 0.9;\n lin = linearOf({ l: x.l, c, h: x.h });\n }\n const ch = (v: number) => fromLinear(Math.min(1, Math.max(0, v)));\n return formatColor(rgba(ch(lin[0]), ch(lin[1]), ch(lin[2]), 1));\n}\n\n/** A colour that does not parse gives the curve's default brand (a violet), as its source did. */\nfunction sineBase(color: G9ColorInput): G9Oklch {\n try {\n return sineOklch(color);\n } catch {\n return { l: 0.55, c: 0.15, h: 280 };\n }\n}\n\nfunction sineStep(l: number): G9TonalStep {\n let best: G9TonalStep = 500;\n let distance = Number.POSITIVE_INFINITY;\n for (const step of g9TonalSteps) {\n const d = Math.abs(SINE_L[step] - l);\n if (d < distance) {\n distance = d;\n best = step;\n }\n }\n return best;\n}\n\nfunction sineTonalScale(color: G9ColorInput): G9TonalScale {\n const base = sineBase(color);\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) {\n const l = SINE_L[step];\n const curve = Math.sin(Math.PI * Math.min(1, Math.max(0, (l - 0.12) / 0.9)));\n out[step] = sineHex({ l, c: base.c * (0.25 + 0.75 * curve), h: base.h });\n }\n out[sineStep(base.l)] = sineHex(base);\n return out;\n}\n\nfunction sineNeutralScale(color: G9ColorInput, tint: number): G9TonalScale {\n const base = sineBase(color);\n const c = Math.min(0.03, base.c * 0.2) * Math.min(1, Math.max(0, tint));\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) out[step] = sineHex({ l: SINE_L[step], c, h: base.h });\n return out;\n}\n\n/**\n * Neutrals of a fixed hue and chroma, whatever the brand (warm paper, cool steel), on the sine curve's lightness\n * steps (ShopManager's `fixedNeutralScale`).\n */\nexport function fixedNeutralScale(hue: number, chroma: number): G9TonalScale {\n const out = {} as Record<G9TonalStep, string>;\n for (const step of g9TonalSteps) out[step] = sineHex({ l: SINE_L[step], c: chroma, h: hue });\n return out;\n}\n\nfunction stepContrast(fg: G9ColorInput, bg: G9ColorInput, min: number): string {\n if (getContrastRatio(fg, bg) >= min) return opaque(fg);\n let base: G9Oklch;\n try {\n base = sineOklch(fg);\n } catch {\n return typeof fg === 'string' ? fg : opaque(fg);\n }\n const darker = getLuminance(bg) > 0.18;\n let best = opaque(fg);\n for (let i = 1; i <= 40; i++) {\n const l = Math.min(1, Math.max(0, base.l + (darker ? -1 : 1) * i * 0.02));\n best = sineHex({ l, c: base.c, h: base.h });\n if (getContrastRatio(best, bg) >= min) return best;\n }\n return best;\n}\n"],"names":["toLinear","x","fromLinear","v","linearToOklab","r","g","b","l","Math","m","s","oklabToLinear","L","a","OKLCH_CACHE","Map","toOklch","color","hit","Object","toOklchUncached","toRgba","A","B","c","h","EPS","inGamut","rgb","linearOf","rad","isInSrgbGamut","fromOklch","_x_alpha","probe","lo","hi","i","mid","ch","rgba","oklchToHex","formatColor","opaque","g9TonalSteps","STEP_L","STEP_C","nearestTonalStep","best","step","tonalScale","options","sineTonalScale","src","exact","peak","out","neutralScale","tint","sineNeutralScale","colorDistance","y","ra","rb","ensureContrast","fg","bg","min","stepContrast","getContrastRatio","bgL","getLuminance","ratio","darker","found","k","hex","readableOn","dark","mixOklch","t","_y_alpha","_x_alpha1","dh","interpolateStops","stops","RangeError","chartPalette","primary","background","n","p","li","SINE_L","sineOklch","sineHex","fits","lin","sineBase","sineStep","distance","Number","d","base","curve","fixedNeutralScale","hue","chroma"],"mappings":";AAeA,MAAMA,WAAW,CAACC,IACTA,KAAK,UAAUA,IAAI,QAAS,AAACA,CAAAA,CAAAA,IAAI,KAAI,IAAK,KAAI,KAAM;AAE7D,MAAMC,aAAa,CAACC,IACXA,KAAK,YAAY,QAAQA,IAAI,QAAQA,KAAM,KAAI,GAAE,IAAK;AAI/D,SAASC,cAAcC,CAAS,EAAEC,CAAS,EAAEC,CAAS;IACpD,MAAMC,IAAIC,KAAK,IAAI,CAAC,eAAeJ,IAAI,eAAeC,IAAI,eAAeC;IACzE,MAAMG,IAAID,KAAK,IAAI,CAAC,eAAeJ,IAAI,eAAeC,IAAI,eAAeC;IACzE,MAAMI,IAAIF,KAAK,IAAI,CAAC,eAAeJ,IAAI,eAAeC,IAAI,eAAeC;IACzE,OAAO;QACL,eAAeC,IAAI,cAAcE,IAAI,eAAeC;QACpD,eAAeH,IAAI,cAAcE,IAAI,eAAeC;QACpD,eAAeH,IAAI,eAAeE,IAAI,cAAcC;KACrD;AACH;AAGA,SAASC,cAAcC,CAAS,EAAEC,CAAS,EAAEP,CAAS;IACpD,MAAMC,IAAKK,AAAAA,CAAAA,IA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AEzB;QAAG,GAAG+E,KAAK,CAAC;IAAC;IACrF,OAAO/C;AACT;AAMO,SAASiD,kBAAkBC,GAAW,EAAEC,MAAc;IAC3D,MAAMnD,MAAM,CAAC;IACb,KAAK,MAAMP,QAAQL,aAAcY,GAAG,CAACP,KAAK,GAAG8C,QAAQ;QAAE,GAAGF,MAAM,CAAC5C,KAAK;QAAE,GAAG0D;QAAQ,GAAGD;IAAI;IAC1F,OAAOlD;AACT;AAEA,SAASY,aAAaH,EAAgB,EAAEC,EAAgB,EAAEC,GAAW;IACnE,IAAIE,iBAAiBJ,IAAIC,OAAOC,KAAK,OAAOxB,OAAOsB;IACnD,IAAIsC;IACJ,IAAI;QACFA,OAAOT,UAAU7B;IACnB,EAAE,OAAM;QACN,OAAO,AAAc,YAAd,OAAOA,KAAkBA,KAAKtB,OAAOsB;IAC9C;IACA,MAAMQ,SAASF,aAAaL,MAAM;IAClC,IAAIlB,OAAOL,OAAOsB;IAClB,IAAK,IAAI5B,IAAI,GAAGA,KAAK,IAAIA,IAAK;QAC5B,MAAM9B,IAAIC,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAG,CAAC,GAAG+F,KAAK,CAAC,GAAI9B,AAAAA,CAAAA,SAAS,KAAK,KAAKpC,IAAI;QACnEW,OAAO+C,QAAQ;YAAExF;YAAG,GAAGgG,KAAK,CAAC;YAAE,GAAGA,KAAK,CAAC;QAAC;QACzC,IAAIlC,iBAAiBrB,MAAMkB,OAAOC,KAAK;IACzC;IACA,OAAOnB;AACT"}
|
package/dist/tokens/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { type G9MetricName, G9Metrics, g9MetricUnits } from './generated/metrics
|
|
|
4
4
|
export { G9ColorToken, type G9PaletteValues, g9ColorTokens, g9DarkPalette, g9LightPalette } from './generated/palettes.js';
|
|
5
5
|
export { type G9CornerRadii, type G9CornerRadius, type G9EdgeInsets, type G9FullScreenSheetTopPaddingInput, type G9LayoutMetricOverrides, type G9LayoutMetrics, g9LayoutMetricConstants, g9LayoutMetricDefaults, g9LayoutMetrics, resolveFullScreenSheetTopPadding, resolveLayoutMetrics, } from './layout-metrics.js';
|
|
6
6
|
export { toRootCssVariables } from './root.js';
|
|
7
|
-
export { type G9ControlHeights, type G9Density, type G9ShapeRadii, type G9ShapeSet, type G9ThemeFonts, type G9TypeRole, type G9TypeRoleName, g9DefaultShape, g9DensitySteps, g9MinTouchTarget, resolveShape, toShapeCssVariables, } from './shape.js';
|
|
7
|
+
export { familyForWeight, type G9ControlHeights, type G9Density, type G9FontWeight, type G9FontWeights, type G9ShapeRadii, type G9ShapeSet, type G9ThemeFonts, type G9TypeRole, type G9TypeRoleName, g9DefaultShape, g9DensitySteps, g9FontFamilyFor, g9FontWeights, g9MinTouchTarget, resolveShape, toShapeCssVariables, } from './shape.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,KAAK,cAAc,EACnB,OAAO,EACP,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,eAAe,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACrG,OAAO,EAAE,KAAK,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACxH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gCAAgC,EACrC,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,uBA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K,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
|
package/dist/tokens/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export { G9Metrics, g9MetricUnits } from "./generated/metrics.js";
|
|
|
4
4
|
export { G9ColorToken, g9ColorTokens, g9DarkPalette, g9LightPalette } from "./generated/palettes.js";
|
|
5
5
|
export { g9LayoutMetricConstants, g9LayoutMetricDefaults, g9LayoutMetrics, resolveFullScreenSheetTopPadding, resolveLayoutMetrics } from "./layout-metrics.js";
|
|
6
6
|
export { toRootCssVariables } from "./root.js";
|
|
7
|
-
export { g9DefaultShape, g9DensitySteps, g9MinTouchTarget, resolveShape, toShapeCssVariables } from "./shape.js";
|
|
7
|
+
export { familyForWeight, g9DefaultShape, g9DensitySteps, g9FontFamilyFor, g9FontWeights, g9MinTouchTarget, resolveShape, toShapeCssVariables } from "./shape.js";
|
package/dist/tokens/shape.d.ts
CHANGED
|
@@ -36,7 +36,36 @@ export interface G9ThemeFonts {
|
|
|
36
36
|
readonly arabic?: string;
|
|
37
37
|
/** Numbers and code (`--g9-font-mono`, for the app's own styles). */
|
|
38
38
|
readonly mono?: string;
|
|
39
|
+
/**
|
|
40
|
+
* One family per weight for `latin` (`{ 500: 'InterMedium', 700: 'InterBold' }`): Lynx on Android ignores an
|
|
41
|
+
* `@font-face` weight, so a family that has only its regular file draws 600 and 700 as a synthesised bold. Each G9 text
|
|
42
|
+
* of weight 500, 600, 700 or 800 then reads `--g9-font-text-<weight>`. A weight left out takes the nearest heavier one
|
|
43
|
+
* given, else the nearest lighter, else `latin` itself.
|
|
44
|
+
*/
|
|
45
|
+
readonly latinByWeight?: G9FontWeights;
|
|
46
|
+
/** As {@link G9ThemeFonts.latinByWeight}, for `arabic` (Riskara: `{ 500: 'RkSansMd', 700: 'RkSansBd' }`). */
|
|
47
|
+
readonly arabicByWeight?: G9FontWeights;
|
|
48
|
+
/** As {@link G9ThemeFonts.latinByWeight}, for `mono` (`--g9-font-mono-<weight>`). */
|
|
49
|
+
readonly monoByWeight?: G9FontWeights;
|
|
39
50
|
}
|
|
51
|
+
/** The weights a theme can give a family of its own (400 is the script's base family). */
|
|
52
|
+
export type G9FontWeight = 500 | 600 | 700 | 800;
|
|
53
|
+
/** A family per weight (see {@link G9ThemeFonts.latinByWeight}). */
|
|
54
|
+
export type G9FontWeights = {
|
|
55
|
+
readonly [W in G9FontWeight]?: string;
|
|
56
|
+
};
|
|
57
|
+
/** The weights every G9 text style can ask a family for. */
|
|
58
|
+
export declare const g9FontWeights: readonly G9FontWeight[];
|
|
59
|
+
/**
|
|
60
|
+
* The family for `weight` from a base family and its per-weight families: the exact one, else the nearest heavier
|
|
61
|
+
* given, else the nearest lighter, else the base. Undefined when there is no family at all (the platform's font).
|
|
62
|
+
*/
|
|
63
|
+
export declare function familyForWeight(weight: 400 | G9FontWeight, base: string | undefined, byWeight: G9FontWeights | undefined): string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* The `font-family` value for a G9 text of `weight` in a style written in code (an inline style): the provider's
|
|
66
|
+
* per-weight variable (`var(--g9-font-text-700)`), or the base one for 400 and lighter.
|
|
67
|
+
*/
|
|
68
|
+
export declare function g9FontFamilyFor(weight: number | 'bold' | 'normal'): string;
|
|
40
69
|
/** A named density step (LC-07): the three control heights move together. */
|
|
41
70
|
export type G9Density = 'compact' | 'regular' | 'comfortable';
|
|
42
71
|
/** What each density step adds to every control height, in dp (`regular` is the stock look). */
|
|
@@ -67,8 +96,9 @@ export declare const g9DefaultShape: G9ShapeSet;
|
|
|
67
96
|
export declare function resolveShape(over: Partial<G9ShapeSet> | undefined, base?: G9ShapeSet): G9ShapeSet;
|
|
68
97
|
/**
|
|
69
98
|
* CSS variables of a shape: `--g9-radius-<role>`, `--g9-type-<role>-size|line|weight`, `--g9-height-sm|md|lg`,
|
|
70
|
-
* `--g9-touch-target` (all px), and `--g9-font-latin|arabic|mono` for the families a theme
|
|
71
|
-
* also `--g9-font-text`: the
|
|
99
|
+
* `--g9-touch-target` (all px), and `--g9-font-latin|arabic|mono` (plus `-500|600|700|800`) for the families a theme
|
|
100
|
+
* names. With a `direction`, also `--g9-font-text` and `--g9-font-text-500|600|700|800`: the families of that direction's
|
|
101
|
+
* script (what every G9 text style reads, by its weight).
|
|
72
102
|
*/
|
|
73
103
|
export declare function toShapeCssVariables(shape: G9ShapeSet, direction?: 'ltr' | 'rtl'): Readonly<Record<string, string>>;
|
|
74
104
|
//# sourceMappingURL=shape.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../src/tokens/shape.ts"],"names":[],"mappings":"AAMA,mCAAmC;AACnC,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,iEAAiE;AACjE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAC9C;AAED,6FAA6F;AA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eights = [
|
|
3
|
+
500,
|
|
4
|
+
600,
|
|
5
|
+
700,
|
|
6
|
+
800
|
|
7
|
+
];
|
|
8
|
+
const FONT_TEXT_VAR = {
|
|
9
|
+
500: '--g9-font-text-500',
|
|
10
|
+
600: '--g9-font-text-600',
|
|
11
|
+
700: '--g9-font-text-700',
|
|
12
|
+
800: '--g9-font-text-800'
|
|
13
|
+
};
|
|
14
|
+
function familyForWeight(weight, base, byWeight) {
|
|
15
|
+
var _ref, _given_find;
|
|
16
|
+
if (400 === weight || !byWeight) return base || void 0;
|
|
17
|
+
const given = g9FontWeights.filter((w)=>'string' == typeof byWeight[w] && byWeight[w]);
|
|
18
|
+
const pick = null != (_ref = null != (_given_find = given.find((w)=>w === weight)) ? _given_find : given.find((w)=>w > weight)) ? _ref : [
|
|
19
|
+
...given
|
|
20
|
+
].reverse().find((w)=>w < weight);
|
|
21
|
+
return (pick ? byWeight[pick] : base) || void 0;
|
|
22
|
+
}
|
|
23
|
+
function g9FontFamilyFor(weight) {
|
|
24
|
+
const w = 'bold' === weight ? 700 : 'normal' === weight ? 400 : weight;
|
|
25
|
+
if (w < 500) return 'var(--g9-font-text)';
|
|
26
|
+
return `var(${FONT_TEXT_VAR[w >= 800 ? 800 : w >= 700 ? 700 : w >= 600 ? 600 : 500]})`;
|
|
27
|
+
}
|
|
2
28
|
const g9DensitySteps = Object.freeze({
|
|
3
29
|
compact: -4,
|
|
4
30
|
regular: 0,
|
|
@@ -103,7 +129,6 @@ function resolveShape(over, base = g9DefaultShape) {
|
|
|
103
129
|
}
|
|
104
130
|
function toShapeCssVariables(shape, direction) {
|
|
105
131
|
var _shape_fonts;
|
|
106
|
-
var _shape_fonts1, _shape_fonts2;
|
|
107
132
|
const out = {};
|
|
108
133
|
for (const [k, v] of Object.entries(shape.radii))out[`--g9-radius-${toKebabCase(k)}`] = `${v}px`;
|
|
109
134
|
for (const [k, v] of Object.entries(shape.type)){
|
|
@@ -113,11 +138,30 @@ function toShapeCssVariables(shape, direction) {
|
|
|
113
138
|
}
|
|
114
139
|
for (const [k, v] of Object.entries(shape.heights))out[`--g9-height-${k}`] = `${v}px`;
|
|
115
140
|
out['--g9-touch-target'] = `${shape.touchTarget}px`;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
141
|
+
const fonts = null != (_shape_fonts = shape.fonts) ? _shape_fonts : {};
|
|
142
|
+
for (const script of [
|
|
143
|
+
'latin',
|
|
144
|
+
'arabic',
|
|
145
|
+
'mono'
|
|
146
|
+
]){
|
|
147
|
+
const family = fonts[script];
|
|
148
|
+
if ('string' == typeof family && family) out[`--g9-font-${script}`] = family;
|
|
149
|
+
for (const w of g9FontWeights){
|
|
150
|
+
const f = familyForWeight(w, family, fonts[`${script}ByWeight`]);
|
|
151
|
+
if (f) out[`--g9-font-${script}-${w}`] = f;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const script = 'rtl' === direction ? 'arabic' : 'ltr' === direction ? 'latin' : void 0;
|
|
155
|
+
if (script) {
|
|
156
|
+
const text = fonts[script];
|
|
157
|
+
if (text) out['--g9-font-text'] = text;
|
|
158
|
+
for (const w of g9FontWeights){
|
|
159
|
+
const f = familyForWeight(w, text, fonts[`${script}ByWeight`]);
|
|
160
|
+
if (f) out[FONT_TEXT_VAR[w]] = f;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
119
163
|
return out;
|
|
120
164
|
}
|
|
121
|
-
export { g9DefaultShape, g9DensitySteps, g9MinTouchTarget, resolveShape, toShapeCssVariables };
|
|
165
|
+
export { familyForWeight, g9DefaultShape, g9DensitySteps, g9FontFamilyFor, g9FontWeights, g9MinTouchTarget, resolveShape, toShapeCssVariables };
|
|
122
166
|
|
|
123
167
|
//# sourceMappingURL=shape.js.map
|
package/dist/tokens/shape.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens/shape.js","sources":["../../src/tokens/shape.ts"],"sourcesContent":["// The shape of a theme: corner radii, the type roles and the three control heights. With the palette this is the whole\n// look of a template (ShopManager's ShapeSet + CONTROL_HEIGHTS, SAC's radii, G9Hub's rounded-* scale): a recipe or an\n// app swaps shapes, every control reads them through CSS variables (`var(--g9-radius-card)`), so a shape change repaints\n// without a React render.\nimport { toKebabCase } from './css-vars';\n\n/** Corner radii by role, in dp. */\nexport interface G9ShapeRadii {\n readonly control: number;\n readonly field: number;\n readonly chip: number;\n readonly card: number;\n readonly sheet: number;\n readonly dialog: number;\n readonly toast: number;\n /** A pill: half the height (a large value). */\n readonly pill: number;\n}\n\n/** A type role: size and line height in dp, a weight 400…800. */\nexport interface G9TypeRole {\n readonly size: number;\n readonly lineHeight: number;\n readonly weight: 400 | 500 | 600 | 700 | 800;\n}\n\n/** A role of the type scale (display, title, section, body, label, caption, price, mono). */\nexport type G9TypeRoleName = 'display' | 'title' | 'section' | 'body' | 'label' | 'caption' | 'price' | 'mono';\n\n/** The three heights every control family shares (button, field, segmented, stepper, chip in its large size). */\nexport interface G9ControlHeights {\n readonly sm: number;\n readonly md: number;\n readonly lg: number;\n}\n\n/**\n * Font families of a theme, per script (LC-07). Unset: the platform's own (the stock look). Every G9 text reads\n * `var(--g9-font-text)`, which a right-to-left root takes from `arabic` and a left-to-right one from `latin`; no letter\n * spacing is ever added to Arabic script (`.g9-dir-rtl` sets it to 0).\n */\nexport interface G9ThemeFonts {\n /** Latin and the other left-to-right scripts. */\n readonly latin?: string;\n /** Arabic script (Persian, Arabic, Urdu): the font of a right-to-left culture. */\n readonly arabic?: string;\n /** Numbers and code (`--g9-font-mono`, for the app's own styles). */\n readonly mono?: string;\n}\n\n/** A named density step (LC-07): the three control heights move together. */\nexport type G9Density = 'compact' | 'regular' | 'comfortable';\n\n/** What each density step adds to every control height, in dp (`regular` is the stock look). */\nexport const g9DensitySteps: Readonly<Record<G9Density, number>> = Object.freeze({\n compact: -4,\n regular: 0,\n comfortable: 8,\n});\n\n/** The platform's minimum touch target in dp: no density or override takes `touchTarget` under it. */\nexport const g9MinTouchTarget = 44;\n\n/** A theme's shape: corner radii per role, the type scale and the three control heights. */\nexport interface G9ShapeSet {\n readonly radii: G9ShapeRadii;\n readonly type: { readonly [K in G9TypeRoleName]: G9TypeRole };\n readonly heights: G9ControlHeights;\n /** Minimum touch target (oracles flag smaller interactive elements). Default 44, never under {@link g9MinTouchTarget}. */\n readonly touchTarget: number;\n /** Font families per script; unset: the platform's own. */\n readonly fonts?: G9ThemeFonts;\n /** The density step the heights stand at. Default `regular`. */\n readonly density?: G9Density;\n}\n\n/** The default shape: 12 px controls and fields, 16 px cards, 24 px sheets, the type scale and heights 36 / 44 / 52. */\nexport const g9DefaultShape: G9ShapeSet = Object.freeze({\n radii: Object.freeze({ control: 12, field: 12, chip: 999, card: 16, sheet: 24, dialog: 20, toast: 14, pill: 999 }),\n type: Object.freeze({\n display: { size: 28, lineHeight: 40, weight: 800 },\n title: { size: 20, lineHeight: 30, weight: 700 },\n section: { size: 16, lineHeight: 26, weight: 700 },\n body: { size: 14, lineHeight: 24, weight: 400 },\n label: { size: 14, lineHeight: 20, weight: 600 },\n caption: { size: 12, lineHeight: 18, weight: 400 },\n price: { size: 16, lineHeight: 24, weight: 700 },\n mono: { size: 13, lineHeight: 20, weight: 500 },\n }),\n heights: Object.freeze({ sm: 40, md: 44, lg: 52 }),\n touchTarget: 44,\n}) as G9ShapeSet;\n\n/**\n * A shape with some parts replaced (deep for radii, type roles, heights and fonts). A `density` moves the base's three\n * heights together by the step's difference from the base's own step (explicit `heights` still win, part by part);\n * `touchTarget` never goes under {@link g9MinTouchTarget}.\n */\nexport function resolveShape(over: Partial<G9ShapeSet> | undefined, base: G9ShapeSet = g9DefaultShape): G9ShapeSet {\n if (!over) return base;\n const density = over.density ?? base.density;\n const shift = g9DensitySteps[density ?? 'regular'] - g9DensitySteps[base.density ?? 'regular'];\n const moved = shift\n ? { sm: base.heights.sm + shift, md: base.heights.md + shift, lg: base.heights.lg + shift }\n : base.heights;\n const fonts = over.fonts || base.fonts ? Object.freeze({ ...base.fonts, ...over.fonts }) : undefined;\n return Object.freeze({\n radii: Object.freeze({ ...base.radii, ...over.radii }),\n type: Object.freeze({ ...base.type, ...over.type }),\n heights: Object.freeze({ ...moved, ...over.heights }),\n touchTarget: Math.max(g9MinTouchTarget, over.touchTarget ?? base.touchTarget),\n ...(fonts ? { fonts } : {}),\n ...(density ? { density } : {}),\n });\n}\n\n/**\n * CSS variables of a shape: `--g9-radius-<role>`, `--g9-type-<role>-size|line|weight`, `--g9-height-sm|md|lg`,\n * `--g9-touch-target` (all px), and `--g9-font-latin|arabic|mono` for the families a theme names. With a `direction`,\n * also `--g9-font-text`: the family of that direction's script (what every G9 text style reads).\n */\nexport function toShapeCssVariables(shape: G9ShapeSet, direction?: 'ltr' | 'rtl'): Readonly<Record<string, string>> {\n const out: Record<string, string> = {};\n for (const [k, v] of Object.entries(shape.radii)) out[`--g9-radius-${toKebabCase(k)}`] = `${v}px`;\n for (const [k, v] of Object.entries(shape.type)) {\n out[`--g9-type-${k}-size`] = `${v.size}px`;\n out[`--g9-type-${k}-line`] = `${v.lineHeight}px`;\n out[`--g9-type-${k}-weight`] = String(v.weight);\n }\n for (const [k, v] of Object.entries(shape.heights)) out[`--g9-height-${k}`] = `${v}px`;\n out['--g9-touch-target'] = `${shape.touchTarget}px`;\n // only the families a theme names: unset, a text keeps the platform's font (the stock look is untouched)\n for (const [script, family] of Object.entries(shape.fonts ?? {}))\n if (typeof family === 'string' && family) out[`--g9-font-${script}`] = family;\n // the font every G9 text reads, as a literal: native Lynx does not resolve a variable a stylesheet rule defines from\n // another one (`--a: var(--b)` stayed unresolved on the A21s), so the provider writes it for its root's direction\n const text = direction === 'rtl' ? shape.fonts?.arabic : direction === 'ltr' ? shape.fonts?.latin : undefined;\n if (text) out['--g9-font-text'] = text;\n return out;\n}\n"],"names":["g9DensitySteps","Object","g9MinTouchTarget","g9DefaultShape","resolveShape","over","base","_over_density","_base_density","_over_touchTarget","density","shift","moved","fonts","undefined","Math","toShapeCssVariables","shape","direction","_sh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AAC,UAAU,EAAEC,EAAE,KAAK,CAAC,CAAC,GAAG,GAAGC,EAAE,IAAI,CAAC,EAAE,CAAC;QAC1CF,GAAG,CAAC,CAAC,UAAU,EAAEC,EAAE,KAAK,CAAC,CAAC,GAAG,GAAGC,EAAE,UAAU,CAAC,EAAE,CAAC;QAChDF,GAAG,CAAC,CAAC,UAAU,EAAEC,EAAE,OAAO,CAAC,CAAC,GAAGG,OAAOF,EAAE,MAAM;IAChD;IACA,KAAK,MAAM,CAACD,GAAGC,EAAE,IAAIvB,OAAO,OAAO,CAACgB,MAAM,OAAO,EAAGK,GAAG,CAAC,CAAC,YAAY,EAAEC,GAAG,CAAC,GAAG,GAAGC,EAAE,EAAE,CAAC;IACtFF,GAAG,CAAC,oBAAoB,GAAG,GAAGL,MAAM,WAAW,CAAC,EAAE,CAAC;IAEnD,KAAK,MAAM,CAACU,QAAQC,OAAO,IAAI3B,OAAO,OAAO,CAAC,QAAAkB,CAAAA,eAAAA,MAAM,KAAK,AAAD,IAAVA,eAAe,CAAC,GAC5D,IAAI,AAAkB,YAAlB,OAAOS,UAAuBA,QAAQN,GAAG,CAAC,CAAC,UAAU,EAAEK,QAAQ,CAAC,GAAGC;IAGzE,MAAMC,OAAOX,AAAc,UAAdA,YAAsB,QAAAE,CAAAA,gBAAAA,MAAM,KAAK,AAAD,IAAVA,KAAAA,IAAAA,cAAa,MAAM,GAAGF,AAAc,UAAdA,YAAsB,QAAAG,CAAAA,gBAAAA,MAAM,KAAK,AAAD,IAAVA,KAAAA,IAAAA,cAAa,KAAK,GAAGP;IACpG,IAAIe,MAAMP,GAAG,CAAC,iBAAiB,GAAGO;IAClC,OAAOP;AACT"}
|
|
1
|
+
{"version":3,"file":"tokens/shape.js","sources":["../../src/tokens/shape.ts"],"sourcesContent":["// The shape of a theme: corner radii, the type roles and the three control heights. With the palette this is the whole\n// look of a template (ShopManager's ShapeSet + CONTROL_HEIGHTS, SAC's radii, G9Hub's rounded-* scale): a recipe or an\n// app swaps shapes, every control reads them through CSS variables (`var(--g9-radius-card)`), so a shape change repaints\n// without a React render.\nimport { toKebabCase } from './css-vars';\n\n/** Corner radii by role, in dp. */\nexport interface G9ShapeRadii {\n readonly control: number;\n readonly field: number;\n readonly chip: number;\n readonly card: number;\n readonly sheet: number;\n readonly dialog: number;\n readonly toast: number;\n /** A pill: half the height (a large value). */\n readonly pill: number;\n}\n\n/** A type role: size and line height in dp, a weight 400…800. */\nexport interface G9TypeRole {\n readonly size: number;\n readonly lineHeight: number;\n readonly weight: 400 | 500 | 600 | 700 | 800;\n}\n\n/** A role of the type scale (display, title, section, body, label, caption, price, mono). */\nexport type G9TypeRoleName = 'display' | 'title' | 'section' | 'body' | 'label' | 'caption' | 'price' | 'mono';\n\n/** The three heights every control family shares (button, field, segmented, stepper, chip in its large size). */\nexport interface G9ControlHeights {\n readonly sm: number;\n readonly md: number;\n readonly lg: number;\n}\n\n/**\n * Font families of a theme, per script (LC-07). Unset: the platform's own (the stock look). Every G9 text reads\n * `var(--g9-font-text)`, which a right-to-left root takes from `arabic` and a left-to-right one from `latin`; no letter\n * spacing is ever added to Arabic script (`.g9-dir-rtl` sets it to 0).\n */\nexport interface G9ThemeFonts {\n /** Latin and the other left-to-right scripts. */\n readonly latin?: string;\n /** Arabic script (Persian, Arabic, Urdu): the font of a right-to-left culture. */\n readonly arabic?: string;\n /** Numbers and code (`--g9-font-mono`, for the app's own styles). */\n readonly mono?: string;\n /**\n * One family per weight for `latin` (`{ 500: 'InterMedium', 700: 'InterBold' }`): Lynx on Android ignores an\n * `@font-face` weight, so a family that has only its regular file draws 600 and 700 as a synthesised bold. Each G9 text\n * of weight 500, 600, 700 or 800 then reads `--g9-font-text-<weight>`. A weight left out takes the nearest heavier one\n * given, else the nearest lighter, else `latin` itself.\n */\n readonly latinByWeight?: G9FontWeights;\n /** As {@link G9ThemeFonts.latinByWeight}, for `arabic` (Riskara: `{ 500: 'RkSansMd', 700: 'RkSansBd' }`). */\n readonly arabicByWeight?: G9FontWeights;\n /** As {@link G9ThemeFonts.latinByWeight}, for `mono` (`--g9-font-mono-<weight>`). */\n readonly monoByWeight?: G9FontWeights;\n}\n\n/** The weights a theme can give a family of its own (400 is the script's base family). */\nexport type G9FontWeight = 500 | 600 | 700 | 800;\n\n/** A family per weight (see {@link G9ThemeFonts.latinByWeight}). */\nexport type G9FontWeights = { readonly [W in G9FontWeight]?: string };\n\n/** The weights every G9 text style can ask a family for. */\nexport const g9FontWeights: readonly G9FontWeight[] = [500, 600, 700, 800];\n\n/** The variable each weight's family is written to, spelled out (the stylesheets read these names). */\nconst FONT_TEXT_VAR: Readonly<Record<G9FontWeight, string>> = {\n 500: '--g9-font-text-500',\n 600: '--g9-font-text-600',\n 700: '--g9-font-text-700',\n 800: '--g9-font-text-800',\n};\n\n/**\n * The family for `weight` from a base family and its per-weight families: the exact one, else the nearest heavier\n * given, else the nearest lighter, else the base. Undefined when there is no family at all (the platform's font).\n */\nexport function familyForWeight(\n weight: 400 | G9FontWeight,\n base: string | undefined,\n byWeight: G9FontWeights | undefined,\n): string | undefined {\n if (weight === 400 || !byWeight) return base || undefined;\n const given = g9FontWeights.filter((w) => typeof byWeight[w] === 'string' && byWeight[w]);\n const pick =\n given.find((w) => w === weight) ?? given.find((w) => w > weight) ?? [...given].reverse().find((w) => w < weight);\n return (pick ? byWeight[pick] : base) || undefined;\n}\n\n/**\n * The `font-family` value for a G9 text of `weight` in a style written in code (an inline style): the provider's\n * per-weight variable (`var(--g9-font-text-700)`), or the base one for 400 and lighter.\n */\nexport function g9FontFamilyFor(weight: number | 'bold' | 'normal'): string {\n const w = weight === 'bold' ? 700 : weight === 'normal' ? 400 : weight;\n if (w < 500) return 'var(--g9-font-text)';\n return `var(${FONT_TEXT_VAR[w >= 800 ? 800 : w >= 700 ? 700 : w >= 600 ? 600 : 500]})`;\n}\n\n/** A named density step (LC-07): the three control heights move together. */\nexport type G9Density = 'compact' | 'regular' | 'comfortable';\n\n/** What each density step adds to every control height, in dp (`regular` is the stock look). */\nexport const g9DensitySteps: Readonly<Record<G9Density, number>> = Object.freeze({\n compact: -4,\n regular: 0,\n comfortable: 8,\n});\n\n/** The platform's minimum touch target in dp: no density or override takes `touchTarget` under it. */\nexport const g9MinTouchTarget = 44;\n\n/** A theme's shape: corner radii per role, the type scale and the three control heights. */\nexport interface G9ShapeSet {\n readonly radii: G9ShapeRadii;\n readonly type: { readonly [K in G9TypeRoleName]: G9TypeRole };\n readonly heights: G9ControlHeights;\n /** Minimum touch target (oracles flag smaller interactive elements). Default 44, never under {@link g9MinTouchTarget}. */\n readonly touchTarget: number;\n /** Font families per script; unset: the platform's own. */\n readonly fonts?: G9ThemeFonts;\n /** The density step the heights stand at. Default `regular`. */\n readonly density?: G9Density;\n}\n\n/** The default shape: 12 px controls and fields, 16 px cards, 24 px sheets, the type scale and heights 36 / 44 / 52. */\nexport const g9DefaultShape: G9ShapeSet = Object.freeze({\n radii: Object.freeze({ control: 12, field: 12, chip: 999, card: 16, sheet: 24, dialog: 20, toast: 14, pill: 999 }),\n type: Object.freeze({\n display: { size: 28, lineHeight: 40, weight: 800 },\n title: { size: 20, lineHeight: 30, weight: 700 },\n section: { size: 16, lineHeight: 26, weight: 700 },\n body: { size: 14, lineHeight: 24, weight: 400 },\n label: { size: 14, lineHeight: 20, weight: 600 },\n caption: { size: 12, lineHeight: 18, weight: 400 },\n price: { size: 16, lineHeight: 24, weight: 700 },\n mono: { size: 13, lineHeight: 20, weight: 500 },\n }),\n heights: Object.freeze({ sm: 40, md: 44, lg: 52 }),\n touchTarget: 44,\n}) as G9ShapeSet;\n\n/**\n * A shape with some parts replaced (deep for radii, type roles, heights and fonts). A `density` moves the base's three\n * heights together by the step's difference from the base's own step (explicit `heights` still win, part by part);\n * `touchTarget` never goes under {@link g9MinTouchTarget}.\n */\nexport function resolveShape(over: Partial<G9ShapeSet> | undefined, base: G9ShapeSet = g9DefaultShape): G9ShapeSet {\n if (!over) return base;\n const density = over.density ?? base.density;\n const shift = g9DensitySteps[density ?? 'regular'] - g9DensitySteps[base.density ?? 'regular'];\n const moved = shift\n ? { sm: base.heights.sm + shift, md: base.heights.md + shift, lg: base.heights.lg + shift }\n : base.heights;\n const fonts = over.fonts || base.fonts ? Object.freeze({ ...base.fonts, ...over.fonts }) : undefined;\n return Object.freeze({\n radii: Object.freeze({ ...base.radii, ...over.radii }),\n type: Object.freeze({ ...base.type, ...over.type }),\n heights: Object.freeze({ ...moved, ...over.heights }),\n touchTarget: Math.max(g9MinTouchTarget, over.touchTarget ?? base.touchTarget),\n ...(fonts ? { fonts } : {}),\n ...(density ? { density } : {}),\n });\n}\n\n/**\n * CSS variables of a shape: `--g9-radius-<role>`, `--g9-type-<role>-size|line|weight`, `--g9-height-sm|md|lg`,\n * `--g9-touch-target` (all px), and `--g9-font-latin|arabic|mono` (plus `-500|600|700|800`) for the families a theme\n * names. With a `direction`, also `--g9-font-text` and `--g9-font-text-500|600|700|800`: the families of that direction's\n * script (what every G9 text style reads, by its weight).\n */\nexport function toShapeCssVariables(shape: G9ShapeSet, direction?: 'ltr' | 'rtl'): Readonly<Record<string, string>> {\n const out: Record<string, string> = {};\n for (const [k, v] of Object.entries(shape.radii)) out[`--g9-radius-${toKebabCase(k)}`] = `${v}px`;\n for (const [k, v] of Object.entries(shape.type)) {\n out[`--g9-type-${k}-size`] = `${v.size}px`;\n out[`--g9-type-${k}-line`] = `${v.lineHeight}px`;\n out[`--g9-type-${k}-weight`] = String(v.weight);\n }\n for (const [k, v] of Object.entries(shape.heights)) out[`--g9-height-${k}`] = `${v}px`;\n out['--g9-touch-target'] = `${shape.touchTarget}px`;\n // only the families a theme names: unset, a text keeps the platform's font (the stock look is untouched)\n const fonts = shape.fonts ?? {};\n for (const script of ['latin', 'arabic', 'mono'] as const) {\n const family = fonts[script];\n if (typeof family === 'string' && family) out[`--g9-font-${script}`] = family;\n for (const w of g9FontWeights) {\n const f = familyForWeight(w, family, fonts[`${script}ByWeight`]);\n if (f) out[`--g9-font-${script}-${w}`] = f;\n }\n }\n // the font every G9 text reads, as a literal: native Lynx does not resolve a variable a stylesheet rule defines from\n // another one (`--a: var(--b)` stayed unresolved on the A21s), so the provider writes it for its root's direction\n const script = direction === 'rtl' ? 'arabic' : direction === 'ltr' ? 'latin' : undefined;\n if (script) {\n const text = fonts[script];\n if (text) out['--g9-font-text'] = text;\n // one literal per weight as well (a G9 text of weight 500 to 800 reads its own; see G9ThemeFonts.latinByWeight)\n for (const w of g9FontWeights) {\n const f = familyForWeight(w, text, fonts[`${script}ByWeight`]);\n if (f) out[FONT_TEXT_VAR[w]] = f;\n }\n }\n return out;\n}\n"],"names":["g9FontWeights","FONT_TEXT_VAR","familyForWeight","weight","base","byWeight","_ref","undefined","given","w","pick","g9FontFamilyFor","g9DensitySteps","Object","g9MinTouchTarget","g9DefaultShape","resolveShape","over","_over_density","_base_density","_over_touchTarget","density","shift","moved","fonts","Math","toShapeCssVariables","shape","direction","_shape_fonts","out","k","v","toKebabCase","String","script","family","f","text"],"mappings":";AAoEO,MAAMA,gBAAyC;IAAC;IAAK;IAAK;IAAK;CAAI;AAG1E,MAAMC,gBAAwD;IAC5D,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;AACP;AAMO,SAASC,gBACdC,MAA0B,EAC1BC,IAAwB,EACxBC,QAAmC;QAKjCC,MAAAA;IAHF,IAAIH,AAAW,QAAXA,UAAkB,CAACE,UAAU,OAAOD,QAAQG;IAChD,MAAMC,QAAQR,cAAc,MAAM,CAAC,CAACS,IAAM,AAAuB,YAAvB,OAAOJ,QAAQ,CAACI,EAAE,IAAiBJ,QAAQ,CAACI,EAAE;IACxF,MAAMC,OAAAA,QACJJ,CAAAA,OAAAA,QAAAA,CAAAA,cAAAA,MAAM,IAAI,CAAC,CAACG,IAAMA,MAAMN,OAAM,IAA9BG,cAAmCE,MAAM,IAAI,CAAC,CAACC,IAAMA,IAAIN,OAAM,IAA/DG,OAAoE;WAAIE;KAAM,CAAC,OAAO,GAAG,IAAI,CAAC,CAACC,IAA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G,CAAC,CAAC,UAAU,EAAEK,OAAO,CAAC,EAAE1B,GAAG,CAAC,GAAG4B;QAC3C;IACF;IAGA,MAAMF,SAASP,AAAc,UAAdA,YAAsB,WAAWA,AAAc,UAAdA,YAAsB,UAAUrB;IAChF,IAAI4B,QAAQ;QACV,MAAMG,OAAOd,KAAK,CAACW,OAAO;QAC1B,IAAIG,MAAMR,GAAG,CAAC,iBAAiB,GAAGQ;QAElC,KAAK,MAAM7B,KAAKT,cAAe;YAC7B,MAAMqC,IAAInC,gBAAgBO,GAAG6B,MAAMd,KAAK,CAAC,GAAGW,OAAO,QAAQ,CAAC,CAAC;YAC7D,IAAIE,GAAGP,GAAG,CAAC7B,aAAa,CAACQ,EAAE,CAAC,GAAG4B;QACjC;IACF;IACA,OAAOP;AACT"}
|
package/docs/api.md
CHANGED
|
@@ -10,6 +10,8 @@ folder) explain how the pieces fit; the migration tables map every MAUI member.
|
|
|
10
10
|
| --- | --- | --- |
|
|
11
11
|
| `cssVariableName` | function | CSS variable of a colour token: `Primary` → `--g9-primary` (plan/specs/01-Architecture.md §6). |
|
|
12
12
|
| `cssVariablesToText` | function | Renders variables as CSS declarations inside `selector`, one per line (e.g. for a generated stylesheet). |
|
|
13
|
+
| `familyForWeight` | function | The family for `weight` from a base family and its per-weight families: the exact one, else the nearest heavier given, else the nearest lighter, else the base. Undefined when there is no family at all (the platform's font). |
|
|
14
|
+
| `g9FontFamilyFor` | function | The `font-family` value for a G9 text of `weight` in a style written in code (an inline style): the provider's per-weight variable (`var(--g9-font-text-700)`), or the base one for 400 and lighter. |
|
|
13
15
|
| `g9Token` | function | A colour usable in any G9 colour prop or stylesheet that follows the active theme: `g9Token('Primary')` is `var(--g9-primary)`. Replaces the MAUI `{G9Color Primary}` markup extension. |
|
|
14
16
|
| `layoutCssVariableName` | function | CSS variable of a layout metric: `EdgeSpacing` → `--g9-layout-edge-spacing`. Insets and corner radii are emitted per side/corner, e.g. `--g9-layout-body-padding-start`, `--g9-layout-map-chrome-corner-radius-top-end`. |
|
|
15
17
|
| `metricCssVariableName` | function | CSS variable of a `G9Metrics` value: `RadiusMd` → `--g9-metric-radius-md`. |
|
|
@@ -23,13 +25,14 @@ folder) explain how the pieces fit; the migration tables map every MAUI member.
|
|
|
23
25
|
| `toLayoutCssVariables` | function | The layout metrics as CSS variables (the counterpart of MAUI `G9LayoutMetrics.InstallDefaults`, which seeded the resource keys XAML bound to). Lengths get `px`, `DeferredContentLoadDelayMs` gets `ms`, counts and ratios none. |
|
|
24
26
|
| `toMetricCssVariables` | function | One `--g9-metric-<name>` variable per `G9Metrics` value, with its unit (`px`, `ms` or none). |
|
|
25
27
|
| `toRootCssVariables` | function | Every CSS variable a `G9Provider` root carries for a theme, a shape and a direction: the metrics (`--g9-metric-*`), the layout metrics (`--g9-layout-*`), the shape (`--g9-radius-*`, `--g9-type-*`, `--g9-height-*`, `--g9-touch-target`, the fonts), the colour tokens and the derived colours. What the provider writes at mount (less a theme's token aliases), so a page outside Lynx — the static-render contract of `@g9tm/lynxcontrols-web/static` — reads the same values the app does. |
|
|
26
|
-
| `toShapeCssVariables` | function | CSS variables of a shape: `--g9-radius-<role>`, `--g9-type-<role>-size\|line\|weight`, `--g9-height-sm\|md\|lg`, `--g9-touch-target` (all px), and `--g9-font-latin\|arabic\|mono` for the families a theme names. With a `direction`, also `--g9-font-text`: the
|
|
28
|
+
| `toShapeCssVariables` | function | CSS variables of a shape: `--g9-radius-<role>`, `--g9-type-<role>-size\|line\|weight`, `--g9-height-sm\|md\|lg`, `--g9-touch-target` (all px), and `--g9-font-latin\|arabic\|mono` (plus `-500\|600\|700\|800`) for the families a theme names. With a `direction`, also `--g9-font-text` and `--g9-font-text-500\|600\|700\|800`: the families of that direction's script (what every G9 text style reads, by its weight). |
|
|
27
29
|
| `G9ColorToken` | enum | The colour tokens of the G9 theme in MAUI declaration order (MAUI `G9ColorToken`). Values keep the MAUI names so `G9ColorToken.Primary === 'Primary'`; the CSS variable is `--g9-primary` (see `cssVariableName`). |
|
|
28
30
|
| `g9ColorTokens` | constant | Every token, in declaration order. |
|
|
29
31
|
| `g9DarkPalette` | constant | The stock dark palette (MAUI `G9Theme.Dark.xaml`). |
|
|
30
32
|
| `g9DefaultShape` | constant | The default shape: 12 px controls and fields, 16 px cards, 24 px sheets, the type scale and heights 36 / 44 / 52. |
|
|
31
33
|
| `g9DensitySteps` | constant | What each density step adds to every control height, in dp (`regular` is the stock look). |
|
|
32
34
|
| `g9Derived` | constant | The derived variables, as `var(...)` references (what controls write into their styles). |
|
|
35
|
+
| `g9FontWeights` | constant | The weights every G9 text style can ask a family for. |
|
|
33
36
|
| `g9GradientTokens` | constant | The tokens a solid button paints as a soft vertical gradient (MAUI `BuildSolidOrGradient`). |
|
|
34
37
|
| `g9LayoutMetricConstants` | constant | Compile-time constants of MAUI `G9LayoutMetrics`: never read from resources, so not overridable. |
|
|
35
38
|
| `g9LayoutMetricDefaults` | constant | The layout metrics an app may retune (MAUI read these from `Application.Resources` with the literal fallbacks below; the census card `Core.Theming` lists them as `=> D(nameof(X), n)`, `Th(…)` and `Cr(…)`). |
|
|
@@ -49,6 +52,8 @@ folder) explain how the pieces fit; the migration tables map every MAUI member.
|
|
|
49
52
|
| `G9CornerRadius` | type | A corner radius: one value for all four corners, or one per corner. |
|
|
50
53
|
| `G9CssVariables` | type | A set of CSS custom properties: name (`--g9-…`) to value. Feed it to a root element's style or `setProperty`. |
|
|
51
54
|
| `G9Density` | type | A named density step (LC-07): the three control heights move together. |
|
|
55
|
+
| `G9FontWeight` | type | The weights a theme can give a family of its own (400 is the script's base family). |
|
|
56
|
+
| `G9FontWeights` | type | A family per weight (see `G9ThemeFonts.latinByWeight`). |
|
|
52
57
|
| `G9GradientToken` | type | A colour token that has gradient stops (`--g9-<token>-grad-top` / `-grad-bottom`). |
|
|
53
58
|
| `G9LayoutMetricOverrides` | type | Values an app may override; `MapBottomBarMargin` is derived from `MapChromeEdgeSpacing` unless overridden. |
|
|
54
59
|
| `G9LayoutMetrics` | type | Every layout metric, resolved (MAUI `G9LayoutMetrics`). |
|
|
@@ -99,6 +104,7 @@ folder) explain how the pieces fit; the migration tables map every MAUI member.
|
|
|
99
104
|
| `ensureContrast` | function | `fg` moved in lightness (hue and chroma kept) until its WCAG contrast with `bg` is at least `min`. Goes darker on a light background and lighter on a dark one; returns `fg` unchanged when it already passes. If no lightness of this hue reaches `min`, returns black or white, whichever contrasts more. |
|
|
100
105
|
| `exportTheme` | function | A theme as portable JSON (personal themes, sharing, backup). |
|
|
101
106
|
| `fillToCss` | function | A fill as a CSS `background` value: the colour, or `linear-gradient(to bottom, …)`. |
|
|
107
|
+
| `fixedNeutralScale` | function | Neutrals of a fixed hue and chroma, whatever the brand (warm paper, cool steel), on the sine curve's lightness steps (ShopManager's `fixedNeutralScale`). |
|
|
102
108
|
| `formatColor` | function | Formats a colour as CSS: `#RRGGBB` when opaque, otherwise `rgba(R, G, B, A)`. Channels are rounded to the nearest byte; the alpha is printed with the fewest digits that parse back to the same float32 value, so `parseColor(formatColor(c))` reproduces the alpha exactly. |
|
|
103
109
|
| `fromOklch` | function | OKLCH → sRGB (`G9Rgba`, channels 0..1). Out-of-gamut colours keep L and H and lose chroma until they fit (binary search, 18 steps ≈ 1e-6 chroma), so a vivid brand never shifts hue when it is darkened or lightened. |
|
|
104
110
|
| `getContrastingTextColor` | function | Black on light backgrounds (luminance above 0.5), white otherwise. MAUI `GetContrastingTextColor`. |
|
|
@@ -169,10 +175,12 @@ folder) explain how the pieces fit; the migration tables map every MAUI member.
|
|
|
169
175
|
| `G9DesignRegistry` | interface | Pilot's `DesignRegistry`. |
|
|
170
176
|
| `G9DesignRegistryOptions` | interface | What `createDesignRegistry` edits live: the theme store and, when the app allows it, the shape. |
|
|
171
177
|
| `G9DesignToken` | interface | One token as Pilot reads it. |
|
|
178
|
+
| `G9EnsureContrastOptions` | interface | Options of `ensureContrast`. |
|
|
172
179
|
| `G9GradientStop` | interface | A gradient stop: colour at `offset` (`0..1`). |
|
|
173
180
|
| `G9Oklch` | interface | A colour in OKLCH. `alpha` 0..1 (default 1). |
|
|
174
181
|
| `G9ResolvedTheme` | interface | A resolved theme: what is painted and why. Frozen. |
|
|
175
182
|
| `G9Rgba` | interface | A colour as four channels in `0..1`, stored at float32 precision exactly like MAUI `Color`. Colour arithmetic (darken, mix, contrast) runs on this shape so its results match the original helpers bit for bit; format with `formatColor` to get a CSS string back. |
|
|
183
|
+
| `G9ScaleOptions` | interface | Options of `tonalScale` and `neutralScale`. |
|
|
176
184
|
| `G9ThemeDefinition` | interface | One selectable theme. |
|
|
177
185
|
| `G9ThemeOptions` | interface | Inputs of theme resolution. |
|
|
178
186
|
| `G9ThemeRecipe` | interface | A named recipe. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g9tm/lynxcontrols-foundation",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Pure TypeScript core: design tokens, theme model, culture (strings, digits, calendars, relative time, durations), icon model, safe execution, diagnostics, preference and capability contracts. No React, no UI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|