@principal-ai/logo-component 0.1.5 → 0.1.6

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.
@@ -1,271 +0,0 @@
1
- "use strict";
2
- /**
3
- * Maze Generator using Recursive Backtracking
4
- * Creates a perfect maze (exactly one path between any two cells)
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.MazeGenerator = void 0;
8
- exports.generateMaze = generateMaze;
9
- class MazeGenerator {
10
- constructor(rows, cols) {
11
- this.rows = rows;
12
- this.cols = cols;
13
- this.grid = this.initializeGrid();
14
- }
15
- initializeGrid() {
16
- const grid = [];
17
- for (let row = 0; row < this.rows; row++) {
18
- grid[row] = [];
19
- for (let col = 0; col < this.cols; col++) {
20
- grid[row][col] = {
21
- row,
22
- col,
23
- visited: false,
24
- walls: {
25
- north: true,
26
- south: true,
27
- east: true,
28
- west: true,
29
- },
30
- };
31
- }
32
- }
33
- return grid;
34
- }
35
- getCell(row, col) {
36
- if (row < 0 || row >= this.rows || col < 0 || col >= this.cols) {
37
- return null;
38
- }
39
- return this.grid[row][col];
40
- }
41
- getUnvisitedNeighbors(cell) {
42
- const neighbors = [];
43
- const { row, col } = cell;
44
- // North
45
- const north = this.getCell(row - 1, col);
46
- if (north && !north.visited)
47
- neighbors.push(north);
48
- // South
49
- const south = this.getCell(row + 1, col);
50
- if (south && !south.visited)
51
- neighbors.push(south);
52
- // East
53
- const east = this.getCell(row, col + 1);
54
- if (east && !east.visited)
55
- neighbors.push(east);
56
- // West
57
- const west = this.getCell(row, col - 1);
58
- if (west && !west.visited)
59
- neighbors.push(west);
60
- return neighbors;
61
- }
62
- removeWallBetween(current, next) {
63
- const rowDiff = current.row - next.row;
64
- const colDiff = current.col - next.col;
65
- // North
66
- if (rowDiff === 1) {
67
- current.walls.north = false;
68
- next.walls.south = false;
69
- }
70
- // South
71
- else if (rowDiff === -1) {
72
- current.walls.south = false;
73
- next.walls.north = false;
74
- }
75
- // East
76
- else if (colDiff === -1) {
77
- current.walls.east = false;
78
- next.walls.west = false;
79
- }
80
- // West
81
- else if (colDiff === 1) {
82
- current.walls.west = false;
83
- next.walls.east = false;
84
- }
85
- }
86
- recursiveBacktrack(cell) {
87
- cell.visited = true;
88
- const neighbors = this.getUnvisitedNeighbors(cell);
89
- // Shuffle neighbors for randomness
90
- this.shuffle(neighbors);
91
- for (const neighbor of neighbors) {
92
- if (!neighbor.visited) {
93
- this.removeWallBetween(cell, neighbor);
94
- this.recursiveBacktrack(neighbor);
95
- }
96
- }
97
- }
98
- shuffle(array) {
99
- for (let i = array.length - 1; i > 0; i--) {
100
- const j = Math.floor(Math.random() * (i + 1));
101
- [array[i], array[j]] = [array[j], array[i]];
102
- }
103
- }
104
- /**
105
- * Generate the maze starting from a specific cell
106
- */
107
- generate(startRow = 0, startCol = 0) {
108
- const startCell = this.getCell(startRow, startCol);
109
- if (startCell) {
110
- this.recursiveBacktrack(startCell);
111
- }
112
- }
113
- /**
114
- * Convert the maze to wall segments for rendering
115
- */
116
- getWalls() {
117
- const horizontal = [];
118
- const vertical = [];
119
- // Convert cell walls to line segments
120
- for (let row = 0; row < this.rows; row++) {
121
- for (let col = 0; col < this.cols; col++) {
122
- const cell = this.grid[row][col];
123
- // North wall
124
- if (cell.walls.north) {
125
- // Check if we can extend an existing horizontal wall
126
- const lastHWall = horizontal[horizontal.length - 1];
127
- if (lastHWall && lastHWall[1] === row && lastHWall[2] === col) {
128
- // Extend the wall
129
- lastHWall[2] = col + 1;
130
- }
131
- else {
132
- // Create new wall segment
133
- horizontal.push([col, row, col + 1, row]);
134
- }
135
- }
136
- // West wall
137
- if (cell.walls.west) {
138
- // Check if we can extend an existing vertical wall
139
- const lastVWall = vertical[vertical.length - 1];
140
- if (lastVWall && lastVWall[0] === col && lastVWall[3] === row) {
141
- // Extend the wall
142
- lastVWall[3] = row + 1;
143
- }
144
- else {
145
- // Create new wall segment
146
- vertical.push([col, row, col, row + 1]);
147
- }
148
- }
149
- // South wall (only for bottom row)
150
- if (row === this.rows - 1 && cell.walls.south) {
151
- const lastHWall = horizontal[horizontal.length - 1];
152
- if (lastHWall && lastHWall[1] === row + 1 && lastHWall[2] === col) {
153
- lastHWall[2] = col + 1;
154
- }
155
- else {
156
- horizontal.push([col, row + 1, col + 1, row + 1]);
157
- }
158
- }
159
- // East wall (only for rightmost column)
160
- if (col === this.cols - 1 && cell.walls.east) {
161
- const lastVWall = vertical[vertical.length - 1];
162
- if (lastVWall && lastVWall[0] === col + 1 && lastVWall[3] === row) {
163
- lastVWall[3] = row + 1;
164
- }
165
- else {
166
- vertical.push([col + 1, row, col + 1, row + 1]);
167
- }
168
- }
169
- }
170
- }
171
- return { horizontal, vertical };
172
- }
173
- /**
174
- * Get a copy of the grid for debugging or analysis
175
- */
176
- getGrid() {
177
- return this.grid;
178
- }
179
- /**
180
- * Find path from start to end using BFS
181
- * Returns array of cells representing the path
182
- */
183
- findPath(startRow, startCol, endRow, endCol) {
184
- const visited = new Set();
185
- const queue = [];
186
- const startCell = this.getCell(startRow, startCol);
187
- if (!startCell)
188
- return [];
189
- queue.push({ cell: startCell, path: [startCell] });
190
- visited.add(`${startRow},${startCol}`);
191
- while (queue.length > 0) {
192
- const { cell, path } = queue.shift();
193
- if (cell.row === endRow && cell.col === endCol) {
194
- return path;
195
- }
196
- // Check all four directions
197
- const neighbors = [
198
- { dir: 'north', dr: -1, dc: 0, wall: cell.walls.north },
199
- { dir: 'south', dr: 1, dc: 0, wall: cell.walls.south },
200
- { dir: 'east', dr: 0, dc: 1, wall: cell.walls.east },
201
- { dir: 'west', dr: 0, dc: -1, wall: cell.walls.west },
202
- ];
203
- for (const { dr, dc, wall } of neighbors) {
204
- if (wall)
205
- continue; // Can't go through wall
206
- const nextRow = cell.row + dr;
207
- const nextCol = cell.col + dc;
208
- const key = `${nextRow},${nextCol}`;
209
- if (visited.has(key))
210
- continue;
211
- const nextCell = this.getCell(nextRow, nextCol);
212
- if (!nextCell)
213
- continue;
214
- visited.add(key);
215
- queue.push({
216
- cell: nextCell,
217
- path: [...path, nextCell]
218
- });
219
- }
220
- }
221
- return []; // No path found
222
- }
223
- /**
224
- * Add a blockage (wall) at a specific position
225
- */
226
- addBlockage(row, col, direction) {
227
- const cell = this.getCell(row, col);
228
- if (!cell)
229
- return;
230
- cell.walls[direction] = true;
231
- // Also add the wall to the adjacent cell
232
- if (direction === 'north') {
233
- const neighbor = this.getCell(row - 1, col);
234
- if (neighbor)
235
- neighbor.walls.south = true;
236
- }
237
- else if (direction === 'south') {
238
- const neighbor = this.getCell(row + 1, col);
239
- if (neighbor)
240
- neighbor.walls.north = true;
241
- }
242
- else if (direction === 'east') {
243
- const neighbor = this.getCell(row, col + 1);
244
- if (neighbor)
245
- neighbor.walls.west = true;
246
- }
247
- else if (direction === 'west') {
248
- const neighbor = this.getCell(row, col - 1);
249
- if (neighbor)
250
- neighbor.walls.east = true;
251
- }
252
- }
253
- }
254
- exports.MazeGenerator = MazeGenerator;
255
- /**
256
- * Helper function to generate a maze with default settings
257
- */
258
- function generateMaze(rows, cols, seed) {
259
- // Use seed for reproducible mazes (if provided)
260
- if (seed !== undefined) {
261
- // Simple seeded random (not cryptographically secure)
262
- let currentSeed = seed;
263
- Math.random = () => {
264
- currentSeed = (currentSeed * 9301 + 49297) % 233280;
265
- return currentSeed / 233280;
266
- };
267
- }
268
- const generator = new MazeGenerator(rows, cols);
269
- generator.generate(0, 0);
270
- return generator.getWalls();
271
- }