dreamcontext 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/LICENSE +201 -21
  2. package/NOTICE +7 -0
  3. package/README.md +77 -12
  4. package/agents/dreamcontext-explore.md +1 -1
  5. package/agents/sleep-product.md +29 -8
  6. package/agents/sleep-tasks.md +44 -9
  7. package/dist/agents/dreamcontext-explore.md +1 -1
  8. package/dist/agents/sleep-product.md +29 -8
  9. package/dist/agents/sleep-tasks.md +44 -9
  10. package/dist/dashboard/assets/{BrainCanvas3D-1HMiA14F.js → BrainCanvas3D-LLqVeXtb.js} +1 -1
  11. package/dist/dashboard/assets/{_baseUniq-C7pfRmXz.js → _baseUniq-DW0uA0ty.js} +1 -1
  12. package/dist/dashboard/assets/{arc-B5x_GF9Q.js → arc-fVUGtlbL.js} +1 -1
  13. package/dist/dashboard/assets/{architectureDiagram-Q4EWVU46-CWmjaqno.js → architectureDiagram-Q4EWVU46-Dz2PKBsS.js} +1 -1
  14. package/dist/dashboard/assets/{blockDiagram-DXYQGD6D-B7SyUIdV.js → blockDiagram-DXYQGD6D-ByWKxzhL.js} +1 -1
  15. package/dist/dashboard/assets/{c4Diagram-AHTNJAMY-OeJBWXHU.js → c4Diagram-AHTNJAMY-dpHsVM3D.js} +1 -1
  16. package/dist/dashboard/assets/channel-zrLwggBX.js +1 -0
  17. package/dist/dashboard/assets/{chunk-4BX2VUAB-2Oop1B0M.js → chunk-4BX2VUAB-HEXb6Yg5.js} +1 -1
  18. package/dist/dashboard/assets/{chunk-4TB4RGXK-Bh7qSu_X.js → chunk-4TB4RGXK-DeVy5g6H.js} +1 -1
  19. package/dist/dashboard/assets/{chunk-55IACEB6-gNeHRO_i.js → chunk-55IACEB6-DGy3ZgDZ.js} +1 -1
  20. package/dist/dashboard/assets/{chunk-EDXVE4YY-BRniAH53.js → chunk-EDXVE4YY-CYJehjz4.js} +1 -1
  21. package/dist/dashboard/assets/{chunk-FMBD7UC4-B5r8U2gJ.js → chunk-FMBD7UC4-DKTOmvgZ.js} +1 -1
  22. package/dist/dashboard/assets/{chunk-OYMX7WX6-Dd1c17fm.js → chunk-OYMX7WX6-mmtWyiDA.js} +1 -1
  23. package/dist/dashboard/assets/{chunk-QZHKN3VN-BIw-OdTn.js → chunk-QZHKN3VN-DSdV0iwY.js} +1 -1
  24. package/dist/dashboard/assets/{chunk-YZCP3GAM-Dl9MlwCW.js → chunk-YZCP3GAM-DbY-KoDn.js} +1 -1
  25. package/dist/dashboard/assets/classDiagram-6PBFFD2Q-BvejNiwH.js +1 -0
  26. package/dist/dashboard/assets/classDiagram-v2-HSJHXN6E-BvejNiwH.js +1 -0
  27. package/dist/dashboard/assets/clone-BFVdml6g.js +1 -0
  28. package/dist/dashboard/assets/{cose-bilkent-S5V4N54A-DlrROH5K.js → cose-bilkent-S5V4N54A-p0t1DY88.js} +1 -1
  29. package/dist/dashboard/assets/{dagre-KV5264BT-B0GpPXKL.js → dagre-KV5264BT-DYE0WzHM.js} +1 -1
  30. package/dist/dashboard/assets/{diagram-5BDNPKRD-BBYcDW2Z.js → diagram-5BDNPKRD-D9EiQCOP.js} +1 -1
  31. package/dist/dashboard/assets/{diagram-G4DWMVQ6-BxHxugdp.js → diagram-G4DWMVQ6-poDXSAfu.js} +1 -1
  32. package/dist/dashboard/assets/{diagram-MMDJMWI5-C9Jc19Wo.js → diagram-MMDJMWI5-CHZ7wgN1.js} +1 -1
  33. package/dist/dashboard/assets/{diagram-TYMM5635-Vmo5GAAU.js → diagram-TYMM5635-DVk6fYG7.js} +1 -1
  34. package/dist/dashboard/assets/{erDiagram-SMLLAGMA-pskr9x-V.js → erDiagram-SMLLAGMA-D2sqkGin.js} +1 -1
  35. package/dist/dashboard/assets/{flowDiagram-DWJPFMVM-B1D7Ky0W.js → flowDiagram-DWJPFMVM-DrMlKBYA.js} +1 -1
  36. package/dist/dashboard/assets/{ganttDiagram-T4ZO3ILL-BVJZZV1M.js → ganttDiagram-T4ZO3ILL-Cf4FbEFp.js} +1 -1
  37. package/dist/dashboard/assets/{gitGraphDiagram-UUTBAWPF-BiOGN6We.js → gitGraphDiagram-UUTBAWPF-BsbOq1C9.js} +1 -1
  38. package/dist/dashboard/assets/{graph-D58deEXr.js → graph-CUxxgCtS.js} +1 -1
  39. package/dist/dashboard/assets/index-CqSkXBSu.css +1 -0
  40. package/dist/dashboard/assets/index-flRpQtDj.js +476 -0
  41. package/dist/dashboard/assets/{infoDiagram-42DDH7IO-DgJYg1X1.js → infoDiagram-42DDH7IO-DTkMnZiD.js} +1 -1
  42. package/dist/dashboard/assets/{ishikawaDiagram-UXIWVN3A-arJgr-8P.js → ishikawaDiagram-UXIWVN3A-CahQ348K.js} +1 -1
  43. package/dist/dashboard/assets/{journeyDiagram-VCZTEJTY-B3DCvb8p.js → journeyDiagram-VCZTEJTY-BDY2Nslc.js} +1 -1
  44. package/dist/dashboard/assets/{kanban-definition-6JOO6SKY-B--dN6Ma.js → kanban-definition-6JOO6SKY-CgrwoTjI.js} +1 -1
  45. package/dist/dashboard/assets/{layout-z2qEbZWC.js → layout-IaUxkFkm.js} +1 -1
  46. package/dist/dashboard/assets/{linear-BQu1dwrM.js → linear-shc0iNFn.js} +1 -1
  47. package/dist/dashboard/assets/{min-DkF5b2sh.js → min-BIL7YgTN.js} +1 -1
  48. package/dist/dashboard/assets/{mindmap-definition-QFDTVHPH-Bw04koyq.js → mindmap-definition-QFDTVHPH-GmO0JRtA.js} +1 -1
  49. package/dist/dashboard/assets/{pieDiagram-DEJITSTG-vNqz64o8.js → pieDiagram-DEJITSTG-Bfm_toYA.js} +1 -1
  50. package/dist/dashboard/assets/{quadrantDiagram-34T5L4WZ-TuVP5Gi6.js → quadrantDiagram-34T5L4WZ-DIjTM3lm.js} +1 -1
  51. package/dist/dashboard/assets/{requirementDiagram-MS252O5E-D3mS8_ke.js → requirementDiagram-MS252O5E-B9AEoGYh.js} +1 -1
  52. package/dist/dashboard/assets/{sankeyDiagram-XADWPNL6-BmVRers6.js → sankeyDiagram-XADWPNL6-C_O5XLXm.js} +1 -1
  53. package/dist/dashboard/assets/{sequenceDiagram-FGHM5R23-CTYCgk5P.js → sequenceDiagram-FGHM5R23-CHSxSvmJ.js} +1 -1
  54. package/dist/dashboard/assets/{stateDiagram-FHFEXIEX-DNbP2aCg.js → stateDiagram-FHFEXIEX-B0URrhHw.js} +1 -1
  55. package/dist/dashboard/assets/stateDiagram-v2-QKLJ7IA2-FdAb9MBo.js +1 -0
  56. package/dist/dashboard/assets/{timeline-definition-GMOUNBTQ-DKHJd4z8.js → timeline-definition-GMOUNBTQ-CycU2gVC.js} +1 -1
  57. package/dist/dashboard/assets/{vennDiagram-DHZGUBPP-ChotNMNq.js → vennDiagram-DHZGUBPP-DcU2536G.js} +1 -1
  58. package/dist/dashboard/assets/{wardley-RL74JXVD-Dmo2_ksP.js → wardley-RL74JXVD-BWqqaX3S.js} +1 -1
  59. package/dist/dashboard/assets/{wardleyDiagram-NUSXRM2D-Z6Wbiv2H.js → wardleyDiagram-NUSXRM2D-CUnIHJgd.js} +1 -1
  60. package/dist/dashboard/assets/{xychartDiagram-5P7HB3ND-BJa0AHtN.js → xychartDiagram-5P7HB3ND-b9fcOYTj.js} +1 -1
  61. package/dist/dashboard/index.html +2 -2
  62. package/dist/dashboard/media/README.md +29 -0
  63. package/dist/dashboard/media/brain-hero.png +0 -0
  64. package/dist/dashboard/media/brain.mp4 +0 -0
  65. package/dist/dashboard/media/brain.webm +0 -0
  66. package/dist/dashboard/media/shot-disabled.png +0 -0
  67. package/dist/dashboard/media/shot-enabled.png +0 -0
  68. package/dist/index.js +3408 -2051
  69. package/dist/skill-packs/catalog.json +44 -0
  70. package/dist/skill-packs/excalidraw/SKILL.md +123 -0
  71. package/dist/skill-packs/excalidraw/examples/hello.spec.json +14 -0
  72. package/dist/skill-packs/excalidraw/examples/sample.png +0 -0
  73. package/dist/skill-packs/excalidraw/examples/style_board.js +31 -0
  74. package/dist/skill-packs/excalidraw/package.json +5 -0
  75. package/dist/skill-packs/excalidraw/reference/format.md +93 -0
  76. package/dist/skill-packs/excalidraw/scripts/build_excalidraw.js +357 -0
  77. package/dist/skill-packs/excalidraw/scripts/lib/fractional-indexing.LICENSE +121 -0
  78. package/dist/skill-packs/excalidraw/scripts/lib/fractional-indexing.js +311 -0
  79. package/dist/skill-packs/excalidraw/scripts/lib/imagesize.js +65 -0
  80. package/dist/skill-packs/excalidraw/scripts/lib/style.js +130 -0
  81. package/dist/skill-packs/video-watching/SKILL.md +151 -0
  82. package/dist/skill-packs/video-watching/scripts/build_frame_index.py +95 -0
  83. package/dist/skill-packs/video-watching/scripts/gap_fill.py +45 -0
  84. package/dist/skill-packs/video-watching/scripts/transcribe.sh +136 -0
  85. package/package.json +4 -2
  86. package/skill/SKILL.md +5 -0
  87. package/skill-packs/catalog.json +44 -0
  88. package/skill-packs/excalidraw/SKILL.md +123 -0
  89. package/skill-packs/excalidraw/examples/hello.spec.json +14 -0
  90. package/skill-packs/excalidraw/examples/sample.png +0 -0
  91. package/skill-packs/excalidraw/examples/style_board.js +31 -0
  92. package/skill-packs/excalidraw/package.json +5 -0
  93. package/skill-packs/excalidraw/reference/format.md +93 -0
  94. package/skill-packs/excalidraw/scripts/build_excalidraw.js +357 -0
  95. package/skill-packs/excalidraw/scripts/lib/fractional-indexing.LICENSE +121 -0
  96. package/skill-packs/excalidraw/scripts/lib/fractional-indexing.js +311 -0
  97. package/skill-packs/excalidraw/scripts/lib/imagesize.js +65 -0
  98. package/skill-packs/excalidraw/scripts/lib/style.js +130 -0
  99. package/skill-packs/video-watching/SKILL.md +151 -0
  100. package/skill-packs/video-watching/scripts/build_frame_index.py +95 -0
  101. package/skill-packs/video-watching/scripts/gap_fill.py +45 -0
  102. package/skill-packs/video-watching/scripts/transcribe.sh +136 -0
  103. package/dist/dashboard/assets/channel-CbuTKKsM.js +0 -1
  104. package/dist/dashboard/assets/classDiagram-6PBFFD2Q-HXl3A_sM.js +0 -1
  105. package/dist/dashboard/assets/classDiagram-v2-HSJHXN6E-HXl3A_sM.js +0 -1
  106. package/dist/dashboard/assets/clone-NKHOtdi8.js +0 -1
  107. package/dist/dashboard/assets/index-DK_2-eWY.css +0 -1
  108. package/dist/dashboard/assets/index-Ds-JXWtr.js +0 -476
  109. package/dist/dashboard/assets/stateDiagram-v2-QKLJ7IA2-CfN6kjo8.js +0 -1
@@ -0,0 +1,93 @@
1
+ # Obsidian `.excalidraw.md` format (reverse-engineered from this vault)
2
+
3
+ Source files inspected: `lina/excalidraw/Lina Web Funnel.excalidraw.md` (decompressed),
4
+ `Lina Web Funnel Benchmark.excalidraw.md`. Plugin: `zsviczian/obsidian-excalidraw-plugin`.
5
+
6
+ ## File anatomy
7
+ ```
8
+ ---
9
+
10
+ excalidraw-plugin: parsed
11
+ tags: [excalidraw]
12
+
13
+ ---
14
+ ==⚠ Switch to EXCALIDRAW VIEW … ⚠== …saving hint…
15
+
16
+
17
+ # Excalidraw Data
18
+
19
+ ## Text Elements
20
+ <text content> ^<elementId> ← one block per text element, blank line between
21
+
22
+ ## Embedded Files
23
+ <sha1>: [[image filename.png]] ← maps fileId → vault image, blank line between
24
+
25
+ %%
26
+ ## Drawing
27
+ ```json
28
+ { "type":"excalidraw", "version":2, "source":"…", "elements":[…], "appState":{…}, "files":{} }
29
+ ```
30
+ %%
31
+ ```
32
+ - `## Drawing` may be ` ```compressed-json ` (LZString.compressToBase64) **or** ` ```json `
33
+ (uncompressed). The plugin reads both. We emit uncompressed JSON — readable, no deps.
34
+ - The whole drawing block is wrapped in `%% … %%` (Obsidian comment) so it hides in reading view.
35
+ - `## Text Elements` and `## Embedded Files` sit **before** the `%%`.
36
+
37
+ ## Image embedding (the key mechanism)
38
+ - An image element is `{"type":"image", "fileId":"<sha1>", …, "scale":[1,1], "status":"pending", "crop":null}`.
39
+ - `fileId` is the **sha1 of the image file's bytes**.
40
+ - The `## Embedded Files` line `<sha1>: [[file.png]]` is what the plugin uses to load the picture
41
+ from the vault. **The scene `files` object can be empty (`{}`)** — no base64 dataURL required.
42
+ - `crop` is optional (only when the user cropped). `null` shows the whole image.
43
+
44
+ ## Ground-truth image element (decompressed from the vault)
45
+ ```json
46
+ {
47
+ "id":"GtJwnnEj","type":"image","x":-147.3,"y":-290.5,"width":118.8,"height":469,
48
+ "angle":0,"strokeColor":"transparent","backgroundColor":"transparent","fillStyle":"solid",
49
+ "strokeWidth":2,"strokeStyle":"solid","roughness":1,"opacity":100,"groupIds":[],"frameId":null,
50
+ "index":"a0","roundness":null,"seed":2054545386,"version":188,"versionNonce":1261541290,
51
+ "isDeleted":false,"boundElements":[],"updated":1779266944741,"link":null,"locked":false,
52
+ "status":"pending","fileId":"3eaa974da433f70ba06cb3fb2587b486d6143d32","scale":[1,1],
53
+ "crop":{ "x":713.7,"y":0,"width":871.3,"height":3440,"naturalWidth":2283,"naturalHeight":3440 },
54
+ "hasTextLink":false
55
+ }
56
+ ```
57
+ …and its `## Embedded Files` line:
58
+ ```
59
+ 3eaa974da433f70ba06cb3fb2587b486d6143d32: [[Pasted Image 20260515130812_941.png]]
60
+ ```
61
+
62
+ ## z-order: fractional indices
63
+ - Every element has a string `index` (`"a0"`, `"a1"`, …) — fractional indexing, compared
64
+ lexicographically. We generate them with the vendored `fractional-indexing` lib
65
+ (`generateNKeysBetween(null,null,N)`), which matches the vault output exactly.
66
+ - Excalidraw's `restore()` (run by the plugin on load) repairs invalid/missing indices, but we emit
67
+ valid ascending ones anyway.
68
+
69
+ ## appState
70
+ Minimal is fine: `{"gridSize":null,"gridStep":5,"gridModeEnabled":false,"viewBackgroundColor":"#ffffff"}`.
71
+
72
+ ## House style (measured from MemoryOS High Level / Personalization Module / Research)
73
+ The vault's presentation boards share one fingerprint — `scripts/lib/style.js` encodes it:
74
+ - **Font:** Excalifont, `fontFamily: 5`, for ~100% of text. Sizes form a scale: ~16 labels, ~20 body,
75
+ ~28 sub-headers, ~44–50 section titles (scaled up on large zoomed-out canvases).
76
+ - **Fills:** `fillStyle: "solid"` exclusively (never hachure). **Every rectangle is rounded.**
77
+ - **Ink:** `strokeColor: "#1e1e1e"`, `strokeWidth: 2` dominant (1 for fine/secondary).
78
+ - **Semantic palette** (Excalidraw native swatches): green `#b2f2bb`/`#2f9e44` (benefit/go),
79
+ red `#ffc9c9`/`#e03131` (pain/risk), blue `#a5d8ff`/`#1971c2` (system/flow), purple `#d0bfff`/`#6741d9`
80
+ (core service), yellow `#ffec99`/`#f08c00` (processing), mint `#96f2d7`/`#0c8599` (result),
81
+ pale variants `#ebfbee`/`#e7f5ff`/`#f3f0ff` for backdrops.
82
+ - **Patterns:** rounded-card (rect + centered label, grouped) · color nodes by role · ellipse = actor,
83
+ diamond = decision, container-rect groups sub-states · arrows almost always single end-arrowhead,
84
+ labeled inline ("req", "msg+ctx") · side-annotation arrows to spec notes · big plain section titles
85
+ ("Configuration", "Flow") · benefit/risk **card columns** · hub-and-spoke concept maps · bulleted
86
+ spec lists as one text block. Heavy use of embedded screenshots in research murals (huge canvases,
87
+ 29+ groups) — exactly the funnel-map use case.
88
+
89
+ ## Tooling note
90
+ The `yctimlin/mcp_excalidraw` MCP server was evaluated and rejected for this vault: it needs a
91
+ running localhost canvas server and exports excalidraw.com JSON / PNG / share-URLs — it does **not**
92
+ write Obsidian `.excalidraw.md` with the `## Embedded Files` wikilink section. Hand-generating the
93
+ file (this skill) is the correct, dependency-light path for bulk-embedding local screenshots.
@@ -0,0 +1,357 @@
1
+ #!/usr/bin/env node
2
+ // build_excalidraw.js — generate an Obsidian-compatible .excalidraw.md board from a high-level spec.
3
+ //
4
+ // Format reverse-engineered from the user's own vault (see ../reference/format.md):
5
+ // - frontmatter `excalidraw-plugin: parsed`
6
+ // - `## Text Elements` : "<text> ^<id>" per text element
7
+ // - `## Embedded Files` : "<sha1>: [[image.png]]" (plugin resolves image from vault by this map)
8
+ // - `%% ## Drawing ```json <scene> ``` %%` (uncompressed JSON; plugin reads it fine)
9
+ // Images need NO base64 — the fileId (sha1 of the file) + the Embedded Files wikilink is enough.
10
+ //
11
+ // Usage (CLI): node build_excalidraw.js <spec.json> [--out <path.excalidraw.md>]
12
+ // Usage (API): const { buildExcalidraw, lane, grid } = require('./build_excalidraw.js')
13
+ //
14
+ // Spec shape:
15
+ // {
16
+ // "out": "/abs/Board.excalidraw.md", // or pass --out
17
+ // "vaultRoot": "/abs/vault", // auto-detected (walks up for .obsidian) if omitted
18
+ // "attachDir": "Attachments", // where external images get copied (relative to board dir)
19
+ // "wikilinkMode": "basename" | "path", // how Embedded Files links are written (default basename)
20
+ // "background": "#ffffff",
21
+ // "elements": [ <ElementSpec>, ... ]
22
+ // }
23
+ // ElementSpec.type: text | image | rectangle | ellipse | diamond | line | arrow | frame
24
+ const fs = require('fs');
25
+ const path = require('path');
26
+ const crypto = require('crypto');
27
+ const { generateNKeysBetween } = require('./lib/fractional-indexing.js');
28
+ const { imageSize } = require('./lib/imagesize.js');
29
+
30
+ // ---------- deterministic PRNG (stable seeds => clean git diffs) ----------
31
+ function mulberry32(seed) {
32
+ let a = seed >>> 0;
33
+ return function () {
34
+ a |= 0; a = (a + 0x6d2b79f5) | 0;
35
+ let t = Math.imul(a ^ (a >>> 15), 1 | a);
36
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
37
+ return ((t ^ (t >>> 14)) >>> 0);
38
+ };
39
+ }
40
+ function strHash(s) { let h = 2166136261; for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619); } return h >>> 0; }
41
+ const B62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
42
+ function idFrom(rng) { let s = ''; for (let i = 0; i < 8; i++) s += B62[rng() % 62]; return s; }
43
+
44
+ const FIXED_UPDATED = 1735689600000; // stable timestamp; visual no-op
45
+
46
+ // ---------- vault helpers ----------
47
+ function findVaultRoot(startDir) {
48
+ let d = startDir;
49
+ for (let i = 0; i < 40; i++) {
50
+ if (fs.existsSync(path.join(d, '.obsidian'))) return d;
51
+ const p = path.dirname(d);
52
+ if (p === d) break; d = p;
53
+ }
54
+ return null;
55
+ }
56
+
57
+ // ---------- text sizing ----------
58
+ // When a fixedWidth is given the text element is treated as WRAPPING (autoResize off downstream),
59
+ // so height must reflect word-wrapped line count — otherwise long captions render as one wide line
60
+ // and overlap their neighbours. Honors explicit \n and greedily wraps each logical line to width.
61
+ function sizeText(text, fontSize, fixedWidth) {
62
+ const rawLines = String(text).split('\n');
63
+ if (fixedWidth != null) {
64
+ const charW = fontSize * 0.52; // approx Excalifont glyph advance
65
+ const perLine = Math.max(1, Math.floor(fixedWidth / charW));
66
+ let totalLines = 0;
67
+ for (const ln of rawLines) {
68
+ const words = ln.split(/\s+/).filter(Boolean);
69
+ if (!words.length) { totalLines += 1; continue; }
70
+ let cur = 0, lc = 1;
71
+ for (const w of words) {
72
+ const add = (cur ? 1 : 0) + w.length;
73
+ if (cur + add > perLine && cur > 0) { lc++; cur = w.length; }
74
+ else cur += add;
75
+ }
76
+ totalLines += lc;
77
+ }
78
+ return { width: fixedWidth, height: Math.max(Math.round(fontSize * 1.25), Math.round(totalLines * fontSize * 1.25)) };
79
+ }
80
+ const maxLen = rawLines.reduce((m, l) => Math.max(m, l.length), 0);
81
+ return { width: Math.max(10, Math.round(maxLen * fontSize * 0.6)), height: Math.round(rawLines.length * fontSize * 1.25) };
82
+ }
83
+
84
+ // ---------- element factory ----------
85
+ function baseEl(rng, type, x, y, w, h, overrides) {
86
+ return Object.assign({
87
+ id: idFrom(rng),
88
+ type, x, y, width: w, height: h,
89
+ angle: 0,
90
+ strokeColor: '#1e1e1e',
91
+ backgroundColor: 'transparent',
92
+ fillStyle: 'solid',
93
+ strokeWidth: 2,
94
+ strokeStyle: 'solid',
95
+ roughness: 1,
96
+ opacity: 100,
97
+ groupIds: [],
98
+ frameId: null,
99
+ index: 'a0',
100
+ roundness: null,
101
+ seed: rng() >>> 0,
102
+ version: 1,
103
+ versionNonce: rng() >>> 0,
104
+ isDeleted: false,
105
+ boundElements: [],
106
+ updated: FIXED_UPDATED,
107
+ link: null,
108
+ locked: false,
109
+ }, overrides || {});
110
+ }
111
+
112
+ // ---------- main build ----------
113
+ function buildExcalidraw(spec) {
114
+ const outPath = spec.out;
115
+ if (!outPath) throw new Error('spec.out (output .excalidraw.md path) is required');
116
+ const boardDir = path.dirname(path.resolve(outPath));
117
+ const vaultRoot = spec.vaultRoot || findVaultRoot(boardDir) || boardDir;
118
+ const attachDir = spec.attachDir || 'Attachments';
119
+ const wikilinkMode = spec.wikilinkMode || 'basename';
120
+ const background = spec.background || '#ffffff';
121
+
122
+ const rng = mulberry32(strHash(path.resolve(outPath)));
123
+ const elements = [];
124
+ const textEntries = []; // {text, id}
125
+ const embedded = new Map(); // sha1 -> linkName
126
+ const usedNames = new Map(); // linkName -> sha1 (collision guard)
127
+
128
+ function placeImage(srcPath) {
129
+ const abs = path.resolve(srcPath);
130
+ if (!fs.existsSync(abs)) throw new Error('image not found: ' + abs);
131
+ const bytes = fs.readFileSync(abs);
132
+ const sha = crypto.createHash('sha1').update(bytes).digest('hex');
133
+ const dims = imageSize(abs);
134
+ if (embedded.has(sha)) return { sha, dims, link: embedded.get(sha) };
135
+
136
+ // ensure the image is inside the vault so the plugin can resolve it
137
+ let insideVault = abs.startsWith(path.resolve(vaultRoot) + path.sep);
138
+ let finalAbs = abs;
139
+ if (!insideVault) {
140
+ const destDir = path.join(boardDir, attachDir);
141
+ fs.mkdirSync(destDir, { recursive: true });
142
+ finalAbs = path.join(destDir, path.basename(abs));
143
+ fs.copyFileSync(abs, finalAbs);
144
+ }
145
+ let link;
146
+ if (wikilinkMode === 'path') {
147
+ link = path.relative(vaultRoot, finalAbs).split(path.sep).join('/');
148
+ } else {
149
+ link = path.basename(finalAbs);
150
+ // disambiguate same-basename/different-content within this board
151
+ if (usedNames.has(link) && usedNames.get(link) !== sha) {
152
+ const ext = path.extname(link); const stem = link.slice(0, -ext.length || undefined);
153
+ link = `${stem}-${sha.slice(0, 6)}${ext}`;
154
+ }
155
+ }
156
+ usedNames.set(link, sha);
157
+ embedded.set(sha, link);
158
+ return { sha, dims, link };
159
+ }
160
+
161
+ for (const e of (spec.elements || [])) {
162
+ const type = e.type;
163
+ if (type === 'text') {
164
+ const fontSize = e.fontSize || 20;
165
+ const { width, height } = sizeText(e.text, fontSize, e.width);
166
+ const el = baseEl(rng, 'text', e.x || 0, e.y || 0, width, height, {
167
+ strokeColor: e.color || '#1e1e1e',
168
+ text: String(e.text),
169
+ rawText: String(e.text),
170
+ originalText: String(e.text),
171
+ fontSize,
172
+ fontFamily: e.fontFamily || 5,
173
+ textAlign: e.align || 'left',
174
+ verticalAlign: e.verticalAlign || 'top',
175
+ containerId: null,
176
+ lineHeight: 1.25,
177
+ // width given ⇒ wrap to it (autoResize off); width omitted ⇒ size to content (single line)
178
+ autoResize: e.width == null,
179
+ backgroundColor: 'transparent',
180
+ });
181
+ elements.push(el);
182
+ textEntries.push({ text: el.text, id: el.id });
183
+ } else if (type === 'image') {
184
+ const { sha, dims, link } = placeImage(e.path);
185
+ let w = e.width, h = e.height;
186
+ if (w && !h) h = Math.round(w * dims.height / dims.width);
187
+ else if (h && !w) w = Math.round(h * dims.width / dims.height);
188
+ else if (!w && !h) { w = dims.width; h = dims.height; }
189
+ const el = baseEl(rng, 'image', e.x || 0, e.y || 0, w, h, {
190
+ strokeColor: 'transparent',
191
+ fileId: sha,
192
+ scale: [1, 1],
193
+ status: 'pending',
194
+ crop: null,
195
+ });
196
+ elements.push(el);
197
+ } else if (type === 'rectangle' || type === 'ellipse' || type === 'diamond') {
198
+ const el = baseEl(rng, type, e.x || 0, e.y || 0, e.width || 100, e.height || 100, {
199
+ strokeColor: e.strokeColor || '#1e1e1e',
200
+ backgroundColor: e.backgroundColor || 'transparent',
201
+ fillStyle: e.fillStyle || 'solid',
202
+ strokeWidth: e.strokeWidth || 2,
203
+ strokeStyle: e.strokeStyle || 'solid',
204
+ roundness: e.roundness ? { type: 3 } : null,
205
+ });
206
+ elements.push(el);
207
+ } else if (type === 'line' || type === 'arrow') {
208
+ const pts = (e.points && e.points.length ? e.points : [[0, 0], [100, 0]]);
209
+ const xs = pts.map((p) => p[0]); const ys = pts.map((p) => p[1]);
210
+ const minX = Math.min(...xs); const minY = Math.min(...ys);
211
+ const norm = pts.map((p) => [p[0] - minX, p[1] - minY]);
212
+ const w = Math.max(...xs) - minX; const h = Math.max(...ys) - minY;
213
+ const el = baseEl(rng, type, (e.x || 0) + minX, (e.y || 0) + minY, w, h, {
214
+ strokeColor: e.strokeColor || '#1e1e1e',
215
+ strokeWidth: e.strokeWidth || 2,
216
+ strokeStyle: e.strokeStyle || 'solid',
217
+ points: norm,
218
+ lastCommittedPoint: null,
219
+ startBinding: null,
220
+ endBinding: null,
221
+ startArrowhead: e.startArrow || null,
222
+ endArrowhead: type === 'arrow' ? (e.endArrow || 'arrow') : (e.endArrow || null),
223
+ });
224
+ elements.push(el);
225
+ } else if (type === 'frame') {
226
+ const el = baseEl(rng, 'frame', e.x || 0, e.y || 0, e.width || 600, e.height || 400, {
227
+ strokeColor: '#bbb', backgroundColor: 'transparent', name: e.name || 'Frame', roundness: null,
228
+ });
229
+ elements.push(el);
230
+ } else {
231
+ throw new Error('unknown element type: ' + type);
232
+ }
233
+ }
234
+
235
+ // group support: specs sharing a `group` key move together in Excalidraw
236
+ const groupMap = new Map();
237
+ const gidFor = (key) => { if (!groupMap.has(key)) groupMap.set(key, idFrom(rng) + idFrom(rng)); return groupMap.get(key); };
238
+ (spec.elements || []).forEach((e, i) => { if (e.group != null && elements[i]) elements[i].groupIds = [gidFor(String(e.group))]; });
239
+
240
+ // assign canonical fractional indices in array order (z-order)
241
+ const keys = generateNKeysBetween(null, null, elements.length);
242
+ elements.forEach((el, i) => { el.index = keys[i]; });
243
+
244
+ const scene = {
245
+ type: 'excalidraw',
246
+ version: 2,
247
+ source: 'https://github.com/zsviczian/obsidian-excalidraw-plugin',
248
+ elements,
249
+ appState: { gridSize: null, gridStep: 5, gridModeEnabled: false, viewBackgroundColor: background },
250
+ files: {},
251
+ };
252
+
253
+ // ---------- assemble markdown ----------
254
+ const L = [];
255
+ L.push('---', '', 'excalidraw-plugin: parsed', 'tags: [excalidraw]', '', '---');
256
+ L.push("==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠== You can decompress Drawing data with the command palette: 'Decompress current Excalidraw file'. For more info check in plugin settings under 'Saving'");
257
+ L.push('', '', '# Excalidraw Data', '');
258
+ L.push('## Text Elements');
259
+ for (const t of textEntries) L.push(`${t.text} ^${t.id}`, '');
260
+ L.push('## Embedded Files');
261
+ for (const [sha, link] of embedded) L.push(`${sha}: [[${link}]]`, '');
262
+ L.push('%%');
263
+ L.push('## Drawing');
264
+ L.push('```json');
265
+ L.push(JSON.stringify(scene, null, '\t'));
266
+ L.push('```');
267
+ L.push('%%');
268
+ const md = L.join('\n') + '\n';
269
+
270
+ fs.mkdirSync(boardDir, { recursive: true });
271
+ fs.writeFileSync(outPath, md, 'utf8');
272
+
273
+ return { outPath, elements: elements.length, images: embedded.size, texts: textEntries.length, vaultRoot };
274
+ }
275
+
276
+ // ---------- layout helpers (JS API) ----------
277
+ // Real on-board thumbnail height from the image file, so captions hug the image and rows never
278
+ // gap (short image) or overlap (tall image). Falls back to a 1.6 aspect if the file is unreadable.
279
+ function thumbHeight(p, thumbW) {
280
+ try { const d = imageSize(p); if (d && d.width) return Math.max(1, Math.round(thumbW * d.height / d.width)); } catch (e) {}
281
+ return Math.round(thumbW * 1.6);
282
+ }
283
+
284
+ // A horizontal lane: optional title, then a row of images left->right with each caption hugging
285
+ // its own image's bottom (wraps to thumbW). Returns ElementSpec[] (spread with ...) and also carries
286
+ // `.width` / `.height` / `.nextY` so lanes/sections stack cleanly without manual height math.
287
+ function lane(opts) {
288
+ const { title, images = [], x = 0, y = 0, thumbW = 220, gap = 40, captionSize = 14, captionGap = 8,
289
+ titleSize = 28, titleColor = '#1e1e1e', captionColor = '#555', laneGap = 48 } = opts;
290
+ const els = [];
291
+ let cy = y, titleH = 0;
292
+ if (title) {
293
+ els.push({ type: 'text', x, y: cy, text: title, fontSize: titleSize, color: titleColor, width: Math.max(300, String(title).length * titleSize * 0.6) });
294
+ titleH = titleSize * 1.4 + 12; cy += titleH;
295
+ }
296
+ let cx = x, maxH = 0, capMax = 0;
297
+ for (const im of images) {
298
+ const h = thumbHeight(im.path, thumbW);
299
+ els.push({ type: 'image', x: cx, y: cy, path: im.path, width: thumbW, height: h });
300
+ if (im.caption) {
301
+ els.push({ type: 'text', x: cx, y: cy + h + captionGap, text: im.caption, fontSize: captionSize, color: captionColor, width: thumbW });
302
+ capMax = Math.max(capMax, captionGap + sizeText(im.caption, captionSize, thumbW).height);
303
+ }
304
+ maxH = Math.max(maxH, h);
305
+ cx += thumbW + gap;
306
+ }
307
+ els.width = images.length ? images.length * thumbW + (images.length - 1) * gap : 0;
308
+ els.height = titleH + maxH + capMax;
309
+ els.nextY = y + els.height + laneGap;
310
+ return els;
311
+ }
312
+
313
+ // A wrapping grid of images. Each row sizes to its tallest image and every caption hugs its own
314
+ // image's bottom — no fixed-aspect rowH guess, so no gaps under short shots or overlaps under tall
315
+ // ones. Returns ElementSpec[] carrying `.height` / `.nextY` for stacking below the grid.
316
+ function grid(opts) {
317
+ const { images = [], x = 0, y = 0, cols = 6, thumbW = 220, gapX = 36, gapY = 60,
318
+ captionSize = 14, captionGap = 8, captionColor = '#555' } = opts;
319
+ const els = [];
320
+ let rowTop = y;
321
+ for (let r = 0; r * cols < images.length; r++) {
322
+ const row = images.slice(r * cols, r * cols + cols);
323
+ const hs = row.map((im) => thumbHeight(im.path, thumbW));
324
+ const maxH = Math.max(...hs);
325
+ let capMax = 0;
326
+ row.forEach((im, ci) => {
327
+ const cx = x + ci * (thumbW + gapX);
328
+ const h = hs[ci];
329
+ els.push({ type: 'image', x: cx, y: rowTop, path: im.path, width: thumbW, height: h });
330
+ if (im.caption) {
331
+ els.push({ type: 'text', x: cx, y: rowTop + h + captionGap, text: im.caption, fontSize: captionSize, color: captionColor, width: thumbW });
332
+ capMax = Math.max(capMax, captionGap + sizeText(im.caption, captionSize, thumbW).height);
333
+ }
334
+ });
335
+ rowTop += maxH + capMax + gapY;
336
+ }
337
+ els.height = rowTop - y;
338
+ els.nextY = rowTop;
339
+ return els;
340
+ }
341
+
342
+ module.exports = { buildExcalidraw, lane, grid, thumbHeight };
343
+
344
+ // ---------- CLI ----------
345
+ if (require.main === module) {
346
+ const args = process.argv.slice(2);
347
+ let specPath = null, out = null;
348
+ for (let i = 0; i < args.length; i++) {
349
+ if (args[i] === '--out') out = args[++i];
350
+ else specPath = args[i];
351
+ }
352
+ if (!specPath) { console.error('usage: node build_excalidraw.js <spec.json> [--out <path.excalidraw.md>]'); process.exit(1); }
353
+ const spec = JSON.parse(fs.readFileSync(specPath, 'utf8'));
354
+ if (out) spec.out = out;
355
+ const res = buildExcalidraw(spec);
356
+ console.log(`OK ${res.outPath}\n elements=${res.elements} images=${res.images} texts=${res.texts}\n vaultRoot=${res.vaultRoot}`);
357
+ }
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.