@starasia/theme 3.0.4 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export * from './oklch';
2
+ export * from './ramp';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * OKLab / OKLCH color math (Björn Ottosson's formulation) + sRGB gamut
3
+ * handling and WCAG contrast. No runtime dependency — the theme engine must
4
+ * stay self-contained (paket harus mandiri, lihat atomic self-sufficient).
5
+ *
6
+ * OKLCH dipakai karena perceptually uniform: menggeser Lightness menghasilkan
7
+ * tangga shade yang rata di mata (dasar generator ramp), beda dari HSL yang
8
+ * timpang di hue tertentu.
9
+ */
10
+ export interface RGB {
11
+ r: number;
12
+ g: number;
13
+ b: number;
14
+ }
15
+ export interface OKLCH {
16
+ l: number;
17
+ c: number;
18
+ h: number;
19
+ }
20
+ export declare function hexToRgb(hex: string): RGB;
21
+ export declare function rgbToHex({ r, g, b }: RGB): string;
22
+ export declare function rgbToOklch({ r, g, b }: RGB): OKLCH;
23
+ export declare const hexToOklch: (hex: string) => OKLCH;
24
+ export declare const oklchToHex: (c: OKLCH) => string;
25
+ /** WCAG contrast ratio 1..21 antara dua warna hex. */
26
+ export declare function contrastRatio(hexA: string, hexB: string): number;
27
+ /**
28
+ * Pilih warna teks (dari kandidat) dengan kontras terbaik di atas `bg`.
29
+ * Default kandidat putih vs ink gelap Starasia (gray-1100 #1e1f21).
30
+ */
31
+ export declare function pickTextOn(bg: string, candidates?: string[]): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Ramp generator: satu warna seed → tangga shade 50..900 (atau 50..1100 untuk
3
+ * netral) di ruang OKLCH.
4
+ *
5
+ * Prinsip: Lightness tiap langkah DIPATOK ke tangga perseptual yang diukur dari
6
+ * palet Starasia yang ada (lihat LADDERS) supaya struktur terang-gelap konsisten
7
+ * & kompatibel dengan mapping semantic light/dark yang sudah ada. Seed hanya
8
+ * menyumbang HUE + skala CHROMA. Efeknya: seed = warna brand default akan
9
+ * mereproduksi ramp default (parity), seed baru = ramp bernuansa sama tapi hue
10
+ * berbeda. Chroma dibentuk oleh profil taper per-skala lalu di-clamp ke gamut.
11
+ */
12
+ export interface Ladder {
13
+ /** Perceptual lightness per langkah (0..1). */
14
+ L: number[];
15
+ /** Profil chroma per langkah (bentuk taper; dinormalisasi internal). */
16
+ C: number[];
17
+ }
18
+ export declare const SCALE_KEYS_10: readonly ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"];
19
+ export declare const SCALE_KEYS_12: readonly ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "1100"];
20
+ export declare const LADDERS: Record<"brand" | "error" | "success" | "info" | "warning", Ladder>;
21
+ export declare const NEUTRAL_LADDER_GRAY: number[];
22
+ export declare const NEUTRAL_LADDER_DARK: number[];
23
+ /**
24
+ * Bangun ramp berwarna (10 langkah) dari seed + ladder skala.
25
+ * Chroma puncak = chroma seed; langkah lain mengikuti profil taper ladder.
26
+ */
27
+ export declare function rampFromSeed(seedHex: string, ladder: Ladder): string[];
28
+ /**
29
+ * Ramp netral (12 langkah) dari seed + tangga L. Chroma seed di-cap rendah lalu
30
+ * dibentuk parabola (puncak di tengah) supaya ujung putih/hitam tetap netral.
31
+ */
32
+ export declare function neutralRamp(seedHex: string, ladderL: number[]): string[];
33
+ /** Pilih hex dari ramp yang Lightness-nya paling dekat ke target. */
34
+ export declare function pickByLightness(ramp: string[], targetL: number): string;
@@ -1,5 +1,6 @@
1
1
  import { default as React, PropsWithChildren } from 'react';
2
2
  import { ThemeObject } from '../types/theme';
3
+ import { ThemeSeed } from '../theme/buildTheme';
3
4
 
4
5
  export interface ThemeContextProps {
5
6
  theme?: ThemeObject;
@@ -8,5 +9,11 @@ export interface ThemeContextProps {
8
9
  export declare const ThemeContext: React.Context<ThemeContextProps>;
9
10
  export interface ThemeProviderProps extends PropsWithChildren {
10
11
  value?: ThemeObject;
12
+ /**
13
+ * Seed tema (brand/status/neutral/radius/font) → di-generate penuh ke token
14
+ * `--sa-*` lewat buildTheme dan di-inject global di `:root` (light + dark).
15
+ * Opt-in & additif: tanpa `seed`, perilaku lama (brand via `value`) utuh.
16
+ */
17
+ seed?: ThemeSeed;
11
18
  }
12
- export declare function ThemeProvider({ value, children }: ThemeProviderProps): React.JSX.Element;
19
+ export declare function ThemeProvider({ value, seed, children }: ThemeProviderProps): React.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -2,3 +2,5 @@ export type { ThemeObject } from './types';
2
2
  export * from './components';
3
3
  export * from './hooks';
4
4
  export * from './helpers/createTheme';
5
+ export * from './theme';
6
+ export * from './color';
package/dist/index.es.js CHANGED
@@ -1,56 +1,194 @@
1
- import { jsx as S } from "react/jsx-runtime";
2
- import { createContext as E, useState as v, useMemo as a, useRef as g, useEffect as u, useContext as C } from "react";
3
- const j = (r) => {
1
+ import { jsx as Y } from "react/jsx-runtime";
2
+ import { createContext as z, useState as G, useMemo as y, useEffect as g, useRef as q, useContext as W } from "react";
3
+ const Q = (t, n) => {
4
+ if (typeof document > "u")
5
+ return;
6
+ const r = document.getElementById(n);
7
+ if (r)
8
+ r.textContent = t;
9
+ else {
10
+ const e = document.createElement("style");
11
+ e.id = n, e.textContent = t, document.head.appendChild(e);
12
+ }
13
+ }, V = (t) => {
4
14
  if (typeof document > "u")
5
15
  return null;
6
- const e = document.getElementById(r);
7
- if (e)
8
- return e;
9
- const t = document.createElement("style");
10
- return t.id = r, document.head.appendChild(t), t;
11
- }, b = E({
12
- theme: void 0,
13
- setTheme: () => {
16
+ const n = document.getElementById(t);
17
+ if (n)
18
+ return n;
19
+ const r = document.createElement("style");
20
+ return r.id = t, document.head.appendChild(r), r;
21
+ };
22
+ function L(t) {
23
+ let n = t.trim().replace(/^#/, "");
24
+ n.length === 3 && (n = n.split("").map((e) => e + e).join("")), n.length === 8 && (n = n.slice(0, 6));
25
+ const r = parseInt(n, 16);
26
+ return {
27
+ r: (r >> 16 & 255) / 255,
28
+ g: (r >> 8 & 255) / 255,
29
+ b: (r & 255) / 255
30
+ };
31
+ }
32
+ const E = (t) => Math.max(0, Math.min(255, Math.round(t * 255))).toString(16).padStart(2, "0");
33
+ function X({ r: t, g: n, b: r }) {
34
+ return `#${E(t)}${E(n)}${E(r)}`;
35
+ }
36
+ const x = (t) => t <= 0.04045 ? t / 12.92 : Math.pow((t + 0.055) / 1.055, 2.4), S = (t) => t <= 31308e-7 ? 12.92 * t : 1.055 * Math.pow(t, 1 / 2.4) - 0.055;
37
+ function Z(t, n, r) {
38
+ const e = 0.4122214708 * t + 0.5363325363 * n + 0.0514459929 * r, o = 0.2119034982 * t + 0.6806995451 * n + 0.1073969566 * r, s = 0.0883024619 * t + 0.2817188376 * n + 0.6299787005 * r, a = Math.cbrt(e), c = Math.cbrt(o), m = Math.cbrt(s);
39
+ return {
40
+ L: 0.2104542553 * a + 0.793617785 * c - 0.0040720468 * m,
41
+ a: 1.9779984951 * a - 2.428592205 * c + 0.4505937099 * m,
42
+ b: 0.0259040371 * a + 0.7827717662 * c - 0.808675766 * m
43
+ };
44
+ }
45
+ function T(t, n, r) {
46
+ const e = t + 0.3963377774 * n + 0.2158037573 * r, o = t - 0.1055613458 * n - 0.0638541728 * r, s = t - 0.0894841775 * n - 1.291485548 * r, a = e * e * e, c = o * o * o, m = s * s * s;
47
+ return {
48
+ r: 4.0767416621 * a - 3.3077115913 * c + 0.2309699292 * m,
49
+ g: -1.2684380046 * a + 2.6097574011 * c - 0.3413193965 * m,
50
+ b: -0.0041960863 * a - 0.7034186147 * c + 1.707614701 * m
51
+ };
52
+ }
53
+ function t0({ r: t, g: n, b: r }) {
54
+ const { L: e, a: o, b: s } = Z(
55
+ x(t),
56
+ x(n),
57
+ x(r)
58
+ ), a = Math.sqrt(o * o + s * s);
59
+ let c = Math.atan2(s, o) * 180 / Math.PI;
60
+ return c < 0 && (c += 360), { l: e, c: a, h: c };
61
+ }
62
+ const $ = (t) => t0(L(t)), k = ({ r: t, g: n, b: r }, e = 1e-4) => t >= -e && t <= 1 + e && n >= -e && n <= 1 + e && r >= -e && r <= 1 + e;
63
+ function n0({ l: t, c: n, h: r }) {
64
+ const e = r * Math.PI / 180, o = (a) => T(t, a * Math.cos(e), a * Math.sin(e));
65
+ let s = o(n);
66
+ if (!k(s)) {
67
+ let a = 0, c = n;
68
+ for (let m = 0; m < 20; m++) {
69
+ const l = (a + c) / 2;
70
+ s = o(l), k(s) ? a = l : c = l;
71
+ }
72
+ s = o(a);
14
73
  }
15
- }), w = "sa-theme-style";
16
- function O(r) {
17
- const e = r.split(",").map((t) => Number(t.trim()));
18
- return e.length !== 3 || e.some((t) => !Number.isFinite(t) || t < 0 || t > 255) ? null : "#" + e.map((t) => Math.round(t).toString(16).padStart(2, "0")).join("");
74
+ return {
75
+ r: Math.min(1, Math.max(0, S(s.r))),
76
+ g: Math.min(1, Math.max(0, S(s.g))),
77
+ b: Math.min(1, Math.max(0, S(s.b)))
78
+ };
19
79
  }
20
- function y(r) {
21
- if (!r)
22
- return "";
23
- const e = /* @__PURE__ */ new Set(["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"]), t = Object.entries(r).filter(([n]) => e.has(n)).map(([n, o]) => {
24
- const s = O(o);
25
- return s ? ` --sa-color-brand-${n}: ${s};` : "";
26
- }).filter(Boolean).join(`
27
- `);
28
- return t ? `:root {
29
- ${t}
30
- }` : "";
80
+ const U = (t) => X(n0(t));
81
+ function A({ r: t, g: n, b: r }) {
82
+ return 0.2126 * x(t) + 0.7152 * x(n) + 0.0722 * x(r);
83
+ }
84
+ function r0(t, n) {
85
+ const r = A(L(t)), e = A(L(n)), o = Math.max(r, e), s = Math.min(r, e);
86
+ return (o + 0.05) / (s + 0.05);
87
+ }
88
+ function R(t, n = ["#ffffff", "#1e1f21"]) {
89
+ let r = n[0], e = -1;
90
+ for (const o of n) {
91
+ const s = r0(t, o);
92
+ s > e && (e = s, r = o);
93
+ }
94
+ return r;
95
+ }
96
+ const D = ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"], N = ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "1100"], O = {
97
+ brand: {
98
+ L: [0.9434, 0.8816, 0.7612, 0.6375, 0.5179, 0.4415, 0.2695, 0.2429, 0.2155, 0.1878],
99
+ C: [0.0143, 0.031, 0.0645, 0.1017, 0.1394, 0.1429, 0.086, 0.0761, 0.066, 0.0549]
100
+ },
101
+ error: {
102
+ L: [0.9678, 0.8921, 0.8422, 0.7752, 0.7325, 0.6785, 0.54, 0.4653, 0.3903, 0.3073],
103
+ C: [0.0166, 0.0588, 0.09, 0.1362, 0.169, 0.2131, 0.2047, 0.1753, 0.1448, 0.1075]
104
+ },
105
+ success: {
106
+ L: [0.9836, 0.9065, 0.8635, 0.8241, 0.7874, 0.7549, 0.6605, 0.5598, 0.4572, 0.3455],
107
+ C: [0.0231, 0.0626, 0.0939, 0.1214, 0.1468, 0.1662, 0.1444, 0.1203, 0.0962, 0.0689]
108
+ },
109
+ info: {
110
+ L: [0.9783, 0.9523, 0.908, 0.8431, 0.7845, 0.6989, 0.6232, 0.5302, 0.4651, 0.3061],
111
+ C: [0.0134, 0.0275, 0.0604, 0.1075, 0.1426, 0.147, 0.1432, 0.1223, 0.1045, 0.0663]
112
+ },
113
+ warning: {
114
+ L: [0.9673, 0.9003, 0.8504, 0.8055, 0.7624, 0.6961, 0.5244, 0.3979, 0.2567, 0.2201],
115
+ C: [0.0205, 0.0679, 0.0991, 0.1284, 0.1495, 0.1346, 0.0998, 0.0731, 0.0415, 0.0332]
116
+ }
117
+ }, e0 = [1, 0.9791, 0.9577, 0.9007, 0.7857, 0.6501, 0.6028, 0.5383, 0.4389, 0.36, 0.2856, 0.239], o0 = [0.2127, 0.2401, 0.3133, 0.3673, 0.4198, 0.5093, 0.603, 0.682, 0.7408, 0.8102, 0.8546, 0.9153], s0 = 0.02;
118
+ function j(t, n) {
119
+ const { c: r, h: e } = $(t), o = Math.max(...n.C) || 1;
120
+ return n.L.map(
121
+ (s, a) => U({ l: s, c: r * (n.C[a] / o), h: e })
122
+ );
31
123
  }
32
- function $({ value: r, children: e }) {
33
- const [t, n] = v(r), o = a(
34
- () => t ? JSON.stringify(t) : "",
35
- [t]
36
- ), s = g(null);
37
- u(() => {
38
- var l, i;
39
- s.current || (s.current = j(w));
40
- const c = s.current;
41
- if (!c)
124
+ function w(t, n) {
125
+ const { c: r, h: e } = $(t), o = Math.min(r, s0), s = n.length;
126
+ return n.map((a, c) => {
127
+ const m = c / (s - 1), l = 1 - Math.abs(2 * m - 1);
128
+ return U({ l: a, c: o * l, h: e });
129
+ });
130
+ }
131
+ function g0(t, n) {
132
+ let r = t[0], e = 1 / 0;
133
+ for (const o of t) {
134
+ const s = Math.abs($(o).l - n);
135
+ s < e && (e = s, r = o);
136
+ }
137
+ return r;
138
+ }
139
+ const E0 = {
140
+ name: "starasia",
141
+ brand: "#1a4fa0",
142
+ neutral: "#7d818a",
143
+ error: "#ff4d6d",
144
+ success: "#30ce84",
145
+ info: "#00abeb",
146
+ warning: "#ed9f30",
147
+ radius: 8,
148
+ font: { body: "Inter" }
149
+ }, I = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"', a0 = 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace', f = (t) => Math.round(t * 10) / 10;
150
+ function b(t, n, r, e) {
151
+ e.forEach((o, s) => {
152
+ t[`--sa-color-${n}-${o}`] = r[s];
153
+ });
154
+ }
155
+ function c0(t, n = {}) {
156
+ var l, u, d;
157
+ const r = n.selector ?? ":root", e = n.darkPrimary ?? !0, o = {}, s = {}, a = { brand: [] }, c = j(t.brand, O.brand);
158
+ if (a.brand = c, b(o, "brand", c, D), o["--sa-text-on-brand"] = R(c[6]), ["error", "success", "info", "warning"].forEach((i) => {
159
+ const p = t[i];
160
+ if (!p)
42
161
  return;
43
- const x = o ? JSON.parse(o) : void 0;
44
- c.textContent = x ? y((i = (l = x == null ? void 0 : x.colors) == null ? void 0 : l.raw) == null ? void 0 : i.blue) : "";
45
- }, [o]), u(() => () => {
46
- s.current && (s.current.textContent = "");
47
- }, []);
48
- const f = (c) => {
49
- c && n(c);
50
- };
51
- return /* @__PURE__ */ S(b.Provider, { value: { theme: t, setTheme: f }, children: e });
162
+ const _ = j(p, O[i]);
163
+ a[i] = _, b(o, i, _, D);
164
+ }), t.neutral) {
165
+ const i = w(t.neutral, e0), p = w(t.neutral, o0);
166
+ a.gray = i, a.dark = p, b(o, "gray", i, N), b(o, "dark", p, N);
167
+ }
168
+ if (typeof t.radius == "number") {
169
+ const i = t.radius;
170
+ o["--sa-radii-xs"] = `${f(i * 0.5)}px`, o["--sa-radii-sm"] = `${f(i * 0.75)}px`, o["--sa-radii-md"] = `${f(i)}px`, o["--sa-radii-lg"] = `${f(i * 1.5)}px`, o["--sa-radii-xl"] = `${f(i * 1.75)}px`, o["--sa-radii-2xl"] = `${f(i * 2)}px`, o["--sa-radii-rounded"] = `${f(i)}px`;
171
+ }
172
+ if ((l = t.font) != null && l.body && (o["--sa-font-family"] = `"${t.font.body}", ${I}`), (u = t.font) != null && u.heading && (o["--sa-font-family-heading"] = `"${t.font.heading}", ${I}`), (d = t.font) != null && d.mono && (o["--sa-font-family-mono"] = `"${t.font.mono}", ${a0}`), e) {
173
+ const i = c[4];
174
+ s["--sa-background-brand"] = i, s["--sa-background-brand-hover"] = c[3], s["--sa-background-brand-pressed"] = c[5], s["--sa-text-on-brand"] = R(i);
175
+ }
176
+ return { css: i0(r, o, s), rootTokens: o, darkTokens: s, ramps: a };
52
177
  }
53
- const N = {
178
+ function v(t, n) {
179
+ const r = Object.entries(n).map(([e, o]) => ` ${e}: ${o};`);
180
+ return r.length ? `${t} {
181
+ ${r.join(`
182
+ `)}
183
+ }` : "";
184
+ }
185
+ function i0(t, n, r) {
186
+ const e = t === ":root" ? '[data-theme="dark"]' : `${t}[data-theme="dark"], ${t} [data-theme="dark"]`;
187
+ return [v(t, n), v(e, r)].filter(Boolean).join(`
188
+
189
+ `);
190
+ }
191
+ const l0 = {
54
192
  raw: {
55
193
  white: {
56
194
  900: "255, 255, 255"
@@ -149,7 +287,7 @@ const N = {
149
287
  tertiary: "230, 237, 246"
150
288
  }
151
289
  }
152
- }, D = {
290
+ }, m0 = {
153
291
  radii: {
154
292
  none: "0",
155
293
  xs: "0.25rem",
@@ -207,7 +345,7 @@ const N = {
207
345
  inner: "inset 0 2px 4px 0 #0000000d",
208
346
  card: "0px 4px 35px 0px #7090b040"
209
347
  }
210
- }, H = {
348
+ }, u0 = {
211
349
  fontSizes: {
212
350
  xs: "0.625rem",
213
351
  sm: "0.75rem",
@@ -247,64 +385,142 @@ const N = {
247
385
  relaxed: 1.625,
248
386
  loose: 2
249
387
  }
250
- }, J = {
251
- colors: N,
252
- metrics: D,
253
- font: H
254
- }, p = J, d = (r, e) => {
255
- const t = {};
256
- return Object.keys(r).forEach((n) => {
257
- if (r != null && r[n] && typeof (r == null ? void 0 : r[n]) == "object") {
258
- t[n] = {
259
- ...r == null ? void 0 : r[n],
260
- ...e == null ? void 0 : e[n],
261
- ...d(r == null ? void 0 : r[n], e == null ? void 0 : e[n])
388
+ }, P = {
389
+ colors: l0,
390
+ metrics: m0,
391
+ font: u0
392
+ }, J = z({
393
+ theme: void 0,
394
+ setTheme: () => {
395
+ }
396
+ }), f0 = "sa-theme-style", M = "sa-theme-seed-style";
397
+ function x0(t) {
398
+ const n = t.split(",").map((r) => Number(r.trim()));
399
+ return n.length !== 3 || n.some((r) => !Number.isFinite(r) || r < 0 || r > 255) ? null : "#" + n.map((r) => Math.round(r).toString(16).padStart(2, "0")).join("");
400
+ }
401
+ var F, H;
402
+ const d0 = ((H = (F = P.colors) == null ? void 0 : F.raw) == null ? void 0 : H.blue) ?? {}, B = (t) => (t ?? "").replace(/\s+/g, "");
403
+ function p0(t) {
404
+ if (!t)
405
+ return "";
406
+ const n = /* @__PURE__ */ new Set(["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"]), r = Object.entries(t).filter(([e]) => n.has(e)).filter(
407
+ ([e, o]) => B(o) !== B(d0[e])
408
+ ).map(([e, o]) => {
409
+ const s = x0(o);
410
+ return s ? ` --sa-color-brand-${e}: ${s};` : "";
411
+ }).filter(Boolean).join(`
412
+ `);
413
+ return r ? `:root {
414
+ ${r}
415
+ }` : "";
416
+ }
417
+ function S0({ value: t, seed: n, children: r }) {
418
+ const [e, o] = G(t), s = y(() => n ? JSON.stringify(n) : "", [n]);
419
+ g(() => {
420
+ if (typeof document > "u")
421
+ return;
422
+ if (!s) {
423
+ const u = document.getElementById(M);
424
+ u && (u.textContent = "");
425
+ return;
426
+ }
427
+ const { css: l } = c0(JSON.parse(s));
428
+ return Q(l, M), () => {
429
+ const u = document.getElementById(M);
430
+ u && (u.textContent = "");
431
+ };
432
+ }, [s]);
433
+ const a = y(
434
+ () => e ? JSON.stringify(e) : "",
435
+ [e]
436
+ ), c = q(null);
437
+ g(() => {
438
+ var d, i;
439
+ c.current || (c.current = V(f0));
440
+ const l = c.current;
441
+ if (!l)
442
+ return;
443
+ const u = a ? JSON.parse(a) : void 0;
444
+ l.textContent = u ? p0((i = (d = u == null ? void 0 : u.colors) == null ? void 0 : d.raw) == null ? void 0 : i.blue) : "";
445
+ }, [a]), g(() => () => {
446
+ c.current && (c.current.textContent = "");
447
+ }, []);
448
+ const m = (l) => {
449
+ l && o(l);
450
+ };
451
+ return /* @__PURE__ */ Y(J.Provider, { value: { theme: e, setTheme: m }, children: r });
452
+ }
453
+ const C = P, K = (t, n) => {
454
+ const r = {};
455
+ return Object.keys(t).forEach((e) => {
456
+ if (t != null && t[e] && typeof (t == null ? void 0 : t[e]) == "object") {
457
+ r[e] = {
458
+ ...t == null ? void 0 : t[e],
459
+ ...n == null ? void 0 : n[e],
460
+ ...K(t == null ? void 0 : t[e], n == null ? void 0 : n[e])
262
461
  };
263
462
  return;
264
463
  }
265
- t[n] = (e == null ? void 0 : e[n]) || (r == null ? void 0 : r[n]);
266
- }), t;
464
+ r[e] = (n == null ? void 0 : n[e]) || (t == null ? void 0 : t[e]);
465
+ }), r;
267
466
  };
268
- function m() {
269
- const r = C(b), e = a(
467
+ function h() {
468
+ const t = W(J), n = y(
270
469
  () => ({
271
- ...p,
272
- ...r.theme,
273
- ...d(p, r.theme)
470
+ ...C,
471
+ ...t.theme,
472
+ ...K(C, t.theme)
274
473
  }),
275
- [r.theme, p]
474
+ [t.theme, C]
276
475
  );
277
- return { ...r, theme: e };
476
+ return { ...t, theme: n };
278
477
  }
279
- function h() {
280
- const { theme: r } = m();
281
- return r.colors;
478
+ function M0() {
479
+ const { theme: t } = h();
480
+ return t.colors;
282
481
  }
283
- function B() {
284
- var e;
285
- const { theme: r } = m();
286
- return (e = r.metrics) == null ? void 0 : e.spacing;
482
+ function C0() {
483
+ var n;
484
+ const { theme: t } = h();
485
+ return (n = t.metrics) == null ? void 0 : n.spacing;
287
486
  }
288
- function F() {
289
- var e;
290
- const { theme: r } = m();
291
- return (e = r.metrics) == null ? void 0 : e.radii;
487
+ function y0() {
488
+ var n;
489
+ const { theme: t } = h();
490
+ return (n = t.metrics) == null ? void 0 : n.radii;
292
491
  }
293
- function L() {
294
- var e;
295
- const { theme: r } = m();
296
- return (e = r == null ? void 0 : r.metrics) == null ? void 0 : e.shadows;
492
+ function L0() {
493
+ var n;
494
+ const { theme: t } = h();
495
+ return (n = t == null ? void 0 : t.metrics) == null ? void 0 : n.shadows;
297
496
  }
298
- function P(r) {
299
- return r;
497
+ function $0(t) {
498
+ return t;
300
499
  }
301
500
  export {
302
- b as ThemeContext,
303
- $ as ThemeProvider,
304
- P as createTheme,
305
- h as useColor,
306
- F as useRadius,
307
- L as useShadow,
308
- B as useSpacing,
309
- m as useTheme
501
+ O as LADDERS,
502
+ o0 as NEUTRAL_LADDER_DARK,
503
+ e0 as NEUTRAL_LADDER_GRAY,
504
+ E0 as SA_DEFAULT_SEED,
505
+ D as SCALE_KEYS_10,
506
+ N as SCALE_KEYS_12,
507
+ J as ThemeContext,
508
+ S0 as ThemeProvider,
509
+ c0 as buildTheme,
510
+ r0 as contrastRatio,
511
+ $0 as createTheme,
512
+ $ as hexToOklch,
513
+ L as hexToRgb,
514
+ w as neutralRamp,
515
+ U as oklchToHex,
516
+ g0 as pickByLightness,
517
+ R as pickTextOn,
518
+ j as rampFromSeed,
519
+ X as rgbToHex,
520
+ t0 as rgbToOklch,
521
+ M0 as useColor,
522
+ y0 as useRadius,
523
+ L0 as useShadow,
524
+ C0 as useSpacing,
525
+ h as useTheme
310
526
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,9 @@
1
- (function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s["@starasia/theme"]={},s.jsxRuntime,s.React))})(this,function(s,c,o){"use strict";const S=e=>{if(typeof document>"u")return null;const r=document.getElementById(e);if(r)return r;const t=document.createElement("style");return t.id=e,document.head.appendChild(t),t},p=o.createContext({theme:void 0,setTheme:()=>{}}),E="sa-theme-style";function j(e){const r=e.split(",").map(t=>Number(t.trim()));return r.length!==3||r.some(t=>!Number.isFinite(t)||t<0||t>255)?null:"#"+r.map(t=>Math.round(t).toString(16).padStart(2,"0")).join("")}function h(e){if(!e)return"";const r=new Set(["50","100","200","300","400","500","600","700","800","900"]),t=Object.entries(e).filter(([n])=>r.has(n)).map(([n,m])=>{const i=j(m);return i?` --sa-color-brand-${n}: ${i};`:""}).filter(Boolean).join(`
2
- `);return t?`:root {
3
- ${t}
4
- }`:""}function v({value:e,children:r}){const[t,n]=o.useState(e),m=o.useMemo(()=>t?JSON.stringify(t):"",[t]),i=o.useRef(null);o.useEffect(()=>{var f,b;i.current||(i.current=S(E));const x=i.current;if(!x)return;const l=m?JSON.parse(m):void 0;x.textContent=l?h((b=(f=l==null?void 0:l.colors)==null?void 0:f.raw)==null?void 0:b.blue):""},[m]),o.useEffect(()=>()=>{i.current&&(i.current.textContent="")},[]);const M=x=>{x&&n(x)};return c.jsx(p.Provider,{value:{theme:t,setTheme:M},children:r})}const a={colors:{raw:{white:{900:"255, 255, 255"},black:{900:"0, 0, 0"},blue:{50:"230, 237, 246",100:"204, 217, 237",200:"153, 179, 219",300:"102, 140, 201",400:"51, 102, 183",500:"26, 79, 160",600:"4, 37, 79",700:"3, 31, 67",800:"2, 25, 55",900:"2, 19, 43"},pink:{50:"251, 219, 241",100:"248, 183, 228",200:"245, 147, 215",300:"241, 111, 202",400:"238, 75, 189",500:"235, 39, 176",600:"215, 19, 157",700:"179, 16, 131",800:"143, 13, 104",900:"107, 9, 78"},purple:{50:"249, 229, 252",100:"240, 196, 248",200:"230, 162, 244",300:"220, 128, 240",400:"210, 95, 236",500:"200, 61, 232",600:"180, 41, 212",700:"150, 34, 177",800:"120, 27, 142",900:"90, 21, 106"},red:{50:"251, 222, 222",100:"247, 188, 188",200:"243, 153, 153",300:"239, 119, 119",400:"235, 84, 84",500:"231, 50, 50",600:"212, 30, 30",700:"176, 25, 25",800:"141, 20, 20",900:"105, 15, 15"},orange:{50:"253, 235, 217",100:"251, 215, 179",200:"249, 195, 141",300:"247, 175, 103",400:"245, 155, 65",500:"243, 135, 27",600:"224, 116, 8",700:"187, 96, 7",800:"150, 77, 6",900:"112, 58, 4"},yellow:{50:"255, 250, 219",100:"255, 246, 184",200:"255, 241, 149",300:"255, 237, 114",400:"255, 232, 79",500:"255, 228, 44",600:"236, 209, 25",700:"197, 174, 21",800:"157, 139, 17",900:"118, 104, 12"},green:{50:"236, 255, 246",100:"151, 230, 193",200:"117, 222, 173",300:"82, 214, 152",400:"48, 206, 132",500:"40, 172, 110",600:"32, 137, 88",700:"24, 103, 66",800:"16, 68, 44",900:"16, 68, 44"},brand:{default:"4, 37, 79",active:"2, 19, 43",secondary:"153, 179, 219",tertiary:"230, 237, 246"}}},metrics:{radii:{none:"0",xs:"0.25rem",sm:"0.375rem",md:"0.5rem",lg:"0.75rem",xl:"0.875rem","2xl":"1rem",full:"12rem"},spacing:{0:"0rem",1:"0.063rem",2:"0.125rem",4:"0.25rem",6:"0.375rem",8:"0.5rem",10:"0.625rem",12:"0.75rem",14:"0.875rem",16:"1rem",18:"1.125rem",20:"1.25rem",24:"1.5rem",28:"1.75rem",32:"2rem",36:"2.25rem",40:"2.5rem",48:"3rem",64:"4rem",80:"5rem",96:"6rem",128:"8rem",160:"10rem",192:"12rem",224:"14rem",256:"16rem",xs:"0.25rem",sm:"0.5rem",md:"0.75rem",lg:"1rem",xl:"1.5rem","2xl":"2rem","3xl":"4rem"},border:{default:"1px solid var(--sa-border-subtle, #0b120e24)"},shadows:{sm:"0 1px 2px 0 #0000000d",md:"0 4px 6px -1px #0000001a, 0 2px 4px -2px #0000001a",lg:"0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a",xl:"0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a","2xl":"0 25px 50px -12px #00000040",inner:"inset 0 2px 4px 0 #0000000d",card:"0px 4px 35px 0px #7090b040"}},font:{fontSizes:{xs:"0.625rem",sm:"0.75rem",md:"0.875rem",lg:"1rem",xl:"1.125rem","2xl":"1.25rem","3xl":"1.5rem","4xl":"2rem","5xl":"2.25rem","6xl":"3rem"},fontWeights:{hairline:100,thin:100,light:300,normal:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},lineHeights:{3:"0.75rem",4:"1rem",5:"1.25rem",6:"1.5rem",7:"1.75rem",8:"1.875rem",9:"2.25rem",10:"2.5rem",none:1,tight:1.25,snug:1.375,normal:1.5,relaxed:1.625,loose:2}}},d=(e,r)=>{const t={};return Object.keys(e).forEach(n=>{if(e!=null&&e[n]&&typeof(e==null?void 0:e[n])=="object"){t[n]={...e==null?void 0:e[n],...r==null?void 0:r[n],...d(e==null?void 0:e[n],r==null?void 0:r[n])};return}t[n]=(r==null?void 0:r[n])||(e==null?void 0:e[n])}),t};function u(){const e=o.useContext(p),r=o.useMemo(()=>({...a,...e.theme,...d(a,e.theme)}),[e.theme,a]);return{...e,theme:r}}function C(){const{theme:e}=u();return e.colors}function g(){var r;const{theme:e}=u();return(r=e.metrics)==null?void 0:r.spacing}function w(){var r;const{theme:e}=u();return(r=e.metrics)==null?void 0:r.radii}function y(){var r;const{theme:e}=u();return(r=e==null?void 0:e.metrics)==null?void 0:r.shadows}function O(e){return e}s.ThemeContext=p,s.ThemeProvider=v,s.createTheme=O,s.useColor=C,s.useRadius=w,s.useShadow=y,s.useSpacing=g,s.useTheme=u,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],x):(a=typeof globalThis<"u"?globalThis:a||self,x(a["@starasia/theme"]={},a.jsxRuntime,a.React))})(this,function(a,x,d){"use strict";var z,W;const V=(t,n)=>{if(typeof document>"u")return;const e=document.getElementById(n);if(e)e.textContent=t;else{const r=document.createElement("style");r.id=n,r.textContent=t,document.head.appendChild(r)}},X=t=>{if(typeof document>"u")return null;const n=document.getElementById(t);if(n)return n;const e=document.createElement("style");return e.id=t,document.head.appendChild(e),e};function S(t){let n=t.trim().replace(/^#/,"");n.length===3&&(n=n.split("").map(r=>r+r).join("")),n.length===8&&(n=n.slice(0,6));const e=parseInt(n,16);return{r:(e>>16&255)/255,g:(e>>8&255)/255,b:(e&255)/255}}const y=t=>Math.max(0,Math.min(255,Math.round(t*255))).toString(16).padStart(2,"0");function T({r:t,g:n,b:e}){return`#${y(t)}${y(n)}${y(e)}`}const h=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),L=t=>t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055;function Z(t,n,e){const r=.4122214708*t+.5363325363*n+.0514459929*e,o=.2119034982*t+.6806995451*n+.1073969566*e,s=.0883024619*t+.2817188376*n+.6299787005*e,c=Math.cbrt(r),i=Math.cbrt(o),m=Math.cbrt(s);return{L:.2104542553*c+.793617785*i-.0040720468*m,a:1.9779984951*c-2.428592205*i+.4505937099*m,b:.0259040371*c+.7827717662*i-.808675766*m}}function t0(t,n,e){const r=t+.3963377774*n+.2158037573*e,o=t-.1055613458*n-.0638541728*e,s=t-.0894841775*n-1.291485548*e,c=r*r*r,i=o*o*o,m=s*s*s;return{r:4.0767416621*c-3.3077115913*i+.2309699292*m,g:-1.2684380046*c+2.6097574011*i-.3413193965*m,b:-.0041960863*c-.7034186147*i+1.707614701*m}}function v({r:t,g:n,b:e}){const{L:r,a:o,b:s}=Z(h(t),h(n),h(e)),c=Math.sqrt(o*o+s*s);let i=Math.atan2(s,o)*180/Math.PI;return i<0&&(i+=360),{l:r,c,h:i}}const M=t=>v(S(t)),I=({r:t,g:n,b:e},r=1e-4)=>t>=-r&&t<=1+r&&n>=-r&&n<=1+r&&e>=-r&&e<=1+r;function n0({l:t,c:n,h:e}){const r=e*Math.PI/180,o=c=>t0(t,c*Math.cos(r),c*Math.sin(r));let s=o(n);if(!I(s)){let c=0,i=n;for(let m=0;m<20;m++){const u=(c+i)/2;s=o(u),I(s)?c=u:i=u}s=o(c)}return{r:Math.min(1,Math.max(0,L(s.r))),g:Math.min(1,Math.max(0,L(s.g))),b:Math.min(1,Math.max(0,L(s.b)))}}const _=t=>T(n0(t));function B({r:t,g:n,b:e}){return .2126*h(t)+.7152*h(n)+.0722*h(e)}function F(t,n){const e=B(S(t)),r=B(S(n)),o=Math.max(e,r),s=Math.min(e,r);return(o+.05)/(s+.05)}function R(t,n=["#ffffff","#1e1f21"]){let e=n[0],r=-1;for(const o of n){const s=F(t,o);s>r&&(r=s,e=o)}return e}const A=["50","100","200","300","400","500","600","700","800","900"],k=["50","100","200","300","400","500","600","700","800","900","1000","1100"],$={brand:{L:[.9434,.8816,.7612,.6375,.5179,.4415,.2695,.2429,.2155,.1878],C:[.0143,.031,.0645,.1017,.1394,.1429,.086,.0761,.066,.0549]},error:{L:[.9678,.8921,.8422,.7752,.7325,.6785,.54,.4653,.3903,.3073],C:[.0166,.0588,.09,.1362,.169,.2131,.2047,.1753,.1448,.1075]},success:{L:[.9836,.9065,.8635,.8241,.7874,.7549,.6605,.5598,.4572,.3455],C:[.0231,.0626,.0939,.1214,.1468,.1662,.1444,.1203,.0962,.0689]},info:{L:[.9783,.9523,.908,.8431,.7845,.6989,.6232,.5302,.4651,.3061],C:[.0134,.0275,.0604,.1075,.1426,.147,.1432,.1223,.1045,.0663]},warning:{L:[.9673,.9003,.8504,.8055,.7624,.6961,.5244,.3979,.2567,.2201],C:[.0205,.0679,.0991,.1284,.1495,.1346,.0998,.0731,.0415,.0332]}},H=[1,.9791,.9577,.9007,.7857,.6501,.6028,.5383,.4389,.36,.2856,.239],U=[.2127,.2401,.3133,.3673,.4198,.5093,.603,.682,.7408,.8102,.8546,.9153],e0=.02;function D(t,n){const{c:e,h:r}=M(t),o=Math.max(...n.C)||1;return n.L.map((s,c)=>_({l:s,c:e*(n.C[c]/o),h:r}))}function j(t,n){const{c:e,h:r}=M(t),o=Math.min(e,e0),s=n.length;return n.map((c,i)=>{const m=i/(s-1),u=1-Math.abs(2*m-1);return _({l:c,c:o*u,h:r})})}function r0(t,n){let e=t[0],r=1/0;for(const o of t){const s=Math.abs(M(o).l-n);s<r&&(r=s,e=o)}return e}const o0={name:"starasia",brand:"#1a4fa0",neutral:"#7d818a",error:"#ff4d6d",success:"#30ce84",info:"#00abeb",warning:"#ed9f30",radius:8,font:{body:"Inter"}},P='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',s0='ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',b=t=>Math.round(t*10)/10;function C(t,n,e,r){r.forEach((o,s)=>{t[`--sa-color-${n}-${o}`]=e[s]})}function K(t,n={}){var u,f,E;const e=n.selector??":root",r=n.darkPrimary??!0,o={},s={},c={brand:[]},i=D(t.brand,$.brand);if(c.brand=i,C(o,"brand",i,A),o["--sa-text-on-brand"]=R(i[6]),["error","success","info","warning"].forEach(l=>{const g=t[l];if(!g)return;const Q=D(g,$[l]);c[l]=Q,C(o,l,Q,A)}),t.neutral){const l=j(t.neutral,H),g=j(t.neutral,U);c.gray=l,c.dark=g,C(o,"gray",l,k),C(o,"dark",g,k)}if(typeof t.radius=="number"){const l=t.radius;o["--sa-radii-xs"]=`${b(l*.5)}px`,o["--sa-radii-sm"]=`${b(l*.75)}px`,o["--sa-radii-md"]=`${b(l)}px`,o["--sa-radii-lg"]=`${b(l*1.5)}px`,o["--sa-radii-xl"]=`${b(l*1.75)}px`,o["--sa-radii-2xl"]=`${b(l*2)}px`,o["--sa-radii-rounded"]=`${b(l)}px`}if((u=t.font)!=null&&u.body&&(o["--sa-font-family"]=`"${t.font.body}", ${P}`),(f=t.font)!=null&&f.heading&&(o["--sa-font-family-heading"]=`"${t.font.heading}", ${P}`),(E=t.font)!=null&&E.mono&&(o["--sa-font-family-mono"]=`"${t.font.mono}", ${s0}`),r){const l=i[4];s["--sa-background-brand"]=l,s["--sa-background-brand-hover"]=i[3],s["--sa-background-brand-pressed"]=i[5],s["--sa-text-on-brand"]=R(l)}return{css:a0(e,o,s),rootTokens:o,darkTokens:s,ramps:c}}function Y(t,n){const e=Object.entries(n).map(([r,o])=>` ${r}: ${o};`);return e.length?`${t} {
2
+ ${e.join(`
3
+ `)}
4
+ }`:""}function a0(t,n,e){const r=t===":root"?'[data-theme="dark"]':`${t}[data-theme="dark"], ${t} [data-theme="dark"]`;return[Y(t,n),Y(r,e)].filter(Boolean).join(`
5
+
6
+ `)}const J={colors:{raw:{white:{900:"255, 255, 255"},black:{900:"0, 0, 0"},blue:{50:"230, 237, 246",100:"204, 217, 237",200:"153, 179, 219",300:"102, 140, 201",400:"51, 102, 183",500:"26, 79, 160",600:"4, 37, 79",700:"3, 31, 67",800:"2, 25, 55",900:"2, 19, 43"},pink:{50:"251, 219, 241",100:"248, 183, 228",200:"245, 147, 215",300:"241, 111, 202",400:"238, 75, 189",500:"235, 39, 176",600:"215, 19, 157",700:"179, 16, 131",800:"143, 13, 104",900:"107, 9, 78"},purple:{50:"249, 229, 252",100:"240, 196, 248",200:"230, 162, 244",300:"220, 128, 240",400:"210, 95, 236",500:"200, 61, 232",600:"180, 41, 212",700:"150, 34, 177",800:"120, 27, 142",900:"90, 21, 106"},red:{50:"251, 222, 222",100:"247, 188, 188",200:"243, 153, 153",300:"239, 119, 119",400:"235, 84, 84",500:"231, 50, 50",600:"212, 30, 30",700:"176, 25, 25",800:"141, 20, 20",900:"105, 15, 15"},orange:{50:"253, 235, 217",100:"251, 215, 179",200:"249, 195, 141",300:"247, 175, 103",400:"245, 155, 65",500:"243, 135, 27",600:"224, 116, 8",700:"187, 96, 7",800:"150, 77, 6",900:"112, 58, 4"},yellow:{50:"255, 250, 219",100:"255, 246, 184",200:"255, 241, 149",300:"255, 237, 114",400:"255, 232, 79",500:"255, 228, 44",600:"236, 209, 25",700:"197, 174, 21",800:"157, 139, 17",900:"118, 104, 12"},green:{50:"236, 255, 246",100:"151, 230, 193",200:"117, 222, 173",300:"82, 214, 152",400:"48, 206, 132",500:"40, 172, 110",600:"32, 137, 88",700:"24, 103, 66",800:"16, 68, 44",900:"16, 68, 44"},brand:{default:"4, 37, 79",active:"2, 19, 43",secondary:"153, 179, 219",tertiary:"230, 237, 246"}}},metrics:{radii:{none:"0",xs:"0.25rem",sm:"0.375rem",md:"0.5rem",lg:"0.75rem",xl:"0.875rem","2xl":"1rem",full:"12rem"},spacing:{0:"0rem",1:"0.063rem",2:"0.125rem",4:"0.25rem",6:"0.375rem",8:"0.5rem",10:"0.625rem",12:"0.75rem",14:"0.875rem",16:"1rem",18:"1.125rem",20:"1.25rem",24:"1.5rem",28:"1.75rem",32:"2rem",36:"2.25rem",40:"2.5rem",48:"3rem",64:"4rem",80:"5rem",96:"6rem",128:"8rem",160:"10rem",192:"12rem",224:"14rem",256:"16rem",xs:"0.25rem",sm:"0.5rem",md:"0.75rem",lg:"1rem",xl:"1.5rem","2xl":"2rem","3xl":"4rem"},border:{default:"1px solid var(--sa-border-subtle, #0b120e24)"},shadows:{sm:"0 1px 2px 0 #0000000d",md:"0 4px 6px -1px #0000001a, 0 2px 4px -2px #0000001a",lg:"0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a",xl:"0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a","2xl":"0 25px 50px -12px #00000040",inner:"inset 0 2px 4px 0 #0000000d",card:"0px 4px 35px 0px #7090b040"}},font:{fontSizes:{xs:"0.625rem",sm:"0.75rem",md:"0.875rem",lg:"1rem",xl:"1.125rem","2xl":"1.25rem","3xl":"1.5rem","4xl":"2rem","5xl":"2.25rem","6xl":"3rem"},fontWeights:{hairline:100,thin:100,light:300,normal:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},lineHeights:{3:"0.75rem",4:"1rem",5:"1.25rem",6:"1.5rem",7:"1.75rem",8:"1.875rem",9:"2.25rem",10:"2.5rem",none:1,tight:1.25,snug:1.375,normal:1.5,relaxed:1.625,loose:2}}},O=d.createContext({theme:void 0,setTheme:()=>{}}),c0="sa-theme-style",N="sa-theme-seed-style";function i0(t){const n=t.split(",").map(e=>Number(e.trim()));return n.length!==3||n.some(e=>!Number.isFinite(e)||e<0||e>255)?null:"#"+n.map(e=>Math.round(e).toString(16).padStart(2,"0")).join("")}const l0=((W=(z=J.colors)==null?void 0:z.raw)==null?void 0:W.blue)??{},q=t=>(t??"").replace(/\s+/g,"");function u0(t){if(!t)return"";const n=new Set(["50","100","200","300","400","500","600","700","800","900"]),e=Object.entries(t).filter(([r])=>n.has(r)).filter(([r,o])=>q(o)!==q(l0[r])).map(([r,o])=>{const s=i0(o);return s?` --sa-color-brand-${r}: ${s};`:""}).filter(Boolean).join(`
7
+ `);return e?`:root {
8
+ ${e}
9
+ }`:""}function m0({value:t,seed:n,children:e}){const[r,o]=d.useState(t),s=d.useMemo(()=>n?JSON.stringify(n):"",[n]);d.useEffect(()=>{if(typeof document>"u")return;if(!s){const f=document.getElementById(N);f&&(f.textContent="");return}const{css:u}=K(JSON.parse(s));return V(u,N),()=>{const f=document.getElementById(N);f&&(f.textContent="")}},[s]);const c=d.useMemo(()=>r?JSON.stringify(r):"",[r]),i=d.useRef(null);d.useEffect(()=>{var E,l;i.current||(i.current=X(c0));const u=i.current;if(!u)return;const f=c?JSON.parse(c):void 0;u.textContent=f?u0((l=(E=f==null?void 0:f.colors)==null?void 0:E.raw)==null?void 0:l.blue):""},[c]),d.useEffect(()=>()=>{i.current&&(i.current.textContent="")},[]);const m=u=>{u&&o(u)};return x.jsx(O.Provider,{value:{theme:r,setTheme:m},children:e})}const w=J,G=(t,n)=>{const e={};return Object.keys(t).forEach(r=>{if(t!=null&&t[r]&&typeof(t==null?void 0:t[r])=="object"){e[r]={...t==null?void 0:t[r],...n==null?void 0:n[r],...G(t==null?void 0:t[r],n==null?void 0:n[r])};return}e[r]=(n==null?void 0:n[r])||(t==null?void 0:t[r])}),e};function p(){const t=d.useContext(O),n=d.useMemo(()=>({...w,...t.theme,...G(w,t.theme)}),[t.theme,w]);return{...t,theme:n}}function f0(){const{theme:t}=p();return t.colors}function d0(){var n;const{theme:t}=p();return(n=t.metrics)==null?void 0:n.spacing}function b0(){var n;const{theme:t}=p();return(n=t.metrics)==null?void 0:n.radii}function h0(){var n;const{theme:t}=p();return(n=t==null?void 0:t.metrics)==null?void 0:n.shadows}function x0(t){return t}a.LADDERS=$,a.NEUTRAL_LADDER_DARK=U,a.NEUTRAL_LADDER_GRAY=H,a.SA_DEFAULT_SEED=o0,a.SCALE_KEYS_10=A,a.SCALE_KEYS_12=k,a.ThemeContext=O,a.ThemeProvider=m0,a.buildTheme=K,a.contrastRatio=F,a.createTheme=x0,a.hexToOklch=M,a.hexToRgb=S,a.neutralRamp=j,a.oklchToHex=_,a.pickByLightness=r0,a.pickTextOn=R,a.rampFromSeed=D,a.rgbToHex=T,a.rgbToOklch=v,a.useColor=f0,a.useRadius=b0,a.useShadow=h0,a.useSpacing=d0,a.useTheme=p,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,66 @@
1
+ /**
2
+ * buildTheme(seed) — mesin tema Starasia.
3
+ *
4
+ * Mengubah SEED kecil (segelintir warna + radius + font) menjadi override token
5
+ * `--sa-*`. Kuncinya: token semantic Starasia didefinisikan sebagai
6
+ * `var(--sa-color-<scale>-<shade>)`, dan mapping light & dark memakai SKALA
7
+ * primitif yang sama (shade beda). Jadi cukup regenerate SKALA PRIMITIF di
8
+ * `:root` — seluruh token semantic (light & dark) ikut ter-resolve ulang tanpa
9
+ * perlu menulis ratusan token satu per satu.
10
+ *
11
+ * ⚠️ Berlaku untuk penerapan GLOBAL di `:root` (token semantic dideklarasikan di
12
+ * `:root`/`[data-theme]`). Override primitif di selector ber-scope TIDAK
13
+ * menata ulang token semantic turunan — tema ber-scope/curated (emit semantic
14
+ * penuh) adalah increment terpisah.
15
+ */
16
+ export interface ThemeSeed {
17
+ /** Nama tema (opsional, untuk export/label). */
18
+ name?: string;
19
+ /** Warna brand utama (wajib) — sumber ramp brand. */
20
+ brand: string;
21
+ /** Netral/base (opsional) — menata ulang skala gray & dark (surface). */
22
+ neutral?: string;
23
+ /** Status (opsional). Kalau diisi, skala status di-generate dari sini. */
24
+ success?: string;
25
+ warning?: string;
26
+ error?: string;
27
+ info?: string;
28
+ /** Radius `md` dalam px (opsional). Token xs..2xl diskalakan proporsional. */
29
+ radius?: number;
30
+ /** Font family (opsional). */
31
+ font?: {
32
+ body?: string;
33
+ heading?: string;
34
+ mono?: string;
35
+ };
36
+ }
37
+ export interface BuildThemeOptions {
38
+ /** Selector target. Default `:root` (penerapan global, light+dark benar). */
39
+ selector?: string;
40
+ /**
41
+ * Arahkan ulang fill primary DARK ke ramp brand (bukan azure default).
42
+ * Default true supaya brand kustom konsisten di dark mode.
43
+ */
44
+ darkPrimary?: boolean;
45
+ }
46
+ export interface BuiltTheme {
47
+ /** Teks CSS siap-inject (blok `:root` + blok dark). */
48
+ css: string;
49
+ /** Override token di `:root` (untuk export JSON). */
50
+ rootTokens: Record<string, string>;
51
+ /** Override token di blok dark. */
52
+ darkTokens: Record<string, string>;
53
+ /** Ramp mentah (untuk swatch di builder). */
54
+ ramps: {
55
+ brand: string[];
56
+ error?: string[];
57
+ success?: string[];
58
+ info?: string[];
59
+ warning?: string[];
60
+ gray?: string[];
61
+ dark?: string[];
62
+ };
63
+ }
64
+ /** Seed yang mereproduksi palet Starasia default (patokan parity & studio). */
65
+ export declare const SA_DEFAULT_SEED: ThemeSeed;
66
+ export declare function buildTheme(seed: ThemeSeed, options?: BuildThemeOptions): BuiltTheme;
@@ -0,0 +1 @@
1
+ export * from './buildTheme';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@starasia/theme",
3
3
  "author": "Prawito Hudoro",
4
- "version": "3.0.4",
4
+ "version": "3.1.0",
5
5
  "description": "Theme component for starasia UI",
6
6
  "main": "dist/index.umd.js",
7
7
  "module": "dist/index.es.js",