@dooc-dev/dooc 0.0.4 → 0.0.6
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/cli.js +157 -58
- package/dist/code-worker.global.js +152 -0
- package/dist/code.global.js +101 -101
- package/dist/compiler/asset-references.d.ts +4 -0
- package/dist/compiler/asset-references.js +117 -0
- package/dist/compiler/bundle-urls.d.ts +1 -1
- package/dist/compiler/bundle-urls.js +17 -5
- package/dist/compiler/check.js +10 -5
- package/dist/compiler/code-languages.js +7 -2
- package/dist/compiler/compile.d.ts +5 -0
- package/dist/compiler/compile.js +117 -12
- package/dist/compiler/config.js +2 -1
- package/dist/compiler/dxf.d.ts +1 -0
- package/dist/compiler/dxf.js +81 -0
- package/dist/compiler/export.d.ts +4 -0
- package/dist/compiler/export.js +147 -0
- package/dist/compiler/figures.js +43 -10
- package/dist/compiler/files.js +82 -41
- package/dist/compiler/fonts.js +4 -1
- package/dist/compiler/icons.d.ts +1 -1
- package/dist/compiler/icons.js +11 -2
- package/dist/compiler/ignored-files.d.ts +5 -0
- package/dist/compiler/ignored-files.js +98 -0
- package/dist/compiler/locales.js +13 -8
- package/dist/compiler/ops.d.ts +6 -0
- package/dist/compiler/ops.js +99 -8
- package/dist/compiler/subformat-schema.d.ts +14 -0
- package/dist/compiler/subformat-schema.js +92 -0
- package/dist/compiler/subformats.d.ts +22 -0
- package/dist/compiler/subformats.js +339 -0
- package/dist/compiler/textfile.js +3 -0
- package/dist/compiler/theme-variants.js +5 -2
- package/dist/core/code-file.js +7 -5
- package/dist/core/code-grammars.d.ts +5 -0
- package/dist/core/code-grammars.js +34 -0
- package/dist/core/content-metadata.d.ts +16 -6
- package/dist/core/content-metadata.js +283 -17
- package/dist/core/content-types.d.ts +4 -2
- package/dist/core/escape-html.d.ts +1 -0
- package/dist/core/escape-html.js +1 -0
- package/dist/core/figure-frame.js +20 -2
- package/dist/core/file-embed.js +7 -3
- package/dist/core/files.d.ts +2 -1
- package/dist/core/files.js +6 -8
- package/dist/core/flow-base-css.generated.js +1 -1
- package/dist/core/html.d.ts +4 -1
- package/dist/core/html.js +11 -10
- package/dist/core/icons.d.ts +3 -0
- package/dist/core/icons.js +3 -0
- package/dist/core/json-tools.d.ts +1 -0
- package/dist/core/json-tools.js +12 -0
- package/dist/core/language.js +5 -2
- package/dist/core/markdown.js +3 -1
- package/dist/core/previewers.d.ts +8 -0
- package/dist/core/previewers.js +2 -0
- package/dist/core/routing.d.ts +5 -2
- package/dist/core/routing.js +17 -5
- package/dist/core/schema-fields.d.ts +13 -0
- package/dist/core/schema-fields.js +175 -0
- package/dist/core/schema-graph-mount.js +26 -3
- package/dist/core/schema-refs.d.ts +8 -0
- package/dist/core/schema-refs.js +82 -0
- package/dist/core/subformat-record.d.ts +3 -0
- package/dist/core/subformat-record.js +131 -0
- package/dist/core/subformats.d.ts +43 -0
- package/dist/core/subformats.js +81 -0
- package/dist/core/toc-ui.js +26 -24
- package/dist/edit.global.js +326 -118
- package/dist/flow.global.js +3 -3
- package/dist/graph/abnfDiagram-S7VZAUFO-ASBULSKE.js +1 -0
- package/dist/graph/architecture-WOLXFQ4H-V57EDXXY.js +1 -0
- package/dist/graph/architectureDiagram-YGSQEFNW-GIMP347N.js +36 -0
- package/dist/graph/blockDiagram-APKKGZFW-RDL2T4JW.js +140 -0
- package/dist/graph/bpmnIcons-APHXDYXF-TWOSQNUQ.js +1 -0
- package/dist/graph/c4Diagram-KJ2TOQU5-75LIUC4F.js +38 -0
- package/dist/graph/chunk-26TUJSYJ.js +1 -0
- package/dist/graph/chunk-3LU66YMI.js +1 -0
- package/dist/graph/chunk-3RNHDNP5.js +1 -0
- package/dist/graph/chunk-3Y2PDVDE.js +1 -0
- package/dist/graph/chunk-3YJHMOOA.js +3 -0
- package/dist/graph/chunk-4KILFWYV.js +339 -0
- package/dist/graph/chunk-4QDE4SUK.js +1 -0
- package/dist/graph/chunk-5OO6DATX.js +1 -0
- package/dist/graph/chunk-5UUEAHTN.js +1 -0
- package/dist/graph/chunk-6T55RVVR.js +1 -0
- package/dist/graph/chunk-ARAJTKOH.js +2 -0
- package/dist/graph/chunk-BBD5CEDC.js +72 -0
- package/dist/graph/chunk-BVXT562I.js +1 -0
- package/dist/graph/chunk-BZAMCJ6B.js +32 -0
- package/dist/graph/chunk-C6J4A356.js +15 -0
- package/dist/graph/chunk-EG5UVNOC.js +213 -0
- package/dist/graph/chunk-GF4TOPUK.js +1 -0
- package/dist/graph/chunk-GYT4IYBZ.js +1 -0
- package/dist/graph/chunk-HJG2HUYJ.js +88 -0
- package/dist/graph/chunk-HOPPTA6H.js +62 -0
- package/dist/graph/chunk-I3DMZIHV.js +1 -0
- package/dist/graph/chunk-IC23EEF6.js +1 -0
- package/dist/graph/chunk-ISO77HML.js +1 -0
- package/dist/graph/chunk-JD7ZBJD2.js +1 -0
- package/dist/graph/chunk-JRSH5GNS.js +1 -0
- package/dist/graph/chunk-JSHWCPFJ.js +1 -0
- package/dist/graph/chunk-K2KLZU7M.js +10 -0
- package/dist/graph/chunk-K4I76XBX.js +14 -0
- package/dist/graph/chunk-KT4VPQD5.js +135 -0
- package/dist/graph/chunk-KU6GTEMS.js +1 -0
- package/dist/graph/chunk-LT6LXKCR.js +136 -0
- package/dist/graph/chunk-MPR575IN.js +1 -0
- package/dist/graph/chunk-N3OHKGRZ.js +1 -0
- package/dist/graph/chunk-O656ZI37.js +1 -0
- package/dist/graph/chunk-OFZLK5G4.js +1 -0
- package/dist/graph/chunk-PDH25ALM.js +2 -0
- package/dist/graph/chunk-PW2RGZ3O.js +1 -0
- package/dist/graph/chunk-QCJUF4YA.js +1 -0
- package/dist/graph/chunk-QEEA3KYY.js +2 -0
- package/dist/graph/chunk-QYAXYFNI.js +1 -0
- package/dist/graph/chunk-QYTM6GY3.js +1 -0
- package/dist/graph/chunk-R63JUMUK.js +1 -0
- package/dist/graph/chunk-SCEY3ZPT.js +1 -0
- package/dist/graph/chunk-VM2H7G2R.js +1 -0
- package/dist/graph/chunk-XQS73SBQ.js +1 -0
- package/dist/graph/chunk-YCRLJT2S.js +1 -0
- package/dist/graph/chunk-Z4FIZ7CR.js +1 -0
- package/dist/graph/chunk-ZMCB7VP2.js +1 -0
- package/dist/graph/chunk-ZSZXN4BT.js +2 -0
- package/dist/graph/classDiagram-v2-L25IHNXF-JL7LVDZH.js +217 -0
- package/dist/graph/cose-bilkent-JH36ORCC-PNM3EYPB.js +1 -0
- package/dist/graph/cynefin-EF2NZ3EQ-PSXP3DXL.js +1 -0
- package/dist/graph/cynefinDiagram-L36ESFBY-QVY54CXO.js +62 -0
- package/dist/graph/dagre-SPEB5RXH-HPGQXBZJ.js +4 -0
- package/dist/graph/diagram-3B7GL73J-DWH5WS2P.js +200 -0
- package/dist/graph/diagram-DNEMPZML-TEGH2U5I.js +24 -0
- package/dist/graph/diagram-L3MUGCDN-X4MREUWR.js +41 -0
- package/dist/graph/diagram-LA4NIPWU-NXT746HG.js +24 -0
- package/dist/graph/diagram-MHCOC4E2-JGHXSAGS.js +3 -0
- package/dist/graph/diagram-XPFHEONP-ZHZPBLT4.js +30 -0
- package/dist/graph/ebnfDiagram-UZSYDL2S-SMF6KJ43.js +1 -0
- package/dist/graph/elk-XV6XMXQE-AZ4HLCWI.js +27 -0
- package/dist/graph/erDiagram-EYBAPDEH-B3JNJ357.js +99 -0
- package/dist/graph/eventmodeling-K75KTNOO-WG6DDYMC.js +1 -0
- package/dist/graph/flowDiagram-MALGAFMO-2R7EYAQI.js +1 -0
- package/dist/graph/ganttDiagram-23REXITY-YXBYWFOJ.js +292 -0
- package/dist/graph/gitGraph-VSP46ZUC-VBFWJBBT.js +1 -0
- package/dist/graph/gitGraphDiagram-STJD7YCW-4FZDCFGV.js +106 -0
- package/dist/graph/info-OHQRW6UA-ALVDUVYV.js +1 -0
- package/dist/graph/infoDiagram-KBXO4MBG-7EHX2GQG.js +2 -0
- package/dist/graph/ishikawaDiagram-M35NCXHK-FRZD2PWQ.js +70 -0
- package/dist/graph/journeyDiagram-OPLOXDXO-7Z66JCPR.js +139 -0
- package/dist/graph/kanban-definition-BZKZHSQY-NN5AIKTE.js +89 -0
- package/dist/graph/katex-DXDNVO6V.js +257 -0
- package/dist/graph/mindmap-definition-I2QAS2VK-HDPCABN2.js +98 -0
- package/dist/graph/packet-JDAUHWVQ-5MQIBWAH.js +1 -0
- package/dist/graph/pegDiagram-FD4XPPHP-H2BFNCKT.js +1 -0
- package/dist/graph/pie-XZMESJXO-T5VRKHVT.js +1 -0
- package/dist/graph/pieDiagram-J4AKIIQI-O3NJSVD3.js +39 -0
- package/dist/graph/quadrantDiagram-XTYBLID2-TMTZJI3P.js +7 -0
- package/dist/graph/radar-ABXABTNO-C6FXIBYW.js +1 -0
- package/dist/graph/railroad-I3PHUGI6-ZSO5JXB3.js +1 -0
- package/dist/graph/railroad-abnf-LNEFI6M7-CI4GQRHB.js +1 -0
- package/dist/graph/railroad-ebnf-DWYD2UWJ-MUENNCGK.js +1 -0
- package/dist/graph/railroad-peg-JR7BVNR7-N3X5GGIX.js +1 -0
- package/dist/graph/railroadDiagram-MRQ6NCDL-JHWS23UO.js +1 -0
- package/dist/graph/requirementDiagram-Y7LWUY3S-7DVLPO4B.js +84 -0
- package/dist/graph/sankeyDiagram-WGJFYUXA-Z5L4R5TR.js +40 -0
- package/dist/graph/schema-graph-global.js +639 -0
- package/dist/graph/sequenceDiagram-5NDRBG5M-RCTU25NT.js +169 -0
- package/dist/graph/sizeCapture-INFHLROL-RROY32P5.js +1 -0
- package/dist/graph/stateDiagram-v2-FJ4FJNEA-BXUSPWDK.js +291 -0
- package/dist/graph/swimlanes-UMQ2AFYF-LDD74Q2S.js +1 -0
- package/dist/graph/swimlanesDiagram-OMPLPG4O-ZYULLJSU.js +8 -0
- package/dist/graph/timeline-definition-SEUHKTQE-ZQSMIVAS.js +120 -0
- package/dist/graph/treeView-D4JQ5SDB-42S7U73N.js +1 -0
- package/dist/graph/treemap-SAJKECNS-RUBYQ7XF.js +1 -0
- package/dist/graph/usecaseDiagram-AFA6YXN4-57RDRYXF.js +370 -0
- package/dist/graph/vennDiagram-NNMJR3RB-5C3LVAV6.js +34 -0
- package/dist/graph/wardley-7MLQ67FV-NV5HXTTC.js +1 -0
- package/dist/graph/wardleyDiagram-S7YFUSEH-6D5BKXHM.js +78 -0
- package/dist/graph/xychartDiagram-GGNKY7IX-6ET3ZM67.js +7 -0
- package/dist/mcp.js +54 -12
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/transport.d.ts +22 -0
- package/dist/plugins/transport.js +1 -0
- package/dist/plugins.global.js +95 -0
- package/dist/subformats.global.js +21 -0
- package/dist/ui.global.js +80 -60
- package/dist/viewer/build-plugins.d.ts +7 -0
- package/dist/viewer/build-plugins.js +70 -0
- package/dist/viewer/build.d.ts +11 -0
- package/dist/viewer/build.js +52 -11
- package/dist/viewer/code-file.js +7 -2
- package/dist/viewer/editor-tools.d.ts +7 -7
- package/dist/viewer/editor-tools.js +36 -5
- package/dist/viewer/figure-preview.d.ts +4 -0
- package/dist/viewer/figure-preview.js +54 -0
- package/dist/viewer/font-picker.js +5 -1
- package/dist/viewer/git-diff.d.ts +3 -0
- package/dist/viewer/git-diff.js +47 -0
- package/dist/viewer/hmr.js +8 -4
- package/dist/viewer/i18n.js +7 -5
- package/dist/viewer/language-picker.d.ts +2 -2
- package/dist/viewer/language-picker.js +26 -9
- package/dist/viewer/lazy-preview.d.ts +2 -0
- package/dist/viewer/lazy-preview.js +43 -0
- package/dist/viewer/locales/eng.json +95 -10
- package/dist/viewer/locales/jpn.json +96 -11
- package/dist/viewer/locales/zho.json +96 -11
- package/dist/viewer/nav-focus.js +8 -1
- package/dist/viewer/nav-update.d.ts +2 -0
- package/dist/viewer/nav-update.js +117 -0
- package/dist/viewer/plugin-blocks.js +1 -1
- package/dist/viewer/plugin-style.d.ts +1 -0
- package/dist/viewer/plugin-style.js +82 -0
- package/dist/viewer/plugins.js +1 -1
- package/dist/viewer/resize.d.ts +0 -2
- package/dist/viewer/resize.js +2 -98
- package/dist/viewer/resource-library.d.ts +11 -9
- package/dist/viewer/resource-library.js +181 -31
- package/dist/viewer/search.d.ts +4 -2
- package/dist/viewer/search.js +252 -53
- package/dist/viewer/serve.d.ts +11 -5
- package/dist/viewer/serve.js +913 -295
- package/dist/viewer/site-icon.js +13 -6
- package/dist/viewer/site-title.js +15 -2
- package/dist/viewer/textfile.d.ts +5 -0
- package/dist/viewer/textfile.js +34 -2
- package/dist/viewer/theme-picker.d.ts +2 -0
- package/dist/viewer/theme-picker.js +24 -8
- package/dist/viewer/workspace.d.ts +2 -0
- package/dist/viewer/workspace.js +46 -1
- package/package.json +27 -10
- package/dist/compiler/bundle.d.ts +0 -2
- package/dist/compiler/bundle.js +0 -100
package/dist/core/html.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// "just map blocks + inline segments to output" pipeline as consumers (= prevents rendering
|
|
3
3
|
// semantics from drifting). Headings and body text share the same weight (headings are also
|
|
4
4
|
// font-weight 400).
|
|
5
|
+
import { escapeHtml } from "./escape-html.js";
|
|
5
6
|
import { figureFrameHtml } from "./figure-frame.js";
|
|
6
7
|
import { parseFigureLink } from "./file-embed.js";
|
|
7
8
|
import { GRAPH_LAYOUT_MARGIN, GRAPH_LEGEND, graphUid, layoutGraph, } from "./graph.js";
|
|
@@ -13,8 +14,8 @@ import { layoutSchemaGraph, SCHEMA_LAYOUT_MARGIN, schemaGraphClientData, schemaG
|
|
|
13
14
|
import { docDisplayName } from "./taxonomy.js";
|
|
14
15
|
import { termAnchor } from "./term-reference.js";
|
|
15
16
|
import { textfileName } from "./textfile.js";
|
|
17
|
+
export { escapeHtml } from "./escape-html.js";
|
|
16
18
|
export const emptyCtx = { figures: new Map(), terms: [] };
|
|
17
|
-
export const escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
18
19
|
// File links open their resource page; SVGs and terms also have hover previews.
|
|
19
20
|
const segmentsHtml = (text, ctx, seg) => inlineHtml(seg(text), ctx);
|
|
20
21
|
const inlineHtml = (segments, ctx) => segments
|
|
@@ -48,7 +49,7 @@ const inlineHtml = (segments, ctx) => segments
|
|
|
48
49
|
? `#${encodeURIComponent(figureRef.fragment)}`
|
|
49
50
|
: "");
|
|
50
51
|
const pop = fig.kind === "svg"
|
|
51
|
-
? `<span class="figpop">${figureFrameHtml(fig, "fig-frame figpop-frame")}</span>`
|
|
52
|
+
? `<span class="figpop">${(ctx.figurePreview ?? figureFrameHtml)(fig, "fig-frame figpop-frame")}</span>`
|
|
52
53
|
: "";
|
|
53
54
|
return `<a class="figref" href="${escapeHtml(href)}">${label}${pop}</a>`;
|
|
54
55
|
}
|
|
@@ -90,10 +91,10 @@ const listHtml = (items, ctx, seg, ordered = false) => {
|
|
|
90
91
|
// caption: line 1 = the label "Fig.<name>", then a newline and the description (.cap keeps it via
|
|
91
92
|
// pre-line). The figure content is figure-frame.ts's sandboxed iframe (fully isolates svg / html;
|
|
92
93
|
// raster images use <img>).
|
|
93
|
-
const figureHtml = (fig, withLabel = true, caption) => {
|
|
94
|
+
const figureHtml = (fig, ctx, withLabel = true, caption) => {
|
|
94
95
|
const label = caption ?? fig.title ?? `Fig.${fig.name}`;
|
|
95
96
|
const cap = [withLabel ? label : undefined, fig.desc].filter(Boolean).join("\n");
|
|
96
|
-
return `<figure class="fig">${figureFrameHtml(fig, "fig-frame", caption)}${cap ? `<figcaption class="cap">${escapeHtml(cap)}</figcaption>` : ""}</figure>`;
|
|
97
|
+
return `<figure class="fig">${(ctx.figurePreview ?? figureFrameHtml)(fig, "fig-frame", caption)}${cap ? `<figcaption class="cap">${escapeHtml(cap)}</figcaption>` : ""}</figure>`;
|
|
97
98
|
};
|
|
98
99
|
const tableHtml = (b, ctx, seg) => {
|
|
99
100
|
if (b.dataSource) {
|
|
@@ -388,8 +389,8 @@ const blockHtml = (b, ctx, seg) => {
|
|
|
388
389
|
const fig = ctx.figures.get(b.name);
|
|
389
390
|
if (fig) {
|
|
390
391
|
if (b.alt !== undefined)
|
|
391
|
-
return `<figure class="fig">${figureFrameHtml(fig, "fig-frame", b.alt)}</figure>`;
|
|
392
|
-
return figureHtml(fig, true, b.caption);
|
|
392
|
+
return `<figure class="fig">${(ctx.figurePreview ?? figureFrameHtml)(fig, "fig-frame", b.alt)}</figure>`;
|
|
393
|
+
return figureHtml(fig, ctx, true, b.caption);
|
|
393
394
|
}
|
|
394
395
|
return `<div class="ph">${escapeHtml(b.alt || `Fig. ${b.name}`)}<span> — not found in figures/</span></div>`;
|
|
395
396
|
}
|
|
@@ -399,7 +400,7 @@ const blockHtml = (b, ctx, seg) => {
|
|
|
399
400
|
// Figure list. The h2 doubles as the label, so captions omit it. h2 id = fig name
|
|
400
401
|
// (anchor).
|
|
401
402
|
return [...ctx.figures.values()]
|
|
402
|
-
.map((f) => `<h2 id="${escapeHtml(f.name)}">${escapeHtml(f.title ?? f.name)}</h2>${figureHtml(f, false)}`)
|
|
403
|
+
.map((f) => `<h2 id="${escapeHtml(f.name)}">${escapeHtml(f.title ?? f.name)}</h2>${figureHtml(f, ctx, false)}`)
|
|
403
404
|
.join("\n");
|
|
404
405
|
case "schemaGraph":
|
|
405
406
|
// table DSL → ER diagram. The parsed model is turned into SVG with a
|
|
@@ -425,7 +426,7 @@ export const blocksHtml = (blocks, ctx = emptyCtx) => {
|
|
|
425
426
|
.filter((h) => h !== "")
|
|
426
427
|
.join("\n");
|
|
427
428
|
};
|
|
428
|
-
//
|
|
429
|
+
// Keep the document outline beside its title in every viewer.
|
|
429
430
|
const inPageTocHtml = (toc, title = "Contents") => {
|
|
430
431
|
if (toc.length === 0) {
|
|
431
432
|
return "";
|
|
@@ -433,12 +434,12 @@ const inPageTocHtml = (toc, title = "Contents") => {
|
|
|
433
434
|
const items = toc
|
|
434
435
|
.map((t) => `<li class="lvl${t.depth}"><a href="#${escapeHtml(t.slug)}" data-toc-target="${escapeHtml(t.slug)}" title="${escapeHtml(t.text)}">${escapeHtml(t.text)}</a></li>`)
|
|
435
436
|
.join("");
|
|
436
|
-
return `<nav class="in-toc" aria-label="${escapeHtml(title)}"><button class="toc-current" type="button" aria-expanded="false">${escapeHtml(toc[0]?.text ?? "")}</button><ul class="toc-options" popover>${items}</ul
|
|
437
|
+
return `<nav class="in-toc" aria-label="${escapeHtml(title)}"><button class="toc-current" type="button" aria-expanded="false">${escapeHtml(toc[0]?.text ?? "")}</button><ul class="toc-options" popover>${items}</ul></nav>`;
|
|
437
438
|
};
|
|
438
439
|
export const docHtml = (fm, blocks, errors, ctx = emptyCtx, toc = []) => {
|
|
439
440
|
const errBox = errors.length > 0
|
|
440
441
|
? `<div class="errors">${errors.map((e) => `<div>${escapeHtml(e)}</div>`).join("")}</div>`
|
|
441
442
|
: "";
|
|
442
443
|
const lang = ctx.lang ? ` lang="${escapeHtml(ctx.lang)}"` : "";
|
|
443
|
-
return `<article${lang}>${errBox}<h1>${escapeHtml(docDisplayName(fm, ""))}</h1>${inPageTocHtml(toc, ctx.tocTitle)}
|
|
444
|
+
return `<article${lang}>${errBox}<header class="doc-title"><h1>${escapeHtml(docDisplayName(fm, ""))}</h1>${inPageTocHtml(toc, ctx.tocTitle)}</header>${blocksHtml(blocks, ctx)}</article>`;
|
|
444
445
|
};
|
package/dist/core/icons.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
export declare const FOLDER_ICON_PATH = "M2 5h6l2 2h8v10H2Z";
|
|
2
|
+
export declare const RELOAD_ICON_PATH = "M17 8a7 7 0 1 0 0 5M17 3v5h-5";
|
|
3
|
+
export declare const SEARCH_ICON_PATH = "M14 14l4 4M15 9a6 6 0 1 1-12 0 6 6 0 0 1 12 0";
|
|
1
4
|
export declare const CHECK_ICON = "<svg class=\"ic-ok\" viewBox=\"0 0 20 20\" width=\"14\" height=\"14\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m4 10 4 4 8-8\"/></svg>";
|
|
2
5
|
export declare const PLUGINS_ICON = "<svg class=\"nav-icon\" viewBox=\"0 0 20 20\" width=\"18\" height=\"18\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m10 2 4 2v5l-4 2-4-2V4Zm-4 2 4 2 4-2m-4 2v5M6 9l-4 2v5l4 2 4-2v-5m-8 0 4 2 4-2m-4 2v5m8-9 4 2v5l-4 2-4-2m0-5 4 2 4-2m-4 2v5\"/></svg>";
|
package/dist/core/icons.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
export const FOLDER_ICON_PATH = "M2 5h6l2 2h8v10H2Z";
|
|
2
|
+
export const RELOAD_ICON_PATH = "M17 8a7 7 0 1 0 0 5M17 3v5h-5";
|
|
3
|
+
export const SEARCH_ICON_PATH = "M14 14l4 4M15 9a6 6 0 1 1-12 0 6 6 0 0 1 12 0";
|
|
1
4
|
export const CHECK_ICON = '<svg class="ic-ok" viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 10 4 4 8-8"/></svg>';
|
|
2
5
|
export const PLUGINS_ICON = '<svg class="nav-icon" viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m10 2 4 2v5l-4 2-4-2V4Zm-4 2 4 2 4-2m-4 2v5M6 9l-4 2v5l4 2 4-2v-5m-8 0 4 2 4-2m-4 2v5m8-9 4 2v5l-4 2-4-2m0-5 4 2 4-2m-4 2v5"/></svg>';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatJson: (content: string) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getLanguageService } from "vscode-json-languageservice";
|
|
2
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
3
|
+
export const formatJson = (content) => {
|
|
4
|
+
JSON.parse(content);
|
|
5
|
+
const document = TextDocument.create("file:///document.json", "json", 0, content);
|
|
6
|
+
const edits = getLanguageService({}).format(document, undefined, {
|
|
7
|
+
tabSize: 2,
|
|
8
|
+
insertSpaces: true,
|
|
9
|
+
eol: content.includes("\r\n") ? "\r\n" : "\n",
|
|
10
|
+
});
|
|
11
|
+
return TextDocument.applyEdits(document, edits);
|
|
12
|
+
};
|
package/dist/core/language.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { iso6393, iso6393To1 } from "iso-639-3";
|
|
2
2
|
export const DEFAULT_LANG = "en";
|
|
3
|
-
|
|
3
|
+
let contentCodes;
|
|
4
4
|
const from1 = new Map(Object.entries(iso6393To1).map(([three, two]) => [two, three]));
|
|
5
|
-
export const isContentLanguage = (code) =>
|
|
5
|
+
export const isContentLanguage = (code) => {
|
|
6
|
+
contentCodes ??= new Set(iso6393.map((language) => language.iso6393));
|
|
7
|
+
return contentCodes.has(code);
|
|
8
|
+
};
|
|
6
9
|
/** Normalize site language declarations and translation directory names consistently. */
|
|
7
10
|
export const contentLanguageCode = (tag) => {
|
|
8
11
|
const primary = tag.toLowerCase().split("-")[0] ?? "";
|
package/dist/core/markdown.js
CHANGED
|
@@ -8,7 +8,8 @@ import { parseFigureLink } from "./file-embed.js";
|
|
|
8
8
|
import { parseDocLink } from "./routing.js";
|
|
9
9
|
import { parseTermReference, termFileUrl } from "./term-reference.js";
|
|
10
10
|
const processor = unified().use(remarkParse).use(remarkFrontmatter).use(remarkGfm);
|
|
11
|
-
const
|
|
11
|
+
const createInlinePrinter = () => unified().use(remarkGfm).use(remarkStringify);
|
|
12
|
+
let inlinePrinter;
|
|
12
13
|
export const parseMdast = (raw) => processor.parse(raw);
|
|
13
14
|
/** File previews occupy whole paragraphs; prose, lists and tables keep their inline layout. */
|
|
14
15
|
export const standaloneImages = (node) => node.type === "paragraph" &&
|
|
@@ -115,6 +116,7 @@ export const inlineToText = (nodes) => {
|
|
|
115
116
|
/* Reported by validation. */
|
|
116
117
|
}
|
|
117
118
|
});
|
|
119
|
+
inlinePrinter ??= createInlinePrinter();
|
|
118
120
|
return inlinePrinter.stringify(root).replace(/\n$/, "");
|
|
119
121
|
};
|
|
120
122
|
export const listItems = (n, convert) => n.children.map((li) => {
|
|
@@ -22,6 +22,14 @@ export declare const PREVIEWERS: readonly [{
|
|
|
22
22
|
readonly id: "video";
|
|
23
23
|
readonly label: "Video";
|
|
24
24
|
readonly extensions: readonly ["mp4", "webm"];
|
|
25
|
+
}, {
|
|
26
|
+
readonly id: "pdf";
|
|
27
|
+
readonly label: "PDF";
|
|
28
|
+
readonly extensions: readonly ["pdf"];
|
|
29
|
+
}, {
|
|
30
|
+
readonly id: "dxf";
|
|
31
|
+
readonly label: "DXF";
|
|
32
|
+
readonly extensions: readonly ["dxf"];
|
|
25
33
|
}];
|
|
26
34
|
export type PreviewerId = (typeof PREVIEWERS)[number]["id"];
|
|
27
35
|
export interface PreviewSettings {
|
package/dist/core/previewers.js
CHANGED
|
@@ -43,6 +43,8 @@ export const PREVIEWERS = [
|
|
|
43
43
|
],
|
|
44
44
|
},
|
|
45
45
|
{ id: "video", label: "Video", extensions: ["mp4", "webm"] },
|
|
46
|
+
{ id: "pdf", label: "PDF", extensions: ["pdf"] },
|
|
47
|
+
{ id: "dxf", label: "DXF", extensions: ["dxf"] },
|
|
46
48
|
];
|
|
47
49
|
export const defaultPreviewSettings = () => ({
|
|
48
50
|
domains: [],
|
package/dist/core/routing.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { CompiledDoc } from "./content-types.js";
|
|
2
2
|
/** The minimal doc reference routing needs (a shape CompiledDoc satisfies). */
|
|
3
|
-
export type DocRef = Pick<CompiledDoc, "id" | "parent"
|
|
3
|
+
export type DocRef = Pick<CompiledDoc, "id" | "parent"> & {
|
|
4
|
+
file?: string;
|
|
5
|
+
sourceFile?: string;
|
|
6
|
+
};
|
|
4
7
|
/** Parse `<docId>` (leading/trailing `/` are ignored). undefined if the shape differs. */
|
|
5
8
|
export declare const parseRoutePath: (path: string) => string | undefined;
|
|
6
9
|
/** Document links use paths relative to the docs root and optional heading fragments. */
|
|
@@ -14,7 +17,7 @@ export declare const childrenOf: <D extends DocRef>(docs: readonly D[], parent?:
|
|
|
14
17
|
export declare const ancestorsOf: <D extends DocRef>(docs: readonly D[], id: string) => D[];
|
|
15
18
|
/** DOM anchor id for a heading — namespaced by doc id. */
|
|
16
19
|
export declare const headingAnchor: (docId: string, slug: string) => string;
|
|
17
|
-
/**
|
|
20
|
+
/** File routes cannot shadow API/tool routes; legacy IDs retain hierarchy paths. */
|
|
18
21
|
export declare const docPath: (docs: readonly DocRef[], id: string) => string;
|
|
19
22
|
/** Resolve only the complete hierarchy path; no legacy single-id aliases. */
|
|
20
23
|
export declare const resolveDocPath: (docs: readonly DocRef[], path: string) => string | undefined;
|
package/dist/core/routing.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// through here and never build paths themselves — a consumer is a display-only wrapper, and this
|
|
3
3
|
// package owns routing.
|
|
4
4
|
//
|
|
5
|
-
//
|
|
6
|
-
// Body links reference source files
|
|
5
|
+
// File-based URLs use a reserved namespace; legacy URLs follow the manifest hierarchy.
|
|
6
|
+
// Body links reference source files, and heading fragments stay separate.
|
|
7
7
|
import { isDocId } from "./content-metadata.js";
|
|
8
|
-
import { localFile } from "./files.js";
|
|
8
|
+
import { fileDocumentId, localFile } from "./files.js";
|
|
9
9
|
import { parseFileReference } from "./textfile.js";
|
|
10
10
|
/** Parse `<docId>` (leading/trailing `/` are ignored). undefined if the shape differs. */
|
|
11
11
|
export const parseRoutePath = (path) => {
|
|
@@ -52,10 +52,22 @@ export const ancestorsOf = (docs, id) => {
|
|
|
52
52
|
};
|
|
53
53
|
/** DOM anchor id for a heading — namespaced by doc id. */
|
|
54
54
|
export const headingAnchor = (docId, slug) => `${docId}__${slug}`;
|
|
55
|
-
/**
|
|
56
|
-
export const docPath = (docs, id) =>
|
|
55
|
+
/** File routes cannot shadow API/tool routes; legacy IDs retain hierarchy paths. */
|
|
56
|
+
export const docPath = (docs, id) => {
|
|
57
|
+
const doc = docs.find((item) => item.id === id);
|
|
58
|
+
const file = doc?.sourceFile ?? doc?.file;
|
|
59
|
+
if (file && fileDocumentId(file) === id)
|
|
60
|
+
return `/_docs/${file.split("/").map(encodeURIComponent).join("/")}`;
|
|
61
|
+
return `/${[...ancestorsOf(docs, id).map((doc) => doc.id), id].join("/")}`;
|
|
62
|
+
};
|
|
57
63
|
/** Resolve only the complete hierarchy path; no legacy single-id aliases. */
|
|
58
64
|
export const resolveDocPath = (docs, path) => {
|
|
65
|
+
const fileDoc = docs.find((doc) => {
|
|
66
|
+
const file = doc.sourceFile ?? doc.file;
|
|
67
|
+
return file && fileDocumentId(file) === doc.id && docPath(docs, doc.id) === path;
|
|
68
|
+
});
|
|
69
|
+
if (fileDoc)
|
|
70
|
+
return fileDoc.id;
|
|
59
71
|
const parts = path.split("/").filter(Boolean);
|
|
60
72
|
const id = parts.at(-1);
|
|
61
73
|
if (!id || !parts.every(isDocId) || !docs.some((doc) => doc.id === id))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SchemaObject = Record<string, unknown>;
|
|
2
|
+
export declare const schemaTypes: string[];
|
|
3
|
+
export declare const schemaObject: (value: unknown) => value is SchemaObject;
|
|
4
|
+
export declare const schemaKeyword: (name: string) => SchemaObject;
|
|
5
|
+
export declare const schemaConstraints: Record<string, string[]>;
|
|
6
|
+
export declare const schemaJsonParameters: string[];
|
|
7
|
+
export declare const parseFieldSchema: (content: string) => SchemaObject;
|
|
8
|
+
export declare const renameSchemaField: (parent: SchemaObject, from: string, to: string) => void;
|
|
9
|
+
export declare const schemaFieldNamesLocked: (schema: unknown) => boolean;
|
|
10
|
+
export declare const setSchemaType: (schema: SchemaObject, type: string) => void;
|
|
11
|
+
export declare const formatSchemaChoices: (values: unknown[], type: unknown) => string;
|
|
12
|
+
export declare const schemaChoices: (text: string, type: unknown) => unknown[];
|
|
13
|
+
export declare const parseSchemaParameter: (key: string, text: string, type: unknown) => unknown;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import metadata from "ajv/dist/refs/json-schema-2020-12/meta/meta-data.json" with { type: "json" };
|
|
2
|
+
import validation from "ajv/dist/refs/json-schema-2020-12/meta/validation.json" with {
|
|
3
|
+
type: "json"
|
|
4
|
+
};
|
|
5
|
+
import { SUBFORMAT_SCHEMA_VERSION } from "./subformats.js";
|
|
6
|
+
export const schemaTypes = validation.$defs.simpleTypes.enum;
|
|
7
|
+
export const schemaObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
8
|
+
export const schemaKeyword = (name) => {
|
|
9
|
+
const value = validation.properties[name] ??
|
|
10
|
+
metadata.properties[name];
|
|
11
|
+
let rule = schemaObject(value) ? value : {};
|
|
12
|
+
while (typeof rule.$ref === "string" && rule.$ref.startsWith("#/$defs/")) {
|
|
13
|
+
const target = validation.$defs[rule.$ref.slice(8)];
|
|
14
|
+
if (!target)
|
|
15
|
+
break;
|
|
16
|
+
const { $ref: _ref, ...rest } = rule;
|
|
17
|
+
rule = { ...target, ...rest };
|
|
18
|
+
}
|
|
19
|
+
return rule;
|
|
20
|
+
};
|
|
21
|
+
export const schemaConstraints = {
|
|
22
|
+
string: ["minLength", "maxLength", "pattern"],
|
|
23
|
+
number: ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"],
|
|
24
|
+
integer: ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"],
|
|
25
|
+
array: ["minItems", "maxItems", "uniqueItems"],
|
|
26
|
+
object: ["minProperties", "maxProperties"],
|
|
27
|
+
};
|
|
28
|
+
export const schemaJsonParameters = [
|
|
29
|
+
"const",
|
|
30
|
+
"default",
|
|
31
|
+
"examples",
|
|
32
|
+
"oneOf",
|
|
33
|
+
"anyOf",
|
|
34
|
+
"allOf",
|
|
35
|
+
"not",
|
|
36
|
+
"$defs",
|
|
37
|
+
];
|
|
38
|
+
const matchesType = (value, type) => type === undefined ||
|
|
39
|
+
(Array.isArray(type)
|
|
40
|
+
? type.some((item) => matchesType(value, item))
|
|
41
|
+
: type === "null"
|
|
42
|
+
? value === null
|
|
43
|
+
: type === "integer"
|
|
44
|
+
? Number.isSafeInteger(value)
|
|
45
|
+
: type === "array"
|
|
46
|
+
? Array.isArray(value)
|
|
47
|
+
: type === "object"
|
|
48
|
+
? schemaObject(value)
|
|
49
|
+
: typeof value === type);
|
|
50
|
+
const parseSchemaJson = (content) => JSON.parse(content, (_key, value) => {
|
|
51
|
+
if (typeof value === "number" &&
|
|
52
|
+
(!Number.isFinite(value) || (Number.isInteger(value) && !Number.isSafeInteger(value))))
|
|
53
|
+
throw new Error("Use JSON text for numbers outside the safe integer range.");
|
|
54
|
+
return value;
|
|
55
|
+
});
|
|
56
|
+
export const parseFieldSchema = (content) => {
|
|
57
|
+
const schema = parseSchemaJson(content);
|
|
58
|
+
if (!schemaObject(schema))
|
|
59
|
+
throw new Error("Build kit requires a schema object.");
|
|
60
|
+
if (schema.$schema !== undefined && schema.$schema !== SUBFORMAT_SCHEMA_VERSION)
|
|
61
|
+
throw new Error("Build kit uses JSON Schema 2020-12.");
|
|
62
|
+
return schema;
|
|
63
|
+
};
|
|
64
|
+
export const renameSchemaField = (parent, from, to) => {
|
|
65
|
+
if (!to.trim())
|
|
66
|
+
throw new Error("Enter a field name.");
|
|
67
|
+
if (from === to)
|
|
68
|
+
return;
|
|
69
|
+
const properties = schemaObject(parent.properties) ? parent.properties : {};
|
|
70
|
+
if (Object.hasOwn(properties, to))
|
|
71
|
+
throw new Error("A field with this name already exists.");
|
|
72
|
+
parent.properties = Object.fromEntries(Object.entries(properties).map(([name, schema]) => [name === from ? to : name, schema]));
|
|
73
|
+
if (Array.isArray(parent.required))
|
|
74
|
+
parent.required = parent.required.map((name) => (name === from ? to : name));
|
|
75
|
+
};
|
|
76
|
+
export const schemaFieldNamesLocked = (schema) => {
|
|
77
|
+
if (Array.isArray(schema))
|
|
78
|
+
return schema.some(schemaFieldNamesLocked);
|
|
79
|
+
if (!schemaObject(schema))
|
|
80
|
+
return false;
|
|
81
|
+
return Object.entries(schema).some(([key, value]) => [
|
|
82
|
+
"$ref",
|
|
83
|
+
"$dynamicRef",
|
|
84
|
+
"dependentRequired",
|
|
85
|
+
"dependentSchemas",
|
|
86
|
+
"if",
|
|
87
|
+
"then",
|
|
88
|
+
"else",
|
|
89
|
+
"allOf",
|
|
90
|
+
"anyOf",
|
|
91
|
+
"oneOf",
|
|
92
|
+
"not",
|
|
93
|
+
"patternProperties",
|
|
94
|
+
"propertyNames",
|
|
95
|
+
].includes(key) ||
|
|
96
|
+
(!["enum", "const", "default", "examples"].includes(key) &&
|
|
97
|
+
schemaFieldNamesLocked(value)));
|
|
98
|
+
};
|
|
99
|
+
export const setSchemaType = (schema, type) => {
|
|
100
|
+
if (type && !schemaTypes.includes(type))
|
|
101
|
+
throw new Error("Choose a schema type.");
|
|
102
|
+
if ((schema.type ?? "") === type)
|
|
103
|
+
return;
|
|
104
|
+
const values = [
|
|
105
|
+
...(Array.isArray(schema.enum) ? schema.enum : []),
|
|
106
|
+
...["const", "default"].flatMap((key) => (Object.hasOwn(schema, key) ? [schema[key]] : [])),
|
|
107
|
+
];
|
|
108
|
+
if (type && values.some((value) => !matchesType(value, type)))
|
|
109
|
+
throw new Error("Change existing choices or defaults before changing the type.");
|
|
110
|
+
if ((schemaObject(schema.properties) && Object.keys(schema.properties).length) ||
|
|
111
|
+
(schemaObject(schema.items) && Object.keys(schema.items).some((key) => key !== "type")) ||
|
|
112
|
+
schema.prefixItems)
|
|
113
|
+
throw new Error("Remove nested fields before changing the type.");
|
|
114
|
+
for (const key of new Set(Object.values(schemaConstraints).flat()))
|
|
115
|
+
if (!(schemaConstraints[type] ?? []).includes(key))
|
|
116
|
+
delete schema[key];
|
|
117
|
+
if (type !== "string")
|
|
118
|
+
delete schema.format;
|
|
119
|
+
if (type !== "array")
|
|
120
|
+
delete schema.items;
|
|
121
|
+
if (type !== "object") {
|
|
122
|
+
delete schema.properties;
|
|
123
|
+
delete schema.required;
|
|
124
|
+
delete schema.additionalProperties;
|
|
125
|
+
}
|
|
126
|
+
if (type)
|
|
127
|
+
schema.type = type;
|
|
128
|
+
else
|
|
129
|
+
delete schema.type;
|
|
130
|
+
if (type === "object")
|
|
131
|
+
schema.properties ??= {};
|
|
132
|
+
if (type === "array")
|
|
133
|
+
schema.items ??= { type: "string" };
|
|
134
|
+
};
|
|
135
|
+
export const formatSchemaChoices = (values, type) => values
|
|
136
|
+
.map((value) => type === "string" &&
|
|
137
|
+
typeof value === "string" &&
|
|
138
|
+
value !== "" &&
|
|
139
|
+
!/[\r\n]/.test(value) &&
|
|
140
|
+
!value.trimStart().startsWith('"')
|
|
141
|
+
? value
|
|
142
|
+
: JSON.stringify(value))
|
|
143
|
+
.join("\n");
|
|
144
|
+
export const schemaChoices = (text, type) => {
|
|
145
|
+
const lines = text.split(/\r?\n/).filter((line) => line.length > 0);
|
|
146
|
+
const values = lines.map((line) => {
|
|
147
|
+
const value = type === "string" && !line.trimStart().startsWith('"') ? line : parseSchemaJson(line);
|
|
148
|
+
if (!matchesType(value, type))
|
|
149
|
+
throw new Error("Each choice must match the field type.");
|
|
150
|
+
return value;
|
|
151
|
+
});
|
|
152
|
+
if (!values.length)
|
|
153
|
+
throw new Error("Enter at least one choice.");
|
|
154
|
+
if (new Set(values.map((value) => JSON.stringify(value, (_key, item) => schemaObject(item)
|
|
155
|
+
? Object.fromEntries(Object.entries(item).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
156
|
+
: item))).size !== values.length)
|
|
157
|
+
throw new Error("Choices must be unique.");
|
|
158
|
+
return values;
|
|
159
|
+
};
|
|
160
|
+
export const parseSchemaParameter = (key, text, type) => {
|
|
161
|
+
const value = parseSchemaJson(text);
|
|
162
|
+
const isSchema = (item) => typeof item === "boolean" || schemaObject(item);
|
|
163
|
+
if (["oneOf", "anyOf", "allOf"].includes(key) &&
|
|
164
|
+
(!Array.isArray(value) || !value.length || !value.every(isSchema)))
|
|
165
|
+
throw new Error("Enter a non-empty JSON array of schemas.");
|
|
166
|
+
if (key === "not" && !isSchema(value))
|
|
167
|
+
throw new Error("Enter a JSON schema object or boolean.");
|
|
168
|
+
if (key === "$defs" && (!schemaObject(value) || !Object.values(value).every(isSchema)))
|
|
169
|
+
throw new Error("Enter an object containing named schemas.");
|
|
170
|
+
if (key === "examples" && !Array.isArray(value))
|
|
171
|
+
throw new Error("Examples must be a JSON array.");
|
|
172
|
+
if (key === "const" && !matchesType(value, type))
|
|
173
|
+
throw new Error("The constant must match the field type.");
|
|
174
|
+
return value;
|
|
175
|
+
};
|
|
@@ -64,19 +64,40 @@ export const mountSchemaGraphs = (root = document) => {
|
|
|
64
64
|
*/
|
|
65
65
|
export const watchSchemaGraphs = (root = document) => {
|
|
66
66
|
const mounted = new Map();
|
|
67
|
+
const pending = new Set();
|
|
68
|
+
const visibility = new IntersectionObserver((entries) => {
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
if (!entry.isIntersecting)
|
|
71
|
+
continue;
|
|
72
|
+
const svg = entry.target;
|
|
73
|
+
visibility.unobserve(svg);
|
|
74
|
+
pending.delete(svg);
|
|
75
|
+
if (!root.contains(svg))
|
|
76
|
+
continue;
|
|
77
|
+
const dispose = mountOne(svg);
|
|
78
|
+
if (dispose)
|
|
79
|
+
mounted.set(svg, dispose);
|
|
80
|
+
}
|
|
81
|
+
}, { rootMargin: "200px" });
|
|
67
82
|
const mount = (node) => {
|
|
68
83
|
const svgs = [...node.querySelectorAll("svg[data-sg-layout]")];
|
|
69
84
|
if (node instanceof SVGSVGElement && node.matches("svg[data-sg-layout]")) {
|
|
70
85
|
svgs.unshift(node);
|
|
71
86
|
}
|
|
72
87
|
for (const svg of svgs) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
if (mounted.has(svg) || pending.has(svg))
|
|
89
|
+
continue;
|
|
90
|
+
pending.add(svg);
|
|
91
|
+
visibility.observe(svg);
|
|
76
92
|
}
|
|
77
93
|
};
|
|
78
94
|
mount(root);
|
|
79
95
|
const observer = new MutationObserver((records) => {
|
|
96
|
+
for (const svg of pending)
|
|
97
|
+
if (!root.contains(svg)) {
|
|
98
|
+
pending.delete(svg);
|
|
99
|
+
visibility.unobserve(svg);
|
|
100
|
+
}
|
|
80
101
|
// Look only at added subtrees instead of scanning the whole document on every keystroke.
|
|
81
102
|
for (const [svg, dispose] of mounted) {
|
|
82
103
|
if (!root.contains(svg)) {
|
|
@@ -97,6 +118,8 @@ export const watchSchemaGraphs = (root = document) => {
|
|
|
97
118
|
});
|
|
98
119
|
return () => {
|
|
99
120
|
observer.disconnect();
|
|
121
|
+
visibility.disconnect();
|
|
122
|
+
pending.clear();
|
|
100
123
|
for (const dispose of mounted.values()) {
|
|
101
124
|
dispose();
|
|
102
125
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SchemaObject } from "./schema-fields.js";
|
|
2
|
+
export interface SchemaContext {
|
|
3
|
+
uri: string;
|
|
4
|
+
schemas: Record<string, SchemaObject | boolean>;
|
|
5
|
+
}
|
|
6
|
+
/** Visit schema positions only; defaults, examples and enum values are data. */
|
|
7
|
+
export declare const visitSchema: (schema: unknown, base: string, visit: (schema: SchemaObject, base: string) => void) => void;
|
|
8
|
+
export declare const schemaResolver: (schema: SchemaObject, context?: SchemaContext) => (definition: unknown) => SchemaObject;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { schemaObject } from "./schema-fields.js";
|
|
2
|
+
/** Visit schema positions only; defaults, examples and enum values are data. */
|
|
3
|
+
export const visitSchema = (schema, base, visit) => {
|
|
4
|
+
if (!schemaObject(schema))
|
|
5
|
+
return;
|
|
6
|
+
if (typeof schema.$id === "string")
|
|
7
|
+
base = new URL(schema.$id, base).href;
|
|
8
|
+
visit(schema, base);
|
|
9
|
+
for (const key of [
|
|
10
|
+
"properties",
|
|
11
|
+
"patternProperties",
|
|
12
|
+
"$defs",
|
|
13
|
+
"definitions",
|
|
14
|
+
"dependentSchemas",
|
|
15
|
+
])
|
|
16
|
+
if (schemaObject(schema[key]))
|
|
17
|
+
for (const child of Object.values(schema[key]))
|
|
18
|
+
visitSchema(child, base, visit);
|
|
19
|
+
for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"])
|
|
20
|
+
if (Array.isArray(schema[key]))
|
|
21
|
+
for (const child of schema[key])
|
|
22
|
+
visitSchema(child, base, visit);
|
|
23
|
+
for (const key of [
|
|
24
|
+
"items",
|
|
25
|
+
"additionalProperties",
|
|
26
|
+
"unevaluatedProperties",
|
|
27
|
+
"unevaluatedItems",
|
|
28
|
+
"contains",
|
|
29
|
+
"propertyNames",
|
|
30
|
+
"not",
|
|
31
|
+
"if",
|
|
32
|
+
"then",
|
|
33
|
+
"else",
|
|
34
|
+
])
|
|
35
|
+
visitSchema(schema[key], base, visit);
|
|
36
|
+
};
|
|
37
|
+
export const schemaResolver = (schema, context) => {
|
|
38
|
+
const base = context?.uri ?? "file:///schema.json";
|
|
39
|
+
const resources = new Map();
|
|
40
|
+
const bases = new WeakMap();
|
|
41
|
+
for (const [uri, document] of Object.entries({ ...context?.schemas, [base]: schema })) {
|
|
42
|
+
resources.set(uri, document);
|
|
43
|
+
visitSchema(document, uri, (node, resolved) => {
|
|
44
|
+
bases.set(node, resolved);
|
|
45
|
+
if (node === document || typeof node.$id === "string")
|
|
46
|
+
resources.set(resolved, node);
|
|
47
|
+
for (const key of ["$anchor", "$dynamicAnchor"])
|
|
48
|
+
if (typeof node[key] === "string")
|
|
49
|
+
resources.set(`${resolved.split("#")[0]}#${node[key]}`, node);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return (definition) => {
|
|
53
|
+
let current = schemaObject(definition) ? definition : {};
|
|
54
|
+
let result = current;
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
while (typeof current.$ref === "string" && !seen.has(current)) {
|
|
57
|
+
seen.add(current);
|
|
58
|
+
const uri = new URL(current.$ref, bases.get(current) ?? base);
|
|
59
|
+
let target = resources.get(uri.href);
|
|
60
|
+
if (target === undefined) {
|
|
61
|
+
const fragment = decodeURIComponent(uri.hash.slice(1));
|
|
62
|
+
uri.hash = "";
|
|
63
|
+
target = resources.get(uri.href);
|
|
64
|
+
if (fragment && !fragment.startsWith("/"))
|
|
65
|
+
break;
|
|
66
|
+
for (const key of fragment ? fragment.slice(1).split("/") : []) {
|
|
67
|
+
const name = key.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
68
|
+
target =
|
|
69
|
+
target && typeof target === "object" && Object.hasOwn(target, name)
|
|
70
|
+
? target[name]
|
|
71
|
+
: undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!schemaObject(target))
|
|
75
|
+
break;
|
|
76
|
+
const { $ref: _ref, ...siblings } = result;
|
|
77
|
+
result = { ...target, ...siblings };
|
|
78
|
+
current = target;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Subformat } from "./subformats.js";
|
|
2
|
+
export declare const parseSubformatRecord: (content: string, format: Subformat["format"]) => Record<string, unknown>;
|
|
3
|
+
export declare const setSubformatValue: (source: string, format: Subformat["format"], path: (string | number)[], value: unknown) => string;
|