@skillre/dsh-plugin-sticky-wall 0.2.1 → 0.3.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/client.js CHANGED
@@ -267,9 +267,9 @@ window.__ModuleLoader__.load({
267
267
  var import_react = require("react");
268
268
 
269
269
  // src/layout.ts
270
- var PREVIEW_CELL_W = 300;
271
- var PREVIEW_CELL_H = 232;
272
- var PREVIEW_COLUMNS = 4;
270
+ var GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
271
+ var PREVIEW_STEP = 196;
272
+ var PREVIEW_NOMINAL_HEIGHT = 200;
273
273
  var PREVIEW_TILT = 4;
274
274
  function hash(text) {
275
275
  let value = 2166136261;
@@ -306,20 +306,60 @@ window.__ModuleLoader__.load({
306
306
  md: 288,
307
307
  lg: 336
308
308
  });
309
+ function columns(text) {
310
+ let total = 0;
311
+ for (const char of text) {
312
+ const code = char.codePointAt(0) ?? 0;
313
+ total += code >= 4352 && (code <= 4447 || code >= 11904 && code <= 42191 || code >= 44032 && code <= 55203 || code >= 63744 && code <= 64255 || code >= 65072 && code <= 65103 || code >= 65280 && code <= 65376 || code >= 65504 && code <= 65510) ? 2 : 1;
314
+ }
315
+ return total;
316
+ }
317
+ function estimateHeight(note, width) {
318
+ const columnsPerLine = columnsPerLineFor(width);
319
+ let lines = 0;
320
+ for (const paragraph of note.body.split("\n")) {
321
+ if (paragraph.trim() === "") {
322
+ lines += 0.4;
323
+ continue;
324
+ }
325
+ lines += Math.max(1, Math.ceil(columns(paragraph.replace(/^[#>*\-+\d. ]+/u, "")) / columnsPerLine));
326
+ }
327
+ if (note.title !== "") {
328
+ const titleColumns = columnsPerLineFor(width, 0.92);
329
+ lines += Math.max(1, Math.ceil(columns(note.title) / titleColumns));
330
+ }
331
+ if (note.tags.length > 0) {
332
+ let pillColumns = 0;
333
+ for (const tag of note.tags) pillColumns += columns(tag) + 4;
334
+ lines += Math.max(1, Math.ceil(pillColumns / columnsPerLine));
335
+ }
336
+ const clamped = Math.min(16, Math.max(2, lines));
337
+ const estimated = Math.round(58 + clamped * 19);
338
+ return Math.min(estimated, MAX_CARD_HEIGHT[width]);
339
+ }
340
+ function columnsPerLineFor(width, density = 1) {
341
+ return Math.max(8, Math.floor((WIDTH_PX[width] - 26) / 7.1 * density));
342
+ }
309
343
  function layoutOf(note, index) {
310
344
  return note.layout ?? previewLayout(note, index);
311
345
  }
312
346
  function previewLayout(note, index) {
313
- const column = index % PREVIEW_COLUMNS;
314
- const row = Math.floor(index / PREVIEW_COLUMNS);
315
347
  const width = previewWidth(note.id);
348
+ const radius = PREVIEW_STEP * Math.sqrt(Math.max(0, index));
349
+ const theta = index * GOLDEN_ANGLE + (unit(`${note.id}:pa`) - 0.5) * 0.55;
316
350
  return clampLayout({
317
- x: column * PREVIEW_CELL_W + unit(`${note.id}:px`) * 42,
318
- y: row * PREVIEW_CELL_H + unit(`${note.id}:py`) * 34,
351
+ x: Math.cos(theta) * radius - WIDTH_PX[width] / 2,
352
+ y: Math.sin(theta) * radius - PREVIEW_NOMINAL_HEIGHT / 2,
319
353
  rotate: (unit(`${note.id}:pr`) - 0.5) * 2 * PREVIEW_TILT,
320
354
  width
321
355
  });
322
356
  }
357
+ function rotatedExtent(width, height, rotate) {
358
+ const radians = Math.abs(rotate) * Math.PI / 180;
359
+ const cos = Math.cos(radians);
360
+ const sin = Math.sin(radians);
361
+ return { width: width * cos + height * sin, height: height * cos + width * sin };
362
+ }
323
363
 
324
364
  // src/client/markdown.tsx
325
365
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -569,7 +609,7 @@ window.__ModuleLoader__.load({
569
609
  .skw-count { margin-left: auto; font-size: 12px; color: var(--dsw-alias-label-tertiary); font-variant-numeric: tabular-nums; white-space: nowrap; }
570
610
 
571
611
  .skw-body { flex: 1 1 auto; overflow: auto; overscroll-behavior: contain; padding: 4px 22px 40px; }
572
- .skw-body[data-view="canvas"] { padding: 0; overflow: hidden; }
612
+ .skw-body[data-view="canvas"] { padding: 0; overflow: hidden; position: relative; }
573
613
  /* Masonry-style columns, not a row grid: cards keep their natural height and
574
614
  short notes no longer sit in a tall row with dead space underneath. */
575
615
  .skw-grid { column-count: 5; column-gap: 14px; }
@@ -579,29 +619,44 @@ window.__ModuleLoader__.load({
579
619
  @media (max-width: 560px) { .skw-grid { column-count: 1; } }
580
620
 
581
621
  /* The free canvas.
582
- A scroll container holding a world-sized surface; every card is absolutely
583
- positioned in world coordinates. Scrolling pans, and \u2318/Ctrl + wheel scales
584
- the world around its origin, so a wall keeps its spatial memory instead of
585
- being re-flowed by the window width. */
586
- .skw-canvas-scroll { width: 100%; height: 100%; overflow: auto; overscroll-behavior: contain; }
622
+ One clipping viewport holding one transformed world. The camera is
623
+ translate3d(pan) scale(zoom) on .skw-world, written imperatively, so a pan or
624
+ a zoom never re-renders React and never triggers layout. Cards keep left/top
625
+ in world coordinates and a rotate(); the drag is the only thing that writes
626
+ their transform, and it is removed on drop. */
587
627
  .skw-canvas {
588
- position: relative; min-width: 100%; min-height: 100%;
589
- /* The same dot grid as the page, so the canvas reads as the paper itself. */
628
+ position: relative; width: 100%; height: 100%; overflow: hidden;
629
+ /* The dot grid lives on the viewport and is shifted/scaled with the camera, so
630
+ the paper moves under the cards instead of staying a screen texture. */
590
631
  background-image: radial-gradient(circle at 1px 1px, var(--dsw-alias-border-l1) 1px, transparent 0);
591
632
  background-size: 22px 22px;
633
+ cursor: grab; touch-action: none;
634
+ user-select: none; -webkit-user-select: none;
635
+ }
636
+ .skw-canvas[data-panning="true"] { cursor: grabbing; }
637
+ .skw-canvas[data-panning="true"] .skw-note { cursor: grabbing; }
638
+ .skw-world {
639
+ position: absolute; left: 0; top: 0; width: 0; height: 0;
640
+ transform-origin: 0 0;
641
+ /* The world wrapper is a zero-sized origin marker; cards position themselves
642
+ from it. Promoting it once keeps pan/zoom on the compositor. */
643
+ will-change: transform;
644
+ }
645
+ /* A soft halo at the wall's middle. Decorative only: it marks where the camera
646
+ opens, and it is drawn under the cards so it never intercepts a pointer. */
647
+ .skw-origin-glow {
648
+ position: absolute; width: 620px; height: 620px; margin: -310px 0 0 -310px;
649
+ border-radius: 50%; pointer-events: none;
650
+ background: radial-gradient(circle, color-mix(in srgb, var(--dsw-alias-brand-primary) 9%, transparent) 0%, transparent 68%);
592
651
  }
593
- .skw-world { position: absolute; inset: 0; }
594
- .skw-note-slot { position: absolute; inset: 0; pointer-events: none; }
595
- /* Cards inside the canvas are absolutely placed by their stored layout, and
596
- only the card itself takes pointer events, so empty paper stays scrollable. */
597
652
  /* The canvas card.
598
653
  Performance note: transform must NEVER be transitioned here. The drag writes
599
654
  a new transform on every animation frame, and an active transition makes each
600
655
  write an animation target \u2014 the browser then interpolates toward it, so the
601
- card visibly lags the pointer by ~160ms and reads as sticky. Only the
602
- shadow is animated. */
656
+ card visibly lags the pointer by ~160ms and reads as sticky. Only the shadow
657
+ and the drop shadow animate. */
603
658
  .skw-canvas .skw-note {
604
- position: absolute; pointer-events: auto; margin: 0;
659
+ position: absolute; margin: 0; pointer-events: auto;
605
660
  cursor: grab; touch-action: none;
606
661
  /* One layer per card, promoted once. Toggling will-change on drag would
607
662
  itself cost a style recalculation on the press. */
@@ -609,8 +664,8 @@ window.__ModuleLoader__.load({
609
664
  transition: box-shadow .18s ease;
610
665
  /* The Host's tidy pass estimates card heights from text columns, so the
611
666
  rendered box has to honour the same budget: without a cap a long note grows
612
- past its estimate and the shelf packing underneath it overlaps. The value
613
- mirrors MAX_CARD_HEIGHT in src/layout.ts. */
667
+ past its estimate and the packing underneath it overlaps. The value mirrors
668
+ MAX_CARD_HEIGHT in src/layout.ts. */
614
669
  overflow: hidden;
615
670
  }
616
671
  .skw-canvas .skw-note[data-width="sm"] { max-height: 236px; }
@@ -618,11 +673,13 @@ window.__ModuleLoader__.load({
618
673
  .skw-canvas .skw-note[data-width="lg"] { max-height: 336px; }
619
674
  /* While dragging: no hover lift, no text selection, a lifted shadow, and no
620
675
  pointer events on the card's own children so the drag cannot be interrupted
621
- by a child capturing the pointer. */
676
+ by a child capturing the pointer. Containment keeps the lifted card's paint
677
+ out of the rest of the wall. */
622
678
  .skw-canvas .skw-note[data-dragging="true"] {
623
679
  cursor: grabbing; z-index: 20;
624
- box-shadow: 0 4px 10px var(--dsw-alias-bg-mask-2), 0 26px 46px -14px var(--skw-note-glow);
680
+ box-shadow: 0 6px 14px var(--dsw-alias-bg-mask-2), 0 34px 60px -16px var(--skw-note-glow);
625
681
  user-select: none; -webkit-user-select: none;
682
+ contain: layout paint;
626
683
  }
627
684
  .skw-canvas .skw-note[data-dragging="true"] * { pointer-events: none; }
628
685
  /* The hover lift belongs to the grid view only. On the canvas the card already
@@ -685,7 +742,7 @@ window.__ModuleLoader__.load({
685
742
  makes the wall read as paper rather than as flat rectangles. */
686
743
  box-shadow: 0 1px 2px var(--dsw-alias-bg-mask-2), 0 6px 16px -8px var(--skw-note-glow);
687
744
  cursor: default;
688
- transition: box-shadow .18s ease, transform .18s ease;
745
+ transition: box-shadow .18s ease, transform .18s ease, opacity .18s ease;
689
746
  break-inside: avoid; -webkit-column-break-inside: avoid;
690
747
  margin: 0 0 14px;
691
748
  }
@@ -711,7 +768,13 @@ window.__ModuleLoader__.load({
711
768
  .skw-note-body { margin: 0; overflow-wrap: anywhere; font-size: 13px; line-height: 20px; flex: 1; color: var(--skw-note-ink); opacity: .92; }
712
769
  /* Clamp the rendered Markdown block, not a plain string: display:-webkit-box
713
770
  on the wrapper clips every child, so a long note stays a card and not a page. */
714
- .skw-note-body.is-clamped { display: -webkit-box; -webkit-line-clamp: 12; -webkit-box-orient: vertical; overflow: hidden; }
771
+ .skw-note-body.is-clamped { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; -webkit-line-clamp: 12; }
772
+ /* Clamp per width preset so the body ends on a whole line instead of being cut
773
+ mid-glyph by the card's own max-height. The numbers are what fits under the
774
+ budget once the action bar, title, tags and footer have taken their share. */
775
+ .skw-note[data-width="sm"] .skw-note-body.is-clamped { -webkit-line-clamp: 5; }
776
+ .skw-note[data-width="md"] .skw-note-body.is-clamped { -webkit-line-clamp: 8; }
777
+ .skw-note[data-width="lg"] .skw-note-body.is-clamped { -webkit-line-clamp: 11; }
715
778
  .skw-note-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 1px; }
716
779
  /* Tags read as real labels: a tinted pill with the note's accent, not a grey
717
780
  block. */
@@ -895,10 +958,12 @@ window.__ModuleLoader__.load({
895
958
 
896
959
  // src/client/view.tsx
897
960
  var import_jsx_runtime2 = require("react/jsx-runtime");
898
- var ZOOM_MIN = 0.4;
961
+ var ZOOM_MIN = 0.35;
899
962
  var ZOOM_MAX = 2;
900
963
  var DRAG_THRESHOLD = 3;
901
964
  var WIDTH_CYCLE = ["sm", "md", "lg"];
965
+ var DOT_PITCH = 22;
966
+ var WHEEL_PAN = 1;
902
967
  function SidebarGlyph({ size = 18 }) {
903
968
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { className: "skw-glyph", width: size, height: size, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
904
969
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "4", y: "7.5", width: "11.5", height: "11.5", rx: "2", stroke: "currentColor", strokeWidth: "1.6" }),
@@ -923,6 +988,28 @@ window.__ModuleLoader__.load({
923
988
  function parseTags(raw) {
924
989
  return raw.split(/[,,\s]+/).map((tag) => tag.trim()).filter((tag) => tag !== "");
925
990
  }
991
+ function clampZoom(value) {
992
+ return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, value));
993
+ }
994
+ function sameNote(left, right) {
995
+ if (left.title !== right.title || left.body !== right.body || left.color !== right.color || left.pinned !== right.pinned || left.archived !== right.archived || left.createdAt !== right.createdAt || left.updatedAt !== right.updatedAt || left.tags.length !== right.tags.length || left.tags.some((tag, index) => tag !== right.tags[index])) {
996
+ return false;
997
+ }
998
+ if (left.layout === right.layout) return true;
999
+ if (left.layout === null || right.layout === null) return false;
1000
+ return left.layout.x === right.layout.x && left.layout.y === right.layout.y && left.layout.rotate === right.layout.rotate && left.layout.width === right.layout.width;
1001
+ }
1002
+ function reconcileNotes(previous, next) {
1003
+ const byId = new Map(previous.map((note) => [note.id, note]));
1004
+ let changed = previous.length !== next.length;
1005
+ const merged = next.map((note) => {
1006
+ const old = byId.get(note.id);
1007
+ if (old !== void 0 && sameNote(old, note)) return old;
1008
+ changed = true;
1009
+ return note;
1010
+ });
1011
+ return changed ? merged : previous;
1012
+ }
926
1013
  function Composer({
927
1014
  draft,
928
1015
  t,
@@ -1098,28 +1185,21 @@ window.__ModuleLoader__.load({
1098
1185
  }
1099
1186
  );
1100
1187
  }
1101
- function NoteCard({
1188
+ var NoteCard = (0, import_react.memo)(function NoteCard2({
1102
1189
  note,
1103
1190
  index,
1191
+ surface,
1104
1192
  t,
1105
1193
  locale,
1106
- onEdit,
1107
- onPatch,
1108
- onRemove,
1109
- onResize,
1110
- onDragStart
1194
+ actions
1111
1195
  }) {
1112
1196
  const layout = layoutOf(note, index);
1113
- const style = {
1114
- left: `${layout.x}px`,
1115
- top: `${layout.y}px`,
1116
- width: `${WIDTH_PX[layout.width]}px`,
1117
- transform: `rotate(${layout.rotate}deg)`
1118
- };
1197
+ const style = surface === "canvas" ? { left: `${layout.x}px`, top: `${layout.y}px`, width: `${WIDTH_PX[layout.width]}px`, transform: `rotate(${layout.rotate}deg)` } : {};
1119
1198
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1120
1199
  "article",
1121
1200
  {
1122
1201
  className: "skw-note",
1202
+ "data-note-id": note.id,
1123
1203
  "data-color": note.color,
1124
1204
  "data-pinned": note.pinned,
1125
1205
  "data-archived": note.archived,
@@ -1127,12 +1207,12 @@ window.__ModuleLoader__.load({
1127
1207
  style,
1128
1208
  "aria-label": note.title || note.body.slice(0, 40),
1129
1209
  tabIndex: 0,
1130
- onPointerDown: (event) => onDragStart(note, event),
1131
- onDoubleClick: () => onEdit(note),
1210
+ onPointerDown: (event) => actions.drag(note, event),
1211
+ onDoubleClick: () => actions.edit(note),
1132
1212
  onKeyDown: (event) => {
1133
1213
  if (event.key === "Enter" && !event.metaKey && !event.ctrlKey) {
1134
1214
  event.preventDefault();
1135
- onEdit(note);
1215
+ actions.edit(note);
1136
1216
  }
1137
1217
  },
1138
1218
  children: [
@@ -1149,7 +1229,7 @@ window.__ModuleLoader__.load({
1149
1229
  "data-on": note.pinned,
1150
1230
  "aria-label": note.pinned ? t("unpin") : t("pin"),
1151
1231
  onPointerDown: (event) => event.stopPropagation(),
1152
- onClick: () => onPatch(note, { pinned: !note.pinned }),
1232
+ onClick: () => actions.patch(note, { pinned: !note.pinned }),
1153
1233
  children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "skw-pin", "aria-hidden": "true", children: note.pinned ? "\u2605" : "\u2606" })
1154
1234
  }
1155
1235
  ),
@@ -1161,7 +1241,7 @@ window.__ModuleLoader__.load({
1161
1241
  title: t("resize"),
1162
1242
  "aria-label": t("resize"),
1163
1243
  onPointerDown: (event) => event.stopPropagation(),
1164
- onClick: () => onResize(note, WIDTH_CYCLE[(WIDTH_CYCLE.indexOf(layout.width) + 1) % WIDTH_CYCLE.length] ?? "md"),
1244
+ onClick: () => actions.resize(note, WIDTH_CYCLE[(WIDTH_CYCLE.indexOf(layout.width) + 1) % WIDTH_CYCLE.length] ?? "md"),
1165
1245
  children: "\u2922"
1166
1246
  }
1167
1247
  ),
@@ -1173,7 +1253,7 @@ window.__ModuleLoader__.load({
1173
1253
  title: t("edit"),
1174
1254
  "aria-label": t("edit"),
1175
1255
  onPointerDown: (event) => event.stopPropagation(),
1176
- onClick: () => onEdit(note),
1256
+ onClick: () => actions.edit(note),
1177
1257
  children: "\u270E"
1178
1258
  }
1179
1259
  ),
@@ -1185,7 +1265,7 @@ window.__ModuleLoader__.load({
1185
1265
  title: note.archived ? t("restore") : t("archive"),
1186
1266
  "aria-label": note.archived ? t("restore") : t("archive"),
1187
1267
  onPointerDown: (event) => event.stopPropagation(),
1188
- onClick: () => onPatch(note, { archived: !note.archived }),
1268
+ onClick: () => actions.patch(note, { archived: !note.archived }),
1189
1269
  children: note.archived ? "\u21A9" : "\u25A4"
1190
1270
  }
1191
1271
  ),
@@ -1197,7 +1277,7 @@ window.__ModuleLoader__.load({
1197
1277
  title: t("delete"),
1198
1278
  "aria-label": t("delete"),
1199
1279
  onPointerDown: (event) => event.stopPropagation(),
1200
- onClick: () => onRemove(note),
1280
+ onClick: () => actions.remove(note),
1201
1281
  children: "\u2715"
1202
1282
  }
1203
1283
  )
@@ -1221,7 +1301,7 @@ window.__ModuleLoader__.load({
1221
1301
  ]
1222
1302
  }
1223
1303
  );
1224
- }
1304
+ });
1225
1305
  function NoteRow({ note, t, locale, onEdit }) {
1226
1306
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { className: "skw-row", type: "button", "data-color": note.color, "data-archived": note.archived, onClick: () => onEdit(note), children: [
1227
1307
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "skw-row-dot", "aria-hidden": "true" }),
@@ -1245,14 +1325,25 @@ window.__ModuleLoader__.load({
1245
1325
  const [draft, setDraft] = (0, import_react.useState)(null);
1246
1326
  const [draftError, setDraftError] = (0, import_react.useState)("");
1247
1327
  const [confirming, setConfirming] = (0, import_react.useState)(null);
1248
- const [camera, setCamera] = (0, import_react.useState)({ zoom: 1 });
1328
+ const [zoom, setZoom] = (0, import_react.useState)(1);
1329
+ const [viewportTick, setViewportTick] = (0, import_react.useState)(0);
1249
1330
  const [, setLocaleRevision] = (0, import_react.useState)(0);
1250
1331
  const alive = (0, import_react.useRef)(true);
1251
1332
  const life = (0, import_react.useRef)(new AbortController());
1252
1333
  const sequence = (0, import_react.useRef)(0);
1253
1334
  const inFlight = (0, import_react.useRef)(false);
1335
+ const viewportRefCurrent = (0, import_react.useRef)(null);
1336
+ const worldRef = (0, import_react.useRef)(null);
1337
+ const detachWheel = (0, import_react.useRef)(null);
1338
+ const camera = (0, import_react.useRef)({ zoom: 1, panX: 0, panY: 0 });
1339
+ const centreRequest = (0, import_react.useRef)(true);
1254
1340
  const drag = (0, import_react.useRef)(null);
1255
- const canvasRef = (0, import_react.useRef)(null);
1341
+ const pan = (0, import_react.useRef)(null);
1342
+ const live = (0, import_react.useRef)({ mutate: (_run) => {
1343
+ } });
1344
+ live.current.mutate = (run) => {
1345
+ void mutate(run);
1346
+ };
1256
1347
  const activeLocale = locale.getSnapshot().active;
1257
1348
  const stableIndex = (0, import_react.useMemo)(() => {
1258
1349
  const map = /* @__PURE__ */ new Map();
@@ -1272,7 +1363,7 @@ window.__ModuleLoader__.load({
1272
1363
  try {
1273
1364
  const next = await api.list(options.includeArchived, options.sort, life.current.signal);
1274
1365
  if (alive.current && seq === sequence.current) {
1275
- setNotes(next);
1366
+ setNotes((previous) => reconcileNotes(previous, next));
1276
1367
  if (options.clearError !== false) setError("");
1277
1368
  }
1278
1369
  } catch (cause) {
@@ -1348,16 +1439,147 @@ window.__ModuleLoader__.load({
1348
1439
  });
1349
1440
  }, [notes, filter, query, showArchived]);
1350
1441
  const archivedCount = notes.filter((note) => note.archived).length;
1351
- const extent = (0, import_react.useMemo)(() => {
1352
- let maxX = 0;
1353
- let maxY = 0;
1354
- for (const [index, note] of visible.entries()) {
1355
- const layout = layoutOf(note, index);
1356
- maxX = Math.max(maxX, layout.x + WIDTH_PX[layout.width]);
1357
- maxY = Math.max(maxY, layout.y + 220);
1442
+ const wallBounds = (0, import_react.useMemo)(() => {
1443
+ let minX = Number.POSITIVE_INFINITY;
1444
+ let minY = Number.POSITIVE_INFINITY;
1445
+ let maxX = Number.NEGATIVE_INFINITY;
1446
+ let maxY = Number.NEGATIVE_INFINITY;
1447
+ let sumX = 0;
1448
+ let sumY = 0;
1449
+ let count = 0;
1450
+ for (const note of visible) {
1451
+ const layout = layoutOf(note, indexOf(note));
1452
+ const width = WIDTH_PX[layout.width];
1453
+ const height = estimateHeight(note, layout.width);
1454
+ const box = rotatedExtent(width, height, layout.rotate);
1455
+ const centreX = layout.x + width / 2;
1456
+ const centreY = layout.y + height / 2;
1457
+ minX = Math.min(minX, centreX - box.width / 2);
1458
+ maxX = Math.max(maxX, centreX + box.width / 2);
1459
+ minY = Math.min(minY, centreY - box.height / 2);
1460
+ maxY = Math.max(maxY, centreY + box.height / 2);
1461
+ sumX += centreX;
1462
+ sumY += centreY;
1463
+ count += 1;
1464
+ }
1465
+ if (count === 0) return { centre: { x: 0, y: 0 }, width: 0, height: 0 };
1466
+ return {
1467
+ // The centroid, not the box's middle: an uneven disc has a centre of mass
1468
+ // that reads as "the middle" to the eye even when its bounds are lopsided.
1469
+ centre: { x: sumX / count, y: sumY / count },
1470
+ width: maxX - minX,
1471
+ height: maxY - minY
1472
+ };
1473
+ }, [visible, stableIndex]);
1474
+ const wallCentre = wallBounds.centre;
1475
+ const hasNotes = visible.length > 0;
1476
+ const applyCamera = (0, import_react.useCallback)(() => {
1477
+ const current = camera.current;
1478
+ const world = worldRef.current;
1479
+ const viewport = viewportRefCurrent.current;
1480
+ if (world !== null) world.style.transform = `translate3d(${current.panX}px, ${current.panY}px, 0) scale(${current.zoom})`;
1481
+ if (viewport !== null) {
1482
+ viewport.style.backgroundSize = `${DOT_PITCH * current.zoom}px ${DOT_PITCH * current.zoom}px`;
1483
+ viewport.style.backgroundPosition = `${current.panX}px ${current.panY}px`;
1484
+ }
1485
+ }, []);
1486
+ const centreOn = (0, import_react.useCallback)((worldX, worldY) => {
1487
+ const viewport = viewportRefCurrent.current;
1488
+ const current = camera.current;
1489
+ if (viewport !== null) {
1490
+ current.panX = viewport.clientWidth / 2 - worldX * current.zoom;
1491
+ current.panY = viewport.clientHeight / 2 - worldY * current.zoom;
1492
+ }
1493
+ applyCamera();
1494
+ }, [applyCamera]);
1495
+ (0, import_react.useEffect)(() => {
1496
+ if (hasNotes) centreRequest.current = true;
1497
+ setViewportTick((value) => value + 1);
1498
+ }, [hasNotes, view]);
1499
+ const zoomTo = (0, import_react.useCallback)((next, anchor) => {
1500
+ const viewport = viewportRefCurrent.current;
1501
+ const current = camera.current;
1502
+ const target = clampZoom(next);
1503
+ if (viewport === null) {
1504
+ current.zoom = target;
1505
+ setZoom(target);
1506
+ return;
1507
+ }
1508
+ const ax = anchor?.x ?? viewport.clientWidth / 2;
1509
+ const ay = anchor?.y ?? viewport.clientHeight / 2;
1510
+ const worldX = (ax - current.panX) / current.zoom;
1511
+ const worldY = (ay - current.panY) / current.zoom;
1512
+ current.zoom = target;
1513
+ current.panX = ax - worldX * target;
1514
+ current.panY = ay - worldY * target;
1515
+ setZoom(target);
1516
+ applyCamera();
1517
+ }, [applyCamera]);
1518
+ const fitWall = (0, import_react.useCallback)(() => {
1519
+ const viewport = viewportRefCurrent.current;
1520
+ if (viewport === null) return;
1521
+ const availableWidth = viewport.clientWidth;
1522
+ const availableHeight = viewport.clientHeight;
1523
+ const margin = 48;
1524
+ const fit = Math.min(
1525
+ availableWidth > 0 ? (availableWidth - margin * 2) / Math.max(1, wallBounds.width) : 1,
1526
+ availableHeight > 0 ? (availableHeight - margin * 2) / Math.max(1, wallBounds.height) : 1
1527
+ );
1528
+ const target = clampZoom(Math.min(1, fit));
1529
+ camera.current.zoom = target;
1530
+ setZoom(target);
1531
+ centreOn(wallBounds.centre.x, wallBounds.centre.y);
1532
+ }, [centreOn, wallBounds]);
1533
+ const resetView = (0, import_react.useCallback)(() => fitWall(), [fitWall]);
1534
+ const onWheel = (0, import_react.useCallback)((event) => {
1535
+ const node = viewportRefCurrent.current;
1536
+ if (node === null) return;
1537
+ if (event.ctrlKey || event.metaKey) {
1538
+ event.preventDefault();
1539
+ const rect = node.getBoundingClientRect();
1540
+ zoomTo(camera.current.zoom - event.deltaY * 22e-4, { x: event.clientX - rect.left, y: event.clientY - rect.top });
1541
+ return;
1358
1542
  }
1359
- return { width: maxX + 420, height: maxY + 320 };
1360
- }, [visible]);
1543
+ event.preventDefault();
1544
+ camera.current.panX -= event.deltaX * WHEEL_PAN;
1545
+ camera.current.panY -= event.deltaY * WHEEL_PAN;
1546
+ applyCamera();
1547
+ }, [applyCamera, zoomTo]);
1548
+ const bindViewport = (0, import_react.useCallback)((node) => {
1549
+ viewportRefCurrent.current = node;
1550
+ detachWheel.current?.();
1551
+ detachWheel.current = null;
1552
+ if (node === null) return;
1553
+ node.addEventListener("wheel", onWheel, { passive: false });
1554
+ detachWheel.current = () => node.removeEventListener("wheel", onWheel);
1555
+ }, [onWheel]);
1556
+ (0, import_react.useEffect)(() => {
1557
+ const node = viewportRefCurrent.current;
1558
+ if (node === null) return;
1559
+ detachWheel.current?.();
1560
+ node.addEventListener("wheel", onWheel, { passive: false });
1561
+ detachWheel.current = () => node.removeEventListener("wheel", onWheel);
1562
+ }, [onWheel]);
1563
+ (0, import_react.useEffect)(() => {
1564
+ const node = viewportRefCurrent.current;
1565
+ if (node === null || typeof ResizeObserver === "undefined") return;
1566
+ const observer = new ResizeObserver(() => {
1567
+ if (drag.current !== null || pan.current !== null) return;
1568
+ centreRequest.current = true;
1569
+ setViewportTick((value) => value + 1);
1570
+ });
1571
+ observer.observe(node);
1572
+ return () => observer.disconnect();
1573
+ }, [view]);
1574
+ (0, import_react.useLayoutEffect)(() => {
1575
+ if (view !== "canvas") return;
1576
+ if (centreRequest.current) {
1577
+ centreRequest.current = false;
1578
+ fitWall();
1579
+ return;
1580
+ }
1581
+ applyCamera();
1582
+ }, [applyCamera, centreOn, fitWall, view, viewportTick]);
1361
1583
  function startDrag(note, event) {
1362
1584
  if (event.button !== 0 || event.isPrimary === false) return;
1363
1585
  const layout = layoutOf(note, indexOf(note));
@@ -1375,8 +1597,6 @@ window.__ModuleLoader__.load({
1375
1597
  width: layout.width,
1376
1598
  moved: false,
1377
1599
  captured: false,
1378
- x: layout.x,
1379
- y: layout.y,
1380
1600
  frame: 0,
1381
1601
  lastX: event.clientX,
1382
1602
  lastY: event.clientY
@@ -1387,52 +1607,105 @@ window.__ModuleLoader__.load({
1387
1607
  } catch {
1388
1608
  }
1389
1609
  }
1610
+ function startPan(event) {
1611
+ if (event.button !== 0 || event.isPrimary === false) return;
1612
+ const target = event.target;
1613
+ if (target !== null && target.closest(".skw-note") !== null) return;
1614
+ const node = viewportRefCurrent.current;
1615
+ if (node === null) return;
1616
+ node.setAttribute("data-panning", "true");
1617
+ pan.current = {
1618
+ pointerId: event.pointerId,
1619
+ startX: event.clientX,
1620
+ startY: event.clientY,
1621
+ originX: camera.current.panX,
1622
+ originY: camera.current.panY,
1623
+ node,
1624
+ frame: 0,
1625
+ lastX: event.clientX,
1626
+ lastY: event.clientY
1627
+ };
1628
+ }
1390
1629
  (0, import_react.useEffect)(() => {
1391
- const paint = (current) => {
1630
+ const paintDrag = (current) => {
1392
1631
  current.frame = 0;
1393
1632
  const node = current.node;
1394
1633
  if (node === null) return;
1395
- const dx = (current.lastX - current.startX) / camera.zoom;
1396
- const dy = (current.lastY - current.startY) / camera.zoom;
1634
+ const zoomNow = camera.current.zoom;
1635
+ const dx = (current.lastX - current.startX) / zoomNow;
1636
+ const dy = (current.lastY - current.startY) / zoomNow;
1397
1637
  node.style.transform = `translate3d(${dx}px, ${dy}px, 0) rotate(${current.rotate}deg)`;
1398
1638
  };
1639
+ const paintPan = (current) => {
1640
+ current.frame = 0;
1641
+ camera.current.panX = current.originX + (current.lastX - current.startX);
1642
+ camera.current.panY = current.originY + (current.lastY - current.startY);
1643
+ applyCamera();
1644
+ };
1399
1645
  const move = (event) => {
1400
1646
  const current = drag.current;
1401
- if (current === null || event.pointerId !== current.pointerId) return;
1402
- current.lastX = event.clientX;
1403
- current.lastY = event.clientY;
1404
- if (!current.moved) {
1405
- if (Math.hypot(event.clientX - current.startX, event.clientY - current.startY) < DRAG_THRESHOLD) return;
1406
- current.moved = true;
1647
+ if (current !== null && event.pointerId === current.pointerId) {
1648
+ current.lastX = event.clientX;
1649
+ current.lastY = event.clientY;
1650
+ if (!current.moved) {
1651
+ if (Math.hypot(event.clientX - current.startX, event.clientY - current.startY) < DRAG_THRESHOLD) return;
1652
+ current.moved = true;
1653
+ }
1654
+ if (current.frame === 0) current.frame = requestAnimationFrame(() => paintDrag(current));
1655
+ return;
1656
+ }
1657
+ const panning = pan.current;
1658
+ if (panning !== null && event.pointerId === panning.pointerId) {
1659
+ panning.lastX = event.clientX;
1660
+ panning.lastY = event.clientY;
1661
+ if (panning.frame === 0) panning.frame = requestAnimationFrame(() => paintPan(panning));
1407
1662
  }
1408
- if (current.frame === 0) current.frame = requestAnimationFrame(() => paint(current));
1409
1663
  };
1410
1664
  const finish = (event) => {
1665
+ const panning = pan.current;
1666
+ if (panning !== null && event.pointerId === panning.pointerId) {
1667
+ pan.current = null;
1668
+ if (panning.frame !== 0) {
1669
+ cancelAnimationFrame(panning.frame);
1670
+ panning.frame = 0;
1671
+ camera.current.panX = panning.originX + (panning.lastX - panning.startX);
1672
+ camera.current.panY = panning.originY + (panning.lastY - panning.startY);
1673
+ applyCamera();
1674
+ }
1675
+ panning.node?.removeAttribute("data-panning");
1676
+ }
1411
1677
  const current = drag.current;
1412
1678
  if (current === null || event.pointerId !== current.pointerId) return;
1413
1679
  drag.current = null;
1414
1680
  if (current.frame !== 0) cancelAnimationFrame(current.frame);
1415
1681
  const node = current.node;
1416
- if (node !== null) {
1417
- node.removeAttribute("data-dragging");
1418
- node.style.transform = `translate3d(0, 0, 0) rotate(${current.rotate}deg)`;
1682
+ const zoomNow = camera.current.zoom;
1683
+ const release = () => {
1419
1684
  if (current.captured) {
1420
1685
  try {
1421
- node.releasePointerCapture?.(event.pointerId);
1686
+ node?.releasePointerCapture?.(event.pointerId);
1422
1687
  } catch {
1423
1688
  }
1424
1689
  }
1425
- }
1426
- if (!current.moved) return;
1427
- const dx = (current.lastX - current.startX) / camera.zoom;
1428
- const dy = (current.lastY - current.startY) / camera.zoom;
1429
- const layout = {
1430
- x: current.originX + dx,
1431
- y: current.originY + dy,
1432
- rotate: current.rotate,
1433
- width: current.width
1434
1690
  };
1435
- void mutate(async () => {
1691
+ if (!current.moved) {
1692
+ node?.removeAttribute("data-dragging");
1693
+ if (node !== null) node.style.transform = `rotate(${current.rotate}deg)`;
1694
+ release();
1695
+ return;
1696
+ }
1697
+ const dx = (current.lastX - current.startX) / zoomNow;
1698
+ const dy = (current.lastY - current.startY) / zoomNow;
1699
+ const layout = clampLayout({ x: current.originX + dx, y: current.originY + dy, rotate: current.rotate, width: current.width });
1700
+ if (node !== null) {
1701
+ node.removeAttribute("data-dragging");
1702
+ node.style.transform = `rotate(${current.rotate}deg)`;
1703
+ node.style.left = `${layout.x}px`;
1704
+ node.style.top = `${layout.y}px`;
1705
+ release();
1706
+ }
1707
+ setNotes((previous) => previous.map((note) => note.id === current.id ? { ...note, layout } : note));
1708
+ live.current.mutate(async () => {
1436
1709
  await api.move(current.id, layout, life.current.signal);
1437
1710
  });
1438
1711
  };
@@ -1445,17 +1718,35 @@ window.__ModuleLoader__.load({
1445
1718
  window.removeEventListener("pointercancel", finish);
1446
1719
  const pending = drag.current;
1447
1720
  if (pending !== null && pending.frame !== 0) cancelAnimationFrame(pending.frame);
1721
+ const pendingPan = pan.current;
1722
+ if (pendingPan !== null && pendingPan.frame !== 0) cancelAnimationFrame(pendingPan.frame);
1723
+ pan.current?.node?.removeAttribute("data-panning");
1448
1724
  };
1449
- }, [camera.zoom, api, mutate]);
1450
- function onWheel(event) {
1451
- if (!event.ctrlKey && !event.metaKey) return;
1452
- event.preventDefault();
1453
- const next = Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, camera.zoom - event.deltaY * 2e-3));
1454
- setCamera((current) => ({ ...current, zoom: next }));
1455
- }
1456
- const zoomBy = (delta) => {
1457
- setCamera((current) => ({ ...current, zoom: Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, current.zoom + delta)) }));
1725
+ }, [api, applyCamera]);
1726
+ const latestActions = (0, import_react.useRef)(null);
1727
+ latestActions.current = {
1728
+ edit: openComposer,
1729
+ patch: (note, patch) => {
1730
+ void mutate(async () => {
1731
+ await api.update(note.id, patch, life.current.signal);
1732
+ });
1733
+ },
1734
+ remove: (note) => setConfirming(note),
1735
+ resize: (note, width) => {
1736
+ void mutate(async () => {
1737
+ const current = notes.find((candidate) => candidate.id === note.id);
1738
+ if (current !== void 0) await api.move(note.id, { ...layoutOf(current, stableIndex.get(current.id) ?? 0), width }, life.current.signal);
1739
+ });
1740
+ },
1741
+ drag: startDrag
1458
1742
  };
1743
+ const actions = (0, import_react.useMemo)(() => ({
1744
+ edit: (note) => latestActions.current?.edit(note),
1745
+ patch: (note, patch) => latestActions.current?.patch(note, patch),
1746
+ remove: (note) => latestActions.current?.remove(note),
1747
+ resize: (note, width) => latestActions.current?.resize(note, width),
1748
+ drag: (note, event) => latestActions.current?.drag(note, event)
1749
+ }), []);
1459
1750
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "skw-page", "aria-label": t("title"), children: [
1460
1751
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: WALL_CSS }),
1461
1752
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("header", { className: "skw-head", children: [
@@ -1476,6 +1767,8 @@ window.__ModuleLoader__.load({
1476
1767
  disabled: busy || visible.length === 0,
1477
1768
  onClick: () => void mutate(async () => {
1478
1769
  await api.arrange(life.current.signal);
1770
+ centreRequest.current = true;
1771
+ setViewportTick((value) => value + 1);
1479
1772
  }),
1480
1773
  children: t("arrange")
1481
1774
  }
@@ -1530,73 +1823,19 @@ window.__ModuleLoader__.load({
1530
1823
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "skw-empty-icon", "aria-hidden": "true", children: "\u{1F5D2}\uFE0F" }),
1531
1824
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: filter === "archived" ? t("emptyArchived") : query.trim() !== "" ? t("noResults") : t("empty") }),
1532
1825
  filter !== "archived" && query.trim() === "" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "skw-btn", type: "button", onClick: () => openComposer(), children: t("new") })
1533
- ] }) : view === "list" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-list", children: visible.map((note) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NoteRow, { note, t, locale: activeLocale, onEdit: openComposer }, note.id)) }) : view === "grid" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-grid", children: visible.map((note) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1534
- NoteCard,
1535
- {
1536
- note,
1537
- index: indexOf(note),
1538
- t,
1539
- locale: activeLocale,
1540
- onEdit: openComposer,
1541
- onPatch: (target, patch) => void mutate(async () => {
1542
- await api.update(target.id, patch, life.current.signal);
1543
- }),
1544
- onRemove: (target) => setConfirming(target),
1545
- onResize: (target, width) => void mutate(async () => {
1546
- const current = notes.find((candidate) => candidate.id === target.id);
1547
- if (current !== void 0) await api.move(target.id, { ...layoutOf(current, stableIndex.get(current.id) ?? 0), width }, life.current.signal);
1548
- }),
1549
- onDragStart: () => {
1550
- }
1551
- },
1552
- note.id
1553
- )) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-canvas-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1554
- "div",
1555
- {
1556
- ref: canvasRef,
1557
- className: "skw-canvas",
1558
- "data-zoomed": camera.zoom !== 1,
1559
- style: { width: `${extent.width}px`, height: `${extent.height}px` },
1560
- onWheel,
1561
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-world", style: { transform: `scale(${camera.zoom})`, transformOrigin: "0 0" }, children: visible.map((note) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-note-slot", "data-note-id": note.id, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1562
- NoteCard,
1563
- {
1564
- note,
1565
- index: indexOf(note),
1566
- t,
1567
- locale: activeLocale,
1568
- onEdit: openComposer,
1569
- onPatch: (target, patch) => void mutate(async () => {
1570
- await api.update(target.id, patch, life.current.signal);
1571
- }),
1572
- onRemove: (target) => setConfirming(target),
1573
- onResize: (target, width) => void mutate(async () => {
1574
- const current = notes.find((candidate) => candidate.id === target.id);
1575
- if (current !== void 0) await api.move(target.id, { ...layoutOf(current, stableIndex.get(current.id) ?? 0), width }, life.current.signal);
1576
- }),
1577
- onDragStart: startDrag
1578
- }
1579
- ) }, note.id)) })
1580
- }
1581
- ) })
1826
+ ] }) : view === "list" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-list", children: visible.map((note) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NoteRow, { note, t, locale: activeLocale, onEdit: openComposer }, note.id)) }) : view === "grid" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-grid", children: visible.map((note) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NoteCard, { note, index: indexOf(note), surface: "grid", t, locale: activeLocale, actions }, note.id)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: bindViewport, className: "skw-canvas", "data-zoomed": zoom !== 1, onPointerDown: startPan, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ref: worldRef, className: "skw-world", children: [
1827
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-origin-glow", style: { left: `${wallCentre.x}px`, top: `${wallCentre.y}px` }, "aria-hidden": "true" }),
1828
+ visible.map((note) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NoteCard, { note, index: indexOf(note), surface: "canvas", t, locale: activeLocale, actions }, note.id))
1829
+ ] }) })
1582
1830
  ] }),
1583
1831
  view === "canvas" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "skw-cameras", role: "group", "aria-label": t("zoomLabel"), children: [
1584
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "skw-camera-btn", type: "button", "aria-label": t("zoomOut"), onClick: () => zoomBy(-0.15), children: "\u2212" }),
1832
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "skw-camera-btn", type: "button", "aria-label": t("zoomOut"), onClick: () => zoomTo(zoom - 0.15), children: "\u2212" }),
1585
1833
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "skw-camera-value", children: [
1586
- Math.round(camera.zoom * 100),
1834
+ Math.round(zoom * 100),
1587
1835
  "%"
1588
1836
  ] }),
1589
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "skw-camera-btn", type: "button", "aria-label": t("zoomIn"), onClick: () => zoomBy(0.15), children: "+" }),
1590
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1591
- "button",
1592
- {
1593
- className: "skw-camera-btn",
1594
- type: "button",
1595
- "aria-label": t("zoomReset"),
1596
- onClick: () => setCamera({ zoom: 1 }),
1597
- children: "\u2316"
1598
- }
1599
- )
1837
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "skw-camera-btn", type: "button", "aria-label": t("zoomIn"), onClick: () => zoomTo(zoom + 0.15), children: "+" }),
1838
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: "skw-camera-btn", type: "button", "aria-label": t("zoomReset"), onClick: resetView, children: "\u2316" })
1600
1839
  ] }),
1601
1840
  draft && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1602
1841
  Composer,