console-rects 0.1.1 → 0.1.3

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # console-rects
2
2
 
3
- A utility to visualize rectangles in the console using box-drawing characters. Created at Screen Studio to help debug geometry code when things get complex.
3
+ A utility to visualize rectangles in the console using box-drawing characters. Perfect for debugging geometry code, visualizing overlapping rectangles, or drawing rectangles in the terminal. Created at Screen Studio to help debug geometry code when things get complex.
4
+
5
+ **Use cases:** Debug rectangle collisions, visualize layout calculations, log rectangles to console, debug geometry code, visualize overlapping rectangles in terminal.
4
6
 
5
7
  ## Installation
6
8
 
@@ -12,7 +14,7 @@ yarn install console-rects
12
14
  ## Usage
13
15
 
14
16
  ```typescript
15
- import { logRects } from "console-rects";
17
+ import { logRects, getRectsLog } from "console-rects";
16
18
 
17
19
  const rectangles = [
18
20
  { x: 0, y: 0, width: 100, height: 100 },
@@ -21,6 +23,7 @@ const rectangles = [
21
23
  ];
22
24
 
23
25
  logRects(rectangles);
26
+ getRectsLog(rectangles); // returns the string without logging to console
24
27
  ```
25
28
 
26
29
  This will output a visual representation of the rectangles in your console:
@@ -50,18 +53,52 @@ This will output a visual representation of the rectangles in your console:
50
53
 
51
54
  Each rectangle gets a different line style (light, heavy, double, dashed, dashed-heavy) based on its position in the array.
52
55
 
56
+ You can also use it for snapshot testing:
57
+
58
+ ```ts
59
+ expect(getRectsLog([transformer.zoom(2.5, { x: 0, y: 0.5 }, avaliableSize), avaliableSize])).toMatchInlineSnapshot(`
60
+ "
61
+ [-50, -75]
62
+ ┌───────────0───────────┐
63
+ │ │
64
+ │ │
65
+ │ │
66
+ │ │
67
+ │ │
68
+ │ │
69
+ ┏━━━━━━━━1━━━━━━━━━┓ │
70
+ ┃ ┃ │
71
+ ┃ ┃ │
72
+ ┃ ┃ │
73
+ ┃ ┃ │
74
+ ┃ ┃ │
75
+ ┃ ┃ │
76
+ ┃ ┃ │
77
+ ┃ ┃ │
78
+ ┃ ┃ │
79
+ ┗━━━━━━━━━━━━━━━━━━┛ │
80
+ │ │
81
+ │ │
82
+ │ │
83
+ │ │
84
+ │ │
85
+ │ │
86
+ └───────────────────────┘
87
+ [200, 175]"
88
+ `);
89
+ ```
90
+
53
91
  ## Options
54
92
 
55
93
  - `sizePerPoint` (default: `10`) - Controls the resolution/scale. Smaller values = higher detail.
56
94
  - `showLegend` (default: `true`) - Show coordinate labels at corners.
57
95
  - `startWithNewLine` (default: `true`) - Add a newline before the output.
58
- - `dontLog` (default: `false`) - Return the string without logging to console.
59
96
 
60
97
  ```typescript
61
98
  logRects(rectangles, {
62
99
  sizePerPoint: 20,
63
100
  showLegend: false,
64
- dontLog: true,
101
+ startWithNewLine: false,
65
102
  });
66
103
  ```
67
104
 
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ const UP = 1;
4
4
  const DOWN = 2;
5
5
  const LEFT = 4;
6
6
  const RIGHT = 8;
7
+ const STYLES = ["light", "heavy", "double", "dashed", "dashed-heavy"];
7
8
  const STYLE_CHARS = {
8
9
  light: {
9
10
  [UP]: "╵",
@@ -91,8 +92,10 @@ const STYLE_CHARS = {
91
92
  [UP | DOWN | LEFT | RIGHT]: "╋"
92
93
  }
93
94
  };
94
- const STYLES = Object.keys(STYLE_CHARS);
95
- function findBoundaries(rectangles) {
95
+ function logRects(rectangles, { sizePerPoint = 10, showLegend = true, dontLog = false, startWithNewLine = true } = {}) {
96
+ if (rectangles.length === 0) {
97
+ return "No rectangles to draw";
98
+ }
96
99
  let minX = Infinity;
97
100
  let minY = Infinity;
98
101
  let maxX = -Infinity;
@@ -103,19 +106,13 @@ function findBoundaries(rectangles) {
103
106
  maxX = Math.max(maxX, rect.x + rect.width);
104
107
  maxY = Math.max(maxY, rect.y + rect.height);
105
108
  }
106
- return { minX, minY, maxX, maxY };
107
- }
108
- function logRects(rectangles, { sizePerPoint = 10, showLegend = true, startWithNewLine = true, dontLog = false } = {}) {
109
- if (rectangles.length === 0) {
110
- return "";
111
- }
112
- const { minX, minY, maxX, maxY } = findBoundaries(rectangles);
113
109
  const gridWidth = Math.ceil((maxX - minX) / sizePerPoint);
114
110
  const gridHeight = Math.ceil((maxY - minY) / sizePerPoint);
115
111
  const grid = Array.from(
116
112
  { length: gridHeight },
117
113
  () => Array.from({ length: gridWidth }, () => ({ directions: 0, zIndex: -1 }))
118
114
  );
115
+ const indexGrid = Array.from({ length: gridHeight }, () => Array(gridWidth).fill(null));
119
116
  const setCell = (row, col, direction, zIndex) => {
120
117
  if (row < 0 || row >= gridHeight || col < 0 || col >= gridWidth) return;
121
118
  const cell = grid[row][col];
@@ -152,9 +149,28 @@ function logRects(rectangles, { sizePerPoint = 10, showLegend = true, startWithN
152
149
  drawHorizontal(endRow, startCol, endCol, zIndex);
153
150
  drawVertical(startCol, startRow, endRow, zIndex);
154
151
  drawVertical(endCol, startRow, endRow, zIndex);
152
+ const indexStr = String(zIndex);
153
+ const edgeWidth = endCol - startCol;
154
+ if (edgeWidth >= indexStr.length + 3) {
155
+ const innerWidth = edgeWidth - 1;
156
+ const indexStart = startCol + 1 + Math.floor((innerWidth - indexStr.length) / 2);
157
+ for (let i = 0; i < indexStr.length; i++) {
158
+ const col = indexStart + i;
159
+ if (col >= 0 && col < gridWidth && startRow >= 0 && startRow < gridHeight) {
160
+ const existing = indexGrid[startRow][col];
161
+ if (!existing || zIndex >= existing.zIndex) {
162
+ indexGrid[startRow][col] = { char: indexStr[i], zIndex };
163
+ }
164
+ }
165
+ }
166
+ }
155
167
  });
156
168
  const charGrid = grid.map(
157
- (row) => row.map((cell) => {
169
+ (row, rowIdx) => row.map((cell, colIdx) => {
170
+ const indexData = indexGrid[rowIdx][colIdx];
171
+ if (indexData && indexData.zIndex >= cell.zIndex) {
172
+ return indexData.char;
173
+ }
158
174
  if (cell.directions === 0) return " ";
159
175
  const style = STYLES[cell.zIndex % STYLES.length];
160
176
  return STYLE_CHARS[style][cell.directions] || "?";
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../index.ts"],"sourcesContent":["interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n// Direction bitmasks\nconst UP = 1;\nconst DOWN = 2;\nconst LEFT = 4;\nconst RIGHT = 8;\n\n// Box-drawing character maps for each style\nconst STYLE_CHARS = {\n light: {\n [UP]: \"╵\",\n [DOWN]: \"╷\",\n [LEFT]: \"╴\",\n [RIGHT]: \"╶\",\n [LEFT | RIGHT]: \"─\",\n [UP | DOWN]: \"│\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n heavy: {\n [UP]: \"╹\",\n [DOWN]: \"╻\",\n [LEFT]: \"╸\",\n [RIGHT]: \"╺\",\n [LEFT | RIGHT]: \"━\",\n [UP | DOWN]: \"┃\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n double: {\n [UP]: \"║\",\n [DOWN]: \"║\",\n [LEFT]: \"═\",\n [RIGHT]: \"═\",\n [LEFT | RIGHT]: \"═\",\n [UP | DOWN]: \"║\",\n [DOWN | RIGHT]: \"╔\",\n [DOWN | LEFT]: \"╗\",\n [UP | RIGHT]: \"╚\",\n [UP | LEFT]: \"╝\",\n [UP | DOWN | RIGHT]: \"╠\",\n [UP | DOWN | LEFT]: \"╣\",\n [LEFT | RIGHT | DOWN]: \"╦\",\n [LEFT | RIGHT | UP]: \"╩\",\n [UP | DOWN | LEFT | RIGHT]: \"╬\",\n },\n dashed: {\n [UP]: \"╎\",\n [DOWN]: \"╎\",\n [LEFT]: \"╌\",\n [RIGHT]: \"╌\",\n [LEFT | RIGHT]: \"╌\",\n [UP | DOWN]: \"╎\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n \"dashed-heavy\": {\n [UP]: \"╏\",\n [DOWN]: \"╏\",\n [LEFT]: \"╍\",\n [RIGHT]: \"╍\",\n [LEFT | RIGHT]: \"╍\",\n [UP | DOWN]: \"╏\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n} satisfies Record<string, Record<number, string>>;\n\ntype LineStyle = keyof typeof STYLE_CHARS;\n\nconst STYLES: LineStyle[] = Object.keys(STYLE_CHARS) as LineStyle[];\n\ninterface CellData {\n directions: number;\n zIndex: number; // highest z-index that touched this cell\n}\n\nexport interface LogRectsOptions {\n sizePerPoint?: number;\n showLegend?: boolean;\n startWithNewLine?: boolean;\n dontLog?: boolean;\n}\n\nfunction findBoundaries(rectangles: Rect[]) {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const rect of rectangles) {\n minX = Math.min(minX, rect.x);\n minY = Math.min(minY, rect.y);\n maxX = Math.max(maxX, rect.x + rect.width);\n maxY = Math.max(maxY, rect.y + rect.height);\n }\n\n return { minX, minY, maxX, maxY };\n}\n\nexport function logRects(\n rectangles: Rect[],\n { sizePerPoint = 10, showLegend = true, startWithNewLine = true, dontLog = false }: LogRectsOptions = {}\n): string {\n if (rectangles.length === 0) {\n return \"\";\n }\n\n // Find bounding box of all rectangles\n const { minX, minY, maxX, maxY } = findBoundaries(rectangles);\n\n // Calculate grid dimensions based on resolution\n const gridWidth = Math.ceil((maxX - minX) / sizePerPoint);\n const gridHeight = Math.ceil((maxY - minY) / sizePerPoint);\n\n // Create grid to track directions and z-index at each cell\n const grid: CellData[][] = Array.from({ length: gridHeight }, () =>\n Array.from({ length: gridWidth }, () => ({ directions: 0, zIndex: -1 }))\n );\n\n // Helper to set cell data with z-index awareness\n const setCell = (row: number, col: number, direction: number, zIndex: number) => {\n if (row < 0 || row >= gridHeight || col < 0 || col >= gridWidth) return;\n const cell = grid[row][col];\n if (zIndex >= cell.zIndex) {\n // Higher or equal z-index takes over, reset directions\n if (zIndex > cell.zIndex) {\n cell.directions = 0;\n cell.zIndex = zIndex;\n }\n cell.directions |= direction;\n }\n };\n\n // Helper to draw a horizontal line segment\n const drawHorizontal = (row: number, colStart: number, colEnd: number, zIndex: number) => {\n for (let col = colStart; col <= colEnd; col++) {\n let dirs = 0;\n if (col > colStart) dirs |= LEFT;\n if (col < colEnd) dirs |= RIGHT;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Helper to draw a vertical line segment\n const drawVertical = (col: number, rowStart: number, rowEnd: number, zIndex: number) => {\n for (let row = rowStart; row <= rowEnd; row++) {\n let dirs = 0;\n if (row > rowStart) dirs |= UP;\n if (row < rowEnd) dirs |= DOWN;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Draw each rectangle's outline with z-index = array index\n rectangles.forEach((rect, zIndex) => {\n const startCol = Math.floor((rect.x - minX) / sizePerPoint);\n const startRow = Math.floor((rect.y - minY) / sizePerPoint);\n const endCol = Math.ceil((rect.x + rect.width - minX) / sizePerPoint) - 1;\n const endRow = Math.ceil((rect.y + rect.height - minY) / sizePerPoint) - 1;\n\n // Draw the four edges\n drawHorizontal(startRow, startCol, endCol, zIndex); // Top\n drawHorizontal(endRow, startCol, endCol, zIndex); // Bottom\n drawVertical(startCol, startRow, endRow, zIndex); // Left\n drawVertical(endCol, startRow, endRow, zIndex); // Right\n });\n\n // Convert cell data to characters\n const charGrid: string[][] = grid.map((row) =>\n row.map((cell) => {\n if (cell.directions === 0) return \" \";\n const style = STYLES[cell.zIndex % STYLES.length];\n return STYLE_CHARS[style][cell.directions] || \"?\";\n })\n );\n\n // Build output string\n const lines: string[] = [];\n\n if (showLegend) {\n const topLeftLabel = `[${minX}, ${minY}]`;\n const bottomRightLabel = `[${maxX}, ${maxY}]`;\n const padding = \" \".repeat(topLeftLabel.length + 1);\n\n lines.push(topLeftLabel);\n for (const row of charGrid) {\n lines.push(padding + row.join(\"\"));\n }\n lines.push(padding + \" \".repeat(gridWidth) + \" \" + bottomRightLabel);\n } else {\n for (const row of charGrid) {\n lines.push(row.join(\"\"));\n }\n }\n\n if (startWithNewLine) {\n lines.unshift(\"\");\n }\n\n const output = lines.join(\"\\n\");\n\n if (!dontLog) {\n console.info(output);\n }\n\n return output;\n}\n"],"names":[],"mappings":";;AAQA,MAAM,KAAK;AACX,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,QAAQ;AAGd,MAAM,cAAc;AAAA,EAClB,OAAO;AAAA,IACL,CAAC,EAAE,GAAG;AAAA,IACN,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,KAAK,GAAG;AAAA,IACT,CAAC,OAAO,KAAK,GAAG;AAAA,IAChB,CAAC,KAAK,IAAI,GAAG;AAAA,IACb,CAAC,OAAO,KAAK,GAAG;AAAA,IAChB,CAAC,OAAO,IAAI,GAAG;AAAA,IACf,CAAC,KAAK,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AAO,MAAM;AAChD,aAAO,YAAY,KAAK,EAAE,KAAK,UAAU,KAAK;AAAA,IAChD,CAAC;AAAA,EAAA;AAIH,QAAM,QAAkB,CAAA;AAExB,MAAI,YAAY;AACd,UAAM,eAAe,IAAI,IAAI,KAAK,IAAI;AACtC,UAAM,mBAAmB,IAAI,IAAI,KAAK,IAAI;AAC1C,UAAM,UAAU,IAAI,OAAO,aAAa,SAAS,CAAC;AAElD,UAAM,KAAK,YAAY;AACvB,eAAW,OAAO,UAAU;AAC1B,YAAM,KAAK,UAAU,IAAI,KAAK,EAAE,CAAC;AAAA,IACnC;AACA,UAAM,KAAK,UAAU,IAAI,OAAO,SAAS,IAAI,MAAM,gBAAgB;AAAA,EACrE,OAAO;AACL,eAAW,OAAO,UAAU;AAC1B,YAAM,KAAK,IAAI,KAAK,EAAE,CAAC;AAAA,IACzB;AAAA,EACF;AAEA,MAAI,kBAAkB;AACpB,UAAM,QAAQ,EAAE;AAAA,EAClB;AAEA,QAAM,SAAS,MAAM,KAAK,IAAI;AAE9B,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,MAAM;AAAA,EACrB;AAEA,SAAO;AACT;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../index.ts"],"sourcesContent":["interface Rectangle {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n// Direction bitmasks\nconst UP = 1;\nconst DOWN = 2;\nconst LEFT = 4;\nconst RIGHT = 8;\n\ntype LineStyle = \"light\" | \"heavy\" | \"double\" | \"dashed\" | \"dashed-heavy\";\n\nconst STYLES: LineStyle[] = [\"light\", \"heavy\", \"double\", \"dashed\", \"dashed-heavy\"];\n\n// Box-drawing character maps for each style\nconst STYLE_CHARS: Record<LineStyle, Record<number, string>> = {\n light: {\n [UP]: \"╵\",\n [DOWN]: \"╷\",\n [LEFT]: \"╴\",\n [RIGHT]: \"╶\",\n [LEFT | RIGHT]: \"─\",\n [UP | DOWN]: \"│\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n heavy: {\n [UP]: \"╹\",\n [DOWN]: \"╻\",\n [LEFT]: \"╸\",\n [RIGHT]: \"╺\",\n [LEFT | RIGHT]: \"━\",\n [UP | DOWN]: \"┃\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n double: {\n [UP]: \"║\",\n [DOWN]: \"║\",\n [LEFT]: \"═\",\n [RIGHT]: \"═\",\n [LEFT | RIGHT]: \"═\",\n [UP | DOWN]: \"║\",\n [DOWN | RIGHT]: \"╔\",\n [DOWN | LEFT]: \"╗\",\n [UP | RIGHT]: \"╚\",\n [UP | LEFT]: \"╝\",\n [UP | DOWN | RIGHT]: \"╠\",\n [UP | DOWN | LEFT]: \"╣\",\n [LEFT | RIGHT | DOWN]: \"╦\",\n [LEFT | RIGHT | UP]: \"╩\",\n [UP | DOWN | LEFT | RIGHT]: \"╬\",\n },\n dashed: {\n [UP]: \"╎\",\n [DOWN]: \"╎\",\n [LEFT]: \"╌\",\n [RIGHT]: \"╌\",\n [LEFT | RIGHT]: \"╌\",\n [UP | DOWN]: \"╎\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n \"dashed-heavy\": {\n [UP]: \"╏\",\n [DOWN]: \"╏\",\n [LEFT]: \"╍\",\n [RIGHT]: \"╍\",\n [LEFT | RIGHT]: \"╍\",\n [UP | DOWN]: \"╏\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n};\n\ninterface CellData {\n directions: number;\n zIndex: number;\n}\n\ninterface IndexData {\n char: string;\n zIndex: number;\n}\n\nexport interface LogRectsOptions {\n sizePerPoint?: number;\n showLegend?: boolean;\n dontLog?: boolean;\n startWithNewLine?: boolean;\n}\n\nexport function logRects(\n rectangles: Rectangle[],\n { sizePerPoint = 10, showLegend = true, dontLog = false, startWithNewLine = true }: LogRectsOptions = {}\n): string {\n if (rectangles.length === 0) {\n return \"No rectangles to draw\";\n }\n\n // Find bounding box of all rectangles\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const rect of rectangles) {\n minX = Math.min(minX, rect.x);\n minY = Math.min(minY, rect.y);\n maxX = Math.max(maxX, rect.x + rect.width);\n maxY = Math.max(maxY, rect.y + rect.height);\n }\n\n // Calculate grid dimensions based on resolution\n const gridWidth = Math.ceil((maxX - minX) / sizePerPoint);\n const gridHeight = Math.ceil((maxY - minY) / sizePerPoint);\n\n // Create grid to track directions and z-index at each cell\n const grid: CellData[][] = Array.from({ length: gridHeight }, () =>\n Array.from({ length: gridWidth }, () => ({ directions: 0, zIndex: -1 }))\n );\n\n // Create index overlay grid\n const indexGrid: (IndexData | null)[][] = Array.from({ length: gridHeight }, () => Array(gridWidth).fill(null));\n\n // Helper to set cell data with z-index awareness\n const setCell = (row: number, col: number, direction: number, zIndex: number) => {\n if (row < 0 || row >= gridHeight || col < 0 || col >= gridWidth) return;\n const cell = grid[row][col];\n if (zIndex >= cell.zIndex) {\n if (zIndex > cell.zIndex) {\n cell.directions = 0;\n cell.zIndex = zIndex;\n }\n cell.directions |= direction;\n }\n };\n\n // Helper to draw a horizontal line segment\n const drawHorizontal = (row: number, colStart: number, colEnd: number, zIndex: number) => {\n for (let col = colStart; col <= colEnd; col++) {\n let dirs = 0;\n if (col > colStart) dirs |= LEFT;\n if (col < colEnd) dirs |= RIGHT;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Helper to draw a vertical line segment\n const drawVertical = (col: number, rowStart: number, rowEnd: number, zIndex: number) => {\n for (let row = rowStart; row <= rowEnd; row++) {\n let dirs = 0;\n if (row > rowStart) dirs |= UP;\n if (row < rowEnd) dirs |= DOWN;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Draw each rectangle's outline with z-index = array index\n rectangles.forEach((rect, zIndex) => {\n const startCol = Math.floor((rect.x - minX) / sizePerPoint);\n const startRow = Math.floor((rect.y - minY) / sizePerPoint);\n const endCol = Math.ceil((rect.x + rect.width - minX) / sizePerPoint) - 1;\n const endRow = Math.ceil((rect.y + rect.height - minY) / sizePerPoint) - 1;\n\n // Draw the four edges\n drawHorizontal(startRow, startCol, endCol, zIndex);\n drawHorizontal(endRow, startCol, endCol, zIndex);\n drawVertical(startCol, startRow, endRow, zIndex);\n drawVertical(endCol, startRow, endRow, zIndex);\n\n // Place index at center of top edge if there's room\n const indexStr = String(zIndex);\n const edgeWidth = endCol - startCol; // number of segments (cells - 1)\n\n // Need at least 1 line char on each side of the index\n // Inner width (excluding corners) = edgeWidth - 1\n // Required: innerWidth >= indexStr.length + 2\n if (edgeWidth >= indexStr.length + 3) {\n const innerWidth = edgeWidth - 1;\n const indexStart = startCol + 1 + Math.floor((innerWidth - indexStr.length) / 2);\n\n for (let i = 0; i < indexStr.length; i++) {\n const col = indexStart + i;\n if (col >= 0 && col < gridWidth && startRow >= 0 && startRow < gridHeight) {\n const existing = indexGrid[startRow][col];\n if (!existing || zIndex >= existing.zIndex) {\n indexGrid[startRow][col] = { char: indexStr[i], zIndex };\n }\n }\n }\n }\n });\n\n // Convert cell data to characters, respecting z-index for both edges and indices\n const charGrid: string[][] = grid.map((row, rowIdx) =>\n row.map((cell, colIdx) => {\n const indexData = indexGrid[rowIdx][colIdx];\n\n // If there's an index with higher or equal z-index, use it\n if (indexData && indexData.zIndex >= cell.zIndex) {\n return indexData.char;\n }\n\n // Otherwise use edge character\n if (cell.directions === 0) return \" \";\n const style = STYLES[cell.zIndex % STYLES.length];\n return STYLE_CHARS[style][cell.directions] || \"?\";\n })\n );\n\n // Build output string\n const lines: string[] = [];\n\n if (showLegend) {\n const topLeftLabel = `[${minX}, ${minY}]`;\n const bottomRightLabel = `[${maxX}, ${maxY}]`;\n const padding = \" \".repeat(topLeftLabel.length + 1);\n\n lines.push(topLeftLabel);\n for (const row of charGrid) {\n lines.push(padding + row.join(\"\"));\n }\n lines.push(padding + \" \".repeat(gridWidth) + \" \" + bottomRightLabel);\n } else {\n for (const row of charGrid) {\n lines.push(row.join(\"\"));\n }\n }\n\n if (startWithNewLine) {\n lines.unshift(\"\");\n }\n\n const output = lines.join(\"\\n\");\n\n if (!dontLog) {\n console.info(output);\n }\n\n return output;\n}\n"],"names":[],"mappings":";;AAQA,MAAM,KAAK;AACX,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,QAAQ;AAId,MAAM,SAAsB,CAAC,SAAS,SAAS,UAAU,UAAU,cAAc;AAGjF,MAAM,cAAyD;AAAA,EAC7D,OAAO;AAAA,IACL,CAAC,EAAE,GAAG;AAAA,IACN,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,KAAK,GAAG;AAAA,IACT,CA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AK,EAAE,CAAC;AAAA,IACzB;AAAA,EACF;AAEA,MAAI,kBAAkB;AACpB,UAAM,QAAQ,EAAE;AAAA,EAClB;AAEA,QAAM,SAAS,MAAM,KAAK,IAAI;AAE9B,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,MAAM;AAAA,EACrB;AAEA,SAAO;AACT;;"}
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ const UP = 1;
2
2
  const DOWN = 2;
3
3
  const LEFT = 4;
4
4
  const RIGHT = 8;
5
+ const STYLES = ["light", "heavy", "double", "dashed", "dashed-heavy"];
5
6
  const STYLE_CHARS = {
6
7
  light: {
7
8
  [UP]: "╵",
@@ -89,8 +90,10 @@ const STYLE_CHARS = {
89
90
  [UP | DOWN | LEFT | RIGHT]: "╋"
90
91
  }
91
92
  };
92
- const STYLES = Object.keys(STYLE_CHARS);
93
- function findBoundaries(rectangles) {
93
+ function logRects(rectangles, { sizePerPoint = 10, showLegend = true, dontLog = false, startWithNewLine = true } = {}) {
94
+ if (rectangles.length === 0) {
95
+ return "No rectangles to draw";
96
+ }
94
97
  let minX = Infinity;
95
98
  let minY = Infinity;
96
99
  let maxX = -Infinity;
@@ -101,19 +104,13 @@ function findBoundaries(rectangles) {
101
104
  maxX = Math.max(maxX, rect.x + rect.width);
102
105
  maxY = Math.max(maxY, rect.y + rect.height);
103
106
  }
104
- return { minX, minY, maxX, maxY };
105
- }
106
- function logRects(rectangles, { sizePerPoint = 10, showLegend = true, startWithNewLine = true, dontLog = false } = {}) {
107
- if (rectangles.length === 0) {
108
- return "";
109
- }
110
- const { minX, minY, maxX, maxY } = findBoundaries(rectangles);
111
107
  const gridWidth = Math.ceil((maxX - minX) / sizePerPoint);
112
108
  const gridHeight = Math.ceil((maxY - minY) / sizePerPoint);
113
109
  const grid = Array.from(
114
110
  { length: gridHeight },
115
111
  () => Array.from({ length: gridWidth }, () => ({ directions: 0, zIndex: -1 }))
116
112
  );
113
+ const indexGrid = Array.from({ length: gridHeight }, () => Array(gridWidth).fill(null));
117
114
  const setCell = (row, col, direction, zIndex) => {
118
115
  if (row < 0 || row >= gridHeight || col < 0 || col >= gridWidth) return;
119
116
  const cell = grid[row][col];
@@ -150,9 +147,28 @@ function logRects(rectangles, { sizePerPoint = 10, showLegend = true, startWithN
150
147
  drawHorizontal(endRow, startCol, endCol, zIndex);
151
148
  drawVertical(startCol, startRow, endRow, zIndex);
152
149
  drawVertical(endCol, startRow, endRow, zIndex);
150
+ const indexStr = String(zIndex);
151
+ const edgeWidth = endCol - startCol;
152
+ if (edgeWidth >= indexStr.length + 3) {
153
+ const innerWidth = edgeWidth - 1;
154
+ const indexStart = startCol + 1 + Math.floor((innerWidth - indexStr.length) / 2);
155
+ for (let i = 0; i < indexStr.length; i++) {
156
+ const col = indexStart + i;
157
+ if (col >= 0 && col < gridWidth && startRow >= 0 && startRow < gridHeight) {
158
+ const existing = indexGrid[startRow][col];
159
+ if (!existing || zIndex >= existing.zIndex) {
160
+ indexGrid[startRow][col] = { char: indexStr[i], zIndex };
161
+ }
162
+ }
163
+ }
164
+ }
153
165
  });
154
166
  const charGrid = grid.map(
155
- (row) => row.map((cell) => {
167
+ (row, rowIdx) => row.map((cell, colIdx) => {
168
+ const indexData = indexGrid[rowIdx][colIdx];
169
+ if (indexData && indexData.zIndex >= cell.zIndex) {
170
+ return indexData.char;
171
+ }
156
172
  if (cell.directions === 0) return " ";
157
173
  const style = STYLES[cell.zIndex % STYLES.length];
158
174
  return STYLE_CHARS[style][cell.directions] || "?";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":["interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n// Direction bitmasks\nconst UP = 1;\nconst DOWN = 2;\nconst LEFT = 4;\nconst RIGHT = 8;\n\n// Box-drawing character maps for each style\nconst STYLE_CHARS = {\n light: {\n [UP]: \"╵\",\n [DOWN]: \"╷\",\n [LEFT]: \"╴\",\n [RIGHT]: \"╶\",\n [LEFT | RIGHT]: \"─\",\n [UP | DOWN]: \"│\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n heavy: {\n [UP]: \"╹\",\n [DOWN]: \"╻\",\n [LEFT]: \"╸\",\n [RIGHT]: \"╺\",\n [LEFT | RIGHT]: \"━\",\n [UP | DOWN]: \"┃\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n double: {\n [UP]: \"║\",\n [DOWN]: \"║\",\n [LEFT]: \"═\",\n [RIGHT]: \"═\",\n [LEFT | RIGHT]: \"═\",\n [UP | DOWN]: \"║\",\n [DOWN | RIGHT]: \"╔\",\n [DOWN | LEFT]: \"╗\",\n [UP | RIGHT]: \"╚\",\n [UP | LEFT]: \"╝\",\n [UP | DOWN | RIGHT]: \"╠\",\n [UP | DOWN | LEFT]: \"╣\",\n [LEFT | RIGHT | DOWN]: \"╦\",\n [LEFT | RIGHT | UP]: \"╩\",\n [UP | DOWN | LEFT | RIGHT]: \"╬\",\n },\n dashed: {\n [UP]: \"╎\",\n [DOWN]: \"╎\",\n [LEFT]: \"╌\",\n [RIGHT]: \"╌\",\n [LEFT | RIGHT]: \"╌\",\n [UP | DOWN]: \"╎\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n \"dashed-heavy\": {\n [UP]: \"╏\",\n [DOWN]: \"╏\",\n [LEFT]: \"╍\",\n [RIGHT]: \"╍\",\n [LEFT | RIGHT]: \"╍\",\n [UP | DOWN]: \"╏\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n} satisfies Record<string, Record<number, string>>;\n\ntype LineStyle = keyof typeof STYLE_CHARS;\n\nconst STYLES: LineStyle[] = Object.keys(STYLE_CHARS) as LineStyle[];\n\ninterface CellData {\n directions: number;\n zIndex: number; // highest z-index that touched this cell\n}\n\nexport interface LogRectsOptions {\n sizePerPoint?: number;\n showLegend?: boolean;\n startWithNewLine?: boolean;\n dontLog?: boolean;\n}\n\nfunction findBoundaries(rectangles: Rect[]) {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const rect of rectangles) {\n minX = Math.min(minX, rect.x);\n minY = Math.min(minY, rect.y);\n maxX = Math.max(maxX, rect.x + rect.width);\n maxY = Math.max(maxY, rect.y + rect.height);\n }\n\n return { minX, minY, maxX, maxY };\n}\n\nexport function logRects(\n rectangles: Rect[],\n { sizePerPoint = 10, showLegend = true, startWithNewLine = true, dontLog = false }: LogRectsOptions = {}\n): string {\n if (rectangles.length === 0) {\n return \"\";\n }\n\n // Find bounding box of all rectangles\n const { minX, minY, maxX, maxY } = findBoundaries(rectangles);\n\n // Calculate grid dimensions based on resolution\n const gridWidth = Math.ceil((maxX - minX) / sizePerPoint);\n const gridHeight = Math.ceil((maxY - minY) / sizePerPoint);\n\n // Create grid to track directions and z-index at each cell\n const grid: CellData[][] = Array.from({ length: gridHeight }, () =>\n Array.from({ length: gridWidth }, () => ({ directions: 0, zIndex: -1 }))\n );\n\n // Helper to set cell data with z-index awareness\n const setCell = (row: number, col: number, direction: number, zIndex: number) => {\n if (row < 0 || row >= gridHeight || col < 0 || col >= gridWidth) return;\n const cell = grid[row][col];\n if (zIndex >= cell.zIndex) {\n // Higher or equal z-index takes over, reset directions\n if (zIndex > cell.zIndex) {\n cell.directions = 0;\n cell.zIndex = zIndex;\n }\n cell.directions |= direction;\n }\n };\n\n // Helper to draw a horizontal line segment\n const drawHorizontal = (row: number, colStart: number, colEnd: number, zIndex: number) => {\n for (let col = colStart; col <= colEnd; col++) {\n let dirs = 0;\n if (col > colStart) dirs |= LEFT;\n if (col < colEnd) dirs |= RIGHT;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Helper to draw a vertical line segment\n const drawVertical = (col: number, rowStart: number, rowEnd: number, zIndex: number) => {\n for (let row = rowStart; row <= rowEnd; row++) {\n let dirs = 0;\n if (row > rowStart) dirs |= UP;\n if (row < rowEnd) dirs |= DOWN;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Draw each rectangle's outline with z-index = array index\n rectangles.forEach((rect, zIndex) => {\n const startCol = Math.floor((rect.x - minX) / sizePerPoint);\n const startRow = Math.floor((rect.y - minY) / sizePerPoint);\n const endCol = Math.ceil((rect.x + rect.width - minX) / sizePerPoint) - 1;\n const endRow = Math.ceil((rect.y + rect.height - minY) / sizePerPoint) - 1;\n\n // Draw the four edges\n drawHorizontal(startRow, startCol, endCol, zIndex); // Top\n drawHorizontal(endRow, startCol, endCol, zIndex); // Bottom\n drawVertical(startCol, startRow, endRow, zIndex); // Left\n drawVertical(endCol, startRow, endRow, zIndex); // Right\n });\n\n // Convert cell data to characters\n const charGrid: string[][] = grid.map((row) =>\n row.map((cell) => {\n if (cell.directions === 0) return \" \";\n const style = STYLES[cell.zIndex % STYLES.length];\n return STYLE_CHARS[style][cell.directions] || \"?\";\n })\n );\n\n // Build output string\n const lines: string[] = [];\n\n if (showLegend) {\n const topLeftLabel = `[${minX}, ${minY}]`;\n const bottomRightLabel = `[${maxX}, ${maxY}]`;\n const padding = \" \".repeat(topLeftLabel.length + 1);\n\n lines.push(topLeftLabel);\n for (const row of charGrid) {\n lines.push(padding + row.join(\"\"));\n }\n lines.push(padding + \" \".repeat(gridWidth) + \" \" + bottomRightLabel);\n } else {\n for (const row of charGrid) {\n lines.push(row.join(\"\"));\n }\n }\n\n if (startWithNewLine) {\n lines.unshift(\"\");\n }\n\n const output = lines.join(\"\\n\");\n\n if (!dontLog) {\n console.info(output);\n }\n\n return output;\n}\n"],"names":[],"mappings":"AAQA,MAAM,KAAK;AACX,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,QAAQ;AAGd,MAAM,cAAc;AAAA,EAClB,OAAO;AAAA,IACL,CAAC,EAAE,GAAG;AAAA,IACN,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,KAAK,GAAG;AAAA,IACT,CAAC,OAAO,KAAK,GAAG;AAAA,IAChB,CAAC,KAAK,IAAI,GAAG;AAAA,IACb,CAAC,OAAO,KAAK,GAAG;AAAA,IAChB,CAAC,OAAO,IAAI,GAAG;AAAA,IACf,CAAC,KAAK,KAAK,GAAG;AAAA,IACd,CAAC,KAAK,IAAI,GAAG;AAAA,IACb,CAAC,KAAK,OAAO,KAAK,GAAG;AAAA,IACrB,CAAC,KAAK,OAAO,IAAI,GAAG;AAAA,IACpB,CAAC,OAAO,QAAQ,IAAI,GAAG;AAAA,IACvB,CAAC,OAAO,QAAQ,EAAE,GAAG;AAAA,IACrB,CAAC,KAAK,OAAO,OAAO,KAAK,GAAG;AAAA,EAAA;AAAA,EAE9B,OAA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vB,eAAW,OAAO,UAAU;AAC1B,YAAM,KAAK,UAAU,IAAI,KAAK,EAAE,CAAC;AAAA,IACnC;AACA,UAAM,KAAK,UAAU,IAAI,OAAO,SAAS,IAAI,MAAM,gBAAgB;AAAA,EACrE,OAAO;AACL,eAAW,OAAO,UAAU;AAC1B,YAAM,KAAK,IAAI,KAAK,EAAE,CAAC;AAAA,IACzB;AAAA,EACF;AAEA,MAAI,kBAAkB;AACpB,UAAM,QAAQ,EAAE;AAAA,EAClB;AAEA,QAAM,SAAS,MAAM,KAAK,IAAI;AAE9B,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,MAAM;AAAA,EACrB;AAEA,SAAO;AACT;"}
1
+ {"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":["interface Rectangle {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n// Direction bitmasks\nconst UP = 1;\nconst DOWN = 2;\nconst LEFT = 4;\nconst RIGHT = 8;\n\ntype LineStyle = \"light\" | \"heavy\" | \"double\" | \"dashed\" | \"dashed-heavy\";\n\nconst STYLES: LineStyle[] = [\"light\", \"heavy\", \"double\", \"dashed\", \"dashed-heavy\"];\n\n// Box-drawing character maps for each style\nconst STYLE_CHARS: Record<LineStyle, Record<number, string>> = {\n light: {\n [UP]: \"╵\",\n [DOWN]: \"╷\",\n [LEFT]: \"╴\",\n [RIGHT]: \"╶\",\n [LEFT | RIGHT]: \"─\",\n [UP | DOWN]: \"│\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n heavy: {\n [UP]: \"╹\",\n [DOWN]: \"╻\",\n [LEFT]: \"╸\",\n [RIGHT]: \"╺\",\n [LEFT | RIGHT]: \"━\",\n [UP | DOWN]: \"┃\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n double: {\n [UP]: \"║\",\n [DOWN]: \"║\",\n [LEFT]: \"═\",\n [RIGHT]: \"═\",\n [LEFT | RIGHT]: \"═\",\n [UP | DOWN]: \"║\",\n [DOWN | RIGHT]: \"╔\",\n [DOWN | LEFT]: \"╗\",\n [UP | RIGHT]: \"╚\",\n [UP | LEFT]: \"╝\",\n [UP | DOWN | RIGHT]: \"╠\",\n [UP | DOWN | LEFT]: \"╣\",\n [LEFT | RIGHT | DOWN]: \"╦\",\n [LEFT | RIGHT | UP]: \"╩\",\n [UP | DOWN | LEFT | RIGHT]: \"╬\",\n },\n dashed: {\n [UP]: \"╎\",\n [DOWN]: \"╎\",\n [LEFT]: \"╌\",\n [RIGHT]: \"╌\",\n [LEFT | RIGHT]: \"╌\",\n [UP | DOWN]: \"╎\",\n [DOWN | RIGHT]: \"┌\",\n [DOWN | LEFT]: \"┐\",\n [UP | RIGHT]: \"└\",\n [UP | LEFT]: \"┘\",\n [UP | DOWN | RIGHT]: \"├\",\n [UP | DOWN | LEFT]: \"┤\",\n [LEFT | RIGHT | DOWN]: \"┬\",\n [LEFT | RIGHT | UP]: \"┴\",\n [UP | DOWN | LEFT | RIGHT]: \"┼\",\n },\n \"dashed-heavy\": {\n [UP]: \"╏\",\n [DOWN]: \"╏\",\n [LEFT]: \"╍\",\n [RIGHT]: \"╍\",\n [LEFT | RIGHT]: \"╍\",\n [UP | DOWN]: \"╏\",\n [DOWN | RIGHT]: \"┏\",\n [DOWN | LEFT]: \"┓\",\n [UP | RIGHT]: \"┗\",\n [UP | LEFT]: \"┛\",\n [UP | DOWN | RIGHT]: \"┣\",\n [UP | DOWN | LEFT]: \"┫\",\n [LEFT | RIGHT | DOWN]: \"┳\",\n [LEFT | RIGHT | UP]: \"┻\",\n [UP | DOWN | LEFT | RIGHT]: \"╋\",\n },\n};\n\ninterface CellData {\n directions: number;\n zIndex: number;\n}\n\ninterface IndexData {\n char: string;\n zIndex: number;\n}\n\nexport interface LogRectsOptions {\n sizePerPoint?: number;\n showLegend?: boolean;\n dontLog?: boolean;\n startWithNewLine?: boolean;\n}\n\nexport function logRects(\n rectangles: Rectangle[],\n { sizePerPoint = 10, showLegend = true, dontLog = false, startWithNewLine = true }: LogRectsOptions = {}\n): string {\n if (rectangles.length === 0) {\n return \"No rectangles to draw\";\n }\n\n // Find bounding box of all rectangles\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const rect of rectangles) {\n minX = Math.min(minX, rect.x);\n minY = Math.min(minY, rect.y);\n maxX = Math.max(maxX, rect.x + rect.width);\n maxY = Math.max(maxY, rect.y + rect.height);\n }\n\n // Calculate grid dimensions based on resolution\n const gridWidth = Math.ceil((maxX - minX) / sizePerPoint);\n const gridHeight = Math.ceil((maxY - minY) / sizePerPoint);\n\n // Create grid to track directions and z-index at each cell\n const grid: CellData[][] = Array.from({ length: gridHeight }, () =>\n Array.from({ length: gridWidth }, () => ({ directions: 0, zIndex: -1 }))\n );\n\n // Create index overlay grid\n const indexGrid: (IndexData | null)[][] = Array.from({ length: gridHeight }, () => Array(gridWidth).fill(null));\n\n // Helper to set cell data with z-index awareness\n const setCell = (row: number, col: number, direction: number, zIndex: number) => {\n if (row < 0 || row >= gridHeight || col < 0 || col >= gridWidth) return;\n const cell = grid[row][col];\n if (zIndex >= cell.zIndex) {\n if (zIndex > cell.zIndex) {\n cell.directions = 0;\n cell.zIndex = zIndex;\n }\n cell.directions |= direction;\n }\n };\n\n // Helper to draw a horizontal line segment\n const drawHorizontal = (row: number, colStart: number, colEnd: number, zIndex: number) => {\n for (let col = colStart; col <= colEnd; col++) {\n let dirs = 0;\n if (col > colStart) dirs |= LEFT;\n if (col < colEnd) dirs |= RIGHT;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Helper to draw a vertical line segment\n const drawVertical = (col: number, rowStart: number, rowEnd: number, zIndex: number) => {\n for (let row = rowStart; row <= rowEnd; row++) {\n let dirs = 0;\n if (row > rowStart) dirs |= UP;\n if (row < rowEnd) dirs |= DOWN;\n if (dirs) setCell(row, col, dirs, zIndex);\n }\n };\n\n // Draw each rectangle's outline with z-index = array index\n rectangles.forEach((rect, zIndex) => {\n const startCol = Math.floor((rect.x - minX) / sizePerPoint);\n const startRow = Math.floor((rect.y - minY) / sizePerPoint);\n const endCol = Math.ceil((rect.x + rect.width - minX) / sizePerPoint) - 1;\n const endRow = Math.ceil((rect.y + rect.height - minY) / sizePerPoint) - 1;\n\n // Draw the four edges\n drawHorizontal(startRow, startCol, endCol, zIndex);\n drawHorizontal(endRow, startCol, endCol, zIndex);\n drawVertical(startCol, startRow, endRow, zIndex);\n drawVertical(endCol, startRow, endRow, zIndex);\n\n // Place index at center of top edge if there's room\n const indexStr = String(zIndex);\n const edgeWidth = endCol - startCol; // number of segments (cells - 1)\n\n // Need at least 1 line char on each side of the index\n // Inner width (excluding corners) = edgeWidth - 1\n // Required: innerWidth >= indexStr.length + 2\n if (edgeWidth >= indexStr.length + 3) {\n const innerWidth = edgeWidth - 1;\n const indexStart = startCol + 1 + Math.floor((innerWidth - indexStr.length) / 2);\n\n for (let i = 0; i < indexStr.length; i++) {\n const col = indexStart + i;\n if (col >= 0 && col < gridWidth && startRow >= 0 && startRow < gridHeight) {\n const existing = indexGrid[startRow][col];\n if (!existing || zIndex >= existing.zIndex) {\n indexGrid[startRow][col] = { char: indexStr[i], zIndex };\n }\n }\n }\n }\n });\n\n // Convert cell data to characters, respecting z-index for both edges and indices\n const charGrid: string[][] = grid.map((row, rowIdx) =>\n row.map((cell, colIdx) => {\n const indexData = indexGrid[rowIdx][colIdx];\n\n // If there's an index with higher or equal z-index, use it\n if (indexData && indexData.zIndex >= cell.zIndex) {\n return indexData.char;\n }\n\n // Otherwise use edge character\n if (cell.directions === 0) return \" \";\n const style = STYLES[cell.zIndex % STYLES.length];\n return STYLE_CHARS[style][cell.directions] || \"?\";\n })\n );\n\n // Build output string\n const lines: string[] = [];\n\n if (showLegend) {\n const topLeftLabel = `[${minX}, ${minY}]`;\n const bottomRightLabel = `[${maxX}, ${maxY}]`;\n const padding = \" \".repeat(topLeftLabel.length + 1);\n\n lines.push(topLeftLabel);\n for (const row of charGrid) {\n lines.push(padding + row.join(\"\"));\n }\n lines.push(padding + \" \".repeat(gridWidth) + \" \" + bottomRightLabel);\n } else {\n for (const row of charGrid) {\n lines.push(row.join(\"\"));\n }\n }\n\n if (startWithNewLine) {\n lines.unshift(\"\");\n }\n\n const output = lines.join(\"\\n\");\n\n if (!dontLog) {\n console.info(output);\n }\n\n return output;\n}\n"],"names":[],"mappings":"AAQA,MAAM,KAAK;AACX,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,QAAQ;AAId,MAAM,SAAsB,CAAC,SAAS,SAAS,UAAU,UAAU,cAAc;AAGjF,MAAM,cAAyD;AAAA,EAC7D,OAAO;AAAA,IACL,CAAC,EAAE,GAAG;AAAA,IACN,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,IAAI,GAAG;AAAA,IACR,CAAC,KAAK,GAAG;AAAA,IACT,CAAC,OAAO,KAAK,GAAG;AAAA,IAChB,CAAC,KAAK,IAAI,GAAG;AAAA,IACb,CAAC,OAAO,KAAK,GAAG;AAAA,IAChB,CAAC,OAAO,IAAI,GAAG;AAAA,IACf,CAAC,KAAK,KAAK,GAAG;AAAA,IACd,CAAC,KAAK,IAAI,GAAG;AAAA,IACb,CAAC,KAAK,OAAO,KAAK,GAAG;AAAA,IACrB,CAAC,KAAK,OAAO,IAAI,GAAG;AAAA,IACpB,CA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;
@@ -7,8 +7,8 @@ interface Rect {
7
7
  export interface LogRectsOptions {
8
8
  sizePerPoint?: number;
9
9
  showLegend?: boolean;
10
- startWithNewLine?: boolean;
11
10
  dontLog?: boolean;
11
+ startWithNewLine?: boolean;
12
12
  }
13
- export declare function logRects(rectangles: Rect[], { sizePerPoint, showLegend, startWithNewLine, dontLog }?: LogRectsOptions): string;
13
+ export declare function logRects(rectangles: Rectangle[], { sizePerPoint, showLegend, dontLog, startWithNewLine }?: LogRectsOptions): string;
14
14
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "console-rects",
3
- "version": "0.1.1",
4
- "description": "Visualize rectangles in the console using box-drawing characters. Perfect for debugging geometry code.",
3
+ "version": "0.1.3",
4
+ "description": "Visualize rectangles in the console using box-drawing characters. Perfect for debugging geometry code, visualizing overlapping rectangles, or drawing rectangles in terminal.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
@@ -26,7 +26,18 @@
26
26
  "ascii",
27
27
  "box-drawing",
28
28
  "debugging",
29
- "cli"
29
+ "cli",
30
+ "terminal",
31
+ "overlapping-rectangles",
32
+ "console-log",
33
+ "visualize-rectangles",
34
+ "draw-rectangles",
35
+ "debug-geometry",
36
+ "rectangle-collision",
37
+ "layout-debug",
38
+ "console-visualization",
39
+ "terminal-visualization",
40
+ "ascii-art"
30
41
  ],
31
42
  "author": {
32
43
  "name": "Adam Pietrasiak",