asterui 0.12.36 → 0.12.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Chart.js +71 -63
- package/dist/components/Chart.js.map +1 -1
- package/dist/components/MissingDependency.d.ts +7 -0
- package/dist/components/MissingDependency.js +25 -0
- package/dist/components/MissingDependency.js.map +1 -0
- package/dist/components/QRCode.js +42 -44
- package/dist/components/QRCode.js.map +1 -1
- package/dist/components/VirtualList.js +82 -41
- package/dist/components/VirtualList.js.map +1 -1
- package/package.json +1 -1
package/dist/components/Chart.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import O from "
|
|
4
|
-
function
|
|
5
|
-
return typeof document > "u" ? "" : getComputedStyle(document.documentElement).getPropertyValue(
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as v, useState as w, useEffect as g } from "react";
|
|
3
|
+
import { MissingDependency as O } from "./MissingDependency.js";
|
|
4
|
+
function C(n) {
|
|
5
|
+
return typeof document > "u" ? "" : getComputedStyle(document.documentElement).getPropertyValue(n).trim();
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
10
|
-
const t = parseFloat(
|
|
11
|
-
let
|
|
12
|
-
const
|
|
13
|
-
return
|
|
7
|
+
function S(n) {
|
|
8
|
+
const r = n.match(/oklch\(\s*([\d.]+)%?\s+([\d.]+)\s+([\d.]+)/);
|
|
9
|
+
if (!r) return "";
|
|
10
|
+
const t = parseFloat(r[1]) / 100, e = parseFloat(r[2]), c = parseFloat(r[3]) * Math.PI / 180, a = e * Math.cos(c), i = e * Math.sin(c), s = t + 0.3963377774 * a + 0.2158037573 * i, u = t - 0.1055613458 * a - 0.0638541728 * i, h = t - 0.0894841775 * a - 1.291485548 * i, m = s * s * s, p = u * u * u, d = h * h * h;
|
|
11
|
+
let o = 4.0767416621 * m - 3.3077115913 * p + 0.2309699292 * d, f = -1.2684380046 * m + 2.6097574011 * p - 0.3413193965 * d, M = -0.0041960863 * m - 0.7034186147 * p + 1.707614701 * d;
|
|
12
|
+
const x = (b) => (b = Math.max(0, Math.min(1, b)), b <= 31308e-7 ? 12.92 * b : 1.055 * Math.pow(b, 1 / 2.4) - 0.055);
|
|
13
|
+
return o = Math.round(x(o) * 255), f = Math.round(x(f) * 255), M = Math.round(x(M) * 255), `#${o.toString(16).padStart(2, "0")}${f.toString(16).padStart(2, "0")}${M.toString(16).padStart(2, "0")}`;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function A() {
|
|
16
16
|
return typeof document > "u" ? [] : [
|
|
17
17
|
"--color-primary",
|
|
18
18
|
"--color-secondary",
|
|
@@ -21,24 +21,24 @@ function V() {
|
|
|
21
21
|
"--color-success",
|
|
22
22
|
"--color-warning",
|
|
23
23
|
"--color-error"
|
|
24
|
-
].map((
|
|
25
|
-
const t =
|
|
26
|
-
return t.includes("oklch") ?
|
|
24
|
+
].map((r) => {
|
|
25
|
+
const t = C(r);
|
|
26
|
+
return t.includes("oklch") ? S(t) : t;
|
|
27
27
|
}).filter(Boolean);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
const
|
|
29
|
+
function V() {
|
|
30
|
+
const n = A(), r = C("--color-base-content"), t = r.includes("oklch") ? S(r) : r || "#888888", e = C("--color-base-300"), l = e.includes("oklch") ? S(e) : e || "#e0e0e0", c = t.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i), a = c ? (parseInt(c[1], 16) + parseInt(c[2], 16) + parseInt(c[3], 16)) / 3 > 128 : !1;
|
|
31
31
|
return {
|
|
32
|
-
colors:
|
|
32
|
+
colors: n.length > 0 ? n : void 0,
|
|
33
33
|
theme: {
|
|
34
|
-
mode:
|
|
34
|
+
mode: a ? "dark" : "light"
|
|
35
35
|
},
|
|
36
36
|
chart: {
|
|
37
37
|
background: "transparent",
|
|
38
38
|
foreColor: t
|
|
39
39
|
},
|
|
40
40
|
grid: {
|
|
41
|
-
borderColor:
|
|
41
|
+
borderColor: l
|
|
42
42
|
},
|
|
43
43
|
xaxis: {
|
|
44
44
|
labels: {
|
|
@@ -47,10 +47,10 @@ function A() {
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
axisBorder: {
|
|
50
|
-
color:
|
|
50
|
+
color: l
|
|
51
51
|
},
|
|
52
52
|
axisTicks: {
|
|
53
|
-
color:
|
|
53
|
+
color: l
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
yaxis: {
|
|
@@ -66,7 +66,7 @@ function A() {
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
tooltip: {
|
|
69
|
-
theme:
|
|
69
|
+
theme: a ? "dark" : "light",
|
|
70
70
|
style: {
|
|
71
71
|
fontSize: "12px"
|
|
72
72
|
},
|
|
@@ -90,64 +90,72 @@ function A() {
|
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
const t = { ...
|
|
95
|
-
for (const
|
|
96
|
-
e
|
|
97
|
-
|
|
98
|
-
e
|
|
99
|
-
) : t[
|
|
93
|
+
function k(n, r) {
|
|
94
|
+
const t = { ...n };
|
|
95
|
+
for (const e in r)
|
|
96
|
+
r[e] !== void 0 && (typeof r[e] == "object" && r[e] !== null && !Array.isArray(r[e]) && typeof n[e] == "object" && n[e] !== null && !Array.isArray(n[e]) ? t[e] = k(
|
|
97
|
+
n[e],
|
|
98
|
+
r[e]
|
|
99
|
+
) : t[e] = r[e]);
|
|
100
100
|
return t;
|
|
101
101
|
}
|
|
102
|
-
const
|
|
103
|
-
type:
|
|
104
|
-
series:
|
|
102
|
+
const F = ({
|
|
103
|
+
type: n,
|
|
104
|
+
series: r,
|
|
105
105
|
width: t = "100%",
|
|
106
|
-
height:
|
|
107
|
-
options:
|
|
106
|
+
height: e = 350,
|
|
107
|
+
options: l = {},
|
|
108
108
|
themed: c = !0,
|
|
109
|
-
className:
|
|
109
|
+
className: a = ""
|
|
110
110
|
}) => {
|
|
111
|
-
const
|
|
112
|
-
|
|
111
|
+
const i = v(null), s = v(null), [u, h] = w(null), [m, p] = w(!1);
|
|
112
|
+
g(() => {
|
|
113
|
+
import("apexcharts").then((o) => {
|
|
114
|
+
o.default ? h(() => o.default) : p(!0);
|
|
115
|
+
}).catch(() => {
|
|
116
|
+
p(!0);
|
|
117
|
+
});
|
|
118
|
+
}, []);
|
|
119
|
+
const d = () => {
|
|
120
|
+
const o = {
|
|
113
121
|
chart: {
|
|
114
|
-
type:
|
|
122
|
+
type: n,
|
|
115
123
|
width: t,
|
|
116
|
-
height:
|
|
124
|
+
height: e
|
|
117
125
|
},
|
|
118
|
-
series:
|
|
126
|
+
series: r
|
|
119
127
|
};
|
|
120
128
|
if (c) {
|
|
121
|
-
const
|
|
122
|
-
return
|
|
129
|
+
const f = V();
|
|
130
|
+
return k(k(o, f), l);
|
|
123
131
|
}
|
|
124
|
-
return
|
|
132
|
+
return k(o, l);
|
|
125
133
|
};
|
|
126
|
-
return
|
|
127
|
-
if (!
|
|
128
|
-
const
|
|
129
|
-
return
|
|
130
|
-
|
|
134
|
+
return g(() => {
|
|
135
|
+
if (!i.current || !u) return;
|
|
136
|
+
const o = d();
|
|
137
|
+
return s.current = new u(i.current, o), s.current.render(), () => {
|
|
138
|
+
s.current && (s.current.destroy(), s.current = null);
|
|
131
139
|
};
|
|
132
|
-
}, []),
|
|
133
|
-
if (!
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
}, [
|
|
140
|
+
}, [u]), g(() => {
|
|
141
|
+
if (!s.current) return;
|
|
142
|
+
const o = d();
|
|
143
|
+
s.current.updateOptions(o, !0, !0);
|
|
144
|
+
}, [n, r, t, e, l, c]), g(() => {
|
|
137
145
|
if (!c || typeof window > "u") return;
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
140
|
-
const
|
|
141
|
-
|
|
146
|
+
const o = new MutationObserver(() => {
|
|
147
|
+
if (s.current) {
|
|
148
|
+
const f = d();
|
|
149
|
+
s.current.updateOptions(f, !0, !0);
|
|
142
150
|
}
|
|
143
151
|
});
|
|
144
|
-
return
|
|
152
|
+
return o.observe(document.documentElement, {
|
|
145
153
|
attributes: !0,
|
|
146
154
|
attributeFilter: ["data-theme", "class"]
|
|
147
|
-
}), () =>
|
|
148
|
-
}, [c]), /* @__PURE__ */
|
|
155
|
+
}), () => o.disconnect();
|
|
156
|
+
}, [c]), m ? /* @__PURE__ */ y(O, { packageName: "apexcharts", className: a }) : u ? /* @__PURE__ */ y("div", { ref: i, className: a }) : /* @__PURE__ */ y("div", { className: a, style: { width: t, height: e }, children: /* @__PURE__ */ y("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ y("span", { className: "loading loading-spinner" }) }) });
|
|
149
157
|
};
|
|
150
158
|
export {
|
|
151
|
-
|
|
159
|
+
F as Chart
|
|
152
160
|
};
|
|
153
161
|
//# sourceMappingURL=Chart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chart.js","sources":["../../src/components/Chart.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\nimport ApexCharts from 'apexcharts'\nimport type { ApexOptions } from 'apexcharts'\n\nexport interface ChartProps {\n /** Chart type */\n type: 'line' | 'area' | 'bar' | 'pie' | 'donut' | 'radialBar' | 'scatter' | 'bubble' | 'heatmap' | 'candlestick' | 'boxPlot' | 'radar' | 'polarArea' | 'rangeBar' | 'rangeArea' | 'treemap'\n /** Chart series data */\n series: ApexAxisChartSeries | ApexNonAxisChartSeries\n /** Chart width */\n width?: string | number\n /** Chart height */\n height?: string | number\n /** ApexCharts options (merged with theme defaults) */\n options?: ApexOptions\n /** Use daisyUI theme colors */\n themed?: boolean\n /** Additional CSS classes */\n className?: string\n}\n\n// Get CSS variable value from root\nfunction getCssVar(varName: string): string {\n if (typeof document === 'undefined') return ''\n return getComputedStyle(document.documentElement).getPropertyValue(varName).trim()\n}\n\n// Convert oklch to hex (approximate)\nfunction oklchToHex(oklch: string): string {\n // Parse oklch(L C H) format\n const match = oklch.match(/oklch\\(\\s*([\\d.]+)%?\\s+([\\d.]+)\\s+([\\d.]+)/)\n if (!match) return ''\n\n const l = parseFloat(match[1]) / 100 // Lightness 0-1\n const c = parseFloat(match[2]) // Chroma\n const h = parseFloat(match[3]) // Hue in degrees\n\n // Simplified oklch to sRGB conversion\n // This is an approximation - full conversion is complex\n const hRad = (h * Math.PI) / 180\n const a = c * Math.cos(hRad)\n const b = c * Math.sin(hRad)\n\n // Approximate conversion to linear RGB\n const l_ = l + 0.3963377774 * a + 0.2158037573 * b\n const m_ = l - 0.1055613458 * a - 0.0638541728 * b\n const s_ = l - 0.0894841775 * a - 1.2914855480 * b\n\n const l3 = l_ * l_ * l_\n const m3 = m_ * m_ * m_\n const s3 = s_ * s_ * s_\n\n let r = 4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3\n let g = -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3\n let bl = -0.0041960863 * l3 - 0.7034186147 * m3 + 1.7076147010 * s3\n\n // Clamp and convert to sRGB\n const toSrgb = (x: number) => {\n x = Math.max(0, Math.min(1, x))\n return x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1/2.4) - 0.055\n }\n\n r = Math.round(toSrgb(r) * 255)\n g = Math.round(toSrgb(g) * 255)\n bl = Math.round(toSrgb(bl) * 255)\n\n return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${bl.toString(16).padStart(2, '0')}`\n}\n\n// Get daisyUI theme colors from CSS variables\nfunction getThemeColors(): string[] {\n if (typeof document === 'undefined') return []\n\n const colorVars = [\n '--color-primary',\n '--color-secondary',\n '--color-accent',\n '--color-info',\n '--color-success',\n '--color-warning',\n '--color-error',\n ]\n\n return colorVars\n .map(varName => {\n const value = getCssVar(varName)\n if (value.includes('oklch')) {\n return oklchToHex(value)\n }\n return value\n })\n .filter(Boolean)\n}\n\n// Get theme-aware chart options\nfunction getThemedOptions(): Partial<ApexOptions> {\n const colors = getThemeColors()\n\n // Get text color from CSS variable\n const baseContentVar = getCssVar('--color-base-content')\n const textColor = baseContentVar.includes('oklch')\n ? oklchToHex(baseContentVar)\n : (baseContentVar || '#888888')\n\n // Get grid color from CSS variable\n const base300Var = getCssVar('--color-base-300')\n const gridColor = base300Var.includes('oklch')\n ? oklchToHex(base300Var)\n : (base300Var || '#e0e0e0')\n\n // Determine if dark theme by checking luminance of text color\n // If text is light, we're on dark theme\n const textMatch = textColor.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i)\n const isDark = textMatch\n ? (parseInt(textMatch[1], 16) + parseInt(textMatch[2], 16) + parseInt(textMatch[3], 16)) / 3 > 128\n : false\n\n return {\n colors: colors.length > 0 ? colors : undefined,\n theme: {\n mode: isDark ? 'dark' : 'light',\n },\n chart: {\n background: 'transparent',\n foreColor: textColor,\n },\n grid: {\n borderColor: gridColor,\n },\n xaxis: {\n labels: {\n style: {\n colors: textColor,\n },\n },\n axisBorder: {\n color: gridColor,\n },\n axisTicks: {\n color: gridColor,\n },\n },\n yaxis: {\n labels: {\n style: {\n colors: textColor,\n },\n },\n },\n legend: {\n labels: {\n colors: textColor,\n },\n },\n tooltip: {\n theme: isDark ? 'dark' : 'light',\n style: {\n fontSize: '12px',\n },\n x: {\n show: true,\n },\n marker: {\n show: true,\n },\n },\n dataLabels: {\n style: {\n colors: [textColor, textColor, textColor, textColor, textColor, textColor, textColor],\n },\n background: {\n enabled: false,\n },\n dropShadow: {\n enabled: false,\n },\n },\n }\n}\n\n// Deep merge objects\nfunction deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T {\n const result = { ...target }\n\n for (const key in source) {\n if (source[key] !== undefined) {\n if (\n typeof source[key] === 'object' &&\n source[key] !== null &&\n !Array.isArray(source[key]) &&\n typeof target[key] === 'object' &&\n target[key] !== null &&\n !Array.isArray(target[key])\n ) {\n result[key] = deepMerge(\n target[key] as Record<string, unknown>,\n source[key] as Record<string, unknown>\n ) as T[Extract<keyof T, string>]\n } else {\n result[key] = source[key] as T[Extract<keyof T, string>]\n }\n }\n }\n\n return result\n}\n\nexport const Chart: React.FC<ChartProps> = ({\n type,\n series,\n width = '100%',\n height = 350,\n options = {},\n themed = true,\n className = '',\n}) => {\n const chartRef = useRef<HTMLDivElement>(null)\n const chartInstance = useRef<ApexCharts | null>(null)\n const [, setMounted] = useState(false)\n\n // Build final options\n const buildOptions = (): ApexOptions => {\n const baseOptions: ApexOptions = {\n chart: {\n type,\n width,\n height,\n },\n series,\n }\n\n if (themed) {\n const themedOpts = getThemedOptions()\n return deepMerge(deepMerge(baseOptions as unknown as Record<string, unknown>, themedOpts as unknown as Record<string, unknown>), options as unknown as Record<string, unknown>) as ApexOptions\n }\n\n return deepMerge(baseOptions as unknown as Record<string, unknown>, options as unknown as Record<string, unknown>) as ApexOptions\n }\n\n // Initialize chart\n useEffect(() => {\n if (!chartRef.current) return\n\n const opts = buildOptions()\n chartInstance.current = new ApexCharts(chartRef.current, opts)\n chartInstance.current.render()\n setMounted(true)\n\n return () => {\n if (chartInstance.current) {\n chartInstance.current.destroy()\n chartInstance.current = null\n }\n }\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Update chart when props change\n useEffect(() => {\n if (!chartInstance.current) return\n\n const opts = buildOptions()\n chartInstance.current.updateOptions(opts, true, true)\n }, [type, series, width, height, options, themed]) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Listen for theme changes\n useEffect(() => {\n if (!themed || typeof window === 'undefined') return\n\n const observer = new MutationObserver(() => {\n if (chartInstance.current) {\n const opts = buildOptions()\n chartInstance.current.updateOptions(opts, true, true)\n }\n })\n\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['data-theme', 'class'],\n })\n\n return () => observer.disconnect()\n }, [themed]) // eslint-disable-line react-hooks/exhaustive-deps\n\n return <div ref={chartRef} className={className} />\n}\n"],"names":["getCssVar","varName","oklchToHex","oklch","match","l","c","hRad","a","b","l_","m_","s_","l3","m3","s3","r","g","bl","toSrgb","x","getThemeColors","value","getThemedOptions","colors","baseContentVar","textColor","base300Var","gridColor","textMatch","isDark","deepMerge","target","source","result","key","Chart","type","series","width","height","options","themed","className","chartRef","useRef","chartInstance","setMounted","useState","buildOptions","baseOptions","themedOpts","useEffect","opts","ApexCharts","observer","jsx"],"mappings":";;;AAsBA,SAASA,EAAUC,GAAyB;AAC1C,SAAI,OAAO,WAAa,MAAoB,KACrC,iBAAiB,SAAS,eAAe,EAAE,iBAAiBA,CAAO,EAAE,KAAA;AAC9E;AAGA,SAASC,EAAWC,GAAuB;AAEzC,QAAMC,IAAQD,EAAM,MAAM,4CAA4C;AACtE,MAAI,CAACC,EAAO,QAAO;AAEnB,QAAMC,IAAI,WAAWD,EAAM,CAAC,CAAC,IAAI,KAC3BE,IAAI,WAAWF,EAAM,CAAC,CAAC,GAKvBG,IAJI,WAAWH,EAAM,CAAC,CAAC,IAIX,KAAK,KAAM,KACvBI,IAAIF,IAAI,KAAK,IAAIC,CAAI,GACrBE,IAAIH,IAAI,KAAK,IAAIC,CAAI,GAGrBG,IAAKL,IAAI,eAAeG,IAAI,eAAeC,GAC3CE,IAAKN,IAAI,eAAeG,IAAI,eAAeC,GAC3CG,IAAKP,IAAI,eAAeG,IAAI,cAAeC,GAE3CI,IAAKH,IAAKA,IAAKA,GACfI,IAAKH,IAAKA,IAAKA,GACfI,IAAKH,IAAKA,IAAKA;AAErB,MAAII,IAAI,eAAeH,IAAK,eAAeC,IAAK,eAAeC,GAC3DE,IAAI,gBAAgBJ,IAAK,eAAeC,IAAK,eAAeC,GAC5DG,IAAK,gBAAgBL,IAAK,eAAeC,IAAK,cAAeC;AAGjE,QAAMI,IAAS,CAACC,OACdA,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,GAAGA,CAAC,CAAC,GACvBA,KAAK,WAAY,QAAQA,IAAI,QAAQ,KAAK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c,QAAQ,cAAcO,GAAM,IAAM,EAAI;AAAA,EACtD,GAAG,CAAChB,GAAMC,GAAQC,GAAOC,GAAQC,GAASC,CAAM,CAAC,GAGjDU,EAAU,MAAM;AACd,QAAI,CAACV,KAAU,OAAO,SAAW,IAAa;AAE9C,UAAMa,IAAW,IAAI,iBAAiB,MAAM;AAC1C,UAAIT,EAAc,SAAS;AACzB,cAAMO,IAAOJ,EAAA;AACb,QAAAH,EAAc,QAAQ,cAAcO,GAAM,IAAM,EAAI;AAAA,MACtD;AAAA,IACF,CAAC;AAED,WAAAE,EAAS,QAAQ,SAAS,iBAAiB;AAAA,MACzC,YAAY;AAAA,MACZ,iBAAiB,CAAC,cAAc,OAAO;AAAA,IAAA,CACxC,GAEM,MAAMA,EAAS,WAAA;AAAA,EACxB,GAAG,CAACb,CAAM,CAAC,GAEJ,gBAAAc,EAAC,OAAA,EAAI,KAAKZ,GAAU,WAAAD,EAAA,CAAsB;AACnD;"}
|
|
1
|
+
{"version":3,"file":"Chart.js","sources":["../../src/components/Chart.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\nimport type { ApexOptions } from 'apexcharts'\nimport { MissingDependency } from './MissingDependency'\n\nexport interface ChartProps {\n /** Chart type */\n type: 'line' | 'area' | 'bar' | 'pie' | 'donut' | 'radialBar' | 'scatter' | 'bubble' | 'heatmap' | 'candlestick' | 'boxPlot' | 'radar' | 'polarArea' | 'rangeBar' | 'rangeArea' | 'treemap'\n /** Chart series data */\n series: ApexAxisChartSeries | ApexNonAxisChartSeries\n /** Chart width */\n width?: string | number\n /** Chart height */\n height?: string | number\n /** ApexCharts options (merged with theme defaults) */\n options?: ApexOptions\n /** Use daisyUI theme colors */\n themed?: boolean\n /** Additional CSS classes */\n className?: string\n}\n\n// Get CSS variable value from root\nfunction getCssVar(varName: string): string {\n if (typeof document === 'undefined') return ''\n return getComputedStyle(document.documentElement).getPropertyValue(varName).trim()\n}\n\n// Convert oklch to hex (approximate)\nfunction oklchToHex(oklch: string): string {\n // Parse oklch(L C H) format\n const match = oklch.match(/oklch\\(\\s*([\\d.]+)%?\\s+([\\d.]+)\\s+([\\d.]+)/)\n if (!match) return ''\n\n const l = parseFloat(match[1]) / 100 // Lightness 0-1\n const c = parseFloat(match[2]) // Chroma\n const h = parseFloat(match[3]) // Hue in degrees\n\n // Simplified oklch to sRGB conversion\n // This is an approximation - full conversion is complex\n const hRad = (h * Math.PI) / 180\n const a = c * Math.cos(hRad)\n const b = c * Math.sin(hRad)\n\n // Approximate conversion to linear RGB\n const l_ = l + 0.3963377774 * a + 0.2158037573 * b\n const m_ = l - 0.1055613458 * a - 0.0638541728 * b\n const s_ = l - 0.0894841775 * a - 1.2914855480 * b\n\n const l3 = l_ * l_ * l_\n const m3 = m_ * m_ * m_\n const s3 = s_ * s_ * s_\n\n let r = 4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3\n let g = -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3\n let bl = -0.0041960863 * l3 - 0.7034186147 * m3 + 1.7076147010 * s3\n\n // Clamp and convert to sRGB\n const toSrgb = (x: number) => {\n x = Math.max(0, Math.min(1, x))\n return x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1/2.4) - 0.055\n }\n\n r = Math.round(toSrgb(r) * 255)\n g = Math.round(toSrgb(g) * 255)\n bl = Math.round(toSrgb(bl) * 255)\n\n return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${bl.toString(16).padStart(2, '0')}`\n}\n\n// Get daisyUI theme colors from CSS variables\nfunction getThemeColors(): string[] {\n if (typeof document === 'undefined') return []\n\n const colorVars = [\n '--color-primary',\n '--color-secondary',\n '--color-accent',\n '--color-info',\n '--color-success',\n '--color-warning',\n '--color-error',\n ]\n\n return colorVars\n .map(varName => {\n const value = getCssVar(varName)\n if (value.includes('oklch')) {\n return oklchToHex(value)\n }\n return value\n })\n .filter(Boolean)\n}\n\n// Get theme-aware chart options\nfunction getThemedOptions(): Partial<ApexOptions> {\n const colors = getThemeColors()\n\n // Get text color from CSS variable\n const baseContentVar = getCssVar('--color-base-content')\n const textColor = baseContentVar.includes('oklch')\n ? oklchToHex(baseContentVar)\n : (baseContentVar || '#888888')\n\n // Get grid color from CSS variable\n const base300Var = getCssVar('--color-base-300')\n const gridColor = base300Var.includes('oklch')\n ? oklchToHex(base300Var)\n : (base300Var || '#e0e0e0')\n\n // Determine if dark theme by checking luminance of text color\n // If text is light, we're on dark theme\n const textMatch = textColor.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i)\n const isDark = textMatch\n ? (parseInt(textMatch[1], 16) + parseInt(textMatch[2], 16) + parseInt(textMatch[3], 16)) / 3 > 128\n : false\n\n return {\n colors: colors.length > 0 ? colors : undefined,\n theme: {\n mode: isDark ? 'dark' : 'light',\n },\n chart: {\n background: 'transparent',\n foreColor: textColor,\n },\n grid: {\n borderColor: gridColor,\n },\n xaxis: {\n labels: {\n style: {\n colors: textColor,\n },\n },\n axisBorder: {\n color: gridColor,\n },\n axisTicks: {\n color: gridColor,\n },\n },\n yaxis: {\n labels: {\n style: {\n colors: textColor,\n },\n },\n },\n legend: {\n labels: {\n colors: textColor,\n },\n },\n tooltip: {\n theme: isDark ? 'dark' : 'light',\n style: {\n fontSize: '12px',\n },\n x: {\n show: true,\n },\n marker: {\n show: true,\n },\n },\n dataLabels: {\n style: {\n colors: [textColor, textColor, textColor, textColor, textColor, textColor, textColor],\n },\n background: {\n enabled: false,\n },\n dropShadow: {\n enabled: false,\n },\n },\n }\n}\n\n// Deep merge objects\nfunction deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T {\n const result = { ...target }\n\n for (const key in source) {\n if (source[key] !== undefined) {\n if (\n typeof source[key] === 'object' &&\n source[key] !== null &&\n !Array.isArray(source[key]) &&\n typeof target[key] === 'object' &&\n target[key] !== null &&\n !Array.isArray(target[key])\n ) {\n result[key] = deepMerge(\n target[key] as Record<string, unknown>,\n source[key] as Record<string, unknown>\n ) as T[Extract<keyof T, string>]\n } else {\n result[key] = source[key] as T[Extract<keyof T, string>]\n }\n }\n }\n\n return result\n}\n\nexport const Chart: React.FC<ChartProps> = ({\n type,\n series,\n width = '100%',\n height = 350,\n options = {},\n themed = true,\n className = '',\n}) => {\n const chartRef = useRef<HTMLDivElement>(null)\n const chartInstance = useRef<any>(null)\n const [ApexChartsLib, setApexChartsLib] = useState<any>(null)\n const [missingDep, setMissingDep] = useState(false)\n\n // Load ApexCharts dynamically\n useEffect(() => {\n import('apexcharts')\n .then((mod) => {\n if (mod.default) {\n setApexChartsLib(() => mod.default)\n } else {\n setMissingDep(true)\n }\n })\n .catch(() => {\n setMissingDep(true)\n })\n }, [])\n\n // Build final options\n const buildOptions = (): ApexOptions => {\n const baseOptions: ApexOptions = {\n chart: {\n type,\n width,\n height,\n },\n series,\n }\n\n if (themed) {\n const themedOpts = getThemedOptions()\n return deepMerge(deepMerge(baseOptions as unknown as Record<string, unknown>, themedOpts as unknown as Record<string, unknown>), options as unknown as Record<string, unknown>) as ApexOptions\n }\n\n return deepMerge(baseOptions as unknown as Record<string, unknown>, options as unknown as Record<string, unknown>) as ApexOptions\n }\n\n // Initialize chart\n useEffect(() => {\n if (!chartRef.current || !ApexChartsLib) return\n\n const opts = buildOptions()\n chartInstance.current = new ApexChartsLib(chartRef.current, opts)\n chartInstance.current.render()\n\n return () => {\n if (chartInstance.current) {\n chartInstance.current.destroy()\n chartInstance.current = null\n }\n }\n }, [ApexChartsLib]) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Update chart when props change\n useEffect(() => {\n if (!chartInstance.current) return\n\n const opts = buildOptions()\n chartInstance.current.updateOptions(opts, true, true)\n }, [type, series, width, height, options, themed]) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Listen for theme changes\n useEffect(() => {\n if (!themed || typeof window === 'undefined') return\n\n const observer = new MutationObserver(() => {\n if (chartInstance.current) {\n const opts = buildOptions()\n chartInstance.current.updateOptions(opts, true, true)\n }\n })\n\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['data-theme', 'class'],\n })\n\n return () => observer.disconnect()\n }, [themed]) // eslint-disable-line react-hooks/exhaustive-deps\n\n if (missingDep) {\n return <MissingDependency packageName=\"apexcharts\" className={className} />\n }\n\n if (!ApexChartsLib) {\n return (\n <div className={className} style={{ width, height }}>\n <div className=\"flex items-center justify-center h-full\">\n <span className=\"loading loading-spinner\"></span>\n </div>\n </div>\n )\n }\n\n return <div ref={chartRef} className={className} />\n}\n"],"names":["getCssVar","varName","oklchToHex","oklch","match","l","c","hRad","b","l_","m_","s_","l3","m3","s3","r","g","bl","toSrgb","x","getThemeColors","value","getThemedOptions","colors","baseContentVar","textColor","base300Var","gridColor","textMatch","isDark","deepMerge","target","source","result","key","Chart","type","series","width","height","options","themed","className","chartRef","useRef","chartInstance","ApexChartsLib","setApexChartsLib","useState","missingDep","setMissingDep","useEffect","mod","buildOptions","baseOptions","themedOpts","opts","observer","jsx","MissingDependency"],"mappings":";;;AAsBA,SAASA,EAAUC,GAAyB;AAC1C,SAAI,OAAO,WAAa,MAAoB,KACrC,iBAAiB,SAAS,eAAe,EAAE,iBAAiBA,CAAO,EAAE,KAAA;AAC9E;AAGA,SAASC,EAAWC,GAAuB;AAEzC,QAAMC,IAAQD,EAAM,MAAM,4CAA4C;AACtE,MAAI,CAACC,EAAO,QAAO;AAEnB,QAAMC,IAAI,WAAWD,EAAM,CAAC,CAAC,IAAI,KAC3BE,IAAI,WAAWF,EAAM,CAAC,CAAC,GAKvBG,IAJI,WAAWH,EAAM,CAAC,CAAC,IAIX,KAAK,KAAM,KACvB,IAAIE,IAAI,KAAK,IAAIC,CAAI,GACrBC,IAAIF,IAAI,KAAK,IAAIC,CAAI,GAGrBE,IAAKJ,IAAI,eAAe,IAAI,eAAeG,GAC3CE,IAAKL,IAAI,eAAe,IAAI,eAAeG,GAC3CG,IAAKN,IAAI,eAAe,IAAI,cAAeG,GAE3CI,IAAKH,IAAKA,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EAAA,CAAsB,IAGtEI,IAUE,gBAAAY,EAAC,OAAA,EAAI,KAAKf,GAAU,WAAAD,EAAA,CAAsB,sBAR5C,OAAA,EAAI,WAAAA,GAAsB,OAAO,EAAE,OAAAJ,GAAO,QAAAC,EAAA,GACzC,UAAA,gBAAAmB,EAAC,OAAA,EAAI,WAAU,2CACb,UAAA,gBAAAA,EAAC,UAAK,WAAU,0BAAA,CAA0B,GAC5C,GACF;AAKN;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as e, jsxs as n } from "react/jsx-runtime";
|
|
2
|
+
const t = 200, a = ({
|
|
3
|
+
packageName: s,
|
|
4
|
+
bordered: i = !0,
|
|
5
|
+
className: r = ""
|
|
6
|
+
}) => {
|
|
7
|
+
const c = [
|
|
8
|
+
"inline-flex items-center justify-center",
|
|
9
|
+
i && "border border-base-content/20 p-3",
|
|
10
|
+
"bg-base-100",
|
|
11
|
+
r
|
|
12
|
+
].filter(Boolean).join(" ");
|
|
13
|
+
return /* @__PURE__ */ e("div", { className: c, style: { minWidth: t, minHeight: t }, children: /* @__PURE__ */ n("div", { className: "flex flex-col items-center justify-center gap-1 text-center", children: [
|
|
14
|
+
/* @__PURE__ */ e("svg", { className: "w-6 h-6 text-warning", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
|
|
15
|
+
/* @__PURE__ */ e("span", { className: "text-sm text-base-content/70", children: "Missing dependency" }),
|
|
16
|
+
/* @__PURE__ */ n("code", { className: "text-xs bg-base-200 px-1 py-0.5 rounded whitespace-nowrap", children: [
|
|
17
|
+
"npm install ",
|
|
18
|
+
s
|
|
19
|
+
] })
|
|
20
|
+
] }) });
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
a as MissingDependency
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=MissingDependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MissingDependency.js","sources":["../../src/components/MissingDependency.tsx"],"sourcesContent":["import React from 'react'\n\nexport interface MissingDependencyProps {\n packageName: string\n bordered?: boolean\n className?: string\n}\n\n// Width to accommodate \"@tanstack/react-virtual\" (longest package name)\nconst MIN_WIDTH = 200\n\nexport const MissingDependency: React.FC<MissingDependencyProps> = ({\n packageName,\n bordered = true,\n className = '',\n}) => {\n const containerClasses = [\n 'inline-flex items-center justify-center',\n bordered && 'border border-base-content/20 p-3',\n 'bg-base-100',\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <div className={containerClasses} style={{ minWidth: MIN_WIDTH, minHeight: MIN_WIDTH }}>\n <div className=\"flex flex-col items-center justify-center gap-1 text-center\">\n <svg className=\"w-6 h-6 text-warning\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\">\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth={2} d=\"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z\" />\n </svg>\n <span className=\"text-sm text-base-content/70\">Missing dependency</span>\n <code className=\"text-xs bg-base-200 px-1 py-0.5 rounded whitespace-nowrap\">npm install {packageName}</code>\n </div>\n </div>\n )\n}\n"],"names":["MIN_WIDTH","MissingDependency","packageName","bordered","className","containerClasses","jsx","jsxs"],"mappings":";AASA,MAAMA,IAAY,KAELC,IAAsD,CAAC;AAAA,EAClE,aAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,WAAAC,IAAY;AACd,MAAM;AACJ,QAAMC,IAAmB;AAAA,IACvB;AAAA,IACAF,KAAY;AAAA,IACZ;AAAA,IACAC;AAAA,EAAA,EAEC,OAAO,OAAO,EACd,KAAK,GAAG;AAEX,SACE,gBAAAE,EAAC,OAAA,EAAI,WAAWD,GAAkB,OAAO,EAAE,UAAUL,GAAW,WAAWA,EAAA,GACzE,UAAA,gBAAAO,EAAC,OAAA,EAAI,WAAU,+DACb,UAAA;AAAA,IAAA,gBAAAD,EAAC,SAAI,WAAU,wBAAuB,MAAK,QAAO,SAAQ,aAAY,QAAO,gBAC3E,4BAAC,QAAA,EAAK,eAAc,SAAQ,gBAAe,SAAQ,aAAa,GAAG,GAAE,wIAAuI,EAAA,CAC9M;AAAA,IACA,gBAAAA,EAAC,QAAA,EAAK,WAAU,gCAA+B,UAAA,sBAAkB;AAAA,IACjE,gBAAAC,EAAC,QAAA,EAAK,WAAU,6DAA4D,UAAA;AAAA,MAAA;AAAA,MAAaL;AAAA,IAAA,EAAA,CAAY;AAAA,EAAA,EAAA,CACvG,EAAA,CACF;AAEJ;"}
|
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
import { jsx as e, jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsx as e, jsxs as C } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as M, useState as w, useEffect as Q } from "react";
|
|
3
|
+
import { MissingDependency as D } from "./MissingDependency.js";
|
|
4
|
+
const L = ({
|
|
5
|
+
value: f,
|
|
6
|
+
size: a = 160,
|
|
7
|
+
errorLevel: x = "M",
|
|
8
|
+
icon: g,
|
|
9
|
+
iconSize: t = 40,
|
|
10
|
+
type: h = "canvas",
|
|
10
11
|
color: u = "#000000",
|
|
11
|
-
bgColor:
|
|
12
|
-
bordered:
|
|
13
|
-
status:
|
|
12
|
+
bgColor: p = "#FFFFFF",
|
|
13
|
+
bordered: c = !0,
|
|
14
|
+
status: n = "active",
|
|
14
15
|
onRefresh: N,
|
|
15
|
-
className:
|
|
16
|
-
...
|
|
16
|
+
className: y = "",
|
|
17
|
+
...s
|
|
17
18
|
}) => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
l(
|
|
21
|
-
}, [
|
|
22
|
-
if (
|
|
19
|
+
const i = M(null), [j, l] = w(n === "loading"), [k, F] = w(!1);
|
|
20
|
+
Q(() => {
|
|
21
|
+
l(n === "loading");
|
|
22
|
+
}, [n]), Q(() => {
|
|
23
|
+
if (n !== "active" || !f) return;
|
|
23
24
|
(async () => {
|
|
24
25
|
try {
|
|
25
26
|
l(!0);
|
|
26
27
|
let o;
|
|
27
28
|
try {
|
|
28
|
-
|
|
29
|
+
const v = await import("qrcode");
|
|
30
|
+
o = v.default || v;
|
|
29
31
|
} catch {
|
|
30
|
-
|
|
32
|
+
F(!0), l(!1);
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
33
|
-
if (
|
|
34
|
-
width:
|
|
35
|
+
if (h === "canvas" && i.current && (await o.toCanvas(i.current, f, {
|
|
36
|
+
width: a,
|
|
35
37
|
margin: 1,
|
|
36
38
|
color: {
|
|
37
39
|
dark: u,
|
|
38
|
-
light:
|
|
40
|
+
light: p
|
|
39
41
|
},
|
|
40
|
-
errorCorrectionLevel:
|
|
41
|
-
}),
|
|
42
|
-
const d =
|
|
42
|
+
errorCorrectionLevel: x
|
|
43
|
+
}), g)) {
|
|
44
|
+
const d = i.current.getContext("2d");
|
|
43
45
|
if (d) {
|
|
44
46
|
const m = new Image();
|
|
45
47
|
m.crossOrigin = "anonymous", m.onload = () => {
|
|
46
|
-
const
|
|
47
|
-
d.fillStyle =
|
|
48
|
-
}, m.src =
|
|
48
|
+
const b = (a - t) / 2, R = (a - t) / 2;
|
|
49
|
+
d.fillStyle = p, d.fillRect(b - 4, R - 4, t + 8, t + 8), d.drawImage(m, b, R, t, t);
|
|
50
|
+
}, m.src = g;
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
l(!1);
|
|
@@ -53,21 +55,17 @@ const F = ({
|
|
|
53
55
|
console.error("QR Code generation error:", o), l(!1);
|
|
54
56
|
}
|
|
55
57
|
})();
|
|
56
|
-
}, [
|
|
57
|
-
const
|
|
58
|
+
}, [f, a, x, g, t, h, u, p, n]);
|
|
59
|
+
const r = [
|
|
58
60
|
"inline-flex items-center justify-center",
|
|
59
|
-
|
|
61
|
+
c && "border border-base-content/20 p-3",
|
|
60
62
|
"bg-base-100",
|
|
61
|
-
|
|
63
|
+
y
|
|
62
64
|
].filter(Boolean).join(" ");
|
|
63
|
-
return j ? /* @__PURE__ */ e("div", { className:
|
|
64
|
-
/* @__PURE__ */ e("svg", { className: "w-8 h-8 text-warning", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
|
|
65
|
-
/* @__PURE__ */ e("span", { className: "text-sm text-base-content/70", children: "Missing dependency" }),
|
|
66
|
-
/* @__PURE__ */ e("code", { className: "text-xs bg-base-200 px-2 py-1 rounded", children: "npm install qrcode" })
|
|
67
|
-
] }) }) : s === "loading" || k ? /* @__PURE__ */ e("div", { className: i, style: { width: t + (n ? 24 : 0), height: t + (n ? 24 : 0) }, "data-state": "loading", ...c, children: /* @__PURE__ */ p("div", { className: "flex flex-col items-center justify-center gap-2", children: [
|
|
65
|
+
return k ? /* @__PURE__ */ e(D, { packageName: "qrcode", bordered: c, className: y, ...s }) : n === "loading" || j ? /* @__PURE__ */ e("div", { className: r, style: { width: a + (c ? 24 : 0), height: a + (c ? 24 : 0) }, "data-state": "loading", ...s, children: /* @__PURE__ */ C("div", { className: "flex flex-col items-center justify-center gap-2", children: [
|
|
68
66
|
/* @__PURE__ */ e("span", { className: "loading loading-spinner loading-lg" }),
|
|
69
67
|
/* @__PURE__ */ e("span", { className: "text-sm text-base-content/70", children: "Loading..." })
|
|
70
|
-
] }) }) :
|
|
68
|
+
] }) }) : n === "expired" ? /* @__PURE__ */ e("div", { className: r, style: { width: a + (c ? 24 : 0), height: a + (c ? 24 : 0) }, "data-state": "expired", ...s, children: /* @__PURE__ */ C("div", { className: "flex flex-col items-center justify-center gap-2", children: [
|
|
71
69
|
/* @__PURE__ */ e("svg", { className: "w-12 h-12 text-base-content/30", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ e(
|
|
72
70
|
"path",
|
|
73
71
|
{
|
|
@@ -78,11 +76,11 @@ const F = ({
|
|
|
78
76
|
) }),
|
|
79
77
|
/* @__PURE__ */ e("span", { className: "text-sm text-base-content/70", children: "QR Code Expired" }),
|
|
80
78
|
N && /* @__PURE__ */ e("button", { className: "btn btn-sm btn-primary", onClick: N, children: "Refresh" })
|
|
81
|
-
] }) }) :
|
|
79
|
+
] }) }) : h === "canvas" ? /* @__PURE__ */ e("div", { className: "inline-block", "data-state": "active", ...s, children: /* @__PURE__ */ e("div", { className: r, children: /* @__PURE__ */ e("canvas", { ref: i, style: { display: "block" } }) }) }) : /* @__PURE__ */ e("div", { className: "inline-block", "data-state": "active", ...s, children: /* @__PURE__ */ e("div", { className: r, children: /* @__PURE__ */ e("div", { style: { width: a, height: a }, className: "bg-base-content/5", children: /* @__PURE__ */ e("span", { className: "text-xs text-base-content/50", children: "SVG mode placeholder" }) }) }) });
|
|
82
80
|
};
|
|
83
|
-
|
|
81
|
+
L.displayName = "QRCode";
|
|
84
82
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
L as QRCode,
|
|
84
|
+
L as default
|
|
87
85
|
};
|
|
88
86
|
//# sourceMappingURL=QRCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QRCode.js","sources":["../../src/components/QRCode.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\n\nexport type QRCodeErrorLevel = 'L' | 'M' | 'Q' | 'H'\nexport type QRCodeType = 'canvas' | 'svg'\nexport type QRCodeStatus = 'active' | 'loading' | 'expired'\n\nexport interface QRCodeProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'color'> {\n value: string\n size?: number\n errorLevel?: QRCodeErrorLevel\n icon?: string\n iconSize?: number\n type?: QRCodeType\n color?: string\n bgColor?: string\n bordered?: boolean\n status?: QRCodeStatus\n onRefresh?: () => void\n}\n\nexport const QRCode: React.FC<QRCodeProps> = ({\n value,\n size = 160,\n errorLevel = 'M',\n icon,\n iconSize = 40,\n type = 'canvas',\n color = '#000000',\n bgColor = '#FFFFFF',\n bordered = true,\n status = 'active',\n onRefresh,\n className = '',\n ...rest\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null)\n const [loading, setLoading] = useState(status === 'loading')\n const [missingDep, setMissingDep] = useState(false)\n\n useEffect(() => {\n setLoading(status === 'loading')\n }, [status])\n\n useEffect(() => {\n if (status !== 'active' || !value) return\n\n const generateQRCode = async () => {\n try {\n setLoading(true)\n\n // Dynamic import to gracefully handle missing dependency\n let QRCodeLib\n try {\n
|
|
1
|
+
{"version":3,"file":"QRCode.js","sources":["../../src/components/QRCode.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\nimport { MissingDependency } from './MissingDependency'\n\nexport type QRCodeErrorLevel = 'L' | 'M' | 'Q' | 'H'\nexport type QRCodeType = 'canvas' | 'svg'\nexport type QRCodeStatus = 'active' | 'loading' | 'expired'\n\nexport interface QRCodeProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'color'> {\n value: string\n size?: number\n errorLevel?: QRCodeErrorLevel\n icon?: string\n iconSize?: number\n type?: QRCodeType\n color?: string\n bgColor?: string\n bordered?: boolean\n status?: QRCodeStatus\n onRefresh?: () => void\n}\n\nexport const QRCode: React.FC<QRCodeProps> = ({\n value,\n size = 160,\n errorLevel = 'M',\n icon,\n iconSize = 40,\n type = 'canvas',\n color = '#000000',\n bgColor = '#FFFFFF',\n bordered = true,\n status = 'active',\n onRefresh,\n className = '',\n ...rest\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null)\n const [loading, setLoading] = useState(status === 'loading')\n const [missingDep, setMissingDep] = useState(false)\n\n useEffect(() => {\n setLoading(status === 'loading')\n }, [status])\n\n useEffect(() => {\n if (status !== 'active' || !value) return\n\n const generateQRCode = async () => {\n try {\n setLoading(true)\n\n // Dynamic import to gracefully handle missing dependency\n let QRCodeLib: any\n try {\n const mod = await import('qrcode')\n QRCodeLib = mod.default || mod\n } catch {\n setMissingDep(true)\n setLoading(false)\n return\n }\n\n if (type === 'canvas' && canvasRef.current) {\n await QRCodeLib.toCanvas(canvasRef.current, value, {\n width: size,\n margin: 1,\n color: {\n dark: color,\n light: bgColor,\n },\n errorCorrectionLevel: errorLevel,\n })\n\n if (icon) {\n const canvas = canvasRef.current\n const ctx = canvas.getContext('2d')\n if (ctx) {\n const img = new Image()\n img.crossOrigin = 'anonymous'\n img.onload = () => {\n const iconX = (size - iconSize) / 2\n const iconY = (size - iconSize) / 2\n ctx.fillStyle = bgColor\n ctx.fillRect(iconX - 4, iconY - 4, iconSize + 8, iconSize + 8)\n ctx.drawImage(img, iconX, iconY, iconSize, iconSize)\n }\n img.src = icon\n }\n }\n }\n\n setLoading(false)\n } catch (error) {\n console.error('QR Code generation error:', error)\n setLoading(false)\n }\n }\n\n generateQRCode()\n }, [value, size, errorLevel, icon, iconSize, type, color, bgColor, status])\n\n // Download functionality can be implemented by consumers\n // by accessing the canvas ref and converting to data URL\n\n const containerClasses = [\n 'inline-flex items-center justify-center',\n bordered && 'border border-base-content/20 p-3',\n 'bg-base-100',\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n if (missingDep) {\n return <MissingDependency packageName=\"qrcode\" bordered={bordered} className={className} {...rest} />\n }\n\n if (status === 'loading' || loading) {\n return (\n <div className={containerClasses} style={{ width: size + (bordered ? 24 : 0), height: size + (bordered ? 24 : 0) }} data-state=\"loading\" {...rest}>\n <div className=\"flex flex-col items-center justify-center gap-2\">\n <span className=\"loading loading-spinner loading-lg\"></span>\n <span className=\"text-sm text-base-content/70\">Loading...</span>\n </div>\n </div>\n )\n }\n\n if (status === 'expired') {\n return (\n <div className={containerClasses} style={{ width: size + (bordered ? 24 : 0), height: size + (bordered ? 24 : 0) }} data-state=\"expired\" {...rest}>\n <div className=\"flex flex-col items-center justify-center gap-2\">\n <svg className=\"w-12 h-12 text-base-content/30\" fill=\"currentColor\" viewBox=\"0 0 20 20\">\n <path\n fillRule=\"evenodd\"\n d=\"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z\"\n clipRule=\"evenodd\"\n />\n </svg>\n <span className=\"text-sm text-base-content/70\">QR Code Expired</span>\n {onRefresh && (\n <button className=\"btn btn-sm btn-primary\" onClick={onRefresh}>\n Refresh\n </button>\n )}\n </div>\n </div>\n )\n }\n\n if (type === 'canvas') {\n return (\n <div className=\"inline-block\" data-state=\"active\" {...rest}>\n <div className={containerClasses}>\n <canvas ref={canvasRef} style={{ display: 'block' }} />\n </div>\n </div>\n )\n }\n\n return (\n <div className=\"inline-block\" data-state=\"active\" {...rest}>\n <div className={containerClasses}>\n <div style={{ width: size, height: size }} className=\"bg-base-content/5\">\n <span className=\"text-xs text-base-content/50\">SVG mode placeholder</span>\n </div>\n </div>\n </div>\n )\n}\n\nQRCode.displayName = 'QRCode'\n\nexport default QRCode\n"],"names":["QRCode","value","size","errorLevel","icon","iconSize","type","color","bgColor","bordered","status","onRefresh","className","rest","canvasRef","useRef","loading","setLoading","useState","missingDep","setMissingDep","useEffect","QRCodeLib","mod","ctx","img","iconX","iconY","error","containerClasses","MissingDependency","jsx","jsxs"],"mappings":";;;AAqBO,MAAMA,IAAgC,CAAC;AAAA,EAC5C,OAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC,IAAa;AAAA,EACb,MAAAC;AAAA,EACA,UAAAC,IAAW;AAA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,kCAAiC,MAAK,gBAAe,SAAQ,aAC1E,UAAA,gBAAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,UAAS;AAAA,QACT,GAAE;AAAA,QACF,UAAS;AAAA,MAAA;AAAA,IAAA,GAEb;AAAA,IACA,gBAAAA,EAAC,QAAA,EAAK,WAAU,gCAA+B,UAAA,mBAAe;AAAA,IAC7DpB,KACC,gBAAAoB,EAAC,UAAA,EAAO,WAAU,0BAAyB,SAASpB,GAAW,UAAA,UAAA,CAE/D;AAAA,EAAA,EAAA,CAEJ,EAAA,CACF,IAIAL,MAAS,WAET,gBAAAyB,EAAC,SAAI,WAAU,gBAAe,cAAW,UAAU,GAAGlB,GACpD,UAAA,gBAAAkB,EAAC,OAAA,EAAI,WAAWF,GACd,UAAA,gBAAAE,EAAC,UAAA,EAAO,KAAKjB,GAAW,OAAO,EAAE,SAAS,QAAA,GAAW,EAAA,CACvD,EAAA,CACF,IAKF,gBAAAiB,EAAC,OAAA,EAAI,WAAU,gBAAe,cAAW,UAAU,GAAGlB,GACpD,UAAA,gBAAAkB,EAAC,OAAA,EAAI,WAAWF,GACd,4BAAC,OAAA,EAAI,OAAO,EAAE,OAAO3B,GAAM,QAAQA,EAAA,GAAQ,WAAU,qBACnD,UAAA,gBAAA6B,EAAC,QAAA,EAAK,WAAU,gCAA+B,UAAA,uBAAA,CAAoB,EAAA,CACrE,GACF,GACF;AAEJ;AAEA/B,EAAO,cAAc;"}
|
|
@@ -1,69 +1,110 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import {
|
|
4
|
-
function
|
|
5
|
-
items:
|
|
6
|
-
height:
|
|
7
|
-
itemHeight:
|
|
8
|
-
renderItem:
|
|
9
|
-
overscan:
|
|
10
|
-
className:
|
|
11
|
-
innerClassName:
|
|
12
|
-
itemClassName:
|
|
13
|
-
width:
|
|
14
|
-
gap:
|
|
15
|
-
onScroll:
|
|
1
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as V, useState as x, useEffect as N } from "react";
|
|
3
|
+
import { MissingDependency as S } from "./MissingDependency.js";
|
|
4
|
+
function k({
|
|
5
|
+
items: n,
|
|
6
|
+
height: l,
|
|
7
|
+
itemHeight: c,
|
|
8
|
+
renderItem: p,
|
|
9
|
+
overscan: h = 5,
|
|
10
|
+
className: i = "",
|
|
11
|
+
innerClassName: m = "",
|
|
12
|
+
itemClassName: g = "",
|
|
13
|
+
width: o,
|
|
14
|
+
gap: a = 0,
|
|
15
|
+
onScroll: y
|
|
16
16
|
}) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}),
|
|
25
|
-
|
|
17
|
+
const u = V(null), [z, r] = x(!1), [s, f] = x(null);
|
|
18
|
+
return N(() => {
|
|
19
|
+
import("@tanstack/react-virtual").then((d) => {
|
|
20
|
+
d.useVirtualizer ? f(() => d.useVirtualizer) : r(!0);
|
|
21
|
+
}).catch(() => {
|
|
22
|
+
r(!0);
|
|
23
|
+
});
|
|
24
|
+
}, []), z ? /* @__PURE__ */ t(S, { packageName: "@tanstack/react-virtual", className: i }) : s ? /* @__PURE__ */ t(
|
|
25
|
+
w,
|
|
26
|
+
{
|
|
27
|
+
items: n,
|
|
28
|
+
height: l,
|
|
29
|
+
itemHeight: c,
|
|
30
|
+
renderItem: p,
|
|
31
|
+
overscan: h,
|
|
32
|
+
className: i,
|
|
33
|
+
innerClassName: m,
|
|
34
|
+
itemClassName: g,
|
|
35
|
+
width: o,
|
|
36
|
+
gap: a,
|
|
37
|
+
onScroll: y,
|
|
38
|
+
parentRef: u,
|
|
39
|
+
useVirtualizer: s
|
|
40
|
+
}
|
|
41
|
+
) : /* @__PURE__ */ t("div", { className: `overflow-auto ${i}`, style: { height: l, width: o }, children: /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ t("span", { className: "loading loading-spinner" }) }) });
|
|
42
|
+
}
|
|
43
|
+
function w({
|
|
44
|
+
items: n,
|
|
45
|
+
height: l,
|
|
46
|
+
itemHeight: c,
|
|
47
|
+
renderItem: p,
|
|
48
|
+
overscan: h,
|
|
49
|
+
className: i,
|
|
50
|
+
innerClassName: m,
|
|
51
|
+
itemClassName: g,
|
|
52
|
+
width: o,
|
|
53
|
+
gap: a,
|
|
54
|
+
onScroll: y,
|
|
55
|
+
parentRef: u,
|
|
56
|
+
useVirtualizer: z
|
|
57
|
+
}) {
|
|
58
|
+
const r = V(c), s = V(n);
|
|
59
|
+
r.current = c, s.current = n;
|
|
60
|
+
const f = z({
|
|
61
|
+
count: n.length,
|
|
62
|
+
getScrollElement: () => u.current,
|
|
63
|
+
estimateSize: (e) => (typeof r.current == "function" ? r.current(s.current[e], e) : r.current) + (a || 0),
|
|
64
|
+
overscan: h
|
|
65
|
+
}), d = f.getVirtualItems(), v = (e) => {
|
|
66
|
+
y?.(e.currentTarget.scrollTop);
|
|
26
67
|
};
|
|
27
|
-
return /* @__PURE__ */
|
|
68
|
+
return /* @__PURE__ */ t(
|
|
28
69
|
"div",
|
|
29
70
|
{
|
|
30
|
-
ref:
|
|
31
|
-
className: `overflow-auto ${
|
|
32
|
-
style: { height:
|
|
33
|
-
onScroll:
|
|
34
|
-
children: /* @__PURE__ */
|
|
71
|
+
ref: u,
|
|
72
|
+
className: `overflow-auto ${i}`,
|
|
73
|
+
style: { height: l, width: o },
|
|
74
|
+
onScroll: v,
|
|
75
|
+
children: /* @__PURE__ */ t(
|
|
35
76
|
"div",
|
|
36
77
|
{
|
|
37
|
-
className:
|
|
78
|
+
className: m,
|
|
38
79
|
style: {
|
|
39
|
-
height:
|
|
80
|
+
height: f.getTotalSize(),
|
|
40
81
|
width: "100%",
|
|
41
82
|
position: "relative"
|
|
42
83
|
},
|
|
43
|
-
children:
|
|
84
|
+
children: d.map((e) => /* @__PURE__ */ t(
|
|
44
85
|
"div",
|
|
45
86
|
{
|
|
46
|
-
className:
|
|
47
|
-
"data-index":
|
|
87
|
+
className: g,
|
|
88
|
+
"data-index": e.index,
|
|
48
89
|
style: {
|
|
49
90
|
position: "absolute",
|
|
50
91
|
top: 0,
|
|
51
92
|
left: 0,
|
|
52
93
|
width: "100%",
|
|
53
|
-
height:
|
|
54
|
-
transform: `translateY(${
|
|
94
|
+
height: e.size - (a || 0),
|
|
95
|
+
transform: `translateY(${e.start}px)`
|
|
55
96
|
},
|
|
56
|
-
children:
|
|
97
|
+
children: p(n[e.index], e.index)
|
|
57
98
|
},
|
|
58
|
-
|
|
99
|
+
e.key
|
|
59
100
|
))
|
|
60
101
|
}
|
|
61
102
|
)
|
|
62
103
|
}
|
|
63
104
|
);
|
|
64
105
|
}
|
|
65
|
-
|
|
106
|
+
k.displayName = "VirtualList";
|
|
66
107
|
export {
|
|
67
|
-
|
|
108
|
+
k as VirtualList
|
|
68
109
|
};
|
|
69
110
|
//# sourceMappingURL=VirtualList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualList.js","sources":["../../src/components/VirtualList.tsx"],"sourcesContent":["import React, { useRef } from 'react'\nimport {
|
|
1
|
+
{"version":3,"file":"VirtualList.js","sources":["../../src/components/VirtualList.tsx"],"sourcesContent":["import React, { useRef, useState, useEffect } from 'react'\nimport { MissingDependency } from './MissingDependency'\n\nexport interface VirtualListProps<T> {\n /** Array of items to render */\n items: T[]\n /** Height of the scrollable container */\n height: number | string\n /** Height of each item, or function returning estimated height per item */\n itemHeight: number | ((item: T, index: number) => number)\n /** Render function for each item */\n renderItem: (item: T, index: number) => React.ReactNode\n /** Number of items to render outside visible area */\n overscan?: number\n /** Additional class for the scroll container */\n className?: string\n /** Additional class for the inner container */\n innerClassName?: string\n /** Additional class for each item wrapper */\n itemClassName?: string\n /** Width of the container */\n width?: number | string\n /** Gap between items */\n gap?: number\n /** Callback when scroll position changes */\n onScroll?: (scrollTop: number) => void\n}\n\nexport function VirtualList<T>({\n items,\n height,\n itemHeight,\n renderItem,\n overscan = 5,\n className = '',\n innerClassName = '',\n itemClassName = '',\n width,\n gap = 0,\n onScroll,\n}: VirtualListProps<T>) {\n const parentRef = useRef<HTMLDivElement>(null)\n const [missingDep, setMissingDep] = useState(false)\n const [useVirtualizer, setUseVirtualizer] = useState<any>(null)\n\n useEffect(() => {\n import('@tanstack/react-virtual')\n .then((mod) => {\n if (mod.useVirtualizer) {\n setUseVirtualizer(() => mod.useVirtualizer)\n } else {\n setMissingDep(true)\n }\n })\n .catch(() => {\n setMissingDep(true)\n })\n }, [])\n\n if (missingDep) {\n return <MissingDependency packageName=\"@tanstack/react-virtual\" className={className} />\n }\n\n if (!useVirtualizer) {\n return (\n <div className={`overflow-auto ${className}`} style={{ height, width }}>\n <div className=\"flex items-center justify-center h-full\">\n <span className=\"loading loading-spinner\"></span>\n </div>\n </div>\n )\n }\n\n return (\n <VirtualListInner\n items={items}\n height={height}\n itemHeight={itemHeight}\n renderItem={renderItem}\n overscan={overscan}\n className={className}\n innerClassName={innerClassName}\n itemClassName={itemClassName}\n width={width}\n gap={gap}\n onScroll={onScroll}\n parentRef={parentRef}\n useVirtualizer={useVirtualizer}\n />\n )\n}\n\nfunction VirtualListInner<T>({\n items,\n height,\n itemHeight,\n renderItem,\n overscan,\n className,\n innerClassName,\n itemClassName,\n width,\n gap,\n onScroll,\n parentRef,\n useVirtualizer,\n}: VirtualListProps<T> & { parentRef: React.RefObject<HTMLDivElement | null>; useVirtualizer: any }) {\n const itemHeightRef = useRef(itemHeight)\n const itemsRef = useRef(items)\n itemHeightRef.current = itemHeight\n itemsRef.current = items\n\n const virtualizer = useVirtualizer({\n count: items.length,\n getScrollElement: () => parentRef.current,\n estimateSize: (index: number) => {\n const h = typeof itemHeightRef.current === 'function'\n ? itemHeightRef.current(itemsRef.current[index], index)\n : itemHeightRef.current\n return h + (gap || 0)\n },\n overscan,\n })\n\n const virtualItems = virtualizer.getVirtualItems()\n\n const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {\n onScroll?.(e.currentTarget.scrollTop)\n }\n\n return (\n <div\n ref={parentRef}\n className={`overflow-auto ${className}`}\n style={{ height, width }}\n onScroll={handleScroll}\n >\n <div\n className={innerClassName}\n style={{\n height: virtualizer.getTotalSize(),\n width: '100%',\n position: 'relative',\n }}\n >\n {virtualItems.map((virtualItem: any) => (\n <div\n key={virtualItem.key}\n className={itemClassName}\n data-index={virtualItem.index}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: '100%',\n height: virtualItem.size - (gap || 0),\n transform: `translateY(${virtualItem.start}px)`,\n }}\n >\n {renderItem(items[virtualItem.index], virtualItem.index)}\n </div>\n ))}\n </div>\n </div>\n )\n}\n\nVirtualList.displayName = 'VirtualList'\n"],"names":["VirtualList","items","height","itemHeight","renderItem","overscan","className","innerClassName","itemClassName","width","gap","onScroll","parentRef","useRef","missingDep","setMissingDep","useState","useVirtualizer","setUseVirtualizer","useEffect","mod","jsx","MissingDependency","VirtualListInner","itemHeightRef","itemsRef","virtualizer","index","virtualItems","handleScroll","virtualItem"],"mappings":";;;AA4BO,SAASA,EAAe;AAAA,EAC7B,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,WAAAC,IAAY;AAAA,EACZ,gBAAAC,IAAiB;AAAA,EACjB,eAAAC,IAAgB;AAAA,EAChB,OAAAC;AAAA,EACA,KAAAC,IAAM;AAAA,EACN,UAAAC;AACF,GAAwB;AACtB,QAAMC,IAAYC,EAAuB,IAAI,GACvC,CAACC,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAC5C,CAACC,GAAgBC,CAAiB,IAAIF,EAAc,IAAI;AAgB9D,SAdAG,EAAU,MAAM;AACd,WAAO,yBAAyB,EAC7B,KAAK,CAACC,MAAQ;AACb,MAAIA,EAAI,iBACNF,EAAkB,MAAME,EAAI,cAAc,IAE1CL,EAAc,EAAI;AAAA,IAEtB,CAAC,EACA,MAAM,MAAM;AACX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