mellos-mapping 0.20.0 → 0.20.2

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.
Files changed (43) hide show
  1. package/README.md +360 -63
  2. package/README.zh-CN.md +314 -54
  3. package/dist/hook-session-start.mjs +239 -0
  4. package/dist/mmap.mjs +338 -0
  5. package/dist/server.mjs +1614 -809
  6. package/dist/store-paths.mjs +107 -0
  7. package/dist/watch.mjs +1391 -760
  8. package/lib/domain/ops.d.ts +71 -12
  9. package/lib/domain/ops.js +145 -14
  10. package/lib/domain/types.d.ts +47 -6
  11. package/lib/domain/types.js +34 -3
  12. package/lib/render/canvas.d.ts +50 -0
  13. package/lib/render/canvas.js +210 -0
  14. package/lib/render/draw.d.ts +37 -0
  15. package/lib/render/draw.js +111 -0
  16. package/lib/render/layout.d.ts +89 -0
  17. package/lib/render/layout.js +200 -0
  18. package/lib/render/options.d.ts +39 -0
  19. package/lib/render/options.js +10 -0
  20. package/lib/render/render.d.ts +32 -46
  21. package/lib/render/render.js +58 -789
  22. package/lib/render/routing.d.ts +56 -0
  23. package/lib/render/routing.js +244 -0
  24. package/lib/render/skins.d.ts +54 -0
  25. package/lib/render/skins.js +99 -0
  26. package/lib/render/width.d.ts +24 -0
  27. package/lib/render/width.js +139 -0
  28. package/lib/render/zoom-geometry.d.ts +52 -0
  29. package/lib/render/zoom-geometry.js +56 -0
  30. package/lib/semantics/semantics.d.ts +53 -4
  31. package/lib/semantics/semantics.js +130 -6
  32. package/lib/semantics/vocabulary.d.ts +79 -0
  33. package/lib/semantics/vocabulary.js +112 -0
  34. package/lib/store/format.d.ts +17 -0
  35. package/lib/store/format.js +185 -66
  36. package/lib/store/store.d.ts +220 -20
  37. package/lib/store/store.js +491 -38
  38. package/package.json +12 -4
  39. package/scripts/codex-register.mjs +89 -20
  40. package/scripts/install-mmap-command.mjs +293 -0
  41. package/scripts/mmap.mjs +213 -0
  42. package/scripts/open-pane.mjs +115 -254
  43. package/scripts/pane-core.mjs +418 -0
@@ -0,0 +1,107 @@
1
+ // src/store/store.ts
2
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, join } from "node:path";
4
+
5
+ // src/domain/types.ts
6
+ var ok = (value) => ({ ok: true, value });
7
+ var err = (error) => ({ ok: false, error });
8
+ var ID_RULE = /^[a-z0-9][a-z0-9-]{0,63}$/;
9
+ var ID_RULE_TEXT = "lowercase letters, digits and dashes, starting with a letter or digit, 1-64 chars";
10
+ var RANK_MIN = 0;
11
+ var RANK_MAX = 99;
12
+ var RANK_RULE_TEXT = `an integer in ${RANK_MIN}..${RANK_MAX}, 0 = bottom / most primitive`;
13
+
14
+ // src/store/format.ts
15
+ function makePageId(raw) {
16
+ return ID_RULE.test(raw) ? ok(raw) : err({ kind: "invalid-id", raw, rule: ID_RULE_TEXT });
17
+ }
18
+
19
+ // src/store/store.ts
20
+ function isRecord(v) {
21
+ return typeof v === "object" && v !== null && !Array.isArray(v);
22
+ }
23
+ function stripBom(text) {
24
+ return text.charCodeAt(0) === 65279 ? text.slice(1) : text;
25
+ }
26
+ var STORE_DIR_NAME = ".mellos";
27
+ var STATE_FILE_RELATIVE_PATH = join(STORE_DIR_NAME, "map.json");
28
+ var PAGES_DIR_NAME = "pages";
29
+ var FOCUS_FILE_NAME = "focus";
30
+ function focusFilePath(defaultFile) {
31
+ return join(dirname(defaultFile), FOCUS_FILE_NAME);
32
+ }
33
+ var QUIT_FILE_NAME = "quit";
34
+ function quitFilePath(defaultFile) {
35
+ return join(dirname(defaultFile), QUIT_FILE_NAME);
36
+ }
37
+ var VIEWERS_DIR_NAME = "viewers";
38
+ var VIEWER_FILE_VERSION = 1;
39
+ var VIEWER_STALE_MS = 5e3;
40
+ var VIEWER_SWEEP_MS = 6e4;
41
+ function viewersDirPath(defaultFile) {
42
+ return join(dirname(defaultFile), VIEWERS_DIR_NAME);
43
+ }
44
+ function viewerPidOf(fileName) {
45
+ const m = /^(\d+)\.json$/.exec(fileName);
46
+ return m === null ? void 0 : Number(m[1]);
47
+ }
48
+ function parseViewerReport(raw) {
49
+ let parsed;
50
+ try {
51
+ parsed = JSON.parse(stripBom(raw));
52
+ } catch {
53
+ return void 0;
54
+ }
55
+ if (!isRecord(parsed)) return void 0;
56
+ if (parsed["version"] !== VIEWER_FILE_VERSION) return void 0;
57
+ const follow = parsed["follow"];
58
+ if (typeof follow !== "boolean") return void 0;
59
+ const page = parsed["page"];
60
+ if (page === null || page === void 0) return { page: void 0, follow };
61
+ if (typeof page !== "string") return void 0;
62
+ const id = makePageId(page);
63
+ return id.ok ? { page: id.value, follow } : void 0;
64
+ }
65
+ function readLiveViewers(defaultFile, nowMs) {
66
+ const dir = viewersDirPath(defaultFile);
67
+ let names;
68
+ try {
69
+ names = readdirSync(dir);
70
+ } catch {
71
+ return [];
72
+ }
73
+ const live = [];
74
+ for (const name of names) {
75
+ const pid = viewerPidOf(name);
76
+ if (pid === void 0) continue;
77
+ const path = join(dir, name);
78
+ let raw;
79
+ let ageMs;
80
+ try {
81
+ ageMs = Math.max(0, nowMs - statSync(path).mtimeMs);
82
+ if (ageMs > VIEWER_SWEEP_MS) {
83
+ rmSync(path, { force: true });
84
+ continue;
85
+ }
86
+ if (ageMs > VIEWER_STALE_MS) continue;
87
+ raw = readFileSync(path, "utf8");
88
+ } catch {
89
+ continue;
90
+ }
91
+ const report = parseViewerReport(raw);
92
+ if (report !== void 0) live.push({ ...report, pid, ageMs });
93
+ }
94
+ return live.sort((a, b) => a.ageMs - b.ageMs || a.pid - b.pid);
95
+ }
96
+ var LEGACY_STATE_FILE_RELATIVE_PATH = join(".claude", "mellos-mapping.json");
97
+ export {
98
+ FOCUS_FILE_NAME,
99
+ ID_RULE,
100
+ PAGES_DIR_NAME,
101
+ QUIT_FILE_NAME,
102
+ STATE_FILE_RELATIVE_PATH,
103
+ VIEWERS_DIR_NAME,
104
+ focusFilePath,
105
+ quitFilePath,
106
+ readLiveViewers
107
+ };