@starasia/theme 3.0.0 → 3.0.2

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,6 +1 @@
1
- export * from './brandcolor';
2
- export * from './colorpalette';
3
- export * from './maincolor';
4
- export * from './metric';
5
- export * from './font';
6
1
  export * from './injector';
@@ -1,2 +1,2 @@
1
1
  export declare const injectStyles: (css: string, styleId: string) => void;
2
- export declare const createStyleElement: (styleId: string) => HTMLElement;
2
+ export declare const createStyleElement: (styleId: string) => HTMLElement | null;
package/dist/index.es.js CHANGED
@@ -1,213 +1,52 @@
1
- import { jsx as w } from "react/jsx-runtime";
2
- import { createContext as O, useState as E, useMemo as y, useRef as F, useEffect as P, useContext as N } from "react";
3
- function S(r, t = "") {
4
- let o = "";
5
- for (const n in r)
6
- if (Object.hasOwnProperty.call(r, n)) {
7
- const e = r[n];
8
- o += `/* ${n} */
9
- `;
10
- for (const s in e)
11
- if (Object.hasOwnProperty.call(e, s)) {
12
- const i = e[s];
13
- o += `--${t}-${n}-${s}: ${i};
14
- `;
15
- }
16
- }
17
- return o;
18
- }
19
- function C(r, t) {
20
- let o = "";
21
- for (const n in r) {
22
- const e = r[n];
23
- for (const s in e) {
24
- const i = e[s], c = s ? `${t}-${n}-${s}` : `${t}-${n}`;
25
- o += `--${c}: ${i};
26
- `;
27
- }
28
- }
29
- return o;
30
- }
31
- function M(r, t) {
32
- let o = "";
33
- function n(e, s, i = "", c = "", l = "") {
34
- if (l) {
35
- const a = `${i}${l}-${c}-${e}`;
36
- o += `--${a}: ${s};
37
- `;
38
- } else {
39
- const a = `${i}${e}-${c}`;
40
- o += `--${a}: ${s};
41
- `;
42
- }
43
- }
44
- for (const e in r) {
45
- const s = r[e];
46
- for (const i in s) {
47
- const c = s[i];
48
- if (typeof c == "object")
49
- for (const l in c) {
50
- const a = c[l], u = `${t}-`;
51
- n(
52
- i,
53
- a,
54
- u,
55
- e,
56
- l
57
- );
58
- }
59
- else {
60
- const l = `${t}-`;
61
- n(i, c, l, e);
62
- }
63
- }
64
- }
65
- return o;
66
- }
67
- function B(r, t = "") {
68
- let o = "";
69
- function n(e, s, i = "") {
70
- if (typeof s == "object")
71
- for (const c in s) {
72
- const l = s[c], a = `--${i}-${e}-${c}`;
73
- o += `${a}: ${l};
74
- `;
75
- }
76
- else {
77
- const c = `--${i}-${e}`;
78
- o += `${c}: ${s};
79
- `;
80
- }
81
- }
82
- for (const e in r) {
83
- const s = r[e];
84
- if (typeof s == "object")
85
- n(e, s, `${t}`);
86
- else {
87
- const i = `--${t}-${e}`;
88
- o += `${i}: ${s};
89
- `;
90
- }
91
- }
92
- return o;
93
- }
94
- function D(r, t = "") {
95
- let o = "";
96
- for (const n in r) {
97
- const e = r[n];
98
- for (const s in e) {
99
- const i = `--${t}-${n}-${s}`, c = e[s];
100
- o += `${i}: ${c};
101
- `;
102
- }
103
- }
104
- return o;
105
- }
106
- function H(r, t) {
107
- let o = "";
108
- for (const n in r)
109
- if (Object.hasOwnProperty.call(r, n)) {
110
- const e = r[n];
111
- n === "default" ? o += `--${t}: ${e};
112
- ` : o += `--${t}-${n}: ${e};
113
- `;
114
- }
115
- return o;
116
- }
117
- const J = (r) => {
118
- const t = document.getElementById(r);
119
- if (t)
120
- return t;
121
- const o = document.createElement("style");
122
- return o.id = r, document.head.appendChild(o), o;
123
- };
124
- function g(r, t) {
125
- let o = "";
126
- return Object.keys(r).forEach((n) => {
127
- const e = r[n];
128
- if (e && typeof e == "object") {
129
- o += g(e, `${t}-${n}`);
130
- return;
131
- }
132
- o += `${t}-${n}: ${e};
133
- `;
134
- }), o;
135
- }
136
- function L(r, t) {
137
- let o = "";
138
- return r && (o += g(r, t)), o;
139
- }
140
- function V(r) {
141
- var u, $, p, f, b, d;
142
- if (!r)
143
- return;
144
- const t = (u = r.colors) != null && u.raw ? C(
145
- r.colors.raw,
146
- "sa-ui-raw-color"
147
- ) : "", o = ($ = r.colors) != null && $.computed ? C(
148
- r.colors.computed,
149
- "sa-ui-color"
150
- ) : "", n = (p = r.colors) != null && p.main ? M(r.colors.main, "sa-ui") : "", e = (f = r.colors) != null && f.brand ? S(r.colors.brand, "sa-ui-brand") : "", s = (b = r.colors) != null && b.utility ? S(
151
- r.colors.utility,
152
- "sa-ui-utility"
153
- ) : "", i = (d = r.colors) != null && d.text ? H(
154
- r.colors.text,
155
- "sa-ui-color-text"
156
- ) : "", c = r.metrics ? B(r.metrics, "sa-ui") : "", l = r.font ? D(r.font, "sa-ui") : "", a = r.components ? L(r.components, "--sa-ui") : "";
157
- return `
158
- :root {
159
- ${t}
160
- ${o}
161
- ${n}
162
- ${e}
163
- ${s}
164
- ${i}
165
- ${c}
166
- ${l}
167
- ${a}
168
- }
169
- `;
170
- }
171
- const j = O({
1
+ import { jsx as S } from "react/jsx-runtime";
2
+ import { createContext as f, useState as E, useMemo as a, useRef as g, useEffect as v, useContext as j } from "react";
3
+ const w = (r) => {
4
+ if (typeof document > "u")
5
+ return null;
6
+ const e = document.getElementById(r);
7
+ if (e)
8
+ return e;
9
+ const t = document.createElement("style");
10
+ return t.id = r, document.head.appendChild(t), t;
11
+ }, u = f({
172
12
  theme: void 0,
173
13
  setTheme: () => {
174
14
  }
175
- }), _ = "sa-theme-style";
176
- function z(r) {
177
- const t = r.split(",").map((o) => Number(o.trim()));
178
- return t.length !== 3 || t.some((o) => !Number.isFinite(o) || o < 0 || o > 255) ? null : "#" + t.map((o) => Math.round(o).toString(16).padStart(2, "0")).join("");
15
+ }), C = "sa-theme-style";
16
+ function O(r) {
17
+ const e = r.split(",").map((t) => Number(t.trim()));
18
+ return e.length !== 3 || e.some((t) => !Number.isFinite(t) || t < 0 || t > 255) ? null : "#" + e.map((t) => Math.round(t).toString(16).padStart(2, "0")).join("");
179
19
  }
180
- function A(r) {
20
+ function N(r) {
181
21
  if (!r)
182
22
  return "";
183
- const t = /* @__PURE__ */ new Set(["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"]), o = Object.entries(r).filter(([n]) => t.has(n)).map(([n, e]) => {
184
- const s = z(e);
23
+ const e = /* @__PURE__ */ new Set(["50", "100", "200", "300", "400", "500", "600", "700", "800", "900"]), t = Object.entries(r).filter(([n]) => e.has(n)).map(([n, o]) => {
24
+ const s = O(o);
185
25
  return s ? ` --sa-color-brand-${n}: ${s};` : "";
186
26
  }).filter(Boolean).join(`
187
27
  `);
188
- return o ? `:root {
189
- ${o}
28
+ return t ? `:root {
29
+ ${t}
190
30
  }` : "";
191
31
  }
192
- function q({ value: r, children: t }) {
193
- const [o, n] = E(r), e = y(
194
- () => o ? JSON.stringify(o) : "",
195
- [o]
196
- ), s = F(J(_));
197
- P(() => {
198
- var c, l;
199
- if (e) {
200
- const a = JSON.parse(e), u = V(a) ?? "", $ = A((l = (c = a == null ? void 0 : a.colors) == null ? void 0 : c.raw) == null ? void 0 : l.blue), p = [u, $].filter(Boolean).join(`
201
- `);
202
- p && (s != null && s.current) && (s.current.textContent = p);
32
+ function y({ value: r, children: e }) {
33
+ const [t, n] = E(r), o = a(
34
+ () => t ? JSON.stringify(t) : "",
35
+ [t]
36
+ ), s = g(w(C));
37
+ v(() => {
38
+ var c, i;
39
+ if (o) {
40
+ const m = JSON.parse(o), l = N((i = (c = m == null ? void 0 : m.colors) == null ? void 0 : c.raw) == null ? void 0 : i.blue);
41
+ l && (s != null && s.current) && (s.current.textContent = l);
203
42
  }
204
- }, [e]);
205
- const i = (c) => {
43
+ }, [o]);
44
+ const d = (c) => {
206
45
  c && n(c);
207
46
  };
208
- return /* @__PURE__ */ w(j.Provider, { value: { theme: o, setTheme: i }, children: t });
47
+ return /* @__PURE__ */ S(u.Provider, { value: { theme: t, setTheme: d }, children: e });
209
48
  }
210
- const I = {
49
+ const D = {
211
50
  raw: {
212
51
  white: {
213
52
  900: "255, 255, 255"
@@ -306,7 +145,7 @@ const I = {
306
145
  tertiary: "230, 237, 246"
307
146
  }
308
147
  }
309
- }, K = {
148
+ }, H = {
310
149
  radii: {
311
150
  none: "0",
312
151
  xs: "0.25rem",
@@ -364,7 +203,7 @@ const I = {
364
203
  inner: "inset 0 2px 4px 0 #0000000d",
365
204
  card: "0px 4px 35px 0px #7090b040"
366
205
  }
367
- }, R = {
206
+ }, J = {
368
207
  fontSizes: {
369
208
  xs: "0.625rem",
370
209
  sm: "0.75rem",
@@ -404,64 +243,64 @@ const I = {
404
243
  relaxed: 1.625,
405
244
  loose: 2
406
245
  }
407
- }, U = {
408
- colors: I,
409
- metrics: K,
410
- font: R
411
- }, m = U, v = (r, t) => {
412
- const o = {};
246
+ }, M = {
247
+ colors: D,
248
+ metrics: H,
249
+ font: J
250
+ }, p = M, b = (r, e) => {
251
+ const t = {};
413
252
  return Object.keys(r).forEach((n) => {
414
253
  if (r != null && r[n] && typeof (r == null ? void 0 : r[n]) == "object") {
415
- o[n] = {
254
+ t[n] = {
416
255
  ...r == null ? void 0 : r[n],
417
- ...t == null ? void 0 : t[n],
418
- ...v(r == null ? void 0 : r[n], t == null ? void 0 : t[n])
256
+ ...e == null ? void 0 : e[n],
257
+ ...b(r == null ? void 0 : r[n], e == null ? void 0 : e[n])
419
258
  };
420
259
  return;
421
260
  }
422
- o[n] = (t == null ? void 0 : t[n]) || (r == null ? void 0 : r[n]);
423
- }), o;
261
+ t[n] = (e == null ? void 0 : e[n]) || (r == null ? void 0 : r[n]);
262
+ }), t;
424
263
  };
425
264
  function x() {
426
- const r = N(j), t = y(
265
+ const r = j(u), e = a(
427
266
  () => ({
428
- ...m,
267
+ ...p,
429
268
  ...r.theme,
430
- ...v(m, r.theme)
269
+ ...b(p, r.theme)
431
270
  }),
432
- [r.theme, m]
271
+ [r.theme, p]
433
272
  );
434
- return { ...r, theme: t };
273
+ return { ...r, theme: e };
435
274
  }
436
- function G() {
275
+ function B() {
437
276
  const { theme: r } = x();
438
277
  return r.colors;
439
278
  }
440
- function Q() {
441
- var t;
279
+ function F() {
280
+ var e;
442
281
  const { theme: r } = x();
443
- return (t = r.metrics) == null ? void 0 : t.spacing;
282
+ return (e = r.metrics) == null ? void 0 : e.spacing;
444
283
  }
445
- function X() {
446
- var t;
284
+ function L() {
285
+ var e;
447
286
  const { theme: r } = x();
448
- return (t = r.metrics) == null ? void 0 : t.radii;
287
+ return (e = r.metrics) == null ? void 0 : e.radii;
449
288
  }
450
- function Z() {
451
- var t;
289
+ function P() {
290
+ var e;
452
291
  const { theme: r } = x();
453
- return (t = r == null ? void 0 : r.metrics) == null ? void 0 : t.shadows;
292
+ return (e = r == null ? void 0 : r.metrics) == null ? void 0 : e.shadows;
454
293
  }
455
- function k(r) {
294
+ function _(r) {
456
295
  return r;
457
296
  }
458
297
  export {
459
- j as ThemeContext,
460
- q as ThemeProvider,
461
- k as createTheme,
462
- G as useColor,
463
- X as useRadius,
464
- Z as useShadow,
465
- Q as useSpacing,
298
+ u as ThemeContext,
299
+ y as ThemeProvider,
300
+ _ as createTheme,
301
+ B as useColor,
302
+ L as useRadius,
303
+ P as useShadow,
304
+ F as useSpacing,
466
305
  x as useTheme
467
306
  };
package/dist/index.umd.js CHANGED
@@ -1,29 +1,4 @@
1
- (function(l,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],p):(l=typeof globalThis<"u"?globalThis:l||self,p(l["@starasia/theme"]={},l.jsxRuntime,l.React))})(this,function(l,p,m){"use strict";function C(r,t=""){let o="";for(const e in r)if(Object.hasOwnProperty.call(r,e)){const n=r[e];o+=`/* ${e} */
2
- `;for(const s in n)if(Object.hasOwnProperty.call(n,s)){const i=n[s];o+=`--${t}-${e}-${s}: ${i};
3
- `}}return o}function y(r,t){let o="";for(const e in r){const n=r[e];for(const s in n){const i=n[s],c=s?`${t}-${e}-${s}`:`${t}-${e}`;o+=`--${c}: ${i};
4
- `}}return o}function E(r,t){let o="";function e(n,s,i="",c="",a=""){if(a){const u=`${i}${a}-${c}-${n}`;o+=`--${u}: ${s};
5
- `}else{const u=`${i}${n}-${c}`;o+=`--${u}: ${s};
6
- `}}for(const n in r){const s=r[n];for(const i in s){const c=s[i];if(typeof c=="object")for(const a in c){const u=c[a],$=`${t}-`;e(i,u,$,n,a)}else{const a=`${t}-`;e(i,c,a,n)}}}return o}function P(r,t=""){let o="";function e(n,s,i=""){if(typeof s=="object")for(const c in s){const a=s[c],u=`--${i}-${n}-${c}`;o+=`${u}: ${a};
7
- `}else{const c=`--${i}-${n}`;o+=`${c}: ${s};
8
- `}}for(const n in r){const s=r[n];if(typeof s=="object")e(n,s,`${t}`);else{const i=`--${t}-${n}`;o+=`${i}: ${s};
9
- `}}return o}function F(r,t=""){let o="";for(const e in r){const n=r[e];for(const s in n){const i=`--${t}-${e}-${s}`,c=n[s];o+=`${i}: ${c};
10
- `}}return o}function N(r,t){let o="";for(const e in r)if(Object.hasOwnProperty.call(r,e)){const n=r[e];e==="default"?o+=`--${t}: ${n};
11
- `:o+=`--${t}-${e}: ${n};
12
- `}return o}const M=r=>{const t=document.getElementById(r);if(t)return t;const o=document.createElement("style");return o.id=r,document.head.appendChild(o),o};function j(r,t){let o="";return Object.keys(r).forEach(e=>{const n=r[e];if(n&&typeof n=="object"){o+=j(n,`${t}-${e}`);return}o+=`${t}-${e}: ${n};
13
- `}),o}function B(r,t){let o="";return r&&(o+=j(r,t)),o}function D(r){var $,b,x,v,w,O;if(!r)return;const t=($=r.colors)!=null&&$.raw?y(r.colors.raw,"sa-ui-raw-color"):"",o=(b=r.colors)!=null&&b.computed?y(r.colors.computed,"sa-ui-color"):"",e=(x=r.colors)!=null&&x.main?E(r.colors.main,"sa-ui"):"",n=(v=r.colors)!=null&&v.brand?C(r.colors.brand,"sa-ui-brand"):"",s=(w=r.colors)!=null&&w.utility?C(r.colors.utility,"sa-ui-utility"):"",i=(O=r.colors)!=null&&O.text?N(r.colors.text,"sa-ui-color-text"):"",c=r.metrics?P(r.metrics,"sa-ui"):"",a=r.font?F(r.font,"sa-ui"):"",u=r.components?B(r.components,"--sa-ui"):"";return`
14
- :root {
15
- ${t}
16
- ${o}
17
- ${e}
18
- ${n}
19
- ${s}
20
- ${i}
21
- ${c}
22
- ${a}
23
- ${u}
24
- }
25
- `}const d=m.createContext({theme:void 0,setTheme:()=>{}}),H="sa-theme-style";function R(r){const t=r.split(",").map(o=>Number(o.trim()));return t.length!==3||t.some(o=>!Number.isFinite(o)||o<0||o>255)?null:"#"+t.map(o=>Math.round(o).toString(16).padStart(2,"0")).join("")}function J(r){if(!r)return"";const t=new Set(["50","100","200","300","400","500","600","700","800","900"]),o=Object.entries(r).filter(([e])=>t.has(e)).map(([e,n])=>{const s=R(n);return s?` --sa-color-brand-${e}: ${s};`:""}).filter(Boolean).join(`
26
- `);return o?`:root {
27
- ${o}
28
- }`:""}function L({value:r,children:t}){const[o,e]=m.useState(r),n=m.useMemo(()=>o?JSON.stringify(o):"",[o]),s=m.useRef(M(H));m.useEffect(()=>{var c,a;if(n){const u=JSON.parse(n),$=D(u)??"",b=J((a=(c=u==null?void 0:u.colors)==null?void 0:c.raw)==null?void 0:a.blue),x=[$,b].filter(Boolean).join(`
29
- `);x&&(s!=null&&s.current)&&(s.current.textContent=x)}},[n]);const i=c=>{c&&e(c)};return p.jsx(d.Provider,{value:{theme:o,setTheme:i},children:t})}const S={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:200,normal:300,medium:400,semibold:500,bold:600,extrabold:700,black:800},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}}},g=(r,t)=>{const o={};return Object.keys(r).forEach(e=>{if(r!=null&&r[e]&&typeof(r==null?void 0:r[e])=="object"){o[e]={...r==null?void 0:r[e],...t==null?void 0:t[e],...g(r==null?void 0:r[e],t==null?void 0:t[e])};return}o[e]=(t==null?void 0:t[e])||(r==null?void 0:r[e])}),o};function f(){const r=m.useContext(d),t=m.useMemo(()=>({...S,...r.theme,...g(S,r.theme)}),[r.theme,S]);return{...r,theme:t}}function _(){const{theme:r}=f();return r.colors}function q(){var t;const{theme:r}=f();return(t=r.metrics)==null?void 0:t.spacing}function A(){var t;const{theme:r}=f();return(t=r.metrics)==null?void 0:t.radii}function U(){var t;const{theme:r}=f();return(t=r==null?void 0:r.metrics)==null?void 0:t.shadows}function V(r){return r}l.ThemeContext=d,l.ThemeProvider=L,l.createTheme=V,l.useColor=_,l.useRadius=A,l.useShadow=U,l.useSpacing=q,l.useTheme=f,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
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,u])=>{const i=j(u);return i?` --sa-color-brand-${n}: ${i};`:""}).filter(Boolean).join(`
2
+ `);return t?`:root {
3
+ ${t}
4
+ }`:""}function g({value:e,children:r}){const[t,n]=o.useState(e),u=o.useMemo(()=>t?JSON.stringify(t):"",[t]),i=o.useRef(S(E));o.useEffect(()=>{var x,b;if(u){const a=JSON.parse(u),f=h((b=(x=a==null?void 0:a.colors)==null?void 0:x.raw)==null?void 0:b.blue);f&&(i!=null&&i.current)&&(i.current.textContent=f)}},[u]);const M=x=>{x&&n(x)};return c.jsx(p.Provider,{value:{theme:t,setTheme:M},children:r})}const l={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:200,normal:300,medium:400,semibold:500,bold:600,extrabold:700,black:800},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 m(){const e=o.useContext(p),r=o.useMemo(()=>({...l,...e.theme,...d(l,e.theme)}),[e.theme,l]);return{...e,theme:r}}function v(){const{theme:e}=m();return e.colors}function C(){var r;const{theme:e}=m();return(r=e.metrics)==null?void 0:r.spacing}function w(){var r;const{theme:e}=m();return(r=e.metrics)==null?void 0:r.radii}function O(){var r;const{theme:e}=m();return(r=e==null?void 0:e.metrics)==null?void 0:r.shadows}function y(e){return e}s.ThemeContext=p,s.ThemeProvider=g,s.createTheme=y,s.useColor=v,s.useRadius=w,s.useShadow=O,s.useSpacing=C,s.useTheme=m,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@starasia/theme",
3
3
  "author": "Prawito Hudoro",
4
- "version": "3.0.0",
4
+ "version": "3.0.2",
5
5
  "description": "Theme component for starasia UI",
6
6
  "main": "dist/index.umd.js",
7
7
  "module": "dist/index.es.js",
@@ -1,3 +0,0 @@
1
- import { Brand, Utility } from '../types';
2
-
3
- export declare function generateBrandColorCSSFromTheme(theme: Brand & Utility, prefix?: string): string;
@@ -1,3 +0,0 @@
1
- import { Computed } from '../types/theme';
2
-
3
- export declare function generateColorPaletteCSSFromTheme(theme: Computed, variableNamePrefix: string): string;
@@ -1,3 +0,0 @@
1
- import { ThemeObject } from '../types';
2
-
3
- export declare function generateComponentCSSFromTheme(components?: ThemeObject["components"], prefix?: string): string;
@@ -1,8 +0,0 @@
1
- import { Font } from '../types/theme';
2
-
3
- export declare function generateFontCSSFromTheme(theme: Font, prefix?: string): string;
4
- interface Theme {
5
- [key: string]: string;
6
- }
7
- export declare function generateTextCSSFromTheme(theme: Theme, prefix: string): string;
8
- export {};
@@ -1,3 +0,0 @@
1
- import { ThemeObject } from '../types/theme';
2
-
3
- export declare function generateTheme(theme?: ThemeObject): string | undefined;
@@ -1,3 +0,0 @@
1
- import { Main } from '../types/theme';
2
-
3
- export declare function generateMainColorCSSFromTheme(theme: Main, variableNamePrefix: string): string;
@@ -1,3 +0,0 @@
1
- import { Metrics } from '../types/theme';
2
-
3
- export declare function generateMetricCSSFromTheme(theme: Metrics, prefix?: string): string;