@skillre/dsh-plugin-sticky-wall 0.3.0 → 0.4.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/README.en.md +5 -2
- package/README.md +5 -2
- package/compatibility.json +9 -3
- package/docs/preview.svg +84 -62
- package/docs/preview.zh.svg +84 -62
- package/lib/client.js +290 -111
- package/lib/layout.d.ts +3 -1
- package/lib/layout.js +52 -6
- package/lib/types.d.ts +9 -0
- package/lib/types.js +9 -0
- package/package.json +1 -1
package/lib/layout.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
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 { LAYOUT_LIMITS, WIDTHS, WIDTH_PX } from './types.js';
|
|
23
|
+
import { CENTRE_RADIUS, LAYOUT_LIMITS, WIDTHS, WIDTH_PX } from './types.js';
|
|
24
24
|
/** Golden angle: the phyllotaxis constant that keeps a spiral from lining up. */
|
|
25
25
|
const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
|
|
26
26
|
/** Breathing room kept between two tidied cards, in world pixels. */
|
|
@@ -167,7 +167,9 @@ export function layoutOf(note, index) {
|
|
|
167
167
|
*/
|
|
168
168
|
export function previewLayout(note, index) {
|
|
169
169
|
const width = previewWidth(note.id);
|
|
170
|
-
|
|
170
|
+
// The derived wall leaves the same clear middle as the tidy pass: the centre
|
|
171
|
+
// is the wall's centrepiece, not another place for a card.
|
|
172
|
+
const radius = PREVIEW_STEP * Math.sqrt(Math.max(0, index) + (CENTRE_RADIUS / PREVIEW_STEP) ** 2);
|
|
171
173
|
const theta = index * GOLDEN_ANGLE + (unit(`${note.id}:pa`) - 0.5) * 0.55;
|
|
172
174
|
return clampLayout({
|
|
173
175
|
x: Math.cos(theta) * radius - WIDTH_PX[width] / 2,
|
|
@@ -190,6 +192,20 @@ export function rotatedExtent(width, height, rotate) {
|
|
|
190
192
|
const sin = Math.sin(radians);
|
|
191
193
|
return { width: width * cos + height * sin, height: height * cos + width * sin };
|
|
192
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Distance from the world origin to the nearest point of one footprint.
|
|
197
|
+
*
|
|
198
|
+
* The tidy pass keeps the wall's middle clear for the centrepiece, and "clear"
|
|
199
|
+
* has to mean the card's EDGE: measuring from the centre let a wide card reach
|
|
200
|
+
* over the capture field by half its own width.
|
|
201
|
+
*/
|
|
202
|
+
function nearestEdgeRadius(box) {
|
|
203
|
+
const centreX = box.x + box.width / 2;
|
|
204
|
+
const centreY = box.y + box.height / 2;
|
|
205
|
+
const dx = Math.max(0, Math.abs(centreX) - box.width / 2);
|
|
206
|
+
const dy = Math.max(0, Math.abs(centreY) - box.height / 2);
|
|
207
|
+
return Math.hypot(dx, dy);
|
|
208
|
+
}
|
|
193
209
|
/** Cell coordinate of one world value. */
|
|
194
210
|
function cellOf(value) {
|
|
195
211
|
return Math.floor(value / GRID_CELL);
|
|
@@ -249,7 +265,7 @@ function remember(box, grid) {
|
|
|
249
265
|
* move. Notes already at exactly that layout are omitted by the caller, so
|
|
250
266
|
* pressing tidy on an already-tidy wall writes nothing.
|
|
251
267
|
*/
|
|
252
|
-
export function arrangeLayouts(notes) {
|
|
268
|
+
export function arrangeLayouts(notes, options = {}) {
|
|
253
269
|
const placed = new Map();
|
|
254
270
|
if (notes.length === 0)
|
|
255
271
|
return placed;
|
|
@@ -268,6 +284,15 @@ export function arrangeLayouts(notes) {
|
|
|
268
284
|
// from the average card area fills the disc without a hole in the middle or a
|
|
269
285
|
// sparse rim. The 1.06 slack absorbs the gap the packing has to keep.
|
|
270
286
|
const step = Math.max(72, Math.sqrt(totalArea / (Math.PI * items.length)) * 1.06);
|
|
287
|
+
// Leave a clear disc in the middle.
|
|
288
|
+
//
|
|
289
|
+
// The wall is a composition around a centre, and that centre is where the
|
|
290
|
+
// greeting and the quick-capture field live: packing a card on top of them
|
|
291
|
+
// would make the wall fight its own centrepiece. Offsetting the spiral's start
|
|
292
|
+
// index puts every card beyond `centreRadius` while keeping the same
|
|
293
|
+
// phyllotaxis density, so the ring around the middle stays evenly packed.
|
|
294
|
+
const centreRadius = Math.max(0, options.centreRadius ?? CENTRE_RADIUS);
|
|
295
|
+
const startIndex = centreRadius > 0 ? (centreRadius / step) ** 2 : 0;
|
|
271
296
|
const grid = new Map();
|
|
272
297
|
let cursor = 0;
|
|
273
298
|
let fallbackY = 0;
|
|
@@ -275,7 +300,7 @@ export function arrangeLayouts(notes) {
|
|
|
275
300
|
const { extent } = item;
|
|
276
301
|
let box = null;
|
|
277
302
|
for (let attempt = 0; attempt < MAX_CANDIDATES; attempt += 1) {
|
|
278
|
-
const index = cursor + attempt;
|
|
303
|
+
const index = startIndex + cursor + attempt;
|
|
279
304
|
const jitter = (unit(`${item.note.id}:aj`) - 0.5) * 2 * TIDY_JITTER;
|
|
280
305
|
const radius = step * Math.sqrt(index) + jitter;
|
|
281
306
|
const theta = index * GOLDEN_ANGLE;
|
|
@@ -285,6 +310,11 @@ export function arrangeLayouts(notes) {
|
|
|
285
310
|
width: extent.width,
|
|
286
311
|
height: extent.height,
|
|
287
312
|
};
|
|
313
|
+
// The reserve is measured to the card's NEAREST EDGE, not its centre: a
|
|
314
|
+
// card whose centre clears the radius can still reach into the middle by
|
|
315
|
+
// half its own width, which is what let a wide card sit on the centrepiece.
|
|
316
|
+
if (nearestEdgeRadius(candidate) < centreRadius)
|
|
317
|
+
continue;
|
|
288
318
|
if (!collides(candidate, grid)) {
|
|
289
319
|
box = candidate;
|
|
290
320
|
cursor = index + 1;
|
|
@@ -326,8 +356,24 @@ export function arrangeLayouts(notes) {
|
|
|
326
356
|
const shiftX = sumX / placed.size;
|
|
327
357
|
const shiftY = sumY / placed.size;
|
|
328
358
|
if (Math.abs(shiftX) >= 0.05 || Math.abs(shiftY) >= 0.05) {
|
|
329
|
-
|
|
330
|
-
|
|
359
|
+
// A uniform translation cannot create an overlap, but it CAN push a card back
|
|
360
|
+
// into the reserved middle — which is exactly what happened when the shift
|
|
361
|
+
// was applied unconditionally. Shift only when the reserve survives it.
|
|
362
|
+
const safe = [...placed].every(([id, layout]) => {
|
|
363
|
+
const note = notes.find((candidate) => candidate.id === id);
|
|
364
|
+
const height = note === undefined ? 0 : estimateHeight(note, layout.width);
|
|
365
|
+
const box = {
|
|
366
|
+
x: layout.x - shiftX,
|
|
367
|
+
y: layout.y - shiftY,
|
|
368
|
+
width: WIDTH_PX[layout.width],
|
|
369
|
+
height,
|
|
370
|
+
};
|
|
371
|
+
return nearestEdgeRadius(box) >= centreRadius - 0.5;
|
|
372
|
+
});
|
|
373
|
+
if (safe) {
|
|
374
|
+
for (const [id, layout] of placed) {
|
|
375
|
+
placed.set(id, clampLayout({ ...layout, x: layout.x - shiftX, y: layout.y - shiftY }));
|
|
376
|
+
}
|
|
331
377
|
}
|
|
332
378
|
}
|
|
333
379
|
return placed;
|
package/lib/types.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ export declare const WIDTHS: readonly ["sm", "md", "lg"];
|
|
|
47
47
|
export type NoteWidth = (typeof WIDTHS)[number];
|
|
48
48
|
/** Rendered card width for each preset, in world pixels at zoom 1. */
|
|
49
49
|
export declare const WIDTH_PX: Readonly<Record<NoteWidth, number>>;
|
|
50
|
+
/**
|
|
51
|
+
* Radius of the clear disc the tidy pass leaves at the wall's centre, in world
|
|
52
|
+
* pixels at zoom 1.
|
|
53
|
+
*
|
|
54
|
+
* The centre of the wall is its centrepiece: the greeting, the running tally and
|
|
55
|
+
* the quick-capture field live there. Packing a card on top of them would make
|
|
56
|
+
* the wall fight its own middle, so tidy starts every card outside this radius.
|
|
57
|
+
*/
|
|
58
|
+
export declare const CENTRE_RADIUS = 300;
|
|
50
59
|
/** Bounds of the free canvas: a note may sit anywhere inside this square. */
|
|
51
60
|
export declare const LAYOUT_LIMITS: Readonly<{
|
|
52
61
|
/** Absolute value of x and y, in world pixels. */
|
package/lib/types.js
CHANGED
|
@@ -55,6 +55,15 @@ export const WIDTH_PX = Object.freeze({
|
|
|
55
55
|
md: 222,
|
|
56
56
|
lg: 276,
|
|
57
57
|
});
|
|
58
|
+
/**
|
|
59
|
+
* Radius of the clear disc the tidy pass leaves at the wall's centre, in world
|
|
60
|
+
* pixels at zoom 1.
|
|
61
|
+
*
|
|
62
|
+
* The centre of the wall is its centrepiece: the greeting, the running tally and
|
|
63
|
+
* the quick-capture field live there. Packing a card on top of them would make
|
|
64
|
+
* the wall fight its own middle, so tidy starts every card outside this radius.
|
|
65
|
+
*/
|
|
66
|
+
export const CENTRE_RADIUS = 300;
|
|
58
67
|
/** Bounds of the free canvas: a note may sit anywhere inside this square. */
|
|
59
68
|
export const LAYOUT_LIMITS = Object.freeze({
|
|
60
69
|
/** Absolute value of x and y, in world pixels. */
|