@peter.naydenov/shortcuts 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/AGENTS.md +54 -0
  2. package/Changelog.md +14 -0
  3. package/README.md +935 -426
  4. package/dist/plugins/click/_listenDOM.d.ts +2 -2
  5. package/dist/plugins/form/_listenDOM.d.ts +4 -4
  6. package/dist/plugins/hover/_listenDOM.d.ts +2 -2
  7. package/dist/plugins/key/_listenDOM.d.ts +2 -2
  8. package/dist/plugins/scroll/_listenDOM.d.ts +2 -2
  9. package/dist/shortcuts.cjs +1 -1
  10. package/dist/shortcuts.esm.mjs +1 -1
  11. package/dist/shortcuts.umd.js +1 -1
  12. package/graphify-out/.graphify_benchmark.json +35 -0
  13. package/graphify-out/.graphify_python +1 -0
  14. package/graphify-out/GRAPH_REPORT.md +121 -0
  15. package/graphify-out/cache/024633ee076562ce0dbc0bf3b5315906f4e5d48c57bc96856b98cd5d42a69009.json +1 -0
  16. package/graphify-out/cache/037d2ba5552034c06beca677b1914ac7a053f696dfeaf12ca0de06eb42659f18.json +1 -0
  17. package/graphify-out/cache/055bfc2a3bfb8747f7ee0b7335704d2dff1c071d25a9bdd4f954e4cc2d630772.json +1 -0
  18. package/graphify-out/cache/0b2f626892ed04f158e39593dbf5f266c2a5982a21b2dddb144edc79af81e2d1.json +1 -0
  19. package/graphify-out/cache/0c17fe866170c4ab4023ac0680d1e05c5dc232a17ac0f08dfa1e76c2eaf75c44.json +1 -0
  20. package/graphify-out/cache/1392dca26291b5396829f1a996aac2c1d34a03d134a5fcf54e4f15824ee74e2b.json +1 -0
  21. package/graphify-out/cache/18113cd08ebffb11ed91ffab9c6d34795e22bfb5993941db07a52eed6eba45b8.json +1 -0
  22. package/graphify-out/cache/1a7a71b157cadd117435818e1a6561157c2930c4066d3a207fe04e318f76b296.json +1 -0
  23. package/graphify-out/cache/2448db4b822a94d6f3512ce8788077f35dfb567aef8628a846fad841b40575e7.json +1 -0
  24. package/graphify-out/cache/2592868b7b9d2de3f2cb575b7bd68ca2f252d34f71c12f2e8721d789cfbfbf88.json +1 -0
  25. package/graphify-out/cache/2aaf58292523f67421e6f728fd97740c5bf07dd903cf267cf557a4383759ba5e.json +1 -0
  26. package/graphify-out/cache/349a418954e66e5ef45370dca740ebff559a72d11f5810f6d40c0af14ef768e0.json +1 -0
  27. package/graphify-out/cache/361eacb4abb14862b75257bdf673a353826bf5764fb187ccde94ae21454bcf99.json +1 -0
  28. package/graphify-out/cache/40b4c82a11a2a31b279563c143d91d7894eb3f3d0c386f8323cb8062bcdfadd5.json +1 -0
  29. package/graphify-out/cache/40db98ff036ad694953cb13628795fabc0c5892ff093dfdcc18a309ac0d10846.json +1 -0
  30. package/graphify-out/cache/43a590ac22f05be183ea1a4655922185595c969f79dd3df3d44d1c7e49355785.json +1 -0
  31. package/graphify-out/cache/4993a6e98dcf33bb6fa78341b4eeac4776e2322f10522eecdc5195aa7969f35a.json +1 -0
  32. package/graphify-out/cache/5095c6e52a24f4ecec9acf63835761ad508df88d56b1799faec47672fbd4e348.json +1 -0
  33. package/graphify-out/cache/5cba1d38ffea01d8c62e5a0b0d8b164cf9b115ff1b6f1acc606f78877712d5de.json +1 -0
  34. package/graphify-out/cache/67aadf0b8f90224cb725e903e6fedbf6828f203467a633f98031b0740930cb21.json +1 -0
  35. package/graphify-out/cache/68dffbffbd811942d85ef2600ca31e423d3c3c343de98cbba4c954c94dd11470.json +1 -0
  36. package/graphify-out/cache/69c684e506b9ce22e95aff044c1da4b0f88ef72c510da02a739edbe551372a8e.json +1 -0
  37. package/graphify-out/cache/6e336587fcfe2b298f23326e881f048d37f1bb062d00806c338da58a8fd281ca.json +1 -0
  38. package/graphify-out/cache/78d88737e6db913f091c4c48e96953df065f6808e2b60dd828fdee64067dac91.json +1 -0
  39. package/graphify-out/cache/7e5340b989299a0b7217d1fd0d2b919cba65142f3e468b0aca5f4ffd5c0594d8.json +1 -0
  40. package/graphify-out/cache/813d6bac52066ed8733781c35710ecb7995e6cabbe0d9abb9854e3c67610b974.json +1 -0
  41. package/graphify-out/cache/8180f34832546e874bc5f1931eee545d97300be49faac5c9b6d515653a763324.json +1 -0
  42. package/graphify-out/cache/885894ca90af6a3724182762bc4fc7ff7d22727a931d46fe7593d1eea10c0c71.json +1 -0
  43. package/graphify-out/cache/8a304ae8f6bf02bfa40923cdbea99e4bea943db52c185f22caa43ba7c34f94d3.json +1 -0
  44. package/graphify-out/cache/903a7dea28112a27dcc1b9ece66514f4d5dd6ca264f5ee70835aca069a8df2ad.json +1 -0
  45. package/graphify-out/cache/9831a7833c5bfeb9a0611e416f7038bd37884b42a9a720f9b4c0a01f860a4f54.json +1 -0
  46. package/graphify-out/cache/98dbdcdd1b19bc942850f50b1ebdeb1865c72ba724990217464efd28a3732b32.json +1 -0
  47. package/graphify-out/cache/a2459f621d588f0166ae6a4204bb6b89f9d669b3ad0c54a88afac6c7abb134b4.json +1 -0
  48. package/graphify-out/cache/a25d47ecf087fa6888d641f89f08cefd35c68b5823c8c55b3baa0243ab110110.json +1 -0
  49. package/graphify-out/cache/a3bd22d8493943a3195c3ef1254a7240624a962edf2baa2c30eb0ae60564fbe7.json +1 -0
  50. package/graphify-out/cache/a4d4fb674183a3b348f542b1b9fb9c0d7b176c43636afb2554af088a9613a1c0.json +1 -0
  51. package/graphify-out/cache/a87a705106773b14c5a25697d30c743cdab01df551cdd9892d6ec46f98ad1659.json +1 -0
  52. package/graphify-out/cache/a9416d0397b5fb994b8c3847aea2599a9d33940e6f0652accc5ba1de478349ee.json +1 -0
  53. package/graphify-out/cache/ab03b9df0e9b8a74db3782c96fee833d800d93838fc0c056306ac2ef9a3e0c09.json +1 -0
  54. package/graphify-out/cache/ad3a99182567225cc19374c28d33097f146547bd945967c723b66d1065134ce9.json +1 -0
  55. package/graphify-out/cache/aece91cfc3a5181bbb77a1758921dfb6a323ab04cc402ce42f2832446d04f420.json +1 -0
  56. package/graphify-out/cache/bd65fd515423e8964058f6aa997c05e3e0fb9e6d39209d4a1d76a079c6af46e8.json +1 -0
  57. package/graphify-out/cache/c2a85071784f9516ab2dea976eeb3a514a53b15701bbf60b4d8be6cd3385cd6c.json +1 -0
  58. package/graphify-out/cache/c9a8c9342926031f308af0eb0a8d60cf0b443e84bae839da42998956465e47e6.json +1 -0
  59. package/graphify-out/cache/d05c0aa647a624e0c696f53c027d066c35d0893695e9a23fd820235ee86b4a70.json +1 -0
  60. package/graphify-out/cache/d3d9832015ab51f52ae88375cea2cbeabecd4a000578e28e899ce23e74245733.json +1 -0
  61. package/graphify-out/cache/d449ad503a40840d41cbf24ed57f408bf5fdf891f830990f836cf52da5c605eb.json +1 -0
  62. package/graphify-out/cache/d92b22194973f3c39ac53d85a29f5d4837d07b0f9f0d375e3ddce8da158777fb.json +1 -0
  63. package/graphify-out/cache/dda8f89f688d8a4db8b7279031ad26a0d8d4accc0aa049abda5fa19eac4bd5ef.json +1 -0
  64. package/graphify-out/cache/e1d80dbca10b7e2ba65339eff0649699c6091d30b836a1e9d5d094bb95aacc48.json +1 -0
  65. package/graphify-out/cache/e207108277cbe1af0501688b0268fea879d0414424386fbaa93a5861f306bdba.json +1 -0
  66. package/graphify-out/cache/e6032dad287da859a517d6b59105595db90e81833dbd850b37653bbd0f3acef7.json +1 -0
  67. package/graphify-out/cache/f49d7295a833de68579e0e265832bc78d21e901764e31705423e621a703124dc.json +1 -0
  68. package/graphify-out/cache/fcf90a1251a332948a773c6aaaad4ce7f6de8d2f2333687cb2fe94e0d860a6c9.json +1 -0
  69. package/graphify-out/cache/fe06fcb623d36858b89c8741696482530a084f599d48bea88de7943fae0f9bea.json +1 -0
  70. package/graphify-out/cache/ffa0f819e023809d17aac1af75cf0f6fbf08500615aee27341b658f24357105a.json +1 -0
  71. package/graphify-out/cost.json +12 -0
  72. package/graphify-out/graph.html +266 -0
  73. package/graphify-out/graph.json +634 -0
  74. package/graphify-out/manifest.json +124 -0
  75. package/how-to-create-a-plugin.md +573 -0
  76. package/package.json +23 -21
  77. package/src/main.js +5 -5
  78. package/src/plugins/click/_listenDOM.js +3 -3
  79. package/src/plugins/form/_listenDOM.js +7 -6
  80. package/src/plugins/hover/_listenDOM.js +2 -2
  81. package/src/plugins/key/_listenDOM.js +4 -4
  82. package/src/plugins/scroll/_listenDOM.js +1 -1
  83. package/test/01-general.test.js +1 -1
  84. package/test/02-key.test.js +45 -1
  85. package/test/03-click.test.js +51 -2
  86. package/test/04-form.test.js +26 -1
  87. package/test/05-hover.test.js +50 -2
  88. package/test/06-scroll.test.js +21 -0
  89. package/How.to.create.plugins.md +0 -929
@@ -29,7 +29,7 @@ export type ClickEventData = {
29
29
  */
30
30
  event: Event;
31
31
  /**
32
- * - Extra dependencies object
32
+ * - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
33
33
  */
34
34
  dependencies: any;
35
35
  /**
@@ -68,7 +68,7 @@ export type ClickEventData = {
68
68
  * @property {string|null} note - Current context note
69
69
  * @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
70
70
  * @property {Event} event - The original DOM event
71
- * @property {Object} dependencies - Extra dependencies object
71
+ * @property {Object} dependencies - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
72
72
  * @property {Object} viewport - Viewport information with X, Y, width, height
73
73
  * @property {Object} sizes - Element dimensions with width, height
74
74
  * @property {Object} position - Element position relative to viewport with x, y
@@ -17,7 +17,7 @@ export type FormEventData = {
17
17
  */
18
18
  event: Event;
19
19
  /**
20
- * - Extra dependencies object
20
+ * - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
21
21
  */
22
22
  dependencies: any;
23
23
  /**
@@ -41,7 +41,7 @@ export type FormEventData = {
41
41
  */
42
42
  pagePosition: any;
43
43
  /**
44
- * - Event type ('form-in', 'form-out', 'form-instant')
44
+ * - Event type ('form'). The timing (in/out/instant) lives in the emitted event name (e.g. `email/in`, `email/instant`)
45
45
  */
46
46
  type: string;
47
47
  };
@@ -57,12 +57,12 @@ export type FormEventData = {
57
57
  * @property {string} context - Current context name
58
58
  * @property {string|null} note - Current context note
59
59
  * @property {Event} event - The original DOM event
60
- * @property {Object} dependencies - Extra dependencies object
60
+ * @property {Object} dependencies - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
61
61
  * @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
62
62
  * @property {Object} viewport - Viewport information with X, Y, width, height
63
63
  * @property {Object} sizes - Element dimensions with width, height
64
64
  * @property {Object} position - Element position relative to viewport with x, y
65
65
  * @property {Object} pagePosition - Element position relative to page with x, y
66
- * @property {string} type - Event type ('form-in', 'form-out', 'form-instant')
66
+ * @property {string} type - Event type ('form'). The timing (in/out/instant) lives in the emitted event name (e.g. `email/in`, `email/instant`)
67
67
  */
68
68
  declare function _listenDOM(dependencies: any, state: any): any;
@@ -17,7 +17,7 @@ export type HoverEventData = {
17
17
  */
18
18
  event: Event;
19
19
  /**
20
- * - Extra dependencies object
20
+ * - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
21
21
  */
22
22
  dependencies: any;
23
23
  /**
@@ -57,7 +57,7 @@ export type HoverEventData = {
57
57
  * @property {string} context - Current context name
58
58
  * @property {string|null} note - Current context note
59
59
  * @property {Event} event - The original DOM event
60
- * @property {Object} dependencies - Extra dependencies object
60
+ * @property {Object} dependencies - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
61
61
  * @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
62
62
  * @property {Object} viewport - Viewport information with X, Y, width, height
63
63
  * @property {Object} sizes - Element dimensions with width, height
@@ -25,7 +25,7 @@ export type KeyEventData = {
25
25
  */
26
26
  context: string;
27
27
  /**
28
- * - Extra dependencies object
28
+ * - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
29
29
  */
30
30
  dependencies: any;
31
31
  /**
@@ -55,7 +55,7 @@ export type KeyEventData = {
55
55
  * @property {Function} isWaiting - Function to check if currently waiting for keys
56
56
  * @property {string|null} note - Current context note
57
57
  * @property {string} context - Current context name
58
- * @property {Object} dependencies - Extra dependencies object
58
+ * @property {Object} dependencies - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
59
59
  * @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
60
60
  * @property {Object} viewport - Viewport information with X, Y, width, height
61
61
  * @property {string} type - Event type ('key')
@@ -21,7 +21,7 @@ export type ScrollEventData = {
21
21
  */
22
22
  note: string | null;
23
23
  /**
24
- * - Extra dependencies object
24
+ * - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
25
25
  */
26
26
  dependencies: any;
27
27
  /**
@@ -50,7 +50,7 @@ export type ScrollEventData = {
50
50
  * @property {string} direction - Scroll direction ('up', 'down', 'left', 'right')
51
51
  * @property {string} context - Current context name
52
52
  * @property {string|null} note - Current context note
53
- * @property {Object} dependencies - Extra dependencies object
53
+ * @property {Object} dependencies - Reference to the library's `extra` bag. Always includes `emit: ev.emit` plus any keys you set via `short.setDependencies({...})`
54
54
  * @property {Object} options - Plugin state listenOptions (reference to pluginState.listenOptions)
55
55
  * @property {Object} viewport - Viewport information with X, Y, width, height
56
56
  * @property {string} type - Event type ('scroll')
@@ -1 +1 @@
1
- "use strict";var t=require("@peter.naydenov/notice");var e={_normalizeWithPlugins:function(t,e){return function(t){const n=e.shortcuts;Object.keys(n).forEach(e=>{Object.entries(n[e]).forEach(([i,o])=>{const r=t(i);r!==i&&(delete n[e][i],n[e][r]=o)})})}},_readShortcutWithPlugins:function(t,e){return function(n){const{inAPI:i}=t,o=n.split(":")[0].toLowerCase().trim(),r=i._systemAction(o,"none");let s=n;return-1!==r&&(s=e.plugins[r].shortcutName(n)),s}},_setupPlugin:function(t,e){const{inAPI:n}=t,{currentContext:i,shortcuts:o,exposeShortcut:r,ERROR_EVENT_NAME:s}=e;return function(e){const{prefix:c,_normalizeShortcutName:u,_registerShortcutEvents:l,_listenDOM:a,pluginState:p,deps:d}=e,{resetState:f}=d;p.currentContext=i,p.shortcuts=o,p.exposeShortcut=r,p.ERROR_EVENT_NAME=s;const h={ev:t.ev,extra:t.extra,...d};n._normalizeWithPlugins(u);let m=l(h,p);const g=a(h,p);m>0&&g.start();const v={getPrefix:()=>c,shortcutName:t=>u(t),contextChange:()=>{f(),m=l(h,p),m<1&&g.stop(),m>0&&g.start()},mute:()=>g.stop(),unmute:()=>g.start(),destroy:()=>{g.stop(),f()}};return Object.freeze(v),v}},_systemAction:function(t,e){return function(t,n,i=null){return e.plugins.findIndex(e=>e.getPrefix()===t&&(e[n]&&e[n](i),!0))}},changeContext:function(t,e){const{shortcuts:n,currentContext:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t=!1){const s=i.name;if(!t)return r.reset(),void(i.name=null);s!==t&&(n[t]?(n[s]&&r.reset(),i.name=t,e.plugins.forEach(e=>e.contextChange(t)),Object.entries(n[t]).forEach(([t,e])=>{t.includes(":SETUP")||e.forEach(e=>r.on(t,e))}),r.on("*",(...t)=>{e.exposeShortcut&&e.exposeShortcut(...t)})):r.emit(o,`Context '${t}' does not exist`))}},listShortcuts:function(t,e){const n=e.shortcuts;return function(t=null){if(null!=t){const e=n[t];return null==e?null:Object.entries(e).map(([t,e])=>t)}return Object.keys(n).map(t=>{const e={};return e.context=t,e.shortcuts=Object.entries(n[t]).map(([t,e])=>t),e})}},load:function(t,e){const{shortcuts:n,plugins:i}=e,{API:{changeContext:o,getContext:r}}=t;return function(t){const e=r(),s=i.map(t=>t.getPrefix().toUpperCase());let c=!1;Object.entries(t).forEach(([t,o])=>{t===e&&(c=!0),n[t]={},Object.entries(o).forEach(([e,o])=>{let r=e;const c=e.toUpperCase().trim(),u=s.map((t,e)=>c.startsWith(t)?e:null).filter(t=>null!==t);if(u.length){const t=u[0];r=i[t].shortcutName(e)}o instanceof Function&&(o=[o]),n[t][r]=o})}),c&&(o(),o(e))}},unload:function(t,e){const{currentContext:n,shortcuts:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t){n.name!==t?i[t]?delete i[t]:r.emit(o,`Context '${t}' does not exist`):r.emit(o,`Context '${t}' can't be removed during is current active context. Change the context first`)}}};function n(t,e){const{ev:n,_specialChars:i,_readKeyEvent:o,extra:r,resetState:s}=t,{currentContext:c,streamKeys:u,listenOptions:l}=e;let a=[],p=null,d=!0,f=!1;const h=()=>d=!1,m=()=>d=!0,g=()=>f=!0,v=()=>!1===d;function x(){const t=a.map(t=>[t.join("+")]),i={wait:h,end:m,ignore:g,isWaiting:v,note:c.note,context:c.name,dependencies:r,options:e.listenOptions,viewport:{X:window.scrollX,Y:window.scrollY,width:window.innerWidth,height:window.innerHeight},type:"key"};if(!d){const e=`KEY:${t.at(-1).join("+")}`;n.emit(e,i),f&&(a=a.slice(0,-1),f=!1)}if(d){const o=`KEY:${t.join(",")}`;n.emit(o,i),f&&(a=a.slice(0,-1),f=!1),a=[],clearTimeout(e.keyIgnore),e.keyIgnore=null,clearTimeout(p),p=null}}function E(n){clearTimeout(p);if(i().hasOwnProperty(n.code))return a.push(o(n,i)),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore?(clearTimeout(e.keyIgnore),e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait),void a.pop()):d&&a.length===e.maxSequence?(x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait))):void(d?p=setTimeout(x,l.keyWait):x())}function O(n){if(!i().hasOwnProperty(n.code)){if(clearTimeout(p),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore)return clearTimeout(e.keyIgnore),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));if(a.push(o(n,i)),d&&a.length===e.maxSequence)return x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));d?p=setTimeout(x,l.keyWait):x()}}return{start:function(){e.active||(document.addEventListener("keydown",E),document.addEventListener("keypress",O),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("keydown",E),document.removeEventListener("keypress",O),e.active=!1,p&&(clearTimeout(p),p=null),e.keyIgnore&&(clearTimeout(e.keyIgnore),e.keyIgnore=null),a=[],d=!0,f=!1)}}}function i(t){const e=t.toUpperCase(),n=/KEY\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"KEY:SETUP";return`KEY:${e.slice(i+1).split(",").map(t=>t.trim()).map(t=>t.split("+").map(t=>t.trim()).sort().join("+")).join(",")}`}function o(t,e){const{shiftKey:n,altKey:i,ctrlKey:o}=t,r=e(),s=t.code.replace("Key","").replace("Digit",""),c=[];return o&&c.push("CTRL"),n&&c.push("SHIFT"),i&&c.push("ALT"),r.hasOwnProperty(s)?c.push(r[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||c.push(s.toUpperCase()),c.sort()}function r(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s?0:(Object.entries(c[s]).forEach(([s,c])=>{if(!r.test(s))return;if("KEY:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const u=s.slice(4).split(",").length;e.maxSequence<u&&(e.maxSequence=u)}),i||Object.assign(e.listenOptions,o),n)}function s(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function c(t,e,n){const{listenOptions:{clickTarget:i}}=e,o=n;if(o===document.body)return null;return i.some(t=>o.hasAttribute(t))?o:c(t,e,o.parentNode)}function u(t,e){const{ev:n,_findTarget:i,_readClickEvent:o,extra:r}=t,{listenOptions:s,currentContext:c}=e;let u=null,l=null,a=null,p=null,d=0;function f(){if(!u)return;const{left:t,top:i,width:s,height:f}=u.getBoundingClientRect(),h=window.scrollX,m=window.scrollY,g=o(l,d),v={target:u,x:l.clientX,y:l.clientY,context:c.name,note:c.note,options:e.listenOptions,event:l,dependencies:r,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:f},position:{x:t,y:i},pagePosition:{x:t+h,y:i+m},type:"click"};n.emit(g,v),a=null,p=null,u=null,l=null,d=0}function h(n){let o=e.maxLeftClicks;if(clearTimeout(a),p)return clearTimeout(p),void(p=setTimeout(()=>p=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return f(),void(o>1&&(p=setTimeout(()=>p=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}function m(n){let o=e.maxRightClicks;if(clearTimeout(a),p)return clearTimeout(p),void(p=setTimeout(()=>p=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return f(),void(o>1&&(p=setTimeout(()=>p=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}return{start:function(){e.active||(window.addEventListener("contextmenu",m),document.addEventListener("click",h),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("contextmenu",m),document.removeEventListener("click",h),e.active=!1,p&&(clearTimeout(p),p=null),u=null,l=null,d=0)}}}function l(t){const e=t.toUpperCase(),n=/CLICK\s*\:/i.test(e),i=["LEFT","MIDDLE","RIGHT"],o=["ALT","SHIFT","CTRL"];let r=null,s=0;const c=[],u=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"CLICK:SETUP";return e.slice(u+1).trim().split("-").map(t=>t.trim()).forEach(t=>{i.includes(t)?r=t:o.includes(t)?c.push(t):isNaN(t)||(s=t)}),`CLICK:${r}-${s}${c.length>0?"-":""}${c.sort().join("-")}`}function a(t,e){const{shiftKey:n,altKey:i,ctrlKey:o,key:r,button:s}=t,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][s]}-${e}`,u=[];return o&&u.push("CTRL"),n&&u.push("SHIFT"),i&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function p(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{listenOptions:s,currentContext:{name:c},shortcuts:u}=e;return null==c||(Object.entries(u[c]).forEach(([c,u])=>{if(!r.test(c))return;if("CLICK:SETUP"===c){i=!0;const n=u.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:s});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const[l,a]=c.slice(6).split("-");"LEFT"===l&&e.maxLeftClicks<a&&(e.maxLeftClicks=a),"RIGHT"===l&&e.maxRightClicks<a&&(e.maxRightClicks=a)}),i||Object.assign(e.listenOptions,o)),n}function d(t,e){const{ev:n}=t;let i=null;function o(t,e,n,i){const{left:o,top:r,width:s,height:c}=n.target.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:n.target,context:e.currentContext.name,note:e.currentContext.note,event:n,dependencies:t.extra,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:o,y:r},pagePosition:{x:o+u,y:r+l},type:i}}function r(i){const{callbacks:r,typeFn:s}=e;i.target;const c=o(t,e,i,"form-in"),u=`${s(c)}/in`;null!=r[u]&&n.emit(u,c,r[u])}function s(i){const{callbacks:r,typeFn:s}=e,c=o(t,e,i,"form-out"),u=`${s(c)}/out`;null!=r[u]&&n.emit(u,c,r[u])}function c(r){const{callbacks:s,typeFn:c}=e,u=o(t,e,r,"form-instant"),l=c(u),a=e.wait[`${l}`],p=`${l}/instant`;if(null==s[p])return;if(0===a)return void n.emit(p,u,s[p]);clearTimeout(i),i=setTimeout(()=>n.emit(p,u,s[p]),a)}return{start:function(){e.active||(document.addEventListener("focusin",r),document.addEventListener("focusout",s),document.addEventListener("input",c),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("focusin",r),document.removeEventListener("focusout",s),document.removeEventListener("input",c),e.active=!1,i&&(clearTimeout(i),i=null))}}}function f(t){const e=t.toUpperCase(),n=/FORM\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`FORM:${e.slice(i+1).trim()}`}function h(t,e){const{regex:n,_defaults:i,ev:o}=t,{currentContext:{name:r,note:s},shortcuts:c,callbacks:u,ERROR_EVENT_NAME:l,defaultOptions:a}=e;let p=[],d=[],f=[],h=0;if(null==r)return!1;if(Object.entries(c[r]).forEach(([i,o])=>{if(n.test(i)){if(i.includes("SETUP")){const n=o.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},a);return void Object.assign(e.listenOptions,n)}"FORM:WATCH"===i&&(p=o),"FORM:DEFINE"===i&&(d=o),"FORM:ACTION"===i&&(f=o)}}),0===f.length)return h;const m=new Set;0===d.length&&(d=[i.define]),0===p.length&&(p=[i.watch]);const g=p.map(n=>n({dependencies:t.extra,context:r,note:s,options:e.listenOptions})).reduce((t,e)=>(t.push(e),t),[]);return e.watchList=document.querySelectorAll(g),e.watchList.forEach(n=>{const{left:i,top:o,width:c,height:u}=n.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return m.add(d[0]({target:n,context:r,note:s,dependencies:t.extra,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:i,y:o},pagePosition:{x:i+l,y:o+a}}))}),e.typeFn=d[0]?d[0]:i.define,f.forEach(n=>{if(!(n instanceof Function))return o.emit(l,"The 'form:action' should be a function."),!1;const i=n({dependencies:t.extra,options:e.listenOptions});if(!(i instanceof Array))return o.emit(l,"Warning: The 'form:action' function should RETURN an array."),!1;i.forEach(({fn:t,type:n,timing:i,wait:r=0})=>{if(m.has(n)&&t instanceof Function){const e=`${n}/${i}`,r=u.hasOwnProperty(e);r?u[e].push(t):u[e]=[t],r||o.on(e,(t,e)=>{e.forEach(e=>{e instanceof Function&&e(t)})})}"instant"===i&&(e.wait[`${n}`]=r)})}),h=Object.keys(e.callbacks).length,h}const m={watch:()=>"input, select, textarea, button, a",define:({target:t})=>"checkbox"===t.type||"radio"===t.type?"checkbox":"button"==t.type||"submit"==t.type?"button":"input"};function g(t,e,n){const{listenOptions:{hoverTarget:i}}=e,o=n;if(o===document.body)return!1;if(o===document)return!1;return i.some(t=>o.hasAttribute(t))?o:g(t,e,o.parentNode)}function v(t,e){const{ev:n,_findTarget:i,resetState:o,extra:r}=t;function s(o){const s=o.clientX,c=o.clientY,{hovered:u,hoverRectangle:l,listenOptions:a,hoverTimer:p,leaveTimer:d,lastEvent:f,lastHoverTarget:h}=e,m=i(t,e,o.target);if(!function(t,e,n){return!!t&&e>=t.left&&e<=t.right&&n>=t.top&&n<=t.bottom}(l,s,c)&&m!==u){if(u&&!m){if(e.hovered=!1,e.hoverRectangle=null,p&&(clearTimeout(p),e.hoverTimer=null),"off"===f)return;return void(e.leaveTimer=setTimeout(()=>{n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"},a.wait))}u&&(n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"),clearTimeout(d),clearTimeout(p),e.hovered=m,e.hoverRectangle=m.getBoundingClientRect(),e.hoverTimer=setTimeout(()=>{n.emit("HOVER:ON",g(m)),e.hoverTimer=null,e.lastHoverTarget=m,e.lastEvent="on"},a.wait)}function g(t){const{left:n,top:i,width:s,height:c}=t.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:t,context:e.currentContext.name,note:e.currentContext.note,event:o,dependencies:r,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:n,y:i},pagePosition:{x:n+u,y:i+l},type:"hover"}}}return{start:function(){e.active||(document.addEventListener("mousemove",s),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("mousemove",s),o())}}}function x(t){const e=t.toUpperCase(),n=/HOVER\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`HOVER:${e.slice(i+1).trim()}`}function E(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r,_defaults:s,ev:c}=t,{currentContext:{name:u},shortcuts:l,ERROR_EVENT_NAME:a}=e;return null==u||(Object.entries(l[u]).forEach(([s,c])=>{if(r.test(s)){if("HOVER:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function O(t,e){const{ev:n,resetState:i,extra:o}=t;let r=null,s=null;function c(t){t.clientX,t.clientY;const{lastPosition:i,lastDirection:c,listenOptions:u,currentContext:l}=e,{scrollWait:a,endScrollWait:p,minSpace:d}=u;if(!i)return;let f=null;const h=window.scrollX,m=window.scrollY,g=Math.abs(m-i.y),v=Math.abs(h-i.x);if(g<d&&v<d)return;const x=[];g>=d&&(m>i.y?x.push("down"):x.push("up")),v>=d&&(h>i.x?x.push("right"):x.push("left")),f=x[0]||null;const E=t=>({x:h,y:m,direction:t,context:l.name,note:l.note,dependencies:o,options:e.listenOptions,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},type:"scroll"});x.forEach(t=>{const e=`SCROLL:${t.toUpperCase()}`;n.emit(e,E(t))}),clearTimeout(r),clearTimeout(s);const O=x[x.length-1]||null;r=setTimeout(()=>{},a),s=setTimeout(()=>n.emit("SCROLL:END",E(O)),p),e.lastPosition={x:h,y:m},e.lastDirection=f}return{start:function(){e.active||(e.lastPosition={x:window.scrollX,y:window.scrollY},window.addEventListener("scroll",c),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("scroll",c),i())}}}function y(t){const e=t.toUpperCase(),n=/SCROLL\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`SCROLL:${e.slice(i+1).trim()}`}function w(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s||(Object.entries(c[s]).forEach(([s,c])=>{if(r.test(s)){if("SCROLL:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}exports.pluginClick=function(t,e={}){const n={_findTarget:c,_readClickEvent:a,regex:/CLICK\s*\:/i},i={active:!1,maxLeftClicks:1,maxRightClicks:1,defaultOptions:{mouseWait:320,clickTarget:["data-click","href"]},listenOptions:{mouseWait:320,clickTarget:["data-click","href"]},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return n.resetState=function(){},t({prefix:"click",_normalizeShortcutName:l,_registerShortcutEvents:p,_listenDOM:u,pluginState:i,deps:n})},exports.pluginForm=function(t,e={}){const n={_defaults:m,regex:/FORM\s*\:/i},i={callbacks:{},typeFn:"",watchList:[],wait:{},defaultOptions:{},listenOptions:{}};return n.resetState=function(){i.callbacks={},i.typeFn="",i.watchList=[],i.wait={}},t({prefix:"form",_normalizeShortcutName:f,_registerShortcutEvents:h,_listenDOM:d,pluginState:i,deps:n})},exports.pluginHover=function(t,e={}){const n={_findTarget:g,regex:/HOVER\s*\:/i},i={active:!1,hovered:!1,hoverRectangle:null,hoverTimer:null,leaveTimer:null,lastEvent:"",lastHoverTarget:null,defaultOptions:{hoverTarget:["data-hover"],wait:320},listenOptions:{hoverTarget:["data-hover"],wait:320}};return n.resetState=function(){i.active=!1,i.hovered=!1,i.hoverRectangle=null,clearTimeout(i.hoverTimer),clearTimeout(i.leaveTimer),i.hoverTimer=null,i.leaveTimer=null,i.lastHoverTarget=null},t({prefix:"hover",_normalizeShortcutName:x,_registerShortcutEvents:E,_listenDOM:v,pluginState:i,deps:n})},exports.pluginKey=function(t,e={}){const c={_specialChars:s,_readKeyEvent:o,regex:/KEY\s*\:/i},u={active:!1,maxSequence:1,keyIgnore:null,defaultOptions:{keyWait:480},listenOptions:{keyWait:480},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return c.resetState=function(){u.active=!1,u.keyIgnore=null,u.maxSequence=1},t({prefix:"key",_normalizeShortcutName:i,_registerShortcutEvents:r,_listenDOM:n,pluginState:u,deps:c})},exports.pluginScroll=function(t,e={}){const n={regex:/SCROLL\s*\:/i},i={active:!1,lastPosition:null,lastDirection:null,defaultOptions:{scrollWait:50,endScrollWait:400,minSpace:40},listenOptions:{scrollWait:50,endScrollWait:400,minSpace:40}};return n.resetState=function(){i.active=!1},t({prefix:"scroll",_normalizeShortcutName:y,_registerShortcutEvents:w,_listenDOM:O,pluginState:i,deps:n})},exports.shortcuts=function(n={}){const i={},o={},r=t(),s={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!n.onShortcut||"function"!=typeof n.onShortcut)&&n.onShortcut,ERROR_EVENT_NAME:n.errorEventName?n.errorEventName:"@shortcuts-error"},c={ev:r,inAPI:i,API:o,extra:{}};return o.enablePlugin=(t,e={})=>{if("function"!=typeof t)return;const n=t(i._setupPlugin,e),o=n.getPrefix(),r=i._systemAction(o,"none");-1===r?(s.plugins.push(n),n.unmute()):(n.destroy(),s.plugins[r].unmute())},o.disablePlugin=t=>{const e=i._systemAction(t,"destroy");-1!==e&&s.plugins.splice(e,1)},o.mutePlugin=t=>i._systemAction(t,"mute"),o.unmutePlugin=t=>i._systemAction(t,"unmute"),o.listPlugins=()=>s.plugins.map(t=>t.getPrefix()),o.getContext=()=>s.currentContext.name,o.getNote=()=>s.currentContext.note,o.setNote=(t=null)=>{"string"!=typeof t&&null!=t||(s.currentContext.note=t)},o.pause=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.stop(e)},o.resume=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.start(e)},o.emit=(t,...e)=>r.emit(i._readShortcutWithPlugins(t),...e),o.listContexts=()=>Object.keys(s.shortcuts),o.setDependencies=t=>Object.assign(c.extra,t),o.getDependencies=()=>c.extra,o.reset=function(){r.reset(),o.changeContext(),s.plugins.forEach(t=>t.destroy()),o.listContexts().map(t=>o.unload(t)),c.extra={},s.exposeShortcut=null},Object.entries(e).forEach(([t,e])=>{t.startsWith("_")?i[t]=e(c,s):o[t]=e(c,s)}),o};
1
+ "use strict";var t=require("@peter.naydenov/notice");var e={_normalizeWithPlugins:function(t,e){return function(t){const n=e.shortcuts;Object.keys(n).forEach(e=>{Object.entries(n[e]).forEach(([i,o])=>{const r=t(i);r!==i&&(delete n[e][i],n[e][r]=o)})})}},_readShortcutWithPlugins:function(t,e){return function(n){const{inAPI:i}=t,o=n.split(":")[0].toLowerCase().trim(),r=i._systemAction(o,"none");let s=n;return-1!==r&&(s=e.plugins[r].shortcutName(n)),s}},_setupPlugin:function(t,e){const{inAPI:n}=t,{currentContext:i,shortcuts:o,exposeShortcut:r,ERROR_EVENT_NAME:s}=e;return function(e){const{prefix:c,_normalizeShortcutName:u,_registerShortcutEvents:l,_listenDOM:a,pluginState:p,deps:d}=e,{resetState:f}=d;p.currentContext=i,p.shortcuts=o,p.exposeShortcut=r,p.ERROR_EVENT_NAME=s;const h={ev:t.ev,extra:t.extra,...d};n._normalizeWithPlugins(u);let m=l(h,p);const g=a(h,p);m>0&&g.start();const v={getPrefix:()=>c,shortcutName:t=>u(t),contextChange:()=>{f(),m=l(h,p),m<1&&g.stop(),m>0&&g.start()},mute:()=>g.stop(),unmute:()=>g.start(),destroy:()=>{g.stop(),f()}};return Object.freeze(v),v}},_systemAction:function(t,e){return function(t,n,i=null){return e.plugins.findIndex(e=>e.getPrefix()===t&&(e[n]&&e[n](i),!0))}},changeContext:function(t,e){const{shortcuts:n,currentContext:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t=!1){const s=i.name;if(!t)return r.reset(),void(i.name=null);s!==t&&(n[t]?(n[s]&&r.reset(),i.name=t,e.plugins.forEach(e=>e.contextChange(t)),Object.entries(n[t]).forEach(([t,e])=>{t.includes(":SETUP")||e.forEach(e=>r.on(t,e))}),r.on("*",(...t)=>{e.exposeShortcut&&e.exposeShortcut(...t)})):r.emit(o,`Context '${t}' does not exist`))}},listShortcuts:function(t,e){const n=e.shortcuts;return function(t=null){if(null!=t){const e=n[t];return null==e?null:Object.entries(e).map(([t,e])=>t)}return Object.keys(n).map(t=>{const e={};return e.context=t,e.shortcuts=Object.entries(n[t]).map(([t,e])=>t),e})}},load:function(t,e){const{shortcuts:n,plugins:i}=e,{API:{changeContext:o,getContext:r}}=t;return function(t){const e=r(),s=i.map(t=>t.getPrefix().toUpperCase());let c=!1;Object.entries(t).forEach(([t,o])=>{t===e&&(c=!0),n[t]={},Object.entries(o).forEach(([e,o])=>{let r=e;const c=e.toUpperCase().trim(),u=s.map((t,e)=>c.startsWith(t)?e:null).filter(t=>null!==t);if(u.length){const t=u[0];r=i[t].shortcutName(e)}o instanceof Function&&(o=[o]),n[t][r]=o})}),c&&(o(),o(e))}},unload:function(t,e){const{currentContext:n,shortcuts:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t){n.name!==t?i[t]?delete i[t]:r.emit(o,`Context '${t}' does not exist`):r.emit(o,`Context '${t}' can't be removed during is current active context. Change the context first`)}}};function n(t,e){const{ev:n,_specialChars:i,_readKeyEvent:o,extra:r,resetState:s}=t,{currentContext:c,streamKeys:u,listenOptions:l}=e;let a=[],p=null,d=!0,f=!1;const h=()=>d=!1,m=()=>d=!0,g=()=>f=!0,v=()=>!1===d;function x(){const t=a.map(t=>[t.join("+")]),i={wait:h,end:m,ignore:g,isWaiting:v,note:c.note,context:c.name,dependencies:r,options:e.listenOptions,viewport:{X:window.scrollX,Y:window.scrollY,width:window.innerWidth,height:window.innerHeight},type:"key"};if(!d){const e=`KEY:${t.at(-1).join("+")}`;n.emit(e,i),f&&(a=a.slice(0,-1),f=!1)}if(d){const o=`KEY:${t.join(",")}`;n.emit(o,i),f&&(a=a.slice(0,-1),f=!1),a=[],clearTimeout(e.keyIgnore),e.keyIgnore=null,clearTimeout(p),p=null}}function E(n){clearTimeout(p);if(i().hasOwnProperty(n.code))return a.push(o(n,i)),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore?(clearTimeout(e.keyIgnore),e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait),void a.pop()):d&&a.length===e.maxSequence?(x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait))):void(d?p=setTimeout(x,l.keyWait):x())}function O(n){if(!i().hasOwnProperty(n.code)){if(clearTimeout(p),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore)return clearTimeout(e.keyIgnore),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));if(a.push(o(n,i)),d&&a.length===e.maxSequence)return x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));d?p=setTimeout(x,l.keyWait):x()}}return{start:function(){e.active||(document.addEventListener("keydown",E),document.addEventListener("keypress",O),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("keydown",E),document.removeEventListener("keypress",O),e.active=!1,p&&(clearTimeout(p),p=null),e.keyIgnore&&(clearTimeout(e.keyIgnore),e.keyIgnore=null),a=[],d=!0,f=!1)}}}function i(t){const e=t.toUpperCase(),n=/KEY\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"KEY:SETUP";return`KEY:${e.slice(i+1).split(",").map(t=>t.trim()).map(t=>t.split("+").map(t=>t.trim()).sort().join("+")).join(",")}`}function o(t,e){const{shiftKey:n,altKey:i,ctrlKey:o}=t,r=e(),s=t.code.replace("Key","").replace("Digit",""),c=[];return o&&c.push("CTRL"),n&&c.push("SHIFT"),i&&c.push("ALT"),r.hasOwnProperty(s)?c.push(r[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||c.push(s.toUpperCase()),c.sort()}function r(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s?0:(Object.entries(c[s]).forEach(([s,c])=>{if(!r.test(s))return;if("KEY:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const u=s.slice(4).split(",").length;e.maxSequence<u&&(e.maxSequence=u)}),i||Object.assign(e.listenOptions,o),n)}function s(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function c(t,e,n){const{listenOptions:{clickTarget:i}}=e,o=n;if(o===document.body)return null;return i.some(t=>o.hasAttribute(t))?o:c(t,e,o.parentNode)}function u(t,e){const{ev:n,_findTarget:i,_readClickEvent:o,extra:r}=t,{listenOptions:s,currentContext:c}=e;let u=null,l=null,a=null,p=null,d=0;function f(){if(!u)return;const{left:t,top:i,width:s,height:f}=u.getBoundingClientRect(),h=window.scrollX,m=window.scrollY,g=o(l,d),v={target:u,x:l.clientX,y:l.clientY,context:c.name,note:c.note,options:e.listenOptions,event:l,dependencies:r,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:f},position:{x:t,y:i},pagePosition:{x:t+h,y:i+m},type:"click"};n.emit(g,v),a=null,p=null,u=null,l=null,d=0}function h(n){let o=e.maxLeftClicks;if(clearTimeout(a),p)return clearTimeout(p),void(p=setTimeout(()=>p=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return f(),void(o>1&&(p=setTimeout(()=>p=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}function m(n){let o=e.maxRightClicks;if(clearTimeout(a),p)return clearTimeout(p),void(p=setTimeout(()=>p=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return f(),void(o>1&&(p=setTimeout(()=>p=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}return{start:function(){e.active||(window.addEventListener("contextmenu",m),document.addEventListener("click",h),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("contextmenu",m),document.removeEventListener("click",h),e.active=!1,p&&(clearTimeout(p),p=null),u=null,l=null,d=0)}}}function l(t){const e=t.toUpperCase(),n=/CLICK\s*\:/i.test(e),i=["LEFT","MIDDLE","RIGHT"],o=["ALT","SHIFT","CTRL"];let r=null,s=0;const c=[],u=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"CLICK:SETUP";return e.slice(u+1).trim().split("-").map(t=>t.trim()).forEach(t=>{i.includes(t)?r=t:o.includes(t)?c.push(t):isNaN(t)||(s=t)}),`CLICK:${r}-${s}${c.length>0?"-":""}${c.sort().join("-")}`}function a(t,e){const{shiftKey:n,altKey:i,ctrlKey:o,key:r,button:s}=t,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][s]}-${e}`,u=[];return o&&u.push("CTRL"),n&&u.push("SHIFT"),i&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function p(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{listenOptions:s,currentContext:{name:c},shortcuts:u}=e;return null==c||(Object.entries(u[c]).forEach(([c,u])=>{if(!r.test(c))return;if("CLICK:SETUP"===c){i=!0;const n=u.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:s});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const[l,a]=c.slice(6).split("-");"LEFT"===l&&e.maxLeftClicks<a&&(e.maxLeftClicks=a),"RIGHT"===l&&e.maxRightClicks<a&&(e.maxRightClicks=a)}),i||Object.assign(e.listenOptions,o)),n}function d(t,e){const{ev:n}=t;let i=null;function o(t,e,n,i){const{extra:o}=t,{left:r,top:s,width:c,height:u}=n.target.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return{target:n.target,context:e.currentContext.name,note:e.currentContext.note,event:n,dependencies:o,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:r,y:s},pagePosition:{x:r+l,y:s+a},type:i}}function r(i){const{callbacks:r,typeFn:s}=e;i.target;const c=o(t,e,i,"form"),u=`${s(c)}/in`;null!=r[u]&&n.emit(u,c,r[u])}function s(i){const{callbacks:r,typeFn:s}=e,c=o(t,e,i,"form"),u=`${s(c)}/out`;null!=r[u]&&n.emit(u,c,r[u])}function c(r){const{callbacks:s,typeFn:c}=e,u=o(t,e,r,"form"),l=c(u),a=e.wait[`${l}`],p=`${l}/instant`;if(null==s[p])return;if(0===a)return void n.emit(p,u,s[p]);clearTimeout(i),i=setTimeout(()=>n.emit(p,u,s[p]),a)}return{start:function(){e.active||(document.addEventListener("focusin",r),document.addEventListener("focusout",s),document.addEventListener("input",c),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("focusin",r),document.removeEventListener("focusout",s),document.removeEventListener("input",c),e.active=!1,i&&(clearTimeout(i),i=null))}}}function f(t){const e=t.toUpperCase(),n=/FORM\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`FORM:${e.slice(i+1).trim()}`}function h(t,e){const{regex:n,_defaults:i,ev:o}=t,{currentContext:{name:r,note:s},shortcuts:c,callbacks:u,ERROR_EVENT_NAME:l,defaultOptions:a}=e;let p=[],d=[],f=[],h=0;if(null==r)return!1;if(Object.entries(c[r]).forEach(([i,o])=>{if(n.test(i)){if(i.includes("SETUP")){const n=o.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},a);return void Object.assign(e.listenOptions,n)}"FORM:WATCH"===i&&(p=o),"FORM:DEFINE"===i&&(d=o),"FORM:ACTION"===i&&(f=o)}}),0===f.length)return h;const m=new Set;0===d.length&&(d=[i.define]),0===p.length&&(p=[i.watch]);const g=p.map(n=>n({dependencies:t.extra,context:r,note:s,options:e.listenOptions})).reduce((t,e)=>(t.push(e),t),[]);return e.watchList=document.querySelectorAll(g),e.watchList.forEach(n=>{const{left:i,top:o,width:c,height:u}=n.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return m.add(d[0]({target:n,context:r,note:s,dependencies:t.extra,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:i,y:o},pagePosition:{x:i+l,y:o+a}}))}),e.typeFn=d[0]?d[0]:i.define,f.forEach(n=>{if(!(n instanceof Function))return o.emit(l,"The 'form:action' should be a function."),!1;const i=n({dependencies:t.extra,options:e.listenOptions});if(!(i instanceof Array))return o.emit(l,"Warning: The 'form:action' function should RETURN an array."),!1;i.forEach(({fn:t,type:n,timing:i,wait:r=0})=>{if(m.has(n)&&t instanceof Function){const e=`${n}/${i}`,r=u.hasOwnProperty(e);r?u[e].push(t):u[e]=[t],r||o.on(e,(t,e)=>{e.forEach(e=>{e instanceof Function&&e(t)})})}"instant"===i&&(e.wait[`${n}`]=r)})}),h=Object.keys(e.callbacks).length,h}const m={watch:()=>"input, select, textarea, button, a",define:({target:t})=>"checkbox"===t.type||"radio"===t.type?"checkbox":"button"==t.type||"submit"==t.type?"button":"input"};function g(t,e,n){const{listenOptions:{hoverTarget:i}}=e,o=n;if(o===document.body)return!1;if(o===document)return!1;return i.some(t=>o.hasAttribute(t))?o:g(t,e,o.parentNode)}function v(t,e){const{ev:n,_findTarget:i,resetState:o,extra:r}=t;function s(o){const s=o.clientX,c=o.clientY,{hovered:u,hoverRectangle:l,listenOptions:a,hoverTimer:p,leaveTimer:d,lastEvent:f,lastHoverTarget:h}=e,m=i(t,e,o.target);if(!function(t,e,n){return!!t&&e>=t.left&&e<=t.right&&n>=t.top&&n<=t.bottom}(l,s,c)&&m!==u){if(u&&!m){if(e.hovered=!1,e.hoverRectangle=null,p&&(clearTimeout(p),e.hoverTimer=null),"off"===f)return;return void(e.leaveTimer=setTimeout(()=>{n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"},a.wait))}u&&(n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"),clearTimeout(d),clearTimeout(p),e.hovered=m,e.hoverRectangle=m.getBoundingClientRect(),e.hoverTimer=setTimeout(()=>{n.emit("HOVER:ON",g(m)),e.hoverTimer=null,e.lastHoverTarget=m,e.lastEvent="on"},a.wait)}function g(t){const{left:n,top:i,width:s,height:c}=t.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:t,context:e.currentContext.name,note:e.currentContext.note,event:o,dependencies:r,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:n,y:i},pagePosition:{x:n+u,y:i+l},type:"hover"}}}return{start:function(){e.active||(document.addEventListener("mousemove",s),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("mousemove",s),o())}}}function x(t){const e=t.toUpperCase(),n=/HOVER\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`HOVER:${e.slice(i+1).trim()}`}function E(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r,_defaults:s,ev:c}=t,{currentContext:{name:u},shortcuts:l,ERROR_EVENT_NAME:a}=e;return null==u||(Object.entries(l[u]).forEach(([s,c])=>{if(r.test(s)){if("HOVER:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function O(t,e){const{ev:n,resetState:i,extra:o}=t;let r=null,s=null;function c(t){t.clientX,t.clientY;const{lastPosition:i,lastDirection:c,listenOptions:u,currentContext:l}=e,{scrollWait:a,endScrollWait:p,minSpace:d}=u;if(!i)return;let f=null;const h=window.scrollX,m=window.scrollY,g=Math.abs(m-i.y),v=Math.abs(h-i.x);if(g<d&&v<d)return;const x=[];g>=d&&(m>i.y?x.push("down"):x.push("up")),v>=d&&(h>i.x?x.push("right"):x.push("left")),f=x[0]||null;const E=t=>({x:h,y:m,direction:t,context:l.name,note:l.note,dependencies:o,options:e.listenOptions,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},type:"scroll"});x.forEach(t=>{const e=`SCROLL:${t.toUpperCase()}`;n.emit(e,E(t))}),clearTimeout(r),clearTimeout(s);const O=x[x.length-1]||null;r=setTimeout(()=>{},a),s=setTimeout(()=>n.emit("SCROLL:END",E(O)),p),e.lastPosition={x:h,y:m},e.lastDirection=f}return{start:function(){e.active||(e.lastPosition={x:window.scrollX,y:window.scrollY},window.addEventListener("scroll",c),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("scroll",c),i())}}}function y(t){const e=t.toUpperCase(),n=/SCROLL\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`SCROLL:${e.slice(i+1).trim()}`}function w(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s||(Object.entries(c[s]).forEach(([s,c])=>{if(r.test(s)){if("SCROLL:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}exports.pluginClick=function(t,e={}){const n={_findTarget:c,_readClickEvent:a,regex:/CLICK\s*\:/i},i={active:!1,maxLeftClicks:1,maxRightClicks:1,defaultOptions:{mouseWait:320,clickTarget:["data-click","href"]},listenOptions:{mouseWait:320,clickTarget:["data-click","href"]},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return n.resetState=function(){},t({prefix:"click",_normalizeShortcutName:l,_registerShortcutEvents:p,_listenDOM:u,pluginState:i,deps:n})},exports.pluginForm=function(t,e={}){const n={_defaults:m,regex:/FORM\s*\:/i},i={callbacks:{},typeFn:"",watchList:[],wait:{},defaultOptions:{},listenOptions:{}};return n.resetState=function(){i.callbacks={},i.typeFn="",i.watchList=[],i.wait={}},t({prefix:"form",_normalizeShortcutName:f,_registerShortcutEvents:h,_listenDOM:d,pluginState:i,deps:n})},exports.pluginHover=function(t,e={}){const n={_findTarget:g,regex:/HOVER\s*\:/i},i={active:!1,hovered:!1,hoverRectangle:null,hoverTimer:null,leaveTimer:null,lastEvent:"",lastHoverTarget:null,defaultOptions:{hoverTarget:["data-hover"],wait:320},listenOptions:{hoverTarget:["data-hover"],wait:320}};return n.resetState=function(){i.active=!1,i.hovered=!1,i.hoverRectangle=null,clearTimeout(i.hoverTimer),clearTimeout(i.leaveTimer),i.hoverTimer=null,i.leaveTimer=null,i.lastHoverTarget=null},t({prefix:"hover",_normalizeShortcutName:x,_registerShortcutEvents:E,_listenDOM:v,pluginState:i,deps:n})},exports.pluginKey=function(t,e={}){const c={_specialChars:s,_readKeyEvent:o,regex:/KEY\s*\:/i},u={active:!1,maxSequence:1,keyIgnore:null,defaultOptions:{keyWait:480},listenOptions:{keyWait:480},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return c.resetState=function(){u.active=!1,u.keyIgnore=null,u.maxSequence=1},t({prefix:"key",_normalizeShortcutName:i,_registerShortcutEvents:r,_listenDOM:n,pluginState:u,deps:c})},exports.pluginScroll=function(t,e={}){const n={regex:/SCROLL\s*\:/i},i={active:!1,lastPosition:null,lastDirection:null,defaultOptions:{scrollWait:50,endScrollWait:400,minSpace:40},listenOptions:{scrollWait:50,endScrollWait:400,minSpace:40}};return n.resetState=function(){i.active=!1},t({prefix:"scroll",_normalizeShortcutName:y,_registerShortcutEvents:w,_listenDOM:O,pluginState:i,deps:n})},exports.shortcuts=function(n={}){const i={},o={},r=t(),s={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!n.onShortcut||"function"!=typeof n.onShortcut)&&n.onShortcut,ERROR_EVENT_NAME:n.errorEventName?n.errorEventName:"@shortcuts-error"},c={ev:r,inAPI:i,API:o,extra:{emit:r.emit}};return o.enablePlugin=(t,e={})=>{if("function"!=typeof t)return;const n=t(i._setupPlugin,e),o=n.getPrefix(),r=i._systemAction(o,"none");-1===r?(s.plugins.push(n),n.unmute()):(n.destroy(),s.plugins[r].unmute())},o.disablePlugin=t=>{const e=i._systemAction(t,"destroy");-1!==e&&s.plugins.splice(e,1)},o.mutePlugin=t=>i._systemAction(t,"mute"),o.unmutePlugin=t=>i._systemAction(t,"unmute"),o.listPlugins=()=>s.plugins.map(t=>t.getPrefix()),o.getContext=()=>s.currentContext.name,o.getNote=()=>s.currentContext.note,o.setNote=(t=null)=>{"string"!=typeof t&&null!=t||(s.currentContext.note=t)},o.pause=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.stop(e)},o.resume=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.start(e)},o.emit=(t,...e)=>r.emit(i._readShortcutWithPlugins(t),{dependencies:c.extra,type:"custom"},...e),o.listContexts=()=>Object.keys(s.shortcuts),o.setDependencies=t=>Object.assign(c.extra,t),o.getDependencies=()=>c.extra,o.reset=function(){r.reset(),o.changeContext(),s.plugins.forEach(t=>t.destroy()),o.listContexts().map(t=>o.unload(t)),c.extra={emit:r.emit},s.exposeShortcut=null},Object.entries(e).forEach(([t,e])=>{t.startsWith("_")?i[t]=e(c,s):o[t]=e(c,s)}),o};
@@ -1 +1 @@
1
- import t from"@peter.naydenov/notice";var e={_normalizeWithPlugins:function(t,e){return function(t){const n=e.shortcuts;Object.keys(n).forEach(e=>{Object.entries(n[e]).forEach(([i,o])=>{const r=t(i);r!==i&&(delete n[e][i],n[e][r]=o)})})}},_readShortcutWithPlugins:function(t,e){return function(n){const{inAPI:i}=t,o=n.split(":")[0].toLowerCase().trim(),r=i._systemAction(o,"none");let s=n;return-1!==r&&(s=e.plugins[r].shortcutName(n)),s}},_setupPlugin:function(t,e){const{inAPI:n}=t,{currentContext:i,shortcuts:o,exposeShortcut:r,ERROR_EVENT_NAME:s}=e;return function(e){const{prefix:c,_normalizeShortcutName:u,_registerShortcutEvents:l,_listenDOM:a,pluginState:d,deps:p}=e,{resetState:f}=p;d.currentContext=i,d.shortcuts=o,d.exposeShortcut=r,d.ERROR_EVENT_NAME=s;const h={ev:t.ev,extra:t.extra,...p};n._normalizeWithPlugins(u);let m=l(h,d);const g=a(h,d);m>0&&g.start();const v={getPrefix:()=>c,shortcutName:t=>u(t),contextChange:()=>{f(),m=l(h,d),m<1&&g.stop(),m>0&&g.start()},mute:()=>g.stop(),unmute:()=>g.start(),destroy:()=>{g.stop(),f()}};return Object.freeze(v),v}},_systemAction:function(t,e){return function(t,n,i=null){return e.plugins.findIndex(e=>e.getPrefix()===t&&(e[n]&&e[n](i),!0))}},changeContext:function(t,e){const{shortcuts:n,currentContext:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t=!1){const s=i.name;if(!t)return r.reset(),void(i.name=null);s!==t&&(n[t]?(n[s]&&r.reset(),i.name=t,e.plugins.forEach(e=>e.contextChange(t)),Object.entries(n[t]).forEach(([t,e])=>{t.includes(":SETUP")||e.forEach(e=>r.on(t,e))}),r.on("*",(...t)=>{e.exposeShortcut&&e.exposeShortcut(...t)})):r.emit(o,`Context '${t}' does not exist`))}},listShortcuts:function(t,e){const n=e.shortcuts;return function(t=null){if(null!=t){const e=n[t];return null==e?null:Object.entries(e).map(([t,e])=>t)}return Object.keys(n).map(t=>{const e={};return e.context=t,e.shortcuts=Object.entries(n[t]).map(([t,e])=>t),e})}},load:function(t,e){const{shortcuts:n,plugins:i}=e,{API:{changeContext:o,getContext:r}}=t;return function(t){const e=r(),s=i.map(t=>t.getPrefix().toUpperCase());let c=!1;Object.entries(t).forEach(([t,o])=>{t===e&&(c=!0),n[t]={},Object.entries(o).forEach(([e,o])=>{let r=e;const c=e.toUpperCase().trim(),u=s.map((t,e)=>c.startsWith(t)?e:null).filter(t=>null!==t);if(u.length){const t=u[0];r=i[t].shortcutName(e)}o instanceof Function&&(o=[o]),n[t][r]=o})}),c&&(o(),o(e))}},unload:function(t,e){const{currentContext:n,shortcuts:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t){n.name!==t?i[t]?delete i[t]:r.emit(o,`Context '${t}' does not exist`):r.emit(o,`Context '${t}' can't be removed during is current active context. Change the context first`)}}};function n(t,e){const{ev:n,_specialChars:i,_readKeyEvent:o,extra:r,resetState:s}=t,{currentContext:c,streamKeys:u,listenOptions:l}=e;let a=[],d=null,p=!0,f=!1;const h=()=>p=!1,m=()=>p=!0,g=()=>f=!0,v=()=>!1===p;function x(){const t=a.map(t=>[t.join("+")]),i={wait:h,end:m,ignore:g,isWaiting:v,note:c.note,context:c.name,dependencies:r,options:e.listenOptions,viewport:{X:window.scrollX,Y:window.scrollY,width:window.innerWidth,height:window.innerHeight},type:"key"};if(!p){const e=`KEY:${t.at(-1).join("+")}`;n.emit(e,i),f&&(a=a.slice(0,-1),f=!1)}if(p){const o=`KEY:${t.join(",")}`;n.emit(o,i),f&&(a=a.slice(0,-1),f=!1),a=[],clearTimeout(e.keyIgnore),e.keyIgnore=null,clearTimeout(d),d=null}}function E(n){clearTimeout(d);if(i().hasOwnProperty(n.code))return a.push(o(n,i)),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore?(clearTimeout(e.keyIgnore),e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait),void a.pop()):p&&a.length===e.maxSequence?(x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait))):void(p?d=setTimeout(x,l.keyWait):x())}function O(n){if(!i().hasOwnProperty(n.code)){if(clearTimeout(d),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore)return clearTimeout(e.keyIgnore),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));if(a.push(o(n,i)),p&&a.length===e.maxSequence)return x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));p?d=setTimeout(x,l.keyWait):x()}}return{start:function(){e.active||(document.addEventListener("keydown",E),document.addEventListener("keypress",O),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("keydown",E),document.removeEventListener("keypress",O),e.active=!1,d&&(clearTimeout(d),d=null),e.keyIgnore&&(clearTimeout(e.keyIgnore),e.keyIgnore=null),a=[],p=!0,f=!1)}}}function i(t){const e=t.toUpperCase(),n=/KEY\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"KEY:SETUP";return`KEY:${e.slice(i+1).split(",").map(t=>t.trim()).map(t=>t.split("+").map(t=>t.trim()).sort().join("+")).join(",")}`}function o(t,e){const{shiftKey:n,altKey:i,ctrlKey:o}=t,r=e(),s=t.code.replace("Key","").replace("Digit",""),c=[];return o&&c.push("CTRL"),n&&c.push("SHIFT"),i&&c.push("ALT"),r.hasOwnProperty(s)?c.push(r[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||c.push(s.toUpperCase()),c.sort()}function r(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s?0:(Object.entries(c[s]).forEach(([s,c])=>{if(!r.test(s))return;if("KEY:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const u=s.slice(4).split(",").length;e.maxSequence<u&&(e.maxSequence=u)}),i||Object.assign(e.listenOptions,o),n)}function s(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function c(t,e={}){const c={_specialChars:s,_readKeyEvent:o,regex:/KEY\s*\:/i},u={active:!1,maxSequence:1,keyIgnore:null,defaultOptions:{keyWait:480},listenOptions:{keyWait:480},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return c.resetState=function(){u.active=!1,u.keyIgnore=null,u.maxSequence=1},t({prefix:"key",_normalizeShortcutName:i,_registerShortcutEvents:r,_listenDOM:n,pluginState:u,deps:c})}function u(t,e,n){const{listenOptions:{clickTarget:i}}=e,o=n;if(o===document.body)return null;return i.some(t=>o.hasAttribute(t))?o:u(t,e,o.parentNode)}function l(t,e){const{ev:n,_findTarget:i,_readClickEvent:o,extra:r}=t,{listenOptions:s,currentContext:c}=e;let u=null,l=null,a=null,d=null,p=0;function f(){if(!u)return;const{left:t,top:i,width:s,height:f}=u.getBoundingClientRect(),h=window.scrollX,m=window.scrollY,g=o(l,p),v={target:u,x:l.clientX,y:l.clientY,context:c.name,note:c.note,options:e.listenOptions,event:l,dependencies:r,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:f},position:{x:t,y:i},pagePosition:{x:t+h,y:i+m},type:"click"};n.emit(g,v),a=null,d=null,u=null,l=null,p=0}function h(n){let o=e.maxLeftClicks;if(clearTimeout(a),d)return clearTimeout(d),void(d=setTimeout(()=>d=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,p++,p>=o)return f(),void(o>1&&(d=setTimeout(()=>d=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}function m(n){let o=e.maxRightClicks;if(clearTimeout(a),d)return clearTimeout(d),void(d=setTimeout(()=>d=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,p++,p>=o)return f(),void(o>1&&(d=setTimeout(()=>d=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}return{start:function(){e.active||(window.addEventListener("contextmenu",m),document.addEventListener("click",h),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("contextmenu",m),document.removeEventListener("click",h),e.active=!1,d&&(clearTimeout(d),d=null),u=null,l=null,p=0)}}}function a(t){const e=t.toUpperCase(),n=/CLICK\s*\:/i.test(e),i=["LEFT","MIDDLE","RIGHT"],o=["ALT","SHIFT","CTRL"];let r=null,s=0;const c=[],u=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"CLICK:SETUP";return e.slice(u+1).trim().split("-").map(t=>t.trim()).forEach(t=>{i.includes(t)?r=t:o.includes(t)?c.push(t):isNaN(t)||(s=t)}),`CLICK:${r}-${s}${c.length>0?"-":""}${c.sort().join("-")}`}function d(t,e){const{shiftKey:n,altKey:i,ctrlKey:o,key:r,button:s}=t,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][s]}-${e}`,u=[];return o&&u.push("CTRL"),n&&u.push("SHIFT"),i&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function p(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{listenOptions:s,currentContext:{name:c},shortcuts:u}=e;return null==c||(Object.entries(u[c]).forEach(([c,u])=>{if(!r.test(c))return;if("CLICK:SETUP"===c){i=!0;const n=u.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:s});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const[l,a]=c.slice(6).split("-");"LEFT"===l&&e.maxLeftClicks<a&&(e.maxLeftClicks=a),"RIGHT"===l&&e.maxRightClicks<a&&(e.maxRightClicks=a)}),i||Object.assign(e.listenOptions,o)),n}function f(t,e={}){const n={_findTarget:u,_readClickEvent:d,regex:/CLICK\s*\:/i},i={active:!1,maxLeftClicks:1,maxRightClicks:1,defaultOptions:{mouseWait:320,clickTarget:["data-click","href"]},listenOptions:{mouseWait:320,clickTarget:["data-click","href"]},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return n.resetState=function(){},t({prefix:"click",_normalizeShortcutName:a,_registerShortcutEvents:p,_listenDOM:l,pluginState:i,deps:n})}function h(t,e){const{ev:n}=t;let i=null;function o(t,e,n,i){const{left:o,top:r,width:s,height:c}=n.target.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:n.target,context:e.currentContext.name,note:e.currentContext.note,event:n,dependencies:t.extra,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:o,y:r},pagePosition:{x:o+u,y:r+l},type:i}}function r(i){const{callbacks:r,typeFn:s}=e;i.target;const c=o(t,e,i,"form-in"),u=`${s(c)}/in`;null!=r[u]&&n.emit(u,c,r[u])}function s(i){const{callbacks:r,typeFn:s}=e,c=o(t,e,i,"form-out"),u=`${s(c)}/out`;null!=r[u]&&n.emit(u,c,r[u])}function c(r){const{callbacks:s,typeFn:c}=e,u=o(t,e,r,"form-instant"),l=c(u),a=e.wait[`${l}`],d=`${l}/instant`;if(null==s[d])return;if(0===a)return void n.emit(d,u,s[d]);clearTimeout(i),i=setTimeout(()=>n.emit(d,u,s[d]),a)}return{start:function(){e.active||(document.addEventListener("focusin",r),document.addEventListener("focusout",s),document.addEventListener("input",c),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("focusin",r),document.removeEventListener("focusout",s),document.removeEventListener("input",c),e.active=!1,i&&(clearTimeout(i),i=null))}}}function m(t){const e=t.toUpperCase(),n=/FORM\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`FORM:${e.slice(i+1).trim()}`}function g(t,e){const{regex:n,_defaults:i,ev:o}=t,{currentContext:{name:r,note:s},shortcuts:c,callbacks:u,ERROR_EVENT_NAME:l,defaultOptions:a}=e;let d=[],p=[],f=[],h=0;if(null==r)return!1;if(Object.entries(c[r]).forEach(([i,o])=>{if(n.test(i)){if(i.includes("SETUP")){const n=o.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},a);return void Object.assign(e.listenOptions,n)}"FORM:WATCH"===i&&(d=o),"FORM:DEFINE"===i&&(p=o),"FORM:ACTION"===i&&(f=o)}}),0===f.length)return h;const m=new Set;0===p.length&&(p=[i.define]),0===d.length&&(d=[i.watch]);const g=d.map(n=>n({dependencies:t.extra,context:r,note:s,options:e.listenOptions})).reduce((t,e)=>(t.push(e),t),[]);return e.watchList=document.querySelectorAll(g),e.watchList.forEach(n=>{const{left:i,top:o,width:c,height:u}=n.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return m.add(p[0]({target:n,context:r,note:s,dependencies:t.extra,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:i,y:o},pagePosition:{x:i+l,y:o+a}}))}),e.typeFn=p[0]?p[0]:i.define,f.forEach(n=>{if(!(n instanceof Function))return o.emit(l,"The 'form:action' should be a function."),!1;const i=n({dependencies:t.extra,options:e.listenOptions});if(!(i instanceof Array))return o.emit(l,"Warning: The 'form:action' function should RETURN an array."),!1;i.forEach(({fn:t,type:n,timing:i,wait:r=0})=>{if(m.has(n)&&t instanceof Function){const e=`${n}/${i}`,r=u.hasOwnProperty(e);r?u[e].push(t):u[e]=[t],r||o.on(e,(t,e)=>{e.forEach(e=>{e instanceof Function&&e(t)})})}"instant"===i&&(e.wait[`${n}`]=r)})}),h=Object.keys(e.callbacks).length,h}const v={watch:()=>"input, select, textarea, button, a",define:({target:t})=>"checkbox"===t.type||"radio"===t.type?"checkbox":"button"==t.type||"submit"==t.type?"button":"input"};function x(t,e={}){const n={_defaults:v,regex:/FORM\s*\:/i},i={callbacks:{},typeFn:"",watchList:[],wait:{},defaultOptions:{},listenOptions:{}};return n.resetState=function(){i.callbacks={},i.typeFn="",i.watchList=[],i.wait={}},t({prefix:"form",_normalizeShortcutName:m,_registerShortcutEvents:g,_listenDOM:h,pluginState:i,deps:n})}function E(t,e,n){const{listenOptions:{hoverTarget:i}}=e,o=n;if(o===document.body)return!1;if(o===document)return!1;return i.some(t=>o.hasAttribute(t))?o:E(t,e,o.parentNode)}function O(t,e){const{ev:n,_findTarget:i,resetState:o,extra:r}=t;function s(o){const s=o.clientX,c=o.clientY,{hovered:u,hoverRectangle:l,listenOptions:a,hoverTimer:d,leaveTimer:p,lastEvent:f,lastHoverTarget:h}=e,m=i(t,e,o.target);if(!function(t,e,n){return!!t&&e>=t.left&&e<=t.right&&n>=t.top&&n<=t.bottom}(l,s,c)&&m!==u){if(u&&!m){if(e.hovered=!1,e.hoverRectangle=null,d&&(clearTimeout(d),e.hoverTimer=null),"off"===f)return;return void(e.leaveTimer=setTimeout(()=>{n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"},a.wait))}u&&(n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"),clearTimeout(p),clearTimeout(d),e.hovered=m,e.hoverRectangle=m.getBoundingClientRect(),e.hoverTimer=setTimeout(()=>{n.emit("HOVER:ON",g(m)),e.hoverTimer=null,e.lastHoverTarget=m,e.lastEvent="on"},a.wait)}function g(t){const{left:n,top:i,width:s,height:c}=t.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:t,context:e.currentContext.name,note:e.currentContext.note,event:o,dependencies:r,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:n,y:i},pagePosition:{x:n+u,y:i+l},type:"hover"}}}return{start:function(){e.active||(document.addEventListener("mousemove",s),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("mousemove",s),o())}}}function y(t){const e=t.toUpperCase(),n=/HOVER\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`HOVER:${e.slice(i+1).trim()}`}function w(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r,_defaults:s,ev:c}=t,{currentContext:{name:u},shortcuts:l,ERROR_EVENT_NAME:a}=e;return null==u||(Object.entries(l[u]).forEach(([s,c])=>{if(r.test(s)){if("HOVER:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function T(t,e={}){const n={_findTarget:E,regex:/HOVER\s*\:/i},i={active:!1,hovered:!1,hoverRectangle:null,hoverTimer:null,leaveTimer:null,lastEvent:"",lastHoverTarget:null,defaultOptions:{hoverTarget:["data-hover"],wait:320},listenOptions:{hoverTarget:["data-hover"],wait:320}};return n.resetState=function(){i.active=!1,i.hovered=!1,i.hoverRectangle=null,clearTimeout(i.hoverTimer),clearTimeout(i.leaveTimer),i.hoverTimer=null,i.leaveTimer=null,i.lastHoverTarget=null},t({prefix:"hover",_normalizeShortcutName:y,_registerShortcutEvents:w,_listenDOM:O,pluginState:i,deps:n})}function C(t,e){const{ev:n,resetState:i,extra:o}=t;let r=null,s=null;function c(t){t.clientX,t.clientY;const{lastPosition:i,lastDirection:c,listenOptions:u,currentContext:l}=e,{scrollWait:a,endScrollWait:d,minSpace:p}=u;if(!i)return;let f=null;const h=window.scrollX,m=window.scrollY,g=Math.abs(m-i.y),v=Math.abs(h-i.x);if(g<p&&v<p)return;const x=[];g>=p&&(m>i.y?x.push("down"):x.push("up")),v>=p&&(h>i.x?x.push("right"):x.push("left")),f=x[0]||null;const E=t=>({x:h,y:m,direction:t,context:l.name,note:l.note,dependencies:o,options:e.listenOptions,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},type:"scroll"});x.forEach(t=>{const e=`SCROLL:${t.toUpperCase()}`;n.emit(e,E(t))}),clearTimeout(r),clearTimeout(s);const O=x[x.length-1]||null;r=setTimeout(()=>{},a),s=setTimeout(()=>n.emit("SCROLL:END",E(O)),d),e.lastPosition={x:h,y:m},e.lastDirection=f}return{start:function(){e.active||(e.lastPosition={x:window.scrollX,y:window.scrollY},window.addEventListener("scroll",c),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("scroll",c),i())}}}function S(t){const e=t.toUpperCase(),n=/SCROLL\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`SCROLL:${e.slice(i+1).trim()}`}function k(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s||(Object.entries(c[s]).forEach(([s,c])=>{if(r.test(s)){if("SCROLL:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function R(t,e={}){const n={regex:/SCROLL\s*\:/i},i={active:!1,lastPosition:null,lastDirection:null,defaultOptions:{scrollWait:50,endScrollWait:400,minSpace:40},listenOptions:{scrollWait:50,endScrollWait:400,minSpace:40}};return n.resetState=function(){i.active=!1},t({prefix:"scroll",_normalizeShortcutName:S,_registerShortcutEvents:k,_listenDOM:C,pluginState:i,deps:n})}function L(n={}){const i={},o={},r=t(),s={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!n.onShortcut||"function"!=typeof n.onShortcut)&&n.onShortcut,ERROR_EVENT_NAME:n.errorEventName?n.errorEventName:"@shortcuts-error"},c={ev:r,inAPI:i,API:o,extra:{}};return o.enablePlugin=(t,e={})=>{if("function"!=typeof t)return;const n=t(i._setupPlugin,e),o=n.getPrefix(),r=i._systemAction(o,"none");-1===r?(s.plugins.push(n),n.unmute()):(n.destroy(),s.plugins[r].unmute())},o.disablePlugin=t=>{const e=i._systemAction(t,"destroy");-1!==e&&s.plugins.splice(e,1)},o.mutePlugin=t=>i._systemAction(t,"mute"),o.unmutePlugin=t=>i._systemAction(t,"unmute"),o.listPlugins=()=>s.plugins.map(t=>t.getPrefix()),o.getContext=()=>s.currentContext.name,o.getNote=()=>s.currentContext.note,o.setNote=(t=null)=>{"string"!=typeof t&&null!=t||(s.currentContext.note=t)},o.pause=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.stop(e)},o.resume=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.start(e)},o.emit=(t,...e)=>r.emit(i._readShortcutWithPlugins(t),...e),o.listContexts=()=>Object.keys(s.shortcuts),o.setDependencies=t=>Object.assign(c.extra,t),o.getDependencies=()=>c.extra,o.reset=function(){r.reset(),o.changeContext(),s.plugins.forEach(t=>t.destroy()),o.listContexts().map(t=>o.unload(t)),c.extra={},s.exposeShortcut=null},Object.entries(e).forEach(([t,e])=>{t.startsWith("_")?i[t]=e(c,s):o[t]=e(c,s)}),o}export{f as pluginClick,x as pluginForm,T as pluginHover,c as pluginKey,R as pluginScroll,L as shortcuts};
1
+ import t from"@peter.naydenov/notice";var e={_normalizeWithPlugins:function(t,e){return function(t){const n=e.shortcuts;Object.keys(n).forEach(e=>{Object.entries(n[e]).forEach(([i,o])=>{const r=t(i);r!==i&&(delete n[e][i],n[e][r]=o)})})}},_readShortcutWithPlugins:function(t,e){return function(n){const{inAPI:i}=t,o=n.split(":")[0].toLowerCase().trim(),r=i._systemAction(o,"none");let s=n;return-1!==r&&(s=e.plugins[r].shortcutName(n)),s}},_setupPlugin:function(t,e){const{inAPI:n}=t,{currentContext:i,shortcuts:o,exposeShortcut:r,ERROR_EVENT_NAME:s}=e;return function(e){const{prefix:c,_normalizeShortcutName:u,_registerShortcutEvents:l,_listenDOM:a,pluginState:d,deps:p}=e,{resetState:f}=p;d.currentContext=i,d.shortcuts=o,d.exposeShortcut=r,d.ERROR_EVENT_NAME=s;const m={ev:t.ev,extra:t.extra,...p};n._normalizeWithPlugins(u);let h=l(m,d);const g=a(m,d);h>0&&g.start();const v={getPrefix:()=>c,shortcutName:t=>u(t),contextChange:()=>{f(),h=l(m,d),h<1&&g.stop(),h>0&&g.start()},mute:()=>g.stop(),unmute:()=>g.start(),destroy:()=>{g.stop(),f()}};return Object.freeze(v),v}},_systemAction:function(t,e){return function(t,n,i=null){return e.plugins.findIndex(e=>e.getPrefix()===t&&(e[n]&&e[n](i),!0))}},changeContext:function(t,e){const{shortcuts:n,currentContext:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t=!1){const s=i.name;if(!t)return r.reset(),void(i.name=null);s!==t&&(n[t]?(n[s]&&r.reset(),i.name=t,e.plugins.forEach(e=>e.contextChange(t)),Object.entries(n[t]).forEach(([t,e])=>{t.includes(":SETUP")||e.forEach(e=>r.on(t,e))}),r.on("*",(...t)=>{e.exposeShortcut&&e.exposeShortcut(...t)})):r.emit(o,`Context '${t}' does not exist`))}},listShortcuts:function(t,e){const n=e.shortcuts;return function(t=null){if(null!=t){const e=n[t];return null==e?null:Object.entries(e).map(([t,e])=>t)}return Object.keys(n).map(t=>{const e={};return e.context=t,e.shortcuts=Object.entries(n[t]).map(([t,e])=>t),e})}},load:function(t,e){const{shortcuts:n,plugins:i}=e,{API:{changeContext:o,getContext:r}}=t;return function(t){const e=r(),s=i.map(t=>t.getPrefix().toUpperCase());let c=!1;Object.entries(t).forEach(([t,o])=>{t===e&&(c=!0),n[t]={},Object.entries(o).forEach(([e,o])=>{let r=e;const c=e.toUpperCase().trim(),u=s.map((t,e)=>c.startsWith(t)?e:null).filter(t=>null!==t);if(u.length){const t=u[0];r=i[t].shortcutName(e)}o instanceof Function&&(o=[o]),n[t][r]=o})}),c&&(o(),o(e))}},unload:function(t,e){const{currentContext:n,shortcuts:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t){n.name!==t?i[t]?delete i[t]:r.emit(o,`Context '${t}' does not exist`):r.emit(o,`Context '${t}' can't be removed during is current active context. Change the context first`)}}};function n(t,e){const{ev:n,_specialChars:i,_readKeyEvent:o,extra:r,resetState:s}=t,{currentContext:c,streamKeys:u,listenOptions:l}=e;let a=[],d=null,p=!0,f=!1;const m=()=>p=!1,h=()=>p=!0,g=()=>f=!0,v=()=>!1===p;function x(){const t=a.map(t=>[t.join("+")]),i={wait:m,end:h,ignore:g,isWaiting:v,note:c.note,context:c.name,dependencies:r,options:e.listenOptions,viewport:{X:window.scrollX,Y:window.scrollY,width:window.innerWidth,height:window.innerHeight},type:"key"};if(!p){const e=`KEY:${t.at(-1).join("+")}`;n.emit(e,i),f&&(a=a.slice(0,-1),f=!1)}if(p){const o=`KEY:${t.join(",")}`;n.emit(o,i),f&&(a=a.slice(0,-1),f=!1),a=[],clearTimeout(e.keyIgnore),e.keyIgnore=null,clearTimeout(d),d=null}}function E(n){clearTimeout(d);if(i().hasOwnProperty(n.code))return a.push(o(n,i)),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore?(clearTimeout(e.keyIgnore),e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait),void a.pop()):p&&a.length===e.maxSequence?(x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait))):void(p?d=setTimeout(x,l.keyWait):x())}function O(n){if(!i().hasOwnProperty(n.code)){if(clearTimeout(d),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore)return clearTimeout(e.keyIgnore),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));if(a.push(o(n,i)),p&&a.length===e.maxSequence)return x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));p?d=setTimeout(x,l.keyWait):x()}}return{start:function(){e.active||(document.addEventListener("keydown",E),document.addEventListener("keypress",O),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("keydown",E),document.removeEventListener("keypress",O),e.active=!1,d&&(clearTimeout(d),d=null),e.keyIgnore&&(clearTimeout(e.keyIgnore),e.keyIgnore=null),a=[],p=!0,f=!1)}}}function i(t){const e=t.toUpperCase(),n=/KEY\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"KEY:SETUP";return`KEY:${e.slice(i+1).split(",").map(t=>t.trim()).map(t=>t.split("+").map(t=>t.trim()).sort().join("+")).join(",")}`}function o(t,e){const{shiftKey:n,altKey:i,ctrlKey:o}=t,r=e(),s=t.code.replace("Key","").replace("Digit",""),c=[];return o&&c.push("CTRL"),n&&c.push("SHIFT"),i&&c.push("ALT"),r.hasOwnProperty(s)?c.push(r[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||c.push(s.toUpperCase()),c.sort()}function r(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s?0:(Object.entries(c[s]).forEach(([s,c])=>{if(!r.test(s))return;if("KEY:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const u=s.slice(4).split(",").length;e.maxSequence<u&&(e.maxSequence=u)}),i||Object.assign(e.listenOptions,o),n)}function s(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function c(t,e={}){const c={_specialChars:s,_readKeyEvent:o,regex:/KEY\s*\:/i},u={active:!1,maxSequence:1,keyIgnore:null,defaultOptions:{keyWait:480},listenOptions:{keyWait:480},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return c.resetState=function(){u.active=!1,u.keyIgnore=null,u.maxSequence=1},t({prefix:"key",_normalizeShortcutName:i,_registerShortcutEvents:r,_listenDOM:n,pluginState:u,deps:c})}function u(t,e,n){const{listenOptions:{clickTarget:i}}=e,o=n;if(o===document.body)return null;return i.some(t=>o.hasAttribute(t))?o:u(t,e,o.parentNode)}function l(t,e){const{ev:n,_findTarget:i,_readClickEvent:o,extra:r}=t,{listenOptions:s,currentContext:c}=e;let u=null,l=null,a=null,d=null,p=0;function f(){if(!u)return;const{left:t,top:i,width:s,height:f}=u.getBoundingClientRect(),m=window.scrollX,h=window.scrollY,g=o(l,p),v={target:u,x:l.clientX,y:l.clientY,context:c.name,note:c.note,options:e.listenOptions,event:l,dependencies:r,viewport:{X:m,Y:h,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:f},position:{x:t,y:i},pagePosition:{x:t+m,y:i+h},type:"click"};n.emit(g,v),a=null,d=null,u=null,l=null,p=0}function m(n){let o=e.maxLeftClicks;if(clearTimeout(a),d)return clearTimeout(d),void(d=setTimeout(()=>d=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,p++,p>=o)return f(),void(o>1&&(d=setTimeout(()=>d=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}function h(n){let o=e.maxRightClicks;if(clearTimeout(a),d)return clearTimeout(d),void(d=setTimeout(()=>d=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,p++,p>=o)return f(),void(o>1&&(d=setTimeout(()=>d=null,s.mouseWait)));a=setTimeout(f,s.mouseWait)}}return{start:function(){e.active||(window.addEventListener("contextmenu",h),document.addEventListener("click",m),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("contextmenu",h),document.removeEventListener("click",m),e.active=!1,d&&(clearTimeout(d),d=null),u=null,l=null,p=0)}}}function a(t){const e=t.toUpperCase(),n=/CLICK\s*\:/i.test(e),i=["LEFT","MIDDLE","RIGHT"],o=["ALT","SHIFT","CTRL"];let r=null,s=0;const c=[],u=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"CLICK:SETUP";return e.slice(u+1).trim().split("-").map(t=>t.trim()).forEach(t=>{i.includes(t)?r=t:o.includes(t)?c.push(t):isNaN(t)||(s=t)}),`CLICK:${r}-${s}${c.length>0?"-":""}${c.sort().join("-")}`}function d(t,e){const{shiftKey:n,altKey:i,ctrlKey:o,key:r,button:s}=t,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][s]}-${e}`,u=[];return o&&u.push("CTRL"),n&&u.push("SHIFT"),i&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function p(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{listenOptions:s,currentContext:{name:c},shortcuts:u}=e;return null==c||(Object.entries(u[c]).forEach(([c,u])=>{if(!r.test(c))return;if("CLICK:SETUP"===c){i=!0;const n=u.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:s});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const[l,a]=c.slice(6).split("-");"LEFT"===l&&e.maxLeftClicks<a&&(e.maxLeftClicks=a),"RIGHT"===l&&e.maxRightClicks<a&&(e.maxRightClicks=a)}),i||Object.assign(e.listenOptions,o)),n}function f(t,e={}){const n={_findTarget:u,_readClickEvent:d,regex:/CLICK\s*\:/i},i={active:!1,maxLeftClicks:1,maxRightClicks:1,defaultOptions:{mouseWait:320,clickTarget:["data-click","href"]},listenOptions:{mouseWait:320,clickTarget:["data-click","href"]},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return n.resetState=function(){},t({prefix:"click",_normalizeShortcutName:a,_registerShortcutEvents:p,_listenDOM:l,pluginState:i,deps:n})}function m(t,e){const{ev:n}=t;let i=null;function o(t,e,n,i){const{extra:o}=t,{left:r,top:s,width:c,height:u}=n.target.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return{target:n.target,context:e.currentContext.name,note:e.currentContext.note,event:n,dependencies:o,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:r,y:s},pagePosition:{x:r+l,y:s+a},type:i}}function r(i){const{callbacks:r,typeFn:s}=e;i.target;const c=o(t,e,i,"form"),u=`${s(c)}/in`;null!=r[u]&&n.emit(u,c,r[u])}function s(i){const{callbacks:r,typeFn:s}=e,c=o(t,e,i,"form"),u=`${s(c)}/out`;null!=r[u]&&n.emit(u,c,r[u])}function c(r){const{callbacks:s,typeFn:c}=e,u=o(t,e,r,"form"),l=c(u),a=e.wait[`${l}`],d=`${l}/instant`;if(null==s[d])return;if(0===a)return void n.emit(d,u,s[d]);clearTimeout(i),i=setTimeout(()=>n.emit(d,u,s[d]),a)}return{start:function(){e.active||(document.addEventListener("focusin",r),document.addEventListener("focusout",s),document.addEventListener("input",c),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("focusin",r),document.removeEventListener("focusout",s),document.removeEventListener("input",c),e.active=!1,i&&(clearTimeout(i),i=null))}}}function h(t){const e=t.toUpperCase(),n=/FORM\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`FORM:${e.slice(i+1).trim()}`}function g(t,e){const{regex:n,_defaults:i,ev:o}=t,{currentContext:{name:r,note:s},shortcuts:c,callbacks:u,ERROR_EVENT_NAME:l,defaultOptions:a}=e;let d=[],p=[],f=[],m=0;if(null==r)return!1;if(Object.entries(c[r]).forEach(([i,o])=>{if(n.test(i)){if(i.includes("SETUP")){const n=o.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},a);return void Object.assign(e.listenOptions,n)}"FORM:WATCH"===i&&(d=o),"FORM:DEFINE"===i&&(p=o),"FORM:ACTION"===i&&(f=o)}}),0===f.length)return m;const h=new Set;0===p.length&&(p=[i.define]),0===d.length&&(d=[i.watch]);const g=d.map(n=>n({dependencies:t.extra,context:r,note:s,options:e.listenOptions})).reduce((t,e)=>(t.push(e),t),[]);return e.watchList=document.querySelectorAll(g),e.watchList.forEach(n=>{const{left:i,top:o,width:c,height:u}=n.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return h.add(p[0]({target:n,context:r,note:s,dependencies:t.extra,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:i,y:o},pagePosition:{x:i+l,y:o+a}}))}),e.typeFn=p[0]?p[0]:i.define,f.forEach(n=>{if(!(n instanceof Function))return o.emit(l,"The 'form:action' should be a function."),!1;const i=n({dependencies:t.extra,options:e.listenOptions});if(!(i instanceof Array))return o.emit(l,"Warning: The 'form:action' function should RETURN an array."),!1;i.forEach(({fn:t,type:n,timing:i,wait:r=0})=>{if(h.has(n)&&t instanceof Function){const e=`${n}/${i}`,r=u.hasOwnProperty(e);r?u[e].push(t):u[e]=[t],r||o.on(e,(t,e)=>{e.forEach(e=>{e instanceof Function&&e(t)})})}"instant"===i&&(e.wait[`${n}`]=r)})}),m=Object.keys(e.callbacks).length,m}const v={watch:()=>"input, select, textarea, button, a",define:({target:t})=>"checkbox"===t.type||"radio"===t.type?"checkbox":"button"==t.type||"submit"==t.type?"button":"input"};function x(t,e={}){const n={_defaults:v,regex:/FORM\s*\:/i},i={callbacks:{},typeFn:"",watchList:[],wait:{},defaultOptions:{},listenOptions:{}};return n.resetState=function(){i.callbacks={},i.typeFn="",i.watchList=[],i.wait={}},t({prefix:"form",_normalizeShortcutName:h,_registerShortcutEvents:g,_listenDOM:m,pluginState:i,deps:n})}function E(t,e,n){const{listenOptions:{hoverTarget:i}}=e,o=n;if(o===document.body)return!1;if(o===document)return!1;return i.some(t=>o.hasAttribute(t))?o:E(t,e,o.parentNode)}function O(t,e){const{ev:n,_findTarget:i,resetState:o,extra:r}=t;function s(o){const s=o.clientX,c=o.clientY,{hovered:u,hoverRectangle:l,listenOptions:a,hoverTimer:d,leaveTimer:p,lastEvent:f,lastHoverTarget:m}=e,h=i(t,e,o.target);if(!function(t,e,n){return!!t&&e>=t.left&&e<=t.right&&n>=t.top&&n<=t.bottom}(l,s,c)&&h!==u){if(u&&!h){if(e.hovered=!1,e.hoverRectangle=null,d&&(clearTimeout(d),e.hoverTimer=null),"off"===f)return;return void(e.leaveTimer=setTimeout(()=>{n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"},a.wait))}u&&(n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"),clearTimeout(p),clearTimeout(d),e.hovered=h,e.hoverRectangle=h.getBoundingClientRect(),e.hoverTimer=setTimeout(()=>{n.emit("HOVER:ON",g(h)),e.hoverTimer=null,e.lastHoverTarget=h,e.lastEvent="on"},a.wait)}function g(t){const{left:n,top:i,width:s,height:c}=t.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:t,context:e.currentContext.name,note:e.currentContext.note,event:o,dependencies:r,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:n,y:i},pagePosition:{x:n+u,y:i+l},type:"hover"}}}return{start:function(){e.active||(document.addEventListener("mousemove",s),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("mousemove",s),o())}}}function y(t){const e=t.toUpperCase(),n=/HOVER\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`HOVER:${e.slice(i+1).trim()}`}function w(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r,_defaults:s,ev:c}=t,{currentContext:{name:u},shortcuts:l,ERROR_EVENT_NAME:a}=e;return null==u||(Object.entries(l[u]).forEach(([s,c])=>{if(r.test(s)){if("HOVER:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function T(t,e={}){const n={_findTarget:E,regex:/HOVER\s*\:/i},i={active:!1,hovered:!1,hoverRectangle:null,hoverTimer:null,leaveTimer:null,lastEvent:"",lastHoverTarget:null,defaultOptions:{hoverTarget:["data-hover"],wait:320},listenOptions:{hoverTarget:["data-hover"],wait:320}};return n.resetState=function(){i.active=!1,i.hovered=!1,i.hoverRectangle=null,clearTimeout(i.hoverTimer),clearTimeout(i.leaveTimer),i.hoverTimer=null,i.leaveTimer=null,i.lastHoverTarget=null},t({prefix:"hover",_normalizeShortcutName:y,_registerShortcutEvents:w,_listenDOM:O,pluginState:i,deps:n})}function C(t,e){const{ev:n,resetState:i,extra:o}=t;let r=null,s=null;function c(t){t.clientX,t.clientY;const{lastPosition:i,lastDirection:c,listenOptions:u,currentContext:l}=e,{scrollWait:a,endScrollWait:d,minSpace:p}=u;if(!i)return;let f=null;const m=window.scrollX,h=window.scrollY,g=Math.abs(h-i.y),v=Math.abs(m-i.x);if(g<p&&v<p)return;const x=[];g>=p&&(h>i.y?x.push("down"):x.push("up")),v>=p&&(m>i.x?x.push("right"):x.push("left")),f=x[0]||null;const E=t=>({x:m,y:h,direction:t,context:l.name,note:l.note,dependencies:o,options:e.listenOptions,viewport:{X:m,Y:h,width:window.innerWidth,height:window.innerHeight},type:"scroll"});x.forEach(t=>{const e=`SCROLL:${t.toUpperCase()}`;n.emit(e,E(t))}),clearTimeout(r),clearTimeout(s);const O=x[x.length-1]||null;r=setTimeout(()=>{},a),s=setTimeout(()=>n.emit("SCROLL:END",E(O)),d),e.lastPosition={x:m,y:h},e.lastDirection=f}return{start:function(){e.active||(e.lastPosition={x:window.scrollX,y:window.scrollY},window.addEventListener("scroll",c),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("scroll",c),i())}}}function S(t){const e=t.toUpperCase(),n=/SCROLL\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`SCROLL:${e.slice(i+1).trim()}`}function k(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s||(Object.entries(c[s]).forEach(([s,c])=>{if(r.test(s)){if("SCROLL:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function R(t,e={}){const n={regex:/SCROLL\s*\:/i},i={active:!1,lastPosition:null,lastDirection:null,defaultOptions:{scrollWait:50,endScrollWait:400,minSpace:40},listenOptions:{scrollWait:50,endScrollWait:400,minSpace:40}};return n.resetState=function(){i.active=!1},t({prefix:"scroll",_normalizeShortcutName:S,_registerShortcutEvents:k,_listenDOM:C,pluginState:i,deps:n})}function L(n={}){const i={},o={},r=t(),s={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!n.onShortcut||"function"!=typeof n.onShortcut)&&n.onShortcut,ERROR_EVENT_NAME:n.errorEventName?n.errorEventName:"@shortcuts-error"},c={ev:r,inAPI:i,API:o,extra:{emit:r.emit}};return o.enablePlugin=(t,e={})=>{if("function"!=typeof t)return;const n=t(i._setupPlugin,e),o=n.getPrefix(),r=i._systemAction(o,"none");-1===r?(s.plugins.push(n),n.unmute()):(n.destroy(),s.plugins[r].unmute())},o.disablePlugin=t=>{const e=i._systemAction(t,"destroy");-1!==e&&s.plugins.splice(e,1)},o.mutePlugin=t=>i._systemAction(t,"mute"),o.unmutePlugin=t=>i._systemAction(t,"unmute"),o.listPlugins=()=>s.plugins.map(t=>t.getPrefix()),o.getContext=()=>s.currentContext.name,o.getNote=()=>s.currentContext.note,o.setNote=(t=null)=>{"string"!=typeof t&&null!=t||(s.currentContext.note=t)},o.pause=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.stop(e)},o.resume=(t="*")=>{const e=i._readShortcutWithPlugins(t);r.start(e)},o.emit=(t,...e)=>r.emit(i._readShortcutWithPlugins(t),{dependencies:c.extra,type:"custom"},...e),o.listContexts=()=>Object.keys(s.shortcuts),o.setDependencies=t=>Object.assign(c.extra,t),o.getDependencies=()=>c.extra,o.reset=function(){r.reset(),o.changeContext(),s.plugins.forEach(t=>t.destroy()),o.listContexts().map(t=>o.unload(t)),c.extra={emit:r.emit},s.exposeShortcut=null},Object.entries(e).forEach(([t,e])=>{t.startsWith("_")?i[t]=e(c,s):o[t]=e(c,s)}),o}export{f as pluginClick,x as pluginForm,T as pluginHover,c as pluginKey,R as pluginScroll,L as shortcuts};
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).shortcuts={})}(this,function(t){"use strict";var e={_normalizeWithPlugins:function(t,e){return function(t){const n=e.shortcuts;Object.keys(n).forEach(e=>{Object.entries(n[e]).forEach(([i,o])=>{const r=t(i);r!==i&&(delete n[e][i],n[e][r]=o)})})}},_readShortcutWithPlugins:function(t,e){return function(n){const{inAPI:i}=t,o=n.split(":")[0].toLowerCase().trim(),r=i._systemAction(o,"none");let s=n;return-1!==r&&(s=e.plugins[r].shortcutName(n)),s}},_setupPlugin:function(t,e){const{inAPI:n}=t,{currentContext:i,shortcuts:o,exposeShortcut:r,ERROR_EVENT_NAME:s}=e;return function(e){const{prefix:c,_normalizeShortcutName:u,_registerShortcutEvents:l,_listenDOM:a,pluginState:f,deps:d}=e,{resetState:p}=d;f.currentContext=i,f.shortcuts=o,f.exposeShortcut=r,f.ERROR_EVENT_NAME=s;const h={ev:t.ev,extra:t.extra,...d};n._normalizeWithPlugins(u);let m=l(h,f);const g=a(h,f);m>0&&g.start();const v={getPrefix:()=>c,shortcutName:t=>u(t),contextChange:()=>{p(),m=l(h,f),m<1&&g.stop(),m>0&&g.start()},mute:()=>g.stop(),unmute:()=>g.start(),destroy:()=>{g.stop(),p()}};return Object.freeze(v),v}},_systemAction:function(t,e){return function(t,n,i=null){return e.plugins.findIndex(e=>e.getPrefix()===t&&(e[n]&&e[n](i),!0))}},changeContext:function(t,e){const{shortcuts:n,currentContext:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t=!1){const s=i.name;if(!t)return r.reset(),void(i.name=null);s!==t&&(n[t]?(n[s]&&r.reset(),i.name=t,e.plugins.forEach(e=>e.contextChange(t)),Object.entries(n[t]).forEach(([t,e])=>{t.includes(":SETUP")||e.forEach(e=>r.on(t,e))}),r.on("*",(...t)=>{e.exposeShortcut&&e.exposeShortcut(...t)})):r.emit(o,`Context '${t}' does not exist`))}},listShortcuts:function(t,e){const n=e.shortcuts;return function(t=null){if(null!=t){const e=n[t];return null==e?null:Object.entries(e).map(([t,e])=>t)}return Object.keys(n).map(t=>{const e={};return e.context=t,e.shortcuts=Object.entries(n[t]).map(([t,e])=>t),e})}},load:function(t,e){const{shortcuts:n,plugins:i}=e,{API:{changeContext:o,getContext:r}}=t;return function(t){const e=r(),s=i.map(t=>t.getPrefix().toUpperCase());let c=!1;Object.entries(t).forEach(([t,o])=>{t===e&&(c=!0),n[t]={},Object.entries(o).forEach(([e,o])=>{let r=e;const c=e.toUpperCase().trim(),u=s.map((t,e)=>c.startsWith(t)?e:null).filter(t=>null!==t);if(u.length){const t=u[0];r=i[t].shortcutName(e)}o instanceof Function&&(o=[o]),n[t][r]=o})}),c&&(o(),o(e))}},unload:function(t,e){const{currentContext:n,shortcuts:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t){n.name!==t?i[t]?delete i[t]:r.emit(o,`Context '${t}' does not exist`):r.emit(o,`Context '${t}' can't be removed during is current active context. Change the context first`)}}};function n(t,e){const{ev:n,_specialChars:i,_readKeyEvent:o,extra:r,resetState:s}=t,{currentContext:c,streamKeys:u,listenOptions:l}=e;let a=[],f=null,d=!0,p=!1;const h=()=>d=!1,m=()=>d=!0,g=()=>p=!0,v=()=>!1===d;function x(){const t=a.map(t=>[t.join("+")]),i={wait:h,end:m,ignore:g,isWaiting:v,note:c.note,context:c.name,dependencies:r,options:e.listenOptions,viewport:{X:window.scrollX,Y:window.scrollY,width:window.innerWidth,height:window.innerHeight},type:"key"};if(!d){const e=`KEY:${t.at(-1).join("+")}`;n.emit(e,i),p&&(a=a.slice(0,-1),p=!1)}if(d){const o=`KEY:${t.join(",")}`;n.emit(o,i),p&&(a=a.slice(0,-1),p=!1),a=[],clearTimeout(e.keyIgnore),e.keyIgnore=null,clearTimeout(f),f=null}}function E(n){clearTimeout(f);if(i().hasOwnProperty(n.code))return a.push(o(n,i)),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore?(clearTimeout(e.keyIgnore),e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait),void a.pop()):d&&a.length===e.maxSequence?(x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait))):void(d?f=setTimeout(x,l.keyWait):x())}function O(n){if(!i().hasOwnProperty(n.code)){if(clearTimeout(f),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore)return clearTimeout(e.keyIgnore),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));if(a.push(o(n,i)),d&&a.length===e.maxSequence)return x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));d?f=setTimeout(x,l.keyWait):x()}}return{start:function(){e.active||(document.addEventListener("keydown",E),document.addEventListener("keypress",O),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("keydown",E),document.removeEventListener("keypress",O),e.active=!1,f&&(clearTimeout(f),f=null),e.keyIgnore&&(clearTimeout(e.keyIgnore),e.keyIgnore=null),a=[],d=!0,p=!1)}}}function i(t){const e=t.toUpperCase(),n=/KEY\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"KEY:SETUP";return`KEY:${e.slice(i+1).split(",").map(t=>t.trim()).map(t=>t.split("+").map(t=>t.trim()).sort().join("+")).join(",")}`}function o(t,e){const{shiftKey:n,altKey:i,ctrlKey:o}=t,r=e(),s=t.code.replace("Key","").replace("Digit",""),c=[];return o&&c.push("CTRL"),n&&c.push("SHIFT"),i&&c.push("ALT"),r.hasOwnProperty(s)?c.push(r[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||c.push(s.toUpperCase()),c.sort()}function r(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s?0:(Object.entries(c[s]).forEach(([s,c])=>{if(!r.test(s))return;if("KEY:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const u=s.slice(4).split(",").length;e.maxSequence<u&&(e.maxSequence=u)}),i||Object.assign(e.listenOptions,o),n)}function s(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function c(t,e,n){const{listenOptions:{clickTarget:i}}=e,o=n;if(o===document.body)return null;return i.some(t=>o.hasAttribute(t))?o:c(t,e,o.parentNode)}function u(t,e){const{ev:n,_findTarget:i,_readClickEvent:o,extra:r}=t,{listenOptions:s,currentContext:c}=e;let u=null,l=null,a=null,f=null,d=0;function p(){if(!u)return;const{left:t,top:i,width:s,height:p}=u.getBoundingClientRect(),h=window.scrollX,m=window.scrollY,g=o(l,d),v={target:u,x:l.clientX,y:l.clientY,context:c.name,note:c.note,options:e.listenOptions,event:l,dependencies:r,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:p},position:{x:t,y:i},pagePosition:{x:t+h,y:i+m},type:"click"};n.emit(g,v),a=null,f=null,u=null,l=null,d=0}function h(n){let o=e.maxLeftClicks;if(clearTimeout(a),f)return clearTimeout(f),void(f=setTimeout(()=>f=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return p(),void(o>1&&(f=setTimeout(()=>f=null,s.mouseWait)));a=setTimeout(p,s.mouseWait)}}function m(n){let o=e.maxRightClicks;if(clearTimeout(a),f)return clearTimeout(f),void(f=setTimeout(()=>f=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return p(),void(o>1&&(f=setTimeout(()=>f=null,s.mouseWait)));a=setTimeout(p,s.mouseWait)}}return{start:function(){e.active||(window.addEventListener("contextmenu",m),document.addEventListener("click",h),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("contextmenu",m),document.removeEventListener("click",h),e.active=!1,f&&(clearTimeout(f),f=null),u=null,l=null,d=0)}}}function l(t){const e=t.toUpperCase(),n=/CLICK\s*\:/i.test(e),i=["LEFT","MIDDLE","RIGHT"],o=["ALT","SHIFT","CTRL"];let r=null,s=0;const c=[],u=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"CLICK:SETUP";return e.slice(u+1).trim().split("-").map(t=>t.trim()).forEach(t=>{i.includes(t)?r=t:o.includes(t)?c.push(t):isNaN(t)||(s=t)}),`CLICK:${r}-${s}${c.length>0?"-":""}${c.sort().join("-")}`}function a(t,e){const{shiftKey:n,altKey:i,ctrlKey:o,key:r,button:s}=t,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][s]}-${e}`,u=[];return o&&u.push("CTRL"),n&&u.push("SHIFT"),i&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function f(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{listenOptions:s,currentContext:{name:c},shortcuts:u}=e;return null==c||(Object.entries(u[c]).forEach(([c,u])=>{if(!r.test(c))return;if("CLICK:SETUP"===c){i=!0;const n=u.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:s});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const[l,a]=c.slice(6).split("-");"LEFT"===l&&e.maxLeftClicks<a&&(e.maxLeftClicks=a),"RIGHT"===l&&e.maxRightClicks<a&&(e.maxRightClicks=a)}),i||Object.assign(e.listenOptions,o)),n}function d(t,e){const{ev:n}=t;let i=null;function o(t,e,n,i){const{left:o,top:r,width:s,height:c}=n.target.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:n.target,context:e.currentContext.name,note:e.currentContext.note,event:n,dependencies:t.extra,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:o,y:r},pagePosition:{x:o+u,y:r+l},type:i}}function r(i){const{callbacks:r,typeFn:s}=e;i.target;const c=o(t,e,i,"form-in"),u=`${s(c)}/in`;null!=r[u]&&n.emit(u,c,r[u])}function s(i){const{callbacks:r,typeFn:s}=e,c=o(t,e,i,"form-out"),u=`${s(c)}/out`;null!=r[u]&&n.emit(u,c,r[u])}function c(r){const{callbacks:s,typeFn:c}=e,u=o(t,e,r,"form-instant"),l=c(u),a=e.wait[`${l}`],f=`${l}/instant`;if(null==s[f])return;if(0===a)return void n.emit(f,u,s[f]);clearTimeout(i),i=setTimeout(()=>n.emit(f,u,s[f]),a)}return{start:function(){e.active||(document.addEventListener("focusin",r),document.addEventListener("focusout",s),document.addEventListener("input",c),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("focusin",r),document.removeEventListener("focusout",s),document.removeEventListener("input",c),e.active=!1,i&&(clearTimeout(i),i=null))}}}function p(t){const e=t.toUpperCase(),n=/FORM\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`FORM:${e.slice(i+1).trim()}`}function h(t,e){const{regex:n,_defaults:i,ev:o}=t,{currentContext:{name:r,note:s},shortcuts:c,callbacks:u,ERROR_EVENT_NAME:l,defaultOptions:a}=e;let f=[],d=[],p=[],h=0;if(null==r)return!1;if(Object.entries(c[r]).forEach(([i,o])=>{if(n.test(i)){if(i.includes("SETUP")){const n=o.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},a);return void Object.assign(e.listenOptions,n)}"FORM:WATCH"===i&&(f=o),"FORM:DEFINE"===i&&(d=o),"FORM:ACTION"===i&&(p=o)}}),0===p.length)return h;const m=new Set;0===d.length&&(d=[i.define]),0===f.length&&(f=[i.watch]);const g=f.map(n=>n({dependencies:t.extra,context:r,note:s,options:e.listenOptions})).reduce((t,e)=>(t.push(e),t),[]);return e.watchList=document.querySelectorAll(g),e.watchList.forEach(n=>{const{left:i,top:o,width:c,height:u}=n.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return m.add(d[0]({target:n,context:r,note:s,dependencies:t.extra,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:i,y:o},pagePosition:{x:i+l,y:o+a}}))}),e.typeFn=d[0]?d[0]:i.define,p.forEach(n=>{if(!(n instanceof Function))return o.emit(l,"The 'form:action' should be a function."),!1;const i=n({dependencies:t.extra,options:e.listenOptions});if(!(i instanceof Array))return o.emit(l,"Warning: The 'form:action' function should RETURN an array."),!1;i.forEach(({fn:t,type:n,timing:i,wait:r=0})=>{if(m.has(n)&&t instanceof Function){const e=`${n}/${i}`,r=u.hasOwnProperty(e);r?u[e].push(t):u[e]=[t],r||o.on(e,(t,e)=>{e.forEach(e=>{e instanceof Function&&e(t)})})}"instant"===i&&(e.wait[`${n}`]=r)})}),h=Object.keys(e.callbacks).length,h}const m={watch:()=>"input, select, textarea, button, a",define:({target:t})=>"checkbox"===t.type||"radio"===t.type?"checkbox":"button"==t.type||"submit"==t.type?"button":"input"};function g(t,e,n){const{listenOptions:{hoverTarget:i}}=e,o=n;if(o===document.body)return!1;if(o===document)return!1;return i.some(t=>o.hasAttribute(t))?o:g(t,e,o.parentNode)}function v(t,e){const{ev:n,_findTarget:i,resetState:o,extra:r}=t;function s(o){const s=o.clientX,c=o.clientY,{hovered:u,hoverRectangle:l,listenOptions:a,hoverTimer:f,leaveTimer:d,lastEvent:p,lastHoverTarget:h}=e,m=i(t,e,o.target);if(!function(t,e,n){return!!t&&e>=t.left&&e<=t.right&&n>=t.top&&n<=t.bottom}(l,s,c)&&m!==u){if(u&&!m){if(e.hovered=!1,e.hoverRectangle=null,f&&(clearTimeout(f),e.hoverTimer=null),"off"===p)return;return void(e.leaveTimer=setTimeout(()=>{n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"},a.wait))}u&&(n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"),clearTimeout(d),clearTimeout(f),e.hovered=m,e.hoverRectangle=m.getBoundingClientRect(),e.hoverTimer=setTimeout(()=>{n.emit("HOVER:ON",g(m)),e.hoverTimer=null,e.lastHoverTarget=m,e.lastEvent="on"},a.wait)}function g(t){const{left:n,top:i,width:s,height:c}=t.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:t,context:e.currentContext.name,note:e.currentContext.note,event:o,dependencies:r,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:n,y:i},pagePosition:{x:n+u,y:i+l},type:"hover"}}}return{start:function(){e.active||(document.addEventListener("mousemove",s),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("mousemove",s),o())}}}function x(t){const e=t.toUpperCase(),n=/HOVER\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`HOVER:${e.slice(i+1).trim()}`}function E(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r,_defaults:s,ev:c}=t,{currentContext:{name:u},shortcuts:l,ERROR_EVENT_NAME:a}=e;return null==u||(Object.entries(l[u]).forEach(([s,c])=>{if(r.test(s)){if("HOVER:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function O(t,e){const{ev:n,resetState:i,extra:o}=t;let r=null,s=null;function c(t){t.clientX,t.clientY;const{lastPosition:i,lastDirection:c,listenOptions:u,currentContext:l}=e,{scrollWait:a,endScrollWait:f,minSpace:d}=u;if(!i)return;let p=null;const h=window.scrollX,m=window.scrollY,g=Math.abs(m-i.y),v=Math.abs(h-i.x);if(g<d&&v<d)return;const x=[];g>=d&&(m>i.y?x.push("down"):x.push("up")),v>=d&&(h>i.x?x.push("right"):x.push("left")),p=x[0]||null;const E=t=>({x:h,y:m,direction:t,context:l.name,note:l.note,dependencies:o,options:e.listenOptions,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},type:"scroll"});x.forEach(t=>{const e=`SCROLL:${t.toUpperCase()}`;n.emit(e,E(t))}),clearTimeout(r),clearTimeout(s);const O=x[x.length-1]||null;r=setTimeout(()=>{},a),s=setTimeout(()=>n.emit("SCROLL:END",E(O)),f),e.lastPosition={x:h,y:m},e.lastDirection=p}return{start:function(){e.active||(e.lastPosition={x:window.scrollX,y:window.scrollY},window.addEventListener("scroll",c),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("scroll",c),i())}}}function y(t){const e=t.toUpperCase(),n=/SCROLL\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`SCROLL:${e.slice(i+1).trim()}`}function w(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s||(Object.entries(c[s]).forEach(([s,c])=>{if(r.test(s)){if("SCROLL:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}t.pluginClick=function(t,e={}){const n={_findTarget:c,_readClickEvent:a,regex:/CLICK\s*\:/i},i={active:!1,maxLeftClicks:1,maxRightClicks:1,defaultOptions:{mouseWait:320,clickTarget:["data-click","href"]},listenOptions:{mouseWait:320,clickTarget:["data-click","href"]},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return n.resetState=function(){},t({prefix:"click",_normalizeShortcutName:l,_registerShortcutEvents:f,_listenDOM:u,pluginState:i,deps:n})},t.pluginForm=function(t,e={}){const n={_defaults:m,regex:/FORM\s*\:/i},i={callbacks:{},typeFn:"",watchList:[],wait:{},defaultOptions:{},listenOptions:{}};return n.resetState=function(){i.callbacks={},i.typeFn="",i.watchList=[],i.wait={}},t({prefix:"form",_normalizeShortcutName:p,_registerShortcutEvents:h,_listenDOM:d,pluginState:i,deps:n})},t.pluginHover=function(t,e={}){const n={_findTarget:g,regex:/HOVER\s*\:/i},i={active:!1,hovered:!1,hoverRectangle:null,hoverTimer:null,leaveTimer:null,lastEvent:"",lastHoverTarget:null,defaultOptions:{hoverTarget:["data-hover"],wait:320},listenOptions:{hoverTarget:["data-hover"],wait:320}};return n.resetState=function(){i.active=!1,i.hovered=!1,i.hoverRectangle=null,clearTimeout(i.hoverTimer),clearTimeout(i.leaveTimer),i.hoverTimer=null,i.leaveTimer=null,i.lastHoverTarget=null},t({prefix:"hover",_normalizeShortcutName:x,_registerShortcutEvents:E,_listenDOM:v,pluginState:i,deps:n})},t.pluginKey=function(t,e={}){const c={_specialChars:s,_readKeyEvent:o,regex:/KEY\s*\:/i},u={active:!1,maxSequence:1,keyIgnore:null,defaultOptions:{keyWait:480},listenOptions:{keyWait:480},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return c.resetState=function(){u.active=!1,u.keyIgnore=null,u.maxSequence=1},t({prefix:"key",_normalizeShortcutName:i,_registerShortcutEvents:r,_listenDOM:n,pluginState:u,deps:c})},t.pluginScroll=function(t,e={}){const n={regex:/SCROLL\s*\:/i},i={active:!1,lastPosition:null,lastDirection:null,defaultOptions:{scrollWait:50,endScrollWait:400,minSpace:40},listenOptions:{scrollWait:50,endScrollWait:400,minSpace:40}};return n.resetState=function(){i.active=!1},t({prefix:"scroll",_normalizeShortcutName:y,_registerShortcutEvents:w,_listenDOM:O,pluginState:i,deps:n})},t.shortcuts=function(t={}){const n={},i={},o=function(){let t={"*":[]},e={},n=new Set,i=!1,o="";return{on:function(e,n){t[e]||(t[e]=[]),t[e].push(n)},once:function(t,n){"*"!==t&&(e[t]||(e[t]=[]),e[t].push(n))},off:function(n,i){if(i)return t[n]&&(t[n]=t[n].filter(t=>t!==i)),e[n]&&(e[n]=e[n].filter(t=>t!==i)),t[n]&&0===t[n].length&&delete t[n],void(e[n]&&0===e[n].length&&delete t[n]);e[n]&&delete e[n],t[n]&&delete t[n]},reset:function(){t={"*":[]},e={},n=new Set},emit:function(){const[r,...s]=arguments;function c(e){let i=!1;"*"!==e&&(n.has(e)||(t[e].every(t=>{const e=t(...s);return"string"!=typeof e||"STOP"!==e.toUpperCase()||(i=!0,!1)}),i||t["*"].forEach(t=>t(r,...s))))}if(i&&(console.log(`${o} Event "${r}" was triggered.`),s.length>0&&(console.log("Arguments:"),console.log(...s),console.log("^----"))),"*"!==r){if(e[r]){if(n.has(r))return;e[r].forEach(t=>t(...s)),delete e[r]}t[r]&&c(r)}else Object.keys(t).forEach(t=>c(t))},stop:function(i){if("*"===i){const i=Object.keys(t),o=Object.keys(e);return void(n=new Set([...o,...i]))}n.add(i)},start:function(t){"*"!==t?n.delete(t):n.clear()},debug:function(t,e){i=!!t,e&&"string"==typeof e&&(o=e)}}}(),r={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!t.onShortcut||"function"!=typeof t.onShortcut)&&t.onShortcut,ERROR_EVENT_NAME:t.errorEventName?t.errorEventName:"@shortcuts-error"},s={ev:o,inAPI:n,API:i,extra:{}};return i.enablePlugin=(t,e={})=>{if("function"!=typeof t)return;const i=t(n._setupPlugin,e),o=i.getPrefix(),s=n._systemAction(o,"none");-1===s?(r.plugins.push(i),i.unmute()):(i.destroy(),r.plugins[s].unmute())},i.disablePlugin=t=>{const e=n._systemAction(t,"destroy");-1!==e&&r.plugins.splice(e,1)},i.mutePlugin=t=>n._systemAction(t,"mute"),i.unmutePlugin=t=>n._systemAction(t,"unmute"),i.listPlugins=()=>r.plugins.map(t=>t.getPrefix()),i.getContext=()=>r.currentContext.name,i.getNote=()=>r.currentContext.note,i.setNote=(t=null)=>{"string"!=typeof t&&null!=t||(r.currentContext.note=t)},i.pause=(t="*")=>{const e=n._readShortcutWithPlugins(t);o.stop(e)},i.resume=(t="*")=>{const e=n._readShortcutWithPlugins(t);o.start(e)},i.emit=(t,...e)=>o.emit(n._readShortcutWithPlugins(t),...e),i.listContexts=()=>Object.keys(r.shortcuts),i.setDependencies=t=>Object.assign(s.extra,t),i.getDependencies=()=>s.extra,i.reset=function(){o.reset(),i.changeContext(),r.plugins.forEach(t=>t.destroy()),i.listContexts().map(t=>i.unload(t)),s.extra={},r.exposeShortcut=null},Object.entries(e).forEach(([t,e])=>{t.startsWith("_")?n[t]=e(s,r):i[t]=e(s,r)}),i}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).shortcuts={})}(this,function(t){"use strict";var e={_normalizeWithPlugins:function(t,e){return function(t){const n=e.shortcuts;Object.keys(n).forEach(e=>{Object.entries(n[e]).forEach(([i,o])=>{const r=t(i);r!==i&&(delete n[e][i],n[e][r]=o)})})}},_readShortcutWithPlugins:function(t,e){return function(n){const{inAPI:i}=t,o=n.split(":")[0].toLowerCase().trim(),r=i._systemAction(o,"none");let s=n;return-1!==r&&(s=e.plugins[r].shortcutName(n)),s}},_setupPlugin:function(t,e){const{inAPI:n}=t,{currentContext:i,shortcuts:o,exposeShortcut:r,ERROR_EVENT_NAME:s}=e;return function(e){const{prefix:c,_normalizeShortcutName:u,_registerShortcutEvents:l,_listenDOM:a,pluginState:f,deps:d}=e,{resetState:p}=d;f.currentContext=i,f.shortcuts=o,f.exposeShortcut=r,f.ERROR_EVENT_NAME=s;const h={ev:t.ev,extra:t.extra,...d};n._normalizeWithPlugins(u);let m=l(h,f);const g=a(h,f);m>0&&g.start();const v={getPrefix:()=>c,shortcutName:t=>u(t),contextChange:()=>{p(),m=l(h,f),m<1&&g.stop(),m>0&&g.start()},mute:()=>g.stop(),unmute:()=>g.start(),destroy:()=>{g.stop(),p()}};return Object.freeze(v),v}},_systemAction:function(t,e){return function(t,n,i=null){return e.plugins.findIndex(e=>e.getPrefix()===t&&(e[n]&&e[n](i),!0))}},changeContext:function(t,e){const{shortcuts:n,currentContext:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t=!1){const s=i.name;if(!t)return r.reset(),void(i.name=null);s!==t&&(n[t]?(n[s]&&r.reset(),i.name=t,e.plugins.forEach(e=>e.contextChange(t)),Object.entries(n[t]).forEach(([t,e])=>{t.includes(":SETUP")||e.forEach(e=>r.on(t,e))}),r.on("*",(...t)=>{e.exposeShortcut&&e.exposeShortcut(...t)})):r.emit(o,`Context '${t}' does not exist`))}},listShortcuts:function(t,e){const n=e.shortcuts;return function(t=null){if(null!=t){const e=n[t];return null==e?null:Object.entries(e).map(([t,e])=>t)}return Object.keys(n).map(t=>{const e={};return e.context=t,e.shortcuts=Object.entries(n[t]).map(([t,e])=>t),e})}},load:function(t,e){const{shortcuts:n,plugins:i}=e,{API:{changeContext:o,getContext:r}}=t;return function(t){const e=r(),s=i.map(t=>t.getPrefix().toUpperCase());let c=!1;Object.entries(t).forEach(([t,o])=>{t===e&&(c=!0),n[t]={},Object.entries(o).forEach(([e,o])=>{let r=e;const c=e.toUpperCase().trim(),u=s.map((t,e)=>c.startsWith(t)?e:null).filter(t=>null!==t);if(u.length){const t=u[0];r=i[t].shortcutName(e)}o instanceof Function&&(o=[o]),n[t][r]=o})}),c&&(o(),o(e))}},unload:function(t,e){const{currentContext:n,shortcuts:i,ERROR_EVENT_NAME:o}=e,{ev:r}=t;return function(t){n.name!==t?i[t]?delete i[t]:r.emit(o,`Context '${t}' does not exist`):r.emit(o,`Context '${t}' can't be removed during is current active context. Change the context first`)}}};function n(t,e){const{ev:n,_specialChars:i,_readKeyEvent:o,extra:r,resetState:s}=t,{currentContext:c,streamKeys:u,listenOptions:l}=e;let a=[],f=null,d=!0,p=!1;const h=()=>d=!1,m=()=>d=!0,g=()=>p=!0,v=()=>!1===d;function x(){const t=a.map(t=>[t.join("+")]),i={wait:h,end:m,ignore:g,isWaiting:v,note:c.note,context:c.name,dependencies:r,options:e.listenOptions,viewport:{X:window.scrollX,Y:window.scrollY,width:window.innerWidth,height:window.innerHeight},type:"key"};if(!d){const e=`KEY:${t.at(-1).join("+")}`;n.emit(e,i),p&&(a=a.slice(0,-1),p=!1)}if(d){const o=`KEY:${t.join(",")}`;n.emit(o,i),p&&(a=a.slice(0,-1),p=!1),a=[],clearTimeout(e.keyIgnore),e.keyIgnore=null,clearTimeout(f),f=null}}function E(n){clearTimeout(f);if(i().hasOwnProperty(n.code))return a.push(o(n,i)),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore?(clearTimeout(e.keyIgnore),e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait),void a.pop()):d&&a.length===e.maxSequence?(x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait))):void(d?f=setTimeout(x,l.keyWait):x())}function O(n){if(!i().hasOwnProperty(n.code)){if(clearTimeout(f),u&&u({key:n.key,context:c.name,note:c.note,dependencies:t.extra}),e.keyIgnore)return clearTimeout(e.keyIgnore),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));if(a.push(o(n,i)),d&&a.length===e.maxSequence)return x(),void(e.keyIgnore=setTimeout(()=>e.keyIgnore=null,l.keyWait));d?f=setTimeout(x,l.keyWait):x()}}return{start:function(){e.active||(document.addEventListener("keydown",E),document.addEventListener("keypress",O),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("keydown",E),document.removeEventListener("keypress",O),e.active=!1,f&&(clearTimeout(f),f=null),e.keyIgnore&&(clearTimeout(e.keyIgnore),e.keyIgnore=null),a=[],d=!0,p=!1)}}}function i(t){const e=t.toUpperCase(),n=/KEY\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"KEY:SETUP";return`KEY:${e.slice(i+1).split(",").map(t=>t.trim()).map(t=>t.split("+").map(t=>t.trim()).sort().join("+")).join(",")}`}function o(t,e){const{shiftKey:n,altKey:i,ctrlKey:o}=t,r=e(),s=t.code.replace("Key","").replace("Digit",""),c=[];return o&&c.push("CTRL"),n&&c.push("SHIFT"),i&&c.push("ALT"),r.hasOwnProperty(s)?c.push(r[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||c.push(s.toUpperCase()),c.sort()}function r(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s?0:(Object.entries(c[s]).forEach(([s,c])=>{if(!r.test(s))return;if("KEY:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const u=s.slice(4).split(",").length;e.maxSequence<u&&(e.maxSequence=u)}),i||Object.assign(e.listenOptions,o),n)}function s(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function c(t,e,n){const{listenOptions:{clickTarget:i}}=e,o=n;if(o===document.body)return null;return i.some(t=>o.hasAttribute(t))?o:c(t,e,o.parentNode)}function u(t,e){const{ev:n,_findTarget:i,_readClickEvent:o,extra:r}=t,{listenOptions:s,currentContext:c}=e;let u=null,l=null,a=null,f=null,d=0;function p(){if(!u)return;const{left:t,top:i,width:s,height:p}=u.getBoundingClientRect(),h=window.scrollX,m=window.scrollY,g=o(l,d),v={target:u,x:l.clientX,y:l.clientY,context:c.name,note:c.note,options:e.listenOptions,event:l,dependencies:r,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:p},position:{x:t,y:i},pagePosition:{x:t+h,y:i+m},type:"click"};n.emit(g,v),a=null,f=null,u=null,l=null,d=0}function h(n){let o=e.maxLeftClicks;if(clearTimeout(a),f)return clearTimeout(f),void(f=setTimeout(()=>f=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return p(),void(o>1&&(f=setTimeout(()=>f=null,s.mouseWait)));a=setTimeout(p,s.mouseWait)}}function m(n){let o=e.maxRightClicks;if(clearTimeout(a),f)return clearTimeout(f),void(f=setTimeout(()=>f=null,s.mouseWait));if(u=i(t,e,n.target),null!=u){if(u&&u.dataset.hasOwnProperty("quickClick")&&(o=1),u&&"A"===u.tagName&&(o=1),l=n,d++,d>=o)return p(),void(o>1&&(f=setTimeout(()=>f=null,s.mouseWait)));a=setTimeout(p,s.mouseWait)}}return{start:function(){e.active||(window.addEventListener("contextmenu",m),document.addEventListener("click",h),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("contextmenu",m),document.removeEventListener("click",h),e.active=!1,f&&(clearTimeout(f),f=null),u=null,l=null,d=0)}}}function l(t){const e=t.toUpperCase(),n=/CLICK\s*\:/i.test(e),i=["LEFT","MIDDLE","RIGHT"],o=["ALT","SHIFT","CTRL"];let r=null,s=0;const c=[],u=e.indexOf(":");if(!n)return t;if(e.includes("SETUP"))return"CLICK:SETUP";return e.slice(u+1).trim().split("-").map(t=>t.trim()).forEach(t=>{i.includes(t)?r=t:o.includes(t)?c.push(t):isNaN(t)||(s=t)}),`CLICK:${r}-${s}${c.length>0?"-":""}${c.sort().join("-")}`}function a(t,e){const{shiftKey:n,altKey:i,ctrlKey:o,key:r,button:s}=t,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][s]}-${e}`,u=[];return o&&u.push("CTRL"),n&&u.push("SHIFT"),i&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function f(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{listenOptions:s,currentContext:{name:c},shortcuts:u}=e;return null==c||(Object.entries(u[c]).forEach(([c,u])=>{if(!r.test(c))return;if("CLICK:SETUP"===c){i=!0;const n=u.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:s});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++;const[l,a]=c.slice(6).split("-");"LEFT"===l&&e.maxLeftClicks<a&&(e.maxLeftClicks=a),"RIGHT"===l&&e.maxRightClicks<a&&(e.maxRightClicks=a)}),i||Object.assign(e.listenOptions,o)),n}function d(t,e){const{ev:n}=t;let i=null;function o(t,e,n,i){const{extra:o}=t,{left:r,top:s,width:c,height:u}=n.target.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return{target:n.target,context:e.currentContext.name,note:e.currentContext.note,event:n,dependencies:o,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:r,y:s},pagePosition:{x:r+l,y:s+a},type:i}}function r(i){const{callbacks:r,typeFn:s}=e;i.target;const c=o(t,e,i,"form"),u=`${s(c)}/in`;null!=r[u]&&n.emit(u,c,r[u])}function s(i){const{callbacks:r,typeFn:s}=e,c=o(t,e,i,"form"),u=`${s(c)}/out`;null!=r[u]&&n.emit(u,c,r[u])}function c(r){const{callbacks:s,typeFn:c}=e,u=o(t,e,r,"form"),l=c(u),a=e.wait[`${l}`],f=`${l}/instant`;if(null==s[f])return;if(0===a)return void n.emit(f,u,s[f]);clearTimeout(i),i=setTimeout(()=>n.emit(f,u,s[f]),a)}return{start:function(){e.active||(document.addEventListener("focusin",r),document.addEventListener("focusout",s),document.addEventListener("input",c),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("focusin",r),document.removeEventListener("focusout",s),document.removeEventListener("input",c),e.active=!1,i&&(clearTimeout(i),i=null))}}}function p(t){const e=t.toUpperCase(),n=/FORM\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`FORM:${e.slice(i+1).trim()}`}function h(t,e){const{regex:n,_defaults:i,ev:o}=t,{currentContext:{name:r,note:s},shortcuts:c,callbacks:u,ERROR_EVENT_NAME:l,defaultOptions:a}=e;let f=[],d=[],p=[],h=0;if(null==r)return!1;if(Object.entries(c[r]).forEach(([i,o])=>{if(n.test(i)){if(i.includes("SETUP")){const n=o.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},a);return void Object.assign(e.listenOptions,n)}"FORM:WATCH"===i&&(f=o),"FORM:DEFINE"===i&&(d=o),"FORM:ACTION"===i&&(p=o)}}),0===p.length)return h;const m=new Set;0===d.length&&(d=[i.define]),0===f.length&&(f=[i.watch]);const g=f.map(n=>n({dependencies:t.extra,context:r,note:s,options:e.listenOptions})).reduce((t,e)=>(t.push(e),t),[]);return e.watchList=document.querySelectorAll(g),e.watchList.forEach(n=>{const{left:i,top:o,width:c,height:u}=n.getBoundingClientRect(),l=window.scrollX,a=window.scrollY;return m.add(d[0]({target:n,context:r,note:s,dependencies:t.extra,options:e.listenOptions,viewport:{X:l,Y:a,width:window.innerWidth,height:window.innerHeight},sizes:{width:c,height:u},position:{x:i,y:o},pagePosition:{x:i+l,y:o+a}}))}),e.typeFn=d[0]?d[0]:i.define,p.forEach(n=>{if(!(n instanceof Function))return o.emit(l,"The 'form:action' should be a function."),!1;const i=n({dependencies:t.extra,options:e.listenOptions});if(!(i instanceof Array))return o.emit(l,"Warning: The 'form:action' function should RETURN an array."),!1;i.forEach(({fn:t,type:n,timing:i,wait:r=0})=>{if(m.has(n)&&t instanceof Function){const e=`${n}/${i}`,r=u.hasOwnProperty(e);r?u[e].push(t):u[e]=[t],r||o.on(e,(t,e)=>{e.forEach(e=>{e instanceof Function&&e(t)})})}"instant"===i&&(e.wait[`${n}`]=r)})}),h=Object.keys(e.callbacks).length,h}const m={watch:()=>"input, select, textarea, button, a",define:({target:t})=>"checkbox"===t.type||"radio"===t.type?"checkbox":"button"==t.type||"submit"==t.type?"button":"input"};function g(t,e,n){const{listenOptions:{hoverTarget:i}}=e,o=n;if(o===document.body)return!1;if(o===document)return!1;return i.some(t=>o.hasAttribute(t))?o:g(t,e,o.parentNode)}function v(t,e){const{ev:n,_findTarget:i,resetState:o,extra:r}=t;function s(o){const s=o.clientX,c=o.clientY,{hovered:u,hoverRectangle:l,listenOptions:a,hoverTimer:f,leaveTimer:d,lastEvent:p,lastHoverTarget:h}=e,m=i(t,e,o.target);if(!function(t,e,n){return!!t&&e>=t.left&&e<=t.right&&n>=t.top&&n<=t.bottom}(l,s,c)&&m!==u){if(u&&!m){if(e.hovered=!1,e.hoverRectangle=null,f&&(clearTimeout(f),e.hoverTimer=null),"off"===p)return;return void(e.leaveTimer=setTimeout(()=>{n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"},a.wait))}u&&(n.emit("HOVER:OFF",g(u)),e.leaveTimer=null,e.lastEvent="off"),clearTimeout(d),clearTimeout(f),e.hovered=m,e.hoverRectangle=m.getBoundingClientRect(),e.hoverTimer=setTimeout(()=>{n.emit("HOVER:ON",g(m)),e.hoverTimer=null,e.lastHoverTarget=m,e.lastEvent="on"},a.wait)}function g(t){const{left:n,top:i,width:s,height:c}=t.getBoundingClientRect(),u=window.scrollX,l=window.scrollY;return{target:t,context:e.currentContext.name,note:e.currentContext.note,event:o,dependencies:r,options:e.listenOptions,viewport:{X:u,Y:l,width:window.innerWidth,height:window.innerHeight},sizes:{width:s,height:c},position:{x:n,y:i},pagePosition:{x:n+u,y:i+l},type:"hover"}}}return{start:function(){e.active||(document.addEventListener("mousemove",s),e.active=!0)},stop:function(){e.active&&(document.removeEventListener("mousemove",s),o())}}}function x(t){const e=t.toUpperCase(),n=/HOVER\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`HOVER:${e.slice(i+1).trim()}`}function E(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r,_defaults:s,ev:c}=t,{currentContext:{name:u},shortcuts:l,ERROR_EVENT_NAME:a}=e;return null==u||(Object.entries(l[u]).forEach(([s,c])=>{if(r.test(s)){if("HOVER:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}function O(t,e){const{ev:n,resetState:i,extra:o}=t;let r=null,s=null;function c(t){t.clientX,t.clientY;const{lastPosition:i,lastDirection:c,listenOptions:u,currentContext:l}=e,{scrollWait:a,endScrollWait:f,minSpace:d}=u;if(!i)return;let p=null;const h=window.scrollX,m=window.scrollY,g=Math.abs(m-i.y),v=Math.abs(h-i.x);if(g<d&&v<d)return;const x=[];g>=d&&(m>i.y?x.push("down"):x.push("up")),v>=d&&(h>i.x?x.push("right"):x.push("left")),p=x[0]||null;const E=t=>({x:h,y:m,direction:t,context:l.name,note:l.note,dependencies:o,options:e.listenOptions,viewport:{X:h,Y:m,width:window.innerWidth,height:window.innerHeight},type:"scroll"});x.forEach(t=>{const e=`SCROLL:${t.toUpperCase()}`;n.emit(e,E(t))}),clearTimeout(r),clearTimeout(s);const O=x[x.length-1]||null;r=setTimeout(()=>{},a),s=setTimeout(()=>n.emit("SCROLL:END",E(O)),f),e.lastPosition={x:h,y:m},e.lastDirection=p}return{start:function(){e.active||(e.lastPosition={x:window.scrollX,y:window.scrollY},window.addEventListener("scroll",c),e.active=!0)},stop:function(){e.active&&(window.removeEventListener("scroll",c),i())}}}function y(t){const e=t.toUpperCase(),n=/SCROLL\s*\:/i.test(e),i=e.indexOf(":");if(!n)return t;return`SCROLL:${e.slice(i+1).trim()}`}function w(t,e){let n=0,i=!1;const o=e.defaultOptions,{regex:r}=t,{currentContext:{name:s},shortcuts:c}=e;return null==s||(Object.entries(c[s]).forEach(([s,c])=>{if(r.test(s)){if("SCROLL:SETUP"===s){i=!0;const n=c.reduce((n,i)=>{const o=i({dependencies:t.extra,defaults:structuredClone(e.defaultOptions),options:e.listenOptions});return Object.assign(n,o)},o);return void Object.assign(e.listenOptions,n)}n++}}),i||Object.assign(e.listenOptions,o)),n}t.pluginClick=function(t,e={}){const n={_findTarget:c,_readClickEvent:a,regex:/CLICK\s*\:/i},i={active:!1,maxLeftClicks:1,maxRightClicks:1,defaultOptions:{mouseWait:320,clickTarget:["data-click","href"]},listenOptions:{mouseWait:320,clickTarget:["data-click","href"]},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return n.resetState=function(){},t({prefix:"click",_normalizeShortcutName:l,_registerShortcutEvents:f,_listenDOM:u,pluginState:i,deps:n})},t.pluginForm=function(t,e={}){const n={_defaults:m,regex:/FORM\s*\:/i},i={callbacks:{},typeFn:"",watchList:[],wait:{},defaultOptions:{},listenOptions:{}};return n.resetState=function(){i.callbacks={},i.typeFn="",i.watchList=[],i.wait={}},t({prefix:"form",_normalizeShortcutName:p,_registerShortcutEvents:h,_listenDOM:d,pluginState:i,deps:n})},t.pluginHover=function(t,e={}){const n={_findTarget:g,regex:/HOVER\s*\:/i},i={active:!1,hovered:!1,hoverRectangle:null,hoverTimer:null,leaveTimer:null,lastEvent:"",lastHoverTarget:null,defaultOptions:{hoverTarget:["data-hover"],wait:320},listenOptions:{hoverTarget:["data-hover"],wait:320}};return n.resetState=function(){i.active=!1,i.hovered=!1,i.hoverRectangle=null,clearTimeout(i.hoverTimer),clearTimeout(i.leaveTimer),i.hoverTimer=null,i.leaveTimer=null,i.lastHoverTarget=null},t({prefix:"hover",_normalizeShortcutName:x,_registerShortcutEvents:E,_listenDOM:v,pluginState:i,deps:n})},t.pluginKey=function(t,e={}){const c={_specialChars:s,_readKeyEvent:o,regex:/KEY\s*\:/i},u={active:!1,maxSequence:1,keyIgnore:null,defaultOptions:{keyWait:480},listenOptions:{keyWait:480},streamKeys:!(!e.streamKeys||"function"!=typeof e.streamKeys)&&e.streamKeys};return c.resetState=function(){u.active=!1,u.keyIgnore=null,u.maxSequence=1},t({prefix:"key",_normalizeShortcutName:i,_registerShortcutEvents:r,_listenDOM:n,pluginState:u,deps:c})},t.pluginScroll=function(t,e={}){const n={regex:/SCROLL\s*\:/i},i={active:!1,lastPosition:null,lastDirection:null,defaultOptions:{scrollWait:50,endScrollWait:400,minSpace:40},listenOptions:{scrollWait:50,endScrollWait:400,minSpace:40}};return n.resetState=function(){i.active=!1},t({prefix:"scroll",_normalizeShortcutName:y,_registerShortcutEvents:w,_listenDOM:O,pluginState:i,deps:n})},t.shortcuts=function(t={}){const n={},i={},o=function(){let t={"*":[]},e={},n=new Set,i=!1,o="";return{on:function(e,n){t[e]||(t[e]=[]),t[e].push(n)},once:function(t,n){"*"!==t&&(e[t]||(e[t]=[]),e[t].push(n))},off:function(n,i){if(i)return t[n]&&(t[n]=t[n].filter(t=>t!==i)),e[n]&&(e[n]=e[n].filter(t=>t!==i)),t[n]&&0===t[n].length&&delete t[n],void(e[n]&&0===e[n].length&&delete t[n]);e[n]&&delete e[n],t[n]&&delete t[n]},reset:function(){t={"*":[]},e={},n=new Set},emit:function(){const[r,...s]=arguments;function c(e){let i=!1;"*"!==e&&(n.has(e)||(t[e].every(t=>{const e=t(...s);return"string"!=typeof e||"STOP"!==e.toUpperCase()||(i=!0,!1)}),i||t["*"].forEach(t=>t(r,...s))))}if(i&&(console.log(`${o} Event "${r}" was triggered.`),s.length>0&&(console.log("Arguments:"),console.log(...s),console.log("^----"))),"*"!==r){if(e[r]){if(n.has(r))return;e[r].forEach(t=>t(...s)),delete e[r]}t[r]&&c(r)}else Object.keys(t).forEach(t=>c(t))},stop:function(i){if("*"===i){const i=Object.keys(t),o=Object.keys(e);return void(n=new Set([...o,...i]))}n.add(i)},start:function(t){"*"!==t?n.delete(t):n.clear()},debug:function(t,e){i=!!t,e&&"string"==typeof e&&(o=e)}}}(),r={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!t.onShortcut||"function"!=typeof t.onShortcut)&&t.onShortcut,ERROR_EVENT_NAME:t.errorEventName?t.errorEventName:"@shortcuts-error"},s={ev:o,inAPI:n,API:i,extra:{emit:o.emit}};return i.enablePlugin=(t,e={})=>{if("function"!=typeof t)return;const i=t(n._setupPlugin,e),o=i.getPrefix(),s=n._systemAction(o,"none");-1===s?(r.plugins.push(i),i.unmute()):(i.destroy(),r.plugins[s].unmute())},i.disablePlugin=t=>{const e=n._systemAction(t,"destroy");-1!==e&&r.plugins.splice(e,1)},i.mutePlugin=t=>n._systemAction(t,"mute"),i.unmutePlugin=t=>n._systemAction(t,"unmute"),i.listPlugins=()=>r.plugins.map(t=>t.getPrefix()),i.getContext=()=>r.currentContext.name,i.getNote=()=>r.currentContext.note,i.setNote=(t=null)=>{"string"!=typeof t&&null!=t||(r.currentContext.note=t)},i.pause=(t="*")=>{const e=n._readShortcutWithPlugins(t);o.stop(e)},i.resume=(t="*")=>{const e=n._readShortcutWithPlugins(t);o.start(e)},i.emit=(t,...e)=>o.emit(n._readShortcutWithPlugins(t),{dependencies:s.extra,type:"custom"},...e),i.listContexts=()=>Object.keys(r.shortcuts),i.setDependencies=t=>Object.assign(s.extra,t),i.getDependencies=()=>s.extra,i.reset=function(){o.reset(),i.changeContext(),r.plugins.forEach(t=>t.destroy()),i.listContexts().map(t=>i.unload(t)),s.extra={emit:o.emit},r.exposeShortcut=null},Object.entries(e).forEach(([t,e])=>{t.startsWith("_")?n[t]=e(s,r):i[t]=e(s,r)}),i}});
@@ -0,0 +1,35 @@
1
+ {
2
+ "corpus_tokens": 106545,
3
+ "corpus_words": 79909,
4
+ "nodes": 918,
5
+ "edges": 2370,
6
+ "avg_query_tokens": 20658,
7
+ "reduction_ratio": 5.2,
8
+ "per_question": [
9
+ {
10
+ "question": "how does authentication work",
11
+ "query_tokens": 18215,
12
+ "reduction": 5.8
13
+ },
14
+ {
15
+ "question": "what is the main entry point",
16
+ "query_tokens": 21200,
17
+ "reduction": 5.0
18
+ },
19
+ {
20
+ "question": "how are errors handled",
21
+ "query_tokens": 21139,
22
+ "reduction": 5.0
23
+ },
24
+ {
25
+ "question": "what connects the data layer to the api",
26
+ "query_tokens": 21556,
27
+ "reduction": 4.9
28
+ },
29
+ {
30
+ "question": "what are the core abstractions",
31
+ "query_tokens": 21181,
32
+ "reduction": 5.0
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1 @@
1
+ /Users/peternaydenov/.local/pipx/venvs/graphifyy/bin/python
@@ -0,0 +1,121 @@
1
+ # Graph Report - src (2026-06-07)
2
+
3
+ ## Corpus Check
4
+ - Corpus is ~10,802 words - fits in a single context window. You may not need a graph.
5
+
6
+ ## Summary
7
+ - 39 nodes · 26 edges · 17 communities detected
8
+ - Extraction: 100% EXTRACTED · 0% INFERRED · 0% AMBIGUOUS
9
+ - Token cost: 0 input · 0 output
10
+
11
+ ## God Nodes (most connected - your core abstractions)
12
+
13
+ ## Surprising Connections (you probably didn't know these)
14
+ - None detected - all connections are within the same source files.
15
+
16
+ ## Communities
17
+
18
+ ### Community 0 - "Plugin entry points (index.js)"
19
+ Cohesion: 0.25
20
+ Nodes (0):
21
+
22
+ ### Community 1 - "Library main entry (main.js)"
23
+ Cohesion: 1.0
24
+ Nodes (0):
25
+
26
+ ### Community 2 - "listShortcuts method"
27
+ Cohesion: 1.0
28
+ Nodes (0):
29
+
30
+ ### Community 3 - "unload method"
31
+ Cohesion: 1.0
32
+ Nodes (0):
33
+
34
+ ### Community 4 - "_readShortcutWithPlugins helper"
35
+ Cohesion: 1.0
36
+ Nodes (0):
37
+
38
+ ### Community 5 - "_normalizeWithPlugins helper"
39
+ Cohesion: 1.0
40
+ Nodes (0):
41
+
42
+ ### Community 6 - "load method"
43
+ Cohesion: 1.0
44
+ Nodes (0):
45
+
46
+ ### Community 7 - "_setupPlugin (plugin factory core)"
47
+ Cohesion: 1.0
48
+ Nodes (0):
49
+
50
+ ### Community 8 - "_systemAction helper"
51
+ Cohesion: 1.0
52
+ Nodes (0):
53
+
54
+ ### Community 9 - "changeContext method"
55
+ Cohesion: 1.0
56
+ Nodes (0):
57
+
58
+ ### Community 10 - "_registerShortcutEvents (per-plugin event glue)"
59
+ Cohesion: 1.0
60
+ Nodes (0):
61
+
62
+ ### Community 11 - "_normalizeShortcutName (per-plugin)"
63
+ Cohesion: 1.0
64
+ Nodes (0):
65
+
66
+ ### Community 12 - "_findTarget (hover only)"
67
+ Cohesion: 1.0
68
+ Nodes (0):
69
+
70
+ ### Community 13 - "_readClickEvent (click only)"
71
+ Cohesion: 1.0
72
+ Nodes (0):
73
+
74
+ ### Community 14 - "_specialChars (key only)"
75
+ Cohesion: 1.0
76
+ Nodes (0):
77
+
78
+ ### Community 15 - "_readKeyEvent (key only)"
79
+ Cohesion: 1.0
80
+ Nodes (0):
81
+
82
+ ### Community 16 - "_defaults (form only)"
83
+ Cohesion: 1.0
84
+ Nodes (0):
85
+
86
+ ## Knowledge Gaps
87
+ - **Thin community `Library main entry (main.js)`** (2 nodes): `main.js`, `main()`
88
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
89
+ - **Thin community `listShortcuts method`** (2 nodes): `listShortcuts.js`, `listShortcuts()`
90
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
91
+ - **Thin community `unload method`** (2 nodes): `unload.js`, `unload()`
92
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
93
+ - **Thin community `_readShortcutWithPlugins helper`** (2 nodes): `_readShortcutWithPlugins.js`, `_readShortcutWithPlugins()`
94
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
95
+ - **Thin community `_normalizeWithPlugins helper`** (2 nodes): `_normalizeWithPlugins.js`, `_normalizeWithPlugins()`
96
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
97
+ - **Thin community `load method`** (2 nodes): `load.js`, `load()`
98
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
99
+ - **Thin community `_setupPlugin (plugin factory core)`** (2 nodes): `_setupPlugin.js`, `_setupPlugin()`
100
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
101
+ - **Thin community `_systemAction helper`** (2 nodes): `_systemAction.js`, `_systemAction()`
102
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
103
+ - **Thin community `changeContext method`** (2 nodes): `changeContext.js`, `changeContext()`
104
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
105
+ - **Thin community `_registerShortcutEvents (per-plugin event glue)`** (2 nodes): `_registerShortcutEvents.js`, `_registerShortcutEvents()`
106
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
107
+ - **Thin community `_normalizeShortcutName (per-plugin)`** (2 nodes): `_normalizeShortcutName.js`, `_normalizeShortcutName()`
108
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
109
+ - **Thin community `_findTarget (hover only)`** (2 nodes): `_findTarget.js`, `_findTarget()`
110
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
111
+ - **Thin community `_readClickEvent (click only)`** (2 nodes): `_readClickEvent.js`, `_readClickEvent()`
112
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
113
+ - **Thin community `_specialChars (key only)`** (2 nodes): `_specialChars.js`, `_specialChars()`
114
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
115
+ - **Thin community `_readKeyEvent (key only)`** (2 nodes): `_readKeyEvent.js`, `_readKeyEvent()`
116
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
117
+ - **Thin community `_defaults (form only)`** (1 nodes): `_defaults.js`
118
+ Too small to be a meaningful cluster - may be noise or needs more connections extracted.
119
+
120
+ ## Suggested Questions
121
+ _Not enough signal to generate questions. This usually means the corpus has no AMBIGUOUS edges, no bridge nodes, no INFERRED relationships, and all communities are tightly cohesive. Add more files or run with --mode deep to extract richer edges._
@@ -0,0 +1 @@
1
+ {"nodes": [{"id": "findtarget", "label": "_findTarget.js", "file_type": "code", "source_file": "src/plugins/hover/_findTarget.js", "source_location": "L1"}, {"id": "findtarget_findtarget", "label": "_findTarget()", "file_type": "code", "source_file": "src/plugins/hover/_findTarget.js", "source_location": "L11"}], "edges": [{"source": "findtarget", "target": "findtarget_findtarget", "relation": "contains", "confidence": "EXTRACTED", "source_file": "src/plugins/hover/_findTarget.js", "source_location": "L11", "weight": 1.0}]}
@@ -0,0 +1 @@
1
+ {"nodes": [{"id": "block_navigation", "label": "block-navigation.js", "file_type": "code", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L1"}, {"id": "block_navigation_toggleclass", "label": "toggleClass()", "file_type": "code", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L24"}, {"id": "block_navigation_makecurrent", "label": "makeCurrent()", "file_type": "code", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L31"}, {"id": "block_navigation_gotoprevious", "label": "goToPrevious()", "file_type": "code", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L41"}, {"id": "block_navigation_gotonext", "label": "goToNext()", "file_type": "code", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L52"}], "edges": [{"source": "block_navigation", "target": "block_navigation_toggleclass", "relation": "contains", "confidence": "EXTRACTED", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L24", "weight": 1.0}, {"source": "block_navigation", "target": "block_navigation_makecurrent", "relation": "contains", "confidence": "EXTRACTED", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L31", "weight": 1.0}, {"source": "block_navigation", "target": "block_navigation_gotoprevious", "relation": "contains", "confidence": "EXTRACTED", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L41", "weight": 1.0}, {"source": "block_navigation", "target": "block_navigation_gotonext", "relation": "contains", "confidence": "EXTRACTED", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L52", "weight": 1.0}, {"source": "block_navigation_makecurrent", "target": "block_navigation_toggleclass", "relation": "calls", "confidence": "EXTRACTED", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L32", "weight": 1.0}, {"source": "block_navigation_gotoprevious", "target": "block_navigation_makecurrent", "relation": "calls", "confidence": "EXTRACTED", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L49", "weight": 1.0}, {"source": "block_navigation_gotonext", "target": "block_navigation_makecurrent", "relation": "calls", "confidence": "EXTRACTED", "source_file": "coverage/lcov-report/block-navigation.js", "source_location": "L62", "weight": 1.0}]}
@@ -0,0 +1 @@
1
+ {"nodes": [{"id": "normalizeshortcutname", "label": "_normalizeShortcutName.js", "file_type": "code", "source_file": "src/plugins/form/_normalizeShortcutName.js", "source_location": "L1"}, {"id": "normalizeshortcutname_normalizeshortcutname", "label": "_normalizeShortcutName()", "file_type": "code", "source_file": "src/plugins/form/_normalizeShortcutName.js", "source_location": "L3"}], "edges": [{"source": "normalizeshortcutname", "target": "normalizeshortcutname_normalizeshortcutname", "relation": "contains", "confidence": "EXTRACTED", "source_file": "src/plugins/form/_normalizeShortcutName.js", "source_location": "L3", "weight": 1.0}]}