ooxml-core 1.37.1 → 1.38.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 +7 -0
- package/dist/automation/index.cjs +207 -207
- package/dist/automation/index.mjs +207 -207
- package/dist/{chunk-M2DFN3SP.mjs → chunk-XBIZIBTJ.mjs} +507 -10
- package/dist/collab/merge-values.d.ts +14 -0
- package/dist/collab/merge-values.d.ts.map +1 -0
- package/dist/docx/embedded.cjs +476 -474
- package/dist/docx/embedded.mjs +476 -474
- package/dist/docx/index.cjs +1075 -719
- package/dist/docx/index.d.ts +1 -0
- package/dist/docx/index.d.ts.map +1 -1
- package/dist/docx/index.mjs +1075 -720
- package/dist/docx/layout/index.cjs +4 -0
- package/dist/docx/layout/index.mjs +4 -0
- package/dist/docx/load/index.cjs +164 -164
- package/dist/docx/load/index.mjs +164 -164
- package/dist/docx/merge-snapshots.d.ts +9 -0
- package/dist/docx/merge-snapshots.d.ts.map +1 -0
- package/dist/docx/ui/index.cjs +155 -155
- package/dist/docx/ui/index.mjs +155 -155
- package/dist/embedding/index.cjs +207 -0
- package/dist/embedding/index.d.ts +3 -0
- package/dist/embedding/index.d.ts.map +1 -1
- package/dist/embedding/index.mjs +205 -1
- package/dist/embedding/onedrive/client.d.ts +4 -0
- package/dist/embedding/onedrive/client.d.ts.map +1 -0
- package/dist/embedding/onedrive/index.cjs +617 -0
- package/dist/embedding/onedrive/index.d.ts +6 -0
- package/dist/embedding/onedrive/index.d.ts.map +1 -0
- package/dist/embedding/onedrive/index.mjs +611 -0
- package/dist/embedding/onedrive/metadata.d.ts +6 -0
- package/dist/embedding/onedrive/metadata.d.ts.map +1 -0
- package/dist/embedding/onedrive/requests.d.ts +8 -0
- package/dist/embedding/onedrive/requests.d.ts.map +1 -0
- package/dist/embedding/onedrive/session.d.ts +4 -0
- package/dist/embedding/onedrive/session.d.ts.map +1 -0
- package/dist/embedding/onedrive/transport.d.ts +9 -0
- package/dist/embedding/onedrive/transport.d.ts.map +1 -0
- package/dist/embedding/onedrive/types.d.ts +86 -0
- package/dist/embedding/onedrive/types.d.ts.map +1 -0
- package/dist/embedding/onedrive/upload.d.ts +3 -0
- package/dist/embedding/onedrive/upload.d.ts.map +1 -0
- package/dist/embedding/storage-merge.d.ts +8 -0
- package/dist/embedding/storage-merge.d.ts.map +1 -0
- package/dist/embedding/storage-session.d.ts +7 -0
- package/dist/embedding/storage-session.d.ts.map +1 -0
- package/dist/embedding/versioned-storage.d.ts +67 -0
- package/dist/embedding/versioned-storage.d.ts.map +1 -0
- package/dist/index.cjs +1013 -340
- package/dist/index.mjs +1013 -340
- package/dist/opc/index.cjs +680 -216
- package/dist/opc/index.d.ts +1 -0
- package/dist/opc/index.d.ts.map +1 -1
- package/dist/opc/index.mjs +680 -217
- package/dist/opc/merge-snapshots.d.ts +26 -0
- package/dist/opc/merge-snapshots.d.ts.map +1 -0
- package/dist/pptx/automation/index.cjs +20 -6
- package/dist/pptx/automation/index.d.ts +1 -1
- package/dist/pptx/automation/index.mjs +1 -1
- package/dist/pptx/chunks/{index-DC5m1m_8.d.ts → index-bgj0Ztnq.d.ts} +16 -2
- package/dist/pptx/chunks/index-bgj0Ztnq.d.ts.map +1 -0
- package/dist/pptx/cli/index.cjs +20 -6
- package/dist/pptx/converter/index.cjs +7 -0
- package/dist/pptx/editor/render/find-replace.d.ts +1 -1
- package/dist/pptx/index.cjs +1687 -1159
- package/dist/pptx/index.d.ts +2 -2
- package/dist/pptx/index.mjs +1 -1
- package/dist/teams/index.cjs +215 -201
- package/dist/teams/index.mjs +215 -201
- package/dist/text/index.cjs +193 -0
- package/dist/text/index.d.ts +1 -0
- package/dist/text/index.d.ts.map +1 -1
- package/dist/text/index.mjs +193 -1
- package/dist/text/merge-three-way.d.ts +9 -0
- package/dist/text/merge-three-way.d.ts.map +1 -0
- package/dist/visio/collab/index.cjs +226 -7
- package/dist/visio/collab/index.d.ts +1 -0
- package/dist/visio/collab/index.d.ts.map +1 -1
- package/dist/visio/collab/index.mjs +225 -7
- package/dist/visio/collab/merge-snapshots.d.ts +14 -0
- package/dist/visio/collab/merge-snapshots.d.ts.map +1 -0
- package/dist/visio/index.cjs +9 -9
- package/dist/visio/index.mjs +9 -9
- package/dist/visio/ui/index.cjs +9 -9
- package/dist/visio/ui/index.mjs +9 -9
- package/dist/xlsx/collab/index.cjs +49966 -507
- package/dist/xlsx/collab/index.d.ts +1 -0
- package/dist/xlsx/collab/index.d.ts.map +1 -1
- package/dist/xlsx/collab/index.mjs +49961 -507
- package/dist/xlsx/collab/merge-residual.d.ts +16 -0
- package/dist/xlsx/collab/merge-residual.d.ts.map +1 -0
- package/dist/xlsx/collab/merge-snapshots.d.ts +8 -0
- package/dist/xlsx/collab/merge-snapshots.d.ts.map +1 -0
- package/dist/xlsx/index.cjs +202 -202
- package/dist/xlsx/index.mjs +202 -202
- package/dist/xlsx/load/index.cjs +155 -155
- package/dist/xlsx/load/index.mjs +155 -155
- package/dist/xlsx/ui/index.cjs +202 -202
- package/dist/xlsx/ui/index.mjs +202 -202
- package/dist/xml/index.cjs +390 -22
- package/dist/xml/index.d.ts +1 -0
- package/dist/xml/index.d.ts.map +1 -1
- package/dist/xml/index.mjs +390 -23
- package/dist/xml/merge-three-way.d.ts +16 -0
- package/dist/xml/merge-three-way.d.ts.map +1 -0
- package/package.json +6 -1
- package/dist/pptx/chunks/index-DC5m1m_8.d.ts.map +0 -1
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
var xmldom = require('@xmldom/xmldom');
|
|
4
4
|
var fflate = require('fflate');
|
|
5
5
|
|
|
6
|
+
// xml/xml.ts
|
|
7
|
+
|
|
6
8
|
// xml/namespaces.ts
|
|
7
9
|
var NS = {
|
|
8
10
|
/** WordprocessingML main. */
|
|
@@ -13,6 +15,8 @@ var NS = {
|
|
|
13
15
|
cx: "http://schemas.microsoft.com/office/drawing/2014/chartex",
|
|
14
16
|
/** Relationships (`r:id`, `r:embed`). */
|
|
15
17
|
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"};
|
|
18
|
+
|
|
19
|
+
// xml/xml.ts
|
|
16
20
|
var DEFAULT_XML_LIMITS = {
|
|
17
21
|
maxDepth: 512,
|
|
18
22
|
maxNodes: 5e6
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
|
|
2
2
|
import { Inflate } from 'fflate';
|
|
3
3
|
|
|
4
|
+
// xml/xml.ts
|
|
5
|
+
|
|
4
6
|
// xml/namespaces.ts
|
|
5
7
|
var NS = {
|
|
6
8
|
/** WordprocessingML main. */
|
|
@@ -11,6 +13,8 @@ var NS = {
|
|
|
11
13
|
cx: "http://schemas.microsoft.com/office/drawing/2014/chartex",
|
|
12
14
|
/** Relationships (`r:id`, `r:embed`). */
|
|
13
15
|
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"};
|
|
16
|
+
|
|
17
|
+
// xml/xml.ts
|
|
14
18
|
var DEFAULT_XML_LIMITS = {
|
|
15
19
|
maxDepth: 512,
|
|
16
20
|
maxNodes: 5e6
|
package/dist/docx/load/index.cjs
CHANGED
|
@@ -3577,6 +3577,161 @@ var RELATIONSHIP_TYPES = {
|
|
|
3577
3577
|
diagramColors: `${BASE}/diagramColors`,
|
|
3578
3578
|
diagramDrawing: "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing"};
|
|
3579
3579
|
|
|
3580
|
+
// text/text-diff.ts
|
|
3581
|
+
var isLowSurrogate = (text, at) => {
|
|
3582
|
+
const code = text.charCodeAt(at);
|
|
3583
|
+
return code >= 56320 && code <= 57343;
|
|
3584
|
+
};
|
|
3585
|
+
function shortestEdit(n, m, same6, maxEdits) {
|
|
3586
|
+
const max = Math.min(n + m, maxEdits);
|
|
3587
|
+
const offset = max + 1;
|
|
3588
|
+
const v = new Int32Array(2 * max + 3);
|
|
3589
|
+
const trace = [];
|
|
3590
|
+
for (let d = 0; d <= max; d++) {
|
|
3591
|
+
for (let k = -d; k <= d; k += 2) {
|
|
3592
|
+
const down = k === -d || k !== d && v[offset + k - 1] < v[offset + k + 1];
|
|
3593
|
+
let x = down ? v[offset + k + 1] : v[offset + k - 1] + 1;
|
|
3594
|
+
let y = x - k;
|
|
3595
|
+
while (x < n && y < m && same6(x, y)) {
|
|
3596
|
+
x++;
|
|
3597
|
+
y++;
|
|
3598
|
+
}
|
|
3599
|
+
v[offset + k] = x;
|
|
3600
|
+
if (x >= n && y >= m) return backtrack(trace, n, m, d);
|
|
3601
|
+
}
|
|
3602
|
+
trace.push(v.slice(offset - d, offset + d + 1));
|
|
3603
|
+
}
|
|
3604
|
+
return void 0;
|
|
3605
|
+
}
|
|
3606
|
+
function backtrack(trace, n, m, d) {
|
|
3607
|
+
const edits = [];
|
|
3608
|
+
let x = n;
|
|
3609
|
+
let y = m;
|
|
3610
|
+
for (let step = d; step > 0; step--) {
|
|
3611
|
+
const previous = trace[step - 1];
|
|
3612
|
+
const at = (k2) => previous[k2 + step - 1];
|
|
3613
|
+
const k = x - y;
|
|
3614
|
+
const down = k === -step || k !== step && at(k - 1) < at(k + 1);
|
|
3615
|
+
const before = down ? k + 1 : k - 1;
|
|
3616
|
+
const startX = at(before);
|
|
3617
|
+
const startY = startX - before;
|
|
3618
|
+
edits.push(down ? [startX, startY, true] : [startX, startY, false]);
|
|
3619
|
+
x = startX;
|
|
3620
|
+
y = startY;
|
|
3621
|
+
}
|
|
3622
|
+
return edits.reverse();
|
|
3623
|
+
}
|
|
3624
|
+
function changesOf(edits) {
|
|
3625
|
+
const changes = [];
|
|
3626
|
+
for (const [x, y, inserts] of edits) {
|
|
3627
|
+
const last = changes.at(-1);
|
|
3628
|
+
if (last && last.fromEnd === x && last.toEnd === y) {
|
|
3629
|
+
if (inserts) last.toEnd++;
|
|
3630
|
+
else last.fromEnd++;
|
|
3631
|
+
} else
|
|
3632
|
+
changes.push({
|
|
3633
|
+
fromStart: x,
|
|
3634
|
+
fromEnd: inserts ? x : x + 1,
|
|
3635
|
+
toStart: y,
|
|
3636
|
+
toEnd: inserts ? y + 1 : y
|
|
3637
|
+
});
|
|
3638
|
+
}
|
|
3639
|
+
return changes;
|
|
3640
|
+
}
|
|
3641
|
+
function characterChanges(a2, b, maxEdits) {
|
|
3642
|
+
const edits = shortestEdit(
|
|
3643
|
+
a2.length,
|
|
3644
|
+
b.length,
|
|
3645
|
+
(x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
|
|
3646
|
+
maxEdits
|
|
3647
|
+
);
|
|
3648
|
+
return edits && changesOf(edits);
|
|
3649
|
+
}
|
|
3650
|
+
var TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
|
|
3651
|
+
function tokensOf(text, ids) {
|
|
3652
|
+
const tokens = [];
|
|
3653
|
+
const starts = [];
|
|
3654
|
+
for (const match of text.matchAll(TOKEN)) {
|
|
3655
|
+
let id = ids.get(match[0]);
|
|
3656
|
+
if (id === void 0) ids.set(match[0], id = ids.size);
|
|
3657
|
+
tokens.push(id);
|
|
3658
|
+
starts.push(match.index);
|
|
3659
|
+
}
|
|
3660
|
+
starts.push(text.length);
|
|
3661
|
+
return { tokens, starts };
|
|
3662
|
+
}
|
|
3663
|
+
function tokenChanges(a2, b, maxEdits) {
|
|
3664
|
+
const ids = /* @__PURE__ */ new Map();
|
|
3665
|
+
const from = tokensOf(a2, ids);
|
|
3666
|
+
const to = tokensOf(b, ids);
|
|
3667
|
+
const edits = shortestEdit(
|
|
3668
|
+
from.tokens.length,
|
|
3669
|
+
to.tokens.length,
|
|
3670
|
+
(x, y) => from.tokens[x] === to.tokens[y],
|
|
3671
|
+
maxEdits
|
|
3672
|
+
);
|
|
3673
|
+
if (!edits) return void 0;
|
|
3674
|
+
let budget = maxEdits;
|
|
3675
|
+
return changesOf(edits).flatMap((stretch) => {
|
|
3676
|
+
const change = {
|
|
3677
|
+
fromStart: from.starts[stretch.fromStart],
|
|
3678
|
+
fromEnd: from.starts[stretch.fromEnd],
|
|
3679
|
+
toStart: to.starts[stretch.toStart],
|
|
3680
|
+
toEnd: to.starts[stretch.toEnd]
|
|
3681
|
+
};
|
|
3682
|
+
const inner = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
|
|
3683
|
+
a2.slice(change.fromStart, change.fromEnd),
|
|
3684
|
+
b.slice(change.toStart, change.toEnd),
|
|
3685
|
+
budget
|
|
3686
|
+
) : void 0;
|
|
3687
|
+
if (!inner) return [change];
|
|
3688
|
+
for (const found of inner)
|
|
3689
|
+
budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
|
|
3690
|
+
return inner.map((found) => ({
|
|
3691
|
+
fromStart: found.fromStart + change.fromStart,
|
|
3692
|
+
fromEnd: found.fromEnd + change.fromStart,
|
|
3693
|
+
toStart: found.toStart + change.toStart,
|
|
3694
|
+
toEnd: found.toEnd + change.toStart
|
|
3695
|
+
}));
|
|
3696
|
+
});
|
|
3697
|
+
}
|
|
3698
|
+
function diffText(from, to, maxEdits = 500) {
|
|
3699
|
+
let start = 0;
|
|
3700
|
+
while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
|
|
3701
|
+
start++;
|
|
3702
|
+
let end = 0;
|
|
3703
|
+
while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
|
|
3704
|
+
end++;
|
|
3705
|
+
const a2 = from.slice(start, from.length - end);
|
|
3706
|
+
const b = to.slice(start, to.length - end);
|
|
3707
|
+
if (!a2.length && !b.length) return [];
|
|
3708
|
+
const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
|
|
3709
|
+
const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
|
|
3710
|
+
const result = [];
|
|
3711
|
+
for (const change of changes) {
|
|
3712
|
+
const placed = {
|
|
3713
|
+
fromStart: change.fromStart + start,
|
|
3714
|
+
fromEnd: change.fromEnd + start,
|
|
3715
|
+
toStart: change.toStart + start,
|
|
3716
|
+
toEnd: change.toEnd + start
|
|
3717
|
+
};
|
|
3718
|
+
if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
|
|
3719
|
+
placed.fromStart--;
|
|
3720
|
+
placed.toStart--;
|
|
3721
|
+
}
|
|
3722
|
+
if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
|
|
3723
|
+
placed.fromEnd++;
|
|
3724
|
+
placed.toEnd++;
|
|
3725
|
+
}
|
|
3726
|
+
const last = result.at(-1);
|
|
3727
|
+
if (last && placed.fromStart <= last.fromEnd) {
|
|
3728
|
+
last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
|
|
3729
|
+
last.toEnd = Math.max(last.toEnd, placed.toEnd);
|
|
3730
|
+
} else result.push(placed);
|
|
3731
|
+
}
|
|
3732
|
+
return result;
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3580
3735
|
// opc/relationships.ts
|
|
3581
3736
|
function parseRelationships(xml) {
|
|
3582
3737
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -3713,15 +3868,6 @@ async function ensureRelationship(zip, relsPath, type, target) {
|
|
|
3713
3868
|
zip.file(relsPath, xml.replace("</Relationships>", `${insertion}</Relationships>`));
|
|
3714
3869
|
return id;
|
|
3715
3870
|
}
|
|
3716
|
-
|
|
3717
|
-
// opc/safe-href.ts
|
|
3718
|
-
var SAFE_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
|
|
3719
|
-
function isSafeHyperlinkHref(href) {
|
|
3720
|
-
const scheme2 = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
|
|
3721
|
-
return scheme2 !== void 0 && SAFE_SCHEMES.has(scheme2.toLowerCase());
|
|
3722
|
-
}
|
|
3723
|
-
var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
|
|
3724
|
-
/* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
|
|
3725
3871
|
var DEFAULT_ZIP_LIMITS = {
|
|
3726
3872
|
maxInputBytes: 100 * 1024 * 1024,
|
|
3727
3873
|
maxEntries: 1e4,
|
|
@@ -3944,6 +4090,15 @@ async function openZip(input, limits = {}) {
|
|
|
3944
4090
|
return guardZip(await JSZip__default.default.loadAsync(bytes), limits);
|
|
3945
4091
|
}
|
|
3946
4092
|
|
|
4093
|
+
// opc/safe-href.ts
|
|
4094
|
+
var SAFE_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
|
|
4095
|
+
function isSafeHyperlinkHref(href) {
|
|
4096
|
+
const scheme2 = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
|
|
4097
|
+
return scheme2 !== void 0 && SAFE_SCHEMES.has(scheme2.toLowerCase());
|
|
4098
|
+
}
|
|
4099
|
+
var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
|
|
4100
|
+
/* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
|
|
4101
|
+
|
|
3947
4102
|
// opc/properties/patch.ts
|
|
3948
4103
|
var XMLNS = "http://www.w3.org/2000/xmlns/";
|
|
3949
4104
|
function tagEnd(xml, from) {
|
|
@@ -6346,161 +6501,6 @@ function patchCommentMetadata(parts, identities) {
|
|
|
6346
6501
|
return result;
|
|
6347
6502
|
}
|
|
6348
6503
|
|
|
6349
|
-
// text/text-diff.ts
|
|
6350
|
-
var isLowSurrogate = (text, at) => {
|
|
6351
|
-
const code = text.charCodeAt(at);
|
|
6352
|
-
return code >= 56320 && code <= 57343;
|
|
6353
|
-
};
|
|
6354
|
-
function shortestEdit(n, m, same6, maxEdits) {
|
|
6355
|
-
const max = Math.min(n + m, maxEdits);
|
|
6356
|
-
const offset = max + 1;
|
|
6357
|
-
const v = new Int32Array(2 * max + 3);
|
|
6358
|
-
const trace = [];
|
|
6359
|
-
for (let d = 0; d <= max; d++) {
|
|
6360
|
-
for (let k = -d; k <= d; k += 2) {
|
|
6361
|
-
const down = k === -d || k !== d && v[offset + k - 1] < v[offset + k + 1];
|
|
6362
|
-
let x = down ? v[offset + k + 1] : v[offset + k - 1] + 1;
|
|
6363
|
-
let y = x - k;
|
|
6364
|
-
while (x < n && y < m && same6(x, y)) {
|
|
6365
|
-
x++;
|
|
6366
|
-
y++;
|
|
6367
|
-
}
|
|
6368
|
-
v[offset + k] = x;
|
|
6369
|
-
if (x >= n && y >= m) return backtrack(trace, n, m, d);
|
|
6370
|
-
}
|
|
6371
|
-
trace.push(v.slice(offset - d, offset + d + 1));
|
|
6372
|
-
}
|
|
6373
|
-
return void 0;
|
|
6374
|
-
}
|
|
6375
|
-
function backtrack(trace, n, m, d) {
|
|
6376
|
-
const edits = [];
|
|
6377
|
-
let x = n;
|
|
6378
|
-
let y = m;
|
|
6379
|
-
for (let step = d; step > 0; step--) {
|
|
6380
|
-
const previous = trace[step - 1];
|
|
6381
|
-
const at = (k2) => previous[k2 + step - 1];
|
|
6382
|
-
const k = x - y;
|
|
6383
|
-
const down = k === -step || k !== step && at(k - 1) < at(k + 1);
|
|
6384
|
-
const before = down ? k + 1 : k - 1;
|
|
6385
|
-
const startX = at(before);
|
|
6386
|
-
const startY = startX - before;
|
|
6387
|
-
edits.push(down ? [startX, startY, true] : [startX, startY, false]);
|
|
6388
|
-
x = startX;
|
|
6389
|
-
y = startY;
|
|
6390
|
-
}
|
|
6391
|
-
return edits.reverse();
|
|
6392
|
-
}
|
|
6393
|
-
function changesOf(edits) {
|
|
6394
|
-
const changes = [];
|
|
6395
|
-
for (const [x, y, inserts] of edits) {
|
|
6396
|
-
const last = changes.at(-1);
|
|
6397
|
-
if (last && last.fromEnd === x && last.toEnd === y) {
|
|
6398
|
-
if (inserts) last.toEnd++;
|
|
6399
|
-
else last.fromEnd++;
|
|
6400
|
-
} else
|
|
6401
|
-
changes.push({
|
|
6402
|
-
fromStart: x,
|
|
6403
|
-
fromEnd: inserts ? x : x + 1,
|
|
6404
|
-
toStart: y,
|
|
6405
|
-
toEnd: inserts ? y + 1 : y
|
|
6406
|
-
});
|
|
6407
|
-
}
|
|
6408
|
-
return changes;
|
|
6409
|
-
}
|
|
6410
|
-
function characterChanges(a2, b, maxEdits) {
|
|
6411
|
-
const edits = shortestEdit(
|
|
6412
|
-
a2.length,
|
|
6413
|
-
b.length,
|
|
6414
|
-
(x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
|
|
6415
|
-
maxEdits
|
|
6416
|
-
);
|
|
6417
|
-
return edits && changesOf(edits);
|
|
6418
|
-
}
|
|
6419
|
-
var TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
|
|
6420
|
-
function tokensOf(text, ids) {
|
|
6421
|
-
const tokens = [];
|
|
6422
|
-
const starts = [];
|
|
6423
|
-
for (const match of text.matchAll(TOKEN)) {
|
|
6424
|
-
let id = ids.get(match[0]);
|
|
6425
|
-
if (id === void 0) ids.set(match[0], id = ids.size);
|
|
6426
|
-
tokens.push(id);
|
|
6427
|
-
starts.push(match.index);
|
|
6428
|
-
}
|
|
6429
|
-
starts.push(text.length);
|
|
6430
|
-
return { tokens, starts };
|
|
6431
|
-
}
|
|
6432
|
-
function tokenChanges(a2, b, maxEdits) {
|
|
6433
|
-
const ids = /* @__PURE__ */ new Map();
|
|
6434
|
-
const from = tokensOf(a2, ids);
|
|
6435
|
-
const to = tokensOf(b, ids);
|
|
6436
|
-
const edits = shortestEdit(
|
|
6437
|
-
from.tokens.length,
|
|
6438
|
-
to.tokens.length,
|
|
6439
|
-
(x, y) => from.tokens[x] === to.tokens[y],
|
|
6440
|
-
maxEdits
|
|
6441
|
-
);
|
|
6442
|
-
if (!edits) return void 0;
|
|
6443
|
-
let budget = maxEdits;
|
|
6444
|
-
return changesOf(edits).flatMap((stretch) => {
|
|
6445
|
-
const change = {
|
|
6446
|
-
fromStart: from.starts[stretch.fromStart],
|
|
6447
|
-
fromEnd: from.starts[stretch.fromEnd],
|
|
6448
|
-
toStart: to.starts[stretch.toStart],
|
|
6449
|
-
toEnd: to.starts[stretch.toEnd]
|
|
6450
|
-
};
|
|
6451
|
-
const inner = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
|
|
6452
|
-
a2.slice(change.fromStart, change.fromEnd),
|
|
6453
|
-
b.slice(change.toStart, change.toEnd),
|
|
6454
|
-
budget
|
|
6455
|
-
) : void 0;
|
|
6456
|
-
if (!inner) return [change];
|
|
6457
|
-
for (const found of inner)
|
|
6458
|
-
budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
|
|
6459
|
-
return inner.map((found) => ({
|
|
6460
|
-
fromStart: found.fromStart + change.fromStart,
|
|
6461
|
-
fromEnd: found.fromEnd + change.fromStart,
|
|
6462
|
-
toStart: found.toStart + change.toStart,
|
|
6463
|
-
toEnd: found.toEnd + change.toStart
|
|
6464
|
-
}));
|
|
6465
|
-
});
|
|
6466
|
-
}
|
|
6467
|
-
function diffText(from, to, maxEdits = 500) {
|
|
6468
|
-
let start = 0;
|
|
6469
|
-
while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
|
|
6470
|
-
start++;
|
|
6471
|
-
let end = 0;
|
|
6472
|
-
while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
|
|
6473
|
-
end++;
|
|
6474
|
-
const a2 = from.slice(start, from.length - end);
|
|
6475
|
-
const b = to.slice(start, to.length - end);
|
|
6476
|
-
if (!a2.length && !b.length) return [];
|
|
6477
|
-
const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
|
|
6478
|
-
const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
|
|
6479
|
-
const result = [];
|
|
6480
|
-
for (const change of changes) {
|
|
6481
|
-
const placed = {
|
|
6482
|
-
fromStart: change.fromStart + start,
|
|
6483
|
-
fromEnd: change.fromEnd + start,
|
|
6484
|
-
toStart: change.toStart + start,
|
|
6485
|
-
toEnd: change.toEnd + start
|
|
6486
|
-
};
|
|
6487
|
-
if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
|
|
6488
|
-
placed.fromStart--;
|
|
6489
|
-
placed.toStart--;
|
|
6490
|
-
}
|
|
6491
|
-
if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
|
|
6492
|
-
placed.fromEnd++;
|
|
6493
|
-
placed.toEnd++;
|
|
6494
|
-
}
|
|
6495
|
-
const last = result.at(-1);
|
|
6496
|
-
if (last && placed.fromStart <= last.fromEnd) {
|
|
6497
|
-
last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
|
|
6498
|
-
last.toEnd = Math.max(last.toEnd, placed.toEnd);
|
|
6499
|
-
} else result.push(placed);
|
|
6500
|
-
}
|
|
6501
|
-
return result;
|
|
6502
|
-
}
|
|
6503
|
-
|
|
6504
6504
|
// color/color-primitives.ts
|
|
6505
6505
|
function clampUnitInterval(value) {
|
|
6506
6506
|
return Math.min(1, Math.max(0, value));
|