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.
Files changed (107) hide show
  1. package/README.md +7 -0
  2. package/dist/automation/index.cjs +207 -207
  3. package/dist/automation/index.mjs +207 -207
  4. package/dist/{chunk-M2DFN3SP.mjs → chunk-XBIZIBTJ.mjs} +507 -10
  5. package/dist/collab/merge-values.d.ts +14 -0
  6. package/dist/collab/merge-values.d.ts.map +1 -0
  7. package/dist/docx/embedded.cjs +476 -474
  8. package/dist/docx/embedded.mjs +476 -474
  9. package/dist/docx/index.cjs +1075 -719
  10. package/dist/docx/index.d.ts +1 -0
  11. package/dist/docx/index.d.ts.map +1 -1
  12. package/dist/docx/index.mjs +1075 -720
  13. package/dist/docx/layout/index.cjs +4 -0
  14. package/dist/docx/layout/index.mjs +4 -0
  15. package/dist/docx/load/index.cjs +164 -164
  16. package/dist/docx/load/index.mjs +164 -164
  17. package/dist/docx/merge-snapshots.d.ts +9 -0
  18. package/dist/docx/merge-snapshots.d.ts.map +1 -0
  19. package/dist/docx/ui/index.cjs +155 -155
  20. package/dist/docx/ui/index.mjs +155 -155
  21. package/dist/embedding/index.cjs +207 -0
  22. package/dist/embedding/index.d.ts +3 -0
  23. package/dist/embedding/index.d.ts.map +1 -1
  24. package/dist/embedding/index.mjs +205 -1
  25. package/dist/embedding/onedrive/client.d.ts +4 -0
  26. package/dist/embedding/onedrive/client.d.ts.map +1 -0
  27. package/dist/embedding/onedrive/index.cjs +617 -0
  28. package/dist/embedding/onedrive/index.d.ts +6 -0
  29. package/dist/embedding/onedrive/index.d.ts.map +1 -0
  30. package/dist/embedding/onedrive/index.mjs +611 -0
  31. package/dist/embedding/onedrive/metadata.d.ts +6 -0
  32. package/dist/embedding/onedrive/metadata.d.ts.map +1 -0
  33. package/dist/embedding/onedrive/requests.d.ts +8 -0
  34. package/dist/embedding/onedrive/requests.d.ts.map +1 -0
  35. package/dist/embedding/onedrive/session.d.ts +4 -0
  36. package/dist/embedding/onedrive/session.d.ts.map +1 -0
  37. package/dist/embedding/onedrive/transport.d.ts +9 -0
  38. package/dist/embedding/onedrive/transport.d.ts.map +1 -0
  39. package/dist/embedding/onedrive/types.d.ts +86 -0
  40. package/dist/embedding/onedrive/types.d.ts.map +1 -0
  41. package/dist/embedding/onedrive/upload.d.ts +3 -0
  42. package/dist/embedding/onedrive/upload.d.ts.map +1 -0
  43. package/dist/embedding/storage-merge.d.ts +8 -0
  44. package/dist/embedding/storage-merge.d.ts.map +1 -0
  45. package/dist/embedding/storage-session.d.ts +7 -0
  46. package/dist/embedding/storage-session.d.ts.map +1 -0
  47. package/dist/embedding/versioned-storage.d.ts +67 -0
  48. package/dist/embedding/versioned-storage.d.ts.map +1 -0
  49. package/dist/index.cjs +1013 -340
  50. package/dist/index.mjs +1013 -340
  51. package/dist/opc/index.cjs +680 -216
  52. package/dist/opc/index.d.ts +1 -0
  53. package/dist/opc/index.d.ts.map +1 -1
  54. package/dist/opc/index.mjs +680 -217
  55. package/dist/opc/merge-snapshots.d.ts +26 -0
  56. package/dist/opc/merge-snapshots.d.ts.map +1 -0
  57. package/dist/pptx/automation/index.cjs +20 -6
  58. package/dist/pptx/automation/index.d.ts +1 -1
  59. package/dist/pptx/automation/index.mjs +1 -1
  60. package/dist/pptx/chunks/{index-DC5m1m_8.d.ts → index-bgj0Ztnq.d.ts} +16 -2
  61. package/dist/pptx/chunks/index-bgj0Ztnq.d.ts.map +1 -0
  62. package/dist/pptx/cli/index.cjs +20 -6
  63. package/dist/pptx/converter/index.cjs +7 -0
  64. package/dist/pptx/editor/render/find-replace.d.ts +1 -1
  65. package/dist/pptx/index.cjs +1687 -1159
  66. package/dist/pptx/index.d.ts +2 -2
  67. package/dist/pptx/index.mjs +1 -1
  68. package/dist/teams/index.cjs +215 -201
  69. package/dist/teams/index.mjs +215 -201
  70. package/dist/text/index.cjs +193 -0
  71. package/dist/text/index.d.ts +1 -0
  72. package/dist/text/index.d.ts.map +1 -1
  73. package/dist/text/index.mjs +193 -1
  74. package/dist/text/merge-three-way.d.ts +9 -0
  75. package/dist/text/merge-three-way.d.ts.map +1 -0
  76. package/dist/visio/collab/index.cjs +226 -7
  77. package/dist/visio/collab/index.d.ts +1 -0
  78. package/dist/visio/collab/index.d.ts.map +1 -1
  79. package/dist/visio/collab/index.mjs +225 -7
  80. package/dist/visio/collab/merge-snapshots.d.ts +14 -0
  81. package/dist/visio/collab/merge-snapshots.d.ts.map +1 -0
  82. package/dist/visio/index.cjs +9 -9
  83. package/dist/visio/index.mjs +9 -9
  84. package/dist/visio/ui/index.cjs +9 -9
  85. package/dist/visio/ui/index.mjs +9 -9
  86. package/dist/xlsx/collab/index.cjs +49966 -507
  87. package/dist/xlsx/collab/index.d.ts +1 -0
  88. package/dist/xlsx/collab/index.d.ts.map +1 -1
  89. package/dist/xlsx/collab/index.mjs +49961 -507
  90. package/dist/xlsx/collab/merge-residual.d.ts +16 -0
  91. package/dist/xlsx/collab/merge-residual.d.ts.map +1 -0
  92. package/dist/xlsx/collab/merge-snapshots.d.ts +8 -0
  93. package/dist/xlsx/collab/merge-snapshots.d.ts.map +1 -0
  94. package/dist/xlsx/index.cjs +202 -202
  95. package/dist/xlsx/index.mjs +202 -202
  96. package/dist/xlsx/load/index.cjs +155 -155
  97. package/dist/xlsx/load/index.mjs +155 -155
  98. package/dist/xlsx/ui/index.cjs +202 -202
  99. package/dist/xlsx/ui/index.mjs +202 -202
  100. package/dist/xml/index.cjs +390 -22
  101. package/dist/xml/index.d.ts +1 -0
  102. package/dist/xml/index.d.ts.map +1 -1
  103. package/dist/xml/index.mjs +390 -23
  104. package/dist/xml/merge-three-way.d.ts +16 -0
  105. package/dist/xml/merge-three-way.d.ts.map +1 -0
  106. package/package.json +6 -1
  107. package/dist/pptx/chunks/index-DC5m1m_8.d.ts.map +0 -1
package/README.md CHANGED
@@ -24,6 +24,13 @@ Part of [ooxml](https://github.com/ChristopherVR/ooxml#readme): [Office](https:/
24
24
 
25
25
  ## Why ooxml-core?
26
26
 
27
+ Hosts can connect native DOCX, XLSX, PPTX and VSDX storage through the optional
28
+ [`ooxml-core/embedding/onedrive`](../../docs/onedrive-integration.md) subpath. It exposes the
29
+ shared Graph client, session storage adapter, cloud copies, sharing and retained conflict versions;
30
+ the host supplies Microsoft authentication and item permissions. See the
31
+ [package reference](../../docs/onedrive-integration.md#package-reference) and
32
+ [test/acceptance guide](../../docs/onedrive-testing.md). No public mock service or simulation UI ships.
33
+
27
34
  - **No UI, no framework.** Everything runs in browsers, Node.js, Bun, workers and serverless functions. The viewer apps ([docx](https://christophervr.github.io/ooxml/docx/), [xlsx](https://christophervr.github.io/ooxml/xlsx/), [visio](https://christophervr.github.io/ooxml/visio/), [teams](https://christophervr.github.io/ooxml/teams/) and [pptx](https://christophervr.github.io/ooxml/pptx/)) are thin interfaces on top of it, and so can your application be.
28
35
  - **One package, one structure.** All formats share the same XML model, packaging layer, units, colours and geometry. Each format is an _area_ of this one package, not a separate dependency to keep in step.
29
36
  - **Round-trips without losing what it does not understand.** Documents are loaded into a model, edited, and written back. Untouched parts stay byte-for-byte, unknown markup is preserved, and edits that would damage unsupported content are rejected instead of silently dropped.
@@ -211,6 +211,161 @@ function attr(element5, local, ns, prefix3) {
211
211
  }
212
212
  var relAttr = (element5, local) => attr(element5, local, NS.r, "r");
213
213
 
214
+ // text/text-diff.ts
215
+ var isLowSurrogate = (text9, at3) => {
216
+ const code = text9.charCodeAt(at3);
217
+ return code >= 56320 && code <= 57343;
218
+ };
219
+ function shortestEdit(n, m, same17, maxEdits) {
220
+ const max = Math.min(n + m, maxEdits);
221
+ const offset2 = max + 1;
222
+ const v = new Int32Array(2 * max + 3);
223
+ const trace = [];
224
+ for (let d = 0; d <= max; d++) {
225
+ for (let k = -d; k <= d; k += 2) {
226
+ const down = k === -d || k !== d && v[offset2 + k - 1] < v[offset2 + k + 1];
227
+ let x = down ? v[offset2 + k + 1] : v[offset2 + k - 1] + 1;
228
+ let y = x - k;
229
+ while (x < n && y < m && same17(x, y)) {
230
+ x++;
231
+ y++;
232
+ }
233
+ v[offset2 + k] = x;
234
+ if (x >= n && y >= m) return backtrack(trace, n, m, d);
235
+ }
236
+ trace.push(v.slice(offset2 - d, offset2 + d + 1));
237
+ }
238
+ return void 0;
239
+ }
240
+ function backtrack(trace, n, m, d) {
241
+ const edits2 = [];
242
+ let x = n;
243
+ let y = m;
244
+ for (let step2 = d; step2 > 0; step2--) {
245
+ const previous = trace[step2 - 1];
246
+ const at3 = (k2) => previous[k2 + step2 - 1];
247
+ const k = x - y;
248
+ const down = k === -step2 || k !== step2 && at3(k - 1) < at3(k + 1);
249
+ const before = down ? k + 1 : k - 1;
250
+ const startX = at3(before);
251
+ const startY = startX - before;
252
+ edits2.push(down ? [startX, startY, true] : [startX, startY, false]);
253
+ x = startX;
254
+ y = startY;
255
+ }
256
+ return edits2.reverse();
257
+ }
258
+ function changesOf(edits2) {
259
+ const changes = [];
260
+ for (const [x, y, inserts] of edits2) {
261
+ const last = changes.at(-1);
262
+ if (last && last.fromEnd === x && last.toEnd === y) {
263
+ if (inserts) last.toEnd++;
264
+ else last.fromEnd++;
265
+ } else
266
+ changes.push({
267
+ fromStart: x,
268
+ fromEnd: inserts ? x : x + 1,
269
+ toStart: y,
270
+ toEnd: inserts ? y + 1 : y
271
+ });
272
+ }
273
+ return changes;
274
+ }
275
+ function characterChanges(a2, b, maxEdits) {
276
+ const edits2 = shortestEdit(
277
+ a2.length,
278
+ b.length,
279
+ (x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
280
+ maxEdits
281
+ );
282
+ return edits2 && changesOf(edits2);
283
+ }
284
+ var TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
285
+ function tokensOf(text9, ids) {
286
+ const tokens3 = [];
287
+ const starts = [];
288
+ for (const match2 of text9.matchAll(TOKEN)) {
289
+ let id5 = ids.get(match2[0]);
290
+ if (id5 === void 0) ids.set(match2[0], id5 = ids.size);
291
+ tokens3.push(id5);
292
+ starts.push(match2.index);
293
+ }
294
+ starts.push(text9.length);
295
+ return { tokens: tokens3, starts };
296
+ }
297
+ function tokenChanges(a2, b, maxEdits) {
298
+ const ids = /* @__PURE__ */ new Map();
299
+ const from = tokensOf(a2, ids);
300
+ const to = tokensOf(b, ids);
301
+ const edits2 = shortestEdit(
302
+ from.tokens.length,
303
+ to.tokens.length,
304
+ (x, y) => from.tokens[x] === to.tokens[y],
305
+ maxEdits
306
+ );
307
+ if (!edits2) return void 0;
308
+ let budget = maxEdits;
309
+ return changesOf(edits2).flatMap((stretch) => {
310
+ const change = {
311
+ fromStart: from.starts[stretch.fromStart],
312
+ fromEnd: from.starts[stretch.fromEnd],
313
+ toStart: to.starts[stretch.toStart],
314
+ toEnd: to.starts[stretch.toEnd]
315
+ };
316
+ const inner2 = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
317
+ a2.slice(change.fromStart, change.fromEnd),
318
+ b.slice(change.toStart, change.toEnd),
319
+ budget
320
+ ) : void 0;
321
+ if (!inner2) return [change];
322
+ for (const found of inner2)
323
+ budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
324
+ return inner2.map((found) => ({
325
+ fromStart: found.fromStart + change.fromStart,
326
+ fromEnd: found.fromEnd + change.fromStart,
327
+ toStart: found.toStart + change.toStart,
328
+ toEnd: found.toEnd + change.toStart
329
+ }));
330
+ });
331
+ }
332
+ function diffText(from, to, maxEdits = 500) {
333
+ let start = 0;
334
+ while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
335
+ start++;
336
+ let end = 0;
337
+ while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
338
+ end++;
339
+ const a2 = from.slice(start, from.length - end);
340
+ const b = to.slice(start, to.length - end);
341
+ if (!a2.length && !b.length) return [];
342
+ const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
343
+ const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
344
+ const result2 = [];
345
+ for (const change of changes) {
346
+ const placed = {
347
+ fromStart: change.fromStart + start,
348
+ fromEnd: change.fromEnd + start,
349
+ toStart: change.toStart + start,
350
+ toEnd: change.toEnd + start
351
+ };
352
+ if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
353
+ placed.fromStart--;
354
+ placed.toStart--;
355
+ }
356
+ if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
357
+ placed.fromEnd++;
358
+ placed.toEnd++;
359
+ }
360
+ const last = result2.at(-1);
361
+ if (last && placed.fromStart <= last.fromEnd) {
362
+ last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
363
+ last.toEnd = Math.max(last.toEnd, placed.toEnd);
364
+ } else result2.push(placed);
365
+ }
366
+ return result2;
367
+ }
368
+
214
369
  // xml/lite.ts
215
370
  var LiteElement = class {
216
371
  constructor(tagName2, localName3, namespaceURI) {
@@ -1472,58 +1627,6 @@ async function ensureRelationship(zip, relsPath, type, target3) {
1472
1627
  zip.file(relsPath, xml.replace("</Relationships>", `${insertion}</Relationships>`));
1473
1628
  return id5;
1474
1629
  }
1475
-
1476
- // opc/safe-href.ts
1477
- var SAFE_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
1478
- function isSafeHyperlinkHref(href) {
1479
- const scheme2 = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
1480
- return scheme2 !== void 0 && SAFE_SCHEMES.has(scheme2.toLowerCase());
1481
- }
1482
- var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
1483
- var STORE_SCHEMES = /* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
1484
- var SCRIPT_SCHEMES = /* @__PURE__ */ new Set([
1485
- "javascript",
1486
- "vbscript",
1487
- "livescript",
1488
- "jscript",
1489
- "mocha",
1490
- "data",
1491
- "mhtml",
1492
- "ms-its",
1493
- "mk",
1494
- "x-javascript",
1495
- "blob"
1496
- ]);
1497
- var IGNORABLE = new RegExp(
1498
- "[\\u0000-\\u0020\\u007f\\u00ad\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u2064\\ufeff]",
1499
- "gu"
1500
- );
1501
- var CONTROL = new RegExp("[\\u0000-\\u001f\\u007f]", "u");
1502
- var SCHEME = /^([a-z][a-z0-9+.-]*):/;
1503
- var STORE_ONLY = { store: true, open: false, reason: "not-openable" };
1504
- var reject = (reason) => ({
1505
- store: false,
1506
- open: false,
1507
- reason
1508
- });
1509
- function hyperlinkPolicy(href, options2 = {}) {
1510
- if (typeof href !== "string") return reject("empty");
1511
- const trimmed2 = href.trim();
1512
- const normalized = trimmed2.replace(IGNORABLE, "").toLowerCase();
1513
- if (normalized.length === 0) return reject("empty");
1514
- const scheme2 = SCHEME.exec(normalized)?.[1];
1515
- if (scheme2 !== void 0 && SCRIPT_SCHEMES.has(scheme2)) return reject("script-scheme");
1516
- if (scheme2 !== void 0 && !trimmed2.toLowerCase().startsWith(`${scheme2}:`))
1517
- return reject("obfuscated-scheme");
1518
- if (CONTROL.test(trimmed2)) return reject("control-characters");
1519
- if (scheme2 === void 0) return options2.openRelative ? { store: true, open: true } : STORE_ONLY;
1520
- if (scheme2.length === 1) return STORE_ONLY;
1521
- if (OPEN_SCHEMES.has(scheme2)) return { store: true, open: true };
1522
- if (options2.additionalOpenSchemes?.some((allowed) => allowed.toLowerCase() === scheme2))
1523
- return { store: true, open: true };
1524
- if (STORE_SCHEMES.has(scheme2)) return STORE_ONLY;
1525
- return reject("unsupported-scheme");
1526
- }
1527
1630
  var DEFAULT_ZIP_LIMITS = {
1528
1631
  maxInputBytes: 100 * 1024 * 1024,
1529
1632
  maxEntries: 1e4,
@@ -1746,6 +1849,58 @@ async function openZip(input2, limits = {}) {
1746
1849
  return guardZip(await JSZip__default.default.loadAsync(bytes), limits);
1747
1850
  }
1748
1851
 
1852
+ // opc/safe-href.ts
1853
+ var SAFE_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
1854
+ function isSafeHyperlinkHref(href) {
1855
+ const scheme2 = /^([a-z][a-z0-9+.-]*:)/i.exec(href.trim())?.[1];
1856
+ return scheme2 !== void 0 && SAFE_SCHEMES.has(scheme2.toLowerCase());
1857
+ }
1858
+ var OPEN_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto"]);
1859
+ var STORE_SCHEMES = /* @__PURE__ */ new Set([...OPEN_SCHEMES, "ftp", "file"]);
1860
+ var SCRIPT_SCHEMES = /* @__PURE__ */ new Set([
1861
+ "javascript",
1862
+ "vbscript",
1863
+ "livescript",
1864
+ "jscript",
1865
+ "mocha",
1866
+ "data",
1867
+ "mhtml",
1868
+ "ms-its",
1869
+ "mk",
1870
+ "x-javascript",
1871
+ "blob"
1872
+ ]);
1873
+ var IGNORABLE = new RegExp(
1874
+ "[\\u0000-\\u0020\\u007f\\u00ad\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u2064\\ufeff]",
1875
+ "gu"
1876
+ );
1877
+ var CONTROL = new RegExp("[\\u0000-\\u001f\\u007f]", "u");
1878
+ var SCHEME = /^([a-z][a-z0-9+.-]*):/;
1879
+ var STORE_ONLY = { store: true, open: false, reason: "not-openable" };
1880
+ var reject = (reason) => ({
1881
+ store: false,
1882
+ open: false,
1883
+ reason
1884
+ });
1885
+ function hyperlinkPolicy(href, options2 = {}) {
1886
+ if (typeof href !== "string") return reject("empty");
1887
+ const trimmed2 = href.trim();
1888
+ const normalized = trimmed2.replace(IGNORABLE, "").toLowerCase();
1889
+ if (normalized.length === 0) return reject("empty");
1890
+ const scheme2 = SCHEME.exec(normalized)?.[1];
1891
+ if (scheme2 !== void 0 && SCRIPT_SCHEMES.has(scheme2)) return reject("script-scheme");
1892
+ if (scheme2 !== void 0 && !trimmed2.toLowerCase().startsWith(`${scheme2}:`))
1893
+ return reject("obfuscated-scheme");
1894
+ if (CONTROL.test(trimmed2)) return reject("control-characters");
1895
+ if (scheme2 === void 0) return options2.openRelative ? { store: true, open: true } : STORE_ONLY;
1896
+ if (scheme2.length === 1) return STORE_ONLY;
1897
+ if (OPEN_SCHEMES.has(scheme2)) return { store: true, open: true };
1898
+ if (options2.additionalOpenSchemes?.some((allowed) => allowed.toLowerCase() === scheme2))
1899
+ return { store: true, open: true };
1900
+ if (STORE_SCHEMES.has(scheme2)) return STORE_ONLY;
1901
+ return reject("unsupported-scheme");
1902
+ }
1903
+
1749
1904
  // opc/properties/types.ts
1750
1905
  var CUSTOM_PROPERTIES_FMTID = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
1751
1906
  var PROPERTY_PART_NAMES = {
@@ -4041,161 +4196,6 @@ function patchCommentMetadata(parts, identities) {
4041
4196
  return result2;
4042
4197
  }
4043
4198
 
4044
- // text/text-diff.ts
4045
- var isLowSurrogate = (text9, at3) => {
4046
- const code = text9.charCodeAt(at3);
4047
- return code >= 56320 && code <= 57343;
4048
- };
4049
- function shortestEdit(n, m, same17, maxEdits) {
4050
- const max = Math.min(n + m, maxEdits);
4051
- const offset2 = max + 1;
4052
- const v = new Int32Array(2 * max + 3);
4053
- const trace = [];
4054
- for (let d = 0; d <= max; d++) {
4055
- for (let k = -d; k <= d; k += 2) {
4056
- const down = k === -d || k !== d && v[offset2 + k - 1] < v[offset2 + k + 1];
4057
- let x = down ? v[offset2 + k + 1] : v[offset2 + k - 1] + 1;
4058
- let y = x - k;
4059
- while (x < n && y < m && same17(x, y)) {
4060
- x++;
4061
- y++;
4062
- }
4063
- v[offset2 + k] = x;
4064
- if (x >= n && y >= m) return backtrack(trace, n, m, d);
4065
- }
4066
- trace.push(v.slice(offset2 - d, offset2 + d + 1));
4067
- }
4068
- return void 0;
4069
- }
4070
- function backtrack(trace, n, m, d) {
4071
- const edits2 = [];
4072
- let x = n;
4073
- let y = m;
4074
- for (let step2 = d; step2 > 0; step2--) {
4075
- const previous = trace[step2 - 1];
4076
- const at3 = (k2) => previous[k2 + step2 - 1];
4077
- const k = x - y;
4078
- const down = k === -step2 || k !== step2 && at3(k - 1) < at3(k + 1);
4079
- const before = down ? k + 1 : k - 1;
4080
- const startX = at3(before);
4081
- const startY = startX - before;
4082
- edits2.push(down ? [startX, startY, true] : [startX, startY, false]);
4083
- x = startX;
4084
- y = startY;
4085
- }
4086
- return edits2.reverse();
4087
- }
4088
- function changesOf(edits2) {
4089
- const changes = [];
4090
- for (const [x, y, inserts] of edits2) {
4091
- const last = changes.at(-1);
4092
- if (last && last.fromEnd === x && last.toEnd === y) {
4093
- if (inserts) last.toEnd++;
4094
- else last.fromEnd++;
4095
- } else
4096
- changes.push({
4097
- fromStart: x,
4098
- fromEnd: inserts ? x : x + 1,
4099
- toStart: y,
4100
- toEnd: inserts ? y + 1 : y
4101
- });
4102
- }
4103
- return changes;
4104
- }
4105
- function characterChanges(a2, b, maxEdits) {
4106
- const edits2 = shortestEdit(
4107
- a2.length,
4108
- b.length,
4109
- (x, y) => a2.charCodeAt(x) === b.charCodeAt(y),
4110
- maxEdits
4111
- );
4112
- return edits2 && changesOf(edits2);
4113
- }
4114
- var TOKEN = /[\p{L}\p{N}\p{M}]+|\s+|[\s\S]/gu;
4115
- function tokensOf(text9, ids) {
4116
- const tokens3 = [];
4117
- const starts = [];
4118
- for (const match2 of text9.matchAll(TOKEN)) {
4119
- let id5 = ids.get(match2[0]);
4120
- if (id5 === void 0) ids.set(match2[0], id5 = ids.size);
4121
- tokens3.push(id5);
4122
- starts.push(match2.index);
4123
- }
4124
- starts.push(text9.length);
4125
- return { tokens: tokens3, starts };
4126
- }
4127
- function tokenChanges(a2, b, maxEdits) {
4128
- const ids = /* @__PURE__ */ new Map();
4129
- const from = tokensOf(a2, ids);
4130
- const to = tokensOf(b, ids);
4131
- const edits2 = shortestEdit(
4132
- from.tokens.length,
4133
- to.tokens.length,
4134
- (x, y) => from.tokens[x] === to.tokens[y],
4135
- maxEdits
4136
- );
4137
- if (!edits2) return void 0;
4138
- let budget = maxEdits;
4139
- return changesOf(edits2).flatMap((stretch) => {
4140
- const change = {
4141
- fromStart: from.starts[stretch.fromStart],
4142
- fromEnd: from.starts[stretch.fromEnd],
4143
- toStart: to.starts[stretch.toStart],
4144
- toEnd: to.starts[stretch.toEnd]
4145
- };
4146
- const inner2 = change.fromEnd > change.fromStart && change.toEnd > change.toStart ? characterChanges(
4147
- a2.slice(change.fromStart, change.fromEnd),
4148
- b.slice(change.toStart, change.toEnd),
4149
- budget
4150
- ) : void 0;
4151
- if (!inner2) return [change];
4152
- for (const found of inner2)
4153
- budget -= found.fromEnd - found.fromStart + found.toEnd - found.toStart;
4154
- return inner2.map((found) => ({
4155
- fromStart: found.fromStart + change.fromStart,
4156
- fromEnd: found.fromEnd + change.fromStart,
4157
- toStart: found.toStart + change.toStart,
4158
- toEnd: found.toEnd + change.toStart
4159
- }));
4160
- });
4161
- }
4162
- function diffText(from, to, maxEdits = 500) {
4163
- let start = 0;
4164
- while (start < from.length && start < to.length && from.charCodeAt(start) === to.charCodeAt(start))
4165
- start++;
4166
- let end = 0;
4167
- while (end < from.length - start && end < to.length - start && from.charCodeAt(from.length - 1 - end) === to.charCodeAt(to.length - 1 - end))
4168
- end++;
4169
- const a2 = from.slice(start, from.length - end);
4170
- const b = to.slice(start, to.length - end);
4171
- if (!a2.length && !b.length) return [];
4172
- const found = a2.length && b.length ? characterChanges(a2, b, maxEdits) ?? tokenChanges(a2, b, maxEdits) : void 0;
4173
- const changes = found ?? [{ fromStart: 0, fromEnd: a2.length, toStart: 0, toEnd: b.length }];
4174
- const result2 = [];
4175
- for (const change of changes) {
4176
- const placed = {
4177
- fromStart: change.fromStart + start,
4178
- fromEnd: change.fromEnd + start,
4179
- toStart: change.toStart + start,
4180
- toEnd: change.toEnd + start
4181
- };
4182
- if (placed.fromStart > 0 && placed.toStart > 0 && (isLowSurrogate(from, placed.fromStart) || isLowSurrogate(to, placed.toStart))) {
4183
- placed.fromStart--;
4184
- placed.toStart--;
4185
- }
4186
- if (isLowSurrogate(from, placed.fromEnd) || isLowSurrogate(to, placed.toEnd)) {
4187
- placed.fromEnd++;
4188
- placed.toEnd++;
4189
- }
4190
- const last = result2.at(-1);
4191
- if (last && placed.fromStart <= last.fromEnd) {
4192
- last.fromEnd = Math.max(last.fromEnd, placed.fromEnd);
4193
- last.toEnd = Math.max(last.toEnd, placed.toEnd);
4194
- } else result2.push(placed);
4195
- }
4196
- return result2;
4197
- }
4198
-
4199
4199
  // color/color-primitives.ts
4200
4200
  function clampUnitInterval(value3) {
4201
4201
  return Math.min(1, Math.max(0, value3));