@skillre/dsh-plugin-sticky-wall 0.9.3 → 0.9.5

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 CHANGED
@@ -26,6 +26,7 @@ Non-goals: task management (no scheduling, assignment or reminders), collaborati
26
26
  - **Full-window canvas** — the wall fills the entire window: no title row and no toolbar row. Every control lives in one **floating dock** at the bottom.
27
27
  - **A compact dock** — only the frequent actions stay in the strip: search, filters, three **icon** view buttons, zoom (`− / percent / +`, where the percentage is itself the reset button), tidy and new. Sort, show-archived and clear-archive moved into a `⋯` overflow menu. The dock is a **single row**, centred, and sizes to the window, so no button spills past the strip it is drawn on.
28
28
  - **Camera** — drag empty paper to pan, scroll to pan, `⌘/Ctrl + wheel` to zoom around the pointer (0.35×–2×). Opening the wall and pressing reset both frame the whole wall and centre it. The greeting and the capture field are **page chrome**: they keep their natural size at every zoom level instead of shrinking with the canvas.
29
+ - **The centre tally** — the "N notes · M archived" line under the greeting describes the **whole wall**, not the current filter, so the archive count stays correct while archived notes are hidden (an older build counted archived notes out of the visible list, which by default excludes them and therefore always read zero). How many notes the current view holds is the dock's count label.
29
30
  - **Markdown bodies** — headings, paragraphs, bold/italic/strikethrough, `code`, code blocks, ordered and unordered lists, `- [ ]` checkboxes, quotes, rules, tables and http(s)/mailto links. The composer has a "Preview" toggle.
30
31
  - **Quick capture** — "New" opens a note sheet with an optional title, required body, tags, six pastel colors and a width preset. The sheet starts out large (880×680, still centred on its scrim) and carries a grip in its bottom-right corner: drag it to resize with the pointer, or focus it and use the arrow keys — left/right change the width, up/down the height, `Shift` plus an arrow takes a bigger step, `0` restores the default, and double-clicking the grip resets it too. A size is clamped to stay inside the window with a 24px margin and never goes below 460×380. The size you choose is remembered on this machine and restored next time, and it is **that size** that is remembered: open the wall in a small window and the sheet shrinks to fit, then returns to what you actually picked once the window grows back. The body editor and the preview both fill the sheet instead of each carrying its own height cap.
31
32
  - **Pin and archive** — pinned notes carry a coloured left rail and a star; archived notes hide by default, the "Archive" filter fetches them on its own, and "Clear archive" is a permanent delete.
@@ -160,7 +161,7 @@ The install path was verified end to end: derive the spec from the live index, i
160
161
  - Card width has only **three presets** (small/medium/large); there is no arbitrary resize. A drag keeps the card's existing tilt. This is about a **card on the canvas** — the only thing you can size freely is the note sheet.
161
162
  - Tidy is O(n) spiral placement plus a spatial-grid collision check; the wall holds at most 400 notes, and a wall larger than the viewport needs panning or zooming out.
162
163
  - The canvas is a flat plane: no grouping, layers, connectors or snap alignment, and no rotation gesture beyond the stored tilt.
163
- - Auto-framing has a legibility floor (42%): a large wall is centred rather than crammed entirely into view, so panning is expected. The middle is reserved space — tidy never places a card under the greeting or the capture field, and a capture on a panned or zoomed wall avoids wherever the field currently sits. The greeting and the capture field are **page chrome**, so they keep a fixed size instead of scaling with the canvas; at a deep zoom-out a card can therefore pass beneath them, which is normal overlay behaviour rather than a layering bug.
164
+ - Auto-framing has a legibility floor (42%): a large wall is centred rather than crammed entirely into view, so panning is expected. The reserved middle is sized for that **framing floor** (42%) rather than for 100%, so at every zoom level tidy keeps cards out of the space the greeting and the capture field occupy; a capture on a panned or zoomed wall avoids wherever the field currently sits. The greeting and the capture field are **page chrome**, so they keep a fixed size instead of scaling with the canvas.
164
165
  - Placement is owned by the Host, but two windows open on the same wall each render their own snapshot and do not live-push the other's drags — they do refetch on focus and on the slow poll, so neither stays stale for long.
165
166
  - Archived notes do not occupy a `maxNotes` slot, but restoring them does; a restore at the cap is rejected instead of silently overshooting.
166
167
  - "Clear archive" is a permanent, irreversible delete.
package/README.md CHANGED
@@ -26,6 +26,7 @@
26
26
  - **全幅画布**:便签墙占满整个窗口,没有顶部标题栏和工具栏;所有控件收进底部一条**浮动菜单栏**。
27
27
  - **紧凑菜单栏**:底部只留高频动作 —— 搜索、筛选、三个**图标**视图切换、缩放(`− / 百分比 / +`,百分比本身可点即重置)、整理、新建。排序、显示归档、清空归档收进 `⋯` 溢出菜单。菜单栏是**单行**、居中、宽度自适应窗口,任何按钮都不会溢出背景条。
28
28
  - **相机**:拖动空白纸面平移,滚轮平移,`⌘/Ctrl + 滚轮` 以指针为锚点缩放(0.35×–2×);打开与重置时自动把整面墙框进视野。中间的问候语与记录框是**页面控件**,任何缩放级别下都保持原始大小,不会跟着画布一起缩小。
29
+ - **中间的统计**:问候语下面那行「N 张便签 · M 张已归档」说的是**整面墙**的构成,不是当前筛选结果 —— 所以归档被隐藏时它照样报出归档数量(旧版从当前列表里数归档,而默认列表本来就不含归档便签,于是永远显示 0)。当前视图里有多少条,由底部菜单栏的计数负责。
29
30
  - **Markdown 正文**:正文按 Markdown 渲染 —— 标题、段落、粗体/斜体/删除线、`代码`、代码块、有序/无序列表、`- [ ]` 复选、引用、分隔线、表格、http(s)/mailto 链接。编辑时右侧有「预览」切换。
30
31
  - **随手记录**:`+ 新建` 打开便签纸,标题可选、正文必填,可打标签、选六种柔和底色、选卡片宽度。便签纸默认就很大(880×680,仍然在遮罩里居中),右下角有一个握把:拖它用指针改尺寸,聚焦后方向键也能改 —— 左右改宽、上下改高,`Shift + 方向键` 一次走更大的步长,`0` 恢复默认,双击握把同样恢复默认。尺寸被限制在「始终待在窗口内、四周留 24px」与 460×380 的下限之间。选好的尺寸记在本机、下次打开照旧,而且记的是**你选的那个尺寸本身**:小窗口里打开会先缩到装得下,窗口放大后回到你真正选过的尺寸。正文编辑器与预览都撑满整张便签纸,不再各自带一个高度上限。
31
32
  - **置顶与归档**:置顶的便签带左侧色条与星标;归档的便签默认隐藏,「归档」筛选会单独拉取它们,「清空归档」是永久删除。
@@ -171,7 +172,7 @@ node scripts/preview.mjs check # 离线校验预览图与 locale 元数据(n
171
172
  - 卡片宽度只有小/中/大**三档预设**,不支持任意拖拽调整宽度;拖动会保留卡片原有的轻微倾角。这一条说的是**画布上的卡片**,大小可调的只有随手记录的便签纸。
172
173
  - 整理是 O(n) 的螺旋放置 + 网格碰撞检测;便签上限 400 张,超出视野的墙需要自己平移或缩小。
173
174
  - 画布是二维平面:没有分组、图层、连线或吸附对齐;也不支持双指旋转或触屏捏合之外的手势。
174
- - 自动取景有可读性下限(42%):便签很多时整面墙不会全部挤进视野,而是居中显示、需要平移查看。整理不会把卡片放在问候语和记录框下面;平移到别处再新建时,落点也会避开记录框当前所在的位置。中间的问候语和记录框是**页面控件**,缩放时保持固定大小、不跟随画布放大缩小;因此缩得很小时,卡片可能从它下面经过 —— 这是浮层的正常行为,不是遮挡错误。
175
+ - 自动取景有可读性下限(42%):便签很多时整面墙不会全部挤进视野,而是居中显示、需要平移查看。中间那块留白是按**取景下限**(42%)而不是按 100% 算出来的,所以任何缩放级别下整理都不会把卡片放进问候语和记录框占用的区域;平移到别处再新建时,落点也会避开记录框当前所在的位置。中间的问候语和记录框是**页面控件**,缩放时保持固定大小、不跟随画布放大缩小。
175
176
  - 便签的位置由 Host 保存;同一面墙在两个窗口同时打开时,各自渲染自己的快照,不会实时推送另一个窗口的拖动结果 —— 但窗口重新获得焦点/重新可见时会重新拉取,所以不会长期停在旧状态。
176
177
  - 归档便签不占 `maxNotes` 名额,但恢复它们会占名额;名额已满时恢复会被拒绝而不是悄悄超限。
177
178
  - 「清空归档」是永久删除,不可撤销。
@@ -2,6 +2,102 @@
2
2
  "schemaVersion": 1,
3
3
  "package": "@skillre/dsh-plugin-sticky-wall",
4
4
  "verified": [
5
+ {
6
+ "dsh": "0.2.2-rc.5",
7
+ "verifiedAt": "2026-11-20",
8
+ "result": "passed",
9
+ "checks": [
10
+ "dsh-version",
11
+ "profile-template-created",
12
+ "profile-tarball-install",
13
+ "packed-dependency-and-selection",
14
+ "dump-config",
15
+ "packed-payload-present",
16
+ "legacy-domain-seeded",
17
+ "bounded-startup",
18
+ "api-list",
19
+ "legacy-migration-carries-every-note",
20
+ "legacy-migration-writes-markdown",
21
+ "api-create",
22
+ "api-update",
23
+ "api-move",
24
+ "api-move-clamped",
25
+ "api-move-bounds",
26
+ "api-arrange",
27
+ "api-archive",
28
+ "api-archive-hides-note",
29
+ "api-counts-survive-filtering",
30
+ "storage-persistence-across-restart",
31
+ "storage-persistence-layout",
32
+ "api-delete",
33
+ "api-delete-verified",
34
+ "api-auth-fence",
35
+ "browser-shell-overlays-dismissed",
36
+ "browser-sidebar-entry-present",
37
+ "browser-sidebar-click-attempts",
38
+ "browser-sidebar-entry-selects-panel",
39
+ "browser-wall-page-mounted",
40
+ "browser-welcome-note-seeded",
41
+ "browser-zh-copy",
42
+ "browser-composer-opens",
43
+ "browser-composer-sheet-is-large",
44
+ "browser-composer-sheet-stays-centred",
45
+ "browser-composer-editor-fills-the-sheet",
46
+ "browser-composer-grip-works-from-the-keyboard",
47
+ "browser-composer-grip-resizes-the-sheet",
48
+ "browser-composer-double-click-resets-the-size",
49
+ "browser-composer-size-is-remembered",
50
+ "browser-composer-minimum-size-stays-usable",
51
+ "browser-composer-preview-fills-the-sheet",
52
+ "browser-preview-renders-nested-lists",
53
+ "browser-preview-toggle-keeps-the-editor-and-caret",
54
+ "browser-caret-survives-the-preview-round-trip",
55
+ "browser-composer-sheet-fits-a-small-window",
56
+ "browser-composer-keeps-the-preference-through-a-squeeze",
57
+ "browser-composer-save-creates-note",
58
+ "browser-pin-action-sorts-note-first",
59
+ "browser-search-filters-wall",
60
+ "browser-archive-hides-note",
61
+ "browser-centre-tally-reports-the-hidden-archive",
62
+ "browser-show-archived-toggle",
63
+ "browser-centre-tally-is-stable-when-the-archive-is-shown",
64
+ "browser-note-persists-across-ui-reload",
65
+ "browser-canvas-positions-cards-absolutely",
66
+ "browser-canvas-tidy-repacks-the-wall",
67
+ "browser-canvas-tidy-leaves-no-overlap",
68
+ "browser-canvas-camera-frames-the-wall-centre",
69
+ "browser-canvas-camera-is-a-transform-not-scroll",
70
+ "browser-canvas-drag-persists-placement",
71
+ "browser-canvas-drag-keeps-rotation",
72
+ "browser-canvas-drag-on-paper-pans-the-camera",
73
+ "browser-canvas-wheel-zoom-keeps-the-pointer-anchored",
74
+ "browser-canvas-reset-frames-the-whole-wall",
75
+ "browser-canvas-large-wall-is-a-centred-cluster",
76
+ "browser-canvas-centrepiece-is-at-the-middle",
77
+ "browser-canvas-tidy-keeps-the-centre-clear",
78
+ "browser-canvas-centrepiece-stays-put-while-panning",
79
+ "browser-canvas-centrepiece-keeps-its-size-while-zooming",
80
+ "browser-centre-capture-creates-a-note",
81
+ "browser-centre-capture-lands-visible-and-clear-of-the-field",
82
+ "browser-no-card-covers-the-centrepiece",
83
+ "browser-capture-on-a-panned-wall-stays-clear-of-the-field",
84
+ "browser-capture-on-a-zoomed-wall-stays-clear-of-the-field",
85
+ "browser-canvas-fills-the-page-with-a-floating-dock",
86
+ "browser-canvas-large-wall-screenshot",
87
+ "browser-card-body-renders-markdown",
88
+ "browser-card-body-renders-nested-lists",
89
+ "browser-grid-view-renders-notes",
90
+ "browser-list-view-renders-rows",
91
+ "browser-theme-switches-note-palette",
92
+ "browser-no-uncaught-errors"
93
+ ],
94
+ "evidence": {
95
+ "isolatedMount": "docs/evidence/isolated-mount-0.9.4.json",
96
+ "uiVerification": "docs/evidence/ui-verification.json",
97
+ "tarballSha256": "9d10ac6d944e9e24c571c204193c93fdfa604059cd167d4294e8c03e4216200b"
98
+ },
99
+ "notes": "Verified for the 0.9.4 centre-tally release against DSH 0.2.2-rc.5. The mount run installs the packed tarball into an owned disposable profile, composes it, boots a bounded startup and exercises the Connection API; the UI run drives the real DSH Web app over CDP (58/58). Release-specific checks: (1) the list response reports whole-wall counts (total/live/archived) that survive the archived filter — the mount run observed total 3 / live 1 / archived 2 on a filtered request, and the real UI shows \"1 张便签 · 1 张已归档\" while zero archived cards are on screen, the exact state in which the previous build reported 0 archived; (2) tidy keeps every card clear of the capture field at framing zoom, which is asserted with pixel-level intrusion reporting (0px² across six consecutive UI runs) after the reserve was sized for the framing floor."
100
+ },
5
101
  {
6
102
  "dsh": "0.2.2-rc.5",
7
103
  "verifiedAt": "2026-11-19",
package/lib/client.js CHANGED
@@ -73,7 +73,7 @@ window.__ModuleLoader__.load({
73
73
  md: 222,
74
74
  lg: 276
75
75
  });
76
- var CENTRE_RESERVE = Object.freeze({ halfWidth: 330, halfHeight: 136 });
76
+ var CENTRE_RESERVE = Object.freeze({ halfWidth: 605, halfHeight: 200 });
77
77
  var LAYOUT_LIMITS = Object.freeze({
78
78
  /** Absolute value of x and y, in world pixels. */
79
79
  coord: 2e4,
@@ -95,6 +95,16 @@ window.__ModuleLoader__.load({
95
95
  if (!result.ok) throw new ActionError(result.error.code, result.error.message, result.error.details);
96
96
  return result.value;
97
97
  }
98
+ function normalizeCounts(raw, notes) {
99
+ if (raw !== void 0 && raw !== null && typeof raw === "object") {
100
+ const total = typeof raw.total === "number" && Number.isFinite(raw.total) ? raw.total : notes.length;
101
+ const archived2 = typeof raw.archived === "number" && Number.isFinite(raw.archived) ? raw.archived : 0;
102
+ const live = typeof raw.live === "number" && Number.isFinite(raw.live) ? raw.live : Math.max(0, total - archived2);
103
+ return { total, live, archived: archived2 };
104
+ }
105
+ const archived = notes.filter((note) => note.archived).length;
106
+ return { total: notes.length, live: notes.length - archived, archived };
107
+ }
98
108
  function createApi(connection, lifetime) {
99
109
  const call = async (request, signal) => {
100
110
  const signalToUse = signal === void 0 ? lifetime : AbortSignal.any([lifetime, signal]);
@@ -103,8 +113,10 @@ window.__ModuleLoader__.load({
103
113
  return {
104
114
  async list(includeArchived, sort, signal) {
105
115
  const value = await call({ action: "list", includeArchived, sort }, signal);
116
+ const notes = Array.isArray(value?.notes) ? value.notes : [];
106
117
  return {
107
- notes: Array.isArray(value?.notes) ? value.notes : [],
118
+ notes,
119
+ counts: normalizeCounts(value?.counts, notes),
108
120
  revision: typeof value?.revision === "number" ? value.revision : 0,
109
121
  notesDir: typeof value?.notesDir === "string" ? value.notesDir : "",
110
122
  domain: value?.domain ?? { name: "", version: 0 }
@@ -164,6 +176,9 @@ window.__ModuleLoader__.load({
164
176
  "title": "\u4FBF\u7B7E\u5899",
165
177
  "empty": "\u8FD8\u6CA1\u6709\u4FBF\u7B7E\u3002\u70B9\u300C\u65B0\u5EFA\u300D\u5199\u4E0B\u7B2C\u4E00\u6761\u3002",
166
178
  "emptyArchived": "\u5F52\u6863\u533A\u662F\u7A7A\u7684\u3002",
179
+ // Shown when the wall HAS notes but every one of them is archived. Saying
180
+ // "no notes yet" there was false and hid the way back to them.
181
+ "emptyAllArchived": "\u4FBF\u7B7E\u90FD\u6536\u8FDB\u5F52\u6863\u4E86\u3002\u7528\u4E0B\u65B9\u83DC\u5355\u91CC\u7684\u300C\u663E\u793A\u5F52\u6863\u300D\u67E5\u770B\u3002",
167
182
  "new": "\u65B0\u5EFA",
168
183
  "save": "\u4FDD\u5B58",
169
184
  "cancel": "\u53D6\u6D88",
@@ -187,7 +202,7 @@ window.__ModuleLoader__.load({
187
202
  "search": "\u641C\u7D22\u4FBF\u7B7E\u2026",
188
203
  "bodyPlaceholder": "\u5199\u70B9\u4EC0\u4E48\u2026",
189
204
  "titlePlaceholder": "\u6807\u9898\uFF08\u53EF\u9009\uFF09",
190
- "tagsPlaceholder": "\u6807\u7B7E\uFF0C\u7528\u7A7A\u683C\u5206\u9694",
205
+ "tagsPlaceholder": "\u6807\u7B7E\uFF0C\u7528\u9017\u53F7\u5206\u9694",
191
206
  "colorLabel": "\u989C\u8272",
192
207
  "saveHint": "\u2318/Ctrl + Enter \u4FDD\u5B58 \xB7 Esc \u53D6\u6D88",
193
208
  "count": "{count} \u5F20\u4FBF\u7B7E",
@@ -273,6 +288,9 @@ window.__ModuleLoader__.load({
273
288
  "title": "Sticky wall",
274
289
  "empty": 'No notes yet. Hit "New" to write the first one.',
275
290
  "emptyArchived": "Nothing archived yet.",
291
+ // Shown when the wall HAS notes but every one of them is archived. Saying
292
+ // "no notes yet" there was false and hid the way back to them.
293
+ "emptyAllArchived": 'Every note is in the archive. Use "Show archived" in the menu below to see them.',
276
294
  "new": "New",
277
295
  "save": "Save",
278
296
  "cancel": "Cancel",
@@ -296,7 +314,7 @@ window.__ModuleLoader__.load({
296
314
  "search": "Search notes\u2026",
297
315
  "bodyPlaceholder": "Write something\u2026",
298
316
  "titlePlaceholder": "Title (optional)",
299
- "tagsPlaceholder": "Tags, space separated",
317
+ "tagsPlaceholder": "Tags, comma separated",
300
318
  "colorLabel": "Color",
301
319
  "saveHint": "\u2318/Ctrl + Enter to save \xB7 Esc to cancel",
302
320
  "count": "{count} notes",
@@ -870,7 +888,8 @@ window.__ModuleLoader__.load({
870
888
  function previewLayout(note, index) {
871
889
  const width = previewWidth(note.id);
872
890
  const reserve = CENTRE_RESERVE;
873
- const startRadius = Math.hypot(reserve.halfWidth, reserve.halfHeight) + Math.hypot(WIDTH_PX[width], PREVIEW_NOMINAL_HEIGHT) / 2;
891
+ const widest = Math.max(...Object.values(WIDTH_PX));
892
+ const startRadius = Math.hypot(reserve.halfWidth, reserve.halfHeight) + Math.hypot(widest, PREVIEW_NOMINAL_HEIGHT) / 2;
874
893
  const radius = PREVIEW_STEP * Math.sqrt(Math.max(0, index) + (startRadius / PREVIEW_STEP) ** 2);
875
894
  const theta = index * GOLDEN_ANGLE + (unit(`${note.id}:pa`) - 0.5) * 0.55;
876
895
  return clampLayout({
@@ -938,6 +957,8 @@ window.__ModuleLoader__.load({
938
957
  var import_jsx_runtime = require("react/jsx-runtime");
939
958
  var TASK = /^\[([ xX])\][ \t]+([\s\S]*)$/;
940
959
  var ESCAPABLE = /* @__PURE__ */ new Set(["\\", "`", "*", "_", "{", "}", "[", "]", "(", ")", "#", "+", "-", ".", "!", ">", "~", "|"]);
960
+ var LINK = /\[([^\]]*)\]\(((?:[^()\s]|\([^()\s]*\))*)\)/y;
961
+ var AUTOLINK = /(?:https?:\/\/|www\.)[^\s<>()]+/y;
941
962
  function runLength(text, from, char) {
942
963
  let length = 0;
943
964
  while (text.charAt(from + length) === char) length += 1;
@@ -948,13 +969,17 @@ window.__ModuleLoader__.load({
948
969
  if (char === "") return false;
949
970
  return /[A-Za-z0-9]/.test(char);
950
971
  }
951
- function findClosing(text, from, delimiter) {
972
+ function findClosing(text, from, delimiter, failed) {
973
+ if (failed !== void 0 && failed.has(from)) return -1;
952
974
  const char = delimiter.charAt(0);
953
975
  const underscore = char === "_";
954
976
  let index = from;
955
977
  while (index < text.length) {
956
978
  const found = text.indexOf(delimiter, index);
957
- if (found === -1) return -1;
979
+ if (found === -1) {
980
+ failed?.add(from);
981
+ return -1;
982
+ }
958
983
  let backslashes = 0;
959
984
  for (let probe = found - 1; probe >= 0 && text.charAt(probe) === "\\"; probe -= 1) backslashes += 1;
960
985
  if (backslashes % 2 === 1) {
@@ -971,13 +996,23 @@ window.__ModuleLoader__.load({
971
996
  }
972
997
  return found;
973
998
  }
999
+ failed?.add(from);
974
1000
  return -1;
975
1001
  }
976
- function renderInline(text, keyPrefix = "i") {
1002
+ function renderInline(text, keyPrefix = "i", inLink = false) {
977
1003
  const nodes = [];
978
1004
  let buffer = "";
979
1005
  let counter = 0;
980
1006
  let index = 0;
1007
+ const failedClosers = /* @__PURE__ */ new Map();
1008
+ const failedFor = (delimiter) => {
1009
+ let set = failedClosers.get(delimiter);
1010
+ if (set === void 0) {
1011
+ set = /* @__PURE__ */ new Set();
1012
+ failedClosers.set(delimiter, set);
1013
+ }
1014
+ return set;
1015
+ };
981
1016
  const nextKey = () => `${keyPrefix}-${counter++}`;
982
1017
  const flush = () => {
983
1018
  if (buffer === "") return;
@@ -1000,7 +1035,7 @@ window.__ModuleLoader__.load({
1000
1035
  }
1001
1036
  if (char === "`") {
1002
1037
  const open = runLength(text, index, "`");
1003
- const closing = findClosing(text, index + open, "`".repeat(open));
1038
+ const closing = findClosing(text, index + open, "`".repeat(open), failedFor("`".repeat(open)));
1004
1039
  if (closing !== -1) {
1005
1040
  flush();
1006
1041
  const inner = text.slice(index + open, closing);
@@ -1018,7 +1053,7 @@ window.__ModuleLoader__.load({
1018
1053
  const opens = char !== "_" || !isWordChar(text, index - 1);
1019
1054
  if (opens && run >= 3) {
1020
1055
  const delimiter = char.repeat(3);
1021
- const closing = findClosing(text, index + 3, delimiter);
1056
+ const closing = findClosing(text, index + 3, delimiter, failedFor(delimiter));
1022
1057
  if (closing > index + 3) {
1023
1058
  flush();
1024
1059
  nodes.push(
@@ -1030,7 +1065,7 @@ window.__ModuleLoader__.load({
1030
1065
  }
1031
1066
  if (opens && run >= 2) {
1032
1067
  const delimiter = char + char;
1033
- const closing = findClosing(text, index + 2, delimiter);
1068
+ const closing = findClosing(text, index + 2, delimiter, failedFor(delimiter));
1034
1069
  if (closing > index + 2) {
1035
1070
  flush();
1036
1071
  nodes.push(
@@ -1041,7 +1076,7 @@ window.__ModuleLoader__.load({
1041
1076
  }
1042
1077
  }
1043
1078
  if (opens && run === 1) {
1044
- const closing = findClosing(text, index + 1, char);
1079
+ const closing = findClosing(text, index + 1, char, failedFor(char));
1045
1080
  if (closing > index + 1) {
1046
1081
  flush();
1047
1082
  nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { children: renderInline(text.slice(index + 1, closing), `${keyPrefix}-e`) }, nextKey()));
@@ -1054,7 +1089,7 @@ window.__ModuleLoader__.load({
1054
1089
  continue;
1055
1090
  }
1056
1091
  if (char === "~" && text.startsWith("~~", index)) {
1057
- const closing = findClosing(text, index + 2, "~~");
1092
+ const closing = findClosing(text, index + 2, "~~", failedFor("~~"));
1058
1093
  if (closing > index + 2) {
1059
1094
  flush();
1060
1095
  nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("s", { children: renderInline(text.slice(index + 2, closing), `${keyPrefix}-d`) }, nextKey()));
@@ -1062,21 +1097,23 @@ window.__ModuleLoader__.load({
1062
1097
  continue;
1063
1098
  }
1064
1099
  }
1065
- if (char === "[") {
1066
- const match = /^\[([^\]]*)\]\(((?:[^()\s]|\([^()\s]*\))*)\)/.exec(text.slice(index));
1100
+ if (char === "[" && !inLink) {
1101
+ const close = text.indexOf("]", index + 1);
1102
+ const match = close === -1 || text.charAt(close + 1) !== "(" ? null : (LINK.lastIndex = index, LINK.exec(text));
1067
1103
  if (match !== null) {
1068
1104
  flush();
1069
1105
  const label = match[1] ?? "";
1070
1106
  const href = safeHref(match[2] ?? "");
1071
1107
  nodes.push(
1072
- href === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label }, nextKey()) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "skw-md-link", href, target: "_blank", rel: "noreferrer noopener", children: renderInline(label, `${keyPrefix}-l`) }, nextKey())
1108
+ href === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label }, nextKey()) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "skw-md-link", href, target: "_blank", rel: "noreferrer noopener", children: renderInline(label, `${keyPrefix}-l`, true) }, nextKey())
1073
1109
  );
1074
1110
  index += match[0].length;
1075
1111
  continue;
1076
1112
  }
1077
1113
  }
1078
- if (char === "h" || char === "w") {
1079
- const match = /^(?:https?:\/\/|www\.)[^\s<>()]+/.exec(text.slice(index));
1114
+ if (!inLink && (char === "h" || char === "w")) {
1115
+ AUTOLINK.lastIndex = index;
1116
+ const match = AUTOLINK.exec(text);
1080
1117
  if (match !== null) {
1081
1118
  const raw = match[0];
1082
1119
  const trimmed = raw.replace(/[.,;:!?]+$/, "");
@@ -1217,16 +1254,19 @@ window.__ModuleLoader__.load({
1217
1254
  function leadingSpace(line) {
1218
1255
  return /^[ \t]*/.exec(line)?.[0] ?? "";
1219
1256
  }
1220
- var HEADING_MARKER = /^([ \t]*)(#{1,4})[ \t]+/;
1257
+ var HEADING_MARKER = /^([ \t]*)(#{1,6})[ \t]+/;
1221
1258
  var TODO_MARKER = /^([ \t]*)([-*+])[ \t]+\[[ xX]\][ \t]+/;
1222
- var ORDERED_MARKER = /^([ \t]*)(\d{1,3})([.)])[ \t]+/;
1259
+ var ORDERED_MARKER = /^([ \t]*)(\d{1,9})([.)])[ \t]+/;
1223
1260
  var BULLET_MARKER = /^([ \t]*)([-*+])[ \t]+/;
1224
1261
  var QUOTE_MARKER = /^([ \t]*)>[ \t]?/;
1262
+ var RULE_MARKER = /^([ \t]*)(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
1225
1263
  function stripBlockMarker(line) {
1226
1264
  for (const marker of [HEADING_MARKER, TODO_MARKER, ORDERED_MARKER, BULLET_MARKER, QUOTE_MARKER]) {
1227
1265
  const match = marker.exec(line);
1228
1266
  if (match !== null) return line.slice(match[0].length);
1229
1267
  }
1268
+ const rule = RULE_MARKER.exec(line);
1269
+ if (rule !== null) return "";
1230
1270
  return line.slice(leadingSpace(line).length);
1231
1271
  }
1232
1272
  function wrapSelection(ctx, open, close) {
@@ -1380,7 +1420,12 @@ window.__ModuleLoader__.load({
1380
1420
  en: "Inline",
1381
1421
  actions: [
1382
1422
  { id: "bold", key: "mdBold", zh: "\u7C97\u4F53", en: "Bold", glyph: "B", style: "bold", run: (ctx) => wrapSelection(ctx, "**", "**") },
1383
- { id: "italic", key: "mdItalic", zh: "\u659C\u4F53", en: "Italic", glyph: "I", style: "italic", run: (ctx) => wrapSelection(ctx, "_", "_") },
1423
+ // `*` rather than `_`: the parser refuses an underscore pair that touches a
1424
+ // word character (`snake_case_name` is an identifier), so italicising a
1425
+ // word inside a sentence produced `ab_cd_` — literal text, no <em>. An
1426
+ // empty selection produced `__`, which is a STRONG run and rendered bold.
1427
+ // The asterisk has no such word-boundary rule, so it always works.
1428
+ { id: "italic", key: "mdItalic", zh: "\u659C\u4F53", en: "Italic", glyph: "I", style: "italic", run: (ctx) => wrapSelection(ctx, "*", "*") },
1384
1429
  { id: "strike", key: "mdStrike", zh: "\u5220\u9664\u7EBF", en: "Strikethrough", glyph: "S", style: "strike", run: (ctx) => wrapSelection(ctx, "~~", "~~") },
1385
1430
  { id: "code", key: "mdCode", zh: "\u884C\u5185\u4EE3\u7801", en: "Inline code", glyph: "<>", run: (ctx) => wrapSelection(ctx, "`", "`") },
1386
1431
  { id: "link", key: "mdLink", zh: "\u94FE\u63A5", en: "Link", glyph: "\u26D3", run: (ctx) => wrapSelection(ctx, "[", "](https://)") }
@@ -1403,14 +1448,27 @@ window.__ModuleLoader__.load({
1403
1448
  for (const char of prefix) width += char === " " ? INDENT_WIDTH2 : 1;
1404
1449
  return width;
1405
1450
  }
1451
+ function indentUnitOf(value) {
1452
+ let sawIndent = false;
1453
+ for (const line of value.split("\n")) {
1454
+ if (line.trim() === "") continue;
1455
+ const columns2 = columnsOf(leadingSpace(line));
1456
+ if (columns2 === 0) continue;
1457
+ sawIndent = true;
1458
+ if (columns2 % WIDE_INDENT_UNIT !== 0) return INDENT_WIDTH2;
1459
+ }
1460
+ return sawIndent ? WIDE_INDENT_UNIT : INDENT_WIDTH2;
1461
+ }
1462
+ var WIDE_INDENT_UNIT = 4;
1406
1463
  function indentSelection(value, start, end, direction) {
1464
+ const unit2 = indentUnitOf(value);
1407
1465
  return rewriteLines(value, start, end, (line) => {
1408
1466
  if (line.trim() === "") return line;
1409
1467
  const prefix = leadingSpace(line);
1410
1468
  const body = line.slice(prefix.length);
1411
- if (direction === 1) return `${prefix}${INDENT}${body}`;
1412
- const level = Math.floor(columnsOf(prefix) / INDENT_WIDTH2);
1413
- return `${" ".repeat(Math.max(0, level - 1) * INDENT_WIDTH2)}${body}`;
1469
+ if (direction === 1) return `${prefix}${" ".repeat(unit2)}${body}`;
1470
+ const level = Math.floor(columnsOf(prefix) / unit2);
1471
+ return `${" ".repeat(Math.max(0, level - 1) * unit2)}${body}`;
1414
1472
  });
1415
1473
  }
1416
1474
  function fenceLines(lines) {
@@ -1559,33 +1617,54 @@ window.__ModuleLoader__.load({
1559
1617
  const pending = (0, import_react.useRef)(null);
1560
1618
  const guarded = (0, import_react.useCallback)((event) => {
1561
1619
  const native = event.nativeEvent;
1562
- return composing.current || justEnded.current || native.isComposing || native.keyCode === 229;
1620
+ if (composing.current || native.isComposing || native.keyCode === 229) return true;
1621
+ if (justEnded.current) {
1622
+ justEnded.current = false;
1623
+ return true;
1624
+ }
1625
+ return false;
1563
1626
  }, []);
1564
1627
  (0, import_react.useEffect)(() => {
1565
1628
  const node = areaRef.current;
1566
1629
  if (node === null) return;
1630
+ let expiry = null;
1631
+ const clearExpiry = () => {
1632
+ if (expiry !== null) {
1633
+ clearTimeout(expiry);
1634
+ expiry = null;
1635
+ }
1636
+ };
1567
1637
  const open = () => {
1568
1638
  composing.current = true;
1569
1639
  justEnded.current = false;
1640
+ clearExpiry();
1570
1641
  };
1571
1642
  const close = () => {
1572
1643
  composing.current = false;
1573
1644
  justEnded.current = true;
1574
1645
  tabEscape.current = false;
1646
+ clearExpiry();
1647
+ expiry = setTimeout(() => {
1648
+ justEnded.current = false;
1649
+ expiry = null;
1650
+ }, 0);
1575
1651
  };
1576
1652
  const settle = () => {
1577
1653
  justEnded.current = false;
1654
+ clearExpiry();
1578
1655
  };
1579
1656
  const reset = () => {
1580
1657
  composing.current = false;
1581
1658
  justEnded.current = false;
1582
1659
  tabEscape.current = false;
1660
+ clearExpiry();
1583
1661
  };
1584
1662
  node.addEventListener("compositionstart", open);
1585
1663
  node.addEventListener("compositionend", close);
1586
1664
  node.addEventListener("keyup", settle);
1587
1665
  window.addEventListener("blur", reset);
1588
1666
  return () => {
1667
+ clearExpiry();
1589
1668
  node.removeEventListener("compositionstart", open);
1590
1669
  node.removeEventListener("compositionend", close);
1591
1670
  node.removeEventListener("keyup", settle);
@@ -2716,7 +2795,10 @@ window.__ModuleLoader__.load({
2716
2795
  return stamp2.toLocaleDateString(zh2 ? "zh-CN" : "en-US", { month: "short", day: "numeric" });
2717
2796
  }
2718
2797
  function parseTags(raw) {
2719
- return raw.split(/[,,\s]+/).map((tag) => tag.trim()).filter((tag) => tag !== "");
2798
+ return raw.split(/[,,]/).map((tag) => tag.trim()).filter((tag) => tag !== "");
2799
+ }
2800
+ function formatTags(tags) {
2801
+ return tags.join(", ");
2720
2802
  }
2721
2803
  function clampZoom(value) {
2722
2804
  return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, value));
@@ -3120,6 +3202,7 @@ window.__ModuleLoader__.load({
3120
3202
  }
3121
3203
  function WallPage({ api, locale, t }) {
3122
3204
  const [notes, setNotes] = (0, import_react3.useState)([]);
3205
+ const [counts, setCounts] = (0, import_react3.useState)({ total: 0, live: 0, archived: 0 });
3123
3206
  const [filter, setFilter] = (0, import_react3.useState)("all");
3124
3207
  const [sort, setSort] = (0, import_react3.useState)("pinned");
3125
3208
  const [view, setView] = (0, import_react3.useState)("canvas");
@@ -3199,6 +3282,7 @@ window.__ModuleLoader__.load({
3199
3282
  const snapshot = await api.list(options.includeArchived, options.sort, life.current.signal);
3200
3283
  if (alive.current && seq === sequence.current) {
3201
3284
  setNotes((previous) => reconcileNotes(previous, snapshot.notes));
3285
+ setCounts(snapshot.counts);
3202
3286
  if (snapshot.revision > 0) revision.current = snapshot.revision;
3203
3287
  if (snapshot.notesDir !== "") setNotesDir(snapshot.notesDir);
3204
3288
  if (options.clearError !== false) setError("");
@@ -3297,12 +3381,12 @@ window.__ModuleLoader__.load({
3297
3381
  function openComposer(note) {
3298
3382
  setDraftError("");
3299
3383
  setDraftStatus("idle");
3300
- setDraft(note ? { id: note.id, title: note.title, body: note.body, tags: note.tags.join(" "), color: note.color, width: layoutOf(note, 0).width } : { id: null, title: "", body: "", tags: "", color: "yellow", width: "md" });
3384
+ setDraft(note ? { id: note.id, title: note.title, body: note.body, tags: formatTags(note.tags), color: note.color, width: layoutOf(note, 0).width } : { id: null, title: "", body: "", tags: "", color: "yellow", width: "md" });
3301
3385
  }
3302
3386
  async function saveDraft() {
3303
3387
  if (!draft || inFlight.current) return;
3304
- const body = draft.body.trim();
3305
- if (body === "") {
3388
+ const body = draft.body;
3389
+ if (draft.id === null && body.trim() === "") {
3306
3390
  setDraftError(t("emptyBody"));
3307
3391
  setDraftStatus("failed");
3308
3392
  return;
@@ -3317,6 +3401,10 @@ window.__ModuleLoader__.load({
3317
3401
  life.current.signal,
3318
3402
  { centreReserve: centreReserve() }
3319
3403
  );
3404
+ const placed = note.layout ?? layoutOf(note, notes.length);
3405
+ if (placed.width !== draft.width) {
3406
+ await api.move(note.id, { ...placed, width: draft.width }, life.current.signal);
3407
+ }
3320
3408
  arrival.current = { id: note.id, token: Date.now() };
3321
3409
  setArrivedId(note.id);
3322
3410
  } else {
@@ -3341,13 +3429,13 @@ window.__ModuleLoader__.load({
3341
3429
  return `${note.title} ${note.body} ${note.tags.join(" ")}`.toLowerCase().includes(needle);
3342
3430
  });
3343
3431
  }, [notes, filter, query, showArchived]);
3344
- const archivedCount = notes.filter((note) => note.archived).length;
3432
+ const archivedCount = counts.archived;
3345
3433
  const greeting = (0, import_react3.useMemo)(() => {
3346
3434
  const hour = (/* @__PURE__ */ new Date()).getHours();
3347
3435
  const key = hour < 5 ? "greetNight" : hour < 12 ? "greetMorning" : hour < 18 ? "greetAfternoon" : "greetEvening";
3348
3436
  return t(key);
3349
3437
  }, [t, activeLocale]);
3350
- const emptyCopy = filter === "archived" ? t("emptyArchived") : query.trim() !== "" ? t("noResults") : t("empty");
3438
+ const emptyCopy = filter === "archived" ? t("emptyArchived") : query.trim() !== "" ? t("noResults") : counts.total > 0 && counts.archived === counts.total ? t("emptyAllArchived") : t("empty");
3351
3439
  const wallBounds = (0, import_react3.useMemo)(() => {
3352
3440
  let minX = Number.POSITIVE_INFINITY;
3353
3441
  let minY = Number.POSITIVE_INFINITY;
@@ -3871,7 +3959,7 @@ window.__ModuleLoader__.load({
3871
3959
  )) }),
3872
3960
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "skw-centre", ref: centreRef, "aria-hidden": false, children: [
3873
3961
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "skw-centre-hello", children: greeting }),
3874
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "skw-centre-tally", "data-empty": visible.length === 0, children: visible.length === 0 ? emptyCopy : t("centreTally", { count: visible.length, archived: archivedCount }) }),
3962
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "skw-centre-tally", "data-empty": visible.length === 0, children: visible.length === 0 ? emptyCopy : t("centreTally", { count: counts.live, archived: counts.archived }) }),
3875
3963
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3876
3964
  "form",
3877
3965
  {
@@ -183,16 +183,92 @@ export function findFrontmatter(text) {
183
183
  for (let index = 0; index < lines.length; index += 1) {
184
184
  const line = (lines[index] ?? '').replace(/\r$/, '');
185
185
  const trimmed = line.trim();
186
- // An opening delimiter with no closing one is not frontmatter: the user is
187
- // writing a document that starts with a rule. Fall back to plain body.
186
+ /**
187
+ * An opening delimiter with no closing one is not frontmatter: the user is
188
+ * writing a document that starts with a rule. Fall back to plain body.
189
+ *
190
+ * The content BETWEEN the delimiters must also look like frontmatter. A note
191
+ * that merely starts with a horizontal rule and has another one further down
192
+ * is ordinary Markdown:
193
+ *
194
+ * ---
195
+ * # My notes
196
+ * Shopping list
197
+ * ---
198
+ *
199
+ * Treating that as a frontmatter block discarded everything up to the second
200
+ * rule, and the next write made the loss permanent on disk. So the block is
201
+ * only accepted when every line inside it is something the frontmatter
202
+ * grammar can represent: a `key: value` pair, a `- item` continuation, a
203
+ * comment, or a blank line.
204
+ */
188
205
  if (trimmed === DELIMITER || trimmed === '...') {
206
+ const raw = rest.slice(0, offset);
207
+ if (!looksLikeFrontmatter(raw))
208
+ return null;
189
209
  const bodyStart = offset + line.length + 1;
190
- return { raw: rest.slice(0, offset), body: rest.slice(bodyStart) };
210
+ return { raw, body: rest.slice(bodyStart) };
191
211
  }
192
212
  offset += line.length + 1;
193
213
  }
194
214
  return null;
195
215
  }
216
+ /**
217
+ * Whether a block between two rules is really frontmatter.
218
+ *
219
+ * Two things are being told apart:
220
+ *
221
+ * - a DAMAGED frontmatter, which must still be honoured (its readable keys win)
222
+ * and flagged, per the fail-soft contract — `bad line` next to `color: pink`;
223
+ * - PROSE that merely sits between two horizontal rules, which must not be
224
+ * swallowed at all:
225
+ *
226
+ * ---
227
+ * # My notes
228
+ * Shopping list
229
+ * ---
230
+ *
231
+ * A `key:` anywhere settles it as frontmatter. With no key at all the block is
232
+ * frontmatter only if it still LOOKS like one: a short run of single-token
233
+ * attribute lines. Prose is what fails that test — a sentence carries spaces, and
234
+ * a Markdown heading starts with `#` — so the whole file is kept as the body.
235
+ */
236
+ function looksLikeFrontmatter(raw) {
237
+ const lines = raw.split('\n').map((line) => line.trim()).filter((line) => line !== '');
238
+ if (lines.length === 0)
239
+ return true;
240
+ if (lines.some((line) => /^[A-Za-z0-9_.-]+\s*:/.test(line)))
241
+ return true;
242
+ // No key at all: accept only a short block of attribute-shaped tokens.
243
+ if (lines.length > MAX_DAMAGED_LINES)
244
+ return false;
245
+ // A single line is the ambiguous case a real damaged file produces
246
+ // (`---\nbad line\n---`). Prose between two rules is a MULTI-line document by
247
+ // nature, so one line is read as damaged frontmatter and flagged.
248
+ if (lines.length === 1)
249
+ return true;
250
+ return lines.every((line) => isAttributeToken(line));
251
+ }
252
+ /**
253
+ * Whether one keyless line looks like a frontmatter attribute rather than prose.
254
+ *
255
+ * An attribute is a single token (`bad`, `broken_line`). A sentence has spaces,
256
+ * a Markdown heading starts with `#`, and a list item starts with a marker — none
257
+ * of those belong inside a frontmatter block.
258
+ */
259
+ function isAttributeToken(line) {
260
+ if (line.length > MAX_DAMAGED_LINE_LENGTH)
261
+ return false;
262
+ if (line.startsWith('#'))
263
+ return false;
264
+ if (line.startsWith('- '))
265
+ return false;
266
+ return !/\s/.test(line);
267
+ }
268
+ /** How many keyless lines a damaged frontmatter block may still have. */
269
+ const MAX_DAMAGED_LINES = 8;
270
+ /** How long a keyless "attribute-looking" line may be. */
271
+ const MAX_DAMAGED_LINE_LENGTH = 40;
196
272
  /**
197
273
  * Parse a frontmatter block into its key/value pairs, last writer winning.
198
274
  *
@@ -316,8 +392,18 @@ export function parseNoteFile(text, options) {
316
392
  const title = unquote(entries.get('title') ?? '').slice(0, LIMITS.title);
317
393
  const extra = {};
318
394
  for (const [key, value] of entries) {
395
+ /**
396
+ * `extra` values are stored UNQUOTED, exactly like every known key.
397
+ *
398
+ * They used to keep the raw source text, so a quoted value (`due: "2026-05-01"`)
399
+ * went back through {@link scalar} as if it were a bare string and came out
400
+ * double-quoted. The next read then kept THOSE quotes, and the cycle compounded:
401
+ * measured 39 bytes -> 110 -> 358 over six saves, on its way past the 4 MB file
402
+ * cap where the note silently disappears from the wall. Unquoting here is what
403
+ * makes property 3 ("unknown keys survive") true rather than a loop.
404
+ */
319
405
  if (!KNOWN_KEYS.has(key))
320
- extra[key] = value;
406
+ extra[key] = unquote(value);
321
407
  }
322
408
  const note = {
323
409
  // An explicit id wins; the filename is the fallback so a hand-created file
@@ -362,7 +448,15 @@ function quote(value) {
362
448
  }
363
449
  /** Serialize a scalar plain when it is unambiguous, quoted otherwise. */
364
450
  function scalar(value) {
365
- if (value !== '' && !/^[\s"'[\]{#&*!|>%@`,:?\-]/.test(value) && !/\s$/.test(value) && !/^(true|false|null|yes|no|on|off|~)$/i.test(value) && !/^[+-]?\d/.test(value)) {
451
+ // A value containing a newline MUST be quoted: written bare it becomes several
452
+ // physical lines, and the next read sees only the first as this key's value
453
+ // while the rest parses as a malformed top-level line.
454
+ if (value !== '' &&
455
+ !/[\r\n]/.test(value) &&
456
+ !/^[\s"'[\]{#&*!|>%@`,:?\-]/.test(value) &&
457
+ !/\s$/.test(value) &&
458
+ !/^(true|false|null|yes|no|on|off|~)$/i.test(value) &&
459
+ !/^[+-]?\d/.test(value)) {
366
460
  return value;
367
461
  }
368
462
  return quote(value);
package/lib/index.js CHANGED
@@ -131,11 +131,18 @@ async function readLegacyNotes(facility) {
131
131
  * The directory a 0.7.x install's storage domain wrote its records into.
132
132
  *
133
133
  * It sits beside the notes directory, under the same DSH home, so it is derived
134
- * rather than configured: `storages/<domain name>/notes`. The recovery path uses
135
- * it to find the `<id>.json.bak.<stamp>` files a broken 0.8.0 run left behind.
134
+ * rather than configured: `<DSH_HOME>/storages/<domain name>/notes`. The recovery
135
+ * path uses it to find the `<id>.json.bak.<stamp>` files a broken 0.8.0 run left
136
+ * behind.
137
+ *
138
+ * The home is ONE `dirname` up, not two. `notesDir` is `<DSH_HOME>/sticky-notes`,
139
+ * so a second `dirname` stripped `.dsh` as well and produced
140
+ * `<parent-of-home>/storages/...` — a path that never exists. The recovery then
141
+ * hit ENOENT, reported `already-present`, and left every user's quarantined notes
142
+ * stranded: the whole recovery path was dead code in the shipped configuration.
136
143
  */
137
144
  function legacyNotesDirOf(notesDir) {
138
- const home = dirname(dirname(notesDir));
145
+ const home = dirname(notesDir);
139
146
  return join(home, 'storages', LEGACY_DOMAIN_NAME, 'notes');
140
147
  }
141
148
  /** Model-facing text for one tool result; short, deterministic and readable. */
@@ -368,6 +375,7 @@ export function apply(ctx, rawConfig = {}) {
368
375
  const store = await ready;
369
376
  return {
370
377
  list: (includeArchived, sort) => store.list(includeArchived, sort),
378
+ counts: () => store.counts(),
371
379
  revisionOf: () => store.revision,
372
380
  notesDir: store.notesDir,
373
381
  create: (input, id, options) => store.create(input, id, options),
package/lib/layout.js CHANGED
@@ -292,11 +292,22 @@ export function previewLayout(note, index) {
292
292
  // lands outside the rectangle at any reserve size.
293
293
  const reserve = CENTRE_RESERVE;
294
294
  // The reserve's half-diagonal is how far the RECTANGLE's corner is from the
295
- // middle; the card's own half-diagonal is how far the CARD reaches back inward
296
- // from its centre. Adding both is what guarantees the derived box cannot clip
297
- // a corner of the reserved band.
295
+ // middle; a card's half-diagonal is how far it reaches back inward from its
296
+ // centre. Adding both is what guarantees the derived box cannot clip a corner
297
+ // of the reserved band.
298
+ //
299
+ // The card half-diagonal is the WIDEST preset's, not this card's. Using the
300
+ // card's own width made the start radius — and therefore the whole spiral —
301
+ // depend on which preset the id happened to hash to, so a narrow card at index
302
+ // `i+1` could land INSIDE a wide card at index `i` and the radii stopped
303
+ // increasing with the index. The old reserve's numbers happened to keep that
304
+ // inversion invisible; sizing the reserve for the framing floor exposed it.
305
+ // Reserving for the widest preset costs a few pixels of paper and makes the
306
+ // radius a function of the index alone, which is what "the spiral grows
307
+ // outward" actually requires.
308
+ const widest = Math.max(...Object.values(WIDTH_PX));
298
309
  const startRadius = Math.hypot(reserve.halfWidth, reserve.halfHeight) +
299
- Math.hypot(WIDTH_PX[width], PREVIEW_NOMINAL_HEIGHT) / 2;
310
+ Math.hypot(widest, PREVIEW_NOMINAL_HEIGHT) / 2;
300
311
  const radius = PREVIEW_STEP * Math.sqrt(Math.max(0, index) + (startRadius / PREVIEW_STEP) ** 2);
301
312
  const theta = index * GOLDEN_ANGLE + (unit(`${note.id}:pa`) - 0.5) * 0.55;
302
313
  return clampLayout({
package/lib/migrate.js CHANGED
@@ -57,6 +57,22 @@ async function isAlreadyPresent(notesDir) {
57
57
  * they wrote themselves must never have it confused with the seed.
58
58
  */
59
59
  const SEEDED_WELCOME_BODY = '随手记下一闪而过的灵感,或一件临时的工作。';
60
+ /**
61
+ * Whether one path holds 0.8.0's auto-seeded welcome note.
62
+ *
63
+ * The test is the seeded BODY, not the file name: the name `welcome` is a legal
64
+ * id a 0.7.x wall could genuinely own, and the whole point of the recovery is to
65
+ * bring that note back. Only a file whose text carries the seed's own copy is
66
+ * safe to replace or delete.
67
+ */
68
+ async function isSeededWelcome(path) {
69
+ try {
70
+ return (await readFile(path, 'utf8')).includes(SEEDED_WELCOME_BODY);
71
+ }
72
+ catch {
73
+ return false;
74
+ }
75
+ }
60
76
  /** True when the directory holds nothing but 0.8.0's auto-seeded welcome note. */
61
77
  async function isBuggyEmptyWall(notesDir) {
62
78
  let entries;
@@ -75,13 +91,7 @@ async function isBuggyEmptyWall(notesDir) {
75
91
  const only = files[0] ?? '';
76
92
  if (idOfFile(only) !== 'welcome')
77
93
  return false;
78
- try {
79
- const text = await readFile(join(notesDir, only), 'utf8');
80
- return text.includes(SEEDED_WELCOME_BODY);
81
- }
82
- catch {
83
- return false;
84
- }
94
+ return isSeededWelcome(join(notesDir, only));
85
95
  }
86
96
  /**
87
97
  * Recover a wall that 0.8.0 left looking empty.
@@ -126,12 +136,20 @@ async function recoverFromBuggyWall(notesDir, options) {
126
136
  if (newest.size === 0)
127
137
  return { migrated: false, reason: 'already-present' };
128
138
  let written = 0;
139
+ /** Ids whose quarantined record was written back as a real note. */
140
+ const restored = new Set();
129
141
  for (const [id, { file }] of newest) {
130
142
  const target = join(notesDir, fileNameOf(id));
131
- // Never overwrite a note the user already has on the wall.
132
- const exists = await stat(target).then(() => true, () => false);
133
- if (exists)
134
- continue;
143
+ // Never overwrite a note the user already has on the wall — with ONE
144
+ // exception: 0.8.0's own auto-seeded welcome note. It is not user data, and
145
+ // `isBuggyEmptyWall` only lets this function run when the directory holds
146
+ // nothing else. Skipping it is what destroyed the user's real `welcome`
147
+ // note: the record was never written, and the cleanup below then deleted the
148
+ // seed, so the note vanished from both sides.
149
+ if (await stat(target).then(() => true, () => false)) {
150
+ if (!(await isSeededWelcome(target)))
151
+ continue;
152
+ }
135
153
  try {
136
154
  const envelope = JSON.parse(await readFile(join(legacyDir, file), 'utf8'));
137
155
  const record = envelope.record;
@@ -139,6 +157,7 @@ async function recoverFromBuggyWall(notesDir, options) {
139
157
  continue;
140
158
  const note = normalizeLegacyRecord(record, id);
141
159
  await writeFile(target, serializeNoteFile(note), 'utf8');
160
+ restored.add(id);
142
161
  written += 1;
143
162
  }
144
163
  catch {
@@ -146,10 +165,13 @@ async function recoverFromBuggyWall(notesDir, options) {
146
165
  // must not stop the rest from coming back.
147
166
  }
148
167
  }
149
- // The seeded welcome note is only removed when the user's own notes came back,
150
- // so a failed recovery cannot leave them looking at an empty wall.
151
- if (written > 0)
152
- await rm(join(notesDir, fileNameOf('welcome')), { force: true });
168
+ // Remove the seed only when the user's own `welcome` note did NOT come back.
169
+ // When it did, the file at that path is now the user's note and must survive.
170
+ if (written > 0 && !restored.has('welcome')) {
171
+ const seeded = join(notesDir, fileNameOf('welcome'));
172
+ if (await isSeededWelcome(seeded))
173
+ await rm(seeded, { force: true });
174
+ }
153
175
  return written === 0
154
176
  ? { migrated: false, reason: 'already-present' }
155
177
  : { migrated: true, reason: 'recovered-from-broken-migration', count: written };
@@ -215,6 +237,55 @@ function sameNote(expected, actual) {
215
237
  sameInstant(expected.createdAt, actual.createdAt) &&
216
238
  sameInstant(expected.updatedAt, actual.updatedAt));
217
239
  }
240
+ /**
241
+ * The read-back comparison, allowing for the format's DOCUMENTED normalizations.
242
+ *
243
+ * Four fields are normalized by the writer and passed through unchanged by the
244
+ * legacy reader, so comparing them raw made the migration fail for ordinary
245
+ * walls — an uppercase tag, a ninth tag, an over-long title, a `\r\n` body — and
246
+ * because the failure is deterministic the retry never converged:
247
+ *
248
+ * - `tags` are lowercased, inner whitespace collapsed, each truncated to
249
+ * `LIMITS.tag` and capped at `LIMITS.tags`;
250
+ * - `title` is whitespace-collapsed and truncated to `LIMITS.title`;
251
+ * - `body` has its line endings folded to `\n`;
252
+ * - `createdAt` / `updatedAt` are re-serialized through a date.
253
+ *
254
+ * Everything else — the id, the colour, the flags, the placement, the body's
255
+ * TEXT — must survive exactly. A `NaN` coordinate, for instance, serializes as
256
+ * `x: NaN` and parses back as `0`, which is real corruption and still fails.
257
+ */
258
+ function sameNoteIgnoringNormalization(expected, actual) {
259
+ return (expected.id === actual.id &&
260
+ normalizeTitleForCompare(expected.title) === actual.title &&
261
+ expected.body.replace(/\r\n?/g, '\n') === actual.body &&
262
+ expected.color === actual.color &&
263
+ expected.pinned === actual.pinned &&
264
+ expected.archived === actual.archived &&
265
+ sameTagsForCompare(expected.tags, actual.tags) &&
266
+ sameLayout(expected.layout, actual.layout) &&
267
+ sameInstant(expected.createdAt, actual.createdAt) &&
268
+ sameInstant(expected.updatedAt, actual.updatedAt));
269
+ }
270
+ /** The title as the writer will store it. */
271
+ function normalizeTitleForCompare(raw) {
272
+ return raw.replace(/\s+/g, ' ').trim().slice(0, LIMITS.title);
273
+ }
274
+ /** Whether the legacy tag list and the stored one are the same list, normalized. */
275
+ function sameTagsForCompare(expected, actual) {
276
+ const normalized = [];
277
+ const seen = new Set();
278
+ for (const entry of expected) {
279
+ const tag = entry.trim().toLowerCase().replace(/\s+/g, ' ').slice(0, LIMITS.tag);
280
+ if (tag === '' || seen.has(tag))
281
+ continue;
282
+ seen.add(tag);
283
+ normalized.push(tag);
284
+ if (normalized.length >= LIMITS.tags)
285
+ break;
286
+ }
287
+ return normalized.length === actual.length && normalized.every((tag, index) => tag === actual[index]);
288
+ }
218
289
  /** Compare two placements, treating two `null`s as equal. */
219
290
  function sameLayout(left, right) {
220
291
  if (left === null || right === null)
@@ -278,6 +349,15 @@ export async function migrateNotes(options) {
278
349
  // the one just written, but only a parse proves the bytes survived the
279
350
  // round-trip, and a silently mangled note is the one failure a user would
280
351
  // never notice until the text was already wrong.
352
+ //
353
+ // The comparison tolerates the format's DOCUMENTED normalizations and
354
+ // nothing else. Comparing the raw legacy note against the parsed file failed
355
+ // for any note with an uppercase tag, a ninth tag, a 200-character title or a
356
+ // `\r\n` body — the writer normalizes all four while the legacy reader passes
357
+ // them through — so such a wall aborted DETERMINISTICALLY, could never
358
+ // converge, and (with the retry cancelled) left the notes stranded. A
359
+ // normalization delta is not corruption; a lost id, body, colour, placement
360
+ // or timestamp is, and still fails here.
281
361
  const files = (await readdir(notesDir)).filter((name) => idOfFile(name) !== null);
282
362
  if (files.length !== legacy.length) {
283
363
  throw new Error(`migrated ${String(files.length)} files from ${String(legacy.length)} legacy notes`);
@@ -291,8 +371,9 @@ export async function migrateNotes(options) {
291
371
  fallbackId: note.id,
292
372
  fallbackTime: info.mtime.toISOString(),
293
373
  });
294
- if (!sameNote(note, parsed.note))
374
+ if (!sameNoteIgnoringNormalization(note, parsed.note)) {
295
375
  throw new Error(`migrated file for ${note.id} does not round-trip`);
376
+ }
296
377
  }
297
378
  const at = (options.now ?? (() => new Date()))().toISOString();
298
379
  // Best-effort: the marker is documentation of what happened, and the notes
package/lib/store.d.ts CHANGED
@@ -172,6 +172,20 @@ export declare class StickyWallStore {
172
172
  read(id: string): Note | null;
173
173
  /** Every stored note, newest-relevant first; archived ones only on request. */
174
174
  list(includeArchived?: boolean, sort?: 'pinned' | 'created' | 'updated'): Note[];
175
+ /**
176
+ * The wall's real composition: how many notes exist, live and archived.
177
+ *
178
+ * This is the ONLY honest source for those numbers. `list` returns a
179
+ * projection — the default call omits archived notes entirely — so a caller
180
+ * counting `archived` out of a `list` result is counting its own filter and
181
+ * will read zero on a wall that has an archive. Every note in the map is
182
+ * counted here, archived or not.
183
+ */
184
+ counts(): {
185
+ total: number;
186
+ live: number;
187
+ archived: number;
188
+ };
175
189
  /**
176
190
  * The snapshot the store's own mutations work from.
177
191
  *
package/lib/store.js CHANGED
@@ -97,10 +97,19 @@ function normalizeBody(raw) {
97
97
  * a legitimate edit — the user is clearing the card to retype it, or keeping a
98
98
  * card as a title only — and refusing it left the editor unable to save at all,
99
99
  * with the old text still on disk. Length is still capped.
100
+ *
101
+ * `previousLength` lets a note that is ALREADY over the cap be shortened. Such a
102
+ * note can exist: `load()` reads a hand-written file by its byte size, and a body
103
+ * under that limit can still exceed {@link LIMITS.body}. Rejecting every edit to
104
+ * it left the note permanently stuck, since the only way back under the cap is to
105
+ * delete characters — which is an update carrying an over-limit body until the
106
+ * writer gets there. Growth is still refused.
100
107
  */
101
- function normalizeBodyForUpdate(raw) {
108
+ function normalizeBodyForUpdate(raw, previousLength = 0) {
102
109
  const value = readBody(raw);
103
- assertBodyLength(value);
110
+ if (value.length > LIMITS.body && value.length >= previousLength) {
111
+ assertBodyLength(value);
112
+ }
104
113
  return value;
105
114
  }
106
115
  /** Validate and trim a title; an absent title is the empty string. */
@@ -201,6 +210,17 @@ export class StickyWallStore {
201
210
  */
202
211
  static async open(options) {
203
212
  const store = new StickyWallStore(options);
213
+ /**
214
+ * Whether the one-time migration failed and must be retried.
215
+ *
216
+ * A failed migration leaves the legacy wall untouched, and the contract is
217
+ * that the NEXT start tries again. That retry only works if this start leaves
218
+ * no note file behind: `isAlreadyPresent` treats any `.md` in the directory as
219
+ * "already migrated", so seeding the welcome note after a failure would make
220
+ * the legacy wall permanently invisible — one transient read error would cost
221
+ * the user their whole 0.7.x wall, silently, forever.
222
+ */
223
+ let migrationFailed = false;
204
224
  if (options.readLegacy !== undefined) {
205
225
  const result = await migrateNotes({
206
226
  notesDir: store.notesDir,
@@ -209,6 +229,7 @@ export class StickyWallStore {
209
229
  ...(options.now === undefined ? {} : { now: options.now }),
210
230
  });
211
231
  if (!result.migrated && result.reason === 'failed') {
232
+ migrationFailed = true;
212
233
  // The legacy wall is untouched and the next start retries, so the plugin
213
234
  // still opens — empty rather than broken. Say so loudly enough that the
214
235
  // Host log explains why the user's notes are missing.
@@ -217,7 +238,8 @@ export class StickyWallStore {
217
238
  }
218
239
  await mkdir(store.notesDir, { recursive: true });
219
240
  await store.load();
220
- if (options.seedWelcomeNote)
241
+ // Never seed after a failure: the seed is what would cancel the retry.
242
+ if (options.seedWelcomeNote && !migrationFailed)
221
243
  await store.seedWelcomeNote();
222
244
  return store;
223
245
  }
@@ -302,11 +324,32 @@ export class StickyWallStore {
302
324
  // note has; a note WITH frontmatter keeps its authored `created`.
303
325
  fallbackTime: info.mtime.toISOString(),
304
326
  });
327
+ /**
328
+ * Enforce the body limit on the way IN as well as on the way out.
329
+ *
330
+ * `LIMITS.fileBytes` (4 MB) is a different guard: a file can be well
331
+ * under it and still carry a body twenty times the documented maximum.
332
+ * That body used to load happily and then be impossible to save — every
333
+ * `update` carrying it back was rejected with `body-too-long`, so the
334
+ * note was trapped in the editor. It is also what the renderer would have
335
+ * to lay out, and the client-side cost is linear in its length.
336
+ *
337
+ * The note is kept, not dropped: a hand-written file is the user's text,
338
+ * so it loads with a `metaError` the card can flag, and the editor can
339
+ * still shorten it.
340
+ */
341
+ const tooLong = parsed.note.body.length > LIMITS.body
342
+ ? `body-too-long:${String(parsed.note.body.length)}`
343
+ : undefined;
305
344
  // The file name is the identity on disk. A frontmatter `id` that
306
345
  // disagrees (a hand-copied file, a rename) must not become a second
307
346
  // address for the same note: the next write would then land in a
308
347
  // different file and leave the loaded one behind.
309
- this.notes.set(id, { ...parsed.note, id });
348
+ this.notes.set(id, {
349
+ ...parsed.note,
350
+ id,
351
+ ...(tooLong === undefined ? {} : { metaError: parsed.note.metaError ?? tooLong }),
352
+ });
310
353
  }
311
354
  catch (error) {
312
355
  this.log(`sticky-wall: skipping unreadable note file ${entry.name}: ${error instanceof Error ? error.message : String(error)}`);
@@ -415,6 +458,24 @@ export class StickyWallStore {
415
458
  this.assertOpen();
416
459
  return this.gathered(includeArchived, sort);
417
460
  }
461
+ /**
462
+ * The wall's real composition: how many notes exist, live and archived.
463
+ *
464
+ * This is the ONLY honest source for those numbers. `list` returns a
465
+ * projection — the default call omits archived notes entirely — so a caller
466
+ * counting `archived` out of a `list` result is counting its own filter and
467
+ * will read zero on a wall that has an archive. Every note in the map is
468
+ * counted here, archived or not.
469
+ */
470
+ counts() {
471
+ this.assertOpen();
472
+ let archived = 0;
473
+ for (const note of this.notes.values())
474
+ if (note.archived)
475
+ archived += 1;
476
+ const total = this.notes.size;
477
+ return { total, live: total - archived, archived };
478
+ }
418
479
  /**
419
480
  * The snapshot the store's own mutations work from.
420
481
  *
@@ -505,7 +566,19 @@ export class StickyWallStore {
505
566
  // file's frontmatter is suspect) ride through untouched.
506
567
  const next = { ...current };
507
568
  if (patch?.body !== undefined)
508
- next.body = normalizeBodyForUpdate(patch.body);
569
+ next.body = normalizeBodyForUpdate(patch.body, current.body.length);
570
+ /**
571
+ * Clear the over-limit flag once the body fits again.
572
+ *
573
+ * `load()` marks a hand-written note whose body exceeded the cap so the card
574
+ * can say why it is unsaveable. Shortening the body is the fix, so the mark
575
+ * has to come off — otherwise the card keeps warning about a problem that no
576
+ * longer exists. Any OTHER `metaError` (a malformed or newer frontmatter) is
577
+ * left alone: it describes the file, not the length.
578
+ */
579
+ if (current.metaError?.startsWith('body-too-long') === true && next.body.length <= LIMITS.body) {
580
+ next.metaError = undefined;
581
+ }
509
582
  if (patch?.title !== undefined)
510
583
  next.title = normalizeTitle(patch.title);
511
584
  if (patch?.tags !== undefined)
@@ -30,6 +30,18 @@ export interface HostConnection {
30
30
  /** The store operations the route dispatches onto. */
31
31
  export interface WallActions {
32
32
  list(includeArchived?: boolean, sort?: NoteSort): Note[];
33
+ /**
34
+ * The wall's real composition, counted over every stored note.
35
+ *
36
+ * Separate from {@link WallActions.list} on purpose: `list` returns only what
37
+ * the caller asked for, so a count derived from it describes the request
38
+ * rather than the wall.
39
+ */
40
+ counts(): {
41
+ total: number;
42
+ live: number;
43
+ archived: number;
44
+ };
33
45
  /** The Host's current change counter, for the Client's cheap poll. */
34
46
  revisionOf(): number;
35
47
  /** Absolute directory the notes live in. */
package/lib/transport.js CHANGED
@@ -131,6 +131,10 @@ async function dispatch(actions, request) {
131
131
  case 'list':
132
132
  return {
133
133
  notes: actions.list(request.includeArchived, request.sort),
134
+ // Counted by the Host over EVERY note, never derived from the filtered
135
+ // array above: the default request omits archived notes, so a count
136
+ // taken from `notes` would always report zero archived.
137
+ counts: actions.counts(),
134
138
  revision: actions.revisionOf(),
135
139
  notesDir: actions.notesDir,
136
140
  domain: { name: 'sticky-wall', version: 2 },
package/lib/types.d.ts CHANGED
@@ -89,15 +89,31 @@ export declare const WIDTH_PX: Readonly<Record<NoteWidth, number>>;
89
89
  * wasted a tall column of paper above and below the field while still letting a
90
90
  * wide card reach in from the side.
91
91
  *
92
- * The numbers are the shipped centrepiece at zoom 1 (560px wide, ~140px tall)
93
- * plus a margin, in world pixels. The Client re-derives a zoom-corrected version
94
- * of this rectangle from the rendered DOM before it asks the Host to tidy, so a
95
- * zoomed-out wall reserves proportionally more world space — see
96
- * `WallPage.centreReserve`.
92
+ * **These numbers are derived from the framing floor, not from zoom 1.** The
93
+ * centrepiece is a screen-space HUD: it keeps its painted size (a measured
94
+ * 560x167 block, so half-extents 280x84) at every camera zoom, which means the
95
+ * patch of WORLD it covers is `painted / zoom` and grows as the wall zooms out.
96
+ * A reserve sized for zoom 1 was therefore too small for every framed wall: at
97
+ * 75% the painted field alone needs 339 world px per side against a 330 reserve,
98
+ * so a tidied card grazed the field's edge — measured in the real UI as 1-2
99
+ * cards clipping the field by ~9x17px. That is why this is 605x200 and not
100
+ * 330x136.
101
+ *
102
+ * The value is the smallest one that still contains the HUD at the camera's
103
+ * framing floor (0.42, the lowest zoom `fitWall` will ever frame a wall at):
104
+ * `280 / 0.42 ≈ 667` is the strict bound, and 605 is the measured point at which
105
+ * a 100-card wall still frames with a hole of 508x168 screen px — exactly the
106
+ * painted field. Enlarging it further only buys empty paper in the middle and
107
+ * costs framing zoom (667 frames a 14-card wall at 56% instead of 60%), so the
108
+ * reserve is deliberately the tight bound rather than a comfortable one.
109
+ *
110
+ * The number cannot be derived per-wall from the live zoom without creating the
111
+ * feedback loop documented on `WallPage.centreReserve`, so it is a constant and
112
+ * the cost is accepted: a wall frames slightly lower than it otherwise would.
97
113
  */
98
114
  export declare const CENTRE_RESERVE: Readonly<{
99
- halfWidth: 330;
100
- halfHeight: 136;
115
+ halfWidth: 605;
116
+ halfHeight: 200;
101
117
  }>;
102
118
  /**
103
119
  * A clear rectangle around the wall's centrepiece, in WORLD pixels.
@@ -202,9 +218,33 @@ export interface Note {
202
218
  */
203
219
  extra?: Readonly<Record<string, string>> | undefined;
204
220
  }
221
+ /**
222
+ * How many notes the wall holds, independent of what the Client asked for.
223
+ *
224
+ * This exists because the Client cannot derive it. `list` only returns what the
225
+ * caller requested, and the default request excludes archived notes — so
226
+ * counting archived notes out of the returned array always yields zero on a
227
+ * normal wall. The Host is the only side that knows the real composition, so it
228
+ * states it explicitly instead of letting every caller guess.
229
+ */
230
+ export interface WallCounts {
231
+ /** Every stored note, archived ones included. */
232
+ total: number;
233
+ /** Notes that are not archived; the documented `maxNotes` cap applies here. */
234
+ live: number;
235
+ /** Notes the user archived, whether or not they are in `notes`. */
236
+ archived: number;
237
+ }
205
238
  /** The complete wall state a Client renders. */
206
239
  export interface WallSnapshot {
207
240
  notes: Note[];
241
+ /**
242
+ * The wall's real composition, counted by the Host over EVERY stored note.
243
+ *
244
+ * Deliberately not derived from `notes`: that array is a filtered projection,
245
+ * so a count taken from it describes the request, not the wall.
246
+ */
247
+ counts: WallCounts;
208
248
  /**
209
249
  * Monotonic change counter.
210
250
  *
package/lib/types.js CHANGED
@@ -97,13 +97,29 @@ export const WIDTH_PX = Object.freeze({
97
97
  * wasted a tall column of paper above and below the field while still letting a
98
98
  * wide card reach in from the side.
99
99
  *
100
- * The numbers are the shipped centrepiece at zoom 1 (560px wide, ~140px tall)
101
- * plus a margin, in world pixels. The Client re-derives a zoom-corrected version
102
- * of this rectangle from the rendered DOM before it asks the Host to tidy, so a
103
- * zoomed-out wall reserves proportionally more world space — see
104
- * `WallPage.centreReserve`.
100
+ * **These numbers are derived from the framing floor, not from zoom 1.** The
101
+ * centrepiece is a screen-space HUD: it keeps its painted size (a measured
102
+ * 560x167 block, so half-extents 280x84) at every camera zoom, which means the
103
+ * patch of WORLD it covers is `painted / zoom` and grows as the wall zooms out.
104
+ * A reserve sized for zoom 1 was therefore too small for every framed wall: at
105
+ * 75% the painted field alone needs 339 world px per side against a 330 reserve,
106
+ * so a tidied card grazed the field's edge — measured in the real UI as 1-2
107
+ * cards clipping the field by ~9x17px. That is why this is 605x200 and not
108
+ * 330x136.
109
+ *
110
+ * The value is the smallest one that still contains the HUD at the camera's
111
+ * framing floor (0.42, the lowest zoom `fitWall` will ever frame a wall at):
112
+ * `280 / 0.42 ≈ 667` is the strict bound, and 605 is the measured point at which
113
+ * a 100-card wall still frames with a hole of 508x168 screen px — exactly the
114
+ * painted field. Enlarging it further only buys empty paper in the middle and
115
+ * costs framing zoom (667 frames a 14-card wall at 56% instead of 60%), so the
116
+ * reserve is deliberately the tight bound rather than a comfortable one.
117
+ *
118
+ * The number cannot be derived per-wall from the live zoom without creating the
119
+ * feedback loop documented on `WallPage.centreReserve`, so it is a constant and
120
+ * the cost is accepted: a wall frames slightly lower than it otherwise would.
105
121
  */
106
- export const CENTRE_RESERVE = Object.freeze({ halfWidth: 330, halfHeight: 136 });
122
+ export const CENTRE_RESERVE = Object.freeze({ halfWidth: 605, halfHeight: 200 });
107
123
  /** Bounds of the free canvas: a note may sit anywhere inside this square. */
108
124
  export const LAYOUT_LIMITS = Object.freeze({
109
125
  /** Absolute value of x and y, in world pixels. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillre/dsh-plugin-sticky-wall",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "便签墙:DSH 侧栏的自由画布便签板,可拖动摆放、一键整理,正文按 Markdown 渲染",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",