Skip to content

Commit 941a5b4

Browse files
committed
refactor(core): separate runtime constants from type definitions
1 parent 5671529 commit 941a5b4

32 files changed

Lines changed: 306 additions & 326 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const BUTTON_MAP = {
2+
A: 0,
3+
B: 1,
4+
X: 2,
5+
Y: 3,
6+
LB: 4,
7+
RB: 5,
8+
LT: 6,
9+
RT: 7,
10+
Select: 8,
11+
Start: 9,
12+
L3: 10,
13+
R3: 11,
14+
Up: 12,
15+
Down: 13,
16+
Left: 14,
17+
Right: 15,
18+
} as const;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Core entity types supported by the library.
3+
*/
4+
export const CMP_TYPES = {
5+
// --- Zones ---
6+
/** Area responsible for capturing touches and spawning dynamic widgets */
7+
INPUT_ZONE: 'input-zone',
8+
/** Area responsible for receiving signals and simulating DOM events */
9+
TARGET_ZONE: 'target-zone',
10+
11+
// --- Widgets ---
12+
BUTTON: 'button',
13+
/** Simulates a physical keyboard key press */
14+
KEYBOARD_BUTTON: 'keyboard-button',
15+
/** Simulates a mouse button click/hold */
16+
MOUSE_BUTTON: 'mouse-button',
17+
/** A joystick that outputs 360-degree or locked direction vectors */
18+
JOYSTICK: 'joystick',
19+
/** Classic 4/8-way directional pad */
20+
D_PAD: 'd-pad',
21+
/** Trackpad-style relative movement area */
22+
TRACKPAD: 'trackpad',
23+
24+
// --- Virtual Helpers ---
25+
/** Logic for the on-screen visual cursor */
26+
VIRTUAL_CURSOR: 'virtual-cursor',
27+
/** The top-level managed container */
28+
ROOT_LAYER: 'root-layer',
29+
} as const;
30+
31+
/**
32+
* Standardized input action types for the signal protocol.
33+
*/
34+
export const ACTION_TYPES = {
35+
KEYDOWN: 'keydown',
36+
KEYUP: 'keyup',
37+
POINTER: 'pointer',
38+
POINTERMOVE: 'pointermove',
39+
POINTERDOWN: 'pointerdown',
40+
POINTERUP: 'pointerup',
41+
MOUSE: 'mouse',
42+
MOUSEMOVE: 'mousemove',
43+
MOUSEDOWN: 'mousedown',
44+
MOUSEUP: 'mouseup',
45+
CLICK: 'click',
46+
} as const;
47+
48+
/**
49+
* Supported CSS units for layout calculation.
50+
* Using a constant array for runtime validation.
51+
*/
52+
export const VALID_UNITS = ['px', '%', 'vh', 'vw', 'vmin', 'vmax', 'rem', 'em'] as const;
53+
54+
/**
55+
* Anchor position used to determine the alignment of an element relative to its coordinates.
56+
*/
57+
export const STANDARD_ANCHORS = [
58+
'top-left',
59+
'top-center',
60+
'top-right',
61+
'center-left',
62+
'center',
63+
'center-right',
64+
'bottom-left',
65+
'bottom-center',
66+
'bottom-right',
67+
] as const;
68+
69+
/**
70+
* Cross-framework context keys for dependency injection (e.g., Provide/Inject).
71+
*/
72+
export const CONTEXT = {
73+
/** The key used to propagate Parent IDs through the component tree */
74+
PARENT_ID_KEY: 'omnipad-parent-id-link',
75+
} as const;
76+
77+
export * from './gamepad';
78+
export * from './keys';
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
* Standard key mapping table optimized for Ruffle/Flash environments.
3+
* Categorized and ordered by keyCode in ascending order.
4+
*/
5+
export const STANDARD_KEYS = {
6+
// --- System Controls (8-27) ---
7+
Backspace: { type: 'keyboard', key: 'Backspace', code: 'Backspace', keyCode: 8 },
8+
Tab: { type: 'keyboard', key: 'Tab', code: 'Tab', keyCode: 9 },
9+
Enter: { type: 'keyboard', key: 'Enter', code: 'Enter', keyCode: 13 },
10+
ShiftLeft: { type: 'keyboard', key: 'Shift', code: 'ShiftLeft', keyCode: 16 },
11+
ControlLeft: { type: 'keyboard', key: 'Control', code: 'ControlLeft', keyCode: 17 },
12+
AltLeft: { type: 'keyboard', key: 'Alt', code: 'AltLeft', keyCode: 18 },
13+
Pause: { type: 'keyboard', key: 'Pause', code: 'Pause', keyCode: 19 },
14+
CapsLock: { type: 'keyboard', key: 'CapsLock', code: 'CapsLock', keyCode: 20 },
15+
Escape: { type: 'keyboard', key: 'Escape', code: 'Escape', keyCode: 27 },
16+
17+
// --- Navigation & Editing (32-46) ---
18+
Space: { type: 'keyboard', key: ' ', code: 'Space', keyCode: 32 },
19+
PageUp: { type: 'keyboard', key: 'PageUp', code: 'PageUp', keyCode: 33 },
20+
PageDown: { type: 'keyboard', key: 'PageDown', code: 'PageDown', keyCode: 34 },
21+
End: { type: 'keyboard', key: 'End', code: 'End', keyCode: 35 },
22+
Home: { type: 'keyboard', key: 'Home', code: 'Home', keyCode: 36 },
23+
ArrowLeft: { type: 'keyboard', key: 'ArrowLeft', code: 'ArrowLeft', keyCode: 37 },
24+
ArrowUp: { type: 'keyboard', key: 'ArrowUp', code: 'ArrowUp', keyCode: 38 },
25+
ArrowRight: { type: 'keyboard', key: 'ArrowRight', code: 'ArrowRight', keyCode: 39 },
26+
ArrowDown: { type: 'keyboard', key: 'ArrowDown', code: 'ArrowDown', keyCode: 40 },
27+
PrintScreen: { type: 'keyboard', key: 'PrintScreen', code: 'PrintScreen', keyCode: 44 },
28+
Insert: { type: 'keyboard', key: 'Insert', code: 'Insert', keyCode: 45 },
29+
Delete: { type: 'keyboard', key: 'Delete', code: 'Delete', keyCode: 46 },
30+
31+
// --- Digit Keys 0-9 (48-57) ---
32+
Digit0: { type: 'keyboard', key: '0', code: 'Digit0', keyCode: 48 },
33+
Digit1: { type: 'keyboard', key: '1', code: 'Digit1', keyCode: 49 },
34+
Digit2: { type: 'keyboard', key: '2', code: 'Digit2', keyCode: 50 },
35+
Digit3: { type: 'keyboard', key: '3', code: 'Digit3', keyCode: 51 },
36+
Digit4: { type: 'keyboard', key: '4', code: 'Digit4', keyCode: 52 },
37+
Digit5: { type: 'keyboard', key: '5', code: 'Digit5', keyCode: 53 },
38+
Digit6: { type: 'keyboard', key: '6', code: 'Digit6', keyCode: 54 },
39+
Digit7: { type: 'keyboard', key: '7', code: 'Digit7', keyCode: 55 },
40+
Digit8: { type: 'keyboard', key: '8', code: 'Digit8', keyCode: 56 },
41+
Digit9: { type: 'keyboard', key: '9', code: 'Digit9', keyCode: 57 },
42+
43+
// --- Alpha Keys A-Z (65-90) ---
44+
KeyA: { type: 'keyboard', key: 'a', code: 'KeyA', keyCode: 65 },
45+
KeyB: { type: 'keyboard', key: 'b', code: 'KeyB', keyCode: 66 },
46+
KeyC: { type: 'keyboard', key: 'c', code: 'KeyC', keyCode: 67 },
47+
KeyD: { type: 'keyboard', key: 'd', code: 'KeyD', keyCode: 68 },
48+
KeyE: { type: 'keyboard', key: 'e', code: 'KeyE', keyCode: 69 },
49+
KeyF: { type: 'keyboard', key: 'f', code: 'KeyF', keyCode: 70 },
50+
KeyG: { type: 'keyboard', key: 'g', code: 'KeyG', keyCode: 71 },
51+
KeyH: { type: 'keyboard', key: 'h', code: 'KeyH', keyCode: 72 },
52+
KeyI: { type: 'keyboard', key: 'i', code: 'KeyI', keyCode: 73 },
53+
KeyJ: { type: 'keyboard', key: 'j', code: 'KeyJ', keyCode: 74 },
54+
KeyK: { type: 'keyboard', key: 'k', code: 'KeyK', keyCode: 75 },
55+
KeyL: { type: 'keyboard', key: 'l', code: 'KeyL', keyCode: 76 },
56+
KeyM: { type: 'keyboard', key: 'm', code: 'KeyM', keyCode: 77 },
57+
KeyN: { type: 'keyboard', key: 'n', code: 'KeyN', keyCode: 78 },
58+
KeyO: { type: 'keyboard', key: 'o', code: 'KeyO', keyCode: 79 },
59+
KeyP: { type: 'keyboard', key: 'p', code: 'KeyP', keyCode: 80 },
60+
KeyQ: { type: 'keyboard', key: 'q', code: 'KeyQ', keyCode: 81 },
61+
KeyR: { type: 'keyboard', key: 'r', code: 'KeyR', keyCode: 82 },
62+
KeyS: { type: 'keyboard', key: 's', code: 'KeyS', keyCode: 83 },
63+
KeyT: { type: 'keyboard', key: 't', code: 'KeyT', keyCode: 84 },
64+
KeyU: { type: 'keyboard', key: 'u', code: 'KeyU', keyCode: 85 },
65+
KeyV: { type: 'keyboard', key: 'v', code: 'KeyV', keyCode: 86 },
66+
KeyW: { type: 'keyboard', key: 'w', code: 'KeyW', keyCode: 87 },
67+
KeyX: { type: 'keyboard', key: 'x', code: 'KeyX', keyCode: 88 },
68+
KeyY: { type: 'keyboard', key: 'y', code: 'KeyY', keyCode: 89 },
69+
KeyZ: { type: 'keyboard', key: 'z', code: 'KeyZ', keyCode: 90 },
70+
71+
// --- Meta & Menu (91-93) ---
72+
MetaLeft: { type: 'keyboard', key: 'Meta', code: 'MetaLeft', keyCode: 91 },
73+
ContextMenu: { type: 'keyboard', key: 'ContextMenu', code: 'ContextMenu', keyCode: 93 },
74+
75+
// --- Numpad Digits (96-105) ---
76+
Numpad0: { type: 'keyboard', key: '0', code: 'Numpad0', keyCode: 96 },
77+
Numpad1: { type: 'keyboard', key: '1', code: 'Numpad1', keyCode: 97 },
78+
Numpad2: { type: 'keyboard', key: '2', code: 'Numpad2', keyCode: 98 },
79+
Numpad3: { type: 'keyboard', key: '3', code: 'Numpad3', keyCode: 99 },
80+
Numpad4: { type: 'keyboard', key: '4', code: 'Numpad4', keyCode: 100 },
81+
Numpad5: { type: 'keyboard', key: '5', code: 'Numpad5', keyCode: 101 },
82+
Numpad6: { type: 'keyboard', key: '6', code: 'Numpad6', keyCode: 102 },
83+
Numpad7: { type: 'keyboard', key: '7', code: 'Numpad7', keyCode: 103 },
84+
Numpad8: { type: 'keyboard', key: '8', code: 'Numpad8', keyCode: 104 },
85+
Numpad9: { type: 'keyboard', key: '9', code: 'Numpad9', keyCode: 105 },
86+
87+
// --- Numpad Symbols (106-111) ---
88+
NumpadMultiply: { type: 'keyboard', key: '*', code: 'NumpadMultiply', keyCode: 106 },
89+
NumpadAdd: { type: 'keyboard', key: '+', code: 'NumpadAdd', keyCode: 107 },
90+
NumpadSubtract: { type: 'keyboard', key: '-', code: 'NumpadSubtract', keyCode: 109 },
91+
NumpadDecimal: { type: 'keyboard', key: '.', code: 'NumpadDecimal', keyCode: 110 },
92+
NumpadDivide: { type: 'keyboard', key: '/', code: 'NumpadDivide', keyCode: 111 },
93+
94+
// --- Function Keys (112-123) ---
95+
F1: { type: 'keyboard', key: 'F1', code: 'F1', keyCode: 112 },
96+
F2: { type: 'keyboard', key: 'F2', code: 'F2', keyCode: 113 },
97+
F3: { type: 'keyboard', key: 'F3', code: 'F3', keyCode: 114 },
98+
F4: { type: 'keyboard', key: 'F4', code: 'F4', keyCode: 115 },
99+
F5: { type: 'keyboard', key: 'F5', code: 'F5', keyCode: 116 },
100+
F6: { type: 'keyboard', key: 'F6', code: 'F6', keyCode: 117 },
101+
F7: { type: 'keyboard', key: 'F7', code: 'F7', keyCode: 118 },
102+
F8: { type: 'keyboard', key: 'F8', code: 'F8', keyCode: 119 },
103+
F9: { type: 'keyboard', key: 'F9', code: 'F9', keyCode: 120 },
104+
F10: { type: 'keyboard', key: 'F10', code: 'F10', keyCode: 121 },
105+
F11: { type: 'keyboard', key: 'F11', code: 'F11', keyCode: 122 },
106+
F12: { type: 'keyboard', key: 'F12', code: 'F12', keyCode: 123 },
107+
108+
// --- State Locks (144-145) ---
109+
NumLock: { type: 'keyboard', key: 'NumLock', code: 'NumLock', keyCode: 144 },
110+
ScrollLock: { type: 'keyboard', key: 'ScrollLock', code: 'ScrollLock', keyCode: 145 },
111+
112+
// --- Punctuation (186-222) ---
113+
Semicolon: { type: 'keyboard', key: ';', code: 'Semicolon', keyCode: 186 },
114+
Equal: { type: 'keyboard', key: '=', code: 'Equal', keyCode: 187 },
115+
Comma: { type: 'keyboard', key: ',', code: 'Comma', keyCode: 188 },
116+
Minus: { type: 'keyboard', key: '-', code: 'Minus', keyCode: 189 },
117+
Period: { type: 'keyboard', key: '.', code: 'Period', keyCode: 190 },
118+
Slash: { type: 'keyboard', key: '/', code: 'Slash', keyCode: 191 },
119+
Backquote: { type: 'keyboard', key: '`', code: 'Backquote', keyCode: 192 },
120+
BracketLeft: { type: 'keyboard', key: '[', code: 'BracketLeft', keyCode: 219 },
121+
Backslash: { type: 'keyboard', key: '\\', code: 'Backslash', keyCode: 220 },
122+
BracketRight: { type: 'keyboard', key: ']', code: 'BracketRight', keyCode: 221 },
123+
Quote: { type: 'keyboard', key: "'", code: 'Quote', keyCode: 222 },
124+
125+
// --- Mouse ---
126+
Mouse: { type: 'mouse', button: 0 },
127+
MouseLeft: { type: 'mouse', button: 0 },
128+
MouseMiddle: { type: 'mouse', button: 1 },
129+
MouseRight: { type: 'mouse', button: 2 },
130+
} as const;

packages/core/src/entities/ButtonCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { ButtonState } from '../types/state';
33
import { IPointerHandler, IProgrammatic } from '../types/traits';
44
import { BaseEntity } from './BaseEntity';
55
import { ActionEmitter } from '../runtime/action';
6-
import { AbstractPointerEvent, CMP_TYPES, EntityType } from '../types';
6+
import { AbstractPointerEvent, EntityType } from '../types';
7+
import { CMP_TYPES } from '../constants';
78

89
const INITIAL_STATE: ButtonState = {
910
isActive: false,

packages/core/src/entities/DPadCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { BaseEntity } from './BaseEntity';
22
import { IPointerHandler, IProgrammatic } from '../types/traits';
33
import { DPadConfig } from '../types/configs';
44
import { DPadState } from '../types/state';
5-
import { AbstractPointerEvent, CMP_TYPES, EntityType } from '../types';
5+
import { AbstractPointerEvent, EntityType } from '../types';
66
import { ActionEmitter } from '../runtime/action';
77
import { clamp, isVec2Equal, lerp } from '../utils/math';
8+
import { CMP_TYPES } from '../constants';
89

910
const INITIAL_STATE: DPadState = {
1011
isActive: false,

packages/core/src/entities/InputZoneCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { BaseEntity } from './BaseEntity';
22
import { IDependencyBindable, IPointerHandler } from '../types/traits';
33
import { InputZoneConfig } from '../types/configs';
44
import { InputZoneState } from '../types/state';
5-
import { Vec2, CMP_TYPES, AnyFunction, AbstractPointerEvent, EntityType } from '../types';
5+
import { Vec2, AnyFunction, AbstractPointerEvent, EntityType } from '../types';
66
import { pxToPercent } from '../utils/math';
7+
import { CMP_TYPES } from '../constants';
78

89
interface InputZoneDelegates {
910
dynamicWidgetPointerDown: (e: AbstractPointerEvent) => void;

packages/core/src/entities/JoystickCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { BaseEntity } from './BaseEntity';
22
import { IPointerHandler, IProgrammatic } from '../types/traits';
33
import { JoystickConfig } from '../types/configs';
44
import { JoystickState } from '../types/state';
5-
import { AbstractPointerEvent, CMP_TYPES, EntityType } from '../types';
5+
import { AbstractPointerEvent, EntityType } from '../types';
66
import { ActionEmitter } from '../runtime/action';
77
import { GestureRecognizer } from '../runtime/gesture';
88
import { createTicker } from '../runtime/performance';
99
import { clamp, applyRadialDeadzone, isVec2Equal, lerp } from '../utils/math';
10+
import { CMP_TYPES } from '../constants';
1011

1112
const INITIAL_STATE: JoystickState = {
1213
isActive: false,

packages/core/src/entities/RootLayerCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BaseEntity } from './BaseEntity';
22
import { BaseConfig } from '../types/configs';
3-
import { LayerState, CMP_TYPES, EntityType } from '../types';
3+
import { LayerState, EntityType } from '../types';
4+
import { CMP_TYPES } from '../constants';
45

56
/**
67
* Initial state for the Root Layer.

packages/core/src/entities/TargetZoneCore.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
import {
2-
ACTION_TYPES,
3-
InputActionSignal,
4-
Vec2,
5-
CMP_TYPES,
6-
AnyFunction,
7-
AbstractPointerEvent,
8-
EntityType,
9-
} from '../types';
1+
import { InputActionSignal, Vec2, AnyFunction, AbstractPointerEvent, EntityType } from '../types';
102
import { TargetZoneConfig } from '../types/configs';
113
import { CursorState } from '../types/state';
124
import { IDependencyBindable, IPointerHandler, ISignalReceiver } from '../types/traits';
135
import { clamp, isVec2Equal, percentToPx, pxToPercent } from '../utils/math';
146
import { createRafThrottler } from '../runtime/performance';
157
import { BaseEntity } from './BaseEntity';
8+
import { ACTION_TYPES, CMP_TYPES } from '../constants';
169

1710
/**
1811
* Interface for delegating DOM operations within a target zone.

packages/core/src/entities/TrackpadCore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { BaseEntity } from './BaseEntity';
22
import { IPointerHandler } from '../types/traits';
33
import { TrackpadConfig } from '../types/configs';
44
import { TrackpadState } from '../types/state';
5-
import { AbstractPointerEvent, CMP_TYPES, EntityType } from '../types';
5+
import { AbstractPointerEvent, EntityType } from '../types';
66
import { GestureRecognizer } from '../runtime/gesture';
77
import { isVec2Equal } from '../utils/math';
88
import { ActionEmitter } from '../runtime/action';
9+
import { CMP_TYPES } from '../constants';
910

1011
/**
1112
* Initial state for the trackpad.

0 commit comments

Comments
 (0)