@codexo/exojs-pathfinding 0.19.1 → 0.20.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 (43) hide show
  1. package/README.md +7 -39
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +12 -20
  5. package/dist/esm/Pathfinder.d.ts +0 -50
  6. package/dist/esm/Pathfinder.d.ts.map +0 -1
  7. package/dist/esm/Pathfinder.js +0 -151
  8. package/dist/esm/Pathfinder.js.map +0 -1
  9. package/dist/esm/core/BinaryHeap.d.ts +0 -2
  10. package/dist/esm/core/BinaryHeap.d.ts.map +0 -1
  11. package/dist/esm/core/BinaryHeap.js +0 -90
  12. package/dist/esm/core/BinaryHeap.js.map +0 -1
  13. package/dist/esm/core/SearchState.d.ts +0 -2
  14. package/dist/esm/core/SearchState.d.ts.map +0 -1
  15. package/dist/esm/core/SearchState.js +0 -66
  16. package/dist/esm/core/SearchState.js.map +0 -1
  17. package/dist/esm/core/search.d.ts +0 -2
  18. package/dist/esm/core/search.d.ts.map +0 -1
  19. package/dist/esm/core/search.js +0 -106
  20. package/dist/esm/core/search.js.map +0 -1
  21. package/dist/esm/index.d.ts +0 -2
  22. package/dist/esm/index.d.ts.map +0 -1
  23. package/dist/esm/index.js +0 -5
  24. package/dist/esm/public.d.ts +0 -7
  25. package/dist/esm/public.d.ts.map +0 -1
  26. package/dist/esm/spaces/GridJumpExpansion.d.ts +0 -2
  27. package/dist/esm/spaces/GridJumpExpansion.d.ts.map +0 -1
  28. package/dist/esm/spaces/GridJumpExpansion.js +0 -137
  29. package/dist/esm/spaces/GridJumpExpansion.js.map +0 -1
  30. package/dist/esm/spaces/GridSpace.d.ts +0 -131
  31. package/dist/esm/spaces/GridSpace.d.ts.map +0 -1
  32. package/dist/esm/spaces/GridSpace.js +0 -296
  33. package/dist/esm/spaces/GridSpace.js.map +0 -1
  34. package/dist/esm/spaces/WaypointGraph.d.ts +0 -79
  35. package/dist/esm/spaces/WaypointGraph.d.ts.map +0 -1
  36. package/dist/esm/spaces/WaypointGraph.js +0 -167
  37. package/dist/esm/spaces/WaypointGraph.js.map +0 -1
  38. package/dist/esm/spaces/gridGeometry.d.ts +0 -3
  39. package/dist/esm/spaces/gridGeometry.d.ts.map +0 -1
  40. package/dist/esm/spaces/gridGeometry.js +0 -40
  41. package/dist/esm/spaces/gridGeometry.js.map +0 -1
  42. package/dist/esm/types.d.ts +0 -182
  43. package/dist/esm/types.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,45 +1,13 @@
1
1
  # @codexo/exojs-pathfinding
2
2
 
3
- Weighted-grid and waypoint-graph path queries for ExoJS. Use it to find a route through your navigation model; movement, collision response, animation, and special traversal remain gameplay responsibilities.
3
+ Since ExoJS v0.20, import from @codexo/exojs/pathfinding. This package is a compatibility shim for the 0.20 line; no independent feature development.
4
4
 
5
- ## Install
5
+ Every export of this package is the very binding its Core entry exports, so code that still imports `@codexo/exojs-pathfinding` shares one engine instance with code that already imports `@codexo/exojs/pathfinding`. The package contains no implementation of its own and depends on nothing but its `@codexo/exojs` peer.
6
6
 
7
- ```sh
8
- npm install --save-exact @codexo/exojs @codexo/exojs-pathfinding
9
- ```
7
+ | Import | Replace with | Forwards |
8
+ | --- | --- | --- |
9
+ | `@codexo/exojs-pathfinding` | `@codexo/exojs/pathfinding` | everything |
10
10
 
11
- This is a directly used library. It has no application extension descriptor or global registration step.
11
+ ## Migrating
12
12
 
13
- ## Find a route on a grid
14
-
15
- ```ts
16
- import { GridSpace, Pathfinder } from '@codexo/exojs-pathfinding';
17
-
18
- const grid = GridSpace.from(12, 8, (x, y) => (x === 5 && y !== 4 ? 0 : 1), {
19
- cellSize: 32,
20
- });
21
- const pathfinder = new Pathfinder();
22
- const route = pathfinder.findPathBetween(grid, 16, 16, 336, 208);
23
-
24
- if (route.status === 'found') {
25
- console.log(route.points);
26
- }
27
- ```
28
-
29
- Zero-cost cells are blocked; positive costs describe traversal weight. `findPathBetween` takes the navigation space followed by the start and goal world coordinates, whereas node-oriented queries use navigation-node identifiers. Handle an unreachable or budget-limited result explicitly instead of moving along an assumed route.
30
-
31
- ## Choose the navigation model
32
-
33
- A grid is useful when occupancy and costs follow regular cells. A waypoint graph is useful for authored connections, directed travel, or sparse routes. An edge tagged as a ladder or teleport is metadata: the pathfinder does not animate climbing or execute the teleport.
34
-
35
- A path is valid for the navigation revision it was computed from. Update or rebuild the appropriate navigation data when obstacles or costs change, then invalidate stale results and in-flight searches. Repeated deterministic inputs in one controlled environment are useful for testing; do not infer cross-build or cross-machine lockstep guarantees from a fixed traversal order.
36
-
37
- Query budgets bound search work, not a guaranteed number of milliseconds. Keep planning separate from the controller that follows a path, and include the agent's clearance and collision policy in the navigation model rather than treating a line through walkable cells as a complete movement solution.
38
-
39
- ## Documentation
40
-
41
- [Grid pathfinding](https://exoridus.github.io/ExoJS/en/guide/pathfinding/grid-pathfinding/) · [Waypoint graphs](https://exoridus.github.io/ExoJS/en/guide/pathfinding/waypoint-graphs/) · [Pathfinder API](https://exoridus.github.io/ExoJS/en/api/pathfinder/)
42
-
43
- ## License
44
-
45
- MIT © Codexo
13
+ Change each import to the Core entry in the table, then remove this package with `npm uninstall @codexo/exojs-pathfinding`. `@codexo/exojs` already contains the module; there is nothing else to install. The migration guide on the ExoJS site lists every renamed import.
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@codexo/exojs/pathfinding';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@codexo/exojs/pathfinding';
package/package.json CHANGED
@@ -1,46 +1,38 @@
1
1
  {
2
2
  "name": "@codexo/exojs-pathfinding",
3
- "version": "0.19.1",
4
- "description": "Deterministic, allocation-free 2D pathfinding for ExoJS: A*, jump-point search, weighted grids and waypoint graphs.",
3
+ "version": "0.20.0",
4
+ "description": "Compatibility shim that forwards to @codexo/exojs/pathfinding. Since ExoJS v0.20, import from @codexo/exojs/pathfinding.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/Exoridus/ExoJS.git",
8
- "directory": "packages/exojs-pathfinding"
8
+ "directory": "packages/legacy/exojs-pathfinding"
9
9
  },
10
10
  "type": "module",
11
11
  "sideEffects": false,
12
- "main": "./dist/esm/index.js",
13
- "module": "./dist/esm/index.js",
14
- "types": "./dist/esm/index.d.ts",
12
+ "main": "./index.js",
13
+ "types": "./index.d.ts",
15
14
  "exports": {
16
15
  ".": {
17
- "types": "./dist/esm/index.d.ts",
18
- "import": "./dist/esm/index.js",
19
- "default": "./dist/esm/index.js"
16
+ "types": "./index.d.ts",
17
+ "import": "./index.js",
18
+ "default": "./index.js"
20
19
  },
21
20
  "./package.json": "./package.json"
22
21
  },
23
22
  "files": [
24
- "dist/esm/",
23
+ "index.js",
24
+ "index.d.ts",
25
25
  "README.md",
26
26
  "LICENSE"
27
27
  ],
28
28
  "peerDependencies": {
29
- "@codexo/exojs": "0.19.x"
29
+ "@codexo/exojs": "0.20.x"
30
30
  },
31
31
  "devDependencies": {
32
- "@codexo/exojs": "0.19.1",
33
- "@codexo/exojs-config": "0.0.0"
32
+ "@codexo/exojs": "0.20.0"
34
33
  },
35
34
  "license": "MIT",
36
35
  "publishConfig": {
37
36
  "access": "public"
38
- },
39
- "scripts": {
40
- "build": "tsx ../../scripts/build-extension.ts",
41
- "build:dev": "tsx ../../scripts/build-extension.ts --dev",
42
- "typecheck": "exo-tsc --noEmit && exo-tsc --noEmit -p tsconfig.test.json",
43
- "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
44
- "test": "vitest run --root ../.. --project=exojs-pathfinding"
45
37
  }
46
38
  }
@@ -1,50 +0,0 @@
1
- import type { FindPathOptions, FloodOptions, FloodRegion, NavigationSpace, PathResult } from './types';
2
- /**
3
- * Runs path queries against any {@link NavigationSpace}.
4
- *
5
- * One pathfinder owns the search buffers and reuses them across every query,
6
- * including queries against different spaces of different sizes, so a search
7
- * itself allocates nothing once the buffers have reached their size. The result
8
- * objects are freshly allocated by design: callers hold on to a path, and
9
- * pooling something a caller retains trades a little garbage for use-after-reuse
10
- * bugs.
11
- *
12
- * A pathfinder holds no world state and no lifecycle - construct one per system
13
- * that needs paths, or share one, as long as queries do not interleave with a
14
- * mutation of the space being searched.
15
- */
16
- export declare class Pathfinder {
17
- private readonly state;
18
- private readonly reversed;
19
- /**
20
- * Finds a cost-optimal path between two node ids.
21
- *
22
- * `unreachable` yields an empty path unless {@link FindPathOptions.snapToNearest}
23
- * is set; `budget-exceeded` always carries the best partial path found, which
24
- * is a real, traversable prefix and not a guess at the rest.
25
- */
26
- findPath<Payload>(space: NavigationSpace<Payload>, start: number, goal: number, options?: FindPathOptions): PathResult<Payload>;
27
- /**
28
- * {@link findPath} between two points instead of node ids. A point outside the
29
- * space makes the query `unreachable` unless
30
- * {@link FindPathOptions.snapToNearest} is set and the space can resolve a
31
- * nearest node.
32
- */
33
- findPathBetween<Payload>(space: NavigationSpace<Payload>, startX: number, startY: number, goalX: number, goalY: number, options?: FindPathOptions): PathResult<Payload>;
34
- /**
35
- * Every node reachable from `origin` within {@link FloodOptions.maxCost}, with
36
- * its cost - the "tiles I can still move to this turn" query, and the input a
37
- * flow field for many agents heading to one goal is built from.
38
- */
39
- floodFrom(space: NavigationSpace, origin: number, options?: FloodOptions): FloodRegion;
40
- private resolve;
41
- /**
42
- * Walks the parent chain back from `end` and writes it forwards into `out`.
43
- * With a pruned expansion the chain holds jump points only, so each hop is
44
- * handed back to the expansion to fill in the run it skipped.
45
- */
46
- private reconstruct;
47
- private toPoints;
48
- private toEdges;
49
- }
50
- //# sourceMappingURL=Pathfinder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Pathfinder.d.ts","sourceRoot":"","sources":["../../src/Pathfinder.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAY,UAAU,EAAmB,MAAM,SAAS,CAAC;AAMlI;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAEzC;;;;;;OAMG;IACI,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,UAAU,CAAC,OAAO,CAAC,CAwDzI;IAED;;;;;OAKG;IACI,eAAe,CAAC,OAAO,EAC5B,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,EAC/B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAAoB,GAC5B,UAAU,CAAC,OAAO,CAAC,CAkBrB;IAED;;;;OAIG;IACI,SAAS,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CAShG;IAED,OAAO,CAAC,OAAO;IAQf;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,OAAO;CAahB"}
@@ -1,151 +0,0 @@
1
- import { runFlood, runSearch } from "./core/search.js";
2
- import { SearchState } from "./core/SearchState.js";
3
- import { Vector } from "@codexo/exojs";
4
-
5
- //#region src/Pathfinder.ts
6
- const EMPTY_NODES = Object.freeze([]);
7
- const EMPTY_POINTS = Object.freeze([]);
8
- const EMPTY_EDGES = Object.freeze([]);
9
- /**
10
- * Runs path queries against any {@link NavigationSpace}.
11
- *
12
- * One pathfinder owns the search buffers and reuses them across every query,
13
- * including queries against different spaces of different sizes, so a search
14
- * itself allocates nothing once the buffers have reached their size. The result
15
- * objects are freshly allocated by design: callers hold on to a path, and
16
- * pooling something a caller retains trades a little garbage for use-after-reuse
17
- * bugs.
18
- *
19
- * A pathfinder holds no world state and no lifecycle - construct one per system
20
- * that needs paths, or share one, as long as queries do not interleave with a
21
- * mutation of the space being searched.
22
- */
23
- var Pathfinder = class {
24
- state = new SearchState();
25
- reversed = [];
26
- /**
27
- * Finds a cost-optimal path between two node ids.
28
- *
29
- * `unreachable` yields an empty path unless {@link FindPathOptions.snapToNearest}
30
- * is set; `budget-exceeded` always carries the best partial path found, which
31
- * is a real, traversable prefix and not a guess at the rest.
32
- */
33
- findPath(space, start, goal, options = {}) {
34
- const agentSize = options.agentSize ?? 1;
35
- const budget = options.maxExpandedNodes ?? 0;
36
- const snapToNearest = options.snapToNearest === true;
37
- this.state.reserve(space.nodeCapacity, space.maxDegree);
38
- let expansion = options.pruning === false || space.pruning === void 0 ? null : space.pruning(agentSize);
39
- let outcome = runSearch(this.state, space, start, goal, agentSize, budget, expansion);
40
- if (outcome.status === "unreachable" && snapToNearest && expansion !== null) {
41
- expansion = null;
42
- outcome = runSearch(this.state, space, start, goal, agentSize, budget, null);
43
- }
44
- const snapped = outcome.status === "unreachable" && snapToNearest;
45
- if (outcome.status === "unreachable" && !snapped) return {
46
- status: "unreachable",
47
- nodes: EMPTY_NODES,
48
- points: EMPTY_POINTS,
49
- edges: EMPTY_EDGES,
50
- cost: 0,
51
- revision: space.revision,
52
- expandedNodes: outcome.expandedNodes
53
- };
54
- const nodes = [];
55
- this.reconstruct(outcome.endNode, expansion, nodes);
56
- let path = nodes;
57
- let smoothed = false;
58
- if (options.smooth === true && space.smoothPath !== void 0) {
59
- path = space.smoothPath(nodes, agentSize);
60
- smoothed = true;
61
- }
62
- return {
63
- status: snapped ? "found" : outcome.status,
64
- nodes: path,
65
- points: this.toPoints(space, path),
66
- edges: smoothed ? EMPTY_EDGES : this.toEdges(space, path),
67
- cost: outcome.cost,
68
- revision: space.revision,
69
- expandedNodes: outcome.expandedNodes
70
- };
71
- }
72
- /**
73
- * {@link findPath} between two points instead of node ids. A point outside the
74
- * space makes the query `unreachable` unless
75
- * {@link FindPathOptions.snapToNearest} is set and the space can resolve a
76
- * nearest node.
77
- */
78
- findPathBetween(space, startX, startY, goalX, goalY, options = {}) {
79
- const snap = options.snapToNearest === true;
80
- const start = this.resolve(space, startX, startY, snap);
81
- const goal = this.resolve(space, goalX, goalY, snap);
82
- if (start < 0 || goal < 0) return {
83
- status: "unreachable",
84
- nodes: EMPTY_NODES,
85
- points: EMPTY_POINTS,
86
- edges: EMPTY_EDGES,
87
- cost: 0,
88
- revision: space.revision,
89
- expandedNodes: 0
90
- };
91
- return this.findPath(space, start, goal, options);
92
- }
93
- /**
94
- * Every node reachable from `origin` within {@link FloodOptions.maxCost}, with
95
- * its cost - the "tiles I can still move to this turn" query, and the input a
96
- * flow field for many agents heading to one goal is built from.
97
- */
98
- floodFrom(space, origin, options = {}) {
99
- const nodes = [];
100
- const costs = [];
101
- this.state.reserve(space.nodeCapacity, space.maxDegree);
102
- const expandedNodes = runFlood(this.state, space, origin, options.agentSize ?? 1, options.maxCost ?? Infinity, options.maxExpandedNodes ?? 0, nodes, costs);
103
- return {
104
- nodes,
105
- costs,
106
- revision: space.revision,
107
- expandedNodes
108
- };
109
- }
110
- resolve(space, x, y, snap) {
111
- const node = space.pointToNode(x, y);
112
- if (node >= 0 || !snap || space.nearestNode === void 0) return node;
113
- return space.nearestNode(x, y);
114
- }
115
- /**
116
- * Walks the parent chain back from `end` and writes it forwards into `out`.
117
- * With a pruned expansion the chain holds jump points only, so each hop is
118
- * handed back to the expansion to fill in the run it skipped.
119
- */
120
- reconstruct(end, expansion, out) {
121
- const { reversed } = this;
122
- const { parent } = this.state;
123
- reversed.length = 0;
124
- for (let node = end; node >= 0; node = parent[node]) reversed.push(node);
125
- out.push(reversed[reversed.length - 1]);
126
- for (let index = reversed.length - 2; index >= 0; index--) if (expansion === null) out.push(reversed[index]);
127
- else expansion.expand(reversed[index + 1], reversed[index], out);
128
- }
129
- toPoints(space, nodes) {
130
- const points = [];
131
- for (let index = 0; index < nodes.length; index++) {
132
- const point = new Vector();
133
- space.nodeToPoint(nodes[index], point);
134
- points.push(point);
135
- }
136
- return points;
137
- }
138
- toEdges(space, nodes) {
139
- if (space.describeEdge === void 0) return EMPTY_EDGES;
140
- const edges = [];
141
- for (let index = 1; index < nodes.length; index++) {
142
- const edge = space.describeEdge(nodes[index - 1], nodes[index]);
143
- if (edge !== null) edges.push(edge);
144
- }
145
- return edges;
146
- }
147
- };
148
-
149
- //#endregion
150
- export { Pathfinder };
151
- //# sourceMappingURL=Pathfinder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Pathfinder.js","names":[],"sources":["../../src/Pathfinder.ts"],"sourcesContent":["import { Vector } from '@codexo/exojs';\n\nimport { runFlood, runSearch } from './core/search';\nimport { SearchState } from './core/SearchState';\nimport type { FindPathOptions, FloodOptions, FloodRegion, NavigationSpace, PathEdge, PathResult, PrunedExpansion } from './types';\n\nconst EMPTY_NODES: readonly number[] = Object.freeze([]);\nconst EMPTY_POINTS: readonly Vector[] = Object.freeze([]);\nconst EMPTY_EDGES: ReadonlyArray<PathEdge<never>> = Object.freeze([]);\n\n/**\n * Runs path queries against any {@link NavigationSpace}.\n *\n * One pathfinder owns the search buffers and reuses them across every query,\n * including queries against different spaces of different sizes, so a search\n * itself allocates nothing once the buffers have reached their size. The result\n * objects are freshly allocated by design: callers hold on to a path, and\n * pooling something a caller retains trades a little garbage for use-after-reuse\n * bugs.\n *\n * A pathfinder holds no world state and no lifecycle - construct one per system\n * that needs paths, or share one, as long as queries do not interleave with a\n * mutation of the space being searched.\n */\nexport class Pathfinder {\n private readonly state = new SearchState();\n private readonly reversed: number[] = [];\n\n /**\n * Finds a cost-optimal path between two node ids.\n *\n * `unreachable` yields an empty path unless {@link FindPathOptions.snapToNearest}\n * is set; `budget-exceeded` always carries the best partial path found, which\n * is a real, traversable prefix and not a guess at the rest.\n */\n public findPath<Payload>(space: NavigationSpace<Payload>, start: number, goal: number, options: FindPathOptions = {}): PathResult<Payload> {\n const agentSize = options.agentSize ?? 1;\n const budget = options.maxExpandedNodes ?? 0;\n const snapToNearest = options.snapToNearest === true;\n\n this.state.reserve(space.nodeCapacity, space.maxDegree);\n\n let expansion = options.pruning === false || space.pruning === undefined ? null : space.pruning(agentSize);\n let outcome = runSearch(this.state, space, start, goal, agentSize, budget, expansion);\n\n // A pruned expansion only ever settles jump points, so the closest node it\n // can name is a jump point and not the nearest reachable one. Re-running\n // unpruned costs a second search, but only on the path where the first one\n // already failed to reach the goal.\n if (outcome.status === 'unreachable' && snapToNearest && expansion !== null) {\n expansion = null;\n outcome = runSearch(this.state, space, start, goal, agentSize, budget, null);\n }\n\n const snapped = outcome.status === 'unreachable' && snapToNearest;\n\n if (outcome.status === 'unreachable' && !snapped) {\n return {\n status: 'unreachable',\n nodes: EMPTY_NODES,\n points: EMPTY_POINTS,\n edges: EMPTY_EDGES,\n cost: 0,\n revision: space.revision,\n expandedNodes: outcome.expandedNodes,\n };\n }\n\n const nodes: number[] = [];\n\n this.reconstruct(outcome.endNode, expansion, nodes);\n\n let path = nodes;\n let smoothed = false;\n\n if (options.smooth === true && space.smoothPath !== undefined) {\n path = space.smoothPath(nodes, agentSize);\n smoothed = true;\n }\n\n return {\n status: snapped ? 'found' : outcome.status,\n nodes: path,\n points: this.toPoints(space, path),\n // A smoothed path no longer steps along space edges, so there is nothing\n // truthful to report for it.\n edges: smoothed ? EMPTY_EDGES : this.toEdges(space, path),\n cost: outcome.cost,\n revision: space.revision,\n expandedNodes: outcome.expandedNodes,\n };\n }\n\n /**\n * {@link findPath} between two points instead of node ids. A point outside the\n * space makes the query `unreachable` unless\n * {@link FindPathOptions.snapToNearest} is set and the space can resolve a\n * nearest node.\n */\n public findPathBetween<Payload>(\n space: NavigationSpace<Payload>,\n startX: number,\n startY: number,\n goalX: number,\n goalY: number,\n options: FindPathOptions = {},\n ): PathResult<Payload> {\n const snap = options.snapToNearest === true;\n const start = this.resolve(space, startX, startY, snap);\n const goal = this.resolve(space, goalX, goalY, snap);\n\n if (start < 0 || goal < 0) {\n return {\n status: 'unreachable',\n nodes: EMPTY_NODES,\n points: EMPTY_POINTS,\n edges: EMPTY_EDGES,\n cost: 0,\n revision: space.revision,\n expandedNodes: 0,\n };\n }\n\n return this.findPath(space, start, goal, options);\n }\n\n /**\n * Every node reachable from `origin` within {@link FloodOptions.maxCost}, with\n * its cost - the \"tiles I can still move to this turn\" query, and the input a\n * flow field for many agents heading to one goal is built from.\n */\n public floodFrom(space: NavigationSpace, origin: number, options: FloodOptions = {}): FloodRegion {\n const nodes: number[] = [];\n const costs: number[] = [];\n\n this.state.reserve(space.nodeCapacity, space.maxDegree);\n\n const expandedNodes = runFlood(this.state, space, origin, options.agentSize ?? 1, options.maxCost ?? Infinity, options.maxExpandedNodes ?? 0, nodes, costs);\n\n return { nodes, costs, revision: space.revision, expandedNodes };\n }\n\n private resolve(space: NavigationSpace, x: number, y: number, snap: boolean): number {\n const node = space.pointToNode(x, y);\n\n if (node >= 0 || !snap || space.nearestNode === undefined) return node;\n\n return space.nearestNode(x, y);\n }\n\n /**\n * Walks the parent chain back from `end` and writes it forwards into `out`.\n * With a pruned expansion the chain holds jump points only, so each hop is\n * handed back to the expansion to fill in the run it skipped.\n */\n private reconstruct(end: number, expansion: PrunedExpansion | null, out: number[]): void {\n const { reversed } = this;\n const { parent } = this.state;\n\n reversed.length = 0;\n\n for (let node = end; node >= 0; node = parent[node]!) {\n reversed.push(node);\n }\n\n out.push(reversed[reversed.length - 1]!);\n\n for (let index = reversed.length - 2; index >= 0; index--) {\n if (expansion === null) out.push(reversed[index]!);\n else expansion.expand(reversed[index + 1]!, reversed[index]!, out);\n }\n }\n\n private toPoints(space: NavigationSpace, nodes: readonly number[]): Vector[] {\n const points: Vector[] = [];\n\n for (let index = 0; index < nodes.length; index++) {\n const point = new Vector();\n\n space.nodeToPoint(nodes[index]!, point);\n points.push(point);\n }\n\n return points;\n }\n\n private toEdges<Payload>(space: NavigationSpace<Payload>, nodes: readonly number[]): ReadonlyArray<PathEdge<Payload>> {\n if (space.describeEdge === undefined) return EMPTY_EDGES;\n\n const edges: Array<PathEdge<Payload>> = [];\n\n for (let index = 1; index < nodes.length; index++) {\n const edge = space.describeEdge(nodes[index - 1]!, nodes[index]!);\n\n if (edge !== null) edges.push(edge);\n }\n\n return edges;\n }\n}\n"],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=BinaryHeap.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BinaryHeap.d.ts","sourceRoot":"","sources":["../../../src/core/BinaryHeap.ts"],"names":[],"mappings":""}
@@ -1,90 +0,0 @@
1
- //#region src/core/BinaryHeap.ts
2
- /**
3
- * Min-heap of `(key, node)` pairs over two parallel typed arrays.
4
- *
5
- * Ties on `key` are broken by the lower node id, which is what makes a search
6
- * reproducible: equal-f nodes come off the open list in the same order on every
7
- * platform and every run, so two identical queries return the identical path
8
- * rather than an arbitrary member of the optimal set.
9
- *
10
- * The heap grows by doubling and never shrinks, so a pathfinder that has run
11
- * once at a given problem size does not allocate here again.
12
- *
13
- * @internal
14
- */
15
- var BinaryHeap = class {
16
- nodes;
17
- keys;
18
- count = 0;
19
- constructor(capacity = 64) {
20
- this.nodes = new Int32Array(capacity);
21
- this.keys = new Float64Array(capacity);
22
- }
23
- get size() {
24
- return this.count;
25
- }
26
- clear() {
27
- this.count = 0;
28
- }
29
- push(node, key) {
30
- if (this.count === this.nodes.length) this.grow();
31
- let index = this.count++;
32
- this.nodes[index] = node;
33
- this.keys[index] = key;
34
- while (index > 0) {
35
- const parent = index - 1 >> 1;
36
- if (!this.less(index, parent)) break;
37
- this.swap(index, parent);
38
- index = parent;
39
- }
40
- }
41
- /** Removes and returns the minimum node. The heap must not be empty. */
42
- pop() {
43
- const top = this.nodes[0];
44
- const last = --this.count;
45
- if (last > 0) {
46
- this.nodes[0] = this.nodes[last];
47
- this.keys[0] = this.keys[last];
48
- this.sink();
49
- }
50
- return top;
51
- }
52
- less(a, b) {
53
- const keyA = this.keys[a];
54
- const keyB = this.keys[b];
55
- if (keyA !== keyB) return keyA < keyB;
56
- return this.nodes[a] < this.nodes[b];
57
- }
58
- swap(a, b) {
59
- const node = this.nodes[a];
60
- const key = this.keys[a];
61
- this.nodes[a] = this.nodes[b];
62
- this.keys[a] = this.keys[b];
63
- this.nodes[b] = node;
64
- this.keys[b] = key;
65
- }
66
- sink() {
67
- let index = 0;
68
- for (;;) {
69
- const left = index * 2 + 1;
70
- if (left >= this.count) break;
71
- const right = left + 1;
72
- const child = right < this.count && this.less(right, left) ? right : left;
73
- if (!this.less(child, index)) break;
74
- this.swap(index, child);
75
- index = child;
76
- }
77
- }
78
- grow() {
79
- const nodes = new Int32Array(this.nodes.length * 2);
80
- const keys = new Float64Array(this.keys.length * 2);
81
- nodes.set(this.nodes);
82
- keys.set(this.keys);
83
- this.nodes = nodes;
84
- this.keys = keys;
85
- }
86
- };
87
-
88
- //#endregion
89
- export { BinaryHeap };
90
- //# sourceMappingURL=BinaryHeap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BinaryHeap.js","names":[],"sources":["../../../src/core/BinaryHeap.ts"],"sourcesContent":["/**\n * Min-heap of `(key, node)` pairs over two parallel typed arrays.\n *\n * Ties on `key` are broken by the lower node id, which is what makes a search\n * reproducible: equal-f nodes come off the open list in the same order on every\n * platform and every run, so two identical queries return the identical path\n * rather than an arbitrary member of the optimal set.\n *\n * The heap grows by doubling and never shrinks, so a pathfinder that has run\n * once at a given problem size does not allocate here again.\n *\n * @internal\n */\nexport class BinaryHeap {\n private nodes: Int32Array;\n private keys: Float64Array;\n private count = 0;\n\n public constructor(capacity = 64) {\n this.nodes = new Int32Array(capacity);\n this.keys = new Float64Array(capacity);\n }\n\n public get size(): number {\n return this.count;\n }\n\n public clear(): void {\n this.count = 0;\n }\n\n public push(node: number, key: number): void {\n if (this.count === this.nodes.length) this.grow();\n\n let index = this.count++;\n\n this.nodes[index] = node;\n this.keys[index] = key;\n\n while (index > 0) {\n const parent = (index - 1) >> 1;\n\n if (!this.less(index, parent)) break;\n\n this.swap(index, parent);\n index = parent;\n }\n }\n\n /** Removes and returns the minimum node. The heap must not be empty. */\n public pop(): number {\n const top = this.nodes[0]!;\n const last = --this.count;\n\n if (last > 0) {\n this.nodes[0] = this.nodes[last]!;\n this.keys[0] = this.keys[last]!;\n this.sink();\n }\n\n return top;\n }\n\n private less(a: number, b: number): boolean {\n const keyA = this.keys[a]!;\n const keyB = this.keys[b]!;\n\n if (keyA !== keyB) return keyA < keyB;\n\n return this.nodes[a]! < this.nodes[b]!;\n }\n\n private swap(a: number, b: number): void {\n const node = this.nodes[a]!;\n const key = this.keys[a]!;\n\n this.nodes[a] = this.nodes[b]!;\n this.keys[a] = this.keys[b]!;\n this.nodes[b] = node;\n this.keys[b] = key;\n }\n\n private sink(): void {\n let index = 0;\n\n for (;;) {\n const left = index * 2 + 1;\n\n if (left >= this.count) break;\n\n const right = left + 1;\n const child = right < this.count && this.less(right, left) ? right : left;\n\n if (!this.less(child, index)) break;\n\n this.swap(index, child);\n index = child;\n }\n }\n\n private grow(): void {\n const nodes = new Int32Array(this.nodes.length * 2);\n const keys = new Float64Array(this.keys.length * 2);\n\n nodes.set(this.nodes);\n keys.set(this.keys);\n\n this.nodes = nodes;\n this.keys = keys;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,IAAa,aAAb,MAAwB;CACtB,AAAQ;CACR,AAAQ;CACR,AAAQ,QAAQ;CAEhB,AAAO,YAAY,WAAW,IAAI;EAChC,KAAK,QAAQ,IAAI,WAAW,QAAQ;EACpC,KAAK,OAAO,IAAI,aAAa,QAAQ;CACvC;CAEA,IAAW,OAAe;EACxB,OAAO,KAAK;CACd;CAEA,AAAO,QAAc;EACnB,KAAK,QAAQ;CACf;CAEA,AAAO,KAAK,MAAc,KAAmB;EAC3C,IAAI,KAAK,UAAU,KAAK,MAAM,QAAQ,KAAK,KAAK;EAEhD,IAAI,QAAQ,KAAK;EAEjB,KAAK,MAAM,SAAS;EACpB,KAAK,KAAK,SAAS;EAEnB,OAAO,QAAQ,GAAG;GAChB,MAAM,SAAU,QAAQ,KAAM;GAE9B,IAAI,CAAC,KAAK,KAAK,OAAO,MAAM,GAAG;GAE/B,KAAK,KAAK,OAAO,MAAM;GACvB,QAAQ;EACV;CACF;;CAGA,AAAO,MAAc;EACnB,MAAM,MAAM,KAAK,MAAM;EACvB,MAAM,OAAO,EAAE,KAAK;EAEpB,IAAI,OAAO,GAAG;GACZ,KAAK,MAAM,KAAK,KAAK,MAAM;GAC3B,KAAK,KAAK,KAAK,KAAK,KAAK;GACzB,KAAK,KAAK;EACZ;EAEA,OAAO;CACT;CAEA,AAAQ,KAAK,GAAW,GAAoB;EAC1C,MAAM,OAAO,KAAK,KAAK;EACvB,MAAM,OAAO,KAAK,KAAK;EAEvB,IAAI,SAAS,MAAM,OAAO,OAAO;EAEjC,OAAO,KAAK,MAAM,KAAM,KAAK,MAAM;CACrC;CAEA,AAAQ,KAAK,GAAW,GAAiB;EACvC,MAAM,OAAO,KAAK,MAAM;EACxB,MAAM,MAAM,KAAK,KAAK;EAEtB,KAAK,MAAM,KAAK,KAAK,MAAM;EAC3B,KAAK,KAAK,KAAK,KAAK,KAAK;EACzB,KAAK,MAAM,KAAK;EAChB,KAAK,KAAK,KAAK;CACjB;CAEA,AAAQ,OAAa;EACnB,IAAI,QAAQ;EAEZ,SAAS;GACP,MAAM,OAAO,QAAQ,IAAI;GAEzB,IAAI,QAAQ,KAAK,OAAO;GAExB,MAAM,QAAQ,OAAO;GACrB,MAAM,QAAQ,QAAQ,KAAK,SAAS,KAAK,KAAK,OAAO,IAAI,IAAI,QAAQ;GAErE,IAAI,CAAC,KAAK,KAAK,OAAO,KAAK,GAAG;GAE9B,KAAK,KAAK,OAAO,KAAK;GACtB,QAAQ;EACV;CACF;CAEA,AAAQ,OAAa;EACnB,MAAM,QAAQ,IAAI,WAAW,KAAK,MAAM,SAAS,CAAC;EAClD,MAAM,OAAO,IAAI,aAAa,KAAK,KAAK,SAAS,CAAC;EAElD,MAAM,IAAI,KAAK,KAAK;EACpB,KAAK,IAAI,KAAK,IAAI;EAElB,KAAK,QAAQ;EACb,KAAK,OAAO;CACd;AACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=SearchState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SearchState.d.ts","sourceRoot":"","sources":["../../../src/core/SearchState.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
1
- import { BinaryHeap } from "./BinaryHeap.js";
2
-
3
- //#region src/core/SearchState.ts
4
- /** Largest generation stamp before the counter has to wrap. */
5
- const MAX_GENERATION = 4294967295;
6
- /**
7
- * Reusable per-search bookkeeping: g-scores, parent links, the closed set, the
8
- * open list and the neighbour scratch buffers.
9
- *
10
- * Nothing is cleared between searches. A node's g-score, parent and closed flag
11
- * count only while its generation stamp matches the current one, so starting a
12
- * search is a single counter increment instead of an O(nodeCapacity) wipe. That
13
- * is what lets one pathfinder serve interleaved queries over several spaces of
14
- * different sizes without touching memory it does not visit.
15
- *
16
- * @internal
17
- */
18
- var SearchState = class {
19
- gScore = /* @__PURE__ */ new Float64Array(0);
20
- parent = /* @__PURE__ */ new Int32Array(0);
21
- closed = /* @__PURE__ */ new Uint8Array(0);
22
- neighborNodes = /* @__PURE__ */ new Int32Array(0);
23
- neighborCosts = /* @__PURE__ */ new Float64Array(0);
24
- heap = new BinaryHeap();
25
- stamp = /* @__PURE__ */ new Uint32Array(0);
26
- generation = 0;
27
- /** Grows the buffers to fit a space, keeping the generation stamps valid. */
28
- reserve(nodeCapacity, degree) {
29
- if (nodeCapacity > this.gScore.length) {
30
- const stamp = new Uint32Array(nodeCapacity);
31
- stamp.set(this.stamp);
32
- this.gScore = new Float64Array(nodeCapacity);
33
- this.parent = new Int32Array(nodeCapacity);
34
- this.closed = new Uint8Array(nodeCapacity);
35
- this.stamp = stamp;
36
- }
37
- if (degree > this.neighborNodes.length) {
38
- this.neighborNodes = new Int32Array(degree);
39
- this.neighborCosts = new Float64Array(degree);
40
- }
41
- }
42
- begin() {
43
- if (this.generation === MAX_GENERATION) {
44
- this.stamp.fill(0);
45
- this.generation = 0;
46
- }
47
- this.generation++;
48
- this.heap.clear();
49
- }
50
- /**
51
- * Brings a node into the current search, resetting it on first touch.
52
- * Returns `true` when the node was already part of this search.
53
- */
54
- touch(node) {
55
- if (this.stamp[node] === this.generation) return true;
56
- this.stamp[node] = this.generation;
57
- this.gScore[node] = Infinity;
58
- this.parent[node] = -1;
59
- this.closed[node] = 0;
60
- return false;
61
- }
62
- };
63
-
64
- //#endregion
65
- export { SearchState };
66
- //# sourceMappingURL=SearchState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SearchState.js","names":[],"sources":["../../../src/core/SearchState.ts"],"sourcesContent":["import { BinaryHeap } from './BinaryHeap';\n\n/** Largest generation stamp before the counter has to wrap. */\nconst MAX_GENERATION = 0xffffffff;\n\n/**\n * Reusable per-search bookkeeping: g-scores, parent links, the closed set, the\n * open list and the neighbour scratch buffers.\n *\n * Nothing is cleared between searches. A node's g-score, parent and closed flag\n * count only while its generation stamp matches the current one, so starting a\n * search is a single counter increment instead of an O(nodeCapacity) wipe. That\n * is what lets one pathfinder serve interleaved queries over several spaces of\n * different sizes without touching memory it does not visit.\n *\n * @internal\n */\nexport class SearchState {\n public gScore = new Float64Array(0);\n public parent = new Int32Array(0);\n public closed = new Uint8Array(0);\n public neighborNodes = new Int32Array(0);\n public neighborCosts = new Float64Array(0);\n public readonly heap = new BinaryHeap();\n\n private stamp = new Uint32Array(0);\n private generation = 0;\n\n /** Grows the buffers to fit a space, keeping the generation stamps valid. */\n public reserve(nodeCapacity: number, degree: number): void {\n if (nodeCapacity > this.gScore.length) {\n const stamp = new Uint32Array(nodeCapacity);\n\n stamp.set(this.stamp);\n\n this.gScore = new Float64Array(nodeCapacity);\n this.parent = new Int32Array(nodeCapacity);\n this.closed = new Uint8Array(nodeCapacity);\n this.stamp = stamp;\n }\n\n if (degree > this.neighborNodes.length) {\n this.neighborNodes = new Int32Array(degree);\n this.neighborCosts = new Float64Array(degree);\n }\n }\n\n public begin(): void {\n if (this.generation === MAX_GENERATION) {\n this.stamp.fill(0);\n this.generation = 0;\n }\n\n this.generation++;\n this.heap.clear();\n }\n\n /**\n * Brings a node into the current search, resetting it on first touch.\n * Returns `true` when the node was already part of this search.\n */\n public touch(node: number): boolean {\n if (this.stamp[node] === this.generation) return true;\n\n this.stamp[node] = this.generation;\n this.gScore[node] = Infinity;\n this.parent[node] = -1;\n this.closed[node] = 0;\n\n return false;\n }\n}\n"],"mappings":";;;;AAGA,MAAM,iBAAiB;;;;;;;;;;;;;AAcvB,IAAa,cAAb,MAAyB;CACvB,AAAO,yBAAS,IAAI,aAAa,CAAC;CAClC,AAAO,yBAAS,IAAI,WAAW,CAAC;CAChC,AAAO,yBAAS,IAAI,WAAW,CAAC;CAChC,AAAO,gCAAgB,IAAI,WAAW,CAAC;CACvC,AAAO,gCAAgB,IAAI,aAAa,CAAC;CACzC,AAAgB,OAAO,IAAI,WAAW;CAEtC,AAAQ,wBAAQ,IAAI,YAAY,CAAC;CACjC,AAAQ,aAAa;;CAGrB,AAAO,QAAQ,cAAsB,QAAsB;EACzD,IAAI,eAAe,KAAK,OAAO,QAAQ;GACrC,MAAM,QAAQ,IAAI,YAAY,YAAY;GAE1C,MAAM,IAAI,KAAK,KAAK;GAEpB,KAAK,SAAS,IAAI,aAAa,YAAY;GAC3C,KAAK,SAAS,IAAI,WAAW,YAAY;GACzC,KAAK,SAAS,IAAI,WAAW,YAAY;GACzC,KAAK,QAAQ;EACf;EAEA,IAAI,SAAS,KAAK,cAAc,QAAQ;GACtC,KAAK,gBAAgB,IAAI,WAAW,MAAM;GAC1C,KAAK,gBAAgB,IAAI,aAAa,MAAM;EAC9C;CACF;CAEA,AAAO,QAAc;EACnB,IAAI,KAAK,eAAe,gBAAgB;GACtC,KAAK,MAAM,KAAK,CAAC;GACjB,KAAK,aAAa;EACpB;EAEA,KAAK;EACL,KAAK,KAAK,MAAM;CAClB;;;;;CAMA,AAAO,MAAM,MAAuB;EAClC,IAAI,KAAK,MAAM,UAAU,KAAK,YAAY,OAAO;EAEjD,KAAK,MAAM,QAAQ,KAAK;EACxB,KAAK,OAAO,QAAQ;EACpB,KAAK,OAAO,QAAQ;EACpB,KAAK,OAAO,QAAQ;EAEpB,OAAO;CACT;AACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=search.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/core/search.ts"],"names":[],"mappings":""}
@@ -1,106 +0,0 @@
1
- //#region src/core/search.ts
2
- /**
3
- * A* over a {@link NavigationSpace}, with an optional pruned expansion.
4
- *
5
- * Successors come either from `space.neighbors` or, when `expansion` is given,
6
- * from a parent-dependent pruned generator. Both feed the same relaxation, so
7
- * jump-point search is not a second solver: it is the same A* over a smaller
8
- * successor set.
9
- *
10
- * `endNode` is the goal on success and otherwise the reachable node with the
11
- * lowest heuristic, which is what makes both a budget-exceeded result and a
12
- * snapped result a real path rather than an empty one.
13
- *
14
- * @internal
15
- */
16
- const runSearch = (state, space, start, goal, agentSize, maxExpandedNodes, expansion) => {
17
- const { gScore, parent, closed, neighborNodes, neighborCosts, heap } = state;
18
- state.begin();
19
- state.touch(start);
20
- gScore[start] = 0;
21
- let bestNode = start;
22
- let bestHeuristic = space.heuristic(start, goal);
23
- let expandedNodes = 0;
24
- heap.push(start, bestHeuristic);
25
- while (heap.size > 0) {
26
- const node = heap.pop();
27
- if (closed[node] === 1) continue;
28
- closed[node] = 1;
29
- expandedNodes++;
30
- if (node === goal) return {
31
- status: "found",
32
- endNode: goal,
33
- cost: gScore[goal],
34
- expandedNodes
35
- };
36
- const heuristic = space.heuristic(node, goal);
37
- if (heuristic < bestHeuristic) {
38
- bestHeuristic = heuristic;
39
- bestNode = node;
40
- }
41
- if (maxExpandedNodes > 0 && expandedNodes >= maxExpandedNodes) return {
42
- status: "budget-exceeded",
43
- endNode: bestNode,
44
- cost: gScore[bestNode],
45
- expandedNodes
46
- };
47
- const count = expansion === null ? space.neighbors(node, agentSize, neighborNodes, neighborCosts) : expansion.successors(node, parent[node], goal, neighborNodes, neighborCosts);
48
- const nodeCost = gScore[node];
49
- for (let i = 0; i < count; i++) {
50
- const next = neighborNodes[i];
51
- state.touch(next);
52
- if (closed[next] === 1) continue;
53
- const tentative = nodeCost + neighborCosts[i];
54
- if (tentative >= gScore[next]) continue;
55
- gScore[next] = tentative;
56
- parent[next] = node;
57
- heap.push(next, tentative + space.heuristic(next, goal));
58
- }
59
- }
60
- return {
61
- status: "unreachable",
62
- endNode: bestNode,
63
- cost: gScore[bestNode],
64
- expandedNodes
65
- };
66
- };
67
- /**
68
- * Dijkstra flood from `origin`, appending every settled node and its cost to
69
- * the output arrays in settle order.
70
- *
71
- * @internal
72
- */
73
- const runFlood = (state, space, origin, agentSize, maxCost, maxExpandedNodes, outNodes, outCosts) => {
74
- const { gScore, closed, neighborNodes, neighborCosts, heap } = state;
75
- state.begin();
76
- state.touch(origin);
77
- gScore[origin] = 0;
78
- heap.push(origin, 0);
79
- let expandedNodes = 0;
80
- while (heap.size > 0) {
81
- const node = heap.pop();
82
- if (closed[node] === 1) continue;
83
- const cost = gScore[node];
84
- if (cost > maxCost) break;
85
- closed[node] = 1;
86
- expandedNodes++;
87
- outNodes.push(node);
88
- outCosts.push(cost);
89
- if (maxExpandedNodes > 0 && expandedNodes >= maxExpandedNodes) break;
90
- const count = space.neighbors(node, agentSize, neighborNodes, neighborCosts);
91
- for (let i = 0; i < count; i++) {
92
- const next = neighborNodes[i];
93
- state.touch(next);
94
- if (closed[next] === 1) continue;
95
- const tentative = cost + neighborCosts[i];
96
- if (tentative >= gScore[next] || tentative > maxCost) continue;
97
- gScore[next] = tentative;
98
- heap.push(next, tentative);
99
- }
100
- }
101
- return expandedNodes;
102
- };
103
-
104
- //#endregion
105
- export { runFlood, runSearch };
106
- //# sourceMappingURL=search.js.map