@n3rdw1z4rd/core 0.23.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/astar.js +3 -3
  2. package/dist/dungeon-generator.js +4 -4
  3. package/dist/graph/index.d.ts +21 -0
  4. package/dist/graph/subgraph.js +1 -1
  5. package/dist/graph.cjs +2 -2
  6. package/dist/graph.d.cts +21 -0
  7. package/dist/index.cjs +75 -26
  8. package/dist/index.d.cts +19 -0
  9. package/dist/index.d.ts +11 -0
  10. package/dist/input/input-action-map.d.ts +9 -1
  11. package/dist/input/input-action-map.js +64 -15
  12. package/dist/map2d.js +2 -2
  13. package/dist/math.js +2 -2
  14. package/dist/{rng-edL6atS3.cjs → rng-BtvhTJmM.cjs} +2 -2
  15. package/dist/{spatial-partition-3d-D1uyJVhM.cjs → spatial-partition-3d-qhjqIpcy.cjs} +1 -1
  16. package/dist/three/adaptive-grid.d.ts +1 -1
  17. package/dist/three/adaptive-grid.js +1 -1
  18. package/dist/three/asteroid-mesh.d.ts +1 -1
  19. package/dist/three/camera-rig.js +1 -1
  20. package/dist/three/cube-sphere-geometry.d.ts +1 -1
  21. package/dist/three/index.d.ts +13 -2
  22. package/dist/three/particle-system-3d.js +1 -1
  23. package/dist/three/picking.d.ts +1 -1
  24. package/dist/three/picking.js +1 -1
  25. package/dist/three/starfield.js +4 -4
  26. package/dist/three/texture-atlas.d.ts +1 -1
  27. package/dist/three/texture-atlas.js +1 -1
  28. package/dist/three/texture-utils.js +2 -4
  29. package/dist/three/voxel-geometry.d.ts +44 -10
  30. package/dist/three/voxel-geometry.js +282 -77
  31. package/dist/three/voxel-mesh.d.ts +1 -1
  32. package/dist/three/voxel-mesh.js +1 -1
  33. package/dist/three/world.d.ts +1 -1
  34. package/dist/three/world.js +1 -1
  35. package/dist/three.cjs +290 -87
  36. package/dist/three.d.cts +55 -10
  37. package/dist/webgl.js +2 -2
  38. package/package.json +1 -1
  39. package/dist/input/_input.d.ts +0 -23
  40. package/dist/input/_input.js +0 -96
package/dist/astar.js CHANGED
@@ -1,5 +1,5 @@
1
- import { SQRT2 } from "./math.js";
2
1
  import { Heap } from "heap-js";
2
+ import { SQRT2 } from "./math.js";
3
3
  // src/astar.ts
4
4
  const DEFAULT_MAX_NODES = 1e4;
5
5
  const DIRECTIONS = [
@@ -50,7 +50,7 @@ function findPath(start, goal, cost, options = {}) {
50
50
  const dy = Math.abs(y - goal.y);
51
51
  return diagonal ? Math.max(dx, dy) === 1 : dx + dy === 1;
52
52
  };
53
- const passable = (x, y) => cost(x, y) < Infinity;
53
+ const passable = (x, y) => cost(x, y) < 1e400;
54
54
  if (!adjacent && !partial && !passable(goal.x, goal.y) && !(start.x === goal.x && start.y === goal.y)) return [];
55
55
  let seq = 0;
56
56
  const open = new Heap((a, b) => a.f - b.f || a.h - b.h || a.seq - b.seq);
@@ -84,7 +84,7 @@ function findPath(start, goal, cost, options = {}) {
84
84
  const k = key(x, y);
85
85
  if (closed.has(k)) continue;
86
86
  const stepCost = cost(x, y);
87
- if (!(stepCost < Infinity)) continue;
87
+ if (!(stepCost < 1e400)) continue;
88
88
  const isDiagonal = dx !== 0 && dy !== 0;
89
89
  if (isDiagonal && !cutCorners && (!passable(current.x + dx, current.y) || !passable(current.x, current.y + dy))) continue;
90
90
  const g = current.g + (isDiagonal ? stepCost * SQRT2 : stepCost);
@@ -1,10 +1,10 @@
1
1
  import { findPath } from "./astar.js";
2
+ import { Heap } from "heap-js";
2
3
  import { Map2D } from "./map2d.js";
3
4
  import { rng } from "./rng.js";
4
5
  import { log } from "./log.js";
5
6
  import { distance2d, squaredDistance } from "./math.js";
6
7
  import { Rectangle } from "./rectangle.js";
7
- import { Heap } from "heap-js";
8
8
  // src/dungeon-generator.ts
9
9
  /**
10
10
  * Tile value for empty (unused) space.
@@ -178,7 +178,7 @@ function _getShortestPathBetweenRects(rectA, rectB) {
178
178
  let paths = {
179
179
  a: edgeA[0],
180
180
  b: edgeB[0],
181
- distance: Infinity
181
+ distance: 1e400
182
182
  };
183
183
  for (const a of edgeA) for (const b of edgeB) {
184
184
  const d = distance2d(a.x, a.y, b.x, b.y);
@@ -195,13 +195,13 @@ function _getShortestPathBetweenRects(rectA, rectB) {
195
195
  }
196
196
  function _generatePaths(map, rooms, params = {}) {
197
197
  const walkable = params.walkableValues ?? [map.defaultValue];
198
- const cost = (x, y) => walkable.includes(map.get(x, y)) ? 1 : Infinity;
198
+ const cost = (x, y) => walkable.includes(map.get(x, y)) ? 1 : 1e400;
199
199
  const paths = [];
200
200
  _generateMST(rooms, params).forEach((rects) => {
201
201
  const { a, b } = _getShortestPathBetweenRects(rects.a, rects.b);
202
202
  paths.push(findPath(a, b, cost, {
203
203
  adjacent: true,
204
- maxNodes: Infinity
204
+ maxNodes: 1e400
205
205
  }));
206
206
  });
207
207
  return paths;
@@ -1,3 +1,24 @@
1
+ /**
2
+ * Node graphs: a graph document format, typed pins, node types (built-in or written as
3
+ * scripts), and a lazy, memoized evaluator with list broadcasting. No DOM: runs in a page,
4
+ * a worker or Node.
5
+ *
6
+ * ```ts
7
+ * import { createGraph, createNodeRegistry, addNode, connect, GraphEvaluator } from '@n3rdw1z4rd/core/graph';
8
+ *
9
+ * const nodes = createNodeRegistry();
10
+ * const graph = createGraph();
11
+ * const grid = addNode(graph, nodes.get('list/grid2d')!, [0, 0], { cols: 3, rows: 2 });
12
+ * const count = addNode(graph, nodes.get('list/count')!, [240, 0]);
13
+ * connect(graph, nodes, { node: grid.id, port: 'points' }, { node: count.id, port: 'list' });
14
+ *
15
+ * const { results } = await new GraphEvaluator(nodes).evaluate(graph);
16
+ * results.get(count.id)!.outputs.count; // 6
17
+ * ```
18
+ *
19
+ * @packageDocumentation
20
+ * @module @n3rdw1z4rd/core/graph
21
+ */
1
22
  import { ConnectCheck, GRAPH_FORMAT, GRAPH_VERSION, GraphDoc, GraphGroup, GraphLink, GraphNode, PortRef, SubgraphDef, addNode, canConnect, connect, createGraph, disconnect, getNode, graphId, linkInto, linksInto, normalizeGraph, removeNode } from "./doc.js";
2
23
  import { EvaluateOptions, EvaluateResult, FrameInfo, GraphEvaluator, NodeResult, OUTPUT_LISTS } from "./evaluate.js";
3
24
  import { NodeDef, NodeRegistry, NodeSpec, Param, ParamSpec, Port, PortSpec, RunContext, RunFn, WidgetSpec, defineNode } from "./node.js";
@@ -168,7 +168,7 @@ function collapseToSubgraph(doc, registry, nodeIds, title = "Subgraph") {
168
168
  from: { ...l.from }
169
169
  });
170
170
  }
171
- let minX = Infinity, minY = Infinity, sumX = 0, sumY = 0;
171
+ let minX = 1e400, minY = 1e400, sumX = 0, sumY = 0;
172
172
  for (const n of inside) {
173
173
  minX = Math.min(minX, n.pos[0]);
174
174
  minY = Math.min(minY, n.pos[1]);
package/dist/graph.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rng = require("./rng-edL6atS3.cjs");
2
+ const require_rng = require("./rng-BtvhTJmM.cjs");
3
3
  // src/graph/types.ts
4
4
  /** @category Graph */
5
5
  function parseType(type) {
@@ -1528,7 +1528,7 @@ function collapseToSubgraph(doc, registry, nodeIds, title = "Subgraph") {
1528
1528
  from: { ...l.from }
1529
1529
  });
1530
1530
  }
1531
- let minX = Infinity, minY = Infinity, sumX = 0, sumY = 0;
1531
+ let minX = 1e400, minY = 1e400, sumX = 0, sumY = 0;
1532
1532
  for (const n of inside) {
1533
1533
  minX = Math.min(minX, n.pos[0]);
1534
1534
  minY = Math.min(minY, n.pos[1]);
package/dist/graph.d.cts CHANGED
@@ -1,3 +1,24 @@
1
+ /**
2
+ * Node graphs: a graph document format, typed pins, node types (built-in or written as
3
+ * scripts), and a lazy, memoized evaluator with list broadcasting. No DOM: runs in a page,
4
+ * a worker or Node.
5
+ *
6
+ * ```ts
7
+ * import { createGraph, createNodeRegistry, addNode, connect, GraphEvaluator } from '@n3rdw1z4rd/core/graph';
8
+ *
9
+ * const nodes = createNodeRegistry();
10
+ * const graph = createGraph();
11
+ * const grid = addNode(graph, nodes.get('list/grid2d')!, [0, 0], { cols: 3, rows: 2 });
12
+ * const count = addNode(graph, nodes.get('list/count')!, [240, 0]);
13
+ * connect(graph, nodes, { node: grid.id, port: 'points' }, { node: count.id, port: 'list' });
14
+ *
15
+ * const { results } = await new GraphEvaluator(nodes).evaluate(graph);
16
+ * results.get(count.id)!.outputs.count; // 6
17
+ * ```
18
+ *
19
+ * @packageDocumentation
20
+ * @module @n3rdw1z4rd/core/graph
21
+ */
1
22
  /**
2
23
  * Pin types. A type is a name (`number`, `vec2`, your own…) with a color for the editor;
3
24
  * a trailing `[]` in a port declaration (`vec2[]`) makes the port a **list port** — it takes
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rng = require("./rng-edL6atS3.cjs");
3
- const require_spatial_partition_3d = require("./spatial-partition-3d-D1uyJVhM.cjs");
4
2
  let heap_js = require("heap-js");
3
+ const require_rng = require("./rng-BtvhTJmM.cjs");
4
+ const require_spatial_partition_3d = require("./spatial-partition-3d-qhjqIpcy.cjs");
5
5
  // src/astar.ts
6
6
  const DEFAULT_MAX_NODES = 1e4;
7
7
  const DIRECTIONS = [
@@ -52,7 +52,7 @@ function findPath(start, goal, cost, options = {}) {
52
52
  const dy = Math.abs(y - goal.y);
53
53
  return diagonal ? Math.max(dx, dy) === 1 : dx + dy === 1;
54
54
  };
55
- const passable = (x, y) => cost(x, y) < Infinity;
55
+ const passable = (x, y) => cost(x, y) < 1e400;
56
56
  if (!adjacent && !partial && !passable(goal.x, goal.y) && !(start.x === goal.x && start.y === goal.y)) return [];
57
57
  let seq = 0;
58
58
  const open = new heap_js.Heap((a, b) => a.f - b.f || a.h - b.h || a.seq - b.seq);
@@ -86,7 +86,7 @@ function findPath(start, goal, cost, options = {}) {
86
86
  const k = key$1(x, y);
87
87
  if (closed.has(k)) continue;
88
88
  const stepCost = cost(x, y);
89
- if (!(stepCost < Infinity)) continue;
89
+ if (!(stepCost < 1e400)) continue;
90
90
  const isDiagonal = dx !== 0 && dy !== 0;
91
91
  if (isDiagonal && !cutCorners && (!passable(current.x + dx, current.y) || !passable(current.x, current.y + dy))) continue;
92
92
  const g = current.g + (isDiagonal ? stepCost * require_rng.SQRT2 : stepCost);
@@ -587,7 +587,7 @@ const MAP_2D_MIN_COORD = -1048576;
587
587
  *
588
588
  * @category Maps & Spatial
589
589
  */
590
- const MAP_2D_MAX_COORD = 1048575;
590
+ const MAP_2D_MAX_COORD = 0xfffff;
591
591
  /**
592
592
  * Sparse 2D grid of numbers keyed by integer coordinates. Coordinates are floored, so any point
593
593
  * inside a cell addresses that cell. Cells holding `defaultValue` are not stored: setting a cell to
@@ -630,7 +630,7 @@ var Map2D = class {
630
630
  return [Math.floor(x), Math.floor(y)];
631
631
  }
632
632
  _key(x, y) {
633
- if (!this._warnedOutOfRange && (x < -1048576 || x > 1048575 || y < -1048576 || y > 1048575)) {
633
+ if (!this._warnedOutOfRange && (x < -1048576 || x > 0xfffff || y < -1048576 || y > 0xfffff)) {
634
634
  this._warnedOutOfRange = true;
635
635
  console.warn(`Map2D: (${x}, ${y}) is outside the supported range [${MAP_2D_MIN_COORD}, ${MAP_2D_MAX_COORD}] per axis; it wraps around and collides with other coordinates. Further warnings for this map are suppressed.`);
636
636
  }
@@ -1087,7 +1087,7 @@ function _getShortestPathBetweenRects(rectA, rectB) {
1087
1087
  let paths = {
1088
1088
  a: edgeA[0],
1089
1089
  b: edgeB[0],
1090
- distance: Infinity
1090
+ distance: 1e400
1091
1091
  };
1092
1092
  for (const a of edgeA) for (const b of edgeB) {
1093
1093
  const d = require_rng.distance2d(a.x, a.y, b.x, b.y);
@@ -1104,13 +1104,13 @@ function _getShortestPathBetweenRects(rectA, rectB) {
1104
1104
  }
1105
1105
  function _generatePaths(map, rooms, params = {}) {
1106
1106
  const walkable = params.walkableValues ?? [map.defaultValue];
1107
- const cost = (x, y) => walkable.includes(map.get(x, y)) ? 1 : Infinity;
1107
+ const cost = (x, y) => walkable.includes(map.get(x, y)) ? 1 : 1e400;
1108
1108
  const paths = [];
1109
1109
  _generateMST(rooms, params).forEach((rects) => {
1110
1110
  const { a, b } = _getShortestPathBetweenRects(rects.a, rects.b);
1111
1111
  paths.push(findPath(a, b, cost, {
1112
1112
  adjacent: true,
1113
- maxNodes: Infinity
1113
+ maxNodes: 1e400
1114
1114
  }));
1115
1115
  });
1116
1116
  return paths;
@@ -2258,6 +2258,27 @@ var Observable = class {
2258
2258
  }
2259
2259
  };
2260
2260
  // src/input/input-action-map.ts
2261
+ const SHIFT = 1;
2262
+ const CTRL = 2;
2263
+ const ALT = 4;
2264
+ const META = 8;
2265
+ const MODIFIER_KEYS = [
2266
+ ["ShiftLeft", SHIFT],
2267
+ ["ShiftRight", SHIFT],
2268
+ ["ControlLeft", CTRL],
2269
+ ["ControlRight", CTRL],
2270
+ ["AltLeft", ALT],
2271
+ ["AltRight", ALT],
2272
+ ["MetaLeft", META],
2273
+ ["MetaRight", META]
2274
+ ];
2275
+ const modifierBits = (m) => (m.shift ? SHIFT : 0) | (m.ctrl ? CTRL : 0) | (m.alt ? ALT : 0) | (m.meta ? META : 0);
2276
+ const modifiersOf = (bits) => ({
2277
+ shift: !!(bits & SHIFT),
2278
+ ctrl: !!(bits & CTRL),
2279
+ alt: !!(bits & ALT),
2280
+ meta: !!(bits & META)
2281
+ });
2261
2282
  const ANY = -1;
2262
2283
  const now = () => performance.now();
2263
2284
  const MOUSE_BUTTONS = [
@@ -2408,35 +2429,49 @@ var InputActionMap = class {
2408
2429
  this._updateGestures(time);
2409
2430
  const devices = [...this._controls.keys()];
2410
2431
  const fired = [];
2432
+ const heldMods = this._heldMods();
2411
2433
  for (const name of this.actions.names) {
2412
2434
  const action = this.actions.get(name);
2413
2435
  let states = this._actionStates.get(name);
2414
2436
  if (!states) this._actionStates.set(name, states = /* @__PURE__ */ new Map());
2415
2437
  let anyRaw = 0;
2438
+ let anyPressMods = -1;
2416
2439
  for (const device of devices) {
2417
2440
  let raw = 0;
2418
- for (const binding of action.bindings) raw = Math.max(raw, this._bindingValue(binding, device));
2441
+ let pressMods = -1;
2442
+ for (const binding of action.bindings) {
2443
+ const value = this._bindingValue(binding, device);
2444
+ raw = Math.max(raw, value);
2445
+ const control = this._controls.get(device)?.get(controlId(binding));
2446
+ if (value > 0 && control?.pressed) pressMods = Math.max(0, pressMods) | control.mods;
2447
+ }
2419
2448
  anyRaw = Math.max(anyRaw, raw);
2449
+ if (pressMods >= 0) anyPressMods = Math.max(0, anyPressMods) | pressMods;
2420
2450
  const phase = this._advance(states, device, raw, action, time);
2451
+ const state = states.get(device);
2421
2452
  if (phase) fired.push({
2422
2453
  action: name,
2423
2454
  phase,
2424
2455
  device,
2425
- repeat: states.get(device).repeated
2456
+ repeat: state.repeated,
2457
+ mods: phase === "pressed" && !state.repeated && pressMods >= 0 ? pressMods : heldMods
2426
2458
  });
2427
2459
  }
2428
2460
  const phase = this._advance(states, ANY, anyRaw, action, time);
2461
+ const state = states.get(ANY);
2429
2462
  if (phase) fired.push({
2430
2463
  action: name,
2431
2464
  phase,
2432
2465
  device: ANY,
2433
- repeat: states.get(ANY).repeated
2466
+ repeat: state.repeated,
2467
+ mods: phase === "pressed" && !state.repeated && anyPressMods >= 0 ? anyPressMods : heldMods
2434
2468
  });
2435
2469
  }
2436
2470
  for (const controls of this._controls.values()) for (const state of controls.values()) state.pressed = false;
2437
- for (const { action, phase, device, repeat } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
2471
+ for (const { action, phase, device, repeat, mods } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
2438
2472
  action,
2439
- repeat
2473
+ repeat,
2474
+ modifiers: modifiersOf(mods)
2440
2475
  });
2441
2476
  }
2442
2477
  /** Whether the action is held past its deadzone. Unknown actions return false (and warn once). */
@@ -2646,13 +2681,11 @@ var InputActionMap = class {
2646
2681
  _bindingValue(binding, device) {
2647
2682
  const value = this._controlValue(device, controlId(binding));
2648
2683
  if (value === 0 || binding.type !== "key" || !binding.modifiers) return value;
2649
- const held = (left, right) => this._controlValue(device, `key:${left}`) > 0 || this._controlValue(device, `key:${right}`) > 0;
2650
- const m = binding.modifiers;
2651
- if (m.shift && !held("ShiftLeft", "ShiftRight")) return 0;
2652
- if (m.ctrl && !held("ControlLeft", "ControlRight")) return 0;
2653
- if (m.alt && !held("AltLeft", "AltRight")) return 0;
2654
- if (m.meta && !held("MetaLeft", "MetaRight")) return 0;
2655
- return value;
2684
+ const control = this._controls.get(device)?.get(controlId(binding));
2685
+ let held = control?.pressed ? control.mods : 0;
2686
+ for (const [code, bit] of MODIFIER_KEYS) if (this._controlValue(device, `key:${code}`) > 0) held |= bit;
2687
+ const need = modifierBits(binding.modifiers);
2688
+ return (held & need) === need ? value : 0;
2656
2689
  }
2657
2690
  _control(device, binding) {
2658
2691
  let controls = this._controls.get(device);
@@ -2662,7 +2695,8 @@ var InputActionMap = class {
2662
2695
  if (!state) controls.set(id, state = {
2663
2696
  value: 0,
2664
2697
  pressed: false,
2665
- suppressed: false
2698
+ suppressed: false,
2699
+ mods: 0
2666
2700
  });
2667
2701
  return state;
2668
2702
  }
@@ -2673,14 +2707,29 @@ var InputActionMap = class {
2673
2707
  state.value = value;
2674
2708
  if (value >= .5 && !wasDown) {
2675
2709
  if (this._tryCapture(binding)) state.suppressed = true;
2676
- else state.pressed = true;
2710
+ else {
2711
+ state.pressed = true;
2712
+ state.mods = this._heldMods();
2713
+ }
2677
2714
  }
2678
2715
  if (value === 0) state.suppressed = false;
2679
2716
  }
2680
2717
  /** A one-frame press with no held state: wheel steps, gestures. */
2681
2718
  _pulse(device, binding) {
2682
2719
  const state = this._control(device, binding);
2683
- if (!this._tryCapture(binding)) state.pressed = true;
2720
+ if (!this._tryCapture(binding)) {
2721
+ state.pressed = true;
2722
+ state.mods = this._heldMods();
2723
+ }
2724
+ }
2725
+ /** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
2726
+ _heldMods() {
2727
+ const keys = this._controls.get(0);
2728
+ let bits = 0;
2729
+ if (keys) {
2730
+ for (const [code, bit] of MODIFIER_KEYS) if ((keys.get(`key:${code}`)?.value ?? 0) > 0) bits |= bit;
2731
+ }
2732
+ return bits;
2684
2733
  }
2685
2734
  _tryCapture(binding) {
2686
2735
  const capture = this._capture;
@@ -3535,7 +3584,7 @@ function CreateVertexArray(gl, info, attributes, indices) {
3535
3584
  vao,
3536
3585
  buffers: []
3537
3586
  };
3538
- let vertexCount = Infinity;
3587
+ let vertexCount = 1e400;
3539
3588
  gl.bindVertexArray(vao);
3540
3589
  for (const name in attributes) {
3541
3590
  const attribute = info.attributes[name];
@@ -3575,7 +3624,7 @@ function CreateVertexArray(gl, info, attributes, indices) {
3575
3624
  if (!result.buffers.includes(indices.buffer)) result.buffers.push(indices.buffer);
3576
3625
  }
3577
3626
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, result.indexBuffer);
3578
- } else if (vertexCount < Infinity) result.count = vertexCount;
3627
+ } else if (vertexCount < 1e400) result.count = vertexCount;
3579
3628
  gl.bindVertexArray(null);
3580
3629
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
3581
3630
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
package/dist/index.d.cts CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * The main entry point: math and RNG, input, pathfinding, maps, ECS, events, color, canvas and
3
+ * raw WebGL helpers. Never imports three.js; see {@link "@n3rdw1z4rd/core/three"} for those helpers.
4
+ *
5
+ * ```ts
6
+ * import { rng, findPath, Input } from '@n3rdw1z4rd/core';
7
+ * ```
8
+ *
9
+ * @packageDocumentation
10
+ * @module @n3rdw1z4rd/core
11
+ */
1
12
  import { _ as XYZ, a as Map3DCell, c as MAP_2D_MIN_COORD, d as ColorPalette, f as RGB, g as XY, h as NoiseFunction3D, i as Map3D, l as Map2D, m as KeyValue, n as MAP_3D_MAX_COORD, o as DEFAULT_MAP_2D_VALUE, p as buildColorPalette, r as MAP_3D_MIN_COORD, s as MAP_2D_MAX_COORD, t as DEFAULT_MAP_3D_VALUE, u as Map2DData } from "./map3d-DRHhbrFn.cjs";
2
13
  /**
3
14
  * Cost of stepping onto tile (x, y). Return `Infinity` for blocked tiles. Costs should be >= 1
@@ -1449,6 +1460,12 @@ export interface ActionEvent {
1449
1460
  action: string;
1450
1461
  /** an auto-repeat of a held action (see {@link ActionRepeat}), not a new press */
1451
1462
  repeat: boolean;
1463
+ /**
1464
+ * The modifier keys that were held when the press happened, even if they were let go again
1465
+ * before update() (a quick Shift + arrow between two frames). For auto-repeats and releases:
1466
+ * the ones held now.
1467
+ */
1468
+ modifiers: Required<KeyModifiers>;
1452
1469
  }
1453
1470
  /**
1454
1471
  * Options for the {@link InputActionMap} constructor.
@@ -1700,6 +1717,8 @@ export declare class InputActionMap {
1700
1717
  protected _setControl(device: InputDevice, binding: Binding, value: number): void;
1701
1718
  /** A one-frame press with no held state: wheel steps, gestures. */
1702
1719
  protected _pulse(device: InputDevice, binding: Binding): void;
1720
+ /** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
1721
+ private _heldMods;
1703
1722
  private _tryCapture;
1704
1723
  private _setLastDevice;
1705
1724
  /**
package/dist/index.d.ts CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * The main entry point: math and RNG, input, pathfinding, maps, ECS, events, color, canvas and
3
+ * raw WebGL helpers. Never imports three.js; see {@link "@n3rdw1z4rd/core/three"} for those helpers.
4
+ *
5
+ * ```ts
6
+ * import { rng, findPath, Input } from '@n3rdw1z4rd/core';
7
+ * ```
8
+ *
9
+ * @packageDocumentation
10
+ * @module @n3rdw1z4rd/core
11
+ */
1
12
  import { PathOptions, StepCost, findPath } from "./astar.js";
2
13
  import { CanvasColor, CanvasRenderer, DEFAULT_COLOR, DEFAULT_FONT, DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_PIXEL_SIZE, DEFAULT_TEXTALIGN, DEFAULT_TEXTBASELINE, DrawParams, SpriteParams } from "./canvas-renderer.js";
3
14
  import { Clock, ClockCallback, ONE_SECOND } from "./clock.js";
@@ -2,7 +2,7 @@ import { Observable } from "../observable.js";
2
2
  import { ActionMap } from "./action-map.js";
3
3
  import { GestureFrame, GestureRecognizer, TouchPoint } from "./gestures.js";
4
4
  import { Input } from "./input.js";
5
- import { Binding, MouseButton } from "./bindings.js";
5
+ import { Binding, KeyModifiers, MouseButton } from "./bindings.js";
6
6
  /**
7
7
  * 0 = keyboard, mouse, pen, touch and VR; 1, 2, ... = gamepads.
8
8
  *
@@ -31,6 +31,12 @@ export interface ActionEvent {
31
31
  action: string;
32
32
  /** an auto-repeat of a held action (see {@link ActionRepeat}), not a new press */
33
33
  repeat: boolean;
34
+ /**
35
+ * The modifier keys that were held when the press happened, even if they were let go again
36
+ * before update() (a quick Shift + arrow between two frames). For auto-repeats and releases:
37
+ * the ones held now.
38
+ */
39
+ modifiers: Required<KeyModifiers>;
34
40
  }
35
41
  /**
36
42
  * Options for the {@link InputActionMap} constructor.
@@ -282,6 +288,8 @@ export declare class InputActionMap {
282
288
  protected _setControl(device: InputDevice, binding: Binding, value: number): void;
283
289
  /** A one-frame press with no held state: wheel steps, gestures. */
284
290
  protected _pulse(device: InputDevice, binding: Binding): void;
291
+ /** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
292
+ private _heldMods;
285
293
  private _tryCapture;
286
294
  private _setLastDevice;
287
295
  /**
@@ -4,6 +4,27 @@ import { GestureRecognizer } from "./gestures.js";
4
4
  import { Input } from "./input.js";
5
5
  import { GAMEPAD_AXES, GAMEPAD_BUTTONS, XR_AXES, XR_BUTTONS, controlId } from "./bindings.js";
6
6
  // src/input/input-action-map.ts
7
+ const SHIFT = 1;
8
+ const CTRL = 2;
9
+ const ALT = 4;
10
+ const META = 8;
11
+ const MODIFIER_KEYS = [
12
+ ["ShiftLeft", SHIFT],
13
+ ["ShiftRight", SHIFT],
14
+ ["ControlLeft", CTRL],
15
+ ["ControlRight", CTRL],
16
+ ["AltLeft", ALT],
17
+ ["AltRight", ALT],
18
+ ["MetaLeft", META],
19
+ ["MetaRight", META]
20
+ ];
21
+ const modifierBits = (m) => (m.shift ? SHIFT : 0) | (m.ctrl ? CTRL : 0) | (m.alt ? ALT : 0) | (m.meta ? META : 0);
22
+ const modifiersOf = (bits) => ({
23
+ shift: !!(bits & SHIFT),
24
+ ctrl: !!(bits & CTRL),
25
+ alt: !!(bits & ALT),
26
+ meta: !!(bits & META)
27
+ });
7
28
  const ANY = -1;
8
29
  const now = () => performance.now();
9
30
  const MOUSE_BUTTONS = [
@@ -154,35 +175,49 @@ var InputActionMap = class {
154
175
  this._updateGestures(time);
155
176
  const devices = [...this._controls.keys()];
156
177
  const fired = [];
178
+ const heldMods = this._heldMods();
157
179
  for (const name of this.actions.names) {
158
180
  const action = this.actions.get(name);
159
181
  let states = this._actionStates.get(name);
160
182
  if (!states) this._actionStates.set(name, states = /* @__PURE__ */ new Map());
161
183
  let anyRaw = 0;
184
+ let anyPressMods = -1;
162
185
  for (const device of devices) {
163
186
  let raw = 0;
164
- for (const binding of action.bindings) raw = Math.max(raw, this._bindingValue(binding, device));
187
+ let pressMods = -1;
188
+ for (const binding of action.bindings) {
189
+ const value = this._bindingValue(binding, device);
190
+ raw = Math.max(raw, value);
191
+ const control = this._controls.get(device)?.get(controlId(binding));
192
+ if (value > 0 && control?.pressed) pressMods = Math.max(0, pressMods) | control.mods;
193
+ }
165
194
  anyRaw = Math.max(anyRaw, raw);
195
+ if (pressMods >= 0) anyPressMods = Math.max(0, anyPressMods) | pressMods;
166
196
  const phase = this._advance(states, device, raw, action, time);
197
+ const state = states.get(device);
167
198
  if (phase) fired.push({
168
199
  action: name,
169
200
  phase,
170
201
  device,
171
- repeat: states.get(device).repeated
202
+ repeat: state.repeated,
203
+ mods: phase === "pressed" && !state.repeated && pressMods >= 0 ? pressMods : heldMods
172
204
  });
173
205
  }
174
206
  const phase = this._advance(states, ANY, anyRaw, action, time);
207
+ const state = states.get(ANY);
175
208
  if (phase) fired.push({
176
209
  action: name,
177
210
  phase,
178
211
  device: ANY,
179
- repeat: states.get(ANY).repeated
212
+ repeat: state.repeated,
213
+ mods: phase === "pressed" && !state.repeated && anyPressMods >= 0 ? anyPressMods : heldMods
180
214
  });
181
215
  }
182
216
  for (const controls of this._controls.values()) for (const state of controls.values()) state.pressed = false;
183
- for (const { action, phase, device, repeat } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
217
+ for (const { action, phase, device, repeat, mods } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
184
218
  action,
185
- repeat
219
+ repeat,
220
+ modifiers: modifiersOf(mods)
186
221
  });
187
222
  }
188
223
  /** Whether the action is held past its deadzone. Unknown actions return false (and warn once). */
@@ -392,13 +427,11 @@ var InputActionMap = class {
392
427
  _bindingValue(binding, device) {
393
428
  const value = this._controlValue(device, controlId(binding));
394
429
  if (value === 0 || binding.type !== "key" || !binding.modifiers) return value;
395
- const held = (left, right) => this._controlValue(device, `key:${left}`) > 0 || this._controlValue(device, `key:${right}`) > 0;
396
- const m = binding.modifiers;
397
- if (m.shift && !held("ShiftLeft", "ShiftRight")) return 0;
398
- if (m.ctrl && !held("ControlLeft", "ControlRight")) return 0;
399
- if (m.alt && !held("AltLeft", "AltRight")) return 0;
400
- if (m.meta && !held("MetaLeft", "MetaRight")) return 0;
401
- return value;
430
+ const control = this._controls.get(device)?.get(controlId(binding));
431
+ let held = control?.pressed ? control.mods : 0;
432
+ for (const [code, bit] of MODIFIER_KEYS) if (this._controlValue(device, `key:${code}`) > 0) held |= bit;
433
+ const need = modifierBits(binding.modifiers);
434
+ return (held & need) === need ? value : 0;
402
435
  }
403
436
  _control(device, binding) {
404
437
  let controls = this._controls.get(device);
@@ -408,7 +441,8 @@ var InputActionMap = class {
408
441
  if (!state) controls.set(id, state = {
409
442
  value: 0,
410
443
  pressed: false,
411
- suppressed: false
444
+ suppressed: false,
445
+ mods: 0
412
446
  });
413
447
  return state;
414
448
  }
@@ -419,14 +453,29 @@ var InputActionMap = class {
419
453
  state.value = value;
420
454
  if (value >= .5 && !wasDown) {
421
455
  if (this._tryCapture(binding)) state.suppressed = true;
422
- else state.pressed = true;
456
+ else {
457
+ state.pressed = true;
458
+ state.mods = this._heldMods();
459
+ }
423
460
  }
424
461
  if (value === 0) state.suppressed = false;
425
462
  }
426
463
  /** A one-frame press with no held state: wheel steps, gestures. */
427
464
  _pulse(device, binding) {
428
465
  const state = this._control(device, binding);
429
- if (!this._tryCapture(binding)) state.pressed = true;
466
+ if (!this._tryCapture(binding)) {
467
+ state.pressed = true;
468
+ state.mods = this._heldMods();
469
+ }
470
+ }
471
+ /** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
472
+ _heldMods() {
473
+ const keys = this._controls.get(0);
474
+ let bits = 0;
475
+ if (keys) {
476
+ for (const [code, bit] of MODIFIER_KEYS) if ((keys.get(`key:${code}`)?.value ?? 0) > 0) bits |= bit;
477
+ }
478
+ return bits;
430
479
  }
431
480
  _tryCapture(binding) {
432
481
  const capture = this._capture;
package/dist/map2d.js CHANGED
@@ -19,7 +19,7 @@ const MAP_2D_MIN_COORD = -1048576;
19
19
  *
20
20
  * @category Maps & Spatial
21
21
  */
22
- const MAP_2D_MAX_COORD = 1048575;
22
+ const MAP_2D_MAX_COORD = 0xfffff;
23
23
  /**
24
24
  * Sparse 2D grid of numbers keyed by integer coordinates. Coordinates are floored, so any point
25
25
  * inside a cell addresses that cell. Cells holding `defaultValue` are not stored: setting a cell to
@@ -62,7 +62,7 @@ var Map2D = class {
62
62
  return [Math.floor(x), Math.floor(y)];
63
63
  }
64
64
  _key(x, y) {
65
- if (!this._warnedOutOfRange && (x < -1048576 || x > 1048575 || y < -1048576 || y > 1048575)) {
65
+ if (!this._warnedOutOfRange && (x < -1048576 || x > 0xfffff || y < -1048576 || y > 0xfffff)) {
66
66
  this._warnedOutOfRange = true;
67
67
  console.warn(`Map2D: (${x}, ${y}) is outside the supported range [${MAP_2D_MIN_COORD}, ${MAP_2D_MAX_COORD}] per axis; it wraps around and collides with other coordinates. Further warnings for this map are suppressed.`);
68
68
  }
package/dist/math.js CHANGED
@@ -183,9 +183,9 @@ const roundTo = (value, digits = 0) => {
183
183
  const hash32 = (n) => {
184
184
  n |= 0;
185
185
  n ^= n >>> 16;
186
- n = Math.imul(n, 2246822507);
186
+ n = Math.imul(n, 0x85ebca6b);
187
187
  n ^= n >>> 13;
188
- n = Math.imul(n, 3266489909);
188
+ n = Math.imul(n, 0xc2b2ae35);
189
189
  n ^= n >>> 16;
190
190
  return n >>> 0;
191
191
  };
@@ -183,9 +183,9 @@ const roundTo = (value, digits = 0) => {
183
183
  const hash32 = (n) => {
184
184
  n |= 0;
185
185
  n ^= n >>> 16;
186
- n = Math.imul(n, 2246822507);
186
+ n = Math.imul(n, 0x85ebca6b);
187
187
  n ^= n >>> 13;
188
- n = Math.imul(n, 3266489909);
188
+ n = Math.imul(n, 0xc2b2ae35);
189
189
  n ^= n >>> 16;
190
190
  return n >>> 0;
191
191
  };
@@ -1,4 +1,4 @@
1
- const require_rng = require("./rng-edL6atS3.cjs");
1
+ const require_rng = require("./rng-BtvhTJmM.cjs");
2
2
  // src/log.ts
3
3
  /**
4
4
  * `console.debug` with a bold gray `[dev]` prefix; takes the same arguments. Visible only when the
@@ -1,5 +1,5 @@
1
- import { EditorCamera } from "./editor-camera.js";
2
1
  import { BufferGeometry, ColorRepresentation, LineBasicMaterial, LineSegments } from "three";
2
+ import { EditorCamera } from "./editor-camera.js";
3
3
  /**
4
4
  * An infinite-looking grid on the XY plane for editor views: each {@link AdaptiveGrid.update}
5
5
  * rebuilds just the lines in view, doubling the spacing when zoomed out so lines never get