cynx-lib 1.3.84 → 1.3.85
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/gen.js +77 -77
- package/package.json +5 -1
- package/ui/components/Drawer.jsx +208 -208
- package/ui/components/Pagination.jsx +145 -145
- package/ui/components/PrivacyBlur.jsx +603 -603
- package/utils/index.cjs +5 -0
- package/utils/index.js +22 -20
- package/utils/utils/duration.js +139 -139
- package/utils/utils/oidc.js +214 -214
- package/utils/utils/realtime.js +1634 -1634
- package/utils/utils/session.cjs +15 -2
- package/utils/utils/session.js +67 -58
- package/utils/utils/session_manager.cjs +490 -0
- package/utils/utils/session_manager.js +549 -0
- package/utils/utils/storage.js +393 -393
- package/utils/utils/ui.js +111 -111
- package/vue/components/Badge.vue +79 -79
- package/vue/components/Button.vue +209 -209
- package/vue/components/Checkbox.vue +103 -103
- package/vue/components/CircularProgress.vue +383 -383
- package/vue/components/Divider.vue +94 -94
- package/vue/components/Drawer.vue +243 -243
- package/vue/components/InfoBadge.vue +223 -223
- package/vue/components/Input.vue +341 -341
- package/vue/components/LinearProgress.vue +268 -268
- package/vue/components/Modal.vue +226 -226
- package/vue/components/Pagination.vue +199 -199
- package/vue/components/Select.vue +713 -713
- package/vue/components/Sidebar.vue +955 -955
- package/vue/components/Skeleton.vue +91 -91
- package/vue/components/Spinner.vue +263 -263
- package/vue/components/StatusTag.vue +89 -89
- package/vue/components/TabBar.vue +176 -176
- package/vue/components/Table.vue +388 -388
- package/vue/components/TimePicker.vue +399 -399
- package/vue/components/Toggle.vue +115 -115
- package/vue/components/XTable.vue +119 -119
- package/vue/composables/useAutoSkeletonRows.ts +71 -71
- package/vue/index.d.ts +67 -67
- package/vue/index.js +86 -86
|
@@ -1,383 +1,383 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, ref, onMounted, onBeforeUnmount, watch } from "vue";
|
|
3
|
-
|
|
4
|
-
const SIZES: Record<string, { svg: number; stroke: number; fontSize: string }> = {
|
|
5
|
-
xs: { svg: 48, stroke: 4, fontSize: ".7rem" },
|
|
6
|
-
sm: { svg: 64, stroke: 5, fontSize: ".85rem" },
|
|
7
|
-
md: { svg: 80, stroke: 6, fontSize: "1rem" },
|
|
8
|
-
lg: { svg: 100, stroke: 7, fontSize: "1.15rem" },
|
|
9
|
-
xl: { svg: 120, stroke: 8, fontSize: "1.3rem" },
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export interface CircularSegment {
|
|
13
|
-
value: number;
|
|
14
|
-
color?: string;
|
|
15
|
-
label?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const props = withDefaults(
|
|
19
|
-
defineProps<{
|
|
20
|
-
value?: number;
|
|
21
|
-
segments?: CircularSegment[];
|
|
22
|
-
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
23
|
-
customSize?: number;
|
|
24
|
-
color?: string;
|
|
25
|
-
trackColor?: string;
|
|
26
|
-
label?: string;
|
|
27
|
-
centerText?: string | number;
|
|
28
|
-
showPercent?: boolean;
|
|
29
|
-
animated?: boolean;
|
|
30
|
-
rounded?: boolean;
|
|
31
|
-
indeterminate?: boolean;
|
|
32
|
-
speed?: number;
|
|
33
|
-
strokeWidth?: number;
|
|
34
|
-
gap?: number;
|
|
35
|
-
className?: string;
|
|
36
|
-
style?: Record<string, any>;
|
|
37
|
-
}>(),
|
|
38
|
-
{
|
|
39
|
-
value: 0,
|
|
40
|
-
size: "md",
|
|
41
|
-
color: "var(--blue, #2782e4)",
|
|
42
|
-
trackColor: "var(--bd2, #e0e0e4)",
|
|
43
|
-
label: "",
|
|
44
|
-
showPercent: true,
|
|
45
|
-
animated: true,
|
|
46
|
-
rounded: true,
|
|
47
|
-
indeterminate: false,
|
|
48
|
-
speed: 1,
|
|
49
|
-
gap: 4,
|
|
50
|
-
className: "",
|
|
51
|
-
style: () => ({}),
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const base = computed(() => SIZES[props.size] || SIZES.md);
|
|
56
|
-
const svg = computed(() => props.customSize || base.value.svg);
|
|
57
|
-
const stroke = computed(() =>
|
|
58
|
-
props.strokeWidth ??
|
|
59
|
-
(props.customSize ? Math.max(3, svg.value * 0.06) : base.value.stroke)
|
|
60
|
-
);
|
|
61
|
-
const fontSize = computed(() =>
|
|
62
|
-
props.customSize
|
|
63
|
-
? `${Math.max(11, svg.value * 0.13)}px`
|
|
64
|
-
: base.value.fontSize
|
|
65
|
-
);
|
|
66
|
-
const cx = computed(() => svg.value / 2);
|
|
67
|
-
const cy = computed(() => svg.value / 2);
|
|
68
|
-
const r = computed(() => (svg.value - stroke.value) / 2);
|
|
69
|
-
const c = computed(() => 2 * Math.PI * r.value);
|
|
70
|
-
const pct = computed(() => Math.min(100, Math.max(0, props.value || 0)));
|
|
71
|
-
const BIG = computed(() => c.value * 4);
|
|
72
|
-
const isRounded = computed(() => props.rounded !== false);
|
|
73
|
-
const cap = computed(() => (isRounded.value ? "round" : "butt"));
|
|
74
|
-
|
|
75
|
-
const userGap = computed(() =>
|
|
76
|
-
props.gap !== undefined
|
|
77
|
-
? props.gap
|
|
78
|
-
: isRounded.value
|
|
79
|
-
? c.value * 0.05
|
|
80
|
-
: c.value * 0.03
|
|
81
|
-
);
|
|
82
|
-
const capOverrun = computed(() => (isRounded.value ? stroke.value : 0));
|
|
83
|
-
const gapSize = computed(() => userGap.value + capOverrun.value);
|
|
84
|
-
const total = computed(() => c.value - 2 * gapSize.value);
|
|
85
|
-
|
|
86
|
-
const isFull = computed(() => pct.value >= 100);
|
|
87
|
-
const isEmpty = computed(() => pct.value <= 0);
|
|
88
|
-
|
|
89
|
-
const hasSegments = computed(
|
|
90
|
-
() => Array.isArray(props.segments) && props.segments.length > 0
|
|
91
|
-
);
|
|
92
|
-
const rawSum = computed(() =>
|
|
93
|
-
hasSegments.value
|
|
94
|
-
? props.segments!.reduce((sum, s) => sum + (Number(s.value) || 0), 0)
|
|
95
|
-
: 0
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const indDash = computed(() => {
|
|
99
|
-
if (isEmpty.value) return `0,${BIG.value}`;
|
|
100
|
-
if (isFull.value) return `${c.value + stroke.value * 2},${BIG.value}`;
|
|
101
|
-
const activeLen = (pct.value / 100) * total.value;
|
|
102
|
-
return `${activeLen},${BIG.value}`;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const indOffset = computed(() => 0);
|
|
106
|
-
|
|
107
|
-
const trackDash = computed(() => {
|
|
108
|
-
if (isEmpty.value) return `${c.value},${BIG.value}`;
|
|
109
|
-
if (isFull.value) return `0,${BIG.value}`;
|
|
110
|
-
const activeLen = (pct.value / 100) * total.value;
|
|
111
|
-
const inactiveLen = total.value - activeLen;
|
|
112
|
-
return `${inactiveLen},${BIG.value}`;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const trackOffset = computed(() => {
|
|
116
|
-
if (isEmpty.value || isFull.value) return 0;
|
|
117
|
-
const activeLen = (pct.value / 100) * total.value;
|
|
118
|
-
return -(activeLen + gapSize.value);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const indOpacity = computed(() => (isEmpty.value ? 0 : 1));
|
|
122
|
-
|
|
123
|
-
const computedSegments = computed(() => {
|
|
124
|
-
if (!hasSegments.value || rawSum.value <= 0) return [];
|
|
125
|
-
const activeSegs = props.segments!.filter(
|
|
126
|
-
(seg) => (Number(seg.value) || 0) > 0
|
|
127
|
-
);
|
|
128
|
-
const segCount = activeSegs.length;
|
|
129
|
-
if (segCount === 0) return [];
|
|
130
|
-
|
|
131
|
-
const gapPx = props.gap !== undefined ? props.gap : 4;
|
|
132
|
-
const overrun = isRounded.value ? stroke.value : 0;
|
|
133
|
-
const gapArc = segCount > 1 ? gapPx + overrun : 0;
|
|
134
|
-
const availableC = Math.max(0, c.value - segCount * gapArc);
|
|
135
|
-
|
|
136
|
-
let accumulatedArc = isRounded.value ? stroke.value / 2 : 0;
|
|
137
|
-
|
|
138
|
-
return activeSegs.map((seg, idx) => {
|
|
139
|
-
const val = Number(seg.value) || 0;
|
|
140
|
-
const segLen = (val / rawSum.value) * availableC;
|
|
141
|
-
const currentOffset = accumulatedArc;
|
|
142
|
-
accumulatedArc += segLen + gapArc;
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
key: idx,
|
|
146
|
-
val,
|
|
147
|
-
color: seg.color || props.color,
|
|
148
|
-
label: seg.label,
|
|
149
|
-
strokeDasharray: `${Math.max(0.1, segLen).toFixed(2)}, ${BIG.value}`,
|
|
150
|
-
strokeDashoffset: (-currentOffset).toFixed(2),
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
const gRef = ref<SVGGElement | null>(null);
|
|
156
|
-
const indRef = ref<SVGCircleElement | null>(null);
|
|
157
|
-
const trackRef = ref<SVGCircleElement | null>(null);
|
|
158
|
-
let raf: number | null = null;
|
|
159
|
-
|
|
160
|
-
const startIndeterminate = () => {
|
|
161
|
-
if (raf) cancelAnimationFrame(raf);
|
|
162
|
-
if (!props.indeterminate) return;
|
|
163
|
-
|
|
164
|
-
const capRad = (180 / Math.PI) * (stroke.value / r.value) / 2;
|
|
165
|
-
const gapRad = (180 / Math.PI) * (gapSize.value / r.value);
|
|
166
|
-
const gapArcLen = ((capRad + gapRad) / 360) * c.value;
|
|
167
|
-
let angle = -90;
|
|
168
|
-
let arcFrac = 0.45;
|
|
169
|
-
let arcDir = 1;
|
|
170
|
-
let lastTime = performance.now();
|
|
171
|
-
|
|
172
|
-
function tick(now: number) {
|
|
173
|
-
const dt = (now - lastTime) / 16.67;
|
|
174
|
-
lastTime = now;
|
|
175
|
-
angle = (angle + 3.6 * props.speed * dt) % 360;
|
|
176
|
-
arcFrac += 0.006 * arcDir * props.speed * dt;
|
|
177
|
-
if (arcFrac >= 0.72) {
|
|
178
|
-
arcFrac = 0.72;
|
|
179
|
-
arcDir = -1;
|
|
180
|
-
}
|
|
181
|
-
if (arcFrac <= 0.18) {
|
|
182
|
-
arcFrac = 0.18;
|
|
183
|
-
arcDir = 1;
|
|
184
|
-
}
|
|
185
|
-
const indLen = c.value * arcFrac;
|
|
186
|
-
const trackLen = Math.max(0, c.value - indLen - gapArcLen * 2);
|
|
187
|
-
|
|
188
|
-
if (gRef.value) gRef.value.style.transform = `rotate(${angle}deg)`;
|
|
189
|
-
if (indRef.value)
|
|
190
|
-
indRef.value.setAttribute("stroke-dasharray", `${indLen.toFixed(2)},9999`);
|
|
191
|
-
if (trackRef.value) {
|
|
192
|
-
trackRef.value.setAttribute(
|
|
193
|
-
"stroke-dasharray",
|
|
194
|
-
`${trackLen.toFixed(2)},9999`
|
|
195
|
-
);
|
|
196
|
-
trackRef.value.setAttribute(
|
|
197
|
-
"stroke-dashoffset",
|
|
198
|
-
`${(-(indLen + gapArcLen)).toFixed(2)}`
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
raf = requestAnimationFrame(tick);
|
|
202
|
-
}
|
|
203
|
-
raf = requestAnimationFrame(tick);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
onMounted(() => {
|
|
207
|
-
if (props.indeterminate) startIndeterminate();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
watch(
|
|
211
|
-
() => [props.indeterminate, props.speed, c.value, stroke.value, r.value, gapSize.value],
|
|
212
|
-
() => {
|
|
213
|
-
if (props.indeterminate) {
|
|
214
|
-
startIndeterminate();
|
|
215
|
-
} else if (raf) {
|
|
216
|
-
cancelAnimationFrame(raf);
|
|
217
|
-
raf = null;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
onBeforeUnmount(() => {
|
|
223
|
-
if (raf) cancelAnimationFrame(raf);
|
|
224
|
-
});
|
|
225
|
-
</script>
|
|
226
|
-
|
|
227
|
-
<template>
|
|
228
|
-
<div
|
|
229
|
-
:class="className"
|
|
230
|
-
:style="{
|
|
231
|
-
display: 'inline-flex',
|
|
232
|
-
flexDirection: 'column',
|
|
233
|
-
alignItems: 'center',
|
|
234
|
-
gap: '4px',
|
|
235
|
-
...style,
|
|
236
|
-
}"
|
|
237
|
-
>
|
|
238
|
-
<div :style="{ position: 'relative', width: `${svg}px`, height: `${svg}px` }">
|
|
239
|
-
<svg
|
|
240
|
-
:width="svg"
|
|
241
|
-
:height="svg"
|
|
242
|
-
:viewBox="`0 0 ${svg} ${svg}`"
|
|
243
|
-
>
|
|
244
|
-
<template v-if="indeterminate">
|
|
245
|
-
<g ref="gRef" :style="{ transformOrigin: `${cx}px ${cy}px` }">
|
|
246
|
-
<circle
|
|
247
|
-
ref="trackRef"
|
|
248
|
-
:cx="cx"
|
|
249
|
-
:cy="cy"
|
|
250
|
-
:r="r"
|
|
251
|
-
fill="none"
|
|
252
|
-
:stroke="trackColor"
|
|
253
|
-
:stroke-width="stroke"
|
|
254
|
-
:stroke-linecap="cap"
|
|
255
|
-
/>
|
|
256
|
-
<circle
|
|
257
|
-
ref="indRef"
|
|
258
|
-
:cx="cx"
|
|
259
|
-
:cy="cy"
|
|
260
|
-
:r="r"
|
|
261
|
-
fill="none"
|
|
262
|
-
:stroke="color"
|
|
263
|
-
:stroke-width="stroke"
|
|
264
|
-
:stroke-linecap="cap"
|
|
265
|
-
/>
|
|
266
|
-
</g>
|
|
267
|
-
</template>
|
|
268
|
-
|
|
269
|
-
<template v-else-if="hasSegments">
|
|
270
|
-
<circle
|
|
271
|
-
v-if="rawSum <= 0 || computedSegments.length === 0"
|
|
272
|
-
:cx="cx"
|
|
273
|
-
:cy="cy"
|
|
274
|
-
:r="r"
|
|
275
|
-
fill="none"
|
|
276
|
-
:stroke="trackColor"
|
|
277
|
-
:stroke-width="stroke"
|
|
278
|
-
/>
|
|
279
|
-
<template v-else>
|
|
280
|
-
<circle
|
|
281
|
-
v-for="seg in computedSegments"
|
|
282
|
-
:key="seg.key"
|
|
283
|
-
:cx="cx"
|
|
284
|
-
:cy="cy"
|
|
285
|
-
:r="r"
|
|
286
|
-
fill="none"
|
|
287
|
-
:stroke="seg.color"
|
|
288
|
-
:stroke-width="stroke"
|
|
289
|
-
:stroke-linecap="cap"
|
|
290
|
-
:stroke-dasharray="seg.strokeDasharray"
|
|
291
|
-
:stroke-dashoffset="seg.strokeDashoffset"
|
|
292
|
-
:style="{
|
|
293
|
-
transform: 'rotate(-90deg)',
|
|
294
|
-
transformOrigin: '50% 50%',
|
|
295
|
-
transition: animated
|
|
296
|
-
? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), stroke-dashoffset .5s cubic-bezier(0.4,0,0.2,1)'
|
|
297
|
-
: 'none',
|
|
298
|
-
}"
|
|
299
|
-
>
|
|
300
|
-
<title v-if="seg.label">{{ `${seg.label}: ${seg.val}` }}</title>
|
|
301
|
-
</circle>
|
|
302
|
-
</template>
|
|
303
|
-
</template>
|
|
304
|
-
|
|
305
|
-
<template v-else>
|
|
306
|
-
<circle
|
|
307
|
-
:cx="cx"
|
|
308
|
-
:cy="cy"
|
|
309
|
-
:r="r"
|
|
310
|
-
fill="none"
|
|
311
|
-
:stroke="trackColor"
|
|
312
|
-
:stroke-width="stroke"
|
|
313
|
-
:stroke-linecap="cap"
|
|
314
|
-
:stroke-dasharray="trackDash"
|
|
315
|
-
:stroke-dashoffset="trackOffset"
|
|
316
|
-
:style="{
|
|
317
|
-
transform: 'rotate(-90deg)',
|
|
318
|
-
transformOrigin: '50% 50%',
|
|
319
|
-
transition: animated
|
|
320
|
-
? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), stroke-dashoffset .5s cubic-bezier(0.4,0,0.2,1)'
|
|
321
|
-
: 'none',
|
|
322
|
-
}"
|
|
323
|
-
/>
|
|
324
|
-
<circle
|
|
325
|
-
:cx="cx"
|
|
326
|
-
:cy="cy"
|
|
327
|
-
:r="r"
|
|
328
|
-
fill="none"
|
|
329
|
-
:stroke="color"
|
|
330
|
-
:stroke-width="stroke"
|
|
331
|
-
:stroke-linecap="cap"
|
|
332
|
-
:stroke-dasharray="indDash"
|
|
333
|
-
:stroke-dashoffset="indOffset"
|
|
334
|
-
:style="{
|
|
335
|
-
transform: 'rotate(-90deg)',
|
|
336
|
-
transformOrigin: '50% 50%',
|
|
337
|
-
opacity: indOpacity,
|
|
338
|
-
transition: animated
|
|
339
|
-
? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), opacity .2s'
|
|
340
|
-
: 'none',
|
|
341
|
-
}"
|
|
342
|
-
/>
|
|
343
|
-
</template>
|
|
344
|
-
</svg>
|
|
345
|
-
|
|
346
|
-
<div
|
|
347
|
-
v-if="$slots.default || (showPercent && !indeterminate)"
|
|
348
|
-
:style="{
|
|
349
|
-
position: 'absolute',
|
|
350
|
-
inset: 0,
|
|
351
|
-
display: 'flex',
|
|
352
|
-
alignItems: 'center',
|
|
353
|
-
justifyContent: 'center',
|
|
354
|
-
fontSize: fontSize,
|
|
355
|
-
fontWeight: 600,
|
|
356
|
-
color: 'var(--primary-text, #0f172a)',
|
|
357
|
-
fontVariantNumeric: 'tabular-nums',
|
|
358
|
-
}"
|
|
359
|
-
>
|
|
360
|
-
<slot>
|
|
361
|
-
{{
|
|
362
|
-
centerText !== undefined
|
|
363
|
-
? centerText
|
|
364
|
-
: hasSegments
|
|
365
|
-
? rawSum
|
|
366
|
-
: `${Math.round(pct)}%`
|
|
367
|
-
}}
|
|
368
|
-
</slot>
|
|
369
|
-
</div>
|
|
370
|
-
</div>
|
|
371
|
-
|
|
372
|
-
<span
|
|
373
|
-
v-if="label"
|
|
374
|
-
:style="{
|
|
375
|
-
fontSize: '.6rem',
|
|
376
|
-
color: 'var(--muted, #797b8d)',
|
|
377
|
-
fontWeight: 500,
|
|
378
|
-
}"
|
|
379
|
-
>
|
|
380
|
-
{{ label }}
|
|
381
|
-
</span>
|
|
382
|
-
</div>
|
|
383
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, onMounted, onBeforeUnmount, watch } from "vue";
|
|
3
|
+
|
|
4
|
+
const SIZES: Record<string, { svg: number; stroke: number; fontSize: string }> = {
|
|
5
|
+
xs: { svg: 48, stroke: 4, fontSize: ".7rem" },
|
|
6
|
+
sm: { svg: 64, stroke: 5, fontSize: ".85rem" },
|
|
7
|
+
md: { svg: 80, stroke: 6, fontSize: "1rem" },
|
|
8
|
+
lg: { svg: 100, stroke: 7, fontSize: "1.15rem" },
|
|
9
|
+
xl: { svg: 120, stroke: 8, fontSize: "1.3rem" },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface CircularSegment {
|
|
13
|
+
value: number;
|
|
14
|
+
color?: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(
|
|
19
|
+
defineProps<{
|
|
20
|
+
value?: number;
|
|
21
|
+
segments?: CircularSegment[];
|
|
22
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
23
|
+
customSize?: number;
|
|
24
|
+
color?: string;
|
|
25
|
+
trackColor?: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
centerText?: string | number;
|
|
28
|
+
showPercent?: boolean;
|
|
29
|
+
animated?: boolean;
|
|
30
|
+
rounded?: boolean;
|
|
31
|
+
indeterminate?: boolean;
|
|
32
|
+
speed?: number;
|
|
33
|
+
strokeWidth?: number;
|
|
34
|
+
gap?: number;
|
|
35
|
+
className?: string;
|
|
36
|
+
style?: Record<string, any>;
|
|
37
|
+
}>(),
|
|
38
|
+
{
|
|
39
|
+
value: 0,
|
|
40
|
+
size: "md",
|
|
41
|
+
color: "var(--blue, #2782e4)",
|
|
42
|
+
trackColor: "var(--bd2, #e0e0e4)",
|
|
43
|
+
label: "",
|
|
44
|
+
showPercent: true,
|
|
45
|
+
animated: true,
|
|
46
|
+
rounded: true,
|
|
47
|
+
indeterminate: false,
|
|
48
|
+
speed: 1,
|
|
49
|
+
gap: 4,
|
|
50
|
+
className: "",
|
|
51
|
+
style: () => ({}),
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const base = computed(() => SIZES[props.size] || SIZES.md);
|
|
56
|
+
const svg = computed(() => props.customSize || base.value.svg);
|
|
57
|
+
const stroke = computed(() =>
|
|
58
|
+
props.strokeWidth ??
|
|
59
|
+
(props.customSize ? Math.max(3, svg.value * 0.06) : base.value.stroke)
|
|
60
|
+
);
|
|
61
|
+
const fontSize = computed(() =>
|
|
62
|
+
props.customSize
|
|
63
|
+
? `${Math.max(11, svg.value * 0.13)}px`
|
|
64
|
+
: base.value.fontSize
|
|
65
|
+
);
|
|
66
|
+
const cx = computed(() => svg.value / 2);
|
|
67
|
+
const cy = computed(() => svg.value / 2);
|
|
68
|
+
const r = computed(() => (svg.value - stroke.value) / 2);
|
|
69
|
+
const c = computed(() => 2 * Math.PI * r.value);
|
|
70
|
+
const pct = computed(() => Math.min(100, Math.max(0, props.value || 0)));
|
|
71
|
+
const BIG = computed(() => c.value * 4);
|
|
72
|
+
const isRounded = computed(() => props.rounded !== false);
|
|
73
|
+
const cap = computed(() => (isRounded.value ? "round" : "butt"));
|
|
74
|
+
|
|
75
|
+
const userGap = computed(() =>
|
|
76
|
+
props.gap !== undefined
|
|
77
|
+
? props.gap
|
|
78
|
+
: isRounded.value
|
|
79
|
+
? c.value * 0.05
|
|
80
|
+
: c.value * 0.03
|
|
81
|
+
);
|
|
82
|
+
const capOverrun = computed(() => (isRounded.value ? stroke.value : 0));
|
|
83
|
+
const gapSize = computed(() => userGap.value + capOverrun.value);
|
|
84
|
+
const total = computed(() => c.value - 2 * gapSize.value);
|
|
85
|
+
|
|
86
|
+
const isFull = computed(() => pct.value >= 100);
|
|
87
|
+
const isEmpty = computed(() => pct.value <= 0);
|
|
88
|
+
|
|
89
|
+
const hasSegments = computed(
|
|
90
|
+
() => Array.isArray(props.segments) && props.segments.length > 0
|
|
91
|
+
);
|
|
92
|
+
const rawSum = computed(() =>
|
|
93
|
+
hasSegments.value
|
|
94
|
+
? props.segments!.reduce((sum, s) => sum + (Number(s.value) || 0), 0)
|
|
95
|
+
: 0
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const indDash = computed(() => {
|
|
99
|
+
if (isEmpty.value) return `0,${BIG.value}`;
|
|
100
|
+
if (isFull.value) return `${c.value + stroke.value * 2},${BIG.value}`;
|
|
101
|
+
const activeLen = (pct.value / 100) * total.value;
|
|
102
|
+
return `${activeLen},${BIG.value}`;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const indOffset = computed(() => 0);
|
|
106
|
+
|
|
107
|
+
const trackDash = computed(() => {
|
|
108
|
+
if (isEmpty.value) return `${c.value},${BIG.value}`;
|
|
109
|
+
if (isFull.value) return `0,${BIG.value}`;
|
|
110
|
+
const activeLen = (pct.value / 100) * total.value;
|
|
111
|
+
const inactiveLen = total.value - activeLen;
|
|
112
|
+
return `${inactiveLen},${BIG.value}`;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const trackOffset = computed(() => {
|
|
116
|
+
if (isEmpty.value || isFull.value) return 0;
|
|
117
|
+
const activeLen = (pct.value / 100) * total.value;
|
|
118
|
+
return -(activeLen + gapSize.value);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const indOpacity = computed(() => (isEmpty.value ? 0 : 1));
|
|
122
|
+
|
|
123
|
+
const computedSegments = computed(() => {
|
|
124
|
+
if (!hasSegments.value || rawSum.value <= 0) return [];
|
|
125
|
+
const activeSegs = props.segments!.filter(
|
|
126
|
+
(seg) => (Number(seg.value) || 0) > 0
|
|
127
|
+
);
|
|
128
|
+
const segCount = activeSegs.length;
|
|
129
|
+
if (segCount === 0) return [];
|
|
130
|
+
|
|
131
|
+
const gapPx = props.gap !== undefined ? props.gap : 4;
|
|
132
|
+
const overrun = isRounded.value ? stroke.value : 0;
|
|
133
|
+
const gapArc = segCount > 1 ? gapPx + overrun : 0;
|
|
134
|
+
const availableC = Math.max(0, c.value - segCount * gapArc);
|
|
135
|
+
|
|
136
|
+
let accumulatedArc = isRounded.value ? stroke.value / 2 : 0;
|
|
137
|
+
|
|
138
|
+
return activeSegs.map((seg, idx) => {
|
|
139
|
+
const val = Number(seg.value) || 0;
|
|
140
|
+
const segLen = (val / rawSum.value) * availableC;
|
|
141
|
+
const currentOffset = accumulatedArc;
|
|
142
|
+
accumulatedArc += segLen + gapArc;
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
key: idx,
|
|
146
|
+
val,
|
|
147
|
+
color: seg.color || props.color,
|
|
148
|
+
label: seg.label,
|
|
149
|
+
strokeDasharray: `${Math.max(0.1, segLen).toFixed(2)}, ${BIG.value}`,
|
|
150
|
+
strokeDashoffset: (-currentOffset).toFixed(2),
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const gRef = ref<SVGGElement | null>(null);
|
|
156
|
+
const indRef = ref<SVGCircleElement | null>(null);
|
|
157
|
+
const trackRef = ref<SVGCircleElement | null>(null);
|
|
158
|
+
let raf: number | null = null;
|
|
159
|
+
|
|
160
|
+
const startIndeterminate = () => {
|
|
161
|
+
if (raf) cancelAnimationFrame(raf);
|
|
162
|
+
if (!props.indeterminate) return;
|
|
163
|
+
|
|
164
|
+
const capRad = (180 / Math.PI) * (stroke.value / r.value) / 2;
|
|
165
|
+
const gapRad = (180 / Math.PI) * (gapSize.value / r.value);
|
|
166
|
+
const gapArcLen = ((capRad + gapRad) / 360) * c.value;
|
|
167
|
+
let angle = -90;
|
|
168
|
+
let arcFrac = 0.45;
|
|
169
|
+
let arcDir = 1;
|
|
170
|
+
let lastTime = performance.now();
|
|
171
|
+
|
|
172
|
+
function tick(now: number) {
|
|
173
|
+
const dt = (now - lastTime) / 16.67;
|
|
174
|
+
lastTime = now;
|
|
175
|
+
angle = (angle + 3.6 * props.speed * dt) % 360;
|
|
176
|
+
arcFrac += 0.006 * arcDir * props.speed * dt;
|
|
177
|
+
if (arcFrac >= 0.72) {
|
|
178
|
+
arcFrac = 0.72;
|
|
179
|
+
arcDir = -1;
|
|
180
|
+
}
|
|
181
|
+
if (arcFrac <= 0.18) {
|
|
182
|
+
arcFrac = 0.18;
|
|
183
|
+
arcDir = 1;
|
|
184
|
+
}
|
|
185
|
+
const indLen = c.value * arcFrac;
|
|
186
|
+
const trackLen = Math.max(0, c.value - indLen - gapArcLen * 2);
|
|
187
|
+
|
|
188
|
+
if (gRef.value) gRef.value.style.transform = `rotate(${angle}deg)`;
|
|
189
|
+
if (indRef.value)
|
|
190
|
+
indRef.value.setAttribute("stroke-dasharray", `${indLen.toFixed(2)},9999`);
|
|
191
|
+
if (trackRef.value) {
|
|
192
|
+
trackRef.value.setAttribute(
|
|
193
|
+
"stroke-dasharray",
|
|
194
|
+
`${trackLen.toFixed(2)},9999`
|
|
195
|
+
);
|
|
196
|
+
trackRef.value.setAttribute(
|
|
197
|
+
"stroke-dashoffset",
|
|
198
|
+
`${(-(indLen + gapArcLen)).toFixed(2)}`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
raf = requestAnimationFrame(tick);
|
|
202
|
+
}
|
|
203
|
+
raf = requestAnimationFrame(tick);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
onMounted(() => {
|
|
207
|
+
if (props.indeterminate) startIndeterminate();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
watch(
|
|
211
|
+
() => [props.indeterminate, props.speed, c.value, stroke.value, r.value, gapSize.value],
|
|
212
|
+
() => {
|
|
213
|
+
if (props.indeterminate) {
|
|
214
|
+
startIndeterminate();
|
|
215
|
+
} else if (raf) {
|
|
216
|
+
cancelAnimationFrame(raf);
|
|
217
|
+
raf = null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
onBeforeUnmount(() => {
|
|
223
|
+
if (raf) cancelAnimationFrame(raf);
|
|
224
|
+
});
|
|
225
|
+
</script>
|
|
226
|
+
|
|
227
|
+
<template>
|
|
228
|
+
<div
|
|
229
|
+
:class="className"
|
|
230
|
+
:style="{
|
|
231
|
+
display: 'inline-flex',
|
|
232
|
+
flexDirection: 'column',
|
|
233
|
+
alignItems: 'center',
|
|
234
|
+
gap: '4px',
|
|
235
|
+
...style,
|
|
236
|
+
}"
|
|
237
|
+
>
|
|
238
|
+
<div :style="{ position: 'relative', width: `${svg}px`, height: `${svg}px` }">
|
|
239
|
+
<svg
|
|
240
|
+
:width="svg"
|
|
241
|
+
:height="svg"
|
|
242
|
+
:viewBox="`0 0 ${svg} ${svg}`"
|
|
243
|
+
>
|
|
244
|
+
<template v-if="indeterminate">
|
|
245
|
+
<g ref="gRef" :style="{ transformOrigin: `${cx}px ${cy}px` }">
|
|
246
|
+
<circle
|
|
247
|
+
ref="trackRef"
|
|
248
|
+
:cx="cx"
|
|
249
|
+
:cy="cy"
|
|
250
|
+
:r="r"
|
|
251
|
+
fill="none"
|
|
252
|
+
:stroke="trackColor"
|
|
253
|
+
:stroke-width="stroke"
|
|
254
|
+
:stroke-linecap="cap"
|
|
255
|
+
/>
|
|
256
|
+
<circle
|
|
257
|
+
ref="indRef"
|
|
258
|
+
:cx="cx"
|
|
259
|
+
:cy="cy"
|
|
260
|
+
:r="r"
|
|
261
|
+
fill="none"
|
|
262
|
+
:stroke="color"
|
|
263
|
+
:stroke-width="stroke"
|
|
264
|
+
:stroke-linecap="cap"
|
|
265
|
+
/>
|
|
266
|
+
</g>
|
|
267
|
+
</template>
|
|
268
|
+
|
|
269
|
+
<template v-else-if="hasSegments">
|
|
270
|
+
<circle
|
|
271
|
+
v-if="rawSum <= 0 || computedSegments.length === 0"
|
|
272
|
+
:cx="cx"
|
|
273
|
+
:cy="cy"
|
|
274
|
+
:r="r"
|
|
275
|
+
fill="none"
|
|
276
|
+
:stroke="trackColor"
|
|
277
|
+
:stroke-width="stroke"
|
|
278
|
+
/>
|
|
279
|
+
<template v-else>
|
|
280
|
+
<circle
|
|
281
|
+
v-for="seg in computedSegments"
|
|
282
|
+
:key="seg.key"
|
|
283
|
+
:cx="cx"
|
|
284
|
+
:cy="cy"
|
|
285
|
+
:r="r"
|
|
286
|
+
fill="none"
|
|
287
|
+
:stroke="seg.color"
|
|
288
|
+
:stroke-width="stroke"
|
|
289
|
+
:stroke-linecap="cap"
|
|
290
|
+
:stroke-dasharray="seg.strokeDasharray"
|
|
291
|
+
:stroke-dashoffset="seg.strokeDashoffset"
|
|
292
|
+
:style="{
|
|
293
|
+
transform: 'rotate(-90deg)',
|
|
294
|
+
transformOrigin: '50% 50%',
|
|
295
|
+
transition: animated
|
|
296
|
+
? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), stroke-dashoffset .5s cubic-bezier(0.4,0,0.2,1)'
|
|
297
|
+
: 'none',
|
|
298
|
+
}"
|
|
299
|
+
>
|
|
300
|
+
<title v-if="seg.label">{{ `${seg.label}: ${seg.val}` }}</title>
|
|
301
|
+
</circle>
|
|
302
|
+
</template>
|
|
303
|
+
</template>
|
|
304
|
+
|
|
305
|
+
<template v-else>
|
|
306
|
+
<circle
|
|
307
|
+
:cx="cx"
|
|
308
|
+
:cy="cy"
|
|
309
|
+
:r="r"
|
|
310
|
+
fill="none"
|
|
311
|
+
:stroke="trackColor"
|
|
312
|
+
:stroke-width="stroke"
|
|
313
|
+
:stroke-linecap="cap"
|
|
314
|
+
:stroke-dasharray="trackDash"
|
|
315
|
+
:stroke-dashoffset="trackOffset"
|
|
316
|
+
:style="{
|
|
317
|
+
transform: 'rotate(-90deg)',
|
|
318
|
+
transformOrigin: '50% 50%',
|
|
319
|
+
transition: animated
|
|
320
|
+
? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), stroke-dashoffset .5s cubic-bezier(0.4,0,0.2,1)'
|
|
321
|
+
: 'none',
|
|
322
|
+
}"
|
|
323
|
+
/>
|
|
324
|
+
<circle
|
|
325
|
+
:cx="cx"
|
|
326
|
+
:cy="cy"
|
|
327
|
+
:r="r"
|
|
328
|
+
fill="none"
|
|
329
|
+
:stroke="color"
|
|
330
|
+
:stroke-width="stroke"
|
|
331
|
+
:stroke-linecap="cap"
|
|
332
|
+
:stroke-dasharray="indDash"
|
|
333
|
+
:stroke-dashoffset="indOffset"
|
|
334
|
+
:style="{
|
|
335
|
+
transform: 'rotate(-90deg)',
|
|
336
|
+
transformOrigin: '50% 50%',
|
|
337
|
+
opacity: indOpacity,
|
|
338
|
+
transition: animated
|
|
339
|
+
? 'stroke-dasharray .5s cubic-bezier(0.4,0,0.2,1), opacity .2s'
|
|
340
|
+
: 'none',
|
|
341
|
+
}"
|
|
342
|
+
/>
|
|
343
|
+
</template>
|
|
344
|
+
</svg>
|
|
345
|
+
|
|
346
|
+
<div
|
|
347
|
+
v-if="$slots.default || (showPercent && !indeterminate)"
|
|
348
|
+
:style="{
|
|
349
|
+
position: 'absolute',
|
|
350
|
+
inset: 0,
|
|
351
|
+
display: 'flex',
|
|
352
|
+
alignItems: 'center',
|
|
353
|
+
justifyContent: 'center',
|
|
354
|
+
fontSize: fontSize,
|
|
355
|
+
fontWeight: 600,
|
|
356
|
+
color: 'var(--primary-text, #0f172a)',
|
|
357
|
+
fontVariantNumeric: 'tabular-nums',
|
|
358
|
+
}"
|
|
359
|
+
>
|
|
360
|
+
<slot>
|
|
361
|
+
{{
|
|
362
|
+
centerText !== undefined
|
|
363
|
+
? centerText
|
|
364
|
+
: hasSegments
|
|
365
|
+
? rawSum
|
|
366
|
+
: `${Math.round(pct)}%`
|
|
367
|
+
}}
|
|
368
|
+
</slot>
|
|
369
|
+
</div>
|
|
370
|
+
</div>
|
|
371
|
+
|
|
372
|
+
<span
|
|
373
|
+
v-if="label"
|
|
374
|
+
:style="{
|
|
375
|
+
fontSize: '.6rem',
|
|
376
|
+
color: 'var(--muted, #797b8d)',
|
|
377
|
+
fontWeight: 500,
|
|
378
|
+
}"
|
|
379
|
+
>
|
|
380
|
+
{{ label }}
|
|
381
|
+
</span>
|
|
382
|
+
</div>
|
|
383
|
+
</template>
|