@open-document/core 0.2.0 → 0.4.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/README.md +1 -0
- package/README.zh-TW.md +1 -0
- package/dist/{build-U81g9Hnk.js → build-BzhYQKev.js} +1 -1
- package/dist/check-CCAaXofH.js +42 -0
- package/dist/cli/bin.js +45 -12
- package/dist/config-CNr8hd5X.js +2461 -0
- package/dist/{config-CSC5lHsR.d.ts → config-P61niZMf.d.ts} +6 -0
- package/dist/context-CJpdjYfU.js +15 -0
- package/dist/{dev-DwwFT6uX.js → dev-BhXgunme.js} +1 -1
- package/dist/diagram-xlVDekYk.js +763 -0
- package/dist/export-B69kDkyp.js +36 -0
- package/dist/import-DBhCpUsl.js +26 -0
- package/dist/index.d.ts +236 -91
- package/dist/index.js +516 -88
- package/dist/ops/index.d.ts +96 -1
- package/dist/ops/index.js +4 -199
- package/dist/ops-BCBmRMCS.js +1275 -0
- package/dist/{preview-C_jbySle.js → preview-Da4Aq9yF.js} +1 -1
- package/dist/sdk-C9nl30dW.d.ts +129 -0
- package/dist/sdk-DhcqZdAw.js +50 -0
- package/dist/vite/index.d.ts +7 -1
- package/dist/vite/index.js +1 -2
- package/env.d.ts +33 -1
- package/package.json +10 -1
- package/skills/create-doc/SKILL.md +7 -3
- package/skills/create-theme/SKILL.md +1 -1
- package/skills/doc-authoring/SKILL.md +86 -6
- package/skills/doc-authoring/references/long-form.md +131 -0
- package/skills/doc-authoring/references/pagination.md +2 -1
- package/src/app/components/data-table.tsx +196 -0
- package/src/app/components/diagram.tsx +76 -0
- package/src/app/components/flow-page.tsx +20 -3
- package/src/app/components/footnote.tsx +196 -0
- package/src/app/components/numbering.tsx +208 -0
- package/src/app/components/themes/theme-preview.tsx +2 -2
- package/src/app/lib/agent-bridge.ts +128 -0
- package/src/app/lib/diagnostics.ts +282 -0
- package/src/app/lib/export-html.ts +35 -11
- package/src/app/lib/export-pdf.ts +54 -19
- package/src/app/lib/flow-measure.ts +100 -31
- package/src/app/lib/flow.test.ts +46 -0
- package/src/app/lib/flow.ts +28 -3
- package/src/app/lib/footnotes.test.tsx +102 -0
- package/src/app/lib/footnotes.ts +94 -0
- package/src/app/lib/labels.ts +175 -0
- package/src/app/lib/page-context.tsx +6 -1
- package/src/app/lib/scan.ts +26 -0
- package/src/app/lib/sdk.test.ts +15 -9
- package/src/app/lib/sdk.ts +37 -11
- package/src/app/lib/use-doc-pages.ts +50 -15
- package/src/app/routes/doc.tsx +158 -115
- package/dist/config-8zkUElGq.js +0 -1169
- package/dist/design-IyRSwCtK.js +0 -52
- package/dist/edit-ops-D2W2plpc.js +0 -1190
package/src/app/routes/doc.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import appConfig from 'virtual:open-doc/config';
|
|
1
2
|
import {
|
|
2
3
|
ArrowLeft,
|
|
3
4
|
Check,
|
|
@@ -21,11 +22,14 @@ import { DesignProvider } from '../components/design-panel/design-provider';
|
|
|
21
22
|
import { DocSidebar } from '../components/doc-sidebar';
|
|
22
23
|
import { Inspector } from '../components/inspector/inspector';
|
|
23
24
|
import { PageFrame } from '../components/page-frame';
|
|
25
|
+
import { ThemeToggle } from '../components/theme-toggle';
|
|
24
26
|
import { Menu, MenuItem } from '../components/ui/menu';
|
|
27
|
+
import { useAgentBridge } from '../lib/agent-bridge';
|
|
25
28
|
import { exportDocAsHtml } from '../lib/export-html';
|
|
26
29
|
import { exportDocAsPdf } from '../lib/export-pdf';
|
|
27
|
-
import {
|
|
30
|
+
import { type OutlineEntry, useDocOutline } from '../lib/outline';
|
|
28
31
|
import { nextFrame, waitForFonts } from '../lib/print-ready';
|
|
32
|
+
import { scanDocument } from '../lib/scan';
|
|
29
33
|
import { resolvePageGeometry } from '../lib/sdk';
|
|
30
34
|
import { useDocModule } from '../lib/use-doc-module';
|
|
31
35
|
import { useDocPages } from '../lib/use-doc-pages';
|
|
@@ -50,6 +54,34 @@ const MIN_SCALE = 0.25;
|
|
|
50
54
|
const MAX_SCALE = 2;
|
|
51
55
|
const PAGE_GAP = 24;
|
|
52
56
|
|
|
57
|
+
const BACK_CLASS =
|
|
58
|
+
'flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* `config.home` leaves the router on purpose. A `<Link>` resolves inside the
|
|
62
|
+
* app's basename, which is exactly wrong when the viewer is mounted under a
|
|
63
|
+
* larger site and "back" means that site.
|
|
64
|
+
*
|
|
65
|
+
* With no `home` and no document browser there is nowhere to go: `/` renders
|
|
66
|
+
* "not found". A control that leads nowhere is worse than no control, and a
|
|
67
|
+
* host that mounts the viewer this way is providing its own way back.
|
|
68
|
+
*/
|
|
69
|
+
const HeaderBackLink = () => {
|
|
70
|
+
if (appConfig.home !== undefined) {
|
|
71
|
+
return (
|
|
72
|
+
<a href={appConfig.home} className={BACK_CLASS} aria-label="Back to workspace">
|
|
73
|
+
<ArrowLeft className="size-4" />
|
|
74
|
+
</a>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (!appConfig.build.showDocBrowser) return null;
|
|
78
|
+
return (
|
|
79
|
+
<Link to="/" className={BACK_CLASS} aria-label="Back to documents">
|
|
80
|
+
<ArrowLeft className="size-4" />
|
|
81
|
+
</Link>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
53
85
|
export function Doc() {
|
|
54
86
|
const { docId } = useParams<{ docId: string }>();
|
|
55
87
|
const state = useDocModule(docId);
|
|
@@ -71,9 +103,11 @@ export function Doc() {
|
|
|
71
103
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
72
104
|
|
|
73
105
|
const geometry = useMemo(() => resolvePageGeometry(doc?.meta), [doc?.meta]);
|
|
74
|
-
const { pages, measuring } = useDocPages(doc, geometry);
|
|
106
|
+
const { pages, measuring, overflowing } = useDocPages(doc, geometry);
|
|
75
107
|
const outline = useDocOutline();
|
|
76
108
|
|
|
109
|
+
useAgentBridge({ docId: docId ?? '', doc, pages, geometry, measuring, oversized: overflowing });
|
|
110
|
+
|
|
77
111
|
const clamp = (value: number) => Math.max(MIN_SCALE, Math.min(MAX_SCALE, value));
|
|
78
112
|
const fitWidthScale = available.width ? clamp(available.width / geometry.width) : 1;
|
|
79
113
|
// Fit page is bounded by both axes so the whole sheet lands inside the pane.
|
|
@@ -108,7 +142,6 @@ export function Doc() {
|
|
|
108
142
|
// Headings only exist once the pages are in the DOM at their final metrics,
|
|
109
143
|
// so the scan waits for fonts — a late-loading face reflows headings and
|
|
110
144
|
// would otherwise strand the outline on stale text.
|
|
111
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: `doc` re-scans on hot reload, when the module identity changes but the status stays 'ready'.
|
|
112
145
|
useEffect(() => {
|
|
113
146
|
if (state.status !== 'ready' || measuring) return;
|
|
114
147
|
let cancelled = false;
|
|
@@ -118,7 +151,7 @@ export function Doc() {
|
|
|
118
151
|
await nextFrame();
|
|
119
152
|
const root = pagesRef.current;
|
|
120
153
|
if (cancelled || !root) return;
|
|
121
|
-
|
|
154
|
+
scanDocument(root, doc?.meta);
|
|
122
155
|
})();
|
|
123
156
|
return () => {
|
|
124
157
|
cancelled = true;
|
|
@@ -277,129 +310,134 @@ export function Doc() {
|
|
|
277
310
|
|
|
278
311
|
const view = (
|
|
279
312
|
<div ref={rootRef} className="flex h-screen flex-col bg-background text-foreground">
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
<h1 className="truncate font-medium text-sm">{doc.meta?.title ?? docId}</h1>
|
|
290
|
-
{doc.meta?.subtitle && (
|
|
291
|
-
<p className="truncate text-muted-foreground text-xs">{doc.meta.subtitle}</p>
|
|
292
|
-
)}
|
|
313
|
+
{/* Equal `1fr` rails put the title at the true centre of the bar rather
|
|
314
|
+
than the centre of what is left over, which is where a flex row would
|
|
315
|
+
drop it — the control cluster is many times wider than the back link.
|
|
316
|
+
The control rail keeps its automatic minimum — no `min-w-0` — so when
|
|
317
|
+
it outgrows its share the title truncates and slides instead of being
|
|
318
|
+
overlapped by it. */}
|
|
319
|
+
<header className="grid h-12 flex-none grid-cols-[1fr_minmax(0,auto)_1fr] items-center gap-3 border-b border-border px-3">
|
|
320
|
+
<div className="flex min-w-0 items-center">
|
|
321
|
+
<HeaderBackLink />
|
|
293
322
|
</div>
|
|
294
323
|
|
|
295
|
-
<
|
|
296
|
-
|
|
297
|
-
|
|
324
|
+
<h1 className="truncate text-center font-medium text-sm">{doc.meta?.title ?? docId}</h1>
|
|
325
|
+
|
|
326
|
+
<div className="flex items-center justify-end gap-3">
|
|
327
|
+
<span className="hidden whitespace-nowrap font-mono text-muted-foreground text-xs tabular-nums sm:inline">
|
|
328
|
+
{currentPage} / {pages.length}
|
|
329
|
+
</span>
|
|
330
|
+
|
|
331
|
+
<div className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
332
|
+
<IconButton label="Zoom out" onClick={() => zoom(-0.1)}>
|
|
333
|
+
<Minus className="size-3.5" />
|
|
334
|
+
</IconButton>
|
|
335
|
+
<button
|
|
336
|
+
type="button"
|
|
337
|
+
onClick={actualSize}
|
|
338
|
+
title="Actual size (100%)"
|
|
339
|
+
className="w-11 rounded text-center font-mono text-[11px] tabular-nums transition-colors hover:bg-accent"
|
|
340
|
+
>
|
|
341
|
+
{Math.round(scale * 100)}%
|
|
342
|
+
</button>
|
|
343
|
+
<IconButton label="Zoom in" onClick={() => zoom(0.1)}>
|
|
344
|
+
<Plus className="size-3.5" />
|
|
345
|
+
</IconButton>
|
|
346
|
+
<IconButton
|
|
347
|
+
label="Fit width"
|
|
348
|
+
onClick={() => fitTo('fit-width')}
|
|
349
|
+
active={manualScale === null && zoomMode === 'fit-width'}
|
|
350
|
+
>
|
|
351
|
+
<MoveHorizontal className="size-3.5" />
|
|
352
|
+
</IconButton>
|
|
353
|
+
<IconButton
|
|
354
|
+
label="Fit page"
|
|
355
|
+
onClick={() => fitTo('fit-page')}
|
|
356
|
+
active={manualScale === null && zoomMode === 'fit-page'}
|
|
357
|
+
>
|
|
358
|
+
<Scan className="size-3.5" />
|
|
359
|
+
</IconButton>
|
|
360
|
+
</div>
|
|
298
361
|
|
|
299
|
-
<div className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
300
|
-
<IconButton label="Zoom out" onClick={() => zoom(-0.1)}>
|
|
301
|
-
<Minus className="size-3.5" />
|
|
302
|
-
</IconButton>
|
|
303
|
-
<button
|
|
304
|
-
type="button"
|
|
305
|
-
onClick={actualSize}
|
|
306
|
-
title="Actual size (100%)"
|
|
307
|
-
className="w-11 rounded text-center font-mono text-[11px] tabular-nums transition-colors hover:bg-accent"
|
|
308
|
-
>
|
|
309
|
-
{Math.round(scale * 100)}%
|
|
310
|
-
</button>
|
|
311
|
-
<IconButton label="Zoom in" onClick={() => zoom(0.1)}>
|
|
312
|
-
<Plus className="size-3.5" />
|
|
313
|
-
</IconButton>
|
|
314
|
-
<IconButton
|
|
315
|
-
label="Fit width"
|
|
316
|
-
onClick={() => fitTo('fit-width')}
|
|
317
|
-
active={manualScale === null && zoomMode === 'fit-width'}
|
|
318
|
-
>
|
|
319
|
-
<MoveHorizontal className="size-3.5" />
|
|
320
|
-
</IconButton>
|
|
321
362
|
<IconButton
|
|
322
|
-
label=
|
|
323
|
-
onClick={
|
|
324
|
-
active={manualScale === null && zoomMode === 'fit-page'}
|
|
363
|
+
label={isFullscreen ? 'Exit fullscreen (F)' : 'Fullscreen (F)'}
|
|
364
|
+
onClick={toggleFullscreen}
|
|
325
365
|
>
|
|
326
|
-
<
|
|
366
|
+
{isFullscreen ? <Minimize className="size-4" /> : <Maximize className="size-4" />}
|
|
327
367
|
</IconButton>
|
|
328
|
-
</div>
|
|
329
368
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
{import.meta.env.DEV && (
|
|
338
|
-
<button
|
|
339
|
-
type="button"
|
|
340
|
-
onClick={() => setInspecting((on) => !on)}
|
|
341
|
-
title="Inspect and edit on the page"
|
|
342
|
-
className={cn(
|
|
343
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
344
|
-
inspecting && 'border-transparent bg-[#3b82f6] text-white hover:bg-[#3b82f6]',
|
|
345
|
-
)}
|
|
346
|
-
>
|
|
347
|
-
<MousePointerClick className="size-3.5" />
|
|
348
|
-
Inspect
|
|
349
|
-
</button>
|
|
350
|
-
)}
|
|
351
|
-
{import.meta.env.DEV && (
|
|
352
|
-
<button
|
|
353
|
-
type="button"
|
|
354
|
-
onClick={() => setDesignOpen((open) => !open)}
|
|
355
|
-
className={cn(
|
|
356
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
357
|
-
designOpen && 'bg-accent',
|
|
358
|
-
)}
|
|
359
|
-
>
|
|
360
|
-
<Palette className="size-3.5" />
|
|
361
|
-
Design
|
|
362
|
-
</button>
|
|
363
|
-
)}
|
|
364
|
-
<Menu
|
|
365
|
-
trigger={(props) => (
|
|
369
|
+
{/* The document browser normally carries this. A viewer mounted with
|
|
370
|
+
`showDocBrowser: false` never shows that shell, and without it a
|
|
371
|
+
reader has no way to change the theme at all. */}
|
|
372
|
+
{!appConfig.build.showDocBrowser && <ThemeToggle />}
|
|
373
|
+
|
|
374
|
+
{import.meta.env.DEV && (
|
|
366
375
|
<button
|
|
367
376
|
type="button"
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
{
|
|
377
|
+
onClick={() => setInspecting((on) => !on)}
|
|
378
|
+
title="Inspect and edit on the page"
|
|
379
|
+
className={cn(
|
|
380
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
381
|
+
inspecting && 'border-transparent bg-[#3b82f6] text-white hover:bg-[#3b82f6]',
|
|
382
|
+
)}
|
|
371
383
|
>
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
384
|
+
<MousePointerClick className="size-3.5" />
|
|
385
|
+
Inspect
|
|
386
|
+
</button>
|
|
387
|
+
)}
|
|
388
|
+
{import.meta.env.DEV && (
|
|
389
|
+
<button
|
|
390
|
+
type="button"
|
|
391
|
+
onClick={() => setDesignOpen((open) => !open)}
|
|
392
|
+
className={cn(
|
|
393
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
394
|
+
designOpen && 'bg-accent',
|
|
378
395
|
)}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
396
|
+
>
|
|
397
|
+
<Palette className="size-3.5" />
|
|
398
|
+
Design
|
|
382
399
|
</button>
|
|
383
400
|
)}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
void runDownload(format);
|
|
392
|
-
}}
|
|
401
|
+
<Menu
|
|
402
|
+
trigger={(props) => (
|
|
403
|
+
<button
|
|
404
|
+
type="button"
|
|
405
|
+
disabled={download !== null}
|
|
406
|
+
className="flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
407
|
+
{...props}
|
|
393
408
|
>
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
<
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
409
|
+
{download ? (
|
|
410
|
+
<Loader2 className="size-3.5 animate-spin" />
|
|
411
|
+
) : downloaded ? (
|
|
412
|
+
<Check className="size-3.5" />
|
|
413
|
+
) : (
|
|
414
|
+
<Download className="size-3.5" />
|
|
415
|
+
)}
|
|
416
|
+
{download
|
|
417
|
+
? `${DOWNLOAD_LABEL[download.format]} ${Math.round(download.percent)}%`
|
|
418
|
+
: 'Download'}
|
|
419
|
+
</button>
|
|
420
|
+
)}
|
|
421
|
+
>
|
|
422
|
+
{(close) =>
|
|
423
|
+
DOWNLOAD_FORMATS.map(({ format, label, hint, icon: Icon }) => (
|
|
424
|
+
<MenuItem
|
|
425
|
+
key={format}
|
|
426
|
+
onClick={() => {
|
|
427
|
+
close();
|
|
428
|
+
void runDownload(format);
|
|
429
|
+
}}
|
|
430
|
+
>
|
|
431
|
+
<Icon className="size-3.5 flex-none" />
|
|
432
|
+
<span className="flex-1">
|
|
433
|
+
{label}
|
|
434
|
+
<span className="block text-[10px] text-muted-foreground">{hint}</span>
|
|
435
|
+
</span>
|
|
436
|
+
</MenuItem>
|
|
437
|
+
))
|
|
438
|
+
}
|
|
439
|
+
</Menu>
|
|
440
|
+
</div>
|
|
403
441
|
</header>
|
|
404
442
|
|
|
405
443
|
<div className="flex min-h-0 flex-1">
|
|
@@ -489,9 +527,14 @@ function Centered({ children }: { children: React.ReactNode }) {
|
|
|
489
527
|
}
|
|
490
528
|
|
|
491
529
|
function BackLink() {
|
|
492
|
-
|
|
493
|
-
|
|
530
|
+
const className = 'mt-4 inline-block text-muted-foreground text-xs underline';
|
|
531
|
+
return appConfig.home === undefined ? (
|
|
532
|
+
<Link to="/" className={className}>
|
|
494
533
|
Back to documents
|
|
495
534
|
</Link>
|
|
535
|
+
) : (
|
|
536
|
+
<a href={appConfig.home} className={className}>
|
|
537
|
+
Back to workspace
|
|
538
|
+
</a>
|
|
496
539
|
);
|
|
497
540
|
}
|