@kumix/ui 0.4.0 → 0.4.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.
- package/README.md +52 -45
- package/dist/{cascader-types-DVT-znZ-.d.ts → cascader-types-zhnUQ4sP.d.ts} +11 -3
- package/dist/cascader-types-zhnUQ4sP.d.ts.map +1 -0
- package/dist/components/agents/agent-code.js +1 -1
- package/dist/components/agents/approval-card/index.d.ts +2 -0
- package/dist/components/agents/approval-card/index.d.ts.map +1 -1
- package/dist/components/agents/approval-card/index.js +2 -0
- package/dist/components/agents/approval-card/index.js.map +1 -1
- package/dist/components/agents/citations.d.ts +14 -2
- package/dist/components/agents/citations.d.ts.map +1 -1
- package/dist/components/agents/citations.js +11 -7
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/loading-states/reasoning-text.d.ts.map +1 -1
- package/dist/components/agents/loading-states/reasoning-text.js +3 -0
- package/dist/components/agents/loading-states/reasoning-text.js.map +1 -1
- package/dist/components/charts/bump-chart/context.js +1 -2
- package/dist/components/charts/bump-chart/plot.js +1 -2
- package/dist/components/charts/bump-chart/point.js +1 -1
- package/dist/components/charts/bump-chart/series.d.ts +1 -0
- package/dist/components/charts/candlestick-chart/context.d.ts +79 -0
- package/dist/components/charts/candlestick-chart/context.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart/context.js +69 -0
- package/dist/components/charts/candlestick-chart/context.js.map +1 -0
- package/dist/components/charts/candlestick-chart/legend.d.ts +12 -0
- package/dist/components/charts/candlestick-chart/legend.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart/legend.js +56 -0
- package/dist/components/charts/candlestick-chart/legend.js.map +1 -0
- package/dist/components/charts/candlestick-chart/plot.d.ts +9 -0
- package/dist/components/charts/candlestick-chart/plot.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart/plot.js +218 -0
- package/dist/components/charts/candlestick-chart/plot.js.map +1 -0
- package/dist/components/charts/candlestick-chart.d.ts +18 -0
- package/dist/components/charts/candlestick-chart.d.ts.map +1 -0
- package/dist/components/charts/candlestick-chart.js +34 -0
- package/dist/components/charts/candlestick-chart.js.map +1 -0
- package/dist/components/charts/composition-chart/context.js +1 -2
- package/dist/components/charts/composition-chart/plot.js +1 -1
- package/dist/components/charts/donut-chart/center.d.ts +16 -0
- package/dist/components/charts/donut-chart/center.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/center.js +78 -0
- package/dist/components/charts/donut-chart/center.js.map +1 -0
- package/dist/components/charts/donut-chart/context.d.ts +68 -0
- package/dist/components/charts/donut-chart/context.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/context.js +2 -0
- package/dist/components/charts/donut-chart/legend.d.ts +17 -0
- package/dist/components/charts/donut-chart/legend.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/legend.js +85 -0
- package/dist/components/charts/donut-chart/legend.js.map +1 -0
- package/dist/components/charts/donut-chart/plot.d.ts +10 -0
- package/dist/components/charts/donut-chart/plot.d.ts.map +1 -0
- package/dist/components/charts/donut-chart/plot.js +108 -0
- package/dist/components/charts/donut-chart/plot.js.map +1 -0
- package/dist/components/charts/donut-chart.d.ts +22 -0
- package/dist/components/charts/donut-chart.d.ts.map +1 -0
- package/dist/components/charts/donut-chart.js +37 -0
- package/dist/components/charts/donut-chart.js.map +1 -0
- package/dist/components/charts/funnel-chart.d.ts.map +1 -1
- package/dist/components/charts/funnel-chart.js +1 -2
- package/dist/components/charts/funnel-chart.js.map +1 -1
- package/dist/components/charts/heat-calendar/tooltip.js +1 -1
- package/dist/components/charts/liquidity-heatmap.d.ts.map +1 -1
- package/dist/components/charts/liquidity-heatmap.js +1 -1
- package/dist/components/charts/order-book/depth-row.d.ts +8 -2
- package/dist/components/charts/order-book/depth-row.d.ts.map +1 -1
- package/dist/components/charts/order-book/depth-row.js +11 -3
- package/dist/components/charts/order-book/depth-row.js.map +1 -1
- package/dist/components/charts/order-book.d.ts +33 -1
- package/dist/components/charts/order-book.d.ts.map +1 -1
- package/dist/components/charts/order-book.js +92 -17
- package/dist/components/charts/order-book.js.map +1 -1
- package/dist/components/charts/price-target-fan/tooltip.js +1 -1
- package/dist/components/charts/returns-calendar/tooltip.js +1 -1
- package/dist/components/charts/status-bar/tooltip.js +1 -1
- package/dist/components/charts/treemap/tooltip.js +1 -1
- package/dist/components/charts/treemap.d.ts.map +1 -1
- package/dist/components/charts/volume-profile/tooltip.js +1 -1
- package/dist/components/charts/volume-profile.d.ts.map +1 -1
- package/dist/components/custom/confirm-dialog.d.ts +1 -0
- package/dist/components/custom/toast.d.ts +1 -0
- package/dist/components/motion/action-swap.d.ts +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +46 -20
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-badge.d.ts +1 -1
- package/dist/components/motion/animated-badge.d.ts.map +1 -1
- package/dist/components/motion/animated-badge.js +60 -101
- package/dist/components/motion/animated-badge.js.map +1 -1
- package/dist/components/motion/animated-sidebar.d.ts +1 -0
- package/dist/components/motion/animated-sidebar.js +1 -1
- package/dist/components/motion/animated-toast-stack.js +1 -1
- package/dist/components/motion/attachment-upload.d.ts.map +1 -1
- package/dist/components/motion/attachment-upload.js +2 -3
- package/dist/components/motion/attachment-upload.js.map +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -2
- package/dist/components/motion/availability-scheduler/day-row.js +2 -2
- package/dist/components/motion/availability-scheduler/index.js +1 -1
- package/dist/components/motion/bloom-menu.d.ts +1 -0
- package/dist/components/motion/bloom-menu.d.ts.map +1 -1
- package/dist/components/motion/bloom-menu.js +73 -8
- package/dist/components/motion/bloom-menu.js.map +1 -1
- package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
- package/dist/components/motion/bottom-sheet.js +6 -10
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/bounce-sidebar.d.ts.map +1 -1
- package/dist/components/motion/bounce-sidebar.js +34 -42
- package/dist/components/motion/bounce-sidebar.js.map +1 -1
- package/dist/components/motion/bouncy-accordion.d.ts.map +1 -1
- package/dist/components/motion/bouncy-accordion.js +35 -22
- package/dist/components/motion/bouncy-accordion.js.map +1 -1
- package/dist/components/motion/button/stateful.d.ts.map +1 -1
- package/dist/components/motion/button/stateful.js +3 -0
- package/dist/components/motion/button/stateful.js.map +1 -1
- package/dist/components/motion/card.d.ts +44 -0
- package/dist/components/motion/card.d.ts.map +1 -0
- package/dist/components/motion/card.js +122 -0
- package/dist/components/motion/card.js.map +1 -0
- package/dist/components/motion/center-morph-modal.js +1 -1
- package/dist/components/motion/checkbox.d.ts +3 -1
- package/dist/components/motion/checkbox.d.ts.map +1 -1
- package/dist/components/motion/checkbox.js +18 -6
- package/dist/components/motion/checkbox.js.map +1 -1
- package/dist/components/motion/color-picker.d.ts +110 -0
- package/dist/components/motion/color-picker.d.ts.map +1 -0
- package/dist/components/motion/color-picker.js +1053 -0
- package/dist/components/motion/color-picker.js.map +1 -0
- package/dist/components/motion/color-selector.d.ts.map +1 -1
- package/dist/components/motion/color-selector.js +9 -2
- package/dist/components/motion/color-selector.js.map +1 -1
- package/dist/components/motion/combobox/content.d.ts +1 -0
- package/dist/components/motion/command-palette.js +3 -3
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.d.ts +1 -0
- package/dist/components/motion/context-menu.js +1 -1
- package/dist/components/motion/date-range-picker.d.ts.map +1 -1
- package/dist/components/motion/digit-swap.d.ts +9 -1
- package/dist/components/motion/digit-swap.d.ts.map +1 -1
- package/dist/components/motion/digit-swap.js +18 -7
- package/dist/components/motion/digit-swap.js.map +1 -1
- package/dist/components/motion/drawer.d.ts +1 -1
- package/dist/components/motion/drawer.d.ts.map +1 -1
- package/dist/components/motion/drawer.js +10 -10
- package/dist/components/motion/drawer.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
- package/dist/components/motion/expandable-control.d.ts +1 -0
- package/dist/components/motion/feedback-widget.js +4 -1
- package/dist/components/motion/feedback-widget.js.map +1 -1
- package/dist/components/motion/knockout-wheel.d.ts.map +1 -1
- package/dist/components/motion/knockout-wheel.js +1 -2
- package/dist/components/motion/knockout-wheel.js.map +1 -1
- package/dist/components/motion/morphing-lightbox.d.ts.map +1 -1
- package/dist/components/motion/morphing-lightbox.js +1 -1
- package/dist/components/motion/morphing-modal.d.ts +6 -1
- package/dist/components/motion/morphing-modal.d.ts.map +1 -1
- package/dist/components/motion/morphing-modal.js +37 -5
- package/dist/components/motion/morphing-modal.js.map +1 -1
- package/dist/components/motion/morphing-search-chips.d.ts +54 -0
- package/dist/components/motion/morphing-search-chips.d.ts.map +1 -0
- package/dist/components/motion/morphing-search-chips.js +599 -0
- package/dist/components/motion/morphing-search-chips.js.map +1 -0
- package/dist/components/motion/morphing-search.js +1 -1
- package/dist/components/motion/morphing-tabs.js +1 -1
- package/dist/components/motion/multi-select/content.d.ts +1 -0
- package/dist/components/motion/not-found/shared.d.ts +1 -0
- package/dist/components/motion/number-ticker.d.ts +6 -1
- package/dist/components/motion/number-ticker.d.ts.map +1 -1
- package/dist/components/motion/number-ticker.js +19 -9
- package/dist/components/motion/number-ticker.js.map +1 -1
- package/dist/components/motion/otp-input.js +19 -11
- package/dist/components/motion/otp-input.js.map +1 -1
- package/dist/components/motion/parallax.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts +5 -3
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +47 -52
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts +1 -0
- package/dist/components/motion/popover.js +7 -1
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/prediction-market-card.js +2 -3
- package/dist/components/motion/prediction-market-card.js.map +1 -1
- package/dist/components/motion/prediction-market.js +1 -1
- package/dist/components/motion/project-folder.js +1 -1
- package/dist/components/motion/radio.d.ts +8 -2
- package/dist/components/motion/radio.d.ts.map +1 -1
- package/dist/components/motion/radio.js +70 -10
- package/dist/components/motion/radio.js.map +1 -1
- package/dist/components/motion/scroll-progress.d.ts +1 -0
- package/dist/components/motion/select-morph.d.ts +1 -1
- package/dist/components/motion/select-morph.d.ts.map +1 -1
- package/dist/components/motion/select-morph.js +89 -21
- package/dist/components/motion/select-morph.js.map +1 -1
- package/dist/components/motion/select.d.ts.map +1 -1
- package/dist/components/motion/select.js +153 -135
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/shader-background.d.ts +4 -2
- package/dist/components/motion/shader-background.d.ts.map +1 -1
- package/dist/components/motion/shader-background.js +9 -3
- package/dist/components/motion/shader-background.js.map +1 -1
- package/dist/components/motion/shared-layout-bg.d.ts.map +1 -1
- package/dist/components/motion/shared-layout-bg.js +17 -3
- package/dist/components/motion/shared-layout-bg.js.map +1 -1
- package/dist/components/motion/sortable-list.d.ts +1 -0
- package/dist/components/motion/sortable-stack.js +1 -2
- package/dist/components/motion/swipeable-list.d.ts.map +1 -1
- package/dist/components/motion/swipeable-list.js +61 -4
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/table/row-handle.js +1 -1
- package/dist/components/motion/table/table-header.js +1 -1
- package/dist/components/motion/tabs.d.ts +13 -3
- package/dist/components/motion/tabs.d.ts.map +1 -1
- package/dist/components/motion/tabs.js +248 -26
- package/dist/components/motion/tabs.js.map +1 -1
- package/dist/components/motion/text-reveal.d.ts +1 -0
- package/dist/components/motion/theme-toggle.js +1 -1
- package/dist/components/motion/tooltip/positioner.d.ts +8 -26
- package/dist/components/motion/tooltip/positioner.d.ts.map +1 -1
- package/dist/components/motion/tooltip/positioner.js +1 -2
- package/dist/components/motion/tooltip.d.ts +62 -20
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +1 -135
- package/dist/components/motion/wallet-card/account-avatar.js +1 -2
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/autocomplete.d.ts.map +1 -1
- package/dist/components/reui/autocomplete.js +1 -1
- package/dist/components/reui/autocomplete.js.map +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-async.d.ts +21 -5
- package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-async.js +61 -34
- package/dist/components/reui/cascader/cascader-async.js.map +1 -1
- package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-columns.js +5 -2
- package/dist/components/reui/cascader/cascader-columns.js.map +1 -1
- package/dist/components/reui/cascader/cascader-context.d.ts +3 -1
- package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-context.js.map +1 -1
- package/dist/components/reui/cascader/cascader-i18n.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-item.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-lib.d.ts +34 -8
- package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-lib.js +145 -29
- package/dist/components/reui/cascader/cascader-lib.js.map +1 -1
- package/dist/components/reui/cascader/cascader-nav.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-types.d.ts +1 -1
- package/dist/components/reui/cascader/cascader.d.ts +13 -8
- package/dist/components/reui/cascader/cascader.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader.js +31 -16
- package/dist/components/reui/cascader/cascader.js.map +1 -1
- package/dist/components/reui/code-block/code-block.d.ts.map +1 -1
- package/dist/components/reui/color-picker.d.ts +280 -0
- package/dist/components/reui/color-picker.d.ts.map +1 -0
- package/dist/components/reui/color-picker.js +2013 -0
- package/dist/components/reui/color-picker.js.map +1 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-cell-selection.js +1 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js +1 -0
- package/dist/components/reui/data-grid/data-grid-column-filter.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts +6 -8
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js +50 -29
- package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.js +1 -0
- package/dist/components/reui/data-grid/data-grid-column-visibility.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js +2 -1
- package/dist/components/reui/data-grid/data-grid-pagination.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js +10 -3
- package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +15 -10
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.d.ts +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.js +54 -14
- package/dist/components/reui/data-grid/data-grid-table-dnd.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js +37 -42
- package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +174 -16
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +223 -89
- package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid.d.ts +55 -1
- package/dist/components/reui/data-grid/data-grid.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid.js +112 -22
- package/dist/components/reui/data-grid/data-grid.js.map +1 -1
- package/dist/components/reui/date-selector.d.ts +1 -0
- package/dist/components/reui/date-selector.d.ts.map +1 -1
- package/dist/components/reui/date-selector.js +22 -16
- package/dist/components/reui/date-selector.js.map +1 -1
- package/dist/components/reui/emoji-picker.d.ts +367 -0
- package/dist/components/reui/emoji-picker.d.ts.map +1 -0
- package/dist/components/reui/emoji-picker.js +1768 -0
- package/dist/components/reui/emoji-picker.js.map +1 -0
- package/dist/components/reui/event-calendar/event-calendar-agenda-view.js +3 -5
- package/dist/components/reui/event-calendar/event-calendar-agenda-view.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-i18n.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar-nav.js +4 -4
- package/dist/components/reui/event-calendar/event-calendar-nav.js.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar.d.ts.map +1 -1
- package/dist/components/reui/event-calendar/event-calendar.js +34 -31
- package/dist/components/reui/event-calendar/event-calendar.js.map +1 -1
- package/dist/components/reui/file-type.d.ts +792 -0
- package/dist/components/reui/file-type.d.ts.map +1 -0
- package/dist/components/reui/file-type.js +1367 -0
- package/dist/components/reui/file-type.js.map +1 -0
- package/dist/components/reui/filters/filters-advanced.d.ts +1 -0
- package/dist/components/reui/filters/filters-advanced.js +1 -1
- package/dist/components/reui/filters/filters-advanced.js.map +1 -1
- package/dist/components/reui/filters/filters-builder.d.ts +1 -1
- package/dist/components/reui/filters/filters-chip.d.ts +5 -1
- package/dist/components/reui/filters/filters-chip.d.ts.map +1 -1
- package/dist/components/reui/filters/filters-chip.js +1 -1
- package/dist/components/reui/filters/filters-lib.d.ts +1 -1
- package/dist/components/reui/filters/filters-lib.d.ts.map +1 -1
- package/dist/components/reui/frame.d.ts.map +1 -1
- package/dist/components/reui/frame.js.map +1 -1
- package/dist/components/reui/gantt/gantt-nav.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-nav.js +4 -4
- package/dist/components/reui/gantt/gantt-nav.js.map +1 -1
- package/dist/components/reui/gantt/gantt.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt.js +5 -2
- package/dist/components/reui/gantt/gantt.js.map +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/reui/icon-tile.js +8 -7
- package/dist/components/reui/icon-tile.js.map +1 -1
- package/dist/components/reui/kanban.d.ts.map +1 -1
- package/dist/components/reui/kanban.js +1 -1
- package/dist/components/reui/kanban.js.map +1 -1
- package/dist/components/reui/number-field.d.ts.map +1 -1
- package/dist/components/reui/number-field.js.map +1 -1
- package/dist/components/reui/phone-input.js +30 -27
- package/dist/components/reui/phone-input.js.map +1 -1
- package/dist/components/reui/scrollspy.d.ts +1 -0
- package/dist/components/reui/time-picker.js +1 -1
- package/dist/components/reui/time-picker.js.map +1 -1
- package/dist/components/ui/attachment.d.ts +1 -1
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/code-block.d.ts +29 -0
- package/dist/components/ui/code-block.d.ts.map +1 -0
- package/dist/components/ui/code-block.js +124 -0
- package/dist/components/ui/code-block.js.map +1 -0
- package/dist/components/ui/command.d.ts.map +1 -1
- package/dist/components/ui/direction.js +1 -2
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/field.js +1 -1
- package/dist/components/ui/input-group.d.ts +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/message-scroller.d.ts.map +1 -1
- package/dist/components/ui/questionnaire.d.ts.map +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/trace.d.ts +21 -0
- package/dist/components/ui/trace.d.ts.map +1 -0
- package/dist/components/ui/trace.js +77 -0
- package/dist/components/ui/trace.js.map +1 -0
- package/dist/context-BYXeJQnz.d.ts.map +1 -1
- package/dist/context-tTdLKYNf.js +99 -0
- package/dist/context-tTdLKYNf.js.map +1 -0
- package/dist/{copy-menu-C5GaT4Z-.js → copy-menu-DOg9Jh-U.js} +2 -2
- package/dist/{copy-menu-C5GaT4Z-.js.map → copy-menu-DOg9Jh-U.js.map} +1 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +1 -0
- package/dist/hooks/use-focus-trap.d.ts +22 -0
- package/dist/hooks/use-focus-trap.d.ts.map +1 -0
- package/dist/hooks/use-focus-trap.js +80 -0
- package/dist/hooks/use-focus-trap.js.map +1 -0
- package/dist/hooks/use-highlighted-code.d.ts +5 -0
- package/dist/hooks/use-highlighted-code.d.ts.map +1 -0
- package/dist/hooks/use-highlighted-code.js +128 -0
- package/dist/hooks/use-highlighted-code.js.map +1 -0
- package/dist/hooks/use-hover-gesture.d.ts +1 -0
- package/dist/hooks/use-intersection-observer.d.ts +1 -0
- package/dist/hooks/use-listbox.d.ts +29 -0
- package/dist/hooks/use-listbox.d.ts.map +1 -0
- package/dist/hooks/use-listbox.js +75 -0
- package/dist/hooks/use-listbox.js.map +1 -0
- package/dist/hooks/use-scroll-position.d.ts +1 -0
- package/dist/hooks/use-slider-input.d.ts +1 -0
- package/dist/hooks/use-viewport.d.ts +1 -0
- package/dist/lib/tick-sound.d.ts +1 -0
- package/dist/model-NSIg2p7a.d.ts +20 -0
- package/dist/model-NSIg2p7a.d.ts.map +1 -0
- package/dist/model-_mRyI6V9.d.ts +18 -0
- package/dist/model-_mRyI6V9.d.ts.map +1 -0
- package/dist/{positioner-3mCqiebN.js → positioner-3r3cfkqT.js} +97 -33
- package/dist/positioner-3r3cfkqT.js.map +1 -0
- package/dist/tooltip-Bam5KeYe.js +535 -0
- package/dist/tooltip-Bam5KeYe.js.map +1 -0
- package/dist/tooltip-C01qUgsW.d.ts.map +1 -1
- package/dist/use-position-DOi1gVL0.d.ts +32 -0
- package/dist/use-position-DOi1gVL0.d.ts.map +1 -0
- package/package.json +11 -11
- package/dist/cascader-types-DVT-znZ-.d.ts.map +0 -1
- package/dist/components/motion/tooltip.js.map +0 -1
- package/dist/model-DfeFradZ.d.ts +0 -9
- package/dist/model-DfeFradZ.d.ts.map +0 -1
- package/dist/positioner-3mCqiebN.js.map +0 -1
|
@@ -0,0 +1,2013 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "../ui/button.js";
|
|
3
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger } from "../ui/dropdown-menu.js";
|
|
4
|
+
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "../ui/input-group.js";
|
|
5
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
|
|
6
|
+
import { Separator } from "../ui/separator.js";
|
|
7
|
+
import { Fragment, createContext, useContext, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
8
|
+
import { cn } from "@kumix/utils";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { flushSync } from "react-dom";
|
|
11
|
+
import { CheckIcon, ChevronDownIcon, CopyIcon, PipetteIcon } from "lucide-react";
|
|
12
|
+
//#region src/components/reui/color-picker.tsx
|
|
13
|
+
const SPACE_CHANNELS = {
|
|
14
|
+
rgb: [
|
|
15
|
+
"red",
|
|
16
|
+
"green",
|
|
17
|
+
"blue"
|
|
18
|
+
],
|
|
19
|
+
hsl: [
|
|
20
|
+
"hue",
|
|
21
|
+
"saturation",
|
|
22
|
+
"lightness"
|
|
23
|
+
],
|
|
24
|
+
hsv: [
|
|
25
|
+
"hue",
|
|
26
|
+
"saturation",
|
|
27
|
+
"brightness"
|
|
28
|
+
],
|
|
29
|
+
oklch: [
|
|
30
|
+
"lightness",
|
|
31
|
+
"chroma",
|
|
32
|
+
"hue"
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
const COLOR_PICKER_FORMATS = [
|
|
36
|
+
"hex",
|
|
37
|
+
"rgb",
|
|
38
|
+
"hsl",
|
|
39
|
+
"hsb",
|
|
40
|
+
"oklch"
|
|
41
|
+
];
|
|
42
|
+
const FORMAT_LABELS = {
|
|
43
|
+
hex: "HEX",
|
|
44
|
+
rgb: "RGB",
|
|
45
|
+
hsl: "HSL",
|
|
46
|
+
hsb: "HSB",
|
|
47
|
+
oklch: "OKLCH"
|
|
48
|
+
};
|
|
49
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
50
|
+
const wrapHue = (hue) => (hue % 360 + 360) % 360;
|
|
51
|
+
const fixed = (value, digits) => String(Number(value.toFixed(digits)) + 0);
|
|
52
|
+
function rgbToHsv([red, green, blue], fallbackHue = 0) {
|
|
53
|
+
const r = red / 255;
|
|
54
|
+
const g = green / 255;
|
|
55
|
+
const b = blue / 255;
|
|
56
|
+
const max = Math.max(r, g, b);
|
|
57
|
+
const delta = max - Math.min(r, g, b);
|
|
58
|
+
let hue = fallbackHue;
|
|
59
|
+
if (delta > 1e-9) {
|
|
60
|
+
hue = max === r ? (g - b) / delta % 6 : max === g ? (b - r) / delta + 2 : (r - g) / delta + 4;
|
|
61
|
+
hue = wrapHue(hue * 60);
|
|
62
|
+
}
|
|
63
|
+
return [
|
|
64
|
+
hue,
|
|
65
|
+
max === 0 ? 0 : delta / max * 100,
|
|
66
|
+
max * 100
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
function hsvToRgb([hue, saturation, brightness]) {
|
|
70
|
+
const s = saturation / 100;
|
|
71
|
+
const v = brightness / 100;
|
|
72
|
+
const channel = (n) => {
|
|
73
|
+
const k = (n + hue / 60) % 6;
|
|
74
|
+
return (v - v * s * Math.max(0, Math.min(k, 4 - k, 1))) * 255;
|
|
75
|
+
};
|
|
76
|
+
return [
|
|
77
|
+
channel(5),
|
|
78
|
+
channel(3),
|
|
79
|
+
channel(1)
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
function hsvToHsl([hue, saturation, brightness]) {
|
|
83
|
+
const s = saturation / 100;
|
|
84
|
+
const v = brightness / 100;
|
|
85
|
+
const l = v * (1 - s / 2);
|
|
86
|
+
return [
|
|
87
|
+
hue,
|
|
88
|
+
(l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l)) * 100,
|
|
89
|
+
l * 100
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
function hslToHsv([hue, saturation, lightness]) {
|
|
93
|
+
const s = saturation / 100;
|
|
94
|
+
const l = lightness / 100;
|
|
95
|
+
const v = l + s * Math.min(l, 1 - l);
|
|
96
|
+
return [
|
|
97
|
+
hue,
|
|
98
|
+
v === 0 ? 0 : 2 * (1 - l / v) * 100,
|
|
99
|
+
v * 100
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
const toLinear = (channel) => {
|
|
103
|
+
const c = channel / 255;
|
|
104
|
+
return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
|
|
105
|
+
};
|
|
106
|
+
const fromLinear = (channel) => 255 * (channel <= .0031308 ? 12.92 * channel : 1.055 * channel ** (1 / 2.4) - .055);
|
|
107
|
+
function linearToOklab([r, g, b]) {
|
|
108
|
+
const l = Math.cbrt(.4122214708 * r + .5363325363 * g + .0514459929 * b);
|
|
109
|
+
const m = Math.cbrt(.2119034982 * r + .6806995451 * g + .1073969566 * b);
|
|
110
|
+
const s = Math.cbrt(.0883024619 * r + .2817188376 * g + .6299787005 * b);
|
|
111
|
+
return [
|
|
112
|
+
.2104542553 * l + .793617785 * m - .0040720468 * s,
|
|
113
|
+
1.9779984951 * l - 2.428592205 * m + .4505937099 * s,
|
|
114
|
+
.0259040371 * l + .7827717662 * m - .808675766 * s
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
function oklabToOklch([lightness, a, b], fallbackHue = 0) {
|
|
118
|
+
const chroma = Math.sqrt(a * a + b * b);
|
|
119
|
+
const hue = chroma < 1e-4 ? fallbackHue : wrapHue(Math.atan2(b, a) * 180 / Math.PI);
|
|
120
|
+
return [
|
|
121
|
+
lightness * 100,
|
|
122
|
+
chroma,
|
|
123
|
+
hue
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
function rgbToOklch(rgb, fallbackHue = 0) {
|
|
127
|
+
return oklabToOklch(linearToOklab(rgb.map(toLinear)), fallbackHue);
|
|
128
|
+
}
|
|
129
|
+
function oklchToLinear([lightness, chroma, hue]) {
|
|
130
|
+
const angle = hue * Math.PI / 180;
|
|
131
|
+
const L = lightness / 100;
|
|
132
|
+
const a = chroma * Math.cos(angle);
|
|
133
|
+
const b = chroma * Math.sin(angle);
|
|
134
|
+
const l = (L + .3963377774 * a + .2158037573 * b) ** 3;
|
|
135
|
+
const m = (L - .1055613458 * a - .0638541728 * b) ** 3;
|
|
136
|
+
const s = (L - .0894841775 * a - 1.291485548 * b) ** 3;
|
|
137
|
+
return [
|
|
138
|
+
4.0767416621 * l - 3.3077115913 * m + .2309699292 * s,
|
|
139
|
+
-1.2684380046 * l + 2.6097574011 * m - .3413193965 * s,
|
|
140
|
+
-.0041960863 * l - .7034186147 * m + 1.707614701 * s
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
const inSrgb = (linear) => linear.every((channel) => channel >= -1e-4 && channel <= 1.0001);
|
|
144
|
+
const clipLinear = (linear) => linear.map((channel) => clamp(channel, 0, 1));
|
|
145
|
+
function clipError(clipped, [lightness, chroma, hue]) {
|
|
146
|
+
const [l, a, b] = linearToOklab(clipped);
|
|
147
|
+
const angle = hue * Math.PI / 180;
|
|
148
|
+
return Math.hypot(l - lightness / 100, a - chroma * Math.cos(angle), b - chroma * Math.sin(angle));
|
|
149
|
+
}
|
|
150
|
+
function oklchToRgb([lightness, chroma, hue]) {
|
|
151
|
+
const encode = (linear) => linear.map((channel) => fromLinear(channel));
|
|
152
|
+
if (lightness >= 100) return [
|
|
153
|
+
255,
|
|
154
|
+
255,
|
|
155
|
+
255
|
|
156
|
+
];
|
|
157
|
+
if (lightness <= 0) return [
|
|
158
|
+
0,
|
|
159
|
+
0,
|
|
160
|
+
0
|
|
161
|
+
];
|
|
162
|
+
const target = [
|
|
163
|
+
lightness,
|
|
164
|
+
Math.max(0, chroma),
|
|
165
|
+
hue
|
|
166
|
+
];
|
|
167
|
+
const origin = oklchToLinear(target);
|
|
168
|
+
if (inSrgb(origin)) return encode(clipLinear(origin));
|
|
169
|
+
let clipped = clipLinear(origin);
|
|
170
|
+
if (clipError(clipped, target) < .02) return encode(clipped);
|
|
171
|
+
let low = 0;
|
|
172
|
+
let high = target[1];
|
|
173
|
+
let lowInGamut = true;
|
|
174
|
+
while (high - low > 1e-4) {
|
|
175
|
+
const mid = (low + high) / 2;
|
|
176
|
+
const current = [
|
|
177
|
+
lightness,
|
|
178
|
+
mid,
|
|
179
|
+
hue
|
|
180
|
+
];
|
|
181
|
+
const linear = oklchToLinear(current);
|
|
182
|
+
if (lowInGamut && inSrgb(linear)) {
|
|
183
|
+
low = mid;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
clipped = clipLinear(linear);
|
|
187
|
+
const error = clipError(clipped, current);
|
|
188
|
+
if (error < .02) {
|
|
189
|
+
if (.02 - error < 1e-4) break;
|
|
190
|
+
lowInGamut = false;
|
|
191
|
+
low = mid;
|
|
192
|
+
} else high = mid;
|
|
193
|
+
}
|
|
194
|
+
return encode(clipped);
|
|
195
|
+
}
|
|
196
|
+
function toRgb(color) {
|
|
197
|
+
const { space, channels } = color;
|
|
198
|
+
if (space === "rgb") return channels;
|
|
199
|
+
if (space === "hsv") return hsvToRgb(channels);
|
|
200
|
+
if (space === "hsl") return hsvToRgb(hslToHsv(channels));
|
|
201
|
+
return oklchToRgb(channels);
|
|
202
|
+
}
|
|
203
|
+
/** A color's channels in another space. */
|
|
204
|
+
function toSpace(color, space) {
|
|
205
|
+
const { space: from, channels } = color;
|
|
206
|
+
if (from === space) return channels;
|
|
207
|
+
if (from === "hsv" && space === "hsl") return hsvToHsl(channels);
|
|
208
|
+
if (from === "hsl" && space === "hsv") return hslToHsv(channels);
|
|
209
|
+
const rgb = toRgb(color);
|
|
210
|
+
const hue = from === "rgb" ? 0 : channels[from === "oklch" ? 2 : 0];
|
|
211
|
+
if (space === "rgb") return rgb;
|
|
212
|
+
if (space === "hsv") return rgbToHsv(rgb, hue);
|
|
213
|
+
if (space === "hsl") return hsvToHsl(rgbToHsv(rgb, hue));
|
|
214
|
+
return rgbToOklch(rgb, hue);
|
|
215
|
+
}
|
|
216
|
+
/** Whether a color fits sRGB. OKLCH can reach past it; the picker then maps it into sRGB the way CSS does. */
|
|
217
|
+
function isColorInSrgb(color) {
|
|
218
|
+
return color.space !== "oklch" || inSrgb(oklchToLinear(color.channels));
|
|
219
|
+
}
|
|
220
|
+
const HEX_PATTERN = /^#?([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/;
|
|
221
|
+
const FUNCTION_PATTERN = /^([a-z][a-z\d-]*)\(([\s\S]*)\)$/;
|
|
222
|
+
const NUMBER_PATTERN = /^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%|deg|rad|grad|turn)?$/;
|
|
223
|
+
const NAMED_COLORS = "alicebluef0f8ff antiquewhitefaebd7 aqua00ffff aquamarine7fffd4 azuref0ffff beigef5f5dc bisqueffe4c4 black000000 blanchedalmondffebcd blue0000ff blueviolet8a2be2 browna52a2a burlywooddeb887 cadetblue5f9ea0 chartreuse7fff00 chocolated2691e coralff7f50 cornflowerblue6495ed cornsilkfff8dc crimsondc143c cyan00ffff darkblue00008b darkcyan008b8b darkgoldenrodb8860b darkgraya9a9a9 darkgreen006400 darkgreya9a9a9 darkkhakibdb76b darkmagenta8b008b darkolivegreen556b2f darkorangeff8c00 darkorchid9932cc darkred8b0000 darksalmone9967a darkseagreen8fbc8f darkslateblue483d8b darkslategray2f4f4f darkslategrey2f4f4f darkturquoise00ced1 darkviolet9400d3 deeppinkff1493 deepskyblue00bfff dimgray696969 dimgrey696969 dodgerblue1e90ff firebrickb22222 floralwhitefffaf0 forestgreen228b22 fuchsiaff00ff gainsborodcdcdc ghostwhitef8f8ff goldffd700 goldenroddaa520 gray808080 green008000 greenyellowadff2f grey808080 honeydewf0fff0 hotpinkff69b4 indianredcd5c5c indigo4b0082 ivoryfffff0 khakif0e68c lavendere6e6fa lavenderblushfff0f5 lawngreen7cfc00 lemonchiffonfffacd lightblueadd8e6 lightcoralf08080 lightcyane0ffff lightgoldenrodyellowfafad2 lightgrayd3d3d3 lightgreen90ee90 lightgreyd3d3d3 lightpinkffb6c1 lightsalmonffa07a lightseagreen20b2aa lightskyblue87cefa lightslategray778899 lightslategrey778899 lightsteelblueb0c4de lightyellowffffe0 lime00ff00 limegreen32cd32 linenfaf0e6 magentaff00ff maroon800000 mediumaquamarine66cdaa mediumblue0000cd mediumorchidba55d3 mediumpurple9370db mediumseagreen3cb371 mediumslateblue7b68ee mediumspringgreen00fa9a mediumturquoise48d1cc mediumvioletredc71585 midnightblue191970 mintcreamf5fffa mistyroseffe4e1 moccasinffe4b5 navajowhiteffdead navy000080 oldlacefdf5e6 olive808000 olivedrab6b8e23 orangeffa500 orangeredff4500 orchidda70d6 palegoldenrodeee8aa palegreen98fb98 paleturquoiseafeeee palevioletreddb7093 papayawhipffefd5 peachpuffffdab9 perucd853f pinkffc0cb plumdda0dd powderblueb0e0e6 purple800080 rebeccapurple663399 redff0000 rosybrownbc8f8f royalblue4169e1 saddlebrown8b4513 salmonfa8072 sandybrownf4a460 seagreen2e8b57 seashellfff5ee siennaa0522d silverc0c0c0 skyblue87ceeb slateblue6a5acd slategray708090 slategrey708090 snowfffafa springgreen00ff7f steelblue4682b4 tand2b48c teal008080 thistled8bfd8 tomatoff6347 turquoise40e0d0 violetee82ee wheatf5deb3 whiteffffff whitesmokef5f5f5 yellowffff00 yellowgreen9acd32";
|
|
224
|
+
let namedColors = null;
|
|
225
|
+
function namedColor(name) {
|
|
226
|
+
namedColors ??= new Map(NAMED_COLORS.split(" ").map((entry) => [entry.slice(0, -6), entry.slice(-6)]));
|
|
227
|
+
return namedColors.get(name);
|
|
228
|
+
}
|
|
229
|
+
function readNumber(token, percentOf, angle = false) {
|
|
230
|
+
if (token === "none") return 0;
|
|
231
|
+
const match = NUMBER_PATTERN.exec(token);
|
|
232
|
+
if (!match) return null;
|
|
233
|
+
const value = Number(match[1]);
|
|
234
|
+
if (!Number.isFinite(value)) return null;
|
|
235
|
+
const unit = match[2];
|
|
236
|
+
if (!unit) return value;
|
|
237
|
+
if (unit === "%") return angle ? null : value * percentOf / 100;
|
|
238
|
+
if (!angle) return null;
|
|
239
|
+
if (unit === "rad") return value * 180 / Math.PI;
|
|
240
|
+
if (unit === "grad") return value * .9;
|
|
241
|
+
if (unit === "turn") return value * 360;
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
244
|
+
const multiply = (matrix, [x, y, z]) => matrix.map((row) => row[0] * x + row[1] * y + row[2] * z);
|
|
245
|
+
const compose = (outer, inner) => outer.map((row) => [
|
|
246
|
+
0,
|
|
247
|
+
1,
|
|
248
|
+
2
|
|
249
|
+
].map((column) => row[0] * inner[0][column] + row[1] * inner[1][column] + row[2] * inner[2][column]));
|
|
250
|
+
const XYZ_TO_SRGB = [
|
|
251
|
+
[
|
|
252
|
+
12831 / 3959,
|
|
253
|
+
-329 / 214,
|
|
254
|
+
-1974 / 3959
|
|
255
|
+
],
|
|
256
|
+
[
|
|
257
|
+
-851781 / 878810,
|
|
258
|
+
1648619 / 878810,
|
|
259
|
+
36519 / 878810
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
705 / 12673,
|
|
263
|
+
-2585 / 12673,
|
|
264
|
+
705 / 667
|
|
265
|
+
]
|
|
266
|
+
];
|
|
267
|
+
const D50_TO_SRGB = compose(XYZ_TO_SRGB, [
|
|
268
|
+
[
|
|
269
|
+
.955473421488075,
|
|
270
|
+
-.02309845494876471,
|
|
271
|
+
.06325924320057072
|
|
272
|
+
],
|
|
273
|
+
[
|
|
274
|
+
-.0283697093338637,
|
|
275
|
+
1.0099953980813041,
|
|
276
|
+
.021041441191917323
|
|
277
|
+
],
|
|
278
|
+
[
|
|
279
|
+
.012314014864481998,
|
|
280
|
+
-.020507649298898964,
|
|
281
|
+
1.330365926242124
|
|
282
|
+
]
|
|
283
|
+
]);
|
|
284
|
+
const decodeSrgb = (value) => {
|
|
285
|
+
const size = Math.abs(value);
|
|
286
|
+
return Math.sign(value) * (size <= .04045 ? size / 12.92 : ((size + .055) / 1.055) ** 2.4);
|
|
287
|
+
};
|
|
288
|
+
const RGB_SPACES = {
|
|
289
|
+
srgb: {
|
|
290
|
+
decode: decodeSrgb,
|
|
291
|
+
toSrgb: null
|
|
292
|
+
},
|
|
293
|
+
"srgb-linear": {
|
|
294
|
+
decode: (value) => value,
|
|
295
|
+
toSrgb: null
|
|
296
|
+
},
|
|
297
|
+
"display-p3": {
|
|
298
|
+
decode: decodeSrgb,
|
|
299
|
+
toSrgb: compose(XYZ_TO_SRGB, [
|
|
300
|
+
[
|
|
301
|
+
.4865709486482162,
|
|
302
|
+
.26566769316909306,
|
|
303
|
+
.1982172852343625
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
.2289745640697488,
|
|
307
|
+
.6917385218365064,
|
|
308
|
+
.079286914093745
|
|
309
|
+
],
|
|
310
|
+
[
|
|
311
|
+
0,
|
|
312
|
+
.04511338185890264,
|
|
313
|
+
1.043944368900976
|
|
314
|
+
]
|
|
315
|
+
])
|
|
316
|
+
},
|
|
317
|
+
"a98-rgb": {
|
|
318
|
+
decode: (value) => Math.sign(value) * Math.abs(value) ** (563 / 256),
|
|
319
|
+
toSrgb: compose(XYZ_TO_SRGB, [
|
|
320
|
+
[
|
|
321
|
+
573536 / 994567,
|
|
322
|
+
263643 / 1420810,
|
|
323
|
+
187206 / 994567
|
|
324
|
+
],
|
|
325
|
+
[
|
|
326
|
+
591459 / 1989134,
|
|
327
|
+
6239551 / 9945670,
|
|
328
|
+
374412 / 4972835
|
|
329
|
+
],
|
|
330
|
+
[
|
|
331
|
+
53769 / 1989134,
|
|
332
|
+
351524 / 4972835,
|
|
333
|
+
4929758 / 4972835
|
|
334
|
+
]
|
|
335
|
+
])
|
|
336
|
+
},
|
|
337
|
+
"prophoto-rgb": {
|
|
338
|
+
decode: (value) => {
|
|
339
|
+
const size = Math.abs(value);
|
|
340
|
+
return size <= 16 / 512 ? value / 16 : Math.sign(value) * size ** 1.8;
|
|
341
|
+
},
|
|
342
|
+
toSrgb: compose(D50_TO_SRGB, [
|
|
343
|
+
[
|
|
344
|
+
.7977666449006423,
|
|
345
|
+
.13518129740053308,
|
|
346
|
+
.0313477341283922
|
|
347
|
+
],
|
|
348
|
+
[
|
|
349
|
+
.2880748288194013,
|
|
350
|
+
.711835234241873,
|
|
351
|
+
8993693872564e-17
|
|
352
|
+
],
|
|
353
|
+
[
|
|
354
|
+
0,
|
|
355
|
+
0,
|
|
356
|
+
.8251046025104602
|
|
357
|
+
]
|
|
358
|
+
])
|
|
359
|
+
},
|
|
360
|
+
rec2020: {
|
|
361
|
+
decode: (value) => {
|
|
362
|
+
const size = Math.abs(value);
|
|
363
|
+
return size < .08124285829863151 ? value / 4.5 : Math.sign(value) * ((size + .09929682680944) / 1.09929682680944) ** (1 / .45);
|
|
364
|
+
},
|
|
365
|
+
toSrgb: compose(XYZ_TO_SRGB, [
|
|
366
|
+
[
|
|
367
|
+
.6369580483012914,
|
|
368
|
+
.14461690358620832,
|
|
369
|
+
.1688809751641721
|
|
370
|
+
],
|
|
371
|
+
[
|
|
372
|
+
.2627002120112671,
|
|
373
|
+
.6779980715188708,
|
|
374
|
+
.05930171646986196
|
|
375
|
+
],
|
|
376
|
+
[
|
|
377
|
+
0,
|
|
378
|
+
.028072693049087428,
|
|
379
|
+
1.060985057710791
|
|
380
|
+
]
|
|
381
|
+
])
|
|
382
|
+
},
|
|
383
|
+
xyz: {
|
|
384
|
+
decode: (value) => value,
|
|
385
|
+
toSrgb: XYZ_TO_SRGB
|
|
386
|
+
},
|
|
387
|
+
"xyz-d65": {
|
|
388
|
+
decode: (value) => value,
|
|
389
|
+
toSrgb: XYZ_TO_SRGB
|
|
390
|
+
},
|
|
391
|
+
"xyz-d50": {
|
|
392
|
+
decode: (value) => value,
|
|
393
|
+
toSrgb: D50_TO_SRGB
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
function labToXyz([lightness, a, b]) {
|
|
397
|
+
const kappa = 24389 / 27;
|
|
398
|
+
const epsilon = 216 / 24389;
|
|
399
|
+
const fy = (lightness + 16) / 116;
|
|
400
|
+
const fx = a / 500 + fy;
|
|
401
|
+
const fz = fy - b / 200;
|
|
402
|
+
const x = fx ** 3 > epsilon ? fx ** 3 : (116 * fx - 16) / kappa;
|
|
403
|
+
const y = lightness > kappa * epsilon ? fy ** 3 : lightness / kappa;
|
|
404
|
+
const z = fz ** 3 > epsilon ? fz ** 3 : (116 * fz - 16) / kappa;
|
|
405
|
+
return [
|
|
406
|
+
x * (.3457 / .3585),
|
|
407
|
+
y,
|
|
408
|
+
z * (.2958 / .3585)
|
|
409
|
+
];
|
|
410
|
+
}
|
|
411
|
+
const fromLinearSrgb = (linear) => oklabToOklch(linearToOklab(linear));
|
|
412
|
+
const isUnit = (channels) => channels.every((channel) => channel >= -1e-6 && channel <= 1 + 1e-6);
|
|
413
|
+
function readChannels(name, parts) {
|
|
414
|
+
if (name === "rgb") {
|
|
415
|
+
const rgb = parts.map((part) => readNumber(part, 255));
|
|
416
|
+
if (rgb.some((value) => value === null)) return null;
|
|
417
|
+
return {
|
|
418
|
+
space: "rgb",
|
|
419
|
+
channels: rgb.map((value) => clamp(value, 0, 255))
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
if (name === "hsl" || name === "hsv" || name === "hsb" || name === "hwb") {
|
|
423
|
+
const hue = readNumber(parts[0], 1, true);
|
|
424
|
+
const first = readNumber(parts[1], 100);
|
|
425
|
+
const second = readNumber(parts[2], 100);
|
|
426
|
+
if (hue === null || first === null || second === null) return null;
|
|
427
|
+
const x = clamp(first, 0, 100);
|
|
428
|
+
const y = clamp(second, 0, 100);
|
|
429
|
+
if (name === "hsl") return {
|
|
430
|
+
space: "hsl",
|
|
431
|
+
channels: [
|
|
432
|
+
hue,
|
|
433
|
+
x,
|
|
434
|
+
y
|
|
435
|
+
]
|
|
436
|
+
};
|
|
437
|
+
if (name !== "hwb") return {
|
|
438
|
+
space: "hsv",
|
|
439
|
+
channels: [
|
|
440
|
+
hue,
|
|
441
|
+
x,
|
|
442
|
+
y
|
|
443
|
+
]
|
|
444
|
+
};
|
|
445
|
+
const total = x + y;
|
|
446
|
+
if (total >= 100) return {
|
|
447
|
+
space: "hsv",
|
|
448
|
+
channels: [
|
|
449
|
+
hue,
|
|
450
|
+
0,
|
|
451
|
+
x / total * 100
|
|
452
|
+
]
|
|
453
|
+
};
|
|
454
|
+
const brightness = 100 - y;
|
|
455
|
+
return {
|
|
456
|
+
space: "hsv",
|
|
457
|
+
channels: [
|
|
458
|
+
hue,
|
|
459
|
+
(1 - x / brightness) * 100,
|
|
460
|
+
brightness
|
|
461
|
+
]
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (name === "oklch" || name === "oklab") {
|
|
465
|
+
const lightness = readNumber(parts[0], 1);
|
|
466
|
+
const second = readNumber(parts[1], .4);
|
|
467
|
+
const third = name === "oklch" ? readNumber(parts[2], 1, true) : readNumber(parts[2], .4);
|
|
468
|
+
if (lightness === null || second === null || third === null) return null;
|
|
469
|
+
const l = clamp(lightness, 0, 1);
|
|
470
|
+
if (name === "oklch") return {
|
|
471
|
+
space: "oklch",
|
|
472
|
+
channels: [
|
|
473
|
+
l * 100,
|
|
474
|
+
Math.max(0, second),
|
|
475
|
+
third
|
|
476
|
+
]
|
|
477
|
+
};
|
|
478
|
+
return {
|
|
479
|
+
space: "oklch",
|
|
480
|
+
channels: oklabToOklch([
|
|
481
|
+
l,
|
|
482
|
+
second,
|
|
483
|
+
third
|
|
484
|
+
])
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
if (name === "lab" || name === "lch") {
|
|
488
|
+
const lightness = readNumber(parts[0], 100);
|
|
489
|
+
const second = readNumber(parts[1], name === "lab" ? 125 : 150);
|
|
490
|
+
const third = name === "lch" ? readNumber(parts[2], 1, true) : readNumber(parts[2], 125);
|
|
491
|
+
if (lightness === null || second === null || third === null) return null;
|
|
492
|
+
const l = clamp(lightness, 0, 100);
|
|
493
|
+
const angle = third * Math.PI / 180;
|
|
494
|
+
const [a, b] = name === "lab" ? [second, third] : [Math.max(0, second) * Math.cos(angle), Math.max(0, second) * Math.sin(angle)];
|
|
495
|
+
return {
|
|
496
|
+
space: "oklch",
|
|
497
|
+
channels: fromLinearSrgb(multiply(D50_TO_SRGB, labToXyz([
|
|
498
|
+
l,
|
|
499
|
+
a,
|
|
500
|
+
b
|
|
501
|
+
])))
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
if (name === "color") {
|
|
505
|
+
const target = RGB_SPACES[parts[0]];
|
|
506
|
+
if (!target || parts.length !== 4) return null;
|
|
507
|
+
const values = parts.slice(1).map((part) => readNumber(part, 1));
|
|
508
|
+
if (values.some((value) => value === null)) return null;
|
|
509
|
+
const channels = values;
|
|
510
|
+
if (parts[0] === "srgb" && isUnit(channels)) return {
|
|
511
|
+
space: "rgb",
|
|
512
|
+
channels: channels.map((value) => clamp(value, 0, 1) * 255)
|
|
513
|
+
};
|
|
514
|
+
const linear = channels.map(target.decode);
|
|
515
|
+
return {
|
|
516
|
+
space: "oklch",
|
|
517
|
+
channels: fromLinearSrgb(target.toSrgb ? multiply(target.toSrgb, linear) : linear)
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Reads a CSS color: hex with 3, 4, 6 or 8 digits, `#` optional; the 148
|
|
524
|
+
* named colors and `transparent`; `rgb()`, `hsl()`, `hwb()`, `lab()`,
|
|
525
|
+
* `lch()`, `oklab()`, `oklch()` and `color()` in any of CSS Color 4's RGB
|
|
526
|
+
* and XYZ spaces, plus `hsb()` or `hsv()`; modern or comma syntax, with or
|
|
527
|
+
* without alpha. A color that can fall outside sRGB is kept as OKLCH.
|
|
528
|
+
* Anything else, `var()` and `currentColor` included, is `null`.
|
|
529
|
+
*/
|
|
530
|
+
function parseColor(input) {
|
|
531
|
+
if (typeof input !== "string") return null;
|
|
532
|
+
const text = input.trim().toLowerCase();
|
|
533
|
+
if (!text) return null;
|
|
534
|
+
if (text === "transparent") return {
|
|
535
|
+
space: "rgb",
|
|
536
|
+
channels: [
|
|
537
|
+
0,
|
|
538
|
+
0,
|
|
539
|
+
0
|
|
540
|
+
],
|
|
541
|
+
alpha: 0
|
|
542
|
+
};
|
|
543
|
+
const hex = HEX_PATTERN.exec(namedColor(text) ?? text);
|
|
544
|
+
if (hex) {
|
|
545
|
+
let digits = hex[1];
|
|
546
|
+
if (digits.length <= 4) digits = [...digits].map((digit) => digit + digit).join("");
|
|
547
|
+
const byte = (index) => parseInt(digits.slice(index, index + 2), 16);
|
|
548
|
+
return {
|
|
549
|
+
space: "rgb",
|
|
550
|
+
channels: [
|
|
551
|
+
byte(0),
|
|
552
|
+
byte(2),
|
|
553
|
+
byte(4)
|
|
554
|
+
],
|
|
555
|
+
alpha: digits.length === 8 ? byte(6) / 255 : 1
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
const call = FUNCTION_PATTERN.exec(text);
|
|
559
|
+
if (!call) return null;
|
|
560
|
+
const name = call[1].replace(/a$/, "");
|
|
561
|
+
const [main, slash, ...rest] = call[2].split("/");
|
|
562
|
+
if (rest.length > 0) return null;
|
|
563
|
+
const parts = main.split(/[\s,]+/).filter(Boolean);
|
|
564
|
+
const count = name === "color" ? 4 : 3;
|
|
565
|
+
const alphaToken = slash?.trim() ?? (name === "color" ? void 0 : parts[3]);
|
|
566
|
+
if (parts.length !== count && !(name !== "color" && parts.length === 4 && slash === void 0)) return null;
|
|
567
|
+
const alpha = alphaToken === void 0 ? 1 : readNumber(alphaToken, 1);
|
|
568
|
+
const read = readChannels(name, parts.slice(0, count));
|
|
569
|
+
if (alpha === null || !read) return null;
|
|
570
|
+
const channels = read.channels;
|
|
571
|
+
if (channels.some((channel) => !Number.isFinite(channel))) return null;
|
|
572
|
+
if (read.space !== "rgb") {
|
|
573
|
+
const hueIndex = read.space === "oklch" ? 2 : 0;
|
|
574
|
+
channels[hueIndex] = wrapHue(channels[hueIndex]);
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
space: read.space,
|
|
578
|
+
channels,
|
|
579
|
+
alpha: clamp(alpha, 0, 1)
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
const CSS_WIDE = /^(inherit|initial|unset|revert|revert-layer|currentcolor)$/;
|
|
583
|
+
function parseWithBrowser(text) {
|
|
584
|
+
if (typeof document === "undefined" || CSS_WIDE.test(text.toLowerCase()) || !CSS.supports?.("color", text)) return null;
|
|
585
|
+
const parent = document.createElement("div");
|
|
586
|
+
const probe = document.createElement("div");
|
|
587
|
+
parent.style.display = "none";
|
|
588
|
+
probe.style.color = text;
|
|
589
|
+
parent.append(probe);
|
|
590
|
+
document.body.append(parent);
|
|
591
|
+
parent.style.color = "rgb(1, 2, 3)";
|
|
592
|
+
const first = getComputedStyle(probe).color;
|
|
593
|
+
parent.style.color = "rgb(4, 5, 6)";
|
|
594
|
+
const second = getComputedStyle(probe).color;
|
|
595
|
+
parent.remove();
|
|
596
|
+
return first === second ? parseColor(first) : null;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Writes a color in a format. HEX gains a fourth byte and the others a
|
|
600
|
+
* `/ alpha` only when the color is translucent; OKLCH keeps channels outside
|
|
601
|
+
* sRGB, every other format maps the color into sRGB the way CSS does.
|
|
602
|
+
*/
|
|
603
|
+
function formatColor(color, format) {
|
|
604
|
+
const alpha = clamp(color.alpha, 0, 1);
|
|
605
|
+
const tail = fixed(alpha, 2) !== "1" ? ` / ${fixed(alpha, 2)}` : "";
|
|
606
|
+
if (format === "hex" || format === "rgb") {
|
|
607
|
+
const rgb = toRgb(color).map((channel) => Math.round(clamp(channel, 0, 255)));
|
|
608
|
+
if (format === "rgb") return `rgb(${rgb.join(" ")}${tail})`;
|
|
609
|
+
const opacity = Math.round(alpha * 255);
|
|
610
|
+
return `#${(opacity < 255 ? [...rgb, opacity] : rgb).map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
611
|
+
}
|
|
612
|
+
if (format === "oklch") {
|
|
613
|
+
const [l, c, h] = toSpace(color, "oklch");
|
|
614
|
+
const hue = fixed(wrapHue(Number(h.toFixed(3))), 3);
|
|
615
|
+
return `oklch(${fixed(l, 2)}% ${fixed(Math.max(0, c), 5)} ${hue}${tail})`;
|
|
616
|
+
}
|
|
617
|
+
const [h, s, third] = toSpace(color, format === "hsl" ? "hsl" : "hsv");
|
|
618
|
+
return `${format}(${fixed(h, 1)} ${fixed(s, 1)}% ${fixed(third, 1)}%${tail})`;
|
|
619
|
+
}
|
|
620
|
+
const toCss = (color) => formatColor(color, color.space === "oklch" ? "oklch" : "rgb");
|
|
621
|
+
function luminance(rgb) {
|
|
622
|
+
const [r, g, b] = rgb.map(toLinear);
|
|
623
|
+
return .2126 * r + .7152 * g + .0722 * b;
|
|
624
|
+
}
|
|
625
|
+
function over(top, bottom) {
|
|
626
|
+
return toRgb(top).map((channel, index) => channel * top.alpha + bottom[index] * (1 - top.alpha));
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* The WCAG 2 contrast ratio, 1 to 21. A translucent foreground is laid over
|
|
630
|
+
* the background, and a translucent background over white. `null` when either
|
|
631
|
+
* color does not parse.
|
|
632
|
+
*/
|
|
633
|
+
function getContrastRatio(foreground, background) {
|
|
634
|
+
const front = typeof foreground === "string" ? parseColor(foreground) : foreground;
|
|
635
|
+
const back = typeof background === "string" ? parseColor(background) : background;
|
|
636
|
+
if (!front || !back) return null;
|
|
637
|
+
const base = over(back, [
|
|
638
|
+
255,
|
|
639
|
+
255,
|
|
640
|
+
255
|
|
641
|
+
]);
|
|
642
|
+
const a = luminance(over(front, base));
|
|
643
|
+
const b = luminance(base);
|
|
644
|
+
return (Math.max(a, b) + .05) / (Math.min(a, b) + .05);
|
|
645
|
+
}
|
|
646
|
+
const FOREGROUND_SWITCH = .36;
|
|
647
|
+
/**
|
|
648
|
+
* The text color that reads better on a background: `light` on a dark one,
|
|
649
|
+
* `dark` on a light one. Light text also has to reach 3:1 by WCAG 2, the AA
|
|
650
|
+
* bar for large text and icons, so orange-500 and sky-500 take dark text.
|
|
651
|
+
* A translucent background is laid over white, as in `getContrastRatio`.
|
|
652
|
+
* `null` when the background does not parse.
|
|
653
|
+
*/
|
|
654
|
+
function getForegroundColor(background, { light = "#ffffff", dark = "#0a0a0a" } = {}) {
|
|
655
|
+
const color = typeof background === "string" ? parseColor(background) : background;
|
|
656
|
+
if (!color) return null;
|
|
657
|
+
return luminance(over(color, [
|
|
658
|
+
255,
|
|
659
|
+
255,
|
|
660
|
+
255
|
|
661
|
+
])) < FOREGROUND_SWITCH && (getContrastRatio(light, color) ?? 0) >= 3 ? light : dark;
|
|
662
|
+
}
|
|
663
|
+
const HUE_NAMES = [
|
|
664
|
+
[15, "pink"],
|
|
665
|
+
[45, "red"],
|
|
666
|
+
[80, "orange"],
|
|
667
|
+
[120, "yellow"],
|
|
668
|
+
[135, "lime"],
|
|
669
|
+
[165, "green"],
|
|
670
|
+
[205, "cyan"],
|
|
671
|
+
[250, "sky blue"],
|
|
672
|
+
[280, "blue"],
|
|
673
|
+
[300, "violet"],
|
|
674
|
+
[320, "purple"],
|
|
675
|
+
[345, "magenta"],
|
|
676
|
+
[360, "pink"]
|
|
677
|
+
];
|
|
678
|
+
/** A rough English name: "dark vibrant blue", "light gray". Swap it through `i18n.functions`. */
|
|
679
|
+
function nameColor(color) {
|
|
680
|
+
const [lightness, chroma, hue] = toSpace(color, "oklch");
|
|
681
|
+
const l = lightness / 100;
|
|
682
|
+
if (chroma < .025) {
|
|
683
|
+
if (l < .2) return "black";
|
|
684
|
+
if (l < .45) return "dark gray";
|
|
685
|
+
if (l < .75) return "gray";
|
|
686
|
+
return l < .95 ? "light gray" : "white";
|
|
687
|
+
}
|
|
688
|
+
let name = HUE_NAMES.find(([end]) => hue < end)?.[1] ?? "pink";
|
|
689
|
+
if (l < .6 && hue >= 40 && hue < 100) name = "brown";
|
|
690
|
+
else if (l < .6 && hue >= 100 && hue < 135) name = "olive";
|
|
691
|
+
return `${l < .45 ? "dark " : l > .82 ? "light " : ""}${chroma < .07 ? "grayish " : chroma > .2 ? "vibrant " : ""}${name}`;
|
|
692
|
+
}
|
|
693
|
+
const DEFAULT_COLOR_PICKER_I18N = {
|
|
694
|
+
labels: {
|
|
695
|
+
placeholder: "Select color",
|
|
696
|
+
panelLabel: "Choose color",
|
|
697
|
+
openPicker: "Open color picker",
|
|
698
|
+
area: "Color",
|
|
699
|
+
hue: "Hue",
|
|
700
|
+
saturation: "Saturation",
|
|
701
|
+
brightness: "Brightness",
|
|
702
|
+
lightness: "Lightness",
|
|
703
|
+
chroma: "Chroma",
|
|
704
|
+
red: "Red",
|
|
705
|
+
green: "Green",
|
|
706
|
+
blue: "Blue",
|
|
707
|
+
alpha: "Opacity",
|
|
708
|
+
hex: "Hex",
|
|
709
|
+
format: "Color format",
|
|
710
|
+
eyeDropper: "Pick a color from the screen",
|
|
711
|
+
copy: "Copy color",
|
|
712
|
+
copied: "Copied",
|
|
713
|
+
clear: "Clear",
|
|
714
|
+
swatches: "Swatches"
|
|
715
|
+
},
|
|
716
|
+
functions: { getColorName: nameColor }
|
|
717
|
+
};
|
|
718
|
+
/** Merges per section, so an override can carry one key without restating the rest. */
|
|
719
|
+
function mergeColorPickerI18n(overrides) {
|
|
720
|
+
if (!overrides?.labels && !overrides?.functions) return DEFAULT_COLOR_PICKER_I18N;
|
|
721
|
+
return {
|
|
722
|
+
labels: {
|
|
723
|
+
...DEFAULT_COLOR_PICKER_I18N.labels,
|
|
724
|
+
...overrides.labels
|
|
725
|
+
},
|
|
726
|
+
functions: {
|
|
727
|
+
...DEFAULT_COLOR_PICKER_I18N.functions,
|
|
728
|
+
...overrides.functions
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
const DEFAULT_SPACE = {
|
|
733
|
+
hue: "hsv",
|
|
734
|
+
saturation: "hsv",
|
|
735
|
+
brightness: "hsv",
|
|
736
|
+
lightness: "hsl",
|
|
737
|
+
chroma: "oklch",
|
|
738
|
+
red: "rgb",
|
|
739
|
+
green: "rgb",
|
|
740
|
+
blue: "rgb",
|
|
741
|
+
alpha: "rgb"
|
|
742
|
+
};
|
|
743
|
+
const resolveSpace = (channel, space) => channel !== "alpha" && space && SPACE_CHANNELS[space].includes(channel) ? space : DEFAULT_SPACE[channel];
|
|
744
|
+
function channelRange(space, channel) {
|
|
745
|
+
if (channel === "alpha") return {
|
|
746
|
+
max: 1,
|
|
747
|
+
step: .01
|
|
748
|
+
};
|
|
749
|
+
if (channel === "hue") return {
|
|
750
|
+
max: 360,
|
|
751
|
+
step: 1
|
|
752
|
+
};
|
|
753
|
+
if (channel === "chroma") return {
|
|
754
|
+
max: .4,
|
|
755
|
+
step: .004
|
|
756
|
+
};
|
|
757
|
+
return {
|
|
758
|
+
max: space === "rgb" ? 255 : 100,
|
|
759
|
+
step: 1
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
function readChannel(color, space, channel) {
|
|
763
|
+
if (channel === "alpha") return color.alpha;
|
|
764
|
+
return toSpace(color, space)[SPACE_CHANNELS[space].indexOf(channel)];
|
|
765
|
+
}
|
|
766
|
+
function withChannel(color, space, channel, value) {
|
|
767
|
+
if (channel === "alpha") return {
|
|
768
|
+
...color,
|
|
769
|
+
alpha: clamp(value, 0, 1)
|
|
770
|
+
};
|
|
771
|
+
const channels = [...toSpace(color, space)];
|
|
772
|
+
channels[SPACE_CHANNELS[space].indexOf(channel)] = value;
|
|
773
|
+
return {
|
|
774
|
+
space,
|
|
775
|
+
channels,
|
|
776
|
+
alpha: color.alpha
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function channelValueText(color, space, channel, i18n) {
|
|
780
|
+
const value = readChannel(color, space, channel);
|
|
781
|
+
if (channel === "alpha") return `${Math.round(value * 100)}%`;
|
|
782
|
+
if (channel === "chroma") return fixed(value, 3);
|
|
783
|
+
if (channel === "hue") return `${Math.round(value)}°, ${i18n.functions.getColorName(color)}`;
|
|
784
|
+
return space === "rgb" ? String(Math.round(value)) : `${Math.round(value)}%`;
|
|
785
|
+
}
|
|
786
|
+
function trackStops(color, space, channel) {
|
|
787
|
+
const opaque = {
|
|
788
|
+
...color,
|
|
789
|
+
alpha: 1
|
|
790
|
+
};
|
|
791
|
+
if (channel === "alpha") return ["transparent", toCss(opaque)];
|
|
792
|
+
let base = opaque;
|
|
793
|
+
if (channel === "hue") base = space === "oklch" ? withChannel(opaque, "oklch", "chroma", Math.max(readChannel(opaque, "oklch", "chroma"), .12)) : {
|
|
794
|
+
space: "hsv",
|
|
795
|
+
channels: [
|
|
796
|
+
0,
|
|
797
|
+
100,
|
|
798
|
+
100
|
|
799
|
+
],
|
|
800
|
+
alpha: 1
|
|
801
|
+
};
|
|
802
|
+
const count = channel === "hue" || space === "oklch" ? 13 : space === "hsl" && channel === "lightness" ? 3 : 2;
|
|
803
|
+
const { max } = channelRange(space, channel);
|
|
804
|
+
const target = channel === "hue" && space !== "oklch" ? "hsv" : space;
|
|
805
|
+
return Array.from({ length: count }, (_, index) => formatColor(withChannel(base, target, channel, max * index / (count - 1)), "rgb"));
|
|
806
|
+
}
|
|
807
|
+
const CHECKER = "repeating-conic-gradient(var(--color-muted) 0 25%, var(--color-background) 0 50%) 50% / 8px 8px";
|
|
808
|
+
const EMPTY_COLOR = {
|
|
809
|
+
space: "hsv",
|
|
810
|
+
channels: [
|
|
811
|
+
0,
|
|
812
|
+
0,
|
|
813
|
+
100
|
|
814
|
+
],
|
|
815
|
+
alpha: 1
|
|
816
|
+
};
|
|
817
|
+
const ColorPickerContext = createContext(null);
|
|
818
|
+
/** "inline" unless a part renders inside `ColorPickerContent`. */
|
|
819
|
+
const SurfaceContext = createContext("inline");
|
|
820
|
+
function useColorPickerContext(part) {
|
|
821
|
+
const context = useContext(ColorPickerContext);
|
|
822
|
+
if (!context) throw new Error(`${part} must be used within a ColorPicker`);
|
|
823
|
+
return context;
|
|
824
|
+
}
|
|
825
|
+
/** The picker's state and actions, inside a `ColorPicker`. */
|
|
826
|
+
function useColorPicker() {
|
|
827
|
+
const context = useColorPickerContext("useColorPicker");
|
|
828
|
+
return {
|
|
829
|
+
value: context.value,
|
|
830
|
+
color: context.color,
|
|
831
|
+
format: context.format,
|
|
832
|
+
open: context.open,
|
|
833
|
+
setOpen: context.setOpen,
|
|
834
|
+
setValue: (value) => {
|
|
835
|
+
if (!value) return context.change(null);
|
|
836
|
+
const parsed = parseColor(value);
|
|
837
|
+
if (parsed) context.change(parsed);
|
|
838
|
+
},
|
|
839
|
+
clear: () => context.change(null)
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function assignRef(ref, node) {
|
|
843
|
+
if (typeof ref === "function") ref(node);
|
|
844
|
+
else if (ref) ref.current = node;
|
|
845
|
+
}
|
|
846
|
+
function ColorPicker({ value, defaultValue = null, onValueChange, onValueCommit, format = "hex", alpha = false, swatches, open: openProp, defaultOpen = false, onOpenChange, disabled = false, readOnly = false, invalid = false, name, form, required = false, inputRef, id: idProp, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, i18n: i18nProp, placeholder, className, children }) {
|
|
847
|
+
const generatedId = useId();
|
|
848
|
+
const id = idProp ?? generatedId;
|
|
849
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
850
|
+
const [initialValue] = useState(defaultValue);
|
|
851
|
+
const [openState, setOpenState] = useState(defaultOpen);
|
|
852
|
+
const open = openProp ?? openState;
|
|
853
|
+
const raw = (value !== void 0 ? value : uncontrolled) || null;
|
|
854
|
+
const [held, setHeld] = useState(() => ({
|
|
855
|
+
value: raw,
|
|
856
|
+
color: parseColor(raw)
|
|
857
|
+
}));
|
|
858
|
+
let color = held.color;
|
|
859
|
+
if (held.value !== raw) {
|
|
860
|
+
color = parseColor(raw);
|
|
861
|
+
setHeld({
|
|
862
|
+
value: raw,
|
|
863
|
+
color
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
if (color && !alpha && color.alpha !== 1) color = {
|
|
867
|
+
...color,
|
|
868
|
+
alpha: 1
|
|
869
|
+
};
|
|
870
|
+
const display = color ?? EMPTY_COLOR;
|
|
871
|
+
const latest = useRef({
|
|
872
|
+
value: raw,
|
|
873
|
+
color: display
|
|
874
|
+
});
|
|
875
|
+
useLayoutEffect(() => {
|
|
876
|
+
latest.current = {
|
|
877
|
+
value: raw,
|
|
878
|
+
color: display
|
|
879
|
+
};
|
|
880
|
+
});
|
|
881
|
+
const interaction = useRef(null);
|
|
882
|
+
const focusTarget = useRef(null);
|
|
883
|
+
const fieldRef = useRef(null);
|
|
884
|
+
const resetRef = useRef(() => {});
|
|
885
|
+
const i18n = mergeColorPickerI18n(i18nProp);
|
|
886
|
+
const editable = !disabled && !readOnly;
|
|
887
|
+
const setOpen = (next) => {
|
|
888
|
+
if (next && disabled) return;
|
|
889
|
+
if (openProp === void 0) setOpenState(next);
|
|
890
|
+
onOpenChange?.(next);
|
|
891
|
+
};
|
|
892
|
+
const canonical = (text) => {
|
|
893
|
+
const parsed = parseColor(text);
|
|
894
|
+
if (!parsed) return null;
|
|
895
|
+
return formatColor(alpha ? parsed : {
|
|
896
|
+
...parsed,
|
|
897
|
+
alpha: 1
|
|
898
|
+
}, format);
|
|
899
|
+
};
|
|
900
|
+
const emit = (next) => {
|
|
901
|
+
if (!editable) return;
|
|
902
|
+
const normalized = next && !alpha ? {
|
|
903
|
+
...next,
|
|
904
|
+
alpha: 1
|
|
905
|
+
} : next;
|
|
906
|
+
const nextValue = normalized ? formatColor(normalized, format) : null;
|
|
907
|
+
const previous = latest.current.value;
|
|
908
|
+
const same = nextValue === previous || nextValue === canonical(previous);
|
|
909
|
+
const kept = same ? previous : nextValue;
|
|
910
|
+
latest.current = {
|
|
911
|
+
value: kept,
|
|
912
|
+
color: normalized ?? EMPTY_COLOR
|
|
913
|
+
};
|
|
914
|
+
setHeld({
|
|
915
|
+
value: kept,
|
|
916
|
+
color: normalized
|
|
917
|
+
});
|
|
918
|
+
if (same) return;
|
|
919
|
+
if (value === void 0) setUncontrolled(nextValue);
|
|
920
|
+
onValueChange?.(nextValue);
|
|
921
|
+
};
|
|
922
|
+
const startInteraction = () => {
|
|
923
|
+
interaction.current = { from: latest.current.value };
|
|
924
|
+
};
|
|
925
|
+
const endInteraction = () => {
|
|
926
|
+
const started = interaction.current;
|
|
927
|
+
interaction.current = null;
|
|
928
|
+
if (started && started.from !== latest.current.value) onValueCommit?.(latest.current.value);
|
|
929
|
+
};
|
|
930
|
+
const [fieldsFormat, setFieldsFormat] = useState(null);
|
|
931
|
+
const shownFormat = fieldsFormat ?? format;
|
|
932
|
+
const [copied, setCopied] = useState(null);
|
|
933
|
+
const copiedTimer = useRef(0);
|
|
934
|
+
useEffect(() => () => window.clearTimeout(copiedTimer.current), []);
|
|
935
|
+
const context = {
|
|
936
|
+
id,
|
|
937
|
+
value: raw,
|
|
938
|
+
text: color ? format === "hex" ? formatColor(color, format).toUpperCase() : formatColor(color, format) : null,
|
|
939
|
+
color,
|
|
940
|
+
display,
|
|
941
|
+
format,
|
|
942
|
+
alpha,
|
|
943
|
+
i18n,
|
|
944
|
+
disabled,
|
|
945
|
+
readOnly,
|
|
946
|
+
editable,
|
|
947
|
+
invalid,
|
|
948
|
+
required,
|
|
949
|
+
label,
|
|
950
|
+
labelledBy,
|
|
951
|
+
describedBy,
|
|
952
|
+
swatches,
|
|
953
|
+
open,
|
|
954
|
+
setOpen,
|
|
955
|
+
getColor: () => latest.current.color,
|
|
956
|
+
emit,
|
|
957
|
+
startInteraction,
|
|
958
|
+
endInteraction,
|
|
959
|
+
change: (next) => {
|
|
960
|
+
startInteraction();
|
|
961
|
+
emit(next);
|
|
962
|
+
endInteraction();
|
|
963
|
+
},
|
|
964
|
+
registerFocusTarget: (node) => {
|
|
965
|
+
if (node) focusTarget.current = node;
|
|
966
|
+
},
|
|
967
|
+
shownFormat,
|
|
968
|
+
setFieldsFormat,
|
|
969
|
+
copy: (to = shownFormat) => {
|
|
970
|
+
if (!color) return;
|
|
971
|
+
navigator.clipboard?.writeText(formatColor(color, to)).then(() => {
|
|
972
|
+
setCopied(to);
|
|
973
|
+
window.clearTimeout(copiedTimer.current);
|
|
974
|
+
copiedTimer.current = window.setTimeout(() => setCopied(null), 1500);
|
|
975
|
+
}, () => {});
|
|
976
|
+
},
|
|
977
|
+
copied
|
|
978
|
+
};
|
|
979
|
+
useEffect(() => {
|
|
980
|
+
resetRef.current = () => context.change(parseColor(initialValue));
|
|
981
|
+
});
|
|
982
|
+
const hasField = !!name || required;
|
|
983
|
+
useEffect(() => {
|
|
984
|
+
const root = fieldRef.current?.getRootNode();
|
|
985
|
+
if (!root) return;
|
|
986
|
+
let pending = 0;
|
|
987
|
+
const onReset = (event) => {
|
|
988
|
+
if (event.target !== fieldRef.current?.form) return;
|
|
989
|
+
pending = window.setTimeout(() => {
|
|
990
|
+
if (!event.defaultPrevented) resetRef.current();
|
|
991
|
+
});
|
|
992
|
+
};
|
|
993
|
+
root.addEventListener("reset", onReset, true);
|
|
994
|
+
return () => {
|
|
995
|
+
root.removeEventListener("reset", onReset, true);
|
|
996
|
+
window.clearTimeout(pending);
|
|
997
|
+
};
|
|
998
|
+
}, []);
|
|
999
|
+
return /* @__PURE__ */ jsxs(ColorPickerContext.Provider, {
|
|
1000
|
+
value: context,
|
|
1001
|
+
children: [
|
|
1002
|
+
/* @__PURE__ */ jsx(Popover, {
|
|
1003
|
+
open,
|
|
1004
|
+
onOpenChange: (next) => setOpen(next),
|
|
1005
|
+
children: children === void 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ColorPickerTrigger, {
|
|
1006
|
+
className,
|
|
1007
|
+
placeholder
|
|
1008
|
+
}), /* @__PURE__ */ jsx(ColorPickerContent, {})] }) : children
|
|
1009
|
+
}),
|
|
1010
|
+
/* @__PURE__ */ jsx("span", {
|
|
1011
|
+
role: "status",
|
|
1012
|
+
className: "sr-only",
|
|
1013
|
+
children: copied ? i18n.labels.copied : ""
|
|
1014
|
+
}),
|
|
1015
|
+
hasField && /* @__PURE__ */ jsx("input", {
|
|
1016
|
+
ref: (node) => {
|
|
1017
|
+
fieldRef.current = node;
|
|
1018
|
+
assignRef(inputRef, node);
|
|
1019
|
+
},
|
|
1020
|
+
type: "text",
|
|
1021
|
+
name,
|
|
1022
|
+
form,
|
|
1023
|
+
required: required && !readOnly,
|
|
1024
|
+
disabled,
|
|
1025
|
+
value: color ? formatColor(color, format) : "",
|
|
1026
|
+
onChange: () => {},
|
|
1027
|
+
tabIndex: -1,
|
|
1028
|
+
"aria-hidden": "true",
|
|
1029
|
+
"data-slot": "color-picker-field",
|
|
1030
|
+
onFocus: (event) => {
|
|
1031
|
+
const target = (focusTarget.current?.isConnected ? focusTarget.current : null) ?? event.currentTarget.ownerDocument.getElementById(`${id}-area`);
|
|
1032
|
+
if (target) target.focus();
|
|
1033
|
+
else event.currentTarget.blur();
|
|
1034
|
+
},
|
|
1035
|
+
className: "pointer-events-none absolute size-px max-w-px opacity-0"
|
|
1036
|
+
})
|
|
1037
|
+
]
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
const SWATCH_CLASS = "forced-color-adjust-none relative inline-flex size-4 shrink-0 after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:inset-ring after:inset-ring-foreground/10";
|
|
1041
|
+
const SWATCH_SQUARE = "rounded-[4px]";
|
|
1042
|
+
const EMPTY_SWATCH = "linear-gradient(to top right, transparent calc(50% - 0.75px), var(--color-destructive) calc(50% - 0.75px) calc(50% + 0.75px), transparent calc(50% + 0.75px))";
|
|
1043
|
+
function swatchBackground(color) {
|
|
1044
|
+
if (!color) return EMPTY_SWATCH;
|
|
1045
|
+
const css = toCss(color);
|
|
1046
|
+
return color.alpha < 1 ? `linear-gradient(${css}, ${css}), ${CHECKER}` : css;
|
|
1047
|
+
}
|
|
1048
|
+
/** A color chip: the value in a trigger, or any color in a table or a legend. */
|
|
1049
|
+
function ColorPickerSwatch({ color: colorProp, shape = "square", className, style, ...props }) {
|
|
1050
|
+
const context = useContext(ColorPickerContext);
|
|
1051
|
+
const color = colorProp !== void 0 ? parseColor(colorProp) : context?.color ?? null;
|
|
1052
|
+
const labelled = !!props["aria-label"] || !!props["aria-labelledby"];
|
|
1053
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1054
|
+
role: labelled ? "img" : void 0,
|
|
1055
|
+
"aria-hidden": labelled ? void 0 : true,
|
|
1056
|
+
"data-slot": "color-picker-swatch",
|
|
1057
|
+
"data-empty": color ? void 0 : "",
|
|
1058
|
+
className: cn(SWATCH_CLASS, shape === "circle" ? "rounded-full" : SWATCH_SQUARE, className),
|
|
1059
|
+
style: {
|
|
1060
|
+
background: swatchBackground(color),
|
|
1061
|
+
...style
|
|
1062
|
+
},
|
|
1063
|
+
...props
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
const CHEVRON_ICON = /* @__PURE__ */ jsx(ChevronDownIcon, { "aria-hidden": "true" });
|
|
1067
|
+
/** The value as text, or the placeholder. For custom trigger content. */
|
|
1068
|
+
function ColorPickerValue({ placeholder, className, ...props }) {
|
|
1069
|
+
const context = useColorPickerContext("ColorPickerValue");
|
|
1070
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1071
|
+
"data-slot": "color-picker-value",
|
|
1072
|
+
"data-placeholder": context.color ? void 0 : "",
|
|
1073
|
+
className: cn("truncate", className),
|
|
1074
|
+
...props,
|
|
1075
|
+
children: context.text ?? placeholder ?? context.i18n.labels.placeholder
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
const TRIGGER_CLASS = "font-normal normal-case tracking-normal tabular-nums data-placeholder:text-muted-foreground";
|
|
1079
|
+
/** A shadcn Button that opens the picker. Children replace the swatch, value and chevron. */
|
|
1080
|
+
function ColorPickerTrigger({ className, variant = "outline", placeholder, children, ref, ...props }) {
|
|
1081
|
+
const context = useColorPickerContext("ColorPickerTrigger");
|
|
1082
|
+
const labelledBy = props["aria-labelledby"] ?? context.labelledBy;
|
|
1083
|
+
const buttonProps = {
|
|
1084
|
+
variant,
|
|
1085
|
+
disabled: context.disabled,
|
|
1086
|
+
"aria-label": context.label,
|
|
1087
|
+
"aria-describedby": context.describedBy,
|
|
1088
|
+
...context.invalid && {
|
|
1089
|
+
"aria-invalid": true,
|
|
1090
|
+
"data-invalid": ""
|
|
1091
|
+
},
|
|
1092
|
+
...props,
|
|
1093
|
+
"aria-labelledby": labelledBy ? `${labelledBy} ${context.id}` : void 0,
|
|
1094
|
+
onKeyDown: (event) => {
|
|
1095
|
+
props.onKeyDown?.(event);
|
|
1096
|
+
if (!event.defaultPrevented) copyOnShortcut(event, context);
|
|
1097
|
+
},
|
|
1098
|
+
id: context.id,
|
|
1099
|
+
ref: (node) => {
|
|
1100
|
+
context.registerFocusTarget(node);
|
|
1101
|
+
assignRef(ref, node);
|
|
1102
|
+
},
|
|
1103
|
+
"data-slot": "color-picker-trigger",
|
|
1104
|
+
"data-placeholder": context.color ? void 0 : "",
|
|
1105
|
+
className: cn(TRIGGER_CLASS, children === void 0 && "justify-start", className)
|
|
1106
|
+
};
|
|
1107
|
+
const content = children === void 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
1108
|
+
/* @__PURE__ */ jsx(ColorPickerSwatch, { "data-icon": "inline-start" }),
|
|
1109
|
+
/* @__PURE__ */ jsx(ColorPickerValue, {
|
|
1110
|
+
placeholder,
|
|
1111
|
+
className: "flex-1 text-start"
|
|
1112
|
+
}),
|
|
1113
|
+
/* @__PURE__ */ jsx("span", {
|
|
1114
|
+
"data-icon": "inline-end",
|
|
1115
|
+
"aria-hidden": "true",
|
|
1116
|
+
className: "flex text-muted-foreground",
|
|
1117
|
+
children: CHEVRON_ICON
|
|
1118
|
+
})
|
|
1119
|
+
] }) : children;
|
|
1120
|
+
return /* @__PURE__ */ jsx(PopoverTrigger, {
|
|
1121
|
+
id: context.id,
|
|
1122
|
+
render: /* @__PURE__ */ jsx(Button, { ...buttonProps }),
|
|
1123
|
+
children: content
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* A typable field with a swatch button that opens the picker. It reads any
|
|
1128
|
+
* CSS color the browser knows, named colors included, on blur and Enter;
|
|
1129
|
+
* Escape restores the value and Alt+ArrowDown opens the popover.
|
|
1130
|
+
*/
|
|
1131
|
+
function ColorPickerInput({ className, placeholder, onBlur, onKeyDown, onChange, ref, ...props }) {
|
|
1132
|
+
const context = useColorPickerContext("ColorPickerInput");
|
|
1133
|
+
const [text, setText] = useState(null);
|
|
1134
|
+
const current = context.text ?? "";
|
|
1135
|
+
const shown = text ?? current;
|
|
1136
|
+
const fieldRef = useRef(null);
|
|
1137
|
+
useEscapeRevert(fieldRef, text !== null, () => setText(null));
|
|
1138
|
+
const read = () => {
|
|
1139
|
+
if (text === null) return;
|
|
1140
|
+
setText(null);
|
|
1141
|
+
if (text === current) return;
|
|
1142
|
+
if (!text.trim()) return context.change(null);
|
|
1143
|
+
const typed = parseColor(text) ?? parseWithBrowser(text.trim());
|
|
1144
|
+
if (typed) context.change(typed);
|
|
1145
|
+
};
|
|
1146
|
+
const swatchProps = {
|
|
1147
|
+
size: "icon-xs",
|
|
1148
|
+
disabled: context.disabled,
|
|
1149
|
+
"aria-label": context.i18n.labels.openPicker,
|
|
1150
|
+
"data-slot": "color-picker-input-trigger"
|
|
1151
|
+
};
|
|
1152
|
+
return /* @__PURE__ */ jsxs(InputGroup, {
|
|
1153
|
+
"data-slot": "color-picker-input",
|
|
1154
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
1155
|
+
className,
|
|
1156
|
+
children: [/* @__PURE__ */ jsx(InputGroupAddon, {
|
|
1157
|
+
align: "inline-start",
|
|
1158
|
+
children: /* @__PURE__ */ jsx(PopoverTrigger, {
|
|
1159
|
+
render: /* @__PURE__ */ jsx(InputGroupButton, { ...swatchProps }),
|
|
1160
|
+
children: /* @__PURE__ */ jsx(ColorPickerSwatch, {})
|
|
1161
|
+
})
|
|
1162
|
+
}), /* @__PURE__ */ jsx(InputGroupInput, {
|
|
1163
|
+
value: shown,
|
|
1164
|
+
placeholder: placeholder ?? context.i18n.labels.placeholder,
|
|
1165
|
+
disabled: context.disabled,
|
|
1166
|
+
readOnly: context.readOnly,
|
|
1167
|
+
required: context.required,
|
|
1168
|
+
autoComplete: "off",
|
|
1169
|
+
autoCorrect: "off",
|
|
1170
|
+
autoCapitalize: "off",
|
|
1171
|
+
spellCheck: false,
|
|
1172
|
+
"aria-keyshortcuts": "Alt+ArrowDown",
|
|
1173
|
+
"aria-label": context.label,
|
|
1174
|
+
"aria-labelledby": context.labelledBy,
|
|
1175
|
+
"aria-describedby": context.describedBy,
|
|
1176
|
+
"aria-invalid": context.invalid || void 0,
|
|
1177
|
+
className: "tabular-nums",
|
|
1178
|
+
onChange: (event) => {
|
|
1179
|
+
onChange?.(event);
|
|
1180
|
+
setText(event.target.value);
|
|
1181
|
+
},
|
|
1182
|
+
onBlur: (event) => {
|
|
1183
|
+
onBlur?.(event);
|
|
1184
|
+
read();
|
|
1185
|
+
},
|
|
1186
|
+
onKeyDown: (event) => {
|
|
1187
|
+
onKeyDown?.(event);
|
|
1188
|
+
if (event.defaultPrevented || copyOnShortcut(event, context)) return;
|
|
1189
|
+
if (event.key === "Enter") flushSync(() => read());
|
|
1190
|
+
else if (event.altKey && event.key === "ArrowDown") {
|
|
1191
|
+
event.preventDefault();
|
|
1192
|
+
read();
|
|
1193
|
+
context.setOpen(true);
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
...props,
|
|
1197
|
+
id: context.id,
|
|
1198
|
+
ref: (node) => {
|
|
1199
|
+
fieldRef.current = node;
|
|
1200
|
+
context.registerFocusTarget(node);
|
|
1201
|
+
assignRef(ref, node);
|
|
1202
|
+
}
|
|
1203
|
+
})]
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
const TABBABLE = "button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])";
|
|
1207
|
+
/**
|
|
1208
|
+
* The popover: the default panel unless given children. Tab cycles inside
|
|
1209
|
+
* it, as in a date picker dialog, in both twins.
|
|
1210
|
+
*/
|
|
1211
|
+
function ColorPickerContent({ className, align = "start", onKeyDown, children, ...props }) {
|
|
1212
|
+
const context = useColorPickerContext("ColorPickerContent");
|
|
1213
|
+
return /* @__PURE__ */ jsx(PopoverContent, {
|
|
1214
|
+
align,
|
|
1215
|
+
"aria-labelledby": context.labelledBy,
|
|
1216
|
+
"aria-label": context.labelledBy ? void 0 : context.label ?? context.i18n.labels.panelLabel,
|
|
1217
|
+
className: cn("w-(--color-picker-content-width) max-w-[calc(100vw-1rem)]", context.alpha ? "[--color-picker-content-width:--spacing(96)] md:[--color-picker-content-width:--spacing(84)]" : "[--color-picker-content-width:--spacing(72)]", className),
|
|
1218
|
+
onKeyDown: (event) => {
|
|
1219
|
+
onKeyDown?.(event);
|
|
1220
|
+
if (event.defaultPrevented || event.key !== "Tab") return;
|
|
1221
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
1222
|
+
const items = Array.from(event.currentTarget.querySelectorAll(TABBABLE));
|
|
1223
|
+
const active = event.currentTarget.ownerDocument.activeElement;
|
|
1224
|
+
const first = items[0];
|
|
1225
|
+
const last = items[items.length - 1];
|
|
1226
|
+
if (!event.shiftKey && active === last) {
|
|
1227
|
+
event.preventDefault();
|
|
1228
|
+
first?.focus();
|
|
1229
|
+
} else if (event.shiftKey && active === first) {
|
|
1230
|
+
event.preventDefault();
|
|
1231
|
+
last?.focus();
|
|
1232
|
+
}
|
|
1233
|
+
},
|
|
1234
|
+
...props,
|
|
1235
|
+
children: /* @__PURE__ */ jsx(SurfaceContext.Provider, {
|
|
1236
|
+
value: "popup",
|
|
1237
|
+
children: children === void 0 ? /* @__PURE__ */ jsx(ColorPickerPanel, {}) : children
|
|
1238
|
+
})
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
const PANEL_CLASS = "flex w-full min-w-0 flex-col gap-2.5";
|
|
1242
|
+
/**
|
|
1243
|
+
* The area, the sliders, the fields and any `swatches`, rendered in place:
|
|
1244
|
+
* put it straight inside a `ColorPicker` for an always-open picker.
|
|
1245
|
+
*/
|
|
1246
|
+
function ColorPickerPanel({ className, children, ...props }) {
|
|
1247
|
+
const context = useColorPickerContext("ColorPickerPanel");
|
|
1248
|
+
const inline = useContext(SurfaceContext) === "inline";
|
|
1249
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1250
|
+
role: inline ? "group" : void 0,
|
|
1251
|
+
"aria-labelledby": inline ? context.labelledBy : void 0,
|
|
1252
|
+
"aria-label": inline && !context.labelledBy ? context.label ?? context.i18n.labels.panelLabel : void 0,
|
|
1253
|
+
"data-slot": "color-picker-panel",
|
|
1254
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
1255
|
+
className: cn(PANEL_CLASS, className),
|
|
1256
|
+
...props,
|
|
1257
|
+
children: children === void 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
1258
|
+
/* @__PURE__ */ jsx(ColorPickerArea, {}),
|
|
1259
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1260
|
+
className: "flex items-center gap-3",
|
|
1261
|
+
children: [
|
|
1262
|
+
/* @__PURE__ */ jsx(ColorPickerEyeDropper, {}),
|
|
1263
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1264
|
+
className: "flex min-w-0 flex-1 flex-col gap-2.5",
|
|
1265
|
+
children: [/* @__PURE__ */ jsx(ColorPickerSlider, { channel: "hue" }), context.alpha && /* @__PURE__ */ jsx(ColorPickerSlider, { channel: "alpha" })]
|
|
1266
|
+
}),
|
|
1267
|
+
/* @__PURE__ */ jsx(ColorPickerCopy, {})
|
|
1268
|
+
]
|
|
1269
|
+
}),
|
|
1270
|
+
/* @__PURE__ */ jsx(ColorPickerFields, {}),
|
|
1271
|
+
context.swatches && context.swatches.length > 0 && /* @__PURE__ */ jsx(ColorPickerSwatches, { colors: context.swatches })
|
|
1272
|
+
] }) : children
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
function copyOnShortcut(event, context) {
|
|
1276
|
+
if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "c" || !context.color) return false;
|
|
1277
|
+
const target = event.target;
|
|
1278
|
+
if (target instanceof HTMLInputElement ? target.selectionStart !== target.selectionEnd : !!event.currentTarget.ownerDocument.getSelection()?.toString()) return false;
|
|
1279
|
+
event.preventDefault();
|
|
1280
|
+
context.copy();
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
function useEscapeRevert(field, editing, revert) {
|
|
1284
|
+
const revertRef = useRef(revert);
|
|
1285
|
+
useLayoutEffect(() => {
|
|
1286
|
+
revertRef.current = revert;
|
|
1287
|
+
});
|
|
1288
|
+
useEffect(() => {
|
|
1289
|
+
const view = field.current?.ownerDocument.defaultView;
|
|
1290
|
+
if (!editing || !view) return;
|
|
1291
|
+
const onKeyDown = (event) => {
|
|
1292
|
+
if (event.key !== "Escape" || event.target !== field.current) return;
|
|
1293
|
+
event.preventDefault();
|
|
1294
|
+
event.stopPropagation();
|
|
1295
|
+
revertRef.current();
|
|
1296
|
+
};
|
|
1297
|
+
view.addEventListener("keydown", onKeyDown, true);
|
|
1298
|
+
return () => view.removeEventListener("keydown", onKeyDown, true);
|
|
1299
|
+
}, [editing, field]);
|
|
1300
|
+
}
|
|
1301
|
+
const THUMB_CLASS = "pointer-events-none absolute size-(--color-picker-thumb-size) -translate-x-1/2 -translate-y-1/2 border-2 border-white shadow-[0_0_0_1px_rgb(0_0_0/0.12),0_1px_3px_rgb(0_0_0/0.3)] transition-[box-shadow] rounded-full ring-ring/50 group-focus-visible/color-picker-control:ring-3 forced-colors:outline-2 forced-colors:outline-solid";
|
|
1302
|
+
const EDGE_CLASS = "after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:inset-ring after:inset-ring-foreground/10";
|
|
1303
|
+
const CONTROL_CLASS = "group/color-picker-control relative outline-none [--color-picker-thumb-size:calc(var(--spacing)*4)] select-none aria-disabled:pointer-events-none aria-disabled:opacity-50 data-dragging:cursor-grabbing";
|
|
1304
|
+
function pointerRatio(event, element, inset = 0) {
|
|
1305
|
+
const rect = element.getBoundingClientRect();
|
|
1306
|
+
const ratio = (offset, size) => size > inset ? clamp((offset - inset / 2) / (size - inset), 0, 1) : 0;
|
|
1307
|
+
return {
|
|
1308
|
+
x: ratio(event.clientX - rect.left, rect.width),
|
|
1309
|
+
y: ratio(event.clientY - rect.top, rect.height)
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
const travel = (fraction) => `calc(var(--color-picker-thumb-size) / 2 + (100% - var(--color-picker-thumb-size)) * ${fraction})`;
|
|
1313
|
+
function useDrag(context, update) {
|
|
1314
|
+
const pointer = useRef(null);
|
|
1315
|
+
const [dragging, setDragging] = useState(false);
|
|
1316
|
+
const end = (event) => {
|
|
1317
|
+
if (pointer.current !== event.pointerId) return;
|
|
1318
|
+
pointer.current = null;
|
|
1319
|
+
setDragging(false);
|
|
1320
|
+
context.endInteraction();
|
|
1321
|
+
};
|
|
1322
|
+
return {
|
|
1323
|
+
dragging,
|
|
1324
|
+
handlers: {
|
|
1325
|
+
onPointerDown: (event) => {
|
|
1326
|
+
if (event.button !== 0 || !context.editable) return;
|
|
1327
|
+
pointer.current = event.pointerId;
|
|
1328
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
1329
|
+
setDragging(true);
|
|
1330
|
+
context.startInteraction();
|
|
1331
|
+
update(event, event.currentTarget);
|
|
1332
|
+
},
|
|
1333
|
+
onPointerMove: (event) => {
|
|
1334
|
+
if (pointer.current === event.pointerId) update(event, event.currentTarget);
|
|
1335
|
+
},
|
|
1336
|
+
onPointerUp: end,
|
|
1337
|
+
onPointerCancel: end
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
function keyDelta(event, step) {
|
|
1342
|
+
const size = event.shiftKey ? step * 10 : step;
|
|
1343
|
+
switch (event.key) {
|
|
1344
|
+
case "ArrowUp":
|
|
1345
|
+
case "ArrowRight": return size;
|
|
1346
|
+
case "ArrowDown":
|
|
1347
|
+
case "ArrowLeft": return -size;
|
|
1348
|
+
case "PageUp": return step * 10;
|
|
1349
|
+
case "PageDown": return -step * 10;
|
|
1350
|
+
case "Home": return -Infinity;
|
|
1351
|
+
case "End": return Infinity;
|
|
1352
|
+
}
|
|
1353
|
+
return null;
|
|
1354
|
+
}
|
|
1355
|
+
const snap = (value, step) => Number((Math.round(value / step) * step).toFixed(4));
|
|
1356
|
+
const AREA_CLASS = "forced-color-adjust-none h-40 w-full touch-none bg-[linear-gradient(to_top,#000,transparent),linear-gradient(to_right,#fff,transparent)] rounded-md";
|
|
1357
|
+
/**
|
|
1358
|
+
* The saturation and brightness square, at the current hue. A single slider
|
|
1359
|
+
* to assistive tech, whose value text names both channels and the color.
|
|
1360
|
+
* Arrows move it, Shift by ten, Page keys move brightness.
|
|
1361
|
+
*/
|
|
1362
|
+
function ColorPickerArea({ className, style, onKeyDown, ...props }) {
|
|
1363
|
+
const context = useColorPickerContext("ColorPickerArea");
|
|
1364
|
+
const { labels } = context.i18n;
|
|
1365
|
+
const [hue, saturation, brightness] = toSpace(context.display, "hsv");
|
|
1366
|
+
const set = (s, v) => {
|
|
1367
|
+
const [h] = toSpace(context.getColor(), "hsv");
|
|
1368
|
+
context.emit({
|
|
1369
|
+
space: "hsv",
|
|
1370
|
+
channels: [
|
|
1371
|
+
h,
|
|
1372
|
+
clamp(s, 0, 100),
|
|
1373
|
+
clamp(v, 0, 100)
|
|
1374
|
+
],
|
|
1375
|
+
alpha: context.getColor().alpha
|
|
1376
|
+
});
|
|
1377
|
+
};
|
|
1378
|
+
const { dragging, handlers } = useDrag(context, (event, element) => {
|
|
1379
|
+
const { x, y } = pointerRatio(event, element);
|
|
1380
|
+
set(x * 100, (1 - y) * 100);
|
|
1381
|
+
});
|
|
1382
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1383
|
+
id: `${context.id}-area`,
|
|
1384
|
+
role: "slider",
|
|
1385
|
+
tabIndex: context.disabled ? -1 : 0,
|
|
1386
|
+
"aria-label": labels.area,
|
|
1387
|
+
"aria-valuemin": 0,
|
|
1388
|
+
"aria-valuemax": 100,
|
|
1389
|
+
"aria-valuenow": Math.round(saturation),
|
|
1390
|
+
"aria-valuetext": `${labels.saturation} ${Math.round(saturation)}%, ${labels.brightness} ${Math.round(brightness)}%, ${context.i18n.functions.getColorName(context.display)}`,
|
|
1391
|
+
"aria-disabled": context.disabled || void 0,
|
|
1392
|
+
"aria-readonly": context.readOnly || void 0,
|
|
1393
|
+
dir: "ltr",
|
|
1394
|
+
"data-slot": "color-picker-area",
|
|
1395
|
+
"data-dragging": dragging ? "" : void 0,
|
|
1396
|
+
className: cn(CONTROL_CLASS, EDGE_CLASS, AREA_CLASS, className),
|
|
1397
|
+
style: {
|
|
1398
|
+
backgroundColor: `hsl(${hue} 100% 50%)`,
|
|
1399
|
+
...style
|
|
1400
|
+
},
|
|
1401
|
+
onKeyDown: (event) => {
|
|
1402
|
+
onKeyDown?.(event);
|
|
1403
|
+
if (event.defaultPrevented || copyOnShortcut(event, context)) return;
|
|
1404
|
+
if (!context.editable) return;
|
|
1405
|
+
const delta = keyDelta(event, 1);
|
|
1406
|
+
if (delta === null) return;
|
|
1407
|
+
event.preventDefault();
|
|
1408
|
+
const vertical = event.key === "ArrowUp" || event.key === "ArrowDown" || event.key.startsWith("Page");
|
|
1409
|
+
context.startInteraction();
|
|
1410
|
+
if (vertical) set(saturation, Math.round(brightness) + delta);
|
|
1411
|
+
else set(Math.round(saturation) + delta, brightness);
|
|
1412
|
+
context.endInteraction();
|
|
1413
|
+
},
|
|
1414
|
+
...handlers,
|
|
1415
|
+
...props,
|
|
1416
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1417
|
+
"data-slot": "color-picker-area-thumb",
|
|
1418
|
+
className: THUMB_CLASS,
|
|
1419
|
+
style: {
|
|
1420
|
+
left: `${saturation}%`,
|
|
1421
|
+
top: `${100 - brightness}%`
|
|
1422
|
+
}
|
|
1423
|
+
})
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
const SLIDER_CLASS = "forced-color-adjust-none data-[orientation=horizontal]:h-3 data-[orientation=horizontal]:min-h-3 data-[orientation=horizontal]:w-full data-[orientation=horizontal]:min-w-0 data-[orientation=horizontal]:touch-pan-y data-[orientation=vertical]:h-40 data-[orientation=vertical]:shrink-0 data-[orientation=vertical]:w-3 data-[orientation=vertical]:touch-pan-x rounded-full";
|
|
1427
|
+
/** One channel as a gradient track. Vertical tracks run bottom to top. */
|
|
1428
|
+
function ColorPickerSlider({ channel, colorSpace, orientation = "horizontal", className, style, onKeyDown, ...props }) {
|
|
1429
|
+
const context = useColorPickerContext("ColorPickerSlider");
|
|
1430
|
+
const space = resolveSpace(channel, colorSpace);
|
|
1431
|
+
const { max, step } = channelRange(space, channel);
|
|
1432
|
+
const precision = channel === "chroma" ? .001 : step;
|
|
1433
|
+
const value = readChannel(context.display, space, channel);
|
|
1434
|
+
const vertical = orientation === "vertical";
|
|
1435
|
+
const set = (next) => {
|
|
1436
|
+
context.emit(withChannel(context.getColor(), space, channel, clamp(snap(next, precision), 0, max)));
|
|
1437
|
+
};
|
|
1438
|
+
const { dragging, handlers } = useDrag(context, (event, element) => {
|
|
1439
|
+
const thumb = element.lastElementChild;
|
|
1440
|
+
const { x, y } = pointerRatio(event, element, (vertical ? thumb?.offsetHeight : thumb?.offsetWidth) ?? 0);
|
|
1441
|
+
set((vertical ? 1 - y : x) * max);
|
|
1442
|
+
});
|
|
1443
|
+
const colors = trackStops(context.display, space, channel);
|
|
1444
|
+
const stops = colors.map((color, index) => `${color} ${travel(index / (colors.length - 1))}`);
|
|
1445
|
+
const gradient = `linear-gradient(${vertical ? "to top" : "to right"}, ${stops.join(", ")})`;
|
|
1446
|
+
const fraction = clamp(value, 0, max) / max;
|
|
1447
|
+
const scale = channel === "alpha" ? 100 : 1;
|
|
1448
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1449
|
+
role: "slider",
|
|
1450
|
+
tabIndex: context.disabled ? -1 : 0,
|
|
1451
|
+
"aria-label": context.i18n.labels[channel],
|
|
1452
|
+
"aria-orientation": orientation,
|
|
1453
|
+
"aria-valuemin": 0,
|
|
1454
|
+
"aria-valuemax": max * scale,
|
|
1455
|
+
"aria-valuenow": Number((value * scale).toFixed(3)),
|
|
1456
|
+
"aria-valuetext": channelValueText(context.display, space, channel, context.i18n),
|
|
1457
|
+
"aria-disabled": context.disabled || void 0,
|
|
1458
|
+
"aria-readonly": context.readOnly || void 0,
|
|
1459
|
+
dir: "ltr",
|
|
1460
|
+
"data-slot": "color-picker-slider",
|
|
1461
|
+
"data-channel": channel,
|
|
1462
|
+
"data-orientation": orientation,
|
|
1463
|
+
"data-dragging": dragging ? "" : void 0,
|
|
1464
|
+
className: cn(CONTROL_CLASS, EDGE_CLASS, SLIDER_CLASS, className),
|
|
1465
|
+
style: {
|
|
1466
|
+
background: channel === "alpha" ? `${gradient}, ${CHECKER}` : gradient,
|
|
1467
|
+
...style
|
|
1468
|
+
},
|
|
1469
|
+
onKeyDown: (event) => {
|
|
1470
|
+
onKeyDown?.(event);
|
|
1471
|
+
if (event.defaultPrevented || copyOnShortcut(event, context)) return;
|
|
1472
|
+
if (!context.editable) return;
|
|
1473
|
+
const delta = keyDelta(event, step);
|
|
1474
|
+
if (delta === null) return;
|
|
1475
|
+
event.preventDefault();
|
|
1476
|
+
context.startInteraction();
|
|
1477
|
+
set(snap(value, step) + delta);
|
|
1478
|
+
context.endInteraction();
|
|
1479
|
+
},
|
|
1480
|
+
...handlers,
|
|
1481
|
+
...props,
|
|
1482
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1483
|
+
"data-slot": "color-picker-slider-thumb",
|
|
1484
|
+
className: THUMB_CLASS,
|
|
1485
|
+
style: vertical ? {
|
|
1486
|
+
left: "50%",
|
|
1487
|
+
top: travel(1 - fraction)
|
|
1488
|
+
} : {
|
|
1489
|
+
left: travel(fraction),
|
|
1490
|
+
top: "50%"
|
|
1491
|
+
}
|
|
1492
|
+
})
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
const WHEEL_RING_CLASS = "forced-color-adjust-none pointer-events-none absolute inset-0 rounded-full bg-[conic-gradient(#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)] mask-[radial-gradient(farthest-side,transparent_calc(100%-var(--color-picker-wheel-thickness)),#000_calc(100%-var(--color-picker-wheel-thickness)+1px))]";
|
|
1496
|
+
/**
|
|
1497
|
+
* A hue ring. Children fill the square inscribed in its hole: an area there
|
|
1498
|
+
* gives the classic ring-and-square picker. `--color-picker-wheel-thickness`
|
|
1499
|
+
* sets the ring's width.
|
|
1500
|
+
*/
|
|
1501
|
+
function ColorPickerWheel({ className, children, onKeyDown, ...props }) {
|
|
1502
|
+
const context = useColorPickerContext("ColorPickerWheel");
|
|
1503
|
+
const [hue] = toSpace(context.display, "hsv");
|
|
1504
|
+
const set = (next) => {
|
|
1505
|
+
context.emit(withChannel(context.getColor(), "hsv", "hue", wrapHue(Math.round(next))));
|
|
1506
|
+
};
|
|
1507
|
+
const { dragging, handlers } = useDrag(context, (event, element) => {
|
|
1508
|
+
const rect = element.getBoundingClientRect();
|
|
1509
|
+
const x = event.clientX - rect.left - rect.width / 2;
|
|
1510
|
+
const y = event.clientY - rect.top - rect.height / 2;
|
|
1511
|
+
set(Math.atan2(x, -y) * 180 / Math.PI);
|
|
1512
|
+
});
|
|
1513
|
+
const onPointerDown = (event) => {
|
|
1514
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1515
|
+
const thumb = event.currentTarget.querySelector("[data-slot=color-picker-wheel-thumb]")?.getBoundingClientRect();
|
|
1516
|
+
if (thumb) {
|
|
1517
|
+
const centerX = rect.left + rect.width / 2;
|
|
1518
|
+
const centerY = rect.top + rect.height / 2;
|
|
1519
|
+
const inner = 2 * Math.hypot(thumb.left + thumb.width / 2 - centerX, thumb.top + thumb.height / 2 - centerY) - rect.width / 2;
|
|
1520
|
+
if (Math.hypot(event.clientX - centerX, event.clientY - centerY) < inner - 2) return;
|
|
1521
|
+
}
|
|
1522
|
+
handlers.onPointerDown(event);
|
|
1523
|
+
};
|
|
1524
|
+
const angle = hue * Math.PI / 180;
|
|
1525
|
+
const radius = "(50% - var(--color-picker-wheel-thickness) / 2)";
|
|
1526
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1527
|
+
"data-slot": "color-picker-wheel",
|
|
1528
|
+
className: cn("relative size-48 shrink-0 [--color-picker-wheel-thickness:calc(var(--spacing)*5)]", className),
|
|
1529
|
+
...props,
|
|
1530
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1531
|
+
role: "slider",
|
|
1532
|
+
tabIndex: context.disabled ? -1 : 0,
|
|
1533
|
+
"aria-label": context.i18n.labels.hue,
|
|
1534
|
+
"aria-valuemin": 0,
|
|
1535
|
+
"aria-valuemax": 360,
|
|
1536
|
+
"aria-valuenow": Math.round(hue),
|
|
1537
|
+
"aria-valuetext": channelValueText(context.display, "hsv", "hue", context.i18n),
|
|
1538
|
+
"aria-disabled": context.disabled || void 0,
|
|
1539
|
+
"aria-readonly": context.readOnly || void 0,
|
|
1540
|
+
"data-slot": "color-picker-wheel-track",
|
|
1541
|
+
"data-dragging": dragging ? "" : void 0,
|
|
1542
|
+
className: cn(CONTROL_CLASS, "absolute inset-0 touch-none rounded-full"),
|
|
1543
|
+
onKeyDown: (event) => {
|
|
1544
|
+
onKeyDown?.(event);
|
|
1545
|
+
if (event.defaultPrevented || copyOnShortcut(event, context)) return;
|
|
1546
|
+
if (!context.editable) return;
|
|
1547
|
+
const delta = keyDelta(event, 1);
|
|
1548
|
+
if (delta === null) return;
|
|
1549
|
+
event.preventDefault();
|
|
1550
|
+
context.startInteraction();
|
|
1551
|
+
set(Number.isFinite(delta) ? Math.round(hue) + delta : delta > 0 ? 359 : 0);
|
|
1552
|
+
context.endInteraction();
|
|
1553
|
+
},
|
|
1554
|
+
...handlers,
|
|
1555
|
+
onPointerDown,
|
|
1556
|
+
children: [/* @__PURE__ */ jsx("div", { className: WHEEL_RING_CLASS }), /* @__PURE__ */ jsx("div", {
|
|
1557
|
+
"data-slot": "color-picker-wheel-thumb",
|
|
1558
|
+
className: THUMB_CLASS,
|
|
1559
|
+
style: {
|
|
1560
|
+
left: `calc(50% + ${radius} * ${Math.sin(angle)})`,
|
|
1561
|
+
top: `calc(50% - ${radius} * ${Math.cos(angle)})`
|
|
1562
|
+
}
|
|
1563
|
+
})]
|
|
1564
|
+
}), children !== void 0 && /* @__PURE__ */ jsx("div", {
|
|
1565
|
+
className: "absolute inset-[calc(50%-(50%-var(--color-picker-wheel-thickness))*0.7071+var(--spacing)*1.5)] flex items-center justify-center",
|
|
1566
|
+
children
|
|
1567
|
+
})]
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
const getEyeDropper = () => window.EyeDropper;
|
|
1571
|
+
const noSubscribe = () => () => {};
|
|
1572
|
+
/**
|
|
1573
|
+
* Samples a color from anywhere on screen, keeping the current opacity.
|
|
1574
|
+
* Renders nothing where the browser has no EyeDropper (Firefox, Safari).
|
|
1575
|
+
*/
|
|
1576
|
+
function ColorPickerEyeDropper({ variant = "ghost", size = "icon-sm", onClick, children, ...props }) {
|
|
1577
|
+
const context = useColorPickerContext("ColorPickerEyeDropper");
|
|
1578
|
+
if (!useSyncExternalStore(noSubscribe, () => !!getEyeDropper(), () => false)) return null;
|
|
1579
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
1580
|
+
type: "button",
|
|
1581
|
+
variant,
|
|
1582
|
+
size,
|
|
1583
|
+
disabled: !context.editable,
|
|
1584
|
+
"aria-label": context.i18n.labels.eyeDropper,
|
|
1585
|
+
"data-slot": "color-picker-eye-dropper",
|
|
1586
|
+
onClick: async (event) => {
|
|
1587
|
+
onClick?.(event);
|
|
1588
|
+
const EyeDropper = getEyeDropper();
|
|
1589
|
+
if (event.defaultPrevented || !EyeDropper) return;
|
|
1590
|
+
try {
|
|
1591
|
+
const { sRGBHex } = await new EyeDropper().open();
|
|
1592
|
+
const picked = parseColor(sRGBHex);
|
|
1593
|
+
if (picked) context.change({
|
|
1594
|
+
...picked,
|
|
1595
|
+
alpha: context.getColor().alpha
|
|
1596
|
+
});
|
|
1597
|
+
} catch {}
|
|
1598
|
+
},
|
|
1599
|
+
...props,
|
|
1600
|
+
children: children === void 0 ? /* @__PURE__ */ jsx(PipetteIcon, { "aria-hidden": "true" }) : children
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Copies the value and confirms for a moment, in `format` or, by default, the
|
|
1605
|
+
* format on screen: what the fields show, else the picker's.
|
|
1606
|
+
*/
|
|
1607
|
+
function ColorPickerCopy({ format, variant = "ghost", size = "icon-sm", onClick, children, ...props }) {
|
|
1608
|
+
const context = useColorPickerContext("ColorPickerCopy");
|
|
1609
|
+
const target = format ?? context.shownFormat;
|
|
1610
|
+
const copied = context.copied === target;
|
|
1611
|
+
const { labels } = context.i18n;
|
|
1612
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
1613
|
+
type: "button",
|
|
1614
|
+
variant,
|
|
1615
|
+
size,
|
|
1616
|
+
disabled: context.disabled || !context.color,
|
|
1617
|
+
"aria-label": copied ? labels.copied : labels.copy,
|
|
1618
|
+
"aria-keyshortcuts": "Control+C Meta+C",
|
|
1619
|
+
"data-slot": "color-picker-copy",
|
|
1620
|
+
"data-copied": copied ? "" : void 0,
|
|
1621
|
+
onClick: (event) => {
|
|
1622
|
+
onClick?.(event);
|
|
1623
|
+
if (!event.defaultPrevented) context.copy(target);
|
|
1624
|
+
},
|
|
1625
|
+
...props,
|
|
1626
|
+
children: children === void 0 ? copied ? /* @__PURE__ */ jsx(CheckIcon, { "aria-hidden": "true" }) : /* @__PURE__ */ jsx(CopyIcon, { "aria-hidden": "true" }) : children
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Empties the value, for an optional color. It stays enabled while empty:
|
|
1631
|
+
* disabling itself on click would drop keyboard focus to the page.
|
|
1632
|
+
*/
|
|
1633
|
+
function ColorPickerClear({ variant = "ghost", size = "sm", onClick, children, ...props }) {
|
|
1634
|
+
const context = useColorPickerContext("ColorPickerClear");
|
|
1635
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
1636
|
+
type: "button",
|
|
1637
|
+
variant,
|
|
1638
|
+
size,
|
|
1639
|
+
disabled: !context.editable,
|
|
1640
|
+
"data-slot": "color-picker-clear",
|
|
1641
|
+
onClick: (event) => {
|
|
1642
|
+
onClick?.(event);
|
|
1643
|
+
if (!event.defaultPrevented) context.change(null);
|
|
1644
|
+
},
|
|
1645
|
+
...props,
|
|
1646
|
+
children: children === void 0 ? context.i18n.labels.clear : children
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
const FORMAT_FIELDS = {
|
|
1650
|
+
hex: {
|
|
1651
|
+
space: "rgb",
|
|
1652
|
+
channels: ["hex"]
|
|
1653
|
+
},
|
|
1654
|
+
rgb: {
|
|
1655
|
+
space: "rgb",
|
|
1656
|
+
channels: [
|
|
1657
|
+
"red",
|
|
1658
|
+
"green",
|
|
1659
|
+
"blue"
|
|
1660
|
+
]
|
|
1661
|
+
},
|
|
1662
|
+
hsl: {
|
|
1663
|
+
space: "hsl",
|
|
1664
|
+
channels: [
|
|
1665
|
+
"hue",
|
|
1666
|
+
"saturation",
|
|
1667
|
+
"lightness"
|
|
1668
|
+
]
|
|
1669
|
+
},
|
|
1670
|
+
hsb: {
|
|
1671
|
+
space: "hsv",
|
|
1672
|
+
channels: [
|
|
1673
|
+
"hue",
|
|
1674
|
+
"saturation",
|
|
1675
|
+
"brightness"
|
|
1676
|
+
]
|
|
1677
|
+
},
|
|
1678
|
+
oklch: {
|
|
1679
|
+
space: "oklch",
|
|
1680
|
+
channels: [
|
|
1681
|
+
"lightness",
|
|
1682
|
+
"chroma",
|
|
1683
|
+
"hue"
|
|
1684
|
+
]
|
|
1685
|
+
}
|
|
1686
|
+
};
|
|
1687
|
+
function channelText(color, space, channel) {
|
|
1688
|
+
if (channel === "hex") return formatColor({
|
|
1689
|
+
...color,
|
|
1690
|
+
alpha: 1
|
|
1691
|
+
}, "hex").slice(1).toUpperCase();
|
|
1692
|
+
if (channel === "alpha") return `${Math.round(color.alpha * 100)}%`;
|
|
1693
|
+
const value = readChannel(color, space, channel);
|
|
1694
|
+
if (channel === "chroma") return fixed(value, 3);
|
|
1695
|
+
return space === "oklch" ? fixed(value, 1) : String(Math.round(value));
|
|
1696
|
+
}
|
|
1697
|
+
const FIELD_NUMBER = /^([+-]?(?:\d+(?:[.,]\d*)?|[.,]\d+))\s*(%|°|deg|grad|rad|turn)?$/;
|
|
1698
|
+
function readChannelText(text, color, space, channel) {
|
|
1699
|
+
if (channel === "hex") {
|
|
1700
|
+
const digits = text.trim().replace(/^#/, "");
|
|
1701
|
+
const parsed = /^[\da-f]+$/i.test(digits) ? parseColor(digits) : null;
|
|
1702
|
+
if (!parsed) return null;
|
|
1703
|
+
return digits.length === 4 || digits.length === 8 ? parsed : {
|
|
1704
|
+
...parsed,
|
|
1705
|
+
alpha: color.alpha
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
const match = FIELD_NUMBER.exec(text.trim().toLowerCase());
|
|
1709
|
+
if (!match) return null;
|
|
1710
|
+
const value = Number(match[1].replace(",", "."));
|
|
1711
|
+
const unit = match[2];
|
|
1712
|
+
if (!Number.isFinite(value)) return null;
|
|
1713
|
+
if (channel === "hue") {
|
|
1714
|
+
if (unit === "%") return null;
|
|
1715
|
+
const degrees = unit === "rad" ? value * 180 / Math.PI : unit === "grad" ? value * .9 : unit === "turn" ? value * 360 : value;
|
|
1716
|
+
return withChannel(color, space, channel, wrapHue(degrees));
|
|
1717
|
+
}
|
|
1718
|
+
if (unit && unit !== "%") return null;
|
|
1719
|
+
if (channel === "alpha") return {
|
|
1720
|
+
...color,
|
|
1721
|
+
alpha: clamp(value / 100, 0, 1)
|
|
1722
|
+
};
|
|
1723
|
+
const { max } = channelRange(space, channel);
|
|
1724
|
+
const scaled = unit === "%" ? value * max / 100 : value;
|
|
1725
|
+
return withChannel(color, space, channel, clamp(scaled, 0, max));
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* One channel as a borderless field for an `InputGroup`. Text is read on blur
|
|
1729
|
+
* and Enter; ArrowUp and ArrowDown step it, Shift by ten.
|
|
1730
|
+
*/
|
|
1731
|
+
function ColorPickerChannelInput({ channel, colorSpace, className, onBlur, onKeyDown, onChange, ref, ...props }) {
|
|
1732
|
+
const context = useColorPickerContext("ColorPickerChannelInput");
|
|
1733
|
+
const space = channel === "hex" ? "rgb" : resolveSpace(channel, colorSpace);
|
|
1734
|
+
const [text, setText] = useState(null);
|
|
1735
|
+
const current = channelText(context.display, space, channel);
|
|
1736
|
+
const shown = text ?? current;
|
|
1737
|
+
const fieldRef = useRef(null);
|
|
1738
|
+
useEscapeRevert(fieldRef, text !== null, () => setText(null));
|
|
1739
|
+
const { max } = channelRange(space, channel === "hex" ? "red" : channel);
|
|
1740
|
+
const spin = channel === "hex" ? {} : {
|
|
1741
|
+
role: "spinbutton",
|
|
1742
|
+
"aria-valuemin": 0,
|
|
1743
|
+
"aria-valuemax": channel === "alpha" ? 100 : max,
|
|
1744
|
+
"aria-valuenow": channel === "alpha" ? Math.round(context.display.alpha * 100) : Number(channelText(context.display, space, channel)),
|
|
1745
|
+
"aria-valuetext": shown
|
|
1746
|
+
};
|
|
1747
|
+
const read = () => {
|
|
1748
|
+
if (text === null) return;
|
|
1749
|
+
setText(null);
|
|
1750
|
+
if (text === current) return;
|
|
1751
|
+
const next = readChannelText(text, context.display, space, channel);
|
|
1752
|
+
if (next) context.change(next);
|
|
1753
|
+
};
|
|
1754
|
+
return /* @__PURE__ */ jsx(InputGroupInput, {
|
|
1755
|
+
value: shown,
|
|
1756
|
+
inputMode: channel === "hex" ? "text" : "decimal",
|
|
1757
|
+
maxLength: channel === "hex" ? 9 : 8,
|
|
1758
|
+
disabled: context.disabled,
|
|
1759
|
+
readOnly: context.readOnly,
|
|
1760
|
+
autoComplete: "off",
|
|
1761
|
+
autoCorrect: "off",
|
|
1762
|
+
autoCapitalize: "off",
|
|
1763
|
+
spellCheck: false,
|
|
1764
|
+
"aria-label": context.i18n.labels[channel],
|
|
1765
|
+
...spin,
|
|
1766
|
+
"data-channel": channel,
|
|
1767
|
+
className: cn("h-auto min-w-0 self-stretch pr-1 pl-2 tabular-nums", channel === "hex" ? "flex-[1_1_calc(5.8ch+0.75rem)] uppercase" : channel === "alpha" ? "flex-[1_1_calc(4.8ch+0.75rem)]" : space !== "oklch" ? "flex-[1_1_calc(3.25ch+0.75rem)]" : channel === "lightness" ? "flex-[1_1_calc(3.7ch+0.75rem)]" : "flex-[1_1_calc(4.7ch+0.75rem)]", className),
|
|
1768
|
+
onChange: (event) => {
|
|
1769
|
+
onChange?.(event);
|
|
1770
|
+
setText(event.target.value);
|
|
1771
|
+
},
|
|
1772
|
+
onBlur: (event) => {
|
|
1773
|
+
onBlur?.(event);
|
|
1774
|
+
read();
|
|
1775
|
+
},
|
|
1776
|
+
onKeyDown: (event) => {
|
|
1777
|
+
onKeyDown?.(event);
|
|
1778
|
+
if (event.defaultPrevented || copyOnShortcut(event, context)) return;
|
|
1779
|
+
const step = STEP_KEYS[event.key];
|
|
1780
|
+
if (event.key === "Enter") flushSync(() => read());
|
|
1781
|
+
else if (step && channel !== "hex" && context.editable) {
|
|
1782
|
+
event.preventDefault();
|
|
1783
|
+
const from = readChannelText(shown, context.display, space, channel);
|
|
1784
|
+
if (!from) return;
|
|
1785
|
+
const unit = channel === "alpha" ? .01 : channel === "chroma" ? .001 : 1;
|
|
1786
|
+
const delta = step * unit * (event.shiftKey ? 10 : 1);
|
|
1787
|
+
const { max: top } = channelRange(space, channel);
|
|
1788
|
+
const next = snap(readChannel(from, space, channel) + delta, unit);
|
|
1789
|
+
setText(null);
|
|
1790
|
+
context.change(withChannel(from, space, channel, channel === "hue" ? wrapHue(next) : clamp(next, 0, top)));
|
|
1791
|
+
}
|
|
1792
|
+
},
|
|
1793
|
+
...props,
|
|
1794
|
+
ref: (node) => {
|
|
1795
|
+
fieldRef.current = node;
|
|
1796
|
+
assignRef(ref, node);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
const STEP_KEYS = {
|
|
1801
|
+
ArrowUp: 1,
|
|
1802
|
+
ArrowDown: -1,
|
|
1803
|
+
PageUp: 10,
|
|
1804
|
+
PageDown: -10
|
|
1805
|
+
};
|
|
1806
|
+
const DIVIDER = /* @__PURE__ */ jsx(Separator, {
|
|
1807
|
+
orientation: "vertical",
|
|
1808
|
+
"aria-hidden": "true"
|
|
1809
|
+
});
|
|
1810
|
+
const FORMAT_ADDON_CLASS = "pr-[0.2rem]";
|
|
1811
|
+
/**
|
|
1812
|
+
* A format menu and the value's channels as joined fields: one hex field, or
|
|
1813
|
+
* three channels, plus opacity when the picker takes alpha.
|
|
1814
|
+
*/
|
|
1815
|
+
function ColorPickerFields({ format: formatProp, defaultFormat, onFormatChange, formats = COLOR_PICKER_FORMATS, className, ...props }) {
|
|
1816
|
+
const context = useColorPickerContext("ColorPickerFields");
|
|
1817
|
+
const [formatState, setFormatState] = useState(defaultFormat ?? context.format);
|
|
1818
|
+
const shown = formatProp ?? formatState;
|
|
1819
|
+
const fields = FORMAT_FIELDS[shown];
|
|
1820
|
+
const { setFieldsFormat } = context;
|
|
1821
|
+
useLayoutEffect(() => {
|
|
1822
|
+
setFieldsFormat(shown);
|
|
1823
|
+
return () => setFieldsFormat(null);
|
|
1824
|
+
}, [shown, setFieldsFormat]);
|
|
1825
|
+
const menu = formats.length > 1;
|
|
1826
|
+
const setFormat = (next) => {
|
|
1827
|
+
if (formatProp === void 0) setFormatState(next);
|
|
1828
|
+
onFormatChange?.(next);
|
|
1829
|
+
};
|
|
1830
|
+
const menuProps = {
|
|
1831
|
+
size: "xs",
|
|
1832
|
+
disabled: context.disabled,
|
|
1833
|
+
"aria-label": `${context.i18n.labels.format}, ${FORMAT_LABELS[shown]}`,
|
|
1834
|
+
"data-slot": "color-picker-format-trigger",
|
|
1835
|
+
className: "gap-1 text-xs font-medium"
|
|
1836
|
+
};
|
|
1837
|
+
return /* @__PURE__ */ jsxs(InputGroup, {
|
|
1838
|
+
dir: "ltr",
|
|
1839
|
+
"data-slot": "color-picker-fields",
|
|
1840
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
1841
|
+
className,
|
|
1842
|
+
...props,
|
|
1843
|
+
children: [menu && /* @__PURE__ */ jsx(InputGroupAddon, {
|
|
1844
|
+
align: "inline-start",
|
|
1845
|
+
className: FORMAT_ADDON_CLASS,
|
|
1846
|
+
children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsxs(DropdownMenuTrigger, {
|
|
1847
|
+
render: /* @__PURE__ */ jsx(InputGroupButton, { ...menuProps }),
|
|
1848
|
+
children: [FORMAT_LABELS[shown], CHEVRON_ICON]
|
|
1849
|
+
}), /* @__PURE__ */ jsx(DropdownMenuContent, {
|
|
1850
|
+
align: "start",
|
|
1851
|
+
className: "w-auto min-w-56",
|
|
1852
|
+
onClick: (event) => event.stopPropagation(),
|
|
1853
|
+
children: /* @__PURE__ */ jsx(DropdownMenuRadioGroup, {
|
|
1854
|
+
value: shown,
|
|
1855
|
+
onValueChange: (next) => setFormat(next),
|
|
1856
|
+
children: formats.map((item) => /* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
|
|
1857
|
+
value: item,
|
|
1858
|
+
closeOnClick: true,
|
|
1859
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1860
|
+
className: "w-12 shrink-0 font-medium",
|
|
1861
|
+
children: FORMAT_LABELS[item]
|
|
1862
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1863
|
+
className: "truncate text-muted-foreground text-xs tabular-nums",
|
|
1864
|
+
children: formatColor(context.display, item).replace(/^\w+\(|\)$/g, "")
|
|
1865
|
+
})]
|
|
1866
|
+
}, item))
|
|
1867
|
+
})
|
|
1868
|
+
})] })
|
|
1869
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1870
|
+
className: "flex min-w-0 flex-1 self-stretch",
|
|
1871
|
+
children: [fields.channels.map((channel, index) => /* @__PURE__ */ jsxs(Fragment, { children: [(menu || index > 0) && DIVIDER, /* @__PURE__ */ jsx(ColorPickerChannelInput, {
|
|
1872
|
+
channel,
|
|
1873
|
+
colorSpace: fields.space
|
|
1874
|
+
})] }, `${shown}-${channel}`)), context.alpha && /* @__PURE__ */ jsxs(Fragment$1, { children: [DIVIDER, /* @__PURE__ */ jsx(ColorPickerChannelInput, {
|
|
1875
|
+
channel: "alpha",
|
|
1876
|
+
className: "w-[calc(4.8ch+0.75rem)] flex-none"
|
|
1877
|
+
})] })]
|
|
1878
|
+
})]
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
const SwatchesContext = createContext({
|
|
1882
|
+
shape: "square",
|
|
1883
|
+
activeId: null,
|
|
1884
|
+
setActiveId: () => {}
|
|
1885
|
+
});
|
|
1886
|
+
const OPTION_SELECTOR = "[data-slot=\"color-picker-swatch-item\"]:not([aria-disabled=\"true\"])";
|
|
1887
|
+
function neighbor(options, current, key, rtl) {
|
|
1888
|
+
if (key === "Home") return options[0];
|
|
1889
|
+
if (key === "End") return options[options.length - 1];
|
|
1890
|
+
if (!current) return options[0];
|
|
1891
|
+
const forward = key === "ArrowDown" || key === (rtl ? "ArrowLeft" : "ArrowRight");
|
|
1892
|
+
return options[options.indexOf(current) + (forward ? 1 : -1)];
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Preset colors as a listbox: one tab stop, arrow keys move through them in
|
|
1896
|
+
* order, Enter or Space picks. `--color-picker-swatch-size` sets the chip size.
|
|
1897
|
+
*/
|
|
1898
|
+
function ColorPickerSwatches({ colors, shape = "square", className, children, onKeyDown, onFocus, ...props }) {
|
|
1899
|
+
const context = useColorPickerContext("ColorPickerSwatches");
|
|
1900
|
+
const [activeId, setActiveId] = useState(null);
|
|
1901
|
+
const listRef = useRef(null);
|
|
1902
|
+
const options = () => Array.from(listRef.current?.querySelectorAll(OPTION_SELECTOR) ?? []);
|
|
1903
|
+
const activate = (option) => {
|
|
1904
|
+
if (!option) return;
|
|
1905
|
+
setActiveId(option.id);
|
|
1906
|
+
option.scrollIntoView?.({ block: "nearest" });
|
|
1907
|
+
};
|
|
1908
|
+
return /* @__PURE__ */ jsx(SwatchesContext.Provider, {
|
|
1909
|
+
value: {
|
|
1910
|
+
shape,
|
|
1911
|
+
activeId,
|
|
1912
|
+
setActiveId
|
|
1913
|
+
},
|
|
1914
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1915
|
+
ref: listRef,
|
|
1916
|
+
role: "listbox",
|
|
1917
|
+
tabIndex: context.disabled ? -1 : 0,
|
|
1918
|
+
"aria-label": context.i18n.labels.swatches,
|
|
1919
|
+
"aria-activedescendant": activeId ?? void 0,
|
|
1920
|
+
"aria-disabled": context.disabled || void 0,
|
|
1921
|
+
"aria-readonly": context.readOnly || void 0,
|
|
1922
|
+
"data-slot": "color-picker-swatches",
|
|
1923
|
+
"data-empty": activeId ? void 0 : "",
|
|
1924
|
+
className: cn("group/color-picker-swatches grid grid-cols-[repeat(auto-fill,var(--color-picker-swatch-size))] justify-between gap-x-1 gap-y-1.5 outline-none [--color-picker-swatch-size:calc(var(--spacing)*6)] aria-disabled:opacity-50 data-empty:focus-visible:outline-2 data-empty:focus-visible:outline-ring data-empty:focus-visible:outline-offset-2", className),
|
|
1925
|
+
onFocus: (event) => {
|
|
1926
|
+
onFocus?.(event);
|
|
1927
|
+
if (event.target !== event.currentTarget) return;
|
|
1928
|
+
if (!(activeId ? event.currentTarget.ownerDocument.getElementById(activeId) : null)) {
|
|
1929
|
+
const selected = event.currentTarget.querySelector(`${OPTION_SELECTOR}[aria-selected="true"]`);
|
|
1930
|
+
setActiveId(selected?.id ?? null);
|
|
1931
|
+
}
|
|
1932
|
+
},
|
|
1933
|
+
onKeyDown: (event) => {
|
|
1934
|
+
onKeyDown?.(event);
|
|
1935
|
+
if (event.defaultPrevented || copyOnShortcut(event, context)) return;
|
|
1936
|
+
if (context.disabled) return;
|
|
1937
|
+
const list = options();
|
|
1938
|
+
const current = list.find((option) => option.id === activeId);
|
|
1939
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1940
|
+
event.preventDefault();
|
|
1941
|
+
current?.click();
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
if (![
|
|
1945
|
+
"ArrowLeft",
|
|
1946
|
+
"ArrowRight",
|
|
1947
|
+
"ArrowUp",
|
|
1948
|
+
"ArrowDown",
|
|
1949
|
+
"Home",
|
|
1950
|
+
"End"
|
|
1951
|
+
].includes(event.key)) return;
|
|
1952
|
+
event.preventDefault();
|
|
1953
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
1954
|
+
activate(neighbor(list, current, event.key, rtl) ?? current);
|
|
1955
|
+
},
|
|
1956
|
+
...props,
|
|
1957
|
+
children: children ?? colors?.map((item, index) => {
|
|
1958
|
+
const swatch = typeof item === "string" ? { value: item } : item;
|
|
1959
|
+
return /* @__PURE__ */ jsx(ColorPickerSwatchItem, {
|
|
1960
|
+
value: swatch.value,
|
|
1961
|
+
label: swatch.label
|
|
1962
|
+
}, `${index}-${swatch.value}`);
|
|
1963
|
+
})
|
|
1964
|
+
})
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
const SWATCH_ITEM_SQUARE = "rounded-md";
|
|
1968
|
+
const SWATCH_ITEM_CLASS = "forced-color-adjust-none relative flex size-(--color-picker-swatch-size) shrink-0 cursor-default items-center justify-center outline-offset-2 transition-[scale] duration-150 after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:inset-ring after:inset-ring-foreground/10 not-aria-disabled:hover:scale-110 aria-disabled:opacity-40 motion-reduce:transition-none group-focus-visible/color-picker-swatches:data-active:outline-2 group-focus-visible/color-picker-swatches:data-active:outline-ring [&_svg]:size-3.5";
|
|
1969
|
+
/** One preset. Selected while the picker's value is this color. */
|
|
1970
|
+
function ColorPickerSwatchItem({ value, label, disabled = false, className, style, onClick, ...props }) {
|
|
1971
|
+
const context = useColorPickerContext("ColorPickerSwatchItem");
|
|
1972
|
+
const swatches = useContext(SwatchesContext);
|
|
1973
|
+
const id = useId();
|
|
1974
|
+
const parsed = parseColor(value);
|
|
1975
|
+
const color = parsed && !context.alpha ? {
|
|
1976
|
+
...parsed,
|
|
1977
|
+
alpha: 1
|
|
1978
|
+
} : parsed;
|
|
1979
|
+
const selected = !!color && !!context.color && formatColor(color, "hex") === formatColor(context.color, "hex");
|
|
1980
|
+
const check = (color && getForegroundColor(color, {
|
|
1981
|
+
light: "#fff",
|
|
1982
|
+
dark: "#000"
|
|
1983
|
+
})) ?? "#000";
|
|
1984
|
+
const inactive = disabled || !color;
|
|
1985
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1986
|
+
id,
|
|
1987
|
+
role: "option",
|
|
1988
|
+
"aria-selected": selected,
|
|
1989
|
+
"aria-disabled": inactive || void 0,
|
|
1990
|
+
"aria-label": label ?? (color ? context.i18n.functions.getColorName(color) : value),
|
|
1991
|
+
"data-slot": "color-picker-swatch-item",
|
|
1992
|
+
"data-active": swatches.activeId === id ? "" : void 0,
|
|
1993
|
+
"data-selected": selected ? "" : void 0,
|
|
1994
|
+
className: cn(SWATCH_ITEM_CLASS, swatches.shape === "circle" ? "rounded-full" : SWATCH_ITEM_SQUARE, className),
|
|
1995
|
+
style: {
|
|
1996
|
+
background: swatchBackground(color),
|
|
1997
|
+
color: check,
|
|
1998
|
+
...style
|
|
1999
|
+
},
|
|
2000
|
+
onClick: (event) => {
|
|
2001
|
+
onClick?.(event);
|
|
2002
|
+
if (event.defaultPrevented || inactive || !context.editable) return;
|
|
2003
|
+
swatches.setActiveId(id);
|
|
2004
|
+
context.change(color);
|
|
2005
|
+
},
|
|
2006
|
+
...props,
|
|
2007
|
+
children: selected && /* @__PURE__ */ jsx(CheckIcon, { "aria-hidden": "true" })
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
//#endregion
|
|
2011
|
+
export { COLOR_PICKER_FORMATS, ColorPicker, ColorPickerArea, ColorPickerChannelInput, ColorPickerClear, ColorPickerContent, ColorPickerCopy, ColorPickerEyeDropper, ColorPickerFields, ColorPickerInput, ColorPickerPanel, ColorPickerSlider, ColorPickerSwatch, ColorPickerSwatchItem, ColorPickerSwatches, ColorPickerTrigger, ColorPickerValue, ColorPickerWheel, DEFAULT_COLOR_PICKER_I18N, formatColor, getContrastRatio, getForegroundColor, isColorInSrgb, mergeColorPickerI18n, parseColor, useColorPicker };
|
|
2012
|
+
|
|
2013
|
+
//# sourceMappingURL=color-picker.js.map
|