@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,22 @@
|
|
|
1
|
+
import { Ok } from "@alanscodelog/utils/Result";
|
|
2
|
+
import { areValidKeys } from "./areValidKeys.js";
|
|
3
|
+
import { containsPossibleToggleChords } from "./containsPossibleToggleChords.js";
|
|
4
|
+
import { isValidChord } from "./isValidChord.js";
|
|
5
|
+
export function isValidChain(chain, manager) {
|
|
6
|
+
const sorter = manager.options.sorter;
|
|
7
|
+
if (chain.length === 0 || chain.length === 1 && chain[0].length === 0) {
|
|
8
|
+
return Ok(true);
|
|
9
|
+
}
|
|
10
|
+
const resIsValid = areValidKeys(chain, manager);
|
|
11
|
+
if (resIsValid.isError) return resIsValid;
|
|
12
|
+
const val = [];
|
|
13
|
+
for (let i = 0; i < chain.length; i++) {
|
|
14
|
+
const chord = chain[i];
|
|
15
|
+
const res2 = isValidChord(chain, chord, i, manager);
|
|
16
|
+
if (res2.isError) return res2;
|
|
17
|
+
val.push(sorter.sort([...chord], manager.keys));
|
|
18
|
+
}
|
|
19
|
+
const res = containsPossibleToggleChords(chain, manager);
|
|
20
|
+
if (res.isError) return res;
|
|
21
|
+
return Ok(true);
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Result } from "@alanscodelog/utils/Result";
|
|
2
|
+
import { KnownError } from "../helpers/KnownError.js";
|
|
3
|
+
import { type Manager, type PickManager, SHORTCUT_ERROR } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Guards against invalid chords (for various reasons). See the {@link ERROR}.CHORD_W_... errors.
|
|
6
|
+
*
|
|
7
|
+
* Does not check if the keys are valid.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function isValidChord(chain: string[][], chord: string[], i: number, manager: Pick<Manager, "keys"> & PickManager<"options", "stringifier" | "sorter">): Result<true, KnownError<typeof SHORTCUT_ERROR.CHORD_W_DUPLICATE_KEY | typeof SHORTCUT_ERROR.CHORD_W_ONLY_MODIFIERS | typeof SHORTCUT_ERROR.CHORD_W_MULTIPLE_TRIGGER_KEYS | typeof SHORTCUT_ERROR.CHORD_W_MULTIPLE_WHEEL_KEYS>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { crop } from "@alanscodelog/utils/crop";
|
|
2
|
+
import { findDuplicates } from "@alanscodelog/utils/findDuplicates";
|
|
3
|
+
import { indent } from "@alanscodelog/utils/indent";
|
|
4
|
+
import { Err, Ok } from "@alanscodelog/utils/Result";
|
|
5
|
+
import { getKeyFromIdOrVariant } from "../helpers/getKeyFromIdOrVariant.js";
|
|
6
|
+
import { KnownError } from "../helpers/KnownError.js";
|
|
7
|
+
import { SHORTCUT_ERROR } from "../types/index.js";
|
|
8
|
+
import { isTriggerKey } from "../utils/isTriggerKey.js";
|
|
9
|
+
import { isWheelKey } from "../utils/isWheelKey.js";
|
|
10
|
+
export function isValidChord(chain, chord, i, manager) {
|
|
11
|
+
const keys = manager.keys;
|
|
12
|
+
const s = manager.options.stringifier;
|
|
13
|
+
const prettyChord = s.stringify(chord, manager);
|
|
14
|
+
const prettyChain = s.stringify(chain, manager);
|
|
15
|
+
const repeated = findDuplicates(chord, { equals: (id, otherId) => {
|
|
16
|
+
const key = getKeyFromIdOrVariant(id, keys).unwrap()[0];
|
|
17
|
+
const other = getKeyFromIdOrVariant(otherId, keys).unwrap()[0];
|
|
18
|
+
if (key.id === other.id) return true;
|
|
19
|
+
if (key.variants?.includes(other.id) || other.variants?.includes(key.id)) return true;
|
|
20
|
+
if (isWheelKey(key) && isWheelKey(other)) return false;
|
|
21
|
+
return false;
|
|
22
|
+
} });
|
|
23
|
+
if (repeated.length > 0) {
|
|
24
|
+
const prettyRepeated = s.stringifyList("keys", repeated, manager);
|
|
25
|
+
return Err(new KnownError(SHORTCUT_ERROR.CHORD_W_DUPLICATE_KEY, crop`
|
|
26
|
+
Chord "${prettyChord}" in chain "${prettyChain}" contains duplicate or incompatible keys:
|
|
27
|
+
${indent(prettyRepeated, 4)}
|
|
28
|
+
Chords cannot contain duplicate keys. This includes more than one of the same toggle, regardless of the state.
|
|
29
|
+
`, { chord, i, keys: repeated }));
|
|
30
|
+
}
|
|
31
|
+
const onlyModifiers = chord.filter((id) => getKeyFromIdOrVariant(id, keys).unwrap()[0].isModifier);
|
|
32
|
+
const containsOnlyModifiers = onlyModifiers.length === chord.length;
|
|
33
|
+
if (i < chain.length - 1 && containsOnlyModifiers) {
|
|
34
|
+
return Err(new KnownError(SHORTCUT_ERROR.CHORD_W_ONLY_MODIFIERS, crop`
|
|
35
|
+
Chain "${prettyChain}" is impossible.
|
|
36
|
+
Chord #${i + 1} "${prettyChord}" cannot contain only modifiers if it is followed by another chord.
|
|
37
|
+
A chord can only consist of only modifiers if it's the last chord in a chain.
|
|
38
|
+
`, { chord, i, keys: onlyModifiers }));
|
|
39
|
+
}
|
|
40
|
+
const wheelKeys = chord.filter((id) => isWheelKey(getKeyFromIdOrVariant(id, keys).unwrap()[0]));
|
|
41
|
+
const prettyWheelKeys = s.stringifyList("keys", wheelKeys, manager);
|
|
42
|
+
if (wheelKeys.length > 1) {
|
|
43
|
+
return Err(new KnownError(SHORTCUT_ERROR.CHORD_W_MULTIPLE_WHEEL_KEYS, crop`
|
|
44
|
+
Chain "${prettyChain}" is impossible.
|
|
45
|
+
Chord #${i + 1} "${prettyChord}" contains multiple wheel keys: ${prettyWheelKeys}
|
|
46
|
+
Chords can only contain one.
|
|
47
|
+
`, { chord, i, keys: wheelKeys }));
|
|
48
|
+
}
|
|
49
|
+
const triggerKeys = chord.filter((id) => isTriggerKey(getKeyFromIdOrVariant(id, keys).unwrap()[0]));
|
|
50
|
+
const prettyTriggerKeys = s.stringifyList("keys", triggerKeys, manager);
|
|
51
|
+
if (triggerKeys.length > 1) {
|
|
52
|
+
return Err(new KnownError(SHORTCUT_ERROR.CHORD_W_MULTIPLE_TRIGGER_KEYS, crop`
|
|
53
|
+
Chain "${prettyChain}" is impossible.
|
|
54
|
+
Chord #${i + 1} "${prettyChord}" contains multiple trigger (non-modifier/non-root toggle) keys: ${prettyTriggerKeys}
|
|
55
|
+
Chords can only contain one.
|
|
56
|
+
`, { chord, i, keys: triggerKeys }));
|
|
57
|
+
}
|
|
58
|
+
return Ok(true);
|
|
59
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Result } from "@alanscodelog/utils/Result";
|
|
2
|
+
import type { Manager, MultipleErrors, PickManager, Shortcut } from "../types/index.js";
|
|
3
|
+
import { SHORTCUT_ERROR } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidCommand(commandName: string | undefined, manager: Pick<Manager, "commands"> & Partial<Pick<Manager, "keys">> & PickManager<"options", "stringifier">,
|
|
8
|
+
/**
|
|
9
|
+
* Shortcut will only be added to error if the manager contains keys.
|
|
10
|
+
* Otherwise it will be ignored.
|
|
11
|
+
*/
|
|
12
|
+
shortcut?: Shortcut): Result<true, MultipleErrors<typeof SHORTCUT_ERROR.UNKNOWN_COMMAND>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { crop } from "@alanscodelog/utils/crop";
|
|
2
|
+
import { indent } from "@alanscodelog/utils/indent";
|
|
3
|
+
import { Err, Ok } from "@alanscodelog/utils/Result";
|
|
4
|
+
import { KnownError } from "../helpers/KnownError.js";
|
|
5
|
+
import { SHORTCUT_ERROR } from "../types/index.js";
|
|
6
|
+
export function isValidCommand(commandName, manager, shortcut) {
|
|
7
|
+
const commands = manager.commands;
|
|
8
|
+
const s = manager.options.stringifier;
|
|
9
|
+
if (commandName === void 0) return Ok(true);
|
|
10
|
+
const command = commands.entries[commandName];
|
|
11
|
+
if (command === void 0) {
|
|
12
|
+
const shortcutString = shortcut && "keys" in manager ? ` in shortcut ${s.stringify(shortcut, manager)}` : "";
|
|
13
|
+
return Err(new KnownError(SHORTCUT_ERROR.UNKNOWN_COMMAND, crop`
|
|
14
|
+
Unknown command: ${commandName}${shortcutString}. Cannot find in:
|
|
15
|
+
|
|
16
|
+
${indent(s.stringifyList("commands", Object.values(commands.entries)), 3)}
|
|
17
|
+
`, { command: commandName, commands, shortcut }));
|
|
18
|
+
}
|
|
19
|
+
return Ok(true);
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isMouseKey } from "../utils/isMouseKey.js";
|
|
2
|
+
import { isWheelKey } from "../utils/isWheelKey.js";
|
|
3
|
+
export function keyOrder(key, dictOrEnum) {
|
|
4
|
+
let type = [
|
|
5
|
+
key.isModifier ? "mod" : "",
|
|
6
|
+
key.isToggle ? "toggle" : "",
|
|
7
|
+
isMouseKey(key) ? "mouse" : "",
|
|
8
|
+
isWheelKey(key) ? "wheel" : ""
|
|
9
|
+
].join("");
|
|
10
|
+
if (type === "") {
|
|
11
|
+
type = "normal";
|
|
12
|
+
}
|
|
13
|
+
return dictOrEnum[type];
|
|
14
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Result } from "@alanscodelog/utils/Result";
|
|
2
|
+
import type { AnyInputEvent, Manager, ManagerSetEntries, MultipleErrors } from "../types/index.js";
|
|
3
|
+
export declare function removeFromChain(manager: Manager, keys: string[], e?: AnyInputEvent): Result<true, MultipleErrors<ManagerSetEntries["state.chain"]["error"]>>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Ok } from "@alanscodelog/utils/Result";
|
|
2
|
+
import { checkTrigger } from "./checkTrigger.js";
|
|
3
|
+
import { checkUntrigger } from "./checkUntrigger.js";
|
|
4
|
+
import { cloneLastChord } from "./cloneLastChord.js";
|
|
5
|
+
import { getPressedNonModifierKeys } from "./getPressedNonModifierKeys.js";
|
|
6
|
+
import { setManagerProp } from "../core/setManagerProp.js";
|
|
7
|
+
import { cloneChain } from "../utils/cloneChain.js";
|
|
8
|
+
export function removeFromChain(manager, keys, e) {
|
|
9
|
+
if (keys.length === 0) return Ok(true);
|
|
10
|
+
if (manager.state.isAwaitingKeyup) {
|
|
11
|
+
checkUntrigger(manager, e);
|
|
12
|
+
if (getPressedNonModifierKeys(manager).length === 0) {
|
|
13
|
+
setManagerProp(manager, "state.isAwaitingKeyup", false);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (manager.state.nextIsChord) return Ok(true);
|
|
17
|
+
const lastChord = cloneLastChord(manager.state.chain) ?? [];
|
|
18
|
+
for (const id of keys) {
|
|
19
|
+
const key = manager.keys.entries[id];
|
|
20
|
+
const i = lastChord.indexOf(key.id);
|
|
21
|
+
if (i > -1) {
|
|
22
|
+
lastChord.splice(i, 1);
|
|
23
|
+
const chain = manager.state.chain;
|
|
24
|
+
const precedingChords = chain.slice(0, chain.length - 1);
|
|
25
|
+
const spreadableLastChord = precedingChords.length === 0 && lastChord.length === 0 ? [] : [lastChord];
|
|
26
|
+
const res = setManagerProp(manager, "state.chain", cloneChain([...precedingChords, ...spreadableLastChord]));
|
|
27
|
+
if (res.isError) return res;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
checkTrigger(manager, e);
|
|
31
|
+
return Ok(true);
|
|
32
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Key, KeySetEntries, Manager } from "../types/index.js";
|
|
2
|
+
export declare function safeSetEmulatedToggleState<THooks extends Manager["hooks"]>(key: Key, value: boolean, manager: KeySetEntries["toggleOnPressed" | "toggleOffPressed"]["manager"] & {
|
|
3
|
+
hooks?: THooks;
|
|
4
|
+
}): import("@alanscodelog/utils").Result<true, import("../helpers/KnownError.ts").KnownError<"CANNOT_SET_WHILE_DISABLED"> | import("../types/manager.ts").CanHookErrors<THooks extends never ? never : THooks, "canSetKeyProp">>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { setKeyProp } from "../core/setKeyProp.js";
|
|
2
|
+
export function safeSetEmulatedToggleState(key, value, manager) {
|
|
3
|
+
const res = setKeyProp(key, "toggleOnPressed", value, manager, { check: "only" });
|
|
4
|
+
if (res.isOk) {
|
|
5
|
+
const res2 = setKeyProp(key, "toggleOffPressed", !value, manager, { check: "only" });
|
|
6
|
+
if (res2.isOk) {
|
|
7
|
+
setKeyProp(key, "toggleOnPressed", value, manager, { check: false });
|
|
8
|
+
setKeyProp(key, "toggleOffPressed", !value, manager, { check: false });
|
|
9
|
+
}
|
|
10
|
+
return res2;
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Result } from "@alanscodelog/utils/Result";
|
|
2
|
+
import type { CanHookErrors, KeySetEntries, Manager, MultipleErrors } from "../types/index.js";
|
|
3
|
+
import { SHORTCUT_ERROR } from "../types/index.js";
|
|
4
|
+
export declare function setKeysState<THooks extends Manager["hooks"]>(keysList: string[], manager: KeySetEntries["pressed" | "toggleOnPressed" | "toggleOffPressed"]["manager"] & {
|
|
5
|
+
hooks?: THooks;
|
|
6
|
+
}, state: boolean, { ignoreToggleType }?: {
|
|
7
|
+
ignoreToggleType?: boolean;
|
|
8
|
+
}): Result<true, MultipleErrors<typeof SHORTCUT_ERROR.CANNOT_SET_WHILE_DISABLED | typeof SHORTCUT_ERROR.INCORRECT_TOGGLE_STATE> | CanHookErrors<THooks extends never ? never : THooks, "canSetKeyProp">>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Err, Ok } from "@alanscodelog/utils/Result";
|
|
2
|
+
import { safeSetEmulatedToggleState } from "./safeSetEmulatedToggleState.js";
|
|
3
|
+
import { setKeyProp } from "../core/setKeyProp.js";
|
|
4
|
+
import { KnownError } from "../helpers/KnownError.js";
|
|
5
|
+
import { SHORTCUT_ERROR } from "../types/index.js";
|
|
6
|
+
export function setKeysState(keysList, manager, state, {
|
|
7
|
+
ignoreToggleType = false
|
|
8
|
+
} = {}) {
|
|
9
|
+
const s = manager.options.stringifier;
|
|
10
|
+
for (const id of keysList) {
|
|
11
|
+
const key = manager.keys.entries[id];
|
|
12
|
+
const isRoot = id === key.id;
|
|
13
|
+
const isOn = id === key.toggleOnId;
|
|
14
|
+
const isOff = id === key.toggleOffId;
|
|
15
|
+
if (isRoot && key.pressed === state || isOn && key.toggleOnPressed === state || isOff && key.toggleOffPressed === state) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const res = setKeyProp(key, "pressed", state, manager);
|
|
19
|
+
if (res.isError) return res;
|
|
20
|
+
if (isRoot && state) {
|
|
21
|
+
if (ignoreToggleType && key.isToggle || key.isToggle === "emulated") {
|
|
22
|
+
if (key.toggleOnPressed && key.toggleOffPressed) {
|
|
23
|
+
return Err(new KnownError(
|
|
24
|
+
SHORTCUT_ERROR.INCORRECT_TOGGLE_STATE,
|
|
25
|
+
`Key ${s.stringify(key, manager)} is a toggle key whose on and off versions are both pressed, which is not a valid state. This should not happen if letting the manager manage the state.`,
|
|
26
|
+
{ key }
|
|
27
|
+
));
|
|
28
|
+
}
|
|
29
|
+
let res2;
|
|
30
|
+
if (!key.toggleOnPressed && !key.toggleOffPressed) {
|
|
31
|
+
res2 = safeSetEmulatedToggleState(key, true, manager);
|
|
32
|
+
} else if (key.toggleOnPressed) {
|
|
33
|
+
res2 = safeSetEmulatedToggleState(key, false, manager);
|
|
34
|
+
} else if (key.toggleOffPressed) {
|
|
35
|
+
res2 = safeSetEmulatedToggleState(key, true, manager);
|
|
36
|
+
}
|
|
37
|
+
if (res2?.isError) return res2;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return Ok(true);
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AnyInputEvent, Manager } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Should be used after we attempt to process the event and set key states.
|
|
4
|
+
*
|
|
5
|
+
* This should cause it to only actually change the state if it was changed off-focus.
|
|
6
|
+
*
|
|
7
|
+
* Technically not neccesary with wheel/mouse events, but ordered similarly for consistency.
|
|
8
|
+
*
|
|
9
|
+
* Modifiers need to be added/removed from the chain on changes, but not toggles.
|
|
10
|
+
*
|
|
11
|
+
* Mutates the passed keys array to remove processed keys.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare function updateNativeKeysState(manager: Manager, e: AnyInputEvent, keyIds?: string[]): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { multisplice } from "@alanscodelog/utils/multisplice";
|
|
2
|
+
import { addToChain } from "./addToChain.js";
|
|
3
|
+
import { getModifierState } from "./getModifierState.js";
|
|
4
|
+
import { removeFromChain } from "./removeFromChain.js";
|
|
5
|
+
import { safeSetEmulatedToggleState } from "./safeSetEmulatedToggleState.js";
|
|
6
|
+
import { setKeyProp } from "../core/setKeyProp.js";
|
|
7
|
+
import { KnownError } from "../helpers/KnownError.js";
|
|
8
|
+
import { SHORTCUT_ERROR } from "../types/index.js";
|
|
9
|
+
export function updateNativeKeysState(manager, e, keyIds = []) {
|
|
10
|
+
const s = manager.options.stringifier;
|
|
11
|
+
for (const id of manager.keys.nativeToggleKeys) {
|
|
12
|
+
const key = manager.keys.entries[id];
|
|
13
|
+
if (key.toggleOnPressed && key.toggleOffPressed) {
|
|
14
|
+
throw new KnownError(SHORTCUT_ERROR.INCORRECT_TOGGLE_STATE, `Key ${s.stringify(key, manager)} is a toggle key whose on and off versions are both pressed, which is not a valid state.`, { key });
|
|
15
|
+
}
|
|
16
|
+
const modifierState = getModifierState(key, e, manager);
|
|
17
|
+
if (modifierState === null) continue;
|
|
18
|
+
if (modifierState) {
|
|
19
|
+
if (!key.toggleOnPressed) {
|
|
20
|
+
safeSetEmulatedToggleState(key, true, manager);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
if (key.toggleOnPressed) {
|
|
24
|
+
safeSetEmulatedToggleState(key, false, manager);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const added = [];
|
|
29
|
+
const removed = [];
|
|
30
|
+
for (const id of manager.keys.nativeModifierKeys) {
|
|
31
|
+
const key = manager.keys.entries[id];
|
|
32
|
+
const modifierState = getModifierState(key, e, manager);
|
|
33
|
+
if (modifierState === null) continue;
|
|
34
|
+
if (modifierState) {
|
|
35
|
+
if (!key.pressed) {
|
|
36
|
+
if (setKeyProp(key, "pressed", true, manager).isOk) {
|
|
37
|
+
added.push(id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if (key.pressed) {
|
|
42
|
+
if (setKeyProp(key, "pressed", false, manager).isOk) {
|
|
43
|
+
removed.push(id);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (added.length > 0) {
|
|
49
|
+
addToChain(manager, added, e);
|
|
50
|
+
const indexes = keyIds.map((key) => added.indexOf(key)).filter((i) => i > -1);
|
|
51
|
+
multisplice(keyIds, indexes);
|
|
52
|
+
}
|
|
53
|
+
if (removed.length > 0) {
|
|
54
|
+
removeFromChain(manager, removed, e);
|
|
55
|
+
const indexes = keyIds.map((key) => added.indexOf(key)).filter((i) => i > -1);
|
|
56
|
+
multisplice(keyIds, indexes);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RawKey } from "../types/keys.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates the given keyboard layout, assiging the correct sizes and positions to keys.
|
|
4
|
+
*
|
|
5
|
+
* It returns an array of raw keys so that if you're extending {@link Key} you can create them with your extended class (you should override {@link Key.create}).
|
|
6
|
+
*
|
|
7
|
+
* Labels are assigned for most keys in english as a fallback, see {@link labelWithEvent}/{@link labelWithKeyboardMap} for proper labeling during runtime.
|
|
8
|
+
*
|
|
9
|
+
* Currently only supports generating the following layouts: `ansi`, `iso`. Technically the layout returned is a variation of these that includes half height 1.3333u (4u / 3 keys) media keys over the numpad.
|
|
10
|
+
*
|
|
11
|
+
* Pull requests for [standard layouts]([https://www.w3.org/TR/uievents-code) welcomed.
|
|
12
|
+
*
|
|
13
|
+
* You can remove sections using the options. Note that this just removes them and does not do any repositioning. If you only remove the numpad, for example, the media keys will still be placed above it. The idea is to easily allow reducing the size of the created layout to then adjust only a few keys to your liking.
|
|
14
|
+
*
|
|
15
|
+
* Also note the `navigation` section is split into two sections with `navigation` only refering to the 6 `Insert`, `Home`, etc. keys, and `arrowKeys` refering to the arrow keys.
|
|
16
|
+
*
|
|
17
|
+
* This also adds the following classes to some keys: `center-label` for media and arrow keys, and `iso-enter` for the iso enter which requires a different approach to styling (see the demo, it's painful).
|
|
18
|
+
*/
|
|
19
|
+
export declare function createLayout<TNumpad extends boolean = true, TMediaKeys extends boolean = true, TFn extends boolean = true, TNavigation extends boolean = true, TArrowKeys extends boolean = true, TNames extends string = "Escape" | (TFn extends true ? "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" : never) | "Backquote" | "Digit1" | "Digit2" | "Digit3" | "Digit4" | "Digit5" | "Digit6" | "Digit7" | "Digit8" | "Digit9" | "Digit0" | "Minus" | "Equal" | "Backspace" | "Tab" | "KeyQ" | "KeyW" | "KeyE" | "KeyR" | "KeyT" | "KeyY" | "KeyU" | "KeyI" | "KeyO" | "KeyP" | "BracketLeft" | "BracketRight" | "Backslash" | "CapsLock" | "KeyA" | "KeyS" | "KeyD" | "KeyF" | "KeyG" | "KeyH" | "KeyJ" | "KeyK" | "KeyL" | "Semicolon" | "Quote" | "Enter" | "VirtualShiftLeft" | "IntlBackslash" | "KeyZ" | "KeyX" | "KeyC" | "KeyV" | "KeyB" | "KeyN" | "KeyM" | "Comma" | "Period" | "Slash" | "VirtualShiftRight" | "VirtualControlLeft" | "VirtualMetaLeft" | "VirtualAltLeft" | "Space" | "VirtualAltRight" | "VirtualMetaRight" | "ContextMenu" | "VirtualControlRight" | "PrintScreen" | "ScrollLock" | "Pause" | (TNavigation extends true ? "Insert" | "Home" | "PageUp" : never) | (TArrowKeys extends true ? "ArrowUp" | "ArrowLeft" | "ArrowDown" | "ArrowRight" : never) | (TMediaKeys extends true ? "AudioVolumeMute" | "AudioVolumeDown" | "AudioVolumeUp" | "MediaTrackPrevious" | "MediaTrackPause" | "MediaTrackNext" : never) | (TNumpad extends true ? ("NumLock" | "NumpadDivide" | "NumpadMultiply" | "NumpadSubtract" | "Numpad7" | "Numpad8" | "Numpad9" | "NumpadAdd" | "Numpad4" | "Numpad5" | "Numpad6" | "Numpad1" | "Numpad2" | "Numpad3" | "NumpadEnter" | "Numpad0" | "NumpadDecimal") : never)>(type?: "ansi" | "iso" | "", { numpad, mediaKeys, fn, navigation, arrowKeys }?: Partial<{
|
|
20
|
+
numpad: TNumpad;
|
|
21
|
+
mediaKeys: TMediaKeys;
|
|
22
|
+
fn: TFn;
|
|
23
|
+
navigation: TNavigation;
|
|
24
|
+
arrowKeys: TArrowKeys;
|
|
25
|
+
}>): RawKey<TNames>[];
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { calculateAndSetPositionAndSize } from "../helpers/calculateAndSetPositionAndWidth.js";
|
|
2
|
+
const start = 0;
|
|
3
|
+
const mediaKey = { height: 0.5, width: 4 / 3 };
|
|
4
|
+
const setY = (yVal) => (val) => {
|
|
5
|
+
val.y = yVal;
|
|
6
|
+
return val;
|
|
7
|
+
};
|
|
8
|
+
export function createLayout(type = "ansi", {
|
|
9
|
+
numpad = true,
|
|
10
|
+
mediaKeys = true,
|
|
11
|
+
fn = true,
|
|
12
|
+
navigation = true,
|
|
13
|
+
arrowKeys = true
|
|
14
|
+
} = {}) {
|
|
15
|
+
const keys = [
|
|
16
|
+
...calculateAndSetPositionAndSize([
|
|
17
|
+
{ id: "Escape", label: "Esc" },
|
|
18
|
+
...fn ? [
|
|
19
|
+
{ id: "F1", x: 2 },
|
|
20
|
+
{ id: "F2" },
|
|
21
|
+
{ id: "F3" },
|
|
22
|
+
{ id: "F4" },
|
|
23
|
+
{ id: "F5", x: 6.5 },
|
|
24
|
+
{ id: "F6" },
|
|
25
|
+
{ id: "F7" },
|
|
26
|
+
{ id: "F8" },
|
|
27
|
+
{ id: "F9", x: 11 },
|
|
28
|
+
{ id: "F10" },
|
|
29
|
+
{ id: "F11" },
|
|
30
|
+
{ id: "F12" }
|
|
31
|
+
] : []
|
|
32
|
+
]).map(setY(start + 0)),
|
|
33
|
+
...calculateAndSetPositionAndSize([
|
|
34
|
+
{ id: "Backquote", label: "`" },
|
|
35
|
+
{ id: "Digit1", label: "1" },
|
|
36
|
+
{ id: "Digit2", label: "2" },
|
|
37
|
+
{ id: "Digit3", label: "3" },
|
|
38
|
+
{ id: "Digit4", label: "4" },
|
|
39
|
+
{ id: "Digit5", label: "5" },
|
|
40
|
+
{ id: "Digit6", label: "6" },
|
|
41
|
+
{ id: "Digit7", label: "7" },
|
|
42
|
+
{ id: "Digit8", label: "8" },
|
|
43
|
+
{ id: "Digit9", label: "9" },
|
|
44
|
+
{ id: "Digit0", label: "0" },
|
|
45
|
+
{ id: "Minus", label: "-" },
|
|
46
|
+
{ id: "Equal", label: "=" },
|
|
47
|
+
{ id: "Backspace", width: 2 }
|
|
48
|
+
]).map(setY(start + 2)),
|
|
49
|
+
...calculateAndSetPositionAndSize([
|
|
50
|
+
{ id: "Tab", width: 1.5 },
|
|
51
|
+
{ id: "KeyQ", label: "q" },
|
|
52
|
+
{ id: "KeyW", label: "w" },
|
|
53
|
+
{ id: "KeyE", label: "e" },
|
|
54
|
+
{ id: "KeyR", label: "r" },
|
|
55
|
+
{ id: "KeyT", label: "t" },
|
|
56
|
+
{ id: "KeyY", label: "y" },
|
|
57
|
+
{ id: "KeyU", label: "u" },
|
|
58
|
+
{ id: "KeyI", label: "i" },
|
|
59
|
+
{ id: "KeyO", label: "o" },
|
|
60
|
+
{ id: "KeyP", label: "p" },
|
|
61
|
+
{ id: "BracketLeft", label: "[" },
|
|
62
|
+
{ id: "BracketRight", label: "]" },
|
|
63
|
+
type === "ansi" ? { id: "Backslash", label: "\\", width: 1.5 } : type === "iso" ? { id: "Enter", width: 1.5, height: 2, classes: ["iso-enter"] } : {}
|
|
64
|
+
]).map(setY(start + 3)),
|
|
65
|
+
...calculateAndSetPositionAndSize([
|
|
66
|
+
{ id: "CapsLock", width: 1.75, isToggle: "native" },
|
|
67
|
+
{ id: "KeyA", label: "a" },
|
|
68
|
+
{ id: "KeyS", label: "s" },
|
|
69
|
+
{ id: "KeyD", label: "d" },
|
|
70
|
+
{ id: "KeyF", label: "f" },
|
|
71
|
+
{ id: "KeyG", label: "g" },
|
|
72
|
+
{ id: "KeyH", label: "h" },
|
|
73
|
+
{ id: "KeyJ", label: "j" },
|
|
74
|
+
{ id: "KeyK", label: "k" },
|
|
75
|
+
{ id: "KeyL", label: "l" },
|
|
76
|
+
{ id: "Semicolon", label: ";" },
|
|
77
|
+
{ id: "Quote", label: "'" },
|
|
78
|
+
type === "ansi" ? { id: "Enter", width: 2.25 } : type === "iso" ? { id: "Backslash", label: "#", width: 1 } : {}
|
|
79
|
+
]).map(setY(start + 4)),
|
|
80
|
+
...calculateAndSetPositionAndSize([
|
|
81
|
+
...type === "ansi" ? [
|
|
82
|
+
{ id: "VirtualShiftLeft", isModifier: "native", label: "Shift", variants: ["ShiftLeft", "ShiftRight", "Shift"], width: 2.25 }
|
|
83
|
+
] : type === "iso" ? [
|
|
84
|
+
{ id: "VirtualShiftLeft", isModifier: "native", label: "Shift", variants: ["ShiftLeft", "ShiftRight", "Shift"], width: 1.25 },
|
|
85
|
+
{ id: "IntlBackslash", label: "\\", width: 1 }
|
|
86
|
+
] : [],
|
|
87
|
+
{ id: "KeyZ", label: "z" },
|
|
88
|
+
{ id: "KeyX", label: "x" },
|
|
89
|
+
{ id: "KeyC", label: "c" },
|
|
90
|
+
{ id: "KeyV", label: "v" },
|
|
91
|
+
{ id: "KeyB", label: "b" },
|
|
92
|
+
{ id: "KeyN", label: "n" },
|
|
93
|
+
{ id: "KeyM", label: "m" },
|
|
94
|
+
{ id: "Comma", label: "," },
|
|
95
|
+
{ id: "Period", label: "." },
|
|
96
|
+
{ id: "Slash", label: "/" },
|
|
97
|
+
{
|
|
98
|
+
id: "VirtualShiftRight",
|
|
99
|
+
isModifier: "native",
|
|
100
|
+
label: "Shift",
|
|
101
|
+
variants: ["ShiftLeft", "ShiftRight", "Shift"],
|
|
102
|
+
width: 2.75
|
|
103
|
+
}
|
|
104
|
+
]).map(setY(start + 5)),
|
|
105
|
+
...calculateAndSetPositionAndSize([
|
|
106
|
+
{
|
|
107
|
+
id: "VirtualControlLeft",
|
|
108
|
+
isModifier: "native",
|
|
109
|
+
label: "Ctrl",
|
|
110
|
+
variants: ["ControlLeft", "ControlRight", "Control", "Ctrl"],
|
|
111
|
+
width: 1.25
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "VirtualMetaLeft",
|
|
115
|
+
isModifier: "native",
|
|
116
|
+
label: "Meta",
|
|
117
|
+
variants: ["MetaLeft", "MetaRight", "Meta"],
|
|
118
|
+
width: 1.25
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "VirtualAltLeft",
|
|
122
|
+
isModifier: "native",
|
|
123
|
+
label: "Alt",
|
|
124
|
+
variants: ["AltLeft", "AltRight", "Alt"],
|
|
125
|
+
width: 1.25
|
|
126
|
+
},
|
|
127
|
+
{ id: "Space", label: "", width: 6.25 },
|
|
128
|
+
{
|
|
129
|
+
id: "VirtualAltRight",
|
|
130
|
+
isModifier: "native",
|
|
131
|
+
label: "Alt",
|
|
132
|
+
variants: ["AltLeft", "AltRight", "Alt"],
|
|
133
|
+
width: 1.25
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: "VirtualMetaRight",
|
|
137
|
+
isModifier: "native",
|
|
138
|
+
label: "Meta",
|
|
139
|
+
variants: ["MetaLeft", "MetaRight", "Meta"],
|
|
140
|
+
width: 1.25
|
|
141
|
+
},
|
|
142
|
+
{ id: "ContextMenu", label: "Menu", width: 1.25 },
|
|
143
|
+
{
|
|
144
|
+
id: "VirtualControlRight",
|
|
145
|
+
isModifier: "native",
|
|
146
|
+
label: "Ctrl",
|
|
147
|
+
variants: ["ControlLeft", "ControlRight", "Control", "Ctrl"],
|
|
148
|
+
width: 1.25
|
|
149
|
+
}
|
|
150
|
+
]).map(setY(start + 6)),
|
|
151
|
+
...calculateAndSetPositionAndSize([
|
|
152
|
+
{ id: "PrintScreen", label: "PrtScn", x: 15.5 },
|
|
153
|
+
{ id: "ScrollLock", label: "Scroll\nLock", isToggle: "native" },
|
|
154
|
+
{ id: "Pause", label: "Pause\nBreak" }
|
|
155
|
+
]).map(setY(start)),
|
|
156
|
+
...navigation ? [
|
|
157
|
+
...calculateAndSetPositionAndSize([
|
|
158
|
+
{ id: "Insert", x: 15.5 },
|
|
159
|
+
{ id: "Home" },
|
|
160
|
+
{ id: "PageUp", label: "Pg\nUp" }
|
|
161
|
+
]).map(setY(start + 2)),
|
|
162
|
+
...calculateAndSetPositionAndSize([
|
|
163
|
+
{ id: "Delete", x: 15.5 },
|
|
164
|
+
{ id: "End" },
|
|
165
|
+
{ id: "PageDown", label: "Pg\nDown" }
|
|
166
|
+
]).map(setY(start + 3))
|
|
167
|
+
] : [],
|
|
168
|
+
...arrowKeys ? [
|
|
169
|
+
...calculateAndSetPositionAndSize([
|
|
170
|
+
{ id: "ArrowUp", label: "\u25B2", x: 16.5, y: start + 5, classes: ["center-label"] }
|
|
171
|
+
]),
|
|
172
|
+
...calculateAndSetPositionAndSize([
|
|
173
|
+
{ id: "ArrowLeft", label: "\u25C4", x: 15.5, classes: ["center-label"] },
|
|
174
|
+
{ id: "ArrowDown", label: "\u25BC", classes: ["center-label"] },
|
|
175
|
+
{ id: "ArrowRight", label: "\u25BA", classes: ["center-label"] }
|
|
176
|
+
]).map(setY(start + 6))
|
|
177
|
+
] : [],
|
|
178
|
+
...mediaKeys ? [
|
|
179
|
+
...calculateAndSetPositionAndSize([
|
|
180
|
+
{ id: "AudioVolumeMute", label: "\u{1F507}", x: 19, ...mediaKey, classes: ["center-label"] },
|
|
181
|
+
{ id: "AudioVolumeDown", label: "\u{1F509}", ...mediaKey, classes: ["center-label"] },
|
|
182
|
+
{ id: "AudioVolumeUp", label: "\u{1F50A}", ...mediaKey, classes: ["center-label"] }
|
|
183
|
+
]).map(setY(start)),
|
|
184
|
+
...calculateAndSetPositionAndSize([
|
|
185
|
+
{ id: "MediaTrackPrevious", label: "\u23EE\uFE0F", x: 19, ...mediaKey, classes: ["center-label"] },
|
|
186
|
+
{ id: "MediaTrackPause", label: "\u23EF\uFE0F", ...mediaKey, classes: ["center-label"] },
|
|
187
|
+
{ id: "MediaTrackNext", label: "\u23ED\uFE0F", ...mediaKey, classes: ["center-label"] }
|
|
188
|
+
]).map(setY(start + 0.5))
|
|
189
|
+
] : [],
|
|
190
|
+
...numpad ? [
|
|
191
|
+
...calculateAndSetPositionAndSize([
|
|
192
|
+
{ id: "NumLock", label: "Num\nLock", x: 19, isToggle: "native" },
|
|
193
|
+
{ id: "NumpadDivide", label: "/" },
|
|
194
|
+
{ id: "NumpadMultiply", label: "*" },
|
|
195
|
+
{ id: "NumpadSubtract", label: "-" }
|
|
196
|
+
]).map(setY(start + 2)),
|
|
197
|
+
...calculateAndSetPositionAndSize([
|
|
198
|
+
{ id: "Numpad7", label: "7", x: 19 },
|
|
199
|
+
{ id: "Numpad8", label: "8" },
|
|
200
|
+
{ id: "Numpad9", label: "9" },
|
|
201
|
+
{ id: "NumpadAdd", label: "+", height: 2 }
|
|
202
|
+
]).map(setY(start + 3)),
|
|
203
|
+
...calculateAndSetPositionAndSize([
|
|
204
|
+
{ id: "Numpad4", label: "4", x: 19 },
|
|
205
|
+
{ id: "Numpad5", label: "5" },
|
|
206
|
+
{ id: "Numpad6", label: "6" }
|
|
207
|
+
]).map(setY(start + 4)),
|
|
208
|
+
...calculateAndSetPositionAndSize([
|
|
209
|
+
{ id: "Numpad1", label: "1", x: 19 },
|
|
210
|
+
{ id: "Numpad2", label: "2" },
|
|
211
|
+
{ id: "Numpad3", label: "3" },
|
|
212
|
+
{ id: "NumpadEnter", label: "+", height: 2 }
|
|
213
|
+
]).map(setY(start + 5)),
|
|
214
|
+
...calculateAndSetPositionAndSize([
|
|
215
|
+
{ id: "Numpad0", label: "0", x: 19, width: 2 },
|
|
216
|
+
{ id: "NumpadDecimal", label: "." }
|
|
217
|
+
]).map(setY(start + 6))
|
|
218
|
+
] : []
|
|
219
|
+
];
|
|
220
|
+
return keys;
|
|
221
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
|
|
3
|
+
declare module "@nuxt/schema" {
|
|
4
|
+
interface PublicRuntimeConfig {
|
|
5
|
+
witchcraftSpellcraft: {};
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface ModuleOptions {
|
|
9
|
+
}
|
|
10
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
11
|
+
|
|
12
|
+
export { _default as default };
|
|
13
|
+
export type { ModuleOptions };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createResolver, defineNuxtModule, addTypeTemplate, addImportsDir } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const dependencies = {
|
|
4
|
+
"@witchcraft/ui": "^0.2.4"};
|
|
5
|
+
const pkg = {
|
|
6
|
+
dependencies: dependencies};
|
|
7
|
+
|
|
8
|
+
const { resolve } = createResolver(import.meta.url);
|
|
9
|
+
const module = defineNuxtModule({
|
|
10
|
+
meta: {
|
|
11
|
+
name: "witchcraftSpellcraft",
|
|
12
|
+
configKey: "witchcraftSpellcraft"
|
|
13
|
+
},
|
|
14
|
+
defaults: {},
|
|
15
|
+
moduleDependencies: {
|
|
16
|
+
"@witchcraft/ui/nuxt": {
|
|
17
|
+
version: pkg.dependencies["@witchcraft/ui"]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
async setup(_options, nuxt) {
|
|
21
|
+
addTypeTemplate({
|
|
22
|
+
filename: "types/witchcraft-spellcraft.d.ts",
|
|
23
|
+
getContents: () => `
|
|
24
|
+
import { type NavigatorWKeyboard } from "./src/types/general.ts"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
declare global {
|
|
28
|
+
interface Navigator {
|
|
29
|
+
keyboard: NavigatorWKeyboard["keyboard"]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`
|
|
33
|
+
});
|
|
34
|
+
addImportsDir(resolve("runtime/composables"));
|
|
35
|
+
addImportsDir(resolve("runtime/utils"));
|
|
36
|
+
nuxt.options.alias["#witchcraft-spellcraft"] = resolve("runtime");
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export { module as default };
|