@zovaris/sephiro 0.10.0 → 0.12.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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { cn } from "cn";
2
2
  import { Fragment, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
4
- import { ArrowDownIcon, ArrowUpRightIcon, ArrowsHorizontalIcon, CaretDownIcon, CaretLeftIcon, CaretRightIcon, CaretUpIcon, CheckIcon, FileCodeIcon, FileIcon, FileTextIcon, ImageIcon, InfoIcon, MagnifyingGlassIcon, MinusIcon, MusicNotesIcon, PlusIcon, TrayIcon, VideoIcon, WarningIcon, XIcon } from "@phosphor-icons/react";
4
+ import { ArrowDownIcon, ArrowUpIcon, ArrowUpRightIcon, ArrowsHorizontalIcon, CalendarBlankIcon, CaretDownIcon, CaretLeftIcon, CaretRightIcon, CaretUpIcon, CheckIcon, FileCodeIcon, FileIcon, FileTextIcon, ImageIcon, InfoIcon, MagnifyingGlassIcon, MinusIcon, MusicNotesIcon, PlusIcon, StopIcon, TrayIcon, VideoIcon, WarningIcon, XIcon } from "@phosphor-icons/react";
5
5
  import { createPortal } from "react-dom";
6
6
  import { Toaster, toast } from "sonner";
7
7
  //#region src/lib/node.ts
@@ -256,9 +256,14 @@ const SPEED_TOKEN = {
256
256
  };
257
257
  /** Extra time granted to an exit animation so React never cuts it short. */
258
258
  const EXIT_FRAME_BUDGET = 40;
259
- /** Parses a CSS time string ("180ms", "0.18s", "0ms") into milliseconds. */
259
+ /**
260
+ * Parses a CSS time string ("180ms", "0.18s", "0ms") into milliseconds.
261
+ *
262
+ * The leading digit is optional because a minifier shortens `180ms` to `.18s`
263
+ * in production, and that is what `getComputedStyle` gives back there.
264
+ */
260
265
  function parseDurationMs(value) {
261
- const match = value.trim().match(/^(\d+(?:\.\d+)?)(ms|s)?$/);
266
+ const match = value.trim().match(/^(\d*\.?\d+)(ms|s)?$/);
262
267
  if (!match) return 0;
263
268
  const amount = Number.parseFloat(match[1]);
264
269
  if (!Number.isFinite(amount) || amount <= 0) return 0;
@@ -413,13 +418,15 @@ function Badge({ variant = "neutral", size = "sm", onRemove, removeLabel, classN
413
418
  }
414
419
  //#endregion
415
420
  //#region src/atoms/Spinner/index.tsx
416
- function Spinner({ size = "md", label, className, ...props }) {
421
+ function Spinner({ size = "md", label, variant = "ring", className, ...props }) {
417
422
  return /* @__PURE__ */ jsx("span", {
418
423
  ...node(props),
419
- className: cn("sph-spinner", `sph-spinner--${size}`, className),
424
+ className: cn("sph-spinner", `sph-spinner--${size}`, variant === "dots" && "sph-spinner--dots", className),
425
+ "data-variant": variant === "dots" ? "dots" : void 0,
420
426
  role: label ? "status" : void 0,
421
427
  "aria-label": label,
422
- "aria-hidden": label ? void 0 : true
428
+ "aria-hidden": label ? void 0 : true,
429
+ children: variant === "dots" && /* @__PURE__ */ jsx("span", { "aria-hidden": "true" })
423
430
  });
424
431
  }
425
432
  //#endregion
@@ -1060,7 +1067,7 @@ const DAYS_IN_MONTH = [
1060
1067
  30,
1061
1068
  31
1062
1069
  ];
1063
- const pad = (value) => String(value).padStart(2, "0");
1070
+ const pad$1 = (value) => String(value).padStart(2, "0");
1064
1071
  function isLeapYear(year) {
1065
1072
  return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
1066
1073
  }
@@ -1074,13 +1081,13 @@ function shiftMonth(month, delta) {
1074
1081
  const index = mon - 1 + delta;
1075
1082
  const nextYear = year + Math.floor(index / 12);
1076
1083
  const nextMonth = (index % 12 + 12) % 12;
1077
- return `${nextYear}-${pad(nextMonth + 1)}`;
1084
+ return `${nextYear}-${pad$1(nextMonth + 1)}`;
1078
1085
  }
1079
1086
  /** Shifts a `YYYY-MM-DD` day by a number of days (UTC math, timezone safe). */
1080
1087
  function shiftDay(day, delta) {
1081
1088
  const [year, mon, date] = day.split("-").map(Number);
1082
1089
  const next = new Date(Date.UTC(year, mon - 1, date + delta));
1083
- return `${next.getUTCFullYear()}-${pad(next.getUTCMonth() + 1)}-${pad(next.getUTCDate())}`;
1090
+ return `${next.getUTCFullYear()}-${pad$1(next.getUTCMonth() + 1)}-${pad$1(next.getUTCDate())}`;
1084
1091
  }
1085
1092
  /**
1086
1093
  * Grid cells for a month: leading blanks for the offset, then one
@@ -1090,13 +1097,13 @@ function monthGrid(month, weekStartsOn) {
1090
1097
  const [year, mon] = month.split("-").map(Number);
1091
1098
  const offset = (new Date(Date.UTC(year, mon - 1, 1)).getUTCDay() - weekStartsOn + 7) % 7;
1092
1099
  const cells = Array.from({ length: offset }, () => null);
1093
- for (let day = 1; day <= daysInMonth(month); day++) cells.push(`${month}-${pad(day)}`);
1100
+ for (let day = 1; day <= daysInMonth(month); day++) cells.push(`${month}-${pad$1(day)}`);
1094
1101
  return cells;
1095
1102
  }
1096
1103
  function shiftMonthDay(day, delta) {
1097
1104
  const month = shiftMonth(day.slice(0, 7), delta);
1098
1105
  const date = Math.min(Number(day.slice(8, 10)), daysInMonth(month));
1099
- return `${month}-${pad(date)}`;
1106
+ return `${month}-${pad$1(date)}`;
1100
1107
  }
1101
1108
  function weekday(day) {
1102
1109
  const [year, mon, date] = day.split("-").map(Number);
@@ -1127,7 +1134,7 @@ function rangeSpan(range, hover = null) {
1127
1134
  }
1128
1135
  function localToday() {
1129
1136
  const now = /* @__PURE__ */ new Date();
1130
- return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
1137
+ return `${now.getFullYear()}-${pad$1(now.getMonth() + 1)}-${pad$1(now.getDate())}`;
1131
1138
  }
1132
1139
  const EMPTY_RANGE = {
1133
1140
  start: null,
@@ -3588,6 +3595,23 @@ function Delta({ value, format = signed, className, ...props }) {
3588
3595
  function firstEnabled(items) {
3589
3596
  return items.find((item) => !item.disabled)?.value;
3590
3597
  }
3598
+ /** The enabled tab a key press moves to, or undefined if the key does nothing. */
3599
+ function tabTarget(items, index, key, vertical) {
3600
+ const enabled = items.flatMap((item, position) => item.disabled ? [] : [position]);
3601
+ if (key === "Home") return enabled[0];
3602
+ if (key === "End") return enabled[enabled.length - 1];
3603
+ if (![
3604
+ "ArrowLeft",
3605
+ "ArrowRight",
3606
+ "ArrowUp",
3607
+ "ArrowDown"
3608
+ ].includes(key)) return void 0;
3609
+ const direction = vertical ? key === "ArrowDown" ? 1 : -1 : key === "ArrowRight" ? 1 : -1;
3610
+ for (let step = 1; step <= items.length; step += 1) {
3611
+ const next = (index + step * direction + items.length) % items.length;
3612
+ if (!items[next]?.disabled) return next;
3613
+ }
3614
+ }
3591
3615
  function Tabs({ items, value, defaultValue, onValueChange, children, ariaLabel = "Tabs", orientation = "horizontal", className }) {
3592
3616
  const generatedId = useId();
3593
3617
  const listRef = useRef(null);
@@ -3601,22 +3625,11 @@ function Tabs({ items, value, defaultValue, onValueChange, children, ariaLabel =
3601
3625
  onValueChange?.(nextValue);
3602
3626
  };
3603
3627
  const move = (event, index) => {
3604
- const direction = orientation === "vertical" ? event.key === "ArrowDown" ? 1 : -1 : event.key === "ArrowRight" ? 1 : -1;
3605
- if (![
3606
- "ArrowLeft",
3607
- "ArrowRight",
3608
- "ArrowUp",
3609
- "ArrowDown"
3610
- ].includes(event.key)) return;
3628
+ const next = tabTarget(items, index, event.key, orientation === "vertical");
3629
+ if (next === void 0) return;
3611
3630
  event.preventDefault();
3612
- for (let step = 1; step <= items.length; step += 1) {
3613
- const next = (index + step * direction + items.length) % items.length;
3614
- if (!items[next]?.disabled) {
3615
- setValue(items[next].value);
3616
- document.getElementById(`${generatedId}-${next}`)?.focus();
3617
- return;
3618
- }
3619
- }
3631
+ setValue(items[next].value);
3632
+ document.getElementById(`${generatedId}-${next}`)?.focus();
3620
3633
  };
3621
3634
  const panelId = `${generatedId}-panel`;
3622
3635
  useIsoLayoutEffect(() => {
@@ -3776,6 +3789,466 @@ function Timeline({ items, label = "Timeline", className, ...props }) {
3776
3789
  });
3777
3790
  }
3778
3791
  //#endregion
3792
+ //#region src/molecules/TreeView/index.tsx
3793
+ /** Rows in display order, descending only into expanded branches. */
3794
+ function visibleRows(items, expanded) {
3795
+ const rows = [];
3796
+ const walk = (nodes, level, parent) => {
3797
+ nodes.forEach((item, index) => {
3798
+ rows.push({
3799
+ item,
3800
+ level,
3801
+ parent,
3802
+ setSize: nodes.length,
3803
+ posInSet: index + 1
3804
+ });
3805
+ if (item.children?.length && expanded.has(item.value)) walk(item.children, level + 1, item.value);
3806
+ });
3807
+ };
3808
+ walk(items, 1);
3809
+ return rows;
3810
+ }
3811
+ /** What a key press asks for at the focused row, or undefined if it does nothing. */
3812
+ function treeStep(rows, index, key, expanded) {
3813
+ const row = rows[index];
3814
+ if (!row) return void 0;
3815
+ const { value } = row.item;
3816
+ const branch = (row.item.children?.length ?? 0) > 0;
3817
+ const open = expanded.has(value);
3818
+ switch (key) {
3819
+ case "ArrowDown": return {
3820
+ type: "focus",
3821
+ index: Math.min(index + 1, rows.length - 1)
3822
+ };
3823
+ case "ArrowUp": return {
3824
+ type: "focus",
3825
+ index: Math.max(index - 1, 0)
3826
+ };
3827
+ case "Home": return {
3828
+ type: "focus",
3829
+ index: 0
3830
+ };
3831
+ case "End": return {
3832
+ type: "focus",
3833
+ index: rows.length - 1
3834
+ };
3835
+ case "ArrowRight":
3836
+ if (branch && !open) return {
3837
+ type: "expand",
3838
+ value
3839
+ };
3840
+ if (branch && open) return {
3841
+ type: "focus",
3842
+ index: index + 1
3843
+ };
3844
+ return;
3845
+ case "ArrowLeft":
3846
+ if (branch && open) return {
3847
+ type: "collapse",
3848
+ value
3849
+ };
3850
+ if (row.parent !== void 0) return {
3851
+ type: "focus",
3852
+ index: rows.findIndex((entry) => entry.item.value === row.parent)
3853
+ };
3854
+ return;
3855
+ case "Enter":
3856
+ case " ": return {
3857
+ type: "select",
3858
+ value
3859
+ };
3860
+ default: return;
3861
+ }
3862
+ }
3863
+ function TreeView({ items, label, defaultExpanded = [], selected, defaultSelected, onSelect, className, ...props }) {
3864
+ const generatedId = useId();
3865
+ const [expandedValues, setExpandedValues] = useState(defaultExpanded);
3866
+ const [uncontrolled, setUncontrolled] = useState(defaultSelected);
3867
+ const [focusValue, setFocusValue] = useState();
3868
+ const selectedValue = selected ?? uncontrolled;
3869
+ const expanded = new Set(expandedValues);
3870
+ const rows = visibleRows(items, expanded);
3871
+ const tabStop = Math.max(0, rows.findIndex((row) => row.item.value === (focusValue ?? selectedValue)));
3872
+ const focusRow = (index) => {
3873
+ const row = rows[index];
3874
+ if (!row) return;
3875
+ setFocusValue(row.item.value);
3876
+ document.getElementById(`${generatedId}-${index}`)?.focus();
3877
+ };
3878
+ const setOpen = (value, open) => setExpandedValues((current) => open ? [...current.filter((entry) => entry !== value), value] : current.filter((entry) => entry !== value));
3879
+ const choose = (value) => {
3880
+ setUncontrolled(value);
3881
+ onSelect?.(value);
3882
+ };
3883
+ const handleKey = (event, index) => {
3884
+ const step = treeStep(rows, index, event.key, expanded);
3885
+ if (!step) return;
3886
+ event.preventDefault();
3887
+ if (step.type === "focus") focusRow(step.index);
3888
+ else if (step.type === "expand") setOpen(step.value, true);
3889
+ else if (step.type === "collapse") setOpen(step.value, false);
3890
+ else if (!rows[index].item.disabled) choose(step.value);
3891
+ };
3892
+ const handleClick = (row) => {
3893
+ if (row.item.disabled) return;
3894
+ if (row.item.children?.length) setOpen(row.item.value, !expanded.has(row.item.value));
3895
+ setFocusValue(row.item.value);
3896
+ choose(row.item.value);
3897
+ };
3898
+ return /* @__PURE__ */ jsx("ul", {
3899
+ ...node(props),
3900
+ role: "tree",
3901
+ "aria-label": label,
3902
+ className: cn("sph-tree", className),
3903
+ children: rows.map((row, index) => {
3904
+ const { item } = row;
3905
+ const branch = (item.children?.length ?? 0) > 0;
3906
+ const open = expanded.has(item.value);
3907
+ const isSelected = selectedValue === item.value;
3908
+ return /* @__PURE__ */ jsx("li", {
3909
+ id: `${generatedId}-${index}`,
3910
+ role: "treeitem",
3911
+ className: "sph-tree__item",
3912
+ "aria-level": row.level,
3913
+ "aria-setsize": row.setSize,
3914
+ "aria-posinset": row.posInSet,
3915
+ "aria-expanded": branch ? open : void 0,
3916
+ "aria-selected": isSelected,
3917
+ "aria-disabled": item.disabled || void 0,
3918
+ tabIndex: index === tabStop ? 0 : -1,
3919
+ "data-selected": isSelected || void 0,
3920
+ style: { "--sph-tree-level": String(row.level - 1) },
3921
+ onKeyDown: (event) => handleKey(event, index),
3922
+ onClick: () => handleClick(row),
3923
+ children: /* @__PURE__ */ jsxs("div", {
3924
+ className: "sph-tree__row",
3925
+ children: [/* @__PURE__ */ jsx("span", {
3926
+ className: "sph-tree__chevron",
3927
+ "aria-hidden": "true",
3928
+ "data-open": open || void 0,
3929
+ children: branch && /* @__PURE__ */ jsx(CaretRightIcon, {
3930
+ size: 12,
3931
+ weight: "bold"
3932
+ })
3933
+ }), /* @__PURE__ */ jsx("span", {
3934
+ className: "sph-tree__label",
3935
+ children: node(item.label)
3936
+ })]
3937
+ })
3938
+ }, item.value);
3939
+ })
3940
+ });
3941
+ }
3942
+ //#endregion
3943
+ //#region src/molecules/Carousel/index.tsx
3944
+ /** The slide a key press moves to, or undefined if the key does nothing. Slides wrap at both ends. */
3945
+ function slideAfter(current, count, key) {
3946
+ if (count === 0) return void 0;
3947
+ if (key === "ArrowRight") return (current + 1) % count;
3948
+ if (key === "ArrowLeft") return (current - 1 + count) % count;
3949
+ if (key === "Home") return 0;
3950
+ if (key === "End") return count - 1;
3951
+ }
3952
+ function Carousel({ slides, label, index, defaultIndex = 0, onIndexChange, className, ...props }) {
3953
+ const [uncontrolled, setUncontrolled] = useState(defaultIndex);
3954
+ const count = slides.length;
3955
+ const current = count === 0 ? 0 : Math.min(Math.max(index ?? uncontrolled, 0), count - 1);
3956
+ const go = (next) => {
3957
+ setUncontrolled(next);
3958
+ onIndexChange?.(next);
3959
+ };
3960
+ const handleKey = (event) => {
3961
+ if (event.target.closest?.("input, textarea, select, [contenteditable='true']")) return;
3962
+ const next = slideAfter(current, count, event.key);
3963
+ if (next === void 0) return;
3964
+ event.preventDefault();
3965
+ go(next);
3966
+ };
3967
+ return /* @__PURE__ */ jsxs("section", {
3968
+ ...node(props),
3969
+ role: "region",
3970
+ "aria-roledescription": "carousel",
3971
+ "aria-label": label,
3972
+ className: cn("sph-carousel", className),
3973
+ onKeyDown: handleKey,
3974
+ children: [/* @__PURE__ */ jsx("div", {
3975
+ className: "sph-carousel__viewport",
3976
+ children: slides.map((slide, position) => /* @__PURE__ */ jsx("div", {
3977
+ role: "group",
3978
+ "aria-roledescription": "slide",
3979
+ "aria-label": `${position + 1} of ${count}`,
3980
+ className: "sph-carousel__slide",
3981
+ hidden: position !== current,
3982
+ children: node(slide)
3983
+ }, `slide-${position}`))
3984
+ }), /* @__PURE__ */ jsxs("div", {
3985
+ className: "sph-carousel__controls",
3986
+ children: [
3987
+ /* @__PURE__ */ jsx("button", {
3988
+ type: "button",
3989
+ className: "sph-carousel__button",
3990
+ "aria-label": "Previous slide",
3991
+ disabled: count < 2,
3992
+ onClick: () => go((current - 1 + count) % count),
3993
+ children: /* @__PURE__ */ jsx("span", {
3994
+ "aria-hidden": "true",
3995
+ children: /* @__PURE__ */ jsx(CaretLeftIcon, {
3996
+ size: 14,
3997
+ weight: "bold"
3998
+ })
3999
+ })
4000
+ }),
4001
+ /* @__PURE__ */ jsx("div", {
4002
+ className: "sph-carousel__dots",
4003
+ children: slides.map((_, position) => /* @__PURE__ */ jsx("button", {
4004
+ type: "button",
4005
+ className: "sph-carousel__dot",
4006
+ "aria-label": `Show slide ${position + 1}`,
4007
+ "aria-current": position === current ? "true" : void 0,
4008
+ "data-active": position === current || void 0,
4009
+ onClick: () => go(position)
4010
+ }, `dot-${position}`))
4011
+ }),
4012
+ /* @__PURE__ */ jsx("button", {
4013
+ type: "button",
4014
+ className: "sph-carousel__button",
4015
+ "aria-label": "Next slide",
4016
+ disabled: count < 2,
4017
+ onClick: () => go((current + 1) % count),
4018
+ children: /* @__PURE__ */ jsx("span", {
4019
+ "aria-hidden": "true",
4020
+ children: /* @__PURE__ */ jsx(CaretRightIcon, {
4021
+ size: 14,
4022
+ weight: "bold"
4023
+ })
4024
+ })
4025
+ })
4026
+ ]
4027
+ })]
4028
+ });
4029
+ }
4030
+ //#endregion
4031
+ //#region src/molecules/DateRangeField/index.tsx
4032
+ const EMPTY = {
4033
+ start: null,
4034
+ end: null
4035
+ };
4036
+ const pad = (value) => String(value).padStart(2, "0");
4037
+ /** Day, month and year text for a `YYYY-MM-DD` value, or blanks. */
4038
+ function segmentsOf(day) {
4039
+ return day ? [
4040
+ day.slice(8, 10),
4041
+ day.slice(5, 7),
4042
+ day.slice(0, 4)
4043
+ ] : [
4044
+ "",
4045
+ "",
4046
+ ""
4047
+ ];
4048
+ }
4049
+ /** The `YYYY-MM-DD` value when all three segments form a real date. */
4050
+ function dayFromSegments(parts) {
4051
+ const [dd, mm, yyyy] = parts;
4052
+ if (!/^\d{2}$/.test(dd) || !/^\d{2}$/.test(mm) || !/^\d{4}$/.test(yyyy)) return null;
4053
+ const month = Number(mm);
4054
+ const day = Number(dd);
4055
+ if (month < 1 || month > 12 || day < 1) return null;
4056
+ if (day > daysInMonth(`${yyyy}-${mm}`)) return null;
4057
+ return `${yyyy}-${mm}-${dd}`;
4058
+ }
4059
+ /**
4060
+ * Types one digit into a segment. A segment advances once it is full, or
4061
+ * when a lone first digit cannot start a longer value (4 to 9 for days,
4062
+ * 2 to 9 for months).
4063
+ */
4064
+ function typeSegment(parts, part, digit) {
4065
+ const size = part === 2 ? 4 : 2;
4066
+ const current = parts[part];
4067
+ let next = current.length >= size ? digit : `${current}${digit}`;
4068
+ let advance = next.length === size;
4069
+ const maxLeading = part === 0 ? 3 : 1;
4070
+ if (part < 2 && next.length === 1 && Number(next) > maxLeading) {
4071
+ next = `0${next}`;
4072
+ advance = true;
4073
+ }
4074
+ return {
4075
+ parts: parts.map((value, index) => index === part ? next : value),
4076
+ advance
4077
+ };
4078
+ }
4079
+ const wrap = (value, low, high) => low + ((value - low) % (high - low + 1) + (high - low + 1)) % (high - low + 1);
4080
+ /**
4081
+ * Steps one segment up or down. Days and months wrap, years move by one, and
4082
+ * the day is clamped to the length of the resulting month. Blank parts start
4083
+ * from the first day, January, or this year.
4084
+ */
4085
+ function stepSegment(parts, part, delta, today = /* @__PURE__ */ new Date()) {
4086
+ let day = parts[0].length === 2 ? Number(parts[0]) : 1;
4087
+ let month = parts[1].length === 2 ? Number(parts[1]) : 1;
4088
+ let year = parts[2].length === 4 ? Number(parts[2]) : today.getFullYear();
4089
+ if (part === 0) day = wrap(day + delta, 1, daysInMonth(`${year}-${pad(month)}`));
4090
+ if (part === 1) month = wrap(month + delta, 1, 12);
4091
+ if (part === 2) year = Math.min(9999, Math.max(1e3, year + delta));
4092
+ day = Math.min(day, daysInMonth(`${year}-${pad(month)}`));
4093
+ return [
4094
+ pad(day),
4095
+ pad(month),
4096
+ String(year)
4097
+ ];
4098
+ }
4099
+ /** Keeps the earlier date first, the way Calendar orders a picked range. */
4100
+ function orderRange(range) {
4101
+ const { start, end } = range;
4102
+ if (start && end && end < start) return {
4103
+ start: end,
4104
+ end: start
4105
+ };
4106
+ return range;
4107
+ }
4108
+ const SEGMENT_NAMES = [
4109
+ "day",
4110
+ "month",
4111
+ "year"
4112
+ ];
4113
+ const PLACEHOLDERS = [
4114
+ "DD",
4115
+ "MM",
4116
+ "YYYY"
4117
+ ];
4118
+ const ENDPOINT_NAMES = {
4119
+ start: "Start",
4120
+ end: "End"
4121
+ };
4122
+ function DateRangeField({ range, defaultRange, onRangeChange, min, max, label, layout = "split", className, ...props }) {
4123
+ const rootRef = useRef(null);
4124
+ const [uncontrolled, setUncontrolled] = useState(defaultRange ?? EMPTY);
4125
+ const [drafts, setDrafts] = useState({});
4126
+ const current = range ?? uncontrolled;
4127
+ const publish = (next) => {
4128
+ const ordered = orderRange(next);
4129
+ setUncontrolled(ordered);
4130
+ onRangeChange?.(ordered);
4131
+ };
4132
+ const focusSegment = (endpoint, part) => {
4133
+ rootRef.current?.querySelector(`[data-segment="${endpoint}-${part}"]`)?.focus();
4134
+ };
4135
+ const edit = (endpoint, parts) => {
4136
+ const day = dayFromSegments(parts);
4137
+ if (day) {
4138
+ setDrafts((all) => ({
4139
+ ...all,
4140
+ [endpoint]: void 0
4141
+ }));
4142
+ publish({
4143
+ ...current,
4144
+ [endpoint]: day
4145
+ });
4146
+ } else setDrafts((all) => ({
4147
+ ...all,
4148
+ [endpoint]: parts
4149
+ }));
4150
+ };
4151
+ const handleKey = (endpoint, part, event) => {
4152
+ const parts = drafts[endpoint] ?? segmentsOf(current[endpoint]);
4153
+ if (/^\d$/.test(event.key)) {
4154
+ event.preventDefault();
4155
+ const typed = typeSegment(parts, part, event.key);
4156
+ edit(endpoint, typed.parts);
4157
+ if (typed.advance) {
4158
+ if (part < 2) focusSegment(endpoint, part + 1);
4159
+ else if (endpoint === "start") focusSegment("end", 0);
4160
+ }
4161
+ return;
4162
+ }
4163
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
4164
+ event.preventDefault();
4165
+ edit(endpoint, stepSegment(parts, part, event.key === "ArrowUp" ? 1 : -1));
4166
+ return;
4167
+ }
4168
+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
4169
+ event.preventDefault();
4170
+ const next = event.key === "ArrowLeft" ? part - 1 : part + 1;
4171
+ if (next >= 0 && next <= 2) focusSegment(endpoint, next);
4172
+ return;
4173
+ }
4174
+ if (event.key === "Backspace") {
4175
+ event.preventDefault();
4176
+ edit(endpoint, parts.map((value, index) => index === part ? "" : value));
4177
+ }
4178
+ };
4179
+ const endpointField = (endpoint) => /* @__PURE__ */ jsxs("div", {
4180
+ role: "group",
4181
+ "aria-label": `${ENDPOINT_NAMES[endpoint]} date`,
4182
+ className: "sph-date-range__date",
4183
+ children: [/* @__PURE__ */ jsx("span", {
4184
+ className: "sph-date-range__endpoint",
4185
+ "aria-hidden": "true",
4186
+ children: ENDPOINT_NAMES[endpoint]
4187
+ }), (drafts[endpoint] ?? segmentsOf(current[endpoint])).map((value, part) => /* @__PURE__ */ jsxs("span", {
4188
+ className: "sph-date-range__segment-wrap",
4189
+ children: [part > 0 && /* @__PURE__ */ jsx("span", {
4190
+ className: "sph-date-range__sep",
4191
+ "aria-hidden": "true",
4192
+ children: "/"
4193
+ }), /* @__PURE__ */ jsx("input", {
4194
+ type: "text",
4195
+ inputMode: "numeric",
4196
+ autoComplete: "off",
4197
+ className: "sph-date-range__segment",
4198
+ "data-segment": `${endpoint}-${part}`,
4199
+ "data-part": part,
4200
+ "aria-label": `${ENDPOINT_NAMES[endpoint]} ${SEGMENT_NAMES[part]}`,
4201
+ placeholder: PLACEHOLDERS[part],
4202
+ value,
4203
+ readOnly: true,
4204
+ onKeyDown: (event) => handleKey(endpoint, part, event)
4205
+ })]
4206
+ }, part))]
4207
+ });
4208
+ return /* @__PURE__ */ jsxs("div", {
4209
+ ...node(props),
4210
+ ref: rootRef,
4211
+ role: "group",
4212
+ "aria-label": label,
4213
+ "data-layout": layout,
4214
+ className: cn("sph-date-range", className),
4215
+ children: [
4216
+ endpointField("start"),
4217
+ /* @__PURE__ */ jsx("span", {
4218
+ className: "sph-date-range__dash",
4219
+ "aria-hidden": "true",
4220
+ children: "–"
4221
+ }),
4222
+ endpointField("end"),
4223
+ /* @__PURE__ */ jsx(Popover, {
4224
+ ariaLabel: "Choose dates",
4225
+ placement: "end",
4226
+ trigger: /* @__PURE__ */ jsx("button", {
4227
+ type: "button",
4228
+ className: "sph-date-range__trigger",
4229
+ "aria-label": "Open calendar",
4230
+ children: /* @__PURE__ */ jsx(CalendarBlankIcon, {
4231
+ size: 16,
4232
+ "aria-hidden": "true"
4233
+ })
4234
+ }),
4235
+ children: /* @__PURE__ */ jsx(Calendar, {
4236
+ mode: "range",
4237
+ months: 2,
4238
+ range: current,
4239
+ min,
4240
+ max,
4241
+ ariaLabel: label,
4242
+ onRangeChange: (next) => {
4243
+ setDrafts({});
4244
+ publish(next);
4245
+ }
4246
+ })
4247
+ })
4248
+ ]
4249
+ });
4250
+ }
4251
+ //#endregion
3779
4252
  //#region src/molecules/Toast/index.tsx
3780
4253
  const toastIcons = {
3781
4254
  success: /* @__PURE__ */ jsx("span", {
@@ -4208,188 +4681,211 @@ function Chart({ categories, series, variant = "line", height = 160, smooth = fa
4208
4681
  ...node(props),
4209
4682
  className: cn("sph-chart", className),
4210
4683
  "data-variant": variant,
4211
- children: [showLegend && /* @__PURE__ */ jsx("figcaption", {
4212
- className: "sph-chart__legend",
4213
- "aria-label": "Series",
4214
- children: series.map((entry, index) => {
4215
- const isHidden = hidden.has(index);
4216
- return /* @__PURE__ */ jsxs("button", {
4217
- type: "button",
4218
- className: "sph-chart__legend-item",
4219
- "aria-pressed": !isHidden,
4220
- "data-hidden": isHidden || void 0,
4221
- onClick: () => toggle(index),
4222
- children: [/* @__PURE__ */ jsx("span", {
4223
- className: "sph-chart__legend-dot",
4224
- style: { background: TONE_VAR[resolved[index].tone] },
4225
- "aria-hidden": "true"
4226
- }), entry.name]
4227
- }, `legend-${entry.name}-${index}`);
4228
- })
4229
- }), /* @__PURE__ */ jsxs("div", {
4230
- className: "sph-chart__plot",
4231
- role: "img",
4232
- "aria-label": summary,
4233
- style: { gridTemplateRows: `${height}px auto` },
4234
- children: [
4235
- /* @__PURE__ */ jsx("div", {
4236
- className: "sph-chart__yaxis",
4237
- style: {
4238
- width: `calc(${longestTick}ch + 8px)`,
4239
- fontSize: "10px"
4240
- },
4241
- children: tickList.map((tick) => /* @__PURE__ */ jsx("span", {
4242
- style: { bottom: `${scale(tick)}%` },
4243
- children: format(tick)
4244
- }, `y-${tick}`))
4245
- }),
4246
- /* @__PURE__ */ jsxs("div", {
4247
- className: "sph-chart__area",
4248
- style: {
4249
- "--sph-chart-anchor": anchorName,
4250
- "--sph-chart-x": `${pointerX}%`,
4251
- "--sph-chart-y": `${anchorTop}%`
4252
- },
4253
- onPointerMove: (event) => {
4254
- const rect = event.currentTarget.getBoundingClientRect();
4255
- const ratio = rect.width > 0 ? (event.clientX - rect.left) / rect.width : 0;
4256
- setHover(Math.min(count - 1, Math.max(0, Math.floor(ratio * count))));
4257
- },
4258
- onPointerLeave: () => setHover(null),
4259
- children: [
4260
- /* @__PURE__ */ jsx("div", {
4261
- className: "sph-chart__grid",
4262
- "aria-hidden": "true",
4263
- children: tickList.map((tick) => /* @__PURE__ */ jsx("i", { style: { bottom: `${scale(tick)}%` } }, `g-${tick}`))
4264
- }),
4265
- variant === "bar" ? /* @__PURE__ */ jsx("div", {
4266
- className: "sph-chart__bands",
4267
- children: categories.map((_, band) => /* @__PURE__ */ jsx("div", {
4268
- className: "sph-chart__band",
4269
- style: { width: `${bandPct}%` },
4270
- children: shown.map((entry, position) => {
4271
- const value = entry.values[band];
4272
- if (value == null) return null;
4273
- const rect = barRect(0, position, 1, shown.length);
4274
- return /* @__PURE__ */ jsx("div", {
4275
- className: "sph-chart__bar",
4276
- style: {
4277
- left: `${rect.left}%`,
4278
- width: `${rect.width}%`,
4279
- height: `${scale(value)}%`,
4280
- background: TONE_VAR[entry.tone]
4281
- }
4282
- }, `bar-${entry.name}-${entry.tone}`);
4283
- })
4284
- }, `band-${band}`))
4285
- }) : /* @__PURE__ */ jsx("div", {
4286
- className: "sph-chart__series-layer",
4287
- children: /* @__PURE__ */ jsxs("svg", {
4288
- viewBox: "0 0 100 100",
4289
- preserveAspectRatio: "none",
4290
- children: [
4291
- variant === "area" && /* @__PURE__ */ jsx("defs", { children: shown.map((entry) => /* @__PURE__ */ jsxs("linearGradient", {
4292
- id: `${gradientId}-s${entry.index}`,
4293
- x1: "0",
4294
- y1: "0",
4295
- x2: "0",
4296
- y2: "1",
4297
- children: [/* @__PURE__ */ jsx("stop", {
4298
- offset: "0%",
4299
- style: {
4300
- stopColor: TONE_VAR[entry.tone],
4301
- stopOpacity: .32
4302
- }
4303
- }), /* @__PURE__ */ jsx("stop", {
4304
- offset: "100%",
4305
- style: {
4306
- stopColor: TONE_VAR[entry.tone],
4307
- stopOpacity: 0
4308
- }
4309
- })]
4310
- }, `grad-${entry.index}`)) }),
4311
- variant === "area" && shown.map((entry) => pointsFor(entry).map((points, segmentIndex) => /* @__PURE__ */ jsx("path", {
4312
- d: areaPath(points, 100, smooth),
4313
- fill: `url(#${gradientId}-s${entry.index})`
4314
- }, `fill-${entry.index}-${segmentIndex}`))),
4315
- shown.map((entry) => pointsFor(entry).map((points, segmentIndex) => /* @__PURE__ */ jsx("path", {
4316
- className: "sph-chart__line",
4317
- d: linePath(points, smooth),
4318
- fill: "none",
4319
- stroke: TONE_VAR[entry.tone],
4320
- strokeWidth: 1.75,
4321
- strokeLinecap: "round",
4322
- strokeLinejoin: "round",
4323
- vectorEffect: "non-scaling-stroke"
4324
- }, `line-${entry.index}-${segmentIndex}`)))
4325
- ]
4326
- })
4327
- }),
4328
- /* @__PURE__ */ jsx("span", {
4329
- className: "sph-chart__anchor",
4684
+ children: [
4685
+ showLegend && /* @__PURE__ */ jsx("figcaption", {
4686
+ className: "sph-chart__legend",
4687
+ "aria-label": "Series",
4688
+ children: series.map((entry, index) => {
4689
+ const isHidden = hidden.has(index);
4690
+ return /* @__PURE__ */ jsxs("button", {
4691
+ type: "button",
4692
+ className: "sph-chart__legend-item",
4693
+ "aria-pressed": !isHidden,
4694
+ "data-hidden": isHidden || void 0,
4695
+ onClick: () => toggle(index),
4696
+ children: [/* @__PURE__ */ jsx("span", {
4697
+ className: "sph-chart__legend-dot",
4698
+ style: { background: TONE_VAR[resolved[index].tone] },
4330
4699
  "aria-hidden": "true"
4331
- }),
4332
- hover !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4700
+ }), entry.name]
4701
+ }, `legend-${entry.name}-${index}`);
4702
+ })
4703
+ }),
4704
+ /* @__PURE__ */ jsxs("div", {
4705
+ className: "sph-chart__plot",
4706
+ role: "img",
4707
+ "aria-label": summary,
4708
+ style: { gridTemplateRows: `${height}px auto` },
4709
+ children: [
4710
+ /* @__PURE__ */ jsx("div", {
4711
+ className: "sph-chart__yaxis",
4712
+ style: {
4713
+ width: `calc(${longestTick}ch + 8px)`,
4714
+ fontSize: "10px"
4715
+ },
4716
+ children: tickList.map((tick) => /* @__PURE__ */ jsx("span", {
4717
+ style: { bottom: `${scale(tick)}%` },
4718
+ children: format(tick)
4719
+ }, `y-${tick}`))
4720
+ }),
4721
+ /* @__PURE__ */ jsxs("div", {
4722
+ className: "sph-chart__area",
4723
+ style: {
4724
+ "--sph-chart-anchor": anchorName,
4725
+ "--sph-chart-x": `${pointerX}%`,
4726
+ "--sph-chart-y": `${anchorTop}%`
4727
+ },
4728
+ onPointerMove: (event) => {
4729
+ const rect = event.currentTarget.getBoundingClientRect();
4730
+ const ratio = rect.width > 0 ? (event.clientX - rect.left) / rect.width : 0;
4731
+ setHover(Math.min(count - 1, Math.max(0, Math.floor(ratio * count))));
4732
+ },
4733
+ onPointerLeave: () => setHover(null),
4734
+ children: [
4735
+ /* @__PURE__ */ jsx("div", {
4736
+ className: "sph-chart__grid",
4737
+ "aria-hidden": "true",
4738
+ children: tickList.map((tick) => /* @__PURE__ */ jsx("i", { style: { bottom: `${scale(tick)}%` } }, `g-${tick}`))
4739
+ }),
4333
4740
  variant === "bar" ? /* @__PURE__ */ jsx("div", {
4334
- className: "sph-chart__band-tint",
4335
- style: {
4336
- left: `${hover * bandPct}%`,
4337
- width: `${bandPct}%`
4338
- },
4339
- "aria-hidden": "true"
4340
- }, `tint-${hover}`) : /* @__PURE__ */ jsx("div", {
4341
- className: "sph-chart__guide",
4342
- style: { left: `${xPct(hover)}%` },
4741
+ className: "sph-chart__bands",
4742
+ children: categories.map((_, band) => /* @__PURE__ */ jsx("div", {
4743
+ className: "sph-chart__band",
4744
+ style: { width: `${bandPct}%` },
4745
+ children: shown.map((entry, position) => {
4746
+ const value = entry.values[band];
4747
+ if (value == null) return null;
4748
+ const rect = barRect(0, position, 1, shown.length);
4749
+ return /* @__PURE__ */ jsx("div", {
4750
+ className: "sph-chart__bar",
4751
+ style: {
4752
+ left: `${rect.left}%`,
4753
+ width: `${rect.width}%`,
4754
+ height: `${scale(value)}%`,
4755
+ background: TONE_VAR[entry.tone]
4756
+ }
4757
+ }, `bar-${entry.name}-${entry.tone}`);
4758
+ })
4759
+ }, `band-${band}`))
4760
+ }) : /* @__PURE__ */ jsx("div", {
4761
+ className: "sph-chart__series-layer",
4762
+ children: /* @__PURE__ */ jsxs("svg", {
4763
+ viewBox: "0 0 100 100",
4764
+ preserveAspectRatio: "none",
4765
+ children: [
4766
+ variant === "area" && /* @__PURE__ */ jsx("defs", { children: shown.map((entry) => /* @__PURE__ */ jsxs("linearGradient", {
4767
+ id: `${gradientId}-s${entry.index}`,
4768
+ x1: "0",
4769
+ y1: "0",
4770
+ x2: "0",
4771
+ y2: "1",
4772
+ children: [/* @__PURE__ */ jsx("stop", {
4773
+ offset: "0%",
4774
+ style: {
4775
+ stopColor: TONE_VAR[entry.tone],
4776
+ stopOpacity: .32
4777
+ }
4778
+ }), /* @__PURE__ */ jsx("stop", {
4779
+ offset: "100%",
4780
+ style: {
4781
+ stopColor: TONE_VAR[entry.tone],
4782
+ stopOpacity: 0
4783
+ }
4784
+ })]
4785
+ }, `grad-${entry.index}`)) }),
4786
+ variant === "area" && shown.map((entry) => pointsFor(entry).map((points, segmentIndex) => /* @__PURE__ */ jsx("path", {
4787
+ d: areaPath(points, 100, smooth),
4788
+ fill: `url(#${gradientId}-s${entry.index})`
4789
+ }, `fill-${entry.index}-${segmentIndex}`))),
4790
+ shown.map((entry) => pointsFor(entry).map((points, segmentIndex) => /* @__PURE__ */ jsx("path", {
4791
+ className: "sph-chart__line",
4792
+ d: linePath(points, smooth),
4793
+ fill: "none",
4794
+ stroke: TONE_VAR[entry.tone],
4795
+ strokeWidth: 1.75,
4796
+ strokeLinecap: "round",
4797
+ strokeLinejoin: "round",
4798
+ vectorEffect: "non-scaling-stroke"
4799
+ }, `line-${entry.index}-${segmentIndex}`)))
4800
+ ]
4801
+ })
4802
+ }),
4803
+ /* @__PURE__ */ jsx("span", {
4804
+ className: "sph-chart__anchor",
4343
4805
  "aria-hidden": "true"
4344
- }, `guide-${hover}`),
4345
- variant !== "bar" && shown.map((entry) => {
4346
- const value = entry.values[hover];
4347
- if (value == null) return null;
4348
- return /* @__PURE__ */ jsx("span", {
4349
- className: "sph-chart__dot",
4806
+ }),
4807
+ hover !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4808
+ variant === "bar" ? /* @__PURE__ */ jsx("div", {
4809
+ className: "sph-chart__band-tint",
4350
4810
  style: {
4351
- left: `${xPct(hover)}%`,
4352
- top: `${topPct(value)}%`,
4353
- background: TONE_VAR[entry.tone]
4811
+ left: `${hover * bandPct}%`,
4812
+ width: `${bandPct}%`
4354
4813
  },
4355
4814
  "aria-hidden": "true"
4356
- }, `dot-${hover}-${entry.name}-${entry.tone}`);
4357
- }),
4358
- anchor !== void 0 && /* @__PURE__ */ jsx("div", {
4359
- className: "sph-chart__tooltip",
4360
- children: /* @__PURE__ */ jsxs("div", {
4361
- className: "sph-chart__tooltip-card",
4362
- children: [/* @__PURE__ */ jsx("span", {
4363
- className: "sph-chart__tooltip-label",
4364
- children: categories[hover]
4365
- }), shown.map((entry) => {
4366
- const value = entry.values[hover];
4367
- return /* @__PURE__ */ jsxs("span", {
4368
- className: "sph-chart__tooltip-row",
4369
- children: [
4370
- /* @__PURE__ */ jsx("i", {
4371
- style: { background: TONE_VAR[entry.tone] },
4372
- "aria-hidden": "true"
4373
- }),
4374
- /* @__PURE__ */ jsx("span", { children: entry.name }),
4375
- /* @__PURE__ */ jsx("b", { children: value == null ? "–" : format(value) })
4376
- ]
4377
- }, `tip-row-${entry.name}-${entry.tone}`);
4378
- })]
4379
- })
4380
- }, `tip-${hover}`)
4381
- ] })
4382
- ]
4383
- }),
4384
- /* @__PURE__ */ jsx("div", {
4385
- className: "sph-chart__xaxis",
4386
- children: categories.map((category, index) => /* @__PURE__ */ jsx("span", {
4387
- style: { flex: `0 0 ${bandPct}%` },
4815
+ }, `tint-${hover}`) : /* @__PURE__ */ jsx("div", {
4816
+ className: "sph-chart__guide",
4817
+ style: { left: `${xPct(hover)}%` },
4818
+ "aria-hidden": "true"
4819
+ }, `guide-${hover}`),
4820
+ variant !== "bar" && shown.map((entry) => {
4821
+ const value = entry.values[hover];
4822
+ if (value == null) return null;
4823
+ return /* @__PURE__ */ jsx("span", {
4824
+ className: "sph-chart__dot",
4825
+ style: {
4826
+ left: `${xPct(hover)}%`,
4827
+ top: `${topPct(value)}%`,
4828
+ background: TONE_VAR[entry.tone]
4829
+ },
4830
+ "aria-hidden": "true"
4831
+ }, `dot-${hover}-${entry.name}-${entry.tone}`);
4832
+ }),
4833
+ anchor !== void 0 && /* @__PURE__ */ jsx("div", {
4834
+ className: "sph-chart__tooltip",
4835
+ children: /* @__PURE__ */ jsxs("div", {
4836
+ className: "sph-chart__tooltip-card",
4837
+ children: [/* @__PURE__ */ jsx("span", {
4838
+ className: "sph-chart__tooltip-label",
4839
+ children: categories[hover]
4840
+ }), shown.map((entry) => {
4841
+ const value = entry.values[hover];
4842
+ return /* @__PURE__ */ jsxs("span", {
4843
+ className: "sph-chart__tooltip-row",
4844
+ children: [
4845
+ /* @__PURE__ */ jsx("i", {
4846
+ style: { background: TONE_VAR[entry.tone] },
4847
+ "aria-hidden": "true"
4848
+ }),
4849
+ /* @__PURE__ */ jsx("span", { children: entry.name }),
4850
+ /* @__PURE__ */ jsx("b", { children: value == null ? "–" : format(value) })
4851
+ ]
4852
+ }, `tip-row-${entry.name}-${entry.tone}`);
4853
+ })]
4854
+ })
4855
+ }, `tip-${hover}`)
4856
+ ] })
4857
+ ]
4858
+ }),
4859
+ /* @__PURE__ */ jsx("div", {
4860
+ className: "sph-chart__xaxis",
4861
+ children: categories.map((category, index) => /* @__PURE__ */ jsx("span", {
4862
+ style: { flex: `0 0 ${bandPct}%` },
4863
+ children: category
4864
+ }, `x-${category}-${index}`))
4865
+ })
4866
+ ]
4867
+ }),
4868
+ /* @__PURE__ */ jsxs("table", {
4869
+ className: "sph-visually-hidden",
4870
+ children: [
4871
+ /* @__PURE__ */ jsx("caption", { children: summary }),
4872
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
4873
+ scope: "col",
4874
+ children: "Category"
4875
+ }), resolved.map((entry) => /* @__PURE__ */ jsx("th", {
4876
+ scope: "col",
4877
+ children: entry.name
4878
+ }, `head-${entry.index}`))] }) }),
4879
+ /* @__PURE__ */ jsx("tbody", { children: categories.map((category, row) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
4880
+ scope: "row",
4388
4881
  children: category
4389
- }, `x-${category}-${index}`))
4390
- })
4391
- ]
4392
- })]
4882
+ }), resolved.map((entry) => {
4883
+ const value = entry.values[row];
4884
+ return /* @__PURE__ */ jsx("td", { children: value == null ? "–" : format(value) }, `cell-${entry.index}-${row}`);
4885
+ })] }, `row-${row}`)) })
4886
+ ]
4887
+ })
4888
+ ]
4393
4889
  });
4394
4890
  }
4395
4891
  //#endregion
@@ -7685,6 +8181,791 @@ function ChatScroller({ children, itemCount, newCount, threshold = 48, ariaLabel
7685
8181
  });
7686
8182
  }
7687
8183
  //#endregion
7688
- export { Accordion, AnimatedNumber, Attachment, Avatar, AvatarGroup, Badge, Breadcrumb, Button, Calendar, Card, Chart, ChatScroller, Checkbox, Citation, Collapsible, Combobox, CommandPalette, ContextMenu, Delta, Dialog, Drawer, EmptyState, Field, FieldMessage, HoldButton, HoverCard, IconButton, Input, Kbd, MagneticDropzone, Menu, Menubar, MetadataList, Notice, NumberInput, OTPInput, OverflowList, Pagination, PlanCard, Popover, Progress, QuestionCard, RadioGroup, ReasoningSteps, Resizable, Reveal, ScrollArea, SegmentedControl, Select, Separator, SidePanel, Sidebar, Skeleton, Slider, Spinner, Stat, StatGroup, StatusMark, Stepper, StreamingText, Surface, Table, Tabs, TaskList, Textarea, Timeline, Timestamp, Toast, ToastViewport, Toggle, ToolCalls, Toolbar, Tooltip, TooltipGroup, describeDropzoneResult, motionDurationMs, parseDurationMs, toast, usePresence, validateDropzoneFiles };
8184
+ //#region src/organisms/ChatInput/index.tsx
8185
+ function findChatInputTrigger(value, cursor) {
8186
+ const at = Math.max(0, Math.min(cursor, value.length));
8187
+ const start = value.slice(0, at).search(/\S*$/);
8188
+ const marker = value[start];
8189
+ if (marker !== "@" && marker !== "/") return null;
8190
+ let end = at;
8191
+ while (end < value.length && !/\s/.test(value[end])) end += 1;
8192
+ return {
8193
+ kind: marker === "@" ? "mention" : "command",
8194
+ query: value.slice(start + 1, at),
8195
+ start,
8196
+ end
8197
+ };
8198
+ }
8199
+ /** How many recently used entries keep their place at the top of the tray. */
8200
+ const RECENT_LIMIT = 8;
8201
+ /** A label hit always outranks the same query found in the other fields. */
8202
+ const LABEL_BONUS = 20;
8203
+ /**
8204
+ * Keeps the suggestions that match the query, ordered for the tray: recently
8205
+ * used entries first, then the strongest fuzzy match, then the caller's order.
8206
+ *
8207
+ * Labels win over ids, descriptions and keywords, and only label hits are
8208
+ * highlighted, matching CommandPalette and Combobox.
8209
+ */
8210
+ function matchChatInputSuggestions(items, query, recents = []) {
8211
+ const recentRank = new Map(recents.map((id, index) => [id, index]));
8212
+ return items.flatMap((item, order) => {
8213
+ const label = matchText(item.label, query);
8214
+ const hit = label ?? matchText(item.id, query) ?? matchText(item.description ?? "", query) ?? matchText(item.keywords ?? "", query);
8215
+ if (!hit) return [];
8216
+ return [{
8217
+ item,
8218
+ indexes: label?.indexes ?? [],
8219
+ recent: recentRank.get(item.id) ?? recents.length,
8220
+ score: label ? label.score + LABEL_BONUS : hit.score,
8221
+ order
8222
+ }];
8223
+ }).sort((a, b) => a.recent - b.recent || b.score - a.score || a.order - b.order).map(({ item, indexes }) => ({
8224
+ item,
8225
+ indexes
8226
+ }));
8227
+ }
8228
+ function filterChatInputSuggestions(items, query, recents = []) {
8229
+ return matchChatInputSuggestions(items, query, recents).map((match) => match.item);
8230
+ }
8231
+ function replaceChatInputTrigger(value, trigger, replacement) {
8232
+ const suffix = value.slice(trigger.end);
8233
+ const dedupeSpace = replacement.endsWith(" ") && suffix.startsWith(" ");
8234
+ const inserted = dedupeSpace ? replacement.slice(0, -1) : replacement;
8235
+ return {
8236
+ value: `${value.slice(0, trigger.start)}${inserted}${suffix}`,
8237
+ cursor: trigger.start + inserted.length + Number(dedupeSpace)
8238
+ };
8239
+ }
8240
+ function shouldSendOnEnter(event) {
8241
+ return event.key === "Enter" && !event.shiftKey && !event.ctrlKey && !event.metaKey && !event.altKey && !event.isComposing && event.keyCode !== 229;
8242
+ }
8243
+ function canPreviewImage(file) {
8244
+ return /^image\/(png|jpeg|gif|webp|avif|bmp)$/.test(file.type);
8245
+ }
8246
+ function FilePreview({ file, onRemove }) {
8247
+ const [url, setUrl] = useState();
8248
+ const [failed, setFailed] = useState(false);
8249
+ useEffect(() => {
8250
+ setFailed(false);
8251
+ if (!canPreviewImage(file)) {
8252
+ setUrl(void 0);
8253
+ return;
8254
+ }
8255
+ const next = URL.createObjectURL(file);
8256
+ setUrl(next);
8257
+ return () => URL.revokeObjectURL(next);
8258
+ }, [file]);
8259
+ const Icon = iconForFile(file.name);
8260
+ return /* @__PURE__ */ jsxs("li", {
8261
+ className: "sph-chat-input__file",
8262
+ title: file.name,
8263
+ children: [url && !failed ? /* @__PURE__ */ jsx("img", {
8264
+ className: "sph-chat-input__preview",
8265
+ src: url,
8266
+ alt: file.name,
8267
+ onError: () => setFailed(true)
8268
+ }) : /* @__PURE__ */ jsxs("div", {
8269
+ className: "sph-chat-input__file-info",
8270
+ children: [
8271
+ /* @__PURE__ */ jsx(Icon, {
8272
+ size: 22,
8273
+ "aria-hidden": "true"
8274
+ }),
8275
+ /* @__PURE__ */ jsx("span", { children: file.name }),
8276
+ /* @__PURE__ */ jsxs("small", { children: [Math.ceil(file.size / 1024), " KB"] })
8277
+ ]
8278
+ }), onRemove && /* @__PURE__ */ jsx(IconButton, {
8279
+ className: "sph-chat-input__remove",
8280
+ size: "sm",
8281
+ label: `Remove ${file.name}`,
8282
+ icon: /* @__PURE__ */ jsx(XIcon, {
8283
+ size: 14,
8284
+ "aria-hidden": "true"
8285
+ }),
8286
+ onClick: onRemove
8287
+ })]
8288
+ });
8289
+ }
8290
+ function ChatInput({ value, defaultValue = "", onValueChange, files, onFilesChange, onSend, onStop, state = "ready", disabled = false, placeholder = "Message the agent…", label = "Message the agent", sendLabel = "Send message", stopLabel = "Stop response", addFilesLabel = "Add files", mentions = [], commands = [], onMentionSelect, onCommandSelect, mentionLabel = "Files and context", commandLabel = "Commands", tools, hint, error, accept, maxFiles = 5, maxSize = 10485760, onReject, className, onPaste, ...props }) {
8291
+ const [draft, setDraft] = useState(defaultValue);
8292
+ const [localFiles, setLocalFiles] = useState([]);
8293
+ const [announcement, setAnnouncement] = useState("");
8294
+ const picker = useRef(null);
8295
+ const editor = useRef(null);
8296
+ const form = useRef(null);
8297
+ const composing = useRef(false);
8298
+ const [isComposing, setIsComposing] = useState(false);
8299
+ const [cursor, setCursor] = useState((value ?? defaultValue).length);
8300
+ const [activeSuggestion, setActiveSuggestion] = useState(0);
8301
+ const [suggestionsDismissed, setSuggestionsDismissed] = useState(false);
8302
+ const [recents, setRecents] = useState([]);
8303
+ const pendingCursor = useRef(null);
8304
+ const errorId = `${useId()}-error`;
8305
+ const suggestionListId = `${useId()}-suggestions`;
8306
+ const text = value ?? draft;
8307
+ const attachments = files ?? localFiles;
8308
+ const busy = state === "submitting" || state === "streaming";
8309
+ const locked = disabled || busy;
8310
+ const canSend = !locked && (text.trim().length > 0 || attachments.length > 0);
8311
+ const trigger = !isComposing ? findChatInputTrigger(text, cursor) : null;
8312
+ const recentIds = (kind) => recents.flatMap((entry) => {
8313
+ const prefix = `${kind}:`;
8314
+ return entry.startsWith(prefix) ? [entry.slice(prefix.length)] : [];
8315
+ });
8316
+ const suggestions = trigger ? matchChatInputSuggestions(trigger.kind === "mention" ? mentions : commands, trigger.query, recentIds(trigger.kind)) : [];
8317
+ const suggestionItems = suggestions.map((match) => match.item);
8318
+ const suggestionsOpen = Boolean(trigger && suggestionItems.length > 0 && !locked && !suggestionsDismissed);
8319
+ const tray = usePresence(suggestionsOpen, "fast");
8320
+ const lastTray = useRef(null);
8321
+ if (suggestionsOpen && trigger) lastTray.current = {
8322
+ kind: trigger.kind,
8323
+ label: trigger.kind === "mention" ? mentionLabel : commandLabel,
8324
+ matches: suggestions
8325
+ };
8326
+ const trayContent = tray.present ? lastTray.current : null;
8327
+ const enabledSuggestions = suggestionItems.flatMap((item, index) => item.disabled ? [] : [index]);
8328
+ const activeSuggestionIndex = enabledSuggestions.includes(activeSuggestion) ? activeSuggestion : enabledSuggestions[0] ?? -1;
8329
+ useIsoLayoutEffect(() => {
8330
+ if (pendingCursor.current === null) return;
8331
+ const next = pendingCursor.current;
8332
+ pendingCursor.current = null;
8333
+ editor.current?.setSelectionRange(next, next);
8334
+ }, [text]);
8335
+ useIsoLayoutEffect(() => {
8336
+ const textarea = editor.current;
8337
+ if (!textarea || typeof CSS !== "undefined" && CSS.supports("field-sizing", "content")) return;
8338
+ const resize = () => {
8339
+ textarea.style.height = "auto";
8340
+ textarea.style.height = `${textarea.scrollHeight}px`;
8341
+ };
8342
+ resize();
8343
+ if (typeof ResizeObserver === "undefined") return;
8344
+ let width = textarea.clientWidth;
8345
+ const observer = new ResizeObserver(() => {
8346
+ if (textarea.clientWidth !== width) {
8347
+ width = textarea.clientWidth;
8348
+ resize();
8349
+ }
8350
+ });
8351
+ observer.observe(textarea);
8352
+ return () => observer.disconnect();
8353
+ }, [text]);
8354
+ const changeFiles = (next) => {
8355
+ if (files === void 0) setLocalFiles(next);
8356
+ onFilesChange?.(next);
8357
+ };
8358
+ const addFiles = (incoming) => {
8359
+ if (locked) return;
8360
+ const result = validateDropzoneFiles(incoming, {
8361
+ accept,
8362
+ maxSize,
8363
+ maxFiles: Math.max(0, maxFiles - attachments.length)
8364
+ });
8365
+ if (result.accepted.length) changeFiles([...attachments, ...result.accepted]);
8366
+ setAnnouncement(describeDropzoneResult(result));
8367
+ for (const rejected of result.rejected) onReject?.(rejected.files, rejected.reason);
8368
+ };
8369
+ const chooseSuggestion = (item) => {
8370
+ if (!trigger || item.disabled) return;
8371
+ const mention = trigger.kind === "mention";
8372
+ const replacement = mention ? `@${item.insertText ?? item.id} ` : item.insertText ?? "";
8373
+ const next = replaceChatInputTrigger(text, trigger, replacement);
8374
+ pendingCursor.current = next.cursor;
8375
+ setCursor(next.cursor);
8376
+ if (value === void 0) setDraft(next.value);
8377
+ onValueChange?.(next.value);
8378
+ const key = `${trigger.kind}:${item.id}`;
8379
+ setRecents((previous) => [key, ...previous.filter((entry) => entry !== key)].slice(0, RECENT_LIMIT));
8380
+ if (mention) onMentionSelect?.(item);
8381
+ else onCommandSelect?.(item);
8382
+ };
8383
+ const keyDown = (event) => {
8384
+ if (suggestionsOpen && !composing.current && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
8385
+ event.preventDefault();
8386
+ const current = enabledSuggestions.indexOf(activeSuggestionIndex);
8387
+ const offset = event.key === "ArrowDown" ? 1 : -1;
8388
+ const next = enabledSuggestions[(current + offset + enabledSuggestions.length) % enabledSuggestions.length];
8389
+ if (next !== void 0) setActiveSuggestion(next);
8390
+ return;
8391
+ }
8392
+ if (suggestionsOpen && !composing.current && event.key === "Escape") {
8393
+ event.preventDefault();
8394
+ setSuggestionsDismissed(true);
8395
+ return;
8396
+ }
8397
+ if (suggestionsOpen && !composing.current && event.key === "Enter" && activeSuggestionIndex >= 0) {
8398
+ event.preventDefault();
8399
+ chooseSuggestion(suggestionItems[activeSuggestionIndex]);
8400
+ return;
8401
+ }
8402
+ if (!suggestionsOpen && !composing.current && shouldSendOnEnter({
8403
+ key: event.key,
8404
+ shiftKey: event.shiftKey,
8405
+ ctrlKey: event.ctrlKey,
8406
+ metaKey: event.metaKey,
8407
+ altKey: event.altKey,
8408
+ isComposing: event.nativeEvent?.isComposing ?? event.isComposing,
8409
+ keyCode: event.keyCode
8410
+ })) {
8411
+ event.preventDefault();
8412
+ if (canSend && !event.repeat) form.current?.requestSubmit();
8413
+ }
8414
+ };
8415
+ return /* @__PURE__ */ jsxs("form", {
8416
+ ...node(props),
8417
+ ref: form,
8418
+ className: cn("sph-chat-input", className),
8419
+ "data-state": state,
8420
+ "aria-label": label,
8421
+ "data-disabled": disabled || void 0,
8422
+ onPaste: (event) => {
8423
+ onPaste?.(event);
8424
+ if (event.defaultPrevented) return;
8425
+ const incoming = Array.from(event.clipboardData?.files ?? []);
8426
+ if (!incoming.length) return;
8427
+ if (!event.clipboardData?.getData("text/plain")) event.preventDefault();
8428
+ addFiles(incoming);
8429
+ },
8430
+ onSubmit: (event) => {
8431
+ event.preventDefault();
8432
+ if (canSend) onSend({
8433
+ text,
8434
+ files: [...attachments]
8435
+ });
8436
+ },
8437
+ onDragOver: (event) => {
8438
+ if (event.dataTransfer?.types.includes("Files")) event.preventDefault();
8439
+ },
8440
+ onDrop: (event) => {
8441
+ if (!event.dataTransfer?.files.length) return;
8442
+ event.preventDefault();
8443
+ addFiles(Array.from(event.dataTransfer.files));
8444
+ },
8445
+ children: [
8446
+ /* @__PURE__ */ jsx("textarea", {
8447
+ ref: editor,
8448
+ className: "sph-chat-input__textarea",
8449
+ rows: 1,
8450
+ value: text,
8451
+ placeholder,
8452
+ "aria-label": label,
8453
+ disabled,
8454
+ readOnly: busy,
8455
+ "aria-invalid": state === "error" || void 0,
8456
+ "aria-describedby": error !== void 0 ? errorId : void 0,
8457
+ "aria-autocomplete": "list",
8458
+ "aria-haspopup": "listbox",
8459
+ "aria-expanded": suggestionsOpen,
8460
+ "aria-controls": suggestionsOpen ? suggestionListId : void 0,
8461
+ "aria-activedescendant": activeSuggestionIndex >= 0 && suggestionsOpen ? `${suggestionListId}-${activeSuggestionIndex}` : void 0,
8462
+ onSelect: (event) => {
8463
+ setSuggestionsDismissed(false);
8464
+ setActiveSuggestion(0);
8465
+ setCursor(event.currentTarget.selectionStart ?? 0);
8466
+ },
8467
+ onCompositionStart: () => {
8468
+ composing.current = true;
8469
+ setIsComposing(true);
8470
+ },
8471
+ onCompositionEnd: (event) => {
8472
+ composing.current = false;
8473
+ setSuggestionsDismissed(false);
8474
+ setIsComposing(false);
8475
+ setCursor(event.currentTarget.selectionStart ?? 0);
8476
+ },
8477
+ onKeyDown: keyDown,
8478
+ onInput: (event) => {
8479
+ const next = event.currentTarget.value;
8480
+ setSuggestionsDismissed(false);
8481
+ setActiveSuggestion(0);
8482
+ if (value === void 0) setDraft(next);
8483
+ setCursor(event.currentTarget.selectionStart ?? next.length);
8484
+ onValueChange?.(next);
8485
+ }
8486
+ }),
8487
+ trayContent && /* @__PURE__ */ jsxs("div", {
8488
+ ref: tray.ref,
8489
+ className: "sph-chat-input__suggestions",
8490
+ id: suggestionListId,
8491
+ role: "listbox",
8492
+ "data-state": tray.state,
8493
+ "data-kind": trayContent.kind,
8494
+ "aria-label": trayContent.label,
8495
+ children: [/* @__PURE__ */ jsx("span", {
8496
+ className: "sph-chat-input__suggestions-label",
8497
+ "aria-hidden": "true",
8498
+ children: trayContent.label
8499
+ }), trayContent.matches.map(({ item, indexes }, index) => {
8500
+ const mention = trayContent.kind === "mention";
8501
+ const Icon = mention ? iconForFile(item.id) : void 0;
8502
+ return /* @__PURE__ */ jsxs("div", {
8503
+ id: `${suggestionListId}-${index}`,
8504
+ role: "option",
8505
+ "aria-selected": index === activeSuggestionIndex,
8506
+ "aria-disabled": item.disabled || void 0,
8507
+ className: "sph-chat-input__suggestion",
8508
+ "data-active": index === activeSuggestionIndex || void 0,
8509
+ "data-disabled": item.disabled || void 0,
8510
+ style: { "--sph-motion-index": index },
8511
+ onMouseDown: (event) => event.preventDefault(),
8512
+ onClick: () => chooseSuggestion(item),
8513
+ children: [
8514
+ Icon && /* @__PURE__ */ jsx(Icon, {
8515
+ className: "sph-chat-input__suggestion-icon",
8516
+ size: 16,
8517
+ "aria-hidden": "true"
8518
+ }),
8519
+ /* @__PURE__ */ jsxs("span", {
8520
+ className: "sph-chat-input__suggestion-body",
8521
+ children: [/* @__PURE__ */ jsxs("span", {
8522
+ className: "sph-chat-input__suggestion-name",
8523
+ children: [/* @__PURE__ */ jsx("span", {
8524
+ className: "sph-chat-input__suggestion-token",
8525
+ "aria-hidden": "true",
8526
+ children: mention ? "@" : "/"
8527
+ }), /* @__PURE__ */ jsx(Highlight, {
8528
+ text: item.label,
8529
+ indexes
8530
+ })]
8531
+ }), item.description && /* @__PURE__ */ jsx("span", {
8532
+ className: "sph-chat-input__suggestion-description",
8533
+ children: item.description
8534
+ })]
8535
+ }),
8536
+ /* @__PURE__ */ jsx("span", {
8537
+ className: "sph-chat-input__suggestion-enter",
8538
+ "aria-hidden": "true",
8539
+ children: "↵"
8540
+ })
8541
+ ]
8542
+ }, item.id);
8543
+ })]
8544
+ }, trayContent.kind),
8545
+ attachments.length > 0 && /* @__PURE__ */ jsx("ul", {
8546
+ className: "sph-chat-input__files",
8547
+ "aria-label": "Attachments",
8548
+ children: attachments.map((file, index) => /* @__PURE__ */ jsx(FilePreview, {
8549
+ file,
8550
+ onRemove: locked ? void 0 : () => {
8551
+ changeFiles(attachments.filter((_, at) => at !== index));
8552
+ editor.current?.focus();
8553
+ }
8554
+ }, `${index}-${file.name}-${file.lastModified}`))
8555
+ }),
8556
+ /* @__PURE__ */ jsxs("div", {
8557
+ className: "sph-chat-input__rail",
8558
+ children: [
8559
+ /* @__PURE__ */ jsx("input", {
8560
+ ref: picker,
8561
+ type: "file",
8562
+ accept,
8563
+ multiple: true,
8564
+ hidden: true,
8565
+ disabled: locked,
8566
+ onChange: (event) => {
8567
+ addFiles(Array.from(event.currentTarget.files ?? []));
8568
+ event.currentTarget.value = "";
8569
+ }
8570
+ }),
8571
+ /* @__PURE__ */ jsx("div", {
8572
+ className: "sph-chat-input__tools",
8573
+ children: node(tools)
8574
+ }),
8575
+ /* @__PURE__ */ jsxs("div", {
8576
+ className: "sph-chat-input__actions",
8577
+ children: [/* @__PURE__ */ jsx(IconButton, {
8578
+ size: "md",
8579
+ label: addFilesLabel,
8580
+ disabled: locked,
8581
+ icon: /* @__PURE__ */ jsx(PlusIcon, {
8582
+ size: 20,
8583
+ "aria-hidden": "true"
8584
+ }),
8585
+ onClick: () => picker.current?.click()
8586
+ }), busy ? /* @__PURE__ */ jsx(IconButton, {
8587
+ type: "button",
8588
+ size: "md",
8589
+ variant: "solid",
8590
+ label: stopLabel,
8591
+ icon: /* @__PURE__ */ jsx(StopIcon, {
8592
+ size: 18,
8593
+ "aria-hidden": "true"
8594
+ }),
8595
+ disabled: disabled || !onStop,
8596
+ onClick: () => onStop?.()
8597
+ }, "stop") : /* @__PURE__ */ jsx(IconButton, {
8598
+ type: "submit",
8599
+ size: "md",
8600
+ variant: "solid",
8601
+ label: sendLabel,
8602
+ icon: /* @__PURE__ */ jsx(ArrowUpIcon, {
8603
+ size: 20,
8604
+ "aria-hidden": "true"
8605
+ }),
8606
+ disabled: !canSend
8607
+ }, "send")]
8608
+ })
8609
+ ]
8610
+ }),
8611
+ hint !== void 0 && /* @__PURE__ */ jsx("div", {
8612
+ className: "sph-chat-input__hint",
8613
+ children: node(hint)
8614
+ }),
8615
+ error !== void 0 && /* @__PURE__ */ jsx("div", {
8616
+ id: errorId,
8617
+ className: "sph-chat-input__error",
8618
+ role: "alert",
8619
+ children: node(error)
8620
+ }),
8621
+ /* @__PURE__ */ jsx("span", {
8622
+ className: "sph-visually-hidden",
8623
+ role: "status",
8624
+ children: announcement
8625
+ })
8626
+ ]
8627
+ });
8628
+ }
8629
+ //#endregion
8630
+ //#region src/molecules/Message/index.tsx
8631
+ const labels$2 = {
8632
+ streaming: "Responding",
8633
+ complete: "Complete",
8634
+ stopped: "Stopped",
8635
+ error: "Response failed"
8636
+ };
8637
+ function Message({ author, role = "assistant", state = "complete", children, avatar, metadata, actions, error, onRetry, retryLabel = "Retry", statusLabel, className, ...props }) {
8638
+ const heading = useId();
8639
+ return /* @__PURE__ */ jsxs("article", {
8640
+ ...node(props),
8641
+ className: cn("sph-message", className),
8642
+ "data-role": role,
8643
+ "data-state": state,
8644
+ "aria-labelledby": heading,
8645
+ children: [
8646
+ /* @__PURE__ */ jsxs("header", {
8647
+ className: "sph-message__header",
8648
+ children: [
8649
+ node(avatar),
8650
+ /* @__PURE__ */ jsx("span", {
8651
+ id: heading,
8652
+ className: "sph-message__author",
8653
+ children: author
8654
+ }),
8655
+ /* @__PURE__ */ jsx("span", {
8656
+ className: "sph-message__metadata",
8657
+ children: node(metadata)
8658
+ })
8659
+ ]
8660
+ }),
8661
+ /* @__PURE__ */ jsx("div", {
8662
+ className: "sph-message__content",
8663
+ children: node(children)
8664
+ }),
8665
+ /* @__PURE__ */ jsxs("footer", {
8666
+ className: "sph-message__footer",
8667
+ children: [
8668
+ /* @__PURE__ */ jsx("span", {
8669
+ role: "status",
8670
+ className: state === "complete" ? "sph-visually-hidden" : "sph-message__status",
8671
+ children: statusLabel ?? labels$2[state]
8672
+ }),
8673
+ node(actions),
8674
+ (state === "error" || state === "stopped") && onRetry && /* @__PURE__ */ jsx(Button, {
8675
+ size: "sm",
8676
+ variant: "quiet",
8677
+ onClick: onRetry,
8678
+ children: retryLabel
8679
+ })
8680
+ ]
8681
+ }),
8682
+ state === "error" && error !== void 0 && /* @__PURE__ */ jsx("div", {
8683
+ className: "sph-message__error",
8684
+ role: "alert",
8685
+ children: node(error)
8686
+ })
8687
+ ]
8688
+ });
8689
+ }
8690
+ //#endregion
8691
+ //#region src/molecules/ApprovalCard/index.tsx
8692
+ const labels$1 = {
8693
+ pending: "Approval required",
8694
+ submitting: "Sending decision",
8695
+ approved: "Approved",
8696
+ rejected: "Rejected",
8697
+ expired: "Approval expired",
8698
+ error: "Decision failed"
8699
+ };
8700
+ function ApprovalCard({ title, action, target, description, state = "pending", onApprove, onReject, approveLabel = "Approve action", rejectLabel = "Reject", statusLabel, error, className, ...props }) {
8701
+ const id = useId();
8702
+ const actionable = state === "pending" || state === "error";
8703
+ return /* @__PURE__ */ jsxs("div", {
8704
+ ...node(props),
8705
+ className: cn("sph-approval-card", className),
8706
+ "data-state": state,
8707
+ role: "group",
8708
+ "aria-labelledby": `${id}-title`,
8709
+ "aria-describedby": `${id}-details`,
8710
+ children: [
8711
+ /* @__PURE__ */ jsxs("div", {
8712
+ className: "sph-approval-card__header",
8713
+ children: [/* @__PURE__ */ jsx("h3", {
8714
+ id: `${id}-title`,
8715
+ className: "sph-approval-card__title",
8716
+ children: node(title)
8717
+ }), /* @__PURE__ */ jsx("span", {
8718
+ role: "status",
8719
+ className: "sph-approval-card__status",
8720
+ children: statusLabel ?? labels$1[state]
8721
+ })]
8722
+ }),
8723
+ /* @__PURE__ */ jsxs("div", {
8724
+ id: `${id}-details`,
8725
+ className: "sph-approval-card__details",
8726
+ children: [
8727
+ /* @__PURE__ */ jsx("div", {
8728
+ className: "sph-approval-card__action",
8729
+ children: node(action)
8730
+ }),
8731
+ target !== void 0 && /* @__PURE__ */ jsx("div", {
8732
+ className: "sph-approval-card__target",
8733
+ children: node(target)
8734
+ }),
8735
+ description !== void 0 && /* @__PURE__ */ jsx("div", { children: node(description) })
8736
+ ]
8737
+ }),
8738
+ state === "error" && error !== void 0 && /* @__PURE__ */ jsx("div", {
8739
+ role: "alert",
8740
+ children: node(error)
8741
+ }),
8742
+ (actionable || state === "submitting") && /* @__PURE__ */ jsxs("div", {
8743
+ className: "sph-approval-card__footer",
8744
+ children: [/* @__PURE__ */ jsx(Button, {
8745
+ size: "sm",
8746
+ variant: "quiet",
8747
+ disabled: !actionable,
8748
+ onClick: onReject,
8749
+ children: rejectLabel
8750
+ }), /* @__PURE__ */ jsx(Button, {
8751
+ size: "sm",
8752
+ variant: "primary",
8753
+ disabled: !actionable,
8754
+ loading: state === "submitting",
8755
+ onClick: onApprove,
8756
+ children: approveLabel
8757
+ })]
8758
+ })
8759
+ ]
8760
+ });
8761
+ }
8762
+ //#endregion
8763
+ //#region src/molecules/CodeBlock/index.tsx
8764
+ function CodeBlock({ code, language, filename, wrap = false, renderCode, onCopy, copyLabel = "Copy code", copiedLabel = "Copied", copyErrorLabel = "Could not copy code", className, ...props }) {
8765
+ const [copyState, setCopyState] = useState("idle");
8766
+ const copy = async () => {
8767
+ setCopyState("copying");
8768
+ try {
8769
+ if (onCopy) await onCopy(code);
8770
+ else await navigator.clipboard.writeText(code);
8771
+ setCopyState("copied");
8772
+ } catch {
8773
+ setCopyState("error");
8774
+ }
8775
+ };
8776
+ return /* @__PURE__ */ jsxs("figure", {
8777
+ ...node(props),
8778
+ className: cn("sph-code-block", className),
8779
+ "data-wrap": wrap || void 0,
8780
+ children: [
8781
+ /* @__PURE__ */ jsxs("figcaption", {
8782
+ className: "sph-code-block__header",
8783
+ children: [
8784
+ /* @__PURE__ */ jsx("span", { children: filename ?? language ?? "Code" }),
8785
+ filename && language && /* @__PURE__ */ jsx("span", {
8786
+ className: "sph-code-block__language",
8787
+ children: language
8788
+ }),
8789
+ /* @__PURE__ */ jsx(Button, {
8790
+ size: "sm",
8791
+ variant: "quiet",
8792
+ disabled: copyState === "copying",
8793
+ onClick: copy,
8794
+ children: copyLabel
8795
+ })
8796
+ ]
8797
+ }),
8798
+ /* @__PURE__ */ jsx("pre", {
8799
+ className: "sph-code-block__pre",
8800
+ tabIndex: 0,
8801
+ "aria-label": filename ?? language ?? "Code",
8802
+ children: /* @__PURE__ */ jsx("code", { children: renderCode ? node(renderCode(code, language)) : code })
8803
+ }),
8804
+ /* @__PURE__ */ jsx("span", {
8805
+ role: "status",
8806
+ className: copyState === "error" ? "sph-code-block__feedback" : "sph-visually-hidden",
8807
+ children: copyState === "copied" ? copiedLabel : copyState === "error" ? copyErrorLabel : ""
8808
+ })
8809
+ ]
8810
+ });
8811
+ }
8812
+ //#endregion
8813
+ //#region src/molecules/DiffView/index.tsx
8814
+ function diffStats(hunks) {
8815
+ let added = 0;
8816
+ let removed = 0;
8817
+ for (const hunk of hunks) for (const line of hunk.lines) {
8818
+ if (line.type === "added") added++;
8819
+ if (line.type === "removed") removed++;
8820
+ }
8821
+ return {
8822
+ added,
8823
+ removed
8824
+ };
8825
+ }
8826
+ function Hunk({ hunk, contextLimit, expandLabel, collapseLabel }) {
8827
+ const [expanded, setExpanded] = useState(false);
8828
+ const id = useId();
8829
+ const limit = Math.max(0, Math.floor(contextLimit));
8830
+ let context = 0;
8831
+ const visible = hunk.lines.filter((line) => {
8832
+ if (line.type !== "context") {
8833
+ context = 0;
8834
+ return true;
8835
+ }
8836
+ return ++context <= limit;
8837
+ });
8838
+ const hidden = hunk.lines.length - visible.length;
8839
+ const lines = expanded ? hunk.lines : visible;
8840
+ return /* @__PURE__ */ jsxs("section", {
8841
+ className: "sph-diff-view__hunk",
8842
+ "aria-label": hunk.header,
8843
+ children: [/* @__PURE__ */ jsxs("div", {
8844
+ className: "sph-diff-view__hunk-header",
8845
+ children: [/* @__PURE__ */ jsx("code", { children: hunk.header }), hidden > 0 && /* @__PURE__ */ jsx(Button, {
8846
+ size: "sm",
8847
+ variant: "quiet",
8848
+ "aria-expanded": expanded,
8849
+ "aria-controls": id,
8850
+ onClick: () => setExpanded(!expanded),
8851
+ children: expanded ? collapseLabel : `${expandLabel} (${hidden})`
8852
+ })]
8853
+ }), /* @__PURE__ */ jsx("div", {
8854
+ id,
8855
+ className: "sph-diff-view__lines",
8856
+ children: lines.map((line, index) => /* @__PURE__ */ jsxs("div", {
8857
+ className: "sph-diff-view__line",
8858
+ "data-kind": line.type,
8859
+ children: [
8860
+ /* @__PURE__ */ jsx("span", {
8861
+ className: "sph-diff-view__number",
8862
+ children: line.oldLine ?? ""
8863
+ }),
8864
+ /* @__PURE__ */ jsx("span", {
8865
+ className: "sph-diff-view__number",
8866
+ children: line.newLine ?? ""
8867
+ }),
8868
+ /* @__PURE__ */ jsx("span", {
8869
+ className: "sph-diff-view__sign",
8870
+ "aria-label": line.type,
8871
+ children: line.type === "added" ? "+" : line.type === "removed" ? "−" : " "
8872
+ }),
8873
+ /* @__PURE__ */ jsx("code", { children: line.text })
8874
+ ]
8875
+ }, index))
8876
+ })]
8877
+ });
8878
+ }
8879
+ function DiffView({ filename, hunks, contextLimit = 3, actions, emptyLabel = "No changes", expandLabel = "Show context", collapseLabel = "Hide context", className, ...props }) {
8880
+ const stats = diffStats(hunks);
8881
+ return /* @__PURE__ */ jsxs("figure", {
8882
+ ...node(props),
8883
+ className: cn("sph-diff-view", className),
8884
+ children: [/* @__PURE__ */ jsxs("figcaption", {
8885
+ className: "sph-diff-view__header",
8886
+ children: [
8887
+ /* @__PURE__ */ jsx("span", { children: filename }),
8888
+ /* @__PURE__ */ jsxs("span", {
8889
+ className: "sph-diff-view__stats",
8890
+ children: [
8891
+ stats.added,
8892
+ " added · ",
8893
+ stats.removed,
8894
+ " removed"
8895
+ ]
8896
+ }),
8897
+ node(actions)
8898
+ ]
8899
+ }), /* @__PURE__ */ jsx("div", {
8900
+ className: "sph-diff-view__viewport",
8901
+ tabIndex: 0,
8902
+ "aria-label": `Changes in ${filename}`,
8903
+ children: hunks.length ? hunks.map((hunk) => /* @__PURE__ */ jsx(Hunk, {
8904
+ hunk,
8905
+ contextLimit,
8906
+ expandLabel,
8907
+ collapseLabel
8908
+ }, hunk.id)) : /* @__PURE__ */ jsx("p", { children: emptyLabel })
8909
+ })]
8910
+ });
8911
+ }
8912
+ //#endregion
8913
+ //#region src/molecules/ArtifactCard/index.tsx
8914
+ const labels = {
8915
+ generating: "Generating",
8916
+ ready: "Ready",
8917
+ error: "Generation failed"
8918
+ };
8919
+ function ArtifactCard({ title, kind, description, version, state = "ready", children, actions, onOpen, openLabel = "Open artifact", statusLabel, className, ...props }) {
8920
+ const id = useId();
8921
+ return /* @__PURE__ */ jsxs("article", {
8922
+ ...node(props),
8923
+ className: cn("sph-artifact-card", className),
8924
+ "data-state": state,
8925
+ "aria-labelledby": id,
8926
+ children: [
8927
+ /* @__PURE__ */ jsxs("header", {
8928
+ className: "sph-artifact-card__header",
8929
+ children: [
8930
+ /* @__PURE__ */ jsxs("div", {
8931
+ className: "sph-artifact-card__meta",
8932
+ children: [node(kind), version && /* @__PURE__ */ jsx("span", { children: version })]
8933
+ }),
8934
+ /* @__PURE__ */ jsx("h3", {
8935
+ id,
8936
+ className: "sph-artifact-card__title",
8937
+ children: node(title)
8938
+ }),
8939
+ description !== void 0 && /* @__PURE__ */ jsx("p", {
8940
+ className: "sph-artifact-card__description",
8941
+ children: node(description)
8942
+ })
8943
+ ]
8944
+ }),
8945
+ children !== void 0 && /* @__PURE__ */ jsx("div", {
8946
+ className: "sph-artifact-card__content",
8947
+ children: node(children)
8948
+ }),
8949
+ /* @__PURE__ */ jsxs("footer", {
8950
+ className: "sph-artifact-card__footer",
8951
+ children: [
8952
+ /* @__PURE__ */ jsx("span", {
8953
+ role: "status",
8954
+ children: statusLabel ?? labels[state]
8955
+ }),
8956
+ node(actions),
8957
+ onOpen && /* @__PURE__ */ jsx(Button, {
8958
+ size: "sm",
8959
+ disabled: state !== "ready",
8960
+ onClick: onOpen,
8961
+ children: openLabel
8962
+ })
8963
+ ]
8964
+ })
8965
+ ]
8966
+ });
8967
+ }
8968
+ //#endregion
8969
+ export { Accordion, AnimatedNumber, ApprovalCard, ArtifactCard, Attachment, Avatar, AvatarGroup, Badge, Breadcrumb, Button, Calendar, Card, Carousel, Chart, ChatInput, ChatScroller, Checkbox, Citation, CodeBlock, Collapsible, Combobox, CommandPalette, ContextMenu, DateRangeField, Delta, Dialog, DiffView, Drawer, EmptyState, Field, FieldMessage, HoldButton, HoverCard, IconButton, Input, Kbd, MagneticDropzone, Menu, Menubar, Message, MetadataList, Notice, NumberInput, OTPInput, OverflowList, Pagination, PlanCard, Popover, Progress, QuestionCard, RadioGroup, ReasoningSteps, Resizable, Reveal, ScrollArea, SegmentedControl, Select, Separator, SidePanel, Sidebar, Skeleton, Slider, Spinner, Stat, StatGroup, StatusMark, Stepper, StreamingText, Surface, Table, Tabs, TaskList, Textarea, Timeline, Timestamp, Toast, ToastViewport, Toggle, ToolCalls, Toolbar, Tooltip, TooltipGroup, TreeView, dayFromSegments, describeDropzoneResult, filterChatInputSuggestions, findChatInputTrigger, matchChatInputSuggestions, motionDurationMs, orderRange, parseDurationMs, replaceChatInputTrigger, segmentsOf, slideAfter, stepSegment, toast, typeSegment, usePresence, validateDropzoneFiles };
7689
8970
 
7690
8971
  //# sourceMappingURL=index.js.map