ooxml-core 0.5.0 → 0.7.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 (95) hide show
  1. package/README.md +1 -0
  2. package/dist/digest/algorithm-names.d.ts +20 -0
  3. package/dist/digest/algorithm-names.d.ts.map +1 -0
  4. package/dist/digest/base64.d.ts +8 -0
  5. package/dist/digest/base64.d.ts.map +1 -0
  6. package/dist/digest/digest.d.ts +13 -0
  7. package/dist/digest/digest.d.ts.map +1 -0
  8. package/dist/digest/index.cjs +594 -0
  9. package/dist/digest/index.d.ts +8 -0
  10. package/dist/digest/index.d.ts.map +1 -0
  11. package/dist/digest/index.mjs +581 -0
  12. package/dist/digest/password-hash.d.ts +30 -0
  13. package/dist/digest/password-hash.d.ts.map +1 -0
  14. package/dist/digest/sha1.d.ts +3 -0
  15. package/dist/digest/sha1.d.ts.map +1 -0
  16. package/dist/digest/sha256.d.ts +10 -0
  17. package/dist/digest/sha256.d.ts.map +1 -0
  18. package/dist/digest/sha512.d.ts +5 -0
  19. package/dist/digest/sha512.d.ts.map +1 -0
  20. package/dist/docx/block-parser.d.ts.map +1 -1
  21. package/dist/docx/embedded.cjs +131 -54
  22. package/dist/docx/embedded.mjs +131 -54
  23. package/dist/docx/equation.d.ts +8 -0
  24. package/dist/docx/equation.d.ts.map +1 -0
  25. package/dist/docx/index.cjs +131 -54
  26. package/dist/docx/index.mjs +131 -54
  27. package/dist/docx/layout/adapter.d.ts.map +1 -1
  28. package/dist/docx/layout/index.cjs +3 -1
  29. package/dist/docx/layout/index.mjs +3 -1
  30. package/dist/docx/load/index.cjs +133 -56
  31. package/dist/docx/load/index.mjs +133 -56
  32. package/dist/docx/model-run.d.ts +5 -0
  33. package/dist/docx/model-run.d.ts.map +1 -1
  34. package/dist/docx/parse-revisions.d.ts.map +1 -1
  35. package/dist/docx/parse-table.d.ts.map +1 -1
  36. package/dist/docx/write-inline.d.ts.map +1 -1
  37. package/dist/docx/write-table-margins.d.ts +5 -0
  38. package/dist/docx/write-table-margins.d.ts.map +1 -0
  39. package/dist/docx/write-table-properties.d.ts +3 -1
  40. package/dist/docx/write-table-properties.d.ts.map +1 -1
  41. package/dist/docx/write-table.d.ts.map +1 -1
  42. package/dist/index.cjs +598 -0
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.mjs +598 -1
  46. package/dist/visio/cell-formula.d.ts +9 -0
  47. package/dist/visio/cell-formula.d.ts.map +1 -0
  48. package/dist/visio/edit-commands.d.ts +33 -0
  49. package/dist/visio/edit-commands.d.ts.map +1 -0
  50. package/dist/visio/edit-geometry-admission.d.ts +10 -0
  51. package/dist/visio/edit-geometry-admission.d.ts.map +1 -0
  52. package/dist/visio/edit-geometry.d.ts +3 -0
  53. package/dist/visio/edit-geometry.d.ts.map +1 -0
  54. package/dist/visio/edit-recalculate-index.d.ts +25 -0
  55. package/dist/visio/edit-recalculate-index.d.ts.map +1 -0
  56. package/dist/visio/edit-recalculate.d.ts +11 -0
  57. package/dist/visio/edit-recalculate.d.ts.map +1 -0
  58. package/dist/visio/edit-scope.d.ts +5 -0
  59. package/dist/visio/edit-scope.d.ts.map +1 -0
  60. package/dist/visio/edit.d.ts +4 -8
  61. package/dist/visio/edit.d.ts.map +1 -1
  62. package/dist/visio/formula-evaluate.d.ts +10 -0
  63. package/dist/visio/formula-evaluate.d.ts.map +1 -0
  64. package/dist/visio/formula-theme.d.ts +2 -0
  65. package/dist/visio/formula-theme.d.ts.map +1 -0
  66. package/dist/visio/formula.d.ts +52 -0
  67. package/dist/visio/formula.d.ts.map +1 -0
  68. package/dist/visio/index.cjs +1605 -232
  69. package/dist/visio/index.d.ts +2 -1
  70. package/dist/visio/index.d.ts.map +1 -1
  71. package/dist/visio/index.mjs +1601 -233
  72. package/dist/xlsx/edit/history.d.ts +1 -1
  73. package/dist/xlsx/edit/history.d.ts.map +1 -1
  74. package/dist/xlsx/edit/index.d.ts +1 -1
  75. package/dist/xlsx/edit/index.d.ts.map +1 -1
  76. package/dist/xlsx/edit/protection.d.ts +18 -6
  77. package/dist/xlsx/edit/protection.d.ts.map +1 -1
  78. package/dist/xlsx/edit/types.d.ts +2 -2
  79. package/dist/xlsx/index.cjs +671 -28
  80. package/dist/xlsx/index.mjs +670 -29
  81. package/dist/xlsx/load/index.cjs +56 -19
  82. package/dist/xlsx/load/index.mjs +56 -19
  83. package/dist/xlsx/model.d.ts +21 -0
  84. package/dist/xlsx/model.d.ts.map +1 -1
  85. package/dist/xlsx/read/load.d.ts.map +1 -1
  86. package/dist/xlsx/read/password-hash.d.ts +15 -0
  87. package/dist/xlsx/read/password-hash.d.ts.map +1 -0
  88. package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
  89. package/dist/xlsx/read/workbook-part.d.ts +3 -1
  90. package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
  91. package/dist/xlsx/write/password-hash.d.ts +8 -0
  92. package/dist/xlsx/write/password-hash.d.ts.map +1 -0
  93. package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
  94. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  95. package/package.json +6 -1
@@ -8220,10 +8220,10 @@ var DISTRIBUTION_MORE = [
8220
8220
  "The hypergeometric distribution.",
8221
8221
  5,
8222
8222
  5,
8223
- (k, n2, K, N, c2) => {
8223
+ (k, n2, K3, N, c2) => {
8224
8224
  const kk = Math.trunc(k);
8225
8225
  const nn = Math.trunc(n2 ?? 0);
8226
- const KK = Math.trunc(K ?? 0);
8226
+ const KK = Math.trunc(K3 ?? 0);
8227
8227
  const NN = Math.trunc(N ?? 0);
8228
8228
  if (kk < 0 || nn > NN || KK > NN || kk > Math.min(nn, KK)) fail(ERR.NUM);
8229
8229
  const pmf = (i) => combin(KK, i) * combin(NN - KK, nn - i) / combin(NN, nn);
@@ -11539,6 +11539,29 @@ function translateReferences(formula, dRow, dCol) {
11539
11539
  return translateFormula(formula, dRow, dCol);
11540
11540
  }
11541
11541
 
11542
+ // src/xlsx/read/password-hash.ts
11543
+ function modernHashAttributeNames(prefix = "") {
11544
+ const name = (base) => prefix ? `${prefix}${base[0].toUpperCase()}${base.slice(1)}` : base;
11545
+ return {
11546
+ algorithmName: name("algorithmName"),
11547
+ hashValue: name("hashValue"),
11548
+ saltValue: name("saltValue"),
11549
+ spinCount: name("spinCount")
11550
+ };
11551
+ }
11552
+ function readModernHash(node, prefix = "") {
11553
+ const names = modernHashAttributeNames(prefix);
11554
+ const algorithmName = att(node, names.algorithmName);
11555
+ const hashValue = att(node, names.hashValue);
11556
+ const saltValue = att(node, names.saltValue);
11557
+ if (!algorithmName || !hashValue || !saltValue) return void 0;
11558
+ const hash = { algorithmName, hashValue, saltValue };
11559
+ const spin2 = att(node, names.spinCount);
11560
+ const spinCount = spin2 === void 0 || spin2.trim() === "" ? Number.NaN : Number(spin2);
11561
+ if (Number.isFinite(spinCount)) hash.spinCount = spinCount;
11562
+ return hash;
11563
+ }
11564
+
11542
11565
  // src/xlsx/read/workbook-part.ts
11543
11566
  function parseWorkbookPart(xml) {
11544
11567
  const root = parseXml(xml, { label: "XLSX workbook" }).documentElement;
@@ -11566,16 +11589,19 @@ function parseWorkbookPart(xml) {
11566
11589
  if (name.name) definedNames.push(name);
11567
11590
  }
11568
11591
  const view = xFirst(xFirst(root, "bookViews"), "workbookView");
11569
- const password = att(xFirst(root, "workbookProtection"), "workbookPassword");
11592
+ const protection = xFirst(root, "workbookProtection");
11593
+ const password = att(protection, "workbookPassword");
11594
+ const modernHash = readModernHash(protection, "workbook");
11570
11595
  const calcMode = att(xFirst(root, "calcPr"), "calcMode");
11571
11596
  return {
11572
11597
  ...password ? { workbookPasswordHash: password } : {},
11598
+ ...modernHash ? { workbookModernHash: modernHash } : {},
11573
11599
  ...calcMode === "manual" ? { calcMode: "manual" } : {},
11574
11600
  sheets,
11575
11601
  definedNames,
11576
11602
  date1904: boolAttr(xFirst(root, "workbookPr"), "date1904", false),
11577
11603
  activeTab: numAttr(view, "activeTab") ?? 0,
11578
- structureLocked: boolAttr(xFirst(root, "workbookProtection"), "lockStructure", false),
11604
+ structureLocked: boolAttr(protection, "lockStructure", false),
11579
11605
  fullCalcOnLoad: boolAttr(xFirst(root, "calcPr"), "fullCalcOnLoad", false)
11580
11606
  };
11581
11607
  }
@@ -11750,6 +11776,8 @@ function readProtection(node) {
11750
11776
  const protection = { sheet: boolAttr(node, "sheet", false) };
11751
11777
  const password = att(node, "password");
11752
11778
  if (password) protection.passwordHash = password;
11779
+ const modernHash = readModernHash(node);
11780
+ if (modernHash) protection.modernHash = modernHash;
11753
11781
  const allow = [];
11754
11782
  for (const attribute of Array.from(node.attributes)) {
11755
11783
  if (PROTECTION_META.has(attribute.name)) continue;
@@ -12657,6 +12685,7 @@ async function loadXlsx(input) {
12657
12685
  if (book.fullCalcOnLoad) workbook.fullCalcOnLoad = true;
12658
12686
  if (book.structureLocked) workbook.structureLocked = true;
12659
12687
  if (book.workbookPasswordHash) workbook.workbookPasswordHash = book.workbookPasswordHash;
12688
+ if (book.workbookModernHash) workbook.workbookModernHash = book.workbookModernHash;
12660
12689
  if (book.calcMode) workbook.calcMode = book.calcMode;
12661
12690
  if (!sheets.length) throw new Error("XLSX workbook has no sheets");
12662
12691
  liftPrintAreas(workbook);
@@ -13561,6 +13590,18 @@ function themePart(theme2, sourceXml) {
13561
13590
  return `${XML_HEADER}${buildXml(doc).replace(/^<\?xml[^>]*\?>\s*/, "")}`;
13562
13591
  }
13563
13592
 
13593
+ // src/xlsx/write/password-hash.ts
13594
+ function modernHashValues(hash, prefix = "") {
13595
+ if (!hash) return {};
13596
+ const names = modernHashAttributeNames(prefix);
13597
+ return {
13598
+ [names.algorithmName]: hash.algorithmName,
13599
+ [names.hashValue]: hash.hashValue,
13600
+ [names.saltValue]: hash.saltValue,
13601
+ [names.spinCount]: hash.spinCount === void 0 ? void 0 : String(hash.spinCount)
13602
+ };
13603
+ }
13604
+
13564
13605
  // src/xlsx/write/workbook-part.ts
13565
13606
  var KEPT_BEFORE_SHEETS = ["fileVersion", "fileSharing"];
13566
13607
  var KEPT_AFTER_SHEETS = ["functionGroups", "externalReferences"];
@@ -13611,18 +13652,17 @@ function workbookXml(workbook, sheets, activeTab, sourceXml) {
13611
13652
  out += raw(KEPT_BEFORE_SHEETS) || '<fileVersion appName="xl" lastEdited="7" lowestEdited="7" rupBuild="27328"/>';
13612
13653
  out += `<workbookPr${copyAttrs(kept.get("workbookPr"), ["date1904"])}${workbook.date1904 ? ' date1904="1"' : ""}/>`;
13613
13654
  if (workbook.structureLocked) {
13614
- const protection = kept.get("workbookProtection");
13615
- const sourceHash = protection?.getAttribute("workbookPassword") || void 0;
13616
- const skip = ["lockStructure", "workbookPassword"];
13617
- if (sourceHash !== workbook.workbookPasswordHash)
13618
- skip.push(
13619
- "workbookAlgorithmName",
13620
- "workbookHashValue",
13621
- "workbookSaltValue",
13622
- "workbookSpinCount"
13623
- );
13655
+ const skip = [
13656
+ "lockStructure",
13657
+ "workbookPassword",
13658
+ "workbookAlgorithmName",
13659
+ "workbookHashValue",
13660
+ "workbookSaltValue",
13661
+ "workbookSpinCount"
13662
+ ];
13663
+ const modern = Object.entries(modernHashValues(workbook.workbookModernHash, "workbook")).filter((entry) => entry[1] !== void 0).map(([name, value]) => ` ${name}="${escapeAttr3(value)}"`).join("");
13624
13664
  const password = workbook.workbookPasswordHash ? ` workbookPassword="${escapeAttr3(workbook.workbookPasswordHash)}"` : "";
13625
- out += `<workbookProtection${copyAttrs(protection, skip)}${password} lockStructure="1"/>`;
13665
+ out += `<workbookProtection${copyAttrs(kept.get("workbookProtection"), skip)}${modern}${password} lockStructure="1"/>`;
13626
13666
  }
13627
13667
  const view = kept.get("bookViews") ? elements(kept.get("bookViews"))[0] : void 0;
13628
13668
  out += `<bookViews><workbookView${copyAttrs(view, ["activeTab", "firstSheet", "xr2:uid"])}${activeTab ? ` activeTab="${activeTab}"` : ""}/></bookViews>`;
@@ -14229,18 +14269,15 @@ function colsXml(sheet, styleCount) {
14229
14269
  }
14230
14270
  return out.length ? `<cols>${out.join("")}</cols>` : "";
14231
14271
  }
14232
- var HASH_ATTRS = ["algorithmName", "hashValue", "saltValue", "spinCount"];
14233
14272
  function protectionXml2(sheet) {
14234
14273
  const protection = sheet.protection;
14235
14274
  if (!protection) return "";
14236
14275
  const source2 = snapshotElement(sheet, "sheetProtection");
14237
14276
  if (source2 && sameModel(readProtection(source2), protection))
14238
14277
  return snapshotXml(sheet, "sheetProtection") ?? "";
14239
- const values = {};
14240
- if (protection.passwordHash !== void 0 && protection.passwordHash === att(source2, "password"))
14241
- for (const name of HASH_ATTRS) values[name] = att(source2, name);
14242
- else if (protection.passwordHash === void 0 && att(source2, "password") === void 0)
14243
- for (const name of HASH_ATTRS) values[name] = att(source2, name);
14278
+ const values = modernHashValues(
14279
+ protection.modernHash
14280
+ );
14244
14281
  values["password"] = protection.passwordHash;
14245
14282
  values["sheet"] = protection.sheet || void 0;
14246
14283
  const allow = new Set(protection.allow ?? []);
@@ -16691,7 +16728,12 @@ function replaceOne(ctx, query, replacement, at) {
16691
16728
  }
16692
16729
 
16693
16730
  // src/xlsx/edit/history.ts
16694
- var SETTING_KEYS = ["structureLocked", "workbookPasswordHash", "calcMode"];
16731
+ var SETTING_KEYS = [
16732
+ "structureLocked",
16733
+ "workbookPasswordHash",
16734
+ "workbookModernHash",
16735
+ "calcMode"
16736
+ ];
16695
16737
  function captureSettings(workbook) {
16696
16738
  const out = {};
16697
16739
  for (const key of SETTING_KEYS) if (workbook[key] !== void 0) out[key] = workbook[key];
@@ -17670,6 +17712,583 @@ function setPrintOptions(ctx, s, patch) {
17670
17712
  );
17671
17713
  }
17672
17714
 
17715
+ // src/digest/algorithm-names.ts
17716
+ var CANONICAL_BY_LOOKUP_KEY = {
17717
+ SHA1: "SHA-1",
17718
+ SHA256: "SHA-256",
17719
+ SHA384: "SHA-384",
17720
+ SHA512: "SHA-512",
17721
+ MD2: "MD2",
17722
+ MD4: "MD4",
17723
+ MD5: "MD5",
17724
+ RIPEMD128: "RIPEMD-128",
17725
+ RIPEMD160: "RIPEMD-160",
17726
+ WHIRLPOOL: "WHIRLPOOL"
17727
+ };
17728
+ function normalizeDigestAlgorithmName(name) {
17729
+ const key = name.toUpperCase().replace(/[-_\s]/g, "");
17730
+ return Object.hasOwn(CANONICAL_BY_LOOKUP_KEY, key) ? CANONICAL_BY_LOOKUP_KEY[key] : void 0;
17731
+ }
17732
+
17733
+ // src/digest/base64.ts
17734
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
17735
+ var VALUES = new Map([...ALPHABET].map((char, index2) => [char, index2]));
17736
+ function encodeBase64(bytes) {
17737
+ let out = "";
17738
+ for (let i = 0; i < bytes.length; i += 3) {
17739
+ const a = bytes[i];
17740
+ const b = bytes[i + 1];
17741
+ const c2 = bytes[i + 2];
17742
+ const n2 = a << 16 | (b ?? 0) << 8 | (c2 ?? 0);
17743
+ out += ALPHABET[n2 >> 18] + ALPHABET[n2 >> 12 & 63];
17744
+ out += b === void 0 ? "=" : ALPHABET[n2 >> 6 & 63];
17745
+ out += c2 === void 0 ? "=" : ALPHABET[n2 & 63];
17746
+ }
17747
+ return out;
17748
+ }
17749
+ function decodeBase64(text2) {
17750
+ const compact3 = text2.replace(/\s+/g, "");
17751
+ const body = compact3.replace(/={1,2}$/, "");
17752
+ if (body.length % 4 === 1) return void 0;
17753
+ if (compact3.length !== body.length && compact3.length % 4 !== 0) return void 0;
17754
+ const out = new Uint8Array(Math.floor(body.length * 3 / 4));
17755
+ let bits = 0;
17756
+ let buffer = 0;
17757
+ let index2 = 0;
17758
+ for (const char of body) {
17759
+ const value = VALUES.get(char);
17760
+ if (value === void 0) return void 0;
17761
+ buffer = (buffer << 6 | value) & 16777215;
17762
+ bits += 6;
17763
+ if (bits >= 8) {
17764
+ bits -= 8;
17765
+ out[index2++] = buffer >> bits & 255;
17766
+ }
17767
+ }
17768
+ return out;
17769
+ }
17770
+
17771
+ // src/digest/sha256.ts
17772
+ var K = new Uint32Array([
17773
+ 1116352408,
17774
+ 1899447441,
17775
+ 3049323471,
17776
+ 3921009573,
17777
+ 961987163,
17778
+ 1508970993,
17779
+ 2453635748,
17780
+ 2870763221,
17781
+ 3624381080,
17782
+ 310598401,
17783
+ 607225278,
17784
+ 1426881987,
17785
+ 1925078388,
17786
+ 2162078206,
17787
+ 2614888103,
17788
+ 3248222580,
17789
+ 3835390401,
17790
+ 4022224774,
17791
+ 264347078,
17792
+ 604807628,
17793
+ 770255983,
17794
+ 1249150122,
17795
+ 1555081692,
17796
+ 1996064986,
17797
+ 2554220882,
17798
+ 2821834349,
17799
+ 2952996808,
17800
+ 3210313671,
17801
+ 3336571891,
17802
+ 3584528711,
17803
+ 113926993,
17804
+ 338241895,
17805
+ 666307205,
17806
+ 773529912,
17807
+ 1294757372,
17808
+ 1396182291,
17809
+ 1695183700,
17810
+ 1986661051,
17811
+ 2177026350,
17812
+ 2456956037,
17813
+ 2730485921,
17814
+ 2820302411,
17815
+ 3259730800,
17816
+ 3345764771,
17817
+ 3516065817,
17818
+ 3600352804,
17819
+ 4094571909,
17820
+ 275423344,
17821
+ 430227734,
17822
+ 506948616,
17823
+ 659060556,
17824
+ 883997877,
17825
+ 958139571,
17826
+ 1322822218,
17827
+ 1537002063,
17828
+ 1747873779,
17829
+ 1955562222,
17830
+ 2024104815,
17831
+ 2227730452,
17832
+ 2361852424,
17833
+ 2428436474,
17834
+ 2756734187,
17835
+ 3204031479,
17836
+ 3329325298
17837
+ ]);
17838
+ var IV = [
17839
+ 1779033703,
17840
+ 3144134277,
17841
+ 1013904242,
17842
+ 2773480762,
17843
+ 1359893119,
17844
+ 2600822924,
17845
+ 528734635,
17846
+ 1541459225
17847
+ ];
17848
+ var W = new Uint32Array(64);
17849
+ var rotr = (x, n2) => x >>> n2 | x << 32 - n2;
17850
+ function compress(h, view, offset2) {
17851
+ for (let i = 0; i < 16; i++) W[i] = view.getUint32(offset2 + i * 4);
17852
+ for (let i = 16; i < 64; i++) {
17853
+ const a2 = W[i - 15];
17854
+ const b2 = W[i - 2];
17855
+ const s0 = rotr(a2, 7) ^ rotr(a2, 18) ^ a2 >>> 3;
17856
+ const s1 = rotr(b2, 17) ^ rotr(b2, 19) ^ b2 >>> 10;
17857
+ W[i] = W[i - 16] + s0 + W[i - 7] + s1 >>> 0;
17858
+ }
17859
+ let a = h[0], b = h[1], c2 = h[2], d = h[3], e = h[4], f = h[5], g = h[6], k = h[7];
17860
+ for (let i = 0; i < 64; i++) {
17861
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
17862
+ const ch = e & f ^ ~e & g;
17863
+ const t1 = k + S1 + ch + K[i] + W[i] >>> 0;
17864
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
17865
+ const maj = a & b ^ a & c2 ^ b & c2;
17866
+ const t2 = S0 + maj >>> 0;
17867
+ k = g;
17868
+ g = f;
17869
+ f = e;
17870
+ e = d + t1 >>> 0;
17871
+ d = c2;
17872
+ c2 = b;
17873
+ b = a;
17874
+ a = t1 + t2 >>> 0;
17875
+ }
17876
+ h[0] = h[0] + a >>> 0;
17877
+ h[1] = h[1] + b >>> 0;
17878
+ h[2] = h[2] + c2 >>> 0;
17879
+ h[3] = h[3] + d >>> 0;
17880
+ h[4] = h[4] + e >>> 0;
17881
+ h[5] = h[5] + f >>> 0;
17882
+ h[6] = h[6] + g >>> 0;
17883
+ h[7] = h[7] + k >>> 0;
17884
+ }
17885
+ function pad64(data) {
17886
+ const padded = new Uint8Array(Math.ceil((data.length + 9) / 64) * 64);
17887
+ padded.set(data);
17888
+ padded[data.length] = 128;
17889
+ const bits = data.length * 8;
17890
+ const view = new DataView(padded.buffer);
17891
+ view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
17892
+ view.setUint32(padded.length - 4, bits >>> 0);
17893
+ return view;
17894
+ }
17895
+ function wordsOut(h) {
17896
+ const out = new Uint8Array(h.length * 4);
17897
+ const view = new DataView(out.buffer);
17898
+ for (let i = 0; i < h.length; i++) view.setUint32(i * 4, h[i]);
17899
+ return out;
17900
+ }
17901
+ function sha256(data) {
17902
+ const h = new Uint32Array(IV);
17903
+ const view = pad64(data);
17904
+ for (let offset2 = 0; offset2 < view.byteLength; offset2 += 64) compress(h, view, offset2);
17905
+ return wordsOut(h);
17906
+ }
17907
+
17908
+ // src/digest/sha1.ts
17909
+ var W2 = new Uint32Array(80);
17910
+ var rotl = (x, n2) => x << n2 | x >>> 32 - n2;
17911
+ function compress2(h, view, offset2) {
17912
+ for (let i = 0; i < 16; i++) W2[i] = view.getUint32(offset2 + i * 4);
17913
+ for (let i = 16; i < 80; i++) W2[i] = rotl(W2[i - 3] ^ W2[i - 8] ^ W2[i - 14] ^ W2[i - 16], 1);
17914
+ let a = h[0], b = h[1], c2 = h[2], d = h[3], e = h[4];
17915
+ for (let i = 0; i < 80; i++) {
17916
+ let f;
17917
+ let k;
17918
+ if (i < 20) {
17919
+ f = b & c2 | ~b & d;
17920
+ k = 1518500249;
17921
+ } else if (i < 40) {
17922
+ f = b ^ c2 ^ d;
17923
+ k = 1859775393;
17924
+ } else if (i < 60) {
17925
+ f = b & c2 | b & d | c2 & d;
17926
+ k = 2400959708;
17927
+ } else {
17928
+ f = b ^ c2 ^ d;
17929
+ k = 3395469782;
17930
+ }
17931
+ const t = rotl(a, 5) + f + e + k + W2[i] >>> 0;
17932
+ e = d;
17933
+ d = c2;
17934
+ c2 = rotl(b, 30) >>> 0;
17935
+ b = a;
17936
+ a = t;
17937
+ }
17938
+ h[0] = h[0] + a >>> 0;
17939
+ h[1] = h[1] + b >>> 0;
17940
+ h[2] = h[2] + c2 >>> 0;
17941
+ h[3] = h[3] + d >>> 0;
17942
+ h[4] = h[4] + e >>> 0;
17943
+ }
17944
+ function sha1(data) {
17945
+ const h = new Uint32Array([1732584193, 4023233417, 2562383102, 271733878, 3285377520]);
17946
+ const view = pad64(data);
17947
+ for (let offset2 = 0; offset2 < view.byteLength; offset2 += 64) compress2(h, view, offset2);
17948
+ return wordsOut(h);
17949
+ }
17950
+
17951
+ // src/digest/sha512.ts
17952
+ var K2 = new Uint32Array([
17953
+ 1116352408,
17954
+ 3609767458,
17955
+ 1899447441,
17956
+ 602891725,
17957
+ 3049323471,
17958
+ 3964484399,
17959
+ 3921009573,
17960
+ 2173295548,
17961
+ 961987163,
17962
+ 4081628472,
17963
+ 1508970993,
17964
+ 3053834265,
17965
+ 2453635748,
17966
+ 2937671579,
17967
+ 2870763221,
17968
+ 3664609560,
17969
+ 3624381080,
17970
+ 2734883394,
17971
+ 310598401,
17972
+ 1164996542,
17973
+ 607225278,
17974
+ 1323610764,
17975
+ 1426881987,
17976
+ 3590304994,
17977
+ 1925078388,
17978
+ 4068182383,
17979
+ 2162078206,
17980
+ 991336113,
17981
+ 2614888103,
17982
+ 633803317,
17983
+ 3248222580,
17984
+ 3479774868,
17985
+ 3835390401,
17986
+ 2666613458,
17987
+ 4022224774,
17988
+ 944711139,
17989
+ 264347078,
17990
+ 2341262773,
17991
+ 604807628,
17992
+ 2007800933,
17993
+ 770255983,
17994
+ 1495990901,
17995
+ 1249150122,
17996
+ 1856431235,
17997
+ 1555081692,
17998
+ 3175218132,
17999
+ 1996064986,
18000
+ 2198950837,
18001
+ 2554220882,
18002
+ 3999719339,
18003
+ 2821834349,
18004
+ 766784016,
18005
+ 2952996808,
18006
+ 2566594879,
18007
+ 3210313671,
18008
+ 3203337956,
18009
+ 3336571891,
18010
+ 1034457026,
18011
+ 3584528711,
18012
+ 2466948901,
18013
+ 113926993,
18014
+ 3758326383,
18015
+ 338241895,
18016
+ 168717936,
18017
+ 666307205,
18018
+ 1188179964,
18019
+ 773529912,
18020
+ 1546045734,
18021
+ 1294757372,
18022
+ 1522805485,
18023
+ 1396182291,
18024
+ 2643833823,
18025
+ 1695183700,
18026
+ 2343527390,
18027
+ 1986661051,
18028
+ 1014477480,
18029
+ 2177026350,
18030
+ 1206759142,
18031
+ 2456956037,
18032
+ 344077627,
18033
+ 2730485921,
18034
+ 1290863460,
18035
+ 2820302411,
18036
+ 3158454273,
18037
+ 3259730800,
18038
+ 3505952657,
18039
+ 3345764771,
18040
+ 106217008,
18041
+ 3516065817,
18042
+ 3606008344,
18043
+ 3600352804,
18044
+ 1432725776,
18045
+ 4094571909,
18046
+ 1467031594,
18047
+ 275423344,
18048
+ 851169720,
18049
+ 430227734,
18050
+ 3100823752,
18051
+ 506948616,
18052
+ 1363258195,
18053
+ 659060556,
18054
+ 3750685593,
18055
+ 883997877,
18056
+ 3785050280,
18057
+ 958139571,
18058
+ 3318307427,
18059
+ 1322822218,
18060
+ 3812723403,
18061
+ 1537002063,
18062
+ 2003034995,
18063
+ 1747873779,
18064
+ 3602036899,
18065
+ 1955562222,
18066
+ 1575990012,
18067
+ 2024104815,
18068
+ 1125592928,
18069
+ 2227730452,
18070
+ 2716904306,
18071
+ 2361852424,
18072
+ 442776044,
18073
+ 2428436474,
18074
+ 593698344,
18075
+ 2756734187,
18076
+ 3733110249,
18077
+ 3204031479,
18078
+ 2999351573,
18079
+ 3329325298,
18080
+ 3815920427,
18081
+ 3391569614,
18082
+ 3928383900,
18083
+ 3515267271,
18084
+ 566280711,
18085
+ 3940187606,
18086
+ 3454069534,
18087
+ 4118630271,
18088
+ 4000239992,
18089
+ 116418474,
18090
+ 1914138554,
18091
+ 174292421,
18092
+ 2731055270,
18093
+ 289380356,
18094
+ 3203993006,
18095
+ 460393269,
18096
+ 320620315,
18097
+ 685471733,
18098
+ 587496836,
18099
+ 852142971,
18100
+ 1086792851,
18101
+ 1017036298,
18102
+ 365543100,
18103
+ 1126000580,
18104
+ 2618297676,
18105
+ 1288033470,
18106
+ 3409855158,
18107
+ 1501505948,
18108
+ 4234509866,
18109
+ 1607167915,
18110
+ 987167468,
18111
+ 1816402316,
18112
+ 1246189591
18113
+ ]);
18114
+ var IV_512 = [
18115
+ 1779033703,
18116
+ 4089235720,
18117
+ 3144134277,
18118
+ 2227873595,
18119
+ 1013904242,
18120
+ 4271175723,
18121
+ 2773480762,
18122
+ 1595750129,
18123
+ 1359893119,
18124
+ 2917565137,
18125
+ 2600822924,
18126
+ 725511199,
18127
+ 528734635,
18128
+ 4215389547,
18129
+ 1541459225,
18130
+ 327033209
18131
+ ];
18132
+ var IV_384 = [
18133
+ 3418070365,
18134
+ 3238371032,
18135
+ 1654270250,
18136
+ 914150663,
18137
+ 2438529370,
18138
+ 812702999,
18139
+ 355462360,
18140
+ 4144912697,
18141
+ 1731405415,
18142
+ 4290775857,
18143
+ 2394180231,
18144
+ 1750603025,
18145
+ 3675008525,
18146
+ 1694076839,
18147
+ 1203062813,
18148
+ 3204075428
18149
+ ];
18150
+ var W3 = new Uint32Array(160);
18151
+ function compress3(h, data, offset2) {
18152
+ for (let i = 0; i < 32; i++) {
18153
+ const o = offset2 + i * 4;
18154
+ W3[i] = (data[o] << 24 | data[o + 1] << 16 | data[o + 2] << 8 | data[o + 3]) >>> 0;
18155
+ }
18156
+ for (let i = 16; i < 80; i++) {
18157
+ const xh = W3[(i - 15) * 2];
18158
+ const xl = W3[(i - 15) * 2 + 1];
18159
+ const s0h = (xh >>> 1 | xl << 31) ^ (xh >>> 8 | xl << 24) ^ xh >>> 7;
18160
+ const s0l = (xl >>> 1 | xh << 31) ^ (xl >>> 8 | xh << 24) ^ (xl >>> 7 | xh << 25);
18161
+ const yh = W3[(i - 2) * 2];
18162
+ const yl = W3[(i - 2) * 2 + 1];
18163
+ const s1h = (yh >>> 19 | yl << 13) ^ (yl >>> 29 | yh << 3) ^ yh >>> 6;
18164
+ const s1l = (yl >>> 19 | yh << 13) ^ (yh >>> 29 | yl << 3) ^ (yl >>> 6 | yh << 26);
18165
+ let lo = (s0l >>> 0) + (s1l >>> 0) + W3[(i - 7) * 2 + 1] + W3[(i - 16) * 2 + 1];
18166
+ const hi = s0h + s1h + W3[(i - 7) * 2] + W3[(i - 16) * 2] + Math.floor(lo / 4294967296);
18167
+ lo >>>= 0;
18168
+ W3[i * 2] = hi >>> 0;
18169
+ W3[i * 2 + 1] = lo;
18170
+ }
18171
+ let ah = h[0], al = h[1], bh = h[2], bl = h[3], ch = h[4], cl = h[5], dh = h[6], dl = h[7];
18172
+ let eh = h[8], el2 = h[9], fh = h[10], fl = h[11], gh = h[12], gl = h[13], hh = h[14], hl = h[15];
18173
+ for (let i = 0; i < 80; i++) {
18174
+ const S1h = (eh >>> 14 | el2 << 18) ^ (eh >>> 18 | el2 << 14) ^ (el2 >>> 9 | eh << 23);
18175
+ const S1l = (el2 >>> 14 | eh << 18) ^ (el2 >>> 18 | eh << 14) ^ (eh >>> 9 | el2 << 23);
18176
+ const chh = eh & fh ^ ~eh & gh;
18177
+ const chl = el2 & fl ^ ~el2 & gl;
18178
+ let t1l = (hl >>> 0) + (S1l >>> 0) + (chl >>> 0) + K2[i * 2 + 1] + W3[i * 2 + 1];
18179
+ const t1h = hh + S1h + chh + K2[i * 2] + W3[i * 2] + Math.floor(t1l / 4294967296);
18180
+ t1l >>>= 0;
18181
+ const S0h = (ah >>> 28 | al << 4) ^ (al >>> 2 | ah << 30) ^ (al >>> 7 | ah << 25);
18182
+ const S0l = (al >>> 28 | ah << 4) ^ (ah >>> 2 | al << 30) ^ (ah >>> 7 | al << 25);
18183
+ const majh = ah & bh ^ ah & ch ^ bh & ch;
18184
+ const majl = al & bl ^ al & cl ^ bl & cl;
18185
+ let t2l = (S0l >>> 0) + (majl >>> 0);
18186
+ const t2h = S0h + majh + Math.floor(t2l / 4294967296);
18187
+ t2l >>>= 0;
18188
+ hh = gh;
18189
+ hl = gl;
18190
+ gh = fh;
18191
+ gl = fl;
18192
+ fh = eh;
18193
+ fl = el2;
18194
+ let nl = (dl >>> 0) + t1l;
18195
+ eh = dh + t1h + Math.floor(nl / 4294967296) >>> 0;
18196
+ el2 = nl >>> 0;
18197
+ dh = ch;
18198
+ dl = cl;
18199
+ ch = bh;
18200
+ cl = bl;
18201
+ bh = ah;
18202
+ bl = al;
18203
+ nl = t1l + t2l;
18204
+ ah = t1h + t2h + Math.floor(nl / 4294967296) >>> 0;
18205
+ al = nl >>> 0;
18206
+ }
18207
+ const add = (i, xh, xl) => {
18208
+ const lo = (h[i + 1] >>> 0) + (xl >>> 0);
18209
+ h[i] = h[i] + xh + Math.floor(lo / 4294967296) >>> 0;
18210
+ h[i + 1] = lo >>> 0;
18211
+ };
18212
+ add(0, ah, al);
18213
+ add(2, bh, bl);
18214
+ add(4, ch, cl);
18215
+ add(6, dh, dl);
18216
+ add(8, eh, el2);
18217
+ add(10, fh, fl);
18218
+ add(12, gh, gl);
18219
+ add(14, hh, hl);
18220
+ }
18221
+ function digest64(data, iv, bytes) {
18222
+ const h = new Uint32Array(iv);
18223
+ const padded = new Uint8Array(Math.ceil((data.length + 17) / 128) * 128);
18224
+ padded.set(data);
18225
+ padded[data.length] = 128;
18226
+ const bits = data.length * 8;
18227
+ const view = new DataView(padded.buffer);
18228
+ view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
18229
+ view.setUint32(padded.length - 4, bits >>> 0);
18230
+ for (let offset2 = 0; offset2 < padded.length; offset2 += 128) compress3(h, padded, offset2);
18231
+ const out = new Uint8Array(bytes);
18232
+ const outView = new DataView(out.buffer);
18233
+ for (let i = 0; i < bytes / 4; i++) outView.setUint32(i * 4, h[i]);
18234
+ return out;
18235
+ }
18236
+ var sha512 = (data) => digest64(data, IV_512, 64);
18237
+ var sha384 = (data) => digest64(data, IV_384, 48);
18238
+
18239
+ // src/digest/digest.ts
18240
+ var DIGESTS = {
18241
+ "SHA-1": sha1,
18242
+ "SHA-256": sha256,
18243
+ "SHA-384": sha384,
18244
+ "SHA-512": sha512
18245
+ };
18246
+ function digestFunction(name) {
18247
+ const canonical = normalizeDigestAlgorithmName(name);
18248
+ return canonical && canonical in DIGESTS ? DIGESTS[canonical] : void 0;
18249
+ }
18250
+
18251
+ // src/digest/password-hash.ts
18252
+ var MAX_SPIN_COUNT = 1e7;
18253
+ var validSpinCount = (spinCount) => spinCount === void 0 || Number.isInteger(spinCount) && spinCount >= 0 && spinCount <= MAX_SPIN_COUNT;
18254
+ function spin(password, salt, spinCount, digest) {
18255
+ const input = new Uint8Array(salt.length + password.length * 2);
18256
+ input.set(salt);
18257
+ for (let i = 0; i < password.length; i++) {
18258
+ const code = password.charCodeAt(i);
18259
+ input[salt.length + i * 2] = code & 255;
18260
+ input[salt.length + i * 2 + 1] = code >> 8;
18261
+ }
18262
+ let value = digest(input);
18263
+ const buffer = new Uint8Array(value.length + 4);
18264
+ const view = new DataView(buffer.buffer);
18265
+ for (let i = 0; i < spinCount; i++) {
18266
+ buffer.set(value);
18267
+ view.setUint32(value.length, i, true);
18268
+ value = digest(buffer);
18269
+ }
18270
+ return value;
18271
+ }
18272
+ function hashBytes(password, { algorithmName, saltValue, spinCount }) {
18273
+ const digest = digestFunction(algorithmName);
18274
+ const salt = decodeBase64(saltValue);
18275
+ if (!digest || !salt || !validSpinCount(spinCount)) return void 0;
18276
+ return spin(password, salt, spinCount ?? 0, digest);
18277
+ }
18278
+ function hashPassword(password, options) {
18279
+ const bytes = hashBytes(password, options);
18280
+ return bytes && encodeBase64(bytes);
18281
+ }
18282
+ function verifyPasswordHash(password, hash) {
18283
+ if (!digestFunction(hash.algorithmName)) return void 0;
18284
+ const expected = decodeBase64(hash.hashValue);
18285
+ const actual = expected && hashBytes(password, hash);
18286
+ if (!expected || !actual || actual.length !== expected.length) return false;
18287
+ let difference = 0;
18288
+ for (let i = 0; i < actual.length; i++) difference |= actual[i] ^ expected[i];
18289
+ return difference === 0;
18290
+ }
18291
+
17673
18292
  // src/xlsx/edit/protection.ts
17674
18293
  function legacyPasswordHash(password) {
17675
18294
  let hash = 0;
@@ -17681,15 +18300,30 @@ function legacyPasswordHash(password) {
17681
18300
  hash ^= 52811;
17682
18301
  return hash.toString(16).toUpperCase();
17683
18302
  }
17684
- var sameHash = (hash, password) => hash === void 0 || hash.toUpperCase() === legacyPasswordHash(password);
18303
+ var sameLegacyHash = (hash, password) => hash.toUpperCase() === legacyPasswordHash(password);
18304
+ function matchesHashes(modern, legacy, password) {
18305
+ const verdict = modern ? verifyPasswordHash(password, modern) : void 0;
18306
+ if (verdict !== void 0) return verdict;
18307
+ if (legacy !== void 0) return sameLegacyHash(legacy, password);
18308
+ return !modern;
18309
+ }
18310
+ var protectionOf = (sheet) => sheet && "rows" in sheet ? sheet.protection : sheet;
17685
18311
  function verifySheetPassword(sheet, password) {
17686
- const protection = sheet && "rows" in sheet ? sheet.protection : sheet;
18312
+ const protection = protectionOf(sheet);
17687
18313
  if (!protection?.sheet) return true;
17688
- return sameHash(protection.passwordHash, password);
18314
+ return matchesHashes(protection.modernHash, protection.passwordHash, password);
18315
+ }
18316
+ async function verifySheetPasswordAsync(sheet, password) {
18317
+ return verifySheetPassword(sheet, password);
18318
+ }
18319
+ async function modernPasswordHash(password, hash, digest = "SHA-512") {
18320
+ const value = hashPassword(password, { ...hash, algorithmName: digest });
18321
+ if (value === void 0) throw new Error(`Cannot compute a ${digest} password hash`);
18322
+ return value;
17689
18323
  }
17690
18324
  function verifyWorkbookPassword(workbook, password) {
17691
18325
  if (!workbook.structureLocked) return true;
17692
- return sameHash(workbook.workbookPasswordHash, password);
18326
+ return matchesHashes(workbook.workbookModernHash, workbook.workbookPasswordHash, password);
17693
18327
  }
17694
18328
  var WRONG_PASSWORD = "The password you supplied is not correct.";
17695
18329
  function setSheetProtection(ctx, s, protection, password) {
@@ -17706,8 +18340,13 @@ function setSheetProtection(ctx, s, protection, password) {
17706
18340
  return;
17707
18341
  }
17708
18342
  const next = structuredClone(protection);
17709
- if (password) next.passwordHash = legacyPasswordHash(password);
17710
- else if (password === "") delete next.passwordHash;
18343
+ if (password) {
18344
+ next.passwordHash = legacyPasswordHash(password);
18345
+ delete next.modernHash;
18346
+ } else if (password === "") {
18347
+ delete next.passwordHash;
18348
+ delete next.modernHash;
18349
+ }
17711
18350
  sheet.protection = next;
17712
18351
  },
17713
18352
  { sheet: s }
@@ -17722,9 +18361,11 @@ function setWorkbookProtection(ctx, locked, password) {
17722
18361
  workbook.structureLocked = true;
17723
18362
  if (password) workbook.workbookPasswordHash = legacyPasswordHash(password);
17724
18363
  else if (password === "") delete workbook.workbookPasswordHash;
18364
+ if (password !== void 0) delete workbook.workbookModernHash;
17725
18365
  } else {
17726
18366
  delete workbook.structureLocked;
17727
18367
  delete workbook.workbookPasswordHash;
18368
+ delete workbook.workbookModernHash;
17728
18369
  }
17729
18370
  });
17730
18371
  }
@@ -20500,6 +21141,7 @@ exports.mergeAt = mergeAt;
20500
21141
  exports.mergeFont = mergeFont;
20501
21142
  exports.mergeView = mergeView;
20502
21143
  exports.mixColors = mixColors;
21144
+ exports.modernPasswordHash = modernPasswordHash;
20503
21145
  exports.modulateLuminance = modulateLuminance;
20504
21146
  exports.moveReferencesInFormula = moveReferencesInFormula;
20505
21147
  exports.navigate = navigate;
@@ -20573,6 +21215,7 @@ exports.validateSheetName = validateSheetName;
20573
21215
  exports.validateTableName = validateTableName;
20574
21216
  exports.validationAt = validationAt;
20575
21217
  exports.verifySheetPassword = verifySheetPassword;
21218
+ exports.verifySheetPasswordAsync = verifySheetPasswordAsync;
20576
21219
  exports.verifyWorkbookPassword = verifyWorkbookPassword;
20577
21220
  exports.visibleCells = visibleCells;
20578
21221
  exports.wrappedLineCount = wrappedLineCount;