asterui 0.12.54 → 0.12.56

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
+ {"version":3,"file":"ThemeProvider.js","sources":["../../src/components/ThemeProvider.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useState, useCallback, useMemo } from 'react'\n\n// Common dark themes in DaisyUI\nconst DARK_THEMES = new Set([\n 'dark', 'synthwave', 'halloween', 'forest', 'black', 'luxury', 'dracula',\n 'business', 'night', 'coffee', 'dim', 'sunset'\n])\n\nexport interface ThemeProviderProps {\n children: React.ReactNode\n /** Default theme. Use \"system\" to follow browser preference. */\n defaultTheme?: string\n /** localStorage key for persisting theme. Set to false to disable persistence. */\n storageKey?: string | false\n /** Light theme to use when system preference is light */\n lightTheme?: string\n /** Dark theme to use when system preference is dark */\n darkTheme?: string\n /** Custom function to determine if a theme is dark */\n isDarkTheme?: (theme: string) => boolean\n}\n\nexport interface ThemeColors {\n background: string\n foreground: string\n primary: string\n primaryContent: string\n secondary: string\n accent: string\n info: string\n success: string\n warning: string\n error: string\n}\n\nexport interface ThemeContextValue {\n /** The theme setting (what user selected: \"system\", \"light\", \"dark\", etc.) */\n theme: string\n /** The actual applied theme after resolving \"system\" */\n resolvedTheme: string\n /** Whether the resolved theme is dark */\n isDark: boolean\n /** Set the theme */\n setTheme: (theme: string) => void\n /** Computed theme colors as hex values (for canvas/non-CSS contexts) */\n colors: ThemeColors\n /** The system preference (\"light\" or \"dark\") */\n systemTheme: 'light' | 'dark'\n}\n\nconst ThemeContext = createContext<ThemeContextValue | undefined>(undefined)\n\n// Convert any CSS color to hex\nfunction colorToHex(color: string): string {\n if (typeof document === 'undefined') return '#000000'\n const canvas = document.createElement('canvas')\n canvas.width = canvas.height = 1\n const ctx = canvas.getContext('2d')\n if (!ctx) return '#000000'\n ctx.fillStyle = color\n ctx.fillRect(0, 0, 1, 1)\n const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data\n return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`\n}\n\nfunction getThemeColors(): ThemeColors {\n if (typeof document === 'undefined') {\n return {\n background: '#ffffff',\n foreground: '#000000',\n primary: '#6366f1',\n primaryContent: '#ffffff',\n secondary: '#f000b8',\n accent: '#37cdbe',\n info: '#3abff8',\n success: '#36d399',\n warning: '#fbbd23',\n error: '#f87272',\n }\n }\n\n const style = getComputedStyle(document.documentElement)\n const getColor = (varName: string, fallback: string): string => {\n const value = style.getPropertyValue(varName).trim()\n return value ? colorToHex(value) : fallback\n }\n\n return {\n background: getColor('--color-base-100', '#ffffff'),\n foreground: getColor('--color-base-content', '#000000'),\n primary: getColor('--color-primary', '#6366f1'),\n primaryContent: getColor('--color-primary-content', '#ffffff'),\n secondary: getColor('--color-secondary', '#f000b8'),\n accent: getColor('--color-accent', '#37cdbe'),\n info: getColor('--color-info', '#3abff8'),\n success: getColor('--color-success', '#36d399'),\n warning: getColor('--color-warning', '#fbbd23'),\n error: getColor('--color-error', '#f87272'),\n }\n}\n\nfunction getSystemTheme(): 'light' | 'dark' {\n if (typeof window === 'undefined') return 'light'\n return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'\n}\n\nfunction getStoredTheme(key: string | false): string | null {\n if (!key || typeof window === 'undefined') return null\n try {\n return localStorage.getItem(key)\n } catch {\n return null\n }\n}\n\nfunction storeTheme(key: string | false, theme: string): void {\n if (!key || typeof window === 'undefined') return\n try {\n localStorage.setItem(key, theme)\n } catch {\n // Ignore storage errors\n }\n}\n\nexport function ThemeProvider({\n children,\n defaultTheme = 'system',\n storageKey = 'asterui-theme',\n lightTheme = 'light',\n darkTheme = 'dark',\n isDarkTheme,\n}: ThemeProviderProps) {\n // Initialize theme from storage or default\n const [theme, setThemeState] = useState<string>(() => {\n const stored = getStoredTheme(storageKey)\n return stored || defaultTheme\n })\n\n // Track system preference\n const [systemTheme, setSystemTheme] = useState<'light' | 'dark'>(getSystemTheme)\n\n // Resolve the actual theme\n const resolvedTheme = useMemo(() => {\n if (theme === 'system') {\n return systemTheme === 'dark' ? darkTheme : lightTheme\n }\n return theme\n }, [theme, systemTheme, lightTheme, darkTheme])\n\n // Determine if dark\n const isDark = useMemo(() => {\n if (isDarkTheme) return isDarkTheme(resolvedTheme)\n return DARK_THEMES.has(resolvedTheme)\n }, [resolvedTheme, isDarkTheme])\n\n // Track colors (updated after theme applies)\n const [colors, setColors] = useState<ThemeColors>(getThemeColors)\n\n // Set theme function\n const setTheme = useCallback((newTheme: string) => {\n setThemeState(newTheme)\n storeTheme(storageKey, newTheme)\n }, [storageKey])\n\n // Apply theme to document\n useEffect(() => {\n if (typeof document === 'undefined') return\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n\n // Double RAF ensures CSS has fully recalculated after attribute change\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n setColors(getThemeColors())\n })\n })\n }, [resolvedTheme])\n\n // Listen for system preference changes\n useEffect(() => {\n if (typeof window === 'undefined') return\n\n const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const handleChange = (e: MediaQueryListEvent) => {\n setSystemTheme(e.matches ? 'dark' : 'light')\n }\n\n mediaQuery.addEventListener('change', handleChange)\n return () => mediaQuery.removeEventListener('change', handleChange)\n }, [])\n\n // Listen for storage changes (cross-tab sync)\n useEffect(() => {\n if (!storageKey || typeof window === 'undefined') return\n\n const handleStorage = (e: StorageEvent) => {\n if (e.key === storageKey && e.newValue) {\n setThemeState(e.newValue)\n }\n }\n\n window.addEventListener('storage', handleStorage)\n return () => window.removeEventListener('storage', handleStorage)\n }, [storageKey])\n\n const value = useMemo<ThemeContextValue>(() => ({\n theme,\n resolvedTheme,\n isDark,\n setTheme,\n colors,\n systemTheme,\n }), [theme, resolvedTheme, isDark, setTheme, colors, systemTheme])\n\n return (\n <ThemeContext.Provider value={value}>\n {children}\n </ThemeContext.Provider>\n )\n}\n\n/**\n * Hook to access theme context.\n * Must be used within a ThemeProvider.\n */\nexport function useThemeContext(): ThemeContextValue {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useThemeContext must be used within a ThemeProvider')\n }\n return context\n}\n\n/**\n * Check if ThemeProvider is present in the tree.\n */\nexport function useHasThemeProvider(): boolean {\n return useContext(ThemeContext) !== undefined\n}\n"],"names":["DARK_THEMES","ThemeContext","createContext","colorToHex","color","canvas","ctx","r","g","b","getThemeColors","style","getColor","varName","fallback","value","getSystemTheme","getStoredTheme","key","storeTheme","theme","ThemeProvider","children","defaultTheme","storageKey","lightTheme","darkTheme","isDarkTheme","setThemeState","useState","systemTheme","setSystemTheme","resolvedTheme","useMemo","isDark","colors","setColors","setTheme","useCallback","newTheme","useEffect","mediaQuery","handleChange","e","handleStorage","jsx","useThemeContext","context","useContext","useHasThemeProvider"],"mappings":";;AAGA,MAAMA,wBAAkB,IAAI;AAAA,EAC1B;AAAA,EAAQ;AAAA,EAAa;AAAA,EAAa;AAAA,EAAU;AAAA,EAAS;AAAA,EAAU;AAAA,EAC/D;AAAA,EAAY;AAAA,EAAS;AAAA,EAAU;AAAA,EAAO;AACxC,CAAC,GA4CKC,IAAeC,EAA6C,MAAS;AAG3E,SAASC,EAAWC,GAAuB;AACzC,MAAI,OAAO,WAAa,IAAa,QAAO;AAC5C,QAAMC,IAAS,SAAS,cAAc,QAAQ;AAC9C,EAAAA,EAAO,QAAQA,EAAO,SAAS;AAC/B,QAAMC,IAAMD,EAAO,WAAW,IAAI;AAClC,MAAI,CAACC,EAAK,QAAO;AACjB,EAAAA,EAAI,YAAYF,GAChBE,EAAI,SAAS,GAAG,GAAG,GAAG,CAAC;AACvB,QAAM,CAACC,GAAGC,GAAGC,CAAC,IAAIH,EAAI,aAAa,GAAG,GAAG,GAAG,CAAC,EAAE;AAC/C,SAAO,MAAM,KAAK,OAAOC,KAAK,OAAOC,KAAK,KAAKC,GAAG,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACzE;AAEA,SAASC,IAA8B;AACrC,MAAI,OAAO,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AAG,CAAA,CAAE,GAGLF,EAAU,MAAM;AACd,QAAI,CAAChB,KAAc,OAAO,SAAW,IAAa;AAElD,UAAMoB,IAAgB,CAACD,MAAoB;AACzC,MAAIA,EAAE,QAAQnB,KAAcmB,EAAE,YAC5Bf,EAAce,EAAE,QAAQ;AAAA,IAE5B;AAEA,kBAAO,iBAAiB,WAAWC,CAAa,GACzC,MAAM,OAAO,oBAAoB,WAAWA,CAAa;AAAA,EAClE,GAAG,CAACpB,CAAU,CAAC;AAEf,QAAMT,IAAQkB,EAA2B,OAAO;AAAA,IAC9C,OAAAb;AAAA,IACA,eAAAY;AAAA,IACA,QAAAE;AAAA,IACA,UAAAG;AAAA,IACA,QAAAF;AAAA,IACA,aAAAL;AAAA,EAAA,IACE,CAACV,GAAOY,GAAeE,GAAQG,GAAUF,GAAQL,CAAW,CAAC;AAEjE,SACE,gBAAAe,EAAC5C,EAAa,UAAb,EAAsB,OAAAc,GACpB,UAAAO,EAAA,CACH;AAEJ;AAMO,SAASwB,IAAqC;AACnD,QAAMC,IAAUC,EAAW/C,CAAY;AACvC,MAAI,CAAC8C;AACH,UAAM,IAAI,MAAM,qDAAqD;AAEvE,SAAOA;AACT;AAKO,SAASE,IAA+B;AAC7C,SAAOD,EAAW/C,CAAY,MAAM;AACtC;"}
@@ -1,120 +1,112 @@
1
- import { jsxs as z, jsx as R } from "react/jsx-runtime";
2
- import { useState as V, useMemo as P, useEffect as Y } from "react";
3
- const D = "asterui", O = 0.22, U = (t, c = O) => {
4
- const r = `rgba(0,0,0,${c})`;
5
- if (t && t.includes("var(--bc")) {
6
- if (typeof window < "u") {
7
- const a = getComputedStyle(document.documentElement).getPropertyValue("--bc").trim(), g = getComputedStyle(document.body).getPropertyValue("--bc").trim(), m = a || g;
8
- if (m)
9
- return t.replace(/var\(--bc\)/g, m);
10
- }
11
- return r;
12
- }
13
- if (t) return t;
14
- if (typeof window > "u") return r;
15
- const i = getComputedStyle(document.documentElement).getPropertyValue("--bc").trim(), d = getComputedStyle(document.body).getPropertyValue("--bc").trim(), s = i || d;
16
- return s ? `hsl(${s} / ${c})` : r;
17
- }, M = (t, c) => {
18
- const r = t?.fontSize ?? 16;
1
+ import { jsxs as R, jsx as Y } from "react/jsx-runtime";
2
+ import { useState as D, useMemo as A, useEffect as M } from "react";
3
+ import { useTheme as U } from "../hooks/useTheme.js";
4
+ const B = "asterui", X = 0.22;
5
+ function _(r, l) {
6
+ const n = Math.round(l * 255).toString(16).padStart(2, "0");
7
+ return r + n;
8
+ }
9
+ const K = (r, l) => {
10
+ const n = r?.fontSize ?? 16;
19
11
  return {
20
- color: c,
21
- fontSize: r,
22
- fontWeight: t?.fontWeight ?? 600,
23
- fontStyle: t?.fontStyle ?? "normal",
24
- fontFamily: t?.fontFamily ?? "sans-serif",
25
- lineHeight: t?.lineHeight ?? r * 1.2
12
+ color: l,
13
+ fontSize: n,
14
+ fontWeight: r?.fontWeight ?? 600,
15
+ fontStyle: r?.fontStyle ?? "normal",
16
+ fontFamily: r?.fontFamily ?? "sans-serif",
17
+ lineHeight: r?.lineHeight ?? n * 1.2
26
18
  };
27
- }, X = ({
28
- children: t,
29
- className: c = "",
30
- style: r,
31
- content: i,
32
- image: d,
33
- width: s = 120,
34
- height: a = 64,
35
- gap: g,
36
- offset: m,
37
- rotate: T = -22,
38
- zIndex: W = 1e3,
39
- font: S,
40
- ...A
19
+ }, q = ({
20
+ children: r,
21
+ className: l = "",
22
+ style: n,
23
+ content: c,
24
+ image: v,
25
+ width: a = 120,
26
+ height: i = 64,
27
+ gap: E,
28
+ offset: k,
29
+ rotate: F = -22,
30
+ zIndex: I = 1e3,
31
+ font: y,
32
+ ...b
41
33
  }) => {
42
- const [y, $] = V(null), u = g?.[0] ?? 120, f = g?.[1] ?? 120, B = m?.[0] ?? u / 2, F = m?.[1] ?? f / 2, E = P(
43
- () => typeof i == "string" ? [i] : Array.isArray(i) ? i : [D],
44
- [i]
45
- ), k = U(S?.color), l = P(
46
- () => M(S, k),
47
- [S, k]
48
- ), h = Math.PI / 180 * T, I = E.join("|");
49
- Y(() => {
34
+ const [m, L] = D(null), d = E?.[0] ?? 120, f = E?.[1] ?? 120, H = k?.[0] ?? d / 2, N = k?.[1] ?? f / 2, { colors: P } = U(), h = A(
35
+ () => typeof c == "string" ? [c] : Array.isArray(c) ? c : [B],
36
+ [c]
37
+ ), W = y?.color ?? _(P.foreground, X), s = A(
38
+ () => K(y, W),
39
+ [y, W]
40
+ ), S = Math.PI / 180 * F, j = h.join("|");
41
+ M(() => {
50
42
  if (typeof window > "u") return;
51
- let p = !1;
52
- const n = window.devicePixelRatio || 1, w = s + u, C = a + f, v = document.createElement("canvas");
53
- v.width = w * n, v.height = C * n;
54
- const e = v.getContext("2d");
43
+ let u = !1;
44
+ const o = window.devicePixelRatio || 1, $ = a + d, T = i + f, g = document.createElement("canvas");
45
+ g.width = $ * o, g.height = T * o;
46
+ const e = g.getContext("2d");
55
47
  if (!e) return;
56
- const L = () => {
57
- const o = v.toDataURL();
58
- p || $({ url: o, width: w, height: C });
59
- }, N = () => {
60
- e.save(), e.translate((u / 2 + s / 2) * n, (f / 2 + a / 2) * n), e.rotate(h), e.fillStyle = l.color, e.textAlign = "center", e.textBaseline = "middle", e.font = `${l.fontStyle} normal ${l.fontWeight} ${l.fontSize * n}px ${l.fontFamily}`;
61
- const o = l.lineHeight * n, b = -((E.length - 1) * o) / 2;
62
- E.forEach((x, j) => {
63
- e.fillText(x, 0, b + j * o);
48
+ const w = () => {
49
+ const t = g.toDataURL();
50
+ u || L({ url: t, width: $, height: T });
51
+ }, C = () => {
52
+ e.save(), e.translate((d / 2 + a / 2) * o, (f / 2 + i / 2) * o), e.rotate(S), e.fillStyle = s.color, e.textAlign = "center", e.textBaseline = "middle", e.font = `${s.fontStyle} normal ${s.fontWeight} ${s.fontSize * o}px ${s.fontFamily}`;
53
+ const t = s.lineHeight * o, p = -((h.length - 1) * t) / 2;
54
+ h.forEach((x, O) => {
55
+ e.fillText(x, 0, p + O * t);
64
56
  }), e.restore();
65
57
  };
66
- if (d) {
67
- const o = new Image();
68
- o.crossOrigin = "anonymous", o.referrerPolicy = "no-referrer";
69
- const b = () => {
70
- e.save(), e.translate((u / 2 + s / 2) * n, (f / 2 + a / 2) * n), e.rotate(h), e.drawImage(
71
- o,
72
- -s / 2 * n,
73
- -a / 2 * n,
74
- s * n,
75
- a * n
76
- ), e.restore(), L();
58
+ if (v) {
59
+ const t = new Image();
60
+ t.crossOrigin = "anonymous", t.referrerPolicy = "no-referrer";
61
+ const p = () => {
62
+ e.save(), e.translate((d / 2 + a / 2) * o, (f / 2 + i / 2) * o), e.rotate(S), e.drawImage(
63
+ t,
64
+ -a / 2 * o,
65
+ -i / 2 * o,
66
+ a * o,
67
+ i * o
68
+ ), e.restore(), w();
77
69
  }, x = () => {
78
- p || $(null);
70
+ u || L(null);
79
71
  };
80
- return o.addEventListener("load", b), o.addEventListener("error", x), o.src = d, () => {
81
- p = !0, o.removeEventListener("load", b), o.removeEventListener("error", x);
72
+ return t.addEventListener("load", p), t.addEventListener("error", x), t.src = v, () => {
73
+ u = !0, t.removeEventListener("load", p), t.removeEventListener("error", x);
82
74
  };
83
75
  } else
84
- N(), L();
76
+ C(), w();
85
77
  return () => {
86
- p = !0;
78
+ u = !0;
87
79
  };
88
80
  }, [
89
- l,
90
- u,
91
- f,
92
- a,
81
+ s,
93
82
  d,
94
- h,
95
- I,
96
- s
83
+ f,
84
+ i,
85
+ v,
86
+ S,
87
+ j,
88
+ a
97
89
  ]);
98
- const H = ["relative", c].filter(Boolean).join(" ");
99
- return /* @__PURE__ */ z(
90
+ const z = ["relative", l].filter(Boolean).join(" ");
91
+ return /* @__PURE__ */ R(
100
92
  "div",
101
93
  {
102
- className: H,
103
- style: { position: r?.position ?? "relative", ...r },
104
- ...A,
94
+ className: z,
95
+ style: { position: n?.position ?? "relative", ...n },
96
+ ...b,
105
97
  children: [
106
- t,
107
- y && /* @__PURE__ */ R(
98
+ r,
99
+ m && /* @__PURE__ */ Y(
108
100
  "div",
109
101
  {
110
102
  "aria-hidden": !0,
111
103
  className: "pointer-events-none absolute inset-0",
112
104
  style: {
113
- zIndex: W,
114
- backgroundImage: `url(${y.url})`,
105
+ zIndex: I,
106
+ backgroundImage: `url(${m.url})`,
115
107
  backgroundRepeat: "repeat",
116
- backgroundSize: `${y.width}px ${y.height}px`,
117
- backgroundPosition: `${B}px ${F}px`
108
+ backgroundSize: `${m.width}px ${m.height}px`,
109
+ backgroundPosition: `${H}px ${N}px`
118
110
  }
119
111
  }
120
112
  )
@@ -122,8 +114,8 @@ const D = "asterui", O = 0.22, U = (t, c = O) => {
122
114
  }
123
115
  );
124
116
  };
125
- X.displayName = "Watermark";
117
+ q.displayName = "Watermark";
126
118
  export {
127
- X as Watermark
119
+ q as Watermark
128
120
  };
129
121
  //# sourceMappingURL=Watermark.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Watermark.js","sources":["../../src/components/Watermark.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useState } from 'react'\n\nexport type WatermarkGap = [number, number]\nexport type WatermarkOffset = [number, number]\n\nexport interface WatermarkFontOptions {\n /** Text color for watermark content */\n color?: string\n /** Font size in pixels */\n fontSize?: number\n /** Font weight for watermark text */\n fontWeight?: number | 'normal' | 'bold' | 'bolder' | 'lighter'\n /** Font style for watermark text */\n fontStyle?: 'normal' | 'italic' | 'oblique'\n /** Font family for watermark text */\n fontFamily?: string\n /** Line height in pixels for multi-line content */\n lineHeight?: number\n}\n\nexport interface WatermarkProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'content'> {\n /** Text to render inside the watermark; falls back to \"asterui\" */\n content?: string | string[]\n /** Image source (URL or base64) to render instead of text */\n image?: string\n /** Width of a single watermark tile in pixels */\n width?: number\n /** Height of a single watermark tile in pixels */\n height?: number\n /** Horizontal/vertical gap between watermarks in pixels */\n gap?: WatermarkGap\n /** Offset for the first watermark tile from the top-left corner */\n offset?: WatermarkOffset\n /** Rotation angle in degrees */\n rotate?: number\n /** z-index for the overlay layer */\n zIndex?: number\n /** Font settings for text watermarks */\n font?: WatermarkFontOptions\n /** Content to protect with the watermark */\n children?: React.ReactNode\n}\n\ntype WatermarkImage = {\n url: string\n width: number\n height: number\n}\n\nconst DEFAULT_CONTENT = 'asterui'\nconst DEFAULT_OPACITY = 0.22\n\nconst resolveThemeColor = (requested?: string, opacity = DEFAULT_OPACITY) => {\n const fallback = `rgba(0,0,0,${opacity})`\n\n if (requested && requested.includes('var(--bc')) {\n if (typeof window !== 'undefined') {\n const docBase = getComputedStyle(document.documentElement).getPropertyValue('--bc').trim()\n const bodyBase = getComputedStyle(document.body).getPropertyValue('--bc').trim()\n const base = docBase || bodyBase\n if (base) {\n return requested.replace(/var\\(--bc\\)/g, base)\n }\n }\n return fallback\n }\n\n if (requested) return requested\n\n if (typeof window === 'undefined') return fallback\n\n const docBase = getComputedStyle(document.documentElement).getPropertyValue('--bc').trim()\n const bodyBase = getComputedStyle(document.body).getPropertyValue('--bc').trim()\n const base = docBase || bodyBase\n\n return base ? `hsl(${base} / ${opacity})` : fallback\n}\n\nconst getFontSettings = (font: WatermarkFontOptions | undefined, resolvedColor: string) => {\n const fontSize = font?.fontSize ?? 16\n\n return {\n color: resolvedColor,\n fontSize,\n fontWeight: font?.fontWeight ?? 600,\n fontStyle: font?.fontStyle ?? 'normal',\n fontFamily: font?.fontFamily ?? 'sans-serif',\n lineHeight: font?.lineHeight ?? fontSize * 1.2,\n }\n}\n\nexport const Watermark: React.FC<WatermarkProps> = ({\n children,\n className = '',\n style,\n content,\n image,\n width = 120,\n height = 64,\n gap,\n offset,\n rotate = -22,\n zIndex = 1000,\n font,\n ...rest\n}) => {\n const [watermark, setWatermark] = useState<WatermarkImage | null>(null)\n\n const gapX = gap?.[0] ?? 120\n const gapY = gap?.[1] ?? 120\n const offsetX = offset?.[0] ?? gapX / 2\n const offsetY = offset?.[1] ?? gapY / 2\n const textLines = useMemo(\n () =>\n typeof content === 'string'\n ? [content]\n : Array.isArray(content)\n ? content\n : [DEFAULT_CONTENT],\n [content]\n )\n const resolvedColor = resolveThemeColor(font?.color)\n const fontSettings = useMemo(\n () => getFontSettings(font, resolvedColor),\n [font, resolvedColor]\n )\n const rotationInRadians = (Math.PI / 180) * rotate\n const textKey = textLines.join('|')\n\n useEffect(() => {\n if (typeof window === 'undefined') return\n\n let cancelled = false\n const ratio = window.devicePixelRatio || 1\n const tileWidth = width + gapX\n const tileHeight = height + gapY\n const canvas = document.createElement('canvas')\n canvas.width = tileWidth * ratio\n canvas.height = tileHeight * ratio\n const ctx = canvas.getContext('2d')\n\n if (!ctx) return\n\n const commitWatermark = () => {\n const url = canvas.toDataURL()\n if (!cancelled) {\n setWatermark({ url, width: tileWidth, height: tileHeight })\n }\n }\n\n const drawText = () => {\n ctx.save()\n ctx.translate((gapX / 2 + width / 2) * ratio, (gapY / 2 + height / 2) * ratio)\n ctx.rotate(rotationInRadians)\n ctx.fillStyle = fontSettings.color\n ctx.textAlign = 'center'\n ctx.textBaseline = 'middle'\n ctx.font = `${fontSettings.fontStyle} normal ${fontSettings.fontWeight} ${fontSettings.fontSize * ratio}px ${fontSettings.fontFamily}`\n\n const lineHeight = fontSettings.lineHeight * ratio\n const startY = -((textLines.length - 1) * lineHeight) / 2\n\n textLines.forEach((line, index) => {\n ctx.fillText(line, 0, startY + index * lineHeight)\n })\n\n ctx.restore()\n }\n\n if (image) {\n const img = new Image()\n img.crossOrigin = 'anonymous'\n img.referrerPolicy = 'no-referrer'\n\n const handleLoad = () => {\n ctx.save()\n ctx.translate((gapX / 2 + width / 2) * ratio, (gapY / 2 + height / 2) * ratio)\n ctx.rotate(rotationInRadians)\n ctx.drawImage(\n img,\n (-width / 2) * ratio,\n (-height / 2) * ratio,\n width * ratio,\n height * ratio\n )\n ctx.restore()\n commitWatermark()\n }\n\n const handleError = () => {\n if (!cancelled) setWatermark(null)\n }\n\n img.addEventListener('load', handleLoad)\n img.addEventListener('error', handleError)\n img.src = image\n\n return () => {\n cancelled = true\n img.removeEventListener('load', handleLoad)\n img.removeEventListener('error', handleError)\n }\n } else {\n drawText()\n commitWatermark()\n }\n\n return () => {\n cancelled = true\n }\n }, [\n fontSettings,\n gapX,\n gapY,\n height,\n image,\n rotationInRadians,\n textKey,\n width,\n ])\n\n const classes = ['relative', className].filter(Boolean).join(' ')\n\n return (\n <div\n className={classes}\n style={{ position: style?.position ?? 'relative', ...style }}\n {...rest}\n >\n {children}\n {watermark && (\n <div\n aria-hidden\n className=\"pointer-events-none absolute inset-0\"\n style={{\n zIndex,\n backgroundImage: `url(${watermark.url})`,\n backgroundRepeat: 'repeat',\n backgroundSize: `${watermark.width}px ${watermark.height}px`,\n backgroundPosition: `${offsetX}px ${offsetY}px`,\n }}\n />\n )}\n </div>\n )\n}\n\nWatermark.displayName = 'Watermark'\n"],"names":["DEFAULT_CONTENT","DEFAULT_OPACITY","resolveThemeColor","requested","opacity","fallback","docBase","bodyBase","base","getFontSettings","font","resolvedColor","fontSize","Watermark","children","className","style","content","image","width","height","gap","offset","rotate","zIndex","rest","watermark","setWatermark","useState","gapX","gapY","offsetX","offsetY","textLines","useMemo","fontSettings","rotationInRadians","textKey","useEffect","cancelled","ratio","tileWidth","tileHeight","canvas","ctx","commitWatermark","url","drawText","lineHeight","startY","line","index","img","handleLoad","handleError","classes","jsxs","jsx"],"mappings":";;AAkDA,MAAMA,IAAkB,WAClBC,IAAkB,MAElBC,IAAoB,CAACC,GAAoBC,IAAUH,MAAoB;AAC3E,QAAMI,IAAW,cAAcD,CAAO;AAEtC,MAAID,KAAaA,EAAU,SAAS,UAAU,GAAG;AAC/C,QAAI,OAAO,SAAW,KAAa;AACjC,YAAMG,IAAU,iBAAiB,SAAS,eAAe,EAAE,iBAAiB,MAAM,EAAE,KAAA,GAC9EC,IAAW,iBAAiB,SAAS,IAAI,EAAE,iBAAiB,MAAM,EAAE,KAAA,GACpEC,IAAOF,KAAWC;AACxB,UAAIC;AACF,eAAOL,EAAU,QAAQ,gBAAgBK,CAAI;AAA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ACC,gBAAA+B;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,eAAW;AAAA,YACX,WAAU;AAAA,YACV,OAAO;AAAA,cACL,QAAAjC;AAAA,cACA,iBAAiB,OAAOE,EAAU,GAAG;AAAA,cACrC,kBAAkB;AAAA,cAClB,gBAAgB,GAAGA,EAAU,KAAK,MAAMA,EAAU,MAAM;AAAA,cACxD,oBAAoB,GAAGK,CAAO,MAAMC,CAAO;AAAA,YAAA;AAAA,UAC7C;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA;AAIR;AAEAnB,EAAU,cAAc;"}
1
+ {"version":3,"file":"Watermark.js","sources":["../../src/components/Watermark.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useState } from 'react'\nimport { useTheme } from '../hooks/useTheme'\n\nexport type WatermarkGap = [number, number]\nexport type WatermarkOffset = [number, number]\n\nexport interface WatermarkFontOptions {\n /** Text color for watermark content */\n color?: string\n /** Font size in pixels */\n fontSize?: number\n /** Font weight for watermark text */\n fontWeight?: number | 'normal' | 'bold' | 'bolder' | 'lighter'\n /** Font style for watermark text */\n fontStyle?: 'normal' | 'italic' | 'oblique'\n /** Font family for watermark text */\n fontFamily?: string\n /** Line height in pixels for multi-line content */\n lineHeight?: number\n}\n\nexport interface WatermarkProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, 'content'> {\n /** Text to render inside the watermark; falls back to \"asterui\" */\n content?: string | string[]\n /** Image source (URL or base64) to render instead of text */\n image?: string\n /** Width of a single watermark tile in pixels */\n width?: number\n /** Height of a single watermark tile in pixels */\n height?: number\n /** Horizontal/vertical gap between watermarks in pixels */\n gap?: WatermarkGap\n /** Offset for the first watermark tile from the top-left corner */\n offset?: WatermarkOffset\n /** Rotation angle in degrees */\n rotate?: number\n /** z-index for the overlay layer */\n zIndex?: number\n /** Font settings for text watermarks */\n font?: WatermarkFontOptions\n /** Content to protect with the watermark */\n children?: React.ReactNode\n}\n\ntype WatermarkImage = {\n url: string\n width: number\n height: number\n}\n\nconst DEFAULT_CONTENT = 'asterui'\nconst DEFAULT_OPACITY = 0.22\n\n// Add opacity to a hex color (returns #rrggbbaa format)\nfunction hexWithOpacity(hex: string, opacity: number): string {\n const alpha = Math.round(opacity * 255).toString(16).padStart(2, '0')\n return hex + alpha\n}\n\nconst getFontSettings = (font: WatermarkFontOptions | undefined, resolvedColor: string) => {\n const fontSize = font?.fontSize ?? 16\n\n return {\n color: resolvedColor,\n fontSize,\n fontWeight: font?.fontWeight ?? 600,\n fontStyle: font?.fontStyle ?? 'normal',\n fontFamily: font?.fontFamily ?? 'sans-serif',\n lineHeight: font?.lineHeight ?? fontSize * 1.2,\n }\n}\n\nexport const Watermark: React.FC<WatermarkProps> = ({\n children,\n className = '',\n style,\n content,\n image,\n width = 120,\n height = 64,\n gap,\n offset,\n rotate = -22,\n zIndex = 1000,\n font,\n ...rest\n}) => {\n const [watermark, setWatermark] = useState<WatermarkImage | null>(null)\n\n const gapX = gap?.[0] ?? 120\n const gapY = gap?.[1] ?? 120\n const offsetX = offset?.[0] ?? gapX / 2\n const offsetY = offset?.[1] ?? gapY / 2\n const { colors } = useTheme()\n const textLines = useMemo(\n () =>\n typeof content === 'string'\n ? [content]\n : Array.isArray(content)\n ? content\n : [DEFAULT_CONTENT],\n [content]\n )\n // Use provided color or theme foreground with opacity\n const resolvedColor = font?.color ?? hexWithOpacity(colors.foreground, DEFAULT_OPACITY)\n const fontSettings = useMemo(\n () => getFontSettings(font, resolvedColor),\n [font, resolvedColor]\n )\n const rotationInRadians = (Math.PI / 180) * rotate\n const textKey = textLines.join('|')\n\n useEffect(() => {\n if (typeof window === 'undefined') return\n\n let cancelled = false\n const ratio = window.devicePixelRatio || 1\n const tileWidth = width + gapX\n const tileHeight = height + gapY\n const canvas = document.createElement('canvas')\n canvas.width = tileWidth * ratio\n canvas.height = tileHeight * ratio\n const ctx = canvas.getContext('2d')\n\n if (!ctx) return\n\n const commitWatermark = () => {\n const url = canvas.toDataURL()\n if (!cancelled) {\n setWatermark({ url, width: tileWidth, height: tileHeight })\n }\n }\n\n const drawText = () => {\n ctx.save()\n ctx.translate((gapX / 2 + width / 2) * ratio, (gapY / 2 + height / 2) * ratio)\n ctx.rotate(rotationInRadians)\n ctx.fillStyle = fontSettings.color\n ctx.textAlign = 'center'\n ctx.textBaseline = 'middle'\n ctx.font = `${fontSettings.fontStyle} normal ${fontSettings.fontWeight} ${fontSettings.fontSize * ratio}px ${fontSettings.fontFamily}`\n\n const lineHeight = fontSettings.lineHeight * ratio\n const startY = -((textLines.length - 1) * lineHeight) / 2\n\n textLines.forEach((line, index) => {\n ctx.fillText(line, 0, startY + index * lineHeight)\n })\n\n ctx.restore()\n }\n\n if (image) {\n const img = new Image()\n img.crossOrigin = 'anonymous'\n img.referrerPolicy = 'no-referrer'\n\n const handleLoad = () => {\n ctx.save()\n ctx.translate((gapX / 2 + width / 2) * ratio, (gapY / 2 + height / 2) * ratio)\n ctx.rotate(rotationInRadians)\n ctx.drawImage(\n img,\n (-width / 2) * ratio,\n (-height / 2) * ratio,\n width * ratio,\n height * ratio\n )\n ctx.restore()\n commitWatermark()\n }\n\n const handleError = () => {\n if (!cancelled) setWatermark(null)\n }\n\n img.addEventListener('load', handleLoad)\n img.addEventListener('error', handleError)\n img.src = image\n\n return () => {\n cancelled = true\n img.removeEventListener('load', handleLoad)\n img.removeEventListener('error', handleError)\n }\n } else {\n drawText()\n commitWatermark()\n }\n\n return () => {\n cancelled = true\n }\n }, [\n fontSettings,\n gapX,\n gapY,\n height,\n image,\n rotationInRadians,\n textKey,\n width,\n ])\n\n const classes = ['relative', className].filter(Boolean).join(' ')\n\n return (\n <div\n className={classes}\n style={{ position: style?.position ?? 'relative', ...style }}\n {...rest}\n >\n {children}\n {watermark && (\n <div\n aria-hidden\n className=\"pointer-events-none absolute inset-0\"\n style={{\n zIndex,\n backgroundImage: `url(${watermark.url})`,\n backgroundRepeat: 'repeat',\n backgroundSize: `${watermark.width}px ${watermark.height}px`,\n backgroundPosition: `${offsetX}px ${offsetY}px`,\n }}\n />\n )}\n </div>\n )\n}\n\nWatermark.displayName = 'Watermark'\n"],"names":["DEFAULT_CONTENT","DEFAULT_OPACITY","hexWithOpacity","hex","opacity","alpha","getFontSettings","font","resolvedColor","fontSize","Watermark","children","className","style","content","image","width","height","gap","offset","rotate","zIndex","rest","watermark","setWatermark","useState","gapX","gapY","offsetX","offsetY","colors","useTheme","textLines","useMemo","fontSettings","rotationInRadians","textKey","useEffect","cancelled","ratio","tileWidth","tileHeight","canvas","ctx","commitWatermark","url","drawText","lineHeight","startY","line","index","img","handleLoad","handleError","classes","jsxs","jsx"],"mappings":";;;AAmDA,MAAMA,IAAkB,WAClBC,IAAkB;AAGxB,SAASC,EAAeC,GAAaC,GAAyB;AAC5D,QAAMC,IAAQ,KAAK,MAAMD,IAAU,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AACpE,SAAOD,IAAME;AACf;AAEA,MAAMC,IAAkB,CAACC,GAAwCC,MAA0B;AACzF,QAAMC,IAAWF,GAAM,YAAY;AAEnC,SAAO;AAAA,IACL,OAAOC;AAAA,IACP,UAAAC;AAAA,IACA,YAAYF,GAAM,cAAc;AAAA,IAChC,WAAWA,GAAM,aAAa;AAAA,IAC9B,YAAYA,GAAM,cAAc;AAAA,IAChC,YAAYA,GAAM,cAAcE,IAAW;AAAA,EAAA;AAE/C,GAEaC,IAAsC,CAAC;AAAA,EAClD,UAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,QAAAC,IAAS;AAAA,EACT,KAAAC;AAAA,EACA,QAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,QAAAC,IAAS;AAAA,EACT,MAAAd;AAAA,EACA,GAAGe;AACL,MAAM;AACJ,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAgC,IAAI,GAEhEC,IAAOR,IAAM,CAA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F;AAAA,IACAoB;AAAA,IACAC;AAAA,IACApB;AAAA,EAAA,CACD;AAED,QAAMsC,IAAU,CAAC,YAAY1C,CAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAEhE,SACE,gBAAA2C;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWD;AAAA,MACX,OAAO,EAAE,UAAUzC,GAAO,YAAY,YAAY,GAAGA,EAAA;AAAA,MACpD,GAAGS;AAAA,MAEH,UAAA;AAAA,QAAAX;AAAA,QACAY,KACC,gBAAAiC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,eAAW;AAAA,YACX,WAAU;AAAA,YACV,OAAO;AAAA,cACL,QAAAnC;AAAA,cACA,iBAAiB,OAAOE,EAAU,GAAG;AAAA,cACrC,kBAAkB;AAAA,cAClB,gBAAgB,GAAGA,EAAU,KAAK,MAAMA,EAAU,MAAM;AAAA,cACxD,oBAAoB,GAAGK,CAAO,MAAMC,CAAO;AAAA,YAAA;AAAA,UAC7C;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA;AAIR;AAEAnB,EAAU,cAAc;"}
@@ -0,0 +1,22 @@
1
+ import { default as React } from 'react';
2
+ export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
3
+ export declare const SizeContext: React.Context<Size | undefined>;
4
+ export interface SizeProviderProps {
5
+ /** Size to provide to child components */
6
+ size: Size;
7
+ /** Child components */
8
+ children: React.ReactNode;
9
+ }
10
+ /**
11
+ * Provides size context to child components.
12
+ *
13
+ * Used by Button, CopyButton, and other sized components to transmit
14
+ * their size to child icons, allowing icons to automatically match
15
+ * the parent component's size.
16
+ */
17
+ export declare function SizeProvider({ size, children }: SizeProviderProps): import("react/jsx-runtime").JSX.Element;
18
+ /**
19
+ * Hook to access the current size context.
20
+ * Returns undefined if not within a SizeProvider.
21
+ */
22
+ export declare function useSize(): Size | undefined;
@@ -0,0 +1,15 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { createContext as i, useContext as n } from "react";
3
+ const e = i(void 0);
4
+ function c({ size: t, children: o }) {
5
+ return /* @__PURE__ */ r(e.Provider, { value: t, children: o });
6
+ }
7
+ function f() {
8
+ return n(e);
9
+ }
10
+ export {
11
+ e as SizeContext,
12
+ c as SizeProvider,
13
+ f as useSize
14
+ };
15
+ //# sourceMappingURL=SizeContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SizeContext.js","sources":["../../src/contexts/SizeContext.tsx"],"sourcesContent":["import React, { createContext, useContext } from 'react'\n\nexport type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n\nexport const SizeContext = createContext<Size | undefined>(undefined)\n\nexport interface SizeProviderProps {\n /** Size to provide to child components */\n size: Size\n /** Child components */\n children: React.ReactNode\n}\n\n/**\n * Provides size context to child components.\n *\n * Used by Button, CopyButton, and other sized components to transmit\n * their size to child icons, allowing icons to automatically match\n * the parent component's size.\n */\nexport function SizeProvider({ size, children }: SizeProviderProps) {\n return (\n <SizeContext.Provider value={size}>\n {children}\n </SizeContext.Provider>\n )\n}\n\n/**\n * Hook to access the current size context.\n * Returns undefined if not within a SizeProvider.\n */\nexport function useSize(): Size | undefined {\n return useContext(SizeContext)\n}\n"],"names":["SizeContext","createContext","SizeProvider","size","children","useSize","useContext"],"mappings":";;AAIO,MAAMA,IAAcC,EAAgC,MAAS;AAgB7D,SAASC,EAAa,EAAE,MAAAC,GAAM,UAAAC,KAA+B;AAClE,2BACGJ,EAAY,UAAZ,EAAqB,OAAOG,GAC1B,UAAAC,GACH;AAEJ;AAMO,SAASC,IAA4B;AAC1C,SAAOC,EAAWN,CAAW;AAC/B;"}
@@ -1,29 +1,39 @@
1
- export interface ThemeColors {
2
- /** Base background color (--b1 / base-100) */
3
- background: string;
4
- /** Base content/text color (--bc / base-content) */
5
- foreground: string;
6
- /** Primary color (--p / primary) */
7
- primary: string;
8
- /** Primary content color (--pc / primary-content) */
9
- primaryContent: string;
10
- }
1
+ import { ThemeColors } from '../components/ThemeProvider';
2
+ export type { ThemeColors };
11
3
  export interface UseThemeReturn {
4
+ /** The theme setting (what user selected). Only available with ThemeProvider. */
5
+ theme: string | undefined;
6
+ /** The actual applied theme. Only available with ThemeProvider. */
7
+ resolvedTheme: string | undefined;
12
8
  /** Whether dark mode is active */
13
9
  isDark: boolean;
10
+ /** Set the theme. Only available with ThemeProvider. */
11
+ setTheme: ((theme: string) => void) | undefined;
14
12
  /** Computed theme colors as hex values */
15
13
  colors: ThemeColors;
14
+ /** The system preference. Only available with ThemeProvider. */
15
+ systemTheme: 'light' | 'dark' | undefined;
16
16
  }
17
17
  /**
18
- * Hook to detect current theme and get computed colors
18
+ * Hook to detect current theme and get computed colors.
19
+ *
20
+ * When used within a ThemeProvider, returns full theme control including
21
+ * setTheme, theme selection, and resolved theme.
19
22
  *
20
- * Checks the `data-theme` attribute on the document root (for DaisyUI themes)
21
- * and falls back to system preference via `prefers-color-scheme`.
23
+ * When used standalone (without ThemeProvider), provides read-only access
24
+ * to isDark and colors based on the current data-theme attribute and
25
+ * system preference.
22
26
  *
23
- * Returns both the dark mode state and computed theme colors as hex values,
24
- * useful for canvas-based components that can't use CSS variables directly.
27
+ * @example
28
+ * // With ThemeProvider (full control)
29
+ * const { theme, setTheme, resolvedTheme, isDark, colors } = useTheme()
30
+ * setTheme('dark')
31
+ * setTheme('system')
25
32
  *
26
- * Automatically updates when theme changes.
33
+ * @example
34
+ * // Without ThemeProvider (read-only)
35
+ * const { isDark, colors } = useTheme()
36
+ * // colors.primary, colors.foreground, etc.
27
37
  */
28
38
  export declare function useTheme(): UseThemeReturn;
29
39
  export default useTheme;
@@ -1,56 +1,119 @@
1
- import { useState as m, useEffect as i } from "react";
2
- function c(t) {
3
- const r = document.createElement("canvas");
4
- r.width = r.height = 1;
5
- const e = r.getContext("2d");
6
- if (!e) return "#000000";
7
- e.fillStyle = t, e.fillRect(0, 0, 1, 1);
8
- const [o, n, a] = e.getImageData(0, 0, 1, 1).data;
9
- return `#${((1 << 24) + (o << 16) + (n << 8) + a).toString(16).slice(1)}`;
1
+ import { useState as i, useEffect as m, useMemo as u } from "react";
2
+ import { useHasThemeProvider as d, useThemeContext as l } from "../components/ThemeProvider.js";
3
+ const h = /* @__PURE__ */ new Set([
4
+ "dark",
5
+ "synthwave",
6
+ "halloween",
7
+ "forest",
8
+ "black",
9
+ "luxury",
10
+ "dracula",
11
+ "business",
12
+ "night",
13
+ "coffee",
14
+ "dim",
15
+ "sunset"
16
+ ]);
17
+ function g(r) {
18
+ if (typeof document > "u") return "#000000";
19
+ const e = document.createElement("canvas");
20
+ e.width = e.height = 1;
21
+ const t = e.getContext("2d");
22
+ if (!t) return "#000000";
23
+ t.fillStyle = r, t.fillRect(0, 0, 1, 1);
24
+ const [n, o, s] = t.getImageData(0, 0, 1, 1).data;
25
+ return `#${((1 << 24) + (n << 16) + (o << 8) + s).toString(16).slice(1)}`;
10
26
  }
11
- function u() {
12
- const t = getComputedStyle(document.documentElement), r = t.getPropertyValue("--b1").trim(), e = t.getPropertyValue("--bc").trim(), o = t.getPropertyValue("--p").trim(), n = t.getPropertyValue("--pc").trim();
27
+ function a() {
28
+ if (typeof document > "u")
29
+ return {
30
+ background: "#ffffff",
31
+ foreground: "#000000",
32
+ primary: "#6366f1",
33
+ primaryContent: "#ffffff",
34
+ secondary: "#f000b8",
35
+ accent: "#37cdbe",
36
+ info: "#3abff8",
37
+ success: "#36d399",
38
+ warning: "#fbbd23",
39
+ error: "#f87272"
40
+ };
41
+ const r = getComputedStyle(document.documentElement), e = (t, n) => {
42
+ const o = r.getPropertyValue(t).trim();
43
+ return o ? g(o) : n;
44
+ };
13
45
  return {
14
- background: r ? c(`oklch(${r})`) : "#ffffff",
15
- foreground: e ? c(`oklch(${e})`) : "#000000",
16
- primary: o ? c(`oklch(${o})`) : "#6366f1",
17
- primaryContent: n ? c(`oklch(${n})`) : "#ffffff"
46
+ background: e("--color-base-100", "#ffffff"),
47
+ foreground: e("--color-base-content", "#000000"),
48
+ primary: e("--color-primary", "#6366f1"),
49
+ primaryContent: e("--color-primary-content", "#ffffff"),
50
+ secondary: e("--color-secondary", "#f000b8"),
51
+ accent: e("--color-accent", "#37cdbe"),
52
+ info: e("--color-info", "#3abff8"),
53
+ success: e("--color-success", "#36d399"),
54
+ warning: e("--color-warning", "#fbbd23"),
55
+ error: e("--color-error", "#f87272")
18
56
  };
19
57
  }
20
- function d() {
21
- const [t, r] = m({
58
+ function y() {
59
+ return typeof window > "u" ? "light" : window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
60
+ }
61
+ function b() {
62
+ return typeof document > "u" ? null : document.documentElement.getAttribute("data-theme");
63
+ }
64
+ function k() {
65
+ if (d()) {
66
+ const e = l();
67
+ return {
68
+ theme: e.theme,
69
+ resolvedTheme: e.resolvedTheme,
70
+ isDark: e.isDark,
71
+ setTheme: e.setTheme,
72
+ colors: e.colors,
73
+ systemTheme: e.systemTheme
74
+ };
75
+ }
76
+ return T();
77
+ }
78
+ function T() {
79
+ const [r, e] = i(() => ({
22
80
  isDark: !1,
23
- colors: {
24
- background: "#ffffff",
25
- foreground: "#000000",
26
- primary: "#6366f1",
27
- primaryContent: "#ffffff"
28
- }
29
- });
30
- return i(() => {
31
- const e = () => {
32
- const s = document.documentElement.getAttribute("data-theme"), f = s === "dark" || !s && window.matchMedia("(prefers-color-scheme: dark)").matches;
33
- requestAnimationFrame(() => {
34
- r({
35
- isDark: f,
36
- colors: u()
81
+ colors: a()
82
+ }));
83
+ return m(() => {
84
+ const t = () => {
85
+ const s = b(), f = y();
86
+ let c = !1;
87
+ s ? c = h.has(s) : c = f === "dark", requestAnimationFrame(() => {
88
+ requestAnimationFrame(() => {
89
+ e({
90
+ isDark: c,
91
+ colors: a()
92
+ });
37
93
  });
38
94
  });
39
95
  };
40
- e();
41
- const o = new MutationObserver(e);
42
- o.observe(document.documentElement, {
96
+ t();
97
+ const n = new MutationObserver(t);
98
+ n.observe(document.documentElement, {
43
99
  attributes: !0,
44
100
  attributeFilter: ["data-theme", "class"]
45
101
  });
46
- const n = window.matchMedia("(prefers-color-scheme: dark)");
47
- return n.addEventListener("change", e), () => {
48
- o.disconnect(), n.removeEventListener("change", e);
102
+ const o = window.matchMedia("(prefers-color-scheme: dark)");
103
+ return o.addEventListener("change", t), () => {
104
+ n.disconnect(), o.removeEventListener("change", t);
49
105
  };
50
- }, []), t;
106
+ }, []), u(() => ({
107
+ theme: void 0,
108
+ resolvedTheme: void 0,
109
+ isDark: r.isDark,
110
+ setTheme: void 0,
111
+ colors: r.colors,
112
+ systemTheme: void 0
113
+ }), [r.isDark, r.colors]);
51
114
  }
52
115
  export {
53
- d as default,
54
- d as useTheme
116
+ k as default,
117
+ k as useTheme
55
118
  };
56
119
  //# sourceMappingURL=useTheme.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.js","sources":["../../src/hooks/useTheme.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nexport interface ThemeColors {\n /** Base background color (--b1 / base-100) */\n background: string\n /** Base content/text color (--bc / base-content) */\n foreground: string\n /** Primary color (--p / primary) */\n primary: string\n /** Primary content color (--pc / primary-content) */\n primaryContent: string\n}\n\nexport interface UseThemeReturn {\n /** Whether dark mode is active */\n isDark: boolean\n /** Computed theme colors as hex values */\n colors: ThemeColors\n}\n\n// Convert any CSS color to hex\nfunction colorToHex(color: string): string {\n const canvas = document.createElement('canvas')\n canvas.width = canvas.height = 1\n const ctx = canvas.getContext('2d')\n if (!ctx) return '#000000'\n ctx.fillStyle = color\n ctx.fillRect(0, 0, 1, 1)\n const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data\n return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`\n}\n\nfunction getThemeColors(): ThemeColors {\n const style = getComputedStyle(document.documentElement)\n\n // Get computed colors from CSS custom properties\n const background = style.getPropertyValue('--b1').trim()\n const foreground = style.getPropertyValue('--bc').trim()\n const primary = style.getPropertyValue('--p').trim()\n const primaryContent = style.getPropertyValue('--pc').trim()\n\n // DaisyUI uses oklch, convert to hex for canvas compatibility\n return {\n background: background ? colorToHex(`oklch(${background})`) : '#ffffff',\n foreground: foreground ? colorToHex(`oklch(${foreground})`) : '#000000',\n primary: primary ? colorToHex(`oklch(${primary})`) : '#6366f1',\n primaryContent: primaryContent ? colorToHex(`oklch(${primaryContent})`) : '#ffffff',\n }\n}\n\n/**\n * Hook to detect current theme and get computed colors\n *\n * Checks the `data-theme` attribute on the document root (for DaisyUI themes)\n * and falls back to system preference via `prefers-color-scheme`.\n *\n * Returns both the dark mode state and computed theme colors as hex values,\n * useful for canvas-based components that can't use CSS variables directly.\n *\n * Automatically updates when theme changes.\n */\nexport function useTheme(): UseThemeReturn {\n const [state, setState] = useState<UseThemeReturn>({\n isDark: false,\n colors: {\n background: '#ffffff',\n foreground: '#000000',\n primary: '#6366f1',\n primaryContent: '#ffffff',\n }\n })\n\n useEffect(() => {\n const checkTheme = () => {\n const html = document.documentElement\n const theme = html.getAttribute('data-theme')\n // Check for explicit dark theme or system preference\n const isDark = theme === 'dark' ||\n (!theme && window.matchMedia('(prefers-color-scheme: dark)').matches)\n\n // Small delay to ensure CSS variables are updated\n requestAnimationFrame(() => {\n setState({\n isDark,\n colors: getThemeColors()\n })\n })\n }\n\n checkTheme()\n\n // Watch for theme changes via attribute mutation\n const observer = new MutationObserver(checkTheme)\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['data-theme', 'class']\n })\n\n // Also watch for system preference changes\n const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')\n mediaQuery.addEventListener('change', checkTheme)\n\n return () => {\n observer.disconnect()\n mediaQuery.removeEventListener('change', checkTheme)\n }\n }, [])\n\n return state\n}\n\nexport default useTheme\n"],"names":["colorToHex","color","canvas","ctx","r","g","b","getThemeColors","style","background","foreground","primary","primaryContent","useTheme","state","setState","useState","useEffect","checkTheme","theme","isDark","observer","mediaQuery"],"mappings":";AAqBA,SAASA,EAAWC,GAAuB;AACzC,QAAMC,IAAS,SAAS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A,KAAS,OAAO,WAAW,8BAA8B,EAAE;AAG/D,4BAAsB,MAAM;AAC1B,QAAAJ,EAAS;AAAA,UACP,QAAAK;AAAA,UACA,QAAQb,EAAA;AAAA,QAAe,CACxB;AAAA,MACH,CAAC;AAAA,IACH;AAEA,IAAAW,EAAA;AAGA,UAAMG,IAAW,IAAI,iBAAiBH,CAAU;AAChD,IAAAG,EAAS,QAAQ,SAAS,iBAAiB;AAAA,MACzC,YAAY;AAAA,MACZ,iBAAiB,CAAC,cAAc,OAAO;AAAA,IAAA,CACxC;AAGD,UAAMC,IAAa,OAAO,WAAW,8BAA8B;AACnE,WAAAA,EAAW,iBAAiB,UAAUJ,CAAU,GAEzC,MAAM;AACX,MAAAG,EAAS,WAAA,GACTC,EAAW,oBAAoB,UAAUJ,CAAU;AAAA,IACrD;AAAA,EACF,GAAG,CAAA,CAAE,GAEEJ;AACT;"}
1
+ {"version":3,"file":"useTheme.js","sources":["../../src/hooks/useTheme.ts"],"sourcesContent":["import { useEffect, useState, useMemo } from 'react'\nimport { useHasThemeProvider, useThemeContext, type ThemeColors } from '../components/ThemeProvider'\n\nexport type { ThemeColors }\n\n// Common dark themes in DaisyUI\nconst DARK_THEMES = new Set([\n 'dark', 'synthwave', 'halloween', 'forest', 'black', 'luxury', 'dracula',\n 'business', 'night', 'coffee', 'dim', 'sunset'\n])\n\nexport interface UseThemeReturn {\n /** The theme setting (what user selected). Only available with ThemeProvider. */\n theme: string | undefined\n /** The actual applied theme. Only available with ThemeProvider. */\n resolvedTheme: string | undefined\n /** Whether dark mode is active */\n isDark: boolean\n /** Set the theme. Only available with ThemeProvider. */\n setTheme: ((theme: string) => void) | undefined\n /** Computed theme colors as hex values */\n colors: ThemeColors\n /** The system preference. Only available with ThemeProvider. */\n systemTheme: 'light' | 'dark' | undefined\n}\n\n// Convert any CSS color to hex\nfunction colorToHex(color: string): string {\n if (typeof document === 'undefined') return '#000000'\n const canvas = document.createElement('canvas')\n canvas.width = canvas.height = 1\n const ctx = canvas.getContext('2d')\n if (!ctx) return '#000000'\n ctx.fillStyle = color\n ctx.fillRect(0, 0, 1, 1)\n const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data\n return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`\n}\n\nfunction getThemeColors(): ThemeColors {\n if (typeof document === 'undefined') {\n return {\n background: '#ffffff',\n foreground: '#000000',\n primary: '#6366f1',\n primaryContent: '#ffffff',\n secondary: '#f000b8',\n accent: '#37cdbe',\n info: '#3abff8',\n success: '#36d399',\n warning: '#fbbd23',\n error: '#f87272',\n }\n }\n\n const style = getComputedStyle(document.documentElement)\n const getColor = (varName: string, fallback: string): string => {\n const value = style.getPropertyValue(varName).trim()\n return value ? colorToHex(value) : fallback\n }\n\n return {\n background: getColor('--color-base-100', '#ffffff'),\n foreground: getColor('--color-base-content', '#000000'),\n primary: getColor('--color-primary', '#6366f1'),\n primaryContent: getColor('--color-primary-content', '#ffffff'),\n secondary: getColor('--color-secondary', '#f000b8'),\n accent: getColor('--color-accent', '#37cdbe'),\n info: getColor('--color-info', '#3abff8'),\n success: getColor('--color-success', '#36d399'),\n warning: getColor('--color-warning', '#fbbd23'),\n error: getColor('--color-error', '#f87272'),\n }\n}\n\nfunction getSystemTheme(): 'light' | 'dark' {\n if (typeof window === 'undefined') return 'light'\n return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'\n}\n\nfunction getCurrentTheme(): string | null {\n if (typeof document === 'undefined') return null\n return document.documentElement.getAttribute('data-theme')\n}\n\n/**\n * Hook to detect current theme and get computed colors.\n *\n * When used within a ThemeProvider, returns full theme control including\n * setTheme, theme selection, and resolved theme.\n *\n * When used standalone (without ThemeProvider), provides read-only access\n * to isDark and colors based on the current data-theme attribute and\n * system preference.\n *\n * @example\n * // With ThemeProvider (full control)\n * const { theme, setTheme, resolvedTheme, isDark, colors } = useTheme()\n * setTheme('dark')\n * setTheme('system')\n *\n * @example\n * // Without ThemeProvider (read-only)\n * const { isDark, colors } = useTheme()\n * // colors.primary, colors.foreground, etc.\n */\nexport function useTheme(): UseThemeReturn {\n const hasProvider = useHasThemeProvider()\n\n // If we have a provider, use its context\n if (hasProvider) {\n // This is safe because hasProvider is stable after initial render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const context = useThemeContext()\n return {\n theme: context.theme,\n resolvedTheme: context.resolvedTheme,\n isDark: context.isDark,\n setTheme: context.setTheme,\n colors: context.colors,\n systemTheme: context.systemTheme,\n }\n }\n\n // Standalone mode - no provider\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useThemeStandalone()\n}\n\n/**\n * Standalone theme detection (no ThemeProvider)\n */\nfunction useThemeStandalone(): UseThemeReturn {\n const [state, setState] = useState<{ isDark: boolean; colors: ThemeColors }>(() => ({\n isDark: false,\n colors: getThemeColors(),\n }))\n\n useEffect(() => {\n const updateTheme = () => {\n const currentTheme = getCurrentTheme()\n const systemTheme = getSystemTheme()\n\n // Determine if dark based on data-theme or system preference\n let isDark = false\n if (currentTheme) {\n isDark = DARK_THEMES.has(currentTheme)\n } else {\n isDark = systemTheme === 'dark'\n }\n\n // Double RAF ensures CSS has fully recalculated\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n setState({\n isDark,\n colors: getThemeColors(),\n })\n })\n })\n }\n\n updateTheme()\n\n // Watch for theme changes via attribute mutation\n const observer = new MutationObserver(updateTheme)\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['data-theme', 'class']\n })\n\n // Watch for system preference changes\n const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')\n mediaQuery.addEventListener('change', updateTheme)\n\n return () => {\n observer.disconnect()\n mediaQuery.removeEventListener('change', updateTheme)\n }\n }, [])\n\n return useMemo(() => ({\n theme: undefined,\n resolvedTheme: undefined,\n isDark: state.isDark,\n setTheme: undefined,\n colors: state.colors,\n systemTheme: undefined,\n }), [state.isDark, state.colors])\n}\n\nexport default useTheme\n"],"names":["DARK_THEMES","colorToHex","color","canvas","ctx","r","g","b","getThemeColors","style","getColor","varName","fallback","value","getSystemTheme","getCurrentTheme","useTheme","useHasThemeProvider","context","useThemeContext","useThemeStandalone","state","setState","useState","useEffect","updateTheme","currentTheme","systemTheme","isDark","observer","mediaQuery","useMemo"],"mappings":";;AAMA,MAAMA,wBAAkB,IAAI;AAAA,EAC1B;AAAA,EAAQ;AAAA,EAAa;AAAA,EAAa;AAAA,EAAU;AAAA,EAAS;AAAA,EAAU;AAAA,EAC/D;AAAA,EAAY;AAAA,EAAS;AAAA,EAAU;AAAA,EAAO;AACxC,CAAC;AAkBD,SAASC,EAAWC,GAAuB;AACzC,MAAI,OAAO,WAAa,IAAa,QAAO;AAC5C,QAAMC,IAAS,SAAS,cAAc,QAAQ;AAC9C,EAAAA,EAAO,QAAQA,EAAO,SAAS;AAC/B,QAAMC,IAAMD,EAAO,WAAW,IAAI;AAClC,MAAI,CAACC,EAAK,QAAO;AACjB,EAAAA,EAAI,YAAYF,GAChBE,EAAI,SAAS,GAAG,GAAG,GAAG,CAAC;AACvB,QAAM,CAACC,GAAGC,GAAGC,CAAC,IAAIH,EAAI,aAAa,GAAG,GAAG,GAAG,CAAC,EAAE;AAC/C,SAAO,MAAM,KAAK,OAAOC,KAAK,OAAOC,KAAK,KAAKC,GAAG,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AACzE;AAEA,SAASC,IAA8B;AACrC,MAAI,OAAO,WAAa;AACtB,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,gBAAgB;AAAA,MAChB,WAAW;AAAA,MACX,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IAAA;AAIX,QAAMC,IAAQ,iBAAiB,SAAS,eAAe,GACjDC,IAAW,CAACC,GAAiBC,MAA6B;AAC9D,UAAMC,IAAQJ,EAAM,iBAAiBE,CAAO,EAAE,KAAA;AAC9C,WAAOE,IAAQZ,EAA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