@alulore/kumiko 0.17.3 → 0.18.2

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.
Files changed (73) hide show
  1. package/dist/avatar/avatar-name.d.ts +12 -0
  2. package/dist/avatar/avatar-name.js +42 -0
  3. package/dist/avatar/avatar.css +274 -0
  4. package/dist/avatar/avatar.d.ts +72 -0
  5. package/dist/avatar/avatar.js +45 -0
  6. package/dist/avatar/index.d.ts +3 -0
  7. package/dist/avatar/index.js +3 -0
  8. package/dist/board/board-api.d.ts +1 -0
  9. package/dist/board/board-selection.d.ts +1 -0
  10. package/dist/board/board-slots.d.ts +7 -0
  11. package/dist/board/board-slots.js +2 -1
  12. package/dist/board/refused-home.js +26 -1
  13. package/dist/dialog/dialog.css +7 -1
  14. package/dist/dialog/dialog.d.ts +9 -0
  15. package/dist/dialog/dialog.js +20 -0
  16. package/dist/dialog/index.d.ts +4 -3
  17. package/dist/dialog/index.js +4 -3
  18. package/dist/drawer/drawer.css +514 -0
  19. package/dist/drawer/drawer.d.ts +55 -0
  20. package/dist/drawer/drawer.js +43 -0
  21. package/dist/drawer/index.d.ts +2 -0
  22. package/dist/drawer/index.js +2 -0
  23. package/dist/file-input/file-dropzone.d.ts +67 -0
  24. package/dist/file-input/file-dropzone.js +97 -0
  25. package/dist/file-input/file-input.css +505 -0
  26. package/dist/file-input/file-input.d.ts +29 -0
  27. package/dist/file-input/file-input.js +21 -0
  28. package/dist/file-input/file-preview.d.ts +15 -0
  29. package/dist/file-input/file-preview.js +41 -0
  30. package/dist/file-input/index.d.ts +4 -0
  31. package/dist/file-input/index.js +4 -0
  32. package/dist/hover-card/hover-card.js +2 -0
  33. package/dist/media-viewer/index.d.ts +1 -0
  34. package/dist/media-viewer/index.js +1 -0
  35. package/dist/media-viewer/labels.d.ts +27 -0
  36. package/dist/media-viewer/labels.js +23 -0
  37. package/dist/media-viewer/media-viewer.d.ts +3 -0
  38. package/dist/media-viewer/media-viewer.js +6 -3
  39. package/dist/media-viewer/video-controls.js +4 -2
  40. package/dist/media-viewer/viewer-chrome.js +11 -5
  41. package/dist/menu/menu.js +2 -0
  42. package/dist/motion/settle-close.d.ts +5 -0
  43. package/dist/motion/settle-close.js +78 -0
  44. package/dist/otp-input/index.d.ts +2 -0
  45. package/dist/otp-input/index.js +2 -0
  46. package/dist/otp-input/otp-input.css +336 -0
  47. package/dist/otp-input/otp-input.d.ts +56 -0
  48. package/dist/otp-input/otp-input.js +44 -0
  49. package/dist/popover/index.d.ts +2 -1
  50. package/dist/popover/index.js +2 -1
  51. package/dist/popover/popover.d.ts +3 -0
  52. package/dist/popover/popover.js +8 -0
  53. package/dist/server-render.test.d.ts +1 -0
  54. package/dist/server-render.test.js +57 -0
  55. package/dist/skeleton/index.d.ts +1 -0
  56. package/dist/skeleton/index.js +1 -0
  57. package/dist/skeleton/skeleton.css +143 -0
  58. package/dist/skeleton/skeleton.d.ts +44 -0
  59. package/dist/skeleton/skeleton.js +22 -0
  60. package/dist/smooth-caret/smooth-caret.css +4 -2
  61. package/dist/tabs/index.d.ts +2 -0
  62. package/dist/tabs/index.js +2 -0
  63. package/dist/tabs/tabs.css +616 -0
  64. package/dist/tabs/tabs.d.ts +51 -0
  65. package/dist/tabs/tabs.js +20 -0
  66. package/dist/titlebar/index.d.ts +1 -1
  67. package/dist/titlebar/index.js +1 -1
  68. package/dist/titlebar/titlebar.d.ts +15 -2
  69. package/dist/titlebar/titlebar.js +18 -9
  70. package/dist/toast/index.d.ts +2 -1
  71. package/dist/toast/index.js +2 -1
  72. package/dist/tooltip/tooltip.js +2 -0
  73. package/package.json +59 -5
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ /** The extension a file's badge shows, like `"PDF"`: at most four letters, upper case. */
4
+ export function extensionOf(name) {
5
+ const dot = name.lastIndexOf(".");
6
+ return dot > 0 ? name.slice(dot + 1, dot + 5).toUpperCase() : "";
7
+ }
8
+ /** Whether a browser can draw the file as a picture. */
9
+ export function isPicture(file) {
10
+ return file.type.startsWith("image/") && file.type !== "image/svg+xml";
11
+ }
12
+ /**
13
+ * An object URL for the file while the component is mounted, made after render and revoked on cleanup, so a
14
+ * server render makes none and a removed file's URL is freed.
15
+ */
16
+ function useObjectUrl(file, wanted) {
17
+ const [url, setUrl] = useState();
18
+ useEffect(() => {
19
+ if (!wanted) {
20
+ return undefined;
21
+ }
22
+ const next = URL.createObjectURL(file);
23
+ setUrl(next);
24
+ return () => {
25
+ URL.revokeObjectURL(next);
26
+ setUrl(undefined);
27
+ };
28
+ }, [file, wanted]);
29
+ return url;
30
+ }
31
+ /**
32
+ * A small square for a file: the picture itself for an image, or a page badge with the file's extension. A
33
+ * picture the browser can't decode shows the badge too. Screen readers skip it; the file's name is written beside
34
+ * it.
35
+ */
36
+ export function FilePreview({ file, thumbnail = true, ...props }) {
37
+ const url = useObjectUrl(file, thumbnail && isPicture(file));
38
+ const [broken, setBroken] = useState();
39
+ const picture = url !== undefined && url !== broken;
40
+ return (_jsx("span", { "aria-hidden": true, "data-slot": "file-preview", "data-kind": picture ? "picture" : "badge", ...props, children: picture ? (_jsx("img", { src: url, alt: "", "data-slot": "file-preview-image", onError: () => setBroken(url) })) : (_jsx("span", { "data-slot": "file-preview-badge", children: extensionOf(file.name) })) }));
41
+ }
@@ -0,0 +1,4 @@
1
+ export { createFileInputController, FileInputItem, FileInputItemRemove, FileInputList, FileInputTrigger, formatFileSize, relativePath, type FileInputChange, type FileInputController, type FileInputItemState, type FileInputState, type FileInputValueChangeDetails, type FileRejection, type FileRejectionReason } from "@ui-sdk/react/file-input";
2
+ export { FileDropzone, fileDropzoneLabels, type FileDropzoneLabels, type FileDropzoneProps, type FileStatus } from "./file-dropzone";
3
+ export { FileInput, FileInputDropzone, FileInputIcon, FileInputRemoveButton, type FileInputDropzoneProps, type FileInputLook, type FileInputProps, type FileInputRemoveButtonProps } from "./file-input";
4
+ export { extensionOf, FilePreview, isPicture, type FilePreviewProps } from "./file-preview";
@@ -0,0 +1,4 @@
1
+ export { createFileInputController, FileInputItem, FileInputItemRemove, FileInputList, FileInputTrigger, formatFileSize, relativePath } from "@ui-sdk/react/file-input";
2
+ export { FileDropzone, fileDropzoneLabels } from "./file-dropzone";
3
+ export { FileInput, FileInputDropzone, FileInputIcon, FileInputRemoveButton } from "./file-input";
4
+ export { extensionOf, FilePreview, isPicture } from "./file-preview";
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { HoverCard as SdkHoverCard } from "@ui-sdk/react/hover-card";
3
+ import { useSettledClose } from "../motion/settle-close";
3
4
  /** How long the pointer rests on a trigger before its card opens, unless `delay` says otherwise. */
4
5
  const restingDelay = 450;
5
6
  /** The ui-sdk hover card, which waits 450ms instead of 600ms. Any `delay` still overrides it. */
6
7
  export function HoverCard({ delay = restingDelay, ...props }) {
8
+ useSettledClose();
7
9
  return _jsx(SdkHoverCard, { delay: delay, ...props });
8
10
  }
@@ -1,4 +1,5 @@
1
1
  export { MediaViewer, type MediaViewerProps } from "./media-viewer";
2
+ export { mediaViewerLabels, type MediaViewerLabels } from "./labels";
2
3
  export { behaviourDefaults, lookDefaults, type Background, type Chrome, type DoubleTap, type Indicator, type Layout, type MediaViewerBehaviour, type MediaViewerItem, type MediaViewerLook, type OpenMotion, type PagingMotion, type VideoControls, type WheelMode, type ZoomedDrag } from "./types";
3
4
  export { FIT, actualScale, clampPan, fitSize, maxScale, panLimits, zoomTo, type View, type ZoomAnchor } from "./zoom-pan";
4
5
  export type { OriginOf } from "./viewer-motion";
@@ -1,3 +1,4 @@
1
1
  export { MediaViewer } from "./media-viewer";
2
+ export { mediaViewerLabels } from "./labels";
2
3
  export { behaviourDefaults, lookDefaults } from "./types";
3
4
  export { FIT, actualScale, clampPan, fitSize, maxScale, panLimits, zoomTo } from "./zoom-pan";
@@ -0,0 +1,27 @@
1
+ /** The words the viewer gives screen readers for its parts. Pass your own through `labels` to translate them. */
2
+ export interface MediaViewerLabels {
3
+ /** The row of slides. */
4
+ media: string;
5
+ previous: string;
6
+ next: string;
7
+ close: string;
8
+ download: string;
9
+ fullscreen: string;
10
+ /** The group of zoom buttons. */
11
+ zoom: string;
12
+ zoomIn: string;
13
+ zoomOut: string;
14
+ /** The button that fits the picture back in view. It shows this word. */
15
+ fit: string;
16
+ /** The dots or thumbnail strip that jump to an item. */
17
+ pick: string;
18
+ play: string;
19
+ pause: string;
20
+ /** The video's position slider. */
21
+ position: string;
22
+ mute: string;
23
+ unmute: string;
24
+ }
25
+ export declare const mediaViewerLabels: MediaViewerLabels;
26
+ export declare const LabelsContext: import("react").Context<MediaViewerLabels>;
27
+ export declare function useLabels(): MediaViewerLabels;
@@ -0,0 +1,23 @@
1
+ import { createContext, useContext } from "react";
2
+ export const mediaViewerLabels = {
3
+ media: "Media",
4
+ previous: "Previous",
5
+ next: "Next",
6
+ close: "Close viewer",
7
+ download: "Download",
8
+ fullscreen: "Toggle fullscreen",
9
+ zoom: "Zoom",
10
+ zoomIn: "Zoom in",
11
+ zoomOut: "Zoom out",
12
+ fit: "Fit",
13
+ pick: "Pick an item",
14
+ play: "Play",
15
+ pause: "Pause",
16
+ position: "Position",
17
+ mute: "Mute",
18
+ unmute: "Unmute"
19
+ };
20
+ export const LabelsContext = createContext(mediaViewerLabels);
21
+ export function useLabels() {
22
+ return useContext(LabelsContext);
23
+ }
@@ -1,3 +1,4 @@
1
+ import { type MediaViewerLabels } from "./labels";
1
2
  import { type MediaViewerBehaviour, type MediaViewerItem, type MediaViewerLook } from "./types";
2
3
  import { type OriginOf } from "./viewer-motion";
3
4
  export type MediaViewerProps = MediaViewerBehaviour & MediaViewerLook & {
@@ -9,6 +10,8 @@ export type MediaViewerProps = MediaViewerBehaviour & MediaViewerLook & {
9
10
  onClose: () => void;
10
11
  /** The element an item sits in on the page: the viewer opens and closes toward it and returns focus to it. */
11
12
  getOrigin?: OriginOf;
13
+ /** The words the viewer gives screen readers, and the Fit button's word. Any you leave out stay English. */
14
+ labels?: Partial<MediaViewerLabels>;
12
15
  };
13
16
  /**
14
17
  * Shows images and video full screen: zoom and pan, swiping between items, closing.
@@ -1,7 +1,8 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Carousel, CarouselContent, CarouselItem, CarouselViewport, createCarouselController } from "@ui-sdk/react/carousel";
3
- import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { Dialog, DialogContent } from "../dialog";
5
+ import { LabelsContext, mediaViewerLabels, useLabels } from "./labels";
5
6
  import { MediaSlide } from "./media-slide";
6
7
  import { PagerDrag } from "./pager-drag";
7
8
  import { behaviourDefaults, lookDefaults } from "./types";
@@ -70,10 +71,11 @@ function Pager(props) {
70
71
  const { items, index, set, zoomed, controller } = props;
71
72
  const slide = (item, active) => slideFor(props, item, active);
72
73
  const current = items[index];
74
+ const labels = useLabels();
73
75
  if (set.paging !== "slide") {
74
76
  return _jsx("div", { "data-mv-single": "", children: current ? slide(current, true) : null });
75
77
  }
76
- return (_jsx(Carousel, { "aria-label": "Media", page: index + 1, onPageChange: (page, details) => {
78
+ return (_jsx(Carousel, { "aria-label": labels.media, page: index + 1, onPageChange: (page, details) => {
77
79
  /* The carousel reports the halfway scroll of a finger drag as a swipe; the drag decides the page. */
78
80
  if (props.pagerBusy() &&
79
81
  (details.reason === "swipe" || details.reason === "scroll")) {
@@ -223,6 +225,7 @@ export function MediaViewer(props) {
223
225
  const set = settle(props);
224
226
  const parts = useParts(props, set);
225
227
  const { chrome } = parts;
228
+ const labels = useMemo(() => ({ ...mediaViewerLabels, ...props.labels }), [props.labels]);
226
229
  const item = items[index];
227
230
  return (_jsx(Dialog, { open: open && item !== undefined, onOpenChange: (next) => {
228
231
  if (!next) {
@@ -237,5 +240,5 @@ export function MediaViewer(props) {
237
240
  event.target.closest("[data-mv-chrome]")) {
238
241
  chrome.poke();
239
242
  }
240
- }, children: _jsx(Interior, { props: props, set: set, parts: parts }) }) }));
243
+ }, children: _jsx(LabelsContext.Provider, { value: labels, children: _jsx(Interior, { props: props, set: set, parts: parts }) }) }) }));
241
244
  }
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
3
  import { Icon } from "./icons";
4
+ import { useLabels } from "./labels";
4
5
  const CLIP_EVENTS = ["play", "pause", "volumechange", "timeupdate", "loadedmetadata"];
5
6
  function useClipState(video) {
6
7
  const [state, setState] = useState({
@@ -60,11 +61,12 @@ function togglePlay(video) {
60
61
  /* A minimal set of video controls: play or pause, a scrubber, and mute. */
61
62
  export function VideoControls({ video }) {
62
63
  const state = useClipState(video);
63
- return (_jsxs("div", { "data-mv-control": "", "data-mv-video-controls": "", children: [_jsx("button", { type: "button", "data-mv-button": "", onClick: () => togglePlay(video.current), "aria-label": state.playing ? "Pause" : "Play", children: _jsx(Icon, { name: state.playing ? "pause" : "play" }) }), _jsx("input", { type: "range", "aria-label": "Position", min: 0, max: state.length || 1, step: "any", value: state.time, onChange: (event) => {
64
+ const labels = useLabels();
65
+ return (_jsxs("div", { "data-mv-control": "", "data-mv-video-controls": "", children: [_jsx("button", { type: "button", "data-mv-button": "", onClick: () => togglePlay(video.current), "aria-label": state.playing ? labels.pause : labels.play, children: _jsx(Icon, { name: state.playing ? "pause" : "play" }) }), _jsx("input", { type: "range", "aria-label": labels.position, min: 0, max: state.length || 1, step: "any", value: state.time, onChange: (event) => {
64
66
  if (video.current) {
65
67
  video.current.currentTime = Number(event.target.value);
66
68
  }
67
- } }), _jsx("span", { "aria-hidden": "true", children: clock(state.time) }), _jsx("button", { type: "button", "data-mv-button": "", "aria-label": state.muted ? "Unmute" : "Mute", "aria-pressed": state.muted, onClick: () => {
69
+ } }), _jsx("span", { "aria-hidden": "true", children: clock(state.time) }), _jsx("button", { type: "button", "data-mv-button": "", "aria-label": state.muted ? labels.unmute : labels.mute, "aria-pressed": state.muted, onClick: () => {
68
70
  if (video.current) {
69
71
  video.current.muted = !video.current.muted;
70
72
  }
@@ -1,27 +1,33 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { DialogClose, DialogTitle } from "../dialog";
3
3
  import { Icon } from "./icons";
4
+ import { useLabels } from "./labels";
4
5
  function Button({ label, icon, onClick, disabled }) {
5
6
  return (_jsx("button", { type: "button", "data-mv-button": "", "aria-label": label, disabled: disabled, onClick: onClick, children: _jsx(Icon, { name: icon }) }));
6
7
  }
7
8
  function Dots({ items, index, onGo }) {
8
- return (_jsx("div", { "data-mv-indicator": "dots", role: "group", "aria-label": "Pick an item", children: items.map((item, at) => (_jsx("button", { type: "button", "data-mv-dot": "", "aria-label": item.name, "aria-current": at === index ? "true" : undefined, onClick: () => onGo(at) }, item.id))) }));
9
+ const labels = useLabels();
10
+ return (_jsx("div", { "data-mv-indicator": "dots", role: "group", "aria-label": labels.pick, children: items.map((item, at) => (_jsx("button", { type: "button", "data-mv-dot": "", "aria-label": item.name, "aria-current": at === index ? "true" : undefined, onClick: () => onGo(at) }, item.id))) }));
9
11
  }
10
12
  function Strip({ items, index, onGo }) {
11
- return (_jsx("div", { "data-mv-indicator": "strip", role: "group", "aria-label": "Pick an item", children: items.map((item, at) => (_jsx("button", { type: "button", "data-mv-thumb": "", "aria-label": item.name, "aria-current": at === index ? "true" : undefined, onClick: () => onGo(at), children: _jsx("img", { src: item.thumb ?? item.poster ?? item.src, alt: "", draggable: false }) }, item.id))) }));
13
+ const labels = useLabels();
14
+ return (_jsx("div", { "data-mv-indicator": "strip", role: "group", "aria-label": labels.pick, children: items.map((item, at) => (_jsx("button", { type: "button", "data-mv-thumb": "", "aria-label": item.name, "aria-current": at === index ? "true" : undefined, onClick: () => onGo(at), children: _jsx("img", { src: item.thumb ?? item.poster ?? item.src, alt: "", draggable: false }) }, item.id))) }));
12
15
  }
13
16
  function Zoom({ zoom, zoomable, onZoom, onFit }) {
14
- return (_jsxs("div", { "data-mv-zoom": "", role: "group", "aria-label": "Zoom", children: [_jsx(Button, { label: "Zoom out", icon: "minus", disabled: !zoomable, onClick: () => onZoom(1 / 1.25) }), _jsxs("span", { "data-mv-percent": "", "aria-live": "off", children: [Math.round(zoom * 100), "%"] }), _jsx(Button, { label: "Zoom in", icon: "plus", disabled: !zoomable, onClick: () => onZoom(1.25) }), _jsx("button", { type: "button", "data-mv-button": "", "data-mv-fit": "", disabled: !zoomable, onClick: onFit, children: "Fit" })] }));
17
+ const labels = useLabels();
18
+ return (_jsxs("div", { "data-mv-zoom": "", role: "group", "aria-label": labels.zoom, children: [_jsx(Button, { label: labels.zoomOut, icon: "minus", disabled: !zoomable, onClick: () => onZoom(1 / 1.25) }), _jsxs("span", { "data-mv-percent": "", "aria-live": "off", children: [Math.round(zoom * 100), "%"] }), _jsx(Button, { label: labels.zoomIn, icon: "plus", disabled: !zoomable, onClick: () => onZoom(1.25) }), _jsx("button", { type: "button", "data-mv-button": "", "data-mv-fit": "", disabled: !zoomable, onClick: onFit, children: labels.fit })] }));
15
19
  }
16
20
  function Heading({ item, index, count }) {
17
21
  const size = item.width && item.height ? `${item.width} × ${item.height}` : "";
18
22
  return (_jsxs("div", { "data-mv-heading": "", children: [_jsx(DialogTitle, { children: item.name }), _jsxs("div", { "data-mv-meta": "", children: [count > 1 ? _jsx("span", { "data-mv-counter": "", children: `${index + 1} / ${count}` }) : null, size === "" ? null : _jsx("span", { "data-mv-size": "", children: size })] })] }));
19
23
  }
20
24
  function TopBar({ item, index, count, onFullscreen }) {
21
- return (_jsxs("div", { "data-mv-chrome": "", "data-mv-top": "", children: [_jsx(Heading, { item: item, index: index, count: count }), _jsxs("div", { "data-mv-actions": "", children: [_jsx("span", { "data-mv-optional": "", children: _jsx(Button, { label: "Toggle fullscreen", icon: "fullscreen", onClick: onFullscreen }) }), _jsx("a", { "data-mv-button": "", "data-mv-optional": "", href: item.src, download: item.name, "aria-label": "Download", children: _jsx(Icon, { name: "download" }) }), _jsx(DialogClose, { "data-mv-button": "", "aria-label": "Close viewer", children: _jsx(Icon, { name: "close" }) })] })] }));
25
+ const labels = useLabels();
26
+ return (_jsxs("div", { "data-mv-chrome": "", "data-mv-top": "", children: [_jsx(Heading, { item: item, index: index, count: count }), _jsxs("div", { "data-mv-actions": "", children: [_jsx("span", { "data-mv-optional": "", children: _jsx(Button, { label: labels.fullscreen, icon: "fullscreen", onClick: onFullscreen }) }), _jsx("a", { "data-mv-button": "", "data-mv-optional": "", href: item.src, download: item.name, "aria-label": labels.download, children: _jsx(Icon, { name: "download" }) }), _jsx(DialogClose, { "data-mv-button": "", "aria-label": labels.close, children: _jsx(Icon, { name: "close" }) })] })] }));
22
27
  }
23
28
  function Sides({ onStep }) {
24
- return (_jsxs(_Fragment, { children: [_jsx("span", { "data-mv-chrome": "", "data-mv-optional": "", "data-mv-side": "start", children: _jsx(Button, { label: "Previous", icon: "previous", onClick: () => onStep(-1) }) }), _jsx("span", { "data-mv-chrome": "", "data-mv-optional": "", "data-mv-side": "end", children: _jsx(Button, { label: "Next", icon: "next", onClick: () => onStep(1) }) })] }));
29
+ const labels = useLabels();
30
+ return (_jsxs(_Fragment, { children: [_jsx("span", { "data-mv-chrome": "", "data-mv-optional": "", "data-mv-side": "start", children: _jsx(Button, { label: labels.previous, icon: "previous", onClick: () => onStep(-1) }) }), _jsx("span", { "data-mv-chrome": "", "data-mv-optional": "", "data-mv-side": "end", children: _jsx(Button, { label: labels.next, icon: "next", onClick: () => onStep(1) }) })] }));
25
31
  }
26
32
  /* The buttons, bars and indicators. Their place is the layout word's business, not this markup's. */
27
33
  export function ViewerChrome(props) {
package/dist/menu/menu.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Menu as SdkMenu, MenuContent as SdkMenuContent } from "@ui-sdk/react/menu";
3
3
  import { createContext, use, useEffect, useId, useState } from "react";
4
+ import { useSettledClose } from "../motion/settle-close";
4
5
  const open = new Set();
5
6
  /** Menus still fading out, each with a way to cut its fade short. */
6
7
  const closing = new Map();
@@ -45,6 +46,7 @@ function changed(id, next, set) {
45
46
  */
46
47
  export function Menu({ onOpenChange, onOpenChangeComplete, ...props }) {
47
48
  const id = useId();
49
+ useSettledClose();
48
50
  const [on, setOn] = useState(false);
49
51
  const [el] = useState(() => ({ current: null }));
50
52
  const set = (next) => {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Keeps a popup's close from being stretched by infinite animations inside it.
3
+ * Call it from any component that renders a ui-sdk popup; all callers share one observer.
4
+ */
5
+ export declare function useSettledClose(): void;
@@ -0,0 +1,78 @@
1
+ import { useEffect } from "react";
2
+ const ending = "data-ending-style";
3
+ /** The animations cancelled when a close began, kept so a close that is taken back can restart them. */
4
+ const cancelled = new WeakMap();
5
+ function isInfinite(animation) {
6
+ return animation.effect?.getComputedTiming().endTime === Infinity;
7
+ }
8
+ /**
9
+ * Cancels the infinite animations inside a closing popup, leaving finite ones alone.
10
+ * An exit in ui-sdk ends when every animation inside has finished.
11
+ * An endless one, like a bobbing hint, makes it wait for a timer instead.
12
+ * The backdrop, done sooner, then starts back toward opaque before the popup is hidden.
13
+ */
14
+ function settle(el) {
15
+ const infinite = el.getAnimations({ subtree: true }).filter((one) => isInfinite(one));
16
+ if (infinite.length === 0) {
17
+ return;
18
+ }
19
+ for (const animation of infinite) {
20
+ animation.cancel();
21
+ }
22
+ cancelled.set(el, infinite);
23
+ }
24
+ /** A close taken back (the popup opens again mid-exit) brings its looping animations back. */
25
+ function restore(el) {
26
+ const kept = cancelled.get(el);
27
+ cancelled.delete(el);
28
+ if (kept && Object.hasOwn(el.dataset, "open")) {
29
+ for (const animation of kept) {
30
+ if (animation.playState === "idle") {
31
+ animation.play();
32
+ }
33
+ }
34
+ }
35
+ }
36
+ function watch(mutations) {
37
+ for (const { target, oldValue } of mutations) {
38
+ if (!(target instanceof HTMLElement)) {
39
+ continue;
40
+ }
41
+ if (target.hasAttribute(ending)) {
42
+ if (oldValue === null) {
43
+ settle(target);
44
+ }
45
+ }
46
+ else {
47
+ restore(target);
48
+ }
49
+ }
50
+ }
51
+ let users = 0;
52
+ let observer = null;
53
+ function acquire() {
54
+ users += 1;
55
+ if (users === 1) {
56
+ observer = new MutationObserver(watch);
57
+ observer.observe(document, {
58
+ attributes: true,
59
+ attributeFilter: [ending],
60
+ attributeOldValue: true,
61
+ subtree: true
62
+ });
63
+ }
64
+ return () => {
65
+ users -= 1;
66
+ if (users === 0) {
67
+ observer?.disconnect();
68
+ observer = null;
69
+ }
70
+ };
71
+ }
72
+ /**
73
+ * Keeps a popup's close from being stretched by infinite animations inside it.
74
+ * Call it from any component that renders a ui-sdk popup; all callers share one observer.
75
+ */
76
+ export function useSettledClose() {
77
+ useEffect(acquire, []);
78
+ }
@@ -0,0 +1,2 @@
1
+ export { OTPInput, OTPInputSlot, OTPInputSlots, type OTPInputLook, type OTPInputProps, type OTPInputSize, type OTPInputSlotProps, type OTPInputSlotsProps } from "./otp-input";
2
+ export { createOTPInputController, OTPInputGroup, OTPInputSeparator, type OTPInputApi, type OTPInputChangeOptions, type OTPInputController, type OTPInputOptions, type OTPInputPattern, type OTPInputSlotData, type OTPInputSlotState, type OTPInputState, type OTPInputValueChangeReason } from "@ui-sdk/react/otp-input";
@@ -0,0 +1,2 @@
1
+ export { OTPInput, OTPInputSlot, OTPInputSlots } from "./otp-input";
2
+ export { createOTPInputController, OTPInputGroup, OTPInputSeparator } from "@ui-sdk/react/otp-input";