asterui 0.12.25 → 0.12.27
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/Cascader.d.ts +2 -0
- package/dist/components/Descriptions.d.ts +35 -3
- package/dist/components/Empty.d.ts +10 -1
- package/dist/components/Image.d.ts +13 -1
- package/dist/components/List.d.ts +74 -8
- package/dist/components/Table.d.ts +64 -10
- package/dist/components/Tag.d.ts +16 -4
- package/dist/components/Timeline.d.ts +62 -7
- package/dist/components/Tree.d.ts +2 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.js +151 -152
- package/dist/index.js.map +1 -1
- package/dist/index10.js +1 -1
- package/dist/index100.js +5 -32
- package/dist/index100.js.map +1 -1
- package/dist/index101.js +13 -5
- package/dist/index101.js.map +1 -1
- package/dist/index102.js +43 -11
- package/dist/index102.js.map +1 -1
- package/dist/index103.js +11 -44
- package/dist/index103.js.map +1 -1
- package/dist/index104.js +12 -10
- package/dist/index104.js.map +1 -1
- package/dist/index105.js +7 -14
- package/dist/index105.js.map +1 -1
- package/dist/index106.js +12 -7
- package/dist/index106.js.map +1 -1
- package/dist/index107.js +29 -11
- package/dist/index107.js.map +1 -1
- package/dist/index108.js +16 -29
- package/dist/index108.js.map +1 -1
- package/dist/index109.js +31 -16
- package/dist/index109.js.map +1 -1
- package/dist/index110.js +517 -30
- package/dist/index110.js.map +1 -1
- package/dist/index111.js +45 -515
- package/dist/index111.js.map +1 -1
- package/dist/index15.js.map +1 -1
- package/dist/index22.js +1 -1
- package/dist/index23.js +127 -93
- package/dist/index23.js.map +1 -1
- package/dist/index39.js +162 -115
- package/dist/index39.js.map +1 -1
- package/dist/index40.js +398 -40
- package/dist/index40.js.map +1 -1
- package/dist/index41.js +132 -389
- package/dist/index41.js.map +1 -1
- package/dist/index42.js +252 -91
- package/dist/index42.js.map +1 -1
- package/dist/index43.js +143 -247
- package/dist/index43.js.map +1 -1
- package/dist/index44.js +15 -154
- package/dist/index44.js.map +1 -1
- package/dist/index45.js +17 -15
- package/dist/index45.js.map +1 -1
- package/dist/index46.js +136 -16
- package/dist/index46.js.map +1 -1
- package/dist/index47.js +118 -133
- package/dist/index47.js.map +1 -1
- package/dist/index48.js +35 -13
- package/dist/index48.js.map +1 -1
- package/dist/index49.js +34 -35
- package/dist/index49.js.map +1 -1
- package/dist/index50.js +81 -34
- package/dist/index50.js.map +1 -1
- package/dist/index51.js +166 -71
- package/dist/index51.js.map +1 -1
- package/dist/index52.js +144 -167
- package/dist/index52.js.map +1 -1
- package/dist/index53.js +11 -152
- package/dist/index53.js.map +1 -1
- package/dist/index54.js +55 -10
- package/dist/index54.js.map +1 -1
- package/dist/index55.js +12 -55
- package/dist/index55.js.map +1 -1
- package/dist/index56.js +7 -14
- package/dist/index56.js.map +1 -1
- package/dist/index57.js +333 -6
- package/dist/index57.js.map +1 -1
- package/dist/index58.js +47 -334
- package/dist/index58.js.map +1 -1
- package/dist/index59.js +122 -47
- package/dist/index59.js.map +1 -1
- package/dist/index60.js +108 -120
- package/dist/index60.js.map +1 -1
- package/dist/index61.js +167 -107
- package/dist/index61.js.map +1 -1
- package/dist/index62.js +29 -167
- package/dist/index62.js.map +1 -1
- package/dist/index63.js +120 -30
- package/dist/index63.js.map +1 -1
- package/dist/index64.js +80 -116
- package/dist/index64.js.map +1 -1
- package/dist/index65.js +19 -85
- package/dist/index65.js.map +1 -1
- package/dist/index66.js +73 -19
- package/dist/index66.js.map +1 -1
- package/dist/index67.js +54 -71
- package/dist/index67.js.map +1 -1
- package/dist/index68.js +44 -56
- package/dist/index68.js.map +1 -1
- package/dist/index69.js +49 -42
- package/dist/index69.js.map +1 -1
- package/dist/index70.js +121 -50
- package/dist/index70.js.map +1 -1
- package/dist/index71.js +102 -118
- package/dist/index71.js.map +1 -1
- package/dist/index72.js +72 -105
- package/dist/index72.js.map +1 -1
- package/dist/index73.js +67 -73
- package/dist/index73.js.map +1 -1
- package/dist/index74.js +19 -66
- package/dist/index74.js.map +1 -1
- package/dist/index75.js +55 -18
- package/dist/index75.js.map +1 -1
- package/dist/index76.js +251 -55
- package/dist/index76.js.map +1 -1
- package/dist/index77.js +22 -254
- package/dist/index77.js.map +1 -1
- package/dist/index78.js +31 -22
- package/dist/index78.js.map +1 -1
- package/dist/index79.js +93 -30
- package/dist/index79.js.map +1 -1
- package/dist/index80.js +626 -86
- package/dist/index80.js.map +1 -1
- package/dist/index81.js +73 -322
- package/dist/index81.js.map +1 -1
- package/dist/index82.js +39 -79
- package/dist/index82.js.map +1 -1
- package/dist/index83.js +23 -40
- package/dist/index83.js.map +1 -1
- package/dist/index84.js +207 -23
- package/dist/index84.js.map +1 -1
- package/dist/index85.js +149 -122
- package/dist/index85.js.map +1 -1
- package/dist/index86.js +152 -147
- package/dist/index86.js.map +1 -1
- package/dist/index87.js +143 -156
- package/dist/index87.js.map +1 -1
- package/dist/index88.js +35 -65
- package/dist/index88.js.map +1 -1
- package/dist/index89.js +234 -35
- package/dist/index89.js.map +1 -1
- package/dist/index90.js +31 -231
- package/dist/index90.js.map +1 -1
- package/dist/index91.js +210 -34
- package/dist/index91.js.map +1 -1
- package/dist/index92.js +418 -187
- package/dist/index92.js.map +1 -1
- package/dist/index93.js +686 -376
- package/dist/index93.js.map +1 -1
- package/dist/index94.js +165 -738
- package/dist/index94.js.map +1 -1
- package/dist/index95.js +253 -173
- package/dist/index95.js.map +1 -1
- package/dist/index96.js +64 -256
- package/dist/index96.js.map +1 -1
- package/dist/index97.js +121 -61
- package/dist/index97.js.map +1 -1
- package/dist/index98.js +14 -126
- package/dist/index98.js.map +1 -1
- package/dist/index99.js +31 -12
- package/dist/index99.js.map +1 -1
- package/package.json +1 -1
- package/dist/components/Indicator.d.ts +0 -7
- package/dist/index112.js +0 -53
- package/dist/index112.js.map +0 -1
package/dist/index50.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index50.js","sources":["../src/components/
|
|
1
|
+
{"version":3,"file":"index50.js","sources":["../src/components/Masonry.tsx"],"sourcesContent":["import React, { useRef, useState, useLayoutEffect, useCallback } from 'react'\n\nexport interface MasonryProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode\n columns?:\n | number\n | {\n xs?: number\n sm?: number\n md?: number\n lg?: number\n xl?: number\n '2xl'?: number\n }\n gap?: number\n}\n\n// Tailwind breakpoints in pixels\nconst BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536,\n}\n\nfunction getColumnsForWidth(\n columns: MasonryProps['columns'],\n width: number\n): number {\n if (typeof columns === 'number') {\n return columns\n }\n\n if (!columns) return 3\n\n // Find the appropriate column count for current width\n // Start from largest breakpoint and work down\n if (columns['2xl'] !== undefined && width >= BREAKPOINTS['2xl']) {\n return columns['2xl']\n }\n if (columns.xl !== undefined && width >= BREAKPOINTS.xl) {\n return columns.xl\n }\n if (columns.lg !== undefined && width >= BREAKPOINTS.lg) {\n return columns.lg\n }\n if (columns.md !== undefined && width >= BREAKPOINTS.md) {\n return columns.md\n }\n if (columns.sm !== undefined && width >= BREAKPOINTS.sm) {\n return columns.sm\n }\n if (columns.xs !== undefined) {\n return columns.xs\n }\n\n // Default fallback\n return 3\n}\n\nexport const Masonry: React.FC<MasonryProps> = ({\n children,\n columns = 3,\n gap = 16,\n className = '',\n style,\n ...rest\n}) => {\n const containerRef = useRef<HTMLDivElement>(null)\n const [positions, setPositions] = useState<\n Array<{ left: number; top: number }>\n >([])\n const [containerHeight, setContainerHeight] = useState(0)\n const itemRefs = useRef<(HTMLDivElement | null)[]>([])\n\n const childArray = React.Children.toArray(children)\n\n const calculateLayout = useCallback(() => {\n const container = containerRef.current\n if (!container || childArray.length === 0) return\n\n const containerWidth = container.offsetWidth\n // Use viewport width for responsive breakpoints (matches Tailwind behavior)\n const viewportWidth = typeof window !== 'undefined' ? window.innerWidth : containerWidth\n const numColumns = getColumnsForWidth(columns, viewportWidth)\n const columnWidth = (containerWidth - gap * (numColumns - 1)) / numColumns\n\n // Track height of each column\n const columnHeights = new Array(numColumns).fill(0)\n const newPositions: Array<{ left: number; top: number }> = []\n\n // Place each item in the shortest column\n childArray.forEach((_, index) => {\n const itemEl = itemRefs.current[index]\n if (!itemEl) return\n\n // Find shortest column\n let shortestColumn = 0\n let minHeight = columnHeights[0]\n for (let i = 1; i < numColumns; i++) {\n if (columnHeights[i] < minHeight) {\n minHeight = columnHeights[i]\n shortestColumn = i\n }\n }\n\n // Calculate position\n const left = shortestColumn * (columnWidth + gap)\n const top = columnHeights[shortestColumn]\n\n newPositions[index] = { left, top }\n\n // Update column height\n const itemHeight = itemEl.offsetHeight\n columnHeights[shortestColumn] += itemHeight + gap\n })\n\n setPositions(newPositions)\n setContainerHeight(Math.max(...columnHeights) - gap)\n }, [children, columns, gap, childArray.length])\n\n // Calculate layout after render and on resize\n useLayoutEffect(() => {\n calculateLayout()\n\n const handleResize = () => {\n calculateLayout()\n }\n\n window.addEventListener('resize', handleResize)\n return () => window.removeEventListener('resize', handleResize)\n }, [calculateLayout])\n\n // Recalculate when children change\n useLayoutEffect(() => {\n // Small delay to ensure refs are populated\n const timer = setTimeout(calculateLayout, 0)\n return () => clearTimeout(timer)\n }, [children, calculateLayout])\n\n const containerWidth = containerRef.current?.offsetWidth ?? 0\n const viewportWidth = typeof window !== 'undefined' ? window.innerWidth : containerWidth\n const numColumns = getColumnsForWidth(columns, viewportWidth)\n const columnWidth =\n containerWidth > 0\n ? (containerWidth - gap * (numColumns - 1)) / numColumns\n : 0\n\n return (\n <div\n ref={containerRef}\n className={className}\n style={{\n position: 'relative',\n height: containerHeight > 0 ? containerHeight : undefined,\n ...style,\n }}\n {...rest}\n >\n {childArray.map((child, index) => (\n <div\n key={index}\n ref={(el) => {\n itemRefs.current[index] = el\n }}\n style={{\n position: positions.length > 0 ? 'absolute' : 'relative',\n left: positions[index]?.left ?? 0,\n top: positions[index]?.top ?? 0,\n width: columnWidth > 0 ? columnWidth : '100%',\n visibility: positions.length > 0 ? 'visible' : 'hidden',\n }}\n >\n {child}\n </div>\n ))}\n </div>\n )\n}\n\nMasonry.displayName = 'Masonry'\n\nexport default Masonry\n"],"names":["BREAKPOINTS","getColumnsForWidth","columns","width","Masonry","children","gap","className","style","rest","containerRef","useRef","positions","setPositions","useState","containerHeight","setContainerHeight","itemRefs","childArray","React","calculateLayout","useCallback","container","containerWidth","viewportWidth","numColumns","columnWidth","columnHeights","newPositions","_","index","itemEl","shortestColumn","minHeight","i","left","top","itemHeight","useLayoutEffect","handleResize","timer","jsx","child","el"],"mappings":";;AAkBA,MAAMA,IAAc;AAAA,EAClB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,SAASC,EACPC,GACAC,GACQ;AACR,SAAI,OAAOD,KAAY,WACdA,IAGJA,IAIDA,EAAQ,KAAK,MAAM,UAAaC,KAASH,EAAY,KAAK,IACrDE,EAAQ,KAAK,IAElBA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,SACVA,EAAQ,KAIV,IAxBc;AAyBvB;AAEO,MAAME,IAAkC,CAAC;AAAA,EAC9C,UAAAC;AAAA,EACA,SAAAH,IAAU;AAAA,EACV,KAAAI,IAAM;AAAA,EACN,WAAAC,IAAY;AAAA,EACZ,OAAAC;AAAA,EACA,GAAGC;AACL,MAAM;AACJ,QAAMC,IAAeC,EAAuB,IAAI,GAC1C,CAACC,GAAWC,CAAY,IAAIC,EAEhC,CAAA,CAAE,GACE,CAACC,GAAiBC,CAAkB,IAAIF,EAAS,CAAC,GAClDG,IAAWN,EAAkC,EAAE,GAE/CO,IAAaC,EAAM,SAAS,QAAQd,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|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { jsx as a, jsxs as K } from "react/jsx-runtime";
|
|
2
|
+
import { useState as f, useRef as $, useCallback as A, useEffect as C } from "react";
|
|
3
|
+
import { createPortal as oe } from "react-dom";
|
|
4
|
+
const fe = ({
|
|
5
|
+
value: p,
|
|
6
|
+
defaultValue: q = "",
|
|
7
|
+
onChange: E,
|
|
8
|
+
onSelect: U,
|
|
9
|
+
onSearch: W,
|
|
10
|
+
options: R = [],
|
|
11
|
+
loading: X = !1,
|
|
12
|
+
prefix: k = "@",
|
|
13
|
+
split: v = " ",
|
|
14
|
+
placeholder: Y,
|
|
15
|
+
disabled: G = !1,
|
|
16
|
+
readOnly: J = !1,
|
|
17
|
+
rows: V = 3,
|
|
18
|
+
autoSize: o = !1,
|
|
19
|
+
notFoundContent: Q = "No matches found",
|
|
20
|
+
filterOption: x = !0,
|
|
21
|
+
className: Z = "",
|
|
22
|
+
dropdownClassName: _ = "",
|
|
23
|
+
...z
|
|
20
24
|
}) => {
|
|
21
|
-
const h =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
const [ee, T] = f(q), h = p !== void 0 ? p : ee, [u, m] = f(!1), [I, N] = f(null), [D, M] = f(""), [d, y] = f(0), [g, H] = f(null), [j, te] = f({ top: 0, left: 0 }), l = $(null), b = $(null), B = $(null), ne = Array.isArray(k) ? k : [k], c = A(() => {
|
|
26
|
+
if (!x) return R;
|
|
27
|
+
const e = typeof x == "function" ? x : (t, n) => (n.label || n.value).toLowerCase().includes(t.toLowerCase());
|
|
28
|
+
return R.filter((t) => e(D, t));
|
|
29
|
+
}, [R, D, x])(), L = A(() => {
|
|
30
|
+
const e = l.current;
|
|
31
|
+
if (!e || !o) return;
|
|
32
|
+
e.style.height = "auto";
|
|
33
|
+
const t = e.scrollHeight;
|
|
34
|
+
if (typeof o == "object") {
|
|
35
|
+
const n = parseInt(getComputedStyle(e).lineHeight) || 20, r = o.minRows ? o.minRows * n : 0, s = o.maxRows ? o.maxRows * n : 1 / 0;
|
|
36
|
+
e.style.height = `${Math.min(Math.max(t, r), s)}px`;
|
|
37
|
+
} else
|
|
38
|
+
e.style.height = `${t}px`;
|
|
39
|
+
}, [o]);
|
|
40
|
+
C(() => {
|
|
41
|
+
L();
|
|
42
|
+
}, [h, L]);
|
|
43
|
+
const O = A(() => {
|
|
44
|
+
const e = l.current, t = B.current;
|
|
45
|
+
if (!e || !t || g === null) return;
|
|
46
|
+
const n = h.substring(0, g);
|
|
47
|
+
t.textContent = n;
|
|
48
|
+
const r = e.getBoundingClientRect(), s = t.getBoundingClientRect(), w = parseInt(getComputedStyle(e).lineHeight) || 20;
|
|
49
|
+
te({
|
|
50
|
+
top: r.top + window.scrollY + w + 4,
|
|
51
|
+
left: r.left + window.scrollX + Math.min(s.width % r.width, r.width - 200)
|
|
52
|
+
});
|
|
53
|
+
}, [h, g]);
|
|
54
|
+
C(() => {
|
|
55
|
+
u && O();
|
|
56
|
+
}, [u, O, D]);
|
|
57
|
+
const re = (e) => {
|
|
58
|
+
const t = e.target.value, n = e.target.selectionStart;
|
|
59
|
+
p === void 0 && T(t), E?.(t), se(t, n);
|
|
60
|
+
}, se = (e, t) => {
|
|
61
|
+
let n = null, r = null;
|
|
62
|
+
for (const s of ne) {
|
|
63
|
+
const i = e.substring(0, t).lastIndexOf(s);
|
|
64
|
+
if (i !== -1) {
|
|
65
|
+
const S = i > 0 ? e[i - 1] : v;
|
|
66
|
+
if (S === v || S === `
|
|
67
|
+
` || i === 0) {
|
|
68
|
+
const F = e.substring(i + s.length, t);
|
|
69
|
+
if (!F.includes(v) && !F.includes(`
|
|
70
|
+
`)) {
|
|
71
|
+
n = s, r = i;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (n !== null && r !== null) {
|
|
78
|
+
const s = e.substring(r + n.length, t);
|
|
79
|
+
N(n), M(s), H(r), m(!0), y(0), W?.(s, n);
|
|
80
|
+
} else
|
|
81
|
+
m(!1), N(null), M(""), H(null);
|
|
82
|
+
}, P = (e) => {
|
|
83
|
+
if (e.disabled || g === null || I === null) return;
|
|
84
|
+
const t = l.current;
|
|
85
|
+
if (!t) return;
|
|
86
|
+
const n = h.substring(0, g), r = h.substring(t.selectionStart), s = `${I}${e.value}${v}`, w = n + s + r;
|
|
87
|
+
p === void 0 && T(w), E?.(w), U?.(e, I), m(!1), N(null), M(""), H(null), setTimeout(() => {
|
|
88
|
+
const i = n.length + s.length;
|
|
89
|
+
t.focus(), t.setSelectionRange(i, i);
|
|
90
|
+
}, 0);
|
|
91
|
+
}, ae = (e) => {
|
|
92
|
+
if (u)
|
|
93
|
+
switch (e.key) {
|
|
94
|
+
case "ArrowDown":
|
|
95
|
+
e.preventDefault(), y((t) => (t + 1) % Math.max(c.length, 1));
|
|
96
|
+
break;
|
|
97
|
+
case "ArrowUp":
|
|
98
|
+
e.preventDefault(), y((t) => (t - 1 + c.length) % Math.max(c.length, 1));
|
|
99
|
+
break;
|
|
100
|
+
case "Enter":
|
|
101
|
+
c[d] && (e.preventDefault(), P(c[d]));
|
|
102
|
+
break;
|
|
103
|
+
case "Escape":
|
|
104
|
+
e.preventDefault(), m(!1);
|
|
105
|
+
break;
|
|
106
|
+
case "Tab":
|
|
107
|
+
c[d] && (e.preventDefault(), P(c[d]));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
C(() => {
|
|
112
|
+
const e = (t) => {
|
|
113
|
+
b.current && !b.current.contains(t.target) && l.current && !l.current.contains(t.target) && m(!1);
|
|
41
114
|
};
|
|
42
|
-
return
|
|
43
|
-
}, [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const v = h.current?.offsetWidth ?? 0, N = typeof window < "u" ? window.innerWidth : v, g = L(e, N), p = v > 0 ? (v - r * (g - 1)) / g : 0;
|
|
48
|
-
return /* @__PURE__ */ H(
|
|
115
|
+
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
116
|
+
}, []), C(() => {
|
|
117
|
+
u && b.current && b.current.querySelector('[data-active="true"]')?.scrollIntoView({ block: "nearest" });
|
|
118
|
+
}, [d, u]);
|
|
119
|
+
const le = u && /* @__PURE__ */ a(
|
|
49
120
|
"div",
|
|
50
121
|
{
|
|
51
|
-
ref:
|
|
52
|
-
className: z
|
|
122
|
+
ref: b,
|
|
123
|
+
className: `fixed z-50 bg-base-100 border border-base-300 rounded-lg shadow-lg
|
|
124
|
+
min-w-48 max-h-60 overflow-auto ${_}`,
|
|
53
125
|
style: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
...M
|
|
126
|
+
top: j.top,
|
|
127
|
+
left: j.left
|
|
57
128
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"div",
|
|
129
|
+
children: X ? /* @__PURE__ */ a("div", { className: "p-3 text-center text-base-content/60", children: /* @__PURE__ */ a("span", { className: "loading loading-spinner loading-sm" }) }) : c.length === 0 ? /* @__PURE__ */ a("div", { className: "p-3 text-center text-base-content/60 text-sm", children: Q }) : /* @__PURE__ */ a("ul", { className: "menu menu-sm p-1", children: c.map((e, t) => /* @__PURE__ */ a("li", { children: /* @__PURE__ */ K(
|
|
130
|
+
"button",
|
|
61
131
|
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
n
|
|
75
|
-
))
|
|
132
|
+
type: "button",
|
|
133
|
+
"data-active": t === d,
|
|
134
|
+
className: `flex items-center gap-2 ${t === d ? "active" : ""} ${e.disabled ? "disabled opacity-50 cursor-not-allowed" : ""}`,
|
|
135
|
+
onClick: () => P(e),
|
|
136
|
+
onMouseEnter: () => y(t),
|
|
137
|
+
children: [
|
|
138
|
+
e.avatar && /* @__PURE__ */ a("div", { className: "avatar", children: /* @__PURE__ */ a("div", { className: "w-6 h-6 rounded-full", children: /* @__PURE__ */ a("img", { src: e.avatar, alt: "" }) }) }),
|
|
139
|
+
/* @__PURE__ */ a("span", { children: e.label || e.value })
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
) }, e.value)) })
|
|
76
143
|
}
|
|
77
144
|
);
|
|
145
|
+
return /* @__PURE__ */ K("div", { className: `relative ${Z}`, "data-state": u ? "open" : "closed", ...z, children: [
|
|
146
|
+
/* @__PURE__ */ a(
|
|
147
|
+
"div",
|
|
148
|
+
{
|
|
149
|
+
ref: B,
|
|
150
|
+
className: "invisible absolute whitespace-pre-wrap break-words",
|
|
151
|
+
style: {
|
|
152
|
+
font: l.current ? getComputedStyle(l.current).font : void 0,
|
|
153
|
+
width: l.current?.clientWidth,
|
|
154
|
+
padding: l.current ? getComputedStyle(l.current).padding : void 0
|
|
155
|
+
},
|
|
156
|
+
"aria-hidden": "true"
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
/* @__PURE__ */ a(
|
|
160
|
+
"textarea",
|
|
161
|
+
{
|
|
162
|
+
ref: l,
|
|
163
|
+
value: h,
|
|
164
|
+
onChange: re,
|
|
165
|
+
onKeyDown: ae,
|
|
166
|
+
placeholder: Y,
|
|
167
|
+
disabled: G,
|
|
168
|
+
readOnly: J,
|
|
169
|
+
rows: typeof o == "object" ? o.minRows || V : o ? 1 : V,
|
|
170
|
+
className: "textarea textarea-bordered w-full resize-none"
|
|
171
|
+
}
|
|
172
|
+
),
|
|
173
|
+
oe(le, document.body)
|
|
174
|
+
] });
|
|
78
175
|
};
|
|
79
|
-
K.displayName = "Masonry";
|
|
80
176
|
export {
|
|
81
|
-
|
|
82
|
-
K as default
|
|
177
|
+
fe as Mention
|
|
83
178
|
};
|
|
84
179
|
//# sourceMappingURL=index51.js.map
|
package/dist/index51.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index51.js","sources":["../src/components/Masonry.tsx"],"sourcesContent":["import React, { useRef, useState, useLayoutEffect, useCallback } from 'react'\n\nexport interface MasonryProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode\n columns?:\n | number\n | {\n xs?: number\n sm?: number\n md?: number\n lg?: number\n xl?: number\n '2xl'?: number\n }\n gap?: number\n}\n\n// Tailwind breakpoints in pixels\nconst BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536,\n}\n\nfunction getColumnsForWidth(\n columns: MasonryProps['columns'],\n width: number\n): number {\n if (typeof columns === 'number') {\n return columns\n }\n\n if (!columns) return 3\n\n // Find the appropriate column count for current width\n // Start from largest breakpoint and work down\n if (columns['2xl'] !== undefined && width >= BREAKPOINTS['2xl']) {\n return columns['2xl']\n }\n if (columns.xl !== undefined && width >= BREAKPOINTS.xl) {\n return columns.xl\n }\n if (columns.lg !== undefined && width >= BREAKPOINTS.lg) {\n return columns.lg\n }\n if (columns.md !== undefined && width >= BREAKPOINTS.md) {\n return columns.md\n }\n if (columns.sm !== undefined && width >= BREAKPOINTS.sm) {\n return columns.sm\n }\n if (columns.xs !== undefined) {\n return columns.xs\n }\n\n // Default fallback\n return 3\n}\n\nexport const Masonry: React.FC<MasonryProps> = ({\n children,\n columns = 3,\n gap = 16,\n className = '',\n style,\n ...rest\n}) => {\n const containerRef = useRef<HTMLDivElement>(null)\n const [positions, setPositions] = useState<\n Array<{ left: number; top: number }>\n >([])\n const [containerHeight, setContainerHeight] = useState(0)\n const itemRefs = useRef<(HTMLDivElement | null)[]>([])\n\n const childArray = React.Children.toArray(children)\n\n const calculateLayout = useCallback(() => {\n const container = containerRef.current\n if (!container || childArray.length === 0) return\n\n const containerWidth = container.offsetWidth\n // Use viewport width for responsive breakpoints (matches Tailwind behavior)\n const viewportWidth = typeof window !== 'undefined' ? window.innerWidth : containerWidth\n const numColumns = getColumnsForWidth(columns, viewportWidth)\n const columnWidth = (containerWidth - gap * (numColumns - 1)) / numColumns\n\n // Track height of each column\n const columnHeights = new Array(numColumns).fill(0)\n const newPositions: Array<{ left: number; top: number }> = []\n\n // Place each item in the shortest column\n childArray.forEach((_, index) => {\n const itemEl = itemRefs.current[index]\n if (!itemEl) return\n\n // Find shortest column\n let shortestColumn = 0\n let minHeight = columnHeights[0]\n for (let i = 1; i < numColumns; i++) {\n if (columnHeights[i] < minHeight) {\n minHeight = columnHeights[i]\n shortestColumn = i\n }\n }\n\n // Calculate position\n const left = shortestColumn * (columnWidth + gap)\n const top = columnHeights[shortestColumn]\n\n newPositions[index] = { left, top }\n\n // Update column height\n const itemHeight = itemEl.offsetHeight\n columnHeights[shortestColumn] += itemHeight + gap\n })\n\n setPositions(newPositions)\n setContainerHeight(Math.max(...columnHeights) - gap)\n }, [children, columns, gap, childArray.length])\n\n // Calculate layout after render and on resize\n useLayoutEffect(() => {\n calculateLayout()\n\n const handleResize = () => {\n calculateLayout()\n }\n\n window.addEventListener('resize', handleResize)\n return () => window.removeEventListener('resize', handleResize)\n }, [calculateLayout])\n\n // Recalculate when children change\n useLayoutEffect(() => {\n // Small delay to ensure refs are populated\n const timer = setTimeout(calculateLayout, 0)\n return () => clearTimeout(timer)\n }, [children, calculateLayout])\n\n const containerWidth = containerRef.current?.offsetWidth ?? 0\n const viewportWidth = typeof window !== 'undefined' ? window.innerWidth : containerWidth\n const numColumns = getColumnsForWidth(columns, viewportWidth)\n const columnWidth =\n containerWidth > 0\n ? (containerWidth - gap * (numColumns - 1)) / numColumns\n : 0\n\n return (\n <div\n ref={containerRef}\n className={className}\n style={{\n position: 'relative',\n height: containerHeight > 0 ? containerHeight : undefined,\n ...style,\n }}\n {...rest}\n >\n {childArray.map((child, index) => (\n <div\n key={index}\n ref={(el) => {\n itemRefs.current[index] = el\n }}\n style={{\n position: positions.length > 0 ? 'absolute' : 'relative',\n left: positions[index]?.left ?? 0,\n top: positions[index]?.top ?? 0,\n width: columnWidth > 0 ? columnWidth : '100%',\n visibility: positions.length > 0 ? 'visible' : 'hidden',\n }}\n >\n {child}\n </div>\n ))}\n </div>\n )\n}\n\nMasonry.displayName = 'Masonry'\n\nexport default Masonry\n"],"names":["BREAKPOINTS","getColumnsForWidth","columns","width","Masonry","children","gap","className","style","rest","containerRef","useRef","positions","setPositions","useState","containerHeight","setContainerHeight","itemRefs","childArray","React","calculateLayout","useCallback","container","containerWidth","viewportWidth","numColumns","columnWidth","columnHeights","newPositions","_","index","itemEl","shortestColumn","minHeight","i","left","top","itemHeight","useLayoutEffect","handleResize","timer","jsx","child","el"],"mappings":";;AAkBA,MAAMA,IAAc;AAAA,EAClB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,SAASC,EACPC,GACAC,GACQ;AACR,SAAI,OAAOD,KAAY,WACdA,IAGJA,IAIDA,EAAQ,KAAK,MAAM,UAAaC,KAASH,EAAY,KAAK,IACrDE,EAAQ,KAAK,IAElBA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,UAAaC,KAASH,EAAY,KAC5CE,EAAQ,KAEbA,EAAQ,OAAO,SACVA,EAAQ,KAIV,IAxBc;AAyBvB;AAEO,MAAME,IAAkC,CAAC;AAAA,EAC9C,UAAAC;AAAA,EACA,SAAAH,IAAU;AAAA,EACV,KAAAI,IAAM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;AAAA,QAZIZ;AAAA,MAAA,CAcR;AAAA,IAAA;AAAA,EAAA;AAGP;AAEA1B,EAAQ,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index51.js","sources":["../src/components/Mention.tsx"],"sourcesContent":["import React, { useState, useRef, useCallback, useEffect } from 'react'\nimport { createPortal } from 'react-dom'\n\nexport interface MentionOption {\n value: string\n label?: string\n avatar?: string\n disabled?: boolean\n}\n\nexport interface MentionProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'onSelect' | 'defaultValue' | 'prefix'> {\n value?: string\n defaultValue?: string\n onChange?: (value: string) => void\n onSelect?: (option: MentionOption, prefix: string) => void\n onSearch?: (text: string, prefix: string) => void\n options?: MentionOption[]\n loading?: boolean\n prefix?: string | string[]\n split?: string\n placeholder?: string\n disabled?: boolean\n readOnly?: boolean\n rows?: number\n autoSize?: boolean | { minRows?: number; maxRows?: number }\n notFoundContent?: React.ReactNode\n filterOption?: boolean | ((input: string, option: MentionOption) => boolean)\n dropdownClassName?: string\n}\n\nexport const Mention: React.FC<MentionProps> = ({\n value,\n defaultValue = '',\n onChange,\n onSelect,\n onSearch,\n options = [],\n loading = false,\n prefix = '@',\n split = ' ',\n placeholder,\n disabled = false,\n readOnly = false,\n rows = 3,\n autoSize = false,\n notFoundContent = 'No matches found',\n filterOption = true,\n className = '',\n dropdownClassName = '',\n ...rest\n}) => {\n const [internalValue, setInternalValue] = useState(defaultValue)\n const currentValue = value !== undefined ? value : internalValue\n\n const [isOpen, setIsOpen] = useState(false)\n const [activePrefix, setActivePrefix] = useState<string | null>(null)\n const [searchText, setSearchText] = useState('')\n const [activeIndex, setActiveIndex] = useState(0)\n const [mentionStart, setMentionStart] = useState<number | null>(null)\n const [dropdownPosition, setDropdownPosition] = useState({ top: 0, left: 0 })\n\n const textareaRef = useRef<HTMLTextAreaElement>(null)\n const dropdownRef = useRef<HTMLDivElement>(null)\n const measureRef = useRef<HTMLDivElement>(null)\n\n const prefixes = Array.isArray(prefix) ? prefix : [prefix]\n\n // Filter options based on search text\n const filteredOptions = useCallback(() => {\n if (!filterOption) return options\n\n const filterFn =\n typeof filterOption === 'function'\n ? filterOption\n : (input: string, option: MentionOption) => {\n const label = option.label || option.value\n return label.toLowerCase().includes(input.toLowerCase())\n }\n\n return options.filter((opt) => filterFn(searchText, opt))\n }, [options, searchText, filterOption])\n\n const filtered = filteredOptions()\n\n // Update textarea height for autoSize\n const updateHeight = useCallback(() => {\n const textarea = textareaRef.current\n if (!textarea || !autoSize) return\n\n textarea.style.height = 'auto'\n const scrollHeight = textarea.scrollHeight\n\n if (typeof autoSize === 'object') {\n const lineHeight = parseInt(getComputedStyle(textarea).lineHeight) || 20\n const minHeight = autoSize.minRows ? autoSize.minRows * lineHeight : 0\n const maxHeight = autoSize.maxRows ? autoSize.maxRows * lineHeight : Infinity\n\n textarea.style.height = `${Math.min(Math.max(scrollHeight, minHeight), maxHeight)}px`\n } else {\n textarea.style.height = `${scrollHeight}px`\n }\n }, [autoSize])\n\n useEffect(() => {\n updateHeight()\n }, [currentValue, updateHeight])\n\n // Calculate dropdown position\n const updateDropdownPosition = useCallback(() => {\n const textarea = textareaRef.current\n const measure = measureRef.current\n if (!textarea || !measure || mentionStart === null) return\n\n // Get text before cursor to measure position\n const textBeforeCursor = currentValue.substring(0, mentionStart)\n\n // Create a temporary element to measure text position\n measure.textContent = textBeforeCursor\n\n const textareaRect = textarea.getBoundingClientRect()\n const measureRect = measure.getBoundingClientRect()\n\n // Calculate position relative to viewport\n const lineHeight = parseInt(getComputedStyle(textarea).lineHeight) || 20\n\n setDropdownPosition({\n top: textareaRect.top + window.scrollY + lineHeight + 4,\n left: textareaRect.left + window.scrollX + Math.min(measureRect.width % textareaRect.width, textareaRect.width - 200),\n })\n }, [currentValue, mentionStart])\n\n useEffect(() => {\n if (isOpen) {\n updateDropdownPosition()\n }\n }, [isOpen, updateDropdownPosition, searchText])\n\n // Handle text change\n const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n const newValue = e.target.value\n const cursorPos = e.target.selectionStart\n\n if (value === undefined) {\n setInternalValue(newValue)\n }\n onChange?.(newValue)\n\n // Check if we should open the mention dropdown\n checkForMention(newValue, cursorPos)\n }\n\n const checkForMention = (text: string, cursorPos: number) => {\n // Look backwards from cursor for a prefix\n let foundPrefix: string | null = null\n let foundStart: number | null = null\n\n for (const p of prefixes) {\n // Find the last occurrence of prefix before cursor\n const beforeCursor = text.substring(0, cursorPos)\n const lastPrefixIndex = beforeCursor.lastIndexOf(p)\n\n if (lastPrefixIndex !== -1) {\n // Check if prefix is at start or preceded by whitespace/split\n const charBefore = lastPrefixIndex > 0 ? text[lastPrefixIndex - 1] : split\n if (charBefore === split || charBefore === '\\n' || lastPrefixIndex === 0) {\n // Check if there's no space between prefix and cursor\n const textAfterPrefix = text.substring(lastPrefixIndex + p.length, cursorPos)\n if (!textAfterPrefix.includes(split) && !textAfterPrefix.includes('\\n')) {\n foundPrefix = p\n foundStart = lastPrefixIndex\n break\n }\n }\n }\n }\n\n if (foundPrefix !== null && foundStart !== null) {\n const search = text.substring(foundStart + foundPrefix.length, cursorPos)\n setActivePrefix(foundPrefix)\n setSearchText(search)\n setMentionStart(foundStart)\n setIsOpen(true)\n setActiveIndex(0)\n onSearch?.(search, foundPrefix)\n } else {\n setIsOpen(false)\n setActivePrefix(null)\n setSearchText('')\n setMentionStart(null)\n }\n }\n\n // Handle option selection\n const selectOption = (option: MentionOption) => {\n if (option.disabled || mentionStart === null || activePrefix === null) return\n\n const textarea = textareaRef.current\n if (!textarea) return\n\n const beforeMention = currentValue.substring(0, mentionStart)\n const afterCursor = currentValue.substring(textarea.selectionStart)\n\n const mentionText = `${activePrefix}${option.value}${split}`\n const newValue = beforeMention + mentionText + afterCursor\n\n if (value === undefined) {\n setInternalValue(newValue)\n }\n onChange?.(newValue)\n onSelect?.(option, activePrefix)\n\n setIsOpen(false)\n setActivePrefix(null)\n setSearchText('')\n setMentionStart(null)\n\n // Set cursor position after mention\n setTimeout(() => {\n const newCursorPos = beforeMention.length + mentionText.length\n textarea.focus()\n textarea.setSelectionRange(newCursorPos, newCursorPos)\n }, 0)\n }\n\n // Handle keyboard navigation\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (!isOpen) return\n\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault()\n setActiveIndex((prev) => (prev + 1) % Math.max(filtered.length, 1))\n break\n case 'ArrowUp':\n e.preventDefault()\n setActiveIndex((prev) => (prev - 1 + filtered.length) % Math.max(filtered.length, 1))\n break\n case 'Enter':\n if (filtered[activeIndex]) {\n e.preventDefault()\n selectOption(filtered[activeIndex])\n }\n break\n case 'Escape':\n e.preventDefault()\n setIsOpen(false)\n break\n case 'Tab':\n if (filtered[activeIndex]) {\n e.preventDefault()\n selectOption(filtered[activeIndex])\n }\n break\n }\n }\n\n // Close dropdown on outside click\n useEffect(() => {\n const handleClickOutside = (e: MouseEvent) => {\n if (\n dropdownRef.current &&\n !dropdownRef.current.contains(e.target as Node) &&\n textareaRef.current &&\n !textareaRef.current.contains(e.target as Node)\n ) {\n setIsOpen(false)\n }\n }\n\n document.addEventListener('mousedown', handleClickOutside)\n return () => document.removeEventListener('mousedown', handleClickOutside)\n }, [])\n\n // Scroll active item into view\n useEffect(() => {\n if (isOpen && dropdownRef.current) {\n const activeItem = dropdownRef.current.querySelector('[data-active=\"true\"]')\n activeItem?.scrollIntoView({ block: 'nearest' })\n }\n }, [activeIndex, isOpen])\n\n const dropdown = isOpen && (\n <div\n ref={dropdownRef}\n className={`fixed z-50 bg-base-100 border border-base-300 rounded-lg shadow-lg\n min-w-48 max-h-60 overflow-auto ${dropdownClassName}`}\n style={{\n top: dropdownPosition.top,\n left: dropdownPosition.left,\n }}\n >\n {loading ? (\n <div className=\"p-3 text-center text-base-content/60\">\n <span className=\"loading loading-spinner loading-sm\"></span>\n </div>\n ) : filtered.length === 0 ? (\n <div className=\"p-3 text-center text-base-content/60 text-sm\">\n {notFoundContent}\n </div>\n ) : (\n <ul className=\"menu menu-sm p-1\">\n {filtered.map((option, index) => (\n <li key={option.value}>\n <button\n type=\"button\"\n data-active={index === activeIndex}\n className={`flex items-center gap-2 ${\n index === activeIndex ? 'active' : ''\n } ${option.disabled ? 'disabled opacity-50 cursor-not-allowed' : ''}`}\n onClick={() => selectOption(option)}\n onMouseEnter={() => setActiveIndex(index)}\n >\n {option.avatar && (\n <div className=\"avatar\">\n <div className=\"w-6 h-6 rounded-full\">\n <img src={option.avatar} alt=\"\" />\n </div>\n </div>\n )}\n <span>{option.label || option.value}</span>\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n )\n\n return (\n <div className={`relative ${className}`} data-state={isOpen ? 'open' : 'closed'} {...rest}>\n {/* Hidden measure element for cursor position */}\n <div\n ref={measureRef}\n className=\"invisible absolute whitespace-pre-wrap break-words\"\n style={{\n font: textareaRef.current ? getComputedStyle(textareaRef.current).font : undefined,\n width: textareaRef.current?.clientWidth,\n padding: textareaRef.current ? getComputedStyle(textareaRef.current).padding : undefined,\n }}\n aria-hidden=\"true\"\n />\n\n <textarea\n ref={textareaRef}\n value={currentValue}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readOnly}\n rows={typeof autoSize === 'object' ? autoSize.minRows || rows : autoSize ? 1 : rows}\n className=\"textarea textarea-bordered w-full resize-none\"\n />\n\n {createPortal(dropdown, document.body)}\n </div>\n )\n}\n"],"names":["Mention","value","defaultValue","onChange","onSelect","onSearch","options","loading","prefix","split","placeholder","disabled","readOnly","rows","autoSize","notFoundContent","filterOption","className","dropdownClassName","rest","internalValue","setInternalValue","useState","currentValue","isOpen","setIsOpen","activePrefix","setActivePrefix","searchText","setSearchText","activeIndex","setActiveIndex","mentionStart","setMentionStart","dropdownPosition","setDropdownPosition","textareaRef","useRef","dropdownRef","measureRef","prefixes","filtered","useCallback","filterFn","input","option","opt","updateHeight","textarea","scrollHeight","lineHeight","minHeight","maxHeight","useEffect","updateDropdownPosition","measure","textBeforeCursor","textareaRect","measureRect","handleChange","newValue","cursorPos","checkForMention","text","foundPrefix","foundStart","p","lastPrefixIndex","charBefore","textAfterPrefix","search","selectOption","beforeMention","afterCursor","mentionText","newCursorPos","handleKeyDown","prev","handleClickOutside","e","dropdown","jsx","index","jsxs","createPortal"],"mappings":";;;AA8BO,MAAMA,KAAkC,CAAC;AAAA,EAC9C,OAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC,IAAU,CAAA;AAAA,EACV,SAAAC,IAAU;AAAA,EACV,QAAAC,IAAS;AAAA,EACT,OAAAC,IAAQ;AAAA,EACR,aAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,UAAAC,IAAW;AAAA,EACX,MAAAC,IAAO;AAAA,EACP,UAAAC,IAAW;AAAA,EACX,iBAAAC,IAAkB;AAAA,EAClB,cAAAC,IAAe;AAAA,EACf,WAAAC,IAAY;AAAA,EACZ,mBAAAC,IAAoB;AAAA,EACpB,GAAGC;AACL,MAAM;AACJ,QAAM,CAACC,IAAeC,CAAgB,IAAIC,EAASpB,CAAY,GACzDqB,IAAetB,MAAU,SAAYA,IAAQmB,IAE7C,CAACI,GAAQC,CAAS,IAAIH,EAAS,EAAK,GACpC,CAACI,GAAcC,CAAe,IAAIL,EAAwB,IAAI,GAC9D,CAACM,GAAYC,CAAa,IAAIP,EAAS,EAAE,GACzC,CAACQ,GAAaC,CAAc,IAAIT,EAAS,CAAC,GAC1C,CAACU,GAAcC,CAAe,IAAIX,EAAwB,IAAI,GAC9D,CAACY,GAAkBC,EAAmB,IAAIb,EAAS,EAAE,KAAK,GAAG,MAAM,GAAG,GAEtEc,IAAcC,EAA4B,IAAI,GAC9CC,IAAcD,EAAuB,IAAI,GACzCE,IAAaF,EAAuB,IAAI,GAExCG,KAAW,MAAM,QAAQhC,CAAM,IAAIA,IAAS,CAACA,CAAM,G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