@dooc-dev/dooc 0.0.5 → 0.0.7
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 +162 -67
- package/dist/code-worker.global.js +152 -0
- package/dist/code.global.js +101 -101
- package/dist/compiler/bundle-urls.js +2 -0
- package/dist/compiler/check.js +2 -0
- package/dist/compiler/compile.js +13 -3
- package/dist/compiler/dxf.d.ts +1 -0
- package/dist/compiler/dxf.js +81 -0
- package/dist/compiler/export.js +22 -15
- package/dist/compiler/figures.js +39 -10
- package/dist/compiler/files.js +2 -0
- package/dist/compiler/ignored-files.d.ts +2 -0
- package/dist/compiler/ignored-files.js +30 -0
- package/dist/compiler/ops.js +1 -1
- package/dist/compiler/subformat-schema.d.ts +14 -0
- package/dist/compiler/subformat-schema.js +92 -0
- package/dist/compiler/subformats.d.ts +5 -7
- package/dist/compiler/subformats.js +115 -75
- 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 +2 -1
- package/dist/core/content-metadata.js +7 -2
- package/dist/core/content-types.d.ts +1 -1
- package/dist/core/escape-html.d.ts +1 -0
- package/dist/core/escape-html.js +1 -0
- package/dist/core/figure-frame.js +1 -1
- package/dist/core/file-embed.js +7 -3
- package/dist/core/html.d.ts +4 -1
- package/dist/core/html.js +8 -7
- 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/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/toc-ui.js +1 -1
- package/dist/edit.global.js +266 -285
- package/dist/flow.global.js +1031 -1057
- package/dist/graph/abnfDiagram-S7VZAUFO-GAGCW2J5.js +1 -0
- package/dist/graph/architecture-WOLXFQ4H-AWAC3VBS.js +1 -0
- package/dist/graph/architectureDiagram-YGSQEFNW-WQ7QKSUJ.js +36 -0
- package/dist/graph/blockDiagram-APKKGZFW-H7ZNJMOM.js +140 -0
- package/dist/graph/bpmnIcons-APHXDYXF-EAVPNTFE.js +1 -0
- package/dist/graph/c4Diagram-KJ2TOQU5-3IYS34YL.js +38 -0
- package/dist/graph/chunk-3CJU2RDX.js +1 -0
- package/dist/graph/chunk-3LU66YMI.js +1 -0
- package/dist/graph/chunk-3Y2PDVDE.js +1 -0
- package/dist/graph/chunk-4KILFWYV.js +339 -0
- package/dist/graph/chunk-4QDE4SUK.js +1 -0
- package/dist/graph/chunk-5N2X2DXU.js +1 -0
- package/dist/graph/chunk-5OO6DATX.js +1 -0
- package/dist/graph/chunk-67BPVAXC.js +1 -0
- package/dist/graph/chunk-6CDZONCA.js +1 -0
- package/dist/graph/chunk-7ASYMKN2.js +1 -0
- package/dist/graph/chunk-7JQUFVT4.js +10 -0
- package/dist/graph/chunk-7LSMJ4VU.js +72 -0
- package/dist/graph/chunk-7UKJADAE.js +213 -0
- package/dist/graph/chunk-AARGNXTW.js +32 -0
- package/dist/graph/chunk-ARAJTKOH.js +2 -0
- package/dist/graph/chunk-BOXAA5AP.js +62 -0
- package/dist/graph/chunk-BTMPKSGF.js +1 -0
- package/dist/graph/chunk-BVXT562I.js +1 -0
- package/dist/graph/chunk-DIDARDST.js +1 -0
- package/dist/graph/chunk-EWYECPNJ.js +1 -0
- package/dist/graph/chunk-FD7ZFC7R.js +3 -0
- package/dist/graph/chunk-GF4TOPUK.js +1 -0
- package/dist/graph/chunk-GWYODWCE.js +1 -0
- package/dist/graph/chunk-HKRJKXEE.js +1 -0
- package/dist/graph/chunk-I5LEUF24.js +1 -0
- package/dist/graph/chunk-ICJPOOXG.js +1 -0
- package/dist/graph/chunk-IVZHB6RS.js +135 -0
- package/dist/graph/chunk-JSHWCPFJ.js +1 -0
- package/dist/graph/chunk-JZGXHT3J.js +1 -0
- package/dist/graph/chunk-K4I76XBX.js +14 -0
- package/dist/graph/chunk-LSRL537V.js +88 -0
- package/dist/graph/chunk-LT6LXKCR.js +136 -0
- package/dist/graph/chunk-MPR575IN.js +1 -0
- package/dist/graph/chunk-N44XPVUD.js +15 -0
- package/dist/graph/chunk-NDAMZVXQ.js +1 -0
- package/dist/graph/chunk-O656ZI37.js +1 -0
- package/dist/graph/chunk-PDH25ALM.js +2 -0
- package/dist/graph/chunk-QLS7NIYR.js +2 -0
- package/dist/graph/chunk-QQIGL7OP.js +1 -0
- package/dist/graph/chunk-QYAXYFNI.js +1 -0
- package/dist/graph/chunk-QYTM6GY3.js +1 -0
- package/dist/graph/chunk-RJFVWYCA.js +1 -0
- package/dist/graph/chunk-SCEY3ZPT.js +1 -0
- package/dist/graph/chunk-SQE76S5B.js +1 -0
- package/dist/graph/chunk-WQHTQAFY.js +1 -0
- package/dist/graph/chunk-XQS73SBQ.js +1 -0
- package/dist/graph/chunk-Z4FIZ7CR.js +1 -0
- package/dist/graph/chunk-ZSZXN4BT.js +2 -0
- package/dist/graph/classDiagram-v2-L25IHNXF-HNTCDTNK.js +217 -0
- package/dist/graph/cose-bilkent-JH36ORCC-2GVA7XKO.js +1 -0
- package/dist/graph/cynefin-EF2NZ3EQ-TCI65RAQ.js +1 -0
- package/dist/graph/cynefinDiagram-L36ESFBY-OKQ5BLVF.js +62 -0
- package/dist/graph/dagre-SPEB5RXH-KZEBD52K.js +4 -0
- package/dist/graph/diagram-3B7GL73J-ESCBJM3O.js +200 -0
- package/dist/graph/diagram-DNEMPZML-ZIBUSQZI.js +24 -0
- package/dist/graph/diagram-L3MUGCDN-IGK62IPN.js +41 -0
- package/dist/graph/diagram-LA4NIPWU-2KZCOFJ5.js +24 -0
- package/dist/graph/diagram-MHCOC4E2-EYAAB236.js +3 -0
- package/dist/graph/diagram-XPFHEONP-OZ5ARGMG.js +30 -0
- package/dist/graph/ebnfDiagram-UZSYDL2S-M3XJHARD.js +1 -0
- package/dist/graph/erDiagram-EYBAPDEH-Y7KUBH7A.js +99 -0
- package/dist/graph/eventmodeling-K75KTNOO-ROLYRDEP.js +1 -0
- package/dist/graph/flowDiagram-MALGAFMO-AAUEIPCR.js +1 -0
- package/dist/graph/ganttDiagram-23REXITY-JSBTFSSJ.js +292 -0
- package/dist/graph/gitGraph-VSP46ZUC-ZCBCDVNF.js +1 -0
- package/dist/graph/gitGraphDiagram-STJD7YCW-3ZA5FT3G.js +106 -0
- package/dist/graph/info-OHQRW6UA-JKJGOQNY.js +1 -0
- package/dist/graph/infoDiagram-KBXO4MBG-6LFMPP2O.js +2 -0
- package/dist/graph/ishikawaDiagram-M35NCXHK-YLEU44DY.js +70 -0
- package/dist/graph/journeyDiagram-OPLOXDXO-ZHJV66ZT.js +139 -0
- package/dist/graph/kanban-definition-BZKZHSQY-SDU25WUM.js +89 -0
- package/dist/graph/katex-WSLZOTY7.js +257 -0
- package/dist/graph/mindmap-definition-I2QAS2VK-XQNBCYHN.js +98 -0
- package/dist/graph/packet-JDAUHWVQ-Y3H77ERD.js +1 -0
- package/dist/graph/pegDiagram-FD4XPPHP-YO4VWH6V.js +1 -0
- package/dist/graph/pie-XZMESJXO-PRER4XL5.js +1 -0
- package/dist/graph/pieDiagram-J4AKIIQI-TJ5WOOSV.js +39 -0
- package/dist/graph/quadrantDiagram-XTYBLID2-G6MSSZLW.js +7 -0
- package/dist/graph/radar-ABXABTNO-M6MV34GM.js +1 -0
- package/dist/graph/railroad-I3PHUGI6-YIWPGN6Q.js +1 -0
- package/dist/graph/railroad-abnf-LNEFI6M7-7JHLZ2R7.js +1 -0
- package/dist/graph/railroad-ebnf-DWYD2UWJ-V55BXEWY.js +1 -0
- package/dist/graph/railroad-peg-JR7BVNR7-XCGKDRMK.js +1 -0
- package/dist/graph/railroadDiagram-MRQ6NCDL-RACSFXC4.js +1 -0
- package/dist/graph/requirementDiagram-Y7LWUY3S-4LQIQWHQ.js +84 -0
- package/dist/graph/sankeyDiagram-WGJFYUXA-K3RXG5FB.js +40 -0
- package/dist/graph/schema-graph-global.js +639 -0
- package/dist/graph/sequenceDiagram-5NDRBG5M-Y6RBHRS3.js +169 -0
- package/dist/graph/sizeCapture-INFHLROL-TJW3VUGH.js +1 -0
- package/dist/graph/stateDiagram-v2-FJ4FJNEA-4M5WZORG.js +291 -0
- package/dist/graph/swimlanes-UMQ2AFYF-O4W6U4RO.js +1 -0
- package/dist/graph/swimlanesDiagram-OMPLPG4O-HZAKM45N.js +8 -0
- package/dist/graph/timeline-definition-SEUHKTQE-IHISQ4Q7.js +120 -0
- package/dist/graph/treeView-D4JQ5SDB-EVGY4VYS.js +1 -0
- package/dist/graph/treemap-SAJKECNS-LN3SMFRX.js +1 -0
- package/dist/graph/usecaseDiagram-AFA6YXN4-B645A3J6.js +370 -0
- package/dist/graph/vennDiagram-NNMJR3RB-K3HWMON6.js +34 -0
- package/dist/graph/wardley-7MLQ67FV-RRWOELC6.js +1 -0
- package/dist/graph/wardleyDiagram-S7YFUSEH-DMMWKJEK.js +78 -0
- package/dist/graph/xychartDiagram-GGNKY7IX-K6MUQVXR.js +7 -0
- package/dist/mcp.js +5 -4
- package/dist/plugins.global.js +71 -104
- package/dist/subformats.global.js +6 -112
- package/dist/ui.global.js +75 -108
- package/dist/viewer/build.d.ts +2 -0
- package/dist/viewer/build.js +22 -8
- package/dist/viewer/code-file.js +7 -2
- package/dist/viewer/figure-preview.d.ts +4 -0
- package/dist/viewer/figure-preview.js +54 -0
- package/dist/viewer/hmr.js +4 -3
- package/dist/viewer/lazy-preview.d.ts +2 -0
- package/dist/viewer/lazy-preview.js +43 -0
- package/dist/viewer/locales/eng.json +26 -3
- package/dist/viewer/locales/jpn.json +26 -3
- package/dist/viewer/locales/zho.json +26 -3
- package/dist/viewer/plugin-blocks.js +1 -1
- package/dist/viewer/plugins.js +1 -1
- package/dist/viewer/resource-library.d.ts +1 -1
- package/dist/viewer/resource-library.js +5 -4
- package/dist/viewer/serve.d.ts +2 -1
- package/dist/viewer/serve.js +148 -41
- package/dist/viewer/textfile.d.ts +2 -0
- package/dist/viewer/textfile.js +20 -5
- package/package.json +14 -4
- package/dist/viewer/lazy-graph.d.ts +0 -2
- package/dist/viewer/lazy-graph.js +0 -30
|
@@ -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
|
+
};
|
package/dist/core/toc-ui.js
CHANGED
|
@@ -31,7 +31,7 @@ export function mountToc(doc) {
|
|
|
31
31
|
if (!article || !button || !list)
|
|
32
32
|
continue;
|
|
33
33
|
const pane = nav.closest(".preview-pane");
|
|
34
|
-
const scroller = pane ?? doc.scrollingElement;
|
|
34
|
+
const scroller = pane ?? nav.closest("main") ?? doc.scrollingElement;
|
|
35
35
|
if (!scroller)
|
|
36
36
|
continue;
|
|
37
37
|
const header = (pane ?? article.parentElement)?.querySelector(":scope > .pane-actions, :scope > .page-actions");
|