cladogram 0.5.3 → 0.5.5-beta.1

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 (54) hide show
  1. package/README.md +25 -6
  2. package/bin/clado.js +17 -6
  3. package/docs/plugin-development.md +135 -0
  4. package/docs/plugin-ui.md +43 -0
  5. package/docs/release.md +14 -0
  6. package/package.json +7 -1
  7. package/plugins/agent/index.js +181 -0
  8. package/plugins/agent/style.css +105 -0
  9. package/plugins/brand/index.js +262 -0
  10. package/plugins/brand/style.css +162 -0
  11. package/plugins/directory/capabilities.json +27 -0
  12. package/plugins/directory/index.js +201 -0
  13. package/plugins/directory/style.css +59 -0
  14. package/plugins/view-controls/index.js +58 -0
  15. package/plugins/view-controls/style.css +66 -0
  16. package/skills/clado/SKILL.md +19 -15
  17. package/src/html/app-css.js +69 -47
  18. package/src/html/canvas-chain.js +7 -7
  19. package/src/html/canvas-focus.js +2 -4
  20. package/src/html/canvas-screenshot.js +199 -0
  21. package/src/html/canvas-ui.css +5 -9
  22. package/src/html/canvas-ui.js +35 -27
  23. package/src/html/page.js +11 -37
  24. package/src/html/plugin-assets.js +33 -0
  25. package/src/html/plugin-ui.css +188 -0
  26. package/src/html/plugin-ui.js +51 -0
  27. package/src/html/runtime-api.js +41 -0
  28. package/src/html/runtime.js +164 -87
  29. package/src/server/agent.js +223 -0
  30. package/src/server/assets/clado-plugin-sdk.js +111 -0
  31. package/src/server/assets/library-canvas.js +14 -10
  32. package/src/server/assets/library-plugin-bridge.js +84 -0
  33. package/src/server/assets/library-plugins.css +39 -0
  34. package/src/server/assets/library-plugins.js +200 -0
  35. package/src/server/assets/library.css +8 -6
  36. package/src/server/assets/library.html +3 -13
  37. package/src/server/assets/library.js +280 -47
  38. package/src/server/canvas-capture.js +47 -0
  39. package/src/server/export.js +6 -3
  40. package/src/server/mcp.js +40 -17
  41. package/src/server/plugin-capabilities.js +188 -0
  42. package/src/server/plugin-settings.js +117 -0
  43. package/src/server/plugins.js +236 -0
  44. package/src/server/workspace.js +222 -29
  45. package/src/skill/install.js +1 -1
  46. package/src/skill/targets.js +3 -3
  47. package/src/util/update.js +3 -2
  48. package/src/vendor/html-to-image.min.js +24 -0
  49. package/src/workspace/service.js +21 -13
  50. package/src/workspace/storage.js +88 -20
  51. package/templates/business-flow.mdc +1 -1
  52. package/templates/call-chain.mdc +1 -1
  53. package/templates/data-design.mdc +1 -1
  54. package/src/server/assets/tree.js +0 -26
package/src/html/page.js CHANGED
@@ -1,14 +1,6 @@
1
1
  /**
2
2
  * 组装那一页 HTML。
3
3
  *
4
- * 页面的形状(`docs/spec.md` §五):
5
- *
6
- * ┌ 顶栏 ── 模式开关 / 命令行 / 诊断 / 深浅色 ──────────────┐
7
- * │ 卡片模式:无限画布,一张张卡片 + 它们之间的线 │
8
- * │ 文档模式:左大纲右正文 │
9
- * │ 脑图模式:同一块画布,换成一棵树 │
10
- * └ 底部一行提示 ────────────────────────────────────────┘
11
- *
12
4
  * 三个模式**永远都在这一页里**,`--mode` 只决定进来先看哪个 —— 切模式不回服务端,
13
5
  * 渲染全在浏览器里(`src/html/runtime.js`)。
14
6
  *
@@ -17,6 +9,7 @@
17
9
  */
18
10
 
19
11
  import { readFileSync } from 'node:fs';
12
+ import { pluginMarkup } from './plugin-assets.js';
20
13
  import { fileURLToPath } from 'node:url';
21
14
  import { dirname, join } from 'node:path';
22
15
 
@@ -56,17 +49,6 @@ function hasCodeBlock(doc) {
56
49
  return scan(doc.preamble) || doc.cards.some((c) => scan(c.md) || walk(c.nodes || []));
57
50
  }
58
51
 
59
- function diagChips(diagnostics) {
60
- const errors = diagnostics.filter((d) => d.severity === 'error').length;
61
- const warns = diagnostics.filter((d) => d.severity === 'warn' || d.severity === 'warning').length;
62
- const e = `<div class="chip${errors ? ' bad' : ''}">${errors} error</div>`;
63
- const w = warns
64
- ? `<div class="chip warn" id="warnChip" title="点开看构建输出">⚠ ${warns} warning</div>`
65
- : '<div class="chip">0 warning</div>';
66
- return e + w;
67
- }
68
-
69
- /** 构建输出原样摆在放大镜里 —— 点顶栏那个 warning chip 就能看见 */
70
52
  export function renderDiagnosticsText(diagnostics, file) {
71
53
  if (!diagnostics.length) return `${file}: 没有任何问题。`;
72
54
  return diagnostics.map((d) => {
@@ -115,6 +97,7 @@ export function renderHtml(doc, diagnostics = [], options = {}) {
115
97
  const canvasCss = readFileSync(join(HERE, 'canvas-ui.css'), 'utf8');
116
98
  const canvasUi = readFileSync(join(HERE, 'canvas-ui.js'), 'utf8');
117
99
  const diag = renderDiagnosticsText(diagnostics, file);
100
+ const plugins = pluginMarkup({ inline: true, materialOnly: options.workspaceChrome });
118
101
 
119
102
  return `<!DOCTYPE html>
120
103
  <html lang="zh-CN" data-theme="${theme}">
@@ -128,21 +111,10 @@ ${vendorCss()}
128
111
  ${APP_CSS}
129
112
  ${canvasCss}
130
113
  </style>
114
+ ${plugins.styles}
131
115
  </head>
132
116
  <body data-mode="${mode}">
133
117
 
134
- <header class="top">
135
- <div class="brand">clado<span>${escapeHtml(version)}</span></div>
136
- <div class="seg" id="modes">
137
- <button data-mode="doc" title="文档 doc">doc</button>
138
- <button data-mode="cards" title="卡片 cards">cards</button>
139
- <button data-mode="mindmap" title="脑图 mindmap">mindmap</button>
140
- </div>
141
- <div class="diag">${diagChips(diagnostics)}</div>
142
- <button type="button" id="exit-focus" hidden>退出聚焦</button>
143
- <button class="icon" id="theme" title="切浅色 / 深色">☾︎</button>
144
- </header>
145
-
146
118
  <div id="stage">
147
119
  <div id="world"><svg id="wires"></svg><div id="mind"><svg id="mwires"></svg></div></div>
148
120
  </div>
@@ -150,15 +122,15 @@ ${canvasCss}
150
122
  <div id="doc"><div class="docwrap"><nav class="toc" id="toc"></nav><article id="article"></article></div></div>
151
123
 
152
124
  <div id="lens">
153
- <div class="lensbar">
125
+ <div class="lensbar clado-ui-glass">
154
126
  <span id="lensLabel">图</span>
155
- <button id="lensOut" title="缩小">−</button>
127
+ <button id="lensOut" class="clado-ui-button" title="缩小">−</button>
156
128
  <span id="lensPct" style="min-width:44px;text-align:center">100%</span>
157
- <button id="lensIn" title="放大">+</button>
158
- <button id="lensFit" title="适应窗口">⤢</button>
159
- <button id="lensClose" title="关掉(Esc / 点背景)">✕</button>
129
+ <button id="lensIn" class="clado-ui-button" title="放大">+</button>
130
+ <button id="lensFit" class="clado-ui-button" title="适应窗口">⤢</button>
131
+ <button id="lensClose" class="clado-ui-button" title="关掉(Esc / 点背景)">✕</button>
160
132
  </div>
161
- <div id="lensStage"><div id="lensInner"></div></div>
133
+ <div id="lensStage"><div id="lensInner" class="clado-ui-glass clado-ui-glass-panel"></div></div>
162
134
  </div>
163
135
 
164
136
  <div class="hint" id="hint"></div>
@@ -167,6 +139,7 @@ ${canvasCss}
167
139
  window.__CLADO__ = ${json(doc)};
168
140
  window.__CLADO_CMD__ = ${json(command)};
169
141
  window.__CLADO_LIVE__ = ${json(!!options.library)};
142
+ window.__CLADO_WORKSPACE_CHROME__ = ${json(!!options.workspaceChrome)};
170
143
  window.__CLADO_DIAG__ = ${json(diag)};
171
144
  window.__CLADO_DIAGNOSTICS__ = ${json(diagnostics)};
172
145
  window.__CLADO_FILE__ = ${json(basenameForDisplay(file))};
@@ -174,6 +147,7 @@ window.__CLADO_FILE__ = ${json(basenameForDisplay(file))};
174
147
  <script id="clado-runtime">
175
148
  ${runtime}
176
149
  </script>
150
+ ${plugins.scripts}
177
151
  <script id="clado-canvas-ui">${canvasUi}</script>
178
152
  </body>
179
153
  </html>
@@ -0,0 +1,33 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ const shared = ['plugin-ui.css', 'plugin-ui.js'].map(name => ({
4
+ path: '/' + name,
5
+ file: new URL(name, import.meta.url),
6
+ }));
7
+ const packageAssets = id =>
8
+ ['style.css', 'index.js'].map(name => {
9
+ const path = '/plugins/' + id + '/' + name;
10
+ return { path, file: new URL('../..' + path, import.meta.url) };
11
+ });
12
+ const canvasAssets = [...shared, ...packageAssets('brand'), ...packageAssets('view-controls')];
13
+ const screenshotAssets = [
14
+ { path: '/html-to-image.js', file: new URL('../vendor/html-to-image.min.js', import.meta.url) },
15
+ { path: '/canvas-screenshot.js', file: new URL('canvas-screenshot.js', import.meta.url) },
16
+ ];
17
+ const workspaceAssets = [...canvasAssets, ...packageAssets('directory'), ...screenshotAssets];
18
+ const agentAssets = packageAssets('agent');
19
+ export const workspacePluginAssets = new Map([...workspaceAssets, ...agentAssets].map(({ path, file }) => [path, file]));
20
+
21
+ export function pluginMarkup({ workspace = false, inline = false, agent = false, materialOnly = false } = {}) {
22
+ const assets = materialOnly ? [shared[0]] : agent ? [...workspaceAssets, ...agentAssets] : workspace ? workspaceAssets : canvasAssets;
23
+ const tags = { styles: [], scripts: [] };
24
+ for (const { path, file } of assets) {
25
+ const css = path.endsWith('.css');
26
+ if (css) {
27
+ tags.styles.push(inline ? '<style>' + readFileSync(file, 'utf8') + '</style>' : '<link rel="stylesheet" href="' + path + '">');
28
+ } else {
29
+ tags.scripts.push(inline ? '<script>' + readFileSync(file, 'utf8').replace(/<\/script/gi, '<\\/script') + '</script>' : '<script src="' + path + '"></script>');
30
+ }
31
+ }
32
+ return { styles: tags.styles.join('\n'), scripts: tags.scripts.join('\n') };
33
+ }
@@ -0,0 +1,188 @@
1
+ :root {
2
+ --clado-ui-text: #191919;
3
+ --clado-ui-muted: #565656;
4
+ --clado-ui-accent: #252525;
5
+ --clado-ui-surface: rgb(252 252 252 / .04);
6
+ --clado-ui-panel-surface: rgb(250 250 250 / .13);
7
+ --clado-ui-well: rgb(231 231 231 / .46);
8
+ --clado-ui-solid: #f8f8f8;
9
+ --clado-ui-edge: #17171724;
10
+ --clado-ui-active: #e9e9e9;
11
+ --clado-ui-highlight: rgb(255 255 255 / .34);
12
+ --clado-ui-rim: rgb(93 93 93 / .08);
13
+ --clado-ui-shadow: 0 3px 12px rgb(21 21 21 / .10), 0 1px 3px rgb(21 21 21 / .06);
14
+ --clado-ui-glass-outline: rgb(100 100 100 / .17);
15
+ --clado-ui-glass-shadow: 0 5px 22px rgb(21 21 21 / .09);
16
+ --clado-ui-control-blur: 14px;
17
+ --clado-ui-panel-blur: 18px;
18
+ --clado-ui-radius: 16px;
19
+ --clado-ui-gap: 8px;
20
+ }
21
+ :root[data-theme="dark"] {
22
+ color-scheme: dark;
23
+ --clado-ui-text: #f3f3f3;
24
+ --clado-ui-muted: #b4b4b4;
25
+ --clado-ui-accent: #ededed;
26
+ --clado-ui-surface: rgb(33 33 33 / .38);
27
+ --clado-ui-panel-surface: rgb(30 30 30 / .68);
28
+ --clado-ui-well: rgb(128 128 128 / .16);
29
+ --clado-ui-solid: #292929;
30
+ --clado-ui-edge: #ffffff2a;
31
+ --clado-ui-active: #424242;
32
+ --clado-ui-highlight: #ffffff23;
33
+ --clado-ui-rim: #ffffff23;
34
+ --clado-ui-shadow: 0 8px 26px #0005, 0 2px 6px #0003;
35
+ --clado-ui-glass-outline: rgb(180 180 180 / .23);
36
+ --clado-ui-glass-shadow: 0 6px 24px #0005;
37
+ --clado-ui-control-blur: 14px;
38
+ --clado-ui-panel-blur: 30px;
39
+ }
40
+ .clado-plugin-slot {
41
+ position: fixed;
42
+ display: flex;
43
+ gap: var(--clado-ui-gap);
44
+ z-index: 18;
45
+ font: 13px/1.35 system-ui, sans-serif;
46
+ pointer-events: none;
47
+ opacity: 1;
48
+ transform: translateY(0);
49
+ transition: opacity 160ms ease, transform 160ms ease;
50
+ }
51
+ .clado-plugin-slot.clado-slot-hidden {
52
+ opacity: 0;
53
+ transform: translateY(-4px) scale(.985);
54
+ pointer-events: none;
55
+ }
56
+ .clado-plugin-slot.clado-slot-hidden > * { pointer-events: none; }
57
+ @media (prefers-reduced-motion: reduce) {
58
+ .clado-plugin-slot { transition: none; }
59
+ }
60
+ .clado-plugin-slot[hidden], .clado-plugin-slot [hidden] { display: none !important; }
61
+ .clado-plugin-slot > * { pointer-events: auto; }
62
+ .clado-plugin-slot[data-slot="top-left"] { top: 14px; left: 16px; max-width: calc(100vw - 250px); flex-direction: column; align-items: start; }
63
+ .clado-plugin-slot[data-slot="top-right"] { top: 14px; right: 16px; flex-direction: column; align-items: end; }
64
+ .clado-plugin-slot[data-slot="bottom-left"] { bottom: 16px; left: 16px; align-items: end; }
65
+ .clado-plugin-slot[data-slot="bottom-right"] { bottom: 16px; right: 16px; flex-direction: column-reverse; align-items: end; }
66
+ :where(.clado-ui-glass) {
67
+ position: relative;
68
+ z-index: 0;
69
+ }
70
+ .clado-ui-glass {
71
+ --clado-ui-glass-fill: var(--clado-ui-surface);
72
+ --clado-ui-glass-blur: var(--clado-ui-control-blur);
73
+ --clado-ui-glass-feather: 3px;
74
+ color: var(--clado-ui-text);
75
+ background: var(--clado-ui-solid);
76
+ border: 1px solid var(--clado-ui-edge);
77
+ border-radius: var(--clado-ui-radius);
78
+ box-shadow: var(--clado-ui-shadow);
79
+ }
80
+ .clado-ui-glass.clado-ui-glass-panel {
81
+ --clado-ui-glass-fill: var(--clado-ui-panel-surface);
82
+ --clado-ui-glass-blur: var(--clado-ui-panel-blur);
83
+ --clado-ui-glass-feather: 5px;
84
+ }
85
+ .clado-ui-button {
86
+ appearance: none;
87
+ border: 1px solid transparent;
88
+ background: transparent;
89
+ color: var(--clado-ui-muted);
90
+ border-radius: 10px;
91
+ font: inherit;
92
+ line-height: 1.15;
93
+ min-height: 32px;
94
+ padding: 5px 10px;
95
+ cursor: pointer;
96
+ white-space: nowrap;
97
+ }
98
+ .clado-ui-button:where(:hover:not(:disabled), [aria-pressed="true"], [aria-expanded="true"], [aria-current="page"], .clado-ui-button-primary) {
99
+ color: var(--clado-ui-accent);
100
+ background: var(--clado-ui-active);
101
+ }
102
+ .clado-ui-button:focus-visible { outline: 2px solid var(--clado-ui-accent); outline-offset: 2px; }
103
+ .clado-ui-button:disabled { opacity: .5; cursor: default; }
104
+ .clado-ui-dialog {
105
+ color-scheme: light;
106
+ --clado-ui-text: #191919;
107
+ --clado-ui-muted: #565656;
108
+ --clado-ui-accent: #252525;
109
+ --clado-ui-edge: #17171724;
110
+ --clado-ui-active: #e9e9e9;
111
+ --ink: var(--clado-ui-text);
112
+ --muted: var(--clado-ui-muted);
113
+ --line: #e3e3e3;
114
+ color: var(--clado-ui-text);
115
+ background: #fff;
116
+ border: 1px solid #e3e3e3;
117
+ border-radius: var(--clado-ui-radius);
118
+ box-shadow: 0 10px 36px rgb(21 21 21 / .14);
119
+ }
120
+ .clado-ui-dialog::backdrop { background: transparent; }
121
+ .clado-ui-glass.clado-ui-button {
122
+ background-color: var(--clado-ui-solid);
123
+ border-color: var(--clado-ui-edge);
124
+ }
125
+ .clado-ui-glass.clado-ui-button:where(:hover:not(:disabled), [aria-expanded="true"], [aria-pressed="true"], [aria-current="page"], .clado-ui-button-primary) {
126
+ background-color: var(--clado-ui-active);
127
+ }
128
+ @supports (backdrop-filter: blur(1px)) {
129
+ @media (prefers-reduced-transparency: no-preference) {
130
+ .clado-ui-glass {
131
+ background: transparent;
132
+ border-color: var(--clado-ui-glass-outline);
133
+ box-shadow: var(--clado-ui-glass-shadow);
134
+ }
135
+ .clado-ui-glass::before {
136
+ content: "";
137
+ position: absolute;
138
+ z-index: -1;
139
+ inset: 0;
140
+ border-radius: inherit;
141
+ pointer-events: none;
142
+ background: var(--clado-ui-glass-fill);
143
+ backdrop-filter: blur(var(--clado-ui-glass-blur)) saturate(145%);
144
+ /* Retain enough blur at the edge to keep text behind the glass indistinct. */
145
+ mask-image:
146
+ linear-gradient(to right, rgb(0 0 0 / .95), #000 var(--clado-ui-glass-feather), #000 calc(100% - var(--clado-ui-glass-feather)), rgb(0 0 0 / .95)),
147
+ linear-gradient(to bottom, rgb(0 0 0 / .95), #000 var(--clado-ui-glass-feather), #000 calc(100% - var(--clado-ui-glass-feather)), rgb(0 0 0 / .95));
148
+ mask-composite: intersect;
149
+ }
150
+ .clado-ui-button, .clado-ui-glass.clado-ui-button {
151
+ --clado-ui-button-tint: 4%;
152
+ --clado-ui-button-outline: color-mix(in srgb, var(--clado-ui-edge) 36%, transparent);
153
+ background: color-mix(in srgb, var(--clado-ui-accent) var(--clado-ui-button-tint), transparent) padding-box;
154
+ border-color: var(--clado-ui-button-outline);
155
+ }
156
+ .clado-ui-button:hover:where(:not(:disabled)) {
157
+ --clado-ui-button-tint: 8%;
158
+ }
159
+ .clado-ui-button:is([aria-expanded="true"], [aria-pressed="true"], [aria-current="page"], .clado-ui-button-primary) {
160
+ --clado-ui-button-tint: 12%;
161
+ --clado-ui-button-outline: color-mix(in srgb, var(--clado-ui-accent) 16%, transparent);
162
+ }
163
+ .clado-ui-glass.clado-ui-button {
164
+ border-color: var(--clado-ui-glass-outline);
165
+ }
166
+ @supports (mask-composite: exclude) {
167
+ /* Keep the highlights on a thin rim so a white canvas does not become a white fill. */
168
+ .clado-ui-glass::after {
169
+ content: "";
170
+ position: absolute;
171
+ z-index: 1;
172
+ inset: -1px;
173
+ padding: 1px;
174
+ border-radius: inherit;
175
+ pointer-events: none;
176
+ background: linear-gradient(146deg, var(--clado-ui-highlight), transparent 32% 58%, var(--clado-ui-rim));
177
+ mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
178
+ mask-composite: exclude;
179
+ }
180
+ }
181
+ }
182
+ }
183
+ @media (max-width: 460px) {
184
+ .clado-plugin-slot[data-slot="top-left"] { top: 10px; left: 10px; max-width: calc(100vw - 207px); }
185
+ .clado-plugin-slot[data-slot="top-right"] { top: 10px; right: 10px; }
186
+ .clado-plugin-slot[data-slot="bottom-left"] { bottom: 10px; left: 10px; }
187
+ .clado-plugin-slot[data-slot="bottom-right"] { bottom: 10px; right: 10px; }
188
+ }
@@ -0,0 +1,51 @@
1
+ (() => {
2
+ function createHost(bridge, isEnabled = () => true) {
3
+ const slots = new Map();
4
+ let hidden = false;
5
+ return {
6
+ capabilities(pluginId, mountId) {
7
+ if (!bridge || !isEnabled(pluginId)) return undefined;
8
+ const identity = { pluginId, mountId };
9
+ return {
10
+ provide: invoke => bridge.provide(identity, invoke),
11
+ list: query => bridge.list(identity, query),
12
+ call: (to, input) => bridge.call(identity, to, input),
13
+ };
14
+ },
15
+ mount(slot, element, pluginId) {
16
+ if (!isEnabled(pluginId)) return () => {};
17
+ if (!slots.has(slot)) {
18
+ const region = document.createElement('div');
19
+ region.className = 'clado-plugin-slot';
20
+ region.dataset.slot = slot;
21
+ region.classList.toggle('clado-slot-hidden', hidden);
22
+ region.setAttribute('aria-hidden', String(hidden));
23
+ region.inert = hidden;
24
+ slots.set(slot, region);
25
+ document.body.append(region);
26
+ }
27
+ const region = slots.get(slot);
28
+ element.dataset.pluginId = pluginId;
29
+ region.append(element);
30
+ return () => {
31
+ element.remove();
32
+ if (!region.childElementCount) {
33
+ region.remove();
34
+ slots.delete(slot);
35
+ }
36
+ };
37
+ },
38
+ setHidden(next) {
39
+ if (hidden === next) return;
40
+ hidden = next;
41
+ for (const slot of slots.values()) {
42
+ slot.classList.toggle('clado-slot-hidden', hidden);
43
+ slot.setAttribute('aria-hidden', String(hidden));
44
+ slot.inert = hidden;
45
+ }
46
+ },
47
+ };
48
+ }
49
+
50
+ window.CladoPluginUI = { createHost };
51
+ })();
@@ -3,6 +3,8 @@
3
3
  setMode: setMode, setTheme: setTheme, clearFocus: clearLit,
4
4
  focusPath: focusPath,
5
5
  isChainOpen: canvasChainIsOpen,
6
+ isLensOpen: function () { return $('#lens').classList.contains('open'); },
7
+ isFocused: function () { return !!canvasFocusId; },
6
8
  contentPath: function (id) { var r = canvasRecords[id]; return r ? r.fullPath : null; },
7
9
  selectionPath: function (target) { var r = canvasRecordForTarget(target); return r && r.titlePath || null; },
8
10
  hasSelectionPath: function (path) {
@@ -10,6 +12,45 @@
10
12
  for (var record of Object.values(canvasRecords)) if (record.titlePath.length === path.length && path.every(function (part, i) { return part === record.titlePath[i]; })) count++;
11
13
  return count === 1;
12
14
  },
15
+ readPluginContext: function (fields, selectedPaths, page) {
16
+ var result = {}, mode = document.body.dataset.mode;
17
+ if (fields.includes('document')) {
18
+ result.document = { title: DOC.title, mode: mode, theme: document.documentElement.dataset.theme };
19
+ }
20
+ if (fields.includes('viewport')) {
21
+ var view = $(mode === 'doc' ? '#doc' : '#stage');
22
+ var bounds = view.getBoundingClientRect();
23
+ result.viewport = { width: bounds.width, height: bounds.height, scale: mode === 'doc' ? 1 : scale };
24
+ }
25
+ if (fields.includes('selection')) {
26
+ var byPath = new Map((selectedPaths.length ? Object.values(canvasRecords) : []).map(function (record) {
27
+ return [JSON.stringify(record.titlePath), record];
28
+ }));
29
+ function selectedContent(record) {
30
+ return { nodePath: record.titlePath, markdown: record.markdown,
31
+ children: record.kids.map(function (id) { return selectedContent(canvasRecords[id]); }) };
32
+ }
33
+ result.selection = selectedPaths.map(function (path) { return byPath.get(JSON.stringify(path)); })
34
+ .filter(Boolean).map(selectedContent);
35
+ }
36
+ if (fields.includes('graph')) {
37
+ var records = Object.values(canvasRecords);
38
+ var rows = records.map(function (record) {
39
+ return { kind: 'node', nodePath: record.titlePath,
40
+ parent: record.parent ? canvasRecords[record.parent].titlePath : null };
41
+ });
42
+ records.forEach(function (record) {
43
+ (canvasOut[record.id] || []).forEach(function (target) {
44
+ rows.push({ kind: 'link', from: record.titlePath, to: canvasRecords[target].titlePath });
45
+ });
46
+ });
47
+ result.graph = {
48
+ items: rows.slice(page.offset, page.offset + page.limit),
49
+ nextOffset: page.offset + page.limit < rows.length ? page.offset + page.limit : null
50
+ };
51
+ }
52
+ return result;
53
+ },
13
54
  focusTitle: function (title) {
14
55
  var r = Object.values(canvasRecords).find(function (r) { return r.title === title || r.fullPath === title; });
15
56
  if (!r) return;