numori-ui 0.4.0 → 0.6.0
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/CHANGELOG.md +120 -0
- package/README.md +27 -20
- package/dist/components/AppShell.js +234 -0
- package/dist/components/AppShell.js.map +1 -0
- package/dist/components/Avatar.js +71 -19
- package/dist/components/Avatar.js.map +1 -1
- package/dist/components/Checkbox.js +11 -2
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/CopyField.js +195 -0
- package/dist/components/CopyField.js.map +1 -0
- package/dist/components/DescriptionList.js +116 -0
- package/dist/components/DescriptionList.js.map +1 -0
- package/dist/components/Dropdown.js +3 -1
- package/dist/components/Dropdown.js.map +1 -1
- package/dist/components/EmptyState.js +123 -0
- package/dist/components/EmptyState.js.map +1 -0
- package/dist/components/FormField.js +43 -13
- package/dist/components/FormField.js.map +1 -1
- package/dist/components/Input.js +15 -1
- package/dist/components/Input.js.map +1 -1
- package/dist/components/Modal.js +61 -4
- package/dist/components/Modal.js.map +1 -1
- package/dist/components/PageHeader.js +106 -0
- package/dist/components/PageHeader.js.map +1 -0
- package/dist/components/Pagination.js +236 -0
- package/dist/components/Pagination.js.map +1 -0
- package/dist/components/Prompt.js +11 -6
- package/dist/components/Prompt.js.map +1 -1
- package/dist/components/Segmented.js +10 -2
- package/dist/components/Segmented.js.map +1 -1
- package/dist/components/Select.js +11 -2
- package/dist/components/Select.js.map +1 -1
- package/dist/components/Sidebar.js +69 -0
- package/dist/components/Sidebar.js.map +1 -0
- package/dist/components/SidebarGroup.js +50 -0
- package/dist/components/SidebarGroup.js.map +1 -0
- package/dist/components/SidebarItem.js +167 -0
- package/dist/components/SidebarItem.js.map +1 -0
- package/dist/components/Skeleton.js +122 -0
- package/dist/components/Skeleton.js.map +1 -0
- package/dist/components/SplitPane.js +264 -0
- package/dist/components/SplitPane.js.map +1 -0
- package/dist/components/StatCard.js +185 -0
- package/dist/components/StatCard.js.map +1 -0
- package/dist/components/Table.js +182 -50
- package/dist/components/Table.js.map +1 -1
- package/dist/components/Tabs.js +216 -0
- package/dist/components/Tabs.js.map +1 -0
- package/dist/components/Toggle.js +11 -2
- package/dist/components/Toggle.js.map +1 -1
- package/dist/components/Tree.js +417 -0
- package/dist/components/Tree.js.map +1 -0
- package/dist/components/VirtualList.js +292 -0
- package/dist/components/VirtualList.js.map +1 -0
- package/dist/components/index.js +105 -81
- package/dist/components/index.js.map +1 -1
- package/dist/icons/mdi.js +12 -0
- package/dist/icons/mdi.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +54 -39
- package/dist/index.js.map +1 -1
- package/dist/internal/focusTrap.js +163 -0
- package/dist/internal/focusTrap.js.map +1 -0
- package/dist/internal/formField.js +26 -0
- package/dist/internal/formField.js.map +1 -0
- package/dist/manifest.js +16 -1
- package/dist/manifest.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AppShell.vue +231 -0
- package/src/components/Avatar.vue +69 -18
- package/src/components/Checkbox.vue +5 -0
- package/src/components/CopyField.vue +178 -0
- package/src/components/DescriptionList.vue +114 -0
- package/src/components/Dropdown.vue +4 -1
- package/src/components/EmptyState.vue +107 -0
- package/src/components/FormField.vue +37 -4
- package/src/components/Input.vue +9 -0
- package/src/components/Modal.vue +51 -3
- package/src/components/PageHeader.vue +102 -0
- package/src/components/Pagination.vue +199 -0
- package/src/components/Prompt.vue +14 -3
- package/src/components/Segmented.vue +5 -0
- package/src/components/Select.vue +6 -1
- package/src/components/Sidebar.vue +61 -0
- package/src/components/SidebarGroup.vue +43 -0
- package/src/components/SidebarItem.vue +159 -0
- package/src/components/Skeleton.vue +91 -0
- package/src/components/SplitPane.vue +264 -0
- package/src/components/StatCard.vue +165 -0
- package/src/components/Table.vue +148 -18
- package/src/components/Tabs.vue +217 -0
- package/src/components/Toggle.vue +5 -0
- package/src/components/Tree.vue +428 -0
- package/src/components/VirtualList.vue +250 -0
- package/src/components/index.js +45 -6
- package/src/icons/mdi.js +12 -0
- package/src/internal/focusTrap.js +185 -0
- package/src/internal/formField.js +23 -0
- package/src/manifest.js +15 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { computed, createElementBlock, createElementVNode, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, renderSlot, useId } from "vue";
|
|
2
|
+
//#region src/components/SplitPane.vue
|
|
3
|
+
var _hoisted_1 = [
|
|
4
|
+
"aria-label",
|
|
5
|
+
"aria-orientation",
|
|
6
|
+
"aria-valuenow",
|
|
7
|
+
"aria-valuemin",
|
|
8
|
+
"aria-valuemax",
|
|
9
|
+
"data-dragging"
|
|
10
|
+
];
|
|
11
|
+
var _hoisted_2 = { class: "relative min-h-0 min-w-0 flex-1 overflow-hidden" };
|
|
12
|
+
var _sfc_main = {
|
|
13
|
+
__name: "SplitPane",
|
|
14
|
+
props: {
|
|
15
|
+
/**
|
|
16
|
+
* Size of the start pane in pixels, for `v-model`. Leave unset to let the
|
|
17
|
+
* component manage it from `defaultSize`.
|
|
18
|
+
* @type {number}
|
|
19
|
+
* @default undefined
|
|
20
|
+
*/
|
|
21
|
+
modelValue: {
|
|
22
|
+
type: Number,
|
|
23
|
+
default: void 0
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* Initial size in pixels when uncontrolled, and the size double-click resets to.
|
|
27
|
+
* @type {number}
|
|
28
|
+
* @default 320
|
|
29
|
+
*/
|
|
30
|
+
defaultSize: {
|
|
31
|
+
type: Number,
|
|
32
|
+
default: 320
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Smallest start pane size in pixels.
|
|
36
|
+
* @type {number}
|
|
37
|
+
* @default 160
|
|
38
|
+
*/
|
|
39
|
+
min: {
|
|
40
|
+
type: Number,
|
|
41
|
+
default: 160
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Largest start pane size in pixels. The pane is also never allowed to push
|
|
45
|
+
* the end pane below `endMin`.
|
|
46
|
+
* @type {number}
|
|
47
|
+
* @default 800
|
|
48
|
+
*/
|
|
49
|
+
max: {
|
|
50
|
+
type: Number,
|
|
51
|
+
default: 800
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* Smallest size the end pane may be squeezed to, in pixels.
|
|
55
|
+
* @type {number}
|
|
56
|
+
* @default 240
|
|
57
|
+
*/
|
|
58
|
+
endMin: {
|
|
59
|
+
type: Number,
|
|
60
|
+
default: 240
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Layout direction. `horizontal` puts the panes side by side.
|
|
64
|
+
* @type {string}
|
|
65
|
+
* @default 'horizontal'
|
|
66
|
+
* @values 'horizontal' | 'vertical'
|
|
67
|
+
*/
|
|
68
|
+
direction: {
|
|
69
|
+
type: String,
|
|
70
|
+
default: "horizontal"
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Arrow-key step in pixels. Shift multiplies it by five.
|
|
74
|
+
* @type {number}
|
|
75
|
+
* @default 16
|
|
76
|
+
*/
|
|
77
|
+
step: {
|
|
78
|
+
type: Number,
|
|
79
|
+
default: 16
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Accessible name for the splitter.
|
|
83
|
+
* @type {string}
|
|
84
|
+
* @default 'Resize panes'
|
|
85
|
+
*/
|
|
86
|
+
label: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: "Resize panes"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
emits: ["update:modelValue", "resize-end"],
|
|
92
|
+
setup(__props, { emit: __emit }) {
|
|
93
|
+
/**
|
|
94
|
+
* UiSplitPane — two panes divided by a draggable, keyboard-operable splitter.
|
|
95
|
+
*
|
|
96
|
+
* The `start` pane has an explicit size in pixels; the `end` pane takes the
|
|
97
|
+
* rest. Drag the splitter with a mouse, finger or pen, or focus it and use the
|
|
98
|
+
* arrow keys (Shift for bigger steps), Home and End for the limits, and Enter
|
|
99
|
+
* to toggle between the current size and `min`. Double-click resets to
|
|
100
|
+
* `defaultSize`.
|
|
101
|
+
*
|
|
102
|
+
* Follows the WAI-ARIA window splitter pattern: the splitter is a focusable
|
|
103
|
+
* `role="separator"` whose `aria-valuenow` is the start pane's size and whose
|
|
104
|
+
* `aria-controls` points at it, so assistive technology can report and change
|
|
105
|
+
* the split.
|
|
106
|
+
*
|
|
107
|
+
* Bind `v-model` to persist the size (for example to local storage); leave it
|
|
108
|
+
* unbound and the component keeps its own state. `update:modelValue` fires on
|
|
109
|
+
* every change while dragging, and `resize-end` once when a drag or key press
|
|
110
|
+
* finishes — persist on the latter to avoid a write per pixel.
|
|
111
|
+
*
|
|
112
|
+
* The component fills its parent (`h-full w-full`), so give the parent a
|
|
113
|
+
* size. Panes can nest: put a second `UiSplitPane` in `#end` for three columns.
|
|
114
|
+
*
|
|
115
|
+
* @example Message list beside a reader
|
|
116
|
+
* <UiSplitPane v-model="listWidth" :min="280" :max="640" label="Resize message list">
|
|
117
|
+
* <template #start><MessageList /></template>
|
|
118
|
+
* <template #end><MessageReader /></template>
|
|
119
|
+
* </UiSplitPane>
|
|
120
|
+
*
|
|
121
|
+
* @example Stacked
|
|
122
|
+
* <UiSplitPane direction="vertical" :default-size="240" label="Resize preview">
|
|
123
|
+
* <template #start>Top</template>
|
|
124
|
+
* <template #end>Bottom</template>
|
|
125
|
+
* </UiSplitPane>
|
|
126
|
+
*
|
|
127
|
+
* @emits {number} update:modelValue — The start pane's new size, in pixels.
|
|
128
|
+
* @emits {number} resize-end — A drag or keyboard adjustment finished, with the final size.
|
|
129
|
+
*
|
|
130
|
+
* @slot start — The sized pane. Scope: `{ size }`.
|
|
131
|
+
* @slot end — The flexible pane.
|
|
132
|
+
*/
|
|
133
|
+
const props = __props;
|
|
134
|
+
const emit = __emit;
|
|
135
|
+
const startId = `${useId()}-start`;
|
|
136
|
+
const rootRef = ref(null);
|
|
137
|
+
const isHorizontal = computed(() => props.direction !== "vertical");
|
|
138
|
+
const internalSize = ref(props.defaultSize);
|
|
139
|
+
const currentSize = computed(() => props.modelValue ?? internalSize.value);
|
|
140
|
+
const extent = ref(0);
|
|
141
|
+
const effectiveMax = computed(() => {
|
|
142
|
+
if (!extent.value) return props.max;
|
|
143
|
+
return Math.max(props.min, Math.min(props.max, extent.value - props.endMin));
|
|
144
|
+
});
|
|
145
|
+
const clamp = (value) => Math.round(Math.min(effectiveMax.value, Math.max(props.min, value)));
|
|
146
|
+
const startStyle = computed(() => {
|
|
147
|
+
const size = `${clamp(currentSize.value)}px`;
|
|
148
|
+
return isHorizontal.value ? { width: size } : { height: size };
|
|
149
|
+
});
|
|
150
|
+
function setSize(value) {
|
|
151
|
+
const next = clamp(value);
|
|
152
|
+
if (next === currentSize.value) return;
|
|
153
|
+
internalSize.value = next;
|
|
154
|
+
emit("update:modelValue", next);
|
|
155
|
+
}
|
|
156
|
+
const finish = () => emit("resize-end", clamp(currentSize.value));
|
|
157
|
+
const dragging = ref(false);
|
|
158
|
+
let dragOrigin = 0;
|
|
159
|
+
let sizeOrigin = 0;
|
|
160
|
+
function onPointerDown(event) {
|
|
161
|
+
if (event.button !== 0) return;
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
164
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
165
|
+
dragging.value = true;
|
|
166
|
+
dragOrigin = isHorizontal.value ? event.clientX : event.clientY;
|
|
167
|
+
sizeOrigin = clamp(currentSize.value);
|
|
168
|
+
event.currentTarget.addEventListener("pointermove", onPointerMove);
|
|
169
|
+
event.currentTarget.addEventListener("pointerup", onPointerUp, { once: true });
|
|
170
|
+
event.currentTarget.addEventListener("pointercancel", onPointerUp, { once: true });
|
|
171
|
+
}
|
|
172
|
+
function onPointerMove(event) {
|
|
173
|
+
if (!dragging.value) return;
|
|
174
|
+
const position = isHorizontal.value ? event.clientX : event.clientY;
|
|
175
|
+
setSize(sizeOrigin + position - dragOrigin);
|
|
176
|
+
}
|
|
177
|
+
function onPointerUp(event) {
|
|
178
|
+
event.currentTarget.removeEventListener("pointermove", onPointerMove);
|
|
179
|
+
event.currentTarget.removeEventListener("pointerup", onPointerUp);
|
|
180
|
+
event.currentTarget.removeEventListener("pointercancel", onPointerUp);
|
|
181
|
+
if (!dragging.value) return;
|
|
182
|
+
dragging.value = false;
|
|
183
|
+
finish();
|
|
184
|
+
}
|
|
185
|
+
let sizeBeforeCollapse = null;
|
|
186
|
+
function onKeydown(event) {
|
|
187
|
+
const decrease = isHorizontal.value ? "ArrowLeft" : "ArrowUp";
|
|
188
|
+
const increase = isHorizontal.value ? "ArrowRight" : "ArrowDown";
|
|
189
|
+
const amount = event.shiftKey ? props.step * 5 : props.step;
|
|
190
|
+
const now = clamp(currentSize.value);
|
|
191
|
+
let next = null;
|
|
192
|
+
if (event.key === decrease) next = now - amount;
|
|
193
|
+
else if (event.key === increase) next = now + amount;
|
|
194
|
+
else if (event.key === "Home") next = props.min;
|
|
195
|
+
else if (event.key === "End") next = effectiveMax.value;
|
|
196
|
+
else if (event.key === "Enter") {
|
|
197
|
+
if (now > props.min) {
|
|
198
|
+
sizeBeforeCollapse = now;
|
|
199
|
+
next = props.min;
|
|
200
|
+
} else next = sizeBeforeCollapse ?? props.defaultSize;
|
|
201
|
+
}
|
|
202
|
+
if (next === null) return;
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
setSize(next);
|
|
205
|
+
finish();
|
|
206
|
+
}
|
|
207
|
+
function reset() {
|
|
208
|
+
setSize(props.defaultSize);
|
|
209
|
+
finish();
|
|
210
|
+
}
|
|
211
|
+
let observer = null;
|
|
212
|
+
onMounted(() => {
|
|
213
|
+
const measure = () => {
|
|
214
|
+
const rect = rootRef.value?.getBoundingClientRect();
|
|
215
|
+
if (rect) extent.value = isHorizontal.value ? rect.width : rect.height;
|
|
216
|
+
};
|
|
217
|
+
measure();
|
|
218
|
+
if (typeof ResizeObserver !== "undefined" && rootRef.value) {
|
|
219
|
+
observer = new ResizeObserver(measure);
|
|
220
|
+
observer.observe(rootRef.value);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
onBeforeUnmount(() => observer?.disconnect());
|
|
224
|
+
return (_ctx, _cache) => {
|
|
225
|
+
return openBlock(), createElementBlock("div", {
|
|
226
|
+
ref_key: "rootRef",
|
|
227
|
+
ref: rootRef,
|
|
228
|
+
class: normalizeClass(["flex h-full w-full min-h-0 min-w-0", [isHorizontal.value ? "flex-row" : "flex-col", dragging.value ? "select-none" : ""]])
|
|
229
|
+
}, [
|
|
230
|
+
createElementVNode("div", {
|
|
231
|
+
id: startId,
|
|
232
|
+
class: "relative min-h-0 min-w-0 shrink-0 overflow-hidden",
|
|
233
|
+
style: normalizeStyle(startStyle.value)
|
|
234
|
+
}, [renderSlot(_ctx.$slots, "start", { size: currentSize.value })], 4),
|
|
235
|
+
createElementVNode("div", {
|
|
236
|
+
role: "separator",
|
|
237
|
+
tabindex: "0",
|
|
238
|
+
"aria-label": __props.label,
|
|
239
|
+
"aria-controls": startId,
|
|
240
|
+
"aria-orientation": isHorizontal.value ? "vertical" : "horizontal",
|
|
241
|
+
"aria-valuenow": Math.round(currentSize.value),
|
|
242
|
+
"aria-valuemin": __props.min,
|
|
243
|
+
"aria-valuemax": effectiveMax.value,
|
|
244
|
+
"data-dragging": dragging.value ? "true" : void 0,
|
|
245
|
+
class: normalizeClass(["group relative z-10 shrink-0 touch-none focus-visible:outline-none", isHorizontal.value ? "w-px cursor-col-resize" : "h-px cursor-row-resize"]),
|
|
246
|
+
onPointerdown: onPointerDown,
|
|
247
|
+
onKeydown,
|
|
248
|
+
onDblclick: reset
|
|
249
|
+
}, [createElementVNode("span", {
|
|
250
|
+
"aria-hidden": "true",
|
|
251
|
+
class: normalizeClass(["absolute bg-gray-200 transition-colors group-hover:bg-primary-400 group-focus-visible:bg-primary-500 group-data-[dragging=true]:bg-primary-500 dark:bg-gray-800 dark:group-hover:bg-primary-500", isHorizontal.value ? "inset-y-0 left-0 w-px group-focus-visible:-left-px group-focus-visible:w-[3px]" : "inset-x-0 top-0 h-px group-focus-visible:-top-px group-focus-visible:h-[3px]"])
|
|
252
|
+
}, null, 2), createElementVNode("span", {
|
|
253
|
+
"aria-hidden": "true",
|
|
254
|
+
class: normalizeClass(["absolute", isHorizontal.value ? "inset-y-0 -left-1.5 w-3" : "inset-x-0 -top-1.5 h-3"])
|
|
255
|
+
}, null, 2)], 42, _hoisted_1),
|
|
256
|
+
createElementVNode("div", _hoisted_2, [renderSlot(_ctx.$slots, "end")])
|
|
257
|
+
], 2);
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
//#endregion
|
|
262
|
+
export { _sfc_main as default };
|
|
263
|
+
|
|
264
|
+
//# sourceMappingURL=SplitPane.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SplitPane.js","names":[],"sources":["../../src/components/SplitPane.vue"],"sourcesContent":["<template>\n <div\n ref=\"rootRef\"\n class=\"flex h-full w-full min-h-0 min-w-0\"\n :class=\"[isHorizontal ? 'flex-row' : 'flex-col', dragging ? 'select-none' : '']\"\n >\n <div\n :id=\"startId\"\n class=\"relative min-h-0 min-w-0 shrink-0 overflow-hidden\"\n :style=\"startStyle\"\n >\n <slot name=\"start\" :size=\"currentSize\" />\n </div>\n\n <!-- The splitter: the WAI-ARIA \"window splitter\" pattern. A 1px rule with\n a wider invisible hit area, focusable and operable from the keyboard. -->\n <div\n role=\"separator\"\n tabindex=\"0\"\n :aria-label=\"label\"\n :aria-controls=\"startId\"\n :aria-orientation=\"isHorizontal ? 'vertical' : 'horizontal'\"\n :aria-valuenow=\"Math.round(currentSize)\"\n :aria-valuemin=\"min\"\n :aria-valuemax=\"effectiveMax\"\n :data-dragging=\"dragging ? 'true' : undefined\"\n class=\"group relative z-10 shrink-0 touch-none focus-visible:outline-none\"\n :class=\"isHorizontal ? 'w-px cursor-col-resize' : 'h-px cursor-row-resize'\"\n @pointerdown=\"onPointerDown\"\n @keydown=\"onKeydown\"\n @dblclick=\"reset\"\n >\n <span\n aria-hidden=\"true\"\n class=\"absolute bg-gray-200 transition-colors group-hover:bg-primary-400 group-focus-visible:bg-primary-500 group-data-[dragging=true]:bg-primary-500 dark:bg-gray-800 dark:group-hover:bg-primary-500\"\n :class=\"\n isHorizontal\n ? 'inset-y-0 left-0 w-px group-focus-visible:-left-px group-focus-visible:w-[3px]'\n : 'inset-x-0 top-0 h-px group-focus-visible:-top-px group-focus-visible:h-[3px]'\n \"\n />\n <span\n aria-hidden=\"true\"\n class=\"absolute\"\n :class=\"isHorizontal ? 'inset-y-0 -left-1.5 w-3' : 'inset-x-0 -top-1.5 h-3'\"\n />\n </div>\n\n <div class=\"relative min-h-0 min-w-0 flex-1 overflow-hidden\">\n <slot name=\"end\" />\n </div>\n </div>\n</template>\n\n<script setup>\n/**\n * UiSplitPane — two panes divided by a draggable, keyboard-operable splitter.\n *\n * The `start` pane has an explicit size in pixels; the `end` pane takes the\n * rest. Drag the splitter with a mouse, finger or pen, or focus it and use the\n * arrow keys (Shift for bigger steps), Home and End for the limits, and Enter\n * to toggle between the current size and `min`. Double-click resets to\n * `defaultSize`.\n *\n * Follows the WAI-ARIA window splitter pattern: the splitter is a focusable\n * `role=\"separator\"` whose `aria-valuenow` is the start pane's size and whose\n * `aria-controls` points at it, so assistive technology can report and change\n * the split.\n *\n * Bind `v-model` to persist the size (for example to local storage); leave it\n * unbound and the component keeps its own state. `update:modelValue` fires on\n * every change while dragging, and `resize-end` once when a drag or key press\n * finishes — persist on the latter to avoid a write per pixel.\n *\n * The component fills its parent (`h-full w-full`), so give the parent a\n * size. Panes can nest: put a second `UiSplitPane` in `#end` for three columns.\n *\n * @example Message list beside a reader\n * <UiSplitPane v-model=\"listWidth\" :min=\"280\" :max=\"640\" label=\"Resize message list\">\n * <template #start><MessageList /></template>\n * <template #end><MessageReader /></template>\n * </UiSplitPane>\n *\n * @example Stacked\n * <UiSplitPane direction=\"vertical\" :default-size=\"240\" label=\"Resize preview\">\n * <template #start>Top</template>\n * <template #end>Bottom</template>\n * </UiSplitPane>\n *\n * @emits {number} update:modelValue — The start pane's new size, in pixels.\n * @emits {number} resize-end — A drag or keyboard adjustment finished, with the final size.\n *\n * @slot start — The sized pane. Scope: `{ size }`.\n * @slot end — The flexible pane.\n */\nimport { computed, onBeforeUnmount, onMounted, ref, useId } from 'vue'\n\nconst props = defineProps({\n /**\n * Size of the start pane in pixels, for `v-model`. Leave unset to let the\n * component manage it from `defaultSize`.\n * @type {number}\n * @default undefined\n */\n modelValue: { type: Number, default: undefined },\n /**\n * Initial size in pixels when uncontrolled, and the size double-click resets to.\n * @type {number}\n * @default 320\n */\n defaultSize: { type: Number, default: 320 },\n /**\n * Smallest start pane size in pixels.\n * @type {number}\n * @default 160\n */\n min: { type: Number, default: 160 },\n /**\n * Largest start pane size in pixels. The pane is also never allowed to push\n * the end pane below `endMin`.\n * @type {number}\n * @default 800\n */\n max: { type: Number, default: 800 },\n /**\n * Smallest size the end pane may be squeezed to, in pixels.\n * @type {number}\n * @default 240\n */\n endMin: { type: Number, default: 240 },\n /**\n * Layout direction. `horizontal` puts the panes side by side.\n * @type {string}\n * @default 'horizontal'\n * @values 'horizontal' | 'vertical'\n */\n direction: { type: String, default: 'horizontal' },\n /**\n * Arrow-key step in pixels. Shift multiplies it by five.\n * @type {number}\n * @default 16\n */\n step: { type: Number, default: 16 },\n /**\n * Accessible name for the splitter.\n * @type {string}\n * @default 'Resize panes'\n */\n label: { type: String, default: 'Resize panes' },\n})\n\nconst emit = defineEmits(['update:modelValue', 'resize-end'])\n\nconst startId = `${useId()}-start`\nconst rootRef = ref(null)\nconst isHorizontal = computed(() => props.direction !== 'vertical')\n\n// ── Size state (controlled or uncontrolled) ──\nconst internalSize = ref(props.defaultSize)\nconst currentSize = computed(() => props.modelValue ?? internalSize.value)\n\n// The container's extent along the split axis, so `max` can respect `endMin`.\nconst extent = ref(0)\nconst effectiveMax = computed(() => {\n if (!extent.value) return props.max\n return Math.max(props.min, Math.min(props.max, extent.value - props.endMin))\n})\n\nconst clamp = (value) => Math.round(Math.min(effectiveMax.value, Math.max(props.min, value)))\n\nconst startStyle = computed(() => {\n const size = `${clamp(currentSize.value)}px`\n return isHorizontal.value ? { width: size } : { height: size }\n})\n\nfunction setSize(value) {\n const next = clamp(value)\n if (next === currentSize.value) return\n internalSize.value = next\n emit('update:modelValue', next)\n}\n\nconst finish = () => emit('resize-end', clamp(currentSize.value))\n\n// ── Pointer dragging ──\nconst dragging = ref(false)\nlet dragOrigin = 0\nlet sizeOrigin = 0\n\nfunction onPointerDown(event) {\n if (event.button !== 0) return\n event.preventDefault()\n event.currentTarget.setPointerCapture?.(event.pointerId)\n event.currentTarget.focus({ preventScroll: true })\n dragging.value = true\n dragOrigin = isHorizontal.value ? event.clientX : event.clientY\n sizeOrigin = clamp(currentSize.value)\n event.currentTarget.addEventListener('pointermove', onPointerMove)\n event.currentTarget.addEventListener('pointerup', onPointerUp, { once: true })\n event.currentTarget.addEventListener('pointercancel', onPointerUp, { once: true })\n}\n\nfunction onPointerMove(event) {\n if (!dragging.value) return\n const position = isHorizontal.value ? event.clientX : event.clientY\n setSize(sizeOrigin + position - dragOrigin)\n}\n\nfunction onPointerUp(event) {\n event.currentTarget.removeEventListener('pointermove', onPointerMove)\n event.currentTarget.removeEventListener('pointerup', onPointerUp)\n event.currentTarget.removeEventListener('pointercancel', onPointerUp)\n if (!dragging.value) return\n dragging.value = false\n finish()\n}\n\n// ── Keyboard ──\nlet sizeBeforeCollapse = null\n\nfunction onKeydown(event) {\n const decrease = isHorizontal.value ? 'ArrowLeft' : 'ArrowUp'\n const increase = isHorizontal.value ? 'ArrowRight' : 'ArrowDown'\n const amount = event.shiftKey ? props.step * 5 : props.step\n const now = clamp(currentSize.value)\n let next = null\n if (event.key === decrease) next = now - amount\n else if (event.key === increase) next = now + amount\n else if (event.key === 'Home') next = props.min\n else if (event.key === 'End') next = effectiveMax.value\n else if (event.key === 'Enter') {\n if (now > props.min) {\n sizeBeforeCollapse = now\n next = props.min\n } else {\n next = sizeBeforeCollapse ?? props.defaultSize\n }\n }\n if (next === null) return\n event.preventDefault()\n setSize(next)\n finish()\n}\n\nfunction reset() {\n setSize(props.defaultSize)\n finish()\n}\n\n// ── Track the container size ──\nlet observer = null\nonMounted(() => {\n const measure = () => {\n const rect = rootRef.value?.getBoundingClientRect()\n if (rect) extent.value = isHorizontal.value ? rect.width : rect.height\n }\n measure()\n if (typeof ResizeObserver !== 'undefined' && rootRef.value) {\n observer = new ResizeObserver(measure)\n observer.observe(rootRef.value)\n }\n})\nonBeforeUnmount(() => observer?.disconnect())\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiGA,MAAM,QAAQ;EAsDd,MAAM,OAAO;EAEb,MAAM,UAAU,GAAG,MAAM,EAAE;EAC3B,MAAM,UAAU,IAAI,IAAI;EACxB,MAAM,eAAe,eAAe,MAAM,cAAc,UAAU;EAGlE,MAAM,eAAe,IAAI,MAAM,WAAW;EAC1C,MAAM,cAAc,eAAe,MAAM,cAAc,aAAa,KAAK;EAGzE,MAAM,SAAS,IAAI,CAAC;EACpB,MAAM,eAAe,eAAe;GAClC,IAAI,CAAC,OAAO,OAAO,OAAO,MAAM;GAChC,OAAO,KAAK,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,OAAO,QAAQ,MAAM,MAAM,CAAC;EAC7E,CAAC;EAED,MAAM,SAAS,UAAU,KAAK,MAAM,KAAK,IAAI,aAAa,OAAO,KAAK,IAAI,MAAM,KAAK,KAAK,CAAC,CAAC;EAE5F,MAAM,aAAa,eAAe;GAChC,MAAM,OAAO,GAAG,MAAM,YAAY,KAAK,EAAE;GACzC,OAAO,aAAa,QAAQ,EAAE,OAAO,KAAK,IAAI,EAAE,QAAQ,KAAK;EAC/D,CAAC;EAED,SAAS,QAAQ,OAAO;GACtB,MA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,KAAK,MAAM,YAAA,KAAW;KACrC,iBAAe,QAAA;KACf,iBAAe,aAAA;KACf,iBAAe,SAAA,QAAQ,SAAY,KAAA;KACpC,OAAK,eAAA,CAAC,sEACE,aAAA,QAAY,2BAAA,wBAAA,CAAA;KACnB,eAAa;KACJ;KACT,YAAU;IAEX,GAAA,CAAA,mBAQE,QAAA;KAPA,eAAY;KACZ,OAAK,eAAA,CAAC,mMACa,aAAA,QAAA,mFAAA,8EAAA,CAAA;IAMrB,GAAA,MAAA,CAAA,GAAA,mBAIE,QAAA;KAHA,eAAY;KACZ,OAAK,eAAA,CAAC,YACE,aAAA,QAAY,4BAAA,wBAAA,CAAA;;IAIxB,mBAEM,OAFN,YAEM,CADJ,WAAmB,KAAA,QAAA,KAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import _sfc_main$1 from "../icons/Icon.js";
|
|
2
|
+
import _sfc_main$2 from "./Card.js";
|
|
3
|
+
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, normalizeClass, openBlock, renderSlot, toDisplayString, withCtx } from "vue";
|
|
4
|
+
//#region src/components/StatCard.vue
|
|
5
|
+
var _hoisted_1 = { class: "flex items-start justify-between gap-3" };
|
|
6
|
+
var _hoisted_2 = { class: "min-w-0" };
|
|
7
|
+
var _hoisted_3 = { class: "truncate text-sm font-medium text-gray-500 dark:text-gray-400" };
|
|
8
|
+
var _hoisted_4 = { class: "mt-1 text-2xl font-semibold tracking-tight text-gray-900 tabular-nums dark:text-gray-50" };
|
|
9
|
+
var _hoisted_5 = {
|
|
10
|
+
key: 0,
|
|
11
|
+
class: "inline-block h-7 w-16 animate-pulse rounded-md bg-gray-200 align-middle motion-reduce:animate-none dark:bg-gray-800",
|
|
12
|
+
"aria-hidden": "true"
|
|
13
|
+
};
|
|
14
|
+
var _hoisted_6 = {
|
|
15
|
+
key: 0,
|
|
16
|
+
class: "mt-3 flex flex-wrap items-center gap-2 text-xs"
|
|
17
|
+
};
|
|
18
|
+
var _hoisted_7 = {
|
|
19
|
+
key: 1,
|
|
20
|
+
class: "text-gray-500 dark:text-gray-400"
|
|
21
|
+
};
|
|
22
|
+
var _sfc_main = {
|
|
23
|
+
__name: "StatCard",
|
|
24
|
+
props: {
|
|
25
|
+
/**
|
|
26
|
+
* What the number measures.
|
|
27
|
+
* @type {string}
|
|
28
|
+
* @default ''
|
|
29
|
+
*/
|
|
30
|
+
label: {
|
|
31
|
+
type: String,
|
|
32
|
+
default: ""
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* The number (or pre-formatted string).
|
|
36
|
+
* @type {string | number}
|
|
37
|
+
* @default ''
|
|
38
|
+
*/
|
|
39
|
+
value: {
|
|
40
|
+
type: [String, Number],
|
|
41
|
+
default: ""
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Secondary line, such as a time window or a unit.
|
|
45
|
+
* @type {string}
|
|
46
|
+
* @default ''
|
|
47
|
+
*/
|
|
48
|
+
hint: {
|
|
49
|
+
type: String,
|
|
50
|
+
default: ""
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* MDI icon in a tinted tile.
|
|
54
|
+
* @type {string}
|
|
55
|
+
* @default ''
|
|
56
|
+
*/
|
|
57
|
+
icon: {
|
|
58
|
+
type: String,
|
|
59
|
+
default: ""
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Icon tile tint.
|
|
63
|
+
* @type {string}
|
|
64
|
+
* @default 'primary'
|
|
65
|
+
* @values 'primary' | 'success' | 'warning' | 'error' | 'gray'
|
|
66
|
+
*/
|
|
67
|
+
color: {
|
|
68
|
+
type: String,
|
|
69
|
+
default: "primary"
|
|
70
|
+
},
|
|
71
|
+
/**
|
|
72
|
+
* Change to show next to the hint, e.g. `'+12%'`. Empty hides it.
|
|
73
|
+
* @type {string}
|
|
74
|
+
* @default ''
|
|
75
|
+
*/
|
|
76
|
+
delta: {
|
|
77
|
+
type: String,
|
|
78
|
+
default: ""
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Direction of the change, which picks the arrow.
|
|
82
|
+
* @type {string}
|
|
83
|
+
* @default 'flat'
|
|
84
|
+
* @values 'up' | 'down' | 'flat'
|
|
85
|
+
*/
|
|
86
|
+
trend: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: "flat"
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Delta colour. `'auto'` makes up green and down red.
|
|
92
|
+
* @type {string}
|
|
93
|
+
* @default 'auto'
|
|
94
|
+
* @values 'auto' | 'green' | 'red' | 'gray'
|
|
95
|
+
*/
|
|
96
|
+
deltaColor: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: "auto"
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Show a placeholder instead of the value.
|
|
102
|
+
* @type {boolean}
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
loading: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: false
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
setup(__props) {
|
|
111
|
+
/**
|
|
112
|
+
* UiStatCard — a single headline number for dashboards: label, value, an
|
|
113
|
+
* optional tinted icon, a trend delta and a hint line.
|
|
114
|
+
*
|
|
115
|
+
* Built on `UiCard`, so external classes merge onto the card surface. While
|
|
116
|
+
* `loading`, the value is replaced by a pulsing placeholder of the same height
|
|
117
|
+
* so a grid of cards doesn't jump when data arrives.
|
|
118
|
+
*
|
|
119
|
+
* The delta's colour follows `trend` (up is green, down is red) unless
|
|
120
|
+
* `deltaColor` says otherwise — for metrics where going up is bad, such as
|
|
121
|
+
* error counts, pass `delta-color="red"` with `trend="up"`.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
|
125
|
+
* <UiStatCard label="Connections" :value="128" icon="mdi:lan-connect" />
|
|
126
|
+
* <UiStatCard label="Documents" value="4,210" icon="mdi:file-document-outline" color="success" />
|
|
127
|
+
* <UiStatCard label="Access denials" :value="3" trend="up" delta="+2" delta-color="red" hint="last hour" />
|
|
128
|
+
* </div>
|
|
129
|
+
*
|
|
130
|
+
* @slot value — Rich value content (overrides `value`).
|
|
131
|
+
* @slot default — Extra content in the footer line.
|
|
132
|
+
*/
|
|
133
|
+
const props = __props;
|
|
134
|
+
const toneClass = computed(() => ({
|
|
135
|
+
primary: "bg-primary-50 text-primary-600 dark:bg-primary-400/10 dark:text-primary-300",
|
|
136
|
+
success: "bg-success-50 text-success-700 dark:bg-success-400/10 dark:text-success-300",
|
|
137
|
+
warning: "bg-warning-50 text-warning-700 dark:bg-warning-400/10 dark:text-warning-300",
|
|
138
|
+
error: "bg-red-50 text-red-600 dark:bg-red-400/10 dark:text-red-300",
|
|
139
|
+
gray: "bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"
|
|
140
|
+
})[props.color] ?? "bg-primary-50 text-primary-600 dark:bg-primary-400/10 dark:text-primary-300");
|
|
141
|
+
const trendIcon = computed(() => ({
|
|
142
|
+
up: "mdi:trending-up",
|
|
143
|
+
down: "mdi:trending-down"
|
|
144
|
+
})[props.trend] ?? "mdi:trending-neutral");
|
|
145
|
+
const deltaClass = computed(() => {
|
|
146
|
+
return {
|
|
147
|
+
green: "text-success-700 dark:text-success-400",
|
|
148
|
+
red: "text-red-600 dark:text-red-400"
|
|
149
|
+
}[props.deltaColor === "auto" ? {
|
|
150
|
+
up: "green",
|
|
151
|
+
down: "red"
|
|
152
|
+
}[props.trend] || "gray" : props.deltaColor] ?? "text-gray-500 dark:text-gray-400";
|
|
153
|
+
});
|
|
154
|
+
return (_ctx, _cache) => {
|
|
155
|
+
return openBlock(), createBlock(_sfc_main$2, {
|
|
156
|
+
padding: "sm",
|
|
157
|
+
"aria-busy": __props.loading ? "true" : void 0
|
|
158
|
+
}, {
|
|
159
|
+
default: withCtx(() => [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("p", _hoisted_3, toDisplayString(__props.label), 1), createElementVNode("p", _hoisted_4, [__props.loading ? (openBlock(), createElementBlock("span", _hoisted_5)) : renderSlot(_ctx.$slots, "value", {}, () => [createTextVNode(toDisplayString(__props.value), 1)], void 0, 1)])]), __props.icon ? (openBlock(), createElementBlock("span", {
|
|
160
|
+
key: 0,
|
|
161
|
+
class: normalizeClass(["inline-flex size-9 shrink-0 items-center justify-center rounded-xl", toneClass.value]),
|
|
162
|
+
"aria-hidden": "true"
|
|
163
|
+
}, [createVNode(_sfc_main$1, {
|
|
164
|
+
name: __props.icon,
|
|
165
|
+
class: "size-5"
|
|
166
|
+
}, null, 8, ["name"])], 2)) : createCommentVNode("", true)]), __props.hint || __props.delta || _ctx.$slots.default ? (openBlock(), createElementBlock("div", _hoisted_6, [
|
|
167
|
+
__props.delta ? (openBlock(), createElementBlock("span", {
|
|
168
|
+
key: 0,
|
|
169
|
+
class: normalizeClass(["inline-flex items-center gap-1 font-medium", deltaClass.value])
|
|
170
|
+
}, [createVNode(_sfc_main$1, {
|
|
171
|
+
name: trendIcon.value,
|
|
172
|
+
class: "size-3.5"
|
|
173
|
+
}, null, 8, ["name"]), createTextVNode(" " + toDisplayString(__props.delta), 1)], 2)) : createCommentVNode("", true),
|
|
174
|
+
__props.hint ? (openBlock(), createElementBlock("span", _hoisted_7, toDisplayString(__props.hint), 1)) : createCommentVNode("", true),
|
|
175
|
+
renderSlot(_ctx.$slots, "default")
|
|
176
|
+
])) : createCommentVNode("", true)]),
|
|
177
|
+
_: 3
|
|
178
|
+
}, 8, ["aria-busy"]);
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
//#endregion
|
|
183
|
+
export { _sfc_main as default };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=StatCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatCard.js","names":["$slots"],"sources":["../../src/components/StatCard.vue"],"sourcesContent":["<template>\n <UiCard padding=\"sm\" :aria-busy=\"loading ? 'true' : undefined\">\n <div class=\"flex items-start justify-between gap-3\">\n <div class=\"min-w-0\">\n <p class=\"truncate text-sm font-medium text-gray-500 dark:text-gray-400\">{{ label }}</p>\n <p\n class=\"mt-1 text-2xl font-semibold tracking-tight text-gray-900 tabular-nums dark:text-gray-50\"\n >\n <span\n v-if=\"loading\"\n class=\"inline-block h-7 w-16 animate-pulse rounded-md bg-gray-200 align-middle motion-reduce:animate-none dark:bg-gray-800\"\n aria-hidden=\"true\"\n />\n <slot v-else name=\"value\">{{ value }}</slot>\n </p>\n </div>\n <span\n v-if=\"icon\"\n class=\"inline-flex size-9 shrink-0 items-center justify-center rounded-xl\"\n :class=\"toneClass\"\n aria-hidden=\"true\"\n >\n <UiIcon :name=\"icon\" class=\"size-5\" />\n </span>\n </div>\n\n <div\n v-if=\"hint || delta || $slots.default\"\n class=\"mt-3 flex flex-wrap items-center gap-2 text-xs\"\n >\n <span v-if=\"delta\" class=\"inline-flex items-center gap-1 font-medium\" :class=\"deltaClass\">\n <UiIcon :name=\"trendIcon\" class=\"size-3.5\" />\n {{ delta }}\n </span>\n <span v-if=\"hint\" class=\"text-gray-500 dark:text-gray-400\">{{ hint }}</span>\n <slot />\n </div>\n </UiCard>\n</template>\n\n<script setup>\n/**\n * UiStatCard — a single headline number for dashboards: label, value, an\n * optional tinted icon, a trend delta and a hint line.\n *\n * Built on `UiCard`, so external classes merge onto the card surface. While\n * `loading`, the value is replaced by a pulsing placeholder of the same height\n * so a grid of cards doesn't jump when data arrives.\n *\n * The delta's colour follows `trend` (up is green, down is red) unless\n * `deltaColor` says otherwise — for metrics where going up is bad, such as\n * error counts, pass `delta-color=\"red\"` with `trend=\"up\"`.\n *\n * @example\n * <div class=\"grid gap-4 sm:grid-cols-2 lg:grid-cols-4\">\n * <UiStatCard label=\"Connections\" :value=\"128\" icon=\"mdi:lan-connect\" />\n * <UiStatCard label=\"Documents\" value=\"4,210\" icon=\"mdi:file-document-outline\" color=\"success\" />\n * <UiStatCard label=\"Access denials\" :value=\"3\" trend=\"up\" delta=\"+2\" delta-color=\"red\" hint=\"last hour\" />\n * </div>\n *\n * @slot value — Rich value content (overrides `value`).\n * @slot default — Extra content in the footer line.\n */\nimport { computed } from 'vue'\nimport UiCard from './Card.vue'\nimport UiIcon from '../icons/Icon.vue'\n\nconst props = defineProps({\n /**\n * What the number measures.\n * @type {string}\n * @default ''\n */\n label: { type: String, default: '' },\n\n /**\n * The number (or pre-formatted string).\n * @type {string | number}\n * @default ''\n */\n value: { type: [String, Number], default: '' },\n\n /**\n * Secondary line, such as a time window or a unit.\n * @type {string}\n * @default ''\n */\n hint: { type: String, default: '' },\n\n /**\n * MDI icon in a tinted tile.\n * @type {string}\n * @default ''\n */\n icon: { type: String, default: '' },\n\n /**\n * Icon tile tint.\n * @type {string}\n * @default 'primary'\n * @values 'primary' | 'success' | 'warning' | 'error' | 'gray'\n */\n color: { type: String, default: 'primary' },\n\n /**\n * Change to show next to the hint, e.g. `'+12%'`. Empty hides it.\n * @type {string}\n * @default ''\n */\n delta: { type: String, default: '' },\n\n /**\n * Direction of the change, which picks the arrow.\n * @type {string}\n * @default 'flat'\n * @values 'up' | 'down' | 'flat'\n */\n trend: { type: String, default: 'flat' },\n\n /**\n * Delta colour. `'auto'` makes up green and down red.\n * @type {string}\n * @default 'auto'\n * @values 'auto' | 'green' | 'red' | 'gray'\n */\n deltaColor: { type: String, default: 'auto' },\n\n /**\n * Show a placeholder instead of the value.\n * @type {boolean}\n * @default false\n */\n loading: { type: Boolean, default: false },\n})\n\nconst toneClass = computed(\n () =>\n ({\n primary: 'bg-primary-50 text-primary-600 dark:bg-primary-400/10 dark:text-primary-300',\n success: 'bg-success-50 text-success-700 dark:bg-success-400/10 dark:text-success-300',\n warning: 'bg-warning-50 text-warning-700 dark:bg-warning-400/10 dark:text-warning-300',\n error: 'bg-red-50 text-red-600 dark:bg-red-400/10 dark:text-red-300',\n gray: 'bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400',\n })[props.color] ??\n 'bg-primary-50 text-primary-600 dark:bg-primary-400/10 dark:text-primary-300',\n)\n\nconst trendIcon = computed(\n () =>\n ({ up: 'mdi:trending-up', down: 'mdi:trending-down' })[props.trend] ?? 'mdi:trending-neutral',\n)\n\nconst deltaClass = computed(() => {\n const tone =\n props.deltaColor === 'auto'\n ? { up: 'green', down: 'red' }[props.trend] || 'gray'\n : props.deltaColor\n return (\n {\n green: 'text-success-700 dark:text-success-400',\n red: 'text-red-600 dark:text-red-400',\n }[tone] ?? 'text-gray-500 dark:text-gray-400'\n )\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmEA,MAAM,QAAQ;EAoEd,MAAM,YAAY,gBAEb;GACC,SAAS;GACT,SAAS;GACT,SAAS;GACT,OAAO;GACP,MAAM;EACR,EAAA,CAAG,MAAM,UACT,6EACJ;EAEA,MAAM,YAAY,gBAEb;GAAE,IAAI;GAAmB,MAAM;EAAoB,EAAA,CAAG,MAAM,UAAU,sBAC3E;EAEA,MAAM,aAAa,eAAe;GAKhC,OACE;IACE,OAAO;IACP,KAAK;GACP,EAPA,MAAM,eAAe,SACjB;IAAE,IAAI;IAAS,MAAM;GAAM,EAAE,MAAM,UAAU,SAC7C,MAAM,eAKC;EAEf,CAAC;;GAlKC,OAAA,UAAA,GAAA,YAoCS,aAAA;IApCD,SAAQ;IAAM,aAAW,QAAA,UAAO,SAAY,KAAA;;IAClD,SAAA,cAsBM,CAtBN,mBAsBM,OAtBN,YAsBM,CArBJ,mBAYM,OAZN,YAYM,CAXJ,mBAAwF,KAAxF,YAAwF,gBAAZ,QAAA,KAAK,GAAA,CAAA,GACjF,mBASI,KATJ,YASI,CALM,QAAA,WADR,UAAA,GAAA,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