@hayro_o7/labyrinth 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/components/Labyrinth.svelte +16 -3
- package/dist/components/Labyrinth.svelte.d.ts +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,11 @@ npm install labyrinth
|
|
|
60
60
|
autoPlay={false}
|
|
61
61
|
showGrid={true}
|
|
62
62
|
colors={customColors}
|
|
63
|
+
onControls={(controls) => (labyrinthControls = controls)}
|
|
63
64
|
/>
|
|
65
|
+
|
|
66
|
+
<button on:click={() => labyrinthControls?.play()}>Play</button>
|
|
67
|
+
<button on:click={() => labyrinthControls?.pause()}>Pause</button>
|
|
64
68
|
```
|
|
65
69
|
|
|
66
70
|
## API Reference
|
|
@@ -91,6 +95,7 @@ Generates a perfect maze (exactly one path between any two points) using the Rec
|
|
|
91
95
|
| `legend` | `boolean` | `true` | Toggle the legend panel |
|
|
92
96
|
| `stepCount` | `boolean` | `true` | Toggle the step counter |
|
|
93
97
|
| `colors` | `ColorScheme` | default theme | Custom color scheme (see below) |
|
|
98
|
+
| `onControls` | `(controls: LabyrinthControls) => void` | `undefined` | Receive imperative control methods |
|
|
94
99
|
|
|
95
100
|
### Algorithms
|
|
96
101
|
|
|
@@ -147,6 +152,30 @@ const customColors: ColorScheme = {
|
|
|
147
152
|
|
|
148
153
|
All color properties are optional - only specify the ones you want to override.
|
|
149
154
|
|
|
155
|
+
### Imperative Controls
|
|
156
|
+
|
|
157
|
+
You can access imperative controls (play/pause/reset/step) by providing `onControls`:
|
|
158
|
+
|
|
159
|
+
```svelte
|
|
160
|
+
<script lang="ts">
|
|
161
|
+
import { Labyrinth, generateLabyrinth } from '@hayro_o7/labyrinth';
|
|
162
|
+
import type { LabyrinthControls } from '@hayro_o7/labyrinth';
|
|
163
|
+
|
|
164
|
+
const graph = generateLabyrinth(20, 20);
|
|
165
|
+
let controls: LabyrinthControls | null = null;
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<Labyrinth {graph} onControls={(c) => (controls = c)} />
|
|
169
|
+
|
|
170
|
+
<div class="external-controls">
|
|
171
|
+
<button on:click={() => controls?.play()}>Play</button>
|
|
172
|
+
<button on:click={() => controls?.pause()}>Pause</button>
|
|
173
|
+
<button on:click={() => controls?.reset()}>Reset</button>
|
|
174
|
+
<button on:click={() => controls?.stepBackward()}>Step Back</button>
|
|
175
|
+
<button on:click={() => controls?.stepForward()}>Step Forward</button>
|
|
176
|
+
</div>
|
|
177
|
+
```
|
|
178
|
+
|
|
150
179
|
### Types
|
|
151
180
|
|
|
152
181
|
```typescript
|
|
@@ -194,6 +223,14 @@ interface ColorScheme {
|
|
|
194
223
|
buttonsdisabled?: string;
|
|
195
224
|
buttonstext?: string;
|
|
196
225
|
}
|
|
226
|
+
|
|
227
|
+
interface LabyrinthControls {
|
|
228
|
+
play: () => void;
|
|
229
|
+
pause: () => void;
|
|
230
|
+
reset: () => void;
|
|
231
|
+
stepForward: () => void;
|
|
232
|
+
stepBackward: () => void;
|
|
233
|
+
}
|
|
197
234
|
```
|
|
198
235
|
|
|
199
236
|
## Development
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Graph, AlgorithmType, PathStep } from '../types';
|
|
2
|
+
import type { Graph, AlgorithmType, PathStep, LabyrinthControls } from '../types';
|
|
3
3
|
import { dijkstra } from '../algorithms/dijkstra';
|
|
4
4
|
import { astar } from '../algorithms/astar';
|
|
5
5
|
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
animationSpeed?: number;
|
|
19
19
|
showGrid?: boolean;
|
|
20
20
|
colors?: ColorScheme;
|
|
21
|
+
onControls?: (controls: LabyrinthControls) => void;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
let {
|
|
@@ -32,9 +33,9 @@
|
|
|
32
33
|
stepCount = true,
|
|
33
34
|
animationSpeed = 50,
|
|
34
35
|
showGrid = true,
|
|
35
|
-
colors
|
|
36
|
+
colors,
|
|
37
|
+
onControls
|
|
36
38
|
}: Props = $props();
|
|
37
|
-
|
|
38
39
|
const defaultColors: Required<ColorScheme> = {
|
|
39
40
|
start: '#22c55e',
|
|
40
41
|
end: '#ef4444',
|
|
@@ -182,6 +183,18 @@
|
|
|
182
183
|
|
|
183
184
|
const width = $derived(graph.width * cellSize);
|
|
184
185
|
const height = $derived(graph.height * cellSize);
|
|
186
|
+
|
|
187
|
+
const controlApi: LabyrinthControls = {
|
|
188
|
+
play,
|
|
189
|
+
pause,
|
|
190
|
+
reset,
|
|
191
|
+
stepForward,
|
|
192
|
+
stepBackward
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
$effect(() => {
|
|
196
|
+
onControls?.(controlApi);
|
|
197
|
+
});
|
|
185
198
|
</script>
|
|
186
199
|
|
|
187
200
|
<div class="labyrinth-container" style={cssVars}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Graph, AlgorithmType } from '../types';
|
|
1
|
+
import type { Graph, AlgorithmType, LabyrinthControls } from '../types';
|
|
2
2
|
import type { ColorScheme } from '../types';
|
|
3
3
|
interface Props {
|
|
4
4
|
graph: Graph;
|
|
@@ -13,6 +13,7 @@ interface Props {
|
|
|
13
13
|
animationSpeed?: number;
|
|
14
14
|
showGrid?: boolean;
|
|
15
15
|
colors?: ColorScheme;
|
|
16
|
+
onControls?: (controls: LabyrinthControls) => void;
|
|
16
17
|
}
|
|
17
18
|
declare const Labyrinth: import("svelte").Component<Props, {}, "">;
|
|
18
19
|
type Labyrinth = ReturnType<typeof Labyrinth>;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { generateLabyrinth } from './labyrinth-generator';
|
|
|
2
2
|
export { dijkstra } from './algorithms/dijkstra';
|
|
3
3
|
export { astar } from './algorithms/astar';
|
|
4
4
|
export { default as Labyrinth } from './components/Labyrinth.svelte';
|
|
5
|
-
export type { Graph, GraphNode, Point, Cell, PathStep, AlgorithmResult, AlgorithmType, ColorScheme } from './types';
|
|
5
|
+
export type { Graph, GraphNode, Point, Cell, PathStep, AlgorithmResult, AlgorithmType, ColorScheme, LabyrinthControls } from './types';
|
package/dist/types.d.ts
CHANGED