@starasia/theme 3.0.5 → 3.2.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,12 +1,43 @@
1
1
  import { default as React, PropsWithChildren } from 'react';
2
2
  import { ThemeObject } from '../types/theme';
3
+ import { ThemeSeed } from '../theme/buildTheme';
4
+ import { ThemeMode } from '../theme/persist';
3
5
 
4
6
  export interface ThemeContextProps {
5
7
  theme?: ThemeObject;
6
8
  setTheme: (theme?: ThemeObject) => void;
9
+ /** Seed custom aktif (Fase 2 runtime; null = tak ada). */
10
+ seed: ThemeSeed | null;
11
+ /** Ganti seed custom + persist. Hanya jalur UNCONTROLLED (tanpa prop `seed`). */
12
+ setSeed: (seed: ThemeSeed | null) => void;
13
+ /** Set mode terang/gelap/ikuti-sistem (`data-theme`) + persist. */
14
+ setMode: (mode: ThemeMode) => void;
15
+ /** Set skin (`data-skin`, mis. "tech"/"ocean") + persist. null = default. */
16
+ setSkin: (skin: string | null) => void;
17
+ /** Hapus seed custom + preferensi tersimpan. */
18
+ resetTheme: () => void;
7
19
  }
8
20
  export declare const ThemeContext: React.Context<ThemeContextProps>;
9
21
  export interface ThemeProviderProps extends PropsWithChildren {
10
22
  value?: ThemeObject;
23
+ /**
24
+ * Seed tema (brand/status/neutral/radius/font) → di-generate penuh ke token
25
+ * `--sa-*` lewat buildTheme dan di-inject global di `:root` (light + dark).
26
+ * Opt-in & additif: tanpa `seed`, perilaku lama (brand via `value`) utuh.
27
+ *
28
+ * Kalau prop ini DIISI = mode CONTROLLED (app yang pegang, tak di-persist).
29
+ * Kalau TIDAK diisi = mode UNCONTROLLED: seed dari `setSeed`/storage, di-persist.
30
+ */
31
+ seed?: ThemeSeed;
32
+ /** Simpan & pulihkan seed custom dari localStorage. Default true (auto-on). */
33
+ persist?: boolean;
34
+ /** Key localStorage untuk preferensi tema. Default `"sa-theme"`. */
35
+ storageKey?: string;
36
+ /**
37
+ * Pulihkan mode (`data-theme`) & skin (`data-skin`) tersimpan saat mount.
38
+ * Default false supaya tak bentrok dgn app yang mengelola atribut sendiri;
39
+ * untuk anti-FOUC pakai `themeBootScript()` di `<head>`.
40
+ */
41
+ manageAttributes?: boolean;
11
42
  }
12
- export declare function ThemeProvider({ value, children }: ThemeProviderProps): React.JSX.Element;
43
+ export declare function ThemeProvider({ value, seed, persist, storageKey, manageAttributes, children, }: ThemeProviderProps): React.JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { default as React } from 'react';
2
+
3
+ export interface ThemeSwitcherSkin {
4
+ /** Nilai `data-skin`. null = skin default (atribut dilepas). */
5
+ name: string | null;
6
+ label: string;
7
+ }
8
+ export interface ThemeSwitcherProps {
9
+ /** Pilihan skin. Default: Default + Tech. */
10
+ skins?: ThemeSwitcherSkin[];
11
+ /** Tampilkan segmen mode (Light/Dark/System). Default true. */
12
+ showMode?: boolean;
13
+ /** Tampilkan color picker brand custom (pakai jalur seed). Default false. */
14
+ allowCustom?: boolean;
15
+ /** Key storage (hanya untuk membaca state awal; penulisan oleh ThemeProvider). */
16
+ storageKey?: string;
17
+ className?: string;
18
+ style?: React.CSSProperties;
19
+ }
20
+ /**
21
+ * UI siap-pakai untuk pilih mode + skin (+ brand custom). Menulis atribut
22
+ * `data-theme`/`data-skin` & meng-inject seed lewat context ThemeProvider, dan
23
+ * (kalau `persist` aktif di ThemeProvider) menyimpannya ke localStorage.
24
+ *
25
+ * Catatan: untuk restore mode/skin pre-paint (anti-FOUC), pasang juga
26
+ * `themeBootScript()` di `<head>` — komponen ini merestor saat React mount.
27
+ */
28
+ export declare function ThemeSwitcher({ skins, showMode, allowCustom, storageKey, className, style, }: ThemeSwitcherProps): React.JSX.Element;
@@ -1 +1,2 @@
1
1
  export * from './ThemeProvider';
2
+ export * from './ThemeSwitcher';
@@ -3,4 +3,9 @@ import { ThemeObject } from '../types';
3
3
  export default function useTheme(): {
4
4
  theme: ThemeObject;
5
5
  setTheme: (theme?: ThemeObject | undefined) => void;
6
+ seed: import('..').ThemeSeed | null;
7
+ setSeed: (seed: import('..').ThemeSeed | null) => void;
8
+ setMode: (mode: import('..').ThemeMode) => void;
9
+ setSkin: (skin: string | null) => void;
10
+ resetTheme: () => void;
6
11
  };
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,14 +1,245 @@
1
- import { jsx as w } from "react/jsx-runtime";
2
- import { createContext as C, useState as j, useMemo as f, useRef as O, useEffect as u, useContext as D } from "react";
3
- const N = (r) => {
1
+ import { jsx as y, jsxs as z } from "react/jsx-runtime";
2
+ import { createContext as d0, useState as v, useMemo as U, useEffect as L, useRef as u0, useCallback as M, useContext as s0 } from "react";
3
+ const m0 = (t, e) => {
4
+ if (typeof document > "u")
5
+ return;
6
+ const n = document.getElementById(e);
7
+ if (n)
8
+ n.textContent = t;
9
+ else {
10
+ const r = document.createElement("style");
11
+ r.id = e, r.textContent = t, document.head.appendChild(r);
12
+ }
13
+ }, f0 = (t) => {
4
14
  if (typeof document > "u")
5
15
  return null;
6
- const e = document.getElementById(r);
16
+ const e = document.getElementById(t);
7
17
  if (e)
8
18
  return e;
9
- const t = document.createElement("style");
10
- return t.id = r, document.head.appendChild(t), t;
11
- }, y = {
19
+ const n = document.createElement("style");
20
+ return n.id = t, document.head.appendChild(n), n;
21
+ };
22
+ function H(t) {
23
+ let e = t.trim().replace(/^#/, "");
24
+ e.length === 3 && (e = e.split("").map((r) => r + r).join("")), e.length === 8 && (e = e.slice(0, 6));
25
+ const n = parseInt(e, 16);
26
+ return {
27
+ r: (n >> 16 & 255) / 255,
28
+ g: (n >> 8 & 255) / 255,
29
+ b: (n & 255) / 255
30
+ };
31
+ }
32
+ const I = (t) => Math.max(0, Math.min(255, Math.round(t * 255))).toString(16).padStart(2, "0");
33
+ function p0({ r: t, g: e, b: n }) {
34
+ return `#${I(t)}${I(e)}${I(n)}`;
35
+ }
36
+ const k = (t) => t <= 0.04045 ? t / 12.92 : Math.pow((t + 0.055) / 1.055, 2.4), j = (t) => t <= 31308e-7 ? 12.92 * t : 1.055 * Math.pow(t, 1 / 2.4) - 0.055;
37
+ function b0(t, e, n) {
38
+ const r = 0.4122214708 * t + 0.5363325363 * e + 0.0514459929 * n, o = 0.2119034982 * t + 0.6806995451 * e + 0.1073969566 * n, a = 0.0883024619 * t + 0.2817188376 * e + 0.6299787005 * n, i = Math.cbrt(r), l = Math.cbrt(o), u = Math.cbrt(a);
39
+ return {
40
+ L: 0.2104542553 * i + 0.793617785 * l - 0.0040720468 * u,
41
+ a: 1.9779984951 * i - 2.428592205 * l + 0.4505937099 * u,
42
+ b: 0.0259040371 * i + 0.7827717662 * l - 0.808675766 * u
43
+ };
44
+ }
45
+ function h0(t, e, n) {
46
+ const r = t + 0.3963377774 * e + 0.2158037573 * n, o = t - 0.1055613458 * e - 0.0638541728 * n, a = t - 0.0894841775 * e - 1.291485548 * n, i = r * r * r, l = o * o * o, u = a * a * a;
47
+ return {
48
+ r: 4.0767416621 * i - 3.3077115913 * l + 0.2309699292 * u,
49
+ g: -1.2684380046 * i + 2.6097574011 * l - 0.3413193965 * u,
50
+ b: -0.0041960863 * i - 0.7034186147 * l + 1.707614701 * u
51
+ };
52
+ }
53
+ function x0({ r: t, g: e, b: n }) {
54
+ const { L: r, a: o, b: a } = b0(
55
+ k(t),
56
+ k(e),
57
+ k(n)
58
+ ), i = Math.sqrt(o * o + a * a);
59
+ let l = Math.atan2(a, o) * 180 / Math.PI;
60
+ return l < 0 && (l += 360), { l: r, c: i, h: l };
61
+ }
62
+ const J = (t) => x0(H(t)), G = ({ r: t, g: e, b: n }, r = 1e-4) => t >= -r && t <= 1 + r && e >= -r && e <= 1 + r && n >= -r && n <= 1 + r;
63
+ function g0({ l: t, c: e, h: n }) {
64
+ const r = n * Math.PI / 180, o = (i) => h0(t, i * Math.cos(r), i * Math.sin(r));
65
+ let a = o(e);
66
+ if (!G(a)) {
67
+ let i = 0, l = e;
68
+ for (let u = 0; u < 20; u++) {
69
+ const m = (i + l) / 2;
70
+ a = o(m), G(a) ? i = m : l = m;
71
+ }
72
+ a = o(i);
73
+ }
74
+ return {
75
+ r: Math.min(1, Math.max(0, j(a.r))),
76
+ g: Math.min(1, Math.max(0, j(a.g))),
77
+ b: Math.min(1, Math.max(0, j(a.b)))
78
+ };
79
+ }
80
+ const c0 = (t) => p0(g0(t));
81
+ function W({ r: t, g: e, b: n }) {
82
+ return 0.2126 * k(t) + 0.7152 * k(e) + 0.0722 * k(n);
83
+ }
84
+ function S0(t, e) {
85
+ const n = W(H(t)), r = W(H(e)), o = Math.max(n, r), a = Math.min(n, r);
86
+ return (o + 0.05) / (a + 0.05);
87
+ }
88
+ function K(t, e = ["#ffffff", "#1e1f21"]) {
89
+ let n = e[0], r = -1;
90
+ for (const o of e) {
91
+ const a = S0(t, o);
92
+ a > r && (r = a, n = o);
93
+ }
94
+ return n;
95
+ }
96
+ const Q = ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"], V = ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "1100"], X = {
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
+ }, y0 = [1, 0.9791, 0.9577, 0.9007, 0.7857, 0.6501, 0.6028, 0.5383, 0.4389, 0.36, 0.2856, 0.239], k0 = [0.2127, 0.2401, 0.3133, 0.3673, 0.4198, 0.5093, 0.603, 0.682, 0.7408, 0.8102, 0.8546, 0.9153], E0 = 0.02;
118
+ function Z(t, e) {
119
+ const { c: n, h: r } = J(t), o = Math.max(...e.C) || 1;
120
+ return e.L.map(
121
+ (a, i) => c0({ l: a, c: n * (e.C[i] / o), h: r })
122
+ );
123
+ }
124
+ function q(t, e) {
125
+ const { c: n, h: r } = J(t), o = Math.min(n, E0), a = e.length;
126
+ return e.map((i, l) => {
127
+ const u = l / (a - 1), m = 1 - Math.abs(2 * u - 1);
128
+ return c0({ l: i, c: o * m, h: r });
129
+ });
130
+ }
131
+ function U0(t, e) {
132
+ let n = t[0], r = 1 / 0;
133
+ for (const o of t) {
134
+ const a = Math.abs(J(o).l - e);
135
+ a < r && (r = a, n = o);
136
+ }
137
+ return n;
138
+ }
139
+ const H0 = {
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
+ }, t0 = '-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"', M0 = 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace', S = (t) => Math.round(t * 10) / 10;
150
+ function _(t, e, n, r) {
151
+ r.forEach((o, a) => {
152
+ t[`--sa-color-${e}-${o}`] = n[a];
153
+ });
154
+ }
155
+ function v0(t, e = {}) {
156
+ var m, x, b;
157
+ const n = e.selector ?? ":root", r = e.darkPrimary ?? !0, o = {}, a = {}, i = { brand: [] }, l = Z(t.brand, X.brand);
158
+ if (i.brand = l, _(o, "brand", l, Q), o["--sa-text-on-brand"] = K(l[6]), ["error", "success", "info", "warning"].forEach((d) => {
159
+ const f = t[d];
160
+ if (!f)
161
+ return;
162
+ const p = Z(f, X[d]);
163
+ i[d] = p, _(o, d, p, Q);
164
+ }), t.neutral) {
165
+ const d = q(t.neutral, y0), f = q(t.neutral, k0);
166
+ i.gray = d, i.dark = f, _(o, "gray", d, V), _(o, "dark", f, V);
167
+ }
168
+ if (typeof t.radius == "number") {
169
+ const d = t.radius;
170
+ o["--sa-radii-xs"] = `${S(d * 0.5)}px`, o["--sa-radii-sm"] = `${S(d * 0.75)}px`, o["--sa-radii-md"] = `${S(d)}px`, o["--sa-radii-lg"] = `${S(d * 1.5)}px`, o["--sa-radii-xl"] = `${S(d * 1.75)}px`, o["--sa-radii-2xl"] = `${S(d * 2)}px`, o["--sa-radii-rounded"] = `${S(d)}px`;
171
+ }
172
+ if ((m = t.font) != null && m.body && (o["--sa-font-family"] = `"${t.font.body}", ${t0}`), (x = t.font) != null && x.heading && (o["--sa-font-family-heading"] = `"${t.font.heading}", ${t0}`), (b = t.font) != null && b.mono && (o["--sa-font-family-mono"] = `"${t.font.mono}", ${M0}`), r) {
173
+ const d = l[4];
174
+ a["--sa-background-brand"] = d, a["--sa-background-brand-hover"] = l[3], a["--sa-background-brand-pressed"] = l[5], a["--sa-text-on-brand"] = K(d);
175
+ }
176
+ return { css: C0(n, o, a), rootTokens: o, darkTokens: a, ramps: i };
177
+ }
178
+ function e0(t, e) {
179
+ const n = Object.entries(e).map(([r, o]) => ` ${r}: ${o};`);
180
+ return n.length ? `${t} {
181
+ ${n.join(`
182
+ `)}
183
+ }` : "";
184
+ }
185
+ function C0(t, e, n) {
186
+ const r = t === ":root" ? '[data-theme="dark"]' : `${t}[data-theme="dark"], ${t} [data-theme="dark"]`;
187
+ return [e0(t, e), e0(r, n)].filter(Boolean).join(`
188
+
189
+ `);
190
+ }
191
+ const C = "sa-theme";
192
+ function $(t = C) {
193
+ try {
194
+ if (typeof localStorage > "u")
195
+ return null;
196
+ const e = localStorage.getItem(t);
197
+ return e ? JSON.parse(e) : null;
198
+ } catch {
199
+ return null;
200
+ }
201
+ }
202
+ function w0(t, e = C) {
203
+ try {
204
+ if (typeof localStorage > "u")
205
+ return;
206
+ localStorage.setItem(e, JSON.stringify(t));
207
+ } catch {
208
+ }
209
+ }
210
+ function A0(t = C) {
211
+ try {
212
+ if (typeof localStorage > "u")
213
+ return;
214
+ localStorage.removeItem(t);
215
+ } catch {
216
+ }
217
+ }
218
+ function L0(t) {
219
+ if (t === "system")
220
+ try {
221
+ return typeof window < "u" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
222
+ } catch {
223
+ return "light";
224
+ }
225
+ return t;
226
+ }
227
+ function B(t) {
228
+ if (typeof document > "u")
229
+ return;
230
+ const e = document.documentElement;
231
+ L0(t) === "dark" ? e.setAttribute("data-theme", "dark") : e.removeAttribute("data-theme");
232
+ }
233
+ function n0(t) {
234
+ if (typeof document > "u")
235
+ return;
236
+ const e = document.documentElement;
237
+ t ? e.setAttribute("data-skin", t) : e.removeAttribute("data-skin");
238
+ }
239
+ function J0(t = C) {
240
+ return "(function(){try{var p=JSON.parse(localStorage.getItem(" + JSON.stringify(t) + ")||'{}');var d=document.documentElement;var m=p.mode==='system'?((window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light'):p.mode;if(m==='dark')d.setAttribute('data-theme','dark');if(p.skin)d.setAttribute('data-skin',p.skin);}catch(e){}})();";
241
+ }
242
+ const _0 = {
12
243
  raw: {
13
244
  white: {
14
245
  900: "255, 255, 255"
@@ -107,7 +338,7 @@ const N = (r) => {
107
338
  tertiary: "230, 237, 246"
108
339
  }
109
340
  }
110
- }, R = {
341
+ }, $0 = {
111
342
  radii: {
112
343
  none: "0",
113
344
  xs: "0.25rem",
@@ -165,7 +396,7 @@ const N = (r) => {
165
396
  inner: "inset 0 2px 4px 0 #0000000d",
166
397
  card: "0px 4px 35px 0px #7090b040"
167
398
  }
168
- }, A = {
399
+ }, R0 = {
169
400
  fontSizes: {
170
401
  xs: "0.625rem",
171
402
  sm: "0.75rem",
@@ -205,110 +436,339 @@ const N = (r) => {
205
436
  relaxed: 1.625,
206
437
  loose: 2
207
438
  }
208
- }, E = {
209
- colors: y,
210
- metrics: R,
211
- font: A
212
- }, S = C({
439
+ }, i0 = {
440
+ colors: _0,
441
+ metrics: $0,
442
+ font: R0
443
+ }, T = d0({
213
444
  theme: void 0,
214
445
  setTheme: () => {
446
+ },
447
+ seed: null,
448
+ setSeed: () => {
449
+ },
450
+ setMode: () => {
451
+ },
452
+ setSkin: () => {
453
+ },
454
+ resetTheme: () => {
215
455
  }
216
- }), B = "sa-theme-style";
217
- function F(r) {
218
- const e = r.split(",").map((t) => Number(t.trim()));
219
- 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("");
220
- }
221
- var b, d;
222
- const H = ((d = (b = E.colors) == null ? void 0 : b.raw) == null ? void 0 : d.blue) ?? {}, a = (r) => (r ?? "").replace(/\s+/g, "");
223
- function J(r) {
224
- if (!r)
456
+ }), D0 = "sa-theme-style", F = "sa-theme-seed-style";
457
+ function N0(t) {
458
+ const e = t.split(",").map((n) => Number(n.trim()));
459
+ return e.length !== 3 || e.some((n) => !Number.isFinite(n) || n < 0 || n > 255) ? null : "#" + e.map((n) => Math.round(n).toString(16).padStart(2, "0")).join("");
460
+ }
461
+ var o0, a0;
462
+ const O0 = ((a0 = (o0 = i0.colors) == null ? void 0 : o0.raw) == null ? void 0 : a0.blue) ?? {}, r0 = (t) => (t ?? "").replace(/\s+/g, "");
463
+ function I0(t) {
464
+ if (!t)
225
465
  return "";
226
- const e = /* @__PURE__ */ new Set(["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"]), t = Object.entries(r).filter(([n]) => e.has(n)).filter(
227
- ([n, o]) => a(o) !== a(H[n])
228
- ).map(([n, o]) => {
229
- const s = F(o);
230
- return s ? ` --sa-color-brand-${n}: ${s};` : "";
466
+ const e = /* @__PURE__ */ new Set(["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"]), n = Object.entries(t).filter(([r]) => e.has(r)).filter(
467
+ ([r, o]) => r0(o) !== r0(O0[r])
468
+ ).map(([r, o]) => {
469
+ const a = N0(o);
470
+ return a ? ` --sa-color-brand-${r}: ${a};` : "";
231
471
  }).filter(Boolean).join(`
232
472
  `);
233
- return t ? `:root {
234
- ${t}
473
+ return n ? `:root {
474
+ ${n}
235
475
  }` : "";
236
476
  }
237
- function _({ value: r, children: e }) {
238
- const [t, n] = j(r), o = f(
239
- () => t ? JSON.stringify(t) : "",
240
- [t]
241
- ), s = O(null);
242
- u(() => {
243
- var p, i;
244
- s.current || (s.current = N(B));
245
- const c = s.current;
477
+ function T0({
478
+ value: t,
479
+ seed: e,
480
+ persist: n = !0,
481
+ storageKey: r = C,
482
+ manageAttributes: o = !1,
483
+ children: a
484
+ }) {
485
+ const [i, l] = v(t), u = e !== void 0, [m, x] = v(() => {
486
+ if (u)
487
+ return e;
488
+ if (n) {
489
+ const c = $(r);
490
+ if (c != null && c.seed)
491
+ return c.seed;
492
+ }
493
+ return null;
494
+ }), b = u ? e : m, d = U(
495
+ () => b ? JSON.stringify(b) : "",
496
+ [b]
497
+ );
498
+ L(() => {
499
+ if (typeof document > "u")
500
+ return;
501
+ if (!d) {
502
+ const s = document.getElementById(F);
503
+ s && (s.textContent = "");
504
+ return;
505
+ }
506
+ const { css: c } = v0(JSON.parse(d));
507
+ m0(c, F);
508
+ }, [d]), L(() => {
509
+ var s;
510
+ if (!o || !n)
511
+ return;
512
+ const c = $(r);
513
+ if (c && (c.mode && B(c.mode), c.skin !== void 0 && n0(c.skin), c.mode === "system" && typeof window < "u")) {
514
+ const h = window.matchMedia("(prefers-color-scheme: dark)"), E = () => B("system");
515
+ return (s = h.addEventListener) == null || s.call(h, "change", E), () => {
516
+ var Y;
517
+ return (Y = h.removeEventListener) == null ? void 0 : Y.call(h, "change", E);
518
+ };
519
+ }
520
+ }, [o, n, r]);
521
+ const f = U(
522
+ () => i ? JSON.stringify(i) : "",
523
+ [i]
524
+ ), p = u0(null);
525
+ L(() => {
526
+ var h, E;
527
+ p.current || (p.current = f0(D0));
528
+ const c = p.current;
246
529
  if (!c)
247
530
  return;
248
- const x = o ? JSON.parse(o) : void 0;
249
- c.textContent = x ? J((i = (p = x == null ? void 0 : x.colors) == null ? void 0 : p.raw) == null ? void 0 : i.blue) : "";
250
- }, [o]), u(() => () => {
251
- s.current && (s.current.textContent = "");
531
+ const s = f ? JSON.parse(f) : void 0;
532
+ c.textContent = s ? I0((E = (h = s == null ? void 0 : s.colors) == null ? void 0 : h.raw) == null ? void 0 : E.blue) : "";
533
+ }, [f]), L(() => () => {
534
+ p.current && (p.current.textContent = "");
252
535
  }, []);
253
- const v = (c) => {
254
- c && n(c);
255
- };
256
- return /* @__PURE__ */ w(S.Provider, { value: { theme: t, setTheme: v }, children: e });
257
- }
258
- const m = E, g = (r, e) => {
259
- const t = {};
260
- return Object.keys(r).forEach((n) => {
261
- if (r != null && r[n] && typeof (r == null ? void 0 : r[n]) == "object") {
262
- t[n] = {
263
- ...r == null ? void 0 : r[n],
264
- ...e == null ? void 0 : e[n],
265
- ...g(r == null ? void 0 : r[n], e == null ? void 0 : e[n])
536
+ const D = (c) => {
537
+ c && l(c);
538
+ }, g = M(
539
+ (c) => {
540
+ if (!n)
541
+ return;
542
+ const s = $(r) || {};
543
+ w0({ ...s, ...c }, r);
544
+ },
545
+ [n, r]
546
+ ), N = M(
547
+ (c) => {
548
+ u || (x(c), g({ seed: c }));
549
+ },
550
+ [u, g]
551
+ ), O = M(
552
+ (c) => {
553
+ B(c), g({ mode: c });
554
+ },
555
+ [g]
556
+ ), w = M(
557
+ (c) => {
558
+ n0(c), g({ skin: c });
559
+ },
560
+ [g]
561
+ ), A = M(() => {
562
+ if (u || x(null), A0(r), typeof document < "u") {
563
+ const c = document.getElementById(F);
564
+ c && (c.textContent = "");
565
+ }
566
+ }, [u, r]);
567
+ return /* @__PURE__ */ y(
568
+ T.Provider,
569
+ {
570
+ value: {
571
+ theme: i,
572
+ setTheme: D,
573
+ seed: b,
574
+ setSeed: N,
575
+ setMode: O,
576
+ setSkin: w,
577
+ resetTheme: A
578
+ },
579
+ children: a
580
+ }
581
+ );
582
+ }
583
+ const j0 = [
584
+ { name: null, label: "Default" },
585
+ { name: "tech", label: "Tech" }
586
+ ], B0 = [
587
+ { value: "light", label: "Light" },
588
+ { value: "dark", label: "Dark" },
589
+ { value: "system", label: "System" }
590
+ ];
591
+ function Y0({
592
+ skins: t = j0,
593
+ showMode: e = !0,
594
+ allowCustom: n = !1,
595
+ storageKey: r,
596
+ className: o,
597
+ style: a
598
+ }) {
599
+ var c;
600
+ const { setMode: i, setSkin: l, setSeed: u } = s0(T), m = typeof window < "u" ? $(r) : null, [x, b] = v(
601
+ (m == null ? void 0 : m.mode) ?? (typeof document < "u" && document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light")
602
+ ), [d, f] = v(
603
+ (m == null ? void 0 : m.skin) ?? (typeof document < "u" ? document.documentElement.getAttribute("data-skin") : null)
604
+ ), [p, D] = v(((c = m == null ? void 0 : m.seed) == null ? void 0 : c.brand) ?? "#1a4fa0"), g = (s) => {
605
+ b(s), i(s);
606
+ }, N = (s) => {
607
+ f(s), l(s);
608
+ }, O = (s) => {
609
+ D(s), u({ brand: s });
610
+ }, w = {
611
+ display: "inline-flex",
612
+ gap: 4,
613
+ padding: 4,
614
+ borderRadius: "var(--sa-radii-md)",
615
+ background: "var(--sa-background-neutral)"
616
+ }, A = (s) => ({
617
+ border: "none",
618
+ cursor: "pointer",
619
+ fontSize: 12,
620
+ fontWeight: 500,
621
+ padding: "4px 10px",
622
+ borderRadius: "var(--sa-radii-sm)",
623
+ background: s ? "var(--sa-background-primary)" : "transparent",
624
+ color: s ? "var(--sa-text-primary)" : "var(--sa-text-subtle)",
625
+ boxShadow: s ? "var(--sa-shadow-sm)" : "none"
626
+ });
627
+ return /* @__PURE__ */ z(
628
+ "div",
629
+ {
630
+ className: o,
631
+ style: { display: "flex", gap: 12, flexWrap: "wrap", alignItems: "center", ...a },
632
+ children: [
633
+ e && /* @__PURE__ */ y("div", { role: "group", "aria-label": "Mode", style: w, children: B0.map((s) => /* @__PURE__ */ y(
634
+ "button",
635
+ {
636
+ type: "button",
637
+ "aria-pressed": x === s.value,
638
+ style: A(x === s.value),
639
+ onClick: () => g(s.value),
640
+ children: s.label
641
+ },
642
+ s.value
643
+ )) }),
644
+ t.length > 0 && /* @__PURE__ */ y("div", { role: "group", "aria-label": "Skin", style: w, children: t.map((s) => /* @__PURE__ */ y(
645
+ "button",
646
+ {
647
+ type: "button",
648
+ "aria-pressed": d === s.name,
649
+ style: A(d === s.name),
650
+ onClick: () => N(s.name),
651
+ children: s.label
652
+ },
653
+ s.name ?? "default"
654
+ )) }),
655
+ n && /* @__PURE__ */ z(
656
+ "label",
657
+ {
658
+ style: {
659
+ display: "inline-flex",
660
+ alignItems: "center",
661
+ gap: 6,
662
+ fontSize: 12,
663
+ color: "var(--sa-text-subtle)"
664
+ },
665
+ children: [
666
+ "Brand",
667
+ /* @__PURE__ */ y(
668
+ "input",
669
+ {
670
+ type: "color",
671
+ value: p,
672
+ onChange: (s) => O(s.target.value),
673
+ "aria-label": "Custom brand color",
674
+ style: {
675
+ width: 28,
676
+ height: 28,
677
+ border: "1px solid var(--sa-border-subtle)",
678
+ borderRadius: 6,
679
+ background: "none",
680
+ cursor: "pointer",
681
+ padding: 0
682
+ }
683
+ }
684
+ )
685
+ ]
686
+ }
687
+ )
688
+ ]
689
+ }
690
+ );
691
+ }
692
+ const P = i0, l0 = (t, e) => {
693
+ const n = {};
694
+ return Object.keys(t).forEach((r) => {
695
+ if (t != null && t[r] && typeof (t == null ? void 0 : t[r]) == "object") {
696
+ n[r] = {
697
+ ...t == null ? void 0 : t[r],
698
+ ...e == null ? void 0 : e[r],
699
+ ...l0(t == null ? void 0 : t[r], e == null ? void 0 : e[r])
266
700
  };
267
701
  return;
268
702
  }
269
- t[n] = (e == null ? void 0 : e[n]) || (r == null ? void 0 : r[n]);
270
- }), t;
703
+ n[r] = (e == null ? void 0 : e[r]) || (t == null ? void 0 : t[r]);
704
+ }), n;
271
705
  };
272
- function l() {
273
- const r = D(S), e = f(
706
+ function R() {
707
+ const t = s0(T), e = U(
274
708
  () => ({
275
- ...m,
276
- ...r.theme,
277
- ...g(m, r.theme)
709
+ ...P,
710
+ ...t.theme,
711
+ ...l0(P, t.theme)
278
712
  }),
279
- [r.theme, m]
713
+ [t.theme, P]
280
714
  );
281
- return { ...r, theme: e };
715
+ return { ...t, theme: e };
282
716
  }
283
- function $() {
284
- const { theme: r } = l();
285
- return r.colors;
717
+ function z0() {
718
+ const { theme: t } = R();
719
+ return t.colors;
286
720
  }
287
- function h() {
721
+ function G0() {
288
722
  var e;
289
- const { theme: r } = l();
290
- return (e = r.metrics) == null ? void 0 : e.spacing;
723
+ const { theme: t } = R();
724
+ return (e = t.metrics) == null ? void 0 : e.spacing;
291
725
  }
292
- function z() {
726
+ function W0() {
293
727
  var e;
294
- const { theme: r } = l();
295
- return (e = r.metrics) == null ? void 0 : e.radii;
728
+ const { theme: t } = R();
729
+ return (e = t.metrics) == null ? void 0 : e.radii;
296
730
  }
297
- function P() {
731
+ function K0() {
298
732
  var e;
299
- const { theme: r } = l();
300
- return (e = r == null ? void 0 : r.metrics) == null ? void 0 : e.shadows;
733
+ const { theme: t } = R();
734
+ return (e = t == null ? void 0 : t.metrics) == null ? void 0 : e.shadows;
301
735
  }
302
- function U(r) {
303
- return r;
736
+ function Q0(t) {
737
+ return t;
304
738
  }
305
739
  export {
306
- S as ThemeContext,
307
- _ as ThemeProvider,
308
- U as createTheme,
309
- $ as useColor,
310
- z as useRadius,
311
- P as useShadow,
312
- h as useSpacing,
313
- l as useTheme
740
+ C as DEFAULT_STORAGE_KEY,
741
+ X as LADDERS,
742
+ k0 as NEUTRAL_LADDER_DARK,
743
+ y0 as NEUTRAL_LADDER_GRAY,
744
+ H0 as SA_DEFAULT_SEED,
745
+ Q as SCALE_KEYS_10,
746
+ V as SCALE_KEYS_12,
747
+ T as ThemeContext,
748
+ T0 as ThemeProvider,
749
+ Y0 as ThemeSwitcher,
750
+ B as applyMode,
751
+ n0 as applySkin,
752
+ v0 as buildTheme,
753
+ A0 as clearPref,
754
+ S0 as contrastRatio,
755
+ Q0 as createTheme,
756
+ J as hexToOklch,
757
+ H as hexToRgb,
758
+ q as neutralRamp,
759
+ c0 as oklchToHex,
760
+ U0 as pickByLightness,
761
+ K as pickTextOn,
762
+ Z as rampFromSeed,
763
+ $ as readPref,
764
+ L0 as resolveMode,
765
+ p0 as rgbToHex,
766
+ x0 as rgbToOklch,
767
+ J0 as themeBootScript,
768
+ z0 as useColor,
769
+ W0 as useRadius,
770
+ K0 as useShadow,
771
+ G0 as useSpacing,
772
+ R as useTheme,
773
+ w0 as writePref
314
774
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,9 @@
1
- (function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s["@starasia/theme"]={},s.jsxRuntime,s.React))})(this,function(s,u,o){"use strict";var S,E;const v=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},d={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}}},p=o.createContext({theme:void 0,setTheme:()=>{}}),g="sa-theme-style";function C(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("")}const w=((E=(S=d.colors)==null?void 0:S.raw)==null?void 0:E.blue)??{},f=e=>(e??"").replace(/\s+/g,"");function y(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)).filter(([n,i])=>f(i)!==f(w[n])).map(([n,i])=>{const c=C(i);return c?` --sa-color-brand-${n}: ${c};`:""}).filter(Boolean).join(`
2
- `);return t?`:root {
3
- ${t}
4
- }`:""}function O({value:e,children:r}){const[t,n]=o.useState(e),i=o.useMemo(()=>t?JSON.stringify(t):"",[t]),c=o.useRef(null);o.useEffect(()=>{var j,h;c.current||(c.current=v(g));const l=c.current;if(!l)return;const x=i?JSON.parse(i):void 0;l.textContent=x?y((h=(j=x==null?void 0:x.colors)==null?void 0:j.raw)==null?void 0:h.blue):""},[i]),o.useEffect(()=>()=>{c.current&&(c.current.textContent="")},[]);const A=l=>{l&&n(l)};return u.jsx(p.Provider,{value:{theme:t,setTheme:A},children:r})}const a=d,b=(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],...b(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 m(){const e=o.useContext(p),r=o.useMemo(()=>({...a,...e.theme,...b(a,e.theme)}),[e.theme,a]);return{...e,theme:r}}function R(){const{theme:e}=m();return e.colors}function D(){var r;const{theme:e}=m();return(r=e.metrics)==null?void 0:r.spacing}function M(){var r;const{theme:e}=m();return(r=e.metrics)==null?void 0:r.radii}function N(){var r;const{theme:e}=m();return(r=e==null?void 0:e.metrics)==null?void 0:r.shadows}function P(e){return e}s.ThemeContext=p,s.ThemeProvider=O,s.createTheme=P,s.useColor=R,s.useRadius=M,s.useShadow=N,s.useSpacing=D,s.useTheme=m,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],b):(s=typeof globalThis<"u"?globalThis:s||self,b(s["@starasia/theme"]={},s.jsxRuntime,s.React))})(this,function(s,b,m){"use strict";var fe,me;const be=(e,t)=>{if(typeof document>"u")return;const n=document.getElementById(t);if(n)n.textContent=e;else{const r=document.createElement("style");r.id=t,r.textContent=e,document.head.appendChild(r)}},pe=e=>{if(typeof document>"u")return null;const t=document.getElementById(e);if(t)return t;const n=document.createElement("style");return n.id=e,document.head.appendChild(n),n};function _(e){let t=e.trim().replace(/^#/,"");t.length===3&&(t=t.split("").map(r=>r+r).join("")),t.length===8&&(t=t.slice(0,6));const n=parseInt(t,16);return{r:(n>>16&255)/255,g:(n>>8&255)/255,b:(n&255)/255}}const N=e=>Math.max(0,Math.min(255,Math.round(e*255))).toString(16).padStart(2,"0");function Q({r:e,g:t,b:n}){return`#${N(e)}${N(t)}${N(n)}`}const M=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4),j=e=>e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055;function Se(e,t,n){const r=.4122214708*e+.5363325363*t+.0514459929*n,o=.2119034982*e+.6806995451*t+.1073969566*n,a=.0883024619*e+.2817188376*t+.6299787005*n,l=Math.cbrt(r),d=Math.cbrt(o),f=Math.cbrt(a);return{L:.2104542553*l+.793617785*d-.0040720468*f,a:1.9779984951*l-2.428592205*d+.4505937099*f,b:.0259040371*l+.7827717662*d-.808675766*f}}function ge(e,t,n){const r=e+.3963377774*t+.2158037573*n,o=e-.1055613458*t-.0638541728*n,a=e-.0894841775*t-1.291485548*n,l=r*r*r,d=o*o*o,f=a*a*a;return{r:4.0767416621*l-3.3077115913*d+.2309699292*f,g:-1.2684380046*l+2.6097574011*d-.3413193965*f,b:-.0041960863*l-.7034186147*d+1.707614701*f}}function V({r:e,g:t,b:n}){const{L:r,a:o,b:a}=Se(M(e),M(t),M(n)),l=Math.sqrt(o*o+a*a);let d=Math.atan2(a,o)*180/Math.PI;return d<0&&(d+=360),{l:r,c:l,h:d}}const w=e=>V(_(e)),X=({r:e,g:t,b:n},r=1e-4)=>e>=-r&&e<=1+r&&t>=-r&&t<=1+r&&n>=-r&&n<=1+r;function xe({l:e,c:t,h:n}){const r=n*Math.PI/180,o=l=>ge(e,l*Math.cos(r),l*Math.sin(r));let a=o(t);if(!X(a)){let l=0,d=t;for(let f=0;f<20;f++){const h=(l+d)/2;a=o(h),X(a)?l=h:d=h}a=o(l)}return{r:Math.min(1,Math.max(0,j(a.r))),g:Math.min(1,Math.max(0,j(a.g))),b:Math.min(1,Math.max(0,j(a.b)))}}const I=e=>Q(xe(e));function Z({r:e,g:t,b:n}){return .2126*M(e)+.7152*M(t)+.0722*M(n)}function ee(e,t){const n=Z(_(e)),r=Z(_(t)),o=Math.max(n,r),a=Math.min(n,r);return(o+.05)/(a+.05)}function B(e,t=["#ffffff","#1e1f21"]){let n=t[0],r=-1;for(const o of t){const a=ee(e,o);a>r&&(r=a,n=o)}return n}const P=["50","100","200","300","400","500","600","700","800","900"],F=["50","100","200","300","400","500","600","700","800","900","1000","1100"],U={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]}},te=[1,.9791,.9577,.9007,.7857,.6501,.6028,.5383,.4389,.36,.2856,.239],ne=[.2127,.2401,.3133,.3673,.4198,.5093,.603,.682,.7408,.8102,.8546,.9153],ye=.02;function H(e,t){const{c:n,h:r}=w(e),o=Math.max(...t.C)||1;return t.L.map((a,l)=>I({l:a,c:n*(t.C[l]/o),h:r}))}function J(e,t){const{c:n,h:r}=w(e),o=Math.min(n,ye),a=t.length;return t.map((l,d)=>{const f=d/(a-1),h=1-Math.abs(2*f-1);return I({l,c:o*h,h:r})})}function ke(e,t){let n=e[0],r=1/0;for(const o of e){const a=Math.abs(w(o).l-t);a<r&&(r=a,n=o)}return n}const Ee={name:"starasia",brand:"#1a4fa0",neutral:"#7d818a",error:"#ff4d6d",success:"#30ce84",info:"#00abeb",warning:"#ed9f30",radius:8,font:{body:"Inter"}},re='-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"',Me='ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',E=e=>Math.round(e*10)/10;function D(e,t,n,r){r.forEach((o,a)=>{e[`--sa-color-${t}-${o}`]=n[a]})}function oe(e,t={}){var h,y,g;const n=t.selector??":root",r=t.darkPrimary??!0,o={},a={},l={brand:[]},d=H(e.brand,U.brand);if(l.brand=d,D(o,"brand",d,P),o["--sa-text-on-brand"]=B(d[6]),["error","success","info","warning"].forEach(u=>{const p=e[u];if(!p)return;const S=H(p,U[u]);l[u]=S,D(o,u,S,P)}),e.neutral){const u=J(e.neutral,te),p=J(e.neutral,ne);l.gray=u,l.dark=p,D(o,"gray",u,F),D(o,"dark",p,F)}if(typeof e.radius=="number"){const u=e.radius;o["--sa-radii-xs"]=`${E(u*.5)}px`,o["--sa-radii-sm"]=`${E(u*.75)}px`,o["--sa-radii-md"]=`${E(u)}px`,o["--sa-radii-lg"]=`${E(u*1.5)}px`,o["--sa-radii-xl"]=`${E(u*1.75)}px`,o["--sa-radii-2xl"]=`${E(u*2)}px`,o["--sa-radii-rounded"]=`${E(u)}px`}if((h=e.font)!=null&&h.body&&(o["--sa-font-family"]=`"${e.font.body}", ${re}`),(y=e.font)!=null&&y.heading&&(o["--sa-font-family-heading"]=`"${e.font.heading}", ${re}`),(g=e.font)!=null&&g.mono&&(o["--sa-font-family-mono"]=`"${e.font.mono}", ${Me}`),r){const u=d[4];a["--sa-background-brand"]=u,a["--sa-background-brand-hover"]=d[3],a["--sa-background-brand-pressed"]=d[5],a["--sa-text-on-brand"]=B(u)}return{css:Ce(n,o,a),rootTokens:o,darkTokens:a,ramps:l}}function ae(e,t){const n=Object.entries(t).map(([r,o])=>` ${r}: ${o};`);return n.length?`${e} {
2
+ ${n.join(`
3
+ `)}
4
+ }`:""}function Ce(e,t,n){const r=e===":root"?'[data-theme="dark"]':`${e}[data-theme="dark"], ${e} [data-theme="dark"]`;return[ae(e,t),ae(r,n)].filter(Boolean).join(`
5
+
6
+ `)}const C="sa-theme";function v(e=C){try{if(typeof localStorage>"u")return null;const t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function se(e,t=C){try{if(typeof localStorage>"u")return;localStorage.setItem(t,JSON.stringify(e))}catch{}}function ie(e=C){try{if(typeof localStorage>"u")return;localStorage.removeItem(e)}catch{}}function ce(e){if(e==="system")try{return typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}catch{return"light"}return e}function R(e){if(typeof document>"u")return;const t=document.documentElement;ce(e)==="dark"?t.setAttribute("data-theme","dark"):t.removeAttribute("data-theme")}function Y(e){if(typeof document>"u")return;const t=document.documentElement;e?t.setAttribute("data-skin",e):t.removeAttribute("data-skin")}function ve(e=C){return"(function(){try{var p=JSON.parse(localStorage.getItem("+JSON.stringify(e)+")||'{}');var d=document.documentElement;var m=p.mode==='system'?((window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light'):p.mode;if(m==='dark')d.setAttribute('data-theme','dark');if(p.skin)d.setAttribute('data-skin',p.skin);}catch(e){}})();"}const le={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=m.createContext({theme:void 0,setTheme:()=>{},seed:null,setSeed:()=>{},setMode:()=>{},setSkin:()=>{},resetTheme:()=>{}}),Ae="sa-theme-style",G="sa-theme-seed-style";function Le(e){const t=e.split(",").map(n=>Number(n.trim()));return t.length!==3||t.some(n=>!Number.isFinite(n)||n<0||n>255)?null:"#"+t.map(n=>Math.round(n).toString(16).padStart(2,"0")).join("")}const _e=((me=(fe=le.colors)==null?void 0:fe.raw)==null?void 0:me.blue)??{},de=e=>(e??"").replace(/\s+/g,"");function we(e){if(!e)return"";const t=new Set(["50","100","200","300","400","500","600","700","800","900"]),n=Object.entries(e).filter(([r])=>t.has(r)).filter(([r,o])=>de(o)!==de(_e[r])).map(([r,o])=>{const a=Le(o);return a?` --sa-color-brand-${r}: ${a};`:""}).filter(Boolean).join(`
7
+ `);return n?`:root {
8
+ ${n}
9
+ }`:""}function De({value:e,seed:t,persist:n=!0,storageKey:r=C,manageAttributes:o=!1,children:a}){const[l,d]=m.useState(e),f=t!==void 0,[h,y]=m.useState(()=>{if(f)return t;if(n){const c=v(r);if(c!=null&&c.seed)return c.seed}return null}),g=f?t:h,u=m.useMemo(()=>g?JSON.stringify(g):"",[g]);m.useEffect(()=>{if(typeof document>"u")return;if(!u){const i=document.getElementById(G);i&&(i.textContent="");return}const{css:c}=oe(JSON.parse(u));be(c,G)},[u]),m.useEffect(()=>{var i;if(!o||!n)return;const c=v(r);if(c&&(c.mode&&R(c.mode),c.skin!==void 0&&Y(c.skin),c.mode==="system"&&typeof window<"u")){const x=window.matchMedia("(prefers-color-scheme: dark)"),L=()=>R("system");return(i=x.addEventListener)==null||i.call(x,"change",L),()=>{var he;return(he=x.removeEventListener)==null?void 0:he.call(x,"change",L)}}},[o,n,r]);const p=m.useMemo(()=>l?JSON.stringify(l):"",[l]),S=m.useRef(null);m.useEffect(()=>{var x,L;S.current||(S.current=pe(Ae));const c=S.current;if(!c)return;const i=p?JSON.parse(p):void 0;c.textContent=i?we((L=(x=i==null?void 0:i.colors)==null?void 0:x.raw)==null?void 0:L.blue):""},[p]),m.useEffect(()=>()=>{S.current&&(S.current.textContent="")},[]);const K=c=>{c&&d(c)},k=m.useCallback(c=>{if(!n)return;const i=v(r)||{};se({...i,...c},r)},[n,r]),W=m.useCallback(c=>{f||(y(c),k({seed:c}))},[f,k]),q=m.useCallback(c=>{R(c),k({mode:c})},[k]),$=m.useCallback(c=>{Y(c),k({skin:c})},[k]),T=m.useCallback(()=>{if(f||y(null),ie(r),typeof document<"u"){const c=document.getElementById(G);c&&(c.textContent="")}},[f,r]);return b.jsx(O.Provider,{value:{theme:l,setTheme:K,seed:g,setSeed:W,setMode:q,setSkin:$,resetTheme:T},children:a})}const Re=[{name:null,label:"Default"},{name:"tech",label:"Tech"}],Oe=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function $e({skins:e=Re,showMode:t=!0,allowCustom:n=!1,storageKey:r,className:o,style:a}){var c;const{setMode:l,setSkin:d,setSeed:f}=m.useContext(O),h=typeof window<"u"?v(r):null,[y,g]=m.useState((h==null?void 0:h.mode)??(typeof document<"u"&&document.documentElement.getAttribute("data-theme")==="dark"?"dark":"light")),[u,p]=m.useState((h==null?void 0:h.skin)??(typeof document<"u"?document.documentElement.getAttribute("data-skin"):null)),[S,K]=m.useState(((c=h==null?void 0:h.seed)==null?void 0:c.brand)??"#1a4fa0"),k=i=>{g(i),l(i)},W=i=>{p(i),d(i)},q=i=>{K(i),f({brand:i})},$={display:"inline-flex",gap:4,padding:4,borderRadius:"var(--sa-radii-md)",background:"var(--sa-background-neutral)"},T=i=>({border:"none",cursor:"pointer",fontSize:12,fontWeight:500,padding:"4px 10px",borderRadius:"var(--sa-radii-sm)",background:i?"var(--sa-background-primary)":"transparent",color:i?"var(--sa-text-primary)":"var(--sa-text-subtle)",boxShadow:i?"var(--sa-shadow-sm)":"none"});return b.jsxs("div",{className:o,style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"center",...a},children:[t&&b.jsx("div",{role:"group","aria-label":"Mode",style:$,children:Oe.map(i=>b.jsx("button",{type:"button","aria-pressed":y===i.value,style:T(y===i.value),onClick:()=>k(i.value),children:i.label},i.value))}),e.length>0&&b.jsx("div",{role:"group","aria-label":"Skin",style:$,children:e.map(i=>b.jsx("button",{type:"button","aria-pressed":u===i.name,style:T(u===i.name),onClick:()=>W(i.name),children:i.label},i.name??"default"))}),n&&b.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12,color:"var(--sa-text-subtle)"},children:["Brand",b.jsx("input",{type:"color",value:S,onChange:i=>q(i.target.value),"aria-label":"Custom brand color",style:{width:28,height:28,border:"1px solid var(--sa-border-subtle)",borderRadius:6,background:"none",cursor:"pointer",padding:0}})]})]})}const z=le,ue=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{if(e!=null&&e[r]&&typeof(e==null?void 0:e[r])=="object"){n[r]={...e==null?void 0:e[r],...t==null?void 0:t[r],...ue(e==null?void 0:e[r],t==null?void 0:t[r])};return}n[r]=(t==null?void 0:t[r])||(e==null?void 0:e[r])}),n};function A(){const e=m.useContext(O),t=m.useMemo(()=>({...z,...e.theme,...ue(z,e.theme)}),[e.theme,z]);return{...e,theme:t}}function Te(){const{theme:e}=A();return e.colors}function Ne(){var t;const{theme:e}=A();return(t=e.metrics)==null?void 0:t.spacing}function je(){var t;const{theme:e}=A();return(t=e.metrics)==null?void 0:t.radii}function Ie(){var t;const{theme:e}=A();return(t=e==null?void 0:e.metrics)==null?void 0:t.shadows}function Be(e){return e}s.DEFAULT_STORAGE_KEY=C,s.LADDERS=U,s.NEUTRAL_LADDER_DARK=ne,s.NEUTRAL_LADDER_GRAY=te,s.SA_DEFAULT_SEED=Ee,s.SCALE_KEYS_10=P,s.SCALE_KEYS_12=F,s.ThemeContext=O,s.ThemeProvider=De,s.ThemeSwitcher=$e,s.applyMode=R,s.applySkin=Y,s.buildTheme=oe,s.clearPref=ie,s.contrastRatio=ee,s.createTheme=Be,s.hexToOklch=w,s.hexToRgb=_,s.neutralRamp=J,s.oklchToHex=I,s.pickByLightness=ke,s.pickTextOn=B,s.rampFromSeed=H,s.readPref=v,s.resolveMode=ce,s.rgbToHex=Q,s.rgbToOklch=V,s.themeBootScript=ve,s.useColor=Te,s.useRadius=je,s.useShadow=Ie,s.useSpacing=Ne,s.useTheme=A,s.writePref=se,Object.defineProperty(s,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,2 @@
1
+ export * from './buildTheme';
2
+ export * from './persist';
@@ -0,0 +1,31 @@
1
+ import { ThemeSeed } from './buildTheme';
2
+
3
+ export type ThemeMode = "light" | "dark" | "system";
4
+ export interface ThemePref {
5
+ /** Seed custom (warna buatan user). */
6
+ seed?: ThemeSeed | null;
7
+ /** Mode terang/gelap/ikuti-sistem. */
8
+ mode?: ThemeMode;
9
+ /** Skin aktif (data-skin), mis. "tech"/"ocean". null = default. */
10
+ skin?: string | null;
11
+ }
12
+ export declare const DEFAULT_STORAGE_KEY = "sa-theme";
13
+ export declare function readPref(key?: string): ThemePref | null;
14
+ export declare function writePref(pref: ThemePref, key?: string): void;
15
+ export declare function clearPref(key?: string): void;
16
+ export type ResolvedMode = "light" | "dark";
17
+ /** Resolve "system" ke light/dark via prefers-color-scheme. */
18
+ export declare function resolveMode(mode: ThemeMode): ResolvedMode;
19
+ /** Terapkan mode ke <html data-theme>. dark → set; light → hapus (default). */
20
+ export declare function applyMode(mode: ThemeMode): void;
21
+ /** Terapkan skin ke <html data-skin>. null/"" → hapus (skin default). */
22
+ export declare function applySkin(skin: string | null | undefined): void;
23
+ /**
24
+ * Snippet JS untuk disisipkan inline di `<head>` SEBELUM bundle app — merestor
25
+ * mode + skin pre-paint (anti-FOUC). Seed custom (warna) tetap apply saat React
26
+ * mount (butuh CSS generate), jadi hanya mode/skin yang bebas-flash.
27
+ *
28
+ * Pakai: `<script dangerouslySetInnerHTML={{__html: themeBootScript()}} />` di
29
+ * document/_document, atau inline di index.html.
30
+ */
31
+ export declare function themeBootScript(key?: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@starasia/theme",
3
3
  "author": "Prawito Hudoro",
4
- "version": "3.0.5",
4
+ "version": "3.2.0",
5
5
  "description": "Theme component for starasia UI",
6
6
  "main": "dist/index.umd.js",
7
7
  "module": "dist/index.es.js",