@open-document/core 0.9.0 → 0.9.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.
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-4nz5NnxW.js";
1
+ import { t as createViteConfig } from "./config-CAZ7Z_va.js";
2
2
  import path from "node:path";
3
3
  import { build as build$1, mergeConfig } from "vite";
4
4
  //#region src/cli/build.ts
@@ -1,6 +1,6 @@
1
- import { _ as listDocIds } from "./config-4nz5NnxW.js";
2
- import { d as closeRenderSession, u as checkLayout } from "./ops-OZZVBgsM.js";
3
- import { t as cliContext } from "./context-BH8C-dSW.js";
1
+ import { _ as listDocIds } from "./config-CAZ7Z_va.js";
2
+ import { d as closeRenderSession, u as checkLayout } from "./ops-B2y9BMpk.js";
3
+ import { t as cliContext } from "./context-PWAh9qbf.js";
4
4
  import chalk from "chalk";
5
5
  //#region src/cli/check.ts
6
6
  function line(finding) {
package/dist/cli/bin.js CHANGED
@@ -165,27 +165,27 @@ async function run(argv) {
165
165
  program.name("open-doc").description("Author documents — we handle the Vite/React stack, pagination, and export.").version(version, "-v, --version", "print version").helpOption("-h, --help", "show help").showHelpAfterError(chalk.dim("(run `open-doc --help` for usage)"));
166
166
  program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").option("--no-skills-check", "skip the built-in skills drift check").option("--mcp", "serve an MCP endpoint at /mcp (requires @open-document/mcp)").action(async (flags) => {
167
167
  if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
168
- const { dev } = await import("../dev-BCSUczXW.js");
168
+ const { dev } = await import("../dev-CYqppXDI.js");
169
169
  await dev(flags);
170
170
  });
171
171
  program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
172
- const { build } = await import("../build-CFL7nhz0.js");
172
+ const { build } = await import("../build-B0GJXy8I.js");
173
173
  await build(flags);
174
174
  });
175
175
  program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
176
- const { preview } = await import("../preview-CwCrw-i3.js");
176
+ const { preview } = await import("../preview-DW3PM-JV.js");
177
177
  await preview(flags);
178
178
  });
179
179
  program.command("export [docIds...]").description("Render documents headlessly to PDF, HTML, PNG, or DOCX").addOption(new Option("-f, --format <format>", "output format").choices([...EXPORT_FORMATS])).option("-o, --out-dir <dir>", "directory to write into (defaults to `out`)").option("--all", "export every document under docs/").action(async (docIds, flags) => {
180
- const { exportDocs } = await import("../export-CmVJdl9a.js");
180
+ const { exportDocs } = await import("../export-1JtO2OMC.js");
181
181
  await exportDocs(docIds, flags);
182
182
  });
183
183
  program.command("check [docIds...]").description("Report layout faults — clipped content, blank sheets, stranded headings").option("--json", "print the full report as JSON").action(async (docIds, flags) => {
184
- const { checkDocs } = await import("../check-CL0-0eB8.js");
184
+ const { checkDocs } = await import("../check-CuDIWsPT.js");
185
185
  await checkDocs(docIds, flags);
186
186
  });
187
187
  program.command("import <file>").description("Turn a Markdown file into a document under docs/").option("--id <id>", "document id (defaults to a slug of the title)").option("--title <title>", "override the title").option("--subtitle <subtitle>", "subtitle, also used as the cover eyebrow").option("--author <author>", "author line on the cover").option("--theme <theme>", "theme id to back-link from meta.theme").addOption(new Option("--page-size <size>", "page size").choices(PAGE_SIZE_NAMES)).addOption(new Option("--orientation <orientation>", "page orientation").choices(ORIENTATIONS)).option("--no-cover", "skip the title page").option("--contents", "add a self-filling contents page").action(async (file, flags) => {
188
- const { importDoc } = await import("../import-E6vRo7xm.js");
188
+ const { importDoc } = await import("../import-CsrdBOZ8.js");
189
189
  await importDoc(file, flags);
190
190
  });
191
191
  program.command("sync:skills").description("Sync built-in skills from @open-document/core into this workspace").option("--dry-run", "show what would change without writing").action(async (flags) => {
@@ -1,4 +1,4 @@
1
- import { a as defaultDesign, n as DiagramSyntaxError, r as parseDelimited, t as compileDiagram } from "./diagram-xlVDekYk.js";
1
+ import { a as defaultDesign, n as DiagramSyntaxError, r as parseDelimited, t as compileDiagram } from "./diagram-CCaUUnRe.js";
2
2
  import chalk from "chalk";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -1,5 +1,5 @@
1
1
  import { t as readCoreVersion } from "./cli/bin.js";
2
- import { A as loadUserConfig, O as makeContext } from "./config-4nz5NnxW.js";
2
+ import { A as loadUserConfig, O as makeContext } from "./config-CAZ7Z_va.js";
3
3
  //#region src/cli/context.ts
4
4
  /** The same context the dev API and the MCP server run on, for commands that call `ops/`. */
5
5
  async function cliContext(userCwd = process.cwd()) {
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-4nz5NnxW.js";
1
+ import { t as createViteConfig } from "./config-CAZ7Z_va.js";
2
2
  import { createServer, mergeConfig } from "vite";
3
3
  //#region src/cli/dev.ts
4
4
  async function dev(opts = {}) {
@@ -196,6 +196,7 @@ function sizeOf(node, lines, fontSize) {
196
196
  const textHeight = lines.length * fontSize * LINE_HEIGHT$1;
197
197
  let width = Math.max(MIN_WIDTH, textWidth + 28);
198
198
  let height = textHeight + 20;
199
+ if (node.shape === "cylinder") height += 12;
199
200
  if (node.shape === "diamond") {
200
201
  width = textWidth * 2 + 28;
201
202
  height = textHeight * 2 + 20;
@@ -359,6 +360,66 @@ function placeLabels(edges, fontSize) {
359
360
  edge.labelAt = chosen;
360
361
  }
361
362
  }
363
+ const CHANNEL_GAP = 18;
364
+ /**
365
+ * A link that runs against the flow — a feedback arrow back to an earlier
366
+ * step. Drawn straight, it would cut through every box between the two ends
367
+ * and park its label on one of them; it goes round the side instead (the
368
+ * right in a column, underneath in a row), clear of everything it passes, and
369
+ * each such link a step further out than the last.
370
+ */
371
+ function routeBack(from, to, nodes, horizontal, lane) {
372
+ if (horizontal) {
373
+ const left = Math.min(from.x, to.x);
374
+ const right = Math.max(from.x + from.width, to.x + to.width);
375
+ const passed = nodes.filter((n) => n.x < right && n.x + n.width > left);
376
+ const channel = Math.max(...passed.map((n) => n.y + n.height)) + CHANNEL_GAP * (lane + 1);
377
+ const start = {
378
+ x: from.x + from.width / 2,
379
+ y: from.y + from.height
380
+ };
381
+ const end = {
382
+ x: to.x + to.width / 2,
383
+ y: to.y + to.height
384
+ };
385
+ return [
386
+ start,
387
+ {
388
+ x: start.x,
389
+ y: channel
390
+ },
391
+ {
392
+ x: end.x,
393
+ y: channel
394
+ },
395
+ end
396
+ ];
397
+ }
398
+ const top = Math.min(from.y, to.y);
399
+ const bottom = Math.max(from.y + from.height, to.y + to.height);
400
+ const passed = nodes.filter((n) => n.y < bottom && n.y + n.height > top);
401
+ const channel = Math.max(...passed.map((n) => n.x + n.width)) + CHANNEL_GAP * (lane + 1);
402
+ const start = {
403
+ x: from.x + from.width,
404
+ y: from.y + from.height / 2
405
+ };
406
+ const end = {
407
+ x: to.x + to.width,
408
+ y: to.y + to.height / 2
409
+ };
410
+ return [
411
+ start,
412
+ {
413
+ x: channel,
414
+ y: start.y
415
+ },
416
+ {
417
+ x: channel,
418
+ y: end.y
419
+ },
420
+ end
421
+ ];
422
+ }
362
423
  /** Straight where the two boxes line up, a single elbow where they do not. */
363
424
  function route(from, to, horizontal) {
364
425
  const fromCentre = {
@@ -480,11 +541,12 @@ function layoutDiagram(diagram, options = {}) {
480
541
  });
481
542
  const byId = new Map(nodes.map((n) => [n.id, n]));
482
543
  const edges = [];
544
+ let lanes = 0;
483
545
  for (const edge of diagram.edges) {
484
546
  const from = byId.get(edge.from);
485
547
  const to = byId.get(edge.to);
486
548
  if (!from || !to) continue;
487
- const points = route(from, to, horizontal);
549
+ const points = (rankOf.get(edge.to) ?? 0) < (rankOf.get(edge.from) ?? 0) ? routeBack(from, to, nodes, horizontal, lanes++) : route(from, to, horizontal);
488
550
  edges.push({
489
551
  ...edge,
490
552
  points,
@@ -492,8 +554,13 @@ function layoutDiagram(diagram, options = {}) {
492
554
  });
493
555
  }
494
556
  placeLabels(edges, opts.fontSize);
495
- const width = Math.max(...nodes.map((n) => n.x + n.width)) + opts.padding;
496
- const height = Math.max(...nodes.map((n) => n.y + n.height)) + opts.padding;
557
+ const labelSize = opts.fontSize * .85;
558
+ const reach = edges.flatMap((edge) => [...edge.points, ...edge.labelAt && edge.label ? [{
559
+ x: edge.labelAt.x + (measureText(edge.label, labelSize) + 10) / 2,
560
+ y: edge.labelAt.y + labelSize * .8
561
+ }] : []]);
562
+ const width = Math.max(...nodes.map((n) => n.x + n.width), ...reach.map((p) => p.x)) + opts.padding;
563
+ const height = Math.max(...nodes.map((n) => n.y + n.height), ...reach.map((p) => p.y)) + opts.padding;
497
564
  return {
498
565
  direction: diagram.direction,
499
566
  nodes,
@@ -513,14 +580,15 @@ var DiagramSyntaxError = class extends Error {
513
580
  }
514
581
  };
515
582
  const HEADER_RE = /^(?:flowchart|graph)(?:\s+(TB|TD|BT|LR|RL))?$/i;
516
- /** `A[Label]`, `A(Label)`, `A([Label])`, `A{Label}`, `A((Label))`, or a bare `A`. */
517
- const NODE_RE = /^([A-Za-z0-9_.-]+)(?:(\(\(|\(\[|\[|\(|\{)([\s\S]*?)(\)\)|\]\)|\]|\)|\}))?$/;
583
+ /** `A[Label]`, `A(Label)`, `A([Label])`, `A[(Label)]`, `A{Label}`, `A((Label))`, or a bare `A`. */
584
+ const NODE_RE = /^([A-Za-z0-9_.-]+)(?:(\(\(|\(\[|\[\(|\[|\(|\{)([\s\S]*?)(\)\)|\]\)|\)\]|\]|\)|\}))?$/;
518
585
  const SHAPES = {
519
586
  "[": "rect",
520
587
  "(": "round",
521
588
  "([": "stadium",
522
589
  "{": "diamond",
523
- "((": "circle"
590
+ "((": "circle",
591
+ "[(": "cylinder"
524
592
  };
525
593
  /**
526
594
  * Links, longest first: `-.->` must be tried before `-->` or the dash prefix
@@ -695,11 +763,12 @@ function escapeXml(text) {
695
763
  * Every colour and face is a `--od-*` variable rather than a literal, which is
696
764
  * the entire reason this renderer exists: the drawing inherits the document's
697
765
  * theme, in the viewer and in the PDF, instead of arriving with a palette of
698
- * its own.
766
+ * its own. Each carries a fallback, since a document without a `design` sets
767
+ * none of them and an unset `fill` paints the shapes solid black.
699
768
  */
700
769
  function shapePath(node) {
701
770
  const { x, y, width: w, height: h } = node;
702
- const common = "fill=\"var(--od-bg)\" stroke=\"var(--od-text)\" stroke-width=\"1.25\"";
771
+ const common = "fill=\"var(--od-bg, #ffffff)\" stroke=\"var(--od-text, #16181d)\" stroke-width=\"1.25\"";
703
772
  switch (node.shape) {
704
773
  case "diamond": return `<polygon points="${[
705
774
  `${x + w / 2},${y}`,
@@ -709,6 +778,10 @@ function shapePath(node) {
709
778
  ].join(" ")}" ${common} />`;
710
779
  case "circle": return `<ellipse cx="${x + w / 2}" cy="${y + h / 2}" rx="${w / 2}" ry="${h / 2}" ${common} />`;
711
780
  case "stadium": return `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${h / 2}" ry="${h / 2}" ${common} />`;
781
+ case "cylinder": {
782
+ const ry = Math.min(8, h / 6);
783
+ return `<path d="${`M${x},${y + ry} A${w / 2},${ry} 0 0 1 ${x + w},${y + ry} L${x + w},${y + h - ry} A${w / 2},${ry} 0 0 1 ${x},${y + h - ry} Z`}" ${common} /><path d="${`M${x},${y + ry} A${w / 2},${ry} 0 0 0 ${x + w},${y + ry}`}" fill="none" stroke="var(--od-text, #16181d)" stroke-width="1.25" />`;
784
+ }
712
785
  case "round": return `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="10" ry="10" ${common} />`;
713
786
  default: return `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="var(--od-radius, 2)" ${common} />`;
714
787
  }
@@ -717,19 +790,19 @@ function nodeText(node, fontSize) {
717
790
  const firstBaseline = node.y + node.height / 2 - node.lines.length * fontSize * LINE_HEIGHT / 2 + fontSize * .98;
718
791
  return node.lines.map((line, i) => {
719
792
  const y = firstBaseline + i * fontSize * LINE_HEIGHT;
720
- return `<text x="${node.x + node.width / 2}" y="${y}" text-anchor="middle" font-family="var(--od-font-body)" font-size="${fontSize}" fill="var(--od-text)">${escapeXml(line)}</text>`;
793
+ return `<text x="${node.x + node.width / 2}" y="${y}" text-anchor="middle" font-family="var(--od-font-body, sans-serif)" font-size="${fontSize}" fill="var(--od-text, #16181d)">${escapeXml(line)}</text>`;
721
794
  }).join("");
722
795
  }
723
796
  function edgePath(edge, marker) {
724
797
  const d = edge.points.map((point, i) => `${i === 0 ? "M" : "L"}${round(point.x)},${round(point.y)}`).join(" ");
725
798
  const dash = edge.style === "dashed" ? " stroke-dasharray=\"5 4\"" : "";
726
- return `<path d="${d}" fill="none" stroke="var(--od-text)" stroke-width="${edge.style === "thick" ? 2.25 : 1.25}"${dash} stroke-linejoin="round"${edge.arrow ? ` marker-end="url(#${marker})"` : ""} />`;
799
+ return `<path d="${d}" fill="none" stroke="var(--od-text, #16181d)" stroke-width="${edge.style === "thick" ? 2.25 : 1.25}"${dash} stroke-linejoin="round"${edge.arrow ? ` marker-end="url(#${marker})"` : ""} />`;
727
800
  }
728
801
  function edgeLabel(edge, fontSize) {
729
802
  if (!edge.labelAt || !edge.label) return "";
730
803
  const size = fontSize * .85;
731
804
  const width = measureText(edge.label, size) + 10;
732
- return `<rect x="${round(edge.labelAt.x - width / 2)}" y="${round(edge.labelAt.y - size * .8)}" width="${round(width)}" height="${round(size * 1.6)}" fill="var(--od-bg)" /><text x="${round(edge.labelAt.x)}" y="${round(edge.labelAt.y + size * .34)}" text-anchor="middle" font-family="var(--od-font-body)" font-size="${size}" fill="var(--od-muted)">${escapeXml(edge.label)}</text>`;
805
+ return `<rect x="${round(edge.labelAt.x - width / 2)}" y="${round(edge.labelAt.y - size * .8)}" width="${round(width)}" height="${round(size * 1.6)}" fill="var(--od-bg, #ffffff)" /><text x="${round(edge.labelAt.x)}" y="${round(edge.labelAt.y + size * .34)}" text-anchor="middle" font-family="var(--od-font-body, sans-serif)" font-size="${size}" fill="var(--od-muted, #6b7280)">${escapeXml(edge.label)}</text>`;
733
806
  }
734
807
  function round(value) {
735
808
  return Math.round(value * 100) / 100;
@@ -737,7 +810,7 @@ function round(value) {
737
810
  function renderDiagram(diagram, options = {}) {
738
811
  const fontSize = options.fontSize ?? 13;
739
812
  const marker = `od-arrow${options.idSuffix ? `-${options.idSuffix}` : ""}`;
740
- const defs = `<defs><marker id="${marker}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,1 L10,5 L0,9 z" fill="var(--od-text)" /></marker></defs>`;
813
+ const defs = `<defs><marker id="${marker}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,1 L10,5 L0,9 z" fill="var(--od-text, #16181d)" /></marker></defs>`;
741
814
  const body = [
742
815
  ...diagram.edges.map((edge) => edgePath(edge, marker)),
743
816
  ...diagram.nodes.map((node) => shapePath(node)),
@@ -1,7 +1,7 @@
1
1
  import { r as EXPORT_FORMATS } from "./sdk-CqNZzbkz.js";
2
- import { _ as listDocIds } from "./config-4nz5NnxW.js";
3
- import { d as closeRenderSession, f as exportDocument } from "./ops-OZZVBgsM.js";
4
- import { t as cliContext } from "./context-BH8C-dSW.js";
2
+ import { _ as listDocIds } from "./config-CAZ7Z_va.js";
3
+ import { d as closeRenderSession, f as exportDocument } from "./ops-B2y9BMpk.js";
4
+ import { t as cliContext } from "./context-PWAh9qbf.js";
5
5
  import chalk from "chalk";
6
6
  //#region src/cli/export.ts
7
7
  const FORMATS = EXPORT_FORMATS;
@@ -1,5 +1,5 @@
1
- import { m as importMarkdown } from "./ops-OZZVBgsM.js";
2
- import { t as cliContext } from "./context-BH8C-dSW.js";
1
+ import { m as importMarkdown } from "./ops-B2y9BMpk.js";
2
+ import { t as cliContext } from "./context-PWAh9qbf.js";
3
3
  import chalk from "chalk";
4
4
  import path from "node:path";
5
5
  //#region src/cli/import.ts
package/dist/index.d.ts CHANGED
@@ -287,7 +287,7 @@ declare function parseDelimited(text: string, opts?: ParseOptions): DelimitedTab
287
287
  //#endregion
288
288
  //#region src/diagram/parse.d.ts
289
289
  type Direction = 'TD' | 'LR';
290
- type NodeShape = 'rect' | 'round' | 'stadium' | 'diamond' | 'circle';
290
+ type NodeShape = 'rect' | 'round' | 'stadium' | 'diamond' | 'circle' | 'cylinder';
291
291
  type DiagramNode = {
292
292
  id: string;
293
293
  label: string;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, t as compileDiagram } from "./diagram-xlVDekYk.js";
1
+ import { a as defaultDesign, i as cssVarsToString, n as DiagramSyntaxError, o as designToCssVars, r as parseDelimited, t as compileDiagram } from "./diagram-CCaUUnRe.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";
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, S as writeDocument, _ as listDocIds, a as writeText, b as renameDocument, f as OpsError, g as duplicateDocument, h as docDir, i as readText, m as deleteDocument, o as writeTexts, p as createDocument, r as addComment, v as listDocuments, x as resolveEntry, y as readDocument } from "../config-4nz5NnxW.js";
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-OZZVBgsM.js";
2
+ import { O as makeContext, S as writeDocument, _ as listDocIds, a as writeText, b as renameDocument, f as OpsError, g as duplicateDocument, h as docDir, i as readText, m as deleteDocument, o as writeTexts, p as createDocument, r as addComment, v as listDocuments, x as resolveEntry, y as readDocument } from "../config-CAZ7Z_va.js";
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-B2y9BMpk.js";
4
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 };
@@ -1,5 +1,5 @@
1
1
  import { c as isPageSizeName, i as ORIENTATIONS, o as PAGE_SIZE_NAMES, s as isOrientation } from "./sdk-CqNZzbkz.js";
2
- import { C as newFolderId, D as writeManifest, E as validateName, T as validateIcon, _ as listDocIds, c as countAssetUsages, d as validateAssetName, f as OpsError, k as DOC_ID_RE, l as resolveScopedAssetFile, n as parseFrontmatter$1, p as createDocument, s as assetImportPath, t as createViteConfig, u as resolveScopedAssetsDir, w as readManifest, x as resolveEntry } from "./config-4nz5NnxW.js";
2
+ import { C as newFolderId, D as writeManifest, E as validateName, T as validateIcon, _ as listDocIds, c as countAssetUsages, d as validateAssetName, f as OpsError, k as DOC_ID_RE, l as resolveScopedAssetFile, n as parseFrontmatter$1, p as createDocument, s as assetImportPath, t as createViteConfig, u as resolveScopedAssetsDir, w as readManifest, x as resolveEntry } from "./config-CAZ7Z_va.js";
3
3
  import path from "node:path";
4
4
  import fs from "node:fs/promises";
5
5
  import { existsSync } from "node:fs";
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./config-4nz5NnxW.js";
1
+ import { t as createViteConfig } from "./config-CAZ7Z_va.js";
2
2
  import { mergeConfig, preview as preview$1 } from "vite";
3
3
  //#region src/cli/preview.ts
4
4
  async function preview(opts = {}) {
@@ -1,2 +1,2 @@
1
- import { j as openDocPlugin, t as createViteConfig } from "../config-4nz5NnxW.js";
1
+ import { j as openDocPlugin, t as createViteConfig } from "../config-CAZ7Z_va.js";
2
2
  export { createViteConfig, openDocPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-document/core",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Runtime and CLI for open-doc — write documents in docs/, we handle the pages, print layout, and export.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -183,8 +183,10 @@ variables, so it prints with the same ink and faces as the prose around it.
183
183
  Never reach for an image of a diagram when the diagram can be written.
184
184
 
185
185
  Supported: `flowchart`/`graph` with `TD` or `LR`; nodes as `A[box]`, `A(round)`,
186
- `A([stadium])`, `A{decision}`, `A((circle))`; links `-->`, `---`, `-.->`, `==>`
187
- with optional `|labels|`; chains `A --> B --> C`; `%%` comments. Anything else
186
+ `A([stadium])`, `A[(database)]`, `A{decision}`, `A((circle))`; links `-->`,
187
+ `---`, `-.->`, `==>` with optional `|labels|`; chains `A --> B --> C`; `%%`
188
+ comments. A link back to an earlier step is drawn round the side, clear of the
189
+ steps in between. Anything else
188
190
  in Mermaid's syntax — subgraphs, class diagrams, sequence diagrams — is not
189
191
  supported, and a bad diagram fails the build with the line to fix.
190
192
 
@@ -12,6 +12,7 @@ import { DocPageProvider } from './page-context';
12
12
  import { nextFrame, waitForFonts, waitForImages } from './print-ready';
13
13
  import { captureScan, restoreScan, scanDocument } from './scan';
14
14
  import type { DocModule, PageGeometry } from './sdk';
15
+ import { scopeSvgIds } from './svg-ids';
15
16
  import type { ExpandedPage } from './use-doc-pages';
16
17
 
17
18
  export const ASSET_EXT_RE =
@@ -69,6 +70,9 @@ export async function withRenderedPages<T>(
69
70
  scanDocument(container, doc.meta);
70
71
  await nextFrame();
71
72
  await nextFrame();
73
+ hosts.forEach((host, i) => {
74
+ scopeSvgIds(host, `export-${i}`);
75
+ });
72
76
 
73
77
  return await visit(hosts, container);
74
78
  } finally {
@@ -19,6 +19,7 @@ import {
19
19
  renderPagesToHtml,
20
20
  toAbsolute,
21
21
  } from './export-dom';
22
+ import { PAGE_ATTR } from './outline';
22
23
  import { type DocModule, type PageGeometry, resolvePageGeometry } from './sdk';
23
24
  import type { ExpandedPage } from './use-doc-pages';
24
25
 
@@ -184,6 +185,7 @@ function buildSvg(pageHtml: string, css: string, geometry: Box, doc: DocModule):
184
185
  // against its foot — a footer, a centred closing, a cover's title — moves up.
185
186
  const content = document.createElementNS(XHTML_NS, 'div');
186
187
  content.setAttribute('style', 'width:100%;height:100%');
188
+ content.setAttribute(PAGE_ATTR, '');
187
189
  content.innerHTML = pageHtml;
188
190
  wrapper.appendChild(content);
189
191
 
@@ -6,6 +6,7 @@ import { DocPageProvider } from './page-context';
6
6
  import { nextFrame, sleep, waitForDataWaitfor, waitForFonts, waitForImages } from './print-ready';
7
7
  import { captureScan, restoreScan, scanDocument } from './scan';
8
8
  import { type DocModule, resolvePageGeometry } from './sdk';
9
+ import { scopeSvgIds } from './svg-ids';
9
10
  import type { ExpandedPage } from './use-doc-pages';
10
11
 
11
12
  export const PRINT_ROOT_ID = 'od-print-root';
@@ -157,6 +158,11 @@ export async function mountPrintCopy(
157
158
  scanDocument(root, doc.meta);
158
159
  await nextFrame();
159
160
  await sleep(50);
161
+ // Last, once React has drawn every page: a page still rendering has no ids
162
+ // to rename yet.
163
+ Array.from(root.children).forEach((host, i) => {
164
+ scopeSvgIds(host, `print-${i}`);
165
+ });
160
166
  } catch (err) {
161
167
  dispose();
162
168
  throw err;
@@ -79,6 +79,9 @@ export async function measureFlowSections(
79
79
 
80
80
  const host = document.createElement('div');
81
81
  host.setAttribute('aria-hidden', 'true');
82
+ // The sheet's own element styles (styles.css) apply here too, so a block
83
+ // measures as it will print.
84
+ host.setAttribute('data-od-measure', '');
82
85
  Object.assign(host.style, {
83
86
  position: 'fixed',
84
87
  left: '-99999px',
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A page is drawn more than once — the thumbnail rail, the viewer, the print
3
+ * copy, an export's offscreen copy — and an inline SVG's `id` comes along each
4
+ * time. `url(#glow)` resolves to the *first* element in the document with that
5
+ * id, which is the thumbnail's. When printing hides the rail, the print copy's
6
+ * gradients, clip paths and markers point into a subtree that is not drawn,
7
+ * and they vanish from the PDF. Renaming the ids inside a copy, and every
8
+ * reference to them inside the same copy, keeps each copy pointing at itself.
9
+ */
10
+
11
+ const URL_REF = /url\(\s*(['"]?)#([^'")\s]+)\1\s*\)/g;
12
+
13
+ export function scopeSvgIds(root: Element, suffix: string): void {
14
+ const renamed = new Map<string, string>();
15
+ for (const el of Array.from(root.querySelectorAll('svg [id]'))) {
16
+ const next = `${el.id}--${suffix}`;
17
+ renamed.set(el.id, next);
18
+ el.id = next;
19
+ }
20
+ if (renamed.size === 0) return;
21
+
22
+ for (const el of Array.from(root.querySelectorAll('svg, svg *'))) {
23
+ for (const attr of Array.from(el.attributes)) {
24
+ let value = attr.value;
25
+ if ((attr.localName === 'href' || attr.name === 'xlink:href') && value.startsWith('#')) {
26
+ const target = renamed.get(value.slice(1));
27
+ if (target) value = `#${target}`;
28
+ } else if (value.includes('url(')) {
29
+ value = value.replace(URL_REF, (whole, quote: string, id: string) => {
30
+ const target = renamed.get(id);
31
+ return target ? `url(${quote}#${target}${quote})` : whole;
32
+ });
33
+ }
34
+ if (value !== attr.value) el.setAttributeNS(attr.namespaceURI, attr.name, value);
35
+ }
36
+ }
37
+ }
@@ -91,6 +91,26 @@
91
91
  background-color: rgb(59 130 246 / 0.3);
92
92
  color: inherit;
93
93
  }
94
+ /* Preflight strips every list of its markers and indent, which suits the
95
+ chrome and not the paper: a plain <ul> in a document should print as a
96
+ list. Given back on the sheet and in the measuring host alike — a list
97
+ measured without its indent wraps differently from the one printed — and
98
+ only just outranking preflight, so a document's own list style still wins. */
99
+ :is([data-od-page], [data-od-measure]) :where(ul, ol) {
100
+ padding-inline-start: 1.5em;
101
+ }
102
+ :is([data-od-page], [data-od-measure]) :where(ul) {
103
+ list-style: disc;
104
+ }
105
+ :is([data-od-page], [data-od-measure]) :where(ol) {
106
+ list-style: decimal;
107
+ }
108
+ :is([data-od-page], [data-od-measure]) :where(ul ul, ol ul) {
109
+ list-style: circle;
110
+ }
111
+ :is([data-od-page], [data-od-measure]) :where(ul ul ul, ol ul ul, ul ol ul) {
112
+ list-style: square;
113
+ }
94
114
  /* A heading's space-above is what separates it from the section before it —
95
115
  but at the top of a page that space is just a dent. Strip it there so the
96
116
  first block of every flow page starts flush with the margin. */