@arshad-shah/cynosure 0.4.0 → 0.5.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/README.md +6 -6
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/adapters/astro/index.d.ts +2 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Accordion/Accordion.js +26 -26
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/Announcer/Announcer.d.ts +2 -1
- package/dist/components/Announcer/Announcer.js +31 -33
- package/dist/components/Announcer/Announcer.js.map +1 -1
- package/dist/components/AppShell/AppShell.js +44 -41
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/Badge/Badge.d.ts +19 -5
- package/dist/components/Badge/Badge.js +19 -13
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Button/Button.d.ts +13 -3
- package/dist/components/Button/Button.js +34 -33
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.js +155 -158
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Calendar/dates.js +42 -38
- package/dist/components/Calendar/dates.js.map +1 -1
- package/dist/components/Card/Card.d.ts +14 -1
- package/dist/components/Card/Card.js +60 -52
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/ChatMessage/ChatMessage.d.ts +55 -0
- package/dist/components/ChatMessage/ChatMessage.js +50 -0
- package/dist/components/ChatMessage/ChatMessage.js.map +1 -0
- package/dist/components/ChatMessage/index.d.ts +1 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +6 -1
- package/dist/components/CodeBlock/CodeBlock.js +40 -37
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/ColorField/ColorField.d.ts +3 -2
- package/dist/components/ColorField/ColorField.js +138 -139
- package/dist/components/ColorField/ColorField.js.map +1 -1
- package/dist/components/ColorField/read-color.js +5 -6
- package/dist/components/ColorField/read-color.js.map +1 -1
- package/dist/components/ColorSwatches/ColorSwatches.js +42 -33
- package/dist/components/ColorSwatches/ColorSwatches.js.map +1 -1
- package/dist/components/Combobox/Combobox.d.ts +13 -2
- package/dist/components/Combobox/Combobox.js +113 -95
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/CommandPalette/CommandPalette.d.ts +14 -1
- package/dist/components/CommandPalette/CommandPalette.js +153 -109
- package/dist/components/CommandPalette/CommandPalette.js.map +1 -1
- package/dist/components/CommandPalette/index.d.ts +1 -1
- package/dist/components/CompareSlider/CompareSlider.js +14 -14
- package/dist/components/CompareSlider/CompareSlider.js.map +1 -1
- package/dist/components/Container/Container.d.ts +1 -1
- package/dist/components/Container/Container.js +1 -1
- package/dist/components/Container/Container.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenu.d.ts +27 -13
- package/dist/components/ContextMenu/ContextMenu.js +64 -46
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.js +38 -39
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/DataGrid/DataGrid.d.ts +135 -0
- package/dist/components/DataGrid/DataGrid.js +385 -0
- package/dist/components/DataGrid/DataGrid.js.map +1 -0
- package/dist/components/DataGrid/index.d.ts +1 -0
- package/dist/components/DateField/DateField.d.ts +4 -3
- package/dist/components/DateField/DateField.js +70 -59
- package/dist/components/DateField/DateField.js.map +1 -1
- package/dist/components/Dialog/Dialog.js +76 -80
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/Disclosure/Disclosure.d.ts +15 -1
- package/dist/components/Disclosure/Disclosure.js +37 -30
- package/dist/components/Disclosure/Disclosure.js.map +1 -1
- package/dist/components/DocumentViewport/DocumentViewport.js +54 -57
- package/dist/components/DocumentViewport/DocumentViewport.js.map +1 -1
- package/dist/components/ErrorBoundary/ErrorBoundary.d.ts +59 -0
- package/dist/components/ErrorBoundary/ErrorBoundary.js +53 -0
- package/dist/components/ErrorBoundary/ErrorBoundary.js.map +1 -0
- package/dist/components/ErrorBoundary/index.d.ts +1 -0
- package/dist/components/Field/Field.d.ts +38 -5
- package/dist/components/Field/Field.js +47 -39
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/Field/index.d.ts +1 -1
- package/dist/components/FileDrop/FileDrop.d.ts +26 -1
- package/dist/components/FileDrop/FileDrop.js +149 -98
- package/dist/components/FileDrop/FileDrop.js.map +1 -1
- package/dist/components/FloatingToolbar/FloatingToolbar.js +83 -81
- package/dist/components/FloatingToolbar/FloatingToolbar.js.map +1 -1
- package/dist/components/Grid/Grid.d.ts +3 -3
- package/dist/components/Grid/Grid.js +55 -47
- package/dist/components/Grid/Grid.js.map +1 -1
- package/dist/components/HighlightedText/HighlightedText.d.ts +40 -0
- package/dist/components/HighlightedText/HighlightedText.js +36 -0
- package/dist/components/HighlightedText/HighlightedText.js.map +1 -0
- package/dist/components/HighlightedText/index.d.ts +2 -0
- package/dist/components/HotkeyField/HotkeyField.d.ts +84 -0
- package/dist/components/HotkeyField/HotkeyField.js +161 -0
- package/dist/components/HotkeyField/HotkeyField.js.map +1 -0
- package/dist/components/HotkeyField/index.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.js +6 -6
- package/dist/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/components/IconButton/IconButton.js +16 -15
- package/dist/components/IconButton/IconButton.js.map +1 -1
- package/dist/components/Inline/Inline.d.ts +2 -2
- package/dist/components/Inline/Inline.js.map +1 -1
- package/dist/components/Kbd/Kbd.d.ts +0 -2
- package/dist/components/Kbd/Kbd.js +16 -22
- package/dist/components/Kbd/Kbd.js.map +1 -1
- package/dist/components/KeyValueEditor/bulk.js +3 -4
- package/dist/components/KeyValueEditor/bulk.js.map +1 -1
- package/dist/components/ListRow/ListRow.d.ts +105 -0
- package/dist/components/ListRow/ListRow.js +164 -0
- package/dist/components/ListRow/ListRow.js.map +1 -0
- package/dist/components/ListRow/index.d.ts +1 -0
- package/dist/components/LoadingDots/LoadingDots.d.ts +7 -2
- package/dist/components/LoadingDots/LoadingDots.js +28 -18
- package/dist/components/LoadingDots/LoadingDots.js.map +1 -1
- package/dist/components/Menu/Menu.d.ts +29 -11
- package/dist/components/Menu/Menu.js +204 -111
- package/dist/components/Menu/Menu.js.map +1 -1
- package/dist/components/Menubar/Menubar.d.ts +40 -0
- package/dist/components/Menubar/Menubar.js +82 -0
- package/dist/components/Menubar/Menubar.js.map +1 -0
- package/dist/components/Menubar/index.d.ts +1 -0
- package/dist/components/Notice/Notice.d.ts +11 -2
- package/dist/components/Notice/Notice.js +31 -28
- package/dist/components/Notice/Notice.js.map +1 -1
- package/dist/components/NumberField/NumberField.d.ts +8 -3
- package/dist/components/NumberField/NumberField.js +151 -100
- package/dist/components/NumberField/NumberField.js.map +1 -1
- package/dist/components/OptionList/OptionList.d.ts +36 -3
- package/dist/components/OptionList/OptionList.js +65 -42
- package/dist/components/OptionList/OptionList.js.map +1 -1
- package/dist/components/OptionList/index.d.ts +1 -1
- package/dist/components/OverlayFrame/OverlayFrame.d.ts +33 -0
- package/dist/components/OverlayFrame/OverlayFrame.js +20 -0
- package/dist/components/OverlayFrame/OverlayFrame.js.map +1 -0
- package/dist/components/OverlayFrame/index.d.ts +1 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.d.ts +71 -4
- package/dist/components/PanZoomCanvas/PanZoomCanvas.js +197 -141
- package/dist/components/PanZoomCanvas/PanZoomCanvas.js.map +1 -1
- package/dist/components/PanZoomCanvas/index.d.ts +1 -1
- package/dist/components/PathField/PathField.d.ts +68 -0
- package/dist/components/PathField/PathField.js +67 -0
- package/dist/components/PathField/PathField.js.map +1 -0
- package/dist/components/PathField/index.d.ts +1 -0
- package/dist/components/Popover/Popover.d.ts +16 -3
- package/dist/components/Popover/Popover.js +51 -42
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.d.ts +4 -3
- package/dist/components/ProgressBar/ProgressBar.js.map +1 -1
- package/dist/components/RowActions/RowActions.d.ts +35 -0
- package/dist/components/RowActions/RowActions.js +38 -0
- package/dist/components/RowActions/RowActions.js.map +1 -0
- package/dist/components/RowActions/index.d.ts +1 -0
- package/dist/components/ScrollArea/ScrollArea.d.ts +55 -0
- package/dist/components/ScrollArea/ScrollArea.js +55 -0
- package/dist/components/ScrollArea/ScrollArea.js.map +1 -0
- package/dist/components/ScrollArea/index.d.ts +1 -0
- package/dist/components/SearchField/SearchField.d.ts +17 -0
- package/dist/components/SearchField/SearchField.js +31 -17
- package/dist/components/SearchField/SearchField.js.map +1 -1
- package/dist/components/SearchField/index.d.ts +1 -1
- package/dist/components/Section/Section.d.ts +1 -1
- package/dist/components/Section/Section.js +1 -1
- package/dist/components/Section/Section.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +6 -3
- package/dist/components/SegmentedControl/SegmentedControl.js +23 -19
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/Select/Select.d.ts +22 -6
- package/dist/components/Select/Select.js +155 -129
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/SelectionFrame/frame-math.js +19 -20
- package/dist/components/SelectionFrame/frame-math.js.map +1 -1
- package/dist/components/SideNav/SideNav.d.ts +13 -1
- package/dist/components/SideNav/SideNav.js +98 -91
- package/dist/components/SideNav/SideNav.js.map +1 -1
- package/dist/components/SignaturePad/SignaturePad.js +63 -62
- package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
- package/dist/components/SignaturePad/ink.js +0 -1
- package/dist/components/SignaturePad/ink.js.map +1 -1
- package/dist/components/Slider/Slider.js +88 -91
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/SortButton/SortButton.d.ts +36 -0
- package/dist/components/SortButton/SortButton.js +35 -0
- package/dist/components/SortButton/SortButton.js.map +1 -0
- package/dist/components/SortButton/index.d.ts +1 -0
- package/dist/components/SortableList/SortableList.js +145 -119
- package/dist/components/SortableList/SortableList.js.map +1 -1
- package/dist/components/SplitPane/SplitPane.d.ts +32 -12
- package/dist/components/SplitPane/SplitPane.js +105 -59
- package/dist/components/SplitPane/SplitPane.js.map +1 -1
- package/dist/components/Stack/Stack.d.ts +2 -2
- package/dist/components/Stack/Stack.js +24 -17
- package/dist/components/Stack/Stack.js.map +1 -1
- package/dist/components/Stack/index.d.ts +1 -1
- package/dist/components/Stat/Stat.js +6 -6
- package/dist/components/Stat/Stat.js.map +1 -1
- package/dist/components/StatusBar/StatusBar.d.ts +95 -0
- package/dist/components/StatusBar/StatusBar.js +110 -0
- package/dist/components/StatusBar/StatusBar.js.map +1 -0
- package/dist/components/StatusBar/index.d.ts +1 -0
- package/dist/components/Table/Table.d.ts +6 -6
- package/dist/components/Table/Table.js +71 -99
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +51 -5
- package/dist/components/Tabs/Tabs.js +289 -171
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/TagInput/TagInput.d.ts +10 -2
- package/dist/components/TagInput/TagInput.js +121 -111
- package/dist/components/TagInput/TagInput.js.map +1 -1
- package/dist/components/Text/Text.d.ts +6 -0
- package/dist/components/Text/Text.js +18 -17
- package/dist/components/Text/Text.js.map +1 -1
- package/dist/components/TextArea/TextArea.d.ts +37 -6
- package/dist/components/TextArea/TextArea.js +200 -72
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/TextArea/index.d.ts +1 -1
- package/dist/components/TextField/TextField.d.ts +18 -6
- package/dist/components/TextField/TextField.js +59 -54
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/TimeField/TimeField.d.ts +4 -3
- package/dist/components/TimeField/TimeField.js +197 -183
- package/dist/components/TimeField/TimeField.js.map +1 -1
- package/dist/components/TitleBar/TitleBar.d.ts +91 -0
- package/dist/components/TitleBar/TitleBar.js +80 -0
- package/dist/components/TitleBar/TitleBar.js.map +1 -0
- package/dist/components/TitleBar/index.d.ts +1 -0
- package/dist/components/Toast/Toast.d.ts +17 -2
- package/dist/components/Toast/Toast.js +162 -145
- package/dist/components/Toast/Toast.js.map +1 -1
- package/dist/components/Toast/index.d.ts +1 -1
- package/dist/components/Toolbar/Toolbar.js +11 -12
- package/dist/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +18 -1
- package/dist/components/Tooltip/Tooltip.js +50 -31
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tree/Tree.d.ts +92 -11
- package/dist/components/Tree/Tree.js +332 -164
- package/dist/components/Tree/Tree.js.map +1 -1
- package/dist/components/VirtualList/VirtualList.d.ts +27 -4
- package/dist/components/VirtualList/VirtualList.js +179 -145
- package/dist/components/VirtualList/VirtualList.js.map +1 -1
- package/dist/components/VirtualList/index.d.ts +1 -1
- package/dist/components/ZoomControls/ZoomControls.d.ts +6 -2
- package/dist/components/ZoomControls/ZoomControls.js +37 -37
- package/dist/components/ZoomControls/ZoomControls.js.map +1 -1
- package/dist/entries/tokens.js +22 -16
- package/dist/foundations/ChoiceBase/ChoiceBase.js +15 -13
- package/dist/foundations/ChoiceBase/ChoiceBase.js.map +1 -1
- package/dist/foundations/LiveRegion/LiveRegion.d.ts +33 -0
- package/dist/foundations/LiveRegion/LiveRegion.js +29 -0
- package/dist/foundations/LiveRegion/LiveRegion.js.map +1 -0
- package/dist/foundations/LiveRegion/index.d.ts +1 -0
- package/dist/foundations/canvas-size.d.ts +14 -0
- package/dist/foundations/canvas-size.js +32 -0
- package/dist/foundations/canvas-size.js.map +1 -0
- package/dist/foundations/dir.js +0 -1
- package/dist/foundations/dir.js.map +1 -1
- package/dist/foundations/draft.d.ts +14 -0
- package/dist/foundations/draft.js +22 -0
- package/dist/foundations/draft.js.map +1 -0
- package/dist/foundations/edge.d.ts +20 -0
- package/dist/foundations/edge.js +26 -0
- package/dist/foundations/edge.js.map +1 -0
- package/dist/foundations/focus.d.ts +5 -0
- package/dist/foundations/focus.js +10 -0
- package/dist/foundations/focus.js.map +1 -0
- package/dist/foundations/hotkey.d.ts +23 -1
- package/dist/foundations/hotkey.js +48 -26
- package/dist/foundations/hotkey.js.map +1 -1
- package/dist/foundations/icon-size.d.ts +7 -0
- package/dist/foundations/icon-size.js +6 -0
- package/dist/foundations/icon-size.js.map +1 -0
- package/dist/foundations/keys.js +12 -13
- package/dist/foundations/keys.js.map +1 -1
- package/dist/{components/Stack/space.d.ts → foundations/layout.d.ts} +34 -0
- package/dist/foundations/layout.js +29 -0
- package/dist/foundations/layout.js.map +1 -0
- package/dist/foundations/listbox.d.ts +47 -2
- package/dist/foundations/listbox.js +56 -25
- package/dist/foundations/listbox.js.map +1 -1
- package/dist/foundations/math.d.ts +25 -0
- package/dist/foundations/math.js +14 -3
- package/dist/foundations/math.js.map +1 -1
- package/dist/foundations/media-query.d.ts +5 -0
- package/dist/foundations/media-query.js +14 -0
- package/dist/foundations/media-query.js.map +1 -0
- package/dist/foundations/motion.d.ts +12 -0
- package/dist/foundations/motion.js +21 -0
- package/dist/foundations/motion.js.map +1 -0
- package/dist/foundations/option-icon.d.ts +3 -1
- package/dist/foundations/option-icon.js +6 -6
- package/dist/foundations/option-icon.js.map +1 -1
- package/dist/foundations/qr.js +0 -1
- package/dist/foundations/qr.js.map +1 -1
- package/dist/foundations/refs.d.ts +8 -0
- package/dist/foundations/refs.js +14 -0
- package/dist/foundations/refs.js.map +1 -0
- package/dist/foundations/reorder.js +5 -6
- package/dist/foundations/reorder.js.map +1 -1
- package/dist/foundations/roving-focus.d.ts +10 -0
- package/dist/foundations/roving-focus.js +34 -31
- package/dist/foundations/roving-focus.js.map +1 -1
- package/dist/foundations/scroll-align.d.ts +11 -0
- package/dist/foundations/scroll-align.js +8 -0
- package/dist/foundations/scroll-align.js.map +1 -0
- package/dist/foundations/sort.d.ts +13 -0
- package/dist/foundations/sort.js +26 -0
- package/dist/foundations/sort.js.map +1 -0
- package/dist/foundations/text-match.d.ts +11 -0
- package/dist/foundations/text-match.js +20 -0
- package/dist/foundations/text-match.js.map +1 -0
- package/dist/foundations/tone-icons.js +4 -5
- package/dist/foundations/tone-icons.js.map +1 -1
- package/dist/foundations/use-follow.d.ts +29 -0
- package/dist/foundations/use-follow.js +51 -0
- package/dist/foundations/use-follow.js.map +1 -0
- package/dist/foundations/virtual-window.d.ts +22 -5
- package/dist/foundations/virtual-window.js +58 -54
- package/dist/foundations/virtual-window.js.map +1 -1
- package/dist/foundations/zoom-gestures.d.ts +23 -1
- package/dist/foundations/zoom-gestures.js +123 -84
- package/dist/foundations/zoom-gestures.js.map +1 -1
- package/dist/foundations/zoom.d.ts +10 -4
- package/dist/foundations/zoom.js +16 -17
- package/dist/foundations/zoom.js.map +1 -1
- package/dist/icons/boxes.d.ts +2 -0
- package/dist/icons/boxes.js +34 -0
- package/dist/icons/boxes.js.map +1 -0
- package/dist/icons/by-name.d.ts +11 -0
- package/dist/icons/by-name.js +11 -0
- package/dist/icons/by-name.js.map +1 -0
- package/dist/icons/cable.d.ts +2 -0
- package/dist/icons/cable.js +14 -0
- package/dist/icons/cable.js.map +1 -0
- package/dist/icons/check-check.d.ts +2 -0
- package/dist/icons/check-check.js +17 -0
- package/dist/icons/check-check.js.map +1 -0
- package/dist/icons/clipboard-paste.d.ts +2 -0
- package/dist/icons/clipboard-paste.js +30 -0
- package/dist/icons/clipboard-paste.js.map +1 -0
- package/dist/icons/facet.d.ts +274 -0
- package/dist/icons/facet.js +830 -0
- package/dist/icons/facet.js.map +1 -0
- package/dist/icons/file-plus.d.ts +2 -0
- package/dist/icons/file-plus.js +14 -0
- package/dist/icons/file-plus.js.map +1 -0
- package/dist/icons/file-question.d.ts +2 -0
- package/dist/icons/file-question.js +14 -0
- package/dist/icons/file-question.js.map +1 -0
- package/dist/icons/file-search.d.ts +2 -0
- package/dist/icons/file-search.js +24 -0
- package/dist/icons/file-search.js.map +1 -0
- package/dist/icons/function.d.ts +2 -0
- package/dist/icons/function.js +20 -0
- package/dist/icons/function.js.map +1 -0
- package/dist/icons/gauge.d.ts +2 -0
- package/dist/icons/gauge.js +14 -0
- package/dist/icons/gauge.js.map +1 -0
- package/dist/icons/hourglass.d.ts +2 -0
- package/dist/icons/hourglass.js +14 -0
- package/dist/icons/hourglass.js.map +1 -0
- package/dist/icons/index.d.ts +1 -250
- package/dist/icons/index.js +548 -500
- package/dist/icons/keywords.d.ts +24 -0
- package/dist/icons/keywords.js +185 -0
- package/dist/icons/keywords.js.map +1 -1
- package/dist/icons/languages.d.ts +2 -0
- package/dist/icons/languages.js +14 -0
- package/dist/icons/languages.js.map +1 -0
- package/dist/icons/loader.d.ts +2 -0
- package/dist/icons/loader.js +14 -0
- package/dist/icons/loader.js.map +1 -0
- package/dist/icons/monitor-down.d.ts +2 -0
- package/dist/icons/monitor-down.js +24 -0
- package/dist/icons/monitor-down.js.map +1 -0
- package/dist/icons/panel-right.d.ts +2 -0
- package/dist/icons/panel-right.js +20 -0
- package/dist/icons/panel-right.js.map +1 -0
- package/dist/icons/party-popper.d.ts +2 -0
- package/dist/icons/party-popper.js +14 -0
- package/dist/icons/party-popper.js.map +1 -0
- package/dist/icons/power-off.d.ts +2 -0
- package/dist/icons/power-off.js +14 -0
- package/dist/icons/power-off.js.map +1 -0
- package/dist/icons/rocket.d.ts +2 -0
- package/dist/icons/rocket.js +21 -0
- package/dist/icons/rocket.js.map +1 -0
- package/dist/icons/rows.d.ts +2 -0
- package/dist/icons/rows.js +20 -0
- package/dist/icons/rows.js.map +1 -0
- package/dist/icons/scissors.d.ts +2 -0
- package/dist/icons/scissors.js +26 -0
- package/dist/icons/scissors.js.map +1 -0
- package/dist/icons/shield-question.d.ts +2 -0
- package/dist/icons/shield-question.js +14 -0
- package/dist/icons/shield-question.js.map +1 -0
- package/dist/icons/square-plus.d.ts +2 -0
- package/dist/icons/square-plus.js +20 -0
- package/dist/icons/square-plus.js.map +1 -0
- package/dist/icons/text-select.d.ts +2 -0
- package/dist/icons/text-select.js +14 -0
- package/dist/icons/text-select.js.map +1 -0
- package/dist/icons/window-maximize.d.ts +2 -0
- package/dist/icons/window-maximize.js +14 -0
- package/dist/icons/window-maximize.js.map +1 -0
- package/dist/icons/window-restore.d.ts +2 -0
- package/dist/icons/window-restore.js +20 -0
- package/dist/icons/window-restore.js.map +1 -0
- package/dist/index.d.ts +24 -9
- package/dist/index.js +326 -282
- package/dist/overlay/dismiss.js +15 -13
- package/dist/overlay/dismiss.js.map +1 -1
- package/dist/overlay/floating.d.ts +7 -2
- package/dist/overlay/floating.js +29 -21
- package/dist/overlay/floating.js.map +1 -1
- package/dist/overlay/listbox-layer.d.ts +3 -2
- package/dist/overlay/listbox-layer.js.map +1 -1
- package/dist/overlay/position.d.ts +5 -2
- package/dist/overlay/position.js +19 -19
- package/dist/overlay/position.js.map +1 -1
- package/dist/overlay/toast-host.js +3 -2
- package/dist/overlay/toast-host.js.map +1 -1
- package/dist/overlay/use-anchored-position.d.ts +2 -2
- package/dist/overlay/use-anchored-position.js +25 -25
- package/dist/overlay/use-anchored-position.js.map +1 -1
- package/dist/styles/badge.css +1 -1
- package/dist/styles/base.css +1 -1
- package/dist/styles/button.css +1 -1
- package/dist/styles/calendar.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/chat-message.css +1 -0
- package/dist/styles/code-block.css +1 -1
- package/dist/styles/command-palette.css +1 -1
- package/dist/styles/data-grid.css +1 -0
- package/dist/styles/disclosure.css +1 -1
- package/dist/styles/error-boundary.css +1 -0
- package/dist/styles/field.css +1 -1
- package/dist/styles/file-drop.css +1 -1
- package/dist/styles/generated-css.d.ts +1 -1
- package/dist/styles/generated-css.js +3 -3
- package/dist/styles/generated-css.js.map +1 -1
- package/dist/styles/highlighted-text.css +1 -0
- package/dist/styles/hotkey-field.css +1 -0
- package/dist/styles/list-row.css +1 -0
- package/dist/styles/loading-dots.css +1 -1
- package/dist/styles/manifest.json +149 -12
- package/dist/styles/menu.css +1 -1
- package/dist/styles/menubar.css +1 -0
- package/dist/styles/notice.css +1 -1
- package/dist/styles/option-list.css +1 -1
- package/dist/styles/overlay-frame.css +1 -0
- package/dist/styles/pan-zoom-canvas.css +1 -1
- package/dist/styles/path-field.css +1 -0
- package/dist/styles/popover.css +1 -1
- package/dist/styles/progress-bar.css +1 -1
- package/dist/styles/row-actions.css +1 -0
- package/dist/styles/scroll-area.css +1 -0
- package/dist/styles/search-field.css +1 -0
- package/dist/styles/segmented-control.css +1 -1
- package/dist/styles/select.css +1 -1
- package/dist/styles/side-nav.css +1 -1
- package/dist/styles/sort-button.css +1 -0
- package/dist/styles/split-pane.css +1 -1
- package/dist/styles/status-bar.css +1 -0
- package/dist/styles/table.css +1 -1
- package/dist/styles/tabs.css +1 -1
- package/dist/styles/text-area.css +1 -1
- package/dist/styles/text-field.css +1 -1
- package/dist/styles/text.css +1 -1
- package/dist/styles/title-bar.css +1 -0
- package/dist/styles/toast.css +1 -1
- package/dist/styles/tokens.css +3 -3
- package/dist/styles/tree.css +1 -1
- package/dist/styles/virtual-list.css +1 -1
- package/dist/styles.css +3 -3
- package/dist/theme/CynosureTheme.d.ts +7 -3
- package/dist/theme/CynosureTheme.js +47 -31
- package/dist/theme/CynosureTheme.js.map +1 -1
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/theme-context.d.ts +9 -0
- package/dist/theme/theme-context.js +8 -0
- package/dist/theme/theme-context.js.map +1 -0
- package/dist/theme/theme-init-script.js +0 -1
- package/dist/theme/theme-init-script.js.map +1 -1
- package/dist/theme/use-color-mode.d.ts +3 -2
- package/dist/theme/use-color-mode.js +35 -38
- package/dist/theme/use-color-mode.js.map +1 -1
- package/dist/theme/use-cynosure-theme.d.ts +18 -0
- package/dist/theme/use-cynosure-theme.js +23 -0
- package/dist/theme/use-cynosure-theme.js.map +1 -0
- package/dist/tokens/chart-themes.d.ts +38 -0
- package/dist/tokens/chart-themes.js +35 -0
- package/dist/tokens/chart-themes.js.map +1 -0
- package/dist/tokens/create-theme.d.ts +11 -1
- package/dist/tokens/create-theme.js +161 -121
- package/dist/tokens/create-theme.js.map +1 -1
- package/dist/tokens/defaults.d.ts +3 -3
- package/dist/tokens/defaults.js +1 -0
- package/dist/tokens/defaults.js.map +1 -1
- package/dist/tokens/editor-themes.d.ts +9 -2
- package/dist/tokens/editor-themes.js +43 -42
- package/dist/tokens/editor-themes.js.map +1 -1
- package/dist/tokens/index.d.ts +3 -1
- package/dist/tokens/named-themes.d.ts +41 -0
- package/dist/tokens/named-themes.js +118 -0
- package/dist/tokens/named-themes.js.map +1 -0
- package/dist/tokens/schema.d.ts +24 -1
- package/dist/tokens/schema.js +13 -0
- package/dist/tokens/schema.js.map +1 -0
- package/dist/tokens/to-css.js +34 -31
- package/dist/tokens/to-css.js.map +1 -1
- package/package.json +10 -6
- package/dist/components/Stack/space.js +0 -23
- package/dist/components/Stack/space.js.map +0 -1
|
@@ -1,92 +1,93 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const n = t.getContext("2d");
|
|
26
|
-
n.setTransform(e, 0, 0, e, 0, 0), i && c.width > 0 && n.scale(c.width / i.width, c.height / i.height), n.fillStyle = P ?? getComputedStyle(t).color;
|
|
27
|
-
for (const o of g ? [...s, g] : s) n.fill(new Path2D(B(o, b)));
|
|
2
|
+
import { useCanvasSize as B } from "../../foundations/canvas-size.js";
|
|
3
|
+
import { inkPath as R, inkPoint as G } from "./ink.js";
|
|
4
|
+
import { useCallback as L, useEffect as U, useRef as u } from "react";
|
|
5
|
+
import { jsx as A } from "react/jsx-runtime";
|
|
6
|
+
var V = 0.75, W = 3e3;
|
|
7
|
+
function K({ label: _, value: l, onChange: q, ink: b, weight: a = "medium", space: s, width: x, height: C, disabled: h = !1, "aria-describedby": v, className: T, style: F }) {
|
|
8
|
+
const m = u(null), i = u(null), y = u(null), I = u(Number.NEGATIVE_INFINITY), f = u(l);
|
|
9
|
+
f.current = l;
|
|
10
|
+
const c = B(m), M = u(/* @__PURE__ */ new WeakMap()), d = L(() => {
|
|
11
|
+
const t = m.current;
|
|
12
|
+
if (!t) return;
|
|
13
|
+
const { dpr: n } = c;
|
|
14
|
+
for (const o of ["width", "height"]) {
|
|
15
|
+
const e = Math.round(c[o] * n);
|
|
16
|
+
t[o] !== e && (t[o] = e);
|
|
17
|
+
}
|
|
18
|
+
const r = t.getContext("2d");
|
|
19
|
+
r.setTransform(n, 0, 0, n, 0, 0), r.clearRect(0, 0, c.width, c.height), s && c.width > 0 && r.scale(c.width / s.width, c.height / s.height), r.fillStyle = b ?? getComputedStyle(t).color;
|
|
20
|
+
for (const o of l) {
|
|
21
|
+
let e = M.current.get(o);
|
|
22
|
+
e?.[0] !== a && (e = [a, new Path2D(R(o, a))], M.current.set(o, e)), r.fill(e[1]);
|
|
23
|
+
}
|
|
24
|
+
i.current && r.fill(new Path2D(R(i.current, a)));
|
|
28
25
|
}, [
|
|
29
|
-
|
|
30
|
-
g,
|
|
31
|
-
P,
|
|
26
|
+
l,
|
|
32
27
|
b,
|
|
33
|
-
|
|
28
|
+
a,
|
|
29
|
+
s,
|
|
34
30
|
c
|
|
35
31
|
]);
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
U(d, [d]);
|
|
33
|
+
const w = u(d);
|
|
34
|
+
w.current = d;
|
|
35
|
+
const E = u(0), g = () => {
|
|
36
|
+
E.current ||= requestAnimationFrame(() => {
|
|
37
|
+
E.current = 0, w.current();
|
|
38
|
+
});
|
|
39
|
+
}, N = (t, n) => {
|
|
40
|
+
const r = t.currentTarget.getBoundingClientRect(), o = s ? {
|
|
41
|
+
x: s.width / r.width,
|
|
42
|
+
y: s.height / r.height
|
|
43
|
+
} : void 0, e = t.nativeEvent, D = e.getCoalescedEvents?.() ?? [];
|
|
44
|
+
for (const j of D.length ? D : [e]) {
|
|
45
|
+
const p = n[n.length - 1] ?? null, S = G(j, r, p, o);
|
|
46
|
+
p && Math.hypot(S.x - p.x, S.y - p.y) < V || n.push(S);
|
|
46
47
|
}
|
|
47
|
-
return
|
|
48
|
-
},
|
|
49
|
-
t.pointerType === "pen" && (
|
|
50
|
-
},
|
|
51
|
-
if (
|
|
52
|
-
const
|
|
53
|
-
|
|
48
|
+
return n;
|
|
49
|
+
}, k = (t) => i.current !== null && t.pointerId === y.current, P = (t) => {
|
|
50
|
+
t.pointerType === "pen" && (I.current = t.timeStamp);
|
|
51
|
+
}, z = (t) => {
|
|
52
|
+
if (P(t), !k(t)) return;
|
|
53
|
+
const n = i.current;
|
|
54
|
+
i.current = null, y.current = null, f.current = [...f.current, n], q(f.current), g();
|
|
54
55
|
};
|
|
55
|
-
return /* @__PURE__ */
|
|
56
|
+
return /* @__PURE__ */ A("div", {
|
|
56
57
|
className: T ? `cy-signature-pad ${T}` : "cy-signature-pad",
|
|
57
|
-
"data-disabled":
|
|
58
|
+
"data-disabled": h ? "" : void 0,
|
|
58
59
|
style: {
|
|
59
|
-
...
|
|
60
|
-
...
|
|
61
|
-
...
|
|
60
|
+
...x ? { inlineSize: x } : {},
|
|
61
|
+
...C ? { blockSize: C } : {},
|
|
62
|
+
...F
|
|
62
63
|
},
|
|
63
|
-
children: /* @__PURE__ */
|
|
64
|
-
ref:
|
|
64
|
+
children: /* @__PURE__ */ A("canvas", {
|
|
65
|
+
ref: m,
|
|
65
66
|
role: "img",
|
|
66
67
|
"aria-label": _,
|
|
67
|
-
"aria-describedby":
|
|
68
|
-
"aria-disabled":
|
|
68
|
+
"aria-describedby": v,
|
|
69
|
+
"aria-disabled": h || void 0,
|
|
69
70
|
className: "cy-signature-pad-canvas cy-reset",
|
|
70
71
|
onPointerDown: (t) => {
|
|
71
|
-
if (
|
|
72
|
+
if (P(t), !(h || i.current) && !(t.pointerType !== "touch" && t.button !== 0) && !(t.pointerType === "touch" && t.timeStamp - I.current < W)) {
|
|
72
73
|
try {
|
|
73
74
|
t.currentTarget.setPointerCapture(t.pointerId);
|
|
74
75
|
} catch {
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
+
y.current = t.pointerId, i.current = N(t, []), g();
|
|
77
78
|
}
|
|
78
79
|
},
|
|
79
80
|
onPointerMove: (t) => {
|
|
80
|
-
|
|
81
|
+
P(t), k(t) && (N(t, i.current), g());
|
|
81
82
|
},
|
|
82
|
-
onPointerUp:
|
|
83
|
-
onPointerCancel:
|
|
83
|
+
onPointerUp: z,
|
|
84
|
+
onPointerCancel: z,
|
|
84
85
|
onContextMenu: (t) => t.preventDefault()
|
|
85
86
|
})
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
89
|
export {
|
|
89
|
-
|
|
90
|
+
K as SignaturePad
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
//# sourceMappingURL=SignaturePad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignaturePad.js","names":["inkPath","inkPoint","useCallback","useEffect","useRef","useState","jsx","MIN_STEP","PALM_MS","SignaturePad","label","value","onChange","ink","weight","space","width","height","disabled","describedBy","className","style","canvas","liveRef","pointer","penSeen","live","setLive","committed","size","setSize","el","measure","s","observer","paint","dpr","ctx","stroke","sample","event","rect","scale","native","samples","out","e","prev","p","ours","notePen","finish"],"sources":["../../../src/components/SignaturePad/SignaturePad.tsx"],"sourcesContent":["import { type CSSProperties, type PointerEvent, useCallback, useEffect, useRef, useState } from \"react\";\nimport { type InkPoint, type InkStroke, type InkWeight, inkPath, inkPoint } from \"./ink.js\";\n\nexport interface SignaturePadTokens {\n /** Ink colour when no `ink` is given (follows light and dark modes). */\n ink: string;\n /** Background of the pad. */\n background: string;\n /** Height when no `height` is given. */\n height: string;\n /** Colour of the guide line people sign on. */\n guide: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n signaturePad: SignaturePadTokens;\n }\n}\n\nexport interface SignaturePadProps {\n /** Accessible name, e.g. \"Draw your signature\". */\n label: string;\n /** The strokes so far, in the pad's coordinate space. */\n value: InkStroke[];\n /** Called once per finished stroke with the new list. Undo and clear are yours (slice or empty the list). */\n onChange: (strokes: InkStroke[]) => void;\n /** Ink colour (any CSS colour). Default: the ink token, so it follows dark mode on screen. */\n ink?: string | undefined;\n /** Nib size. Default `medium`. */\n weight?: InkWeight;\n /**\n * The coordinate space strokes are recorded in. Without it strokes are in shown CSS pixels; with it a signature keeps\n * its shape and weight however big the pad is shown (phone width, text size, a resize while drawing).\n */\n space?: { width: number; height: number } | undefined;\n /** Fixed size in CSS pixels. Default: the full width, and the height token. */\n width?: number | undefined;\n /** Fixed height in CSS pixels. Default: the height token. */\n height?: number | undefined;\n /** Stops drawing; the strokes so far stay shown. */\n disabled?: boolean;\n /** Ids of text that explains the pad (e.g. \"Or type your name instead\"). */\n \"aria-describedby\"?: string | undefined;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-signature-pad-* tokens. */\n style?: CSSProperties;\n}\n\n/** Samples closer than this (pad units) to the last one add nothing. */\nconst MIN_STEP = 0.75;\n/** Touches are ignored for this long after a pen was last seen: a resting palm. */\nconst PALM_MS = 3000;\n\n/**\n * A pad to draw a signature with a mouse, finger or pen. A pen's pressure and tilt shape the line; mouse and touch draw\n * a steady line. One pointer draws at a time, and a palm resting while a pen is in use is ignored. It draws, nothing\n * more: offer typing or uploading a signature beside it for people who cannot draw.\n */\nexport function SignaturePad({\n label,\n value,\n onChange,\n ink,\n weight = \"medium\",\n space,\n width,\n height,\n disabled = false,\n \"aria-describedby\": describedBy,\n className,\n style,\n}: SignaturePadProps) {\n const canvas = useRef<HTMLCanvasElement>(null);\n // Several pointer events can arrive between renders: the stroke in progress lives in a ref; state mirrors it.\n const liveRef = useRef<InkStroke | null>(null);\n const pointer = useRef<number | null>(null);\n const penSeen = useRef(Number.NEGATIVE_INFINITY);\n const [live, setLive] = useState<InkStroke | null>(null);\n // The latest list, updated the moment a stroke ends: a second stroke can finish before React re-renders.\n const committed = useRef(value);\n committed.current = value;\n const [size, setSize] = useState({ width: 0, height: 0 });\n\n useEffect(() => {\n const el = canvas.current as HTMLCanvasElement;\n const measure = () =>\n setSize((s) =>\n s.width === el.clientWidth && s.height === el.clientHeight\n ? s\n : { width: el.clientWidth, height: el.clientHeight },\n );\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(el);\n return () => observer.disconnect();\n }, []);\n\n const paint = useCallback(() => {\n const el = canvas.current as HTMLCanvasElement;\n const dpr = window.devicePixelRatio;\n el.width = Math.round(size.width * dpr);\n el.height = Math.round(size.height * dpr);\n const ctx = el.getContext(\"2d\") as CanvasRenderingContext2D;\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n if (space && size.width > 0) ctx.scale(size.width / space.width, size.height / space.height);\n ctx.fillStyle = ink ?? getComputedStyle(el).color;\n for (const stroke of live ? [...value, live] : value) {\n // Every stroke has at least its first sample, so it always has an outline.\n ctx.fill(new Path2D(inkPath(stroke, weight)));\n }\n }, [value, live, ink, weight, space, size]);\n useEffect(paint, [paint]);\n\n const sample = (event: PointerEvent<HTMLCanvasElement>, stroke: InkStroke): InkStroke => {\n const rect = event.currentTarget.getBoundingClientRect();\n const scale = space ? { x: space.width / rect.width, y: space.height / rect.height } : undefined;\n const native = event.nativeEvent;\n // Coalesced events keep a fast stroke smooth: the browser batches several samples into one event.\n const samples = native.getCoalescedEvents?.() ?? [];\n let out = stroke;\n for (const e of samples.length ? samples : [native]) {\n const prev: InkPoint | null = out[out.length - 1] ?? null;\n const p = inkPoint(e, rect, prev, scale);\n if (prev && Math.hypot(p.x - prev.x, p.y - prev.y) < MIN_STEP) continue;\n out = [...out, p];\n }\n return out;\n };\n\n const ours = (event: PointerEvent) => liveRef.current !== null && event.pointerId === pointer.current;\n const notePen = (event: PointerEvent) => {\n if (event.pointerType === \"pen\") penSeen.current = event.timeStamp;\n };\n const finish = (event: PointerEvent<HTMLCanvasElement>) => {\n notePen(event);\n if (!ours(event)) return;\n const stroke = liveRef.current as InkStroke;\n liveRef.current = null;\n pointer.current = null;\n setLive(null);\n committed.current = [...committed.current, stroke];\n onChange(committed.current);\n };\n\n return (\n <div\n className={className ? `cy-signature-pad ${className}` : \"cy-signature-pad\"}\n data-disabled={disabled ? \"\" : undefined}\n style={{ ...(width ? { inlineSize: width } : {}), ...(height ? { blockSize: height } : {}), ...style }}\n >\n <canvas\n ref={canvas}\n role=\"img\"\n aria-label={label}\n aria-describedby={describedBy}\n aria-disabled={disabled || undefined}\n className=\"cy-signature-pad-canvas cy-reset\"\n onPointerDown={(event) => {\n notePen(event);\n // One stroke at a time: a second finger or a resting palm does not take over.\n if (disabled || liveRef.current) return;\n // Only the tip (or the main mouse button) draws, not a pen's barrel button or eraser.\n if (event.pointerType !== \"touch\" && event.button !== 0) return;\n if (event.pointerType === \"touch\" && event.timeStamp - penSeen.current < PALM_MS) return;\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Synthetic events have no active pointer to capture.\n }\n pointer.current = event.pointerId;\n liveRef.current = sample(event, []);\n setLive(liveRef.current);\n }}\n onPointerMove={(event) => {\n notePen(event);\n if (!ours(event)) return;\n liveRef.current = sample(event, liveRef.current as InkStroke);\n setLive(liveRef.current);\n }}\n onPointerUp={finish}\n onPointerCancel={finish}\n // A long press opens the context menu on Windows and Android, which would cancel the stroke.\n onContextMenu={(event) => event.preventDefault()}\n />\n </div>\n );\n}\n"],"mappings":";;;;AAmDA,IAAMO,IAAW,MAEXC,IAAU;AAOhB,SAAgBC,EAAa,EAC3B,OAAAC,GACA,OAAAC,GACA,UAAAC,GACA,KAAAC,GACA,QAAAC,IAAS,UACT,OAAAC,GACA,OAAAC,GACA,QA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AAM,eAAe;AAAA,IAChD,CAAA;AAAA,EACE,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"SignaturePad.js","names":["useCanvasSize","inkPath","inkPoint","useCallback","useEffect","useRef","jsx","MIN_STEP","PALM_MS","SignaturePad","label","value","onChange","ink","weight","space","width","height","disabled","describedBy","className","style","canvas","liveRef","pointer","penSeen","committed","size","outlines","paint","el","dpr","side","pixels","ctx","stroke","known","latestPaint","frame","requestPaint","sample","event","rect","scale","native","samples","e","prev","p","ours","notePen","finish"],"sources":["../../../src/components/SignaturePad/SignaturePad.tsx"],"sourcesContent":["import { type CSSProperties, type PointerEvent, useCallback, useEffect, useRef } from \"react\";\nimport { useCanvasSize } from \"../../foundations/canvas-size.js\";\nimport { type InkPoint, type InkStroke, type InkWeight, inkPath, inkPoint } from \"./ink.js\";\n\nexport interface SignaturePadTokens {\n /** Ink colour when no `ink` is given (follows light and dark modes). */\n ink: string;\n /** Background of the pad. */\n background: string;\n /** Height when no `height` is given. */\n height: string;\n /** Colour of the guide line people sign on. */\n guide: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n signaturePad: SignaturePadTokens;\n }\n}\n\nexport interface SignaturePadProps {\n /** Accessible name, e.g. \"Draw your signature\". */\n label: string;\n /** The strokes so far, in the pad's coordinate space. */\n value: InkStroke[];\n /** Called once per finished stroke with the new list. Undo and clear are yours (slice or empty the list). */\n onChange: (strokes: InkStroke[]) => void;\n /** Ink colour (any CSS colour). Default: the ink token, so it follows dark mode on screen. */\n ink?: string | undefined;\n /** Nib size. Default `medium`. */\n weight?: InkWeight;\n /**\n * The coordinate space strokes are recorded in. Without it strokes are in shown CSS pixels; with it a signature keeps\n * its shape and weight however big the pad is shown (phone width, text size, a resize while drawing).\n */\n space?: { width: number; height: number } | undefined;\n /** Fixed size in CSS pixels. Default: the full width, and the height token. */\n width?: number | undefined;\n /** Fixed height in CSS pixels. Default: the height token. */\n height?: number | undefined;\n /** Stops drawing; the strokes so far stay shown. */\n disabled?: boolean;\n /** Ids of text that explains the pad (e.g. \"Or type your name instead\"). */\n \"aria-describedby\"?: string | undefined;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-signature-pad-* tokens. */\n style?: CSSProperties;\n}\n\n/** Samples closer than this (pad units) to the last one add nothing. */\nconst MIN_STEP = 0.75;\n/** Touches are ignored for this long after a pen was last seen: a resting palm. */\nconst PALM_MS = 3000;\n\n/**\n * A pad to draw a signature with a mouse, finger or pen. A pen's pressure and tilt shape the line; mouse and touch draw\n * a steady line. One pointer draws at a time, and a palm resting while a pen is in use is ignored. It draws, nothing\n * more: offer typing or uploading a signature beside it for people who cannot draw.\n */\nexport function SignaturePad({\n label,\n value,\n onChange,\n ink,\n weight = \"medium\",\n space,\n width,\n height,\n disabled = false,\n \"aria-describedby\": describedBy,\n className,\n style,\n}: SignaturePadProps) {\n const canvas = useRef<HTMLCanvasElement>(null);\n // The stroke in progress lives in a ref, grown in place and drawn once per frame: pointer moves never re-render.\n const liveRef = useRef<InkStroke | null>(null);\n const pointer = useRef<number | null>(null);\n const penSeen = useRef(Number.NEGATIVE_INFINITY);\n // The latest list, updated the moment a stroke ends: a second stroke can finish before React re-renders.\n const committed = useRef(value);\n committed.current = value;\n // Measured with the screen's density, and again when it changes (a move to another screen, a browser zoom).\n const size = useCanvasSize(canvas);\n\n // One outline per finished stroke, kept while the stroke and the nib are the same.\n const outlines = useRef(new WeakMap<InkStroke, [InkWeight, Path2D]>());\n const paint = useCallback(() => {\n const el = canvas.current;\n if (!el) return;\n const { dpr } = size;\n // The canvas is reallocated only when its size or pixel ratio changes.\n for (const side of [\"width\", \"height\"] as const) {\n const pixels = Math.round(size[side] * dpr);\n if (el[side] !== pixels) el[side] = pixels;\n }\n const ctx = el.getContext(\"2d\") as CanvasRenderingContext2D;\n ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n ctx.clearRect(0, 0, size.width, size.height);\n if (space && size.width > 0) ctx.scale(size.width / space.width, size.height / space.height);\n ctx.fillStyle = ink ?? getComputedStyle(el).color;\n // Every stroke has at least its first sample, so it always has an outline.\n for (const stroke of value) {\n let known = outlines.current.get(stroke);\n if (known?.[0] !== weight) {\n known = [weight, new Path2D(inkPath(stroke, weight))];\n outlines.current.set(stroke, known);\n }\n ctx.fill(known[1]);\n }\n // The live stroke changes on every move: its outline is built afresh each frame.\n if (liveRef.current) ctx.fill(new Path2D(inkPath(liveRef.current, weight)));\n }, [value, ink, weight, space, size]);\n useEffect(paint, [paint]);\n\n // Pointer moves ask for a frame; the latest paint draws it (nothing, once the pad is gone).\n const latestPaint = useRef(paint);\n latestPaint.current = paint;\n const frame = useRef(0);\n const requestPaint = () => {\n frame.current ||= requestAnimationFrame(() => {\n frame.current = 0;\n latestPaint.current();\n });\n };\n\n const sample = (event: PointerEvent<HTMLCanvasElement>, stroke: InkStroke): InkStroke => {\n const rect = event.currentTarget.getBoundingClientRect();\n const scale = space ? { x: space.width / rect.width, y: space.height / rect.height } : undefined;\n const native = event.nativeEvent;\n // Coalesced events keep a fast stroke smooth: the browser batches several samples into one event.\n const samples = native.getCoalescedEvents?.() ?? [];\n // The live stroke is ours alone until it is finished, so samples are pushed onto it rather than copied.\n for (const e of samples.length ? samples : [native]) {\n const prev: InkPoint | null = stroke[stroke.length - 1] ?? null;\n const p = inkPoint(e, rect, prev, scale);\n if (prev && Math.hypot(p.x - prev.x, p.y - prev.y) < MIN_STEP) continue;\n stroke.push(p);\n }\n return stroke;\n };\n\n const ours = (event: PointerEvent) => liveRef.current !== null && event.pointerId === pointer.current;\n const notePen = (event: PointerEvent) => {\n if (event.pointerType === \"pen\") penSeen.current = event.timeStamp;\n };\n const finish = (event: PointerEvent<HTMLCanvasElement>) => {\n notePen(event);\n if (!ours(event)) return;\n const stroke = liveRef.current as InkStroke;\n liveRef.current = null;\n pointer.current = null;\n committed.current = [...committed.current, stroke];\n onChange(committed.current);\n // Drawn from `value` from now on: if the owner keeps the stroke, the next render paints it.\n requestPaint();\n };\n\n return (\n <div\n className={className ? `cy-signature-pad ${className}` : \"cy-signature-pad\"}\n data-disabled={disabled ? \"\" : undefined}\n style={{ ...(width ? { inlineSize: width } : {}), ...(height ? { blockSize: height } : {}), ...style }}\n >\n <canvas\n ref={canvas}\n role=\"img\"\n aria-label={label}\n aria-describedby={describedBy}\n aria-disabled={disabled || undefined}\n className=\"cy-signature-pad-canvas cy-reset\"\n onPointerDown={(event) => {\n notePen(event);\n // One stroke at a time: a second finger or a resting palm does not take over.\n if (disabled || liveRef.current) return;\n // Only the tip (or the main mouse button) draws, not a pen's barrel button or eraser.\n if (event.pointerType !== \"touch\" && event.button !== 0) return;\n if (event.pointerType === \"touch\" && event.timeStamp - penSeen.current < PALM_MS) return;\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Synthetic events have no active pointer to capture.\n }\n pointer.current = event.pointerId;\n liveRef.current = sample(event, []);\n requestPaint();\n }}\n onPointerMove={(event) => {\n notePen(event);\n if (!ours(event)) return;\n sample(event, liveRef.current as InkStroke);\n requestPaint();\n }}\n onPointerUp={finish}\n onPointerCancel={finish}\n // A long press opens the context menu on Windows and Android, which would cancel the stroke.\n onContextMenu={(event) => event.preventDefault()}\n />\n </div>\n );\n}\n"],"mappings":";;;;;AAoDA,IAAMO,IAAW,MAEXC,IAAU;AAOhB,SAAgBC,EAAa,EAC3B,OAAAC,GACA,OAAAC,GACA,UAAAC,GACA,KAAAC,GACA,QAAAC,IAAS,UACT,OAAAC,GACA,OAAAC,GACA,QAAAC,GACA,UAAAC,IAAW,IACX,oBAAoBC,GACpB,WAAAC,GACA,OAAAC,EAAA,GACoB;AACpB,QAAMC,IAASjB,EAA0B,IAAI,GAEvCkB,IAAUlB,EAAyB,IAAI,GACvCmB,IAAUnB,EAAsB,IAAI,GACpCoB,IAAUpB,EAAO,OAAO,iBAAiB,GAEzCqB,IAAYrB,EAAOM,CAAK;AAC9B,EAAAe,EAAU,UAAUf;AAEpB,QAAMgB,IAAO3B,EAAcs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AjC,EAAC,OAAD;AAAA,IACE,WAAWc,IAAY,oBAAoBA,CAAA,KAAc;AAAA,IACzD,iBAAeF,IAAW,KAAK;AAAA,IAC/B,OAAO;AAAA,MAAE,GAAIF,IAAQ,EAAE,YAAYA,EAAM,IAAI,CAAC;AAAA,MAAI,GAAIC,IAAS,EAAE,WAAWA,EAAO,IAAI,CAAC;AAAA,MAAI,GAAGI;AAAA,IAAM;AAAA,IAErG,UAAA,gBAAAf,EAAC,UAAD;AAAA,MACE,KAAKgB;AAAA,MACL,MAAK;AAAA,MACL,cAAYZ;AAAA,MACZ,oBAAkBS;AAAA,MAClB,iBAAeD,KAAY;AAAA,MAC3B,WAAU;AAAA,MACV,eAAA,CAAgBuB,MAAU;AAGxB,YAFAS,EAAQT,CAAK,GAET,EAAAvB,KAAYK,EAAQ,YAEpB,EAAAkB,EAAM,gBAAgB,WAAWA,EAAM,WAAW,MAClD,EAAAA,EAAM,gBAAgB,WAAWA,EAAM,YAAYhB,EAAQ,UAAUjB,IACzE;AAAA,cAAI;AACF,YAAAiC,EAAM,cAAc,kBAAkBA,EAAM,SAAS;AAAA,UACvD,QAAQ;AAAA,UAER;AACA,UAAAjB,EAAQ,UAAUiB,EAAM,WACxBlB,EAAQ,UAAUiB,EAAOC,GAAO,CAAC,CAAC,GAClCF,EAAa;AAAA;AAAA,MACf;AAAA,MACA,eAAA,CAAgBE,MAAU;AAExB,QADAS,EAAQT,CAAK,GACRQ,EAAKR,CAAK,MACfD,EAAOC,GAAOlB,EAAQ,OAAoB,GAC1CgB,EAAa;AAAA,MACf;AAAA,MACA,aAAaY;AAAA,MACb,iBAAiBA;AAAA,MAEjB,eAAA,CAAgBV,MAAUA,EAAM,eAAe;AAAA,IAChD,CAAA;AAAA,EACE,CAAA;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ink.js","names":["clamp","INK_WEIGHTS","STEADY_PRESSURE","penPressure","raw","previous","curved","inkPoint","event","rect","scale","x","y","CAP_STEPS","inkOutline","stroke","weight","tilt","sum","p","size","pts","i","r","a","b","first","arc","cx","cy","from","_","k","left","right","angles","len","nx","ny","last","endCap","startCap","f","n","outlineToPath","outline","mid","current","d","q","end","c1","c2","inkPath","inkToSvg","strokes","options","paths","s","fill"],"sources":["../../../src/components/SignaturePad/ink.ts"],"sourcesContent":["import { clamp } from \"../../foundations/math.js\";\n/**\n * Ink geometry for SignaturePad: pressure from the pen (constant for a mouse or finger), a filled, round-capped\n * outline per stroke, and SVG path data that a canvas (Path2D) and a PDF writer both read the same way. No\n * dependencies: the outline is the offset of a lightly smoothed centre line, which is all a signature needs.\n */\n\n/** One sample: pad units (y down), pressure 0..1, tilt in degrees, time in ms. */\nexport interface InkPoint {\n x: number;\n y: number;\n pressure: number;\n tiltX: number;\n tiltY: number;\n t: number;\n}\nexport type InkStroke = InkPoint[];\nexport type InkWeight = \"thin\" | \"medium\" | \"bold\";\n\n/** Nib diameter in pad units at pressure 0.5. */\nexport const INK_WEIGHTS: Record<InkWeight, number> = { thin: 2.2, medium: 3.4, bold: 5 };\n\n/**\n * Pressure for a mouse or finger, which report none. Constant, like a ballpoint: pressure simulated from speed makes\n * the line wobble as the hand speeds up and slows down, which no real pen does.\n */\nexport const STEADY_PRESSURE = 0.5;\n\n/**\n * A pen's raw pressure through a response curve, eased against the last sample. Pens report light writing as\n * 0.1–0.3, a hairline if used raw, so the curve lifts the low end; easing hides the digitiser's jitter.\n */\nexport function penPressure(raw: number, previous: number | null): number {\n const curved = 0.15 + 0.85 * clamp(raw, 0, 1) ** 0.65;\n return previous === null ? curved : previous + (curved - previous) * 0.5;\n}\n\n/** A sample from a pointer event. `scale` maps shown CSS pixels to the pad's coordinate space. */\nexport function inkPoint(\n event: PointerEvent,\n rect: DOMRect,\n previous: InkPoint | null,\n scale = { x: 1, y: 1 },\n): InkPoint {\n const x = (event.clientX - rect.left) * scale.x;\n const y = (event.clientY - rect.top) * scale.y;\n if (event.pointerType !== \"pen\")\n return { x, y, pressure: STEADY_PRESSURE, tiltX: 0, tiltY: 0, t: event.timeStamp };\n // A pen reports 0 as it lifts off: keep the last pressure, or each stroke would end in a blob or a dot.\n const pressure =\n event.pressure > 0\n ? penPressure(event.pressure, previous?.pressure ?? null)\n : (previous?.pressure ?? STEADY_PRESSURE);\n return { x, y, pressure, tiltX: event.tiltX || 0, tiltY: event.tiltY || 0, t: event.timeStamp };\n}\n\ntype Vec = [number, number];\nconst CAP_STEPS = 8;\n\n/** The filled outline of one stroke: a closed polygon in pad units. */\nexport function inkOutline(stroke: InkStroke, weight: InkWeight, scale = 1): Vec[] {\n if (stroke.length === 0) return [];\n const tilt = stroke.reduce((sum, p) => sum + Math.hypot(p.tiltX, p.tiltY), 0) / stroke.length;\n const size = INK_WEIGHTS[weight] * scale * (1 + 0.25 * Math.min(1, tilt / 60));\n // Light smoothing (1-2-1) takes the jitter out of the centre line without rounding off corners. The ends stay where\n // they were drawn, or every stroke would come up short.\n const pts = stroke.map((p, i) => {\n const r = (size / 2) * (0.4 + 1.2 * p.pressure);\n const a = stroke[i - 1];\n const b = stroke[i + 1];\n if (!a || !b) return { x: p.x, y: p.y, r };\n return { x: (a.x + 2 * p.x + b.x) / 4, y: (a.y + 2 * p.y + b.y) / 4, r };\n });\n const first = pts[0] as (typeof pts)[number];\n const arc = (cx: number, cy: number, r: number, from: number): Vec[] =>\n Array.from({ length: CAP_STEPS + 1 }, (_, k) => {\n const a = from - (Math.PI * k) / CAP_STEPS;\n return [cx + r * Math.cos(a), cy + r * Math.sin(a)];\n });\n if (pts.length === 1)\n return arc(first.x, first.y, first.r, 0).concat(arc(first.x, first.y, first.r, Math.PI));\n const left: Vec[] = [];\n const right: Vec[] = [];\n const angles: number[] = [];\n pts.forEach((p, i) => {\n const a = pts[Math.max(0, i - 1)] as typeof p;\n const b = pts[Math.min(pts.length - 1, i + 1)] as typeof p;\n const len = Math.hypot(b.x - a.x, b.y - a.y) || 1;\n // The normal to the direction of travel: the left side of the stroke.\n const nx = -(b.y - a.y) / len;\n const ny = (b.x - a.x) / len;\n left.push([p.x + nx * p.r, p.y + ny * p.r]);\n right.push([p.x - nx * p.r, p.y - ny * p.r]);\n angles.push(Math.atan2(ny, nx));\n });\n const last = pts[pts.length - 1] as typeof first;\n // Round caps: from the left side round the end to the right side, then back round the start.\n const endCap = arc(last.x, last.y, last.r, angles[angles.length - 1] as number);\n const startCap = arc(first.x, first.y, first.r, (angles[0] as number) + Math.PI);\n return [...left, ...endCap, ...right.reverse(), ...startCap];\n}\n\nconst f = (n: number) => Math.round(n * 100) / 100;\n\n/**\n * SVG path data for a closed outline: smooth quadratics through the midpoints, written as the equivalent cubics, so the\n * path uses only M, C and Z (what Path2D and PDF writers read alike).\n */\nexport function outlineToPath(outline: Vec[]): string {\n const n = outline.length;\n if (n < 2) return \"\";\n const mid = (a: Vec, b: Vec): Vec => [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];\n let current = mid(outline[n - 1] as Vec, outline[0] as Vec);\n let d = `M${f(current[0])} ${f(current[1])}`;\n for (let i = 0; i < n; i++) {\n const q = outline[i] as Vec;\n const end = mid(q, outline[(i + 1) % n] as Vec);\n const c1 = [current[0] + (2 / 3) * (q[0] - current[0]), current[1] + (2 / 3) * (q[1] - current[1])];\n const c2 = [end[0] + (2 / 3) * (q[0] - end[0]), end[1] + (2 / 3) * (q[1] - end[1])];\n d += `C${f(c1[0] as number)} ${f(c1[1] as number)} ${f(c2[0] as number)} ${f(c2[1] as number)} ${f(end[0])} ${f(end[1])}`;\n current = end;\n }\n return `${d}Z`;\n}\n\n/** Path data for one stroke. */\nexport const inkPath = (stroke: InkStroke, weight: InkWeight) => outlineToPath(inkOutline(stroke, weight));\n\n/** A standalone SVG of the strokes, for saving or placing in a PDF. `width` and `height` are the pad's space. */\nexport function inkToSvg(\n strokes: InkStroke[],\n options: { width: number; height: number; ink: string; weight: InkWeight },\n): string {\n const paths = strokes\n .map((s) => inkPath(s, options.weight))\n .filter(Boolean)\n .map((d) => `<path d=\"${d}\"/>`)\n .join(\"\");\n const fill = options.ink.replace(/[<>\"&]/g, \"\");\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${options.width} ${options.height}\" width=\"${options.width}\" height=\"${options.height}\"><g fill=\"${fill}\">${paths}</g></svg>`;\n}\n"],"mappings":";;AAoBA,IAAaC,IAAyC;AAAA,EAAE,MAAM;AAAA,EAAK,QAAQ;AAAA,EAAK,MAAM;AAAE,GAM3EC,IAAkB;AAM/B,SAAgBC,EAAYC,GAAaC,GAAiC;AACxE,QAAMC,IAAS,OAAO,OAAON,EAAMI,GAAK,GAAG,CAAC,KAAK;AACjD,SAAOC,MAAa,OAAOC,IAASD,KAAYC,IAASD,KAAY;AACvE;AAGA,SAAgBE,EACdC,GACAC,GACAJ,GACAK,IAAQ;AAAA,EAAE,GAAG;AAAA,EAAG,GAAG;AAAE,GACX;AACV,QAAMC,KAAKH,EAAM,UAAUC,EAAK,QAAQC,EAAM,GACxCE,KAAKJ,EAAM,UAAUC,EAAK,OAAOC,EAAM;AAC7C,SAAIF,EAAM,gBAAgB,QACjB;AAAA,IAAE,GAAAG;AAAA,IAAG,GAAAC;AAAA,IAAG,UAAUV;AAAA,IAAiB,OAAO;AAAA,IAAG,OAAO;AAAA,IAAG,GAAGM,EAAM;AAAA,EAAU,IAM5E;AAAA,IAAE,GAAAG;AAAA,IAAG,GAAAC;AAAA,IAAG,UAHbJ,EAAM,WAAW,IACbL,EAAYK,EAAM,UAAUH,GAAU,YAAY,IAAI,IACrDA,GAAU,YAAA;AAAA,IACQ,OAAOG,EAAM,SAAS;AAAA,IAAG,OAAOA,EAAM,SAAS;AAAA,IAAG,GAAGA,EAAM;AAAA,EAAU;AAChG;AAGA,IAAMK,IAAY;AAGlB,SAAgBC,EAAWC,GAAmBC,GAAmBN,IAAQ,GAAU;AACjF,MAAIK,EAAO,WAAW,EAAG,QAAO,CAAC;AACjC,QAAME,IAAOF,EAAO,OAAA,CAAQG,GAAKC,MAAMD,IAAM,K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,EAAQ,KAAA,IAASA,EAAQ,MAAA,YAAkBA,EAAQ,KAAA,aAAkBA,EAAQ,MAAA,cAAoBG,CAAA,KAASF,CAAA;AAC3K"}
|
|
1
|
+
{"version":3,"file":"ink.js","names":["clamp","INK_WEIGHTS","STEADY_PRESSURE","penPressure","raw","previous","curved","inkPoint","event","rect","scale","x","y","CAP_STEPS","inkOutline","stroke","weight","tilt","sum","p","size","pts","i","r","a","b","first","arc","cx","cy","from","_","k","left","right","angles","len","nx","ny","last","endCap","startCap","f","n","outlineToPath","outline","mid","current","d","q","end","c1","c2","inkPath","inkToSvg","strokes","options","paths","s","fill"],"sources":["../../../src/components/SignaturePad/ink.ts"],"sourcesContent":["import { clamp } from \"../../foundations/math.js\";\n/**\n * Ink geometry for SignaturePad: pressure from the pen (constant for a mouse or finger), a filled, round-capped\n * outline per stroke, and SVG path data that a canvas (Path2D) and a PDF writer both read the same way. No\n * dependencies: the outline is the offset of a lightly smoothed centre line, which is all a signature needs.\n */\n\n/** One sample: pad units (y down), pressure 0..1, tilt in degrees, time in ms. */\nexport interface InkPoint {\n x: number;\n y: number;\n pressure: number;\n tiltX: number;\n tiltY: number;\n t: number;\n}\nexport type InkStroke = InkPoint[];\nexport type InkWeight = \"thin\" | \"medium\" | \"bold\";\n\n/** Nib diameter in pad units at pressure 0.5. */\nexport const INK_WEIGHTS: Record<InkWeight, number> = { thin: 2.2, medium: 3.4, bold: 5 };\n\n/**\n * Pressure for a mouse or finger, which report none. Constant, like a ballpoint: pressure simulated from speed makes\n * the line wobble as the hand speeds up and slows down, which no real pen does.\n */\nexport const STEADY_PRESSURE = 0.5;\n\n/**\n * A pen's raw pressure through a response curve, eased against the last sample. Pens report light writing as\n * 0.1–0.3, a hairline if used raw, so the curve lifts the low end; easing hides the digitiser's jitter.\n */\nexport function penPressure(raw: number, previous: number | null): number {\n const curved = 0.15 + 0.85 * clamp(raw, 0, 1) ** 0.65;\n return previous === null ? curved : previous + (curved - previous) * 0.5;\n}\n\n/** A sample from a pointer event. `scale` maps shown CSS pixels to the pad's coordinate space. */\nexport function inkPoint(\n event: PointerEvent,\n rect: DOMRect,\n previous: InkPoint | null,\n scale = { x: 1, y: 1 },\n): InkPoint {\n const x = (event.clientX - rect.left) * scale.x;\n const y = (event.clientY - rect.top) * scale.y;\n if (event.pointerType !== \"pen\")\n return { x, y, pressure: STEADY_PRESSURE, tiltX: 0, tiltY: 0, t: event.timeStamp };\n // A pen reports 0 as it lifts off: keep the last pressure, or each stroke would end in a blob or a dot.\n const pressure =\n event.pressure > 0\n ? penPressure(event.pressure, previous?.pressure ?? null)\n : (previous?.pressure ?? STEADY_PRESSURE);\n return { x, y, pressure, tiltX: event.tiltX || 0, tiltY: event.tiltY || 0, t: event.timeStamp };\n}\n\ntype Vec = [number, number];\nconst CAP_STEPS = 8;\n\n/** The filled outline of one stroke: a closed polygon in pad units. */\nexport function inkOutline(stroke: InkStroke, weight: InkWeight, scale = 1): Vec[] {\n if (stroke.length === 0) return [];\n const tilt = stroke.reduce((sum, p) => sum + Math.hypot(p.tiltX, p.tiltY), 0) / stroke.length;\n const size = INK_WEIGHTS[weight] * scale * (1 + 0.25 * Math.min(1, tilt / 60));\n // Light smoothing (1-2-1) takes the jitter out of the centre line without rounding off corners. The ends stay where\n // they were drawn, or every stroke would come up short.\n const pts = stroke.map((p, i) => {\n const r = (size / 2) * (0.4 + 1.2 * p.pressure);\n const a = stroke[i - 1];\n const b = stroke[i + 1];\n if (!a || !b) return { x: p.x, y: p.y, r };\n return { x: (a.x + 2 * p.x + b.x) / 4, y: (a.y + 2 * p.y + b.y) / 4, r };\n });\n const first = pts[0] as (typeof pts)[number];\n const arc = (cx: number, cy: number, r: number, from: number): Vec[] =>\n Array.from({ length: CAP_STEPS + 1 }, (_, k) => {\n const a = from - (Math.PI * k) / CAP_STEPS;\n return [cx + r * Math.cos(a), cy + r * Math.sin(a)];\n });\n if (pts.length === 1)\n return arc(first.x, first.y, first.r, 0).concat(arc(first.x, first.y, first.r, Math.PI));\n const left: Vec[] = [];\n const right: Vec[] = [];\n const angles: number[] = [];\n pts.forEach((p, i) => {\n const a = pts[Math.max(0, i - 1)] as typeof p;\n const b = pts[Math.min(pts.length - 1, i + 1)] as typeof p;\n const len = Math.hypot(b.x - a.x, b.y - a.y) || 1;\n // The normal to the direction of travel: the left side of the stroke.\n const nx = -(b.y - a.y) / len;\n const ny = (b.x - a.x) / len;\n left.push([p.x + nx * p.r, p.y + ny * p.r]);\n right.push([p.x - nx * p.r, p.y - ny * p.r]);\n angles.push(Math.atan2(ny, nx));\n });\n const last = pts[pts.length - 1] as typeof first;\n // Round caps: from the left side round the end to the right side, then back round the start.\n const endCap = arc(last.x, last.y, last.r, angles[angles.length - 1] as number);\n const startCap = arc(first.x, first.y, first.r, (angles[0] as number) + Math.PI);\n return [...left, ...endCap, ...right.reverse(), ...startCap];\n}\n\nconst f = (n: number) => Math.round(n * 100) / 100;\n\n/**\n * SVG path data for a closed outline: smooth quadratics through the midpoints, written as the equivalent cubics, so the\n * path uses only M, C and Z (what Path2D and PDF writers read alike).\n */\nexport function outlineToPath(outline: Vec[]): string {\n const n = outline.length;\n if (n < 2) return \"\";\n const mid = (a: Vec, b: Vec): Vec => [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];\n let current = mid(outline[n - 1] as Vec, outline[0] as Vec);\n let d = `M${f(current[0])} ${f(current[1])}`;\n for (let i = 0; i < n; i++) {\n const q = outline[i] as Vec;\n const end = mid(q, outline[(i + 1) % n] as Vec);\n const c1 = [current[0] + (2 / 3) * (q[0] - current[0]), current[1] + (2 / 3) * (q[1] - current[1])];\n const c2 = [end[0] + (2 / 3) * (q[0] - end[0]), end[1] + (2 / 3) * (q[1] - end[1])];\n d += `C${f(c1[0] as number)} ${f(c1[1] as number)} ${f(c2[0] as number)} ${f(c2[1] as number)} ${f(end[0])} ${f(end[1])}`;\n current = end;\n }\n return `${d}Z`;\n}\n\n/** Path data for one stroke. */\nexport const inkPath = (stroke: InkStroke, weight: InkWeight) => outlineToPath(inkOutline(stroke, weight));\n\n/** A standalone SVG of the strokes, for saving or placing in a PDF. `width` and `height` are the pad's space. */\nexport function inkToSvg(\n strokes: InkStroke[],\n options: { width: number; height: number; ink: string; weight: InkWeight },\n): string {\n const paths = strokes\n .map((s) => inkPath(s, options.weight))\n .filter(Boolean)\n .map((d) => `<path d=\"${d}\"/>`)\n .join(\"\");\n const fill = options.ink.replace(/[<>\"&]/g, \"\");\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${options.width} ${options.height}\" width=\"${options.width}\" height=\"${options.height}\"><g fill=\"${fill}\">${paths}</g></svg>`;\n}\n"],"mappings":";AAoBA,IAAaC,IAAyC;AAAA,EAAE,MAAM;AAAA,EAAK,QAAQ;AAAA,EAAK,MAAM;AAAE,GAM3EC,IAAkB;AAM/B,SAAgBC,EAAYC,GAAaC,GAAiC;AACxE,QAAMC,IAAS,OAAO,OAAON,EAAMI,GAAK,GAAG,CAAC,KAAK;AACjD,SAAOC,MAAa,OAAOC,IAASD,KAAYC,IAASD,KAAY;AACvE;AAGA,SAAgBE,EACdC,GACAC,GACAJ,GACAK,IAAQ;AAAA,EAAE,GAAG;AAAA,EAAG,GAAG;AAAE,GACX;AACV,QAAMC,KAAKH,EAAM,UAAUC,EAAK,QAAQC,EAAM,GACxCE,KAAKJ,EAAM,UAAUC,EAAK,OAAOC,EAAM;AAC7C,SAAIF,EAAM,gBAAgB,QACjB;AAAA,IAAE,GAAAG;AAAA,IAAG,GAAAC;AAAA,IAAG,UAAUV;AAAA,IAAiB,OAAO;AAAA,IAAG,OAAO;AAAA,IAAG,GAAGM,EAAM;AAAA,EAAU,IAM5E;AAAA,IAAE,GAAAG;AAAA,IAAG,GAAAC;AAAA,IAAG,UAHbJ,EAAM,WAAW,IACbL,EAAYK,EAAM,UAAUH,GAAU,YAAY,IAAI,IACrDA,GAAU,YAAA;AAAA,IACQ,OAAOG,EAAM,SAAS;AAAA,IAAG,OAAOA,EAAM,SA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R,QAAMC,IAAQF,EACX,IAAA,CAAKG,MAAML,EAAQK,GAAGF,EAAQ,MAAM,CAAC,EACrC,OAAO,OAAO,EACd,IAAA,CAAKR,MAAM,YAAYA,CAAA,KAAM,EAC7B,KAAK,EAAE,GACJW,IAAOH,EAAQ,IAAI,QAAQ,WAAW,EAAE;AAC9C,SAAO,wDAAwDA,EAAQ,KAAA,IAASA,EAAQ,MAAA,YAAkBA,EAAQ,KAAA,aAAkBA,EAAQ,MAAA,cAAoBG,CAAA,KAASF,CAAA;AAC3K"}
|
|
@@ -1,150 +1,147 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useControllableState as
|
|
3
|
-
import { isRtl as
|
|
4
|
-
import { clamp as
|
|
5
|
-
import { stepKey as
|
|
6
|
-
import { useDrag as
|
|
7
|
-
import { HiddenValue as
|
|
8
|
-
import { useCallback as
|
|
9
|
-
import { jsx as
|
|
10
|
-
var
|
|
2
|
+
import { useControllableState as ae } from "../../foundations/controllable.js";
|
|
3
|
+
import { isRtl as I } from "../../foundations/dir.js";
|
|
4
|
+
import { ariaNumber as R, clamp as N, plainNumber as F, snapToStep as se } from "../../foundations/math.js";
|
|
5
|
+
import { stepKey as le } from "../../foundations/keys.js";
|
|
6
|
+
import { useDrag as oe } from "../../foundations/drag.js";
|
|
7
|
+
import { HiddenValue as ce } from "../../foundations/HiddenValue/HiddenValue.js";
|
|
8
|
+
import { useCallback as ie, useId as ne, useRef as j } from "react";
|
|
9
|
+
import { jsx as i, jsxs as C } from "react/jsx-runtime";
|
|
10
|
+
var ue = {
|
|
11
11
|
minimum: "minimum",
|
|
12
12
|
maximum: "maximum",
|
|
13
|
-
thumb: (
|
|
14
|
-
value:
|
|
15
|
-
}
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
...
|
|
19
|
-
...
|
|
20
|
-
},
|
|
21
|
-
const r = s + Math.round((e - s) / d) * d;
|
|
22
|
-
return Number(Math.min(Math.max(r, s), c).toFixed(ie(d)));
|
|
23
|
-
}, [
|
|
13
|
+
thumb: (u) => `stop ${u + 1}`,
|
|
14
|
+
value: F
|
|
15
|
+
};
|
|
16
|
+
function ge({ label: u, labelHidden: v = !1, value: P, defaultValue: U, onChange: q, onCommit: G, min: s = 0, max: l = 100, step: y = 1, largeStep: J, orientation: $ = "horizontal", marks: O, trackContent: A, showValue: E = !1, name: Q, disabled: d = !1, size: V = "md", labels: W, className: K, style: X }) {
|
|
17
|
+
const _ = ne(), m = {
|
|
18
|
+
...ue,
|
|
19
|
+
...W
|
|
20
|
+
}, L = U ?? s, [w, Y, Z] = ae(P, L, q), c = Array.isArray(w), t = (c ? w : [w]).map((e) => N(e, s, l)), h = j(null), z = j([]), p = j(null), k = J ?? Math.max(y, (l - s) / 10), S = $ === "vertical", B = ie((e) => N(se(e, y, s), s, l), [
|
|
24
21
|
s,
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
l,
|
|
23
|
+
y
|
|
27
24
|
]), b = (e, r) => {
|
|
28
|
-
if (!
|
|
25
|
+
if (!c) return B(r);
|
|
29
26
|
const a = [...t];
|
|
30
|
-
return a[e] = B(
|
|
27
|
+
return a[e] = N(B(r), t[e - 1] ?? s, t[e + 1] ?? l), a;
|
|
31
28
|
}, g = (e, r) => {
|
|
32
|
-
(Array.isArray(e) ? e.every((a, o) => a === t[o]) : e === t[0]) ||
|
|
33
|
-
},
|
|
34
|
-
const r =
|
|
35
|
-
let o =
|
|
36
|
-
return a && (o = 1 - o), s +
|
|
29
|
+
(Array.isArray(e) ? e.every((a, o) => a === t[o]) : e === t[0]) || Y(e), r && G?.(e);
|
|
30
|
+
}, D = (e) => {
|
|
31
|
+
const r = h.current.getBoundingClientRect(), a = !S && I(h.current);
|
|
32
|
+
let o = S ? (r.bottom - e.y) / r.height : (e.x - r.left) / r.width;
|
|
33
|
+
return a && (o = 1 - o), s + N(o) * (l - s);
|
|
37
34
|
};
|
|
38
|
-
|
|
35
|
+
oe(h, {
|
|
39
36
|
touchAction: "css",
|
|
40
37
|
onStart: ({ point: e }) => {
|
|
41
|
-
if (
|
|
42
|
-
const r =
|
|
38
|
+
if (d) return !1;
|
|
39
|
+
const r = D(e), a = t.map((T) => Math.abs(T - r)), o = Math.min(...a), n = a.flatMap((T, te) => T === o ? [te] : []), M = r < t[n[0]] ? n[0] : n[n.length - 1];
|
|
43
40
|
p.current = {
|
|
44
|
-
index:
|
|
45
|
-
from:
|
|
46
|
-
},
|
|
41
|
+
index: M,
|
|
42
|
+
from: c ? [...t] : t[0]
|
|
43
|
+
}, z.current[M]?.focus({ preventScroll: !0 }), g(b(M, r), !1);
|
|
47
44
|
},
|
|
48
|
-
onMove: ({ point: e }) => g(b(p.current.index,
|
|
45
|
+
onMove: ({ point: e }) => g(b(p.current.index, D(e)), !1),
|
|
49
46
|
onEnd: ({ point: e }, r) => {
|
|
50
47
|
const a = p.current;
|
|
51
|
-
p.current = null, g(r ? a.from : b(a.index,
|
|
48
|
+
p.current = null, g(r ? a.from : b(a.index, D(e)), !0);
|
|
52
49
|
}
|
|
53
50
|
});
|
|
54
|
-
const
|
|
55
|
-
const a = t[e], o = !
|
|
51
|
+
const H = (e) => (r) => {
|
|
52
|
+
const a = t[e], o = !S && I(r.currentTarget), n = le(r, {
|
|
56
53
|
value: a,
|
|
57
54
|
min: s,
|
|
58
|
-
max:
|
|
59
|
-
step:
|
|
60
|
-
big:
|
|
55
|
+
max: l,
|
|
56
|
+
step: y,
|
|
57
|
+
big: k,
|
|
61
58
|
rtl: o
|
|
62
59
|
});
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
"--_from":
|
|
66
|
-
"--_to":
|
|
60
|
+
n !== void 0 && (r.preventDefault(), g(b(e, n), !0));
|
|
61
|
+
}, f = (e) => `${(e - s) / (l - s || 1) * 100}%`, x = c ? t.map(m.value).join(t.length === 2 ? " – " : ", ") : m.value(t[0]), ee = c ? {
|
|
62
|
+
"--_from": f(t[0]),
|
|
63
|
+
"--_to": f(t[t.length - 1])
|
|
67
64
|
} : {
|
|
68
65
|
"--_from": "0%",
|
|
69
|
-
"--_to":
|
|
70
|
-
},
|
|
71
|
-
return /* @__PURE__ */
|
|
72
|
-
className:
|
|
73
|
-
...
|
|
66
|
+
"--_to": f(t[0])
|
|
67
|
+
}, re = (e) => t.length === 2 ? e === 0 ? m.minimum : m.maximum : m.thumb(e, t.length);
|
|
68
|
+
return /* @__PURE__ */ C("div", {
|
|
69
|
+
className: K ? `cy-slider ${K}` : "cy-slider",
|
|
70
|
+
...c ? {
|
|
74
71
|
role: "group",
|
|
75
|
-
...v ? { "aria-label":
|
|
72
|
+
...v ? { "aria-label": u } : { "aria-labelledby": `${_}-label` }
|
|
76
73
|
} : {},
|
|
77
|
-
"data-orientation":
|
|
78
|
-
"data-range":
|
|
79
|
-
"data-size":
|
|
80
|
-
"data-disabled":
|
|
81
|
-
style:
|
|
74
|
+
"data-orientation": $,
|
|
75
|
+
"data-range": c || void 0,
|
|
76
|
+
"data-size": V,
|
|
77
|
+
"data-disabled": d || void 0,
|
|
78
|
+
style: X,
|
|
82
79
|
children: [
|
|
83
|
-
(!v ||
|
|
80
|
+
(!v || E) && /* @__PURE__ */ C("div", {
|
|
84
81
|
className: "cy-slider-head cy-reset",
|
|
85
|
-
children: [!v && /* @__PURE__ */
|
|
86
|
-
id: `${
|
|
82
|
+
children: [!v && /* @__PURE__ */ i("span", {
|
|
83
|
+
id: `${_}-label`,
|
|
87
84
|
className: "cy-slider-label cy-reset",
|
|
88
|
-
children:
|
|
89
|
-
}),
|
|
85
|
+
children: u
|
|
86
|
+
}), E && /* @__PURE__ */ i("span", {
|
|
90
87
|
className: "cy-slider-value cy-reset",
|
|
91
88
|
"aria-hidden": "true",
|
|
92
|
-
children:
|
|
89
|
+
children: x
|
|
93
90
|
})]
|
|
94
91
|
}),
|
|
95
|
-
/* @__PURE__ */
|
|
96
|
-
ref:
|
|
92
|
+
/* @__PURE__ */ C("div", {
|
|
93
|
+
ref: h,
|
|
97
94
|
className: "cy-slider-track cy-reset",
|
|
98
|
-
style:
|
|
99
|
-
"data-custom":
|
|
95
|
+
style: ee,
|
|
96
|
+
"data-custom": A !== void 0 ? "" : void 0,
|
|
100
97
|
children: [
|
|
101
|
-
|
|
98
|
+
A !== void 0 ? /* @__PURE__ */ i("div", {
|
|
102
99
|
className: "cy-slider-drawing cy-reset",
|
|
103
100
|
"aria-hidden": "true",
|
|
104
|
-
children:
|
|
105
|
-
}) : /* @__PURE__ */
|
|
106
|
-
|
|
101
|
+
children: A
|
|
102
|
+
}) : /* @__PURE__ */ i("div", { className: "cy-slider-fill cy-reset" }),
|
|
103
|
+
O?.map((e) => /* @__PURE__ */ i("span", {
|
|
107
104
|
className: "cy-slider-mark cy-reset",
|
|
108
105
|
"aria-hidden": "true",
|
|
109
|
-
style: { "--_pos":
|
|
106
|
+
style: { "--_pos": f(e.value) },
|
|
110
107
|
"data-label": e.label ? "" : void 0,
|
|
111
|
-
children: e.label && /* @__PURE__ */
|
|
108
|
+
children: e.label && /* @__PURE__ */ i("span", {
|
|
112
109
|
className: "cy-slider-mark-label cy-reset",
|
|
113
110
|
children: e.label
|
|
114
111
|
})
|
|
115
112
|
}, e.value)),
|
|
116
|
-
t.map((e, r) => /* @__PURE__ */
|
|
113
|
+
t.map((e, r) => /* @__PURE__ */ i("div", {
|
|
117
114
|
ref: (a) => {
|
|
118
|
-
|
|
115
|
+
z.current[r] = a;
|
|
119
116
|
},
|
|
120
117
|
role: "slider",
|
|
121
|
-
tabIndex:
|
|
118
|
+
tabIndex: d ? void 0 : 0,
|
|
122
119
|
className: "cy-slider-thumb cy-reset",
|
|
123
|
-
"aria-orientation":
|
|
124
|
-
"aria-valuemin": t[r - 1] ?? s,
|
|
125
|
-
"aria-valuemax": t[r + 1] ??
|
|
126
|
-
"aria-valuenow": e,
|
|
127
|
-
"aria-valuetext":
|
|
128
|
-
"aria-disabled":
|
|
129
|
-
...
|
|
130
|
-
style: { "--_pos":
|
|
131
|
-
onKeyDown:
|
|
120
|
+
"aria-orientation": $,
|
|
121
|
+
"aria-valuemin": R(t[r - 1] ?? s),
|
|
122
|
+
"aria-valuemax": R(t[r + 1] ?? l),
|
|
123
|
+
"aria-valuenow": R(e),
|
|
124
|
+
"aria-valuetext": m.value(e),
|
|
125
|
+
"aria-disabled": d || void 0,
|
|
126
|
+
...c ? { "aria-label": `${u}, ${re(r)}` } : v ? { "aria-label": u } : { "aria-labelledby": `${_}-label` },
|
|
127
|
+
style: { "--_pos": f(e) },
|
|
128
|
+
onKeyDown: d ? void 0 : H(r)
|
|
132
129
|
}, r))
|
|
133
130
|
]
|
|
134
131
|
}),
|
|
135
|
-
t.map((e, r) => /* @__PURE__ */
|
|
136
|
-
name:
|
|
137
|
-
value:
|
|
138
|
-
disabled:
|
|
132
|
+
t.map((e, r) => /* @__PURE__ */ i(ce, {
|
|
133
|
+
name: Q,
|
|
134
|
+
value: F(e),
|
|
135
|
+
disabled: d,
|
|
139
136
|
onReset: () => {
|
|
140
|
-
|
|
137
|
+
Z(L);
|
|
141
138
|
}
|
|
142
139
|
}, r))
|
|
143
140
|
]
|
|
144
141
|
});
|
|
145
142
|
}
|
|
146
143
|
export {
|
|
147
|
-
|
|
144
|
+
ge as Slider
|
|
148
145
|
};
|
|
149
146
|
|
|
150
147
|
//# sourceMappingURL=Slider.js.map
|