@sprawlify/primitives 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anatomy.cjs +3 -0
- package/dist/anatomy.d.cts +2 -0
- package/dist/anatomy.d.mts +2 -0
- package/dist/anatomy.mjs +3 -0
- package/dist/aria-hidden-DqYx0f_y.mjs +177 -0
- package/dist/aria-hidden-DtLU6hSU.cjs +182 -0
- package/dist/aria-hidden.cjs +4 -0
- package/dist/aria-hidden.d.cts +16 -0
- package/dist/aria-hidden.d.mts +16 -0
- package/dist/aria-hidden.mjs +4 -0
- package/dist/auto-resize-D3qHtFy1.mjs +114 -0
- package/dist/auto-resize-xzlPFDyD.cjs +125 -0
- package/dist/auto-resize.cjs +5 -0
- package/dist/auto-resize.d.cts +17 -0
- package/dist/auto-resize.d.mts +17 -0
- package/dist/auto-resize.mjs +4 -0
- package/dist/chunk-CbDLau6x.cjs +34 -0
- package/dist/collection-8XqaNHs_.mjs +1279 -0
- package/dist/collection-DIoIDISa.cjs +1326 -0
- package/dist/collection.cjs +11 -0
- package/dist/collection.d.cts +5 -0
- package/dist/collection.d.mts +5 -0
- package/dist/collection.mjs +4 -0
- package/dist/color-BkAP1Tkd.d.mts +60 -0
- package/dist/color-VKewNv2e.d.cts +60 -0
- package/dist/color-utils-Cc5GVXZh.mjs +657 -0
- package/dist/color-utils-LER_6Zwu.cjs +680 -0
- package/dist/color-utils.cjs +7 -0
- package/dist/color-utils.d.cts +19 -0
- package/dist/color-utils.d.mts +19 -0
- package/dist/color-utils.mjs +4 -0
- package/dist/core-30pJjyC2.d.mts +49 -0
- package/dist/core-CQFbMdTl.cjs +176 -0
- package/dist/core-CefBjbst.d.cts +49 -0
- package/dist/core-DCFNMTZF.mjs +129 -0
- package/dist/core.cjs +12 -0
- package/dist/core.d.cts +3 -0
- package/dist/core.d.mts +3 -0
- package/dist/core.mjs +5 -0
- package/dist/create-anatomy-B3XYc-qG.d.mts +70 -0
- package/dist/create-anatomy-BGQ8pv8J.d.cts +70 -0
- package/dist/create-anatomy-BbDZbHpC.mjs +39 -0
- package/dist/create-anatomy-CDsIFUXg.cjs +45 -0
- package/dist/create-props-BnF_vl-E.mjs +5 -0
- package/dist/create-props-YKy7JIKj.cjs +11 -0
- package/dist/data-url-C3ITPVRX.d.cts +10 -0
- package/dist/data-url-DLwZ9M77.d.mts +10 -0
- package/dist/date-utils-D2xPHa_I.cjs +738 -0
- package/dist/date-utils-wEa1hhpc.mjs +474 -0
- package/dist/date-utils.cjs +46 -0
- package/dist/date-utils.d.cts +101 -0
- package/dist/date-utils.d.mts +2 -0
- package/dist/date-utils.mjs +3 -0
- package/dist/defineProperty-BoUOT9Ie.cjs +49 -0
- package/dist/defineProperty-DrXfyjd4.mjs +43 -0
- package/dist/dismissable-CTfKZ4OG.cjs +282 -0
- package/dist/dismissable-DDrx0xnH.mjs +271 -0
- package/dist/dismissable-layer-C7pZU2wi.d.cts +39 -0
- package/dist/dismissable-layer-t_b0fk-p.d.mts +39 -0
- package/dist/dismissable.cjs +7 -0
- package/dist/dismissable.d.cts +3 -0
- package/dist/dismissable.d.mts +3 -0
- package/dist/dismissable.mjs +6 -0
- package/dist/dom-query-CWZdWUGp.cjs +2141 -0
- package/dist/dom-query-DFCRhyj1.mjs +1374 -0
- package/dist/dom-query.cjs +130 -0
- package/dist/dom-query.d.cts +307 -0
- package/dist/dom-query.d.mts +307 -0
- package/dist/dom-query.mjs +3 -0
- package/dist/file-utils.cjs +220 -0
- package/dist/file-utils.d.cts +51 -0
- package/dist/file-utils.d.mts +51 -0
- package/dist/file-utils.mjs +210 -0
- package/dist/focus-trap-D-bypQEJ.mjs +485 -0
- package/dist/focus-trap-D4i52S9A.cjs +496 -0
- package/dist/focus-trap.cjs +5 -0
- package/dist/focus-trap.d.cts +88 -0
- package/dist/focus-trap.d.mts +88 -0
- package/dist/focus-trap.mjs +4 -0
- package/dist/focus-visible-DYTWdWpa.cjs +210 -0
- package/dist/focus-visible-irppYatv.mjs +175 -0
- package/dist/focus-visible.cjs +9 -0
- package/dist/focus-visible.d.cts +31 -0
- package/dist/focus-visible.d.mts +31 -0
- package/dist/focus-visible.mjs +4 -0
- package/dist/functions-BOkTDEFM.d.cts +15 -0
- package/dist/functions-IZtWcC8Q.d.mts +15 -0
- package/dist/highlight-word.cjs +100 -0
- package/dist/highlight-word.d.cts +24 -0
- package/dist/highlight-word.d.mts +24 -0
- package/dist/highlight-word.mjs +99 -0
- package/dist/hotkeys.cjs +758 -0
- package/dist/hotkeys.d.cts +130 -0
- package/dist/hotkeys.d.mts +130 -0
- package/dist/hotkeys.mjs +754 -0
- package/dist/i18n-utils.cjs +450 -0
- package/dist/i18n-utils.d.cts +61 -0
- package/dist/i18n-utils.d.mts +61 -0
- package/dist/i18n-utils.mjs +440 -0
- package/dist/index-BkzYij2j.d.mts +25 -0
- package/dist/index-Bqw3r34-.d.cts +1383 -0
- package/dist/index-C0MKXQmE.d.mts +1383 -0
- package/dist/index-C9-feK5c.d.cts +25 -0
- package/dist/index-CD5FN7kY.d.mts +114 -0
- package/dist/index-CJji6wHl.d.cts +15 -0
- package/dist/index-CNi5FkPe.d.mts +15 -0
- package/dist/index-D96rs8B0.d.mts +115 -0
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/interact-outside-BplxR9cR.mjs +200 -0
- package/dist/interact-outside-C8-oFBpB.cjs +205 -0
- package/dist/interact-outside.cjs +5 -0
- package/dist/interact-outside.d.cts +2 -0
- package/dist/interact-outside.d.mts +2 -0
- package/dist/interact-outside.mjs +5 -0
- package/dist/json-tree-utils.cjs +1512 -0
- package/dist/json-tree-utils.d.cts +117 -0
- package/dist/json-tree-utils.d.mts +117 -0
- package/dist/json-tree-utils.mjs +1463 -0
- package/dist/list-collection-BIMJGQjn.d.cts +61 -0
- package/dist/list-collection-Db3eixRU.d.mts +61 -0
- package/dist/live-region-CcZPGo89.cjs +52 -0
- package/dist/live-region-CnPh21WH.mjs +46 -0
- package/dist/live-region.cjs +3 -0
- package/dist/live-region.d.cts +2 -0
- package/dist/live-region.d.mts +2 -0
- package/dist/live-region.mjs +3 -0
- package/dist/machines/accordion/index.cjs +328 -0
- package/dist/machines/accordion/index.d.cts +83 -0
- package/dist/machines/accordion/index.d.mts +83 -0
- package/dist/machines/accordion/index.mjs +322 -0
- package/dist/machines/async-list/index.cjs +311 -0
- package/dist/machines/async-list/index.d.cts +89 -0
- package/dist/machines/async-list/index.d.mts +89 -0
- package/dist/machines/async-list/index.mjs +310 -0
- package/dist/machines/avatar/index.cjs +169 -0
- package/dist/machines/avatar/index.d.cts +63 -0
- package/dist/machines/avatar/index.d.mts +63 -0
- package/dist/machines/avatar/index.mjs +165 -0
- package/dist/machines/bottom-sheet/index.cjs +676 -0
- package/dist/machines/bottom-sheet/index.d.cts +239 -0
- package/dist/machines/bottom-sheet/index.d.mts +239 -0
- package/dist/machines/bottom-sheet/index.mjs +672 -0
- package/dist/machines/carousel/index.cjs +859 -0
- package/dist/machines/carousel/index.d.cts +146 -0
- package/dist/machines/carousel/index.d.mts +146 -0
- package/dist/machines/carousel/index.mjs +851 -0
- package/dist/machines/checkbox/index.cjs +316 -0
- package/dist/machines/checkbox/index.d.cts +81 -0
- package/dist/machines/checkbox/index.d.mts +81 -0
- package/dist/machines/checkbox/index.mjs +312 -0
- package/dist/machines/clipboard/index.cjs +225 -0
- package/dist/machines/clipboard/index.d.cts +68 -0
- package/dist/machines/clipboard/index.d.mts +68 -0
- package/dist/machines/clipboard/index.mjs +219 -0
- package/dist/machines/collapsible/index.cjs +362 -0
- package/dist/machines/collapsible/index.d.cts +82 -0
- package/dist/machines/collapsible/index.d.mts +82 -0
- package/dist/machines/collapsible/index.mjs +358 -0
- package/dist/machines/color-picker/index.cjs +1529 -0
- package/dist/machines/color-picker/index.d.cts +205 -0
- package/dist/machines/color-picker/index.d.mts +205 -0
- package/dist/machines/color-picker/index.mjs +1514 -0
- package/dist/machines/combobox/index.cjs +1593 -0
- package/dist/machines/combobox/index.d.cts +214 -0
- package/dist/machines/combobox/index.d.mts +214 -0
- package/dist/machines/combobox/index.mjs +1582 -0
- package/dist/machines/date-picker/index.cjs +2177 -0
- package/dist/machines/date-picker/index.d.cts +350 -0
- package/dist/machines/date-picker/index.d.mts +350 -0
- package/dist/machines/date-picker/index.mjs +2161 -0
- package/dist/machines/dialog/index.cjs +325 -0
- package/dist/machines/dialog/index.d.cts +80 -0
- package/dist/machines/dialog/index.d.mts +80 -0
- package/dist/machines/dialog/index.mjs +321 -0
- package/dist/machines/editable/index.cjs +551 -0
- package/dist/machines/editable/index.d.cts +114 -0
- package/dist/machines/editable/index.d.mts +114 -0
- package/dist/machines/editable/index.mjs +547 -0
- package/dist/machines/floating-panel/index.cjs +995 -0
- package/dist/machines/floating-panel/index.d.cts +147 -0
- package/dist/machines/floating-panel/index.d.mts +147 -0
- package/dist/machines/floating-panel/index.mjs +988 -0
- package/dist/machines/hover-card/index.cjs +383 -0
- package/dist/machines/hover-card/index.d.cts +69 -0
- package/dist/machines/hover-card/index.d.mts +69 -0
- package/dist/machines/hover-card/index.mjs +379 -0
- package/dist/machines/image-cropper/index.cjs +1995 -0
- package/dist/machines/image-cropper/index.d.cts +182 -0
- package/dist/machines/image-cropper/index.d.mts +182 -0
- package/dist/machines/image-cropper/index.mjs +1990 -0
- package/dist/machines/listbox/index.cjs +794 -0
- package/dist/machines/listbox/index.d.cts +168 -0
- package/dist/machines/listbox/index.d.mts +168 -0
- package/dist/machines/listbox/index.mjs +782 -0
- package/dist/machines/marquee/index.cjs +395 -0
- package/dist/machines/marquee/index.d.cts +102 -0
- package/dist/machines/marquee/index.d.mts +102 -0
- package/dist/machines/marquee/index.mjs +391 -0
- package/dist/machines/menu/index.cjs +1298 -0
- package/dist/machines/menu/index.d.cts +175 -0
- package/dist/machines/menu/index.d.mts +175 -0
- package/dist/machines/menu/index.mjs +1286 -0
- package/dist/machines/navigation-menu/index.cjs +861 -0
- package/dist/machines/navigation-menu/index.d.cts +127 -0
- package/dist/machines/navigation-menu/index.d.mts +127 -0
- package/dist/machines/navigation-menu/index.mjs +857 -0
- package/dist/machines/number-input/index.cjs +996 -0
- package/dist/machines/number-input/index.d.cts +134 -0
- package/dist/machines/number-input/index.d.mts +134 -0
- package/dist/machines/number-input/index.mjs +991 -0
- package/dist/machines/pagination/index.cjs +419 -0
- package/dist/machines/pagination/index.d.cts +139 -0
- package/dist/machines/pagination/index.d.mts +139 -0
- package/dist/machines/pagination/index.mjs +411 -0
- package/dist/machines/password-input/index.cjs +228 -0
- package/dist/machines/password-input/index.d.cts +71 -0
- package/dist/machines/password-input/index.d.mts +71 -0
- package/dist/machines/password-input/index.mjs +224 -0
- package/dist/machines/pin-input/index.cjs +523 -0
- package/dist/machines/pin-input/index.d.cts +105 -0
- package/dist/machines/pin-input/index.d.mts +105 -0
- package/dist/machines/pin-input/index.mjs +519 -0
- package/dist/machines/popover/index.cjs +430 -0
- package/dist/machines/popover/index.d.cts +88 -0
- package/dist/machines/popover/index.d.mts +88 -0
- package/dist/machines/popover/index.mjs +426 -0
- package/dist/machines/presence/index.cjs +192 -0
- package/dist/machines/presence/index.d.cts +44 -0
- package/dist/machines/presence/index.d.mts +44 -0
- package/dist/machines/presence/index.mjs +190 -0
- package/dist/machines/progress/index.cjs +288 -0
- package/dist/machines/progress/index.d.cts +96 -0
- package/dist/machines/progress/index.d.mts +96 -0
- package/dist/machines/progress/index.mjs +284 -0
- package/dist/machines/qr-code/index.cjs +172 -0
- package/dist/machines/qr-code/index.d.cts +70 -0
- package/dist/machines/qr-code/index.d.mts +70 -0
- package/dist/machines/qr-code/index.mjs +167 -0
- package/dist/machines/radio-group/index.cjs +436 -0
- package/dist/machines/radio-group/index.d.cts +106 -0
- package/dist/machines/radio-group/index.d.mts +106 -0
- package/dist/machines/radio-group/index.mjs +430 -0
- package/dist/machines/rating-group/index.cjs +405 -0
- package/dist/machines/rating-group/index.d.cts +101 -0
- package/dist/machines/rating-group/index.d.mts +101 -0
- package/dist/machines/rating-group/index.mjs +399 -0
- package/dist/machines/scroll-area/index.cjs +857 -0
- package/dist/machines/scroll-area/index.d.cts +159 -0
- package/dist/machines/scroll-area/index.d.mts +159 -0
- package/dist/machines/scroll-area/index.mjs +853 -0
- package/dist/machines/select/index.cjs +1165 -0
- package/dist/machines/select/index.d.cts +183 -0
- package/dist/machines/select/index.d.mts +183 -0
- package/dist/machines/select/index.mjs +1154 -0
- package/dist/machines/signature-pad/index.cjs +334 -0
- package/dist/machines/signature-pad/index.d.cts +108 -0
- package/dist/machines/signature-pad/index.d.mts +108 -0
- package/dist/machines/signature-pad/index.mjs +328 -0
- package/dist/machines/slider/index.cjs +957 -0
- package/dist/machines/slider/index.d.cts +149 -0
- package/dist/machines/slider/index.d.mts +149 -0
- package/dist/machines/slider/index.mjs +949 -0
- package/dist/machines/splitter/index.cjs +1112 -0
- package/dist/machines/splitter/index.d.cts +155 -0
- package/dist/machines/splitter/index.d.mts +155 -0
- package/dist/machines/splitter/index.mjs +1103 -0
- package/dist/machines/steps/index.cjs +289 -0
- package/dist/machines/steps/index.d.cts +97 -0
- package/dist/machines/steps/index.d.mts +97 -0
- package/dist/machines/steps/index.mjs +285 -0
- package/dist/machines/switch/index.cjs +305 -0
- package/dist/machines/switch/index.d.cts +80 -0
- package/dist/machines/switch/index.d.mts +80 -0
- package/dist/machines/switch/index.mjs +301 -0
- package/dist/machines/tabs/index.cjs +508 -0
- package/dist/machines/tabs/index.d.cts +111 -0
- package/dist/machines/tabs/index.d.mts +111 -0
- package/dist/machines/tabs/index.mjs +500 -0
- package/dist/machines/tags-input/index.cjs +1127 -0
- package/dist/machines/tags-input/index.d.cts +179 -0
- package/dist/machines/tags-input/index.d.mts +179 -0
- package/dist/machines/tags-input/index.mjs +1121 -0
- package/dist/machines/timer/index.cjs +329 -0
- package/dist/machines/timer/index.d.cts +98 -0
- package/dist/machines/timer/index.d.mts +98 -0
- package/dist/machines/timer/index.mjs +324 -0
- package/dist/machines/toast/index.cjs +1155 -0
- package/dist/machines/toast/index.d.cts +195 -0
- package/dist/machines/toast/index.d.mts +195 -0
- package/dist/machines/toast/index.mjs +1151 -0
- package/dist/machines/toggle/index.cjs +103 -0
- package/dist/machines/toggle/index.d.cts +46 -0
- package/dist/machines/toggle/index.d.mts +46 -0
- package/dist/machines/toggle/index.mjs +99 -0
- package/dist/machines/toggle-group/index.cjs +328 -0
- package/dist/machines/toggle-group/index.d.cts +81 -0
- package/dist/machines/toggle-group/index.d.mts +81 -0
- package/dist/machines/toggle-group/index.mjs +322 -0
- package/dist/machines/tooltip/index.cjs +516 -0
- package/dist/machines/tooltip/index.d.cts +71 -0
- package/dist/machines/tooltip/index.d.mts +71 -0
- package/dist/machines/tooltip/index.mjs +512 -0
- package/dist/machines/tour/index.cjs +1108 -0
- package/dist/machines/tour/index.d.cts +206 -0
- package/dist/machines/tour/index.d.mts +206 -0
- package/dist/machines/tour/index.mjs +1101 -0
- package/dist/machines/tree-view/index.cjs +1271 -0
- package/dist/machines/tree-view/index.d.cts +215 -0
- package/dist/machines/tree-view/index.d.mts +215 -0
- package/dist/machines/tree-view/index.mjs +1263 -0
- package/dist/node-BctU8GXk.d.mts +24 -0
- package/dist/node-CSsuPZVZ.d.cts +24 -0
- package/dist/popper-BPJeAtcA.mjs +349 -0
- package/dist/popper-D0FAW_p7.cjs +373 -0
- package/dist/popper.cjs +8 -0
- package/dist/popper.d.cts +74 -0
- package/dist/popper.d.mts +2 -0
- package/dist/popper.mjs +5 -0
- package/dist/raf-BnlYUlDi.d.mts +15 -0
- package/dist/raf-Cd2FGy0z.d.cts +15 -0
- package/dist/rect-utils-0ellN0a_.mjs +854 -0
- package/dist/rect-utils-DKLRhP8G.cjs +1147 -0
- package/dist/rect-utils.cjs +51 -0
- package/dist/rect-utils.d.cts +198 -0
- package/dist/rect-utils.d.mts +198 -0
- package/dist/rect-utils.mjs +3 -0
- package/dist/remove-scroll-Lrfv79X_.mjs +58 -0
- package/dist/remove-scroll-Uvzg1L9r.cjs +63 -0
- package/dist/remove-scroll.cjs +0 -0
- package/dist/remove-scroll.d.cts +1 -0
- package/dist/remove-scroll.d.mts +1 -0
- package/dist/remove-scroll.mjs +1 -0
- package/dist/scroll-snap-CrTmQRzA.mjs +152 -0
- package/dist/scroll-snap-zyiZLv7W.cjs +175 -0
- package/dist/scroll-snap.cjs +7 -0
- package/dist/scroll-snap.d.cts +14 -0
- package/dist/scroll-snap.d.mts +14 -0
- package/dist/scroll-snap.mjs +4 -0
- package/dist/selection-BIhSzkF7.d.mts +50 -0
- package/dist/selection-CS1GBp8e.d.cts +50 -0
- package/dist/store-BZcXv49B.cjs +305 -0
- package/dist/store-DEojWy9H.mjs +263 -0
- package/dist/store.cjs +9 -0
- package/dist/store.d.cts +26 -0
- package/dist/store.d.mts +26 -0
- package/dist/store.mjs +3 -0
- package/dist/stringify-state.cjs +49 -0
- package/dist/stringify-state.d.cts +8 -0
- package/dist/stringify-state.d.mts +8 -0
- package/dist/stringify-state.mjs +46 -0
- package/dist/tree-collection-BwU5WhGQ.d.mts +78 -0
- package/dist/tree-collection-DP_eznnI.d.cts +78 -0
- package/dist/typeahead-BdNwVP09.d.cts +45 -0
- package/dist/typeahead-XN6lZ7G9.d.mts +45 -0
- package/dist/types-BivBkYg9.d.cts +57 -0
- package/dist/types-Bl_6JtPQ.d.mts +57 -0
- package/dist/types-CPUMVt7c.d.mts +54 -0
- package/dist/types-CT_W6HWr.d.cts +54 -0
- package/dist/types-DDTcG99l.d.mts +201 -0
- package/dist/types-DejIu60O.d.cts +201 -0
- package/dist/types-DiIdKZ3K.d.cts +45 -0
- package/dist/types-GxLIgJib.d.cts +17 -0
- package/dist/types.cjs +15 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +14 -0
- package/dist/utils-BZyrxWWR.mjs +525 -0
- package/dist/utils-_6frwjgJ.cjs +1040 -0
- package/dist/utils.cjs +88 -0
- package/dist/utils.d.cts +144 -0
- package/dist/utils.d.mts +144 -0
- package/dist/utils.mjs +3 -0
- package/dist/wait-for-CMjPsqWk.d.cts +10 -0
- package/dist/wait-for-D2nkdD4z.d.mts +10 -0
- package/package.json +399 -0
|
@@ -0,0 +1,1514 @@
|
|
|
1
|
+
import { t as createAnatomy } from "../../create-anatomy-BbDZbHpC.mjs";
|
|
2
|
+
import { E as disableTextSelection, S as queryAll, T as trackPointerMove, U as raf, W as getInitialFocus, at as setElementValue, bt as isModifierKey, dt as getEventStep, i as visuallyHiddenStyle, k as getRelativePoint, lt as getEventKey, ot as trackFormControl, rt as dispatchInputValueEvent, ut as getEventPoint, vn as dataAttr, x as query, yt as isLeftClick } from "../../dom-query-DFCRhyj1.mjs";
|
|
3
|
+
import { Q as tryCatch, u as createSplitProps } from "../../utils-BZyrxWWR.mjs";
|
|
4
|
+
import { i as getColorAreaGradient, n as parseColor, t as normalizeColor } from "../../color-utils-Cc5GVXZh.mjs";
|
|
5
|
+
import { a as createMachine, i as createGuards } from "../../core-DCFNMTZF.mjs";
|
|
6
|
+
import "../../interact-outside-BplxR9cR.mjs";
|
|
7
|
+
import { n as trackDismissableElement } from "../../dismissable-DDrx0xnH.mjs";
|
|
8
|
+
import { n as getPlacement, t as getPlacementStyles } from "../../popper-BPJeAtcA.mjs";
|
|
9
|
+
import { t as createProps } from "../../create-props-BnF_vl-E.mjs";
|
|
10
|
+
|
|
11
|
+
//#region src/machines/color-picker/color-picker.anatomy.ts
|
|
12
|
+
const anatomy = createAnatomy("color-picker", [
|
|
13
|
+
"root",
|
|
14
|
+
"label",
|
|
15
|
+
"control",
|
|
16
|
+
"trigger",
|
|
17
|
+
"positioner",
|
|
18
|
+
"content",
|
|
19
|
+
"area",
|
|
20
|
+
"areaThumb",
|
|
21
|
+
"valueText",
|
|
22
|
+
"areaBackground",
|
|
23
|
+
"channelSlider",
|
|
24
|
+
"channelSliderLabel",
|
|
25
|
+
"channelSliderTrack",
|
|
26
|
+
"channelSliderThumb",
|
|
27
|
+
"channelSliderValueText",
|
|
28
|
+
"channelInput",
|
|
29
|
+
"transparencyGrid",
|
|
30
|
+
"swatchGroup",
|
|
31
|
+
"swatchTrigger",
|
|
32
|
+
"swatchIndicator",
|
|
33
|
+
"swatch",
|
|
34
|
+
"eyeDropperTrigger",
|
|
35
|
+
"formatTrigger",
|
|
36
|
+
"formatSelect"
|
|
37
|
+
]);
|
|
38
|
+
const parts = anatomy.build();
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/machines/color-picker/color-picker.dom.ts
|
|
42
|
+
const getRootId = (ctx) => ctx.ids?.root ?? `color-picker:${ctx.id}`;
|
|
43
|
+
const getLabelId = (ctx) => ctx.ids?.label ?? `color-picker:${ctx.id}:label`;
|
|
44
|
+
const getHiddenInputId = (ctx) => ctx.ids?.hiddenInput ?? `color-picker:${ctx.id}:hidden-input`;
|
|
45
|
+
const getControlId = (ctx) => ctx.ids?.control ?? `color-picker:${ctx.id}:control`;
|
|
46
|
+
const getTriggerId = (ctx) => ctx.ids?.trigger ?? `color-picker:${ctx.id}:trigger`;
|
|
47
|
+
const getContentId = (ctx) => ctx.ids?.content ?? `color-picker:${ctx.id}:content`;
|
|
48
|
+
const getPositionerId = (ctx) => ctx.ids?.positioner ?? `color-picker:${ctx.id}:positioner`;
|
|
49
|
+
const getFormatSelectId = (ctx) => ctx.ids?.formatSelect ?? `color-picker:${ctx.id}:format-select`;
|
|
50
|
+
const getAreaId = (ctx) => ctx.ids?.area ?? `color-picker:${ctx.id}:area`;
|
|
51
|
+
const getAreaGradientId = (ctx) => ctx.ids?.areaGradient ?? `color-picker:${ctx.id}:area-gradient`;
|
|
52
|
+
const getAreaThumbId = (ctx) => ctx.ids?.areaThumb ?? `color-picker:${ctx.id}:area-thumb`;
|
|
53
|
+
const getChannelSliderTrackId = (ctx, channel) => ctx.ids?.channelSliderTrack?.(channel) ?? `color-picker:${ctx.id}:slider-track:${channel}`;
|
|
54
|
+
const getChannelSliderThumbId = (ctx, channel) => ctx.ids?.channelSliderThumb?.(channel) ?? `color-picker:${ctx.id}:slider-thumb:${channel}`;
|
|
55
|
+
const getContentEl = (ctx) => ctx.getById(getContentId(ctx));
|
|
56
|
+
const getAreaThumbEl = (ctx) => ctx.getById(getAreaThumbId(ctx));
|
|
57
|
+
const getChannelSliderThumbEl = (ctx, channel) => ctx.getById(getChannelSliderThumbId(ctx, channel));
|
|
58
|
+
const getFormatSelectEl = (ctx) => ctx.getById(getFormatSelectId(ctx));
|
|
59
|
+
const getHiddenInputEl = (ctx) => ctx.getById(getHiddenInputId(ctx));
|
|
60
|
+
const getAreaEl = (ctx) => ctx.getById(getAreaId(ctx));
|
|
61
|
+
const getAreaValueFromPoint = (ctx, point, dir) => {
|
|
62
|
+
const areaEl = getAreaEl(ctx);
|
|
63
|
+
if (!areaEl) return;
|
|
64
|
+
const { getPercentValue } = getRelativePoint(point, areaEl);
|
|
65
|
+
return {
|
|
66
|
+
x: getPercentValue({
|
|
67
|
+
dir,
|
|
68
|
+
orientation: "horizontal"
|
|
69
|
+
}),
|
|
70
|
+
y: getPercentValue({ orientation: "vertical" })
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
const getControlEl = (ctx) => ctx.getById(getControlId(ctx));
|
|
74
|
+
const getTriggerEl = (ctx) => ctx.getById(getTriggerId(ctx));
|
|
75
|
+
const getPositionerEl = (ctx) => ctx.getById(getPositionerId(ctx));
|
|
76
|
+
const getChannelSliderTrackEl = (ctx, channel) => ctx.getById(getChannelSliderTrackId(ctx, channel));
|
|
77
|
+
const getChannelSliderValueFromPoint = (ctx, point, channel, dir) => {
|
|
78
|
+
const trackEl = getChannelSliderTrackEl(ctx, channel);
|
|
79
|
+
if (!trackEl) return;
|
|
80
|
+
const { getPercentValue } = getRelativePoint(point, trackEl);
|
|
81
|
+
return {
|
|
82
|
+
x: getPercentValue({
|
|
83
|
+
dir,
|
|
84
|
+
orientation: "horizontal"
|
|
85
|
+
}),
|
|
86
|
+
y: getPercentValue({ orientation: "vertical" })
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const getChannelInputEls = (ctx) => {
|
|
90
|
+
return [...queryAll(getContentEl(ctx), "input[data-channel]"), ...queryAll(getControlEl(ctx), "input[data-channel]")];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/machines/color-picker/utils/get-channel-display-color.ts
|
|
95
|
+
function getChannelDisplayColor(color, channel) {
|
|
96
|
+
switch (channel) {
|
|
97
|
+
case "hue": return parseColor(`hsl(${color.getChannelValue("hue")}, 100%, 50%)`);
|
|
98
|
+
case "lightness":
|
|
99
|
+
case "brightness":
|
|
100
|
+
case "saturation":
|
|
101
|
+
case "red":
|
|
102
|
+
case "green":
|
|
103
|
+
case "blue": return color.withChannelValue("alpha", 1);
|
|
104
|
+
case "alpha": return color;
|
|
105
|
+
default: throw new Error("Unknown color channel: " + channel);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/machines/color-picker/utils/get-channel-input-value.ts
|
|
111
|
+
function getChannelValue(color, channel) {
|
|
112
|
+
if (channel == null) return "";
|
|
113
|
+
if (channel === "hex") return color.toString("hex");
|
|
114
|
+
if (channel === "css") return color.toString("css");
|
|
115
|
+
if (channel in color) return color.getChannelValue(channel).toString();
|
|
116
|
+
const isHSL = color.getFormat() === "hsla";
|
|
117
|
+
switch (channel) {
|
|
118
|
+
case "hue": return isHSL ? color.toFormat("hsla").getChannelValue("hue").toString() : color.toFormat("hsba").getChannelValue("hue").toString();
|
|
119
|
+
case "saturation": return isHSL ? color.toFormat("hsla").getChannelValue("saturation").toString() : color.toFormat("hsba").getChannelValue("saturation").toString();
|
|
120
|
+
case "lightness": return color.toFormat("hsla").getChannelValue("lightness").toString();
|
|
121
|
+
case "brightness": return color.toFormat("hsba").getChannelValue("brightness").toString();
|
|
122
|
+
case "red":
|
|
123
|
+
case "green":
|
|
124
|
+
case "blue": return color.toFormat("rgba").getChannelValue(channel).toString();
|
|
125
|
+
default: return color.getChannelValue(channel).toString();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function getChannelRange(color, channel) {
|
|
129
|
+
switch (channel) {
|
|
130
|
+
case "hex":
|
|
131
|
+
const minColor = parseColor("#000000");
|
|
132
|
+
const maxColor = parseColor("#FFFFFF");
|
|
133
|
+
return {
|
|
134
|
+
minValue: minColor.toHexInt(),
|
|
135
|
+
maxValue: maxColor.toHexInt(),
|
|
136
|
+
pageSize: 10,
|
|
137
|
+
step: 1
|
|
138
|
+
};
|
|
139
|
+
case "css": return;
|
|
140
|
+
case "hue":
|
|
141
|
+
case "saturation":
|
|
142
|
+
case "lightness": return color.toFormat("hsla").getChannelRange(channel);
|
|
143
|
+
case "brightness": return color.toFormat("hsba").getChannelRange(channel);
|
|
144
|
+
case "red":
|
|
145
|
+
case "green":
|
|
146
|
+
case "blue": return color.toFormat("rgba").getChannelRange(channel);
|
|
147
|
+
default: return color.getChannelRange(channel);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/machines/color-picker/utils/get-slider-background.ts
|
|
153
|
+
function getSliderBackgroundDirection(orientation, dir) {
|
|
154
|
+
if (orientation === "vertical") return "top";
|
|
155
|
+
else if (dir === "ltr") return "right";
|
|
156
|
+
else return "left";
|
|
157
|
+
}
|
|
158
|
+
const getSliderBackground = (props$1) => {
|
|
159
|
+
const { channel, value, dir, orientation } = props$1;
|
|
160
|
+
const bgDirection = getSliderBackgroundDirection(orientation, dir);
|
|
161
|
+
const { minValue, maxValue } = value.getChannelRange(channel);
|
|
162
|
+
switch (channel) {
|
|
163
|
+
case "hue": return `linear-gradient(to ${bgDirection}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
|
|
164
|
+
case "lightness": return `linear-gradient(to ${bgDirection}, ${value.withChannelValue(channel, minValue).toString("css")}, ${value.withChannelValue(channel, (maxValue - minValue) / 2).toString("css")}, ${value.withChannelValue(channel, maxValue).toString("css")})`;
|
|
165
|
+
case "saturation":
|
|
166
|
+
case "brightness":
|
|
167
|
+
case "red":
|
|
168
|
+
case "green":
|
|
169
|
+
case "blue":
|
|
170
|
+
case "alpha": return `linear-gradient(to ${bgDirection}, ${value.withChannelValue(channel, minValue).toString("css")}, ${value.withChannelValue(channel, maxValue).toString("css")})`;
|
|
171
|
+
default: throw new Error("Unknown color channel: " + channel);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/machines/color-picker/color-picker.connect.ts
|
|
177
|
+
function connect(service, normalize) {
|
|
178
|
+
const { context, send, prop, computed, state, scope } = service;
|
|
179
|
+
const value = context.get("value");
|
|
180
|
+
const format = context.get("format");
|
|
181
|
+
const areaValue = computed("areaValue");
|
|
182
|
+
const valueAsString = computed("valueAsString");
|
|
183
|
+
const disabled = computed("disabled");
|
|
184
|
+
const readOnly = !!prop("readOnly");
|
|
185
|
+
const invalid = !!prop("invalid");
|
|
186
|
+
const required = !!prop("required");
|
|
187
|
+
const interactive = computed("interactive");
|
|
188
|
+
const dragging = state.hasTag("dragging");
|
|
189
|
+
const open = state.hasTag("open");
|
|
190
|
+
const focused = state.hasTag("focused");
|
|
191
|
+
const getAreaChannels = (props$1) => {
|
|
192
|
+
const channels = areaValue.getChannels();
|
|
193
|
+
return {
|
|
194
|
+
xChannel: props$1.xChannel ?? channels[1],
|
|
195
|
+
yChannel: props$1.yChannel ?? channels[2]
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
const currentPlacement = context.get("currentPlacement");
|
|
199
|
+
const popperStyles = getPlacementStyles({
|
|
200
|
+
...prop("positioning"),
|
|
201
|
+
placement: currentPlacement
|
|
202
|
+
});
|
|
203
|
+
function getSwatchTriggerState(props$1) {
|
|
204
|
+
const color = normalizeColor(props$1.value).toFormat(context.get("format"));
|
|
205
|
+
return {
|
|
206
|
+
value: color,
|
|
207
|
+
valueAsString: color.toString("hex"),
|
|
208
|
+
checked: color.isEqual(value),
|
|
209
|
+
disabled: props$1.disabled || !interactive
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
dragging,
|
|
214
|
+
open,
|
|
215
|
+
valueAsString,
|
|
216
|
+
value,
|
|
217
|
+
inline: !!prop("inline"),
|
|
218
|
+
setOpen(nextOpen) {
|
|
219
|
+
if (prop("inline")) return;
|
|
220
|
+
if (state.hasTag("open") === nextOpen) return;
|
|
221
|
+
send({ type: nextOpen ? "OPEN" : "CLOSE" });
|
|
222
|
+
},
|
|
223
|
+
setValue(value$1) {
|
|
224
|
+
send({
|
|
225
|
+
type: "VALUE.SET",
|
|
226
|
+
value: normalizeColor(value$1),
|
|
227
|
+
src: "set-color"
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
getChannelValue(channel) {
|
|
231
|
+
return getChannelValue(value, channel);
|
|
232
|
+
},
|
|
233
|
+
getChannelValueText(channel, locale) {
|
|
234
|
+
return value.formatChannelValue(channel, locale);
|
|
235
|
+
},
|
|
236
|
+
setChannelValue(channel, channelValue) {
|
|
237
|
+
send({
|
|
238
|
+
type: "VALUE.SET",
|
|
239
|
+
value: value.withChannelValue(channel, channelValue),
|
|
240
|
+
src: "set-channel"
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
format: context.get("format"),
|
|
244
|
+
setFormat(format$1) {
|
|
245
|
+
send({
|
|
246
|
+
type: "VALUE.SET",
|
|
247
|
+
value: value.toFormat(format$1),
|
|
248
|
+
src: "set-format"
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
alpha: value.getChannelValue("alpha"),
|
|
252
|
+
setAlpha(alphaValue) {
|
|
253
|
+
send({
|
|
254
|
+
type: "VALUE.SET",
|
|
255
|
+
value: value.withChannelValue("alpha", alphaValue),
|
|
256
|
+
src: "set-alpha"
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
getRootProps() {
|
|
260
|
+
return normalize.element({
|
|
261
|
+
...parts.root.attrs,
|
|
262
|
+
dir: prop("dir"),
|
|
263
|
+
id: getRootId(scope),
|
|
264
|
+
"data-disabled": dataAttr(disabled),
|
|
265
|
+
"data-readonly": dataAttr(readOnly),
|
|
266
|
+
"data-invalid": dataAttr(invalid),
|
|
267
|
+
style: { "--value": value.toString("css") }
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
getLabelProps() {
|
|
271
|
+
return normalize.element({
|
|
272
|
+
...parts.label.attrs,
|
|
273
|
+
dir: prop("dir"),
|
|
274
|
+
id: getLabelId(scope),
|
|
275
|
+
htmlFor: getHiddenInputId(scope),
|
|
276
|
+
"data-disabled": dataAttr(disabled),
|
|
277
|
+
"data-readonly": dataAttr(readOnly),
|
|
278
|
+
"data-invalid": dataAttr(invalid),
|
|
279
|
+
"data-required": dataAttr(required),
|
|
280
|
+
"data-focus": dataAttr(focused),
|
|
281
|
+
onClick(event) {
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
query(getControlEl(scope), "[data-channel=hex]")?.focus({ preventScroll: true });
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
getControlProps() {
|
|
288
|
+
return normalize.element({
|
|
289
|
+
...parts.control.attrs,
|
|
290
|
+
id: getControlId(scope),
|
|
291
|
+
dir: prop("dir"),
|
|
292
|
+
"data-disabled": dataAttr(disabled),
|
|
293
|
+
"data-readonly": dataAttr(readOnly),
|
|
294
|
+
"data-invalid": dataAttr(invalid),
|
|
295
|
+
"data-state": open ? "open" : "closed",
|
|
296
|
+
"data-focus": dataAttr(focused)
|
|
297
|
+
});
|
|
298
|
+
},
|
|
299
|
+
getTriggerProps() {
|
|
300
|
+
return normalize.button({
|
|
301
|
+
...parts.trigger.attrs,
|
|
302
|
+
id: getTriggerId(scope),
|
|
303
|
+
dir: prop("dir"),
|
|
304
|
+
disabled,
|
|
305
|
+
"aria-label": `select color. current color is ${valueAsString}`,
|
|
306
|
+
"aria-controls": getContentId(scope),
|
|
307
|
+
"aria-labelledby": getLabelId(scope),
|
|
308
|
+
"aria-haspopup": prop("inline") ? void 0 : "dialog",
|
|
309
|
+
"data-disabled": dataAttr(disabled),
|
|
310
|
+
"data-readonly": dataAttr(readOnly),
|
|
311
|
+
"data-invalid": dataAttr(invalid),
|
|
312
|
+
"data-placement": currentPlacement,
|
|
313
|
+
"aria-expanded": open,
|
|
314
|
+
"data-state": open ? "open" : "closed",
|
|
315
|
+
"data-focus": dataAttr(focused),
|
|
316
|
+
type: "button",
|
|
317
|
+
onClick() {
|
|
318
|
+
if (!interactive) return;
|
|
319
|
+
send({ type: "TRIGGER.CLICK" });
|
|
320
|
+
},
|
|
321
|
+
onBlur() {
|
|
322
|
+
if (!interactive) return;
|
|
323
|
+
send({ type: "TRIGGER.BLUR" });
|
|
324
|
+
},
|
|
325
|
+
style: { position: "relative" }
|
|
326
|
+
});
|
|
327
|
+
},
|
|
328
|
+
getPositionerProps() {
|
|
329
|
+
return normalize.element({
|
|
330
|
+
...parts.positioner.attrs,
|
|
331
|
+
id: getPositionerId(scope),
|
|
332
|
+
dir: prop("dir"),
|
|
333
|
+
style: popperStyles.floating
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
getContentProps() {
|
|
337
|
+
return normalize.element({
|
|
338
|
+
...parts.content.attrs,
|
|
339
|
+
id: getContentId(scope),
|
|
340
|
+
dir: prop("dir"),
|
|
341
|
+
role: prop("inline") ? void 0 : "dialog",
|
|
342
|
+
tabIndex: -1,
|
|
343
|
+
"data-placement": currentPlacement,
|
|
344
|
+
"data-state": open ? "open" : "closed",
|
|
345
|
+
hidden: !open
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
getValueTextProps() {
|
|
349
|
+
return normalize.element({
|
|
350
|
+
...parts.valueText.attrs,
|
|
351
|
+
dir: prop("dir"),
|
|
352
|
+
"data-disabled": dataAttr(disabled),
|
|
353
|
+
"data-focus": dataAttr(focused)
|
|
354
|
+
});
|
|
355
|
+
},
|
|
356
|
+
getAreaProps(props$1 = {}) {
|
|
357
|
+
const { xChannel, yChannel } = getAreaChannels(props$1);
|
|
358
|
+
const { areaStyles } = getColorAreaGradient(areaValue, {
|
|
359
|
+
xChannel,
|
|
360
|
+
yChannel,
|
|
361
|
+
dir: prop("dir")
|
|
362
|
+
});
|
|
363
|
+
return normalize.element({
|
|
364
|
+
...parts.area.attrs,
|
|
365
|
+
id: getAreaId(scope),
|
|
366
|
+
role: "group",
|
|
367
|
+
"data-invalid": dataAttr(invalid),
|
|
368
|
+
"data-disabled": dataAttr(disabled),
|
|
369
|
+
"data-readonly": dataAttr(readOnly),
|
|
370
|
+
onPointerDown(event) {
|
|
371
|
+
if (!interactive) return;
|
|
372
|
+
if (!isLeftClick(event)) return;
|
|
373
|
+
if (isModifierKey(event)) return;
|
|
374
|
+
send({
|
|
375
|
+
type: "AREA.POINTER_DOWN",
|
|
376
|
+
point: getEventPoint(event),
|
|
377
|
+
channel: {
|
|
378
|
+
xChannel,
|
|
379
|
+
yChannel
|
|
380
|
+
},
|
|
381
|
+
id: "area"
|
|
382
|
+
});
|
|
383
|
+
event.preventDefault();
|
|
384
|
+
},
|
|
385
|
+
style: {
|
|
386
|
+
position: "relative",
|
|
387
|
+
touchAction: "none",
|
|
388
|
+
forcedColorAdjust: "none",
|
|
389
|
+
...areaStyles
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
},
|
|
393
|
+
getAreaBackgroundProps(props$1 = {}) {
|
|
394
|
+
const { xChannel, yChannel } = getAreaChannels(props$1);
|
|
395
|
+
const { areaGradientStyles } = getColorAreaGradient(areaValue, {
|
|
396
|
+
xChannel,
|
|
397
|
+
yChannel,
|
|
398
|
+
dir: prop("dir")
|
|
399
|
+
});
|
|
400
|
+
return normalize.element({
|
|
401
|
+
...parts.areaBackground.attrs,
|
|
402
|
+
id: getAreaGradientId(scope),
|
|
403
|
+
"data-invalid": dataAttr(invalid),
|
|
404
|
+
"data-disabled": dataAttr(disabled),
|
|
405
|
+
"data-readonly": dataAttr(readOnly),
|
|
406
|
+
style: {
|
|
407
|
+
position: "relative",
|
|
408
|
+
touchAction: "none",
|
|
409
|
+
forcedColorAdjust: "none",
|
|
410
|
+
...areaGradientStyles
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
},
|
|
414
|
+
getAreaThumbProps(props$1 = {}) {
|
|
415
|
+
const { xChannel, yChannel } = getAreaChannels(props$1);
|
|
416
|
+
const channel = {
|
|
417
|
+
xChannel,
|
|
418
|
+
yChannel
|
|
419
|
+
};
|
|
420
|
+
const xPercent = areaValue.getChannelValuePercent(xChannel);
|
|
421
|
+
const yPercent = 1 - areaValue.getChannelValuePercent(yChannel);
|
|
422
|
+
const finalXPercent = prop("dir") === "rtl" ? 1 - xPercent : xPercent;
|
|
423
|
+
const xValue = areaValue.getChannelValue(xChannel);
|
|
424
|
+
const yValue = areaValue.getChannelValue(yChannel);
|
|
425
|
+
const color = areaValue.withChannelValue("alpha", 1).toString("css");
|
|
426
|
+
return normalize.element({
|
|
427
|
+
...parts.areaThumb.attrs,
|
|
428
|
+
id: getAreaThumbId(scope),
|
|
429
|
+
dir: prop("dir"),
|
|
430
|
+
tabIndex: disabled ? void 0 : 0,
|
|
431
|
+
"data-disabled": dataAttr(disabled),
|
|
432
|
+
"data-invalid": dataAttr(invalid),
|
|
433
|
+
"data-readonly": dataAttr(readOnly),
|
|
434
|
+
role: "slider",
|
|
435
|
+
"aria-valuemin": 0,
|
|
436
|
+
"aria-valuemax": 100,
|
|
437
|
+
"aria-valuenow": xValue,
|
|
438
|
+
"aria-label": `${xChannel} and ${yChannel}`,
|
|
439
|
+
"aria-roledescription": "2d slider",
|
|
440
|
+
"aria-valuetext": `${xChannel} ${xValue}, ${yChannel} ${yValue}`,
|
|
441
|
+
style: {
|
|
442
|
+
position: "absolute",
|
|
443
|
+
left: `${finalXPercent * 100}%`,
|
|
444
|
+
top: `${yPercent * 100}%`,
|
|
445
|
+
transform: "translate(-50%, -50%)",
|
|
446
|
+
touchAction: "none",
|
|
447
|
+
forcedColorAdjust: "none",
|
|
448
|
+
"--color": color,
|
|
449
|
+
background: color
|
|
450
|
+
},
|
|
451
|
+
onFocus() {
|
|
452
|
+
if (!interactive) return;
|
|
453
|
+
send({
|
|
454
|
+
type: "AREA.FOCUS",
|
|
455
|
+
id: "area",
|
|
456
|
+
channel
|
|
457
|
+
});
|
|
458
|
+
},
|
|
459
|
+
onKeyDown(event) {
|
|
460
|
+
if (event.defaultPrevented) return;
|
|
461
|
+
if (!interactive) return;
|
|
462
|
+
const step = getEventStep(event);
|
|
463
|
+
const exec = {
|
|
464
|
+
ArrowUp() {
|
|
465
|
+
send({
|
|
466
|
+
type: "AREA.ARROW_UP",
|
|
467
|
+
channel,
|
|
468
|
+
step
|
|
469
|
+
});
|
|
470
|
+
},
|
|
471
|
+
ArrowDown() {
|
|
472
|
+
send({
|
|
473
|
+
type: "AREA.ARROW_DOWN",
|
|
474
|
+
channel,
|
|
475
|
+
step
|
|
476
|
+
});
|
|
477
|
+
},
|
|
478
|
+
ArrowLeft() {
|
|
479
|
+
send({
|
|
480
|
+
type: "AREA.ARROW_LEFT",
|
|
481
|
+
channel,
|
|
482
|
+
step
|
|
483
|
+
});
|
|
484
|
+
},
|
|
485
|
+
ArrowRight() {
|
|
486
|
+
send({
|
|
487
|
+
type: "AREA.ARROW_RIGHT",
|
|
488
|
+
channel,
|
|
489
|
+
step
|
|
490
|
+
});
|
|
491
|
+
},
|
|
492
|
+
PageUp() {
|
|
493
|
+
send({
|
|
494
|
+
type: "AREA.PAGE_UP",
|
|
495
|
+
channel,
|
|
496
|
+
step
|
|
497
|
+
});
|
|
498
|
+
},
|
|
499
|
+
PageDown() {
|
|
500
|
+
send({
|
|
501
|
+
type: "AREA.PAGE_DOWN",
|
|
502
|
+
channel,
|
|
503
|
+
step
|
|
504
|
+
});
|
|
505
|
+
},
|
|
506
|
+
Escape(event$1) {
|
|
507
|
+
event$1.stopPropagation();
|
|
508
|
+
}
|
|
509
|
+
}[getEventKey(event, { dir: prop("dir") })];
|
|
510
|
+
if (exec) {
|
|
511
|
+
exec(event);
|
|
512
|
+
event.preventDefault();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
},
|
|
517
|
+
getTransparencyGridProps(props$1 = {}) {
|
|
518
|
+
const { size = "12px" } = props$1;
|
|
519
|
+
return normalize.element({
|
|
520
|
+
...parts.transparencyGrid.attrs,
|
|
521
|
+
style: {
|
|
522
|
+
"--size": size,
|
|
523
|
+
width: "100%",
|
|
524
|
+
height: "100%",
|
|
525
|
+
position: "absolute",
|
|
526
|
+
backgroundColor: "#fff",
|
|
527
|
+
backgroundImage: "conic-gradient(#eeeeee 0 25%, transparent 0 50%, #eeeeee 0 75%, transparent 0)",
|
|
528
|
+
backgroundSize: "var(--size) var(--size)",
|
|
529
|
+
inset: "0px",
|
|
530
|
+
zIndex: "auto",
|
|
531
|
+
pointerEvents: "none"
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
},
|
|
535
|
+
getChannelSliderProps(props$1) {
|
|
536
|
+
const { orientation = "horizontal", channel, format: format$1 } = props$1;
|
|
537
|
+
return normalize.element({
|
|
538
|
+
...parts.channelSlider.attrs,
|
|
539
|
+
"data-channel": channel,
|
|
540
|
+
"data-orientation": orientation,
|
|
541
|
+
role: "presentation",
|
|
542
|
+
onPointerDown(event) {
|
|
543
|
+
if (!interactive) return;
|
|
544
|
+
if (!isLeftClick(event)) return;
|
|
545
|
+
if (isModifierKey(event)) return;
|
|
546
|
+
send({
|
|
547
|
+
type: "CHANNEL_SLIDER.POINTER_DOWN",
|
|
548
|
+
channel,
|
|
549
|
+
format: format$1,
|
|
550
|
+
point: getEventPoint(event),
|
|
551
|
+
id: channel,
|
|
552
|
+
orientation
|
|
553
|
+
});
|
|
554
|
+
event.preventDefault();
|
|
555
|
+
},
|
|
556
|
+
style: {
|
|
557
|
+
position: "relative",
|
|
558
|
+
touchAction: "none"
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
},
|
|
562
|
+
getChannelSliderTrackProps(props$1) {
|
|
563
|
+
const { orientation = "horizontal", channel, format: format$1 } = props$1;
|
|
564
|
+
const normalizedValue = format$1 ? value.toFormat(format$1) : areaValue;
|
|
565
|
+
return normalize.element({
|
|
566
|
+
...parts.channelSliderTrack.attrs,
|
|
567
|
+
id: getChannelSliderTrackId(scope, channel),
|
|
568
|
+
role: "group",
|
|
569
|
+
"data-channel": channel,
|
|
570
|
+
"data-orientation": orientation,
|
|
571
|
+
style: {
|
|
572
|
+
position: "relative",
|
|
573
|
+
forcedColorAdjust: "none",
|
|
574
|
+
backgroundImage: getSliderBackground({
|
|
575
|
+
orientation,
|
|
576
|
+
channel,
|
|
577
|
+
dir: prop("dir"),
|
|
578
|
+
value: normalizedValue
|
|
579
|
+
})
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
},
|
|
583
|
+
getChannelSliderLabelProps(props$1) {
|
|
584
|
+
const { channel } = props$1;
|
|
585
|
+
return normalize.element({
|
|
586
|
+
...parts.channelSliderLabel.attrs,
|
|
587
|
+
"data-channel": channel,
|
|
588
|
+
onClick(event) {
|
|
589
|
+
if (!interactive) return;
|
|
590
|
+
event.preventDefault();
|
|
591
|
+
const thumbId = getChannelSliderThumbId(scope, channel);
|
|
592
|
+
scope.getById(thumbId)?.focus({ preventScroll: true });
|
|
593
|
+
},
|
|
594
|
+
style: {
|
|
595
|
+
userSelect: "none",
|
|
596
|
+
WebkitUserSelect: "none"
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
},
|
|
600
|
+
getChannelSliderValueTextProps(props$1) {
|
|
601
|
+
return normalize.element({
|
|
602
|
+
...parts.channelSliderValueText.attrs,
|
|
603
|
+
"data-channel": props$1.channel
|
|
604
|
+
});
|
|
605
|
+
},
|
|
606
|
+
getChannelSliderThumbProps(props$1) {
|
|
607
|
+
const { orientation = "horizontal", channel, format: format$1 } = props$1;
|
|
608
|
+
const normalizedValue = format$1 ? value.toFormat(format$1) : areaValue;
|
|
609
|
+
const channelRange = normalizedValue.getChannelRange(channel);
|
|
610
|
+
const channelValue = normalizedValue.getChannelValue(channel);
|
|
611
|
+
const offset = (channelValue - channelRange.minValue) / (channelRange.maxValue - channelRange.minValue);
|
|
612
|
+
const isRtl = prop("dir") === "rtl";
|
|
613
|
+
const finalOffset = orientation === "horizontal" && isRtl ? 1 - offset : offset;
|
|
614
|
+
const placementStyles = orientation === "horizontal" ? {
|
|
615
|
+
left: `${finalOffset * 100}%`,
|
|
616
|
+
top: "50%"
|
|
617
|
+
} : {
|
|
618
|
+
top: `${offset * 100}%`,
|
|
619
|
+
left: "50%"
|
|
620
|
+
};
|
|
621
|
+
return normalize.element({
|
|
622
|
+
...parts.channelSliderThumb.attrs,
|
|
623
|
+
id: getChannelSliderThumbId(scope, channel),
|
|
624
|
+
role: "slider",
|
|
625
|
+
"aria-label": channel,
|
|
626
|
+
tabIndex: disabled ? void 0 : 0,
|
|
627
|
+
"data-channel": channel,
|
|
628
|
+
"data-disabled": dataAttr(disabled),
|
|
629
|
+
"data-orientation": orientation,
|
|
630
|
+
"aria-disabled": dataAttr(disabled),
|
|
631
|
+
"aria-orientation": orientation,
|
|
632
|
+
"aria-valuemax": channelRange.maxValue,
|
|
633
|
+
"aria-valuemin": channelRange.minValue,
|
|
634
|
+
"aria-valuenow": channelValue,
|
|
635
|
+
"aria-valuetext": `${channel} ${channelValue}`,
|
|
636
|
+
style: {
|
|
637
|
+
forcedColorAdjust: "none",
|
|
638
|
+
position: "absolute",
|
|
639
|
+
background: getChannelDisplayColor(areaValue, channel).toString("css"),
|
|
640
|
+
...placementStyles
|
|
641
|
+
},
|
|
642
|
+
onFocus() {
|
|
643
|
+
if (!interactive) return;
|
|
644
|
+
send({
|
|
645
|
+
type: "CHANNEL_SLIDER.FOCUS",
|
|
646
|
+
channel
|
|
647
|
+
});
|
|
648
|
+
},
|
|
649
|
+
onKeyDown(event) {
|
|
650
|
+
if (event.defaultPrevented) return;
|
|
651
|
+
if (!interactive) return;
|
|
652
|
+
const step = getEventStep(event) * channelRange.step;
|
|
653
|
+
const exec = {
|
|
654
|
+
ArrowUp() {
|
|
655
|
+
send({
|
|
656
|
+
type: "CHANNEL_SLIDER.ARROW_UP",
|
|
657
|
+
channel,
|
|
658
|
+
step
|
|
659
|
+
});
|
|
660
|
+
},
|
|
661
|
+
ArrowDown() {
|
|
662
|
+
send({
|
|
663
|
+
type: "CHANNEL_SLIDER.ARROW_DOWN",
|
|
664
|
+
channel,
|
|
665
|
+
step
|
|
666
|
+
});
|
|
667
|
+
},
|
|
668
|
+
ArrowLeft() {
|
|
669
|
+
send({
|
|
670
|
+
type: "CHANNEL_SLIDER.ARROW_LEFT",
|
|
671
|
+
channel,
|
|
672
|
+
step
|
|
673
|
+
});
|
|
674
|
+
},
|
|
675
|
+
ArrowRight() {
|
|
676
|
+
send({
|
|
677
|
+
type: "CHANNEL_SLIDER.ARROW_RIGHT",
|
|
678
|
+
channel,
|
|
679
|
+
step
|
|
680
|
+
});
|
|
681
|
+
},
|
|
682
|
+
PageUp() {
|
|
683
|
+
send({
|
|
684
|
+
type: "CHANNEL_SLIDER.PAGE_UP",
|
|
685
|
+
channel
|
|
686
|
+
});
|
|
687
|
+
},
|
|
688
|
+
PageDown() {
|
|
689
|
+
send({
|
|
690
|
+
type: "CHANNEL_SLIDER.PAGE_DOWN",
|
|
691
|
+
channel
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
Home() {
|
|
695
|
+
send({
|
|
696
|
+
type: "CHANNEL_SLIDER.HOME",
|
|
697
|
+
channel
|
|
698
|
+
});
|
|
699
|
+
},
|
|
700
|
+
End() {
|
|
701
|
+
send({
|
|
702
|
+
type: "CHANNEL_SLIDER.END",
|
|
703
|
+
channel
|
|
704
|
+
});
|
|
705
|
+
},
|
|
706
|
+
Escape(event$1) {
|
|
707
|
+
event$1.stopPropagation();
|
|
708
|
+
}
|
|
709
|
+
}[getEventKey(event, { dir: prop("dir") })];
|
|
710
|
+
if (exec) {
|
|
711
|
+
exec(event);
|
|
712
|
+
event.preventDefault();
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
},
|
|
717
|
+
getChannelInputProps(props$1) {
|
|
718
|
+
const { channel } = props$1;
|
|
719
|
+
const isTextField = channel === "hex" || channel === "css";
|
|
720
|
+
const channelRange = getChannelRange(value, channel);
|
|
721
|
+
return normalize.input({
|
|
722
|
+
...parts.channelInput.attrs,
|
|
723
|
+
dir: prop("dir"),
|
|
724
|
+
type: isTextField ? "text" : "number",
|
|
725
|
+
"data-channel": channel,
|
|
726
|
+
"aria-label": channel,
|
|
727
|
+
spellCheck: false,
|
|
728
|
+
autoComplete: "off",
|
|
729
|
+
disabled,
|
|
730
|
+
"data-disabled": dataAttr(disabled),
|
|
731
|
+
"data-invalid": dataAttr(invalid),
|
|
732
|
+
"data-readonly": dataAttr(readOnly),
|
|
733
|
+
readOnly,
|
|
734
|
+
defaultValue: getChannelValue(value, channel),
|
|
735
|
+
min: channelRange?.minValue,
|
|
736
|
+
max: channelRange?.maxValue,
|
|
737
|
+
step: channelRange?.step,
|
|
738
|
+
onBeforeInput(event) {
|
|
739
|
+
if (isTextField || !interactive) return;
|
|
740
|
+
if (event.currentTarget.value.match(/[^0-9.]/g)) event.preventDefault();
|
|
741
|
+
},
|
|
742
|
+
onFocus(event) {
|
|
743
|
+
if (!interactive) return;
|
|
744
|
+
send({
|
|
745
|
+
type: "CHANNEL_INPUT.FOCUS",
|
|
746
|
+
channel
|
|
747
|
+
});
|
|
748
|
+
event.currentTarget.select();
|
|
749
|
+
},
|
|
750
|
+
onBlur(event) {
|
|
751
|
+
if (!interactive) return;
|
|
752
|
+
send({
|
|
753
|
+
type: "CHANNEL_INPUT.BLUR",
|
|
754
|
+
channel,
|
|
755
|
+
value: isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber,
|
|
756
|
+
isTextField
|
|
757
|
+
});
|
|
758
|
+
},
|
|
759
|
+
onKeyDown(event) {
|
|
760
|
+
if (event.defaultPrevented) return;
|
|
761
|
+
if (!interactive) return;
|
|
762
|
+
if (event.key === "Enter") {
|
|
763
|
+
send({
|
|
764
|
+
type: "CHANNEL_INPUT.CHANGE",
|
|
765
|
+
channel,
|
|
766
|
+
value: isTextField ? event.currentTarget.value : event.currentTarget.valueAsNumber,
|
|
767
|
+
isTextField
|
|
768
|
+
});
|
|
769
|
+
event.preventDefault();
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
style: {
|
|
773
|
+
appearance: "none",
|
|
774
|
+
WebkitAppearance: "none",
|
|
775
|
+
MozAppearance: "textfield"
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
},
|
|
779
|
+
getHiddenInputProps() {
|
|
780
|
+
return normalize.input({
|
|
781
|
+
type: "text",
|
|
782
|
+
disabled,
|
|
783
|
+
name: prop("name"),
|
|
784
|
+
tabIndex: -1,
|
|
785
|
+
readOnly,
|
|
786
|
+
required,
|
|
787
|
+
id: getHiddenInputId(scope),
|
|
788
|
+
style: visuallyHiddenStyle,
|
|
789
|
+
defaultValue: valueAsString
|
|
790
|
+
});
|
|
791
|
+
},
|
|
792
|
+
getEyeDropperTriggerProps() {
|
|
793
|
+
return normalize.button({
|
|
794
|
+
...parts.eyeDropperTrigger.attrs,
|
|
795
|
+
type: "button",
|
|
796
|
+
dir: prop("dir"),
|
|
797
|
+
disabled,
|
|
798
|
+
"data-disabled": dataAttr(disabled),
|
|
799
|
+
"data-invalid": dataAttr(invalid),
|
|
800
|
+
"data-readonly": dataAttr(readOnly),
|
|
801
|
+
"aria-label": "Pick a color from the screen",
|
|
802
|
+
onClick() {
|
|
803
|
+
if (!interactive) return;
|
|
804
|
+
send({ type: "EYEDROPPER.CLICK" });
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
},
|
|
808
|
+
getSwatchGroupProps() {
|
|
809
|
+
return normalize.element({
|
|
810
|
+
...parts.swatchGroup.attrs,
|
|
811
|
+
role: "group"
|
|
812
|
+
});
|
|
813
|
+
},
|
|
814
|
+
getSwatchTriggerState,
|
|
815
|
+
getSwatchTriggerProps(props$1) {
|
|
816
|
+
const swatchState = getSwatchTriggerState(props$1);
|
|
817
|
+
return normalize.button({
|
|
818
|
+
...parts.swatchTrigger.attrs,
|
|
819
|
+
disabled: swatchState.disabled,
|
|
820
|
+
dir: prop("dir"),
|
|
821
|
+
type: "button",
|
|
822
|
+
"aria-label": `select ${swatchState.valueAsString} as the color`,
|
|
823
|
+
"data-state": swatchState.checked ? "checked" : "unchecked",
|
|
824
|
+
"data-value": swatchState.valueAsString,
|
|
825
|
+
"data-disabled": dataAttr(swatchState.disabled),
|
|
826
|
+
onClick() {
|
|
827
|
+
if (swatchState.disabled) return;
|
|
828
|
+
send({
|
|
829
|
+
type: "SWATCH_TRIGGER.CLICK",
|
|
830
|
+
value: swatchState.value
|
|
831
|
+
});
|
|
832
|
+
},
|
|
833
|
+
style: {
|
|
834
|
+
"--color": swatchState.valueAsString,
|
|
835
|
+
position: "relative"
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
},
|
|
839
|
+
getSwatchIndicatorProps(props$1) {
|
|
840
|
+
const swatchState = getSwatchTriggerState(props$1);
|
|
841
|
+
return normalize.element({
|
|
842
|
+
...parts.swatchIndicator.attrs,
|
|
843
|
+
dir: prop("dir"),
|
|
844
|
+
hidden: !swatchState.checked
|
|
845
|
+
});
|
|
846
|
+
},
|
|
847
|
+
getSwatchProps(props$1) {
|
|
848
|
+
const { respectAlpha = true } = props$1;
|
|
849
|
+
const swatchState = getSwatchTriggerState(props$1);
|
|
850
|
+
const color = swatchState.value.toString(respectAlpha ? "css" : "hex");
|
|
851
|
+
return normalize.element({
|
|
852
|
+
...parts.swatch.attrs,
|
|
853
|
+
dir: prop("dir"),
|
|
854
|
+
"data-state": swatchState.checked ? "checked" : "unchecked",
|
|
855
|
+
"data-value": swatchState.valueAsString,
|
|
856
|
+
style: {
|
|
857
|
+
"--color": color,
|
|
858
|
+
position: "relative",
|
|
859
|
+
background: color
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
},
|
|
863
|
+
getFormatTriggerProps() {
|
|
864
|
+
return normalize.button({
|
|
865
|
+
...parts.formatTrigger.attrs,
|
|
866
|
+
dir: prop("dir"),
|
|
867
|
+
type: "button",
|
|
868
|
+
"aria-label": `change color format to ${getNextFormat(format)}`,
|
|
869
|
+
onClick(event) {
|
|
870
|
+
if (event.currentTarget.disabled) return;
|
|
871
|
+
send({
|
|
872
|
+
type: "FORMAT.SET",
|
|
873
|
+
format: getNextFormat(format),
|
|
874
|
+
src: "format-trigger"
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
},
|
|
879
|
+
getFormatSelectProps() {
|
|
880
|
+
return normalize.select({
|
|
881
|
+
...parts.formatSelect.attrs,
|
|
882
|
+
"aria-label": "change color format",
|
|
883
|
+
dir: prop("dir"),
|
|
884
|
+
defaultValue: prop("format"),
|
|
885
|
+
disabled,
|
|
886
|
+
onChange(event) {
|
|
887
|
+
send({
|
|
888
|
+
type: "FORMAT.SET",
|
|
889
|
+
format: assertFormat(event.currentTarget.value),
|
|
890
|
+
src: "format-select"
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
const formats = [
|
|
898
|
+
"hsba",
|
|
899
|
+
"hsla",
|
|
900
|
+
"rgba"
|
|
901
|
+
];
|
|
902
|
+
const formatRegex = /* @__PURE__ */ new RegExp(`^(${formats.join("|")})$`);
|
|
903
|
+
function getNextFormat(format) {
|
|
904
|
+
return formats[formats.indexOf(format) + 1] ?? formats[0];
|
|
905
|
+
}
|
|
906
|
+
function assertFormat(format) {
|
|
907
|
+
if (formatRegex.test(format)) return format;
|
|
908
|
+
throw new Error(`Unsupported color format: ${format}`);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
//#endregion
|
|
912
|
+
//#region src/machines/color-picker/color-picker.parse.ts
|
|
913
|
+
const parse = (colorString) => {
|
|
914
|
+
return parseColor(colorString);
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
//#endregion
|
|
918
|
+
//#region src/machines/color-picker/utils/is-valid-hex.ts
|
|
919
|
+
const HEX_REGEX = /^[0-9a-fA-F]{3,8}$/;
|
|
920
|
+
function isValidHex(value) {
|
|
921
|
+
return HEX_REGEX.test(value);
|
|
922
|
+
}
|
|
923
|
+
function prefixHex(value) {
|
|
924
|
+
if (value.startsWith("#")) return value;
|
|
925
|
+
if (isValidHex(value)) return `#${value}`;
|
|
926
|
+
return value;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region src/machines/color-picker/color-picker.machine.ts
|
|
931
|
+
const { and } = createGuards();
|
|
932
|
+
const machine = createMachine({
|
|
933
|
+
props({ props: props$1 }) {
|
|
934
|
+
return {
|
|
935
|
+
dir: "ltr",
|
|
936
|
+
defaultValue: parse("#000000"),
|
|
937
|
+
defaultFormat: "rgba",
|
|
938
|
+
openAutoFocus: true,
|
|
939
|
+
...props$1,
|
|
940
|
+
positioning: {
|
|
941
|
+
placement: "bottom",
|
|
942
|
+
...props$1.positioning
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
},
|
|
946
|
+
initialState({ prop }) {
|
|
947
|
+
return prop("open") || prop("defaultOpen") || prop("inline") ? "open" : "idle";
|
|
948
|
+
},
|
|
949
|
+
context({ prop, bindable, getContext }) {
|
|
950
|
+
return {
|
|
951
|
+
value: bindable(() => ({
|
|
952
|
+
defaultValue: prop("defaultValue"),
|
|
953
|
+
value: prop("value"),
|
|
954
|
+
isEqual(a, b) {
|
|
955
|
+
return a.toString("css") === b?.toString("css");
|
|
956
|
+
},
|
|
957
|
+
hash(a) {
|
|
958
|
+
return a.toString("css");
|
|
959
|
+
},
|
|
960
|
+
onChange(value) {
|
|
961
|
+
const ctx = getContext();
|
|
962
|
+
const valueAsString = value.toString(ctx.get("format"));
|
|
963
|
+
prop("onValueChange")?.({
|
|
964
|
+
value,
|
|
965
|
+
valueAsString
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
})),
|
|
969
|
+
format: bindable(() => ({
|
|
970
|
+
defaultValue: prop("defaultFormat"),
|
|
971
|
+
value: prop("format"),
|
|
972
|
+
onChange(format) {
|
|
973
|
+
prop("onFormatChange")?.({ format });
|
|
974
|
+
}
|
|
975
|
+
})),
|
|
976
|
+
activeId: bindable(() => ({ defaultValue: null })),
|
|
977
|
+
activeChannel: bindable(() => ({ defaultValue: null })),
|
|
978
|
+
activeOrientation: bindable(() => ({ defaultValue: null })),
|
|
979
|
+
fieldsetDisabled: bindable(() => ({ defaultValue: false })),
|
|
980
|
+
restoreFocus: bindable(() => ({ defaultValue: true })),
|
|
981
|
+
currentPlacement: bindable(() => ({ defaultValue: void 0 }))
|
|
982
|
+
};
|
|
983
|
+
},
|
|
984
|
+
computed: {
|
|
985
|
+
rtl: ({ prop }) => prop("dir") === "rtl",
|
|
986
|
+
disabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
987
|
+
interactive: ({ prop }) => !(prop("disabled") || prop("readOnly")),
|
|
988
|
+
valueAsString: ({ context }) => context.get("value").toString(context.get("format")),
|
|
989
|
+
areaValue: ({ context }) => {
|
|
990
|
+
const format = context.get("format").startsWith("hsl") ? "hsla" : "hsba";
|
|
991
|
+
return context.get("value").toFormat(format);
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
effects: ["trackFormControl"],
|
|
995
|
+
watch({ prop, context, action, track }) {
|
|
996
|
+
track([() => context.hash("value")], () => {
|
|
997
|
+
action(["syncInputElements", "dispatchChangeEvent"]);
|
|
998
|
+
});
|
|
999
|
+
track([() => context.get("format")], () => {
|
|
1000
|
+
action(["syncFormatSelectElement"]);
|
|
1001
|
+
});
|
|
1002
|
+
track([() => prop("open")], () => {
|
|
1003
|
+
action(["toggleVisibility"]);
|
|
1004
|
+
});
|
|
1005
|
+
},
|
|
1006
|
+
on: {
|
|
1007
|
+
"VALUE.SET": { actions: ["setValue"] },
|
|
1008
|
+
"FORMAT.SET": { actions: ["setFormat"] },
|
|
1009
|
+
"CHANNEL_INPUT.CHANGE": { actions: ["setChannelColorFromInput"] },
|
|
1010
|
+
"EYEDROPPER.CLICK": { actions: ["openEyeDropper"] },
|
|
1011
|
+
"SWATCH_TRIGGER.CLICK": { actions: ["setValue"] }
|
|
1012
|
+
},
|
|
1013
|
+
states: {
|
|
1014
|
+
idle: {
|
|
1015
|
+
tags: ["closed"],
|
|
1016
|
+
on: {
|
|
1017
|
+
"CONTROLLED.OPEN": {
|
|
1018
|
+
target: "open",
|
|
1019
|
+
actions: ["setInitialFocus"]
|
|
1020
|
+
},
|
|
1021
|
+
OPEN: [{
|
|
1022
|
+
guard: "isOpenControlled",
|
|
1023
|
+
actions: ["invokeOnOpen"]
|
|
1024
|
+
}, {
|
|
1025
|
+
target: "open",
|
|
1026
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
1027
|
+
}],
|
|
1028
|
+
"TRIGGER.CLICK": [{
|
|
1029
|
+
guard: "isOpenControlled",
|
|
1030
|
+
actions: ["invokeOnOpen"]
|
|
1031
|
+
}, {
|
|
1032
|
+
target: "open",
|
|
1033
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
1034
|
+
}],
|
|
1035
|
+
"CHANNEL_INPUT.FOCUS": {
|
|
1036
|
+
target: "focused",
|
|
1037
|
+
actions: ["setActiveChannel"]
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
},
|
|
1041
|
+
focused: {
|
|
1042
|
+
tags: ["closed", "focused"],
|
|
1043
|
+
on: {
|
|
1044
|
+
"CONTROLLED.OPEN": {
|
|
1045
|
+
target: "open",
|
|
1046
|
+
actions: ["setInitialFocus"]
|
|
1047
|
+
},
|
|
1048
|
+
OPEN: [{
|
|
1049
|
+
guard: "isOpenControlled",
|
|
1050
|
+
actions: ["invokeOnOpen"]
|
|
1051
|
+
}, {
|
|
1052
|
+
target: "open",
|
|
1053
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
1054
|
+
}],
|
|
1055
|
+
"TRIGGER.CLICK": [{
|
|
1056
|
+
guard: "isOpenControlled",
|
|
1057
|
+
actions: ["invokeOnOpen"]
|
|
1058
|
+
}, {
|
|
1059
|
+
target: "open",
|
|
1060
|
+
actions: ["invokeOnOpen", "setInitialFocus"]
|
|
1061
|
+
}],
|
|
1062
|
+
"CHANNEL_INPUT.FOCUS": { actions: ["setActiveChannel"] },
|
|
1063
|
+
"CHANNEL_INPUT.BLUR": {
|
|
1064
|
+
target: "idle",
|
|
1065
|
+
actions: ["setChannelColorFromInput"]
|
|
1066
|
+
},
|
|
1067
|
+
"TRIGGER.BLUR": { target: "idle" }
|
|
1068
|
+
}
|
|
1069
|
+
},
|
|
1070
|
+
open: {
|
|
1071
|
+
tags: ["open"],
|
|
1072
|
+
effects: ["trackPositioning", "trackDismissableElement"],
|
|
1073
|
+
on: {
|
|
1074
|
+
"CONTROLLED.CLOSE": [{
|
|
1075
|
+
guard: "shouldRestoreFocus",
|
|
1076
|
+
target: "focused",
|
|
1077
|
+
actions: ["setReturnFocus"]
|
|
1078
|
+
}, { target: "idle" }],
|
|
1079
|
+
"TRIGGER.CLICK": [{
|
|
1080
|
+
guard: "isOpenControlled",
|
|
1081
|
+
actions: ["invokeOnClose"]
|
|
1082
|
+
}, {
|
|
1083
|
+
target: "idle",
|
|
1084
|
+
actions: ["invokeOnClose"]
|
|
1085
|
+
}],
|
|
1086
|
+
"AREA.POINTER_DOWN": {
|
|
1087
|
+
target: "open:dragging",
|
|
1088
|
+
actions: [
|
|
1089
|
+
"setActiveChannel",
|
|
1090
|
+
"setAreaColorFromPoint",
|
|
1091
|
+
"focusAreaThumb"
|
|
1092
|
+
]
|
|
1093
|
+
},
|
|
1094
|
+
"AREA.FOCUS": { actions: ["setActiveChannel"] },
|
|
1095
|
+
"CHANNEL_SLIDER.POINTER_DOWN": {
|
|
1096
|
+
target: "open:dragging",
|
|
1097
|
+
actions: [
|
|
1098
|
+
"setActiveChannel",
|
|
1099
|
+
"setChannelColorFromPoint",
|
|
1100
|
+
"focusChannelThumb"
|
|
1101
|
+
]
|
|
1102
|
+
},
|
|
1103
|
+
"CHANNEL_SLIDER.FOCUS": { actions: ["setActiveChannel"] },
|
|
1104
|
+
"AREA.ARROW_LEFT": { actions: ["decrementAreaXChannel"] },
|
|
1105
|
+
"AREA.ARROW_RIGHT": { actions: ["incrementAreaXChannel"] },
|
|
1106
|
+
"AREA.ARROW_UP": { actions: ["incrementAreaYChannel"] },
|
|
1107
|
+
"AREA.ARROW_DOWN": { actions: ["decrementAreaYChannel"] },
|
|
1108
|
+
"AREA.PAGE_UP": { actions: ["incrementAreaXChannel"] },
|
|
1109
|
+
"AREA.PAGE_DOWN": { actions: ["decrementAreaXChannel"] },
|
|
1110
|
+
"CHANNEL_SLIDER.ARROW_LEFT": { actions: ["decrementChannel"] },
|
|
1111
|
+
"CHANNEL_SLIDER.ARROW_RIGHT": { actions: ["incrementChannel"] },
|
|
1112
|
+
"CHANNEL_SLIDER.ARROW_UP": { actions: ["incrementChannel"] },
|
|
1113
|
+
"CHANNEL_SLIDER.ARROW_DOWN": { actions: ["decrementChannel"] },
|
|
1114
|
+
"CHANNEL_SLIDER.PAGE_UP": { actions: ["incrementChannel"] },
|
|
1115
|
+
"CHANNEL_SLIDER.PAGE_DOWN": { actions: ["decrementChannel"] },
|
|
1116
|
+
"CHANNEL_SLIDER.HOME": { actions: ["setChannelToMin"] },
|
|
1117
|
+
"CHANNEL_SLIDER.END": { actions: ["setChannelToMax"] },
|
|
1118
|
+
"CHANNEL_INPUT.BLUR": { actions: ["setChannelColorFromInput"] },
|
|
1119
|
+
INTERACT_OUTSIDE: [
|
|
1120
|
+
{
|
|
1121
|
+
guard: "isOpenControlled",
|
|
1122
|
+
actions: ["invokeOnClose"]
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
guard: "shouldRestoreFocus",
|
|
1126
|
+
target: "focused",
|
|
1127
|
+
actions: ["invokeOnClose", "setReturnFocus"]
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
target: "idle",
|
|
1131
|
+
actions: ["invokeOnClose"]
|
|
1132
|
+
}
|
|
1133
|
+
],
|
|
1134
|
+
CLOSE: [{
|
|
1135
|
+
guard: "isOpenControlled",
|
|
1136
|
+
actions: ["invokeOnClose"]
|
|
1137
|
+
}, {
|
|
1138
|
+
target: "idle",
|
|
1139
|
+
actions: ["invokeOnClose"]
|
|
1140
|
+
}],
|
|
1141
|
+
"SWATCH_TRIGGER.CLICK": [
|
|
1142
|
+
{
|
|
1143
|
+
guard: and("isOpenControlled", "closeOnSelect"),
|
|
1144
|
+
actions: ["setValue", "invokeOnClose"]
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
guard: "closeOnSelect",
|
|
1148
|
+
target: "focused",
|
|
1149
|
+
actions: [
|
|
1150
|
+
"setValue",
|
|
1151
|
+
"invokeOnClose",
|
|
1152
|
+
"setReturnFocus"
|
|
1153
|
+
]
|
|
1154
|
+
},
|
|
1155
|
+
{ actions: ["setValue"] }
|
|
1156
|
+
]
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
"open:dragging": {
|
|
1160
|
+
tags: ["open"],
|
|
1161
|
+
exit: ["clearActiveChannel"],
|
|
1162
|
+
effects: [
|
|
1163
|
+
"trackPointerMove",
|
|
1164
|
+
"disableTextSelection",
|
|
1165
|
+
"trackPositioning",
|
|
1166
|
+
"trackDismissableElement"
|
|
1167
|
+
],
|
|
1168
|
+
on: {
|
|
1169
|
+
"CONTROLLED.CLOSE": [{
|
|
1170
|
+
guard: "shouldRestoreFocus",
|
|
1171
|
+
target: "focused",
|
|
1172
|
+
actions: ["setReturnFocus"]
|
|
1173
|
+
}, { target: "idle" }],
|
|
1174
|
+
"AREA.POINTER_MOVE": { actions: ["setAreaColorFromPoint", "focusAreaThumb"] },
|
|
1175
|
+
"AREA.POINTER_UP": {
|
|
1176
|
+
target: "open",
|
|
1177
|
+
actions: ["invokeOnChangeEnd"]
|
|
1178
|
+
},
|
|
1179
|
+
"CHANNEL_SLIDER.POINTER_MOVE": { actions: ["setChannelColorFromPoint", "focusChannelThumb"] },
|
|
1180
|
+
"CHANNEL_SLIDER.POINTER_UP": {
|
|
1181
|
+
target: "open",
|
|
1182
|
+
actions: ["invokeOnChangeEnd"]
|
|
1183
|
+
},
|
|
1184
|
+
INTERACT_OUTSIDE: [
|
|
1185
|
+
{
|
|
1186
|
+
guard: "isOpenControlled",
|
|
1187
|
+
actions: ["invokeOnClose"]
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
guard: "shouldRestoreFocus",
|
|
1191
|
+
target: "focused",
|
|
1192
|
+
actions: ["invokeOnClose", "setReturnFocus"]
|
|
1193
|
+
},
|
|
1194
|
+
{
|
|
1195
|
+
target: "idle",
|
|
1196
|
+
actions: ["invokeOnClose"]
|
|
1197
|
+
}
|
|
1198
|
+
],
|
|
1199
|
+
CLOSE: [{
|
|
1200
|
+
guard: "isOpenControlled",
|
|
1201
|
+
actions: ["invokeOnClose"]
|
|
1202
|
+
}, {
|
|
1203
|
+
target: "idle",
|
|
1204
|
+
actions: ["invokeOnClose"]
|
|
1205
|
+
}]
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
implementations: {
|
|
1210
|
+
guards: {
|
|
1211
|
+
closeOnSelect: ({ prop }) => !!prop("closeOnSelect"),
|
|
1212
|
+
isOpenControlled: ({ prop }) => prop("open") != null || !!prop("inline"),
|
|
1213
|
+
shouldRestoreFocus: ({ context }) => !!context.get("restoreFocus")
|
|
1214
|
+
},
|
|
1215
|
+
effects: {
|
|
1216
|
+
trackPositioning({ context, prop, scope }) {
|
|
1217
|
+
if (prop("inline")) return;
|
|
1218
|
+
if (!context.get("currentPlacement")) context.set("currentPlacement", prop("positioning")?.placement);
|
|
1219
|
+
const anchorEl = getTriggerEl(scope);
|
|
1220
|
+
const getPositionerEl$1 = () => getPositionerEl(scope);
|
|
1221
|
+
return getPlacement(anchorEl, getPositionerEl$1, {
|
|
1222
|
+
...prop("positioning"),
|
|
1223
|
+
defer: true,
|
|
1224
|
+
onComplete(data) {
|
|
1225
|
+
context.set("currentPlacement", data.placement);
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
},
|
|
1229
|
+
trackDismissableElement({ context, scope, prop, send }) {
|
|
1230
|
+
if (prop("inline")) return;
|
|
1231
|
+
const getContentEl$1 = () => getContentEl(scope);
|
|
1232
|
+
return trackDismissableElement(getContentEl$1, {
|
|
1233
|
+
type: "popover",
|
|
1234
|
+
exclude: getTriggerEl(scope),
|
|
1235
|
+
defer: true,
|
|
1236
|
+
onInteractOutside(event) {
|
|
1237
|
+
prop("onInteractOutside")?.(event);
|
|
1238
|
+
if (event.defaultPrevented) return;
|
|
1239
|
+
context.set("restoreFocus", !(event.detail.focusable || event.detail.contextmenu));
|
|
1240
|
+
},
|
|
1241
|
+
onPointerDownOutside: prop("onPointerDownOutside"),
|
|
1242
|
+
onFocusOutside: prop("onFocusOutside"),
|
|
1243
|
+
onDismiss() {
|
|
1244
|
+
send({ type: "INTERACT_OUTSIDE" });
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
},
|
|
1248
|
+
trackFormControl({ context, scope, send }) {
|
|
1249
|
+
return trackFormControl(getHiddenInputEl(scope), {
|
|
1250
|
+
onFieldsetDisabledChange(disabled) {
|
|
1251
|
+
context.set("fieldsetDisabled", disabled);
|
|
1252
|
+
},
|
|
1253
|
+
onFormReset() {
|
|
1254
|
+
send({
|
|
1255
|
+
type: "VALUE.SET",
|
|
1256
|
+
value: context.initial("value"),
|
|
1257
|
+
src: "form.reset"
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
},
|
|
1262
|
+
trackPointerMove({ context, scope, event, send }) {
|
|
1263
|
+
return trackPointerMove(scope.getDoc(), {
|
|
1264
|
+
onPointerMove({ point }) {
|
|
1265
|
+
send({
|
|
1266
|
+
type: context.get("activeId") === "area" ? "AREA.POINTER_MOVE" : "CHANNEL_SLIDER.POINTER_MOVE",
|
|
1267
|
+
point,
|
|
1268
|
+
format: event.format
|
|
1269
|
+
});
|
|
1270
|
+
},
|
|
1271
|
+
onPointerUp() {
|
|
1272
|
+
send({ type: context.get("activeId") === "area" ? "AREA.POINTER_UP" : "CHANNEL_SLIDER.POINTER_UP" });
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
},
|
|
1276
|
+
disableTextSelection({ scope }) {
|
|
1277
|
+
return disableTextSelection({
|
|
1278
|
+
doc: scope.getDoc(),
|
|
1279
|
+
target: getContentEl(scope)
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
},
|
|
1283
|
+
actions: {
|
|
1284
|
+
openEyeDropper({ scope, context }) {
|
|
1285
|
+
const win = scope.getWin();
|
|
1286
|
+
if (!("EyeDropper" in win)) return;
|
|
1287
|
+
new win.EyeDropper().open().then(({ sRGBHex }) => {
|
|
1288
|
+
const format = context.get("value").getFormat();
|
|
1289
|
+
const color = parseColor(sRGBHex).toFormat(format);
|
|
1290
|
+
context.set("value", color);
|
|
1291
|
+
}).catch(() => void 0);
|
|
1292
|
+
},
|
|
1293
|
+
setActiveChannel({ context, event }) {
|
|
1294
|
+
context.set("activeId", event.id);
|
|
1295
|
+
if (event.channel) context.set("activeChannel", event.channel);
|
|
1296
|
+
if (event.orientation) context.set("activeOrientation", event.orientation);
|
|
1297
|
+
},
|
|
1298
|
+
clearActiveChannel({ context }) {
|
|
1299
|
+
context.set("activeChannel", null);
|
|
1300
|
+
context.set("activeId", null);
|
|
1301
|
+
context.set("activeOrientation", null);
|
|
1302
|
+
},
|
|
1303
|
+
setAreaColorFromPoint({ context, event, computed, scope, prop }) {
|
|
1304
|
+
const v = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
|
|
1305
|
+
const { xChannel, yChannel } = event.channel || context.get("activeChannel");
|
|
1306
|
+
const percent = getAreaValueFromPoint(scope, event.point, prop("dir"));
|
|
1307
|
+
if (!percent) return;
|
|
1308
|
+
const xValue = v.getChannelPercentValue(xChannel, percent.x);
|
|
1309
|
+
const yValue = v.getChannelPercentValue(yChannel, 1 - percent.y);
|
|
1310
|
+
const color = v.withChannelValue(xChannel, xValue).withChannelValue(yChannel, yValue);
|
|
1311
|
+
context.set("value", color);
|
|
1312
|
+
},
|
|
1313
|
+
setChannelColorFromPoint({ context, event, computed, scope, prop }) {
|
|
1314
|
+
const channel = event.channel || context.get("activeId");
|
|
1315
|
+
const normalizedValue = event.format ? context.get("value").toFormat(event.format) : computed("areaValue");
|
|
1316
|
+
const percent = getChannelSliderValueFromPoint(scope, event.point, channel, prop("dir"));
|
|
1317
|
+
if (!percent) return;
|
|
1318
|
+
const channelPercent = (context.get("activeOrientation") || "horizontal") === "horizontal" ? percent.x : percent.y;
|
|
1319
|
+
const value = normalizedValue.getChannelPercentValue(channel, channelPercent);
|
|
1320
|
+
const color = normalizedValue.withChannelValue(channel, value);
|
|
1321
|
+
context.set("value", color);
|
|
1322
|
+
},
|
|
1323
|
+
setValue({ context, event }) {
|
|
1324
|
+
context.set("value", event.value);
|
|
1325
|
+
},
|
|
1326
|
+
setFormat({ context, event }) {
|
|
1327
|
+
context.set("format", event.format);
|
|
1328
|
+
},
|
|
1329
|
+
dispatchChangeEvent({ scope, computed }) {
|
|
1330
|
+
dispatchInputValueEvent(getHiddenInputEl(scope), { value: computed("valueAsString") });
|
|
1331
|
+
},
|
|
1332
|
+
syncInputElements({ context, scope }) {
|
|
1333
|
+
syncChannelInputs(scope, context.get("value"));
|
|
1334
|
+
},
|
|
1335
|
+
invokeOnChangeEnd({ context, prop, computed }) {
|
|
1336
|
+
prop("onValueChangeEnd")?.({
|
|
1337
|
+
value: context.get("value"),
|
|
1338
|
+
valueAsString: computed("valueAsString")
|
|
1339
|
+
});
|
|
1340
|
+
},
|
|
1341
|
+
setChannelColorFromInput({ context, event, scope, prop }) {
|
|
1342
|
+
const { channel, isTextField, value } = event;
|
|
1343
|
+
const currentAlpha = context.get("value").getChannelValue("alpha");
|
|
1344
|
+
let color;
|
|
1345
|
+
if (channel === "alpha") {
|
|
1346
|
+
let valueAsNumber = parseFloat(value);
|
|
1347
|
+
valueAsNumber = Number.isNaN(valueAsNumber) ? currentAlpha : valueAsNumber;
|
|
1348
|
+
color = context.get("value").withChannelValue("alpha", valueAsNumber);
|
|
1349
|
+
} else if (isTextField) color = tryCatch(() => {
|
|
1350
|
+
return parse(channel === "hex" ? prefixHex(value) : value).withChannelValue("alpha", currentAlpha);
|
|
1351
|
+
}, () => context.get("value"));
|
|
1352
|
+
else {
|
|
1353
|
+
const current = context.get("value").toFormat(context.get("format"));
|
|
1354
|
+
const valueAsNumber = Number.isNaN(value) ? current.getChannelValue(channel) : value;
|
|
1355
|
+
color = current.withChannelValue(channel, valueAsNumber);
|
|
1356
|
+
}
|
|
1357
|
+
syncChannelInputs(scope, context.get("value"), color);
|
|
1358
|
+
context.set("value", color);
|
|
1359
|
+
prop("onValueChangeEnd")?.({
|
|
1360
|
+
value: color,
|
|
1361
|
+
valueAsString: color.toString(context.get("format"))
|
|
1362
|
+
});
|
|
1363
|
+
},
|
|
1364
|
+
incrementChannel({ context, event }) {
|
|
1365
|
+
const color = context.get("value").incrementChannel(event.channel, event.step);
|
|
1366
|
+
context.set("value", color);
|
|
1367
|
+
},
|
|
1368
|
+
decrementChannel({ context, event }) {
|
|
1369
|
+
const color = context.get("value").decrementChannel(event.channel, event.step);
|
|
1370
|
+
context.set("value", color);
|
|
1371
|
+
},
|
|
1372
|
+
incrementAreaXChannel({ context, event, computed }) {
|
|
1373
|
+
const { xChannel } = event.channel;
|
|
1374
|
+
const color = computed("areaValue").incrementChannel(xChannel, event.step);
|
|
1375
|
+
context.set("value", color);
|
|
1376
|
+
},
|
|
1377
|
+
decrementAreaXChannel({ context, event, computed }) {
|
|
1378
|
+
const { xChannel } = event.channel;
|
|
1379
|
+
const color = computed("areaValue").decrementChannel(xChannel, event.step);
|
|
1380
|
+
context.set("value", color);
|
|
1381
|
+
},
|
|
1382
|
+
incrementAreaYChannel({ context, event, computed }) {
|
|
1383
|
+
const { yChannel } = event.channel;
|
|
1384
|
+
const color = computed("areaValue").incrementChannel(yChannel, event.step);
|
|
1385
|
+
context.set("value", color);
|
|
1386
|
+
},
|
|
1387
|
+
decrementAreaYChannel({ context, event, computed }) {
|
|
1388
|
+
const { yChannel } = event.channel;
|
|
1389
|
+
const color = computed("areaValue").decrementChannel(yChannel, event.step);
|
|
1390
|
+
context.set("value", color);
|
|
1391
|
+
},
|
|
1392
|
+
setChannelToMax({ context, event }) {
|
|
1393
|
+
const value = context.get("value");
|
|
1394
|
+
const range = value.getChannelRange(event.channel);
|
|
1395
|
+
const color = value.withChannelValue(event.channel, range.maxValue);
|
|
1396
|
+
context.set("value", color);
|
|
1397
|
+
},
|
|
1398
|
+
setChannelToMin({ context, event }) {
|
|
1399
|
+
const value = context.get("value");
|
|
1400
|
+
const range = value.getChannelRange(event.channel);
|
|
1401
|
+
const color = value.withChannelValue(event.channel, range.minValue);
|
|
1402
|
+
context.set("value", color);
|
|
1403
|
+
},
|
|
1404
|
+
focusAreaThumb({ scope }) {
|
|
1405
|
+
raf(() => {
|
|
1406
|
+
getAreaThumbEl(scope)?.focus({ preventScroll: true });
|
|
1407
|
+
});
|
|
1408
|
+
},
|
|
1409
|
+
focusChannelThumb({ event, scope }) {
|
|
1410
|
+
raf(() => {
|
|
1411
|
+
getChannelSliderThumbEl(scope, event.channel)?.focus({ preventScroll: true });
|
|
1412
|
+
});
|
|
1413
|
+
},
|
|
1414
|
+
setInitialFocus({ prop, scope }) {
|
|
1415
|
+
if (!prop("openAutoFocus")) return;
|
|
1416
|
+
raf(() => {
|
|
1417
|
+
getInitialFocus({
|
|
1418
|
+
root: getContentEl(scope),
|
|
1419
|
+
getInitialEl: prop("initialFocusEl")
|
|
1420
|
+
})?.focus({ preventScroll: true });
|
|
1421
|
+
});
|
|
1422
|
+
},
|
|
1423
|
+
setReturnFocus({ scope }) {
|
|
1424
|
+
raf(() => {
|
|
1425
|
+
getTriggerEl(scope)?.focus({ preventScroll: true });
|
|
1426
|
+
});
|
|
1427
|
+
},
|
|
1428
|
+
syncFormatSelectElement({ context, scope }) {
|
|
1429
|
+
syncFormatSelect(scope, context.get("format"));
|
|
1430
|
+
},
|
|
1431
|
+
invokeOnOpen({ prop, context }) {
|
|
1432
|
+
if (prop("inline")) return;
|
|
1433
|
+
prop("onOpenChange")?.({
|
|
1434
|
+
open: true,
|
|
1435
|
+
value: context.get("value")
|
|
1436
|
+
});
|
|
1437
|
+
},
|
|
1438
|
+
invokeOnClose({ prop, context }) {
|
|
1439
|
+
if (prop("inline")) return;
|
|
1440
|
+
prop("onOpenChange")?.({
|
|
1441
|
+
open: false,
|
|
1442
|
+
value: context.get("value")
|
|
1443
|
+
});
|
|
1444
|
+
},
|
|
1445
|
+
toggleVisibility({ prop, event, send }) {
|
|
1446
|
+
send({
|
|
1447
|
+
type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE",
|
|
1448
|
+
previousEvent: event
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
function syncChannelInputs(scope, currentValue, nextValue) {
|
|
1455
|
+
const channelInputEls = getChannelInputEls(scope);
|
|
1456
|
+
raf(() => {
|
|
1457
|
+
channelInputEls.forEach((inputEl) => {
|
|
1458
|
+
const channel = inputEl.dataset.channel;
|
|
1459
|
+
setElementValue(inputEl, getChannelValue(nextValue || currentValue, channel));
|
|
1460
|
+
});
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
function syncFormatSelect(scope, format) {
|
|
1464
|
+
const selectEl = getFormatSelectEl(scope);
|
|
1465
|
+
if (!selectEl) return;
|
|
1466
|
+
raf(() => setElementValue(selectEl, format));
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
//#endregion
|
|
1470
|
+
//#region src/machines/color-picker/color-picker.props.ts
|
|
1471
|
+
const props = createProps()([
|
|
1472
|
+
"closeOnSelect",
|
|
1473
|
+
"dir",
|
|
1474
|
+
"disabled",
|
|
1475
|
+
"format",
|
|
1476
|
+
"defaultFormat",
|
|
1477
|
+
"getRootNode",
|
|
1478
|
+
"id",
|
|
1479
|
+
"ids",
|
|
1480
|
+
"initialFocusEl",
|
|
1481
|
+
"inline",
|
|
1482
|
+
"name",
|
|
1483
|
+
"positioning",
|
|
1484
|
+
"onFocusOutside",
|
|
1485
|
+
"onFormatChange",
|
|
1486
|
+
"onInteractOutside",
|
|
1487
|
+
"onOpenChange",
|
|
1488
|
+
"onPointerDownOutside",
|
|
1489
|
+
"onValueChange",
|
|
1490
|
+
"onValueChangeEnd",
|
|
1491
|
+
"defaultOpen",
|
|
1492
|
+
"open",
|
|
1493
|
+
"positioning",
|
|
1494
|
+
"required",
|
|
1495
|
+
"readOnly",
|
|
1496
|
+
"value",
|
|
1497
|
+
"defaultValue",
|
|
1498
|
+
"invalid",
|
|
1499
|
+
"openAutoFocus"
|
|
1500
|
+
]);
|
|
1501
|
+
const splitProps = createSplitProps(props);
|
|
1502
|
+
const areaProps = createProps()(["xChannel", "yChannel"]);
|
|
1503
|
+
const splitAreaProps = createSplitProps(areaProps);
|
|
1504
|
+
const channelProps = createProps()(["channel", "orientation"]);
|
|
1505
|
+
const splitChannelProps = createSplitProps(channelProps);
|
|
1506
|
+
const swatchTriggerProps = createProps()(["value", "disabled"]);
|
|
1507
|
+
const splitSwatchTriggerProps = createSplitProps(swatchTriggerProps);
|
|
1508
|
+
const swatchProps = createProps()(["value", "respectAlpha"]);
|
|
1509
|
+
const splitSwatchProps = createSplitProps(swatchProps);
|
|
1510
|
+
const transparencyGridProps = createProps()(["size"]);
|
|
1511
|
+
const splitTransparencyGridProps = createSplitProps(transparencyGridProps);
|
|
1512
|
+
|
|
1513
|
+
//#endregion
|
|
1514
|
+
export { anatomy, areaProps, channelProps, connect, machine, parse, props, splitAreaProps, splitChannelProps, splitProps, splitSwatchProps, splitSwatchTriggerProps, splitTransparencyGridProps, swatchProps, swatchTriggerProps, transparencyGridProps };
|