@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
package/dist/hotkeys.cjs
ADDED
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
const require_defineProperty = require('./defineProperty-BoUOT9Ie.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/shared/hotkeys/modifier.ts
|
|
4
|
+
const MODIFIER_NORMALIZATION_MAP = new Map([
|
|
5
|
+
["ctrl", "Control"],
|
|
6
|
+
["control", "Control"],
|
|
7
|
+
["alt", "Alt"],
|
|
8
|
+
["option", "Alt"],
|
|
9
|
+
["shift", "Shift"],
|
|
10
|
+
["meta", "Meta"],
|
|
11
|
+
["cmd", "Meta"],
|
|
12
|
+
["command", "Meta"],
|
|
13
|
+
["win", "Meta"],
|
|
14
|
+
["windows", "Meta"]
|
|
15
|
+
]);
|
|
16
|
+
const normalizeModifier = (key) => MODIFIER_NORMALIZATION_MAP.get(key.toLowerCase()) ?? key;
|
|
17
|
+
const MODIFIER_SET = new Set([
|
|
18
|
+
"control",
|
|
19
|
+
"ctrl",
|
|
20
|
+
"alt",
|
|
21
|
+
"option",
|
|
22
|
+
"shift",
|
|
23
|
+
"meta",
|
|
24
|
+
"cmd",
|
|
25
|
+
"command",
|
|
26
|
+
"win",
|
|
27
|
+
"windows"
|
|
28
|
+
]);
|
|
29
|
+
const isModifierSet = (key) => MODIFIER_SET.has(key.toLowerCase());
|
|
30
|
+
function resolveControlOrMeta(key, platform) {
|
|
31
|
+
return isModKey(key.toLowerCase()) ? platform === "mac" ? "Meta" : "Control" : key;
|
|
32
|
+
}
|
|
33
|
+
function isModKey(key) {
|
|
34
|
+
return key.toLowerCase() === "mod" || key.toLowerCase() === "controlormeta";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/shared/hotkeys/normalize.ts
|
|
39
|
+
function normalizeKey(eventKey) {
|
|
40
|
+
if (eventKey.length === 1 && SINGLE_LETTER_REGEX.test(eventKey)) return eventKey.toUpperCase();
|
|
41
|
+
const lower = eventKey.toLowerCase();
|
|
42
|
+
const normalized = KEY_NORMALIZATION_MAP.get(lower);
|
|
43
|
+
if (normalized !== void 0) return normalized;
|
|
44
|
+
if (FUNCTION_KEY_REGEX.test(lower)) return lower.toUpperCase();
|
|
45
|
+
return eventKey;
|
|
46
|
+
}
|
|
47
|
+
const SINGLE_LETTER_REGEX = /[a-z]/i;
|
|
48
|
+
const FUNCTION_KEY_REGEX = /^f([1-9]|1[0-9])$/;
|
|
49
|
+
const KEY_NORMALIZATION_MAP = new Map([
|
|
50
|
+
["backspace", "Backspace"],
|
|
51
|
+
["tab", "Tab"],
|
|
52
|
+
["clear", "Clear"],
|
|
53
|
+
["enter", "Enter"],
|
|
54
|
+
["return", "Enter"],
|
|
55
|
+
["esc", "Escape"],
|
|
56
|
+
["escape", "Escape"],
|
|
57
|
+
["space", " "],
|
|
58
|
+
["spacebar", " "],
|
|
59
|
+
["up", "ArrowUp"],
|
|
60
|
+
["arrowup", "ArrowUp"],
|
|
61
|
+
["down", "ArrowDown"],
|
|
62
|
+
["arrowdown", "ArrowDown"],
|
|
63
|
+
["left", "ArrowLeft"],
|
|
64
|
+
["arrowleft", "ArrowLeft"],
|
|
65
|
+
["right", "ArrowRight"],
|
|
66
|
+
["arrowright", "ArrowRight"],
|
|
67
|
+
["pageup", "PageUp"],
|
|
68
|
+
["pgup", "PageUp"],
|
|
69
|
+
["pagedown", "PageDown"],
|
|
70
|
+
["pgdn", "PageDown"],
|
|
71
|
+
["home", "Home"],
|
|
72
|
+
["end", "End"],
|
|
73
|
+
["del", "Delete"],
|
|
74
|
+
["delete", "Delete"],
|
|
75
|
+
["ins", "Insert"],
|
|
76
|
+
["insert", "Insert"]
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/shared/hotkeys/key-to-code.ts
|
|
81
|
+
function keyToCode(key) {
|
|
82
|
+
if (UPPERCASE_LETTER_REGEX.test(key)) return `Key${key}`;
|
|
83
|
+
if (SINGLE_DIGIT_REGEX.test(key)) return `Digit${key}`;
|
|
84
|
+
if (FUNCTION_KEY_WITH_F20_REGEX.test(key)) return key;
|
|
85
|
+
if (DIRECT_KEY_CODES.has(key)) return key;
|
|
86
|
+
return SPECIAL_KEY_CODES.get(key);
|
|
87
|
+
}
|
|
88
|
+
const UPPERCASE_LETTER_REGEX = /^[A-Z]$/;
|
|
89
|
+
const SINGLE_DIGIT_REGEX = /^[0-9]$/;
|
|
90
|
+
const FUNCTION_KEY_WITH_F20_REGEX = /^F([1-9]|1[0-9]|20)$/;
|
|
91
|
+
const DIRECT_KEY_CODES = new Set([
|
|
92
|
+
"Enter",
|
|
93
|
+
"Tab",
|
|
94
|
+
"Backspace",
|
|
95
|
+
"Delete",
|
|
96
|
+
"Escape",
|
|
97
|
+
"ArrowUp",
|
|
98
|
+
"ArrowDown",
|
|
99
|
+
"ArrowLeft",
|
|
100
|
+
"ArrowRight",
|
|
101
|
+
"Home",
|
|
102
|
+
"End",
|
|
103
|
+
"PageUp",
|
|
104
|
+
"PageDown",
|
|
105
|
+
"Insert"
|
|
106
|
+
]);
|
|
107
|
+
const SPECIAL_KEY_CODES = new Map([
|
|
108
|
+
[" ", "Space"],
|
|
109
|
+
["-", "Minus"],
|
|
110
|
+
["=", "Equal"],
|
|
111
|
+
["+", "Equal"],
|
|
112
|
+
["[", "BracketLeft"],
|
|
113
|
+
["]", "BracketRight"],
|
|
114
|
+
[";", "Semicolon"],
|
|
115
|
+
["'", "Quote"],
|
|
116
|
+
["`", "Backquote"],
|
|
117
|
+
["\\", "Backslash"],
|
|
118
|
+
[",", "Comma"],
|
|
119
|
+
[".", "Period"],
|
|
120
|
+
["/", "Slash"]
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/shared/hotkeys/utils.ts
|
|
125
|
+
const typeOf = (value) => Object.prototype.toString.call(value).slice(8, -1);
|
|
126
|
+
const isDocument = (value) => typeOf(value) === "Document";
|
|
127
|
+
function getDoc(root) {
|
|
128
|
+
return isDocument(root) ? root : root.ownerDocument || document;
|
|
129
|
+
}
|
|
130
|
+
function getWin(root) {
|
|
131
|
+
return getDoc(root).defaultView || window;
|
|
132
|
+
}
|
|
133
|
+
const FORM_TAGS = new Set([
|
|
134
|
+
"input",
|
|
135
|
+
"textarea",
|
|
136
|
+
"select"
|
|
137
|
+
]);
|
|
138
|
+
const isFormTag = (tagName) => FORM_TAGS.has(tagName);
|
|
139
|
+
const MODIFIER_SEPARATOR = "+";
|
|
140
|
+
const SEQUENCE_SEPARATOR = ">";
|
|
141
|
+
const isHTMLElement = (target) => {
|
|
142
|
+
return target !== null && typeof target === "object" && "localName" in target && "nodeType" in target && target.nodeType === 1;
|
|
143
|
+
};
|
|
144
|
+
const getEventTarget = (event) => {
|
|
145
|
+
const target = event.composedPath?.()[0] || event.target;
|
|
146
|
+
return isHTMLElement(target) ? target : null;
|
|
147
|
+
};
|
|
148
|
+
const NA_REGEX = /Mac|iPod|iPhone|iPad/;
|
|
149
|
+
const isMac = () => typeof navigator !== "undefined" && NA_REGEX.test(navigator.userAgent);
|
|
150
|
+
const getPlatform = () => isMac() ? "mac" : "windows";
|
|
151
|
+
const toArray = (value) => {
|
|
152
|
+
if (Array.isArray(value)) return value.filter((item) => item !== void 0);
|
|
153
|
+
return value !== void 0 ? [value] : [];
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/shared/hotkeys/parser.ts
|
|
158
|
+
function parseHotkeyString(hotkey, platform) {
|
|
159
|
+
const parts = hotkey.split(MODIFIER_SEPARATOR);
|
|
160
|
+
const modifiers = [];
|
|
161
|
+
let keyIndex = parts.length - 1;
|
|
162
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
163
|
+
const part = parts[i].trim().toLowerCase();
|
|
164
|
+
const resolved = resolveControlOrMeta(part, platform).toLowerCase();
|
|
165
|
+
if (part === "") {
|
|
166
|
+
keyIndex = i;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
if (isModifierSet(resolved) || resolved === "mod" || resolved === "controlormeta") modifiers.push(parts[i].trim());
|
|
170
|
+
else {
|
|
171
|
+
keyIndex = i;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
modifiers,
|
|
177
|
+
key: parts.slice(keyIndex).join(MODIFIER_SEPARATOR).trim()
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function parseHotkey(hotkey, platform) {
|
|
181
|
+
if (hotkey.includes(SEQUENCE_SEPARATOR)) {
|
|
182
|
+
const sequenceParts = hotkey.split(SEQUENCE_SEPARATOR);
|
|
183
|
+
const sequenceSteps = [];
|
|
184
|
+
const allKeys = [];
|
|
185
|
+
const allCodes = [];
|
|
186
|
+
for (const rawPart of sequenceParts) {
|
|
187
|
+
const part = rawPart.trim();
|
|
188
|
+
if (part.includes(MODIFIER_SEPARATOR)) {
|
|
189
|
+
const { modifiers: modifiers$1, key: key$1 } = parseHotkeyString(part, platform);
|
|
190
|
+
const step = {
|
|
191
|
+
key: normalizeKey(key$1),
|
|
192
|
+
alt: false,
|
|
193
|
+
ctrl: false,
|
|
194
|
+
meta: false,
|
|
195
|
+
shift: false
|
|
196
|
+
};
|
|
197
|
+
for (const modifier of modifiers$1) switch (normalizeModifier(resolveControlOrMeta(modifier, platform))) {
|
|
198
|
+
case "Alt":
|
|
199
|
+
step.alt = true;
|
|
200
|
+
break;
|
|
201
|
+
case "Control":
|
|
202
|
+
step.ctrl = true;
|
|
203
|
+
break;
|
|
204
|
+
case "Meta":
|
|
205
|
+
step.meta = true;
|
|
206
|
+
break;
|
|
207
|
+
case "Shift":
|
|
208
|
+
step.shift = true;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
sequenceSteps.push(step);
|
|
212
|
+
allKeys.push(step.key);
|
|
213
|
+
const code = keyToCode(step.key);
|
|
214
|
+
if (code != null) allCodes.push(code);
|
|
215
|
+
} else {
|
|
216
|
+
const key$1 = normalizeKey(part);
|
|
217
|
+
sequenceSteps.push({
|
|
218
|
+
key: key$1,
|
|
219
|
+
alt: false,
|
|
220
|
+
ctrl: false,
|
|
221
|
+
meta: false,
|
|
222
|
+
shift: false
|
|
223
|
+
});
|
|
224
|
+
allKeys.push(key$1);
|
|
225
|
+
const code = keyToCode(key$1);
|
|
226
|
+
if (code != null) allCodes.push(code);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
keys: allKeys,
|
|
231
|
+
codes: allCodes.length > 0 ? allCodes : void 0,
|
|
232
|
+
alt: false,
|
|
233
|
+
ctrl: false,
|
|
234
|
+
meta: false,
|
|
235
|
+
shift: false,
|
|
236
|
+
isSequence: true,
|
|
237
|
+
sequenceSteps
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
const { modifiers, key } = parseHotkeyString(hotkey, platform);
|
|
241
|
+
const result = {
|
|
242
|
+
keys: [],
|
|
243
|
+
codes: [],
|
|
244
|
+
alt: false,
|
|
245
|
+
ctrl: false,
|
|
246
|
+
meta: false,
|
|
247
|
+
shift: false,
|
|
248
|
+
isSequence: false
|
|
249
|
+
};
|
|
250
|
+
for (const modifier of modifiers) switch (normalizeModifier(resolveControlOrMeta(modifier, platform))) {
|
|
251
|
+
case "Alt":
|
|
252
|
+
result.alt = true;
|
|
253
|
+
break;
|
|
254
|
+
case "Control":
|
|
255
|
+
result.ctrl = true;
|
|
256
|
+
break;
|
|
257
|
+
case "Meta":
|
|
258
|
+
result.meta = true;
|
|
259
|
+
break;
|
|
260
|
+
case "Shift":
|
|
261
|
+
result.shift = true;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
if (key && key !== SEQUENCE_SEPARATOR) {
|
|
265
|
+
const normalizedKey = normalizeKey(key);
|
|
266
|
+
result.keys.push(normalizedKey);
|
|
267
|
+
const code = keyToCode(normalizedKey);
|
|
268
|
+
if (code != null) result.codes?.push(code);
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
function matchesHotkey(parsed, event) {
|
|
273
|
+
if (parsed.alt !== event.altKey) return false;
|
|
274
|
+
if (parsed.ctrl !== event.ctrlKey) return false;
|
|
275
|
+
if (parsed.meta !== event.metaKey) return false;
|
|
276
|
+
if (parsed.shift !== event.shiftKey) return false;
|
|
277
|
+
const eventKey = normalizeKey(event.key);
|
|
278
|
+
const eventCode = event.code;
|
|
279
|
+
const keyMatches = parsed.keys.some((key) => key === eventKey);
|
|
280
|
+
const codeMatches = parsed.codes ? parsed.codes.some((code) => code === eventCode) : false;
|
|
281
|
+
return keyMatches || codeMatches;
|
|
282
|
+
}
|
|
283
|
+
function shouldTrigger(event, options) {
|
|
284
|
+
const target = getEventTarget(event);
|
|
285
|
+
if (!target) return true;
|
|
286
|
+
const tagName = target.localName;
|
|
287
|
+
const isContentEditable = target.getAttribute("contenteditable") === "true";
|
|
288
|
+
if (isFormTag(tagName)) {
|
|
289
|
+
if (options.enableOnFormTags === false || options.enableOnFormTags === void 0) return false;
|
|
290
|
+
if (Array.isArray(options.enableOnFormTags)) {
|
|
291
|
+
if (!options.enableOnFormTags.includes(tagName)) return false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (isContentEditable && !options.enableOnContentEditable) return false;
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
function isHotKey(hotkey, event, options = {}) {
|
|
298
|
+
if (!shouldTrigger(event, options)) return false;
|
|
299
|
+
const platform = getPlatform();
|
|
300
|
+
return toArray(hotkey).some((h) => {
|
|
301
|
+
return matchesHotkey(parseHotkey(h, platform), event);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
function getHotkeyPriority(parsed) {
|
|
305
|
+
let priority = 0;
|
|
306
|
+
if (parsed.isSequence) priority += 1e3;
|
|
307
|
+
if (parsed.alt) priority += 100;
|
|
308
|
+
if (parsed.ctrl) priority += 100;
|
|
309
|
+
if (parsed.meta) priority += 100;
|
|
310
|
+
if (parsed.shift) priority += 100;
|
|
311
|
+
priority += parsed.keys.length * 10;
|
|
312
|
+
return priority;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/shared/hotkeys/store.ts
|
|
317
|
+
const defaultOptions = {
|
|
318
|
+
preventDefault: true,
|
|
319
|
+
stopPropagation: false,
|
|
320
|
+
enableOnFormTags: false,
|
|
321
|
+
enableOnContentEditable: false,
|
|
322
|
+
capture: true
|
|
323
|
+
};
|
|
324
|
+
const DEFAULT_SCOPES = ["*"];
|
|
325
|
+
var HotkeyStore = class {
|
|
326
|
+
constructor(options) {
|
|
327
|
+
require_defineProperty._defineProperty(this, "state", void 0);
|
|
328
|
+
require_defineProperty._defineProperty(this, "context", {});
|
|
329
|
+
require_defineProperty._defineProperty(this, "rootNode", void 0);
|
|
330
|
+
require_defineProperty._defineProperty(this, "sequenceTimeoutMs", 1e3);
|
|
331
|
+
require_defineProperty._defineProperty(this, "sequenceStates", /* @__PURE__ */ new Map());
|
|
332
|
+
require_defineProperty._defineProperty(this, "registrationOrder", 0);
|
|
333
|
+
require_defineProperty._defineProperty(this, "platform", "mac");
|
|
334
|
+
require_defineProperty._defineProperty(this, "listeners", {
|
|
335
|
+
capture: {},
|
|
336
|
+
bubble: {}
|
|
337
|
+
});
|
|
338
|
+
require_defineProperty._defineProperty(this, "subscribers", /* @__PURE__ */ new Set());
|
|
339
|
+
const defaultScopes = options?.activeScopes ? toArray(options.activeScopes) : DEFAULT_SCOPES;
|
|
340
|
+
this.state = {
|
|
341
|
+
pressedKeys: /* @__PURE__ */ new Set(),
|
|
342
|
+
commands: /* @__PURE__ */ new Map(),
|
|
343
|
+
listening: false,
|
|
344
|
+
activeScopes: new Set(defaultScopes)
|
|
345
|
+
};
|
|
346
|
+
if (options?.sequenceTimeoutMs !== void 0) this.sequenceTimeoutMs = options.sequenceTimeoutMs;
|
|
347
|
+
}
|
|
348
|
+
init(options) {
|
|
349
|
+
if (!options.rootNode) throw new Error("rootNode is required for initialization");
|
|
350
|
+
this.rootNode = options.rootNode;
|
|
351
|
+
this.context = options.context ?? {};
|
|
352
|
+
this.platform = getPlatform();
|
|
353
|
+
this.updateParsedHotkeys();
|
|
354
|
+
this.updateListeners();
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
destroy() {
|
|
358
|
+
this.stopListening();
|
|
359
|
+
this.clear();
|
|
360
|
+
this.subscribers.clear();
|
|
361
|
+
this.sequenceStates.clear();
|
|
362
|
+
this.rootNode = void 0;
|
|
363
|
+
this.registrationOrder = 0;
|
|
364
|
+
}
|
|
365
|
+
setContext(context) {
|
|
366
|
+
this.context = context;
|
|
367
|
+
this.notifySubscribers();
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
getContext() {
|
|
371
|
+
return this.context;
|
|
372
|
+
}
|
|
373
|
+
setScope(scope) {
|
|
374
|
+
const scopes = toArray(scope);
|
|
375
|
+
this.state.activeScopes = new Set(scopes);
|
|
376
|
+
this.sequenceStates.clear();
|
|
377
|
+
this.notifySubscribers();
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
addScope(scope) {
|
|
381
|
+
this.state.activeScopes.add(scope);
|
|
382
|
+
this.notifySubscribers();
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
removeScope(scope) {
|
|
386
|
+
this.state.activeScopes.delete(scope);
|
|
387
|
+
this.notifySubscribers();
|
|
388
|
+
return this;
|
|
389
|
+
}
|
|
390
|
+
getActiveScopes() {
|
|
391
|
+
return [...this.state.activeScopes];
|
|
392
|
+
}
|
|
393
|
+
getState() {
|
|
394
|
+
return this.state;
|
|
395
|
+
}
|
|
396
|
+
toggleScope(scope) {
|
|
397
|
+
if (this.state.activeScopes.has(scope)) this.state.activeScopes.delete(scope);
|
|
398
|
+
else this.state.activeScopes.add(scope);
|
|
399
|
+
this.notifySubscribers();
|
|
400
|
+
return this;
|
|
401
|
+
}
|
|
402
|
+
subscribe(selector, callback) {
|
|
403
|
+
const subscriber = {
|
|
404
|
+
selector,
|
|
405
|
+
callback,
|
|
406
|
+
lastValue: selector(this.state, this.context)
|
|
407
|
+
};
|
|
408
|
+
this.subscribers.add(subscriber);
|
|
409
|
+
return () => {
|
|
410
|
+
this.subscribers.delete(subscriber);
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
register(commands) {
|
|
414
|
+
const commandArray = toArray(commands);
|
|
415
|
+
for (const command of commandArray) {
|
|
416
|
+
const scopes = command.scopes ? toArray(command.scopes) : DEFAULT_SCOPES;
|
|
417
|
+
const parsed = parseHotkey(command.hotkey, this.platform);
|
|
418
|
+
const priority = getHotkeyPriority(parsed);
|
|
419
|
+
this.state.commands.set(command.id, {
|
|
420
|
+
id: command.id,
|
|
421
|
+
hotkey: command.hotkey,
|
|
422
|
+
action: command.action,
|
|
423
|
+
options: {
|
|
424
|
+
...defaultOptions,
|
|
425
|
+
...command.options
|
|
426
|
+
},
|
|
427
|
+
enabled: command.enabled ?? true,
|
|
428
|
+
scopes,
|
|
429
|
+
keywords: command.keywords ?? [],
|
|
430
|
+
_parsed: parsed,
|
|
431
|
+
_priority: priority,
|
|
432
|
+
_registrationOrder: this.registrationOrder++,
|
|
433
|
+
...command.label !== void 0 && { label: command.label },
|
|
434
|
+
...command.description !== void 0 && { description: command.description },
|
|
435
|
+
...command.category !== void 0 && { category: command.category }
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
this.updateListeners();
|
|
439
|
+
this.notifySubscribers();
|
|
440
|
+
return this;
|
|
441
|
+
}
|
|
442
|
+
unregister(id) {
|
|
443
|
+
const command = this.state.commands.get(id);
|
|
444
|
+
if (command) {
|
|
445
|
+
this.state.commands.delete(id);
|
|
446
|
+
this.resetSequence(command.hotkey);
|
|
447
|
+
this.updateListeners();
|
|
448
|
+
this.notifySubscribers();
|
|
449
|
+
}
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
enable(id) {
|
|
453
|
+
const command = this.state.commands.get(id);
|
|
454
|
+
if (command) {
|
|
455
|
+
command.enabled = true;
|
|
456
|
+
this.updateListeners();
|
|
457
|
+
this.notifySubscribers();
|
|
458
|
+
}
|
|
459
|
+
return this;
|
|
460
|
+
}
|
|
461
|
+
disable(id) {
|
|
462
|
+
const command = this.state.commands.get(id);
|
|
463
|
+
if (command) {
|
|
464
|
+
command.enabled = false;
|
|
465
|
+
this.updateListeners();
|
|
466
|
+
this.notifySubscribers();
|
|
467
|
+
}
|
|
468
|
+
return this;
|
|
469
|
+
}
|
|
470
|
+
setEnabled(id, enabled) {
|
|
471
|
+
const command = this.state.commands.get(id);
|
|
472
|
+
if (command) {
|
|
473
|
+
command.enabled = enabled;
|
|
474
|
+
this.updateListeners();
|
|
475
|
+
this.notifySubscribers();
|
|
476
|
+
}
|
|
477
|
+
return this;
|
|
478
|
+
}
|
|
479
|
+
clear() {
|
|
480
|
+
for (const hotkey of this.sequenceStates.keys()) this.resetSequence(hotkey);
|
|
481
|
+
this.state.commands.clear();
|
|
482
|
+
this.updateListeners();
|
|
483
|
+
this.notifySubscribers();
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
486
|
+
isPressed(hotkey) {
|
|
487
|
+
let cachedCommand;
|
|
488
|
+
for (const cmd of this.state.commands.values()) if (cmd.hotkey === hotkey) {
|
|
489
|
+
cachedCommand = cmd;
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
const parsed = cachedCommand?._parsed ?? parseHotkey(hotkey, this.platform);
|
|
493
|
+
const keysMatch = parsed.keys.every((k) => this.state.pressedKeys.has(k));
|
|
494
|
+
const modifiersMatch = (!parsed.alt || this.state.pressedKeys.has("Alt")) && (!parsed.ctrl || this.state.pressedKeys.has("Control")) && (!parsed.meta || this.state.pressedKeys.has("Meta")) && (!parsed.shift || this.state.pressedKeys.has("Shift"));
|
|
495
|
+
return keysMatch && modifiersMatch;
|
|
496
|
+
}
|
|
497
|
+
getCurrentlyPressed() {
|
|
498
|
+
return [...this.state.pressedKeys];
|
|
499
|
+
}
|
|
500
|
+
updateParsedHotkeys() {
|
|
501
|
+
for (const command of this.state.commands.values()) if (command.hotkey.split(MODIFIER_SEPARATOR).some((part) => isModKey(part.trim()))) {
|
|
502
|
+
const parsed = parseHotkey(command.hotkey, this.platform);
|
|
503
|
+
command._parsed = parsed;
|
|
504
|
+
command._priority = getHotkeyPriority(parsed);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
updateListeners() {
|
|
508
|
+
if (!this.rootNode) return;
|
|
509
|
+
if (this.state.commands.size > 0) this.startListening();
|
|
510
|
+
else this.stopListening();
|
|
511
|
+
}
|
|
512
|
+
startListening() {
|
|
513
|
+
if (!this.rootNode || this.state.listening) return;
|
|
514
|
+
const win = getWin(this.rootNode);
|
|
515
|
+
const captureKeyDownHandler = this.createKeyDownHandler(true);
|
|
516
|
+
const captureKeyUpHandler = this.createKeyUpHandler();
|
|
517
|
+
const captureBlurHandler = this.createBlurHandler();
|
|
518
|
+
const bubbleKeyDownHandler = this.createKeyDownHandler(false);
|
|
519
|
+
const bubbleKeyUpHandler = this.createKeyUpHandler();
|
|
520
|
+
const bubbleBlurHandler = this.createBlurHandler();
|
|
521
|
+
this.listeners.capture.keyDown = captureKeyDownHandler;
|
|
522
|
+
this.listeners.capture.keyUp = captureKeyUpHandler;
|
|
523
|
+
this.listeners.capture.blur = captureBlurHandler;
|
|
524
|
+
this.listeners.bubble.keyDown = bubbleKeyDownHandler;
|
|
525
|
+
this.listeners.bubble.keyUp = bubbleKeyUpHandler;
|
|
526
|
+
this.listeners.bubble.blur = bubbleBlurHandler;
|
|
527
|
+
const phases = this.getListenerPhases();
|
|
528
|
+
if (phases.capture) {
|
|
529
|
+
this.rootNode.addEventListener("keydown", captureKeyDownHandler, true);
|
|
530
|
+
this.rootNode.addEventListener("keyup", captureKeyUpHandler, true);
|
|
531
|
+
win.addEventListener("blur", captureBlurHandler);
|
|
532
|
+
win.addEventListener("contextmenu", captureBlurHandler);
|
|
533
|
+
}
|
|
534
|
+
if (phases.bubble) {
|
|
535
|
+
this.rootNode.addEventListener("keydown", bubbleKeyDownHandler, false);
|
|
536
|
+
this.rootNode.addEventListener("keyup", bubbleKeyUpHandler, false);
|
|
537
|
+
win.addEventListener("blur", bubbleBlurHandler);
|
|
538
|
+
win.addEventListener("contextmenu", bubbleBlurHandler);
|
|
539
|
+
}
|
|
540
|
+
this.state.listening = true;
|
|
541
|
+
}
|
|
542
|
+
stopListening() {
|
|
543
|
+
if (!this.rootNode || !this.state.listening) return;
|
|
544
|
+
const win = getWin(this.rootNode);
|
|
545
|
+
if (this.listeners.capture.keyDown) this.rootNode.removeEventListener("keydown", this.listeners.capture.keyDown, true);
|
|
546
|
+
if (this.listeners.capture.keyUp) this.rootNode.removeEventListener("keyup", this.listeners.capture.keyUp, true);
|
|
547
|
+
if (this.listeners.capture.blur) {
|
|
548
|
+
win.removeEventListener("blur", this.listeners.capture.blur);
|
|
549
|
+
win.removeEventListener("contextmenu", this.listeners.capture.blur);
|
|
550
|
+
}
|
|
551
|
+
if (this.listeners.bubble.keyDown) this.rootNode.removeEventListener("keydown", this.listeners.bubble.keyDown, false);
|
|
552
|
+
if (this.listeners.bubble.keyUp) this.rootNode.removeEventListener("keyup", this.listeners.bubble.keyUp, false);
|
|
553
|
+
if (this.listeners.bubble.blur) {
|
|
554
|
+
win.removeEventListener("blur", this.listeners.bubble.blur);
|
|
555
|
+
win.removeEventListener("contextmenu", this.listeners.bubble.blur);
|
|
556
|
+
}
|
|
557
|
+
this.listeners.capture = {};
|
|
558
|
+
this.listeners.bubble = {};
|
|
559
|
+
this.state.listening = false;
|
|
560
|
+
}
|
|
561
|
+
getListenerPhases() {
|
|
562
|
+
let capture = false;
|
|
563
|
+
let bubble = false;
|
|
564
|
+
for (const command of this.state.commands.values()) {
|
|
565
|
+
if (!(typeof command.enabled === "function" ? command.enabled(this.context) : command.enabled)) continue;
|
|
566
|
+
if (command.options.capture !== false) capture = true;
|
|
567
|
+
else bubble = true;
|
|
568
|
+
if (capture && bubble) break;
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
capture,
|
|
572
|
+
bubble
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
createKeyDownHandler(isCapture) {
|
|
576
|
+
return ((event) => {
|
|
577
|
+
this.executeMatchingCommands(event, isCapture);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
createKeyUpHandler() {
|
|
581
|
+
return ((event) => {
|
|
582
|
+
const eventKey = normalizeKey(event.key);
|
|
583
|
+
this.state.pressedKeys.delete(eventKey);
|
|
584
|
+
this.notifySubscribers();
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
createBlurHandler() {
|
|
588
|
+
return (() => {
|
|
589
|
+
this.state.pressedKeys.clear();
|
|
590
|
+
for (const hotkey of this.sequenceStates.keys()) this.resetSequence(hotkey);
|
|
591
|
+
this.notifySubscribers();
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
async executeMatchingCommands(event, capture) {
|
|
595
|
+
const eventKey = normalizeKey(event.key);
|
|
596
|
+
this.state.pressedKeys.add(eventKey);
|
|
597
|
+
this.notifySubscribers();
|
|
598
|
+
const matches = [];
|
|
599
|
+
for (const [, command] of this.state.commands) {
|
|
600
|
+
if (!(typeof command.enabled === "function" ? command.enabled(this.context) : command.enabled)) continue;
|
|
601
|
+
if (command.options.capture !== false !== capture) continue;
|
|
602
|
+
if (!command.scopes.some((scope) => scope === "*" || this.state.activeScopes.has(scope))) continue;
|
|
603
|
+
if (!shouldTrigger(event, command.options)) continue;
|
|
604
|
+
if (command._parsed.isSequence ? this.handleSequence(command.hotkey, command._parsed, eventKey, event) : matchesHotkey(command._parsed, event)) matches.push({
|
|
605
|
+
command,
|
|
606
|
+
priority: command._priority
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
if (matches.length === 0) return;
|
|
610
|
+
matches.sort((a, b) => {
|
|
611
|
+
if (b.priority !== a.priority) return b.priority - a.priority;
|
|
612
|
+
return a.command._registrationOrder - b.command._registrationOrder;
|
|
613
|
+
});
|
|
614
|
+
const highestPriority = matches[0].priority;
|
|
615
|
+
const toExecute = matches.filter((m) => m.priority === highestPriority);
|
|
616
|
+
for (const { command } of toExecute) {
|
|
617
|
+
if (command.options.preventDefault) event.preventDefault();
|
|
618
|
+
if (command.options.stopPropagation) event.stopPropagation();
|
|
619
|
+
try {
|
|
620
|
+
await command.action(this.context, event);
|
|
621
|
+
} catch (error) {
|
|
622
|
+
console.error(`Error executing hotkey command "${command.id}":`, error);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
handleSequence(hotkeyString, parsed, eventKey, event) {
|
|
627
|
+
if (!this.rootNode) {
|
|
628
|
+
console.warn("Cannot handle sequence: rootNode is not initialized");
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
const win = getWin(this.rootNode);
|
|
632
|
+
let state = this.sequenceStates.get(hotkeyString);
|
|
633
|
+
if (!state) {
|
|
634
|
+
state = { recordedKeys: [] };
|
|
635
|
+
this.sequenceStates.set(hotkeyString, state);
|
|
636
|
+
}
|
|
637
|
+
if (state.timeoutId) clearTimeout(state.timeoutId);
|
|
638
|
+
const currentStepIndex = state.recordedKeys.length;
|
|
639
|
+
const expectedStep = parsed.sequenceSteps?.[currentStepIndex];
|
|
640
|
+
if (expectedStep) {
|
|
641
|
+
const keyMatches = eventKey === expectedStep.key;
|
|
642
|
+
const codeMatches = parsed.codes && parsed.codes[currentStepIndex] === event.code;
|
|
643
|
+
const modifiersMatch = (expectedStep.alt || false) === event.altKey && (expectedStep.ctrl || false) === event.ctrlKey && (expectedStep.meta || false) === event.metaKey && (expectedStep.shift || false) === event.shiftKey;
|
|
644
|
+
if ((keyMatches || codeMatches) && modifiersMatch) {
|
|
645
|
+
state.recordedKeys.push(eventKey);
|
|
646
|
+
if (state.recordedKeys.length === parsed.sequenceSteps.length) {
|
|
647
|
+
this.resetSequence(hotkeyString);
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
state.timeoutId = win.setTimeout(() => {
|
|
651
|
+
this.resetSequence(hotkeyString);
|
|
652
|
+
}, this.sequenceTimeoutMs);
|
|
653
|
+
} else this.resetSequence(hotkeyString);
|
|
654
|
+
} else this.resetSequence(hotkeyString);
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
resetSequence(hotkey) {
|
|
658
|
+
const state = this.sequenceStates.get(hotkey);
|
|
659
|
+
if (state && typeof state.timeoutId === "number") clearTimeout(state.timeoutId);
|
|
660
|
+
this.sequenceStates.delete(hotkey);
|
|
661
|
+
}
|
|
662
|
+
notifySubscribers() {
|
|
663
|
+
for (const subscriber of this.subscribers) try {
|
|
664
|
+
const newValue = subscriber.selector(this.state, this.context);
|
|
665
|
+
if (newValue !== subscriber.lastValue) {
|
|
666
|
+
subscriber.lastValue = newValue;
|
|
667
|
+
subscriber.callback(newValue);
|
|
668
|
+
}
|
|
669
|
+
} catch (error) {
|
|
670
|
+
console.error("Error in hotkey store subscriber:", error);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
function createHotkeyStore(options) {
|
|
675
|
+
const store = new HotkeyStore(options);
|
|
676
|
+
if (options?.rootNode) store.init(options);
|
|
677
|
+
return store;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region src/shared/hotkeys/format.ts
|
|
682
|
+
const PLATFORM_MODIFIERS = {
|
|
683
|
+
mac: {
|
|
684
|
+
Control: "⌃",
|
|
685
|
+
Alt: "⌥",
|
|
686
|
+
Shift: "⇧",
|
|
687
|
+
Meta: "⌘"
|
|
688
|
+
},
|
|
689
|
+
windows: {
|
|
690
|
+
Control: "Ctrl",
|
|
691
|
+
Alt: "Alt",
|
|
692
|
+
Shift: "Shift",
|
|
693
|
+
Meta: "Win"
|
|
694
|
+
},
|
|
695
|
+
linux: {
|
|
696
|
+
Control: "Ctrl",
|
|
697
|
+
Alt: "Alt",
|
|
698
|
+
Shift: "Shift",
|
|
699
|
+
Meta: "Super"
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
const KEY_SYMBOLS = new Map([
|
|
703
|
+
["ArrowUp", "↑"],
|
|
704
|
+
["ArrowDown", "↓"],
|
|
705
|
+
["ArrowLeft", "←"],
|
|
706
|
+
["ArrowRight", "→"],
|
|
707
|
+
["Backspace", "⌫"],
|
|
708
|
+
["Delete", "⌦"],
|
|
709
|
+
["Enter", "↵"],
|
|
710
|
+
["Tab", "⇥"],
|
|
711
|
+
["Escape", "Esc"],
|
|
712
|
+
["Space", "␣"],
|
|
713
|
+
[" ", "␣"]
|
|
714
|
+
]);
|
|
715
|
+
const KEY_NAMES = new Map([
|
|
716
|
+
["ArrowUp", "Up"],
|
|
717
|
+
["ArrowDown", "Down"],
|
|
718
|
+
["ArrowLeft", "Left"],
|
|
719
|
+
["ArrowRight", "Right"],
|
|
720
|
+
["Space", "Space"],
|
|
721
|
+
[" ", "Space"]
|
|
722
|
+
]);
|
|
723
|
+
function formatHotkey(hotkey, options = {}) {
|
|
724
|
+
const { platform = "auto", style = "mixed", separator = " ", sequenceSeparator = " then ", useShortNames = true } = options;
|
|
725
|
+
const targetPlatform = platform === "auto" ? getPlatform() : platform;
|
|
726
|
+
if (hotkey.includes(SEQUENCE_SEPARATOR)) return hotkey.split(SEQUENCE_SEPARATOR).map((part) => formatSingleHotkey(part.trim(), targetPlatform, style, separator, useShortNames)).join(sequenceSeparator);
|
|
727
|
+
return formatSingleHotkey(hotkey, targetPlatform, style, separator, useShortNames);
|
|
728
|
+
}
|
|
729
|
+
function formatSingleHotkey(hotkey, platform, style, separator, useShortNames) {
|
|
730
|
+
if (!hotkey.trim()) return "";
|
|
731
|
+
const parsed = parseHotkey(hotkey, platform);
|
|
732
|
+
const modifiers = [];
|
|
733
|
+
if (parsed.ctrl) modifiers.push("Control");
|
|
734
|
+
if (parsed.alt) modifiers.push("Alt");
|
|
735
|
+
if (parsed.shift) modifiers.push("Shift");
|
|
736
|
+
if (parsed.meta) modifiers.push("Meta");
|
|
737
|
+
const keys = parsed.keys;
|
|
738
|
+
const platformModifiers = PLATFORM_MODIFIERS[platform];
|
|
739
|
+
const formattedModifiers = modifiers.map((modifier) => {
|
|
740
|
+
const mappedModifier = platformModifiers[modifier];
|
|
741
|
+
if (style === "symbols" && platform === "mac") return mappedModifier || modifier;
|
|
742
|
+
if (style === "text" || platform !== "mac") return useShortNames && modifier === "Control" ? "Ctrl" : mappedModifier || modifier;
|
|
743
|
+
return mappedModifier || modifier;
|
|
744
|
+
});
|
|
745
|
+
const formattedKeys = keys.map((key) => {
|
|
746
|
+
if (style === "symbols") return KEY_SYMBOLS.get(key) || key;
|
|
747
|
+
if (style === "text") return KEY_NAMES.get(key) || key;
|
|
748
|
+
return KEY_SYMBOLS.get(key) || KEY_NAMES.get(key) || key;
|
|
749
|
+
});
|
|
750
|
+
return [...formattedModifiers, ...formattedKeys].join(separator);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
//#endregion
|
|
754
|
+
exports.HotkeyStore = HotkeyStore;
|
|
755
|
+
exports.createHotkeyStore = createHotkeyStore;
|
|
756
|
+
exports.formatHotkey = formatHotkey;
|
|
757
|
+
exports.isHotKey = isHotKey;
|
|
758
|
+
exports.parseHotkey = parseHotkey;
|