@vespera-ui/vue 0.5.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/dist/index.d.ts CHANGED
@@ -1159,5 +1159,176 @@ declare const InlineEdit: vue.DefineComponent<vue.ExtractPropTypes<{
1159
1159
  value: string;
1160
1160
  placeholder: string;
1161
1161
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1162
+ interface TreeNodeData {
1163
+ id?: string;
1164
+ label: string;
1165
+ badge?: string;
1166
+ children?: TreeNodeData[];
1167
+ }
1168
+ declare const Tree: vue.DefineComponent<vue.ExtractPropTypes<{
1169
+ data: {
1170
+ type: PropType<TreeNodeData[]>;
1171
+ default: () => never[];
1172
+ };
1173
+ defaultExpanded: {
1174
+ type: PropType<string[]>;
1175
+ default: () => never[];
1176
+ };
1177
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
1178
+ [key: string]: any;
1179
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1180
+ data: {
1181
+ type: PropType<TreeNodeData[]>;
1182
+ default: () => never[];
1183
+ };
1184
+ defaultExpanded: {
1185
+ type: PropType<string[]>;
1186
+ default: () => never[];
1187
+ };
1188
+ }>> & Readonly<{}>, {
1189
+ data: TreeNodeData[];
1190
+ defaultExpanded: string[];
1191
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1192
+ declare const OTPInput: vue.DefineComponent<vue.ExtractPropTypes<{
1193
+ length: {
1194
+ type: NumberConstructor;
1195
+ default: number;
1196
+ };
1197
+ modelValue: {
1198
+ type: StringConstructor;
1199
+ default: string;
1200
+ };
1201
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
1202
+ [key: string]: any;
1203
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1204
+ length: {
1205
+ type: NumberConstructor;
1206
+ default: number;
1207
+ };
1208
+ modelValue: {
1209
+ type: StringConstructor;
1210
+ default: string;
1211
+ };
1212
+ }>> & Readonly<{
1213
+ "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
1214
+ }>, {
1215
+ length: number;
1216
+ modelValue: string;
1217
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1218
+ declare function niceNum(n: number): string;
1219
+ declare const AreaChart: vue.DefineComponent<vue.ExtractPropTypes<{
1220
+ series: {
1221
+ type: PropType<number[][]>;
1222
+ default: () => never[];
1223
+ };
1224
+ labels: {
1225
+ type: PropType<string[]>;
1226
+ default: undefined;
1227
+ };
1228
+ width: {
1229
+ type: NumberConstructor;
1230
+ default: number;
1231
+ };
1232
+ height: {
1233
+ type: NumberConstructor;
1234
+ default: number;
1235
+ };
1236
+ color: {
1237
+ type: StringConstructor;
1238
+ default: string;
1239
+ };
1240
+ color2: {
1241
+ type: StringConstructor;
1242
+ default: string;
1243
+ };
1244
+ dual: BooleanConstructor;
1245
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
1246
+ [key: string]: any;
1247
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1248
+ series: {
1249
+ type: PropType<number[][]>;
1250
+ default: () => never[];
1251
+ };
1252
+ labels: {
1253
+ type: PropType<string[]>;
1254
+ default: undefined;
1255
+ };
1256
+ width: {
1257
+ type: NumberConstructor;
1258
+ default: number;
1259
+ };
1260
+ height: {
1261
+ type: NumberConstructor;
1262
+ default: number;
1263
+ };
1264
+ color: {
1265
+ type: StringConstructor;
1266
+ default: string;
1267
+ };
1268
+ color2: {
1269
+ type: StringConstructor;
1270
+ default: string;
1271
+ };
1272
+ dual: BooleanConstructor;
1273
+ }>> & Readonly<{}>, {
1274
+ height: number;
1275
+ width: number;
1276
+ color: string;
1277
+ dual: boolean;
1278
+ series: number[][];
1279
+ labels: string[];
1280
+ color2: string;
1281
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1282
+ declare const BarChart: vue.DefineComponent<vue.ExtractPropTypes<{
1283
+ data: {
1284
+ type: PropType<number[]>;
1285
+ default: () => never[];
1286
+ };
1287
+ labels: {
1288
+ type: PropType<string[]>;
1289
+ default: undefined;
1290
+ };
1291
+ width: {
1292
+ type: NumberConstructor;
1293
+ default: number;
1294
+ };
1295
+ height: {
1296
+ type: NumberConstructor;
1297
+ default: number;
1298
+ };
1299
+ color: {
1300
+ type: StringConstructor;
1301
+ default: string;
1302
+ };
1303
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
1304
+ [key: string]: any;
1305
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
1306
+ data: {
1307
+ type: PropType<number[]>;
1308
+ default: () => never[];
1309
+ };
1310
+ labels: {
1311
+ type: PropType<string[]>;
1312
+ default: undefined;
1313
+ };
1314
+ width: {
1315
+ type: NumberConstructor;
1316
+ default: number;
1317
+ };
1318
+ height: {
1319
+ type: NumberConstructor;
1320
+ default: number;
1321
+ };
1322
+ color: {
1323
+ type: StringConstructor;
1324
+ default: string;
1325
+ };
1326
+ }>> & Readonly<{}>, {
1327
+ data: number[];
1328
+ height: number;
1329
+ width: number;
1330
+ color: string;
1331
+ labels: string[];
1332
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
1162
1333
 
1163
- export { Accordion, type AccordionItem, Alert, type AlertTone, Avatar, AvatarGroup, Badge, type BadgeTone, Banner, Breadcrumb, Button, type ButtonVariant, Card, CardHead, Checkbox, CircularProgress, CopyButton, DescriptionList, Divider, Donut, type DonutDatum, EmptyState, Field, IconButton, InlineEdit, Input, Kbd, NativeSelect, NumberStepper, Pagination, type Person, Progress, Radio, RadioGroup, Segmented, type SelectOption, Skeleton, Slider, Sparkline, Spinner, Stat, StatCard, Stepper, Switch, type TabItem, Tabs, Tag, Textarea, Timeline, type TimelineItem, smoothPath };
1334
+ export { Accordion, type AccordionItem, Alert, type AlertTone, AreaChart, Avatar, AvatarGroup, Badge, type BadgeTone, Banner, BarChart, Breadcrumb, Button, type ButtonVariant, Card, CardHead, Checkbox, CircularProgress, CopyButton, DescriptionList, Divider, Donut, type DonutDatum, EmptyState, Field, IconButton, InlineEdit, Input, Kbd, NativeSelect, NumberStepper, OTPInput, Pagination, type Person, Progress, Radio, RadioGroup, Segmented, type SelectOption, Skeleton, Slider, Sparkline, Spinner, Stat, StatCard, Stepper, Switch, type TabItem, Tabs, Tag, Textarea, Timeline, type TimelineItem, Tree, type TreeNodeData, niceNum, smoothPath };
package/dist/index.js CHANGED
@@ -1339,13 +1339,337 @@ var InlineEdit = defineComponent({
1339
1339
  );
1340
1340
  }
1341
1341
  });
1342
+ var svgIconClass = (d, size, cls) => h(
1343
+ "svg",
1344
+ {
1345
+ class: cls,
1346
+ viewBox: "0 0 24 24",
1347
+ width: size,
1348
+ height: size,
1349
+ fill: "none",
1350
+ stroke: "currentColor",
1351
+ "stroke-width": 2,
1352
+ "stroke-linecap": "round",
1353
+ "stroke-linejoin": "round"
1354
+ },
1355
+ [h("path", { d })]
1356
+ );
1357
+ var ICON_LAYERS = "M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5";
1358
+ var treeNodeId = (n) => n.id ?? n.label;
1359
+ var VspTreeNode = defineComponent({
1360
+ name: "VspTreeNode",
1361
+ props: {
1362
+ node: { type: Object, required: true },
1363
+ expanded: { type: Object, required: true },
1364
+ selected: { type: String, default: null },
1365
+ toggle: { type: Function, required: true },
1366
+ select: { type: Function, required: true }
1367
+ },
1368
+ setup(props) {
1369
+ return () => {
1370
+ const node = props.node;
1371
+ const id = treeNodeId(node);
1372
+ const kids = node.children ?? [];
1373
+ const hasKids = kids.length > 0;
1374
+ const open = props.expanded.has(id);
1375
+ return h("div", null, [
1376
+ h(
1377
+ "div",
1378
+ {
1379
+ class: cx("ui-tree-row", open && "open", props.selected === id && "sel"),
1380
+ onClick: () => {
1381
+ if (hasKids) props.toggle(id);
1382
+ props.select(id);
1383
+ }
1384
+ },
1385
+ [
1386
+ hasKids ? svgIconClass(ICON_PATHS.chevR, 16, "tw-chev") : h("span", { style: { width: "16px", flexShrink: 0 } }),
1387
+ svgIconClass(hasKids ? ICON_LAYERS : ICON_DOC, 16, "tw-icon"),
1388
+ h(
1389
+ "span",
1390
+ {
1391
+ style: {
1392
+ flex: 1,
1393
+ minWidth: 0,
1394
+ overflow: "hidden",
1395
+ textOverflow: "ellipsis",
1396
+ whiteSpace: "nowrap"
1397
+ }
1398
+ },
1399
+ node.label
1400
+ ),
1401
+ node.badge != null ? h(
1402
+ "span",
1403
+ { class: "mono", style: { fontSize: "11px", color: "var(--text-faint)" } },
1404
+ node.badge
1405
+ ) : null
1406
+ ]
1407
+ ),
1408
+ hasKids && open ? h(
1409
+ "div",
1410
+ { class: "ui-tree-children" },
1411
+ kids.map(
1412
+ (c, i) => h(VspTreeNode, {
1413
+ key: i,
1414
+ node: c,
1415
+ expanded: props.expanded,
1416
+ selected: props.selected,
1417
+ toggle: props.toggle,
1418
+ select: props.select
1419
+ })
1420
+ )
1421
+ ) : null
1422
+ ]);
1423
+ };
1424
+ }
1425
+ });
1426
+ var Tree = defineComponent({
1427
+ name: "VspTree",
1428
+ props: {
1429
+ data: { type: Array, default: () => [] },
1430
+ defaultExpanded: { type: Array, default: () => [] }
1431
+ },
1432
+ setup(props) {
1433
+ const expanded = ref(new Set(props.defaultExpanded));
1434
+ const selected = ref(null);
1435
+ const toggle = (id) => {
1436
+ const n = new Set(expanded.value);
1437
+ if (n.has(id)) n.delete(id);
1438
+ else n.add(id);
1439
+ expanded.value = n;
1440
+ };
1441
+ return () => h(
1442
+ "div",
1443
+ { class: "ui-tree" },
1444
+ props.data.map(
1445
+ (n, i) => h(VspTreeNode, {
1446
+ key: i,
1447
+ node: n,
1448
+ expanded: expanded.value,
1449
+ selected: selected.value,
1450
+ toggle,
1451
+ select: (id) => selected.value = id
1452
+ })
1453
+ )
1454
+ );
1455
+ }
1456
+ });
1457
+ var OTPInput = defineComponent({
1458
+ name: "VspOTPInput",
1459
+ props: {
1460
+ length: { type: Number, default: 6 },
1461
+ modelValue: { type: String, default: "" }
1462
+ },
1463
+ emits: ["update:modelValue"],
1464
+ setup(props, { emit }) {
1465
+ const refs = [];
1466
+ const set = (i, ch) => {
1467
+ const chars = Array.from({ length: props.length }, (_, k) => props.modelValue[k] ?? "");
1468
+ chars[i] = ch.slice(-1);
1469
+ emit("update:modelValue", chars.join(""));
1470
+ if (ch && i < props.length - 1) refs[i + 1]?.focus();
1471
+ };
1472
+ const onKey = (i, e) => {
1473
+ if (e.key === "Backspace" && !props.modelValue[i] && i > 0) refs[i - 1]?.focus();
1474
+ };
1475
+ return () => h(
1476
+ "div",
1477
+ { class: "ui-otp" },
1478
+ Array.from(
1479
+ { length: props.length },
1480
+ (_, i) => h("input", {
1481
+ key: i,
1482
+ ref: (el) => {
1483
+ refs[i] = el;
1484
+ },
1485
+ inputmode: "numeric",
1486
+ maxlength: 1,
1487
+ value: props.modelValue[i] ?? "",
1488
+ onInput: (e) => set(i, e.target.value.replace(/\D/g, "")),
1489
+ onKeydown: (e) => onKey(i, e)
1490
+ })
1491
+ )
1492
+ );
1493
+ }
1494
+ });
1495
+ function niceNum(n) {
1496
+ if (Math.abs(n) >= 1e6) return (n / 1e6).toFixed(n % 1e6 === 0 ? 0 : 1) + "M";
1497
+ if (Math.abs(n) >= 1e3) return (n / 1e3).toFixed(n % 1e3 === 0 ? 0 : 1) + "k";
1498
+ return String(n);
1499
+ }
1500
+ var AreaChart = defineComponent({
1501
+ name: "VspAreaChart",
1502
+ props: {
1503
+ series: { type: Array, default: () => [] },
1504
+ labels: { type: Array, default: void 0 },
1505
+ width: { type: Number, default: 760 },
1506
+ height: { type: Number, default: 260 },
1507
+ color: { type: String, default: "var(--accent)" },
1508
+ color2: { type: String, default: "var(--accent-2)" },
1509
+ dual: Boolean
1510
+ },
1511
+ setup(props) {
1512
+ const gid = "ac" + useId().replace(/[^a-zA-Z0-9]/g, "");
1513
+ const txt = (x, y, anchor, val) => h(
1514
+ "text",
1515
+ {
1516
+ x,
1517
+ y,
1518
+ "text-anchor": anchor,
1519
+ "font-size": "10",
1520
+ fill: "var(--text-faint)",
1521
+ "font-family": "var(--font-mono)"
1522
+ },
1523
+ val
1524
+ );
1525
+ return () => {
1526
+ const w = props.width;
1527
+ const height = props.height;
1528
+ const padL = 38;
1529
+ const padB = 26;
1530
+ const padT = 12;
1531
+ const padR = 8;
1532
+ const innerW = Math.max(10, w - padL - padR);
1533
+ const innerH = height - padB - padT;
1534
+ const s0 = props.series[0] ?? [];
1535
+ const s1 = props.series[1];
1536
+ const all = props.dual && s1 ? [...s0, ...s1] : s0;
1537
+ const max = Math.max(...all, 0) * 1.12;
1538
+ const rng = max || 1;
1539
+ const sx = (i, len) => padL + i / Math.max(1, len - 1) * innerW;
1540
+ const sy = (v) => padT + innerH - v / rng * innerH;
1541
+ const mkPts = (arr) => arr.map((v, i) => [sx(i, arr.length), sy(v)]);
1542
+ const lines = (props.dual && s1 ? [s0, s1] : [s0]).map(mkPts);
1543
+ const yTicks = 4;
1544
+ const grid = Array.from({ length: yTicks + 1 }, (_, i) => {
1545
+ const y = sy(max / yTicks * i);
1546
+ return h("g", { key: "g" + i }, [
1547
+ h("line", {
1548
+ x1: padL,
1549
+ x2: w - padR,
1550
+ y1: y,
1551
+ y2: y,
1552
+ stroke: "var(--grid-line)",
1553
+ "stroke-width": "1"
1554
+ }),
1555
+ txt(padL - 8, y + 3.5, "end", niceNum(Math.round(max / yTicks * i)))
1556
+ ]);
1557
+ });
1558
+ const lbls = props.labels ? props.labels.map(
1559
+ (lb, i) => i % Math.ceil(props.labels.length / 7) === 0 ? txt(sx(i, props.labels.length), height - 8, "middle", lb) : null
1560
+ ) : [];
1561
+ const lineEls = lines.map((pts, li) => {
1562
+ const stroke = li === 0 ? props.color : props.color2;
1563
+ const lastPt = pts[pts.length - 1];
1564
+ const firstPt = pts[0];
1565
+ return h("g", { key: "ln" + li }, [
1566
+ li === 0 && firstPt && lastPt ? h("path", {
1567
+ d: `${smoothPath(pts)} L ${lastPt[0]} ${padT + innerH} L ${firstPt[0]} ${padT + innerH} Z`,
1568
+ fill: `url(#${gid})`
1569
+ }) : null,
1570
+ h("path", {
1571
+ d: smoothPath(pts),
1572
+ fill: "none",
1573
+ stroke,
1574
+ "stroke-width": "2.4",
1575
+ "stroke-linecap": "round",
1576
+ "stroke-dasharray": li === 1 ? "5 5" : void 0,
1577
+ style: { opacity: li === 1 ? 0.7 : 1 }
1578
+ })
1579
+ ]);
1580
+ });
1581
+ return h("svg", { width: w, height, style: { display: "block" } }, [
1582
+ h("defs", null, [
1583
+ h("linearGradient", { id: gid, x1: "0", x2: "0", y1: "0", y2: "1" }, [
1584
+ h("stop", { offset: "0", "stop-color": props.color, "stop-opacity": "0.22" }),
1585
+ h("stop", { offset: "1", "stop-color": props.color, "stop-opacity": "0" })
1586
+ ])
1587
+ ]),
1588
+ ...grid,
1589
+ ...lbls,
1590
+ ...lineEls
1591
+ ]);
1592
+ };
1593
+ }
1594
+ });
1595
+ var BarChart = defineComponent({
1596
+ name: "VspBarChart",
1597
+ props: {
1598
+ data: { type: Array, default: () => [] },
1599
+ labels: { type: Array, default: void 0 },
1600
+ width: { type: Number, default: 620 },
1601
+ height: { type: Number, default: 240 },
1602
+ color: { type: String, default: "var(--accent)" }
1603
+ },
1604
+ setup(props) {
1605
+ return () => {
1606
+ const w = props.width;
1607
+ const height = props.height;
1608
+ const padL = 34;
1609
+ const padB = 26;
1610
+ const padT = 10;
1611
+ const innerW = Math.max(10, w - padL - 8);
1612
+ const innerH = height - padB - padT;
1613
+ const max = Math.max(...props.data, 0) * 1.15 || 1;
1614
+ const bw = innerW / (props.data.length || 1);
1615
+ const grid = [0, 0.5, 1].map((f, i) => {
1616
+ const y = padT + innerH - f * innerH;
1617
+ return h("g", { key: "g" + i }, [
1618
+ h("line", { x1: padL, x2: w - 8, y1: y, y2: y, stroke: "var(--grid-line)" }),
1619
+ h(
1620
+ "text",
1621
+ {
1622
+ x: padL - 8,
1623
+ y: y + 3.5,
1624
+ "text-anchor": "end",
1625
+ "font-size": "10",
1626
+ fill: "var(--text-faint)",
1627
+ "font-family": "var(--font-mono)"
1628
+ },
1629
+ niceNum(Math.round(max * f))
1630
+ )
1631
+ ]);
1632
+ });
1633
+ const bars = props.data.map((v, i) => {
1634
+ const bh = v / max * innerH;
1635
+ const x = padL + i * bw + bw * 0.18;
1636
+ const bwi = bw * 0.64;
1637
+ return h("g", { key: "b" + i }, [
1638
+ h("rect", {
1639
+ x,
1640
+ y: padT + innerH - bh,
1641
+ width: bwi,
1642
+ height: bh,
1643
+ rx: "4",
1644
+ fill: `color-mix(in oklab, ${props.color} 78%, transparent)`
1645
+ }),
1646
+ props.labels?.[i] != null ? h(
1647
+ "text",
1648
+ {
1649
+ x: x + bwi / 2,
1650
+ y: height - 8,
1651
+ "text-anchor": "middle",
1652
+ "font-size": "10",
1653
+ fill: "var(--text-faint)",
1654
+ "font-family": "var(--font-mono)"
1655
+ },
1656
+ props.labels[i]
1657
+ ) : null
1658
+ ]);
1659
+ });
1660
+ return h("svg", { width: w, height, style: { display: "block" } }, [...grid, ...bars]);
1661
+ };
1662
+ }
1663
+ });
1342
1664
  export {
1343
1665
  Accordion,
1344
1666
  Alert,
1667
+ AreaChart,
1345
1668
  Avatar,
1346
1669
  AvatarGroup,
1347
1670
  Badge,
1348
1671
  Banner,
1672
+ BarChart,
1349
1673
  Breadcrumb,
1350
1674
  Button,
1351
1675
  Card,
@@ -1364,6 +1688,7 @@ export {
1364
1688
  Kbd,
1365
1689
  NativeSelect,
1366
1690
  NumberStepper,
1691
+ OTPInput,
1367
1692
  Pagination,
1368
1693
  Progress,
1369
1694
  Radio,
@@ -1381,6 +1706,8 @@ export {
1381
1706
  Tag,
1382
1707
  Textarea,
1383
1708
  Timeline,
1709
+ Tree,
1710
+ niceNum,
1384
1711
  smoothPath
1385
1712
  };
1386
1713
  //# sourceMappingURL=index.js.map