@drghaliasri/butex 7.0.4 → 7.1.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/dist/document2-cli.js +117 -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 +100 -0
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +99 -0
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2.js +3 -0
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +3 -0
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +4 -2
package/dist/document2.mjs
CHANGED
|
@@ -7073,6 +7073,104 @@ function applyDocument2Command(json, commandInput) {
|
|
|
7073
7073
|
return toDocumentJson2(document2);
|
|
7074
7074
|
}
|
|
7075
7075
|
|
|
7076
|
+
// src/document2/diff.ts
|
|
7077
|
+
import { diffJson } from "diff";
|
|
7078
|
+
var MAX_TOTAL_TEXT_CHARS = 16e3;
|
|
7079
|
+
var MAX_CHANGED_CHUNK_CHARS = 4e3;
|
|
7080
|
+
var MAX_CONTEXT_CHUNK_CHARS = 600;
|
|
7081
|
+
var TRUNCATION_MARKER = "\n\u2026\n";
|
|
7082
|
+
var IDENTITY_KEYS = /* @__PURE__ */ new Set(["id", "inline_ids", "caption_inline_ids", "cell_inline_ids"]);
|
|
7083
|
+
function comparisonValue(value, key) {
|
|
7084
|
+
if (key && IDENTITY_KEYS.has(key)) {
|
|
7085
|
+
return void 0;
|
|
7086
|
+
}
|
|
7087
|
+
if (Array.isArray(value)) {
|
|
7088
|
+
return value.map((entry) => comparisonValue(entry));
|
|
7089
|
+
}
|
|
7090
|
+
if (value && typeof value === "object") {
|
|
7091
|
+
const result = {};
|
|
7092
|
+
for (const childKey of Object.keys(value).sort()) {
|
|
7093
|
+
const child = comparisonValue(value[childKey], childKey);
|
|
7094
|
+
if (child !== void 0) {
|
|
7095
|
+
result[childKey] = child;
|
|
7096
|
+
}
|
|
7097
|
+
}
|
|
7098
|
+
return result;
|
|
7099
|
+
}
|
|
7100
|
+
return value;
|
|
7101
|
+
}
|
|
7102
|
+
function normalizedComparisonDocument(document2) {
|
|
7103
|
+
return comparisonValue(toDocumentJson2(fromDocumentJson2(document2)));
|
|
7104
|
+
}
|
|
7105
|
+
function withoutFinalNewline(value) {
|
|
7106
|
+
return value.endsWith("\n") ? value.slice(0, -1) : value;
|
|
7107
|
+
}
|
|
7108
|
+
function shorten(text, limit, mode) {
|
|
7109
|
+
if (text.length <= limit) {
|
|
7110
|
+
return { text, truncated: false };
|
|
7111
|
+
}
|
|
7112
|
+
if (limit <= TRUNCATION_MARKER.length) {
|
|
7113
|
+
return { text: text.slice(0, Math.max(0, limit)), truncated: true };
|
|
7114
|
+
}
|
|
7115
|
+
const available = limit - TRUNCATION_MARKER.length;
|
|
7116
|
+
if (mode === "head") {
|
|
7117
|
+
return { text: `${text.slice(0, available)}${TRUNCATION_MARKER}`, truncated: true };
|
|
7118
|
+
}
|
|
7119
|
+
if (mode === "tail") {
|
|
7120
|
+
return { text: `${TRUNCATION_MARKER}${text.slice(text.length - available)}`, truncated: true };
|
|
7121
|
+
}
|
|
7122
|
+
const head = Math.ceil(available / 2);
|
|
7123
|
+
const tail = available - head;
|
|
7124
|
+
return {
|
|
7125
|
+
text: `${text.slice(0, head)}${TRUNCATION_MARKER}${text.slice(text.length - tail)}`,
|
|
7126
|
+
truncated: true
|
|
7127
|
+
};
|
|
7128
|
+
}
|
|
7129
|
+
function diffDocument2(before, after) {
|
|
7130
|
+
const beforeComparable = normalizedComparisonDocument(before);
|
|
7131
|
+
const afterComparable = normalizedComparisonDocument(after);
|
|
7132
|
+
const parts = diffJson(beforeComparable, afterComparable);
|
|
7133
|
+
const changed = parts.some((part) => part.added === true || part.removed === true);
|
|
7134
|
+
if (!changed) {
|
|
7135
|
+
return { version: 1, changed: false, truncated: false, chunks: [] };
|
|
7136
|
+
}
|
|
7137
|
+
const chunks = [];
|
|
7138
|
+
let truncated = false;
|
|
7139
|
+
let totalTextChars = 0;
|
|
7140
|
+
const append = (kind, rawText, limit, mode) => {
|
|
7141
|
+
const cleaned = withoutFinalNewline(rawText);
|
|
7142
|
+
if (cleaned.length === 0) return;
|
|
7143
|
+
const perChunk = shorten(cleaned, limit, mode);
|
|
7144
|
+
truncated ||= perChunk.truncated;
|
|
7145
|
+
const remaining = MAX_TOTAL_TEXT_CHARS - totalTextChars;
|
|
7146
|
+
if (remaining <= 0) {
|
|
7147
|
+
truncated = true;
|
|
7148
|
+
return;
|
|
7149
|
+
}
|
|
7150
|
+
const withinBudget = shorten(perChunk.text, remaining, mode);
|
|
7151
|
+
truncated ||= withinBudget.truncated;
|
|
7152
|
+
if (withinBudget.text.length === 0) return;
|
|
7153
|
+
chunks.push({ kind, text: withinBudget.text });
|
|
7154
|
+
totalTextChars += withinBudget.text.length;
|
|
7155
|
+
};
|
|
7156
|
+
parts.forEach((part, index) => {
|
|
7157
|
+
if (part.added) {
|
|
7158
|
+
append("added", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
7159
|
+
return;
|
|
7160
|
+
}
|
|
7161
|
+
if (part.removed) {
|
|
7162
|
+
append("removed", part.value, MAX_CHANGED_CHUNK_CHARS, "both");
|
|
7163
|
+
return;
|
|
7164
|
+
}
|
|
7165
|
+
const previousChanged = index > 0 && (parts[index - 1]?.added === true || parts[index - 1]?.removed === true);
|
|
7166
|
+
const nextChanged = index + 1 < parts.length && (parts[index + 1]?.added === true || parts[index + 1]?.removed === true);
|
|
7167
|
+
if (!previousChanged && !nextChanged) return;
|
|
7168
|
+
const mode = previousChanged && nextChanged ? "both" : previousChanged ? "head" : "tail";
|
|
7169
|
+
append("context", part.value, MAX_CONTEXT_CHUNK_CHARS, mode);
|
|
7170
|
+
});
|
|
7171
|
+
return { version: 1, changed: true, truncated, chunks };
|
|
7172
|
+
}
|
|
7173
|
+
|
|
7076
7174
|
// src/document2/outline.ts
|
|
7077
7175
|
var EXCERPT_LIMIT = 160;
|
|
7078
7176
|
function normalizeExcerpt(value) {
|
|
@@ -8404,6 +8502,7 @@ export {
|
|
|
8404
8502
|
defaultFloatMeta,
|
|
8405
8503
|
detectInlineSpans2,
|
|
8406
8504
|
detectMathSpans2,
|
|
8505
|
+
diffDocument2,
|
|
8407
8506
|
document2HasAbstract,
|
|
8408
8507
|
document2HasMaketitle,
|
|
8409
8508
|
document2HasTitleStack,
|