@llui/components 0.0.1
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/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/components/accordion.d.ts +115 -0
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +138 -0
- package/dist/components/alert-dialog.d.ts +45 -0
- package/dist/components/alert-dialog.d.ts.map +1 -0
- package/dist/components/alert-dialog.js +12 -0
- package/dist/components/angle-slider.d.ts +121 -0
- package/dist/components/angle-slider.d.ts.map +1 -0
- package/dist/components/angle-slider.js +145 -0
- package/dist/components/async-list.d.ts +104 -0
- package/dist/components/async-list.d.ts.map +1 -0
- package/dist/components/async-list.js +117 -0
- package/dist/components/avatar.d.ts +58 -0
- package/dist/components/avatar.d.ts.map +1 -0
- package/dist/components/avatar.js +43 -0
- package/dist/components/carousel.d.ts +128 -0
- package/dist/components/carousel.d.ts.map +1 -0
- package/dist/components/carousel.js +131 -0
- package/dist/components/cascade-select.d.ts +95 -0
- package/dist/components/cascade-select.d.ts.map +1 -0
- package/dist/components/cascade-select.js +100 -0
- package/dist/components/checkbox.d.ts +74 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +73 -0
- package/dist/components/clipboard.d.ts +72 -0
- package/dist/components/clipboard.d.ts.map +1 -0
- package/dist/components/clipboard.js +73 -0
- package/dist/components/collapsible.d.ts +64 -0
- package/dist/components/collapsible.d.ts.map +1 -0
- package/dist/components/collapsible.js +51 -0
- package/dist/components/color-picker.d.ts +125 -0
- package/dist/components/color-picker.d.ts.map +1 -0
- package/dist/components/color-picker.js +169 -0
- package/dist/components/combobox.d.ts +163 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +345 -0
- package/dist/components/context-menu.d.ts +105 -0
- package/dist/components/context-menu.d.ts.map +1 -0
- package/dist/components/context-menu.js +177 -0
- package/dist/components/date-input.d.ts +117 -0
- package/dist/components/date-input.d.ts.map +1 -0
- package/dist/components/date-input.js +149 -0
- package/dist/components/date-picker.d.ts +142 -0
- package/dist/components/date-picker.d.ts.map +1 -0
- package/dist/components/date-picker.js +294 -0
- package/dist/components/dialog.d.ts +152 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +140 -0
- package/dist/components/drawer.d.ts +106 -0
- package/dist/components/drawer.d.ts.map +1 -0
- package/dist/components/drawer.js +136 -0
- package/dist/components/editable.d.ts +92 -0
- package/dist/components/editable.d.ts.map +1 -0
- package/dist/components/editable.js +112 -0
- package/dist/components/file-upload.d.ts +251 -0
- package/dist/components/file-upload.d.ts.map +1 -0
- package/dist/components/file-upload.js +324 -0
- package/dist/components/floating-panel.d.ts +171 -0
- package/dist/components/floating-panel.d.ts.map +1 -0
- package/dist/components/floating-panel.js +198 -0
- package/dist/components/hover-card.d.ts +85 -0
- package/dist/components/hover-card.d.ts.map +1 -0
- package/dist/components/hover-card.js +128 -0
- package/dist/components/image-cropper.d.ts +129 -0
- package/dist/components/image-cropper.d.ts.map +1 -0
- package/dist/components/image-cropper.js +208 -0
- package/dist/components/index.d.ts +109 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +54 -0
- package/dist/components/listbox.d.ts +98 -0
- package/dist/components/listbox.d.ts.map +1 -0
- package/dist/components/listbox.js +174 -0
- package/dist/components/marquee.d.ts +84 -0
- package/dist/components/marquee.d.ts.map +1 -0
- package/dist/components/marquee.js +73 -0
- package/dist/components/menu.d.ts +131 -0
- package/dist/components/menu.d.ts.map +1 -0
- package/dist/components/menu.js +262 -0
- package/dist/components/navigation-menu.d.ts +111 -0
- package/dist/components/navigation-menu.d.ts.map +1 -0
- package/dist/components/navigation-menu.js +102 -0
- package/dist/components/number-input.d.ts +106 -0
- package/dist/components/number-input.d.ts.map +1 -0
- package/dist/components/number-input.js +178 -0
- package/dist/components/pagination.d.ts +113 -0
- package/dist/components/pagination.d.ts.map +1 -0
- package/dist/components/pagination.js +135 -0
- package/dist/components/password-input.d.ts +64 -0
- package/dist/components/password-input.d.ts.map +1 -0
- package/dist/components/password-input.js +52 -0
- package/dist/components/pin-input.d.ts +89 -0
- package/dist/components/pin-input.d.ts.map +1 -0
- package/dist/components/pin-input.js +139 -0
- package/dist/components/popover.d.ts +116 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +146 -0
- package/dist/components/presence.d.ts +71 -0
- package/dist/components/presence.d.ts.map +1 -0
- package/dist/components/presence.js +57 -0
- package/dist/components/progress.d.ts +74 -0
- package/dist/components/progress.d.ts.map +1 -0
- package/dist/components/progress.js +80 -0
- package/dist/components/qr-code.d.ts +114 -0
- package/dist/components/qr-code.d.ts.map +1 -0
- package/dist/components/qr-code.js +108 -0
- package/dist/components/radio-group.d.ts +89 -0
- package/dist/components/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group.js +161 -0
- package/dist/components/rating-group.d.ts +88 -0
- package/dist/components/rating-group.d.ts.map +1 -0
- package/dist/components/rating-group.js +122 -0
- package/dist/components/scroll-area.d.ts +124 -0
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +152 -0
- package/dist/components/select.d.ts +161 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +333 -0
- package/dist/components/signature-pad.d.ts +138 -0
- package/dist/components/signature-pad.d.ts.map +1 -0
- package/dist/components/signature-pad.js +142 -0
- package/dist/components/slider.d.ts +117 -0
- package/dist/components/slider.d.ts.map +1 -0
- package/dist/components/slider.js +210 -0
- package/dist/components/splitter.d.ts +87 -0
- package/dist/components/splitter.d.ts.map +1 -0
- package/dist/components/splitter.js +119 -0
- package/dist/components/steps.d.ts +104 -0
- package/dist/components/steps.d.ts.map +1 -0
- package/dist/components/steps.js +133 -0
- package/dist/components/switch.d.ts +66 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +59 -0
- package/dist/components/tabs.d.ts +146 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +244 -0
- package/dist/components/tags-input.d.ts +118 -0
- package/dist/components/tags-input.d.ts.map +1 -0
- package/dist/components/tags-input.js +168 -0
- package/dist/components/time-picker.d.ts +121 -0
- package/dist/components/time-picker.d.ts.map +1 -0
- package/dist/components/time-picker.js +147 -0
- package/dist/components/timer.d.ts +131 -0
- package/dist/components/timer.d.ts.map +1 -0
- package/dist/components/timer.js +117 -0
- package/dist/components/toast.d.ts +119 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/components/toast.js +102 -0
- package/dist/components/toc.d.ts +119 -0
- package/dist/components/toc.d.ts.map +1 -0
- package/dist/components/toc.js +107 -0
- package/dist/components/toggle-group.d.ts +80 -0
- package/dist/components/toggle-group.d.ts.map +1 -0
- package/dist/components/toggle-group.js +93 -0
- package/dist/components/toggle.d.ts +47 -0
- package/dist/components/toggle.d.ts.map +1 -0
- package/dist/components/toggle.js +41 -0
- package/dist/components/tooltip.d.ts +92 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +147 -0
- package/dist/components/tour.d.ts +145 -0
- package/dist/components/tour.d.ts.map +1 -0
- package/dist/components/tour.js +133 -0
- package/dist/components/tree-view.d.ts +216 -0
- package/dist/components/tree-view.d.ts.map +1 -0
- package/dist/components/tree-view.js +293 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/patterns/confirm-dialog.d.ts +92 -0
- package/dist/patterns/confirm-dialog.d.ts.map +1 -0
- package/dist/patterns/confirm-dialog.js +92 -0
- package/dist/patterns/index.d.ts +3 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +1 -0
- package/dist/utils/anatomy.d.ts +40 -0
- package/dist/utils/anatomy.d.ts.map +1 -0
- package/dist/utils/anatomy.js +41 -0
- package/dist/utils/aria-hidden.d.ts +12 -0
- package/dist/utils/aria-hidden.d.ts.map +1 -0
- package/dist/utils/aria-hidden.js +72 -0
- package/dist/utils/dismissable.d.ts +25 -0
- package/dist/utils/dismissable.d.ts.map +1 -0
- package/dist/utils/dismissable.js +65 -0
- package/dist/utils/dom.d.ts +8 -0
- package/dist/utils/dom.d.ts.map +1 -0
- package/dist/utils/dom.js +21 -0
- package/dist/utils/floating.d.ts +44 -0
- package/dist/utils/floating.d.ts.map +1 -0
- package/dist/utils/floating.js +44 -0
- package/dist/utils/focus-trap.d.ts +18 -0
- package/dist/utils/focus-trap.d.ts.map +1 -0
- package/dist/utils/focus-trap.js +85 -0
- package/dist/utils/focusables.d.ts +6 -0
- package/dist/utils/focusables.d.ts.map +1 -0
- package/dist/utils/focusables.js +65 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/interact-outside.d.ts +26 -0
- package/dist/utils/interact-outside.d.ts.map +1 -0
- package/dist/utils/interact-outside.js +46 -0
- package/dist/utils/remove-scroll.d.ts +8 -0
- package/dist/utils/remove-scroll.d.ts.map +1 -0
- package/dist/utils/remove-scroll.js +37 -0
- package/dist/utils/tree-collection.d.ts +61 -0
- package/dist/utils/tree-collection.d.ts.map +1 -0
- package/dist/utils/tree-collection.js +137 -0
- package/dist/utils/typeahead.d.ts +49 -0
- package/dist/utils/typeahead.d.ts.map +1 -0
- package/dist/utils/typeahead.js +81 -0
- package/package.json +282 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export function init(opts = {}) {
|
|
2
|
+
return {
|
|
3
|
+
value: 'value' in opts ? opts.value : 0,
|
|
4
|
+
min: opts.min ?? 0,
|
|
5
|
+
max: opts.max ?? 100,
|
|
6
|
+
orientation: opts.orientation ?? 'horizontal',
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function update(state, msg) {
|
|
10
|
+
switch (msg.type) {
|
|
11
|
+
case 'setValue':
|
|
12
|
+
return [{ ...state, value: msg.value }, []];
|
|
13
|
+
case 'setMax':
|
|
14
|
+
return [{ ...state, max: msg.max }, []];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function percent(state) {
|
|
18
|
+
if (state.value === null)
|
|
19
|
+
return null;
|
|
20
|
+
const range = state.max - state.min;
|
|
21
|
+
if (range <= 0)
|
|
22
|
+
return 0;
|
|
23
|
+
return ((state.value - state.min) / range) * 100;
|
|
24
|
+
}
|
|
25
|
+
export function valueState(state) {
|
|
26
|
+
if (state.value === null)
|
|
27
|
+
return 'indeterminate';
|
|
28
|
+
if (state.value >= state.max)
|
|
29
|
+
return 'complete';
|
|
30
|
+
return 'loading';
|
|
31
|
+
}
|
|
32
|
+
export function connect(get, _send, opts = {}) {
|
|
33
|
+
const label = opts.label;
|
|
34
|
+
const format = opts.format ?? defaultFormat;
|
|
35
|
+
return {
|
|
36
|
+
root: {
|
|
37
|
+
role: 'progressbar',
|
|
38
|
+
'aria-valuemin': (s) => get(s).min,
|
|
39
|
+
'aria-valuemax': (s) => get(s).max,
|
|
40
|
+
'aria-valuenow': (s) => get(s).value ?? undefined,
|
|
41
|
+
'aria-label': label,
|
|
42
|
+
'data-state': (s) => valueState(get(s)),
|
|
43
|
+
'data-orientation': (s) => get(s).orientation,
|
|
44
|
+
'data-scope': 'progress',
|
|
45
|
+
'data-part': 'root',
|
|
46
|
+
},
|
|
47
|
+
track: {
|
|
48
|
+
'data-state': (s) => valueState(get(s)),
|
|
49
|
+
'data-orientation': (s) => get(s).orientation,
|
|
50
|
+
'data-scope': 'progress',
|
|
51
|
+
'data-part': 'track',
|
|
52
|
+
},
|
|
53
|
+
range: {
|
|
54
|
+
'data-state': (s) => valueState(get(s)),
|
|
55
|
+
'data-orientation': (s) => get(s).orientation,
|
|
56
|
+
'data-scope': 'progress',
|
|
57
|
+
'data-part': 'range',
|
|
58
|
+
style: (s) => rangeStyle(get(s)),
|
|
59
|
+
},
|
|
60
|
+
label: {
|
|
61
|
+
'data-scope': 'progress',
|
|
62
|
+
'data-part': 'label',
|
|
63
|
+
},
|
|
64
|
+
valueText: (s) => format(get(s).value, get(s).max),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function defaultFormat(value, max) {
|
|
68
|
+
if (value === null)
|
|
69
|
+
return 'Loading…';
|
|
70
|
+
const pct = Math.round((value / max) * 100);
|
|
71
|
+
return `${pct}%`;
|
|
72
|
+
}
|
|
73
|
+
function rangeStyle(state) {
|
|
74
|
+
const p = percent(state);
|
|
75
|
+
if (p === null)
|
|
76
|
+
return '';
|
|
77
|
+
const clamped = Math.max(0, Math.min(100, p));
|
|
78
|
+
return state.orientation === 'horizontal' ? `width:${clamped}%;` : `height:${clamped}%;`;
|
|
79
|
+
}
|
|
80
|
+
export const progress = { init, update, connect, percent, valueState };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Send } from '@llui/dom';
|
|
2
|
+
/**
|
|
3
|
+
* QR code — renders a QR matrix as SVG. llui does not bundle a QR
|
|
4
|
+
* encoder (encoders are sizable and consumer apps typically already
|
|
5
|
+
* have one); instead, the consumer provides the encoded matrix via
|
|
6
|
+
* `setMatrix` (or through the optional `encode` callback on
|
|
7
|
+
* ConnectOptions, invoked when the value changes).
|
|
8
|
+
*
|
|
9
|
+
* Minimum usage with a BYOE (bring-your-own-encoder) library — the
|
|
10
|
+
* consumer dispatches `setMatrix` with the encoded bits from their
|
|
11
|
+
* update handler:
|
|
12
|
+
*
|
|
13
|
+
* import QRCode from 'qrcode-generator'
|
|
14
|
+
*
|
|
15
|
+
* update: (state, msg) => {
|
|
16
|
+
* if (msg.type === 'updateQr') {
|
|
17
|
+
* const q = QRCode(0, state.qr.errorCorrection)
|
|
18
|
+
* q.addData(msg.value); q.make()
|
|
19
|
+
* const n = q.getModuleCount()
|
|
20
|
+
* const matrix: boolean[][] = []
|
|
21
|
+
* for (let y = 0; y < n; y++) {
|
|
22
|
+
* const row: boolean[] = []
|
|
23
|
+
* for (let x = 0; x < n; x++) row.push(q.isDark(y, x))
|
|
24
|
+
* matrix.push(row)
|
|
25
|
+
* }
|
|
26
|
+
* return [{ ...state, qr: { ...state.qr, value: msg.value, matrix } }, []]
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
export type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
|
|
31
|
+
export interface QrCodeState {
|
|
32
|
+
value: string;
|
|
33
|
+
/** NxN boolean matrix — true means dark (filled) module. */
|
|
34
|
+
matrix: boolean[][];
|
|
35
|
+
errorCorrection: ErrorCorrectionLevel;
|
|
36
|
+
}
|
|
37
|
+
export type QrCodeMsg = {
|
|
38
|
+
type: 'setValue';
|
|
39
|
+
value: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'setMatrix';
|
|
42
|
+
matrix: boolean[][];
|
|
43
|
+
} | {
|
|
44
|
+
type: 'setErrorCorrection';
|
|
45
|
+
level: ErrorCorrectionLevel;
|
|
46
|
+
};
|
|
47
|
+
export interface QrCodeInit {
|
|
48
|
+
value?: string;
|
|
49
|
+
matrix?: boolean[][];
|
|
50
|
+
errorCorrection?: ErrorCorrectionLevel;
|
|
51
|
+
}
|
|
52
|
+
export declare function init(opts?: QrCodeInit): QrCodeState;
|
|
53
|
+
export declare function update(state: QrCodeState, msg: QrCodeMsg): [QrCodeState, never[]];
|
|
54
|
+
/** Matrix side length (in modules). Returns 0 for empty matrix. */
|
|
55
|
+
export declare function size(state: QrCodeState): number;
|
|
56
|
+
/**
|
|
57
|
+
* Compute an SVG path string that fills every dark module. Each dark
|
|
58
|
+
* module becomes a unit-sized square at (col, row) coordinates in module
|
|
59
|
+
* space; the caller scales via `viewBox` or CSS. Using a single path
|
|
60
|
+
* is vastly more performant than rendering N² individual <rect>s.
|
|
61
|
+
*/
|
|
62
|
+
export declare function toSvgPath(matrix: boolean[][]): string;
|
|
63
|
+
/**
|
|
64
|
+
* Encode the matrix as a monochrome 1-bit-per-pixel PNG-ish URL. This
|
|
65
|
+
* is a helper for <img src> consumption — it generates a `data:image/svg+xml`
|
|
66
|
+
* URL (SVG is simpler and scales losslessly).
|
|
67
|
+
*/
|
|
68
|
+
export declare function toDataUrl(matrix: boolean[][], foreground?: string, background?: string): string;
|
|
69
|
+
export interface QrCodeParts<S> {
|
|
70
|
+
root: {
|
|
71
|
+
'data-scope': 'qr-code';
|
|
72
|
+
'data-part': 'root';
|
|
73
|
+
'aria-label': string;
|
|
74
|
+
};
|
|
75
|
+
svg: {
|
|
76
|
+
'data-scope': 'qr-code';
|
|
77
|
+
'data-part': 'svg';
|
|
78
|
+
role: 'img';
|
|
79
|
+
viewBox: (s: S) => string;
|
|
80
|
+
'shape-rendering': 'crispEdges';
|
|
81
|
+
};
|
|
82
|
+
background: {
|
|
83
|
+
'data-scope': 'qr-code';
|
|
84
|
+
'data-part': 'background';
|
|
85
|
+
};
|
|
86
|
+
foreground: {
|
|
87
|
+
'data-scope': 'qr-code';
|
|
88
|
+
'data-part': 'foreground';
|
|
89
|
+
d: (s: S) => string;
|
|
90
|
+
};
|
|
91
|
+
downloadTrigger: {
|
|
92
|
+
type: 'button';
|
|
93
|
+
'aria-label': string;
|
|
94
|
+
'data-scope': 'qr-code';
|
|
95
|
+
'data-part': 'download-trigger';
|
|
96
|
+
onClick: (e: MouseEvent) => void;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export interface ConnectOptions {
|
|
100
|
+
label?: string;
|
|
101
|
+
downloadLabel?: string;
|
|
102
|
+
/** Filename for the downloaded SVG. */
|
|
103
|
+
downloadFilename?: string;
|
|
104
|
+
}
|
|
105
|
+
export declare function connect<S>(get: (s: S) => QrCodeState, send: Send<QrCodeMsg>, opts?: ConnectOptions): QrCodeParts<S>;
|
|
106
|
+
export declare const qrCode: {
|
|
107
|
+
init: typeof init;
|
|
108
|
+
update: typeof update;
|
|
109
|
+
connect: typeof connect;
|
|
110
|
+
size: typeof size;
|
|
111
|
+
toSvgPath: typeof toSvgPath;
|
|
112
|
+
toDataUrl: typeof toDataUrl;
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=qr-code.d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cAAmB,GACxB,WAAW,CAAC,CAAC,CAAC,CAoDhB;AAED,eAAO,MAAM,MAAM;;;;;;;CAAwD,CAAA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export function init(opts = {}) {
|
|
2
|
+
return {
|
|
3
|
+
value: opts.value ?? '',
|
|
4
|
+
matrix: opts.matrix ?? [],
|
|
5
|
+
errorCorrection: opts.errorCorrection ?? 'M',
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function update(state, msg) {
|
|
9
|
+
switch (msg.type) {
|
|
10
|
+
case 'setValue':
|
|
11
|
+
return [{ ...state, value: msg.value }, []];
|
|
12
|
+
case 'setMatrix':
|
|
13
|
+
return [{ ...state, matrix: msg.matrix }, []];
|
|
14
|
+
case 'setErrorCorrection':
|
|
15
|
+
return [{ ...state, errorCorrection: msg.level }, []];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Matrix side length (in modules). Returns 0 for empty matrix. */
|
|
19
|
+
export function size(state) {
|
|
20
|
+
return state.matrix.length;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compute an SVG path string that fills every dark module. Each dark
|
|
24
|
+
* module becomes a unit-sized square at (col, row) coordinates in module
|
|
25
|
+
* space; the caller scales via `viewBox` or CSS. Using a single path
|
|
26
|
+
* is vastly more performant than rendering N² individual <rect>s.
|
|
27
|
+
*/
|
|
28
|
+
export function toSvgPath(matrix) {
|
|
29
|
+
const parts = [];
|
|
30
|
+
for (let y = 0; y < matrix.length; y++) {
|
|
31
|
+
const row = matrix[y];
|
|
32
|
+
for (let x = 0; x < row.length; x++) {
|
|
33
|
+
if (row[x])
|
|
34
|
+
parts.push(`M${x},${y}h1v1h-1z`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return parts.join('');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Encode the matrix as a monochrome 1-bit-per-pixel PNG-ish URL. This
|
|
41
|
+
* is a helper for <img src> consumption — it generates a `data:image/svg+xml`
|
|
42
|
+
* URL (SVG is simpler and scales losslessly).
|
|
43
|
+
*/
|
|
44
|
+
export function toDataUrl(matrix, foreground = '#000', background = '#fff') {
|
|
45
|
+
const s = matrix.length;
|
|
46
|
+
if (s === 0)
|
|
47
|
+
return '';
|
|
48
|
+
const path = toSvgPath(matrix);
|
|
49
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${s} ${s}" shape-rendering="crispEdges">` +
|
|
50
|
+
`<rect width="${s}" height="${s}" fill="${background}"/>` +
|
|
51
|
+
`<path d="${path}" fill="${foreground}"/>` +
|
|
52
|
+
`</svg>`;
|
|
53
|
+
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
|
54
|
+
}
|
|
55
|
+
export function connect(get, send, opts = {}) {
|
|
56
|
+
const label = opts.label ?? 'QR code';
|
|
57
|
+
const filename = opts.downloadFilename ?? 'qrcode.svg';
|
|
58
|
+
return {
|
|
59
|
+
root: {
|
|
60
|
+
'data-scope': 'qr-code',
|
|
61
|
+
'data-part': 'root',
|
|
62
|
+
'aria-label': label,
|
|
63
|
+
},
|
|
64
|
+
svg: {
|
|
65
|
+
'data-scope': 'qr-code',
|
|
66
|
+
'data-part': 'svg',
|
|
67
|
+
role: 'img',
|
|
68
|
+
viewBox: (s) => {
|
|
69
|
+
const n = size(get(s));
|
|
70
|
+
return n > 0 ? `0 0 ${n} ${n}` : '0 0 1 1';
|
|
71
|
+
},
|
|
72
|
+
'shape-rendering': 'crispEdges',
|
|
73
|
+
},
|
|
74
|
+
background: {
|
|
75
|
+
'data-scope': 'qr-code',
|
|
76
|
+
'data-part': 'background',
|
|
77
|
+
},
|
|
78
|
+
foreground: {
|
|
79
|
+
'data-scope': 'qr-code',
|
|
80
|
+
'data-part': 'foreground',
|
|
81
|
+
d: (s) => toSvgPath(get(s).matrix),
|
|
82
|
+
},
|
|
83
|
+
downloadTrigger: {
|
|
84
|
+
type: 'button',
|
|
85
|
+
'aria-label': opts.downloadLabel ?? 'Download QR code',
|
|
86
|
+
'data-scope': 'qr-code',
|
|
87
|
+
'data-part': 'download-trigger',
|
|
88
|
+
onClick: () => {
|
|
89
|
+
// Generate an SVG blob and trigger a download via a hidden link.
|
|
90
|
+
// State isn't accessible here; caller should use the current value
|
|
91
|
+
// in a DOM query or run this inside a closure with state access.
|
|
92
|
+
// We dispatch a best-effort via the document for now.
|
|
93
|
+
const root = document.querySelector('[data-scope="qr-code"][data-part="svg"]');
|
|
94
|
+
if (!root)
|
|
95
|
+
return;
|
|
96
|
+
const xml = new XMLSerializer().serializeToString(root);
|
|
97
|
+
const blob = new Blob([xml], { type: 'image/svg+xml' });
|
|
98
|
+
const url = URL.createObjectURL(blob);
|
|
99
|
+
const a = document.createElement('a');
|
|
100
|
+
a.href = url;
|
|
101
|
+
a.download = filename;
|
|
102
|
+
a.click();
|
|
103
|
+
URL.revokeObjectURL(url);
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export const qrCode = { init, update, connect, size, toSvgPath, toDataUrl };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Send } from '@llui/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Radio group — a set of mutually-exclusive options. Users select one value
|
|
4
|
+
* at a time. Supports keyboard arrow navigation and disabled items.
|
|
5
|
+
*/
|
|
6
|
+
export type Orientation = 'horizontal' | 'vertical';
|
|
7
|
+
export interface RadioGroupState {
|
|
8
|
+
value: string | null;
|
|
9
|
+
items: string[];
|
|
10
|
+
disabledItems: string[];
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
orientation: Orientation;
|
|
13
|
+
}
|
|
14
|
+
export type RadioGroupMsg = {
|
|
15
|
+
type: 'setValue';
|
|
16
|
+
value: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'setItems';
|
|
19
|
+
items: string[];
|
|
20
|
+
disabled?: string[];
|
|
21
|
+
} | {
|
|
22
|
+
type: 'selectNext';
|
|
23
|
+
from: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'selectPrev';
|
|
26
|
+
from: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'selectFirst';
|
|
29
|
+
} | {
|
|
30
|
+
type: 'selectLast';
|
|
31
|
+
};
|
|
32
|
+
export interface RadioGroupInit {
|
|
33
|
+
value?: string | null;
|
|
34
|
+
items?: string[];
|
|
35
|
+
disabledItems?: string[];
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
orientation?: Orientation;
|
|
38
|
+
}
|
|
39
|
+
export declare function init(opts?: RadioGroupInit): RadioGroupState;
|
|
40
|
+
export declare function update(state: RadioGroupState, msg: RadioGroupMsg): [RadioGroupState, never[]];
|
|
41
|
+
export interface RadioItemParts<S> {
|
|
42
|
+
root: {
|
|
43
|
+
role: 'radio';
|
|
44
|
+
id: string;
|
|
45
|
+
'aria-checked': (s: S) => boolean;
|
|
46
|
+
'aria-disabled': (s: S) => 'true' | undefined;
|
|
47
|
+
'data-state': (s: S) => 'checked' | 'unchecked';
|
|
48
|
+
'data-disabled': (s: S) => '' | undefined;
|
|
49
|
+
'data-scope': 'radio-group';
|
|
50
|
+
'data-part': 'item';
|
|
51
|
+
'data-value': string;
|
|
52
|
+
tabIndex: (s: S) => number;
|
|
53
|
+
onClick: (e: MouseEvent) => void;
|
|
54
|
+
onKeyDown: (e: KeyboardEvent) => void;
|
|
55
|
+
};
|
|
56
|
+
label: {
|
|
57
|
+
'data-scope': 'radio-group';
|
|
58
|
+
'data-part': 'label';
|
|
59
|
+
'data-value': string;
|
|
60
|
+
for: string;
|
|
61
|
+
};
|
|
62
|
+
indicator: {
|
|
63
|
+
'data-state': (s: S) => 'checked' | 'unchecked';
|
|
64
|
+
'data-scope': 'radio-group';
|
|
65
|
+
'data-part': 'indicator';
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface RadioGroupParts<S> {
|
|
69
|
+
root: {
|
|
70
|
+
role: 'radiogroup';
|
|
71
|
+
'aria-orientation': (s: S) => Orientation;
|
|
72
|
+
'aria-disabled': (s: S) => 'true' | undefined;
|
|
73
|
+
'data-scope': 'radio-group';
|
|
74
|
+
'data-part': 'root';
|
|
75
|
+
'data-orientation': (s: S) => Orientation;
|
|
76
|
+
'data-disabled': (s: S) => '' | undefined;
|
|
77
|
+
};
|
|
78
|
+
item: (value: string) => RadioItemParts<S>;
|
|
79
|
+
}
|
|
80
|
+
export interface ConnectOptions {
|
|
81
|
+
id: string;
|
|
82
|
+
}
|
|
83
|
+
export declare function connect<S>(get: (s: S) => RadioGroupState, send: Send<RadioGroupMsg>, opts: ConnectOptions): RadioGroupParts<S>;
|
|
84
|
+
export declare const radioGroup: {
|
|
85
|
+
init: typeof init;
|
|
86
|
+
update: typeof update;
|
|
87
|
+
connect: typeof connect;
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=radio-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio-group.d.ts","sourceRoot":"","sources":["../../src/components/radio-group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;;GAGG;AAEH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,UAAU,CAAA;AAEnD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,QAAQ,EAAE,OAAO,CAAA;IACjB,WAAW,EAAE,WAAW,CAAA;CACzB;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,Y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1
|
+
export function init(opts = {}) {
|
|
2
|
+
return {
|
|
3
|
+
value: opts.value ?? null,
|
|
4
|
+
items: opts.items ?? [],
|
|
5
|
+
disabledItems: opts.disabledItems ?? [],
|
|
6
|
+
disabled: opts.disabled ?? false,
|
|
7
|
+
orientation: opts.orientation ?? 'vertical',
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function nextEnabled(items, disabled, from, delta) {
|
|
11
|
+
if (items.length === 0)
|
|
12
|
+
return null;
|
|
13
|
+
const idx = items.indexOf(from);
|
|
14
|
+
if (idx === -1)
|
|
15
|
+
return null;
|
|
16
|
+
const n = items.length;
|
|
17
|
+
for (let i = 1; i <= n; i++) {
|
|
18
|
+
const next = items[(idx + delta * i + n * n) % n];
|
|
19
|
+
if (!disabled.includes(next))
|
|
20
|
+
return next;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
function firstEnabled(items, disabled) {
|
|
25
|
+
for (const v of items)
|
|
26
|
+
if (!disabled.includes(v))
|
|
27
|
+
return v;
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
function lastEnabled(items, disabled) {
|
|
31
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
32
|
+
const v = items[i];
|
|
33
|
+
if (!disabled.includes(v))
|
|
34
|
+
return v;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export function update(state, msg) {
|
|
39
|
+
if (state.disabled)
|
|
40
|
+
return [state, []];
|
|
41
|
+
switch (msg.type) {
|
|
42
|
+
case 'setValue':
|
|
43
|
+
if (state.disabledItems.includes(msg.value))
|
|
44
|
+
return [state, []];
|
|
45
|
+
return [{ ...state, value: msg.value }, []];
|
|
46
|
+
case 'setItems': {
|
|
47
|
+
const disabled = msg.disabled ?? state.disabledItems;
|
|
48
|
+
const value = state.value && msg.items.includes(state.value) && !disabled.includes(state.value)
|
|
49
|
+
? state.value
|
|
50
|
+
: null;
|
|
51
|
+
return [{ ...state, items: msg.items, disabledItems: disabled, value }, []];
|
|
52
|
+
}
|
|
53
|
+
case 'selectNext': {
|
|
54
|
+
const to = nextEnabled(state.items, state.disabledItems, msg.from, 1);
|
|
55
|
+
return to === null ? [state, []] : [{ ...state, value: to }, []];
|
|
56
|
+
}
|
|
57
|
+
case 'selectPrev': {
|
|
58
|
+
const to = nextEnabled(state.items, state.disabledItems, msg.from, -1);
|
|
59
|
+
return to === null ? [state, []] : [{ ...state, value: to }, []];
|
|
60
|
+
}
|
|
61
|
+
case 'selectFirst': {
|
|
62
|
+
const to = firstEnabled(state.items, state.disabledItems);
|
|
63
|
+
return to === null ? [state, []] : [{ ...state, value: to }, []];
|
|
64
|
+
}
|
|
65
|
+
case 'selectLast': {
|
|
66
|
+
const to = lastEnabled(state.items, state.disabledItems);
|
|
67
|
+
return to === null ? [state, []] : [{ ...state, value: to }, []];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function connect(get, send, opts) {
|
|
72
|
+
const itemId = (v) => `${opts.id}:item:${v}`;
|
|
73
|
+
return {
|
|
74
|
+
root: {
|
|
75
|
+
role: 'radiogroup',
|
|
76
|
+
'aria-orientation': (s) => get(s).orientation,
|
|
77
|
+
'aria-disabled': (s) => (get(s).disabled ? 'true' : undefined),
|
|
78
|
+
'data-scope': 'radio-group',
|
|
79
|
+
'data-part': 'root',
|
|
80
|
+
'data-orientation': (s) => get(s).orientation,
|
|
81
|
+
'data-disabled': (s) => (get(s).disabled ? '' : undefined),
|
|
82
|
+
},
|
|
83
|
+
item: (value) => ({
|
|
84
|
+
root: {
|
|
85
|
+
role: 'radio',
|
|
86
|
+
id: itemId(value),
|
|
87
|
+
'aria-checked': (s) => get(s).value === value,
|
|
88
|
+
'aria-disabled': (s) => get(s).disabledItems.includes(value) || get(s).disabled ? 'true' : undefined,
|
|
89
|
+
'data-state': (s) => (get(s).value === value ? 'checked' : 'unchecked'),
|
|
90
|
+
'data-disabled': (s) => get(s).disabledItems.includes(value) || get(s).disabled ? '' : undefined,
|
|
91
|
+
'data-scope': 'radio-group',
|
|
92
|
+
'data-part': 'item',
|
|
93
|
+
'data-value': value,
|
|
94
|
+
// Only currently-selected (or first if none selected) is tab-stop
|
|
95
|
+
tabIndex: (s) => {
|
|
96
|
+
const st = get(s);
|
|
97
|
+
if (st.disabled || st.disabledItems.includes(value))
|
|
98
|
+
return -1;
|
|
99
|
+
if (st.value === value)
|
|
100
|
+
return 0;
|
|
101
|
+
if (st.value === null) {
|
|
102
|
+
const first = firstEnabled(st.items, st.disabledItems);
|
|
103
|
+
return first === value ? 0 : -1;
|
|
104
|
+
}
|
|
105
|
+
return -1;
|
|
106
|
+
},
|
|
107
|
+
onClick: () => send({ type: 'setValue', value }),
|
|
108
|
+
onKeyDown: (e) => {
|
|
109
|
+
const isVertical = e.currentTarget?.closest('[data-orientation="vertical"]') !==
|
|
110
|
+
null;
|
|
111
|
+
switch (e.key) {
|
|
112
|
+
case 'ArrowDown':
|
|
113
|
+
if (isVertical) {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
send({ type: 'selectNext', from: value });
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
case 'ArrowUp':
|
|
119
|
+
if (isVertical) {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
send({ type: 'selectPrev', from: value });
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
case 'ArrowRight':
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
send({ type: 'selectNext', from: value });
|
|
127
|
+
return;
|
|
128
|
+
case 'ArrowLeft':
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
send({ type: 'selectPrev', from: value });
|
|
131
|
+
return;
|
|
132
|
+
case 'Home':
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
send({ type: 'selectFirst' });
|
|
135
|
+
return;
|
|
136
|
+
case 'End':
|
|
137
|
+
e.preventDefault();
|
|
138
|
+
send({ type: 'selectLast' });
|
|
139
|
+
return;
|
|
140
|
+
case ' ':
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
send({ type: 'setValue', value });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
label: {
|
|
148
|
+
'data-scope': 'radio-group',
|
|
149
|
+
'data-part': 'label',
|
|
150
|
+
'data-value': value,
|
|
151
|
+
for: itemId(value),
|
|
152
|
+
},
|
|
153
|
+
indicator: {
|
|
154
|
+
'data-state': (s) => (get(s).value === value ? 'checked' : 'unchecked'),
|
|
155
|
+
'data-scope': 'radio-group',
|
|
156
|
+
'data-part': 'indicator',
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export const radioGroup = { init, update, connect };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Send } from '@llui/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Rating group — a sequence of clickable items (stars) representing a
|
|
4
|
+
* discrete rating. Supports half-step ratings and keyboard navigation.
|
|
5
|
+
*/
|
|
6
|
+
export interface RatingGroupState {
|
|
7
|
+
value: number;
|
|
8
|
+
count: number;
|
|
9
|
+
/** If true, allows values like 1.5 (half-stars). */
|
|
10
|
+
allowHalf: boolean;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
readOnly: boolean;
|
|
13
|
+
hoveredValue: number | null;
|
|
14
|
+
}
|
|
15
|
+
export type RatingGroupMsg = {
|
|
16
|
+
type: 'setValue';
|
|
17
|
+
value: number;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'hover';
|
|
20
|
+
value: number | null;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'clickItem';
|
|
23
|
+
index: number;
|
|
24
|
+
isLeftHalf: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
type: 'hoverItem';
|
|
27
|
+
index: number;
|
|
28
|
+
isLeftHalf: boolean;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'incrementValue';
|
|
31
|
+
step?: number;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'decrementValue';
|
|
34
|
+
step?: number;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'toEnd';
|
|
37
|
+
};
|
|
38
|
+
export interface RatingGroupInit {
|
|
39
|
+
value?: number;
|
|
40
|
+
count?: number;
|
|
41
|
+
allowHalf?: boolean;
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
readOnly?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare function init(opts?: RatingGroupInit): RatingGroupState;
|
|
46
|
+
export declare function update(state: RatingGroupState, msg: RatingGroupMsg): [RatingGroupState, never[]];
|
|
47
|
+
export type ItemFill = 'full' | 'half' | 'empty';
|
|
48
|
+
export declare function itemFill(state: RatingGroupState, index: number): ItemFill;
|
|
49
|
+
export interface RatingItemParts<S> {
|
|
50
|
+
root: {
|
|
51
|
+
role: 'radio';
|
|
52
|
+
'aria-checked': (s: S) => boolean;
|
|
53
|
+
'data-fill': (s: S) => ItemFill;
|
|
54
|
+
'data-scope': 'rating-group';
|
|
55
|
+
'data-part': 'item';
|
|
56
|
+
'data-value': string;
|
|
57
|
+
'data-disabled': (s: S) => '' | undefined;
|
|
58
|
+
tabIndex: (s: S) => number;
|
|
59
|
+
onClick: (e: MouseEvent) => void;
|
|
60
|
+
onPointerMove: (e: PointerEvent) => void;
|
|
61
|
+
onPointerLeave: (e: PointerEvent) => void;
|
|
62
|
+
onKeyDown: (e: KeyboardEvent) => void;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface RatingGroupParts<S> {
|
|
66
|
+
root: {
|
|
67
|
+
role: 'radiogroup';
|
|
68
|
+
'aria-label': string | undefined;
|
|
69
|
+
'aria-disabled': (s: S) => 'true' | undefined;
|
|
70
|
+
'aria-readonly': (s: S) => 'true' | undefined;
|
|
71
|
+
'data-scope': 'rating-group';
|
|
72
|
+
'data-part': 'root';
|
|
73
|
+
'data-disabled': (s: S) => '' | undefined;
|
|
74
|
+
'data-readonly': (s: S) => '' | undefined;
|
|
75
|
+
};
|
|
76
|
+
item: (index: number) => RatingItemParts<S>;
|
|
77
|
+
}
|
|
78
|
+
export interface ConnectOptions {
|
|
79
|
+
label?: string;
|
|
80
|
+
}
|
|
81
|
+
export declare function connect<S>(get: (s: S) => RatingGroupState, send: Send<RatingGroupMsg>, opts?: ConnectOptions): RatingGroupParts<S>;
|
|
82
|
+
export declare const ratingGroup: {
|
|
83
|
+
init: typeof init;
|
|
84
|
+
update: typeof update;
|
|
85
|
+
connect: typeof connect;
|
|
86
|
+
itemFill: typeof itemFill;
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=rating-group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rating-group.d.ts","sourceRoot":"","sources":["../../src/components/rating-group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;;GAGG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,oDAAoD;IACpD,SAAS,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,gBAAgB,CA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