@drghaliasri/butex 7.4.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -553
- package/dist/{document2-cli.js → document-cli.js} +332 -302
- package/dist/document-cli.js.map +1 -0
- package/dist/document.d.mts +1022 -186
- package/dist/document.d.ts +1022 -186
- package/dist/document.js +6068 -658
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +5928 -618
- package/dist/document.mjs.map +1 -1
- package/dist/index.global.js +19 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -7
- package/dist/index.mjs.map +1 -1
- package/dist/react-document-preview.d.mts +338 -0
- package/dist/react-document-preview.d.ts +338 -0
- package/dist/{react-document2-preview.js → react-document-preview.js} +783 -783
- package/dist/react-document-preview.js.map +1 -0
- package/dist/{react-document2-preview.mjs → react-document-preview.mjs} +776 -776
- package/dist/react-document-preview.mjs.map +1 -0
- package/dist/react-document.d.mts +634 -35
- package/dist/react-document.d.ts +634 -35
- package/dist/react-document.js +13259 -4282
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +12617 -3648
- package/dist/react-document.mjs.map +1 -1
- package/dist/react.js +4 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +4 -4
- package/dist/react.mjs.map +1 -1
- package/package.json +7 -17
- package/dist/document2-cli.js.map +0 -1
- package/dist/document2.d.mts +0 -1156
- package/dist/document2.d.ts +0 -1156
- package/dist/document2.js +0 -9137
- package/dist/document2.js.map +0 -1
- package/dist/document2.mjs +0 -8972
- package/dist/document2.mjs.map +0 -1
- package/dist/react-document2-preview.d.mts +0 -338
- package/dist/react-document2-preview.d.ts +0 -338
- package/dist/react-document2-preview.js.map +0 -1
- package/dist/react-document2-preview.mjs.map +0 -1
- package/dist/react-document2.d.mts +0 -754
- package/dist/react-document2.d.ts +0 -754
- package/dist/react-document2.js +0 -23011
- package/dist/react-document2.js.map +0 -1
- package/dist/react-document2.mjs +0 -22981
- package/dist/react-document2.mjs.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/document-cli/main.ts
|
|
5
5
|
var import_node_events = require("events");
|
|
6
6
|
|
|
7
|
-
// src/
|
|
7
|
+
// src/document-cli/httpServer.ts
|
|
8
8
|
var import_node_crypto = require("crypto");
|
|
9
9
|
var import_node_http = require("http");
|
|
10
10
|
|
|
11
|
-
// src/
|
|
11
|
+
// src/document/ids.ts
|
|
12
12
|
var nextId = 1;
|
|
13
13
|
var instanceId = `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
14
|
-
function
|
|
14
|
+
function documentId(prefix) {
|
|
15
15
|
const id = `${prefix}_${instanceId}_${String(nextId)}`;
|
|
16
16
|
nextId += 1;
|
|
17
17
|
return id;
|
|
@@ -45,7 +45,7 @@ function formatDigits(value, digitForm = "western") {
|
|
|
45
45
|
}).join("");
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// src/
|
|
48
|
+
// src/document/articleMeta.ts
|
|
49
49
|
var BUTEX_BASMALA_LINE1 = "\u0628\u0650\u0633\u0652\u0645\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0652\u0645\u064E\u0670\u0646\u0650 \u0671\u0644\u0631\u064E\u0651\u062D\u0650\u064A\u0645\u0650";
|
|
50
50
|
var BUTEX_BASMALA_LINE2 = "\u0648\u064E\u0671\u0644\u0635\u064E\u0651\u0644\u064E\u0627\u0629\u064F \u0648\u064E\u0671\u0644\u0633\u064E\u0651\u0644\u064E\u0627\u0645\u064F \u0639\u064E\u0644\u064E\u0649\u0670 \u0631\u064E\u0633\u064F\u0648\u0644\u0650 \u0671\u0644\u0644\u064E\u0651\u0670\u0647\u0650";
|
|
51
51
|
var BUTEX_BASMALA_SALAWAT = "\u0635\u064E\u0644\u064E\u0651\u0649 \u0671\u0644\u0644\u064E\u0651\u0647\u064F \u0639\u064E\u0644\u064E\u064A\u0652\u0647\u0650 \u0648\u064E\u0633\u064E\u0644\u064E\u0651\u0645\u064E";
|
|
@@ -168,7 +168,7 @@ var DEFAULT_HIJRI_DATE = {
|
|
|
168
168
|
function hijriMonthLabel(month, locale = "ar") {
|
|
169
169
|
return locale === "en" ? HIJRI_MONTH_LABELS_EN[month] : month;
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function emptyDocumentMeta() {
|
|
172
172
|
return {
|
|
173
173
|
title: "",
|
|
174
174
|
authors: "",
|
|
@@ -194,7 +194,7 @@ function resolveHijriMonthId(value) {
|
|
|
194
194
|
}
|
|
195
195
|
return DEFAULT_HIJRI_DATE.month;
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function normalizeDocumentHijriDate(value) {
|
|
198
198
|
if (typeof value !== "object" || value === null) {
|
|
199
199
|
return { ...DEFAULT_HIJRI_DATE };
|
|
200
200
|
}
|
|
@@ -204,22 +204,22 @@ function normalizeDocument2HijriDate(value) {
|
|
|
204
204
|
const month = resolveHijriMonthId(raw.month);
|
|
205
205
|
return { day, month, year };
|
|
206
206
|
}
|
|
207
|
-
function
|
|
207
|
+
function normalizeDocumentMeta(value) {
|
|
208
208
|
if (typeof value !== "object" || value === null) {
|
|
209
|
-
return
|
|
209
|
+
return emptyDocumentMeta();
|
|
210
210
|
}
|
|
211
211
|
const raw = value;
|
|
212
212
|
return {
|
|
213
213
|
title: typeof raw.title === "string" ? raw.title : "",
|
|
214
214
|
authors: typeof raw.authors === "string" ? raw.authors : "",
|
|
215
|
-
date:
|
|
215
|
+
date: normalizeDocumentHijriDate(raw.date),
|
|
216
216
|
abstract: typeof raw.abstract === "string" ? raw.abstract : ""
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function documentHasMaketitle(meta) {
|
|
220
220
|
return meta.title.trim().length > 0 || meta.authors.trim().length > 0;
|
|
221
221
|
}
|
|
222
|
-
function
|
|
222
|
+
function documentHasAbstract(meta) {
|
|
223
223
|
return meta.abstract.trim().length > 0;
|
|
224
224
|
}
|
|
225
225
|
function formatHijriDate(date, options = "ar") {
|
|
@@ -235,7 +235,7 @@ function formatHijriDate(date, options = "ar") {
|
|
|
235
235
|
return `${day} ${month} ${year}\u0647\u0640`;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
// src/
|
|
238
|
+
// src/document/citations.ts
|
|
239
239
|
var DEFAULT_REFERENCE_FIELD_SEPARATOR = "\u060C";
|
|
240
240
|
function normalizeReferenceFieldSeparator(value) {
|
|
241
241
|
return value === "," ? "," : DEFAULT_REFERENCE_FIELD_SEPARATOR;
|
|
@@ -252,7 +252,7 @@ function citeTokenLatex(keys) {
|
|
|
252
252
|
}
|
|
253
253
|
function referenceFromJson(json) {
|
|
254
254
|
return {
|
|
255
|
-
id:
|
|
255
|
+
id: documentId("ref"),
|
|
256
256
|
key: json.key,
|
|
257
257
|
authors: typeof json.authors === "string" ? json.authors : "",
|
|
258
258
|
title: typeof json.title === "string" ? json.title : "",
|
|
@@ -589,7 +589,7 @@ function fromArabicJson(json) {
|
|
|
589
589
|
return parseNode(json, "arabic");
|
|
590
590
|
}
|
|
591
591
|
|
|
592
|
-
// src/document/mathObject.ts
|
|
592
|
+
// src/shared/math-document/mathObject.ts
|
|
593
593
|
function isObject(value) {
|
|
594
594
|
return typeof value === "object" && value !== null;
|
|
595
595
|
}
|
|
@@ -706,15 +706,15 @@ ${lines.map((line) => ` ${line}`).join(" \\\\\n")}
|
|
|
706
706
|
${math.closing}`;
|
|
707
707
|
}
|
|
708
708
|
|
|
709
|
-
// src/
|
|
709
|
+
// src/document/labels.ts
|
|
710
710
|
function defaultFloatMeta() {
|
|
711
711
|
return {
|
|
712
712
|
centered: true,
|
|
713
713
|
captionEnabled: false,
|
|
714
714
|
caption: "",
|
|
715
715
|
captionField: {
|
|
716
|
-
id:
|
|
717
|
-
tokens: [{ id:
|
|
716
|
+
id: documentId("field"),
|
|
717
|
+
tokens: [{ id: documentId("text"), kind: "text", text: "" }]
|
|
718
718
|
},
|
|
719
719
|
labelEnabled: false,
|
|
720
720
|
label: ""
|
|
@@ -752,7 +752,7 @@ function refTokenLatex(keys, refCommand) {
|
|
|
752
752
|
const command = refCommand === "eqref" ? "\\eqref" : "\\ref";
|
|
753
753
|
return `${command}{${keys.join(",")}}`;
|
|
754
754
|
}
|
|
755
|
-
function
|
|
755
|
+
function collectDocumentLabels(document2) {
|
|
756
756
|
const entries = [];
|
|
757
757
|
const counters = { fig: 0, tab: 0, eq: 0 };
|
|
758
758
|
function pushEqFromField(tokens) {
|
|
@@ -848,7 +848,7 @@ function applyFloatMetaPatch(block, patch) {
|
|
|
848
848
|
const existingText = block.captionField.tokens.find((token) => token.kind === "text");
|
|
849
849
|
block.captionField.tokens = [
|
|
850
850
|
{
|
|
851
|
-
id: existingText?.id ??
|
|
851
|
+
id: existingText?.id ?? documentId("text"),
|
|
852
852
|
kind: "text",
|
|
853
853
|
text: patch.caption
|
|
854
854
|
}
|
|
@@ -862,8 +862,8 @@ function applyFloatMetaPatch(block, patch) {
|
|
|
862
862
|
}
|
|
863
863
|
}
|
|
864
864
|
|
|
865
|
-
// src/
|
|
866
|
-
function
|
|
865
|
+
// src/document/inlineIdentity.ts
|
|
866
|
+
function createDocumentIdentityState() {
|
|
867
867
|
return {
|
|
868
868
|
blockIds: /* @__PURE__ */ new Set(),
|
|
869
869
|
itemIds: /* @__PURE__ */ new Set(),
|
|
@@ -877,9 +877,9 @@ function importedOrGeneratedId(value, prefix, used) {
|
|
|
877
877
|
used.add(imported);
|
|
878
878
|
return imported;
|
|
879
879
|
}
|
|
880
|
-
let generated =
|
|
880
|
+
let generated = documentId(prefix);
|
|
881
881
|
while (used.has(generated)) {
|
|
882
|
-
generated =
|
|
882
|
+
generated = documentId(prefix);
|
|
883
883
|
}
|
|
884
884
|
used.add(generated);
|
|
885
885
|
return generated;
|
|
@@ -932,7 +932,7 @@ function applyImportedInlineIds(field, sidecar, state) {
|
|
|
932
932
|
return field;
|
|
933
933
|
}
|
|
934
934
|
|
|
935
|
-
// src/
|
|
935
|
+
// src/document/inlineScanner.ts
|
|
936
936
|
var MATH_ENVIRONMENTS = /* @__PURE__ */ new Set([
|
|
937
937
|
"equation",
|
|
938
938
|
"equation*",
|
|
@@ -1074,8 +1074,8 @@ function mathSpanAt(value, i) {
|
|
|
1074
1074
|
}
|
|
1075
1075
|
return null;
|
|
1076
1076
|
}
|
|
1077
|
-
function
|
|
1078
|
-
return
|
|
1077
|
+
function detectMathSpans(value) {
|
|
1078
|
+
return detectInlineSpans(value).filter((span) => span.kind === "math").map((span) => ({
|
|
1079
1079
|
start: span.start,
|
|
1080
1080
|
end: span.end,
|
|
1081
1081
|
source: span.source,
|
|
@@ -1084,7 +1084,7 @@ function detectMathSpans2(value) {
|
|
|
1084
1084
|
display: span.display
|
|
1085
1085
|
}));
|
|
1086
1086
|
}
|
|
1087
|
-
function
|
|
1087
|
+
function detectInlineSpans(value) {
|
|
1088
1088
|
const spans = [];
|
|
1089
1089
|
let i = 0;
|
|
1090
1090
|
while (i < value.length) {
|
|
@@ -1111,7 +1111,7 @@ function detectInlineSpans2(value) {
|
|
|
1111
1111
|
return spans;
|
|
1112
1112
|
}
|
|
1113
1113
|
|
|
1114
|
-
// src/
|
|
1114
|
+
// src/document/importJson.ts
|
|
1115
1115
|
var TEXT_COMMANDS = /* @__PURE__ */ new Set(["\\section", "\\subsection", "\\subsubsection", "\\paragraph"]);
|
|
1116
1116
|
var LIST_COMMANDS = /* @__PURE__ */ new Set(["\\begin{itemize}", "\\begin{enumerate}"]);
|
|
1117
1117
|
function isObject2(value) {
|
|
@@ -1173,9 +1173,9 @@ function parseReferences(json) {
|
|
|
1173
1173
|
}
|
|
1174
1174
|
return references;
|
|
1175
1175
|
}
|
|
1176
|
-
function
|
|
1176
|
+
function createInlineField(value = "", mathObjects = [], options = {}, path = "$", diagnostics = [], formats = []) {
|
|
1177
1177
|
const mode = options.mode ?? "english";
|
|
1178
|
-
const spans =
|
|
1178
|
+
const spans = detectInlineSpans(value);
|
|
1179
1179
|
const mathSpans = spans.filter((span) => span.kind === "math");
|
|
1180
1180
|
const tokens = [];
|
|
1181
1181
|
let index = 0;
|
|
@@ -1189,7 +1189,7 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
|
|
|
1189
1189
|
}
|
|
1190
1190
|
if (span.kind === "cite") {
|
|
1191
1191
|
tokens.push({
|
|
1192
|
-
id:
|
|
1192
|
+
id: documentId("cite"),
|
|
1193
1193
|
kind: "cite",
|
|
1194
1194
|
keys: span.keys.length > 0 ? span.keys : []
|
|
1195
1195
|
});
|
|
@@ -1198,7 +1198,7 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
|
|
|
1198
1198
|
}
|
|
1199
1199
|
if (span.kind === "ref") {
|
|
1200
1200
|
tokens.push({
|
|
1201
|
-
id:
|
|
1201
|
+
id: documentId("ref"),
|
|
1202
1202
|
kind: "ref",
|
|
1203
1203
|
keys: span.keys.length > 0 ? span.keys : [],
|
|
1204
1204
|
refCommand: span.refCommand
|
|
@@ -1214,7 +1214,7 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
|
|
|
1214
1214
|
}
|
|
1215
1215
|
if (structuredMathJson && structuredMathJson.math_mode === span.opening && structuredMathJson.closing === span.closing) {
|
|
1216
1216
|
tokens.push({
|
|
1217
|
-
id:
|
|
1217
|
+
id: documentId("math"),
|
|
1218
1218
|
kind: "math",
|
|
1219
1219
|
display: span.display,
|
|
1220
1220
|
opening: span.opening,
|
|
@@ -1229,7 +1229,7 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
|
|
|
1229
1229
|
});
|
|
1230
1230
|
} else {
|
|
1231
1231
|
tokens.push({
|
|
1232
|
-
id:
|
|
1232
|
+
id: documentId("math"),
|
|
1233
1233
|
kind: "math",
|
|
1234
1234
|
display: span.display,
|
|
1235
1235
|
opening: span.opening,
|
|
@@ -1248,7 +1248,7 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
|
|
|
1248
1248
|
if (index < value.length || tokens.length === 0) {
|
|
1249
1249
|
pushFormattedTextTokens(tokens, value.slice(index), index, formats);
|
|
1250
1250
|
}
|
|
1251
|
-
return { id:
|
|
1251
|
+
return { id: documentId("field"), tokens: compactTextTokens(tokens) };
|
|
1252
1252
|
}
|
|
1253
1253
|
function styleFromFormat(format) {
|
|
1254
1254
|
const style = {};
|
|
@@ -1293,7 +1293,7 @@ function styleKey(style) {
|
|
|
1293
1293
|
}
|
|
1294
1294
|
function pushFormattedTextTokens(tokens, text, sourceStart, formats) {
|
|
1295
1295
|
if (text.length === 0) {
|
|
1296
|
-
tokens.push({ id:
|
|
1296
|
+
tokens.push({ id: documentId("text"), kind: "text", text });
|
|
1297
1297
|
return;
|
|
1298
1298
|
}
|
|
1299
1299
|
const styles = Array.from({ length: text.length });
|
|
@@ -1318,7 +1318,7 @@ function pushFormattedTextTokens(tokens, text, sourceStart, formats) {
|
|
|
1318
1318
|
}
|
|
1319
1319
|
const chunk = text.slice(chunkStart, index);
|
|
1320
1320
|
const style = styles[chunkStart];
|
|
1321
|
-
tokens.push({ id:
|
|
1321
|
+
tokens.push({ id: documentId("text"), kind: "text", text: chunk, ...style ? { style } : {} });
|
|
1322
1322
|
chunkStart = index;
|
|
1323
1323
|
}
|
|
1324
1324
|
}
|
|
@@ -1332,7 +1332,7 @@ function parseTextBlock(json, options, path, diagnostics, identities) {
|
|
|
1332
1332
|
kind: "textBlock",
|
|
1333
1333
|
command: json.command,
|
|
1334
1334
|
field: applyImportedInlineIds(
|
|
1335
|
-
|
|
1335
|
+
createInlineField(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.command === "\\paragraph" ? json.formats ?? [] : []),
|
|
1336
1336
|
json.inline_ids,
|
|
1337
1337
|
identities
|
|
1338
1338
|
),
|
|
@@ -1346,7 +1346,7 @@ function parseListItem(json, options, path, diagnostics, identities) {
|
|
|
1346
1346
|
return {
|
|
1347
1347
|
id: importedOrGeneratedId(json.id, "item", identities.itemIds),
|
|
1348
1348
|
field: applyImportedInlineIds(
|
|
1349
|
-
|
|
1349
|
+
createInlineField(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.formats ?? []),
|
|
1350
1350
|
json.inline_ids,
|
|
1351
1351
|
identities
|
|
1352
1352
|
),
|
|
@@ -1375,7 +1375,7 @@ function parseListBlock(json, options, path, diagnostics, identities) {
|
|
|
1375
1375
|
function captionFieldFromJson(json, options, path, diagnostics, identities) {
|
|
1376
1376
|
const caption = typeof json.caption === "string" ? json.caption : "";
|
|
1377
1377
|
return applyImportedInlineIds(
|
|
1378
|
-
|
|
1378
|
+
createInlineField(
|
|
1379
1379
|
caption,
|
|
1380
1380
|
json.caption_math_objects ?? [],
|
|
1381
1381
|
options,
|
|
@@ -1399,12 +1399,12 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1399
1399
|
}
|
|
1400
1400
|
return row.map((cell, columnIndex) => {
|
|
1401
1401
|
const value = requireString(cell, "\\begin{tabular} cells must be strings");
|
|
1402
|
-
const spanCount =
|
|
1402
|
+
const spanCount = detectMathSpans(value).length;
|
|
1403
1403
|
const cellMathObjects = mathObjects.slice(mathObjectIndex, mathObjectIndex + spanCount);
|
|
1404
1404
|
mathObjectIndex += spanCount;
|
|
1405
1405
|
const cellFormats = json.cell_formats?.[rowIndex]?.[columnIndex] ?? [];
|
|
1406
1406
|
return applyImportedInlineIds(
|
|
1407
|
-
|
|
1407
|
+
createInlineField(value, cellMathObjects, options, `${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`, diagnostics, cellFormats),
|
|
1408
1408
|
json.cell_inline_ids?.[rowIndex]?.[columnIndex],
|
|
1409
1409
|
identities
|
|
1410
1410
|
);
|
|
@@ -1487,7 +1487,7 @@ function parseBlock(json, options, path, diagnostics, identities) {
|
|
|
1487
1487
|
...metadataFromJson(json.metadata)
|
|
1488
1488
|
};
|
|
1489
1489
|
}
|
|
1490
|
-
function
|
|
1490
|
+
function fromDocumentJson(json, options = {}) {
|
|
1491
1491
|
if (!isObject2(json) || json.node_type !== "DocumentObject") {
|
|
1492
1492
|
throw new Error('DocumentObject requires node_type "DocumentObject"');
|
|
1493
1493
|
}
|
|
@@ -1495,10 +1495,10 @@ function fromDocumentJson2(json, options = {}) {
|
|
|
1495
1495
|
throw new Error("DocumentObject requires blocks array");
|
|
1496
1496
|
}
|
|
1497
1497
|
const diagnostics = [];
|
|
1498
|
-
const identities =
|
|
1498
|
+
const identities = createDocumentIdentityState();
|
|
1499
1499
|
return {
|
|
1500
1500
|
nodeType: "DocumentObject",
|
|
1501
|
-
meta:
|
|
1501
|
+
meta: normalizeDocumentMeta(json.meta),
|
|
1502
1502
|
references: parseReferences(json.references),
|
|
1503
1503
|
blocks: json.blocks.map(
|
|
1504
1504
|
(block, index) => parseBlock(asBlockJson(block), options, `$.blocks[${String(index)}]`, diagnostics, identities)
|
|
@@ -3999,7 +3999,7 @@ ${ATOMIC_OPERATOR_COMMAND_CSS}
|
|
|
3999
3999
|
${STANDARD_COMMAND_CSS}
|
|
4000
4000
|
`.trim();
|
|
4001
4001
|
|
|
4002
|
-
// src/document/normalizeCharImport.ts
|
|
4002
|
+
// src/shared/math-document/normalizeCharImport.ts
|
|
4003
4003
|
var WRAPPER_SPECS = [
|
|
4004
4004
|
...NON_DEFAULT_CHARACTER_FONT_SPECS.flatMap((font) => [
|
|
4005
4005
|
{ prefix: font.macro, font: font.id },
|
|
@@ -4063,7 +4063,7 @@ function normalizeCharImportExpr(expr) {
|
|
|
4063
4063
|
return { expr: current, characterFont };
|
|
4064
4064
|
}
|
|
4065
4065
|
|
|
4066
|
-
// src/document/mathEditorAdapter.ts
|
|
4066
|
+
// src/shared/math-document/mathEditorAdapter.ts
|
|
4067
4067
|
var COMMAND_FONT_MAP = Object.fromEntries([
|
|
4068
4068
|
["\\text", "infer"],
|
|
4069
4069
|
...NON_DEFAULT_CHARACTER_FONT_SPECS.flatMap((font) => [
|
|
@@ -4762,23 +4762,23 @@ function mathNodeFromEditorSession(session, mathMode = "$", closing = "$") {
|
|
|
4762
4762
|
};
|
|
4763
4763
|
}
|
|
4764
4764
|
|
|
4765
|
-
// src/
|
|
4766
|
-
var
|
|
4765
|
+
// src/document/jsonCommandTypes.ts
|
|
4766
|
+
var DocumentCommandError = class extends Error {
|
|
4767
4767
|
code;
|
|
4768
4768
|
constructor(code, message) {
|
|
4769
4769
|
super(message);
|
|
4770
|
-
this.name = "
|
|
4770
|
+
this.name = "DocumentCommandError";
|
|
4771
4771
|
this.code = code;
|
|
4772
4772
|
}
|
|
4773
4773
|
};
|
|
4774
4774
|
|
|
4775
|
-
// src/
|
|
4775
|
+
// src/document/jsonCommandHelpers.ts
|
|
4776
4776
|
function isObject3(value) {
|
|
4777
4777
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4778
4778
|
}
|
|
4779
4779
|
function requireString2(value, field, allowEmpty = true) {
|
|
4780
4780
|
if (typeof value !== "string" || !allowEmpty && value.trim().length === 0) {
|
|
4781
|
-
throw new
|
|
4781
|
+
throw new DocumentCommandError("invalid_command", `${field} must be a${allowEmpty ? "" : " non-empty"} string`);
|
|
4782
4782
|
}
|
|
4783
4783
|
return value;
|
|
4784
4784
|
}
|
|
@@ -4787,13 +4787,13 @@ function optionalString(value, field) {
|
|
|
4787
4787
|
return void 0;
|
|
4788
4788
|
}
|
|
4789
4789
|
if (typeof value[field] !== "string") {
|
|
4790
|
-
throw new
|
|
4790
|
+
throw new DocumentCommandError("invalid_command", `${field} must be a string when provided`);
|
|
4791
4791
|
}
|
|
4792
4792
|
return value[field];
|
|
4793
4793
|
}
|
|
4794
4794
|
function requireBoolean(value, field) {
|
|
4795
4795
|
if (typeof value !== "boolean") {
|
|
4796
|
-
throw new
|
|
4796
|
+
throw new DocumentCommandError("invalid_command", `${field} must be a boolean`);
|
|
4797
4797
|
}
|
|
4798
4798
|
return value;
|
|
4799
4799
|
}
|
|
@@ -4805,7 +4805,7 @@ function optionalBoolean(value, field) {
|
|
|
4805
4805
|
}
|
|
4806
4806
|
function requireIndex(value, field) {
|
|
4807
4807
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
4808
|
-
throw new
|
|
4808
|
+
throw new DocumentCommandError("invalid_command", `${field} must be a non-negative integer`);
|
|
4809
4809
|
}
|
|
4810
4810
|
return value;
|
|
4811
4811
|
}
|
|
@@ -4814,25 +4814,25 @@ function parseMetadata(value) {
|
|
|
4814
4814
|
return void 0;
|
|
4815
4815
|
}
|
|
4816
4816
|
if (!isObject3(value)) {
|
|
4817
|
-
throw new
|
|
4817
|
+
throw new DocumentCommandError("invalid_command", "metadata must be an object");
|
|
4818
4818
|
}
|
|
4819
4819
|
if (value.source === void 0) {
|
|
4820
4820
|
return void 0;
|
|
4821
4821
|
}
|
|
4822
4822
|
if (value.source !== "agent" && value.source !== "user") {
|
|
4823
|
-
throw new
|
|
4823
|
+
throw new DocumentCommandError("invalid_command", "metadata.source must be agent or user");
|
|
4824
4824
|
}
|
|
4825
4825
|
return { source: value.source };
|
|
4826
4826
|
}
|
|
4827
4827
|
function parseBlockAnchor(value) {
|
|
4828
4828
|
if (!isObject3(value)) {
|
|
4829
|
-
throw new
|
|
4829
|
+
throw new DocumentCommandError("invalid_anchor", "anchor must be an object");
|
|
4830
4830
|
}
|
|
4831
4831
|
const before = typeof value.before_block_id === "string" ? value.before_block_id.trim() : "";
|
|
4832
4832
|
const after = typeof value.after_block_id === "string" ? value.after_block_id.trim() : "";
|
|
4833
4833
|
const choices = Number(before.length > 0) + Number(after.length > 0) + Number(value.end === true);
|
|
4834
4834
|
if (choices !== 1) {
|
|
4835
|
-
throw new
|
|
4835
|
+
throw new DocumentCommandError("invalid_anchor", "anchor requires exactly one block position");
|
|
4836
4836
|
}
|
|
4837
4837
|
if (before) {
|
|
4838
4838
|
return { before_block_id: before };
|
|
@@ -4844,13 +4844,13 @@ function parseBlockAnchor(value) {
|
|
|
4844
4844
|
}
|
|
4845
4845
|
function parseListItemAnchor(value) {
|
|
4846
4846
|
if (!isObject3(value)) {
|
|
4847
|
-
throw new
|
|
4847
|
+
throw new DocumentCommandError("invalid_anchor", "anchor must be an object");
|
|
4848
4848
|
}
|
|
4849
4849
|
const before = typeof value.before_item_id === "string" ? value.before_item_id.trim() : "";
|
|
4850
4850
|
const after = typeof value.after_item_id === "string" ? value.after_item_id.trim() : "";
|
|
4851
4851
|
const choices = Number(before.length > 0) + Number(after.length > 0) + Number(value.end === true);
|
|
4852
4852
|
if (choices !== 1) {
|
|
4853
|
-
throw new
|
|
4853
|
+
throw new DocumentCommandError("invalid_anchor", "anchor requires exactly one list-item position");
|
|
4854
4854
|
}
|
|
4855
4855
|
if (before) {
|
|
4856
4856
|
return { before_item_id: before };
|
|
@@ -4867,7 +4867,7 @@ function blockInsertionIndex(document2, anchor) {
|
|
|
4867
4867
|
const id = "before_block_id" in anchor ? anchor.before_block_id : anchor.after_block_id;
|
|
4868
4868
|
const index = document2.blocks.findIndex((block) => block.id === id);
|
|
4869
4869
|
if (index < 0) {
|
|
4870
|
-
throw new
|
|
4870
|
+
throw new DocumentCommandError("anchor_not_found", "Anchor block was not found");
|
|
4871
4871
|
}
|
|
4872
4872
|
return "before_block_id" in anchor ? index : index + 1;
|
|
4873
4873
|
}
|
|
@@ -4878,7 +4878,7 @@ function itemInsertionIndex(list, anchor) {
|
|
|
4878
4878
|
const id = "before_item_id" in anchor ? anchor.before_item_id : anchor.after_item_id;
|
|
4879
4879
|
const index = list.items.findIndex((item) => item.id === id);
|
|
4880
4880
|
if (index < 0) {
|
|
4881
|
-
throw new
|
|
4881
|
+
throw new DocumentCommandError("anchor_not_found", "Anchor list item was not found");
|
|
4882
4882
|
}
|
|
4883
4883
|
return "before_item_id" in anchor ? index : index + 1;
|
|
4884
4884
|
}
|
|
@@ -4966,9 +4966,9 @@ function documentIdentitySets(document2) {
|
|
|
4966
4966
|
return sets;
|
|
4967
4967
|
}
|
|
4968
4968
|
function unusedGeneratedId(prefix, used) {
|
|
4969
|
-
let id =
|
|
4969
|
+
let id = documentId(prefix);
|
|
4970
4970
|
while (used.has(id)) {
|
|
4971
|
-
id =
|
|
4971
|
+
id = documentId(prefix);
|
|
4972
4972
|
}
|
|
4973
4973
|
return id;
|
|
4974
4974
|
}
|
|
@@ -4982,7 +4982,7 @@ function newTokenId(document2, prefix) {
|
|
|
4982
4982
|
return unusedGeneratedId(prefix, documentIdentitySets(document2).tokens);
|
|
4983
4983
|
}
|
|
4984
4984
|
function createCommandInlineField(document2, text) {
|
|
4985
|
-
const field =
|
|
4985
|
+
const field = createInlineField(text);
|
|
4986
4986
|
const used = documentIdentitySets(document2);
|
|
4987
4987
|
field.id = unusedGeneratedId("field", used.fields);
|
|
4988
4988
|
field.tokens.forEach((token) => {
|
|
@@ -4994,20 +4994,20 @@ function createCommandInlineField(document2, text) {
|
|
|
4994
4994
|
function requireList(document2, listId) {
|
|
4995
4995
|
const block = findBlock(document2.blocks, listId);
|
|
4996
4996
|
if (!block) {
|
|
4997
|
-
throw new
|
|
4997
|
+
throw new DocumentCommandError("list_not_found", "Document list was not found");
|
|
4998
4998
|
}
|
|
4999
4999
|
if (block.kind !== "list") {
|
|
5000
|
-
throw new
|
|
5000
|
+
throw new DocumentCommandError("block_kind_mismatch", "Target block is not a list");
|
|
5001
5001
|
}
|
|
5002
5002
|
return block;
|
|
5003
5003
|
}
|
|
5004
5004
|
function requireTable(document2, tableId) {
|
|
5005
5005
|
const block = findBlock(document2.blocks, tableId);
|
|
5006
5006
|
if (!block) {
|
|
5007
|
-
throw new
|
|
5007
|
+
throw new DocumentCommandError("table_not_found", "Document table was not found");
|
|
5008
5008
|
}
|
|
5009
5009
|
if (block.kind !== "table") {
|
|
5010
|
-
throw new
|
|
5010
|
+
throw new DocumentCommandError("block_kind_mismatch", "Target block is not a table");
|
|
5011
5011
|
}
|
|
5012
5012
|
return block;
|
|
5013
5013
|
}
|
|
@@ -5016,7 +5016,7 @@ function fieldHasStructuredContent(field) {
|
|
|
5016
5016
|
}
|
|
5017
5017
|
function replacePlainField(document2, field, text) {
|
|
5018
5018
|
if (fieldHasStructuredContent(field)) {
|
|
5019
|
-
throw new
|
|
5019
|
+
throw new DocumentCommandError(
|
|
5020
5020
|
"unsupported_inline_content",
|
|
5021
5021
|
"Whole-field replacement is not supported for formatted or structured inline content"
|
|
5022
5022
|
);
|
|
@@ -5027,7 +5027,7 @@ function replacePlainField(document2, field, text) {
|
|
|
5027
5027
|
function textStylesEqual2(a, b) {
|
|
5028
5028
|
return Boolean(a?.bold) === Boolean(b?.bold) && Boolean(a?.italic) === Boolean(b?.italic) && Boolean(a?.underline) === Boolean(b?.underline);
|
|
5029
5029
|
}
|
|
5030
|
-
function compactTextTokens2(tokens, emptyTokenId =
|
|
5030
|
+
function compactTextTokens2(tokens, emptyTokenId = documentId("text")) {
|
|
5031
5031
|
const compacted = [];
|
|
5032
5032
|
for (const token of tokens) {
|
|
5033
5033
|
const previous = compacted[compacted.length - 1];
|
|
@@ -5040,17 +5040,17 @@ function compactTextTokens2(tokens, emptyTokenId = document2Id("text")) {
|
|
|
5040
5040
|
return compacted.length > 0 ? compacted : [{ id: emptyTokenId, kind: "text", text: "" }];
|
|
5041
5041
|
}
|
|
5042
5042
|
|
|
5043
|
-
// src/
|
|
5044
|
-
var
|
|
5045
|
-
function
|
|
5043
|
+
// src/document/keys.ts
|
|
5044
|
+
var DOCUMENT_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
|
|
5045
|
+
function normalizeDocumentKey(key) {
|
|
5046
5046
|
return key.normalize("NFC").trim();
|
|
5047
5047
|
}
|
|
5048
|
-
function
|
|
5049
|
-
const normalized =
|
|
5050
|
-
return normalized.length > 0 &&
|
|
5048
|
+
function isValidDocumentKey(key) {
|
|
5049
|
+
const normalized = normalizeDocumentKey(key);
|
|
5050
|
+
return normalized.length > 0 && DOCUMENT_KEY_PATTERN.test(normalized);
|
|
5051
5051
|
}
|
|
5052
|
-
function
|
|
5053
|
-
const normalized =
|
|
5052
|
+
function isDuplicateDocumentKey(key, namespace) {
|
|
5053
|
+
const normalized = normalizeDocumentKey(key);
|
|
5054
5054
|
if (normalized.length === 0) {
|
|
5055
5055
|
return false;
|
|
5056
5056
|
}
|
|
@@ -5058,7 +5058,7 @@ function isDuplicateDocument2Key(key, namespace) {
|
|
|
5058
5058
|
if (namespace.excludeReferenceId && reference.id === namespace.excludeReferenceId) {
|
|
5059
5059
|
continue;
|
|
5060
5060
|
}
|
|
5061
|
-
if (
|
|
5061
|
+
if (normalizeDocumentKey(reference.key) === normalized) {
|
|
5062
5062
|
return true;
|
|
5063
5063
|
}
|
|
5064
5064
|
}
|
|
@@ -5066,51 +5066,51 @@ function isDuplicateDocument2Key(key, namespace) {
|
|
|
5066
5066
|
if (namespace.excludeOwnerId && label.ownerId === namespace.excludeOwnerId) {
|
|
5067
5067
|
continue;
|
|
5068
5068
|
}
|
|
5069
|
-
if (
|
|
5069
|
+
if (normalizeDocumentKey(label.key) === normalized) {
|
|
5070
5070
|
return true;
|
|
5071
5071
|
}
|
|
5072
5072
|
}
|
|
5073
5073
|
return false;
|
|
5074
5074
|
}
|
|
5075
|
-
function
|
|
5076
|
-
const normalized =
|
|
5075
|
+
function documentKeyError(key, namespace = {}) {
|
|
5076
|
+
const normalized = normalizeDocumentKey(key);
|
|
5077
5077
|
if (normalized.length === 0) {
|
|
5078
5078
|
return "empty";
|
|
5079
5079
|
}
|
|
5080
|
-
if (!
|
|
5080
|
+
if (!DOCUMENT_KEY_PATTERN.test(normalized)) {
|
|
5081
5081
|
return "invalid";
|
|
5082
5082
|
}
|
|
5083
|
-
if (
|
|
5083
|
+
if (isDuplicateDocumentKey(normalized, namespace)) {
|
|
5084
5084
|
return "duplicate";
|
|
5085
5085
|
}
|
|
5086
5086
|
return null;
|
|
5087
5087
|
}
|
|
5088
5088
|
|
|
5089
|
-
// src/
|
|
5089
|
+
// src/document/articleJsonCommands.ts
|
|
5090
5090
|
var REFERENCE_TEXT_FIELDS = ["authors", "title", "year", "venue", "url"];
|
|
5091
5091
|
function hasOwn(value, field) {
|
|
5092
5092
|
return Object.prototype.hasOwnProperty.call(value, field);
|
|
5093
5093
|
}
|
|
5094
5094
|
function parseDatePatch(value) {
|
|
5095
5095
|
if (!isObject3(value)) {
|
|
5096
|
-
throw new
|
|
5096
|
+
throw new DocumentCommandError("invalid_command", "date must be an object");
|
|
5097
5097
|
}
|
|
5098
5098
|
const patch = {};
|
|
5099
5099
|
if (hasOwn(value, "day")) {
|
|
5100
5100
|
if (typeof value.day !== "number" || !Number.isInteger(value.day) || value.day < 1 || value.day > 30) {
|
|
5101
|
-
throw new
|
|
5101
|
+
throw new DocumentCommandError("invalid_command", "date.day must be an integer from 1 to 30");
|
|
5102
5102
|
}
|
|
5103
5103
|
patch.day = value.day;
|
|
5104
5104
|
}
|
|
5105
5105
|
if (hasOwn(value, "month")) {
|
|
5106
5106
|
if (typeof value.month !== "string" || !HIJRI_MONTH_IDS.includes(value.month)) {
|
|
5107
|
-
throw new
|
|
5107
|
+
throw new DocumentCommandError("invalid_command", "date.month must be a supported Hijri month");
|
|
5108
5108
|
}
|
|
5109
5109
|
patch.month = value.month;
|
|
5110
5110
|
}
|
|
5111
5111
|
if (hasOwn(value, "year")) {
|
|
5112
5112
|
if (typeof value.year !== "number" || !Number.isInteger(value.year) || value.year < HIJRI_YEAR_MIN || value.year > HIJRI_YEAR_MAX) {
|
|
5113
|
-
throw new
|
|
5113
|
+
throw new DocumentCommandError(
|
|
5114
5114
|
"invalid_command",
|
|
5115
5115
|
`date.year must be an integer from ${String(HIJRI_YEAR_MIN)} to ${String(HIJRI_YEAR_MAX)}`
|
|
5116
5116
|
);
|
|
@@ -5118,7 +5118,7 @@ function parseDatePatch(value) {
|
|
|
5118
5118
|
patch.year = value.year;
|
|
5119
5119
|
}
|
|
5120
5120
|
if (Object.keys(patch).length === 0) {
|
|
5121
|
-
throw new
|
|
5121
|
+
throw new DocumentCommandError("invalid_command", "date requires at least one field");
|
|
5122
5122
|
}
|
|
5123
5123
|
return patch;
|
|
5124
5124
|
}
|
|
@@ -5127,19 +5127,19 @@ function parseReferenceSeparator(value) {
|
|
|
5127
5127
|
return void 0;
|
|
5128
5128
|
}
|
|
5129
5129
|
if (value.field_separator !== "," && value.field_separator !== "\u060C") {
|
|
5130
|
-
throw new
|
|
5130
|
+
throw new DocumentCommandError("invalid_command", "field_separator must be , or \u060C");
|
|
5131
5131
|
}
|
|
5132
5132
|
return value.field_separator;
|
|
5133
5133
|
}
|
|
5134
5134
|
function parseReferenceAnchor(value) {
|
|
5135
5135
|
if (!isObject3(value)) {
|
|
5136
|
-
throw new
|
|
5136
|
+
throw new DocumentCommandError("invalid_anchor", "anchor must be an object");
|
|
5137
5137
|
}
|
|
5138
|
-
const before = typeof value.before_reference_key === "string" ?
|
|
5139
|
-
const after = typeof value.after_reference_key === "string" ?
|
|
5138
|
+
const before = typeof value.before_reference_key === "string" ? normalizeDocumentKey(value.before_reference_key) : "";
|
|
5139
|
+
const after = typeof value.after_reference_key === "string" ? normalizeDocumentKey(value.after_reference_key) : "";
|
|
5140
5140
|
const choices = Number(before.length > 0) + Number(after.length > 0) + Number(value.end === true);
|
|
5141
5141
|
if (choices !== 1) {
|
|
5142
|
-
throw new
|
|
5142
|
+
throw new DocumentCommandError("invalid_anchor", "anchor requires exactly one reference position");
|
|
5143
5143
|
}
|
|
5144
5144
|
if (before) {
|
|
5145
5145
|
return { before_reference_key: before };
|
|
@@ -5155,7 +5155,7 @@ function parseUpdateDocumentMeta(value) {
|
|
|
5155
5155
|
const abstract = optionalString(value, "abstract");
|
|
5156
5156
|
const date = hasOwn(value, "date") ? parseDatePatch(value.date) : void 0;
|
|
5157
5157
|
if (title === void 0 && authors === void 0 && abstract === void 0 && date === void 0) {
|
|
5158
|
-
throw new
|
|
5158
|
+
throw new DocumentCommandError("invalid_command", "update_document_meta requires at least one field");
|
|
5159
5159
|
}
|
|
5160
5160
|
return {
|
|
5161
5161
|
op: "update_document_meta",
|
|
@@ -5192,7 +5192,7 @@ function parseUpdateReference(value) {
|
|
|
5192
5192
|
const nextKey = optionalString(value, "key");
|
|
5193
5193
|
const fields = referenceFields(value);
|
|
5194
5194
|
if (nextKey === void 0 && Object.keys(fields).length === 0) {
|
|
5195
|
-
throw new
|
|
5195
|
+
throw new DocumentCommandError("invalid_command", "update_reference requires at least one field");
|
|
5196
5196
|
}
|
|
5197
5197
|
return {
|
|
5198
5198
|
op: "update_reference",
|
|
@@ -5224,13 +5224,13 @@ function parseArticleCommand(value) {
|
|
|
5224
5224
|
anchor: parseReferenceAnchor(value.anchor)
|
|
5225
5225
|
};
|
|
5226
5226
|
}
|
|
5227
|
-
throw new
|
|
5227
|
+
throw new DocumentCommandError("invalid_command", "Unsupported article command");
|
|
5228
5228
|
}
|
|
5229
5229
|
function referenceIndexes(document2, key) {
|
|
5230
|
-
const normalized =
|
|
5230
|
+
const normalized = normalizeDocumentKey(key);
|
|
5231
5231
|
const indexes = [];
|
|
5232
5232
|
document2.references.forEach((reference, index) => {
|
|
5233
|
-
if (
|
|
5233
|
+
if (normalizeDocumentKey(reference.key) === normalized) {
|
|
5234
5234
|
indexes.push(index);
|
|
5235
5235
|
}
|
|
5236
5236
|
});
|
|
@@ -5239,25 +5239,25 @@ function referenceIndexes(document2, key) {
|
|
|
5239
5239
|
function referenceTargetIndex(document2, key) {
|
|
5240
5240
|
const indexes = referenceIndexes(document2, key);
|
|
5241
5241
|
if (indexes.length === 0) {
|
|
5242
|
-
throw new
|
|
5242
|
+
throw new DocumentCommandError("reference_not_found", "Document reference was not found");
|
|
5243
5243
|
}
|
|
5244
5244
|
if (indexes.length > 1) {
|
|
5245
|
-
throw new
|
|
5245
|
+
throw new DocumentCommandError("duplicate_key", "Reference key is ambiguous");
|
|
5246
5246
|
}
|
|
5247
5247
|
return indexes[0];
|
|
5248
5248
|
}
|
|
5249
5249
|
function validateReferenceKey(document2, key, excludeReferenceId) {
|
|
5250
|
-
const normalized =
|
|
5251
|
-
const error =
|
|
5250
|
+
const normalized = normalizeDocumentKey(key);
|
|
5251
|
+
const error = documentKeyError(normalized, {
|
|
5252
5252
|
references: document2.references,
|
|
5253
|
-
labels:
|
|
5253
|
+
labels: collectDocumentLabels(document2),
|
|
5254
5254
|
...excludeReferenceId ? { excludeReferenceId } : {}
|
|
5255
5255
|
});
|
|
5256
5256
|
if (error === "duplicate") {
|
|
5257
|
-
throw new
|
|
5257
|
+
throw new DocumentCommandError("duplicate_key", "Reference key is already in use");
|
|
5258
5258
|
}
|
|
5259
5259
|
if (error !== null) {
|
|
5260
|
-
throw new
|
|
5260
|
+
throw new DocumentCommandError("invalid_key", "Reference key is invalid");
|
|
5261
5261
|
}
|
|
5262
5262
|
return normalized;
|
|
5263
5263
|
}
|
|
@@ -5268,10 +5268,10 @@ function referenceInsertionIndex(document2, anchor) {
|
|
|
5268
5268
|
const key = "before_reference_key" in anchor ? anchor.before_reference_key : anchor.after_reference_key;
|
|
5269
5269
|
const indexes = referenceIndexes(document2, key);
|
|
5270
5270
|
if (indexes.length === 0) {
|
|
5271
|
-
throw new
|
|
5271
|
+
throw new DocumentCommandError("anchor_not_found", "Anchor reference was not found");
|
|
5272
5272
|
}
|
|
5273
5273
|
if (indexes.length > 1) {
|
|
5274
|
-
throw new
|
|
5274
|
+
throw new DocumentCommandError("duplicate_key", "Anchor reference key is ambiguous");
|
|
5275
5275
|
}
|
|
5276
5276
|
return "before_reference_key" in anchor ? indexes[0] : indexes[0] + 1;
|
|
5277
5277
|
}
|
|
@@ -5323,7 +5323,7 @@ function applyArticleCommand(document2, command) {
|
|
|
5323
5323
|
title: command.title ?? document2.meta.title,
|
|
5324
5324
|
authors: command.authors ?? document2.meta.authors,
|
|
5325
5325
|
abstract: command.abstract ?? document2.meta.abstract,
|
|
5326
|
-
date: command.date ?
|
|
5326
|
+
date: command.date ? normalizeDocumentHijriDate({ ...document2.meta.date, ...command.date }) : { ...document2.meta.date }
|
|
5327
5327
|
};
|
|
5328
5328
|
return;
|
|
5329
5329
|
}
|
|
@@ -5357,10 +5357,10 @@ function applyArticleCommand(document2, command) {
|
|
|
5357
5357
|
document2.references.splice(targetIndex, 1);
|
|
5358
5358
|
return;
|
|
5359
5359
|
}
|
|
5360
|
-
const targetKey =
|
|
5360
|
+
const targetKey = normalizeDocumentKey(target.key);
|
|
5361
5361
|
const anchorKey = "before_reference_key" in command.anchor ? command.anchor.before_reference_key : "after_reference_key" in command.anchor ? command.anchor.after_reference_key : null;
|
|
5362
|
-
if (anchorKey !== null &&
|
|
5363
|
-
throw new
|
|
5362
|
+
if (anchorKey !== null && normalizeDocumentKey(anchorKey) === targetKey) {
|
|
5363
|
+
throw new DocumentCommandError("invalid_anchor", "A reference cannot be moved relative to itself");
|
|
5364
5364
|
}
|
|
5365
5365
|
if (anchorKey !== null) {
|
|
5366
5366
|
referenceInsertionIndex(document2, command.anchor);
|
|
@@ -5369,16 +5369,16 @@ function applyArticleCommand(document2, command) {
|
|
|
5369
5369
|
document2.references.splice(referenceInsertionIndex(document2, command.anchor), 0, reference);
|
|
5370
5370
|
}
|
|
5371
5371
|
|
|
5372
|
-
// src/
|
|
5372
|
+
// src/document/inlineJsonCommands.ts
|
|
5373
5373
|
function parseInlineAnchor(value) {
|
|
5374
5374
|
if (!isObject3(value)) {
|
|
5375
|
-
throw new
|
|
5375
|
+
throw new DocumentCommandError("invalid_anchor", "anchor must be an object");
|
|
5376
5376
|
}
|
|
5377
5377
|
const before = typeof value.before_token_id === "string" ? value.before_token_id.trim() : "";
|
|
5378
5378
|
const after = typeof value.after_token_id === "string" ? value.after_token_id.trim() : "";
|
|
5379
5379
|
const choices = Number(before.length > 0) + Number(after.length > 0) + Number(value.start === true) + Number(value.end === true);
|
|
5380
5380
|
if (choices !== 1) {
|
|
5381
|
-
throw new
|
|
5381
|
+
throw new DocumentCommandError("invalid_anchor", "anchor requires exactly one inline-token position");
|
|
5382
5382
|
}
|
|
5383
5383
|
if (before) {
|
|
5384
5384
|
return { before_token_id: before };
|
|
@@ -5393,12 +5393,12 @@ function parseStyle(value) {
|
|
|
5393
5393
|
return void 0;
|
|
5394
5394
|
}
|
|
5395
5395
|
if (!isObject3(value)) {
|
|
5396
|
-
throw new
|
|
5396
|
+
throw new DocumentCommandError("invalid_inline_token", "text token style must be an object");
|
|
5397
5397
|
}
|
|
5398
5398
|
const style = {};
|
|
5399
5399
|
for (const key of ["bold", "italic", "underline"]) {
|
|
5400
5400
|
if (value[key] !== void 0 && value[key] !== true) {
|
|
5401
|
-
throw new
|
|
5401
|
+
throw new DocumentCommandError("invalid_inline_token", `text token style.${key} must be true when provided`);
|
|
5402
5402
|
}
|
|
5403
5403
|
if (value[key] === true) {
|
|
5404
5404
|
style[key] = true;
|
|
@@ -5408,12 +5408,12 @@ function parseStyle(value) {
|
|
|
5408
5408
|
}
|
|
5409
5409
|
function normalizedKeys(value) {
|
|
5410
5410
|
if (!Array.isArray(value)) {
|
|
5411
|
-
throw new
|
|
5411
|
+
throw new DocumentCommandError("invalid_inline_token", "citation/reference keys must be an array");
|
|
5412
5412
|
}
|
|
5413
5413
|
const keys = [];
|
|
5414
5414
|
for (const entry of value) {
|
|
5415
5415
|
if (typeof entry !== "string") {
|
|
5416
|
-
throw new
|
|
5416
|
+
throw new DocumentCommandError("invalid_inline_token", "citation/reference keys must be strings");
|
|
5417
5417
|
}
|
|
5418
5418
|
const key = entry.trim();
|
|
5419
5419
|
if (key.length > 0 && !keys.includes(key)) {
|
|
@@ -5421,37 +5421,37 @@ function normalizedKeys(value) {
|
|
|
5421
5421
|
}
|
|
5422
5422
|
}
|
|
5423
5423
|
if (keys.length === 0) {
|
|
5424
|
-
throw new
|
|
5424
|
+
throw new DocumentCommandError("invalid_inline_token", "citation/reference requires at least one non-empty key");
|
|
5425
5425
|
}
|
|
5426
5426
|
return keys;
|
|
5427
5427
|
}
|
|
5428
5428
|
function parseMathObject(value, source) {
|
|
5429
5429
|
if (!isObject3(value) || value.node_type !== "MathObject") {
|
|
5430
|
-
throw new
|
|
5430
|
+
throw new DocumentCommandError("math_object_mismatch", "math_object must be a structured MathObject");
|
|
5431
5431
|
}
|
|
5432
|
-
const spans =
|
|
5432
|
+
const spans = detectInlineSpans(source);
|
|
5433
5433
|
const span = spans[0];
|
|
5434
5434
|
if (spans.length !== 1 || span?.kind !== "math" || span.start !== 0 || span.end !== source.length) {
|
|
5435
|
-
throw new
|
|
5435
|
+
throw new DocumentCommandError("math_object_mismatch", "math source must contain exactly one complete delimited span");
|
|
5436
5436
|
}
|
|
5437
5437
|
if (value.math_mode !== span.opening || value.closing !== span.closing) {
|
|
5438
|
-
throw new
|
|
5438
|
+
throw new DocumentCommandError("math_object_mismatch", "math_object delimiters do not match math source");
|
|
5439
5439
|
}
|
|
5440
5440
|
try {
|
|
5441
5441
|
fromMathObjectJson(value, value.source_side === "arabic" ? "arabic" : "english");
|
|
5442
5442
|
} catch {
|
|
5443
|
-
throw new
|
|
5443
|
+
throw new DocumentCommandError("math_object_mismatch", "math_object must contain a valid structured equation");
|
|
5444
5444
|
}
|
|
5445
5445
|
return value;
|
|
5446
5446
|
}
|
|
5447
5447
|
function parseToken(value) {
|
|
5448
5448
|
if (!isObject3(value) || typeof value.kind !== "string") {
|
|
5449
|
-
throw new
|
|
5449
|
+
throw new DocumentCommandError("invalid_inline_token", "token requires a kind");
|
|
5450
5450
|
}
|
|
5451
5451
|
if (value.kind === "text") {
|
|
5452
5452
|
const text = requireString2(value.text, "token.text");
|
|
5453
|
-
if (
|
|
5454
|
-
throw new
|
|
5453
|
+
if (detectInlineSpans(text).length > 0) {
|
|
5454
|
+
throw new DocumentCommandError("invalid_inline_token", "text token contains structured inline syntax");
|
|
5455
5455
|
}
|
|
5456
5456
|
const style = parseStyle(value.style);
|
|
5457
5457
|
return { kind: "text", text, ...style ? { style } : {} };
|
|
@@ -5461,7 +5461,7 @@ function parseToken(value) {
|
|
|
5461
5461
|
}
|
|
5462
5462
|
if (value.kind === "ref") {
|
|
5463
5463
|
if (value.ref_command !== "ref" && value.ref_command !== "eqref") {
|
|
5464
|
-
throw new
|
|
5464
|
+
throw new DocumentCommandError("invalid_inline_token", "ref_command must be ref or eqref");
|
|
5465
5465
|
}
|
|
5466
5466
|
return { kind: "ref", keys: normalizedKeys(value.keys), ref_command: value.ref_command };
|
|
5467
5467
|
}
|
|
@@ -5469,7 +5469,7 @@ function parseToken(value) {
|
|
|
5469
5469
|
const source = requireString2(value.source, "token.source", false);
|
|
5470
5470
|
return { kind: "math", source, math_object: parseMathObject(value.math_object, source) };
|
|
5471
5471
|
}
|
|
5472
|
-
throw new
|
|
5472
|
+
throw new DocumentCommandError("invalid_inline_token", "Unsupported inline token kind");
|
|
5473
5473
|
}
|
|
5474
5474
|
function parseInlineCommand(value) {
|
|
5475
5475
|
if (value.op === "insert_inline_token") {
|
|
@@ -5495,7 +5495,7 @@ function parseInlineCommand(value) {
|
|
|
5495
5495
|
token_id: requireString2(value.token_id, "token_id", false).trim()
|
|
5496
5496
|
};
|
|
5497
5497
|
}
|
|
5498
|
-
throw new
|
|
5498
|
+
throw new DocumentCommandError("invalid_command", "Unsupported inline command");
|
|
5499
5499
|
}
|
|
5500
5500
|
function liveToken(input, id) {
|
|
5501
5501
|
if (input.kind === "text") {
|
|
@@ -5508,10 +5508,10 @@ function liveToken(input, id) {
|
|
|
5508
5508
|
return { id, kind: "ref", keys: [...input.keys], refCommand: input.ref_command };
|
|
5509
5509
|
}
|
|
5510
5510
|
const mathObject = input.math_object;
|
|
5511
|
-
const spans =
|
|
5511
|
+
const spans = detectInlineSpans(input.source);
|
|
5512
5512
|
const span = spans[0];
|
|
5513
5513
|
if (!span || span.kind !== "math") {
|
|
5514
|
-
throw new
|
|
5514
|
+
throw new DocumentCommandError("math_object_mismatch", "math source is not a complete delimited span");
|
|
5515
5515
|
}
|
|
5516
5516
|
return {
|
|
5517
5517
|
id,
|
|
@@ -5538,14 +5538,14 @@ function insertionIndex(tokens, anchor) {
|
|
|
5538
5538
|
const id = "before_token_id" in anchor ? anchor.before_token_id : anchor.after_token_id;
|
|
5539
5539
|
const index = tokens.findIndex((token) => token.id === id);
|
|
5540
5540
|
if (index < 0) {
|
|
5541
|
-
throw new
|
|
5541
|
+
throw new DocumentCommandError("token_not_found", "Anchor token was not found");
|
|
5542
5542
|
}
|
|
5543
5543
|
return "before_token_id" in anchor ? index : index + 1;
|
|
5544
5544
|
}
|
|
5545
5545
|
function applyInlineCommand(document2, command) {
|
|
5546
5546
|
const field = findField(document2.blocks, command.field_id);
|
|
5547
5547
|
if (!field) {
|
|
5548
|
-
throw new
|
|
5548
|
+
throw new DocumentCommandError("field_not_found", "Inline field was not found");
|
|
5549
5549
|
}
|
|
5550
5550
|
if (command.op === "insert_inline_token") {
|
|
5551
5551
|
const index2 = insertionIndex(field.tokens, command.anchor);
|
|
@@ -5554,7 +5554,7 @@ function applyInlineCommand(document2, command) {
|
|
|
5554
5554
|
}
|
|
5555
5555
|
const index = field.tokens.findIndex((token) => token.id === command.token_id);
|
|
5556
5556
|
if (index < 0) {
|
|
5557
|
-
throw new
|
|
5557
|
+
throw new DocumentCommandError("token_not_found", "Inline token was not found");
|
|
5558
5558
|
}
|
|
5559
5559
|
if (command.op === "replace_inline_token") {
|
|
5560
5560
|
field.tokens[index] = liveToken(command.token, command.token_id);
|
|
@@ -5566,10 +5566,10 @@ function applyInlineCommand(document2, command) {
|
|
|
5566
5566
|
);
|
|
5567
5567
|
}
|
|
5568
5568
|
|
|
5569
|
-
// src/
|
|
5569
|
+
// src/document/listJsonCommands.ts
|
|
5570
5570
|
function stringArray(value, field) {
|
|
5571
5571
|
if (!Array.isArray(value) || value.length === 0 || value.some((entry) => typeof entry !== "string")) {
|
|
5572
|
-
throw new
|
|
5572
|
+
throw new DocumentCommandError("invalid_command", `${field} must be a non-empty string array`);
|
|
5573
5573
|
}
|
|
5574
5574
|
return [...value];
|
|
5575
5575
|
}
|
|
@@ -5615,7 +5615,7 @@ function parseListCommand(value) {
|
|
|
5615
5615
|
anchor: parseListItemAnchor(value.anchor)
|
|
5616
5616
|
};
|
|
5617
5617
|
}
|
|
5618
|
-
throw new
|
|
5618
|
+
throw new DocumentCommandError("invalid_command", "Unsupported list command");
|
|
5619
5619
|
}
|
|
5620
5620
|
function newItem(document2, text) {
|
|
5621
5621
|
return { id: newItemId(document2), field: createCommandInlineField(document2, text), blocks: [] };
|
|
@@ -5644,7 +5644,7 @@ function applyListCommand(document2, command) {
|
|
|
5644
5644
|
}
|
|
5645
5645
|
const itemIndex = list.items.findIndex((item2) => item2.id === command.item_id);
|
|
5646
5646
|
if (itemIndex < 0) {
|
|
5647
|
-
throw new
|
|
5647
|
+
throw new DocumentCommandError("item_not_found", "Document list item was not found");
|
|
5648
5648
|
}
|
|
5649
5649
|
if (command.op === "replace_list_item") {
|
|
5650
5650
|
replacePlainField(document2, list.items[itemIndex].field, command.text);
|
|
@@ -5652,44 +5652,44 @@ function applyListCommand(document2, command) {
|
|
|
5652
5652
|
}
|
|
5653
5653
|
if (command.op === "remove_list_item") {
|
|
5654
5654
|
if (list.items.length === 1) {
|
|
5655
|
-
throw new
|
|
5655
|
+
throw new DocumentCommandError("minimum_structure", "A list must retain at least one item");
|
|
5656
5656
|
}
|
|
5657
5657
|
list.items.splice(itemIndex, 1);
|
|
5658
5658
|
return;
|
|
5659
5659
|
}
|
|
5660
5660
|
const anchorId = "before_item_id" in command.anchor ? command.anchor.before_item_id : "after_item_id" in command.anchor ? command.anchor.after_item_id : null;
|
|
5661
5661
|
if (anchorId === command.item_id) {
|
|
5662
|
-
throw new
|
|
5662
|
+
throw new DocumentCommandError("invalid_anchor", "A list item cannot be moved relative to itself");
|
|
5663
5663
|
}
|
|
5664
5664
|
const [item] = list.items.splice(itemIndex, 1);
|
|
5665
5665
|
if (!item) {
|
|
5666
|
-
throw new
|
|
5666
|
+
throw new DocumentCommandError("item_not_found", "Document list item was not found");
|
|
5667
5667
|
}
|
|
5668
5668
|
list.items.splice(itemInsertionIndex(list, command.anchor), 0, item);
|
|
5669
5669
|
}
|
|
5670
5670
|
|
|
5671
|
-
// src/
|
|
5671
|
+
// src/document/tableJsonCommands.ts
|
|
5672
5672
|
function stringArray2(value, field) {
|
|
5673
5673
|
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
|
|
5674
|
-
throw new
|
|
5674
|
+
throw new DocumentCommandError("invalid_command", `${field} must be a string array`);
|
|
5675
5675
|
}
|
|
5676
5676
|
return [...value];
|
|
5677
5677
|
}
|
|
5678
5678
|
function rectangularRows(value) {
|
|
5679
5679
|
if (!Array.isArray(value) || value.length === 0) {
|
|
5680
|
-
throw new
|
|
5680
|
+
throw new DocumentCommandError("invalid_table_shape", "rows must be a non-empty array");
|
|
5681
5681
|
}
|
|
5682
5682
|
const rows = value.map((row, index) => stringArray2(row, `rows[${String(index)}]`));
|
|
5683
5683
|
const columnCount = rows[0]?.length ?? 0;
|
|
5684
5684
|
if (columnCount === 0 || rows.some((row) => row.length !== columnCount)) {
|
|
5685
|
-
throw new
|
|
5685
|
+
throw new DocumentCommandError("invalid_table_shape", "Table rows must form a non-empty rectangle");
|
|
5686
5686
|
}
|
|
5687
5687
|
return rows;
|
|
5688
5688
|
}
|
|
5689
5689
|
function columns(value) {
|
|
5690
5690
|
const result = requireString2(value, "columns", false);
|
|
5691
5691
|
if (result.trim().length === 0) {
|
|
5692
|
-
throw new
|
|
5692
|
+
throw new DocumentCommandError("invalid_table_shape", "columns must be a non-empty LaTeX specification");
|
|
5693
5693
|
}
|
|
5694
5694
|
return result;
|
|
5695
5695
|
}
|
|
@@ -5766,7 +5766,7 @@ function parseTableCommand(value) {
|
|
|
5766
5766
|
columns: columns(value.columns)
|
|
5767
5767
|
};
|
|
5768
5768
|
}
|
|
5769
|
-
throw new
|
|
5769
|
+
throw new DocumentCommandError("invalid_command", "Unsupported table command");
|
|
5770
5770
|
}
|
|
5771
5771
|
function insertTable(document2, command) {
|
|
5772
5772
|
const block = {
|
|
@@ -5790,12 +5790,12 @@ function insertTable(document2, command) {
|
|
|
5790
5790
|
}
|
|
5791
5791
|
function checkCell(table, rowIndex, columnIndex) {
|
|
5792
5792
|
if (rowIndex >= table.rows.length || columnIndex >= (table.rows[rowIndex]?.length ?? 0)) {
|
|
5793
|
-
throw new
|
|
5793
|
+
throw new DocumentCommandError("index_out_of_range", "Table cell index is out of range");
|
|
5794
5794
|
}
|
|
5795
5795
|
}
|
|
5796
5796
|
function checkExistingIndex(index, length, field) {
|
|
5797
5797
|
if (index >= length) {
|
|
5798
|
-
throw new
|
|
5798
|
+
throw new DocumentCommandError("index_out_of_range", `${field} is out of range`);
|
|
5799
5799
|
}
|
|
5800
5800
|
}
|
|
5801
5801
|
function applyTableCommand(document2, command) {
|
|
@@ -5806,7 +5806,7 @@ function applyTableCommand(document2, command) {
|
|
|
5806
5806
|
const table = requireTable(document2, command.table_id);
|
|
5807
5807
|
const columnCount = table.rows[0]?.length ?? 0;
|
|
5808
5808
|
if (table.rows.length === 0 || columnCount === 0 || table.rows.some((row) => row.length !== columnCount)) {
|
|
5809
|
-
throw new
|
|
5809
|
+
throw new DocumentCommandError("invalid_table_shape", "Target table must be a non-empty rectangle");
|
|
5810
5810
|
}
|
|
5811
5811
|
if (command.op === "replace_table_cell") {
|
|
5812
5812
|
checkCell(table, command.row_index, command.column_index);
|
|
@@ -5815,10 +5815,10 @@ function applyTableCommand(document2, command) {
|
|
|
5815
5815
|
}
|
|
5816
5816
|
if (command.op === "insert_table_row") {
|
|
5817
5817
|
if (command.index > table.rows.length) {
|
|
5818
|
-
throw new
|
|
5818
|
+
throw new DocumentCommandError("index_out_of_range", "Table row insertion index is out of range");
|
|
5819
5819
|
}
|
|
5820
5820
|
if (command.values.length !== columnCount) {
|
|
5821
|
-
throw new
|
|
5821
|
+
throw new DocumentCommandError("invalid_table_shape", "Inserted row must match the current column count");
|
|
5822
5822
|
}
|
|
5823
5823
|
table.rows.splice(command.index, 0, command.values.map((value) => createCommandInlineField(document2, value)));
|
|
5824
5824
|
return;
|
|
@@ -5826,7 +5826,7 @@ function applyTableCommand(document2, command) {
|
|
|
5826
5826
|
if (command.op === "remove_table_row") {
|
|
5827
5827
|
checkExistingIndex(command.index, table.rows.length, "Table row index");
|
|
5828
5828
|
if (table.rows.length === 1) {
|
|
5829
|
-
throw new
|
|
5829
|
+
throw new DocumentCommandError("minimum_structure", "A table must retain at least one row");
|
|
5830
5830
|
}
|
|
5831
5831
|
table.rows.splice(command.index, 1);
|
|
5832
5832
|
return;
|
|
@@ -5840,10 +5840,10 @@ function applyTableCommand(document2, command) {
|
|
|
5840
5840
|
}
|
|
5841
5841
|
if (command.op === "insert_table_column") {
|
|
5842
5842
|
if (command.index > columnCount) {
|
|
5843
|
-
throw new
|
|
5843
|
+
throw new DocumentCommandError("index_out_of_range", "Table column insertion index is out of range");
|
|
5844
5844
|
}
|
|
5845
5845
|
if (command.values.length !== table.rows.length) {
|
|
5846
|
-
throw new
|
|
5846
|
+
throw new DocumentCommandError("invalid_table_shape", "Inserted column requires one value per row");
|
|
5847
5847
|
}
|
|
5848
5848
|
table.rows.forEach((row, index) => row.splice(command.index, 0, createCommandInlineField(document2, command.values[index])));
|
|
5849
5849
|
table.columns = command.columns;
|
|
@@ -5852,7 +5852,7 @@ function applyTableCommand(document2, command) {
|
|
|
5852
5852
|
if (command.op === "remove_table_column") {
|
|
5853
5853
|
checkExistingIndex(command.index, columnCount, "Table column index");
|
|
5854
5854
|
if (columnCount === 1) {
|
|
5855
|
-
throw new
|
|
5855
|
+
throw new DocumentCommandError("minimum_structure", "A table must retain at least one column");
|
|
5856
5856
|
}
|
|
5857
5857
|
table.rows.forEach((row) => row.splice(command.index, 1));
|
|
5858
5858
|
table.columns = command.columns;
|
|
@@ -5867,7 +5867,7 @@ function applyTableCommand(document2, command) {
|
|
|
5867
5867
|
table.columns = command.columns;
|
|
5868
5868
|
}
|
|
5869
5869
|
|
|
5870
|
-
// src/
|
|
5870
|
+
// src/document/exportJson.ts
|
|
5871
5871
|
function serializeField(field) {
|
|
5872
5872
|
let value = "";
|
|
5873
5873
|
let hasPersistedMath = false;
|
|
@@ -6030,9 +6030,9 @@ function referenceJson(reference) {
|
|
|
6030
6030
|
field_separator: reference.fieldSeparator
|
|
6031
6031
|
};
|
|
6032
6032
|
}
|
|
6033
|
-
function
|
|
6033
|
+
function toDocumentJson(document2) {
|
|
6034
6034
|
if (document2.nodeType !== "DocumentObject" || !Array.isArray(document2.blocks)) {
|
|
6035
|
-
throw new Error("
|
|
6035
|
+
throw new Error("toDocumentJson requires a live DocumentNode");
|
|
6036
6036
|
}
|
|
6037
6037
|
return {
|
|
6038
6038
|
node_type: "DocumentObject",
|
|
@@ -6047,7 +6047,7 @@ function toDocumentJson2(document2) {
|
|
|
6047
6047
|
};
|
|
6048
6048
|
}
|
|
6049
6049
|
|
|
6050
|
-
// src/
|
|
6050
|
+
// src/document/jsonCommands.ts
|
|
6051
6051
|
function isInlineCommand(command) {
|
|
6052
6052
|
return command.op === "insert_inline_token" || command.op === "replace_inline_token" || command.op === "remove_inline_token";
|
|
6053
6053
|
}
|
|
@@ -6064,7 +6064,7 @@ function parseTextBlockKind(value) {
|
|
|
6064
6064
|
if (value === "section" || value === "subsection" || value === "subsubsection" || value === "paragraph") {
|
|
6065
6065
|
return value;
|
|
6066
6066
|
}
|
|
6067
|
-
throw new
|
|
6067
|
+
throw new DocumentCommandError("invalid_command", "kind must be section, subsection, subsubsection, or paragraph");
|
|
6068
6068
|
}
|
|
6069
6069
|
function parseBasicCommand(value) {
|
|
6070
6070
|
if (value.op === "insert_text_block") {
|
|
@@ -6106,7 +6106,7 @@ function parseBasicCommand(value) {
|
|
|
6106
6106
|
const hasAssetId = Object.prototype.hasOwnProperty.call(value, "asset_id");
|
|
6107
6107
|
const hasValue = Object.prototype.hasOwnProperty.call(value, "value");
|
|
6108
6108
|
if (!hasAssetId && !hasValue) {
|
|
6109
|
-
throw new
|
|
6109
|
+
throw new DocumentCommandError("invalid_command", "update_figure requires asset_id or value");
|
|
6110
6110
|
}
|
|
6111
6111
|
let assetId;
|
|
6112
6112
|
if (hasAssetId) {
|
|
@@ -6131,7 +6131,7 @@ function parseBasicCommand(value) {
|
|
|
6131
6131
|
const labelEnabled = optionalBoolean(value, "label_enabled");
|
|
6132
6132
|
const label = optionalString(value, "label");
|
|
6133
6133
|
if (centered === void 0 && captionEnabled === void 0 && caption === void 0 && labelEnabled === void 0 && label === void 0) {
|
|
6134
|
-
throw new
|
|
6134
|
+
throw new DocumentCommandError("invalid_command", "update_float_meta requires at least one field");
|
|
6135
6135
|
}
|
|
6136
6136
|
return {
|
|
6137
6137
|
op: value.op,
|
|
@@ -6158,11 +6158,11 @@ function parseBasicCommand(value) {
|
|
|
6158
6158
|
...metadata ? { metadata } : {}
|
|
6159
6159
|
};
|
|
6160
6160
|
}
|
|
6161
|
-
throw new
|
|
6161
|
+
throw new DocumentCommandError("invalid_command", "Unsupported block command");
|
|
6162
6162
|
}
|
|
6163
6163
|
function parseCommand2(value) {
|
|
6164
6164
|
if (!isObject3(value) || typeof value.op !== "string") {
|
|
6165
|
-
throw new
|
|
6165
|
+
throw new DocumentCommandError("invalid_command", "command requires an op");
|
|
6166
6166
|
}
|
|
6167
6167
|
if (value.op === "insert_inline_token" || value.op === "replace_inline_token" || value.op === "remove_inline_token") {
|
|
6168
6168
|
return parseInlineCommand(value);
|
|
@@ -6179,13 +6179,13 @@ function parseCommand2(value) {
|
|
|
6179
6179
|
if (value.op === "insert_text_block" || value.op === "replace_text_block" || value.op === "remove_block" || value.op === "move_block" || value.op === "insert_figure" || value.op === "update_figure" || value.op === "update_float_meta" || value.op === "insert_bibliography") {
|
|
6180
6180
|
return parseBasicCommand(value);
|
|
6181
6181
|
}
|
|
6182
|
-
throw new
|
|
6182
|
+
throw new DocumentCommandError("invalid_command", "Unsupported document command");
|
|
6183
6183
|
}
|
|
6184
6184
|
function parseDocument(json) {
|
|
6185
6185
|
try {
|
|
6186
|
-
return
|
|
6186
|
+
return fromDocumentJson(json);
|
|
6187
6187
|
} catch {
|
|
6188
|
-
throw new
|
|
6188
|
+
throw new DocumentCommandError("invalid_document", "Document JSON is invalid");
|
|
6189
6189
|
}
|
|
6190
6190
|
}
|
|
6191
6191
|
function textCommand(kind) {
|
|
@@ -6213,10 +6213,10 @@ function applyBasicCommand(document2, command) {
|
|
|
6213
6213
|
if (command.op === "replace_text_block") {
|
|
6214
6214
|
const block2 = document2.blocks.find((entry) => entry.id === command.block_id);
|
|
6215
6215
|
if (!block2) {
|
|
6216
|
-
throw new
|
|
6216
|
+
throw new DocumentCommandError("block_not_found", "Document block was not found");
|
|
6217
6217
|
}
|
|
6218
6218
|
if (block2.kind !== "textBlock") {
|
|
6219
|
-
throw new
|
|
6219
|
+
throw new DocumentCommandError("block_kind_mismatch", "Document block is not a text block");
|
|
6220
6220
|
}
|
|
6221
6221
|
replacePlainField(document2, block2.field, command.text);
|
|
6222
6222
|
return;
|
|
@@ -6224,7 +6224,7 @@ function applyBasicCommand(document2, command) {
|
|
|
6224
6224
|
if (command.op === "remove_block") {
|
|
6225
6225
|
const index = document2.blocks.findIndex((block2) => block2.id === command.block_id);
|
|
6226
6226
|
if (index < 0) {
|
|
6227
|
-
throw new
|
|
6227
|
+
throw new DocumentCommandError("block_not_found", "Document block was not found");
|
|
6228
6228
|
}
|
|
6229
6229
|
document2.blocks.splice(index, 1);
|
|
6230
6230
|
return;
|
|
@@ -6232,11 +6232,11 @@ function applyBasicCommand(document2, command) {
|
|
|
6232
6232
|
if (command.op === "move_block") {
|
|
6233
6233
|
const index = document2.blocks.findIndex((block3) => block3.id === command.block_id);
|
|
6234
6234
|
if (index < 0) {
|
|
6235
|
-
throw new
|
|
6235
|
+
throw new DocumentCommandError("block_not_found", "Document block was not found");
|
|
6236
6236
|
}
|
|
6237
6237
|
const anchorId = "before_block_id" in command.anchor ? command.anchor.before_block_id : "after_block_id" in command.anchor ? command.anchor.after_block_id : null;
|
|
6238
6238
|
if (anchorId === command.block_id) {
|
|
6239
|
-
throw new
|
|
6239
|
+
throw new DocumentCommandError("invalid_anchor", "A block cannot be moved relative to itself");
|
|
6240
6240
|
}
|
|
6241
6241
|
if (anchorId !== null) {
|
|
6242
6242
|
blockInsertionIndex(document2, command.anchor);
|
|
@@ -6251,7 +6251,7 @@ function applyBasicCommand(document2, command) {
|
|
|
6251
6251
|
};
|
|
6252
6252
|
var hasBibliography = hasBibliography2;
|
|
6253
6253
|
if (hasBibliography2(document2.blocks)) {
|
|
6254
|
-
throw new
|
|
6254
|
+
throw new DocumentCommandError("bibliography_exists", "Document already contains a bibliography block");
|
|
6255
6255
|
}
|
|
6256
6256
|
const block2 = {
|
|
6257
6257
|
id: newBlockId(document2),
|
|
@@ -6266,10 +6266,10 @@ function applyBasicCommand(document2, command) {
|
|
|
6266
6266
|
if (command.op === "update_figure") {
|
|
6267
6267
|
const block2 = findBlock(document2.blocks, command.block_id);
|
|
6268
6268
|
if (!block2) {
|
|
6269
|
-
throw new
|
|
6269
|
+
throw new DocumentCommandError("block_not_found", "Document block was not found");
|
|
6270
6270
|
}
|
|
6271
6271
|
if (block2.kind !== "image") {
|
|
6272
|
-
throw new
|
|
6272
|
+
throw new DocumentCommandError("block_kind_mismatch", "Target block is not a figure");
|
|
6273
6273
|
}
|
|
6274
6274
|
if ("asset_id" in command) {
|
|
6275
6275
|
if (command.asset_id === null) {
|
|
@@ -6286,26 +6286,26 @@ function applyBasicCommand(document2, command) {
|
|
|
6286
6286
|
if (command.op === "update_float_meta") {
|
|
6287
6287
|
const block2 = findBlock(document2.blocks, command.block_id);
|
|
6288
6288
|
if (!block2) {
|
|
6289
|
-
throw new
|
|
6289
|
+
throw new DocumentCommandError("block_not_found", "Document block was not found");
|
|
6290
6290
|
}
|
|
6291
6291
|
if (block2.kind !== "image" && block2.kind !== "table") {
|
|
6292
|
-
throw new
|
|
6292
|
+
throw new DocumentCommandError("block_kind_mismatch", "Target block is not a figure or table");
|
|
6293
6293
|
}
|
|
6294
6294
|
let label = command.label;
|
|
6295
6295
|
if (label !== void 0) {
|
|
6296
|
-
label = label.trim().length > 0 ?
|
|
6296
|
+
label = label.trim().length > 0 ? normalizeDocumentKey(label) : "";
|
|
6297
6297
|
}
|
|
6298
6298
|
if (label !== void 0 && label.length > 0) {
|
|
6299
|
-
const keyError =
|
|
6299
|
+
const keyError = documentKeyError(label, {
|
|
6300
6300
|
references: document2.references,
|
|
6301
|
-
labels:
|
|
6301
|
+
labels: collectDocumentLabels(document2),
|
|
6302
6302
|
excludeOwnerId: block2.id
|
|
6303
6303
|
});
|
|
6304
6304
|
if (keyError === "duplicate") {
|
|
6305
|
-
throw new
|
|
6305
|
+
throw new DocumentCommandError("duplicate_key", "Float label is already in use");
|
|
6306
6306
|
}
|
|
6307
6307
|
if (keyError !== null) {
|
|
6308
|
-
throw new
|
|
6308
|
+
throw new DocumentCommandError("invalid_key", "Float label is invalid");
|
|
6309
6309
|
}
|
|
6310
6310
|
}
|
|
6311
6311
|
applyFloatMetaPatch(block2, {
|
|
@@ -6336,7 +6336,7 @@ function applyBasicCommand(document2, command) {
|
|
|
6336
6336
|
}
|
|
6337
6337
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
6338
6338
|
}
|
|
6339
|
-
function
|
|
6339
|
+
function applyDocumentCommand(json, commandInput) {
|
|
6340
6340
|
const document2 = parseDocument(json);
|
|
6341
6341
|
const command = parseCommand2(commandInput);
|
|
6342
6342
|
if (isInlineCommand(command)) {
|
|
@@ -6350,10 +6350,10 @@ function applyDocument2Command(json, commandInput) {
|
|
|
6350
6350
|
} else {
|
|
6351
6351
|
applyBasicCommand(document2, command);
|
|
6352
6352
|
}
|
|
6353
|
-
return
|
|
6353
|
+
return toDocumentJson(document2);
|
|
6354
6354
|
}
|
|
6355
6355
|
|
|
6356
|
-
// src/
|
|
6356
|
+
// src/document/diff.ts
|
|
6357
6357
|
var import_diff = require("diff");
|
|
6358
6358
|
var MAX_TOTAL_TEXT_CHARS = 16e3;
|
|
6359
6359
|
var MAX_CHANGED_CHUNK_CHARS = 4e3;
|
|
@@ -6380,7 +6380,7 @@ function comparisonValue(value, key) {
|
|
|
6380
6380
|
return value;
|
|
6381
6381
|
}
|
|
6382
6382
|
function normalizedComparisonDocument(document2) {
|
|
6383
|
-
return comparisonValue(
|
|
6383
|
+
return comparisonValue(toDocumentJson(fromDocumentJson(document2)));
|
|
6384
6384
|
}
|
|
6385
6385
|
function withoutFinalNewline(value) {
|
|
6386
6386
|
return value.endsWith("\n") ? value.slice(0, -1) : value;
|
|
@@ -6406,7 +6406,7 @@ function shorten(text, limit, mode) {
|
|
|
6406
6406
|
truncated: true
|
|
6407
6407
|
};
|
|
6408
6408
|
}
|
|
6409
|
-
function
|
|
6409
|
+
function diffDocument(before, after) {
|
|
6410
6410
|
const beforeComparable = normalizedComparisonDocument(before);
|
|
6411
6411
|
const afterComparable = normalizedComparisonDocument(after);
|
|
6412
6412
|
const parts = (0, import_diff.diffJson)(beforeComparable, afterComparable);
|
|
@@ -6451,7 +6451,7 @@ function diffDocument2(before, after) {
|
|
|
6451
6451
|
return { version: 1, changed: true, truncated, chunks };
|
|
6452
6452
|
}
|
|
6453
6453
|
|
|
6454
|
-
// src/
|
|
6454
|
+
// src/document/outline.ts
|
|
6455
6455
|
var EXCERPT_LIMIT = 160;
|
|
6456
6456
|
function normalizeExcerpt(value) {
|
|
6457
6457
|
const normalized = value.replace(/\s+/g, " ").trim();
|
|
@@ -6499,21 +6499,21 @@ function blockExcerpt(block) {
|
|
|
6499
6499
|
}
|
|
6500
6500
|
return normalizeExcerpt(block.value ?? "");
|
|
6501
6501
|
}
|
|
6502
|
-
function
|
|
6502
|
+
function documentOutline(json) {
|
|
6503
6503
|
if (!json || json.node_type !== "DocumentObject" || !Array.isArray(json.blocks)) {
|
|
6504
|
-
throw new
|
|
6504
|
+
throw new DocumentCommandError("invalid_document", "DocumentObject requires a blocks array");
|
|
6505
6505
|
}
|
|
6506
6506
|
const usedIds = /* @__PURE__ */ new Set();
|
|
6507
6507
|
return json.blocks.map((block) => {
|
|
6508
6508
|
if (!block || typeof block !== "object" || typeof block.command !== "string") {
|
|
6509
|
-
throw new
|
|
6509
|
+
throw new DocumentCommandError("invalid_document", "Document outline requires blocks with string commands");
|
|
6510
6510
|
}
|
|
6511
6511
|
const id = typeof block.id === "string" ? block.id.trim() : "";
|
|
6512
6512
|
if (id.length === 0) {
|
|
6513
|
-
throw new
|
|
6513
|
+
throw new DocumentCommandError("missing_block_id", "Document outline requires canonical block IDs");
|
|
6514
6514
|
}
|
|
6515
6515
|
if (usedIds.has(id)) {
|
|
6516
|
-
throw new
|
|
6516
|
+
throw new DocumentCommandError("duplicate_block_id", `Duplicate document block ID: ${id}`);
|
|
6517
6517
|
}
|
|
6518
6518
|
usedIds.add(id);
|
|
6519
6519
|
return {
|
|
@@ -6525,7 +6525,7 @@ function document2Outline(json) {
|
|
|
6525
6525
|
});
|
|
6526
6526
|
}
|
|
6527
6527
|
|
|
6528
|
-
// src/
|
|
6528
|
+
// src/document/introspection.ts
|
|
6529
6529
|
function appendUnique(target, seen, values) {
|
|
6530
6530
|
for (const value of values) {
|
|
6531
6531
|
if (!seen.has(value)) {
|
|
@@ -6534,7 +6534,7 @@ function appendUnique(target, seen, values) {
|
|
|
6534
6534
|
}
|
|
6535
6535
|
}
|
|
6536
6536
|
}
|
|
6537
|
-
function
|
|
6537
|
+
function getDocumentReferences(document2) {
|
|
6538
6538
|
return document2.references.map((reference) => ({
|
|
6539
6539
|
key: reference.key,
|
|
6540
6540
|
authors: reference.authors,
|
|
@@ -6545,9 +6545,9 @@ function getDocument2References(document2) {
|
|
|
6545
6545
|
field_separator: reference.fieldSeparator
|
|
6546
6546
|
}));
|
|
6547
6547
|
}
|
|
6548
|
-
function
|
|
6548
|
+
function getDocumentReferenceIndex(document2) {
|
|
6549
6549
|
const referenceKeys = new Set(document2.references.map((reference) => reference.key));
|
|
6550
|
-
const labelEntries =
|
|
6550
|
+
const labelEntries = collectDocumentLabels(document2);
|
|
6551
6551
|
const labelKeys = new Set(labelEntries.map((entry) => entry.key));
|
|
6552
6552
|
const citations = [];
|
|
6553
6553
|
const crossReferences = [];
|
|
@@ -6638,7 +6638,7 @@ function getDocument2ReferenceIndex(document2) {
|
|
|
6638
6638
|
};
|
|
6639
6639
|
}
|
|
6640
6640
|
|
|
6641
|
-
// src/
|
|
6641
|
+
// src/document/arabicPreamble.ts
|
|
6642
6642
|
function fontOptions(digitsMapping, includeScript = true) {
|
|
6643
6643
|
const parts = [];
|
|
6644
6644
|
if (includeScript) {
|
|
@@ -6862,7 +6862,7 @@ function getArabicXeLatexPreamble(digitsMappingOrOptions = "arabicdigits") {
|
|
|
6862
6862
|
return arabicXeLatexPreamblePkg(twocolumn) + arabicXeLatexPreambleFont(digitsMapping) + arabicXeLatexPreambleCmd();
|
|
6863
6863
|
}
|
|
6864
6864
|
|
|
6865
|
-
// src/
|
|
6865
|
+
// src/document/exportLatex.ts
|
|
6866
6866
|
function digitsMappingFromDigitForm(digitForm) {
|
|
6867
6867
|
if (digitForm === "western") {
|
|
6868
6868
|
return "digits";
|
|
@@ -7084,7 +7084,7 @@ function authorLatex(authors) {
|
|
|
7084
7084
|
return authors.split(/\n+/).map((line) => line.trim()).filter((line) => line.length > 0).join(" \\\\ ");
|
|
7085
7085
|
}
|
|
7086
7086
|
function articleMaketitlePreamble(meta, twocolumn = false) {
|
|
7087
|
-
if (!
|
|
7087
|
+
if (!documentHasMaketitle(meta)) {
|
|
7088
7088
|
return "";
|
|
7089
7089
|
}
|
|
7090
7090
|
const parts = [butexBasmalaTitlingPreamble({ twocolumn })];
|
|
@@ -7099,12 +7099,12 @@ function articleMaketitlePreamble(meta, twocolumn = false) {
|
|
|
7099
7099
|
}
|
|
7100
7100
|
function articleFrontMatterLatex(meta) {
|
|
7101
7101
|
const parts = [];
|
|
7102
|
-
if (
|
|
7102
|
+
if (documentHasMaketitle(meta)) {
|
|
7103
7103
|
parts.push("\\maketitle");
|
|
7104
7104
|
} else {
|
|
7105
7105
|
parts.push(butexBasmalaDisplayLatex());
|
|
7106
7106
|
}
|
|
7107
|
-
if (
|
|
7107
|
+
if (documentHasAbstract(meta)) {
|
|
7108
7108
|
parts.push(`\\begin{abstract}
|
|
7109
7109
|
${meta.abstract.trim()}
|
|
7110
7110
|
\\end{abstract}`);
|
|
@@ -7113,7 +7113,7 @@ ${meta.abstract.trim()}
|
|
|
7113
7113
|
}
|
|
7114
7114
|
function documentLabelKindMap(document2) {
|
|
7115
7115
|
const map = /* @__PURE__ */ new Map();
|
|
7116
|
-
for (const entry of
|
|
7116
|
+
for (const entry of collectDocumentLabels(document2)) {
|
|
7117
7117
|
if (!map.has(entry.key)) {
|
|
7118
7118
|
map.set(entry.key, entry.kind);
|
|
7119
7119
|
}
|
|
@@ -7125,8 +7125,8 @@ function closingHamdalaLatex() {
|
|
|
7125
7125
|
\\maghribi{${BUTEX_CLOSING_HAMDALA}}
|
|
7126
7126
|
\\end{center}`;
|
|
7127
7127
|
}
|
|
7128
|
-
function
|
|
7129
|
-
const meta = document2.meta ??
|
|
7128
|
+
function documentLatex(document2, options = {}) {
|
|
7129
|
+
const meta = document2.meta ?? emptyDocumentMeta();
|
|
7130
7130
|
const twocolumn = options.twocolumn === true;
|
|
7131
7131
|
const front = articleFrontMatterLatex(meta);
|
|
7132
7132
|
const labelKinds = documentLabelKindMap(document2);
|
|
@@ -7156,7 +7156,7 @@ ${body}
|
|
|
7156
7156
|
`;
|
|
7157
7157
|
}
|
|
7158
7158
|
|
|
7159
|
-
// src/
|
|
7159
|
+
// src/document/validation.ts
|
|
7160
7160
|
var XELATEX_UNSUPPORTED_EMOJI_PATTERN = /[\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
7161
7161
|
function hasXeLatexUnsupportedEmoji(value) {
|
|
7162
7162
|
return XELATEX_UNSUPPORTED_EMOJI_PATTERN.test(value);
|
|
@@ -7175,12 +7175,12 @@ function validateTextValue(context, value, path, blockId, tokenId) {
|
|
|
7175
7175
|
}
|
|
7176
7176
|
}
|
|
7177
7177
|
function registerKey(context, key, path, kind, blockId, tokenId) {
|
|
7178
|
-
const normalized =
|
|
7178
|
+
const normalized = normalizeDocumentKey(key);
|
|
7179
7179
|
if (normalized.length === 0) {
|
|
7180
7180
|
addIssue(context, "key_empty", path, blockId, tokenId);
|
|
7181
7181
|
return;
|
|
7182
7182
|
}
|
|
7183
|
-
if (!
|
|
7183
|
+
if (!isValidDocumentKey(normalized)) {
|
|
7184
7184
|
addIssue(context, "key_invalid", path, blockId, tokenId);
|
|
7185
7185
|
return;
|
|
7186
7186
|
}
|
|
@@ -7303,7 +7303,7 @@ function validateDuplicateKeys(context) {
|
|
|
7303
7303
|
}
|
|
7304
7304
|
function validatePendingReferences(context) {
|
|
7305
7305
|
for (const pending of context.pendingCitations) {
|
|
7306
|
-
if (pending.token.keys.some((key) => !
|
|
7306
|
+
if (pending.token.keys.some((key) => !isValidDocumentKey(normalizeDocumentKey(key)))) {
|
|
7307
7307
|
addIssue(
|
|
7308
7308
|
context,
|
|
7309
7309
|
"missing_citation",
|
|
@@ -7315,8 +7315,8 @@ function validatePendingReferences(context) {
|
|
|
7315
7315
|
}
|
|
7316
7316
|
for (const pending of context.pendingReferences) {
|
|
7317
7317
|
for (const key of pending.token.keys) {
|
|
7318
|
-
const normalized =
|
|
7319
|
-
if (!
|
|
7318
|
+
const normalized = normalizeDocumentKey(key);
|
|
7319
|
+
if (!isValidDocumentKey(normalized)) {
|
|
7320
7320
|
addIssue(
|
|
7321
7321
|
context,
|
|
7322
7322
|
"missing_reference",
|
|
@@ -7370,7 +7370,7 @@ function hasWireDocumentShape(document2) {
|
|
|
7370
7370
|
function resolveDocument(document2) {
|
|
7371
7371
|
if (hasRuntimeDocumentShape(document2)) {
|
|
7372
7372
|
try {
|
|
7373
|
-
|
|
7373
|
+
toDocumentJson(document2);
|
|
7374
7374
|
return document2;
|
|
7375
7375
|
} catch {
|
|
7376
7376
|
return null;
|
|
@@ -7380,12 +7380,12 @@ function resolveDocument(document2) {
|
|
|
7380
7380
|
return null;
|
|
7381
7381
|
}
|
|
7382
7382
|
try {
|
|
7383
|
-
return
|
|
7383
|
+
return fromDocumentJson(document2);
|
|
7384
7384
|
} catch {
|
|
7385
7385
|
return null;
|
|
7386
7386
|
}
|
|
7387
7387
|
}
|
|
7388
|
-
function
|
|
7388
|
+
function validateDocument(document2) {
|
|
7389
7389
|
const resolved = resolveDocument(document2);
|
|
7390
7390
|
if (!resolved) {
|
|
7391
7391
|
return {
|
|
@@ -7425,25 +7425,25 @@ function validateDocument2(document2) {
|
|
|
7425
7425
|
issues: context.issues
|
|
7426
7426
|
};
|
|
7427
7427
|
}
|
|
7428
|
-
var
|
|
7428
|
+
var DocumentValidationError = class extends Error {
|
|
7429
7429
|
issues;
|
|
7430
7430
|
constructor(issues) {
|
|
7431
|
-
super("
|
|
7432
|
-
this.name = "
|
|
7431
|
+
super("Document validation failed; invalid drafts cannot be exported to LaTeX.");
|
|
7432
|
+
this.name = "DocumentValidationError";
|
|
7433
7433
|
this.issues = issues;
|
|
7434
7434
|
}
|
|
7435
7435
|
};
|
|
7436
7436
|
|
|
7437
|
-
// src/
|
|
7438
|
-
function
|
|
7439
|
-
const validation =
|
|
7437
|
+
// src/document/validatedLatex.ts
|
|
7438
|
+
function documentLatex2(document2, options = {}) {
|
|
7439
|
+
const validation = validateDocument(document2);
|
|
7440
7440
|
if (!validation.valid) {
|
|
7441
|
-
throw new
|
|
7441
|
+
throw new DocumentValidationError(validation.issues);
|
|
7442
7442
|
}
|
|
7443
|
-
return
|
|
7443
|
+
return documentLatex(document2, options);
|
|
7444
7444
|
}
|
|
7445
7445
|
|
|
7446
|
-
// src/
|
|
7446
|
+
// src/document-cli/mathDiagnostic.ts
|
|
7447
7447
|
function compactError(error) {
|
|
7448
7448
|
const message = error instanceof Error ? error.message : String(error);
|
|
7449
7449
|
return message.slice(0, 500);
|
|
@@ -7484,7 +7484,7 @@ function diagnoseMathObject(mathObject) {
|
|
|
7484
7484
|
};
|
|
7485
7485
|
}
|
|
7486
7486
|
|
|
7487
|
-
// src/
|
|
7487
|
+
// src/document-cli/mathProjection.ts
|
|
7488
7488
|
function sourceMode2(value) {
|
|
7489
7489
|
if (typeof value === "object" && value !== null && !Array.isArray(value) && value.source_side === "arabic") {
|
|
7490
7490
|
return "arabic";
|
|
@@ -7496,11 +7496,11 @@ function projectMathObjectToEnglish(mathObject) {
|
|
|
7496
7496
|
try {
|
|
7497
7497
|
math = fromMathObjectJson(mathObject, sourceMode2(mathObject));
|
|
7498
7498
|
} catch {
|
|
7499
|
-
throw new
|
|
7499
|
+
throw new DocumentCommandError("invalid_inline_token", "MathObject JSON is invalid");
|
|
7500
7500
|
}
|
|
7501
7501
|
const sessionResult = mathObjectToEditorSession(math);
|
|
7502
7502
|
if (!sessionResult.editable) {
|
|
7503
|
-
throw new
|
|
7503
|
+
throw new DocumentCommandError("unsupported_inline_content", sessionResult.reason);
|
|
7504
7504
|
}
|
|
7505
7505
|
const projected = mathNodeFromEditorSession(
|
|
7506
7506
|
sessionResult.session,
|
|
@@ -7508,52 +7508,67 @@ function projectMathObjectToEnglish(mathObject) {
|
|
|
7508
7508
|
math.closing
|
|
7509
7509
|
);
|
|
7510
7510
|
if (!projected.ok) {
|
|
7511
|
-
throw new
|
|
7511
|
+
throw new DocumentCommandError("unsupported_inline_content", projected.reason);
|
|
7512
7512
|
}
|
|
7513
7513
|
return toMathObjectJson(projected.math);
|
|
7514
7514
|
}
|
|
7515
7515
|
|
|
7516
|
-
// src/
|
|
7517
|
-
var
|
|
7516
|
+
// src/document-cli/protocol.ts
|
|
7517
|
+
var DOCUMENT_WORKER_ROUTES = {
|
|
7518
|
+
normalize: "/v1/document/normalize",
|
|
7519
|
+
outline: "/v1/document/outline",
|
|
7520
|
+
references: "/v1/document/references",
|
|
7521
|
+
reference_index: "/v1/document/reference-index",
|
|
7522
|
+
export: "/v1/document/export",
|
|
7523
|
+
diff: "/v1/document/diff",
|
|
7524
|
+
apply_command: "/v1/document/commands",
|
|
7525
|
+
diagnose_math_object: "/v1/document/diagnostics/math-object",
|
|
7526
|
+
project_math_object_english: "/v1/document/math-object/english",
|
|
7527
|
+
diagnose_contract: "/v1/document/diagnostics/contract"
|
|
7528
|
+
};
|
|
7529
|
+
var DocumentWorkerProtocolError = class extends Error {
|
|
7518
7530
|
code;
|
|
7519
7531
|
constructor(code, message) {
|
|
7520
7532
|
super(message);
|
|
7521
|
-
this.name = "
|
|
7533
|
+
this.name = "DocumentWorkerProtocolError";
|
|
7522
7534
|
this.code = code;
|
|
7523
7535
|
}
|
|
7524
7536
|
};
|
|
7525
7537
|
function isObject4(value) {
|
|
7526
7538
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7527
7539
|
}
|
|
7528
|
-
function
|
|
7540
|
+
function parseDocumentWorkerRequest(value) {
|
|
7529
7541
|
if (!isObject4(value) || typeof value.action !== "string") {
|
|
7530
|
-
throw new
|
|
7542
|
+
throw new DocumentWorkerProtocolError("invalid_request", "Worker request requires an action");
|
|
7543
|
+
}
|
|
7544
|
+
if (value.action === "diagnose_contract") {
|
|
7545
|
+
return { action: "diagnose_contract" };
|
|
7531
7546
|
}
|
|
7532
7547
|
if (value.action === "diff") {
|
|
7533
7548
|
if (!("before" in value) || !("after" in value)) {
|
|
7534
|
-
throw new
|
|
7549
|
+
throw new DocumentWorkerProtocolError("invalid_request", "diff requires before and after documents");
|
|
7535
7550
|
}
|
|
7536
7551
|
return { action: "diff", before: value.before, after: value.after };
|
|
7537
7552
|
}
|
|
7538
7553
|
if (value.action === "diagnose_math_object" || value.action === "project_math_object_english") {
|
|
7539
7554
|
if (!("math_object" in value)) {
|
|
7540
|
-
throw new
|
|
7555
|
+
throw new DocumentWorkerProtocolError("invalid_request", `${value.action} requires math_object`);
|
|
7541
7556
|
}
|
|
7542
7557
|
return { action: value.action, math_object: value.math_object };
|
|
7543
7558
|
}
|
|
7544
7559
|
if (!("document" in value)) {
|
|
7545
|
-
throw new
|
|
7560
|
+
throw new DocumentWorkerProtocolError("invalid_request", "Worker request requires a document");
|
|
7546
7561
|
}
|
|
7547
7562
|
if (value.action === "normalize" || value.action === "outline" || value.action === "references" || value.action === "reference_index" || value.action === "export") {
|
|
7548
7563
|
return { action: value.action, document: value.document };
|
|
7549
7564
|
}
|
|
7550
7565
|
if (value.action === "apply_command") {
|
|
7551
7566
|
if (!("command" in value)) {
|
|
7552
|
-
throw new
|
|
7567
|
+
throw new DocumentWorkerProtocolError("invalid_request", "apply_command requires command");
|
|
7553
7568
|
}
|
|
7554
7569
|
return { action: value.action, document: value.document, command: value.command };
|
|
7555
7570
|
}
|
|
7556
|
-
throw new
|
|
7571
|
+
throw new DocumentWorkerProtocolError("invalid_request", `Unsupported worker action: ${value.action}`);
|
|
7557
7572
|
}
|
|
7558
7573
|
function boundedValidationIssues(issues) {
|
|
7559
7574
|
return issues.slice(0, 100).map((issue) => ({
|
|
@@ -7564,7 +7579,7 @@ function boundedValidationIssues(issues) {
|
|
|
7564
7579
|
}));
|
|
7565
7580
|
}
|
|
7566
7581
|
function workerFailure(error) {
|
|
7567
|
-
if (error instanceof
|
|
7582
|
+
if (error instanceof DocumentValidationError) {
|
|
7568
7583
|
return {
|
|
7569
7584
|
response: {
|
|
7570
7585
|
ok: false,
|
|
@@ -7577,13 +7592,13 @@ function workerFailure(error) {
|
|
|
7577
7592
|
status: 422
|
|
7578
7593
|
};
|
|
7579
7594
|
}
|
|
7580
|
-
if (error instanceof
|
|
7595
|
+
if (error instanceof DocumentCommandError) {
|
|
7581
7596
|
return {
|
|
7582
7597
|
response: { ok: false, error: { code: error.code, message: error.message } },
|
|
7583
7598
|
status: 422
|
|
7584
7599
|
};
|
|
7585
7600
|
}
|
|
7586
|
-
if (error instanceof
|
|
7601
|
+
if (error instanceof DocumentWorkerProtocolError) {
|
|
7587
7602
|
let status = 400;
|
|
7588
7603
|
if (error.code === "payload_too_large") {
|
|
7589
7604
|
status = 413;
|
|
@@ -7603,23 +7618,23 @@ function workerFailure(error) {
|
|
|
7603
7618
|
unexpected: error
|
|
7604
7619
|
};
|
|
7605
7620
|
}
|
|
7606
|
-
function
|
|
7621
|
+
function asDocumentJson(value) {
|
|
7607
7622
|
return value;
|
|
7608
7623
|
}
|
|
7609
|
-
function
|
|
7624
|
+
function asDocumentCommand(value) {
|
|
7610
7625
|
return value;
|
|
7611
7626
|
}
|
|
7612
7627
|
|
|
7613
|
-
// src/
|
|
7628
|
+
// src/document-cli/execute.ts
|
|
7614
7629
|
function resolveDocument2(document2) {
|
|
7615
7630
|
try {
|
|
7616
|
-
return
|
|
7631
|
+
return fromDocumentJson(document2);
|
|
7617
7632
|
} catch {
|
|
7618
|
-
throw new
|
|
7633
|
+
throw new DocumentCommandError("invalid_document", "Document JSON is invalid");
|
|
7619
7634
|
}
|
|
7620
7635
|
}
|
|
7621
7636
|
function normalizeDocument(document2) {
|
|
7622
|
-
return
|
|
7637
|
+
return toDocumentJson(resolveDocument2(document2));
|
|
7623
7638
|
}
|
|
7624
7639
|
function collectAssetIds(blocks) {
|
|
7625
7640
|
const assetIds = [];
|
|
@@ -7646,8 +7661,20 @@ function collectAssetIds(blocks) {
|
|
|
7646
7661
|
}
|
|
7647
7662
|
return assetIds;
|
|
7648
7663
|
}
|
|
7649
|
-
function
|
|
7650
|
-
const request =
|
|
7664
|
+
function executeDocumentWorkerRequest(input) {
|
|
7665
|
+
const request = parseDocumentWorkerRequest(input);
|
|
7666
|
+
if (request.action === "diagnose_contract") {
|
|
7667
|
+
return {
|
|
7668
|
+
ok: true,
|
|
7669
|
+
contract: {
|
|
7670
|
+
service: "butex-document",
|
|
7671
|
+
routes: { ...DOCUMENT_WORKER_ROUTES },
|
|
7672
|
+
build_commit: process.env.BUTEX_BUILD_COMMIT_SHA ?? process.env.RAILWAY_GIT_COMMIT_SHA ?? null,
|
|
7673
|
+
package_version: process.env.npm_package_version ?? null,
|
|
7674
|
+
provenance: "runtime_environment_unverified"
|
|
7675
|
+
}
|
|
7676
|
+
};
|
|
7677
|
+
}
|
|
7651
7678
|
if (request.action === "diagnose_math_object") {
|
|
7652
7679
|
return { ok: true, math_diagnostic: diagnoseMathObject(request.math_object) };
|
|
7653
7680
|
}
|
|
@@ -7664,51 +7691,51 @@ function executeDocument2WorkerRequest(input) {
|
|
|
7664
7691
|
try {
|
|
7665
7692
|
return {
|
|
7666
7693
|
ok: true,
|
|
7667
|
-
diff:
|
|
7694
|
+
diff: diffDocument(asDocumentJson(request.before), asDocumentJson(request.after))
|
|
7668
7695
|
};
|
|
7669
7696
|
} catch {
|
|
7670
|
-
throw new
|
|
7697
|
+
throw new DocumentCommandError("invalid_document", "Document JSON is invalid");
|
|
7671
7698
|
}
|
|
7672
7699
|
}
|
|
7673
7700
|
if (request.action === "outline") {
|
|
7674
|
-
return { ok: true, outline:
|
|
7701
|
+
return { ok: true, outline: documentOutline(asDocumentJson(request.document)) };
|
|
7675
7702
|
}
|
|
7676
7703
|
if (request.action === "references") {
|
|
7677
|
-
return { ok: true, references:
|
|
7704
|
+
return { ok: true, references: getDocumentReferences(resolveDocument2(request.document)) };
|
|
7678
7705
|
}
|
|
7679
7706
|
if (request.action === "reference_index") {
|
|
7680
|
-
return { ok: true, reference_index:
|
|
7707
|
+
return { ok: true, reference_index: getDocumentReferenceIndex(resolveDocument2(request.document)) };
|
|
7681
7708
|
}
|
|
7682
7709
|
if (request.action === "export") {
|
|
7683
7710
|
const document2 = resolveDocument2(request.document);
|
|
7684
7711
|
return {
|
|
7685
7712
|
ok: true,
|
|
7686
|
-
latex:
|
|
7713
|
+
latex: documentLatex2(document2, { twocolumn: true }),
|
|
7687
7714
|
asset_ids: collectAssetIds(document2.blocks)
|
|
7688
7715
|
};
|
|
7689
7716
|
}
|
|
7690
7717
|
return {
|
|
7691
7718
|
ok: true,
|
|
7692
|
-
document:
|
|
7719
|
+
document: applyDocumentCommand(asDocumentJson(request.document), asDocumentCommand(request.command))
|
|
7693
7720
|
};
|
|
7694
7721
|
}
|
|
7695
7722
|
|
|
7696
|
-
// src/
|
|
7697
|
-
var
|
|
7723
|
+
// src/document-cli/stdinTransport.ts
|
|
7724
|
+
var DOCUMENT_WORKER_MAX_BODY_BYTES = 5 * 1024 * 1024;
|
|
7698
7725
|
function parseJson(input) {
|
|
7699
7726
|
try {
|
|
7700
7727
|
return JSON.parse(input);
|
|
7701
7728
|
} catch {
|
|
7702
|
-
throw new
|
|
7729
|
+
throw new DocumentWorkerProtocolError("invalid_json", "Input must be valid JSON");
|
|
7703
7730
|
}
|
|
7704
7731
|
}
|
|
7705
|
-
function
|
|
7732
|
+
function executeDocumentStdinText(input) {
|
|
7706
7733
|
try {
|
|
7707
7734
|
const size = Buffer.byteLength(input);
|
|
7708
|
-
if (size >
|
|
7709
|
-
throw new
|
|
7735
|
+
if (size > DOCUMENT_WORKER_MAX_BODY_BYTES) {
|
|
7736
|
+
throw new DocumentWorkerProtocolError("payload_too_large", "Worker request exceeds the 5 MiB limit");
|
|
7710
7737
|
}
|
|
7711
|
-
const response =
|
|
7738
|
+
const response = executeDocumentWorkerRequest(parseJson(input));
|
|
7712
7739
|
return { output: `${JSON.stringify(response)}
|
|
7713
7740
|
`, exitCode: 0 };
|
|
7714
7741
|
} catch (error) {
|
|
@@ -7727,8 +7754,8 @@ async function readAll(stream) {
|
|
|
7727
7754
|
for await (const chunk of stream) {
|
|
7728
7755
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
7729
7756
|
size += buffer.length;
|
|
7730
|
-
if (size >
|
|
7731
|
-
throw new
|
|
7757
|
+
if (size > DOCUMENT_WORKER_MAX_BODY_BYTES) {
|
|
7758
|
+
throw new DocumentWorkerProtocolError("payload_too_large", "Worker request exceeds the 5 MiB limit");
|
|
7732
7759
|
}
|
|
7733
7760
|
chunks.push(buffer);
|
|
7734
7761
|
}
|
|
@@ -7745,10 +7772,10 @@ function write(stream, value) {
|
|
|
7745
7772
|
});
|
|
7746
7773
|
});
|
|
7747
7774
|
}
|
|
7748
|
-
async function
|
|
7775
|
+
async function runDocumentStdin(input, output, errorOutput) {
|
|
7749
7776
|
let result;
|
|
7750
7777
|
try {
|
|
7751
|
-
result =
|
|
7778
|
+
result = executeDocumentStdinText(await readAll(input));
|
|
7752
7779
|
} catch (error) {
|
|
7753
7780
|
const failure = workerFailure(error);
|
|
7754
7781
|
result = {
|
|
@@ -7767,8 +7794,8 @@ async function runDocument2Stdin(input, output, errorOutput) {
|
|
|
7767
7794
|
return result.exitCode;
|
|
7768
7795
|
}
|
|
7769
7796
|
|
|
7770
|
-
// src/
|
|
7771
|
-
var
|
|
7797
|
+
// src/document-cli/httpServer.ts
|
|
7798
|
+
var DOCUMENT_WORKER_REQUEST_TIMEOUT_MS = 15e3;
|
|
7772
7799
|
function sendJson(response, status, body) {
|
|
7773
7800
|
const json = JSON.stringify(body);
|
|
7774
7801
|
response.writeHead(status, {
|
|
@@ -7797,14 +7824,14 @@ async function readJsonBody(request, maxBodyBytes) {
|
|
|
7797
7824
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
|
|
7798
7825
|
size += buffer.length;
|
|
7799
7826
|
if (size > maxBodyBytes) {
|
|
7800
|
-
throw new
|
|
7827
|
+
throw new DocumentWorkerProtocolError("payload_too_large", "Worker request exceeds the 5 MiB limit");
|
|
7801
7828
|
}
|
|
7802
7829
|
chunks.push(buffer);
|
|
7803
7830
|
}
|
|
7804
7831
|
try {
|
|
7805
7832
|
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
7806
7833
|
} catch {
|
|
7807
|
-
throw new
|
|
7834
|
+
throw new DocumentWorkerProtocolError("invalid_json", "Request body must be valid JSON");
|
|
7808
7835
|
}
|
|
7809
7836
|
}
|
|
7810
7837
|
function requestId(request) {
|
|
@@ -7816,31 +7843,34 @@ function traceId(request) {
|
|
|
7816
7843
|
return typeof value === "string" ? value.slice(0, 128) : void 0;
|
|
7817
7844
|
}
|
|
7818
7845
|
function actionForPath(pathname) {
|
|
7819
|
-
if (pathname ===
|
|
7846
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.diagnose_contract) {
|
|
7847
|
+
return "diagnose_contract";
|
|
7848
|
+
}
|
|
7849
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.normalize) {
|
|
7820
7850
|
return "normalize";
|
|
7821
7851
|
}
|
|
7822
|
-
if (pathname ===
|
|
7852
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.outline) {
|
|
7823
7853
|
return "outline";
|
|
7824
7854
|
}
|
|
7825
|
-
if (pathname ===
|
|
7855
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.references) {
|
|
7826
7856
|
return "references";
|
|
7827
7857
|
}
|
|
7828
|
-
if (pathname ===
|
|
7858
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.reference_index) {
|
|
7829
7859
|
return "reference_index";
|
|
7830
7860
|
}
|
|
7831
|
-
if (pathname ===
|
|
7861
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.export) {
|
|
7832
7862
|
return "export";
|
|
7833
7863
|
}
|
|
7834
|
-
if (pathname ===
|
|
7864
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.diff) {
|
|
7835
7865
|
return "diff";
|
|
7836
7866
|
}
|
|
7837
|
-
if (pathname ===
|
|
7867
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.apply_command) {
|
|
7838
7868
|
return "apply_command";
|
|
7839
7869
|
}
|
|
7840
|
-
if (pathname ===
|
|
7870
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.diagnose_math_object) {
|
|
7841
7871
|
return "diagnose_math_object";
|
|
7842
7872
|
}
|
|
7843
|
-
if (pathname ===
|
|
7873
|
+
if (pathname === DOCUMENT_WORKER_ROUTES.project_math_object_english) {
|
|
7844
7874
|
return "project_math_object_english";
|
|
7845
7875
|
}
|
|
7846
7876
|
return null;
|
|
@@ -7856,11 +7886,11 @@ function defaultLogger(entry) {
|
|
|
7856
7886
|
...unexpected !== void 0 ? { unexpected } : {}
|
|
7857
7887
|
}));
|
|
7858
7888
|
}
|
|
7859
|
-
function
|
|
7889
|
+
function createDocumentHttpServer(options) {
|
|
7860
7890
|
if (options.token.length === 0) {
|
|
7861
7891
|
throw new Error("Document worker HTTP mode requires BUTEX_WORKER_TOKEN");
|
|
7862
7892
|
}
|
|
7863
|
-
const maxBodyBytes = options.maxBodyBytes ??
|
|
7893
|
+
const maxBodyBytes = options.maxBodyBytes ?? DOCUMENT_WORKER_MAX_BODY_BYTES;
|
|
7864
7894
|
const logger = options.logger ?? defaultLogger;
|
|
7865
7895
|
const server = (0, import_node_http.createServer)(async (request, response) => {
|
|
7866
7896
|
const startedAt = Date.now();
|
|
@@ -7871,21 +7901,21 @@ function createDocument2HttpServer(options) {
|
|
|
7871
7901
|
try {
|
|
7872
7902
|
if (request.method === "GET" && pathname === "/health") {
|
|
7873
7903
|
status = 200;
|
|
7874
|
-
sendJson(response, status, { ok: true, service: "butex-
|
|
7904
|
+
sendJson(response, status, { ok: true, service: "butex-document" });
|
|
7875
7905
|
return;
|
|
7876
7906
|
}
|
|
7877
7907
|
const action = request.method === "POST" ? actionForPath(pathname) : null;
|
|
7878
7908
|
if (!action) {
|
|
7879
|
-
throw new
|
|
7909
|
+
throw new DocumentWorkerProtocolError("not_found", "Worker endpoint was not found");
|
|
7880
7910
|
}
|
|
7881
7911
|
if (!tokenMatches(options.token, bearerToken(request))) {
|
|
7882
|
-
throw new
|
|
7912
|
+
throw new DocumentWorkerProtocolError("unauthorized", "Worker service token is invalid");
|
|
7883
7913
|
}
|
|
7884
7914
|
const body = await readJsonBody(request, maxBodyBytes);
|
|
7885
7915
|
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
7886
|
-
throw new
|
|
7916
|
+
throw new DocumentWorkerProtocolError("invalid_request", "Request body must be an object");
|
|
7887
7917
|
}
|
|
7888
|
-
const responseBody =
|
|
7918
|
+
const responseBody = executeDocumentWorkerRequest({ ...body, action });
|
|
7889
7919
|
status = 200;
|
|
7890
7920
|
sendJson(response, status, responseBody);
|
|
7891
7921
|
} catch (error) {
|
|
@@ -7908,13 +7938,13 @@ function createDocument2HttpServer(options) {
|
|
|
7908
7938
|
});
|
|
7909
7939
|
}
|
|
7910
7940
|
});
|
|
7911
|
-
server.requestTimeout =
|
|
7912
|
-
server.headersTimeout =
|
|
7941
|
+
server.requestTimeout = DOCUMENT_WORKER_REQUEST_TIMEOUT_MS;
|
|
7942
|
+
server.headersTimeout = DOCUMENT_WORKER_REQUEST_TIMEOUT_MS;
|
|
7913
7943
|
server.keepAliveTimeout = 5e3;
|
|
7914
7944
|
return server;
|
|
7915
7945
|
}
|
|
7916
7946
|
|
|
7917
|
-
// src/
|
|
7947
|
+
// src/document-cli/main.ts
|
|
7918
7948
|
function parseArgs(args) {
|
|
7919
7949
|
const options = { serve: false, host: "127.0.0.1", help: false };
|
|
7920
7950
|
for (let index = 0; index < args.length; index += 1) {
|
|
@@ -7939,8 +7969,8 @@ function parseArgs(args) {
|
|
|
7939
7969
|
function usage() {
|
|
7940
7970
|
return [
|
|
7941
7971
|
"Usage:",
|
|
7942
|
-
" butex-
|
|
7943
|
-
" butex-
|
|
7972
|
+
" butex-document Read one JSON request from stdin",
|
|
7973
|
+
" butex-document --serve [--host] Run the stateless HTTP worker",
|
|
7944
7974
|
"",
|
|
7945
7975
|
"HTTP mode requires BUTEX_WORKER_TOKEN and honors Railway PORT.",
|
|
7946
7976
|
""
|
|
@@ -7982,14 +8012,14 @@ async function main() {
|
|
|
7982
8012
|
return 0;
|
|
7983
8013
|
}
|
|
7984
8014
|
if (!options.serve) {
|
|
7985
|
-
return
|
|
8015
|
+
return runDocumentStdin(process.stdin, process.stdout, process.stderr);
|
|
7986
8016
|
}
|
|
7987
8017
|
const token = process.env.BUTEX_WORKER_TOKEN ?? "";
|
|
7988
8018
|
const port = portFromEnvironment();
|
|
7989
|
-
const server =
|
|
8019
|
+
const server = createDocumentHttpServer({ token });
|
|
7990
8020
|
installShutdownHandlers(server);
|
|
7991
8021
|
await listen(server, port, options.host);
|
|
7992
|
-
console.error(JSON.stringify({ service: "butex-
|
|
8022
|
+
console.error(JSON.stringify({ service: "butex-document", status: "listening", host: options.host, port }));
|
|
7993
8023
|
return 0;
|
|
7994
8024
|
}
|
|
7995
8025
|
main().then((exitCode) => {
|
|
@@ -8000,4 +8030,4 @@ main().then((exitCode) => {
|
|
|
8000
8030
|
`);
|
|
8001
8031
|
process.exitCode = 1;
|
|
8002
8032
|
});
|
|
8003
|
-
//# sourceMappingURL=
|
|
8033
|
+
//# sourceMappingURL=document-cli.js.map
|