@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.
- package/dist/components/ThemeProvider.d.ts +25 -1
- package/dist/components/ThemeSwitcher.d.ts +28 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/hooks/useTheme.d.ts +5 -0
- package/dist/index.es.js +470 -222
- package/dist/index.umd.js +7 -7
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/persist.d.ts +31 -0
- package/package.json +1 -1
|
@@ -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;
|
package/dist/hooks/useTheme.d.ts
CHANGED
|
@@ -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
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
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
|
|
7
|
-
if (
|
|
8
|
-
|
|
6
|
+
const n = document.getElementById(e);
|
|
7
|
+
if (n)
|
|
8
|
+
n.textContent = t;
|
|
9
9
|
else {
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const r = document.createElement("style");
|
|
11
|
+
r.id = e, r.textContent = t, document.head.appendChild(r);
|
|
12
12
|
}
|
|
13
|
-
},
|
|
13
|
+
}, f0 = (t) => {
|
|
14
14
|
if (typeof document > "u")
|
|
15
15
|
return null;
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
19
|
-
const
|
|
20
|
-
return
|
|
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
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
const
|
|
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: (
|
|
28
|
-
g: (
|
|
29
|
-
b: (
|
|
27
|
+
r: (n >> 16 & 255) / 255,
|
|
28
|
+
g: (n >> 8 & 255) / 255,
|
|
29
|
+
b: (n & 255) / 255
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
function
|
|
34
|
-
return `#${
|
|
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
|
|
37
|
-
function
|
|
38
|
-
const
|
|
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 *
|
|
41
|
-
a: 1.9779984951 *
|
|
42
|
-
b: 0.0259040371 *
|
|
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
|
|
46
|
-
const
|
|
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 *
|
|
49
|
-
g: -1.2684380046 *
|
|
50
|
-
b: -0.0041960863 *
|
|
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
|
|
54
|
-
const { L:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
),
|
|
59
|
-
let
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
const
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
let
|
|
66
|
-
if (!
|
|
67
|
-
let
|
|
68
|
-
for (let
|
|
69
|
-
const
|
|
70
|
-
|
|
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
|
-
|
|
72
|
+
a = o(i);
|
|
73
73
|
}
|
|
74
74
|
return {
|
|
75
|
-
r: Math.min(1, Math.max(0,
|
|
76
|
-
g: Math.min(1, Math.max(0,
|
|
77
|
-
b: Math.min(1, Math.max(0,
|
|
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
|
|
81
|
-
function
|
|
82
|
-
return 0.2126 *
|
|
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
|
|
85
|
-
const
|
|
86
|
-
return (o + 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
|
|
89
|
-
let
|
|
90
|
-
for (const o of
|
|
91
|
-
const
|
|
92
|
-
|
|
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
|
|
94
|
+
return n;
|
|
95
95
|
}
|
|
96
|
-
const
|
|
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
|
-
},
|
|
118
|
-
function
|
|
119
|
-
const { c:
|
|
120
|
-
return
|
|
121
|
-
(
|
|
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
|
|
125
|
-
const { c:
|
|
126
|
-
return
|
|
127
|
-
const
|
|
128
|
-
return
|
|
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
|
|
132
|
-
let
|
|
131
|
+
function U0(t, e) {
|
|
132
|
+
let n = t[0], r = 1 / 0;
|
|
133
133
|
for (const o of t) {
|
|
134
|
-
const
|
|
135
|
-
|
|
134
|
+
const a = Math.abs(J(o).l - e);
|
|
135
|
+
a < r && (r = a, n = o);
|
|
136
136
|
}
|
|
137
|
-
return
|
|
137
|
+
return n;
|
|
138
138
|
}
|
|
139
|
-
const
|
|
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
|
-
},
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
t[`--sa-color-${
|
|
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
|
|
156
|
-
var
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
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
|
|
163
|
-
|
|
162
|
+
const p = Z(f, X[d]);
|
|
163
|
+
i[d] = p, _(o, d, p, Q);
|
|
164
164
|
}), t.neutral) {
|
|
165
|
-
const
|
|
166
|
-
|
|
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
|
|
170
|
-
o["--sa-radii-xs"] = `${
|
|
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 ((
|
|
173
|
-
const
|
|
174
|
-
|
|
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:
|
|
176
|
+
return { css: C0(n, o, a), rootTokens: o, darkTokens: a, ramps: i };
|
|
177
177
|
}
|
|
178
|
-
function
|
|
179
|
-
const
|
|
180
|
-
return
|
|
181
|
-
${
|
|
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
|
|
186
|
-
const
|
|
187
|
-
return [
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
389
|
-
colors:
|
|
390
|
-
metrics:
|
|
391
|
-
font:
|
|
392
|
-
},
|
|
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
|
-
}),
|
|
397
|
-
function
|
|
398
|
-
const
|
|
399
|
-
return
|
|
400
|
-
}
|
|
401
|
-
var
|
|
402
|
-
const
|
|
403
|
-
function
|
|
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
|
|
407
|
-
([
|
|
408
|
-
).map(([
|
|
409
|
-
const
|
|
410
|
-
return
|
|
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
|
|
414
|
-
${
|
|
473
|
+
return n ? `:root {
|
|
474
|
+
${n}
|
|
415
475
|
}` : "";
|
|
416
476
|
}
|
|
417
|
-
function
|
|
418
|
-
|
|
419
|
-
|
|
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 (!
|
|
423
|
-
const
|
|
424
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
|
444
|
-
|
|
445
|
-
}, [
|
|
446
|
-
|
|
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
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
|
465
|
-
}),
|
|
703
|
+
n[r] = (e == null ? void 0 : e[r]) || (t == null ? void 0 : t[r]);
|
|
704
|
+
}), n;
|
|
466
705
|
};
|
|
467
|
-
function
|
|
468
|
-
const t =
|
|
706
|
+
function R() {
|
|
707
|
+
const t = s0(T), e = U(
|
|
469
708
|
() => ({
|
|
470
|
-
...
|
|
709
|
+
...P,
|
|
471
710
|
...t.theme,
|
|
472
|
-
...
|
|
711
|
+
...l0(P, t.theme)
|
|
473
712
|
}),
|
|
474
|
-
[t.theme,
|
|
713
|
+
[t.theme, P]
|
|
475
714
|
);
|
|
476
|
-
return { ...t, theme:
|
|
715
|
+
return { ...t, theme: e };
|
|
477
716
|
}
|
|
478
|
-
function
|
|
479
|
-
const { theme: t } =
|
|
717
|
+
function z0() {
|
|
718
|
+
const { theme: t } = R();
|
|
480
719
|
return t.colors;
|
|
481
720
|
}
|
|
482
|
-
function
|
|
483
|
-
var
|
|
484
|
-
const { theme: t } =
|
|
485
|
-
return (
|
|
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
|
|
488
|
-
var
|
|
489
|
-
const { theme: t } =
|
|
490
|
-
return (
|
|
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
|
|
493
|
-
var
|
|
494
|
-
const { theme: t } =
|
|
495
|
-
return (
|
|
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
|
|
736
|
+
function Q0(t) {
|
|
498
737
|
return t;
|
|
499
738
|
}
|
|
500
739
|
export {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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(
|
|
2
|
-
${
|
|
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
|
|
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
|
|
7
|
-
`);return
|
|
8
|
-
${
|
|
9
|
-
}`:""}function
|
|
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"})});
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -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;
|