@starasia/theme 3.0.3 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +50 -46
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as S } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
2
|
+
import { createContext as E, useState as v, useMemo as a, useRef as g, useEffect as u, useContext as C } from "react";
|
|
3
|
+
const j = (r) => {
|
|
4
4
|
if (typeof document > "u")
|
|
5
5
|
return null;
|
|
6
6
|
const e = document.getElementById(r);
|
|
@@ -8,16 +8,16 @@ const w = (r) => {
|
|
|
8
8
|
return e;
|
|
9
9
|
const t = document.createElement("style");
|
|
10
10
|
return t.id = r, document.head.appendChild(t), t;
|
|
11
|
-
},
|
|
11
|
+
}, b = E({
|
|
12
12
|
theme: void 0,
|
|
13
13
|
setTheme: () => {
|
|
14
14
|
}
|
|
15
|
-
}),
|
|
15
|
+
}), w = "sa-theme-style";
|
|
16
16
|
function O(r) {
|
|
17
17
|
const e = r.split(",").map((t) => Number(t.trim()));
|
|
18
18
|
return e.length !== 3 || e.some((t) => !Number.isFinite(t) || t < 0 || t > 255) ? null : "#" + e.map((t) => Math.round(t).toString(16).padStart(2, "0")).join("");
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function y(r) {
|
|
21
21
|
if (!r)
|
|
22
22
|
return "";
|
|
23
23
|
const e = /* @__PURE__ */ new Set(["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"]), t = Object.entries(r).filter(([n]) => e.has(n)).map(([n, o]) => {
|
|
@@ -29,24 +29,28 @@ function N(r) {
|
|
|
29
29
|
${t}
|
|
30
30
|
}` : "";
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
const [t, n] =
|
|
32
|
+
function $({ value: r, children: e }) {
|
|
33
|
+
const [t, n] = v(r), o = a(
|
|
34
34
|
() => t ? JSON.stringify(t) : "",
|
|
35
35
|
[t]
|
|
36
|
-
), s = g(
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
), s = g(null);
|
|
37
|
+
u(() => {
|
|
38
|
+
var l, i;
|
|
39
|
+
s.current || (s.current = j(w));
|
|
40
|
+
const c = s.current;
|
|
41
|
+
if (!c)
|
|
42
|
+
return;
|
|
43
|
+
const x = o ? JSON.parse(o) : void 0;
|
|
44
|
+
c.textContent = x ? y((i = (l = x == null ? void 0 : x.colors) == null ? void 0 : l.raw) == null ? void 0 : i.blue) : "";
|
|
45
|
+
}, [o]), u(() => () => {
|
|
46
|
+
s.current && (s.current.textContent = "");
|
|
47
|
+
}, []);
|
|
48
|
+
const f = (c) => {
|
|
45
49
|
c && n(c);
|
|
46
50
|
};
|
|
47
|
-
return /* @__PURE__ */ S(
|
|
51
|
+
return /* @__PURE__ */ S(b.Provider, { value: { theme: t, setTheme: f }, children: e });
|
|
48
52
|
}
|
|
49
|
-
const
|
|
53
|
+
const N = {
|
|
50
54
|
raw: {
|
|
51
55
|
white: {
|
|
52
56
|
900: "255, 255, 255"
|
|
@@ -145,7 +149,7 @@ const D = {
|
|
|
145
149
|
tertiary: "230, 237, 246"
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
|
-
},
|
|
152
|
+
}, D = {
|
|
149
153
|
radii: {
|
|
150
154
|
none: "0",
|
|
151
155
|
xs: "0.25rem",
|
|
@@ -203,7 +207,7 @@ const D = {
|
|
|
203
207
|
inner: "inset 0 2px 4px 0 #0000000d",
|
|
204
208
|
card: "0px 4px 35px 0px #7090b040"
|
|
205
209
|
}
|
|
206
|
-
},
|
|
210
|
+
}, H = {
|
|
207
211
|
fontSizes: {
|
|
208
212
|
xs: "0.625rem",
|
|
209
213
|
sm: "0.75rem",
|
|
@@ -243,64 +247,64 @@ const D = {
|
|
|
243
247
|
relaxed: 1.625,
|
|
244
248
|
loose: 2
|
|
245
249
|
}
|
|
246
|
-
},
|
|
247
|
-
colors:
|
|
248
|
-
metrics:
|
|
249
|
-
font:
|
|
250
|
-
}, p =
|
|
250
|
+
}, J = {
|
|
251
|
+
colors: N,
|
|
252
|
+
metrics: D,
|
|
253
|
+
font: H
|
|
254
|
+
}, p = J, d = (r, e) => {
|
|
251
255
|
const t = {};
|
|
252
256
|
return Object.keys(r).forEach((n) => {
|
|
253
257
|
if (r != null && r[n] && typeof (r == null ? void 0 : r[n]) == "object") {
|
|
254
258
|
t[n] = {
|
|
255
259
|
...r == null ? void 0 : r[n],
|
|
256
260
|
...e == null ? void 0 : e[n],
|
|
257
|
-
...
|
|
261
|
+
...d(r == null ? void 0 : r[n], e == null ? void 0 : e[n])
|
|
258
262
|
};
|
|
259
263
|
return;
|
|
260
264
|
}
|
|
261
265
|
t[n] = (e == null ? void 0 : e[n]) || (r == null ? void 0 : r[n]);
|
|
262
266
|
}), t;
|
|
263
267
|
};
|
|
264
|
-
function
|
|
265
|
-
const r =
|
|
268
|
+
function m() {
|
|
269
|
+
const r = C(b), e = a(
|
|
266
270
|
() => ({
|
|
267
271
|
...p,
|
|
268
272
|
...r.theme,
|
|
269
|
-
...
|
|
273
|
+
...d(p, r.theme)
|
|
270
274
|
}),
|
|
271
275
|
[r.theme, p]
|
|
272
276
|
);
|
|
273
277
|
return { ...r, theme: e };
|
|
274
278
|
}
|
|
275
|
-
function
|
|
276
|
-
const { theme: r } =
|
|
279
|
+
function h() {
|
|
280
|
+
const { theme: r } = m();
|
|
277
281
|
return r.colors;
|
|
278
282
|
}
|
|
279
|
-
function
|
|
283
|
+
function B() {
|
|
280
284
|
var e;
|
|
281
|
-
const { theme: r } =
|
|
285
|
+
const { theme: r } = m();
|
|
282
286
|
return (e = r.metrics) == null ? void 0 : e.spacing;
|
|
283
287
|
}
|
|
284
|
-
function
|
|
288
|
+
function F() {
|
|
285
289
|
var e;
|
|
286
|
-
const { theme: r } =
|
|
290
|
+
const { theme: r } = m();
|
|
287
291
|
return (e = r.metrics) == null ? void 0 : e.radii;
|
|
288
292
|
}
|
|
289
|
-
function
|
|
293
|
+
function L() {
|
|
290
294
|
var e;
|
|
291
|
-
const { theme: r } =
|
|
295
|
+
const { theme: r } = m();
|
|
292
296
|
return (e = r == null ? void 0 : r.metrics) == null ? void 0 : e.shadows;
|
|
293
297
|
}
|
|
294
|
-
function
|
|
298
|
+
function P(r) {
|
|
295
299
|
return r;
|
|
296
300
|
}
|
|
297
301
|
export {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
b as ThemeContext,
|
|
303
|
+
$ as ThemeProvider,
|
|
304
|
+
P as createTheme,
|
|
305
|
+
h as useColor,
|
|
306
|
+
F as useRadius,
|
|
307
|
+
L as useShadow,
|
|
308
|
+
B as useSpacing,
|
|
309
|
+
m as useTheme
|
|
306
310
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s["@starasia/theme"]={},s.jsxRuntime,s.React))})(this,function(s,c,o){"use strict";const S=e=>{if(typeof document>"u")return null;const r=document.getElementById(e);if(r)return r;const t=document.createElement("style");return t.id=e,document.head.appendChild(t),t},p=o.createContext({theme:void 0,setTheme:()=>{}}),E="sa-theme-style";function j(e){const r=e.split(",").map(t=>Number(t.trim()));return r.length!==3||r.some(t=>!Number.isFinite(t)||t<0||t>255)?null:"#"+r.map(t=>Math.round(t).toString(16).padStart(2,"0")).join("")}function h(e){if(!e)return"";const r=new Set(["50","100","200","300","400","500","600","700","800","900"]),t=Object.entries(e).filter(([n])=>r.has(n)).map(([n,
|
|
1
|
+
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s["@starasia/theme"]={},s.jsxRuntime,s.React))})(this,function(s,c,o){"use strict";const S=e=>{if(typeof document>"u")return null;const r=document.getElementById(e);if(r)return r;const t=document.createElement("style");return t.id=e,document.head.appendChild(t),t},p=o.createContext({theme:void 0,setTheme:()=>{}}),E="sa-theme-style";function j(e){const r=e.split(",").map(t=>Number(t.trim()));return r.length!==3||r.some(t=>!Number.isFinite(t)||t<0||t>255)?null:"#"+r.map(t=>Math.round(t).toString(16).padStart(2,"0")).join("")}function h(e){if(!e)return"";const r=new Set(["50","100","200","300","400","500","600","700","800","900"]),t=Object.entries(e).filter(([n])=>r.has(n)).map(([n,m])=>{const i=j(m);return i?` --sa-color-brand-${n}: ${i};`:""}).filter(Boolean).join(`
|
|
2
2
|
`);return t?`:root {
|
|
3
3
|
${t}
|
|
4
|
-
}`:""}function
|
|
4
|
+
}`:""}function v({value:e,children:r}){const[t,n]=o.useState(e),m=o.useMemo(()=>t?JSON.stringify(t):"",[t]),i=o.useRef(null);o.useEffect(()=>{var f,b;i.current||(i.current=S(E));const x=i.current;if(!x)return;const l=m?JSON.parse(m):void 0;x.textContent=l?h((b=(f=l==null?void 0:l.colors)==null?void 0:f.raw)==null?void 0:b.blue):""},[m]),o.useEffect(()=>()=>{i.current&&(i.current.textContent="")},[]);const M=x=>{x&&n(x)};return c.jsx(p.Provider,{value:{theme:t,setTheme:M},children:r})}const a={colors:{raw:{white:{900:"255, 255, 255"},black:{900:"0, 0, 0"},blue:{50:"230, 237, 246",100:"204, 217, 237",200:"153, 179, 219",300:"102, 140, 201",400:"51, 102, 183",500:"26, 79, 160",600:"4, 37, 79",700:"3, 31, 67",800:"2, 25, 55",900:"2, 19, 43"},pink:{50:"251, 219, 241",100:"248, 183, 228",200:"245, 147, 215",300:"241, 111, 202",400:"238, 75, 189",500:"235, 39, 176",600:"215, 19, 157",700:"179, 16, 131",800:"143, 13, 104",900:"107, 9, 78"},purple:{50:"249, 229, 252",100:"240, 196, 248",200:"230, 162, 244",300:"220, 128, 240",400:"210, 95, 236",500:"200, 61, 232",600:"180, 41, 212",700:"150, 34, 177",800:"120, 27, 142",900:"90, 21, 106"},red:{50:"251, 222, 222",100:"247, 188, 188",200:"243, 153, 153",300:"239, 119, 119",400:"235, 84, 84",500:"231, 50, 50",600:"212, 30, 30",700:"176, 25, 25",800:"141, 20, 20",900:"105, 15, 15"},orange:{50:"253, 235, 217",100:"251, 215, 179",200:"249, 195, 141",300:"247, 175, 103",400:"245, 155, 65",500:"243, 135, 27",600:"224, 116, 8",700:"187, 96, 7",800:"150, 77, 6",900:"112, 58, 4"},yellow:{50:"255, 250, 219",100:"255, 246, 184",200:"255, 241, 149",300:"255, 237, 114",400:"255, 232, 79",500:"255, 228, 44",600:"236, 209, 25",700:"197, 174, 21",800:"157, 139, 17",900:"118, 104, 12"},green:{50:"236, 255, 246",100:"151, 230, 193",200:"117, 222, 173",300:"82, 214, 152",400:"48, 206, 132",500:"40, 172, 110",600:"32, 137, 88",700:"24, 103, 66",800:"16, 68, 44",900:"16, 68, 44"},brand:{default:"4, 37, 79",active:"2, 19, 43",secondary:"153, 179, 219",tertiary:"230, 237, 246"}}},metrics:{radii:{none:"0",xs:"0.25rem",sm:"0.375rem",md:"0.5rem",lg:"0.75rem",xl:"0.875rem","2xl":"1rem",full:"12rem"},spacing:{0:"0rem",1:"0.063rem",2:"0.125rem",4:"0.25rem",6:"0.375rem",8:"0.5rem",10:"0.625rem",12:"0.75rem",14:"0.875rem",16:"1rem",18:"1.125rem",20:"1.25rem",24:"1.5rem",28:"1.75rem",32:"2rem",36:"2.25rem",40:"2.5rem",48:"3rem",64:"4rem",80:"5rem",96:"6rem",128:"8rem",160:"10rem",192:"12rem",224:"14rem",256:"16rem",xs:"0.25rem",sm:"0.5rem",md:"0.75rem",lg:"1rem",xl:"1.5rem","2xl":"2rem","3xl":"4rem"},border:{default:"1px solid var(--sa-border-subtle, #0b120e24)"},shadows:{sm:"0 1px 2px 0 #0000000d",md:"0 4px 6px -1px #0000001a, 0 2px 4px -2px #0000001a",lg:"0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a",xl:"0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a","2xl":"0 25px 50px -12px #00000040",inner:"inset 0 2px 4px 0 #0000000d",card:"0px 4px 35px 0px #7090b040"}},font:{fontSizes:{xs:"0.625rem",sm:"0.75rem",md:"0.875rem",lg:"1rem",xl:"1.125rem","2xl":"1.25rem","3xl":"1.5rem","4xl":"2rem","5xl":"2.25rem","6xl":"3rem"},fontWeights:{hairline:100,thin:100,light:300,normal:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},lineHeights:{3:"0.75rem",4:"1rem",5:"1.25rem",6:"1.5rem",7:"1.75rem",8:"1.875rem",9:"2.25rem",10:"2.5rem",none:1,tight:1.25,snug:1.375,normal:1.5,relaxed:1.625,loose:2}}},d=(e,r)=>{const t={};return Object.keys(e).forEach(n=>{if(e!=null&&e[n]&&typeof(e==null?void 0:e[n])=="object"){t[n]={...e==null?void 0:e[n],...r==null?void 0:r[n],...d(e==null?void 0:e[n],r==null?void 0:r[n])};return}t[n]=(r==null?void 0:r[n])||(e==null?void 0:e[n])}),t};function u(){const e=o.useContext(p),r=o.useMemo(()=>({...a,...e.theme,...d(a,e.theme)}),[e.theme,a]);return{...e,theme:r}}function C(){const{theme:e}=u();return e.colors}function g(){var r;const{theme:e}=u();return(r=e.metrics)==null?void 0:r.spacing}function w(){var r;const{theme:e}=u();return(r=e.metrics)==null?void 0:r.radii}function y(){var r;const{theme:e}=u();return(r=e==null?void 0:e.metrics)==null?void 0:r.shadows}function O(e){return e}s.ThemeContext=p,s.ThemeProvider=v,s.createTheme=O,s.useColor=C,s.useRadius=w,s.useShadow=y,s.useSpacing=g,s.useTheme=u,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|