@witchcraft/spellcraft 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +579 -0
- package/dist/core/EmulatedEvent.d.ts +10 -0
- package/dist/core/EmulatedEvent.js +19 -0
- package/dist/core/Emulator.d.ts +74 -0
- package/dist/core/Emulator.js +153 -0
- package/dist/core/ShortcutManagerManager.d.ts +103 -0
- package/dist/core/ShortcutManagerManager.js +267 -0
- package/dist/core/addCommand.d.ts +7 -0
- package/dist/core/addCommand.js +7 -0
- package/dist/core/addKey.d.ts +7 -0
- package/dist/core/addKey.js +7 -0
- package/dist/core/addShortcut.d.ts +7 -0
- package/dist/core/addShortcut.js +7 -0
- package/dist/core/attach.d.ts +10 -0
- package/dist/core/attach.js +13 -0
- package/dist/core/createCommand.d.ts +4 -0
- package/dist/core/createCommand.js +11 -0
- package/dist/core/createCommands.d.ts +11 -0
- package/dist/core/createCommands.js +20 -0
- package/dist/core/createCondition.d.ts +7 -0
- package/dist/core/createCondition.js +11 -0
- package/dist/core/createContext.d.ts +2 -0
- package/dist/core/createContext.js +8 -0
- package/dist/core/createKey.d.ts +10 -0
- package/dist/core/createKey.js +35 -0
- package/dist/core/createKeys.d.ts +5 -0
- package/dist/core/createKeys.js +36 -0
- package/dist/core/createManager.d.ts +81 -0
- package/dist/core/createManager.js +83 -0
- package/dist/core/createManagerEventListeners.d.ts +4 -0
- package/dist/core/createManagerEventListeners.js +130 -0
- package/dist/core/createManagerOptions.d.ts +8 -0
- package/dist/core/createManagerOptions.js +17 -0
- package/dist/core/createShortcut.d.ts +8 -0
- package/dist/core/createShortcut.js +24 -0
- package/dist/core/createShortcuts.d.ts +13 -0
- package/dist/core/createShortcuts.js +20 -0
- package/dist/core/detach.d.ts +10 -0
- package/dist/core/detach.js +6 -0
- package/dist/core/index.d.ts +32 -0
- package/dist/core/index.js +32 -0
- package/dist/core/removeCommand.d.ts +7 -0
- package/dist/core/removeCommand.js +7 -0
- package/dist/core/removeKey.d.ts +7 -0
- package/dist/core/removeKey.js +7 -0
- package/dist/core/removeShortcut.d.ts +7 -0
- package/dist/core/removeShortcut.js +7 -0
- package/dist/core/setCommandProp.d.ts +17 -0
- package/dist/core/setCommandProp.js +96 -0
- package/dist/core/setCommandsProp.d.ts +15 -0
- package/dist/core/setCommandsProp.js +94 -0
- package/dist/core/setKeyProp.d.ts +16 -0
- package/dist/core/setKeyProp.js +47 -0
- package/dist/core/setKeysProp.d.ts +10 -0
- package/dist/core/setKeysProp.js +166 -0
- package/dist/core/setManagerProp.d.ts +34 -0
- package/dist/core/setManagerProp.js +54 -0
- package/dist/core/setShortcutProp.d.ts +9 -0
- package/dist/core/setShortcutProp.js +50 -0
- package/dist/core/setShortcutsProp.d.ts +12 -0
- package/dist/core/setShortcutsProp.js +93 -0
- package/dist/defaults/KeysSorter.d.ts +35 -0
- package/dist/defaults/KeysSorter.js +20 -0
- package/dist/defaults/Stringifier.d.ts +66 -0
- package/dist/defaults/Stringifier.js +119 -0
- package/dist/defaults/defaultConditionEquals.d.ts +19 -0
- package/dist/defaults/defaultConditionEquals.js +5 -0
- package/dist/defaults/defaultManagerCallback.d.ts +7 -0
- package/dist/defaults/defaultManagerCallback.js +5 -0
- package/dist/helpers/KnownError.d.ts +8 -0
- package/dist/helpers/KnownError.js +3 -0
- package/dist/helpers/calculateAndSetPositionAndWidth.d.ts +13 -0
- package/dist/helpers/calculateAndSetPositionAndWidth.js +18 -0
- package/dist/helpers/calculateLayoutSize.d.ts +9 -0
- package/dist/helpers/calculateLayoutSize.js +13 -0
- package/dist/helpers/doesShortcutConflict.d.ts +18 -0
- package/dist/helpers/doesShortcutConflict.js +42 -0
- package/dist/helpers/equalsCommand.d.ts +7 -0
- package/dist/helpers/equalsCommand.js +4 -0
- package/dist/helpers/equalsContext.d.ts +7 -0
- package/dist/helpers/equalsContext.js +19 -0
- package/dist/helpers/equalsShortcut.d.ts +9 -0
- package/dist/helpers/equalsShortcut.js +7 -0
- package/dist/helpers/forceClear.d.ts +12 -0
- package/dist/helpers/forceClear.js +16 -0
- package/dist/helpers/forceUpdateNativeKeysState.d.ts +5 -0
- package/dist/helpers/forceUpdateNativeKeysState.js +4 -0
- package/dist/helpers/generateKeyShortcutMap.d.ts +23 -0
- package/dist/helpers/generateKeyShortcutMap.js +64 -0
- package/dist/helpers/getKeyFromEventCode.d.ts +15 -0
- package/dist/helpers/getKeyFromEventCode.js +36 -0
- package/dist/helpers/getKeyFromIdOrVariant.d.ts +4 -0
- package/dist/helpers/getKeyFromIdOrVariant.js +26 -0
- package/dist/helpers/getKeyboardLayoutMap.d.ts +5 -0
- package/dist/helpers/getKeyboardLayoutMap.js +7 -0
- package/dist/helpers/getLabel.d.ts +9 -0
- package/dist/helpers/getLabel.js +6 -0
- package/dist/helpers/getTriggerableShortcut.d.ts +6 -0
- package/dist/helpers/getTriggerableShortcut.js +25 -0
- package/dist/helpers/index.d.ts +28 -0
- package/dist/helpers/index.js +28 -0
- package/dist/helpers/isValidManager.d.ts +3 -0
- package/dist/helpers/isValidManager.js +20 -0
- package/dist/helpers/isValidShortcut.d.ts +3 -0
- package/dist/helpers/isValidShortcut.js +10 -0
- package/dist/helpers/labelWithEvent.d.ts +13 -0
- package/dist/helpers/labelWithEvent.js +20 -0
- package/dist/helpers/labelWithKeyboardMap.d.ts +15 -0
- package/dist/helpers/labelWithKeyboardMap.js +17 -0
- package/dist/helpers/managerToStorableClone.d.ts +12 -0
- package/dist/helpers/managerToStorableClone.js +13 -0
- package/dist/helpers/onKeyboardLayoutChange.d.ts +10 -0
- package/dist/helpers/onKeyboardLayoutChange.js +7 -0
- package/dist/helpers/safeSetManagerChain.d.ts +20 -0
- package/dist/helpers/safeSetManagerChain.js +37 -0
- package/dist/helpers/shortcutCanExecuteIn.d.ts +4 -0
- package/dist/helpers/shortcutCanExecuteIn.js +9 -0
- package/dist/helpers/shortcutIsTriggerableBy.d.ts +2 -0
- package/dist/helpers/shortcutIsTriggerableBy.js +5 -0
- package/dist/helpers/shortcutSwapChords.d.ts +75 -0
- package/dist/helpers/shortcutSwapChords.js +118 -0
- package/dist/helpers/virtualPress.d.ts +13 -0
- package/dist/helpers/virtualPress.js +15 -0
- package/dist/helpers/virtualRelease.d.ts +5 -0
- package/dist/helpers/virtualRelease.js +15 -0
- package/dist/helpers/virtualToggle.d.ts +7 -0
- package/dist/helpers/virtualToggle.js +16 -0
- package/dist/internal/addToChain.d.ts +3 -0
- package/dist/internal/addToChain.js +27 -0
- package/dist/internal/areValidKeys.d.ts +7 -0
- package/dist/internal/areValidKeys.js +28 -0
- package/dist/internal/areValidVariants.d.ts +4 -0
- package/dist/internal/areValidVariants.js +45 -0
- package/dist/internal/checkTrigger.d.ts +2 -0
- package/dist/internal/checkTrigger.js +47 -0
- package/dist/internal/checkUntrigger.d.ts +2 -0
- package/dist/internal/checkUntrigger.js +18 -0
- package/dist/internal/cloneLastChord.d.ts +4 -0
- package/dist/internal/cloneLastChord.js +5 -0
- package/dist/internal/containsPossibleToggleChords.d.ts +13 -0
- package/dist/internal/containsPossibleToggleChords.js +65 -0
- package/dist/internal/errorTextAdd.d.ts +1 -0
- package/dist/internal/errorTextAdd.js +11 -0
- package/dist/internal/errorTextInUse.d.ts +1 -0
- package/dist/internal/errorTextInUse.js +8 -0
- package/dist/internal/errorTextRemove.d.ts +1 -0
- package/dist/internal/errorTextRemove.js +8 -0
- package/dist/internal/getModifierState.d.ts +2 -0
- package/dist/internal/getModifierState.js +7 -0
- package/dist/internal/getPressedKeys.d.ts +7 -0
- package/dist/internal/getPressedKeys.js +18 -0
- package/dist/internal/getPressedModifierKeys.d.ts +2 -0
- package/dist/internal/getPressedModifierKeys.js +10 -0
- package/dist/internal/getPressedNonModifierKeys.d.ts +7 -0
- package/dist/internal/getPressedNonModifierKeys.js +11 -0
- package/dist/internal/inChain.d.ts +5 -0
- package/dist/internal/inChain.js +14 -0
- package/dist/internal/isValidChain.d.ts +10 -0
- package/dist/internal/isValidChain.js +22 -0
- package/dist/internal/isValidChord.d.ts +11 -0
- package/dist/internal/isValidChord.js +59 -0
- package/dist/internal/isValidCommand.d.ts +12 -0
- package/dist/internal/isValidCommand.js +20 -0
- package/dist/internal/keyOrder.d.ts +6 -0
- package/dist/internal/keyOrder.js +14 -0
- package/dist/internal/removeFromChain.d.ts +3 -0
- package/dist/internal/removeFromChain.js +32 -0
- package/dist/internal/safeSetEmulatedToggleState.d.ts +4 -0
- package/dist/internal/safeSetEmulatedToggleState.js +13 -0
- package/dist/internal/setKeysState.d.ts +8 -0
- package/dist/internal/setKeysState.js +42 -0
- package/dist/internal/updateNativeKeysState.d.ts +14 -0
- package/dist/internal/updateNativeKeysState.js +58 -0
- package/dist/layouts/createLayout.d.ts +25 -0
- package/dist/layouts/createLayout.js +221 -0
- package/dist/module.d.mts +13 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +40 -0
- package/dist/runtime/composables/useLabeledByKeyboardLayoutMap.d.ts +9 -0
- package/dist/runtime/composables/useLabeledByKeyboardLayoutMap.js +19 -0
- package/dist/runtime/composables/usePointerCoords.d.ts +32 -0
- package/dist/runtime/composables/usePointerCoords.js +17 -0
- package/dist/runtime/composables/useShortcutManagerContextCount.d.ts +14 -0
- package/dist/runtime/composables/useShortcutManagerContextCount.js +61 -0
- package/dist/runtime/composables/useShortcutManagerKeysLayout.d.ts +18 -0
- package/dist/runtime/composables/useShortcutManagerKeysLayout.js +22 -0
- package/dist/runtime/composables/useShortcutManagerVirtualPress.d.ts +6 -0
- package/dist/runtime/composables/useShortcutManagerVirtualPress.js +24 -0
- package/dist/runtime/types.d.ts +10 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/utils/shortcutToId.d.ts +5 -0
- package/dist/runtime/utils/shortcutToId.js +6 -0
- package/dist/types/commands.d.ts +113 -0
- package/dist/types/commands.js +0 -0
- package/dist/types/condition.d.ts +29 -0
- package/dist/types/condition.js +0 -0
- package/dist/types/context.d.ts +18 -0
- package/dist/types/context.js +0 -0
- package/dist/types/enums.d.ts +186 -0
- package/dist/types/enums.js +70 -0
- package/dist/types/general.d.ts +92 -0
- package/dist/types/general.js +0 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +8 -0
- package/dist/types/keys.d.ts +332 -0
- package/dist/types/keys.js +0 -0
- package/dist/types/manager.d.ts +249 -0
- package/dist/types/manager.js +0 -0
- package/dist/types/plugins.d.ts +1 -0
- package/dist/types/plugins.js +0 -0
- package/dist/types/shortcuts.d.ts +144 -0
- package/dist/types/shortcuts.js +0 -0
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.js +0 -0
- package/dist/types.d.mts +3 -0
- package/dist/utils/chainContainsSubset.d.ts +27 -0
- package/dist/utils/chainContainsSubset.js +45 -0
- package/dist/utils/cloneChain.d.ts +2 -0
- package/dist/utils/cloneChain.js +11 -0
- package/dist/utils/cloneKey.d.ts +3 -0
- package/dist/utils/cloneKey.js +26 -0
- package/dist/utils/containsKey.d.ts +7 -0
- package/dist/utils/containsKey.js +4 -0
- package/dist/utils/dedupeKeys.d.ts +9 -0
- package/dist/utils/dedupeKeys.js +9 -0
- package/dist/utils/equalsKey.d.ts +12 -0
- package/dist/utils/equalsKey.js +13 -0
- package/dist/utils/equalsKeys.d.ts +24 -0
- package/dist/utils/equalsKeys.js +15 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/isAnyKey.d.ts +5 -0
- package/dist/utils/isAnyKey.js +5 -0
- package/dist/utils/isMouseKey.d.ts +5 -0
- package/dist/utils/isMouseKey.js +20 -0
- package/dist/utils/isNormalKey.d.ts +5 -0
- package/dist/utils/isNormalKey.js +5 -0
- package/dist/utils/isTriggerKey.d.ts +5 -0
- package/dist/utils/isTriggerKey.js +3 -0
- package/dist/utils/isWheelKey.d.ts +5 -0
- package/dist/utils/isWheelKey.js +11 -0
- package/dist/utils/mapKeys.d.ts +8 -0
- package/dist/utils/mapKeys.js +5 -0
- package/dist/utils/removeKeys.d.ts +7 -0
- package/dist/utils/removeKeys.js +4 -0
- package/package.json +156 -0
- package/src/core/EmulatedEvent.ts +29 -0
- package/src/core/Emulator.ts +185 -0
- package/src/core/ShortcutManagerManager.ts +380 -0
- package/src/core/addCommand.ts +24 -0
- package/src/core/addKey.ts +25 -0
- package/src/core/addShortcut.ts +24 -0
- package/src/core/attach.ts +27 -0
- package/src/core/createCommand.ts +24 -0
- package/src/core/createCommands.ts +45 -0
- package/src/core/createCondition.ts +21 -0
- package/src/core/createContext.ts +14 -0
- package/src/core/createKey.ts +59 -0
- package/src/core/createKeys.ts +68 -0
- package/src/core/createManager.ts +209 -0
- package/src/core/createManagerEventListeners.ts +139 -0
- package/src/core/createManagerOptions.ts +29 -0
- package/src/core/createShortcut.ts +49 -0
- package/src/core/createShortcuts.ts +51 -0
- package/src/core/detach.ts +21 -0
- package/src/core/index.ts +35 -0
- package/src/core/removeCommand.ts +25 -0
- package/src/core/removeKey.ts +25 -0
- package/src/core/removeShortcut.ts +24 -0
- package/src/core/setCommandProp.ts +140 -0
- package/src/core/setCommandsProp.ts +128 -0
- package/src/core/setKeyProp.ts +80 -0
- package/src/core/setKeysProp.ts +205 -0
- package/src/core/setManagerProp.ts +111 -0
- package/src/core/setShortcutProp.ts +89 -0
- package/src/core/setShortcutsProp.ts +124 -0
- package/src/defaults/KeysSorter.ts +55 -0
- package/src/defaults/Stringifier.ts +234 -0
- package/src/defaults/defaultConditionEquals.ts +29 -0
- package/src/defaults/defaultManagerCallback.ts +14 -0
- package/src/helpers/KnownError.ts +13 -0
- package/src/helpers/calculateAndSetPositionAndWidth.ts +30 -0
- package/src/helpers/calculateLayoutSize.ts +22 -0
- package/src/helpers/doesShortcutConflict.ts +72 -0
- package/src/helpers/equalsCommand.ts +18 -0
- package/src/helpers/equalsContext.ts +29 -0
- package/src/helpers/equalsShortcut.ts +34 -0
- package/src/helpers/forceClear.ts +31 -0
- package/src/helpers/forceUpdateNativeKeysState.ts +9 -0
- package/src/helpers/generateKeyShortcutMap.ts +113 -0
- package/src/helpers/getKeyFromEventCode.ts +67 -0
- package/src/helpers/getKeyFromIdOrVariant.ts +33 -0
- package/src/helpers/getKeyboardLayoutMap.ts +13 -0
- package/src/helpers/getLabel.ts +15 -0
- package/src/helpers/getTriggerableShortcut.ts +37 -0
- package/src/helpers/index.ts +30 -0
- package/src/helpers/isValidManager.ts +29 -0
- package/src/helpers/isValidShortcut.ts +20 -0
- package/src/helpers/labelWithEvent.ts +41 -0
- package/src/helpers/labelWithKeyboardMap.ts +37 -0
- package/src/helpers/managerToStorableClone.ts +26 -0
- package/src/helpers/onKeyboardLayoutChange.ts +17 -0
- package/src/helpers/safeSetManagerChain.ts +66 -0
- package/src/helpers/shortcutCanExecuteIn.ts +24 -0
- package/src/helpers/shortcutIsTriggerableBy.ts +15 -0
- package/src/helpers/shortcutSwapChords.ts +240 -0
- package/src/helpers/virtualPress.ts +34 -0
- package/src/helpers/virtualRelease.ts +25 -0
- package/src/helpers/virtualToggle.ts +28 -0
- package/src/internal/addToChain.ts +40 -0
- package/src/internal/areValidKeys.ts +40 -0
- package/src/internal/areValidVariants.ts +59 -0
- package/src/internal/checkTrigger.ts +55 -0
- package/src/internal/checkUntrigger.ts +26 -0
- package/src/internal/cloneLastChord.ts +10 -0
- package/src/internal/containsPossibleToggleChords.ts +91 -0
- package/src/internal/errorTextAdd.ts +18 -0
- package/src/internal/errorTextInUse.ts +10 -0
- package/src/internal/errorTextRemove.ts +10 -0
- package/src/internal/getModifierState.ts +15 -0
- package/src/internal/getPressedKeys.ts +26 -0
- package/src/internal/getPressedModifierKeys.ts +14 -0
- package/src/internal/getPressedNonModifierKeys.ts +19 -0
- package/src/internal/inChain.ts +25 -0
- package/src/internal/isValidChain.ts +42 -0
- package/src/internal/isValidChord.ts +87 -0
- package/src/internal/isValidCommand.ts +35 -0
- package/src/internal/keyOrder.ts +24 -0
- package/src/internal/removeFromChain.ts +46 -0
- package/src/internal/safeSetEmulatedToggleState.ts +23 -0
- package/src/internal/setKeysState.ts +71 -0
- package/src/internal/updateNativeKeysState.ts +84 -0
- package/src/layouts/createLayout.ts +328 -0
- package/src/module.ts +62 -0
- package/src/runtime/composables/useLabeledByKeyboardLayoutMap.ts +28 -0
- package/src/runtime/composables/usePointerCoords.ts +40 -0
- package/src/runtime/composables/useShortcutManagerContextCount.ts +81 -0
- package/src/runtime/composables/useShortcutManagerKeysLayout.ts +42 -0
- package/src/runtime/composables/useShortcutManagerVirtualPress.ts +30 -0
- package/src/runtime/types.ts +10 -0
- package/src/runtime/utils/shortcutToId.ts +14 -0
- package/src/types/commands.ts +148 -0
- package/src/types/condition.ts +35 -0
- package/src/types/context.ts +19 -0
- package/src/types/enums.ts +236 -0
- package/src/types/general.ts +117 -0
- package/src/types/index.ts +10 -0
- package/src/types/keys.ts +385 -0
- package/src/types/manager.ts +374 -0
- package/src/types/plugins.ts +32 -0
- package/src/types/shortcuts.ts +204 -0
- package/src/types/utils.ts +40 -0
- package/src/utils/chainContainsSubset.ts +97 -0
- package/src/utils/cloneChain.ts +13 -0
- package/src/utils/cloneKey.ts +33 -0
- package/src/utils/containsKey.ts +17 -0
- package/src/utils/dedupeKeys.ts +23 -0
- package/src/utils/equalsKey.ts +32 -0
- package/src/utils/equalsKeys.ts +50 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/isAnyKey.ts +12 -0
- package/src/utils/isMouseKey.ts +27 -0
- package/src/utils/isNormalKey.ts +15 -0
- package/src/utils/isTriggerKey.ts +7 -0
- package/src/utils/isWheelKey.ts +18 -0
- package/src/utils/mapKeys.ts +21 -0
- package/src/utils/removeKeys.ts +16 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { chainContainsSubset } from "./chainContainsSubset.js";
|
|
2
|
+
export { cloneChain } from "./cloneChain.js";
|
|
3
|
+
export { cloneKey } from "./cloneKey.js";
|
|
4
|
+
export { containsKey } from "./containsKey.js";
|
|
5
|
+
export { dedupeKeys } from "./dedupeKeys.js";
|
|
6
|
+
export { equalsKey } from "./equalsKey.js";
|
|
7
|
+
export { equalsKeys } from "./equalsKeys.js";
|
|
8
|
+
export { isAnyKey } from "./isAnyKey.js";
|
|
9
|
+
export { isMouseKey } from "./isMouseKey.js";
|
|
10
|
+
export { isNormalKey } from "./isNormalKey.js";
|
|
11
|
+
export { isTriggerKey } from "./isTriggerKey.js";
|
|
12
|
+
export { isWheelKey } from "./isWheelKey.js";
|
|
13
|
+
export { mapKeys } from "./mapKeys.js";
|
|
14
|
+
export { removeKeys } from "./removeKeys.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { chainContainsSubset } from "./chainContainsSubset.js";
|
|
2
|
+
export { cloneChain } from "./cloneChain.js";
|
|
3
|
+
export { cloneKey } from "./cloneKey.js";
|
|
4
|
+
export { containsKey } from "./containsKey.js";
|
|
5
|
+
export { dedupeKeys } from "./dedupeKeys.js";
|
|
6
|
+
export { equalsKey } from "./equalsKey.js";
|
|
7
|
+
export { equalsKeys } from "./equalsKeys.js";
|
|
8
|
+
export { isAnyKey } from "./isAnyKey.js";
|
|
9
|
+
export { isMouseKey } from "./isMouseKey.js";
|
|
10
|
+
export { isNormalKey } from "./isNormalKey.js";
|
|
11
|
+
export { isTriggerKey } from "./isTriggerKey.js";
|
|
12
|
+
export { isWheelKey } from "./isWheelKey.js";
|
|
13
|
+
export { mapKeys } from "./mapKeys.js";
|
|
14
|
+
export { removeKeys } from "./removeKeys.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const possibleIds = [
|
|
2
|
+
"0",
|
|
3
|
+
"1",
|
|
4
|
+
"2",
|
|
5
|
+
"3",
|
|
6
|
+
"4",
|
|
7
|
+
"0On",
|
|
8
|
+
"1On",
|
|
9
|
+
"2On",
|
|
10
|
+
"3On",
|
|
11
|
+
"4On",
|
|
12
|
+
"0Off",
|
|
13
|
+
"1Off",
|
|
14
|
+
"2Off",
|
|
15
|
+
"3Off",
|
|
16
|
+
"4Off"
|
|
17
|
+
];
|
|
18
|
+
export function isMouseKey(key) {
|
|
19
|
+
return possibleIds.includes(key.id) || (key.variants?.some((id) => possibleIds.includes(id)) ?? false);
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const possibleIds = [
|
|
2
|
+
"WheelUp",
|
|
3
|
+
"WheelDown",
|
|
4
|
+
"WheelUpOn",
|
|
5
|
+
"WheelDownOn",
|
|
6
|
+
"WheelUpOff",
|
|
7
|
+
"WheelDownOff"
|
|
8
|
+
];
|
|
9
|
+
export function isWheelKey(key) {
|
|
10
|
+
return possibleIds.includes(key.id) || (key.variants?.some((id) => possibleIds.includes(id)) ?? false);
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map keys of a chain or chord\* by the given function.
|
|
3
|
+
*
|
|
4
|
+
* Useful for inspecting a chain/chord when debugging.
|
|
5
|
+
*
|
|
6
|
+
* \*This is determined by checking if the first element is an array or not.
|
|
7
|
+
*/
|
|
8
|
+
export declare function mapKeys<TType extends any[] | any[][], TReturn = string>(chainOrChord: TType, func?: (key: TType extends any[][] ? TType[number][number] : TType[number]) => TReturn): TType extends any[][] ? TReturn[][] : TReturn[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { isArray } from "@alanscodelog/utils/isArray";
|
|
2
|
+
export function mapKeys(chainOrChord, func = (key) => key?.id) {
|
|
3
|
+
if (chainOrChord.length === 0) return [];
|
|
4
|
+
return isArray(chainOrChord[0]) ? chainOrChord.map((chord) => chord.map((key) => func(key))) : chainOrChord.map((key) => func(key));
|
|
5
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Keys } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a copy of keysList with the keys given to remove, removed, checking equality according to {@link equalsKey}.
|
|
4
|
+
*/
|
|
5
|
+
export declare const removeKeys: (keysList: readonly string[], toRemove: readonly string[], keys: Keys, opts?: {
|
|
6
|
+
allowVariants?: boolean;
|
|
7
|
+
}) => string[];
|
package/package.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@witchcraft/spellcraft",
|
|
3
|
+
"description": "A shortcut manager library for handling ALL the shortcut needs of an application.",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/core/index.js",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"build": {
|
|
9
|
+
"failOnWarn": false
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/core/index.d.ts",
|
|
14
|
+
"import": "./dist/core/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./utils": {
|
|
17
|
+
"types": "./dist/utils/index.d.ts",
|
|
18
|
+
"import": "./dist/utils/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./helpers": {
|
|
21
|
+
"types": "./dist/helpers/index.d.ts",
|
|
22
|
+
"import": "./dist/helpers/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./types": {
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"import": "./dist/types/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./core": {
|
|
29
|
+
"types": "./dist/core/index.d.ts",
|
|
30
|
+
"import": "./dist/core/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./nuxt": {
|
|
33
|
+
"types": "./dist/types.d.mts",
|
|
34
|
+
"import": "./dist/module.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./*": {
|
|
37
|
+
"types": "./dist/*.js",
|
|
38
|
+
"import": "./dist/*.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"prepare": "husky && cd playground && pnpm i",
|
|
43
|
+
"build": "nuxt-module-build prepare && nuxt-module-build build && nuxi generate playground",
|
|
44
|
+
"build:only": "nuxt-module-build build",
|
|
45
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
46
|
+
"dev:playground": "nuxi dev playground",
|
|
47
|
+
"dev": "nuxi dev playground",
|
|
48
|
+
"test": "pnpm lint:types && vitest run --exclude '.direnv/**/*'",
|
|
49
|
+
"test:watch": "vitest --watch --exclude '.direnv/**/*'",
|
|
50
|
+
"test:inspect-errors": "cross-env INSPECT_ERRORS=true npm run test",
|
|
51
|
+
"coverage": "vitest --exclude '.direnv/**/*' --coverage",
|
|
52
|
+
"coverage:dev": "vitest --exclude '.direnv/**/*' --watch --coverage",
|
|
53
|
+
"doc": "typedoc",
|
|
54
|
+
"doc:watch": "onchange -i \"src/**/*.ts\" \"typedoc.config.js\" -- pnpm doc",
|
|
55
|
+
"doc:serve": "http-server docs --port=5001",
|
|
56
|
+
"doc:dev": "concurrently \"pnpm doc:watch\" \"pnpm doc:serve\"",
|
|
57
|
+
"doc:check-invalid": "typedoc --listInvalidSymbolLinks",
|
|
58
|
+
"lint:eslint": "eslint \"{src,test,playground/app}/**/*.{js,ts,vue,cjs}\" \"*.{js,ts}\" --max-warnings=0 --report-unused-disable-directives",
|
|
59
|
+
"lint:types": "vue-tsc --noEmit && echo 'todo cd playground && vue-tsc --noEmit'",
|
|
60
|
+
"lint:commits": "commitlint --from-last-tag --to HEAD --verbose",
|
|
61
|
+
"lint:imports": "madge --circular --extensions ts ./src",
|
|
62
|
+
"lint": "pnpm lint:types && pnpm lint:eslint && pnpm lint:imports",
|
|
63
|
+
"actions:debug": "act -r -v",
|
|
64
|
+
"gen:exports": "indexit update -o '${path}.js'"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@witchcraft/expressit": "^0.4.0",
|
|
68
|
+
"@witchcraft/ui": "^0.2.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"@witchcraft/ui": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@witchcraft/expressit": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"@alanscodelog/utils": "^6.0.2",
|
|
80
|
+
"@witchcraft/expressit": "^0.4.1",
|
|
81
|
+
"@witchcraft/ui": "^0.2.4",
|
|
82
|
+
"vue": "^3.5.21"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@alanscodelog/commitlint-config": "^3.1.2",
|
|
86
|
+
"@alanscodelog/eslint-config": "^6.3.1",
|
|
87
|
+
"@alanscodelog/semantic-release-config": "^5.0.4",
|
|
88
|
+
"@alanscodelog/tsconfigs": "^6.2.0",
|
|
89
|
+
"@alanscodelog/vite-config": "^0.0.6",
|
|
90
|
+
"@commitlint/cli": "^19.8.1",
|
|
91
|
+
"@iconify/json": "^2.2.385",
|
|
92
|
+
"@nuxt/eslint-config": "^1.9.0",
|
|
93
|
+
"@nuxt/kit": "^4.1.2",
|
|
94
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
95
|
+
"@nuxt/schema": "^4.1.2",
|
|
96
|
+
"@nuxt/types": "^2.18.1",
|
|
97
|
+
"@types/node": "^24.5.2",
|
|
98
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
99
|
+
"@vitest/coverage-c8": "^0.33.0",
|
|
100
|
+
"concurrently": "^9.2.1",
|
|
101
|
+
"cross-env": "^10.0.0",
|
|
102
|
+
"defu": "^6.1.4",
|
|
103
|
+
"fast-glob": "^3.3.3",
|
|
104
|
+
"http-server": "^14.1.1",
|
|
105
|
+
"husky": "^9.1.7",
|
|
106
|
+
"indexit": "2.1.0-beta.3",
|
|
107
|
+
"madge": "^8.0.0",
|
|
108
|
+
"nuxt": "^4.1.2",
|
|
109
|
+
"onchange": "^7.1.0",
|
|
110
|
+
"semantic-release": "^24.2.8",
|
|
111
|
+
"tailwindcss": "^4.1.13",
|
|
112
|
+
"typedoc": "0.28.13",
|
|
113
|
+
"typescript": "^5.9.2",
|
|
114
|
+
"unbuild": "^3.6.1",
|
|
115
|
+
"unplugin-icons": "^22.3.0",
|
|
116
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
117
|
+
"vitest": "^3.2.4",
|
|
118
|
+
"vue-tsc": "^3.0.7"
|
|
119
|
+
},
|
|
120
|
+
"author": "Alan <alanscodelog@gmail.com>",
|
|
121
|
+
"repository": "https://github.com/witchcraftjs/spellcraft",
|
|
122
|
+
"license": "MIT",
|
|
123
|
+
"files": [
|
|
124
|
+
"src",
|
|
125
|
+
"dist"
|
|
126
|
+
],
|
|
127
|
+
"release": {
|
|
128
|
+
"extends": [
|
|
129
|
+
"@alanscodelog/semantic-release-config"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"commitlint": {
|
|
133
|
+
"extends": [
|
|
134
|
+
"@alanscodelog"
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
"babel": {
|
|
138
|
+
"presets": [
|
|
139
|
+
"@alanscodelog"
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
"madge": {
|
|
143
|
+
"detectiveOptions": {
|
|
144
|
+
"ts": {
|
|
145
|
+
"skipTypeImports": true
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"browserslist": "> 0.5%, last 2 versions, not dead, not < 0.25%, not IE > 0, maintained node versions",
|
|
150
|
+
"engines": {
|
|
151
|
+
"node": ">=20.0.0"
|
|
152
|
+
},
|
|
153
|
+
"publishConfig": {
|
|
154
|
+
"access": "public"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class EmulatedEvent<
|
|
2
|
+
TType extends "keydown" | "keyup" | "mousedown" | "mouseup" | "wheel" | "mouseenter" = "keydown" | "keyup" | "mousedown" | "mouseup" | "wheel" | "mouseenter"
|
|
3
|
+
> {
|
|
4
|
+
code!: TType extends "keydown" | "keyup" ? string : never
|
|
5
|
+
|
|
6
|
+
button!: TType extends "mousedown" | "mouseup" ? number : never
|
|
7
|
+
|
|
8
|
+
deltaY!: TType extends "wheel" ? number : never
|
|
9
|
+
|
|
10
|
+
modifiers: string[]
|
|
11
|
+
|
|
12
|
+
type: TType
|
|
13
|
+
|
|
14
|
+
constructor(type: TType, info: Partial<EmulatedEvent<TType>> = {}, modifiers: string[] = []) {
|
|
15
|
+
this.modifiers = modifiers
|
|
16
|
+
this.type = type
|
|
17
|
+
for (const property of Object.keys(info)) {
|
|
18
|
+
(this as any)[property] = (info as any)[property]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getModifierState(code: string): boolean {
|
|
23
|
+
return this.modifiers.includes(code)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
preventDefault(): void {
|
|
27
|
+
// so we don't get annoying type errors
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { AnyFunction } from "@alanscodelog/utils/types"
|
|
2
|
+
|
|
3
|
+
import { EmulatedEvent } from "./EmulatedEvent.js"
|
|
4
|
+
|
|
5
|
+
import type { Keys } from "../types/index.js"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const mouseButtons = ["0", "1", "2", "3", "4", "5"]
|
|
9
|
+
const mouseButtonsDown = mouseButtons.map(b => `${b}+`)
|
|
10
|
+
const mouseButtonsUp = mouseButtons.map(b => `${b}-`)
|
|
11
|
+
const wheelKeys = ["wheelUp", "wheelDown"]
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A simple key emulator for testing purposes. Should be hooked up to a manager class as if it was an element:
|
|
15
|
+
* ```ts
|
|
16
|
+
* const emulator = new Emulator()
|
|
17
|
+
* manager.attach(emulator)
|
|
18
|
+
* // press and release a
|
|
19
|
+
* emulator.fire("KeyA")
|
|
20
|
+
* // in case the pressed keys need to be cleared you can use the manager to do so:
|
|
21
|
+
* manager.clear()
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class Emulator {
|
|
25
|
+
validKeys?: Keys
|
|
26
|
+
|
|
27
|
+
constructor(keys?: Keys) {
|
|
28
|
+
this.validKeys = keys
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
listeners: {
|
|
32
|
+
keydown: AnyFunction[]
|
|
33
|
+
keyup: AnyFunction[]
|
|
34
|
+
wheel: AnyFunction[]
|
|
35
|
+
mousedown: AnyFunction[]
|
|
36
|
+
mouseup: AnyFunction[]
|
|
37
|
+
mouseenter: AnyFunction[]
|
|
38
|
+
} = {
|
|
39
|
+
keydown: [],
|
|
40
|
+
keyup: [],
|
|
41
|
+
wheel: [],
|
|
42
|
+
mousedown: [],
|
|
43
|
+
mouseenter: [],
|
|
44
|
+
mouseup: []
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
initiated: boolean = false
|
|
48
|
+
|
|
49
|
+
addEventListener(type: string, func: AnyFunction): void {
|
|
50
|
+
this.listeners[type as keyof Emulator["listeners"]].push(func)
|
|
51
|
+
this.initiated = true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
removeEventListener(type: string, func: AnyFunction): void {
|
|
55
|
+
const i = this.listeners[type as keyof Emulator["listeners"]].indexOf(func)
|
|
56
|
+
if (i === -1) throw new Error(`Listener ${type} could not be found.`)
|
|
57
|
+
this.listeners[type as keyof Emulator["listeners"]].splice(i, 1)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
mouseenter(modifiers: string[] = []): void {
|
|
61
|
+
const event = new EmulatedEvent("mouseenter", { }, modifiers)
|
|
62
|
+
this._dispatch("mouseenter", event)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* Emulate pressing/releasing keys.
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* // press and release a
|
|
71
|
+
* emulator.fire("KeyA")
|
|
72
|
+
* // hold A down
|
|
73
|
+
* emulator.fire("KeyA+")
|
|
74
|
+
* // release A
|
|
75
|
+
* emulator.fire("KeyA-")
|
|
76
|
+
* // press Ctrl+A
|
|
77
|
+
* emulator.fire("Ctrl+ KeyA Ctrl-")
|
|
78
|
+
*
|
|
79
|
+
* // to truly simulate pressing native modifiers, pass all modifiers pressed as an array
|
|
80
|
+
* emulator.fire("Ctrl+ KeyA Ctrl-", ["ControlLeft"])
|
|
81
|
+
*
|
|
82
|
+
* // emulate a modifier state change out of focus
|
|
83
|
+
* // e.g. user focuses out, holds control+A, and focuses back
|
|
84
|
+
* // only KeyA would fire
|
|
85
|
+
* emulator.fire("KeyA+", ["ControlLeft"])
|
|
86
|
+
* // they release both in focus
|
|
87
|
+
* emulater.fire("KeyA- Ctrl-")
|
|
88
|
+
*
|
|
89
|
+
* // to simulate them releasing out of focus again you will have to add a delay since no events would fire
|
|
90
|
+
* delay(1000)
|
|
91
|
+
*
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* Keys should be a {@link KeyboardEvent.code} (though this is not validated) seperated by one or more whitespace characters*. For buttons `0-5` can be used. For wheel events, you can pass `wheelUp/Down` to set the deltaY respectively which is how the manager gets the direction.
|
|
95
|
+
*
|
|
96
|
+
* `+` and `-` are used to indicate keydown and keyup respectively (except for wheel events*). This can seem confusing but think of the signs as adding/removing from the set of currently held keys. If no `+/-` is given, both are fired.
|
|
97
|
+
*
|
|
98
|
+
* There is no need to handle toggle keys in any special way. You should fire the root code normally (e.g. `emulator.fire("Capslock")` or `emulator.fire("Capslock+ Capslock-")`)
|
|
99
|
+
*
|
|
100
|
+
* \* Multiple whitespace characters have no real meaning, but in tests usually I use them to more easily delimite chords.
|
|
101
|
+
* \*\* Wheel events do not have keyup/keydown so passing `wheelUp+/-` will incorrectly create a keyboard event.
|
|
102
|
+
*
|
|
103
|
+
* Note: While the emulator is aware of correct mouse/wheel names, it does not check key names are valid.
|
|
104
|
+
*/
|
|
105
|
+
fire(str: string, modifiers: string[] = [], validKeys?: Keys): void {
|
|
106
|
+
if (!this.initiated) {
|
|
107
|
+
// eslint-disable-next-line no-console
|
|
108
|
+
console.warn("No manager attached to the emulator.")
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
const keys = str.split(/(\s+)/).filter(part => part.trim() !== "")
|
|
112
|
+
for (const key of keys) {
|
|
113
|
+
if (mouseButtons.includes(key)) {
|
|
114
|
+
this.press("mouse", key, modifiers, validKeys)
|
|
115
|
+
this.release("mouse", key, modifiers, validKeys)
|
|
116
|
+
} else if (mouseButtonsDown.includes(key)) {
|
|
117
|
+
this.press("mouse", key[0], modifiers, validKeys)
|
|
118
|
+
} else if (mouseButtonsUp.includes(key)) {
|
|
119
|
+
this.release("mouse", key[0], modifiers, validKeys)
|
|
120
|
+
} else if (wheelKeys.includes(key)) {
|
|
121
|
+
this.press("wheel", key, modifiers, validKeys)
|
|
122
|
+
} else if (key.endsWith("+")) {
|
|
123
|
+
this.press("key", key.slice(0, key.length - 1), modifiers, validKeys)
|
|
124
|
+
} else if (key.endsWith("-")) {
|
|
125
|
+
this.release("key", key.slice(0, key.length - 1), modifiers, validKeys)
|
|
126
|
+
} else {
|
|
127
|
+
this.press("key", key, modifiers, validKeys)
|
|
128
|
+
this.release("key", key, modifiers, validKeys)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
press(type: "mouse" | "wheel" | "key", key: string, modifiers: string[] = [], validKeys?: Keys): void {
|
|
134
|
+
this._checkIsValidKey(key, validKeys)
|
|
135
|
+
switch (type) {
|
|
136
|
+
case "mouse": {
|
|
137
|
+
const event = new EmulatedEvent("mousedown", { button: Number.parseInt(key, 10) }, modifiers)
|
|
138
|
+
this._dispatch("mousedown", event)
|
|
139
|
+
} break
|
|
140
|
+
case "wheel": {
|
|
141
|
+
const event = new EmulatedEvent("wheel", { deltaY: key === "wheelDown" ? 1 : 0 }, modifiers)
|
|
142
|
+
this._dispatch("wheel", event)
|
|
143
|
+
} break
|
|
144
|
+
case "key": {
|
|
145
|
+
const event = new EmulatedEvent("keydown", { code: key }, modifiers)
|
|
146
|
+
this._dispatch("keydown", event)
|
|
147
|
+
} break
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
release(type: "mouse" | "key", key: string, modifiers: string[] = [], validKeys?: Keys): void {
|
|
152
|
+
this._checkIsValidKey(key, validKeys)
|
|
153
|
+
switch (type) {
|
|
154
|
+
case "mouse": {
|
|
155
|
+
const event = new EmulatedEvent("mouseup", { button: Number.parseInt(key, 10) }, modifiers)
|
|
156
|
+
this._dispatch("mouseup", event)
|
|
157
|
+
} break
|
|
158
|
+
case "key": {
|
|
159
|
+
const event = new EmulatedEvent("keyup", { code: key }, modifiers)
|
|
160
|
+
this._dispatch("keyup", event)
|
|
161
|
+
} break
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private _checkIsValidKey(key: string, validKeys?: Keys): void {
|
|
166
|
+
const valid = validKeys ?? this.validKeys
|
|
167
|
+
|
|
168
|
+
if (valid) {
|
|
169
|
+
const match = Object.values(valid.entries).find(k => k.id === key
|
|
170
|
+
|| k.toggleOnId === key
|
|
171
|
+
|| k.toggleOffId === key
|
|
172
|
+
|| k.variants?.includes(key))
|
|
173
|
+
if (match === undefined) {
|
|
174
|
+
throw new Error(`Emulator was asked to fire key not in valid keys array. ${key}`)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private _dispatch<T extends keyof Emulator["listeners"]>(type: T, event: EmulatedEvent<T>): void {
|
|
180
|
+
for (const listener of this.listeners[type]) {
|
|
181
|
+
listener(event)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|