mdld-parse 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -1
- package/dist/.nojekyll +0 -0
- package/dist/CNAME +1 -0
- package/dist/README.md +425 -0
- package/dist/docs/API.md +397 -0
- package/dist/docs/Architecture.md +190 -0
- package/dist/docs/Guide.md +322 -0
- package/dist/docs/LLM-MDLD-Inducer.md +550 -0
- package/dist/docs/Parser.md +654 -0
- package/dist/docs/Performance.md +238 -0
- package/dist/docs/Spec-render.md +1439 -0
- package/dist/docs/Subject.md +180 -0
- package/dist/docs/Syntax.md +463 -0
- package/dist/docs/TodoList.md +215 -0
- package/dist/docs/Use-Cases.md +354 -0
- package/dist/docs/index.html +108 -0
- package/dist/docs/index.md +56 -0
- package/dist/docs/origin.md +459 -0
- package/dist/docs/polarity.md +586 -0
- package/dist/docs/primary-subject.md +199 -0
- package/dist/docs/statements.md +226 -0
- package/dist/docs/tokenization-performance-report.md +164 -0
- package/dist/examples/Cookbook.md +32 -0
- package/dist/examples/Status-SHACL.md +33 -0
- package/dist/examples/demo/index.md +35 -0
- package/dist/examples/demo/journal.md +18 -0
- package/dist/examples/demo/minimal.md +11 -0
- package/dist/examples/demo/project.md +15 -0
- package/dist/examples/demo/recipe.md +31 -0
- package/dist/examples/demo/research.md +46 -0
- package/dist/examples/demo/space-mission.md +48 -0
- package/dist/examples/dogfood.md +288 -0
- package/dist/examples/few-shot.md +309 -0
- package/dist/examples/graph/rdf-graph.html +473 -0
- package/dist/examples/graph/rdf_force_graph_web_component.html +506 -0
- package/dist/examples/index.md +45 -0
- package/dist/examples/llm-time-workflow.md +173 -0
- package/dist/examples/prov-o.md +2367 -0
- package/dist/examples/rdf.md +827 -0
- package/dist/examples/shacl.md +3399 -0
- package/dist/examples/statements.md +43 -0
- package/dist/examples/workflow.md +150 -0
- package/dist/index.html +2827 -0
- package/dist/index.js +1548 -0
- package/dist/logo.svg +7 -0
- package/dist/spec/Spec-compact.md +363 -0
- package/dist/spec/Spec-ultra.md +221 -0
- package/dist/spec/Spec.md +1068 -0
- package/dist/spec/index.md +46 -0
- package/package.json +13 -8
- package/src/constants.js +0 -31
- package/src/generate.js +0 -245
- package/src/index.js +0 -13
- package/src/locate.js +0 -23
- package/src/merge.js +0 -157
- package/src/parse.js +0 -765
- package/src/render.js +0 -576
- package/src/shared.js +0 -577
- package/src/utils.js +0 -430
package/dist/index.js
ADDED
|
@@ -0,0 +1,1548 @@
|
|
|
1
|
+
//#region src/constants.js
|
|
2
|
+
var e = {
|
|
3
|
+
"@vocab": "http://www.w3.org/2000/01/rdf-schema#",
|
|
4
|
+
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
|
5
|
+
rdfs: "http://www.w3.org/2000/01/rdf-schema#",
|
|
6
|
+
xsd: "http://www.w3.org/2001/XMLSchema#",
|
|
7
|
+
sh: "http://www.w3.org/ns/shacl#",
|
|
8
|
+
prov: "http://www.w3.org/ns/prov#"
|
|
9
|
+
}, t = /^(https?|ftp|mailto|tag|nih|urn|uuid|did|web|ipfs|ipns|data|file|urn:uuid):/, n = /^(https?|ftp|mailto|tag|nih|urn|uuid|did|web|ipfs|ipns|data|file):/, r = class {
|
|
10
|
+
constructor(e) {
|
|
11
|
+
this.id = e;
|
|
12
|
+
}
|
|
13
|
+
equals(e) {
|
|
14
|
+
return !!e && this.termType === e.termType && this.value === e.value;
|
|
15
|
+
}
|
|
16
|
+
}, i = class extends r {
|
|
17
|
+
constructor(e) {
|
|
18
|
+
super(e), this.termType = "NamedNode", this.value = e;
|
|
19
|
+
}
|
|
20
|
+
}, a = class extends r {
|
|
21
|
+
constructor(e) {
|
|
22
|
+
super(e), this.termType = "Literal", this.value = "", this.language = "", this.datatype = null;
|
|
23
|
+
let t = e.match(/^"([^"\\]*(?:\\.[^"\\]*)*)"(\^\^([^"]+))?(@([^-]+)(--(.+))?)?$/);
|
|
24
|
+
t ? (this.value = t[1].replace(/\\"/g, "\"").replace(/\\\\/g, "\\"), t[5] ? (this.language = t[5], this.datatype = new i("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString")) : t[3] ? this.datatype = new i(t[3]) : this.datatype = new i("http://www.w3.org/2001/XMLSchema#string")) : (this.value = e.replace(/^"|"$/g, ""), this.datatype = new i("http://www.w3.org/2001/XMLSchema#string"));
|
|
25
|
+
}
|
|
26
|
+
equals(e) {
|
|
27
|
+
return !!e && this.termType === e.termType && this.value === e.value && this.language === e.language && this.datatype?.value === e.datatype?.value;
|
|
28
|
+
}
|
|
29
|
+
}, o = class extends r {
|
|
30
|
+
constructor(e) {
|
|
31
|
+
super(e || `b${Math.random().toString(36).slice(2, 11)}`), this.termType = "BlankNode", this.value = this.id;
|
|
32
|
+
}
|
|
33
|
+
}, s = class extends r {
|
|
34
|
+
constructor(e) {
|
|
35
|
+
super(e), this.termType = "Variable", this.value = e;
|
|
36
|
+
}
|
|
37
|
+
}, c = new class extends r {
|
|
38
|
+
constructor() {
|
|
39
|
+
super(""), this.termType = "DefaultGraph", this.value = "";
|
|
40
|
+
}
|
|
41
|
+
equals(e) {
|
|
42
|
+
return !!e && this.termType === e.termType;
|
|
43
|
+
}
|
|
44
|
+
}(), l = class extends r {
|
|
45
|
+
constructor(e, t, n, r = c) {
|
|
46
|
+
super(`${e.id}|${t.id}|${n.id}|${r.id}`), this.termType = "Quad", this.subject = e, this.predicate = t, this.object = n, this.graph = r;
|
|
47
|
+
}
|
|
48
|
+
equals(e) {
|
|
49
|
+
return !!e && this.termType === e.termType && this.subject.equals(e.subject) && this.predicate.equals(e.predicate) && this.object.equals(e.object) && this.graph.equals(e.graph);
|
|
50
|
+
}
|
|
51
|
+
toJSON() {
|
|
52
|
+
return {
|
|
53
|
+
termType: this.termType,
|
|
54
|
+
subject: this.subject.toJSON ? this.subject.toJSON() : {
|
|
55
|
+
termType: this.subject.termType,
|
|
56
|
+
value: this.subject.value
|
|
57
|
+
},
|
|
58
|
+
predicate: this.predicate.toJSON ? this.predicate.toJSON() : {
|
|
59
|
+
termType: this.predicate.termType,
|
|
60
|
+
value: this.predicate.value
|
|
61
|
+
},
|
|
62
|
+
object: this.object.toJSON ? this.object.toJSON() : {
|
|
63
|
+
termType: this.object.termType,
|
|
64
|
+
value: this.object.value
|
|
65
|
+
},
|
|
66
|
+
graph: this.graph.toJSON ? this.graph.toJSON() : {
|
|
67
|
+
termType: this.graph.termType,
|
|
68
|
+
value: this.graph.value
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}, u = {
|
|
73
|
+
boolean: "http://www.w3.org/2001/XMLSchema#boolean",
|
|
74
|
+
integer: "http://www.w3.org/2001/XMLSchema#integer",
|
|
75
|
+
double: "http://www.w3.org/2001/XMLSchema#double",
|
|
76
|
+
string: "http://www.w3.org/2001/XMLSchema#string"
|
|
77
|
+
}, d = {
|
|
78
|
+
namedNode: (e) => new i(e),
|
|
79
|
+
blankNode: (e) => new o(e),
|
|
80
|
+
literal: (e, t) => {
|
|
81
|
+
let n = String(e).replace(/"/g, "\\\"");
|
|
82
|
+
if (typeof t == "string") return new a(`"${n}"@${t.toLowerCase()}`);
|
|
83
|
+
if (t !== void 0 && !("termType" in t)) {
|
|
84
|
+
let e = t.direction ? `--${t.direction.toLowerCase()}` : "";
|
|
85
|
+
return new a(`"${n}"@${t.language.toLowerCase()}${e}`);
|
|
86
|
+
}
|
|
87
|
+
let r = t ? t.value : "";
|
|
88
|
+
return r === "" && (typeof e == "boolean" ? r = u.boolean : typeof e == "number" && (Number.isFinite(e) ? r = Number.isInteger(e) ? u.integer : u.double : (r = u.double, Number.isNaN(e) || (e = e > 0 ? "INF" : "-INF")))), r === "" || r === u.string ? new a(`"${n}"`) : new a(`"${n}"^^${r}`);
|
|
89
|
+
},
|
|
90
|
+
variable: (e) => new s(e),
|
|
91
|
+
defaultGraph: () => c,
|
|
92
|
+
quad: (e, t, n, r) => new l(e, t, n, r),
|
|
93
|
+
triple: (e, t, n, r) => new l(e, t, n, r),
|
|
94
|
+
fromTerm: (e) => {
|
|
95
|
+
if (e instanceof r) return e;
|
|
96
|
+
switch (e.termType) {
|
|
97
|
+
case "NamedNode": return new i(e.value);
|
|
98
|
+
case "BlankNode": return new o(e.value);
|
|
99
|
+
case "Variable": return new s(e.value);
|
|
100
|
+
case "DefaultGraph": return c;
|
|
101
|
+
case "Literal":
|
|
102
|
+
let t = String(e.value).replace(/"/g, "\\\"");
|
|
103
|
+
return e.language ? new a(`"${t}"@${e.language}`) : e.datatype ? new a(`"${t}"^^${e.datatype.value || e.datatype}`) : new a(`"${t}"`);
|
|
104
|
+
case "Quad": return d.fromQuad(e);
|
|
105
|
+
default: throw Error(`Unexpected termType: ${e.termType}`);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
fromQuad: (e) => {
|
|
109
|
+
if (e instanceof l) return e;
|
|
110
|
+
if (e.termType !== "Quad") {
|
|
111
|
+
if (e.subject && e.predicate && e.object) return new l(d.fromTerm(e.subject), d.fromTerm(e.predicate), d.fromTerm(e.object), d.fromTerm(e.graph || d.defaultGraph()));
|
|
112
|
+
throw Error(`Unexpected termType: ${e.termType}`);
|
|
113
|
+
}
|
|
114
|
+
return new l(d.fromTerm(e.subject), d.fromTerm(e.predicate), d.fromTerm(e.object), d.fromTerm(e.graph));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function f(e, t) {
|
|
118
|
+
if (!e || !t || !t.quadIndex) return null;
|
|
119
|
+
let n = y(e);
|
|
120
|
+
return n && t.quadIndex.get(n) || null;
|
|
121
|
+
}
|
|
122
|
+
function p(e) {
|
|
123
|
+
let t = 5381;
|
|
124
|
+
for (let n = 0; n < e.length; n++) t = (t << 5) + t + e.charCodeAt(n);
|
|
125
|
+
return Math.abs(t).toString(16).slice(0, 12);
|
|
126
|
+
}
|
|
127
|
+
var m = /* @__PURE__ */ new Map();
|
|
128
|
+
function h(e, n) {
|
|
129
|
+
if (e == null) return null;
|
|
130
|
+
let r = `${e}|${n["@vocab"] || ""}|${Object.keys(n).filter((e) => e !== "@vocab").sort().map((e) => `${e}:${n[e]}`).join(",")}`;
|
|
131
|
+
if (m.has(r)) return m.get(r);
|
|
132
|
+
let i = (typeof e == "string" ? e : typeof e == "object" && typeof e.value == "string" ? e.value : String(e)).trim(), a;
|
|
133
|
+
if (i.match(t)) a = i;
|
|
134
|
+
else if (i.includes(":")) {
|
|
135
|
+
let [e, t] = i.split(":", 2);
|
|
136
|
+
e && !n[e] && e !== "@vocab" && console.warn(`Undefined prefix "${e}" in IRI "${i}" - treating as literal`), a = n[e] ? n[e] + t : i;
|
|
137
|
+
} else a = (n["@vocab"] || "") + i;
|
|
138
|
+
return m.set(r, a), a;
|
|
139
|
+
}
|
|
140
|
+
function g(e, t) {
|
|
141
|
+
if (!e || !n.test(e)) return e;
|
|
142
|
+
if (t["@vocab"] && e.startsWith(t["@vocab"])) return e.substring(t["@vocab"].length);
|
|
143
|
+
for (let [n, r] of Object.entries(t)) if (n !== "@vocab" && e.startsWith(r) && Object.entries(t).filter(([t, n]) => t !== "@vocab" && e.startsWith(n)).every(([e, t]) => r.length >= t.length || e === n && t.length === r.length)) return n + ":" + e.substring(r.length);
|
|
144
|
+
return e;
|
|
145
|
+
}
|
|
146
|
+
var ee = {
|
|
147
|
+
"=#": {
|
|
148
|
+
kind: "fragment",
|
|
149
|
+
extract: (e) => e.substring(2).replace("}", "")
|
|
150
|
+
},
|
|
151
|
+
"+#": {
|
|
152
|
+
kind: "softFragment",
|
|
153
|
+
extract: (e) => e.substring(2).replace("}", "")
|
|
154
|
+
},
|
|
155
|
+
"+": {
|
|
156
|
+
kind: "object",
|
|
157
|
+
extract: (e) => e.substring(1)
|
|
158
|
+
},
|
|
159
|
+
"^^": {
|
|
160
|
+
kind: "datatype",
|
|
161
|
+
extract: (e) => e.substring(2)
|
|
162
|
+
},
|
|
163
|
+
"@": {
|
|
164
|
+
kind: "language",
|
|
165
|
+
extract: (e) => e.substring(1)
|
|
166
|
+
},
|
|
167
|
+
".": {
|
|
168
|
+
kind: "type",
|
|
169
|
+
extract: (e) => e.substring(1)
|
|
170
|
+
},
|
|
171
|
+
"!": {
|
|
172
|
+
kind: "property",
|
|
173
|
+
form: "!",
|
|
174
|
+
extract: (e) => e.substring(1)
|
|
175
|
+
},
|
|
176
|
+
"?": {
|
|
177
|
+
kind: "property",
|
|
178
|
+
form: "?",
|
|
179
|
+
extract: (e) => e.substring(1)
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
function _(e) {
|
|
183
|
+
try {
|
|
184
|
+
let t = String(e || "").trim().replace(/^\{|\}$/g, "").trim();
|
|
185
|
+
if (!t) return {
|
|
186
|
+
subject: null,
|
|
187
|
+
object: null,
|
|
188
|
+
types: [],
|
|
189
|
+
predicates: [],
|
|
190
|
+
datatype: null,
|
|
191
|
+
language: null,
|
|
192
|
+
entries: []
|
|
193
|
+
};
|
|
194
|
+
let n = {
|
|
195
|
+
subject: null,
|
|
196
|
+
object: null,
|
|
197
|
+
types: [],
|
|
198
|
+
predicates: [],
|
|
199
|
+
datatype: null,
|
|
200
|
+
language: null,
|
|
201
|
+
entries: []
|
|
202
|
+
}, r = /\S+/g, i;
|
|
203
|
+
for (; (i = r.exec(t)) !== null;) {
|
|
204
|
+
let e = i[0], t = 1 + i.index, r = t + e.length, a = n.entries.length, o = !1;
|
|
205
|
+
if (e.startsWith("-") && e.length > 1 && (o = !0, e = e.slice(1)), e === "=") {
|
|
206
|
+
o && console.warn("-= is not valid, subject declarations have no polarity"), n.subject = "RESET", n.entries.push({
|
|
207
|
+
kind: "subjectReset",
|
|
208
|
+
relRange: {
|
|
209
|
+
start: t,
|
|
210
|
+
end: r
|
|
211
|
+
},
|
|
212
|
+
raw: e
|
|
213
|
+
});
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (e.startsWith("=") && !e.startsWith("=#")) {
|
|
217
|
+
o && console.warn("-= is not valid, subject declarations have no polarity");
|
|
218
|
+
let i = e.substring(1);
|
|
219
|
+
n.subject = i, n.entries.push({
|
|
220
|
+
kind: "subject",
|
|
221
|
+
iri: i,
|
|
222
|
+
relRange: {
|
|
223
|
+
start: t,
|
|
224
|
+
end: r
|
|
225
|
+
},
|
|
226
|
+
raw: e
|
|
227
|
+
});
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
let s = !1;
|
|
231
|
+
for (let [c, l] of Object.entries(ee)) if (e.startsWith(c)) {
|
|
232
|
+
let c = {
|
|
233
|
+
kind: l.kind,
|
|
234
|
+
relRange: {
|
|
235
|
+
start: t,
|
|
236
|
+
end: r
|
|
237
|
+
},
|
|
238
|
+
raw: i[0]
|
|
239
|
+
}, u = l.extract(e);
|
|
240
|
+
l.kind === "fragment" ? (n.subject = `=#${u}`, c.fragment = u) : l.kind === "softFragment" ? (n.object = `#${u}`, c.fragment = u) : l.kind === "object" ? (o && (console.warn("-+ is not valid, object declarations have no polarity"), o = !1), n.object = u, c.iri = u) : l.kind === "datatype" ? (o && (console.warn("-^^ is not valid, datatype modifiers have no polarity"), o = !1), n.language || (n.datatype = u), c.datatype = u) : l.kind === "language" ? (o && (console.warn("-@ is not valid, language modifiers have no polarity"), o = !1), n.language = u, n.datatype = null, c.language = u) : l.kind === "type" ? (n.types.push({
|
|
241
|
+
iri: u,
|
|
242
|
+
entryIndex: a,
|
|
243
|
+
remove: o
|
|
244
|
+
}), c.iri = u, c.remove = o) : l.kind === "property" && (n.predicates.push({
|
|
245
|
+
iri: u,
|
|
246
|
+
form: l.form,
|
|
247
|
+
entryIndex: a,
|
|
248
|
+
remove: o
|
|
249
|
+
}), c.iri = u, c.form = l.form, c.remove = o), n.entries.push(c), s = !0;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
s || (n.predicates.push({
|
|
253
|
+
iri: e,
|
|
254
|
+
form: "",
|
|
255
|
+
entryIndex: a,
|
|
256
|
+
remove: o
|
|
257
|
+
}), n.entries.push({
|
|
258
|
+
kind: "property",
|
|
259
|
+
iri: e,
|
|
260
|
+
form: "",
|
|
261
|
+
relRange: {
|
|
262
|
+
start: t,
|
|
263
|
+
end: r
|
|
264
|
+
},
|
|
265
|
+
raw: i[0],
|
|
266
|
+
remove: o
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
return n;
|
|
270
|
+
} catch (t) {
|
|
271
|
+
return console.error(`Error parsing semantic block ${e}:`, t), {
|
|
272
|
+
subject: null,
|
|
273
|
+
object: null,
|
|
274
|
+
types: [],
|
|
275
|
+
predicates: [],
|
|
276
|
+
datatype: null,
|
|
277
|
+
language: null,
|
|
278
|
+
entries: []
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function v(e, t, n) {
|
|
283
|
+
let r = n.termType === "Literal" ? JSON.stringify({
|
|
284
|
+
t: "Literal",
|
|
285
|
+
v: n.value,
|
|
286
|
+
lang: n.language || "",
|
|
287
|
+
dt: n.datatype?.value || ""
|
|
288
|
+
}) : JSON.stringify({
|
|
289
|
+
t: n.termType,
|
|
290
|
+
v: n.value
|
|
291
|
+
});
|
|
292
|
+
return JSON.stringify([
|
|
293
|
+
e.value,
|
|
294
|
+
t.value,
|
|
295
|
+
r
|
|
296
|
+
]);
|
|
297
|
+
}
|
|
298
|
+
function y(e) {
|
|
299
|
+
return e ? v(e.subject, e.predicate, e.object) : null;
|
|
300
|
+
}
|
|
301
|
+
function te(e, t, n, r, i) {
|
|
302
|
+
return t ? i.literal(e, i.namedNode(h(t, r))) : n ? i.literal(e, n) : i.literal(e);
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/tokenizers.js
|
|
306
|
+
function b(e) {
|
|
307
|
+
if (e.length < 3) return null;
|
|
308
|
+
let t = e[0];
|
|
309
|
+
if (t !== "`" && t !== "~") return null;
|
|
310
|
+
let n = 1;
|
|
311
|
+
for (; n < e.length && e[n] === t;) n++;
|
|
312
|
+
if (n < 3) return null;
|
|
313
|
+
let r = e.slice(n).trimStart(), i = r.match(/^([^\s{]+)/), a = i ? i[1] : "", o = r.match(/\{([^}]+)\}/), s = o ? o[1] : null;
|
|
314
|
+
return {
|
|
315
|
+
fenceChar: t,
|
|
316
|
+
fenceLength: n,
|
|
317
|
+
lang: a,
|
|
318
|
+
attrs: s,
|
|
319
|
+
infoString: r
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function x(e) {
|
|
323
|
+
if (e[0] !== "[") return null;
|
|
324
|
+
let t = e.indexOf("]", 1);
|
|
325
|
+
if (t === -1) return null;
|
|
326
|
+
let n = e.slice(1, t).trim();
|
|
327
|
+
if (!n) return null;
|
|
328
|
+
let r = t + 1;
|
|
329
|
+
for (; r < e.length && (e[r] === " " || e[r] === " ");) r++;
|
|
330
|
+
if (r >= e.length || e[r] !== "<") return null;
|
|
331
|
+
let i = e.indexOf(">", r + 1);
|
|
332
|
+
if (i === -1) return null;
|
|
333
|
+
let a = e.slice(r + 1, i).trim();
|
|
334
|
+
return a ? {
|
|
335
|
+
prefix: n,
|
|
336
|
+
iri: a
|
|
337
|
+
} : null;
|
|
338
|
+
}
|
|
339
|
+
function S(e) {
|
|
340
|
+
if (e[0] !== "#") return null;
|
|
341
|
+
let t = 1;
|
|
342
|
+
for (; t < e.length && t < 6 && e[t] === "#";) t++;
|
|
343
|
+
if (t >= e.length || e[t] !== " " && e[t] !== " ") return null;
|
|
344
|
+
let n = t;
|
|
345
|
+
for (; n < e.length && (e[n] === " " || e[n] === " ");) n++;
|
|
346
|
+
let r = e.slice(n), i = r.match(/\s*\{([^}]+)\}\s*$/), a = r, o = null;
|
|
347
|
+
return i && (o = i[1], a = r.slice(0, -i[0].length).trim()), {
|
|
348
|
+
depth: t,
|
|
349
|
+
content: a,
|
|
350
|
+
attrs: o
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function C(e) {
|
|
354
|
+
let t = 0;
|
|
355
|
+
for (; t < e.length && (e[t] === " " || e[t] === " ");) t++;
|
|
356
|
+
let n = t;
|
|
357
|
+
if (t >= e.length) return null;
|
|
358
|
+
let r = e[t], i, a = t + 1;
|
|
359
|
+
if (r === "-" || r === "*" || r === "+") i = r;
|
|
360
|
+
else if (r >= "0" && r <= "9") {
|
|
361
|
+
let n = t + 1;
|
|
362
|
+
for (; n < e.length && e[n] >= "0" && e[n] <= "9";) n++;
|
|
363
|
+
if (n >= e.length || e[n] !== ".") return null;
|
|
364
|
+
i = e.slice(t, n + 1), a = n + 1;
|
|
365
|
+
} else return null;
|
|
366
|
+
if (a >= e.length || e[a] !== " " && e[a] !== " ") return null;
|
|
367
|
+
for (; a < e.length && (e[a] === " " || e[a] === " ");) a++;
|
|
368
|
+
let o = e.slice(a), s = null, c = o.match(/\s*\{([^}]+)\}\s*$/);
|
|
369
|
+
return c && (s = c[1], o = o.slice(0, -c[0].length).trim()), {
|
|
370
|
+
indent: n,
|
|
371
|
+
marker: i,
|
|
372
|
+
content: o,
|
|
373
|
+
attrs: s
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function w(e) {
|
|
377
|
+
if (e[0] !== ">" || e.length > 1 && e[1] !== " " && e[1] !== " ") return null;
|
|
378
|
+
let t = 1;
|
|
379
|
+
for (; t < e.length && (e[t] === " " || e[t] === " ");) t++;
|
|
380
|
+
let n = e.slice(t), r = null, i = n.match(/\s*\{([^}]+)\}\s*$/);
|
|
381
|
+
return i && (r = i[1], n = n.slice(0, -i[0].length).trim()), {
|
|
382
|
+
content: n,
|
|
383
|
+
attrs: r
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function T(e) {
|
|
387
|
+
let t = 0;
|
|
388
|
+
for (; t < e.length && (e[t] === " " || e[t] === " ");) t++;
|
|
389
|
+
if (t >= e.length || e[t] !== "{" || (t++, t >= e.length || e[t] !== "=")) return null;
|
|
390
|
+
t++;
|
|
391
|
+
let n = t, r = 1;
|
|
392
|
+
for (; t < e.length && r > 0;) e[t] === "{" && r++, e[t] === "}" && r--, r > 0 && t++;
|
|
393
|
+
if (r > 0) return null;
|
|
394
|
+
let i = e.slice(n, t).trim();
|
|
395
|
+
for (t++; t < e.length && (e[t] === " " || e[t] === " ");) t++;
|
|
396
|
+
return t < e.length ? null : { content: i };
|
|
397
|
+
}
|
|
398
|
+
function ne(e, t, n = "[", r = "]") {
|
|
399
|
+
let i = 1, a = t + 1;
|
|
400
|
+
for (; a < e.length && i > 0;) e[a] === n && i++, e[a] === r && i--, i > 0 && a++;
|
|
401
|
+
return i === 0 ? a : null;
|
|
402
|
+
}
|
|
403
|
+
function E(e, t) {
|
|
404
|
+
let n = t;
|
|
405
|
+
for (; n < e.length && (e[n] === " " || e[n] === " ");) n++;
|
|
406
|
+
if (n >= e.length || e[n] !== "{") return null;
|
|
407
|
+
let r = e.indexOf("}", n + 1);
|
|
408
|
+
return r === -1 ? null : {
|
|
409
|
+
attrs: e.slice(n + 1, r),
|
|
410
|
+
endPos: r + 1
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function re(e, t) {
|
|
414
|
+
if (e[t] !== "<") return null;
|
|
415
|
+
let n = e.indexOf(">", t + 1);
|
|
416
|
+
if (n === -1) return null;
|
|
417
|
+
let r = e.slice(t + 1, n).trim();
|
|
418
|
+
return r.match(/^[a-zA-Z][a-zA-Z0-9+\-.]*:/) ? {
|
|
419
|
+
url: r,
|
|
420
|
+
endPos: n + 1
|
|
421
|
+
} : null;
|
|
422
|
+
}
|
|
423
|
+
function ie(e, t) {
|
|
424
|
+
let n = e[t];
|
|
425
|
+
if (n !== "*" && n !== "_") return null;
|
|
426
|
+
let r = 1;
|
|
427
|
+
for (; t + r < e.length && e[t + r] === n;) r++;
|
|
428
|
+
if (r > 2) return null;
|
|
429
|
+
let i = r === 1 ? "emphasis" : "strong", a = n.repeat(r), o = t + r, s = o;
|
|
430
|
+
for (; s < e.length;) {
|
|
431
|
+
if (e.slice(s, s + r) === a) {
|
|
432
|
+
if (s + r < e.length && e[s + r] === n) {
|
|
433
|
+
s++;
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
let t = e.slice(o, s), a = s + r, c = E(e, a), l = c ? c.endPos : a;
|
|
437
|
+
return {
|
|
438
|
+
type: i,
|
|
439
|
+
content: t,
|
|
440
|
+
attrs: c?.attrs || null,
|
|
441
|
+
endPos: l,
|
|
442
|
+
contentEnd: a
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
s++;
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
function ae(e, t) {
|
|
450
|
+
if (e[t] !== "`") return null;
|
|
451
|
+
let n = 1;
|
|
452
|
+
for (; t + n < e.length && e[t + n] === "`";) n++;
|
|
453
|
+
if (n > 2) return null;
|
|
454
|
+
let r = "`".repeat(n), i = t + n, a = i;
|
|
455
|
+
for (; a < e.length;) {
|
|
456
|
+
if (e.slice(a, a + n) === r) {
|
|
457
|
+
let t = e.slice(i, a), r = a + n, o = E(e, r), s = o ? o.endPos : r;
|
|
458
|
+
return {
|
|
459
|
+
type: "code",
|
|
460
|
+
content: t,
|
|
461
|
+
attrs: o?.attrs || null,
|
|
462
|
+
endPos: s,
|
|
463
|
+
contentEnd: r
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
a++;
|
|
467
|
+
}
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
function oe(e, t) {
|
|
471
|
+
if (e[t] !== "[") return null;
|
|
472
|
+
let n = ne(e, t, "[", "]");
|
|
473
|
+
if (!n) return null;
|
|
474
|
+
let r = e.slice(t + 1, n), i = n + 1, a = null;
|
|
475
|
+
if (i < e.length && e[i] === "(") {
|
|
476
|
+
let t = e.indexOf(")", i + 1);
|
|
477
|
+
t !== -1 && (a = e.slice(i + 1, t), i = t + 1);
|
|
478
|
+
} else if (i < e.length && e[i] === "<") {
|
|
479
|
+
let t = e.indexOf(">", i + 1);
|
|
480
|
+
if (t !== -1) {
|
|
481
|
+
let n = e.slice(i + 1, t).trim();
|
|
482
|
+
n.match(/^[a-zA-Z][a-zA-Z0-9+\-.]*:/) && (a = n, i = t + 1);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
let o = E(e, i), s = o ? o.endPos : i;
|
|
486
|
+
return {
|
|
487
|
+
type: a ? "link" : "span",
|
|
488
|
+
text: r,
|
|
489
|
+
url: a,
|
|
490
|
+
attrs: o?.attrs || null,
|
|
491
|
+
endPos: s,
|
|
492
|
+
bracketEnd: n + 1
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function se(e, t = 0) {
|
|
496
|
+
let n = [], r = e.length, i = 0;
|
|
497
|
+
for (; i < r;) {
|
|
498
|
+
let r = e[i], a = null;
|
|
499
|
+
switch (r) {
|
|
500
|
+
case "<":
|
|
501
|
+
if (a = re(e, i), a) {
|
|
502
|
+
let t = E(e, a.endPos);
|
|
503
|
+
t && (a.attrs = t.attrs, a.endPos = t.endPos), a.type = "link", a.text = a.url;
|
|
504
|
+
}
|
|
505
|
+
break;
|
|
506
|
+
case "[":
|
|
507
|
+
a = oe(e, i);
|
|
508
|
+
break;
|
|
509
|
+
case "*":
|
|
510
|
+
case "_":
|
|
511
|
+
a = ie(e, i);
|
|
512
|
+
break;
|
|
513
|
+
case "`":
|
|
514
|
+
a = ae(e, i);
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
if (!a) {
|
|
518
|
+
i++;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
let o = a.url, s = a.type, c = a.attrs;
|
|
522
|
+
if (o?.startsWith("=") || s === "link" && !c && !o) {
|
|
523
|
+
i = a.endPos;
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
let l = t + i, u = t + a.endPos, d = t + (a.contentEnd || a.bracketEnd || a.endPos), f = {
|
|
527
|
+
type: s,
|
|
528
|
+
text: a.content === void 0 ? a.text === void 0 ? o : a.text : a.content,
|
|
529
|
+
range: [l, u],
|
|
530
|
+
valueRange: [l + +(s === "url"), d - +(s === "url")],
|
|
531
|
+
attrs: c,
|
|
532
|
+
url: o,
|
|
533
|
+
pos: a.endPos
|
|
534
|
+
};
|
|
535
|
+
c && (f.attrsRange = [d, u]), n.push(f), i = a.endPos;
|
|
536
|
+
}
|
|
537
|
+
return n;
|
|
538
|
+
}
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/shared.js
|
|
541
|
+
var D = /* @__PURE__ */ new Map();
|
|
542
|
+
function ce(e) {
|
|
543
|
+
return D.has(e) || D.set(e, RegExp(`^(${e}{3,})`)), D.get(e);
|
|
544
|
+
}
|
|
545
|
+
function O(e, t, n, r, i) {
|
|
546
|
+
let a = r + (r < e.length && e[r] === " " ? 1 : e.slice(r).match(/^\s+/)?.[0]?.length || 0);
|
|
547
|
+
return {
|
|
548
|
+
valueRange: [n + a, n + a + i],
|
|
549
|
+
attrsRange: k(e, t, n)
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function k(e, t, n) {
|
|
553
|
+
if (!t) return null;
|
|
554
|
+
let r = e.lastIndexOf(t);
|
|
555
|
+
return r >= 0 ? [n + r, n + r + t.length] : null;
|
|
556
|
+
}
|
|
557
|
+
function A(e, t, n, r = null, i = null, a = null, o = {}) {
|
|
558
|
+
let s = {
|
|
559
|
+
type: e,
|
|
560
|
+
range: t,
|
|
561
|
+
text: n,
|
|
562
|
+
attrs: r,
|
|
563
|
+
attrsRange: i,
|
|
564
|
+
valueRange: a,
|
|
565
|
+
...o
|
|
566
|
+
};
|
|
567
|
+
return Object.defineProperty(s, "_carriers", {
|
|
568
|
+
enumerable: !1,
|
|
569
|
+
writable: !0,
|
|
570
|
+
value: null
|
|
571
|
+
}), s;
|
|
572
|
+
}
|
|
573
|
+
function le(e, t, n, r, i) {
|
|
574
|
+
let a = i[4] || null, o = O(t, a, n, i[1].length + (i[2] ? i[2].length : 0), i[3].length);
|
|
575
|
+
return A(e, [n, r - 1], i[3].trim(), a, o.attrsRange, o.valueRange, { indent: i[1].length });
|
|
576
|
+
}
|
|
577
|
+
var j = {}, ue = Object.freeze({
|
|
578
|
+
predicates: [],
|
|
579
|
+
types: [],
|
|
580
|
+
subject: null
|
|
581
|
+
});
|
|
582
|
+
function M(e) {
|
|
583
|
+
if (!e) return ue;
|
|
584
|
+
let t = j[e];
|
|
585
|
+
return t || (t = Object.freeze(_(e)), j[e] = t), t;
|
|
586
|
+
}
|
|
587
|
+
function de(e, t) {
|
|
588
|
+
if (!e.range || !t) return 0;
|
|
589
|
+
let n = t.substring(e.range.start, e.range.end).match(/^(\s*)/), r = n ? n[1].length : 0;
|
|
590
|
+
return Math.floor(r / 2);
|
|
591
|
+
}
|
|
592
|
+
function fe(e, t, n = null) {
|
|
593
|
+
if (!t || !e) return "";
|
|
594
|
+
let r = e.substring(t[0], t[1]);
|
|
595
|
+
return n && (r = r.substring(0, n[0] - t[0]) + r.substring(n[1] - t[0])), r.trim();
|
|
596
|
+
}
|
|
597
|
+
function pe(e) {
|
|
598
|
+
if (!e.text) return "";
|
|
599
|
+
let t = e.text;
|
|
600
|
+
e.attrsRange && (t = t.substring(0, e.attrsRange[0] - (e.range?.[0] || 0)) + t.substring(e.attrsRange[1] - (e.range?.[0] || 0)));
|
|
601
|
+
let n = (e._carriers || []).filter((e) => e.attrsRange).map((t) => t.attrsRange.map((t) => t - (e.range?.[0] || 0))).filter(([e, n]) => e >= 0 && n <= t.length).sort((e, t) => t[0] - e[0]);
|
|
602
|
+
for (let [e, r] of n) t = t.substring(0, e) + t.substring(r);
|
|
603
|
+
switch (e.type) {
|
|
604
|
+
case "heading": return t.replace(/^#+\s*/, "").trim();
|
|
605
|
+
case "list": return t.replace(/^[-*+]\s*/, "").trim();
|
|
606
|
+
case "blockquote": return t.replace(/^>\s*/, "").trim();
|
|
607
|
+
default: return t.trim();
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
function me(e, t, n, r = null) {
|
|
611
|
+
return {
|
|
612
|
+
blockId: e.id,
|
|
613
|
+
range: e.range,
|
|
614
|
+
carrierType: e.carrierType,
|
|
615
|
+
subject: t.value,
|
|
616
|
+
predicate: n.value,
|
|
617
|
+
context: e.context,
|
|
618
|
+
polarity: r?.remove ? "-" : "+",
|
|
619
|
+
value: e.text || ""
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
function N(e, t, n) {
|
|
623
|
+
if (!t) return null;
|
|
624
|
+
let r = t.value, i = r.indexOf("#"), a = i > -1 ? r.slice(0, i) : r;
|
|
625
|
+
return n.namedNode(a + "#" + e);
|
|
626
|
+
}
|
|
627
|
+
function P(e, t) {
|
|
628
|
+
return e.subject ? e.subject === "RESET" ? (t.currentSubject = null, null) : e.subject.startsWith("=#") ? N(e.subject.substring(2), t.currentSubject, t.df) : t.df.namedNode(h(e.subject, t.ctx)) : null;
|
|
629
|
+
}
|
|
630
|
+
function he(e, t) {
|
|
631
|
+
return e.object ? e.object.startsWith("#") ? N(e.object.substring(1), t.currentSubject, t.df) : t.df.namedNode(h(e.object, t.ctx)) : null;
|
|
632
|
+
}
|
|
633
|
+
function F(e) {
|
|
634
|
+
return e ? e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'") : "";
|
|
635
|
+
}
|
|
636
|
+
function I(e) {
|
|
637
|
+
return e?.termType === "Literal";
|
|
638
|
+
}
|
|
639
|
+
function L(e) {
|
|
640
|
+
return e?.termType === "NamedNode";
|
|
641
|
+
}
|
|
642
|
+
function ge(e) {
|
|
643
|
+
return e?.value === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
|
|
644
|
+
}
|
|
645
|
+
function R(e, t) {
|
|
646
|
+
if (!e) return null;
|
|
647
|
+
let n = g(e, t);
|
|
648
|
+
return n.includes(":") ? n.split(":")[0] : null;
|
|
649
|
+
}
|
|
650
|
+
function _e(e, t) {
|
|
651
|
+
let n = /* @__PURE__ */ new Set();
|
|
652
|
+
for (let r of e.values()) for (let e of r) {
|
|
653
|
+
let r = R(e.subject.value, t);
|
|
654
|
+
r && n.add(r);
|
|
655
|
+
let i = R(e.predicate.value, t);
|
|
656
|
+
if (i && n.add(i), L(e.object)) {
|
|
657
|
+
let r = R(e.object.value, t);
|
|
658
|
+
r && n.add(r);
|
|
659
|
+
}
|
|
660
|
+
if (e.object.datatype && e.object.datatype.value) {
|
|
661
|
+
let r = R(e.object.datatype.value, t);
|
|
662
|
+
r && n.add(r);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return n;
|
|
666
|
+
}
|
|
667
|
+
function z(e, t, n, r, i = []) {
|
|
668
|
+
let a = r(e, t);
|
|
669
|
+
t.currentBlock = a, t.blockStack.push(a.id), i.forEach((n) => n(e, t)), n(e, t, e.type), t.blockStack.pop(), t.currentBlock = t.blockStack.length > 0 ? t.origin.blocks.get(t.blockStack[t.blockStack.length - 1]) : null;
|
|
670
|
+
}
|
|
671
|
+
function B(e) {
|
|
672
|
+
return e.sort((e, t) => e.predicate.value.localeCompare(t.predicate.value));
|
|
673
|
+
}
|
|
674
|
+
var ve = (e, t) => `[${e}] <${t}>\n`;
|
|
675
|
+
function ye(e, t) {
|
|
676
|
+
let n = g(e.predicate.value, t);
|
|
677
|
+
e.object.language ? n += ` @${e.object.language}` : e.object.datatype.value !== "http://www.w3.org/2001/XMLSchema#string" && (n += ` ^^${g(e.object.datatype.value, t)}`);
|
|
678
|
+
let r = e.object.value || e.object, i = typeof r == "string" ? r : String(r), a = e.object.datatype?.value || "";
|
|
679
|
+
return i.includes("\n") ? `~~~ {${n}}\n${i}\n~~~\n\n` : a.includes("integer") || a.includes("decimal") || a.includes("double") || a.includes("float") ? `\`${i}\` {${n}}\n` : a.includes("date") || a.includes("time") ? `*${i}* {${n}}\n` : a.includes("boolean") ? `**${i}** {${n}}\n` : `[${i}] {${n}}\n`;
|
|
680
|
+
}
|
|
681
|
+
var be = (e, t, n = null) => {
|
|
682
|
+
let r = g(e.object.value, t), i = g(e.predicate.value, t);
|
|
683
|
+
return `[${n && n.has(e.object.value) ? n.get(e.object.value) : r}] {+${r} ?${i}}\n`;
|
|
684
|
+
};
|
|
685
|
+
function xe(e) {
|
|
686
|
+
let t = [], n = [], r = [];
|
|
687
|
+
for (let i of e) ge(i.predicate) ? t.push(i) : I(i.object) ? n.push(i) : L(i.object) && r.push(i);
|
|
688
|
+
return {
|
|
689
|
+
types: t,
|
|
690
|
+
literals: n,
|
|
691
|
+
objects: r
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
//#endregion
|
|
695
|
+
//#region src/parse.js
|
|
696
|
+
function V(t, n = {}) {
|
|
697
|
+
let r = typeof t == "object" && !!t && "text" in t, i = r ? t.text : t, a = r ? {
|
|
698
|
+
context: t.context,
|
|
699
|
+
dataFactory: t.dataFactory,
|
|
700
|
+
graph: t.graph
|
|
701
|
+
} : n, o = {
|
|
702
|
+
ctx: {
|
|
703
|
+
...e,
|
|
704
|
+
...a.context || {}
|
|
705
|
+
},
|
|
706
|
+
df: a.dataFactory || d,
|
|
707
|
+
graph: a.graph ? d.namedNode(a.graph) : d.defaultGraph(),
|
|
708
|
+
quads: [],
|
|
709
|
+
quadBuffer: /* @__PURE__ */ new Map(),
|
|
710
|
+
removeSet: /* @__PURE__ */ new Set(),
|
|
711
|
+
origin: {
|
|
712
|
+
quadIndex: /* @__PURE__ */ new Map(),
|
|
713
|
+
blocks: /* @__PURE__ */ new Map(),
|
|
714
|
+
documentStructure: []
|
|
715
|
+
},
|
|
716
|
+
currentSubject: null,
|
|
717
|
+
primarySubject: null,
|
|
718
|
+
tokens: null,
|
|
719
|
+
currentTokenIndex: -1,
|
|
720
|
+
statements: [],
|
|
721
|
+
statementCandidates: /* @__PURE__ */ new Map(),
|
|
722
|
+
currentBlock: null,
|
|
723
|
+
blockStack: []
|
|
724
|
+
}, s = Se(i);
|
|
725
|
+
o.tokens = s.tokens;
|
|
726
|
+
for (let e = 0; e < o.tokens.length; e++) {
|
|
727
|
+
let t = o.tokens[e];
|
|
728
|
+
if (o.currentTokenIndex = e, t.type === "prefix") {
|
|
729
|
+
let e = t.iri;
|
|
730
|
+
if (t.iri.includes(":")) {
|
|
731
|
+
let n = t.iri.indexOf(":"), r = t.iri.substring(0, n), i = t.iri.substring(n + 1);
|
|
732
|
+
o.ctx[r] && r !== "@vocab" && (e = o.ctx[r] + i);
|
|
733
|
+
}
|
|
734
|
+
o.ctx[t.prefix] = e;
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
Me[t.type]?.(t, o);
|
|
738
|
+
}
|
|
739
|
+
let c = /* @__PURE__ */ new Set();
|
|
740
|
+
for (let e of o.quads) c.add(v(e.subject, e.predicate, e.object));
|
|
741
|
+
let l = [];
|
|
742
|
+
for (let e of o.removeSet) {
|
|
743
|
+
let t = v(e.subject, e.predicate, e.object);
|
|
744
|
+
c.has(t) || l.push(e);
|
|
745
|
+
}
|
|
746
|
+
return {
|
|
747
|
+
quads: o.quads,
|
|
748
|
+
remove: l,
|
|
749
|
+
statements: o.statements,
|
|
750
|
+
origin: o.origin,
|
|
751
|
+
context: o.ctx,
|
|
752
|
+
primarySubject: o.primarySubject,
|
|
753
|
+
md: s.md
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function H(e) {
|
|
757
|
+
return e.type === "code" ? [] : e._carriers || (e._carriers = Ce(e.text, e.range[0]));
|
|
758
|
+
}
|
|
759
|
+
function Se(e) {
|
|
760
|
+
let t = [], n = [], r = e.split("\n"), i = 0, a = null, o = [
|
|
761
|
+
{
|
|
762
|
+
type: "fence",
|
|
763
|
+
test: (e) => b(e.trim()),
|
|
764
|
+
process: s
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
type: "content",
|
|
768
|
+
test: () => a,
|
|
769
|
+
process: (e) => a.content.push(e)
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
type: "prefix",
|
|
773
|
+
test: (e) => x(e),
|
|
774
|
+
process: c
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
type: "standalone",
|
|
778
|
+
test: (e) => T(e),
|
|
779
|
+
process: p
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
type: "heading",
|
|
783
|
+
test: (e) => S(e),
|
|
784
|
+
process: l
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
type: "list",
|
|
788
|
+
test: (e) => C(e),
|
|
789
|
+
process: u
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
type: "blockquote",
|
|
793
|
+
test: (e) => w(e),
|
|
794
|
+
process: d
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
type: "para",
|
|
798
|
+
test: (e) => e.trim(),
|
|
799
|
+
process: f
|
|
800
|
+
}
|
|
801
|
+
];
|
|
802
|
+
function s(e, r, i) {
|
|
803
|
+
let o = e.trim();
|
|
804
|
+
if (a) {
|
|
805
|
+
let i = a.fence[0], s = i.repeat(a.fence.length), c = o.match(ce(i));
|
|
806
|
+
if (c && c[1] === s) {
|
|
807
|
+
let i = a.valueRangeStart, o = Math.max(i, r - 1);
|
|
808
|
+
t.push({
|
|
809
|
+
type: "code",
|
|
810
|
+
range: [a.start, r],
|
|
811
|
+
text: a.content.join("\n"),
|
|
812
|
+
lang: a.lang,
|
|
813
|
+
attrs: a.attrs,
|
|
814
|
+
attrsRange: a.attrsRange,
|
|
815
|
+
valueRange: [i, o]
|
|
816
|
+
});
|
|
817
|
+
for (let e of a.content) n.push(e);
|
|
818
|
+
a = null;
|
|
819
|
+
let s = e.replace(/\r?\n.*$/, "");
|
|
820
|
+
n.push(s);
|
|
821
|
+
}
|
|
822
|
+
} else {
|
|
823
|
+
let t = b(o);
|
|
824
|
+
if (!t) return !1;
|
|
825
|
+
let i = t.attrs, s = i ? e.indexOf(i) : -1, c = r + e.length + 1;
|
|
826
|
+
a = {
|
|
827
|
+
fence: t.fenceChar.repeat(t.fenceLength),
|
|
828
|
+
start: r,
|
|
829
|
+
content: [],
|
|
830
|
+
lang: t.lang,
|
|
831
|
+
attrs: i,
|
|
832
|
+
attrsRange: i && s >= 0 ? [r + s, r + s + i.length] : null,
|
|
833
|
+
valueRangeStart: c
|
|
834
|
+
};
|
|
835
|
+
let l = e.replace(/\s*\{[^}]+\}\s*$/, "");
|
|
836
|
+
n.push(l);
|
|
837
|
+
}
|
|
838
|
+
return !0;
|
|
839
|
+
}
|
|
840
|
+
function c(e, n, r) {
|
|
841
|
+
let i = x(e);
|
|
842
|
+
return t.push({
|
|
843
|
+
type: "prefix",
|
|
844
|
+
prefix: i.prefix,
|
|
845
|
+
iri: i.iri
|
|
846
|
+
}), !0;
|
|
847
|
+
}
|
|
848
|
+
function l(e, r, i) {
|
|
849
|
+
let a = S(e), o = a.attrs, s = a.depth, c = O(e, o, r, s, a.content.length);
|
|
850
|
+
t.push(A("heading", [r, i - 1], a.content, o, c.attrsRange, c.valueRange, { depth: a.depth }));
|
|
851
|
+
let l = `${"#".repeat(a.depth)} ${a.content}`;
|
|
852
|
+
return n.push(l), !0;
|
|
853
|
+
}
|
|
854
|
+
function u(e, r, i) {
|
|
855
|
+
let a = C(e), o = " ".repeat(a.indent), s = [
|
|
856
|
+
e,
|
|
857
|
+
o,
|
|
858
|
+
a.marker,
|
|
859
|
+
a.content,
|
|
860
|
+
a.attrs
|
|
861
|
+
];
|
|
862
|
+
t.push(le("list", e, r, i, s));
|
|
863
|
+
let c = `${o}${a.marker} ${a.content}`;
|
|
864
|
+
return n.push(c), !0;
|
|
865
|
+
}
|
|
866
|
+
function d(e, r, i) {
|
|
867
|
+
let a = w(e), o = a.attrs, s = e.startsWith("> ") ? 2 : e.indexOf(">") + 1, c = s + a.content.length;
|
|
868
|
+
t.push(A("blockquote", [r, i - 1], a.content, o, k(e, o, r), [r + s, r + c]));
|
|
869
|
+
let l = `> ${a.content}`;
|
|
870
|
+
return n.push(l), !0;
|
|
871
|
+
}
|
|
872
|
+
function f(e, r, i) {
|
|
873
|
+
t.push(A("para", [r, i - 1], e.trim()));
|
|
874
|
+
let a = e, o = se(a, 0);
|
|
875
|
+
for (let e of o) if (e.attrs && (e.type === "emphasis" || e.type === "code")) {
|
|
876
|
+
let t = a.substring(0, e.range[0]), n = a.substring(e.range[1]);
|
|
877
|
+
a = t + (e.text || "") + n;
|
|
878
|
+
}
|
|
879
|
+
return a = a.replace(/\[([^\]]+)\]\s*\{[^}]+\}/g, "$1"), a = a.replace(/\s*\{[^}]+\}\s*/g, " "), a = a.replace(/\s+/g, " ").trim(), n.push(a), !0;
|
|
880
|
+
}
|
|
881
|
+
function p(e, n, r) {
|
|
882
|
+
return t.push({
|
|
883
|
+
type: "standalone",
|
|
884
|
+
text: e.trim(),
|
|
885
|
+
range: [n, r - 1]
|
|
886
|
+
}), !0;
|
|
887
|
+
}
|
|
888
|
+
for (let e = 0; e < r.length; e++) {
|
|
889
|
+
let t = r[e], n = i;
|
|
890
|
+
i += t.length + 1;
|
|
891
|
+
for (let e of o) if (e.test(t) && e.process(t, n, i)) break;
|
|
892
|
+
}
|
|
893
|
+
return {
|
|
894
|
+
tokens: t,
|
|
895
|
+
md: n.join("\n")
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
function Ce(e, t = 0) {
|
|
899
|
+
return se(e, t);
|
|
900
|
+
}
|
|
901
|
+
function U(e, t) {
|
|
902
|
+
let n = e._blockId || p(`${e.type}:${e.range?.[0]}:${e.range?.[1]}`);
|
|
903
|
+
e._blockId = n;
|
|
904
|
+
let r = H(e), i = pe(e), a = {
|
|
905
|
+
id: n,
|
|
906
|
+
type: e.type,
|
|
907
|
+
range: e.range,
|
|
908
|
+
text: i,
|
|
909
|
+
subject: null,
|
|
910
|
+
types: [],
|
|
911
|
+
predicates: [],
|
|
912
|
+
carriers: [],
|
|
913
|
+
listLevel: e.indent || 0,
|
|
914
|
+
parentBlockId: t.blockStack.length > 0 ? t.blockStack[t.blockStack.length - 1] : null,
|
|
915
|
+
quadKeys: []
|
|
916
|
+
};
|
|
917
|
+
for (let e of r) {
|
|
918
|
+
let t = {
|
|
919
|
+
type: e.type,
|
|
920
|
+
range: e.range,
|
|
921
|
+
text: e.text,
|
|
922
|
+
subject: null,
|
|
923
|
+
predicates: [],
|
|
924
|
+
sem: null
|
|
925
|
+
};
|
|
926
|
+
if (e.attrs) {
|
|
927
|
+
let n = M(e.attrs);
|
|
928
|
+
t.sem = n, t.predicates = n.predicates || [], t.subject = n.subject, t.types = n.types || [];
|
|
929
|
+
}
|
|
930
|
+
a.carriers.push(t);
|
|
931
|
+
}
|
|
932
|
+
return t.origin.blocks.set(n, a), t.origin.documentStructure.push(a), a;
|
|
933
|
+
}
|
|
934
|
+
function we(e, t, n, r) {
|
|
935
|
+
if (t.subject && t.subject !== "RESET") {
|
|
936
|
+
let n = P(t, r);
|
|
937
|
+
n && (e.subject = n.value);
|
|
938
|
+
}
|
|
939
|
+
if (t.types && t.types.length > 0 && t.types.forEach((t) => {
|
|
940
|
+
let n = h(typeof t == "string" ? t : t.iri, r.ctx);
|
|
941
|
+
e.types.includes(n) || e.types.push(n);
|
|
942
|
+
}), t.predicates && t.predicates.length > 0 && t.predicates.forEach((t) => {
|
|
943
|
+
let n = {
|
|
944
|
+
iri: h(t.iri, r.ctx),
|
|
945
|
+
form: t.form || "",
|
|
946
|
+
object: null
|
|
947
|
+
};
|
|
948
|
+
e.predicates.push(n);
|
|
949
|
+
}), n) {
|
|
950
|
+
let t = {
|
|
951
|
+
type: n.type,
|
|
952
|
+
range: n.range,
|
|
953
|
+
text: n.text,
|
|
954
|
+
subject: null,
|
|
955
|
+
predicates: []
|
|
956
|
+
};
|
|
957
|
+
if (n.attrs) {
|
|
958
|
+
let e = M(n.attrs);
|
|
959
|
+
t.sem = e, t.predicates = e.predicates || [], t.subject = e.subject, t.types = e.types || [];
|
|
960
|
+
}
|
|
961
|
+
e.carriers.push(t);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function Te(e, t, n, r = {}) {
|
|
965
|
+
let { preserveGlobalSubject: i = !1, implicitSubject: a = null } = r;
|
|
966
|
+
if (t.subject === "RESET") {
|
|
967
|
+
n.currentSubject = null;
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
let o = n.currentSubject, s = P(t, n), c = he(t, n);
|
|
971
|
+
s && !n.primarySubject && !t.subject.startsWith("=#") && (n.primarySubject = s.value), s && !i && !a && (n.currentSubject = s);
|
|
972
|
+
let l = i ? s || o : a || n.currentSubject;
|
|
973
|
+
if (!l) return;
|
|
974
|
+
let u = Ee(l.value, t.types, t.predicates, e.range, e.attrsRange || null, e.valueRange || null, e.type || null, n.ctx, e.text), d = te(e.text, t.datatype, t.language, n.ctx, n.df), f = e.url ? n.df.namedNode(h(e.url, n.ctx)) : null, p = s || f;
|
|
975
|
+
n.currentBlock && we(n.currentBlock, t, e, n), ke(t, s, c, f, l, u, n, e), je(t, s, o, c, p, l, d, u, n, e);
|
|
976
|
+
}
|
|
977
|
+
function Ee(e, t, n, r, i, a, o, s, c) {
|
|
978
|
+
let l = {
|
|
979
|
+
subject: e,
|
|
980
|
+
types: t.map((e) => h(typeof e == "string" ? e : e.iri, s)),
|
|
981
|
+
predicates: n.map((e) => ({
|
|
982
|
+
iri: h(e.iri, s),
|
|
983
|
+
form: e.form
|
|
984
|
+
}))
|
|
985
|
+
};
|
|
986
|
+
return {
|
|
987
|
+
id: p([
|
|
988
|
+
e,
|
|
989
|
+
o || "unknown",
|
|
990
|
+
l.types.join(","),
|
|
991
|
+
l.predicates.map((e) => `${e.form}${e.iri}`).join(",")
|
|
992
|
+
].join("|")),
|
|
993
|
+
range: {
|
|
994
|
+
start: r[0],
|
|
995
|
+
end: r[1]
|
|
996
|
+
},
|
|
997
|
+
carrierType: o || null,
|
|
998
|
+
subject: e,
|
|
999
|
+
types: l.types,
|
|
1000
|
+
predicates: l.predicates,
|
|
1001
|
+
context: s,
|
|
1002
|
+
text: c || ""
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
function W(e, t, n, r, i, a, o, s, c, l = null, u = null, d = null, f = null) {
|
|
1006
|
+
if (!a || !o || !s) return;
|
|
1007
|
+
let p = c.quad(a, o, s);
|
|
1008
|
+
if (l?.remove) {
|
|
1009
|
+
let i = v(p.subject, p.predicate, p.object);
|
|
1010
|
+
if (t.has(i)) {
|
|
1011
|
+
t.delete(i);
|
|
1012
|
+
let n = e.findIndex((e) => e.subject.value === p.subject.value && e.predicate.value === p.predicate.value && e.object.value === p.object.value);
|
|
1013
|
+
n !== -1 && e.splice(n, 1), r.delete(i);
|
|
1014
|
+
} else n.add(p);
|
|
1015
|
+
} else {
|
|
1016
|
+
let n = v(p.subject, p.predicate, p.object);
|
|
1017
|
+
t.set(n, p), e.push(p), De(p, c, l, u, d);
|
|
1018
|
+
let s = me(i, a, o, l);
|
|
1019
|
+
r.set(n, s), f.currentBlock && i.id === f.currentBlock.id && (f.currentBlock.quadKeys || (f.currentBlock.quadKeys = []), f.currentBlock.quadKeys.push(n));
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
function De(e, t, n, r = null, i = null) {
|
|
1023
|
+
if (!r || !i) return;
|
|
1024
|
+
let a = e.predicate.value;
|
|
1025
|
+
if (a !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && a !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject" && a !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate" && a !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#object") return;
|
|
1026
|
+
if (a === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && e.object.value === "http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement") {
|
|
1027
|
+
i.set(e.subject.value, { spo: {} });
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
let o = i.get(e.subject.value);
|
|
1031
|
+
if (o && (a === "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject" ? o.spo.subject = e.object : a === "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate" ? o.spo.predicate = e.object : a === "http://www.w3.org/1999/02/22-rdf-syntax-ns#object" && (o.spo.object = e.object, o.objectQuad = e), o.spo.subject && o.spo.predicate && o.spo.object)) {
|
|
1032
|
+
let n = t.quad(o.spo.subject, o.spo.predicate, o.spo.object);
|
|
1033
|
+
r.push(n), i.delete(e.subject.value);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
var Oe = (e, t, n, r, i = null) => {
|
|
1037
|
+
let a = h(e, n.ctx), o = typeof i == "object" ? i : {
|
|
1038
|
+
entryIndex: i,
|
|
1039
|
+
remove: !1
|
|
1040
|
+
};
|
|
1041
|
+
W(n.quads, n.quadBuffer, n.removeSet, n.origin.quadIndex, r, t, n.df.namedNode(h("rdf:type", n.ctx)), n.df.namedNode(a), n.df, {
|
|
1042
|
+
kind: "type",
|
|
1043
|
+
token: `.${e}`,
|
|
1044
|
+
expandedType: a,
|
|
1045
|
+
entryIndex: o.entryIndex,
|
|
1046
|
+
remove: o.remove
|
|
1047
|
+
}, n.statements, n.statementCandidates, n);
|
|
1048
|
+
};
|
|
1049
|
+
function ke(e, t, n, r, i, a, o, s) {
|
|
1050
|
+
e.types.forEach((e) => {
|
|
1051
|
+
Oe(typeof e == "string" ? e : e.iri, t || n || r || i, o, a, typeof e == "string" ? {
|
|
1052
|
+
entryIndex: null,
|
|
1053
|
+
remove: !1
|
|
1054
|
+
} : e);
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
var Ae = (e, t, n, r, i, a, o, s) => {
|
|
1058
|
+
if (e.form === "" && t?.type === "link" && t?.url && t.text === t.url) return null;
|
|
1059
|
+
switch (e.form) {
|
|
1060
|
+
case "": return n ? {
|
|
1061
|
+
subject: i || o,
|
|
1062
|
+
object: s
|
|
1063
|
+
} : t?.type === "link" && t?.url && t.text !== t.url ? {
|
|
1064
|
+
subject: a,
|
|
1065
|
+
object: s
|
|
1066
|
+
} : {
|
|
1067
|
+
subject: i || o,
|
|
1068
|
+
object: s
|
|
1069
|
+
};
|
|
1070
|
+
case "?": return {
|
|
1071
|
+
subject: n ? r : o,
|
|
1072
|
+
object: i || a
|
|
1073
|
+
};
|
|
1074
|
+
case "!": return {
|
|
1075
|
+
subject: i || a,
|
|
1076
|
+
object: n ? r : o
|
|
1077
|
+
};
|
|
1078
|
+
default: return null;
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
function je(e, t, n, r, i, a, o, s, c, l) {
|
|
1082
|
+
e.predicates.forEach((e) => {
|
|
1083
|
+
let u = Ae(e, l, t, n, r, i, a, o);
|
|
1084
|
+
if (u) {
|
|
1085
|
+
let t = c.df.namedNode(h(e.iri, c.ctx));
|
|
1086
|
+
W(c.quads, c.quadBuffer, c.removeSet, c.origin.quadIndex, s, u.subject, t, u.object, c.df, {
|
|
1087
|
+
kind: "pred",
|
|
1088
|
+
token: `${e.form}${e.iri}`,
|
|
1089
|
+
form: e.form,
|
|
1090
|
+
expandedPredicate: t.value,
|
|
1091
|
+
entryIndex: e.entryIndex,
|
|
1092
|
+
remove: e.remove || !1
|
|
1093
|
+
}, c.statements, c.statementCandidates, c);
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
function G(e, t, n, r = {}) {
|
|
1098
|
+
Te(e, t, n, r);
|
|
1099
|
+
}
|
|
1100
|
+
function K(e, t, n) {
|
|
1101
|
+
if (e.attrs) {
|
|
1102
|
+
let r = M(e.attrs);
|
|
1103
|
+
G({
|
|
1104
|
+
type: n,
|
|
1105
|
+
text: e.text,
|
|
1106
|
+
range: e.range,
|
|
1107
|
+
attrsRange: e.attrsRange || null,
|
|
1108
|
+
valueRange: e.valueRange || null
|
|
1109
|
+
}, r, t);
|
|
1110
|
+
}
|
|
1111
|
+
H(e).forEach((e) => {
|
|
1112
|
+
e.attrs && G(e, M(e.attrs), t);
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
function q(e, t) {
|
|
1116
|
+
let n = T(e.text);
|
|
1117
|
+
if (!n) return;
|
|
1118
|
+
let r = M(`{=${n.content}}`), i = e.range[0] + e.text.indexOf("{=");
|
|
1119
|
+
G({
|
|
1120
|
+
type: "standalone",
|
|
1121
|
+
text: "",
|
|
1122
|
+
range: e.range,
|
|
1123
|
+
attrsRange: [i, i + (n.content ? n.content.length : 0)],
|
|
1124
|
+
valueRange: null
|
|
1125
|
+
}, r, t);
|
|
1126
|
+
}
|
|
1127
|
+
var Me = {
|
|
1128
|
+
heading: (e, t) => z(e, t, K, U),
|
|
1129
|
+
code: (e, t) => z(e, t, K, U),
|
|
1130
|
+
blockquote: (e, t) => z(e, t, K, U),
|
|
1131
|
+
para: (e, t) => z(e, t, K, U, [q]),
|
|
1132
|
+
list: (e, t) => z(e, t, K, U),
|
|
1133
|
+
standalone: (e, t) => q(e, t)
|
|
1134
|
+
};
|
|
1135
|
+
//#endregion
|
|
1136
|
+
//#region src/merge.js
|
|
1137
|
+
function J(e) {
|
|
1138
|
+
return y(e);
|
|
1139
|
+
}
|
|
1140
|
+
function Ne(e, t, n) {
|
|
1141
|
+
return typeof e == "string" ? V({
|
|
1142
|
+
text: e,
|
|
1143
|
+
...t,
|
|
1144
|
+
context: {
|
|
1145
|
+
...n,
|
|
1146
|
+
...t.context
|
|
1147
|
+
}
|
|
1148
|
+
}) : e;
|
|
1149
|
+
}
|
|
1150
|
+
function Pe(t, n = {}) {
|
|
1151
|
+
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = [], o = /* @__PURE__ */ new Map(), s = [], c = /* @__PURE__ */ new Map(), l = [];
|
|
1152
|
+
for (let u = 0; u < t.length; u++) {
|
|
1153
|
+
let d = t[u], f = Ne(d, n, {
|
|
1154
|
+
...e,
|
|
1155
|
+
...n.context
|
|
1156
|
+
});
|
|
1157
|
+
if (f.context) for (let [t, n] of Object.entries(f.context)) !c.has(t) && !e[t] && c.set(t, n);
|
|
1158
|
+
let p = {
|
|
1159
|
+
index: u,
|
|
1160
|
+
input: typeof d == "string" ? "string" : "ParseResult",
|
|
1161
|
+
origin: f.origin,
|
|
1162
|
+
context: f.context,
|
|
1163
|
+
statementsCount: f.statements?.length || 0
|
|
1164
|
+
};
|
|
1165
|
+
a.push(p), f.statements && f.statements.length > 0 && s.push(...f.statements), f.primarySubject && l.push(f.primarySubject);
|
|
1166
|
+
for (let e of f.quads) {
|
|
1167
|
+
let t = J(e);
|
|
1168
|
+
r.set(t, e);
|
|
1169
|
+
let n = f.origin.quadIndex.get(t);
|
|
1170
|
+
o.set(t, {
|
|
1171
|
+
...n || {},
|
|
1172
|
+
documentIndex: u,
|
|
1173
|
+
polarity: "+"
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
for (let e of f.remove) {
|
|
1177
|
+
let t = J(e);
|
|
1178
|
+
r.has(t) ? r.delete(t) : i.add(e);
|
|
1179
|
+
let n = f.origin.quadIndex.get(t);
|
|
1180
|
+
o.set(t, {
|
|
1181
|
+
...n || {},
|
|
1182
|
+
documentIndex: u,
|
|
1183
|
+
polarity: "-"
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
let u = Array.from(r.values()), d = Array.from(i), f = {
|
|
1188
|
+
documents: a,
|
|
1189
|
+
quadIndex: o
|
|
1190
|
+
}, p = {
|
|
1191
|
+
...e,
|
|
1192
|
+
...n.context,
|
|
1193
|
+
...Object.fromEntries(c)
|
|
1194
|
+
}, m = new Set(u.map(J)), h = new Set(d.map(J));
|
|
1195
|
+
return {
|
|
1196
|
+
quads: u.filter((e) => !h.has(J(e))),
|
|
1197
|
+
remove: d.filter((e) => !m.has(J(e))),
|
|
1198
|
+
statements: s,
|
|
1199
|
+
origin: f,
|
|
1200
|
+
context: p,
|
|
1201
|
+
primarySubjects: l
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
//#endregion
|
|
1205
|
+
//#region src/generate.js
|
|
1206
|
+
var Y = /* @__PURE__ */ new Map(), X = 1e3;
|
|
1207
|
+
function Fe(e, t) {
|
|
1208
|
+
let n = `${e}|${JSON.stringify(t)}`;
|
|
1209
|
+
if (Y.has(n)) return Y.get(n);
|
|
1210
|
+
let r = g(e, t);
|
|
1211
|
+
return Y.size >= X && Array.from(Y.keys()).slice(0, Math.floor(X / 2)).forEach((e) => Y.delete(e)), Y.set(n, r), r;
|
|
1212
|
+
}
|
|
1213
|
+
function Ie(e, t = {}) {
|
|
1214
|
+
if (!e) return e;
|
|
1215
|
+
for (let [n, r] of Object.entries(t)) if (e.startsWith(r) || e.startsWith(r.slice(0, -1))) return e.substring(r.length);
|
|
1216
|
+
for (let t of [
|
|
1217
|
+
"#",
|
|
1218
|
+
"/",
|
|
1219
|
+
":"
|
|
1220
|
+
]) {
|
|
1221
|
+
let n = e.lastIndexOf(t);
|
|
1222
|
+
if (n !== -1 && n < e.length - 1) return e.substring(n + 1);
|
|
1223
|
+
}
|
|
1224
|
+
return e;
|
|
1225
|
+
}
|
|
1226
|
+
function Le({ quads: t, context: n = {}, primarySubject: r = null }) {
|
|
1227
|
+
let i = Object.assign({}, e, n), a = ze(t), o = Be(a), s = r;
|
|
1228
|
+
!s && a.length > 0 && (s = a[0].subject.value);
|
|
1229
|
+
let { text: c } = He(o, i, s);
|
|
1230
|
+
return {
|
|
1231
|
+
text: c,
|
|
1232
|
+
context: i
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
function Re({ quads: t, focusIRI: n, context: r = {} }) {
|
|
1236
|
+
if (!t?.length || !n) return {
|
|
1237
|
+
text: "",
|
|
1238
|
+
context: Object.assign({}, e, r)
|
|
1239
|
+
};
|
|
1240
|
+
let i = Object.assign({}, e, r), a = Ve(ze(t));
|
|
1241
|
+
if (!a.has(n)) return {
|
|
1242
|
+
text: "",
|
|
1243
|
+
context: i
|
|
1244
|
+
};
|
|
1245
|
+
let { text: o } = He(a, i, n);
|
|
1246
|
+
return {
|
|
1247
|
+
text: o,
|
|
1248
|
+
context: i
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
function ze(e) {
|
|
1252
|
+
return !e || e.length === 0 ? [] : e.map((e) => e.subject.termType && e.predicate.termType && e.object.termType ? e : {
|
|
1253
|
+
subject: d.fromTerm(e.subject),
|
|
1254
|
+
predicate: d.fromTerm(e.predicate),
|
|
1255
|
+
object: d.fromTerm(e.object)
|
|
1256
|
+
}).sort((e, t) => {
|
|
1257
|
+
let n = e.subject.value.localeCompare(t.subject.value);
|
|
1258
|
+
if (n !== 0) return n;
|
|
1259
|
+
let r = e.predicate.value.localeCompare(t.predicate.value);
|
|
1260
|
+
if (r !== 0) return r;
|
|
1261
|
+
let i = (I(e.object), e.object.value), a = (I(t.object), t.object.value);
|
|
1262
|
+
return i.localeCompare(a);
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
function Be(e) {
|
|
1266
|
+
let t = /* @__PURE__ */ new Map();
|
|
1267
|
+
for (let n of e) {
|
|
1268
|
+
let e = n.subject.value, r = t.get(e);
|
|
1269
|
+
r ? r.push(n) : t.set(e, [n]);
|
|
1270
|
+
}
|
|
1271
|
+
return t;
|
|
1272
|
+
}
|
|
1273
|
+
function Ve(e) {
|
|
1274
|
+
let t = /* @__PURE__ */ new Map(), n = (e) => {
|
|
1275
|
+
let n = t.get(e);
|
|
1276
|
+
if (n) return n;
|
|
1277
|
+
let r = [];
|
|
1278
|
+
return t.set(e, r), r;
|
|
1279
|
+
};
|
|
1280
|
+
for (let t of e) {
|
|
1281
|
+
let { subject: e, predicate: r, object: i } = t;
|
|
1282
|
+
n(e.value).push(t), i.termType === "NamedNode" && n(i.value).push(t), n(r.value).push(t), r.value === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && i.termType === "NamedNode" && n(i.value).push(t), i.termType === "Literal" && i.datatype && n(i.datatype.value || i.datatype).push(t);
|
|
1283
|
+
}
|
|
1284
|
+
return t;
|
|
1285
|
+
}
|
|
1286
|
+
function He(t, n, r = null) {
|
|
1287
|
+
let i = [], a = _e(t, n), o = Ue(t), s = Object.entries(n).sort(([e], [t]) => e.localeCompare(t));
|
|
1288
|
+
for (let [t, n] of s) t !== "@vocab" && !t.startsWith("@") && !e[t] && a.has(t) && i.push(ve(t, n));
|
|
1289
|
+
s.length > 0 && i.push("\n");
|
|
1290
|
+
let c = Array.from(t.keys()).sort(), l = r, u = l ? [l, ...c.filter((e) => e !== l)] : c;
|
|
1291
|
+
for (let e of u) {
|
|
1292
|
+
let r = t.get(e);
|
|
1293
|
+
if (!r) continue;
|
|
1294
|
+
let a = Fe(e, n), { types: s, literals: c, objects: l } = xe(r), u = o.has(e), d = u ? o.get(e) : Ie(e, n), f = s.length > 0 ? s.map((e) => "." + Fe(e.object.value, n)).sort().join(" ") : "";
|
|
1295
|
+
u && (f += (f ? " " : "") + "label");
|
|
1296
|
+
let p = f ? " " + f : "";
|
|
1297
|
+
i.push(`# ${d} {=${a}${p}}\n\n`);
|
|
1298
|
+
let m = u ? o.get(e) : null;
|
|
1299
|
+
B(c).forEach((e) => {
|
|
1300
|
+
e.predicate.value === "http://www.w3.org/2000/01/rdf-schema#label" && e.object.value === m || i.push(ye(e, n));
|
|
1301
|
+
}), B(l).forEach((e) => {
|
|
1302
|
+
i.push(be(e, n, o));
|
|
1303
|
+
}), i.push("\n");
|
|
1304
|
+
}
|
|
1305
|
+
return { text: i.join("") };
|
|
1306
|
+
}
|
|
1307
|
+
function Ue(e) {
|
|
1308
|
+
let t = /* @__PURE__ */ new Map();
|
|
1309
|
+
for (let n of e.values()) for (let e of n) e.predicate.value === "http://www.w3.org/2000/01/rdf-schema#label" && e.object.termType === "Literal" && t.set(e.subject.value, e.object.value);
|
|
1310
|
+
return t;
|
|
1311
|
+
}
|
|
1312
|
+
//#endregion
|
|
1313
|
+
//#region src/render.js
|
|
1314
|
+
function We(e, t = {}) {
|
|
1315
|
+
let n = V({
|
|
1316
|
+
text: e,
|
|
1317
|
+
context: t.context || {}
|
|
1318
|
+
}), r = Ge(n, t, e), i = {
|
|
1319
|
+
html: dt(Ke(n.origin.blocks, r), r.ctx),
|
|
1320
|
+
context: r.ctx,
|
|
1321
|
+
metadata: {
|
|
1322
|
+
blockCount: n.origin.blocks.size,
|
|
1323
|
+
quadCount: n.quads.length,
|
|
1324
|
+
renderedRDFaCount: r.renderedRDFaCount,
|
|
1325
|
+
renderTime: Date.now()
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
return t.debug && (i.debug = {
|
|
1329
|
+
originBlocks: Array.from(n.origin.blocks.values()),
|
|
1330
|
+
quadIndex: Array.from(n.origin.quadIndex.entries()),
|
|
1331
|
+
renderMap: r.renderMap
|
|
1332
|
+
}), i;
|
|
1333
|
+
}
|
|
1334
|
+
function Ge(t, n, r) {
|
|
1335
|
+
return {
|
|
1336
|
+
ctx: t.context || {
|
|
1337
|
+
...e,
|
|
1338
|
+
...n.context || {}
|
|
1339
|
+
},
|
|
1340
|
+
df: n.dataFactory || d,
|
|
1341
|
+
baseIRI: n.baseIRI || "",
|
|
1342
|
+
sourceText: r,
|
|
1343
|
+
output: [],
|
|
1344
|
+
currentSubject: null,
|
|
1345
|
+
quadIndex: t.origin.quadIndex,
|
|
1346
|
+
blocks: t.origin.blocks,
|
|
1347
|
+
renderMap: /* @__PURE__ */ new Map(),
|
|
1348
|
+
renderedRDFaCount: 0,
|
|
1349
|
+
validation: n.validate || !1
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
function Ke(e, t) {
|
|
1353
|
+
let n = Array.from(e.values()).sort((e, t) => (e.range?.start || 0) - (t.range?.start || 0)), r = n.filter((e) => e.carrierType === "list");
|
|
1354
|
+
return n.filter((e) => e.carrierType !== "list").forEach((e) => {
|
|
1355
|
+
qe(e, t);
|
|
1356
|
+
}), r.length > 0 && at(r, t), t.output.join("");
|
|
1357
|
+
}
|
|
1358
|
+
function qe(e, t) {
|
|
1359
|
+
e.subject && e.subject !== "RESET" && (t.currentSubject = e.subject);
|
|
1360
|
+
let n = Je(e, t);
|
|
1361
|
+
switch (n && t.renderMap.set(e.id || ft(e), n), e.type || e.carrierType) {
|
|
1362
|
+
case "heading":
|
|
1363
|
+
Xe(e, n, t);
|
|
1364
|
+
break;
|
|
1365
|
+
case "para":
|
|
1366
|
+
Ze(e, n, t);
|
|
1367
|
+
break;
|
|
1368
|
+
case "list": break;
|
|
1369
|
+
case "quote":
|
|
1370
|
+
Qe(e, n, t);
|
|
1371
|
+
break;
|
|
1372
|
+
case "code":
|
|
1373
|
+
$e(e, n, t);
|
|
1374
|
+
break;
|
|
1375
|
+
default: et(e, n, t);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
function Je(e, t) {
|
|
1379
|
+
let n = [];
|
|
1380
|
+
if (!e.subject || e.subject === "RESET" || e.subject.startsWith("=#") || e.subject.startsWith("+")) return "";
|
|
1381
|
+
let r = h(e.subject, t.ctx);
|
|
1382
|
+
if (n.push(`about="${F(r)}"`), e.types && e.types.length > 0) {
|
|
1383
|
+
let r = e.types.map((e) => h(typeof e == "string" ? e : e.iri, t.ctx)).join(" ");
|
|
1384
|
+
n.push(`typeof="${F(r)}"`);
|
|
1385
|
+
}
|
|
1386
|
+
let i = [];
|
|
1387
|
+
if (e.predicates && e.predicates.length > 0 && i.push(...e.predicates), e.carriers && e.carriers.length > 0) for (let t of e.carriers) t.predicates && t.predicates.length > 0 && i.push(...t.predicates);
|
|
1388
|
+
if (i.length > 0) {
|
|
1389
|
+
let { literalProps: e, objectProps: r, reverseProps: a } = Ye(i, t.ctx);
|
|
1390
|
+
e.length > 0 && n.push(`property="${F(e.join(" "))}"`), r.length > 0 && n.push(`rel="${F(r.join(" "))}"`), a.length > 0 && n.push(`rev="${F(a.join(" "))}"`);
|
|
1391
|
+
}
|
|
1392
|
+
return n.length > 1 && t.renderedRDFaCount++, n.length > 0 ? ` ${n.join(" ")}` : "";
|
|
1393
|
+
}
|
|
1394
|
+
function Ye(e, t) {
|
|
1395
|
+
let n = [], r = [], i = [];
|
|
1396
|
+
for (let a of e) {
|
|
1397
|
+
let e = h(typeof a == "string" ? a : a.iri, t);
|
|
1398
|
+
a.polarity === "-" ? i.push(e) : a.object && a.object.termType === "NamedNode" ? r.push(e) : n.push(e);
|
|
1399
|
+
}
|
|
1400
|
+
return {
|
|
1401
|
+
literalProps: n,
|
|
1402
|
+
objectProps: r,
|
|
1403
|
+
reverseProps: i
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
function Xe(e, t, n) {
|
|
1407
|
+
let r = `h${e.text && e.text.match(/^#+/)?.[0]?.length || 1}`, i = fe(n.sourceText, e.range);
|
|
1408
|
+
i = i.replace(/\s*\{[^}]+\}\s*$/g, "").trim(), n.output.push(`<${r}${t}>${F(i)}</${r}>`);
|
|
1409
|
+
}
|
|
1410
|
+
function Ze(e, t, n) {
|
|
1411
|
+
let r = Z(e, n);
|
|
1412
|
+
n.output.push(`<p${t}>${r}</p>`);
|
|
1413
|
+
}
|
|
1414
|
+
function Qe(e, t, n) {
|
|
1415
|
+
let r = Z(e, n);
|
|
1416
|
+
n.output.push(`<blockquote${t}>${r}</blockquote>`);
|
|
1417
|
+
}
|
|
1418
|
+
function $e(e, t, n) {
|
|
1419
|
+
let r = e.info || "", i = e.text || "";
|
|
1420
|
+
n.output.push(`<pre><code${t}${r ? ` class="language-${F(r)}"` : ""}>${F(i)}</code></pre>`);
|
|
1421
|
+
}
|
|
1422
|
+
function et(e, t, n) {
|
|
1423
|
+
let r = Z(e, n);
|
|
1424
|
+
n.output.push(`<div${t}>${r}</div>`);
|
|
1425
|
+
}
|
|
1426
|
+
function Z(e, t) {
|
|
1427
|
+
if (!e.carriers || e.carriers.length === 0) return F(tt(t.sourceText, e.range));
|
|
1428
|
+
let n = nt(e);
|
|
1429
|
+
return rt(tt(t.sourceText, e.range), n, t);
|
|
1430
|
+
}
|
|
1431
|
+
function tt(e, t) {
|
|
1432
|
+
if (!t || !e) return "";
|
|
1433
|
+
let n = e.substring(t[0], t[1]);
|
|
1434
|
+
return n = n.replace(/\s*\{[^}]*\}\s*$/gm, ""), n = n.replace(/\{[^}]*\}/g, ""), n = n.replace(/\s+/g, " ").trim(), n = n.replace(/\]$/, ""), n;
|
|
1435
|
+
}
|
|
1436
|
+
function nt(e) {
|
|
1437
|
+
let t = [];
|
|
1438
|
+
if (!e.carriers) return t;
|
|
1439
|
+
for (let n of e.carriers) !n.text || !n.range || t.push({
|
|
1440
|
+
pos: n.range[0] - e.range[0],
|
|
1441
|
+
carrier: n,
|
|
1442
|
+
length: n.text.length
|
|
1443
|
+
});
|
|
1444
|
+
return t.sort((e, t) => e.pos - t.pos);
|
|
1445
|
+
}
|
|
1446
|
+
function rt(e, t, n) {
|
|
1447
|
+
if (t.length === 0) return F(e);
|
|
1448
|
+
let r = "", i = 0;
|
|
1449
|
+
for (let a of t) a.pos > i && (r += F(e.substring(i, a.pos))), r += it(a.carrier, n), i = a.pos + a.length;
|
|
1450
|
+
return i < e.length && (r += F(e.substring(i))), r;
|
|
1451
|
+
}
|
|
1452
|
+
function it(e, t) {
|
|
1453
|
+
let n = [], r = e.subject || t.currentSubject;
|
|
1454
|
+
if (!r || r === "RESET" || r.startsWith("=#") || r.startsWith("+")) return F(e.text || "");
|
|
1455
|
+
let i = g(h(r, t.ctx), t.ctx);
|
|
1456
|
+
if (n.push(`about="${F(i)}"`), e.types && e.types.length > 0) {
|
|
1457
|
+
let r = e.types.map((e) => g(h(typeof e == "string" ? e : e.iri, t.ctx), t.ctx)).join(" ");
|
|
1458
|
+
n.push(`typeof="${F(r)}"`);
|
|
1459
|
+
}
|
|
1460
|
+
if (e.predicates && e.predicates.length > 0) {
|
|
1461
|
+
let { literalProps: r, objectProps: i, reverseProps: a } = Ye(e.predicates, t.ctx);
|
|
1462
|
+
if (r.length > 0) {
|
|
1463
|
+
let e = r.map((e) => g(e, t.ctx)).join(" ");
|
|
1464
|
+
n.push(`property="${F(e)}"`);
|
|
1465
|
+
}
|
|
1466
|
+
if (i.length > 0) {
|
|
1467
|
+
let e = i.map((e) => g(e, t.ctx)).join(" ");
|
|
1468
|
+
n.push(`rel="${F(e)}"`);
|
|
1469
|
+
}
|
|
1470
|
+
if (a.length > 0) {
|
|
1471
|
+
let e = a.map((e) => g(e, t.ctx)).join(" ");
|
|
1472
|
+
n.push(`rev="${F(e)}"`);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
let a = n.length > 0 ? ` ${n.join(" ")}` : "";
|
|
1476
|
+
switch (e.type) {
|
|
1477
|
+
case "emphasis": return `<em${a}>${F(e.text || "")}</em>`;
|
|
1478
|
+
case "strong": return `<strong${a}>${F(e.text || "")}</strong>`;
|
|
1479
|
+
case "code": return `<code${a}>${F(e.text || "")}</code>`;
|
|
1480
|
+
case "link": return `<a href="${F(e.url || "")}"${a}>${F(e.text || "")}</a>`;
|
|
1481
|
+
default: return `<span${a}>${F(e.text || "")}</span>`;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
function at(e, t) {
|
|
1485
|
+
ot(e, t.sourceText).forEach((e) => {
|
|
1486
|
+
st(e, t);
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
function ot(e, t) {
|
|
1490
|
+
let n = [], r = null, i = e.sort((e, t) => (e.range?.start || 0) - (t.range?.start || 0));
|
|
1491
|
+
for (let e of i) de(e, t) === 0 ? (r && n.push(r), r = {
|
|
1492
|
+
contextName: "Items",
|
|
1493
|
+
blocks: [e]
|
|
1494
|
+
}) : r ? r.blocks.push(e) : r = {
|
|
1495
|
+
contextName: "Items",
|
|
1496
|
+
blocks: [e]
|
|
1497
|
+
};
|
|
1498
|
+
return r && n.push(r), n;
|
|
1499
|
+
}
|
|
1500
|
+
function st(e, t) {
|
|
1501
|
+
t.output.push("<ul>");
|
|
1502
|
+
for (let n of e.blocks) ct(n, t);
|
|
1503
|
+
t.output.push("</ul>");
|
|
1504
|
+
}
|
|
1505
|
+
function ct(e, t) {
|
|
1506
|
+
let n = Je(e, t), r = Z(e, t);
|
|
1507
|
+
t.output.push(`<li${n}>${r}</li>`);
|
|
1508
|
+
}
|
|
1509
|
+
function lt(e) {
|
|
1510
|
+
let t = [];
|
|
1511
|
+
for (let [n, r] of Object.entries(e)) n !== "@vocab" && t.push(`${n}: ${r}`);
|
|
1512
|
+
return t.length > 0 ? ` prefix="${t.join(" ")}"` : "";
|
|
1513
|
+
}
|
|
1514
|
+
function ut(e) {
|
|
1515
|
+
return e["@vocab"] ? ` vocab="${e["@vocab"]}"` : "";
|
|
1516
|
+
}
|
|
1517
|
+
function dt(e, t) {
|
|
1518
|
+
return `<div${lt(t)}${ut(t)}>${e}</div>`;
|
|
1519
|
+
}
|
|
1520
|
+
function ft(e) {
|
|
1521
|
+
return pt(`${e.type || e.carrierType}|${e.subject || ""}|${e.text || ""}`);
|
|
1522
|
+
}
|
|
1523
|
+
function pt(e) {
|
|
1524
|
+
let t = 0;
|
|
1525
|
+
for (let n = 0; n < e.length; n++) {
|
|
1526
|
+
let r = e.charCodeAt(n);
|
|
1527
|
+
t = (t << 5) - t + r, t &= t;
|
|
1528
|
+
}
|
|
1529
|
+
return t.toString(36);
|
|
1530
|
+
}
|
|
1531
|
+
//#endregion
|
|
1532
|
+
//#region src/highlight.js
|
|
1533
|
+
var Q = /* @__PURE__ */ new Map();
|
|
1534
|
+
function $(e) {
|
|
1535
|
+
let t = 0;
|
|
1536
|
+
for (let n = 0; n < e.length; n++) {
|
|
1537
|
+
let r = e.charCodeAt(n);
|
|
1538
|
+
t = (t << 5) - t + r, t &= t;
|
|
1539
|
+
}
|
|
1540
|
+
return Math.abs(t);
|
|
1541
|
+
}
|
|
1542
|
+
function mt(e) {
|
|
1543
|
+
if (Q.has(e)) return Q.get(e);
|
|
1544
|
+
let t = $(e), n = `hsl(${t % 360}, ${15 + t % 10}%, ${45 + t % 10}%)`;
|
|
1545
|
+
return Q.set(e, n), n;
|
|
1546
|
+
}
|
|
1547
|
+
//#endregion
|
|
1548
|
+
export { e as DEFAULT_CONTEXT, d as DataFactory, h as expandIRI, Le as generate, Re as generateNode, mt as getIRIColor, p as hash, $ as hashIRI, f as locate, Pe as merge, V as parse, _ as parseSemanticBlock, We as render, g as shortenIRI };
|