wg-design 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>{let t=e.replace(`#`,``);return[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)]},t=(e,t,n)=>`#`+[e,t,n].map(e=>{let t=Math.max(0,Math.min(255,Math.round(e))).toString(16);return t.length===1?`0`+t:t}).join(``),n=(n,r)=>{let[i,a,o]=e(n),s=r<0?0:255,c=Math.abs(r);return t(i+c*(s-i),a+c*(s-a),o+c*(s-o))},r=e=>({main:e,50:n(e,.85),100:n(e,.7),150:n(e,.6),200:n(e,.5),300:n(e,.35),400:n(e,.2),500:n(e,0),600:n(e,-.15),700:n(e,-.3),750:n(e,-.4),800:n(e,-.5),850:n(e,-.6),900:n(e,-.7)});function i(e,t){let n=r(t.primary),i=r(t.secondary);for(let[t,r]of Object.entries(n))t!==`main`&&e.style.setProperty(`--color-primary-${t}`,r);for(let[t,n]of Object.entries(i))t!==`main`&&e.style.setProperty(`--color-secondary-${t}`,n)}exports.applyTheme=i;
@@ -0,0 +1,2 @@
1
+ export * from './src/runtime/index'
2
+ export {}
@@ -0,0 +1,41 @@
1
+ //#region src/runtime/index.ts
2
+ var e = (e) => {
3
+ let t = e.replace("#", "");
4
+ return [
5
+ parseInt(t.substring(0, 2), 16),
6
+ parseInt(t.substring(2, 4), 16),
7
+ parseInt(t.substring(4, 6), 16)
8
+ ];
9
+ }, t = (e, t, n) => "#" + [
10
+ e,
11
+ t,
12
+ n
13
+ ].map((e) => {
14
+ let t = Math.max(0, Math.min(255, Math.round(e))).toString(16);
15
+ return t.length === 1 ? "0" + t : t;
16
+ }).join(""), n = (n, r) => {
17
+ let [i, a, o] = e(n), s = r < 0 ? 0 : 255, c = Math.abs(r);
18
+ return t(i + c * (s - i), a + c * (s - a), o + c * (s - o));
19
+ }, r = (e) => ({
20
+ main: e,
21
+ 50: n(e, .85),
22
+ 100: n(e, .7),
23
+ 150: n(e, .6),
24
+ 200: n(e, .5),
25
+ 300: n(e, .35),
26
+ 400: n(e, .2),
27
+ 500: n(e, 0),
28
+ 600: n(e, -.15),
29
+ 700: n(e, -.3),
30
+ 750: n(e, -.4),
31
+ 800: n(e, -.5),
32
+ 850: n(e, -.6),
33
+ 900: n(e, -.7)
34
+ });
35
+ function i(e, t) {
36
+ let n = r(t.primary), i = r(t.secondary);
37
+ for (let [t, r] of Object.entries(n)) t !== "main" && e.style.setProperty(`--color-primary-${t}`, r);
38
+ for (let [t, n] of Object.entries(i)) t !== "main" && e.style.setProperty(`--color-secondary-${t}`, n);
39
+ }
40
+ //#endregion
41
+ export { i as applyTheme };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Runtime helpers for applying brand themes to wg-design components.
3
+ * Brand themes in broker are defined by 2 variabled, primary, secondary.
4
+ *
5
+ * End users import this file and get will get their colors set up correctly.
6
+ *
7
+ * The scale generation is copied from existing broker platform code
8
+ */
9
+ type ApplyThemeInput = {
10
+ primary: string;
11
+ secondary: string;
12
+ };
13
+ /**
14
+ * Write a brand's primary + secondary scales to `target` as CSS custom
15
+ * properties. Each colour is expanded into the 13 stops wg-design uses
16
+ * internally (50, 100, 150, 200, 300, 400, 500, 600, 700, 750, 800, 850,
17
+ * 900). Existing wg-design components read these variables via Tailwind
18
+ * utilities — no React re-render is required.
19
+ *
20
+ * Accepts hex strings with or without a leading `#`.
21
+ *
22
+ * @example
23
+ * applyTheme(document.documentElement, {
24
+ * primary: '#CC3333',
25
+ * secondary: '#F5F5F5',
26
+ * });
27
+ */
28
+ export declare function applyTheme(target: HTMLElement, theme: ApplyThemeInput): void;
29
+ export type { ApplyThemeInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wg-design",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -11,7 +11,12 @@
11
11
  "import": "./dist/index.mjs",
12
12
  "require": "./dist/index.cjs"
13
13
  },
14
- "./style.css": "./dist/wg-design.css"
14
+ "./style.css": "./dist/wg-design.css",
15
+ "./runtime": {
16
+ "types": "./dist/runtime.d.ts",
17
+ "import": "./dist/runtime.mjs",
18
+ "require": "./dist/runtime.cjs"
19
+ }
15
20
  },
16
21
  "bin": {
17
22
  "wg-design-check-tokens": "./bin/check-design-tokens.mjs"