@starasia/theme 3.1.0 → 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.
@@ -1,10 +1,21 @@
1
1
  import { default as React, PropsWithChildren } from 'react';
2
2
  import { ThemeObject } from '../types/theme';
3
3
  import { ThemeSeed } from '../theme/buildTheme';
4
+ import { ThemeMode } from '../theme/persist';
4
5
 
5
6
  export interface ThemeContextProps {
6
7
  theme?: ThemeObject;
7
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;
8
19
  }
9
20
  export declare const ThemeContext: React.Context<ThemeContextProps>;
10
21
  export interface ThemeProviderProps extends PropsWithChildren {
@@ -13,7 +24,20 @@ export interface ThemeProviderProps extends PropsWithChildren {
13
24
  * Seed tema (brand/status/neutral/radius/font) → di-generate penuh ke token
14
25
  * `--sa-*` lewat buildTheme dan di-inject global di `:root` (light + dark).
15
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.
16
30
  */
17
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;
18
42
  }
19
- export declare function ThemeProvider({ value, seed, 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.es.js CHANGED
@@ -1,99 +1,99 @@
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) => {
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
4
  if (typeof document > "u")
5
5
  return;
6
- const r = document.getElementById(n);
7
- if (r)
8
- r.textContent = t;
6
+ const n = document.getElementById(e);
7
+ if (n)
8
+ n.textContent = t;
9
9
  else {
10
- const e = document.createElement("style");
11
- e.id = n, e.textContent = t, document.head.appendChild(e);
10
+ const r = document.createElement("style");
11
+ r.id = e, r.textContent = t, document.head.appendChild(r);
12
12
  }
13
- }, V = (t) => {
13
+ }, f0 = (t) => {
14
14
  if (typeof document > "u")
15
15
  return null;
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;
16
+ const e = document.getElementById(t);
17
+ if (e)
18
+ return e;
19
+ const n = document.createElement("style");
20
+ return n.id = t, document.head.appendChild(n), n;
21
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);
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
26
  return {
27
- r: (r >> 16 & 255) / 255,
28
- g: (r >> 8 & 255) / 255,
29
- b: (r & 255) / 255
27
+ r: (n >> 16 & 255) / 255,
28
+ g: (n >> 8 & 255) / 255,
29
+ b: (n & 255) / 255
30
30
  };
31
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)}`;
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
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);
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
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
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
43
  };
44
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;
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
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
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
51
  };
52
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;
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
71
  }
72
- s = o(a);
72
+ a = o(i);
73
73
  }
74
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)))
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
78
  };
79
79
  }
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);
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
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);
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
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);
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
93
  }
94
- return r;
94
+ return n;
95
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 = {
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
97
  brand: {
98
98
  L: [0.9434, 0.8816, 0.7612, 0.6375, 0.5179, 0.4415, 0.2695, 0.2429, 0.2155, 0.1878],
99
99
  C: [0.0143, 0.031, 0.0645, 0.1017, 0.1394, 0.1429, 0.086, 0.0761, 0.066, 0.0549]
@@ -114,29 +114,29 @@ const D = ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"],
114
114
  L: [0.9673, 0.9003, 0.8504, 0.8055, 0.7624, 0.6961, 0.5244, 0.3979, 0.2567, 0.2201],
115
115
  C: [0.0205, 0.0679, 0.0991, 0.1284, 0.1495, 0.1346, 0.0998, 0.0731, 0.0415, 0.0332]
116
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 })
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
122
  );
123
123
  }
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 });
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
129
  });
130
130
  }
131
- function g0(t, n) {
132
- let r = t[0], e = 1 / 0;
131
+ function U0(t, e) {
132
+ let n = t[0], r = 1 / 0;
133
133
  for (const o of t) {
134
- const s = Math.abs($(o).l - n);
135
- s < e && (e = s, r = o);
134
+ const a = Math.abs(J(o).l - e);
135
+ a < r && (r = a, n = o);
136
136
  }
137
- return r;
137
+ return n;
138
138
  }
139
- const E0 = {
139
+ const H0 = {
140
140
  name: "starasia",
141
141
  brand: "#1a4fa0",
142
142
  neutral: "#7d818a",
@@ -146,49 +146,100 @@ const E0 = {
146
146
  warning: "#ed9f30",
147
147
  radius: 8,
148
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];
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
153
  });
154
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)
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
161
  return;
162
- const _ = j(p, O[i]);
163
- a[i] = _, b(o, i, _, D);
162
+ const p = Z(f, X[d]);
163
+ i[d] = p, _(o, d, p, Q);
164
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);
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
167
  }
168
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`;
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
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);
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
175
  }
176
- return { css: i0(r, o, s), rootTokens: o, darkTokens: s, ramps: a };
176
+ return { css: C0(n, o, a), rootTokens: o, darkTokens: a, ramps: i };
177
177
  }
178
- function v(t, n) {
179
- const r = Object.entries(n).map(([e, o]) => ` ${e}: ${o};`);
180
- return r.length ? `${t} {
181
- ${r.join(`
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
182
  `)}
183
183
  }` : "";
184
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(`
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
188
 
189
189
  `);
190
190
  }
191
- const l0 = {
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 = {
192
243
  raw: {
193
244
  white: {
194
245
  900: "255, 255, 255"
@@ -287,7 +338,7 @@ const l0 = {
287
338
  tertiary: "230, 237, 246"
288
339
  }
289
340
  }
290
- }, m0 = {
341
+ }, $0 = {
291
342
  radii: {
292
343
  none: "0",
293
344
  xs: "0.25rem",
@@ -345,7 +396,7 @@ const l0 = {
345
396
  inner: "inset 0 2px 4px 0 #0000000d",
346
397
  card: "0px 4px 35px 0px #7090b040"
347
398
  }
348
- }, u0 = {
399
+ }, R0 = {
349
400
  fontSizes: {
350
401
  xs: "0.625rem",
351
402
  sm: "0.75rem",
@@ -385,142 +436,339 @@ const l0 = {
385
436
  relaxed: 1.625,
386
437
  loose: 2
387
438
  }
388
- }, P = {
389
- colors: l0,
390
- metrics: m0,
391
- font: u0
392
- }, J = z({
439
+ }, i0 = {
440
+ colors: _0,
441
+ metrics: $0,
442
+ font: R0
443
+ }, T = d0({
393
444
  theme: void 0,
394
445
  setTheme: () => {
446
+ },
447
+ seed: null,
448
+ setSeed: () => {
449
+ },
450
+ setMode: () => {
451
+ },
452
+ setSkin: () => {
453
+ },
454
+ resetTheme: () => {
395
455
  }
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) {
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) {
404
464
  if (!t)
405
465
  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};` : "";
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};` : "";
411
471
  }).filter(Boolean).join(`
412
472
  `);
413
- return r ? `:root {
414
- ${r}
473
+ return n ? `:root {
474
+ ${n}
415
475
  }` : "";
416
476
  }
417
- function S0({ value: t, seed: n, children: r }) {
418
- const [e, o] = G(t), s = y(() => n ? JSON.stringify(n) : "", [n]);
419
- g(() => {
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(() => {
420
499
  if (typeof document > "u")
421
500
  return;
422
- if (!s) {
423
- const u = document.getElementById(M);
424
- u && (u.textContent = "");
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)
425
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
+ };
426
519
  }
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)
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;
529
+ if (!c)
442
530
  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 = "");
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 = "");
447
535
  }, []);
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])
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])
461
700
  };
462
701
  return;
463
702
  }
464
- r[e] = (n == null ? void 0 : n[e]) || (t == null ? void 0 : t[e]);
465
- }), r;
703
+ n[r] = (e == null ? void 0 : e[r]) || (t == null ? void 0 : t[r]);
704
+ }), n;
466
705
  };
467
- function h() {
468
- const t = W(J), n = y(
706
+ function R() {
707
+ const t = s0(T), e = U(
469
708
  () => ({
470
- ...C,
709
+ ...P,
471
710
  ...t.theme,
472
- ...K(C, t.theme)
711
+ ...l0(P, t.theme)
473
712
  }),
474
- [t.theme, C]
713
+ [t.theme, P]
475
714
  );
476
- return { ...t, theme: n };
715
+ return { ...t, theme: e };
477
716
  }
478
- function M0() {
479
- const { theme: t } = h();
717
+ function z0() {
718
+ const { theme: t } = R();
480
719
  return t.colors;
481
720
  }
482
- function C0() {
483
- var n;
484
- const { theme: t } = h();
485
- return (n = t.metrics) == null ? void 0 : n.spacing;
721
+ function G0() {
722
+ var e;
723
+ const { theme: t } = R();
724
+ return (e = t.metrics) == null ? void 0 : e.spacing;
486
725
  }
487
- function y0() {
488
- var n;
489
- const { theme: t } = h();
490
- return (n = t.metrics) == null ? void 0 : n.radii;
726
+ function W0() {
727
+ var e;
728
+ const { theme: t } = R();
729
+ return (e = t.metrics) == null ? void 0 : e.radii;
491
730
  }
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;
731
+ function K0() {
732
+ var e;
733
+ const { theme: t } = R();
734
+ return (e = t == null ? void 0 : t.metrics) == null ? void 0 : e.shadows;
496
735
  }
497
- function $0(t) {
736
+ function Q0(t) {
498
737
  return t;
499
738
  }
500
739
  export {
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
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
526
774
  };
package/dist/index.umd.js CHANGED
@@ -1,9 +1,9 @@
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(`
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
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(`
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
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"})});
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"})});
@@ -1 +1,2 @@
1
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.1.0",
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",