@skillre/dsh-plugin-sticky-wall 0.4.0 → 0.6.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.
package/lib/layout.d.ts CHANGED
@@ -5,22 +5,22 @@
5
5
  * rotation and a width preset. Two operations produce those numbers:
6
6
  *
7
7
  * - {@link arrangeLayouts} is the Host-side "tidy" pass. It packs the wall into
8
- * a phyllotaxis (sunflower) disc **centred on the world origin**, so the wall
9
- * has a middle instead of a top-left corner: the Client opens looking at that
10
- * middle, and a tidied wall reads as one composition rather than a list that
11
- * happens to wrap. It is deterministic — the same notes always produce the
12
- * same wall — and it is collision-checked rather than estimated, so two cards
13
- * can never overlap even at the height cap.
8
+ * a compact cluster **centred on the world origin**, hugging the rectangle the
9
+ * centrepiece reserves: the Client opens looking at that middle, and a tidied
10
+ * wall reads as one composition rather than a list that happens to wrap. It is
11
+ * deterministic — the same notes always produce the same wall — and it is
12
+ * collision-checked rather than estimated, so two cards can never overlap even
13
+ * at the height cap.
14
14
  * - {@link previewLayout} is the Client-side fallback for a note that was never
15
15
  * placed (a wall written before the canvas existed, or a note created by the
16
- * agent tool). It is the same spiral without the collision check: O(1) per
17
- * note, index-stable, and centred, so the first render is already a scattered
18
- * wall around the middle instead of one tall stack.
16
+ * agent tool). It is a golden-angle spiral without the collision check: O(1)
17
+ * per note, index-stable, and centred, so the first render is already a
18
+ * scattered wall around the middle instead of one tall stack.
19
19
  *
20
20
  * Both halves import this module, so the geometry never drifts between the
21
21
  * value the Host persists and the value the Client previews.
22
22
  */
23
- import { type Note, type NoteLayout, type NoteWidth } from './types.js';
23
+ import { type CentreReserve, type Note, type NoteLayout, type NoteWidth } from './types.js';
24
24
  /** Clamp one layout into the declared world bounds. */
25
25
  export declare function clampLayout(layout: NoteLayout): NoteLayout;
26
26
  /** True when two layouts describe the same position (rounded comparison). */
@@ -44,10 +44,14 @@ export declare function layoutOf(note: Note, index: number): NoteLayout;
44
44
  /**
45
45
  * Derived position for a note the user never placed.
46
46
  *
47
- * Index-based so two never-placed notes cannot collide, golden-angle spiralled
48
- * so the result reads as a wall scattered around the middle rather than a grid.
49
- * The height used for centring is a nominal constant, not the real estimate:
50
- * a derived position must not move when the user edits the note's text.
47
+ * Index-based so two never-placed notes cannot collide, and laid out on a
48
+ * SQUASHED spiral — the same golden-angle walk with its radius stretched along
49
+ * the x axis — so the result reads as a wide cluster around the middle rather
50
+ * than a circle or a grid. The squash matters: a circle leaves the left and
51
+ * right of a wide window empty and the camera then has to zoom out to frame the
52
+ * empty corners, which is the same "everything looks small" failure the tidy
53
+ * pass fixes. The height used for centring is a nominal constant, not the real
54
+ * estimate: a derived position must not move when the user edits the text.
51
55
  */
52
56
  export declare function previewLayout(note: Note, index: number): NoteLayout;
53
57
  /**
@@ -62,26 +66,140 @@ export declare function rotatedExtent(width: number, height: number, rotate: num
62
66
  width: number;
63
67
  height: number;
64
68
  };
69
+ /**
70
+ * Whether a footprint stays out of a clear rectangle.
71
+ *
72
+ * The tidy pass keeps the wall's middle clear for the centrepiece, and "clear"
73
+ * has to mean the card's EDGE: measuring from the card's centre let a wide card
74
+ * reach over the capture field by half its own width. A rectangle rather than a
75
+ * radius is the honest shape, because the centrepiece is a wide, short stack —
76
+ * a circle either wasted a tall column of paper above and below it or let wide
77
+ * cards in from the sides.
78
+ */
79
+ export declare function intersectsReserve(box: Box, reserve?: CentreReserve): boolean;
80
+ /** One axis-aligned footprint on the wall, in world pixels. */
81
+ export interface Box {
82
+ x: number;
83
+ y: number;
84
+ width: number;
85
+ height: number;
86
+ }
65
87
  /**
66
88
  * Deterministic tidy arrangement for the whole wall.
67
89
  *
68
- * Phyllotaxis packing around the world origin: candidate positions are visited
69
- * on a sunflower spiral and the first one that clears every placed card is
70
- * accepted. The spiral's step is derived from the wall's own average card area,
71
- * so a wall of small notes packs tightly while a wall of large ones does not
72
- * overlap, and a big wall grows outward in a disc instead of a column that runs
73
- * off the coordinate limit.
90
+ * The wall is packed against a CONTOUR: the reserved rectangle's own outline,
91
+ * walked outward frame by frame. This is the third packer in this file's
92
+ * history and each replacement fixed a measured failure rather than a taste.
93
+ *
94
+ * 1. A phyllotaxis first-fit spiral had to keep every candidate clear of a
95
+ * card's full bounding circle, so it saturated at roughly a quarter of the
96
+ * available area and the only way to place the next card was to walk further
97
+ * out: fourteen cards spread over ~2700px of paper.
98
+ * 2. Concentric RINGS fixed that density but paid for it with distance. A ring
99
+ * is a circle, and the first ring's radius is the reserve's half-DIAGONAL —
100
+ * so the innermost cards sit at the rectangle's corner distance in every
101
+ * direction, including the four directions where the rectangle is only a
102
+ * card's width away. A fourteen-card wall then filled a 1645x1794 box, which
103
+ * the camera could only frame at 36%: the cards were individually packed
104
+ * tightly but the wall as a whole looked small and far away. That is the
105
+ * complaint this packer answers.
106
+ * 3. A contour hugs the rectangle instead: along the left and right edges a card
107
+ * sits one card-half-width from the reserve, and along the top and bottom one
108
+ * card-half-height from it. Every card is therefore as close to the middle as
109
+ * its own size allows, which is what makes the wall read as one composition.
110
+ *
111
+ * Two further decisions do the rest of the work:
74
112
  *
75
- * A collision check rather than a shelf estimate is what makes the result
76
- * trustworthy: the estimate is only a height guess, so any packing that merely
77
- * trusts it can overlap at the cap. This one cannot.
113
+ * - **Score by how well the wall FRAMES, not by how free the slot is.** A
114
+ * candidate slot is judged by the zoom the whole wall would need in a
115
+ * reference viewport if the card went there. Filling a slot that widens the
116
+ * wall's box costs zoom, so the packer prefers slots that keep the box close
117
+ * to the window's own aspect — which is why the result is a wide, low cluster
118
+ * instead of a disc that leaves the left and right of the window empty.
119
+ * - **The first frame with room wins.** Walking outward frame by frame and
120
+ * taking the best-scoring slot on the first frame that has any is what makes
121
+ * every card land near the middle: an outer frame is only reached when the
122
+ * inner ones are genuinely full.
123
+ *
124
+ * A collision check still runs on every candidate rather than trusting the
125
+ * height estimate, because the estimate is a line count and a code block's
126
+ * padding is not something a line count can see. The packer never produces an
127
+ * overlap, and the final centring passes repair any card the centring shift
128
+ * nudged into the reserved rectangle.
78
129
  *
79
130
  * Returns a map from note id to its new layout, for every note that needs to
80
131
  * move. Notes already at exactly that layout are omitted by the caller, so
81
132
  * pressing tidy on an already-tidy wall writes nothing.
82
133
  */
83
134
  export declare function arrangeLayouts(notes: readonly Note[], options?: {
84
- centreRadius?: number;
135
+ centreReserve?: CentreReserve | undefined;
85
136
  }): Map<string, NoteLayout>;
86
137
  /** Normalize a submitted width preset, defaulting to the middle size. */
87
138
  export declare function normalizeWidth(raw: unknown): NoteWidth;
139
+ /**
140
+ * Clamp a reserve into something the packer can actually honour.
141
+ *
142
+ * The Client sends a zoom-corrected reserve, so it can arrive as a huge number
143
+ * (a deeply zoomed-out wall) or as garbage. Both extremes are refused here: a
144
+ * non-finite or negative half-extent becomes zero, and the whole reserve is
145
+ * capped well inside the world bounds so the packer can never be asked to keep
146
+ * a middle clear that leaves no paper for the cards.
147
+ */
148
+ export declare function normalizeReserve(raw: CentreReserve): CentreReserve;
149
+ /**
150
+ * The nearest free spot for one new card, in world coordinates.
151
+ *
152
+ * Creating a note used to leave its placement to the Host, which stored `null`
153
+ * and let the Client derive a position from the note's index — and that derived
154
+ * position is a spiral that grows outward, so the tenth note could land a
155
+ * screen and a half away from where the user was looking. The card existed, but
156
+ * the user could not see it, which reads exactly like the capture silently
157
+ * failing.
158
+ *
159
+ * This searches outward from the middle instead: the spiral is walked from just
160
+ * outside the centrepiece's reserve, and the first candidate that clears every
161
+ * existing card (plus a gap) and stays out of the reserve is the answer. The
162
+ * result is therefore the gap nearest the centre of the wall, which is both
163
+ * where the user is looking and where the wall has room.
164
+ *
165
+ * Deterministic for the same inputs, so two windows creating at once cannot
166
+ * disagree about the free spot for the same wall.
167
+ */
168
+ export declare function findFreeLayout(note: Note, existing: readonly Note[], options?: {
169
+ centreReserve?: CentreReserve | undefined;
170
+ }): NoteLayout;
171
+ /**
172
+ * The footprint one note occupies on the wall, as an axis-aligned box.
173
+ *
174
+ * Exposed because the Client needs it for two things the packer already knows:
175
+ * testing whether a card is inside the current viewport, and drawing the reserve
176
+ * it must not cover.
177
+ */
178
+ export declare function noteBox(note: Note, index: number): Box;
179
+ /**
180
+ * The footprint a note occupies at a GIVEN layout.
181
+ *
182
+ * Split out from {@link noteBox} because the useful question is often about a
183
+ * layout that is not stored yet — a planned tidy position, or a candidate spot
184
+ * for a card that does not exist. `noteBox` answers "where is this note now";
185
+ * this answers "where would it be".
186
+ */
187
+ /**
188
+ * Nudge a layout out of the centrepiece's reserved rectangle.
189
+ *
190
+ * The reserve is not only a packing rule: a user can drag a card straight over
191
+ * the quick-capture field, and a card parked there hides the wall's own controls
192
+ * behind itself. This returns the smallest translation that puts the card's
193
+ * footprint clear of the rectangle, which makes the reserve behave like a
194
+ * magnetic edge during a drag rather than a rule that is only enforced on tidy.
195
+ */
196
+ /**
197
+ * Every way out of the reserve, shortest first.
198
+ *
199
+ * Exposed separately from {@link pushOutOfReserve} because the shortest escape is
200
+ * not always usable — it can land on a neighbour — so a caller that cares about
201
+ * collisions needs the whole ordered list, not just the first answer.
202
+ */
203
+ export declare function escapesFromReserve(note: Note, layout: NoteLayout, reserve?: CentreReserve): NoteLayout[];
204
+ export declare function pushOutOfReserve(note: Note, layout: NoteLayout, reserve?: CentreReserve): NoteLayout;
205
+ export declare function footprintOf(note: Note, layout: NoteLayout): Box;