@open-document/core 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-CFL7nhz0.js → build-DJMLK50m.js} +1 -1
- package/dist/{check-CL0-0eB8.js → check-CUKuufBm.js} +3 -3
- package/dist/cli/bin.js +10 -6
- package/dist/{config-4nz5NnxW.js → config-CvzpyAUA.js} +558 -546
- package/dist/{context-BH8C-dSW.js → context-B4ip7SoI.js} +1 -1
- package/dist/{dev-BCSUczXW.js → dev-dnH7DTlD.js} +1 -1
- package/dist/{diagram-xlVDekYk.js → diagram-BK4jTZr4.js} +231 -158
- package/dist/diff-QTo0A5Rx.js +44 -0
- package/dist/{export-CmVJdl9a.js → export-BrRFrexj.js} +3 -3
- package/dist/{import-E6vRo7xm.js → import-C14Vn9ER.js} +2 -2
- package/dist/index.d.ts +54 -3
- package/dist/index.js +457 -18
- package/dist/ops/index.d.ts +72 -17
- package/dist/ops/index.js +3 -3
- package/dist/{ops-OZZVBgsM.js → ops-DKidjLXP.js} +642 -124
- package/dist/{preview-CwCrw-i3.js → preview-wKM4C6Uk.js} +1 -1
- package/dist/{sdk-BqU6mwD_.d.ts → sdk-CpDEGRIo.d.ts} +2 -0
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/skills/doc-authoring/SKILL.md +13 -6
- package/skills/doc-authoring/references/pagination.md +1 -1
- package/skills/doc-authoring/references/tables-and-charts.md +18 -1
- package/src/app/components/browser/browser-ui.tsx +105 -0
- package/src/app/components/chart.tsx +239 -0
- package/src/app/components/command-palette.tsx +284 -0
- package/src/app/components/design-panel/design-panel.tsx +22 -20
- package/src/app/components/design-panel/design-provider.tsx +4 -2
- package/src/app/components/diagram.tsx +11 -1
- package/src/app/components/doc-assets.tsx +6 -5
- package/src/app/components/doc-search.tsx +12 -10
- package/src/app/components/doc-sidebar.tsx +24 -18
- package/src/app/components/flow-page.tsx +2 -0
- package/src/app/components/inspector/inspector.tsx +75 -48
- package/src/app/components/language-toggle.tsx +38 -0
- package/src/app/components/palette-items.ts +128 -0
- package/src/app/components/panel/edit-save-card.tsx +4 -2
- package/src/app/components/panel/fields.tsx +5 -2
- package/src/app/components/panel/save-card.tsx +18 -10
- package/src/app/components/sidebar/folder-item.tsx +10 -8
- package/src/app/components/sidebar/icon-picker.tsx +3 -1
- package/src/app/components/sidebar/sidebar.tsx +44 -13
- package/src/app/components/theme-toggle.tsx +5 -3
- package/src/app/components/ui/menu.tsx +5 -0
- package/src/app/lib/agent-bridge.ts +8 -2
- package/src/app/lib/chart.test.ts +108 -0
- package/src/app/lib/chart.ts +343 -0
- package/src/app/lib/doc-preview.tsx +0 -10
- package/src/app/lib/docs.ts +3 -0
- package/src/app/lib/docx/from-dom.ts +11 -11
- package/src/app/lib/docx/ooxml.test.ts +25 -9
- package/src/app/lib/docx/ooxml.ts +58 -37
- package/src/app/lib/export-docx.ts +13 -8
- package/src/app/lib/export-dom.ts +4 -0
- package/src/app/lib/export-image.ts +2 -0
- package/src/app/lib/export-pdf.ts +6 -0
- package/src/app/lib/flow-measure.ts +3 -0
- package/src/app/lib/flow.ts +1 -1
- package/src/app/lib/i18n-ja/browser.ts +88 -0
- package/src/app/lib/i18n-ja/doc.ts +65 -0
- package/src/app/lib/i18n-ja/index.ts +5 -0
- package/src/app/lib/i18n-ja/panels.ts +104 -0
- package/src/app/lib/i18n-ko/browser.ts +87 -0
- package/src/app/lib/i18n-ko/doc.ts +65 -0
- package/src/app/lib/i18n-ko/index.ts +5 -0
- package/src/app/lib/i18n-ko/panels.ts +102 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
- package/src/app/lib/i18n-zh-cn/index.ts +5 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +98 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
- package/src/app/lib/i18n-zh-tw/index.ts +5 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +99 -0
- package/src/app/lib/i18n.test.ts +24 -0
- package/src/app/lib/i18n.tsx +109 -0
- package/src/app/lib/outline.ts +23 -0
- package/src/app/lib/page-range.test.ts +10 -1
- package/src/app/lib/page-range.ts +26 -0
- package/src/app/lib/sdk.ts +2 -0
- package/src/app/lib/svg-ids.ts +37 -0
- package/src/app/main.tsx +4 -1
- package/src/app/routes/assets.tsx +193 -132
- package/src/app/routes/doc.tsx +666 -310
- package/src/app/routes/home-shell.tsx +115 -88
- package/src/app/routes/home.tsx +200 -67
- package/src/app/routes/themes.tsx +42 -35
- package/src/app/styles.css +99 -0
- package/src/app/virtual.d.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -1,24 +1,269 @@
|
|
|
1
|
-
import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, t as compileDiagram } from "./diagram-
|
|
1
|
+
import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, s as measureText, t as compileDiagram } from "./diagram-BK4jTZr4.js";
|
|
2
2
|
import { a as PAGE_SIZES, c as isPageSizeName, i as ORIENTATIONS, l as resolvePageGeometry, n as DEFAULT_PAGE_SIZE, o as PAGE_SIZE_NAMES, s as isOrientation, t as DEFAULT_ORIENTATION } from "./sdk-CqNZzbkz.js";
|
|
3
3
|
import { Children, Fragment, createContext, isValidElement, useContext, useEffect, useId, useRef, useSyncExternalStore } from "react";
|
|
4
4
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
|
|
5
|
+
const LEGEND_GAP = 14;
|
|
6
|
+
/** A number read the way a CSV cell or a typed literal would hold it. */
|
|
7
|
+
function toNumber(value) {
|
|
8
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
9
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
10
|
+
const n = Number(value.replace(/,/g, ""));
|
|
11
|
+
return Number.isFinite(n) ? n : null;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
function formatChartValue(value, format) {
|
|
16
|
+
if (typeof format === "function") return format(value);
|
|
17
|
+
if (format === "integer") return Math.round(value).toLocaleString();
|
|
18
|
+
if (format === "percent") return `${(value * 100).toLocaleString(void 0, { maximumFractionDigits: 1 })}%`;
|
|
19
|
+
return value.toLocaleString(void 0, { maximumFractionDigits: 2 });
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* host that prints the call site's words, so the inspector can select what it
|
|
10
|
-
* rendered — a table, a caption, a footnote — and find the source behind it.
|
|
11
|
-
* `data-od-prop` says which attribute of the call site those words come from.
|
|
22
|
+
* Round tick values over a range — 0, 20, 40 rather than 0, 17.3, 34.6 —
|
|
23
|
+
* stepping by 1, 2 or 5 times a power of ten.
|
|
12
24
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
function niceTicks(min, max, count = 5) {
|
|
26
|
+
if (min === max) {
|
|
27
|
+
if (min === 0) return [0, 1];
|
|
28
|
+
const pad = Math.abs(min) * .5;
|
|
29
|
+
return niceTicks(Math.min(0, min - pad), Math.max(0, max + pad), count);
|
|
30
|
+
}
|
|
31
|
+
const rough = (max - min) / Math.max(1, count);
|
|
32
|
+
const power = 10 ** Math.floor(Math.log10(rough));
|
|
33
|
+
const step = [
|
|
34
|
+
1,
|
|
35
|
+
2,
|
|
36
|
+
5,
|
|
37
|
+
10
|
|
38
|
+
].map((m) => m * power).find((s) => s >= rough) ?? 10 * power;
|
|
39
|
+
const first = Math.floor(min / step) * step;
|
|
40
|
+
const last = Math.ceil(max / step) * step;
|
|
41
|
+
const ticks = [];
|
|
42
|
+
const digits = Math.max(0, -Math.floor(Math.log10(step)));
|
|
43
|
+
for (let value = first; value <= last + step / 2; value += step) ticks.push(Number(value.toFixed(digits)));
|
|
44
|
+
return ticks;
|
|
45
|
+
}
|
|
46
|
+
function seriesName(spec, key) {
|
|
47
|
+
return spec.labels?.[key] ?? key;
|
|
48
|
+
}
|
|
49
|
+
function legendRow(names, left, top) {
|
|
50
|
+
let x = left;
|
|
51
|
+
return names.map((name, series) => {
|
|
52
|
+
const item = {
|
|
53
|
+
name,
|
|
54
|
+
series,
|
|
55
|
+
x,
|
|
56
|
+
y: top
|
|
57
|
+
};
|
|
58
|
+
x += 14 + measureText(name, 10) + LEGEND_GAP;
|
|
59
|
+
return item;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function slicePath(cx, cy, r, from, to) {
|
|
63
|
+
if (to - from >= Math.PI * 2 - 1e-9) return `M${cx - r},${cy} a${r},${r} 0 1 0 ${r * 2},0 a${r},${r} 0 1 0 ${-r * 2},0 Z`;
|
|
64
|
+
const point = (angle) => ({
|
|
65
|
+
x: cx + r * Math.sin(angle),
|
|
66
|
+
y: cy - r * Math.cos(angle)
|
|
67
|
+
});
|
|
68
|
+
const start = point(from);
|
|
69
|
+
const end = point(to);
|
|
70
|
+
const large = to - from > Math.PI ? 1 : 0;
|
|
71
|
+
return `M${cx},${cy} L${round(start.x)},${round(start.y)} A${r},${r} 0 ${large} 1 ${round(end.x)},${round(end.y)} Z`;
|
|
72
|
+
}
|
|
73
|
+
function round(value) {
|
|
74
|
+
return Math.round(value * 100) / 100;
|
|
75
|
+
}
|
|
76
|
+
function layoutPie(spec) {
|
|
77
|
+
const key = spec.y[0] ?? "";
|
|
78
|
+
const rows = spec.data.map((row) => ({
|
|
79
|
+
name: String(row[spec.x] ?? ""),
|
|
80
|
+
value: toNumber(row[key]) ?? 0
|
|
81
|
+
})).filter((row) => row.value > 0);
|
|
82
|
+
const total = rows.reduce((sum, row) => sum + row.value, 0);
|
|
83
|
+
const r = Math.max(10, Math.min(spec.height / 2 - 6, spec.width * .25));
|
|
84
|
+
const cx = r + 6;
|
|
85
|
+
const cy = spec.height / 2;
|
|
86
|
+
const slices = [];
|
|
87
|
+
const values = [];
|
|
88
|
+
let angle = 0;
|
|
89
|
+
rows.forEach((row, series) => {
|
|
90
|
+
const share = total > 0 ? row.value / total : 0;
|
|
91
|
+
const next = angle + share * Math.PI * 2;
|
|
92
|
+
slices.push({
|
|
93
|
+
series,
|
|
94
|
+
path: slicePath(cx, cy, r, angle, next),
|
|
95
|
+
share,
|
|
96
|
+
name: row.name
|
|
97
|
+
});
|
|
98
|
+
if (spec.values && share >= .06) {
|
|
99
|
+
const mid = (angle + next) / 2;
|
|
100
|
+
values.push({
|
|
101
|
+
text: formatChartValue(share, "percent"),
|
|
102
|
+
x: round(cx + r * .62 * Math.sin(mid)),
|
|
103
|
+
y: round(cy - r * .62 * Math.cos(mid) + 3.5),
|
|
104
|
+
anchor: "middle"
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
angle = next;
|
|
108
|
+
});
|
|
109
|
+
const legendLeft = cx + r + 24;
|
|
110
|
+
const lineHeight = 18;
|
|
111
|
+
const legendTop = cy - rows.length * lineHeight / 2 + lineHeight / 2;
|
|
112
|
+
const legend = slices.map((slice, series) => ({
|
|
113
|
+
name: `${slice.name} ${formatChartValue(slice.share, "percent")}`,
|
|
114
|
+
series,
|
|
115
|
+
x: legendLeft,
|
|
116
|
+
y: round(legendTop + series * lineHeight)
|
|
117
|
+
}));
|
|
118
|
+
return {
|
|
119
|
+
width: spec.width,
|
|
120
|
+
height: spec.height,
|
|
121
|
+
plot: {
|
|
122
|
+
x: cx - r,
|
|
123
|
+
y: cy - r,
|
|
124
|
+
width: r * 2,
|
|
125
|
+
height: r * 2
|
|
126
|
+
},
|
|
127
|
+
baseline: null,
|
|
128
|
+
ticks: [],
|
|
129
|
+
categories: [],
|
|
130
|
+
bars: [],
|
|
131
|
+
lines: [],
|
|
132
|
+
slices,
|
|
133
|
+
legend,
|
|
134
|
+
values
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function layoutChart(spec) {
|
|
138
|
+
if (spec.type === "pie") return layoutPie(spec);
|
|
139
|
+
const names = spec.y.map((key) => seriesName(spec, key));
|
|
140
|
+
const categories = spec.data.map((row) => String(row[spec.x] ?? ""));
|
|
141
|
+
const matrix = spec.data.map((row) => spec.y.map((key) => toNumber(row[key])));
|
|
142
|
+
let lo = Number.POSITIVE_INFINITY;
|
|
143
|
+
let hi = Number.NEGATIVE_INFINITY;
|
|
144
|
+
for (const values of matrix) if (spec.type === "bar" && spec.stacked) {
|
|
145
|
+
const up = values.reduce((sum, v) => sum + Math.max(0, v ?? 0), 0);
|
|
146
|
+
const down = values.reduce((sum, v) => sum + Math.min(0, v ?? 0), 0);
|
|
147
|
+
lo = Math.min(lo, down);
|
|
148
|
+
hi = Math.max(hi, up);
|
|
149
|
+
} else for (const v of values) {
|
|
150
|
+
if (v === null) continue;
|
|
151
|
+
lo = Math.min(lo, v);
|
|
152
|
+
hi = Math.max(hi, v);
|
|
153
|
+
}
|
|
154
|
+
if (!Number.isFinite(lo)) {
|
|
155
|
+
lo = 0;
|
|
156
|
+
hi = 1;
|
|
157
|
+
}
|
|
158
|
+
if (spec.type === "bar" || lo >= 0 && lo <= hi * .5) lo = Math.min(0, lo);
|
|
159
|
+
if (spec.type === "bar") hi = Math.max(0, hi);
|
|
160
|
+
const tickValues = niceTicks(lo, hi);
|
|
161
|
+
const min = tickValues[0] ?? 0;
|
|
162
|
+
const max = tickValues[tickValues.length - 1] ?? 1;
|
|
163
|
+
const tickLabels = tickValues.map((value) => formatChartValue(value, spec.format));
|
|
164
|
+
const top = 6 + (spec.y.length > 1 ? 22 : 0) + (spec.values ? 10 : 0);
|
|
165
|
+
const left = Math.ceil(Math.max(...tickLabels.map((t) => measureText(t, 10))) * 1.2) + 12;
|
|
166
|
+
const plot = {
|
|
167
|
+
x: left,
|
|
168
|
+
y: top,
|
|
169
|
+
width: Math.max(10, spec.width - left - 6),
|
|
170
|
+
height: Math.max(10, spec.height - top - 20)
|
|
171
|
+
};
|
|
172
|
+
const yOf = (value) => round(plot.y + plot.height - (value - min) / (max - min) * plot.height);
|
|
173
|
+
const ticks = tickValues.map((value, i) => ({
|
|
174
|
+
value,
|
|
175
|
+
at: yOf(value),
|
|
176
|
+
label: tickLabels[i] ?? ""
|
|
177
|
+
}));
|
|
178
|
+
const band = plot.width / Math.max(1, categories.length);
|
|
179
|
+
const widest = Math.max(0, ...categories.map((c) => measureText(c, 10)));
|
|
180
|
+
const every = Math.max(1, Math.ceil((widest + 6) / band));
|
|
181
|
+
const categoryLabels = categories.map((text, i) => ({
|
|
182
|
+
text,
|
|
183
|
+
x: round(plot.x + band * (i + .5))
|
|
184
|
+
})).filter((_, i) => i % every === 0);
|
|
185
|
+
const bars = [];
|
|
186
|
+
const lines = [];
|
|
187
|
+
const values = [];
|
|
188
|
+
if (spec.type === "bar") {
|
|
189
|
+
const group = band * .68;
|
|
190
|
+
const each = spec.stacked ? group : group / Math.max(1, spec.y.length);
|
|
191
|
+
matrix.forEach((row, i) => {
|
|
192
|
+
const start = plot.x + band * i + (band - group) / 2;
|
|
193
|
+
let up = 0;
|
|
194
|
+
let down = 0;
|
|
195
|
+
row.forEach((value, series) => {
|
|
196
|
+
if (value === null) return;
|
|
197
|
+
let from;
|
|
198
|
+
let to;
|
|
199
|
+
if (spec.stacked) {
|
|
200
|
+
from = value >= 0 ? up : down;
|
|
201
|
+
to = from + value;
|
|
202
|
+
if (value >= 0) up = to;
|
|
203
|
+
else down = to;
|
|
204
|
+
} else {
|
|
205
|
+
from = 0;
|
|
206
|
+
to = value;
|
|
207
|
+
}
|
|
208
|
+
const y1 = yOf(Math.max(from, to));
|
|
209
|
+
const y2 = yOf(Math.min(from, to));
|
|
210
|
+
const x = round(spec.stacked ? start : start + each * series);
|
|
211
|
+
const width = round(Math.max(1, each - (spec.stacked ? 0 : 2)));
|
|
212
|
+
bars.push({
|
|
213
|
+
x,
|
|
214
|
+
y: y1,
|
|
215
|
+
width,
|
|
216
|
+
height: round(Math.max(0, y2 - y1)),
|
|
217
|
+
series,
|
|
218
|
+
value
|
|
219
|
+
});
|
|
220
|
+
if (spec.values && !spec.stacked) values.push({
|
|
221
|
+
text: formatChartValue(value, spec.format),
|
|
222
|
+
x: round(x + width / 2),
|
|
223
|
+
y: round(value >= 0 ? y1 - 3 : y2 + 10 + 2),
|
|
224
|
+
anchor: "middle"
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
if (spec.values && spec.stacked) values.push({
|
|
228
|
+
text: formatChartValue(up + down, spec.format),
|
|
229
|
+
x: round(start + group / 2),
|
|
230
|
+
y: round(yOf(up) - 3),
|
|
231
|
+
anchor: "middle"
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
} else spec.y.forEach((_, series) => {
|
|
235
|
+
const points = matrix.flatMap((row, i) => {
|
|
236
|
+
const value = row[series];
|
|
237
|
+
return value === null || value === void 0 ? [] : [{
|
|
238
|
+
x: round(plot.x + band * (i + .5)),
|
|
239
|
+
y: yOf(value),
|
|
240
|
+
value
|
|
241
|
+
}];
|
|
242
|
+
});
|
|
243
|
+
lines.push({
|
|
244
|
+
series,
|
|
245
|
+
points
|
|
246
|
+
});
|
|
247
|
+
if (spec.values) for (const point of points) values.push({
|
|
248
|
+
text: formatChartValue(point.value, spec.format),
|
|
249
|
+
x: point.x,
|
|
250
|
+
y: round(point.y - 6),
|
|
251
|
+
anchor: "middle"
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
return {
|
|
255
|
+
width: spec.width,
|
|
256
|
+
height: spec.height,
|
|
257
|
+
plot,
|
|
258
|
+
baseline: min <= 0 && max >= 0 ? yOf(0) : null,
|
|
259
|
+
ticks,
|
|
260
|
+
categories: categoryLabels,
|
|
261
|
+
bars,
|
|
262
|
+
lines,
|
|
263
|
+
slices: [],
|
|
264
|
+
legend: spec.y.length > 1 ? legendRow(names, plot.x, 14) : [],
|
|
265
|
+
values
|
|
266
|
+
};
|
|
22
267
|
}
|
|
23
268
|
//#endregion
|
|
24
269
|
//#region src/app/lib/outline.ts
|
|
@@ -90,6 +335,25 @@ function formatOnPage(vocabulary, page) {
|
|
|
90
335
|
return vocabulary.onPage.replace("{page}", String(page));
|
|
91
336
|
}
|
|
92
337
|
//#endregion
|
|
338
|
+
//#region src/app/lib/source-loc.ts
|
|
339
|
+
/**
|
|
340
|
+
* In dev, `loc-tags-plugin` stamps `data-od-loc` onto the call site of a
|
|
341
|
+
* framework component that forwards it. The component puts it back on the
|
|
342
|
+
* host that prints the call site's words, so the inspector can select what it
|
|
343
|
+
* rendered — a table, a caption, a footnote — and find the source behind it.
|
|
344
|
+
* `data-od-prop` says which attribute of the call site those words come from.
|
|
345
|
+
*/
|
|
346
|
+
const LOC_PROP = "data-od-loc";
|
|
347
|
+
const PROP_ATTR = "data-od-prop";
|
|
348
|
+
/** The attributes pointing a host back at its call site; nothing outside dev. */
|
|
349
|
+
function sourceAttrs(loc, prop) {
|
|
350
|
+
if (!loc) return {};
|
|
351
|
+
return prop ? {
|
|
352
|
+
[LOC_PROP]: loc,
|
|
353
|
+
[PROP_ATTR]: prop
|
|
354
|
+
} : { [LOC_PROP]: loc };
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
93
357
|
//#region src/app/components/footnote.tsx
|
|
94
358
|
/** Stands in for a number the scan has not produced yet, or never will. */
|
|
95
359
|
const UNNUMBERED = "•";
|
|
@@ -388,6 +652,172 @@ function ListOfTables(props) {
|
|
|
388
652
|
});
|
|
389
653
|
}
|
|
390
654
|
//#endregion
|
|
655
|
+
//#region src/app/components/chart.tsx
|
|
656
|
+
const ACCENT = "var(--od-accent, #2563eb)";
|
|
657
|
+
const TEXT = "var(--od-text, #16181d)";
|
|
658
|
+
const MUTED = "var(--od-muted, #6b7280)";
|
|
659
|
+
const RULE = "var(--od-rule, #e5e7eb)";
|
|
660
|
+
const FONT = "var(--od-font-body, sans-serif)";
|
|
661
|
+
/**
|
|
662
|
+
* The accent first, then tints and shades of it and of the text colour, so a
|
|
663
|
+
* chart takes on the document's palette and changes with it — the same reason
|
|
664
|
+
* the diagram renderer draws in `--od-*` variables rather than its own colours.
|
|
665
|
+
*/
|
|
666
|
+
const SERIES = [
|
|
667
|
+
ACCENT,
|
|
668
|
+
`color-mix(in srgb, ${ACCENT} 45%, #ffffff)`,
|
|
669
|
+
`color-mix(in srgb, ${TEXT} 55%, #ffffff)`,
|
|
670
|
+
`color-mix(in srgb, ${ACCENT} 70%, #000000)`,
|
|
671
|
+
`color-mix(in srgb, ${TEXT} 28%, #ffffff)`,
|
|
672
|
+
`color-mix(in srgb, ${ACCENT} 22%, #ffffff)`
|
|
673
|
+
];
|
|
674
|
+
function colorOf(series, colors) {
|
|
675
|
+
return colors?.[series] ?? SERIES[series % SERIES.length] ?? ACCENT;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* A bar, line or pie chart drawn from data, in the document's own colours and
|
|
679
|
+
* type. It lays itself out synchronously into a fixed box, so it measures as
|
|
680
|
+
* it prints; the Word export places it as a picture.
|
|
681
|
+
*/
|
|
682
|
+
function Chart({ type = "bar", data, x, y, labels, stacked, format, values, colors, width = 560, height = type === "pie" ? 220 : 260, caption, captionText, kind = "figure", id, style, className }) {
|
|
683
|
+
const keys = Array.isArray(y) ? y : [y];
|
|
684
|
+
const chart = layoutChart({
|
|
685
|
+
type,
|
|
686
|
+
data,
|
|
687
|
+
x,
|
|
688
|
+
y: keys,
|
|
689
|
+
width,
|
|
690
|
+
height,
|
|
691
|
+
...labels ? { labels } : {},
|
|
692
|
+
...stacked ? { stacked } : {},
|
|
693
|
+
...format ? { format } : {},
|
|
694
|
+
...values ? { values } : {}
|
|
695
|
+
});
|
|
696
|
+
const text = {
|
|
697
|
+
fontFamily: FONT,
|
|
698
|
+
fontSize: 10
|
|
699
|
+
};
|
|
700
|
+
const summary = captionText ?? (typeof caption === "string" ? caption : `${type} chart of ${keys.join(", ")}`);
|
|
701
|
+
const drawing = /* @__PURE__ */ jsxs("svg", {
|
|
702
|
+
viewBox: `0 0 ${chart.width} ${chart.height}`,
|
|
703
|
+
width: chart.width,
|
|
704
|
+
height: chart.height,
|
|
705
|
+
role: "img",
|
|
706
|
+
"aria-label": summary,
|
|
707
|
+
style: {
|
|
708
|
+
display: "block",
|
|
709
|
+
maxWidth: "100%",
|
|
710
|
+
height: "auto",
|
|
711
|
+
margin: "0 auto",
|
|
712
|
+
...caption ? void 0 : style
|
|
713
|
+
},
|
|
714
|
+
className: caption ? void 0 : className,
|
|
715
|
+
children: [
|
|
716
|
+
chart.ticks.map((tick) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
717
|
+
x1: chart.plot.x,
|
|
718
|
+
x2: chart.plot.x + chart.plot.width,
|
|
719
|
+
y1: tick.at,
|
|
720
|
+
y2: tick.at,
|
|
721
|
+
style: { stroke: RULE },
|
|
722
|
+
strokeWidth: 1
|
|
723
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
724
|
+
x: chart.plot.x - 6,
|
|
725
|
+
y: tick.at + 3.5,
|
|
726
|
+
textAnchor: "end",
|
|
727
|
+
style: {
|
|
728
|
+
...text,
|
|
729
|
+
fill: MUTED
|
|
730
|
+
},
|
|
731
|
+
children: tick.label
|
|
732
|
+
})] }, tick.value)),
|
|
733
|
+
chart.bars.map((bar) => /* @__PURE__ */ jsx("rect", {
|
|
734
|
+
x: bar.x,
|
|
735
|
+
y: bar.y,
|
|
736
|
+
width: bar.width,
|
|
737
|
+
height: bar.height,
|
|
738
|
+
style: { fill: colorOf(bar.series, colors) }
|
|
739
|
+
}, `${bar.series}-${bar.x}-${bar.y}`)),
|
|
740
|
+
chart.baseline !== null && chart.bars.length > 0 && /* @__PURE__ */ jsx("line", {
|
|
741
|
+
x1: chart.plot.x,
|
|
742
|
+
x2: chart.plot.x + chart.plot.width,
|
|
743
|
+
y1: chart.baseline,
|
|
744
|
+
y2: chart.baseline,
|
|
745
|
+
style: { stroke: MUTED },
|
|
746
|
+
strokeWidth: 1
|
|
747
|
+
}),
|
|
748
|
+
chart.lines.map((line) => /* @__PURE__ */ jsxs("g", {
|
|
749
|
+
style: { stroke: colorOf(line.series, colors) },
|
|
750
|
+
children: [/* @__PURE__ */ jsx("polyline", {
|
|
751
|
+
points: line.points.map((point) => `${point.x},${point.y}`).join(" "),
|
|
752
|
+
fill: "none",
|
|
753
|
+
strokeWidth: 2,
|
|
754
|
+
strokeLinejoin: "round"
|
|
755
|
+
}), line.points.map((point) => /* @__PURE__ */ jsx("circle", {
|
|
756
|
+
cx: point.x,
|
|
757
|
+
cy: point.y,
|
|
758
|
+
r: 3,
|
|
759
|
+
strokeWidth: 1.5,
|
|
760
|
+
style: { fill: "var(--od-bg, #ffffff)" }
|
|
761
|
+
}, point.x))]
|
|
762
|
+
}, line.series)),
|
|
763
|
+
chart.slices.map((slice) => /* @__PURE__ */ jsx("path", {
|
|
764
|
+
d: slice.path,
|
|
765
|
+
style: {
|
|
766
|
+
fill: colorOf(slice.series, colors),
|
|
767
|
+
stroke: "var(--od-bg, #ffffff)"
|
|
768
|
+
},
|
|
769
|
+
strokeWidth: 1.5
|
|
770
|
+
}, slice.series)),
|
|
771
|
+
chart.categories.map((category) => /* @__PURE__ */ jsx("text", {
|
|
772
|
+
x: category.x,
|
|
773
|
+
y: chart.plot.y + chart.plot.height + 15,
|
|
774
|
+
textAnchor: "middle",
|
|
775
|
+
style: {
|
|
776
|
+
...text,
|
|
777
|
+
fill: MUTED
|
|
778
|
+
},
|
|
779
|
+
children: category.text
|
|
780
|
+
}, category.x)),
|
|
781
|
+
chart.values.map((value) => /* @__PURE__ */ jsx("text", {
|
|
782
|
+
x: value.x,
|
|
783
|
+
y: value.y,
|
|
784
|
+
textAnchor: value.anchor,
|
|
785
|
+
style: {
|
|
786
|
+
...text,
|
|
787
|
+
fill: chart.slices.length > 0 ? "#ffffff" : TEXT
|
|
788
|
+
},
|
|
789
|
+
children: value.text
|
|
790
|
+
}, `${value.x}-${value.y}-${value.text}`)),
|
|
791
|
+
chart.legend.map((item) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
|
|
792
|
+
x: item.x,
|
|
793
|
+
y: item.y - 8,
|
|
794
|
+
width: 9,
|
|
795
|
+
height: 9,
|
|
796
|
+
rx: 2,
|
|
797
|
+
style: { fill: colorOf(item.series, colors) }
|
|
798
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
799
|
+
x: item.x + 14,
|
|
800
|
+
y: item.y,
|
|
801
|
+
style: {
|
|
802
|
+
...text,
|
|
803
|
+
fill: TEXT
|
|
804
|
+
},
|
|
805
|
+
children: item.name
|
|
806
|
+
})] }, item.series))
|
|
807
|
+
]
|
|
808
|
+
});
|
|
809
|
+
if (!caption) return drawing;
|
|
810
|
+
return /* @__PURE__ */ jsx(Figure, {
|
|
811
|
+
...id ? { id } : {},
|
|
812
|
+
caption,
|
|
813
|
+
...captionText ? { captionText } : {},
|
|
814
|
+
kind,
|
|
815
|
+
className,
|
|
816
|
+
...style ? { style } : {},
|
|
817
|
+
children: drawing
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
//#endregion
|
|
391
821
|
//#region src/app/components/data-table.tsx
|
|
392
822
|
function normalizeColumn(column) {
|
|
393
823
|
return typeof column === "string" ? { key: column } : column;
|
|
@@ -501,6 +931,15 @@ function DataTable({ rows, columns, caption, id, limit, compact = false, emptyVa
|
|
|
501
931
|
//#endregion
|
|
502
932
|
//#region src/app/components/diagram.tsx
|
|
503
933
|
/**
|
|
934
|
+
* The compiled SVG carries its natural size as `width`/`height`, which pins it
|
|
935
|
+
* there whatever box holds it — a `width` prop or a narrow column then only
|
|
936
|
+
* shrinks the box while the drawing runs past it. Without them the viewBox
|
|
937
|
+
* scales the drawing to the box, its height following the aspect ratio.
|
|
938
|
+
*/
|
|
939
|
+
function fluid(svg) {
|
|
940
|
+
return svg.replace(/^<svg([^>]*?) width="[^"]*" height="[^"]*"/, "<svg$1");
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
504
943
|
* A diagram compiled from Mermaid-flavoured text at build time. The SVG is
|
|
505
944
|
* inlined rather than referenced through `<img>` so it inherits the document's
|
|
506
945
|
* theme variables — an `<img src="data:…">` would be painted in a document of
|
|
@@ -516,7 +955,7 @@ function Diagram({ chart, caption, captionText, kind = "figure", id, width, alig
|
|
|
516
955
|
marginRight: align === "center" ? "auto" : void 0,
|
|
517
956
|
...caption ? void 0 : style
|
|
518
957
|
},
|
|
519
|
-
dangerouslySetInnerHTML: { __html: chart.svg }
|
|
958
|
+
dangerouslySetInnerHTML: { __html: fluid(chart.svg) }
|
|
520
959
|
});
|
|
521
960
|
if (!caption) return drawing;
|
|
522
961
|
return /* @__PURE__ */ jsx(Figure, {
|
|
@@ -694,4 +1133,4 @@ function paginateBlocks(blocks, available, opts = {}) {
|
|
|
694
1133
|
};
|
|
695
1134
|
}
|
|
696
1135
|
//#endregion
|
|
697
|
-
export { DEFAULT_ORIENTATION, DEFAULT_PAGE_SIZE, DataTable, Diagram, DiagramSyntaxError, Figure, Footnote, Footnotes, ImagePlaceholder, ListOf, ListOfFigures, ListOfTables, ORIENTATIONS, PAGE_SIZES, PAGE_SIZE_NAMES, Ref, TableOfContents, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, isOrientation, isPageSizeName, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber };
|
|
1136
|
+
export { Chart, DEFAULT_ORIENTATION, DEFAULT_PAGE_SIZE, DataTable, Diagram, DiagramSyntaxError, Figure, Footnote, Footnotes, ImagePlaceholder, ListOf, ListOfFigures, ListOfTables, ORIENTATIONS, PAGE_SIZES, PAGE_SIZE_NAMES, Ref, TableOfContents, compileDiagram, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, isOrientation, isPageSizeName, paginateBlocks, parseDelimited, resolvePageGeometry, useDocLabel, useDocLabels, useDocOutline, useDocPageCount, useDocPageNumber };
|
package/dist/ops/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { c as ExportFormat, d as Orientation, h as PageSizeName, p as PAGE_SIZE_NAMES, s as EXPORT_FORMATS, u as ORIENTATIONS } from "../sdk-
|
|
1
|
+
import { c as ExportFormat, d as Orientation, h as PageSizeName, p as PAGE_SIZE_NAMES, s as EXPORT_FORMATS, u as ORIENTATIONS } from "../sdk-CpDEGRIo.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
2
3
|
import "vite";
|
|
3
4
|
//#region src/vite/routes/context.d.ts
|
|
4
5
|
type ApiContext = {
|
|
@@ -24,6 +25,75 @@ type ApiPluginOptions = {
|
|
|
24
25
|
};
|
|
25
26
|
declare function makeContext(opts: ApiPluginOptions): ApiContext;
|
|
26
27
|
//#endregion
|
|
28
|
+
//#region src/app/lib/diagnostics.d.ts
|
|
29
|
+
type LayoutRule = 'unresolved-ref' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
|
|
30
|
+
type LayoutSeverity = 'error' | 'warn';
|
|
31
|
+
type LayoutFinding = {
|
|
32
|
+
/** 1-based sheet the problem is on. */
|
|
33
|
+
page: number;
|
|
34
|
+
rule: LayoutRule;
|
|
35
|
+
severity: LayoutSeverity;
|
|
36
|
+
message: string;
|
|
37
|
+
/** Tag plus a text snippet, so the caller can recognise the element. */
|
|
38
|
+
element?: string;
|
|
39
|
+
/** `line:column` in the document source, from the inspector's `data-od-loc`. */
|
|
40
|
+
loc?: string;
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/render/session.d.ts
|
|
44
|
+
/** Where two pictures of a sheet differ, in the pictures' own pixels. */
|
|
45
|
+
type ImageDiff = {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
/** Share of pixels that changed, 0–1. */
|
|
49
|
+
changed: number;
|
|
50
|
+
boxes: Array<{
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/ops/diff-pages.d.ts
|
|
59
|
+
type LineChange = {
|
|
60
|
+
op: 'same' | 'add' | 'remove';
|
|
61
|
+
text: string;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/ops/diff.d.ts
|
|
65
|
+
type PageStatus = 'same' | 'changed' | 'added' | 'removed';
|
|
66
|
+
type PageChange = {
|
|
67
|
+
status: PageStatus;
|
|
68
|
+
/** 1-based page in the old version, or null for a new page. */
|
|
69
|
+
before: number | null;
|
|
70
|
+
/** 1-based page in the new version, or null for a page that went away. */
|
|
71
|
+
after: number | null;
|
|
72
|
+
/** Lines added and removed, in reading order; empty for an unchanged page. */
|
|
73
|
+
lines: LineChange[];
|
|
74
|
+
/** Changed regions on the new page (or the old one, for a removed page), in CSS px. */
|
|
75
|
+
boxes: ImageDiff['boxes'];
|
|
76
|
+
};
|
|
77
|
+
type DiffResult = {
|
|
78
|
+
docId: string;
|
|
79
|
+
/** The revision compared against, as given and as resolved. */
|
|
80
|
+
since: string;
|
|
81
|
+
commit: string;
|
|
82
|
+
pages: PageChange[];
|
|
83
|
+
/** The report, relative to the workspace root. */
|
|
84
|
+
file: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* What changed in a document since a revision, page by page: the old and new
|
|
88
|
+
* sheets rendered through the same print pipeline as an export, paired by
|
|
89
|
+
* content, compared as pictures and as text, and written up as a report a
|
|
90
|
+
* reviewer can read without the source.
|
|
91
|
+
*/
|
|
92
|
+
declare function diffDocument(ctx: ApiContext, docId: string, opts?: {
|
|
93
|
+
since?: string;
|
|
94
|
+
outDir?: string;
|
|
95
|
+
}): Promise<DiffResult>;
|
|
96
|
+
//#endregion
|
|
27
97
|
//#region src/ops/documents.d.ts
|
|
28
98
|
/**
|
|
29
99
|
* Operations shared by the dev API and the MCP server. Everything here takes an
|
|
@@ -111,21 +181,6 @@ declare function slugify(value: string, fallback?: string): string;
|
|
|
111
181
|
*/
|
|
112
182
|
declare function importMarkdown(ctx: ApiContext, opts: ImportMarkdownOptions): Promise<ImportResult>;
|
|
113
183
|
//#endregion
|
|
114
|
-
//#region src/app/lib/diagnostics.d.ts
|
|
115
|
-
type LayoutRule = 'unresolved-ref' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
|
|
116
|
-
type LayoutSeverity = 'error' | 'warn';
|
|
117
|
-
type LayoutFinding = {
|
|
118
|
-
/** 1-based sheet the problem is on. */
|
|
119
|
-
page: number;
|
|
120
|
-
rule: LayoutRule;
|
|
121
|
-
severity: LayoutSeverity;
|
|
122
|
-
message: string;
|
|
123
|
-
/** Tag plus a text snippet, so the caller can recognise the element. */
|
|
124
|
-
element?: string;
|
|
125
|
-
/** `line:column` in the document source, from the inspector's `data-od-loc`. */
|
|
126
|
-
loc?: string;
|
|
127
|
-
};
|
|
128
|
-
//#endregion
|
|
129
184
|
//#region src/ops/layout.d.ts
|
|
130
185
|
type LayoutReport = {
|
|
131
186
|
docId: string;
|
|
@@ -290,4 +345,4 @@ declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: stri
|
|
|
290
345
|
id: string;
|
|
291
346
|
}>;
|
|
292
347
|
//#endregion
|
|
293
|
-
export { type ApiContext, type AssetSummary, type DocumentSummary, EXPORT_FORMATS, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, ORIENTATIONS, OpsError, type Orientation, PAGE_SIZE_NAMES, type PageSizeName, type ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText, writeTexts };
|
|
348
|
+
export { type ApiContext, type AssetSummary, type DiffResult, type DocumentSummary, EXPORT_FORMATS, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, ORIENTATIONS, OpsError, type Orientation, PAGE_SIZE_NAMES, type PageChange, type PageSizeName, type PageStatus, type ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText, writeTexts };
|
package/dist/ops/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { i as ORIENTATIONS, o as PAGE_SIZE_NAMES, r as EXPORT_FORMATS } from "../sdk-CqNZzbkz.js";
|
|
2
|
-
import { O as makeContext,
|
|
3
|
-
import { a as listAssets, c as readTheme, d as closeRenderSession, f as exportDocument, h as slugify, i as findAssetUsages, l as writeAsset, m as importMarkdown, n as deleteAsset, o as listFolders, p as renderDocPage, r as fileDocument, s as listThemes, t as createFolder, u as checkLayout } from "../ops-
|
|
4
|
-
export { EXPORT_FORMATS, ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText, writeTexts };
|
|
2
|
+
import { O as makeContext, _ as writeDocument, a as writeText, c as createDocument, d as duplicateDocument, f as listDocIds, g as resolveEntry, h as renameDocument, i as readText, l as deleteDocument, m as readDocument, o as writeTexts, p as listDocuments, r as addComment, s as OpsError, u as docDir } from "../config-CvzpyAUA.js";
|
|
3
|
+
import { a as listAssets, c as readTheme, d as closeRenderSession, f as exportDocument, g as diffDocument, h as slugify, i as findAssetUsages, l as writeAsset, m as importMarkdown, n as deleteAsset, o as listFolders, p as renderDocPage, r as fileDocument, s as listThemes, t as createFolder, u as checkLayout } from "../ops-DKidjLXP.js";
|
|
4
|
+
export { EXPORT_FORMATS, ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText, writeTexts };
|