@woven-canvas/core 0.1.0 → 0.1.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/build/_tsup-dts-rollup.d.cts +5 -0
- package/build/_tsup-dts-rollup.d.ts +5 -0
- package/build/index.cjs +30 -21
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +29 -21
- package/build/index.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1045,6 +1045,7 @@ declare class KeyboardDef extends CanvasSingletonDef<typeof KeyboardSchema> {
|
|
|
1045
1045
|
isKeyDown(ctx: Context, key: number): boolean;
|
|
1046
1046
|
isKeyDownTrigger(ctx: Context, key: number): boolean;
|
|
1047
1047
|
isKeyUpTrigger(ctx: Context, key: number): boolean;
|
|
1048
|
+
reset(ctx: Context): void;
|
|
1048
1049
|
}
|
|
1049
1050
|
|
|
1050
1051
|
declare interface KeyboardInput {
|
|
@@ -1293,6 +1294,10 @@ export { removeComponent }
|
|
|
1293
1294
|
|
|
1294
1295
|
export { removeEntity }
|
|
1295
1296
|
|
|
1297
|
+
declare const ResetKeyboard: CommandDef<void>;
|
|
1298
|
+
export { ResetKeyboard }
|
|
1299
|
+
export { ResetKeyboard as ResetKeyboard_alias_1 }
|
|
1300
|
+
|
|
1296
1301
|
declare type ResizeMode = 'scale' | 'text' | 'free' | 'groupOnly';
|
|
1297
1302
|
export { ResizeMode }
|
|
1298
1303
|
export { ResizeMode as ResizeMode_alias_1 }
|
|
@@ -1045,6 +1045,7 @@ declare class KeyboardDef extends CanvasSingletonDef<typeof KeyboardSchema> {
|
|
|
1045
1045
|
isKeyDown(ctx: Context, key: number): boolean;
|
|
1046
1046
|
isKeyDownTrigger(ctx: Context, key: number): boolean;
|
|
1047
1047
|
isKeyUpTrigger(ctx: Context, key: number): boolean;
|
|
1048
|
+
reset(ctx: Context): void;
|
|
1048
1049
|
}
|
|
1049
1050
|
|
|
1050
1051
|
declare interface KeyboardInput {
|
|
@@ -1293,6 +1294,10 @@ export { removeComponent }
|
|
|
1293
1294
|
|
|
1294
1295
|
export { removeEntity }
|
|
1295
1296
|
|
|
1297
|
+
declare const ResetKeyboard: CommandDef<void>;
|
|
1298
|
+
export { ResetKeyboard }
|
|
1299
|
+
export { ResetKeyboard as ResetKeyboard_alias_1 }
|
|
1300
|
+
|
|
1296
1301
|
declare type ResizeMode = 'scale' | 'text' | 'free' | 'groupOnly';
|
|
1297
1302
|
export { ResizeMode }
|
|
1298
1303
|
export { ResizeMode as ResizeMode_alias_1 }
|
package/build/index.cjs
CHANGED
|
@@ -63,6 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
PointerType: () => PointerType,
|
|
64
64
|
RankBounds: () => RankBounds,
|
|
65
65
|
Redo: () => Redo,
|
|
66
|
+
ResetKeyboard: () => ResetKeyboard,
|
|
66
67
|
SINGLETON_ENTITY_ID: () => import_core49.SINGLETON_ENTITY_ID,
|
|
67
68
|
STRATUM_ORDER: () => STRATUM_ORDER,
|
|
68
69
|
ScaleWithZoom: () => ScaleWithZoom,
|
|
@@ -1883,6 +1884,19 @@ var KeyboardDef = class extends import_canvas_store25.CanvasSingletonDef {
|
|
|
1883
1884
|
isKeyUpTrigger(ctx, key) {
|
|
1884
1885
|
return getBit(this.read(ctx).keysUpTrigger, key);
|
|
1885
1886
|
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Reset all keyboard state.
|
|
1889
|
+
* Clears all key states and modifier flags.
|
|
1890
|
+
*/
|
|
1891
|
+
reset(ctx) {
|
|
1892
|
+
const keyboard = this.write(ctx);
|
|
1893
|
+
clearBits(keyboard.keysDown);
|
|
1894
|
+
clearBits(keyboard.keysDownTrigger);
|
|
1895
|
+
clearBits(keyboard.keysUpTrigger);
|
|
1896
|
+
keyboard.shiftDown = false;
|
|
1897
|
+
keyboard.altDown = false;
|
|
1898
|
+
keyboard.modDown = false;
|
|
1899
|
+
}
|
|
1886
1900
|
};
|
|
1887
1901
|
var Keyboard = new KeyboardDef();
|
|
1888
1902
|
function setBit(buffer, bitIndex, value) {
|
|
@@ -2304,6 +2318,7 @@ function on(ctx, def, handler) {
|
|
|
2304
2318
|
}
|
|
2305
2319
|
var Undo = defineCommand("undo");
|
|
2306
2320
|
var Redo = defineCommand("redo");
|
|
2321
|
+
var ResetKeyboard = defineCommand("reset-keyboard");
|
|
2307
2322
|
|
|
2308
2323
|
// src/EditorSystem.ts
|
|
2309
2324
|
var import_core28 = require("@woven-ecs/core");
|
|
@@ -2368,11 +2383,7 @@ function attachKeyboardListeners(domElement) {
|
|
|
2368
2383
|
},
|
|
2369
2384
|
onBlur: () => {
|
|
2370
2385
|
state.eventsBuffer.push({ type: "blur" });
|
|
2371
|
-
}
|
|
2372
|
-
// Reusable buffers - allocated once per instance
|
|
2373
|
-
keysDown: new Uint8Array(32),
|
|
2374
|
-
keysDownTrigger: new Uint8Array(32),
|
|
2375
|
-
keysUpTrigger: new Uint8Array(32)
|
|
2386
|
+
}
|
|
2376
2387
|
};
|
|
2377
2388
|
instanceState.set(domElement, state);
|
|
2378
2389
|
domElement.addEventListener("keydown", state.onKeyDown);
|
|
@@ -2391,19 +2402,19 @@ var keyboardSystem = defineEditorSystem({ phase: "input" }, (ctx) => {
|
|
|
2391
2402
|
const resources = (0, import_core30.getResources)(ctx);
|
|
2392
2403
|
const state = instanceState.get(resources.domElement);
|
|
2393
2404
|
if (!state) return;
|
|
2405
|
+
on(ctx, ResetKeyboard, () => {
|
|
2406
|
+
Keyboard.reset(ctx);
|
|
2407
|
+
});
|
|
2394
2408
|
const hasEvents = state.eventsBuffer.length > 0;
|
|
2395
|
-
const
|
|
2409
|
+
const keyboardRead = Keyboard.read(ctx);
|
|
2410
|
+
const triggersNeedClearing = !isZeroed(keyboardRead.keysDownTrigger) || !isZeroed(keyboardRead.keysUpTrigger);
|
|
2396
2411
|
if (!hasEvents && !triggersNeedClearing) return;
|
|
2397
2412
|
const keyboard = Keyboard.write(ctx);
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
const keysUpTrigger = state.keysUpTrigger;
|
|
2401
|
-
keysDownTrigger.fill(0);
|
|
2402
|
-
keysUpTrigger.fill(0);
|
|
2403
|
-
keysDown.set(keyboard.keysDown);
|
|
2413
|
+
clearBits(keyboard.keysDownTrigger);
|
|
2414
|
+
clearBits(keyboard.keysUpTrigger);
|
|
2404
2415
|
for (const event of state.eventsBuffer) {
|
|
2405
2416
|
if (event.type === "blur") {
|
|
2406
|
-
keysDown
|
|
2417
|
+
clearBits(keyboard.keysDown);
|
|
2407
2418
|
keyboard.shiftDown = false;
|
|
2408
2419
|
keyboard.altDown = false;
|
|
2409
2420
|
keyboard.modDown = false;
|
|
@@ -2412,22 +2423,19 @@ var keyboardSystem = defineEditorSystem({ phase: "input" }, (ctx) => {
|
|
|
2412
2423
|
const keyIndex = codeToIndex[event.code];
|
|
2413
2424
|
if (keyIndex === void 0) continue;
|
|
2414
2425
|
if (event.type === "keydown") {
|
|
2415
|
-
const wasDown = getBit2(keysDown, keyIndex);
|
|
2426
|
+
const wasDown = getBit2(keyboard.keysDown, keyIndex);
|
|
2416
2427
|
if (!wasDown) {
|
|
2417
|
-
setBit(keysDownTrigger, keyIndex, true);
|
|
2428
|
+
setBit(keyboard.keysDownTrigger, keyIndex, true);
|
|
2418
2429
|
}
|
|
2419
|
-
setBit(keysDown, keyIndex, true);
|
|
2430
|
+
setBit(keyboard.keysDown, keyIndex, true);
|
|
2420
2431
|
} else if (event.type === "keyup") {
|
|
2421
|
-
setBit(keysDown, keyIndex, false);
|
|
2422
|
-
setBit(keysUpTrigger, keyIndex, true);
|
|
2432
|
+
setBit(keyboard.keysDown, keyIndex, false);
|
|
2433
|
+
setBit(keyboard.keysUpTrigger, keyIndex, true);
|
|
2423
2434
|
}
|
|
2424
2435
|
keyboard.shiftDown = event.shiftKey;
|
|
2425
2436
|
keyboard.altDown = event.altKey;
|
|
2426
2437
|
keyboard.modDown = event.ctrlKey || event.metaKey;
|
|
2427
2438
|
}
|
|
2428
|
-
keyboard.keysDown = keysDown;
|
|
2429
|
-
keyboard.keysDownTrigger = keysDownTrigger;
|
|
2430
|
-
keyboard.keysUpTrigger = keysUpTrigger;
|
|
2431
2439
|
state.eventsBuffer.length = 0;
|
|
2432
2440
|
});
|
|
2433
2441
|
function getBit2(buffer, bitIndex) {
|
|
@@ -4056,6 +4064,7 @@ function clearPointerTrackingState(ctx) {
|
|
|
4056
4064
|
PointerType,
|
|
4057
4065
|
RankBounds,
|
|
4058
4066
|
Redo,
|
|
4067
|
+
ResetKeyboard,
|
|
4059
4068
|
SINGLETON_ENTITY_ID,
|
|
4060
4069
|
STRATUM_ORDER,
|
|
4061
4070
|
ScaleWithZoom,
|