@g9tm/lynxcontrols-foundation 2.5.2 → 2.5.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAClG,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,eAAe,EACf,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,GACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,KAAK,aAAa,EAAE,KAAK,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAClH,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,EACN,WAAW,EACX,KAAK,OAAO,EACZ,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,uBAAuB,EACvB,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,WAAW,EACX,YAAY,EACZ,GAAG,EACH,UAAU,EACV,cAAc,EACd,IAAI,EACJ,KAAK,EACL,MAAM,EACN,aAAa,EACb,SAAS,EACT,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,SAAS,EACT,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,SAAS,EACT,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,GACR,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,WAAW,EACX,cAAc,EACd,KAAK,aAAa,EAClB,SAAS,EACT,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,SAAS,EACT,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAClG,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB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,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,GACR,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,WAAW,EACX,cAAc,EACd,KAAK,aAAa,EAClB,SAAS,EACT,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,SAAS,EACT,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,YAAY,CAAC"}
@@ -6,7 +6,7 @@ export { contrastFailures, contrastReport, g9ContrastRules } from "./contrast.js
6
6
  export { G9Colors, buildSolidOrGradient, checkBoxMark, fillToCss, switchOffTrack, switchOnTrack, switchThumbOff, switchThumbOn } from "./control-colors.js";
7
7
  export { g9Easings, lightnessOf, parseCssColor, resolveColorFunctions, resolveCssColor, resolveEasing } from "./css-color.js";
8
8
  export { createDesignRegistry } from "./design.js";
9
- export { chartPalette, colorDistance, ensureContrast, fromOklch, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, toOklch, tonalScale } from "./oklch.js";
9
+ export { chartPalette, colorDistance, ensureContrast, fixedNeutralScale, fromOklch, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, toOklch, tonalScale } from "./oklch.js";
10
10
  export { brandRecipe, designedRecipe, getRecipe, listRecipes, recipePalettes, registerRecipe } from "./recipe.js";
11
11
  export { G9ColorScheme, G9ThemeMode, createPalette, createThemeStore, g9DefaultThemeSchedule, isScheduledDark, resolveColorScheme, resolveTheme, stockPalette } from "./theme.js";
12
12
  export { hasSwatch, resolveButtonVariant, resolveButtonVariantVars, resolveProgressColor, resolveProgressColorVar } from "./variants.js";
@@ -7,7 +7,9 @@ export interface G9Oklch {
7
7
  readonly alpha?: number;
8
8
  }
9
9
  /** A colour in OKLCH (lightness, chroma, hue): the perceptual space the brand palettes and tonal scales are built in. Cached per string. */
10
- export declare function toOklch(color: G9ColorInput): G9Oklch;
10
+ export declare function toOklch(color: G9ColorInput, options?: {
11
+ readonly curve?: 'even' | 'sine';
12
+ }): G9Oklch;
11
13
  /** True when the OKLCH colour is inside sRGB. */
12
14
  export declare const isInSrgbGamut: (x: G9Oklch) => boolean;
13
15
  /**
@@ -15,8 +17,13 @@ export declare const isInSrgbGamut: (x: G9Oklch) => boolean;
15
17
  * search, 18 steps ≈ 1e-6 chroma), so a vivid brand never shifts hue when it is darkened or lightened.
16
18
  */
17
19
  export declare function fromOklch(x: G9Oklch): G9Rgba;
18
- /** OKLCH → `#RRGGBB` (or `#RRGGBBAA` with alpha < 1). */
19
- export declare const oklchToHex: (x: G9Oklch) => string;
20
+ /**
21
+ * OKLCH → `#RRGGBB` (or `#RRGGBBAA` with alpha < 1). `gamut: 'steps'` maps an out-of-sRGB colour by cutting chroma 10 %
22
+ * at a time (ShopManager's `@g9/tokens`, to the hex; opaque) instead of the default binary search.
23
+ */
24
+ export declare function oklchToHex(x: G9Oklch, options?: {
25
+ readonly gamut?: 'search' | 'steps';
26
+ }): string;
20
27
  /** Steps of a tonal scale (Tailwind-like names: 50 lightest … 950 darkest). */
21
28
  export declare const g9TonalSteps: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
22
29
  /** A step of a tonal scale: 50, 100, 200 … 900, 950. */
@@ -31,12 +38,12 @@ export declare function nearestTonalStep(color: G9ColorInput): G9TonalStep;
31
38
  * A tonal scale from one colour: same hue, lightness from the step table, chroma scaled from the source's. The source
32
39
  * itself is placed exactly at its nearest step, so the brand colour always appears in its own scale unchanged.
33
40
  */
34
- export declare function tonalScale(color: G9ColorInput): G9TonalScale;
41
+ export declare function tonalScale(color: G9ColorInput, options?: G9ScaleOptions): G9TonalScale;
35
42
  /**
36
43
  * A neutral scale tinted by `color`: the brand's hue at a whisper of chroma (`tint` 0 = pure grey, 1 = 0.02 C, the
37
44
  * strongest tint that still reads as grey), so surfaces and text belong to the brand without looking coloured.
38
45
  */
39
- export declare function neutralScale(color: G9ColorInput, tint?: number): G9TonalScale;
46
+ export declare function neutralScale(color: G9ColorInput, tint?: number, options?: G9ScaleOptions): G9TonalScale;
40
47
  /** Perceptual distance (ΔE in OKLab, ×100: about 2 is just noticeable). */
41
48
  export declare function colorDistance(a: G9ColorInput, b: G9ColorInput): number;
42
49
  /**
@@ -44,7 +51,7 @@ export declare function colorDistance(a: G9ColorInput, b: G9ColorInput): number;
44
51
  * light background and lighter on a dark one; returns `fg` unchanged when it already passes. If no lightness of this hue
45
52
  * reaches `min`, returns black or white, whichever contrasts more.
46
53
  */
47
- export declare function ensureContrast(fg: G9ColorInput, bg: G9ColorInput, min: number): string;
54
+ export declare function ensureContrast(fg: G9ColorInput, bg: G9ColorInput, min: number, options?: G9EnsureContrastOptions): string;
48
55
  /** Black or white text, whichever contrasts more with `bg`, nudged toward `tint`'s hue when given. */
49
56
  export declare function readableOn(bg: G9ColorInput, tint?: G9ColorInput): string;
50
57
  /** Linear interpolation in OKLCH (shorter hue arc). `t` 0..1. */
@@ -60,4 +67,27 @@ export declare function interpolateStops(stops: readonly G9ColorInput[], t: numb
60
67
  * stay distinguishable for n ≤ 10; the same inputs always give the same palette.
61
68
  */
62
69
  export declare function chartPalette(primary: G9ColorInput, background: G9ColorInput, n?: number): string[];
70
+ /** Options of {@link tonalScale} and {@link neutralScale}. */
71
+ export interface G9ScaleOptions {
72
+ /**
73
+ * `'even'` (default): the library's step table, chroma scaled per step from the source. `'sine'`: a lighter, cleaner
74
+ * table whose chroma falls off along a sine towards white and black (ShopManager's `@g9/tokens` curve, reproduced to
75
+ * the hex), with gamut mapping by 10 % chroma steps, as that design system measured its recipes against it.
76
+ */
77
+ readonly curve?: 'even' | 'sine';
78
+ }
79
+ /** Options of {@link ensureContrast}. */
80
+ export interface G9EnsureContrastOptions {
81
+ /**
82
+ * `'search'` (default): the closest passing lightness (a binary search), else black or white. `'steps'`: lightness
83
+ * moved in 0.02 steps (darker on a background whose luminance is over 0.18), the first passing step, else the 40th
84
+ * (ShopManager's `@g9/tokens` contrast repair, reproduced to the hex).
85
+ */
86
+ readonly method?: 'search' | 'steps';
87
+ }
88
+ /**
89
+ * Neutrals of a fixed hue and chroma, whatever the brand (warm paper, cool steel), on the sine curve's lightness
90
+ * steps (ShopManager's `fixedNeutralScale`).
91
+ */
92
+ export declare function fixedNeutralScale(hue: number, chroma: number): G9TonalScale;
63
93
  //# sourceMappingURL=oklch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oklch.d.ts","sourceRoot":"","sources":["../../src/theme/oklch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,MAAM,EAAgD,MAAM,SAAS,CAAC;AAEpH,mDAAmD;AACnD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAuCD,4IAA4I;AAC5I,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAUpD;AAoBD,iDAAiD;AACjD,eAAO,MAAM,aAAa,GAAI,GAAG,OAAO,KAAG,OAA+B,CAAC;AAE3E;;;GAGG;AACH,wBAAgB,SAAS,C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MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;CACtC;AAgFD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAI3E"}
@@ -22,7 +22,8 @@ function oklabToLinear(L, a, b) {
22
22
  ];
23
23
  }
24
24
  const OKLCH_CACHE = new Map();
25
- function toOklch(color) {
25
+ function toOklch(color, options) {
26
+ if ((null == options ? void 0 : options.curve) === 'sine') return sineOklch(color);
26
27
  if ('string' == typeof color) {
27
28
  const hit = OKLCH_CACHE.get(color);
28
29
  if (hit) return hit;
@@ -83,7 +84,9 @@ function fromOklch(x) {
83
84
  const ch = (v)=>fromLinear(Math.min(1, Math.max(0, v)));
84
85
  return rgba(ch(r), ch(g), ch(b), null != (_x_alpha = x.alpha) ? _x_alpha : 1);
85
86
  }
86
- const oklchToHex = (x)=>formatColor(fromOklch(x));
87
+ function oklchToHex(x, options) {
88
+ return (null == options ? void 0 : options.gamut) === 'steps' ? sineHex(x) : formatColor(fromOklch(x));
89
+ }
87
90
  const opaque = (color)=>formatColor({
88
91
  ...toRgba(color),
89
92
  a: 1
@@ -133,7 +136,8 @@ function nearestTonalStep(color) {
133
136
  for (const step of g9TonalSteps)if (Math.abs(STEP_L[step] - l) < Math.abs(STEP_L[best] - l)) best = step;
134
137
  return best;
135
138
  }
136
- function tonalScale(color) {
139
+ function tonalScale(color, options) {
140
+ if ((null == options ? void 0 : options.curve) === 'sine') return sineTonalScale(color);
137
141
  const src = toOklch(color);
138
142
  const exact = nearestTonalStep(color);
139
143
  const peak = src.c / STEP_C[exact];
@@ -145,7 +149,8 @@ function tonalScale(color) {
145
149
  });
146
150
  return out;
147
151
  }
148
- function neutralScale(color, tint = 0.5) {
152
+ function neutralScale(color, tint = 0.5, options) {
153
+ if ((null == options ? void 0 : options.curve) === 'sine') return sineNeutralScale(color, tint);
149
154
  const { h } = toOklch(color);
150
155
  const c = 0.02 * Math.min(1, Math.max(0, tint));
151
156
  const out = {};
@@ -163,7 +168,8 @@ function colorDistance(a, b) {
163
168
  const rb = y.h * Math.PI / 180;
164
169
  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
170
  }
166
- function ensureContrast(fg, bg, min) {
171
+ function ensureContrast(fg, bg, min, options) {
172
+ if ((null == options ? void 0 : options.method) === 'steps') return stepContrast(fg, bg, min);
167
173
  if (getContrastRatio(fg, bg) >= min) return opaque(fg);
168
174
  const src = toOklch(fg);
169
175
  const bgL = getLuminance(bg);
@@ -253,6 +259,127 @@ function chartPalette(primary, background, n = 8) {
253
259
  }
254
260
  return out;
255
261
  }
256
- export { chartPalette, colorDistance, ensureContrast, fromOklch, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, toOklch, tonalScale };
262
+ const SINE_L = {
263
+ 50: 0.975,
264
+ 100: 0.945,
265
+ 200: 0.89,
266
+ 300: 0.81,
267
+ 400: 0.715,
268
+ 500: 0.625,
269
+ 600: 0.54,
270
+ 700: 0.455,
271
+ 800: 0.375,
272
+ 900: 0.295,
273
+ 950: 0.225
274
+ };
275
+ function sineOklch(color) {
276
+ const { r, g, b } = toRgba(color);
277
+ const [L, A, B] = linearToOklab(toLinear(r), toLinear(g), toLinear(b));
278
+ const c = Math.sqrt(A * A + B * B);
279
+ return {
280
+ l: L,
281
+ c,
282
+ h: c < 1e-5 ? 0 : (180 * Math.atan2(B, A) / Math.PI + 360) % 360
283
+ };
284
+ }
285
+ function sineHex(x) {
286
+ const fits = (lin)=>lin.every((v)=>v >= -0.0001 && v <= 1.0001);
287
+ let c = x.c;
288
+ let lin = linearOf({
289
+ l: x.l,
290
+ c,
291
+ h: x.h
292
+ });
293
+ for(let i = 0; i < 24 && !fits(lin); i++){
294
+ c *= 0.9;
295
+ lin = linearOf({
296
+ l: x.l,
297
+ c,
298
+ h: x.h
299
+ });
300
+ }
301
+ const ch = (v)=>fromLinear(Math.min(1, Math.max(0, v)));
302
+ return formatColor(rgba(ch(lin[0]), ch(lin[1]), ch(lin[2]), 1));
303
+ }
304
+ function sineBase(color) {
305
+ try {
306
+ return sineOklch(color);
307
+ } catch {
308
+ return {
309
+ l: 0.55,
310
+ c: 0.15,
311
+ h: 280
312
+ };
313
+ }
314
+ }
315
+ function sineStep(l) {
316
+ let best = 500;
317
+ let distance = 1 / 0;
318
+ for (const step of g9TonalSteps){
319
+ const d = Math.abs(SINE_L[step] - l);
320
+ if (d < distance) {
321
+ distance = d;
322
+ best = step;
323
+ }
324
+ }
325
+ return best;
326
+ }
327
+ function sineTonalScale(color) {
328
+ const base = sineBase(color);
329
+ const out = {};
330
+ for (const step of g9TonalSteps){
331
+ const l = SINE_L[step];
332
+ const curve = Math.sin(Math.PI * Math.min(1, Math.max(0, (l - 0.12) / 0.9)));
333
+ out[step] = sineHex({
334
+ l,
335
+ c: base.c * (0.25 + 0.75 * curve),
336
+ h: base.h
337
+ });
338
+ }
339
+ out[sineStep(base.l)] = sineHex(base);
340
+ return out;
341
+ }
342
+ function sineNeutralScale(color, tint) {
343
+ const base = sineBase(color);
344
+ const c = Math.min(0.03, 0.2 * base.c) * Math.min(1, Math.max(0, tint));
345
+ const out = {};
346
+ for (const step of g9TonalSteps)out[step] = sineHex({
347
+ l: SINE_L[step],
348
+ c,
349
+ h: base.h
350
+ });
351
+ return out;
352
+ }
353
+ function fixedNeutralScale(hue, chroma) {
354
+ const out = {};
355
+ for (const step of g9TonalSteps)out[step] = sineHex({
356
+ l: SINE_L[step],
357
+ c: chroma,
358
+ h: hue
359
+ });
360
+ return out;
361
+ }
362
+ function stepContrast(fg, bg, min) {
363
+ if (getContrastRatio(fg, bg) >= min) return opaque(fg);
364
+ let base;
365
+ try {
366
+ base = sineOklch(fg);
367
+ } catch {
368
+ return 'string' == typeof fg ? fg : opaque(fg);
369
+ }
370
+ const darker = getLuminance(bg) > 0.18;
371
+ let best = opaque(fg);
372
+ for(let i = 1; i <= 40; i++){
373
+ const l = Math.min(1, Math.max(0, base.l + (darker ? -1 : 1) * i * 0.02));
374
+ best = sineHex({
375
+ l,
376
+ c: base.c,
377
+ h: base.h
378
+ });
379
+ if (getContrastRatio(best, bg) >= min) break;
380
+ }
381
+ return best;
382
+ }
383
+ export { chartPalette, colorDistance, ensureContrast, fixedNeutralScale, fromOklch, g9TonalSteps, interpolateStops, isInSrgbGamut, mixOklch, nearestTonalStep, neutralScale, oklchToHex, readableOn, toOklch, tonalScale };
257
384
 
258
385
  //# sourceMappingURL=oklch.js.map
@@ -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,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ACxE,IAAIK,AAAiB,MAAjBA,MAAM,MAAM,EAAQ,MAAM,IAAIC,WAAW;IAC7C,IAAID,AAAiB,MAAjBA,MAAM,MAAM,EAAQ,OAAOvC,YAAYuC,KAAK,CAAC,EAAE;IACnD,MAAMjF,IAAIQ,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAG,CAAC,GAAGoE,MAAOK,CAAAA,MAAM,MAAM,GAAG;IACxD,MAAM5C,IAAI7B,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, options?: { readonly curve?: 'even' | 'sine' }): G9Oklch {\n // the sine curve's reading (ShopManager's): the hue reads 0 only below 1e-5 chroma, and chroma is kept as measured\n if (options?.curve === 'sine') return sineOklch(color);\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/**\n * OKLCH → `#RRGGBB` (or `#RRGGBBAA` with alpha < 1). `gamut: 'steps'` maps an out-of-sRGB colour by cutting chroma 10 %\n * at a time (ShopManager's `@g9/tokens`, to the hex; opaque) instead of the default binary search.\n */\nexport function oklchToHex(x: G9Oklch, options?: { readonly gamut?: 'search' | 'steps' }): string {\n return options?.gamut === 'steps' ? sineHex(x) : formatColor(fromOklch(x));\n}\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","options","sineOklch","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","sineHex","formatColor","opaque","g9TonalSteps","STEP_L","STEP_C","nearestTonalStep","best","step","tonalScale","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","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,QAAQ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;IACnB,EAAE,OAAM;QACN,OAAO,AAAc,YAAd,OAAOA,KAAkBA,KAAKrB,OAAOqB;IAC9C;IACA,MAAMQ,SAASF,aAAaL,MAAM;IAClC,IAAIjB,OAAOL,OAAOqB;IAClB,IAAK,IAAI5B,IAAI,GAAGA,KAAK,IAAIA,IAAK;QAC5B,MAAMhC,IAAIC,KAAK,GAAG,CAAC,GAAGA,KAAK,GAAG,CAAC,GAAG+F,KAAK,CAAC,GAAI5B,AAAAA,CAAAA,SAAS,KAAK,KAAKpC,IAAI;QACnEY,OAAOP,QAAQ;YAAErC;YAAG,GAAGgG,KAAK,CAAC;YAAE,GAAGA,KAAK,CAAC;QAAC;QACzC,IAAIhC,iBAAiBpB,MAAMiB,OAAOC,KAAK;IACzC;IACA,OAAOlB;AACT"}
@@ -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,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,gCAAgC,EAChC,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
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,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,gCAAgC,EAChC,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EACL,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,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"}
@@ -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";
@@ -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). */
@@ -50,6 +79,14 @@ export interface G9ShapeSet {
50
79
  readonly [K in G9TypeRoleName]: G9TypeRole;
51
80
  };
52
81
  readonly heights: G9ControlHeights;
82
+ /**
83
+ * `'shared'`: the controls take their sizes from {@link G9ShapeSet.heights} (a design system that sizes every control
84
+ * from three heights: ShopManager's 40/48/56 and, for gloves, 44/56/64). G9Button small/medium/large = sm/md/lg (its
85
+ * label at `type.label`'s size, small 2 smaller); G9IconButton sm/md/lg = sm/md/lg; G9TextEntry = md; G9Chip = sm
86
+ * (lg: md); G9Segmented = sm items in a 4 dp tray; G9Stepper = an md tray (lg: lg) with sm buttons. Default `'own'`:
87
+ * each control keeps its own table (the stock look).
88
+ */
89
+ readonly sizing?: 'own' | 'shared';
53
90
  /** Minimum touch target (oracles flag smaller interactive elements). Default 44, never under {@link g9MinTouchTarget}. */
54
91
  readonly touchTarget: number;
55
92
  /** Font families per script; unset: the platform's own. */
@@ -67,8 +104,9 @@ export declare const g9DefaultShape: G9ShapeSet;
67
104
  export declare function resolveShape(over: Partial<G9ShapeSet> | undefined, base?: G9ShapeSet): G9ShapeSet;
68
105
  /**
69
106
  * 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 names. With a `direction`,
71
- * also `--g9-font-text`: the family of that direction's script (what every G9 text style reads).
107
+ * `--g9-touch-target` (all px), and `--g9-font-latin|arabic|mono` (plus `-500|600|700|800`) for the families a theme
108
+ * names. With a `direction`, also `--g9-font-text` and `--g9-font-text-500|600|700|800`: the families of that direction's
109
+ * script (what every G9 text style reads, by its weight).
72
110
  */
73
111
  export declare function toShapeCssVariables(shape: G9ShapeSet, direction?: 'ltr' | 'rtl'): Readonly<Record<string, string>>;
74
112
  //# 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;AAC7F,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/G,iHAAiH;AACjH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,QAAQ,CAAC,KAAK,CAAC,EAAE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,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IACnC,0HAA0H;IAC1H,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;IAC9B,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC;CAC9B;AAED,wHAAwH;AACxH,eAAO,MAAM,cAAc,EAAE,UAcb,CAAC;AAEjB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,EAAE,IAAI,GAAE,UAA2B,GAAG,UAAU,CAiBjH;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAiClH"}
@@ -1,4 +1,30 @@
1
1
  import { toKebabCase } from "./css-vars.js";
2
+ const g9FontWeights = [
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,
@@ -66,7 +92,7 @@ const g9DefaultShape = Object.freeze({
66
92
  touchTarget: 44
67
93
  });
68
94
  function resolveShape(over, base = g9DefaultShape) {
69
- var _over_density, _base_density, _over_touchTarget;
95
+ var _over_density, _base_density, _over_touchTarget, _over_sizing, _over_sizing1;
70
96
  if (!over) return base;
71
97
  const density = null != (_over_density = over.density) ? _over_density : base.density;
72
98
  const shift = g9DensitySteps[null != density ? density : 'regular'] - g9DensitySteps[null != (_base_density = base.density) ? _base_density : 'regular'];
@@ -98,12 +124,14 @@ function resolveShape(over, base = g9DefaultShape) {
98
124
  } : {},
99
125
  ...density ? {
100
126
  density
127
+ } : {},
128
+ ...(null != (_over_sizing = over.sizing) ? _over_sizing : base.sizing) ? {
129
+ sizing: null != (_over_sizing1 = over.sizing) ? _over_sizing1 : base.sizing
101
130
  } : {}
102
131
  });
103
132
  }
104
133
  function toShapeCssVariables(shape, direction) {
105
134
  var _shape_fonts;
106
- var _shape_fonts1, _shape_fonts2;
107
135
  const out = {};
108
136
  for (const [k, v] of Object.entries(shape.radii))out[`--g9-radius-${toKebabCase(k)}`] = `${v}px`;
109
137
  for (const [k, v] of Object.entries(shape.type)){
@@ -113,11 +141,30 @@ function toShapeCssVariables(shape, direction) {
113
141
  }
114
142
  for (const [k, v] of Object.entries(shape.heights))out[`--g9-height-${k}`] = `${v}px`;
115
143
  out['--g9-touch-target'] = `${shape.touchTarget}px`;
116
- for (const [script, family] of Object.entries(null != (_shape_fonts = shape.fonts) ? _shape_fonts : {}))if ('string' == typeof family && family) out[`--g9-font-${script}`] = family;
117
- const text = 'rtl' === direction ? null == (_shape_fonts1 = shape.fonts) ? void 0 : _shape_fonts1.arabic : 'ltr' === direction ? null == (_shape_fonts2 = shape.fonts) ? void 0 : _shape_fonts2.latin : void 0;
118
- if (text) out['--g9-font-text'] = text;
144
+ const fonts = null != (_shape_fonts = shape.fonts) ? _shape_fonts : {};
145
+ for (const script of [
146
+ 'latin',
147
+ 'arabic',
148
+ 'mono'
149
+ ]){
150
+ const family = fonts[script];
151
+ if ('string' == typeof family && family) out[`--g9-font-${script}`] = family;
152
+ for (const w of g9FontWeights){
153
+ const f = familyForWeight(w, family, fonts[`${script}ByWeight`]);
154
+ if (f) out[`--g9-font-${script}-${w}`] = f;
155
+ }
156
+ }
157
+ const script = 'rtl' === direction ? 'arabic' : 'ltr' === direction ? 'latin' : void 0;
158
+ if (script) {
159
+ const text = fonts[script];
160
+ if (text) out['--g9-font-text'] = text;
161
+ for (const w of g9FontWeights){
162
+ const f = familyForWeight(w, text, fonts[`${script}ByWeight`]);
163
+ if (f) out[FONT_TEXT_VAR[w]] = f;
164
+ }
165
+ }
119
166
  return out;
120
167
  }
121
- export { g9DefaultShape, g9DensitySteps, g9MinTouchTarget, resolveShape, toShapeCssVariables };
168
+ export { familyForWeight, g9DefaultShape, g9DensitySteps, g9FontFamilyFor, g9FontWeights, g9MinTouchTarget, resolveShape, toShapeCssVariables };
122
169
 
123
170
  //# sourceMappingURL=shape.js.map