@drghaliasri/butex 7.0.4 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document.js +8 -0
- package/dist/document.js.map +1 -1
- package/dist/document.mjs +8 -0
- package/dist/document.mjs.map +1 -1
- package/dist/document2-cli.js +118 -0
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +21 -1
- package/dist/document2.d.ts +21 -1
- package/dist/document2.js +109 -0
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +108 -0
- package/dist/document2.mjs.map +1 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.global.js +8 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react-document.js +8 -0
- package/dist/react-document.js.map +1 -1
- package/dist/react-document.mjs +8 -0
- package/dist/react-document.mjs.map +1 -1
- package/dist/react-document2-preview.js +8 -0
- package/dist/react-document2-preview.js.map +1 -1
- package/dist/react-document2-preview.mjs +8 -0
- package/dist/react-document2-preview.mjs.map +1 -1
- package/dist/react-document2.js +12 -0
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +12 -0
- package/dist/react-document2.mjs.map +1 -1
- package/dist/react.d.mts +8 -0
- package/dist/react.d.ts +8 -0
- package/dist/react.js +8 -0
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +8 -0
- package/dist/react.mjs.map +1 -1
- package/package.json +4 -2
package/dist/document2-cli.js
CHANGED
|
@@ -4485,6 +4485,104 @@ function applyDocument2Command(json, commandInput) {
|
|
|
4485
4485
|
return toDocumentJson2(document2);
|
|
4486
4486
|
}
|
|
4487
4487
|
|
|
4488
|
+
// src/document2/diff.ts
|
|
4489
|
+
var import_diff = require("diff");
|
|
4490
|
+
var MAX_TOTAL_TEXT_CHARS = 16e3;
|
|
4491
|
+
var MAX_CHANGED_CHUNK_CHARS = 4e3;
|
|
4492
|
+
var MAX_CONTEXT_CHUNK_CHARS = 600;
|
|
4493
|
+
var TRUNCATION_MARKER = "\n\u2026\n";
|
|
4494
|
+
var IDENTITY_KEYS = /* @__PURE__ */ new Set(["id", "inline_ids", "caption_inline_ids", "cell_inline_ids"]);
|
|
4495
|
+
function comparisonValue(value, key) {
|
|
4496
|
+
if (key && IDENTITY_KEYS.has(key)) {
|
|
4497
|
+
return void 0;
|
|
4498
|
+
}
|
|
4499
|
+
if (Array.isArray(value)) {
|
|
4500
|
+
return value.map((entry) => comparisonValue(entry));
|
|
4501
|
+
}
|
|
4502
|
+
if (value && typeof value === "object") {
|
|
4503
|
+
const result = {};
|
|
4504
|
+
for (const childKey of Object.keys(value).sort()) {
|
|
4505
|
+
const child = comparisonValue(value[childKey], childKey);
|
|
4506
|
+
if (child !== void 0) {
|
|
4507
|
+
result[childKey] = child;
|
|
4508
|
+
}
|
|
4509
|
+
}
|
|
4510
|
+
return result;
|
|
4511
|
+
}
|
|
4512
|
+
return value;
|
|
4513
|
+
}
|
|
4514
|
+
function normalizedComparisonDocument(document2) {
|
|
4515
|
+
return comparisonValue(toDocumentJson2(fromDocumentJson2(document2)));
|
|
4516
|
+
}
|
|
4517
|
+
function withoutFinalNewline(value) {
|
|
4518
|
+
return value.endsWith("\n") ? value.slice(0, -1) : value;
|
|
4519
|
+
}
|
|
4520
|
+
function shorten(text, limit, mode) {
|
|
4521
|
+
if (text.length <= limit) {
|
|
4522
|
+
return { text, truncated: false };
|
|
4523
|
+
}
|
|
4524
|
+
if (limit <= TRUNCATION_MARKER.length) {
|
|
4525
|
+
return { text: text.slice(0, Math.max(0, limit)), truncated: true };
|
|
4526
|
+
}
|
|
4527
|
+
const available = limit - TRUNCATION_MARKER.length;
|
|
4528
|
+
if (mode === "head") {
|
|
4529
|
+
return { text: `${text.slice(0, available)}${TRUNCATION_MARKER}`, truncated: true };
|
|
4530
|
+
}
|
|
4531
|
+
if (mode === "tail") {
|
|
4532
|
+
return { text: `${TRUNCATION_MARKER}${text.slice(text.length - available)}`, truncated: true };
|
|
4533
|
+
}
|
|
4534
|
+
const head = Math.ceil(available / 2);
|
|
4535
|
+
const tail = available - head;
|
|
4536
|
+
return {
|
|
4537
|
+
text: `${text.slice(0, head)}${TRUNCATION_MARKER}${text.slice(text.length - tail)}`,
|
|
4538
|
+
truncated: true
|
|
4539
|
+
};
|
|
4540
|
+
}
|
|
4541
|
+
function diffDocument2(before, after) {
|
|
4542
|
+
const beforeComparable = normalizedComparisonDocument(before);
|
|
4543
|
+
const afterComparable = normalizedComparisonDocument(after);
|
|
4544
|
+
const parts = (0, import_diff.diffJson)(beforeComparable, afterComparable);
|
|
4545
|
+
const changed = parts.some((part) => part.added === true || part.removed === true);
|
|
4546
|
+
if (!changed) {
|
|
4547
|
+
return { version: 1, changed: false, truncated: false, chunks: [] };
|
|
4548
|
+
}
|
|
4549
|
+
const chunks = [];
|
|
4550
|
+
let truncated = false;
|
|
4551
|
+
let totalTextChars = 0;
|
|
4552
|
+
const append = (kind, rawText, limit, mode) => {
|
|
4553
|
+
const cleaned = withoutFinalNewline(rawText);
|
|
4554
|
+
if (cleaned.length === 0) return;
|
|
4555
|
+
const perChunk = shorten(cleaned, limit, mode);
|
|
4556
|
+
truncated ||= perChunk.truncated;
|
|
4557
|
+
const remaining = MAX_TOTAL_TEXT_CHARS - totalTextChars;
|
|
4558
|
+
if (remaining <= 0) {
|
|
4559
|
+
truncated = true;
|
|
4560
|
+
return;
|
|
4561
|
+
}
|
|
4562
|
+
const withinBudget = shorten(perChunk.text, remaining, mode);
|
|
4563
|
+
truncated ||= withinBudget.truncated;
|
|
4564
|
+
if (withinBudget.text.length === 0) return;
|
|
4565
|
+
chunks.push({ kind, text: withinBudget.text });
|
|
4566
|
+
totalTextChars += withinBudget.text.length;
|
|
4567
|
+
};
|
|
4568
|
+
parts.forEach((part, index) => {
|
|
4569
|
+
if (part.added) {
|
|
4570
|
+
append("added", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
4571
|
+
return;
|
|
4572
|
+
}
|
|
4573
|
+
if (part.removed) {
|
|
4574
|
+
append("removed", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
4575
|
+
return;
|
|
4576
|
+
}
|
|
4577
|
+
const previousChanged = index > 0 && (parts[index - 1]?.added === true || parts[index - 1]?.removed === true);
|
|
4578
|
+
const nextChanged = index + 1 < parts.length && (parts[index + 1]?.added === true || parts[index + 1]?.removed === true);
|
|
4579
|
+
if (!previousChanged && !nextChanged) return;
|
|
4580
|
+
const mode = previousChanged && nextChanged ? "both" : previousChanged ? "head" : "tail";
|
|
4581
|
+
append("context", part.value, MAX_CONTEXT_CHUNK_CHARS, mode);
|
|
4582
|
+
});
|
|
4583
|
+
return { version: 1, changed: true, truncated, chunks };
|
|
4584
|
+
}
|
|
4585
|
+
|
|
4488
4586
|
// src/document2/outline.ts
|
|
4489
4587
|
var EXCERPT_LIMIT = 160;
|
|
4490
4588
|
function normalizeExcerpt(value) {
|
|
@@ -4850,6 +4948,7 @@ ${fontCommands}
|
|
|
4850
4948
|
\newcommand{\arprod}[0]{\text{جـــذ}}
|
|
4851
4949
|
|
|
4852
4950
|
\newcommand{\arlim}[0]{\text{نـــــها}}
|
|
4951
|
+
\newcommand{\ararg}[0]{\text{حج}}
|
|
4853
4952
|
\newcommand{\armax}[0]{\text{أكبر}}
|
|
4854
4953
|
\newcommand{\armin}[0]{\text{أصغر}}
|
|
4855
4954
|
\newcommand{\arsup}[0]{\text{أعلى}}
|
|
@@ -5492,6 +5591,12 @@ function parseDocument2WorkerRequest(value) {
|
|
|
5492
5591
|
if (!isObject4(value) || typeof value.action !== "string") {
|
|
5493
5592
|
throw new Document2WorkerProtocolError("invalid_request", "Worker request requires an action");
|
|
5494
5593
|
}
|
|
5594
|
+
if (value.action === "diff") {
|
|
5595
|
+
if (!("before" in value) || !("after" in value)) {
|
|
5596
|
+
throw new Document2WorkerProtocolError("invalid_request", "diff requires before and after documents");
|
|
5597
|
+
}
|
|
5598
|
+
return { action: "diff", before: value.before, after: value.after };
|
|
5599
|
+
}
|
|
5495
5600
|
if (!("document" in value)) {
|
|
5496
5601
|
throw new Document2WorkerProtocolError("invalid_request", "Worker request requires a document");
|
|
5497
5602
|
}
|
|
@@ -5602,6 +5707,16 @@ function executeDocument2WorkerRequest(input) {
|
|
|
5602
5707
|
if (request.action === "normalize") {
|
|
5603
5708
|
return { ok: true, document: normalizeDocument(request.document) };
|
|
5604
5709
|
}
|
|
5710
|
+
if (request.action === "diff") {
|
|
5711
|
+
try {
|
|
5712
|
+
return {
|
|
5713
|
+
ok: true,
|
|
5714
|
+
diff: diffDocument2(asDocument2Json(request.before), asDocument2Json(request.after))
|
|
5715
|
+
};
|
|
5716
|
+
} catch {
|
|
5717
|
+
throw new Document2CommandError("invalid_document", "Document JSON is invalid");
|
|
5718
|
+
}
|
|
5719
|
+
}
|
|
5605
5720
|
if (request.action === "outline") {
|
|
5606
5721
|
return { ok: true, outline: document2Outline(asDocument2Json(request.document)) };
|
|
5607
5722
|
}
|
|
@@ -5759,6 +5874,9 @@ function actionForPath(pathname) {
|
|
|
5759
5874
|
if (pathname === "/v1/document2/export") {
|
|
5760
5875
|
return "export";
|
|
5761
5876
|
}
|
|
5877
|
+
if (pathname === "/v1/document2/diff") {
|
|
5878
|
+
return "diff";
|
|
5879
|
+
}
|
|
5762
5880
|
if (pathname === "/v1/document2/commands") {
|
|
5763
5881
|
return "apply_command";
|
|
5764
5882
|
}
|