@mcp-b/web-components 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/accordion-B1Q3kuP_.d.ts +373 -0
- package/dist/accordion-item-DvPfhpm8.js +307 -0
- package/dist/accordion-item-bPRIahNn.d.ts +63 -0
- package/dist/accordion-zDr-Br4V.js +483 -0
- package/dist/action-bar-CYsjmhwP.d.ts +29 -0
- package/dist/action-bar-CjN_UcnP.js +56 -0
- package/dist/alert-dialog-4CnO3Nb5.d.ts +60 -0
- package/dist/alert-dialog-D25Oi_TS.js +126 -0
- package/dist/avatar-Bje_KpZo.d.ts +141 -0
- package/dist/avatar-CRP0kW3x.js +224 -0
- package/dist/badge-Ct95U4UO.js +301 -0
- package/dist/badge-D1DNQrWn.d.ts +106 -0
- package/dist/breadcrumb-BxZ-nQE5.d.ts +365 -0
- package/dist/breadcrumb-item-BC454oQe.d.ts +59 -0
- package/dist/breadcrumb-item-P5pdq_gE.js +151 -0
- package/dist/breadcrumb-uURhiqWJ.js +384 -0
- package/dist/button-5k_aL_gD.js +802 -0
- package/dist/button-BQofnUt4.d.ts +354 -0
- package/dist/button-group-BydvJTQy.js +197 -0
- package/dist/button-group-COodHeuB.d.ts +155 -0
- package/dist/callout-B8zTf8Go.js +188 -0
- package/dist/callout-DFwPao36.d.ts +103 -0
- package/dist/card-BYDzdMAU.d.ts +177 -0
- package/dist/card-DIg1-X2G.js +332 -0
- package/dist/carousel-Bktu7wrD.js +843 -0
- package/dist/carousel-DQITCtEY.d.ts +423 -0
- package/dist/carousel-item-B5-X31Ha.js +79 -0
- package/dist/carousel-item-BB3jL2tk.d.ts +34 -0
- package/dist/cdn/loader.js +530 -0
- package/dist/checkbox-D6r7PVPj.js +641 -0
- package/dist/checkbox-DoFcDEKB.d.ts +354 -0
- package/dist/checkbox-group-CLvNAO_F.js +201 -0
- package/dist/checkbox-group-Cnh8rAn4.d.ts +152 -0
- package/dist/color-input-Bky89xg_.d.ts +470 -0
- package/dist/color-input-DPIxi9wR.js +894 -0
- package/dist/color-picker-adwOmtRl.js +1240 -0
- package/dist/color-picker-wQw8bPsq.d.ts +360 -0
- package/dist/combobox-B6al50UG.js +1693 -0
- package/dist/combobox-item-D2H1CMxC.d.ts +714 -0
- package/dist/combobox-item-yM6tDrGG.js +225 -0
- package/dist/comparison-B1-nMwmp.d.ts +134 -0
- package/dist/comparison-CyqKrCN-.js +435 -0
- package/dist/components/accordion/accordion.d.ts +2 -0
- package/dist/components/accordion/accordion.js +2 -0
- package/dist/components/accordion-item/accordion-item.d.ts +2 -0
- package/dist/components/accordion-item/accordion-item.js +2 -0
- package/dist/components/action-bar/action-bar.d.ts +2 -0
- package/dist/components/action-bar/action-bar.js +2 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +2 -0
- package/dist/components/alert-dialog/alert-dialog.js +2 -0
- package/dist/components/avatar/avatar.d.ts +2 -0
- package/dist/components/avatar/avatar.js +2 -0
- package/dist/components/badge/badge.d.ts +2 -0
- package/dist/components/badge/badge.js +2 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +2 -0
- package/dist/components/breadcrumb/breadcrumb.js +2 -0
- package/dist/components/breadcrumb-item/breadcrumb-item.d.ts +2 -0
- package/dist/components/breadcrumb-item/breadcrumb-item.js +2 -0
- package/dist/components/button/button.d.ts +2 -0
- package/dist/components/button/button.js +2 -0
- package/dist/components/button-group/button-group.d.ts +2 -0
- package/dist/components/button-group/button-group.js +2 -0
- package/dist/components/callout/callout.d.ts +2 -0
- package/dist/components/callout/callout.js +2 -0
- package/dist/components/card/card.d.ts +2 -0
- package/dist/components/card/card.js +2 -0
- package/dist/components/carousel/carousel.d.ts +2 -0
- package/dist/components/carousel/carousel.js +2 -0
- package/dist/components/carousel-item/carousel-item.d.ts +2 -0
- package/dist/components/carousel-item/carousel-item.js +2 -0
- package/dist/components/checkbox/checkbox.d.ts +2 -0
- package/dist/components/checkbox/checkbox.js +2 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts +2 -0
- package/dist/components/checkbox-group/checkbox-group.js +2 -0
- package/dist/components/color-input/color-input.d.ts +2 -0
- package/dist/components/color-input/color-input.js +2 -0
- package/dist/components/color-picker/color-picker.d.ts +2 -0
- package/dist/components/color-picker/color-picker.js +2 -0
- package/dist/components/combobox/combobox.d.ts +2 -0
- package/dist/components/combobox/combobox.js +2 -0
- package/dist/components/combobox-item/combobox-item.d.ts +2 -0
- package/dist/components/combobox-item/combobox-item.js +2 -0
- package/dist/components/comparison/comparison.d.ts +2 -0
- package/dist/components/comparison/comparison.js +2 -0
- package/dist/components/copy/copy.d.ts +2 -0
- package/dist/components/copy/copy.js +291 -0
- package/dist/components/data-table/data-table.d.ts +2 -0
- package/dist/components/data-table/data-table.js +2 -0
- package/dist/components/date/date.d.ts +2 -0
- package/dist/components/date/date.js +2 -0
- package/dist/components/dialog/dialog.d.ts +2 -0
- package/dist/components/dialog/dialog.js +2 -0
- package/dist/components/divider/divider.d.ts +2 -0
- package/dist/components/divider/divider.js +2 -0
- package/dist/components/dropdown/dropdown.d.ts +2 -0
- package/dist/components/dropdown/dropdown.js +2 -0
- package/dist/components/dropdown-item/dropdown-item.d.ts +2 -0
- package/dist/components/dropdown-item/dropdown-item.js +2 -0
- package/dist/components/empty-result/empty-result.d.ts +2 -0
- package/dist/components/empty-result/empty-result.js +2 -0
- package/dist/components/empty-state/empty-state.d.ts +2 -0
- package/dist/components/empty-state/empty-state.js +2 -0
- package/dist/components/expander/expander.d.ts +2 -0
- package/dist/components/expander/expander.js +2 -0
- package/dist/components/field/field.d.ts +2 -0
- package/dist/components/field/field.js +2 -0
- package/dist/components/file-input/file-input.d.ts +2 -0
- package/dist/components/file-input/file-input.js +2 -0
- package/dist/components/filter-bar/filter-bar.d.ts +2 -0
- package/dist/components/filter-bar/filter-bar.js +2 -0
- package/dist/components/form-section/form-section.d.ts +2 -0
- package/dist/components/form-section/form-section.js +2 -0
- package/dist/components/icon/icon.d.ts +2 -0
- package/dist/components/icon/icon.js +2 -0
- package/dist/components/include/include.d.ts +2 -0
- package/dist/components/include/include.js +2 -0
- package/dist/components/index.d.ts +85 -0
- package/dist/components/index.js +86 -0
- package/dist/components/infinite-scroller/infinite-scroller.d.ts +2 -0
- package/dist/components/infinite-scroller/infinite-scroller.js +2 -0
- package/dist/components/intersection-observer/intersection-observer.d.ts +2 -0
- package/dist/components/intersection-observer/intersection-observer.js +2 -0
- package/dist/components/listbox/listbox.d.ts +2 -0
- package/dist/components/listbox/listbox.js +2 -0
- package/dist/components/listbox-item/listbox-item.d.ts +2 -0
- package/dist/components/listbox-item/listbox-item.js +2 -0
- package/dist/components/lorem-ipsum/lorem-ipsum.d.ts +2 -0
- package/dist/components/lorem-ipsum/lorem-ipsum.js +2 -0
- package/dist/components/meter/meter.d.ts +2 -0
- package/dist/components/meter/meter.js +2 -0
- package/dist/components/metric/metric.d.ts +2 -0
- package/dist/components/metric/metric.js +2 -0
- package/dist/components/metric-grid/metric-grid.d.ts +2 -0
- package/dist/components/metric-grid/metric-grid.js +2 -0
- package/dist/components/mutation-observer/mutation-observer.d.ts +2 -0
- package/dist/components/mutation-observer/mutation-observer.js +2 -0
- package/dist/components/navicon/navicon.d.ts +2 -0
- package/dist/components/navicon/navicon.js +2 -0
- package/dist/components/number/number.d.ts +2 -0
- package/dist/components/number/number.js +2 -0
- package/dist/components/number-field/number-field.d.ts +2 -0
- package/dist/components/number-field/number-field.js +2 -0
- package/dist/components/pagination/pagination.d.ts +2 -0
- package/dist/components/pagination/pagination.js +2 -0
- package/dist/components/popover/popover.d.ts +2 -0
- package/dist/components/popover/popover.js +2 -0
- package/dist/components/preview-card/preview-card.d.ts +2 -0
- package/dist/components/preview-card/preview-card.js +2 -0
- package/dist/components/progress/progress.d.ts +2 -0
- package/dist/components/progress/progress.js +2 -0
- package/dist/components/radio/radio.d.ts +2 -0
- package/dist/components/radio/radio.js +2 -0
- package/dist/components/radio-item/radio-item.d.ts +2 -0
- package/dist/components/radio-item/radio-item.js +2 -0
- package/dist/components/random-content/random-content.d.ts +2 -0
- package/dist/components/random-content/random-content.js +2 -0
- package/dist/components/rating/rating.d.ts +2 -0
- package/dist/components/rating/rating.js +2 -0
- package/dist/components/resize-observer/resize-observer.d.ts +2 -0
- package/dist/components/resize-observer/resize-observer.js +2 -0
- package/dist/components/scroll-area/scroll-area.d.ts +2 -0
- package/dist/components/scroll-area/scroll-area.js +2 -0
- package/dist/components/scroller/scroller.d.ts +2 -0
- package/dist/components/scroller/scroller.js +2 -0
- package/dist/components/search-list/search-list.d.ts +2 -0
- package/dist/components/search-list/search-list.js +2 -0
- package/dist/components/select/select.d.ts +2 -0
- package/dist/components/select/select.js +2 -0
- package/dist/components/selection-summary/selection-summary.d.ts +2 -0
- package/dist/components/selection-summary/selection-summary.js +2 -0
- package/dist/components/share/share.d.ts +2 -0
- package/dist/components/share/share.js +2 -0
- package/dist/components/slide-activator/slide-activator.d.ts +2 -0
- package/dist/components/slide-activator/slide-activator.js +2 -0
- package/dist/components/slider/slider.d.ts +2 -0
- package/dist/components/slider/slider.js +2 -0
- package/dist/components/sparkline/sparkline.d.ts +2 -0
- package/dist/components/sparkline/sparkline.js +2 -0
- package/dist/components/spinner/spinner.d.ts +2 -0
- package/dist/components/spinner/spinner.js +2 -0
- package/dist/components/splitter/splitter.d.ts +2 -0
- package/dist/components/splitter/splitter.js +2 -0
- package/dist/components/switch/switch.d.ts +2 -0
- package/dist/components/switch/switch.js +2 -0
- package/dist/components/tab/tab.d.ts +2 -0
- package/dist/components/tab/tab.js +2 -0
- package/dist/components/tab-list/tab-list.d.ts +2 -0
- package/dist/components/tab-list/tab-list.js +2 -0
- package/dist/components/tab-panel/tab-panel.d.ts +2 -0
- package/dist/components/tab-panel/tab-panel.js +2 -0
- package/dist/components/text-area/text-area.d.ts +2 -0
- package/dist/components/text-area/text-area.js +2 -0
- package/dist/components/text-field/text-field.d.ts +2 -0
- package/dist/components/text-field/text-field.js +2 -0
- package/dist/components/text-mask/text-mask.d.ts +2 -0
- package/dist/components/text-mask/text-mask.js +2 -0
- package/dist/components/timed-content/timed-content.d.ts +2 -0
- package/dist/components/timed-content/timed-content.js +2 -0
- package/dist/components/toast/toast.d.ts +2 -0
- package/dist/components/toast/toast.js +2 -0
- package/dist/components/toast-item/toast-item.d.ts +2 -0
- package/dist/components/toast-item/toast-item.js +2 -0
- package/dist/components/toggle-icon/toggle-icon.d.ts +2 -0
- package/dist/components/toggle-icon/toggle-icon.js +2 -0
- package/dist/components/toggle-tag/toggle-tag.d.ts +2 -0
- package/dist/components/toggle-tag/toggle-tag.js +2 -0
- package/dist/components/toolbar/toolbar.d.ts +2 -0
- package/dist/components/toolbar/toolbar.js +2 -0
- package/dist/components/tooltip/tooltip.d.ts +2 -0
- package/dist/components/tooltip/tooltip.js +2 -0
- package/dist/components/transition-group/transition-group.d.ts +2 -0
- package/dist/components/transition-group/transition-group.js +2 -0
- package/dist/components/zoomable-frame/zoomable-frame.d.ts +2 -0
- package/dist/components/zoomable-frame/zoomable-frame.js +2 -0
- package/dist/copy-CvC9vaGw.d.ts +206 -0
- package/dist/copy.styles-DWGvGNTP.js +100 -0
- package/dist/data-table-CITa8DSn.js +247 -0
- package/dist/data-table-DL5RhE0d.d.ts +89 -0
- package/dist/date-CJPmOdi9.js +146 -0
- package/dist/date-DtaTBM71.d.ts +142 -0
- package/dist/decorate-DcF3lt7P.js +9 -0
- package/dist/dialog-Cx46HMaZ.js +983 -0
- package/dist/dialog-N-v0woIy.d.ts +414 -0
- package/dist/divider-9vNsfHW8.js +169 -0
- package/dist/divider-DWuAxcXv.d.ts +79 -0
- package/dist/docs/custom-elements.json +29301 -0
- package/dist/dropdown-BXSKpVX9.js +1123 -0
- package/dist/dropdown-Bo00Vlr5.d.ts +537 -0
- package/dist/dropdown-item-_lIs-Tfd.d.ts +111 -0
- package/dist/dropdown-item-i77cRuN6.js +504 -0
- package/dist/empty-result-B2ln1yFL.js +65 -0
- package/dist/empty-result-B54x_Ab2.d.ts +31 -0
- package/dist/empty-state-BLWjtKUo.js +186 -0
- package/dist/empty-state-SGKjpwp3.d.ts +117 -0
- package/dist/expander-BUev0BmM.d.ts +174 -0
- package/dist/expander-Bwvxj6Oa.js +342 -0
- package/dist/field-BEyS909F.js +163 -0
- package/dist/field-ITx0jVw-.d.ts +69 -0
- package/dist/file-input-BEumLJjg.js +841 -0
- package/dist/file-input-D2D6YC0B.d.ts +378 -0
- package/dist/filter-bar-Bj2QzEn9.d.ts +35 -0
- package/dist/filter-bar-Dcs67aXo.js +66 -0
- package/dist/form-section-BchPetkj.js +83 -0
- package/dist/form-section-xFBTBULQ.d.ts +34 -0
- package/dist/icon-BPVkNsY4.js +165 -0
- package/dist/icon-Ci9CPZJV.d.ts +72 -0
- package/dist/icon-library-D_if7p2h.d.ts +2 -0
- package/dist/include-CQHVVtNs.d.ts +103 -0
- package/dist/include-qNUh_6kT.js +155 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +92 -0
- package/dist/infinite-scroller-BmmtnWNt.js +285 -0
- package/dist/infinite-scroller-CuUEAlB9.d.ts +174 -0
- package/dist/intersection-observer-B6TciOAQ.js +503 -0
- package/dist/intersection-observer-B7nmP7Zz.d.ts +418 -0
- package/dist/listbox-C3XXRWGX.js +1257 -0
- package/dist/listbox-DD4ujIJe.d.ts +682 -0
- package/dist/listbox-item-CwD9s3VY.js +135 -0
- package/dist/listbox-item-DQEJWp4Z.d.ts +53 -0
- package/dist/localize-322EtXNX.d.ts +66 -0
- package/dist/lorem-ipsum-B2x3V-v8.js +198 -0
- package/dist/lorem-ipsum-CR82CSuJ.d.ts +130 -0
- package/dist/meter-BC7uaJWf.d.ts +73 -0
- package/dist/meter-BIDyjwFp.js +155 -0
- package/dist/metric-CjlLq_VA.d.ts +36 -0
- package/dist/metric-DbuOcDp_.js +86 -0
- package/dist/metric-grid-C2Pb0Zl3.js +37 -0
- package/dist/metric-grid-C5Xbb1_0.d.ts +27 -0
- package/dist/mutation-observer-BmrZ-GER.d.ts +326 -0
- package/dist/mutation-observer-DS8EBuOp.js +388 -0
- package/dist/navicon-Dic5Qjzb.d.ts +159 -0
- package/dist/navicon-_yMHY27-.js +486 -0
- package/dist/number-BNtNXNF3.js +162 -0
- package/dist/number-BwbnErlB.d.ts +143 -0
- package/dist/number-field-BQHB7UYo.js +726 -0
- package/dist/number-field-odk4lKXM.d.ts +422 -0
- package/dist/pagination-6z2qcf3U.d.ts +322 -0
- package/dist/pagination-DuKPuzdb.js +679 -0
- package/dist/popover-D0sxTU6o.d.ts +259 -0
- package/dist/popover-DJBrJ0za.js +556 -0
- package/dist/preview-card-C7H1FPfd.js +287 -0
- package/dist/preview-card-DitOCZTD.d.ts +86 -0
- package/dist/progress-Db0_axHQ.d.ts +181 -0
- package/dist/progress-DzVk260j.js +494 -0
- package/dist/radio-BtDG9xJM.js +658 -0
- package/dist/radio-CieMa4zU.d.ts +460 -0
- package/dist/radio-item-DIrUStAX.js +264 -0
- package/dist/radio-item-Xq2U3cMu.d.ts +69 -0
- package/dist/random-content-BhSeJFKz.d.ts +380 -0
- package/dist/random-content-BwiirXdG.js +450 -0
- package/dist/rating-4xNsWumY.d.ts +369 -0
- package/dist/rating-C1BcJDIO.js +722 -0
- package/dist/resize-observer-BseSbVWP.d.ts +187 -0
- package/dist/resize-observer-DcrLhddo.js +236 -0
- package/dist/scroll-area-COc1857S.js +127 -0
- package/dist/scroll-area-CVYDf5qY.d.ts +61 -0
- package/dist/scroller-LYgBVyfY.js +590 -0
- package/dist/scroller-bB2rGs7b.d.ts +374 -0
- package/dist/search-list-Clmrg8EV.js +884 -0
- package/dist/search-list-n0GYO7rh.d.ts +777 -0
- package/dist/select-CkZK2jJn.d.ts +506 -0
- package/dist/select-DLIaRnA4.js +690 -0
- package/dist/selection-summary-BVnNJ8Lw.js +48 -0
- package/dist/selection-summary-DmFkGyZI.d.ts +34 -0
- package/dist/share-DPlqP2dc.d.ts +162 -0
- package/dist/share-bsgXZCl7.js +250 -0
- package/dist/sigvelo.d.ts +5 -0
- package/dist/sigvelo.js +5 -0
- package/dist/sigvelo.loader.d.ts +3 -0
- package/dist/sigvelo.loader.js +102 -0
- package/dist/slide-activator-D7bBz69E.d.ts +429 -0
- package/dist/slide-activator-DlxQt9R9.js +798 -0
- package/dist/slider-B0FVsV1o.d.ts +921 -0
- package/dist/slider-B90Il7x3.js +1744 -0
- package/dist/sparkline-CcpTaJ_Z.js +358 -0
- package/dist/sparkline-DlCIt81-.d.ts +235 -0
- package/dist/spinner-C04Dmc0H.js +188 -0
- package/dist/spinner-CZ19x_dC.d.ts +99 -0
- package/dist/splitter-DBDJAzsp.d.ts +325 -0
- package/dist/splitter-MnD4In9H.js +638 -0
- package/dist/switch-CPaEKbog.js +581 -0
- package/dist/switch-Cief9M59.d.ts +248 -0
- package/dist/tab-BcqYGsuW.d.ts +44 -0
- package/dist/tab-C-FtuNmh.js +102 -0
- package/dist/tab-list-B_Ye_Oj9.js +691 -0
- package/dist/tab-list-DDvS8qHr.d.ts +450 -0
- package/dist/tab-panel-BaBl6eep.js +60 -0
- package/dist/tab-panel-BzSJlSfd.d.ts +38 -0
- package/dist/text-area-B_mjCE9W.d.ts +327 -0
- package/dist/text-area-Czixaz-_.js +556 -0
- package/dist/text-field-BClWMp6q.d.ts +424 -0
- package/dist/text-field-inpJfp0A.js +687 -0
- package/dist/text-mask-CNKVKSFp.d.ts +336 -0
- package/dist/text-mask-DDEurj90.js +370 -0
- package/dist/themes/sigvelo.css +10 -0
- package/dist/themes/utilities.css +9 -0
- package/dist/timed-content-D2mGFamc.d.ts +181 -0
- package/dist/timed-content-pvEP4l5V.js +226 -0
- package/dist/toast-BnZaIg6Z.js +636 -0
- package/dist/toast-cEBVK9NQ.d.ts +487 -0
- package/dist/toast-item-BPpJT6vD.d.ts +159 -0
- package/dist/toast-item-IS8IFUEg.js +372 -0
- package/dist/toggle-icon-4oLDeEt4.js +752 -0
- package/dist/toggle-icon-DlwMMWZL.d.ts +359 -0
- package/dist/toggle-tag-1sfTFJtg.js +434 -0
- package/dist/toggle-tag-IVvMGT4R.d.ts +245 -0
- package/dist/toolbar-CABq0ZL1.d.ts +122 -0
- package/dist/toolbar-CEZ0-F-X.js +196 -0
- package/dist/tooltip-DbyoPFNe.js +521 -0
- package/dist/tooltip-ahFthek8.d.ts +192 -0
- package/dist/transition-group-3hnAnwSd.js +801 -0
- package/dist/transition-group-DD_CjSNC.d.ts +608 -0
- package/dist/translations/en.d.ts +6 -0
- package/dist/translations/en.js +75 -0
- package/dist/translations/es.d.ts +6 -0
- package/dist/translations/es.js +75 -0
- package/dist/types/custom-element-jsx.d.ts +13723 -0
- package/dist/utilities/icon-library.d.ts +3 -0
- package/dist/utilities/icon-library.js +93 -0
- package/dist/utilities/localize.d.ts +2 -0
- package/dist/utilities/localize.js +6 -0
- package/dist/zoomable-frame-Cldvj5sE.js +398 -0
- package/dist/zoomable-frame-r6S6587z.d.ts +162 -0
- package/package.json +83 -0
|
@@ -0,0 +1,1240 @@
|
|
|
1
|
+
import { Localize } from "./utilities/localize.js";
|
|
2
|
+
import { t as __decorate } from "./decorate-DcF3lt7P.js";
|
|
3
|
+
import "./button-5k_aL_gD.js";
|
|
4
|
+
import "./components/copy/copy.js";
|
|
5
|
+
import "./slider-B90Il7x3.js";
|
|
6
|
+
import "./text-field-inpJfp0A.js";
|
|
7
|
+
import { css, html } from "lit";
|
|
8
|
+
import { property, query, state } from "lit/decorators.js";
|
|
9
|
+
import hostStyles from "@mcp-b/wc-support/styles/host.styles";
|
|
10
|
+
import { SigveloElement } from "@mcp-b/wc-support/base/sigvelo-element";
|
|
11
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
12
|
+
import { SigveloBlurEvent, SigveloChangeEvent, SigveloFocusEvent, SigveloInputEvent } from "@mcp-b/wc-support/events/form";
|
|
13
|
+
import formControlStyles from "@mcp-b/wc-support/styles/form-control.styles";
|
|
14
|
+
import { TinyColor } from "@ctrl/tinycolor";
|
|
15
|
+
import { DraggableElement } from "@mcp-b/wc-support/utilities/drag";
|
|
16
|
+
import { clamp } from "@mcp-b/wc-support/utilities/math";
|
|
17
|
+
//#region src/components/color-picker/color-picker.styles.ts
|
|
18
|
+
var color_picker_styles_default = css`
|
|
19
|
+
:host {
|
|
20
|
+
display: flex;
|
|
21
|
+
max-width: 100%;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
:host([size="xs"]) {
|
|
25
|
+
width: 10rem;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:host([size="sm"]) {
|
|
29
|
+
width: 14rem;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
:host([size="md"]) {
|
|
33
|
+
width: 18rem;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
:host([size="lg"]) {
|
|
37
|
+
width: 22rem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:host([size="xl"]) {
|
|
41
|
+
width: 26rem;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#picker {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex: 1 1 auto;
|
|
47
|
+
flex-direction: column;
|
|
48
|
+
padding: 1em;
|
|
49
|
+
gap: 1em;
|
|
50
|
+
border: var(--sigvelo-border-style) var(--sigvelo-border-width)
|
|
51
|
+
var(--sigvelo-color-neutral-border-subtle);
|
|
52
|
+
border-radius: var(--sigvelo-radius-md);
|
|
53
|
+
background-color: var(--sigvelo-color-surface);
|
|
54
|
+
box-shadow: var(--sigvelo-elevation-hairline);
|
|
55
|
+
|
|
56
|
+
&.disabled {
|
|
57
|
+
cursor: not-allowed;
|
|
58
|
+
opacity: 0.5;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* Color slider */
|
|
63
|
+
#color-slider {
|
|
64
|
+
position: relative;
|
|
65
|
+
aspect-ratio: 1.4;
|
|
66
|
+
border-radius: var(--sigvelo-radius-md);
|
|
67
|
+
background-color: var(--color-slider-background);
|
|
68
|
+
box-shadow: inset 0 0 0 0.0625rem color-mix(in oklab, black, transparent 90%);
|
|
69
|
+
cursor: crosshair;
|
|
70
|
+
touch-action: none;
|
|
71
|
+
|
|
72
|
+
&:dir(ltr) {
|
|
73
|
+
background-image:
|
|
74
|
+
linear-gradient(rgba(0, 0, 0, 0) 0%, rgb(0, 0, 0) 100%),
|
|
75
|
+
linear-gradient(to right, rgb(255, 255, 255) 0%, rgba(255, 255, 255, 0) 100%);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&:dir(rtl) {
|
|
79
|
+
background-image:
|
|
80
|
+
linear-gradient(rgba(0, 0, 0, 0) 0%, rgb(0, 0, 0) 100%),
|
|
81
|
+
linear-gradient(to left, rgb(255, 255, 255) 0%, rgba(255, 255, 255, 0) 100%);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&:active {
|
|
85
|
+
cursor: none;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
:host(:state(disabled)) #color-slider {
|
|
90
|
+
cursor: not-allowed;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#color-slider-thumb {
|
|
94
|
+
position: absolute;
|
|
95
|
+
width: 1.25em;
|
|
96
|
+
height: 1.25em;
|
|
97
|
+
translate: calc(1.25em / -2) calc(1.25em / -2);
|
|
98
|
+
border: solid 0.0625rem rgb(0 0 0 / 33%);
|
|
99
|
+
border-radius: var(--sigvelo-radius-circle);
|
|
100
|
+
transition: var(--sigvelo-motion-duration-interaction) scale ease;
|
|
101
|
+
|
|
102
|
+
&::after {
|
|
103
|
+
position: absolute;
|
|
104
|
+
top: 0;
|
|
105
|
+
left: 0;
|
|
106
|
+
width: 100%;
|
|
107
|
+
height: 100%;
|
|
108
|
+
border: solid max(0.125em, 1px) white;
|
|
109
|
+
border-radius: inherit;
|
|
110
|
+
box-shadow: inset 0 0 0 0.0625rem rgb(0 0 0 / 33%);
|
|
111
|
+
content: "";
|
|
112
|
+
transition: var(--sigvelo-motion-duration-interaction) scale ease;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
&:focus-visible {
|
|
116
|
+
outline: var(--sigvelo-focus-ring);
|
|
117
|
+
outline-offset: calc(var(--sigvelo-focus-offset) * 2);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
:host(:not(:state(disabled))) #color-slider:active #color-slider-thumb {
|
|
122
|
+
scale: 1.4;
|
|
123
|
+
|
|
124
|
+
&::after {
|
|
125
|
+
border-width: 0.09375em;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#controls {
|
|
130
|
+
display: flex;
|
|
131
|
+
align-items: center;
|
|
132
|
+
gap: 0.5em;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#sliders {
|
|
136
|
+
display: flex;
|
|
137
|
+
flex: 1 1 auto;
|
|
138
|
+
flex-direction: column;
|
|
139
|
+
justify-content: center;
|
|
140
|
+
margin-inline-start: 0.5em;
|
|
141
|
+
gap: 1em;
|
|
142
|
+
|
|
143
|
+
&::part(slider) {
|
|
144
|
+
border-radius: 0;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#hue,
|
|
149
|
+
#alpha {
|
|
150
|
+
--track-size: 1em;
|
|
151
|
+
--thumb-width: 1.25em;
|
|
152
|
+
--thumb-height: 1.25em;
|
|
153
|
+
font-size: inherit;
|
|
154
|
+
|
|
155
|
+
/* Visually hidden */
|
|
156
|
+
&::part(label),
|
|
157
|
+
&::part(description) {
|
|
158
|
+
position: absolute;
|
|
159
|
+
width: 1px;
|
|
160
|
+
height: 1px;
|
|
161
|
+
overflow: hidden;
|
|
162
|
+
white-space: nowrap;
|
|
163
|
+
clip-path: inset(50%);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
&::part(slider) {
|
|
167
|
+
margin-block: 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
&::part(track) {
|
|
171
|
+
border-radius: var(--sigvelo-radius-sm);
|
|
172
|
+
box-shadow: inset 0 0 0 1px color-mix(in oklab, light-dark(black, white), transparent 90%);
|
|
173
|
+
font-size: inherit;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
&::part(thumb) {
|
|
177
|
+
border: solid 0.0625rem rgb(0 0 0 / 33%);
|
|
178
|
+
border-radius: var(--sigvelo-radius-full);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
&::part(thumb)::after {
|
|
182
|
+
position: absolute;
|
|
183
|
+
top: 0;
|
|
184
|
+
left: 0;
|
|
185
|
+
width: 100%;
|
|
186
|
+
height: 100%;
|
|
187
|
+
border: solid max(0.125em, 1px) white;
|
|
188
|
+
border-radius: var(--sigvelo-radius-full);
|
|
189
|
+
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 33%);
|
|
190
|
+
content: "";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
#hue {
|
|
195
|
+
&:dir(ltr)::part(track) {
|
|
196
|
+
background-image: linear-gradient(
|
|
197
|
+
to right,
|
|
198
|
+
rgb(255, 0, 0) 0%,
|
|
199
|
+
rgb(255, 255, 0) 17%,
|
|
200
|
+
rgb(0, 255, 0) 33%,
|
|
201
|
+
rgb(0, 255, 255) 50%,
|
|
202
|
+
rgb(0, 0, 255) 67%,
|
|
203
|
+
rgb(255, 0, 255) 83%,
|
|
204
|
+
rgb(255, 0, 0) 100%
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&:dir(rtl)::part(track) {
|
|
209
|
+
background-image: linear-gradient(
|
|
210
|
+
to left,
|
|
211
|
+
rgb(255, 0, 0) 0%,
|
|
212
|
+
rgb(255, 255, 0) 17%,
|
|
213
|
+
rgb(0, 255, 0) 33%,
|
|
214
|
+
rgb(0, 255, 255) 50%,
|
|
215
|
+
rgb(0, 0, 255) 67%,
|
|
216
|
+
rgb(255, 0, 255) 83%,
|
|
217
|
+
rgb(255, 0, 0) 100%
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&::part(indicator) {
|
|
222
|
+
display: none;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
&::part(thumb) {
|
|
226
|
+
background-color: var(--hue-thumb-color);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
#alpha {
|
|
231
|
+
&::part(track) {
|
|
232
|
+
background-image:
|
|
233
|
+
linear-gradient(45deg, var(--sigvelo-color-neutral-bg-muted) 25%, transparent 25%),
|
|
234
|
+
linear-gradient(45deg, transparent 75%, var(--sigvelo-color-neutral-bg-muted) 75%),
|
|
235
|
+
linear-gradient(45deg, transparent 75%, var(--sigvelo-color-neutral-bg-muted) 75%),
|
|
236
|
+
linear-gradient(45deg, var(--sigvelo-color-neutral-bg-muted) 25%, transparent 25%);
|
|
237
|
+
background-position:
|
|
238
|
+
0 0,
|
|
239
|
+
0 0,
|
|
240
|
+
-0.25em -0.25em,
|
|
241
|
+
0.25em 0.25em;
|
|
242
|
+
background-size: 0.5em 0.5em;
|
|
243
|
+
background-color: transparent;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
&::part(indicator) {
|
|
247
|
+
width: 100% !important;
|
|
248
|
+
background-color: transparent;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
&:dir(ltr)::part(indicator) {
|
|
252
|
+
background-image: linear-gradient(
|
|
253
|
+
to right,
|
|
254
|
+
transparent 0%,
|
|
255
|
+
var(--current-color-without-alpha) 100%
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
&:dir(rtl)::part(indicator) {
|
|
260
|
+
background-image: linear-gradient(
|
|
261
|
+
to left,
|
|
262
|
+
transparent 0%,
|
|
263
|
+
var(--current-color-without-alpha) 100%
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
&::part(thumb) {
|
|
268
|
+
background-color: var(--alpha-thumb-color);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* Eye dropper button */
|
|
273
|
+
#eye-dropper::part(button) {
|
|
274
|
+
min-height: 2.75em;
|
|
275
|
+
border-radius: var(--sigvelo-radius-circle);
|
|
276
|
+
font-size: inherit;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* Preview/copy button */
|
|
280
|
+
#copy-button {
|
|
281
|
+
display: flex;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
#preview-button {
|
|
285
|
+
&::part(button) {
|
|
286
|
+
position: relative;
|
|
287
|
+
width: 2.75em;
|
|
288
|
+
height: 2.75em;
|
|
289
|
+
min-height: 0;
|
|
290
|
+
border: none;
|
|
291
|
+
border-radius: var(--sigvelo-radius-circle);
|
|
292
|
+
background-image:
|
|
293
|
+
linear-gradient(45deg, var(--sigvelo-color-neutral-bg-muted) 25%, transparent 25%),
|
|
294
|
+
linear-gradient(45deg, transparent 75%, var(--sigvelo-color-neutral-bg-muted) 75%),
|
|
295
|
+
linear-gradient(45deg, transparent 75%, var(--sigvelo-color-neutral-bg-muted) 75%),
|
|
296
|
+
linear-gradient(45deg, var(--sigvelo-color-neutral-bg-muted) 25%, transparent 25%);
|
|
297
|
+
background-position:
|
|
298
|
+
0 0,
|
|
299
|
+
0 0,
|
|
300
|
+
-0.25em -0.25em,
|
|
301
|
+
0.25em 0.25em;
|
|
302
|
+
background-size: 0.5em 0.5em;
|
|
303
|
+
background-color: transparent;
|
|
304
|
+
font-size: inherit;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
&::part(button)::after {
|
|
308
|
+
position: absolute;
|
|
309
|
+
top: 0;
|
|
310
|
+
right: 0;
|
|
311
|
+
bottom: 0;
|
|
312
|
+
left: 0;
|
|
313
|
+
border-radius: inherit;
|
|
314
|
+
background-color: var(--current-color);
|
|
315
|
+
box-shadow: inset 0 0 0 1px color-mix(in oklab, light-dark(black, white), transparent 90%);
|
|
316
|
+
content: "";
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
&:disabled {
|
|
320
|
+
cursor: not-allowed;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
&:focus {
|
|
324
|
+
outline: none;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
&:focus-visible {
|
|
328
|
+
outline: var(--sigvelo-focus-ring);
|
|
329
|
+
outline-offset: var(--sigvelo-focus-offset);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/* Color input */
|
|
334
|
+
#color-input::part(label) {
|
|
335
|
+
position: absolute;
|
|
336
|
+
width: 1px;
|
|
337
|
+
height: 1px;
|
|
338
|
+
overflow: hidden;
|
|
339
|
+
white-space: nowrap;
|
|
340
|
+
clip-path: inset(50%);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* Swatches */
|
|
344
|
+
#swatches {
|
|
345
|
+
display: grid;
|
|
346
|
+
grid-template-columns: repeat(8, 1fr);
|
|
347
|
+
gap: 0.25em;
|
|
348
|
+
|
|
349
|
+
button {
|
|
350
|
+
display: inline-block;
|
|
351
|
+
position: relative;
|
|
352
|
+
aspect-ratio: 1;
|
|
353
|
+
margin: 0;
|
|
354
|
+
padding: 0;
|
|
355
|
+
border: none;
|
|
356
|
+
border-radius: var(--sigvelo-radius-sm);
|
|
357
|
+
background: none;
|
|
358
|
+
background-image:
|
|
359
|
+
linear-gradient(45deg, var(--sigvelo-color-neutral-bg-muted) 25%, transparent 25%),
|
|
360
|
+
linear-gradient(45deg, transparent 75%, var(--sigvelo-color-neutral-bg-muted) 75%),
|
|
361
|
+
linear-gradient(45deg, transparent 75%, var(--sigvelo-color-neutral-bg-muted) 75%),
|
|
362
|
+
linear-gradient(45deg, var(--sigvelo-color-neutral-bg-muted) 25%, transparent 25%);
|
|
363
|
+
background-position:
|
|
364
|
+
0 0,
|
|
365
|
+
0 0,
|
|
366
|
+
-0.25em -0.25em,
|
|
367
|
+
0.25em 0.25em;
|
|
368
|
+
background-size: 0.5em 0.5em;
|
|
369
|
+
background-color: transparent;
|
|
370
|
+
cursor: pointer;
|
|
371
|
+
transition: var(--sigvelo-motion-duration-interaction) translate ease;
|
|
372
|
+
|
|
373
|
+
&:active:not(.disabled) {
|
|
374
|
+
translate: 0 var(--sigvelo-motion-distance-xs);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
&:focus {
|
|
378
|
+
outline: none;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
&:focus-visible {
|
|
382
|
+
outline: var(--sigvelo-focus-ring);
|
|
383
|
+
outline-offset: var(--sigvelo-focus-offset);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
&::after {
|
|
387
|
+
position: absolute;
|
|
388
|
+
top: 0;
|
|
389
|
+
left: 0;
|
|
390
|
+
width: 100%;
|
|
391
|
+
height: 100%;
|
|
392
|
+
border-radius: inherit;
|
|
393
|
+
background-color: var(--swatch-color);
|
|
394
|
+
box-shadow: inset 0 0 0 1px color-mix(in oklab, light-dark(black, white), transparent 90%);
|
|
395
|
+
content: "";
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
:host(:state(disabled)) #swatches button {
|
|
401
|
+
cursor: not-allowed;
|
|
402
|
+
}
|
|
403
|
+
`;
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/components/color-picker/color-picker.ts
|
|
406
|
+
const hasEyeDropper = "EyeDropper" in window;
|
|
407
|
+
/**
|
|
408
|
+
* <sigvelo-color-picker>
|
|
409
|
+
*
|
|
410
|
+
* @summary Provides a customizable interface for selecting a color.
|
|
411
|
+
* @tag sigvelo-color-picker
|
|
412
|
+
* @documentation https://design-system.sigvelo.com/docs/components/color-picker
|
|
413
|
+
* @status stable
|
|
414
|
+
* @since 1.0
|
|
415
|
+
*
|
|
416
|
+
* @dependency sigvelo-button
|
|
417
|
+
* @dependency sigvelo-copy
|
|
418
|
+
* @dependency sigvelo-slider
|
|
419
|
+
* @dependency sigvelo-text-field
|
|
420
|
+
*
|
|
421
|
+
* @event sigvelo-change - Emitted when the user commits changes to the color picker's value.
|
|
422
|
+
* @event sigvelo-input - Emitted when the color picker receives input. This can fire very frequently during dragging, so
|
|
423
|
+
* avoid doing expensive operations in the handler. If you don't live feedback, use the `sigvelo-change` event instead.
|
|
424
|
+
*
|
|
425
|
+
* @csspart picker - The element the wraps the color picker.
|
|
426
|
+
* @csspart color-slider - The 2d color slider.
|
|
427
|
+
* @csspart color-slider-thumb - The color slider's thumb.
|
|
428
|
+
* @csspart controls - The container that wraps the sliders and preview.
|
|
429
|
+
* @csspart sliders - The container that wraps the hue and alpha slider.
|
|
430
|
+
* @csspart hue-slider - The slider that controls the color's hue.
|
|
431
|
+
* @csspart hue-slider__label - The hue slider's `label` part.
|
|
432
|
+
* @csspart hue-slider__description - The hue slider's `description` part.
|
|
433
|
+
* @csspart hue-slider__slider - The hue slider's `slider` part.
|
|
434
|
+
* @csspart hue-slider__track - The hue slider's `track` part.
|
|
435
|
+
* @csspart hue-slider__indicator - The hue slider's `indicator` part.
|
|
436
|
+
* @csspart hue-slider__thumb - The hue slider's `thumb` part.
|
|
437
|
+
* @csspart alpha-slider - The slider that controls the color's opacity.
|
|
438
|
+
* @csspart alpha-slider__label - The alpha slider's `label` part.
|
|
439
|
+
* @csspart alpha-slider__description - The alpha slider's `description` part.
|
|
440
|
+
* @csspart alpha-slider__slider - The alpha slider's `slider` part.
|
|
441
|
+
* @csspart alpha-slider__track - The alpha slider's `track` part.
|
|
442
|
+
* @csspart alpha-slider__indicator - The alpha slider's `indicator` part.
|
|
443
|
+
* @csspart alpha-slider__thumb - The alpha slider's `thumb` part.
|
|
444
|
+
* @csspart eye-dropper-button - The eye dropper button, a `<sigvelo-button>` element.
|
|
445
|
+
* @csspart preview-button - The button that shows a preview of the current color, a `<sigvelo-button>` element.
|
|
446
|
+
* @csspart color-input - The color input text field, a `<sigvelo-text-field>` element.
|
|
447
|
+
* @csspart color-input__visual-box - The element that wraps the internal text box.
|
|
448
|
+
* @csspart color-input__text-box - The internal text box, an `<input>` element.
|
|
449
|
+
* @csspart swatches - The element that contains swatches.
|
|
450
|
+
* @csspart swatch - Each individual swatch.
|
|
451
|
+
*
|
|
452
|
+
* @cssstate disabled - Applied when the color picker is disabled.
|
|
453
|
+
* @cssstate focused - Applied when the color picker has focus.
|
|
454
|
+
*
|
|
455
|
+
* @example Default
|
|
456
|
+
* ```html
|
|
457
|
+
* <sigvelo-color-picker
|
|
458
|
+
* label="Select a color"
|
|
459
|
+
* value="#7578c5"
|
|
460
|
+
* with-input
|
|
461
|
+
* with-alpha
|
|
462
|
+
* with-eye-dropper
|
|
463
|
+
* swatches="
|
|
464
|
+
* #09090b; #71717a; #ef4444; #f97316;
|
|
465
|
+
* #f59e0b; #eab308; #84cc16; #22c55e;
|
|
466
|
+
* #10b981; #14b8a6; #06b6d4; #3b82f6;
|
|
467
|
+
* #6366f1; #a855f7; #d946ef; #ec4899
|
|
468
|
+
* "
|
|
469
|
+
* ></sigvelo-color-picker>
|
|
470
|
+
* ```
|
|
471
|
+
*
|
|
472
|
+
* **Note:** This component is a primitive for enabling color selection. It is not a form control, so it will not submit a value to a form. See [color input](/docs/components/color-input) for a color picker suitable for using with forms.
|
|
473
|
+
*
|
|
474
|
+
* @example Labels
|
|
475
|
+
* Use the `label` attribute to provide an accessible label for the color picker. This won't be visible, but it will be read to assistive devices.
|
|
476
|
+
*
|
|
477
|
+
* ```html
|
|
478
|
+
* <sigvelo-color-picker label="Select a color"></sigvelo-color-picker>
|
|
479
|
+
* ```
|
|
480
|
+
*
|
|
481
|
+
* @example Setting an initial value
|
|
482
|
+
* Use the `value` attribute to provide an initial value for the color picker. You can specify values in a variety of formats as well as CSS colors names. Parsing of color values is very permissive. See the TinyColor docs for more details on acceptable color formats.
|
|
483
|
+
*
|
|
484
|
+
* ```html
|
|
485
|
+
* <sigvelo-color-picker
|
|
486
|
+
* label="Select a color"
|
|
487
|
+
* value="#71e0f3"
|
|
488
|
+
* >
|
|
489
|
+
* </sigvelo-color-picker>
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* @example Enabling alpha
|
|
493
|
+
* Add the `with-alpha` attribute to allow the user to adjust opacity.
|
|
494
|
+
*
|
|
495
|
+
* ```html
|
|
496
|
+
* <sigvelo-color-picker
|
|
497
|
+
* label="Select a color"
|
|
498
|
+
* value="#ce238088"
|
|
499
|
+
* with-alpha
|
|
500
|
+
* ></sigvelo-color-picker>
|
|
501
|
+
* ```
|
|
502
|
+
*
|
|
503
|
+
* @example Enabling the eye dropper
|
|
504
|
+
* Add the `with-eye-dropper` attribute to show the eye dropper button, which allows the user to select a color from anywhere on the screen.
|
|
505
|
+
*
|
|
506
|
+
* ```html
|
|
507
|
+
* <sigvelo-color-picker
|
|
508
|
+
* label="Select a color"
|
|
509
|
+
* with-eye-dropper
|
|
510
|
+
* ></sigvelo-color-picker>
|
|
511
|
+
* ```
|
|
512
|
+
*
|
|
513
|
+
* **Warning:** The [EyeDropper API](https://developer.mozilla.org/en-US/docs/Web/API/EyeDropper) is only available in [supportive browsers](https://caniuse.com/?search=eyedropper%20API).
|
|
514
|
+
*
|
|
515
|
+
* @example Enabling the color input
|
|
516
|
+
* Add the `with-input` attribute to show the color input, a text field the user can type into.
|
|
517
|
+
*
|
|
518
|
+
* ```html
|
|
519
|
+
* <sigvelo-color-picker
|
|
520
|
+
* label="Select a color"
|
|
521
|
+
* value="#4716ce"
|
|
522
|
+
* with-input
|
|
523
|
+
* ></sigvelo-color-picker>
|
|
524
|
+
* ```
|
|
525
|
+
*
|
|
526
|
+
* @example Showing swatches
|
|
527
|
+
* Set the `swatches` attribute to one or more semicolon-delimited colors to show as preset swatches below the color picker. You can use any valid CSS color format including hex colors, RGB, HSL, named colors, and more. This is useful for providing users with access to recent colors or a predefined color palette.
|
|
528
|
+
*
|
|
529
|
+
* ```html
|
|
530
|
+
* <sigvelo-color-picker
|
|
531
|
+
* label="Select a color"
|
|
532
|
+
* swatches="
|
|
533
|
+
* #09090b; #71717a; #ef4444; #f97316;
|
|
534
|
+
* #f59e0b; #eab308; #84cc16; #22c55e;
|
|
535
|
+
* #10b981; #14b8a6; #06b6d4; #3b82f6;
|
|
536
|
+
* #6366f1; #a855f7; #d946ef; #ec4899
|
|
537
|
+
* "
|
|
538
|
+
* ></sigvelo-color-picker>
|
|
539
|
+
* ```
|
|
540
|
+
*
|
|
541
|
+
* You can also use any CSS color format in the swatches:
|
|
542
|
+
*
|
|
543
|
+
* ```html
|
|
544
|
+
* <sigvelo-color-picker
|
|
545
|
+
* label="Select a color"
|
|
546
|
+
* swatches="
|
|
547
|
+
* rgb(255 0 0);
|
|
548
|
+
* hsl(120, 100%, 50%);
|
|
549
|
+
* rgb(0 0 255 / 0.5);
|
|
550
|
+
* lightblue;
|
|
551
|
+
* #ff00ff
|
|
552
|
+
* "
|
|
553
|
+
* ></sigvelo-color-picker>
|
|
554
|
+
* ```
|
|
555
|
+
*
|
|
556
|
+
* @example Setting the format
|
|
557
|
+
* Use the `format` attribute to set the format of the value. Valid options include `hex` (default), `rgb,` and `hsl`.
|
|
558
|
+
*
|
|
559
|
+
* ```html
|
|
560
|
+
* <sigvelo-color-picker
|
|
561
|
+
* label="Select a color"
|
|
562
|
+
* value="#ffcc00"
|
|
563
|
+
* format="rgb"
|
|
564
|
+
* with-input
|
|
565
|
+
* id="color-picker__format"
|
|
566
|
+
* ></sigvelo-color-picker>
|
|
567
|
+
*
|
|
568
|
+
* <script>
|
|
569
|
+
* const colorPicker = document.getElementById('color-picker__format');
|
|
570
|
+
*
|
|
571
|
+
* // This will output an RGB string when the color changes
|
|
572
|
+
* colorPicker.addEventListener('sigvelo-change', () => {
|
|
573
|
+
* console.log(colorPicker.value);
|
|
574
|
+
* });
|
|
575
|
+
* <\/script>
|
|
576
|
+
* ```
|
|
577
|
+
*
|
|
578
|
+
* **Note:** You can set the color picker's value using any format and it will automatically be converted to the format specified by the `format` attribute.
|
|
579
|
+
*
|
|
580
|
+
* @example Getting the value programmatically
|
|
581
|
+
* If you need to access the value in a specific format, use the `getValueAs()` method. You can pass `rgb` (default), `hsl`, `hex`, or `hex8` to get a corresponding value.
|
|
582
|
+
*
|
|
583
|
+
* For `rgb`, an object with `{ r, g, b, a }` properties will be returned where `r`, `g`, and `b` range from 0-255 and `a` (alpha) ranges from 0–1. For `hsl`, an object with `{ h, s, l, a }` properties will be returned where `h` ranges from 0–360 and `s`, `l`, and `a` range from 0–1. For `hex` and `hex8`, a string in the format of `#RRGGBB` and `#RRGGBBAA` will be returned, respectively.
|
|
584
|
+
*
|
|
585
|
+
* ```html
|
|
586
|
+
* <sigvelo-color-picker
|
|
587
|
+
* label="Select a color"
|
|
588
|
+
* value="tomato"
|
|
589
|
+
* format="rgb"
|
|
590
|
+
* id="color-picker__object"
|
|
591
|
+
* ></sigvelo-color-picker>
|
|
592
|
+
*
|
|
593
|
+
* <script>
|
|
594
|
+
* const colorPicker = document.getElementById('color-picker__object');
|
|
595
|
+
*
|
|
596
|
+
* // Outputs two objects when the color changes
|
|
597
|
+
* colorPicker.addEventListener('sigvelo-change', () => {
|
|
598
|
+
* console.log(
|
|
599
|
+
* colorPicker.getValueAs('rgb'),
|
|
600
|
+
* colorPicker.getValueAs('hex'),
|
|
601
|
+
* colorPicker.getValueAs('hex8'),
|
|
602
|
+
* colorPicker.getValueAs('hsl')
|
|
603
|
+
* );
|
|
604
|
+
* });
|
|
605
|
+
* <\/script>
|
|
606
|
+
* ```
|
|
607
|
+
*
|
|
608
|
+
* @example Changing the size
|
|
609
|
+
* Use the `size` attribute to change the color pickers's size.
|
|
610
|
+
*
|
|
611
|
+
* ```html
|
|
612
|
+
* <sigvelo-select label="Select a size" style="max-width: 18rem; margin-block-end: 2rem;">
|
|
613
|
+
* <option value="xs">Extra small</option>
|
|
614
|
+
* <option value="sm">Small</option>
|
|
615
|
+
* <option value="md">Medium</option>
|
|
616
|
+
* <option value="lg">Large</option>
|
|
617
|
+
* <option value="xl">Extra large</option>
|
|
618
|
+
* </sigvelo-select>
|
|
619
|
+
*
|
|
620
|
+
* <sigvelo-color-picker
|
|
621
|
+
* size="xs"
|
|
622
|
+
* label="Color picker sizes"
|
|
623
|
+
* swatches="
|
|
624
|
+
* #09090b; #71717a; #ef4444; #f97316;
|
|
625
|
+
* #f59e0b; #eab308; #84cc16; #22c55e;
|
|
626
|
+
* #10b981; #14b8a6; #06b6d4; #3b82f6;
|
|
627
|
+
* #6366f1; #a855f7; #d946ef; #ec4899
|
|
628
|
+
* "
|
|
629
|
+
* with-input
|
|
630
|
+
* with-alpha
|
|
631
|
+
* with-eye-dropper
|
|
632
|
+
* id="color-picker__size"
|
|
633
|
+
* ></sigvelo-color-picker>
|
|
634
|
+
*
|
|
635
|
+
* <script>
|
|
636
|
+
* const colorPicker = document.getElementById('color-picker__size');
|
|
637
|
+
* const select = colorPicker.previousElementSibling;
|
|
638
|
+
*
|
|
639
|
+
* select.addEventListener('sigvelo-change', () => {
|
|
640
|
+
* colorPicker.size = select.value;
|
|
641
|
+
* });
|
|
642
|
+
* <\/script>
|
|
643
|
+
* ```
|
|
644
|
+
*
|
|
645
|
+
* @example Disabling
|
|
646
|
+
* To disable a color picker, add the `disabled` attribute.
|
|
647
|
+
*
|
|
648
|
+
* ```html
|
|
649
|
+
* <sigvelo-color-picker
|
|
650
|
+
* label="Select a color"
|
|
651
|
+
* disabled
|
|
652
|
+
* value="#6366f1"
|
|
653
|
+
* with-alpha
|
|
654
|
+
* with-input
|
|
655
|
+
* with-eye-dropper
|
|
656
|
+
* swatches="
|
|
657
|
+
* #09090b; #71717a; #ef4444; #f97316;
|
|
658
|
+
* #f59e0b; #eab308; #84cc16; #22c55e;
|
|
659
|
+
* #10b981; #14b8a6; #06b6d4; #3b82f6;
|
|
660
|
+
* #6366f1; #a855f7; #d946ef; #ec4899
|
|
661
|
+
* "
|
|
662
|
+
* ></sigvelo-color-picker>
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
var SigveloColorPicker = class extends SigveloElement {
|
|
666
|
+
constructor(..._args) {
|
|
667
|
+
super(..._args);
|
|
668
|
+
this.isDragging = false;
|
|
669
|
+
this.localize = new Localize(this);
|
|
670
|
+
this.wasValueSetInternally = false;
|
|
671
|
+
this.h = 0;
|
|
672
|
+
this.s = 0;
|
|
673
|
+
this.v = 1;
|
|
674
|
+
this.a = 1;
|
|
675
|
+
this.colorSliderThumbX = 0;
|
|
676
|
+
this.colorSliderThumbY = 0;
|
|
677
|
+
this.hasFocus = false;
|
|
678
|
+
this.isChangingV = false;
|
|
679
|
+
this.isChangingS = false;
|
|
680
|
+
this.inputIsFocused = false;
|
|
681
|
+
this.displayValue = "";
|
|
682
|
+
this.hadUserInteraction = false;
|
|
683
|
+
this.value = "";
|
|
684
|
+
this.format = "hex";
|
|
685
|
+
this.disabled = false;
|
|
686
|
+
this.size = "md";
|
|
687
|
+
this.swatches = "";
|
|
688
|
+
this.withAlpha = false;
|
|
689
|
+
this.withEyeDropper = false;
|
|
690
|
+
this.withInput = false;
|
|
691
|
+
this.handleFocusIn = (event) => {
|
|
692
|
+
if (!this.hasFocus && event.target === event.currentTarget) {
|
|
693
|
+
this.hasFocus = true;
|
|
694
|
+
this.dispatchEvent(new SigveloFocusEvent());
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
this.handleFocusOut = (event) => {
|
|
698
|
+
if (this.matches(":focus-visible") || event.target !== event.currentTarget) return;
|
|
699
|
+
this.hasFocus = false;
|
|
700
|
+
this.dispatchEvent(new SigveloBlurEvent());
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
static {
|
|
704
|
+
this.observeSlots = true;
|
|
705
|
+
}
|
|
706
|
+
static {
|
|
707
|
+
this.styles = [
|
|
708
|
+
hostStyles,
|
|
709
|
+
formControlStyles,
|
|
710
|
+
color_picker_styles_default
|
|
711
|
+
];
|
|
712
|
+
}
|
|
713
|
+
get focusableAnchor() {
|
|
714
|
+
return this.colorSliderThumb;
|
|
715
|
+
}
|
|
716
|
+
connectedCallback() {
|
|
717
|
+
super.connectedCallback();
|
|
718
|
+
this.addEventListener("focusin", this.handleFocusIn);
|
|
719
|
+
this.addEventListener("focusout", this.handleFocusOut);
|
|
720
|
+
}
|
|
721
|
+
disconnectedCallback() {
|
|
722
|
+
super.disconnectedCallback();
|
|
723
|
+
this.removeEventListener("focusin", this.handleFocusIn);
|
|
724
|
+
this.removeEventListener("focusout", this.handleFocusOut);
|
|
725
|
+
}
|
|
726
|
+
firstUpdated() {
|
|
727
|
+
this.setColorFromString(this.value);
|
|
728
|
+
this.draggableThumb = new DraggableElement(this.colorSlider, {
|
|
729
|
+
start: (x, y) => {
|
|
730
|
+
this.colorSliderBoundingClientRect = this.colorSlider.getBoundingClientRect();
|
|
731
|
+
this.isDragging = true;
|
|
732
|
+
this.valueWhenDraggingStarted = this.value;
|
|
733
|
+
this.setColorFromCoordinates(x, y);
|
|
734
|
+
},
|
|
735
|
+
move: (x, y) => {
|
|
736
|
+
this.setColorFromCoordinates(x, y);
|
|
737
|
+
},
|
|
738
|
+
stop: () => {
|
|
739
|
+
if (this.value !== this.valueWhenDraggingStarted) {
|
|
740
|
+
this.hadUserInteraction = true;
|
|
741
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
742
|
+
this.dispatchEvent(new Event("change", {
|
|
743
|
+
bubbles: true,
|
|
744
|
+
composed: true
|
|
745
|
+
}));
|
|
746
|
+
}
|
|
747
|
+
this.isDragging = false;
|
|
748
|
+
this.valueWhenDraggingStarted = void 0;
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
updated(changedProperties) {
|
|
753
|
+
if (changedProperties.has("value")) {
|
|
754
|
+
if (!this.isDragging && !this.wasValueSetInternally) this.setColorFromString(this.value);
|
|
755
|
+
if (!this.inputIsFocused) this.displayValue = this.value;
|
|
756
|
+
}
|
|
757
|
+
if (changedProperties.has("dir")) this.updateColorSliderThumbPosition();
|
|
758
|
+
if (changedProperties.has("disabled")) {
|
|
759
|
+
this.customStates.set("disabled", this.disabled);
|
|
760
|
+
this.draggableThumb.toggle(!this.disabled);
|
|
761
|
+
}
|
|
762
|
+
if (changedProperties.has("hasFocus")) this.customStates.set("focused", this.hasFocus);
|
|
763
|
+
if (changedProperties.has("withAlpha") && !this.withAlpha) this.a = 1;
|
|
764
|
+
if (changedProperties.has("h") || changedProperties.has("s") || changedProperties.has("v") || changedProperties.has("a") || changedProperties.has("format") || changedProperties.has("value")) {
|
|
765
|
+
const color = new TinyColor({
|
|
766
|
+
h: this.h,
|
|
767
|
+
s: this.s,
|
|
768
|
+
v: this.v,
|
|
769
|
+
a: this.a
|
|
770
|
+
});
|
|
771
|
+
this.updateColorSliderThumbPosition();
|
|
772
|
+
this.wasValueSetInternally = true;
|
|
773
|
+
switch (this.format) {
|
|
774
|
+
case "rgb":
|
|
775
|
+
this.value = color.toRgbString();
|
|
776
|
+
break;
|
|
777
|
+
case "hsl":
|
|
778
|
+
this.value = color.toHslString();
|
|
779
|
+
break;
|
|
780
|
+
default:
|
|
781
|
+
this.value = this.withAlpha ? color.toHex8String() : color.toHexString();
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
this.updateComplete.then(() => this.wasValueSetInternally = false);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
formatHue(value) {
|
|
788
|
+
return this.localize.number(value.toFixed(0), {
|
|
789
|
+
style: "unit",
|
|
790
|
+
unit: "degree",
|
|
791
|
+
unitDisplay: "narrow"
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
formatAlpha(value) {
|
|
795
|
+
return this.localize.number(value, { style: "percent" });
|
|
796
|
+
}
|
|
797
|
+
async handleColorInputBlur(event) {
|
|
798
|
+
const input = event.target;
|
|
799
|
+
this.inputIsFocused = false;
|
|
800
|
+
if (new TinyColor(input.value).isValid) {
|
|
801
|
+
this.setColorFromString(input.value);
|
|
802
|
+
await this.updateComplete;
|
|
803
|
+
this.displayValue = this.value;
|
|
804
|
+
} else this.displayValue = this.value;
|
|
805
|
+
}
|
|
806
|
+
async handleColorInputFocus(event) {
|
|
807
|
+
if (event.type === "sigvelo-focus") {
|
|
808
|
+
this.inputIsFocused = true;
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
async handleColorInputInput(event) {
|
|
813
|
+
event.stopImmediatePropagation();
|
|
814
|
+
const oldValue = this.value;
|
|
815
|
+
const input = event.target;
|
|
816
|
+
this.displayValue = input.value;
|
|
817
|
+
if (new TinyColor(input.value).isValid) this.setColorFromString(input.value);
|
|
818
|
+
await this.updateComplete;
|
|
819
|
+
if (this.value !== oldValue) {
|
|
820
|
+
this.hadUserInteraction = true;
|
|
821
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
822
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
823
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
824
|
+
this.dispatchEvent(new Event("change", {
|
|
825
|
+
bubbles: true,
|
|
826
|
+
composed: true
|
|
827
|
+
}));
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
handleColorSliderBlur() {
|
|
831
|
+
this.isChangingS = false;
|
|
832
|
+
this.isChangingV = false;
|
|
833
|
+
}
|
|
834
|
+
async handleColorSliderThumbKeyDown(event) {
|
|
835
|
+
const isRtl = this.localize.dir() === "rtl";
|
|
836
|
+
const oldValue = this.value;
|
|
837
|
+
if ([
|
|
838
|
+
"ArrowUp",
|
|
839
|
+
"ArrowDown",
|
|
840
|
+
"PageUp",
|
|
841
|
+
"PageDown"
|
|
842
|
+
].includes(event.key)) {
|
|
843
|
+
let increment = 0;
|
|
844
|
+
if (event.key === "ArrowUp") increment = .01;
|
|
845
|
+
if (event.key === "ArrowDown") increment = -.01;
|
|
846
|
+
if (event.key === "PageUp") increment = .1;
|
|
847
|
+
if (event.key === "PageDown") increment = -.1;
|
|
848
|
+
event.preventDefault();
|
|
849
|
+
this.v = clamp(this.v + increment, 0, 1);
|
|
850
|
+
this.isChangingV = true;
|
|
851
|
+
this.isChangingS = false;
|
|
852
|
+
}
|
|
853
|
+
if ([
|
|
854
|
+
"ArrowLeft",
|
|
855
|
+
"ArrowRight",
|
|
856
|
+
"Home",
|
|
857
|
+
"End"
|
|
858
|
+
].includes(event.key)) {
|
|
859
|
+
let increment = 0;
|
|
860
|
+
if (event.key === "ArrowLeft") increment = -.01;
|
|
861
|
+
if (event.key === "ArrowRight") increment = .01;
|
|
862
|
+
if (event.key === "Home") increment = -.1;
|
|
863
|
+
if (event.key === "End") increment = .1;
|
|
864
|
+
if (isRtl) increment *= -1;
|
|
865
|
+
event.preventDefault();
|
|
866
|
+
this.s = clamp(this.s + increment, 0, 1);
|
|
867
|
+
this.isChangingS = true;
|
|
868
|
+
this.isChangingV = false;
|
|
869
|
+
}
|
|
870
|
+
await this.updateComplete;
|
|
871
|
+
if (this.value !== oldValue) {
|
|
872
|
+
this.hadUserInteraction = true;
|
|
873
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
874
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
875
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
876
|
+
this.dispatchEvent(new Event("change", {
|
|
877
|
+
bubbles: true,
|
|
878
|
+
composed: true
|
|
879
|
+
}));
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
handleEyeDropperClick() {
|
|
883
|
+
new EyeDropper().open().then(async (result) => {
|
|
884
|
+
const oldValue = this.value;
|
|
885
|
+
this.setColorFromString(result.sRGBHex);
|
|
886
|
+
await this.updateComplete;
|
|
887
|
+
if (this.value !== oldValue) {
|
|
888
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
889
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
890
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
891
|
+
this.dispatchEvent(new Event("change", {
|
|
892
|
+
bubbles: true,
|
|
893
|
+
composed: true
|
|
894
|
+
}));
|
|
895
|
+
}
|
|
896
|
+
}).catch(() => {});
|
|
897
|
+
}
|
|
898
|
+
async handleHueSliderInput(event) {
|
|
899
|
+
event.stopImmediatePropagation();
|
|
900
|
+
const value = event.target.value;
|
|
901
|
+
if (typeof value !== "number") return;
|
|
902
|
+
this.h = value;
|
|
903
|
+
await this.updateComplete;
|
|
904
|
+
if (event.type === "sigvelo-input") {
|
|
905
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
906
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
907
|
+
} else if (event.type === "sigvelo-change") {
|
|
908
|
+
this.hadUserInteraction = true;
|
|
909
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
910
|
+
this.dispatchEvent(new Event("change", {
|
|
911
|
+
bubbles: true,
|
|
912
|
+
composed: true
|
|
913
|
+
}));
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
async handleAlphaSliderInput(event) {
|
|
917
|
+
event.stopImmediatePropagation();
|
|
918
|
+
const value = event.target.value;
|
|
919
|
+
if (typeof value !== "number") return;
|
|
920
|
+
this.a = value;
|
|
921
|
+
await this.updateComplete;
|
|
922
|
+
if (event.type === "sigvelo-input") {
|
|
923
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
924
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
925
|
+
} else if (event.type === "sigvelo-change") {
|
|
926
|
+
this.hadUserInteraction = true;
|
|
927
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
928
|
+
this.dispatchEvent(new Event("change", {
|
|
929
|
+
bubbles: true,
|
|
930
|
+
composed: true
|
|
931
|
+
}));
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
/** Sets the color when a swatch is clicked. */
|
|
935
|
+
async handleSwatchClick(color) {
|
|
936
|
+
const oldValue = this.value;
|
|
937
|
+
if (this.disabled) return;
|
|
938
|
+
this.setColorFromString(color);
|
|
939
|
+
this.hadUserInteraction = true;
|
|
940
|
+
this.colorSliderThumb.focus();
|
|
941
|
+
await this.updateComplete;
|
|
942
|
+
if (this.value !== oldValue) {
|
|
943
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
944
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
945
|
+
this.dispatchEvent(new SigveloChangeEvent());
|
|
946
|
+
this.dispatchEvent(new Event("change", {
|
|
947
|
+
bubbles: true,
|
|
948
|
+
composed: true
|
|
949
|
+
}));
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Parses an arbitrary color string and sets the corresponding HSVA values.
|
|
954
|
+
*/
|
|
955
|
+
setColorFromString(color) {
|
|
956
|
+
const hsv = new TinyColor(color).toHsv();
|
|
957
|
+
this.h = hsv.h;
|
|
958
|
+
this.s = hsv.s;
|
|
959
|
+
this.v = hsv.v;
|
|
960
|
+
this.a = hsv.a;
|
|
961
|
+
}
|
|
962
|
+
/** Sets the S and V value based on the pointer's x and y coordinates. */
|
|
963
|
+
async setColorFromCoordinates(x, y) {
|
|
964
|
+
const isRtl = this.localize.dir() === "rtl";
|
|
965
|
+
const oldValue = this.value;
|
|
966
|
+
const { top, left, height, width } = this.colorSliderBoundingClientRect;
|
|
967
|
+
const relativeXPercent = isRtl ? clamp(1 - (x - left) / width, 0, 1) : clamp((x - left) / width, 0, 1);
|
|
968
|
+
const relativeYPercent = clamp((y - top) / height, 0, 1);
|
|
969
|
+
this.s = relativeXPercent;
|
|
970
|
+
this.v = 1 - relativeYPercent;
|
|
971
|
+
await this.updateComplete;
|
|
972
|
+
if (this.value !== oldValue) {
|
|
973
|
+
this.dispatchEvent(new SigveloInputEvent());
|
|
974
|
+
this.dispatchEvent(new InputEvent("input"));
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
/** Prevent custom events that bubble from propagating outside of the component */
|
|
978
|
+
stopPropagation(event) {
|
|
979
|
+
event.stopImmediatePropagation();
|
|
980
|
+
}
|
|
981
|
+
/** Updates the color slider's thumb position based on S and V. */
|
|
982
|
+
updateColorSliderThumbPosition() {
|
|
983
|
+
const isRtl = this.localize.dir() === "rtl";
|
|
984
|
+
this.colorSliderThumbX = isRtl ? (1 - this.s) * 100 : this.s * 100;
|
|
985
|
+
this.colorSliderThumbY = (1 - this.v) * 100;
|
|
986
|
+
}
|
|
987
|
+
/** Sets focus to the color picker. */
|
|
988
|
+
focus() {
|
|
989
|
+
this.colorSliderThumb.focus();
|
|
990
|
+
}
|
|
991
|
+
/** Removes focus from the color picker. */
|
|
992
|
+
blur() {
|
|
993
|
+
this.shadowRoot.activeElement?.blur();
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Gets the current value as a hex string, a hex8 string, an RGB object, or an HSL object. RBG objects have `r`, `g`,
|
|
997
|
+
* and `b` properties ranging from 0–255 and an `a` property (representing opacity) that ranges from 0-1. HSL objects
|
|
998
|
+
* have an `h` property ranging from `0-359` and `s`, `l`, and `a` properties ranging from 0–1.
|
|
999
|
+
*/
|
|
1000
|
+
getValueAs(format = "rgb") {
|
|
1001
|
+
const color = new TinyColor({
|
|
1002
|
+
h: this.h,
|
|
1003
|
+
s: this.s,
|
|
1004
|
+
v: this.v,
|
|
1005
|
+
a: this.a
|
|
1006
|
+
});
|
|
1007
|
+
switch (format) {
|
|
1008
|
+
case "hex": return color.toHexString();
|
|
1009
|
+
case "hex8": return color.toHex8String();
|
|
1010
|
+
case "hsl": return color.toHsl();
|
|
1011
|
+
default: return color.toRgb();
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
render() {
|
|
1015
|
+
const isRtl = this.localize.dir() === "rtl";
|
|
1016
|
+
const currentColor = new TinyColor({
|
|
1017
|
+
h: this.h,
|
|
1018
|
+
s: this.s,
|
|
1019
|
+
v: this.v,
|
|
1020
|
+
a: this.a
|
|
1021
|
+
});
|
|
1022
|
+
const colorWithoutAlpha = new TinyColor({
|
|
1023
|
+
h: this.h,
|
|
1024
|
+
s: this.s,
|
|
1025
|
+
v: this.v,
|
|
1026
|
+
a: 1
|
|
1027
|
+
});
|
|
1028
|
+
const hueColor = new TinyColor({
|
|
1029
|
+
h: this.h,
|
|
1030
|
+
s: 1,
|
|
1031
|
+
v: 1,
|
|
1032
|
+
a: 1
|
|
1033
|
+
});
|
|
1034
|
+
const alphaColor = `color-mix(in oklab, light-dark(white, black), ${currentColor.toHexString()} ${this.a * 100}%);`;
|
|
1035
|
+
const swatches = this.swatches.split(";").map((val) => val.trim()).filter((val) => val !== "");
|
|
1036
|
+
const luminosityText = this.localize.term("percentLuminosity", this.localize.number(this.v, { style: "percent" }));
|
|
1037
|
+
const saturationText = this.localize.term("percentSaturation", this.localize.number(this.s, { style: "percent" }));
|
|
1038
|
+
let valueText = "";
|
|
1039
|
+
if (this.isChangingV) valueText = luminosityText;
|
|
1040
|
+
else if (this.isChangingS) valueText = saturationText;
|
|
1041
|
+
else valueText = `${luminosityText}, ${saturationText}`;
|
|
1042
|
+
return html`
|
|
1043
|
+
<div
|
|
1044
|
+
id="picker"
|
|
1045
|
+
part="picker"
|
|
1046
|
+
class=${classMap({
|
|
1047
|
+
xs: this.size === "xs",
|
|
1048
|
+
sm: this.size === "sm",
|
|
1049
|
+
md: this.size === "md",
|
|
1050
|
+
lg: this.size === "lg",
|
|
1051
|
+
xl: this.size === "xl",
|
|
1052
|
+
disabled: this.disabled
|
|
1053
|
+
})}
|
|
1054
|
+
style="
|
|
1055
|
+
--current-color: ${currentColor.toHex8String()};
|
|
1056
|
+
--current-color-without-alpha: ${colorWithoutAlpha.toHexString()};
|
|
1057
|
+
--hue-thumb-color: ${hueColor.toHexString()};
|
|
1058
|
+
--alpha-thumb-color: ${alphaColor};
|
|
1059
|
+
"
|
|
1060
|
+
>
|
|
1061
|
+
<div
|
|
1062
|
+
id="color-slider"
|
|
1063
|
+
part="color-slider"
|
|
1064
|
+
style="background-color: ${hueColor.toHexString()};"
|
|
1065
|
+
>
|
|
1066
|
+
<span
|
|
1067
|
+
id="color-slider-thumb"
|
|
1068
|
+
part="color-slider-thumb"
|
|
1069
|
+
style="
|
|
1070
|
+
top: ${this.colorSliderThumbY}%;
|
|
1071
|
+
left: ${this.colorSliderThumbX}%;
|
|
1072
|
+
background-color: ${colorWithoutAlpha.toHexString()};
|
|
1073
|
+
"
|
|
1074
|
+
tabindex="${this.disabled ? "-1" : "0"}"
|
|
1075
|
+
role="slider"
|
|
1076
|
+
aria-roledescription="2d slider"
|
|
1077
|
+
aria-label=${this.label}
|
|
1078
|
+
aria-valuenow="0"
|
|
1079
|
+
aria-valuetext="${valueText}"
|
|
1080
|
+
@blur=${this.handleColorSliderBlur}
|
|
1081
|
+
@keydown=${this.handleColorSliderThumbKeyDown}
|
|
1082
|
+
></span>
|
|
1083
|
+
</div>
|
|
1084
|
+
|
|
1085
|
+
<div id="controls" part="controls">
|
|
1086
|
+
<sigvelo-copy id="copy-button" data=${this.value} ?disabled=${this.disabled}>
|
|
1087
|
+
<sigvelo-button
|
|
1088
|
+
id="preview-button"
|
|
1089
|
+
part="preview-button"
|
|
1090
|
+
variant="ghost"
|
|
1091
|
+
?disabled=${this.disabled}
|
|
1092
|
+
icon-label=${this.localize.term("copyToClipboard")}
|
|
1093
|
+
></sigvelo-button>
|
|
1094
|
+
</sigvelo-copy>
|
|
1095
|
+
|
|
1096
|
+
${this.withEyeDropper && hasEyeDropper ? html`
|
|
1097
|
+
<sigvelo-button
|
|
1098
|
+
id="eye-dropper"
|
|
1099
|
+
part="eye-dropper-button"
|
|
1100
|
+
variant="ghost"
|
|
1101
|
+
?disabled=${this.disabled}
|
|
1102
|
+
icon-label=${this.localize.term("selectAColorFromTheScreen")}
|
|
1103
|
+
@click=${this.handleEyeDropperClick}
|
|
1104
|
+
>
|
|
1105
|
+
<sigvelo-icon library="system" name="color-picker"></sigvelo-icon>
|
|
1106
|
+
</sigvelo-button>
|
|
1107
|
+
` : ""}
|
|
1108
|
+
|
|
1109
|
+
<div id="sliders" part="sliders">
|
|
1110
|
+
<sigvelo-slider
|
|
1111
|
+
id="hue"
|
|
1112
|
+
part="hue-slider"
|
|
1113
|
+
exportparts="
|
|
1114
|
+
label:hue-slider__label,
|
|
1115
|
+
description:hue-slider__description,
|
|
1116
|
+
slider:hue-slider__slider,
|
|
1117
|
+
track:hue-slider__track,
|
|
1118
|
+
indicator:hue-slider__indicator,
|
|
1119
|
+
thumb:hue-slider__thumb,
|
|
1120
|
+
"
|
|
1121
|
+
dir=${isRtl ? "rtl" : " ltr"}
|
|
1122
|
+
label="${this.localize.term("hue")}"
|
|
1123
|
+
min="0"
|
|
1124
|
+
max="359"
|
|
1125
|
+
value=${this.h}
|
|
1126
|
+
.valueFormatter=${this.formatHue}
|
|
1127
|
+
?disabled=${this.disabled}
|
|
1128
|
+
@sigvelo-focus=${this.stopPropagation}
|
|
1129
|
+
@sigvelo-blur=${this.stopPropagation}
|
|
1130
|
+
@sigvelo-change=${this.handleHueSliderInput}
|
|
1131
|
+
@sigvelo-input=${this.handleHueSliderInput}
|
|
1132
|
+
></sigvelo-slider>
|
|
1133
|
+
|
|
1134
|
+
${this.withAlpha ? html`
|
|
1135
|
+
<sigvelo-slider
|
|
1136
|
+
id="alpha"
|
|
1137
|
+
part="alpha-slider"
|
|
1138
|
+
exportparts="
|
|
1139
|
+
label:alpha-slider__label,
|
|
1140
|
+
description:alpha-slider__description,
|
|
1141
|
+
slider:alpha-slider__slider,
|
|
1142
|
+
track:alpha-slider__track,
|
|
1143
|
+
indicator:alpha-slider__indicator,
|
|
1144
|
+
thumb:alpha-slider__thumb,
|
|
1145
|
+
"
|
|
1146
|
+
dir=${isRtl ? "rtl" : " ltr"}
|
|
1147
|
+
label=${this.localize.term("opacity")}
|
|
1148
|
+
min="0"
|
|
1149
|
+
max="1"
|
|
1150
|
+
step="0.01"
|
|
1151
|
+
value=${this.a}
|
|
1152
|
+
.valueFormatter=${this.formatAlpha}
|
|
1153
|
+
?disabled=${this.disabled}
|
|
1154
|
+
@sigvelo-focus=${this.stopPropagation}
|
|
1155
|
+
@sigvelo-blur=${this.stopPropagation}
|
|
1156
|
+
@sigvelo-change=${this.handleAlphaSliderInput}
|
|
1157
|
+
@sigvelo-input=${this.handleAlphaSliderInput}
|
|
1158
|
+
></sigvelo-slider>
|
|
1159
|
+
` : ""}
|
|
1160
|
+
</div>
|
|
1161
|
+
</div>
|
|
1162
|
+
|
|
1163
|
+
${this.withInput ? html`
|
|
1164
|
+
<sigvelo-text-field
|
|
1165
|
+
id="color-input"
|
|
1166
|
+
part="color-input"
|
|
1167
|
+
exportparts="
|
|
1168
|
+
visual-box:color-input__visual-box,
|
|
1169
|
+
text-box:color-input__text-box
|
|
1170
|
+
"
|
|
1171
|
+
label=${this.localize.term("colorValue")}
|
|
1172
|
+
value=${this.displayValue}
|
|
1173
|
+
?disabled=${this.disabled}
|
|
1174
|
+
size=${this.size}
|
|
1175
|
+
@sigvelo-input=${this.handleColorInputInput}
|
|
1176
|
+
@sigvelo-blur=${this.handleColorInputBlur}
|
|
1177
|
+
@sigvelo-focus=${this.handleColorInputFocus}
|
|
1178
|
+
></sigvelo-text-field>
|
|
1179
|
+
` : ""}
|
|
1180
|
+
${swatches.length > 0 ? html`
|
|
1181
|
+
<div id="swatches" part="swatches">
|
|
1182
|
+
${swatches.map((swatch) => {
|
|
1183
|
+
return html`
|
|
1184
|
+
<button
|
|
1185
|
+
part="swatch"
|
|
1186
|
+
aria-label="${swatch}"
|
|
1187
|
+
style="--swatch-color: ${swatch}"
|
|
1188
|
+
tabindex=${this.disabled ? "-1" : "0"}
|
|
1189
|
+
@click=${() => this.handleSwatchClick(swatch)}
|
|
1190
|
+
></button>
|
|
1191
|
+
`;
|
|
1192
|
+
})}
|
|
1193
|
+
</div>
|
|
1194
|
+
` : ""}
|
|
1195
|
+
</div>
|
|
1196
|
+
`;
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
__decorate([query("#color-slider")], SigveloColorPicker.prototype, "colorSlider", void 0);
|
|
1200
|
+
__decorate([query("#color-slider-thumb")], SigveloColorPicker.prototype, "colorSliderThumb", void 0);
|
|
1201
|
+
__decorate([state()], SigveloColorPicker.prototype, "h", void 0);
|
|
1202
|
+
__decorate([state()], SigveloColorPicker.prototype, "s", void 0);
|
|
1203
|
+
__decorate([state()], SigveloColorPicker.prototype, "v", void 0);
|
|
1204
|
+
__decorate([state()], SigveloColorPicker.prototype, "a", void 0);
|
|
1205
|
+
__decorate([state()], SigveloColorPicker.prototype, "colorSliderThumbX", void 0);
|
|
1206
|
+
__decorate([state()], SigveloColorPicker.prototype, "colorSliderThumbY", void 0);
|
|
1207
|
+
__decorate([state()], SigveloColorPicker.prototype, "hasFocus", void 0);
|
|
1208
|
+
__decorate([state()], SigveloColorPicker.prototype, "isChangingV", void 0);
|
|
1209
|
+
__decorate([state()], SigveloColorPicker.prototype, "isChangingS", void 0);
|
|
1210
|
+
__decorate([state()], SigveloColorPicker.prototype, "inputIsFocused", void 0);
|
|
1211
|
+
__decorate([state()], SigveloColorPicker.prototype, "displayValue", void 0);
|
|
1212
|
+
__decorate([state()], SigveloColorPicker.prototype, "hadUserInteraction", void 0);
|
|
1213
|
+
__decorate([property()], SigveloColorPicker.prototype, "label", void 0);
|
|
1214
|
+
__decorate([property()], SigveloColorPicker.prototype, "value", void 0);
|
|
1215
|
+
__decorate([property()], SigveloColorPicker.prototype, "format", void 0);
|
|
1216
|
+
__decorate([property({
|
|
1217
|
+
type: Boolean,
|
|
1218
|
+
reflect: true
|
|
1219
|
+
})], SigveloColorPicker.prototype, "disabled", void 0);
|
|
1220
|
+
__decorate([property({ reflect: true })], SigveloColorPicker.prototype, "size", void 0);
|
|
1221
|
+
__decorate([property()], SigveloColorPicker.prototype, "swatches", void 0);
|
|
1222
|
+
__decorate([property({
|
|
1223
|
+
attribute: "with-alpha",
|
|
1224
|
+
type: Boolean,
|
|
1225
|
+
reflect: true
|
|
1226
|
+
})], SigveloColorPicker.prototype, "withAlpha", void 0);
|
|
1227
|
+
__decorate([property({
|
|
1228
|
+
attribute: "with-eye-dropper",
|
|
1229
|
+
type: Boolean,
|
|
1230
|
+
reflect: true
|
|
1231
|
+
})], SigveloColorPicker.prototype, "withEyeDropper", void 0);
|
|
1232
|
+
__decorate([property({
|
|
1233
|
+
attribute: "with-input",
|
|
1234
|
+
type: Boolean,
|
|
1235
|
+
reflect: true
|
|
1236
|
+
})], SigveloColorPicker.prototype, "withInput", void 0);
|
|
1237
|
+
SigveloColorPicker.disableWarning?.("change-in-update");
|
|
1238
|
+
customElements.define("sigvelo-color-picker", SigveloColorPicker);
|
|
1239
|
+
//#endregion
|
|
1240
|
+
export { SigveloColorPicker as t };
|