Skip to content

Commit 4b66941

Browse files
committed
pnpm format
1 parent 1a0db4f commit 4b66941

5 files changed

Lines changed: 122 additions & 123 deletions

File tree

src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const getDraftState = (state: State, draftClick: DraftClick, mousePosition: Abso
2222
const draftPattern = {
2323
anchor: draftClick.anchor,
2424
target: mousePosition,
25-
}
25+
}
2626

2727
if (draftClick.clickedPath === undefined) {
2828
// create top-level screen
@@ -32,7 +32,6 @@ const getDraftState = (state: State, draftClick: DraftClick, mousePosition: Abso
3232
// if draft origin is inside existing screen, add a pattern instead
3333
const { screenIndex, nestedPath } = draftClick.clickedPath
3434

35-
3635
// Re-interpret as relative pattern.
3736
const draftPatternRelative = draftPattern satisfies AbsolutePattern as unknown as RelativePattern
3837

src/draw.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ import { Boundaries, Size, State, ViewportNumber, ViewportPattern } from './type
1010
// -- constants
1111

1212
const COLOR_SIZE = 50
13-
const COLORS = Array(COLOR_SIZE).fill(undefined).map((_, i) => {
14-
const frac = i / COLOR_SIZE
13+
const COLORS = Array(COLOR_SIZE)
14+
.fill(undefined)
15+
.map((_, i) => {
16+
const frac = i / COLOR_SIZE
1517

16-
const hue = (80 + 360 * frac) % 360
17-
const saturation = 50 + (frac * 30)
18-
const lightness = 60
18+
const hue = (80 + 360 * frac) % 360
19+
const saturation = 50 + frac * 30
20+
const lightness = 60
1921

20-
return `hsl(${hue} ${saturation}% ${lightness}%)`
21-
})
22+
return `hsl(${hue} ${saturation}% ${lightness}%)`
23+
})
2224

2325
const MIN_DEPTH = 3
2426
const MAX_DEPTH = Infinity
@@ -206,14 +208,14 @@ function* streamBatchedDrawablePatterns({
206208
} else {
207209
chunk.patterns.push(entry.currentPattern)
208210

209-
if (chunk.patterns.length >= chunkSize) {
210-
yield chunk
211-
chunk = {
212-
depth: entry.depth,
213-
patterns: [],
211+
if (chunk.patterns.length >= chunkSize) {
212+
yield chunk
213+
chunk = {
214+
depth: entry.depth,
215+
patterns: [],
216+
}
214217
}
215218
}
216-
}
217219
}
218220

219221
if (chunk.patterns.length > 0) {

src/queue.test.ts

Lines changed: 104 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,144 @@
1-
import { describe, it, expect } from 'vitest';
2-
import { Queue } from './queue';
3-
4-
1+
import { describe, expect, it } from 'vitest'
2+
import { Queue } from './queue'
53

64
describe('Queue', () => {
75
it('should initialize an empty queue', () => {
8-
const queue = new Queue<number>({ size: 5 });
9-
expect(queue.size).toBe(0);
10-
});
6+
const queue = new Queue<number>({ size: 5 })
7+
expect(queue.size).toBe(0)
8+
})
119

1210
it('should initialize a queue with initial items', () => {
13-
const queue = new Queue<number>({ initialItems: [1, 2, 3], size: 3 });
14-
expect(queue.size).toBe(3);
15-
});
11+
const queue = new Queue<number>({ initialItems: [1, 2, 3], size: 3 })
12+
expect(queue.size).toBe(3)
13+
})
1614

1715
it('should throw an error if initial items exceed capacity', () => {
18-
expect(() => new Queue<number>({ initialItems: [1, 2, 3, 4], size: 3 })).toThrow('Initial items exceed queue capacity');
19-
});
16+
expect(() => new Queue<number>({ initialItems: [1, 2, 3, 4], size: 3 })).toThrow(
17+
'Initial items exceed queue capacity'
18+
)
19+
})
2020

2121
it('should push items to the queue up to its capacity', () => {
22-
const queue = new Queue<string>({ size: 2 });
23-
queue.push('a');
24-
expect(queue.size).toBe(1);
25-
queue.push('b');
26-
expect(queue.size).toBe(2);
27-
});
22+
const queue = new Queue<string>({ size: 2 })
23+
queue.push('a')
24+
expect(queue.size).toBe(1)
25+
queue.push('b')
26+
expect(queue.size).toBe(2)
27+
})
2828

2929
it('should throw an error when pushing to a full queue', () => {
30-
const queue = new Queue<string>({ initialItems: ['a'], size: 1 });
31-
expect(() => queue.push('b')).toThrow('Queue is full');
32-
});
30+
const queue = new Queue<string>({ initialItems: ['a'], size: 1 })
31+
expect(() => queue.push('b')).toThrow('Queue is full')
32+
})
3333

3434
it('should shift items from the queue in FIFO order', () => {
35-
const queue = new Queue<number>({ initialItems: [1, 2, 3], size: 3 });
36-
expect(queue.shift()).toBe(1);
37-
expect(queue.size).toBe(2);
38-
expect(queue.shift()).toBe(2);
39-
expect(queue.size).toBe(1);
40-
expect(queue.shift()).toBe(3);
41-
expect(queue.size).toBe(0);
42-
});
35+
const queue = new Queue<number>({ initialItems: [1, 2, 3], size: 3 })
36+
expect(queue.shift()).toBe(1)
37+
expect(queue.size).toBe(2)
38+
expect(queue.shift()).toBe(2)
39+
expect(queue.size).toBe(1)
40+
expect(queue.shift()).toBe(3)
41+
expect(queue.size).toBe(0)
42+
})
4343

4444
it('should throw an error when shifting from an empty queue', () => {
45-
const queue = new Queue<number>({ size: 5 });
46-
expect(() => queue.shift()).toThrow('Queue is empty');
47-
});
45+
const queue = new Queue<number>({ size: 5 })
46+
expect(() => queue.shift()).toThrow('Queue is empty')
47+
})
4848

4949
it('should handle a mix of push and shift operations correctly', () => {
50-
const queue = new Queue<string>({ size: 2 });
51-
queue.push('one');
52-
queue.push('two');
53-
expect(queue.shift()).toBe('one');
54-
queue.push('three');
55-
expect(queue.size).toBe(2);
56-
expect(queue.shift()).toBe('two');
57-
expect(queue.shift()).toBe('three');
58-
expect(queue.size).toBe(0);
59-
});
50+
const queue = new Queue<string>({ size: 2 })
51+
queue.push('one')
52+
queue.push('two')
53+
expect(queue.shift()).toBe('one')
54+
queue.push('three')
55+
expect(queue.size).toBe(2)
56+
expect(queue.shift()).toBe('two')
57+
expect(queue.shift()).toBe('three')
58+
expect(queue.size).toBe(0)
59+
})
6060

6161
it('should report correct size after multiple pushes and shifts', () => {
62-
const queue = new Queue<number>({ initialItems: [1, 2], size: 5 });
63-
queue.push(3);
64-
expect(queue.size).toBe(3);
65-
queue.shift();
66-
expect(queue.size).toBe(2);
67-
queue.push(4);
68-
expect(queue.size).toBe(3);
69-
expect(queue.shift()).toBe(2);
70-
expect(queue.shift()).toBe(3);
71-
expect(queue.shift()).toBe(4);
72-
expect(queue.size).toBe(0);
73-
});
62+
const queue = new Queue<number>({ initialItems: [1, 2], size: 5 })
63+
queue.push(3)
64+
expect(queue.size).toBe(3)
65+
queue.shift()
66+
expect(queue.size).toBe(2)
67+
queue.push(4)
68+
expect(queue.size).toBe(3)
69+
expect(queue.shift()).toBe(2)
70+
expect(queue.shift()).toBe(3)
71+
expect(queue.shift()).toBe(4)
72+
expect(queue.size).toBe(0)
73+
})
7474

7575
it('should allow pushing after shifting from a full queue', () => {
76-
const queue = new Queue<number>({ initialItems: [1, 2, 3], size: 3 });
77-
expect(queue.size).toBe(3);
78-
expect(queue.shift()).toBe(1);
79-
expect(queue.size).toBe(2);
80-
queue.push(4);
81-
expect(queue.size).toBe(3);
82-
expect(queue.shift()).toBe(2);
83-
expect(queue.shift()).toBe(3);
84-
expect(queue.shift()).toBe(4);
85-
expect(queue.size).toBe(0);
86-
});
76+
const queue = new Queue<number>({ initialItems: [1, 2, 3], size: 3 })
77+
expect(queue.size).toBe(3)
78+
expect(queue.shift()).toBe(1)
79+
expect(queue.size).toBe(2)
80+
queue.push(4)
81+
expect(queue.size).toBe(3)
82+
expect(queue.shift()).toBe(2)
83+
expect(queue.shift()).toBe(3)
84+
expect(queue.shift()).toBe(4)
85+
expect(queue.size).toBe(0)
86+
})
8787

8888
it('should throw if initializing with more items than queue size', () => {
89-
expect(() => new Queue<number>({ initialItems: [1, 2], size: 1 })).toThrow('Initial items exceed queue capacity');
90-
});
89+
expect(() => new Queue<number>({ initialItems: [1, 2], size: 1 })).toThrow(
90+
'Initial items exceed queue capacity'
91+
)
92+
})
9193

9294
it('should throw if initializing with non-positive size', () => {
93-
expect(() => new Queue<number>({ size: 0 })).toThrow('Queue size must be positive');
94-
});
95+
expect(() => new Queue<number>({ size: 0 })).toThrow('Queue size must be positive')
96+
})
9597

9698
it('should handle operations on a queue of size 1', () => {
97-
const queue = new Queue<number>({ size: 1 });
98-
expect(queue.size).toBe(0);
99+
const queue = new Queue<number>({ size: 1 })
100+
expect(queue.size).toBe(0)
99101

100-
queue.push(10);
101-
expect(queue.size).toBe(1);
102-
expect(() => queue.push(20)).toThrow('Queue is full');
102+
queue.push(10)
103+
expect(queue.size).toBe(1)
104+
expect(() => queue.push(20)).toThrow('Queue is full')
103105

104-
expect(queue.shift()).toBe(10);
105-
expect(queue.size).toBe(0);
106-
expect(() => queue.shift()).toThrow('Queue is empty');
106+
expect(queue.shift()).toBe(10)
107+
expect(queue.size).toBe(0)
108+
expect(() => queue.shift()).toThrow('Queue is empty')
107109

108-
queue.push(30);
109-
expect(queue.size).toBe(1);
110-
expect(queue.shift()).toBe(30);
111-
});
110+
queue.push(30)
111+
expect(queue.size).toBe(1)
112+
expect(queue.shift()).toBe(30)
113+
})
112114

113115
it('should correctly handle fill-empty-fill-empty cycles (circular buffer integrity)', () => {
114-
const queue = new Queue<number>({ size: 3 });
116+
const queue = new Queue<number>({ size: 3 })
115117

116118
// Fill 1
117-
queue.push(1);
118-
queue.push(2);
119-
queue.push(3);
120-
expect(queue.size).toBe(3);
121-
expect(() => queue.push(4)).toThrow('Queue is full');
119+
queue.push(1)
120+
queue.push(2)
121+
queue.push(3)
122+
expect(queue.size).toBe(3)
123+
expect(() => queue.push(4)).toThrow('Queue is full')
122124

123125
// Empty 1
124-
expect(queue.shift()).toBe(1);
125-
expect(queue.shift()).toBe(2);
126-
expect(queue.shift()).toBe(3);
127-
expect(queue.size).toBe(0);
128-
expect(() => queue.shift()).toThrow('Queue is empty');
126+
expect(queue.shift()).toBe(1)
127+
expect(queue.shift()).toBe(2)
128+
expect(queue.shift()).toBe(3)
129+
expect(queue.size).toBe(0)
130+
expect(() => queue.shift()).toThrow('Queue is empty')
129131

130132
// Fill 2 (after wrapping)
131-
queue.push(10);
132-
queue.push(20);
133-
queue.push(30);
134-
expect(queue.size).toBe(3);
133+
queue.push(10)
134+
queue.push(20)
135+
queue.push(30)
136+
expect(queue.size).toBe(3)
135137

136138
// Empty 2
137-
expect(queue.shift()).toBe(10);
138-
expect(queue.shift()).toBe(20);
139-
expect(queue.shift()).toBe(30);
140-
expect(queue.size).toBe(0);
141-
});
142-
});
139+
expect(queue.shift()).toBe(10)
140+
expect(queue.shift()).toBe(20)
141+
expect(queue.shift()).toBe(30)
142+
expect(queue.size).toBe(0)
143+
})
144+
})

src/queue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class Queue<T> {
77
private tail = 0
88
private _size = 0
99

10-
constructor({initialItems = [], size}: { initialItems?: T[], size: number}) {
10+
constructor({ initialItems = [], size }: { initialItems?: T[]; size: number }) {
1111
if (size <= 0) {
1212
throw new Error('Queue size must be positive')
1313
}
@@ -18,7 +18,7 @@ export class Queue<T> {
1818

1919
this.buffer = new Array(size).fill(undefined)
2020

21-
for (let i = 0; i< initialItems.length; i++) {
21+
for (let i = 0; i < initialItems.length; i++) {
2222
this.buffer[i] = initialItems[i]
2323
}
2424

src/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
21
type Brand<T, B extends string> = T & { readonly __brand: B }
32

4-
53
// ts-unused-exports:disable-next-line
64
export type RelativeNumber = Brand<number, 'RelativeNumber'>
75
// ts-unused-exports:disable-next-line
86
export type AbsoluteNumber = Brand<number, 'AbsoluteNumber'>
97
export type ViewportNumber = Brand<number, 'ViewportNumber'>
108

11-
129
export type PatternNumber = RelativeNumber | AbsoluteNumber | ViewportNumber
1310

1411
// Used as intermediate type when casting after doing calculations on coordinates.
@@ -43,7 +40,6 @@ export type AbsolutePattern = Pattern<AbsoluteNumber>
4340
// represents a pattern in viewport coordinates.
4441
export type ViewportPattern = Pattern<ViewportNumber>
4542

46-
4743
export type Boundaries<N extends PatternNumber> = {
4844
xMin: N
4945
xMax: N

0 commit comments

Comments
 (0)