ooxml-core 0.4.0 → 0.6.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 (104) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +1 -0
  3. package/dist/digest/algorithm-names.d.ts +20 -0
  4. package/dist/digest/algorithm-names.d.ts.map +1 -0
  5. package/dist/digest/base64.d.ts +8 -0
  6. package/dist/digest/base64.d.ts.map +1 -0
  7. package/dist/digest/digest.d.ts +13 -0
  8. package/dist/digest/digest.d.ts.map +1 -0
  9. package/dist/digest/index.cjs +594 -0
  10. package/dist/digest/index.d.ts +8 -0
  11. package/dist/digest/index.d.ts.map +1 -0
  12. package/dist/digest/index.mjs +581 -0
  13. package/dist/digest/password-hash.d.ts +30 -0
  14. package/dist/digest/password-hash.d.ts.map +1 -0
  15. package/dist/digest/sha1.d.ts +3 -0
  16. package/dist/digest/sha1.d.ts.map +1 -0
  17. package/dist/digest/sha256.d.ts +10 -0
  18. package/dist/digest/sha256.d.ts.map +1 -0
  19. package/dist/digest/sha512.d.ts +5 -0
  20. package/dist/digest/sha512.d.ts.map +1 -0
  21. package/dist/docx/block-parser.d.ts.map +1 -1
  22. package/dist/docx/embedded.cjs +153 -59
  23. package/dist/docx/embedded.mjs +153 -59
  24. package/dist/docx/equation.d.ts +8 -0
  25. package/dist/docx/equation.d.ts.map +1 -0
  26. package/dist/docx/index.cjs +153 -59
  27. package/dist/docx/index.mjs +153 -59
  28. package/dist/docx/layout/adapter.d.ts.map +1 -1
  29. package/dist/docx/layout/index.cjs +3 -1
  30. package/dist/docx/layout/index.mjs +3 -1
  31. package/dist/docx/load/index.cjs +155 -61
  32. package/dist/docx/load/index.mjs +155 -61
  33. package/dist/docx/model-run.d.ts +5 -0
  34. package/dist/docx/model-run.d.ts.map +1 -1
  35. package/dist/docx/parse-revisions.d.ts.map +1 -1
  36. package/dist/docx/parse-table.d.ts.map +1 -1
  37. package/dist/docx/write-inline.d.ts.map +1 -1
  38. package/dist/docx/write-table-margins.d.ts +5 -0
  39. package/dist/docx/write-table-margins.d.ts.map +1 -0
  40. package/dist/docx/write-table-properties.d.ts +6 -2
  41. package/dist/docx/write-table-properties.d.ts.map +1 -1
  42. package/dist/docx/write-table.d.ts.map +1 -1
  43. package/dist/index.cjs +2640 -13
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.mjs +2639 -14
  47. package/dist/math/index.cjs +2050 -0
  48. package/dist/math/index.d.ts +15 -0
  49. package/dist/math/index.d.ts.map +1 -0
  50. package/dist/math/index.mjs +1985 -0
  51. package/dist/math/latex-omml-siblings.d.ts +21 -0
  52. package/dist/math/latex-omml-siblings.d.ts.map +1 -0
  53. package/dist/math/latex-omml-symbols.d.ts +42 -0
  54. package/dist/math/latex-omml-symbols.d.ts.map +1 -0
  55. package/dist/math/latex-to-omml-commands.d.ts +9 -0
  56. package/dist/math/latex-to-omml-commands.d.ts.map +1 -0
  57. package/dist/math/latex-to-omml-constructs.d.ts +39 -0
  58. package/dist/math/latex-to-omml-constructs.d.ts.map +1 -0
  59. package/dist/math/latex-to-omml-environments.d.ts +28 -0
  60. package/dist/math/latex-to-omml-environments.d.ts.map +1 -0
  61. package/dist/math/latex-to-omml.d.ts +9 -0
  62. package/dist/math/latex-to-omml.d.ts.map +1 -0
  63. package/dist/math/omml-color.d.ts +11 -0
  64. package/dist/math/omml-color.d.ts.map +1 -0
  65. package/dist/math/omml-dom.d.ts +7 -0
  66. package/dist/math/omml-dom.d.ts.map +1 -0
  67. package/dist/math/omml-mathml-converters.d.ts +39 -0
  68. package/dist/math/omml-mathml-converters.d.ts.map +1 -0
  69. package/dist/math/omml-mathml-helpers.d.ts +23 -0
  70. package/dist/math/omml-mathml-helpers.d.ts.map +1 -0
  71. package/dist/math/omml-node.d.ts +7 -0
  72. package/dist/math/omml-node.d.ts.map +1 -0
  73. package/dist/math/omml-to-latex-helpers.d.ts +41 -0
  74. package/dist/math/omml-to-latex-helpers.d.ts.map +1 -0
  75. package/dist/math/omml-to-latex-layout.d.ts +18 -0
  76. package/dist/math/omml-to-latex-layout.d.ts.map +1 -0
  77. package/dist/math/omml-to-latex.d.ts +6 -0
  78. package/dist/math/omml-to-latex.d.ts.map +1 -0
  79. package/dist/math/omml-to-mathml.d.ts +21 -0
  80. package/dist/math/omml-to-mathml.d.ts.map +1 -0
  81. package/dist/xlsx/edit/history.d.ts +1 -1
  82. package/dist/xlsx/edit/history.d.ts.map +1 -1
  83. package/dist/xlsx/edit/index.d.ts +1 -1
  84. package/dist/xlsx/edit/index.d.ts.map +1 -1
  85. package/dist/xlsx/edit/protection.d.ts +18 -6
  86. package/dist/xlsx/edit/protection.d.ts.map +1 -1
  87. package/dist/xlsx/edit/types.d.ts +2 -2
  88. package/dist/xlsx/index.cjs +671 -28
  89. package/dist/xlsx/index.mjs +670 -29
  90. package/dist/xlsx/load/index.cjs +56 -19
  91. package/dist/xlsx/load/index.mjs +56 -19
  92. package/dist/xlsx/model.d.ts +21 -0
  93. package/dist/xlsx/model.d.ts.map +1 -1
  94. package/dist/xlsx/read/load.d.ts.map +1 -1
  95. package/dist/xlsx/read/password-hash.d.ts +15 -0
  96. package/dist/xlsx/read/password-hash.d.ts.map +1 -0
  97. package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
  98. package/dist/xlsx/read/workbook-part.d.ts +3 -1
  99. package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
  100. package/dist/xlsx/write/password-hash.d.ts +8 -0
  101. package/dist/xlsx/write/password-hash.d.ts.map +1 -0
  102. package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
  103. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  104. package/package.json +11 -1
@@ -0,0 +1,581 @@
1
+ // src/digest/algorithm-names.ts
2
+ var CANONICAL_BY_LOOKUP_KEY = {
3
+ SHA1: "SHA-1",
4
+ SHA256: "SHA-256",
5
+ SHA384: "SHA-384",
6
+ SHA512: "SHA-512",
7
+ MD2: "MD2",
8
+ MD4: "MD4",
9
+ MD5: "MD5",
10
+ RIPEMD128: "RIPEMD-128",
11
+ RIPEMD160: "RIPEMD-160",
12
+ WHIRLPOOL: "WHIRLPOOL"
13
+ };
14
+ function normalizeDigestAlgorithmName(name) {
15
+ const key = name.toUpperCase().replace(/[-_\s]/g, "");
16
+ return Object.hasOwn(CANONICAL_BY_LOOKUP_KEY, key) ? CANONICAL_BY_LOOKUP_KEY[key] : void 0;
17
+ }
18
+
19
+ // src/digest/base64.ts
20
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
21
+ var VALUES = new Map([...ALPHABET].map((char, index) => [char, index]));
22
+ function encodeBase64(bytes) {
23
+ let out = "";
24
+ for (let i = 0; i < bytes.length; i += 3) {
25
+ const a = bytes[i];
26
+ const b = bytes[i + 1];
27
+ const c = bytes[i + 2];
28
+ const n = a << 16 | (b ?? 0) << 8 | (c ?? 0);
29
+ out += ALPHABET[n >> 18] + ALPHABET[n >> 12 & 63];
30
+ out += b === void 0 ? "=" : ALPHABET[n >> 6 & 63];
31
+ out += c === void 0 ? "=" : ALPHABET[n & 63];
32
+ }
33
+ return out;
34
+ }
35
+ function decodeBase64(text) {
36
+ const compact = text.replace(/\s+/g, "");
37
+ const body = compact.replace(/={1,2}$/, "");
38
+ if (body.length % 4 === 1) return void 0;
39
+ if (compact.length !== body.length && compact.length % 4 !== 0) return void 0;
40
+ const out = new Uint8Array(Math.floor(body.length * 3 / 4));
41
+ let bits = 0;
42
+ let buffer = 0;
43
+ let index = 0;
44
+ for (const char of body) {
45
+ const value = VALUES.get(char);
46
+ if (value === void 0) return void 0;
47
+ buffer = (buffer << 6 | value) & 16777215;
48
+ bits += 6;
49
+ if (bits >= 8) {
50
+ bits -= 8;
51
+ out[index++] = buffer >> bits & 255;
52
+ }
53
+ }
54
+ return out;
55
+ }
56
+
57
+ // src/digest/sha256.ts
58
+ var K = new Uint32Array([
59
+ 1116352408,
60
+ 1899447441,
61
+ 3049323471,
62
+ 3921009573,
63
+ 961987163,
64
+ 1508970993,
65
+ 2453635748,
66
+ 2870763221,
67
+ 3624381080,
68
+ 310598401,
69
+ 607225278,
70
+ 1426881987,
71
+ 1925078388,
72
+ 2162078206,
73
+ 2614888103,
74
+ 3248222580,
75
+ 3835390401,
76
+ 4022224774,
77
+ 264347078,
78
+ 604807628,
79
+ 770255983,
80
+ 1249150122,
81
+ 1555081692,
82
+ 1996064986,
83
+ 2554220882,
84
+ 2821834349,
85
+ 2952996808,
86
+ 3210313671,
87
+ 3336571891,
88
+ 3584528711,
89
+ 113926993,
90
+ 338241895,
91
+ 666307205,
92
+ 773529912,
93
+ 1294757372,
94
+ 1396182291,
95
+ 1695183700,
96
+ 1986661051,
97
+ 2177026350,
98
+ 2456956037,
99
+ 2730485921,
100
+ 2820302411,
101
+ 3259730800,
102
+ 3345764771,
103
+ 3516065817,
104
+ 3600352804,
105
+ 4094571909,
106
+ 275423344,
107
+ 430227734,
108
+ 506948616,
109
+ 659060556,
110
+ 883997877,
111
+ 958139571,
112
+ 1322822218,
113
+ 1537002063,
114
+ 1747873779,
115
+ 1955562222,
116
+ 2024104815,
117
+ 2227730452,
118
+ 2361852424,
119
+ 2428436474,
120
+ 2756734187,
121
+ 3204031479,
122
+ 3329325298
123
+ ]);
124
+ var IV = [
125
+ 1779033703,
126
+ 3144134277,
127
+ 1013904242,
128
+ 2773480762,
129
+ 1359893119,
130
+ 2600822924,
131
+ 528734635,
132
+ 1541459225
133
+ ];
134
+ var W = new Uint32Array(64);
135
+ var rotr = (x, n) => x >>> n | x << 32 - n;
136
+ function compress(h, view, offset) {
137
+ for (let i = 0; i < 16; i++) W[i] = view.getUint32(offset + i * 4);
138
+ for (let i = 16; i < 64; i++) {
139
+ const a2 = W[i - 15];
140
+ const b2 = W[i - 2];
141
+ const s0 = rotr(a2, 7) ^ rotr(a2, 18) ^ a2 >>> 3;
142
+ const s1 = rotr(b2, 17) ^ rotr(b2, 19) ^ b2 >>> 10;
143
+ W[i] = W[i - 16] + s0 + W[i - 7] + s1 >>> 0;
144
+ }
145
+ let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], k = h[7];
146
+ for (let i = 0; i < 64; i++) {
147
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
148
+ const ch = e & f ^ ~e & g;
149
+ const t1 = k + S1 + ch + K[i] + W[i] >>> 0;
150
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
151
+ const maj = a & b ^ a & c ^ b & c;
152
+ const t2 = S0 + maj >>> 0;
153
+ k = g;
154
+ g = f;
155
+ f = e;
156
+ e = d + t1 >>> 0;
157
+ d = c;
158
+ c = b;
159
+ b = a;
160
+ a = t1 + t2 >>> 0;
161
+ }
162
+ h[0] = h[0] + a >>> 0;
163
+ h[1] = h[1] + b >>> 0;
164
+ h[2] = h[2] + c >>> 0;
165
+ h[3] = h[3] + d >>> 0;
166
+ h[4] = h[4] + e >>> 0;
167
+ h[5] = h[5] + f >>> 0;
168
+ h[6] = h[6] + g >>> 0;
169
+ h[7] = h[7] + k >>> 0;
170
+ }
171
+ function pad64(data) {
172
+ const padded = new Uint8Array(Math.ceil((data.length + 9) / 64) * 64);
173
+ padded.set(data);
174
+ padded[data.length] = 128;
175
+ const bits = data.length * 8;
176
+ const view = new DataView(padded.buffer);
177
+ view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
178
+ view.setUint32(padded.length - 4, bits >>> 0);
179
+ return view;
180
+ }
181
+ function wordsOut(h) {
182
+ const out = new Uint8Array(h.length * 4);
183
+ const view = new DataView(out.buffer);
184
+ for (let i = 0; i < h.length; i++) view.setUint32(i * 4, h[i]);
185
+ return out;
186
+ }
187
+ function sha256(data) {
188
+ const h = new Uint32Array(IV);
189
+ const view = pad64(data);
190
+ for (let offset = 0; offset < view.byteLength; offset += 64) compress(h, view, offset);
191
+ return wordsOut(h);
192
+ }
193
+
194
+ // src/digest/sha1.ts
195
+ var W2 = new Uint32Array(80);
196
+ var rotl = (x, n) => x << n | x >>> 32 - n;
197
+ function compress2(h, view, offset) {
198
+ for (let i = 0; i < 16; i++) W2[i] = view.getUint32(offset + i * 4);
199
+ for (let i = 16; i < 80; i++) W2[i] = rotl(W2[i - 3] ^ W2[i - 8] ^ W2[i - 14] ^ W2[i - 16], 1);
200
+ let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4];
201
+ for (let i = 0; i < 80; i++) {
202
+ let f;
203
+ let k;
204
+ if (i < 20) {
205
+ f = b & c | ~b & d;
206
+ k = 1518500249;
207
+ } else if (i < 40) {
208
+ f = b ^ c ^ d;
209
+ k = 1859775393;
210
+ } else if (i < 60) {
211
+ f = b & c | b & d | c & d;
212
+ k = 2400959708;
213
+ } else {
214
+ f = b ^ c ^ d;
215
+ k = 3395469782;
216
+ }
217
+ const t = rotl(a, 5) + f + e + k + W2[i] >>> 0;
218
+ e = d;
219
+ d = c;
220
+ c = rotl(b, 30) >>> 0;
221
+ b = a;
222
+ a = t;
223
+ }
224
+ h[0] = h[0] + a >>> 0;
225
+ h[1] = h[1] + b >>> 0;
226
+ h[2] = h[2] + c >>> 0;
227
+ h[3] = h[3] + d >>> 0;
228
+ h[4] = h[4] + e >>> 0;
229
+ }
230
+ function sha1(data) {
231
+ const h = new Uint32Array([1732584193, 4023233417, 2562383102, 271733878, 3285377520]);
232
+ const view = pad64(data);
233
+ for (let offset = 0; offset < view.byteLength; offset += 64) compress2(h, view, offset);
234
+ return wordsOut(h);
235
+ }
236
+
237
+ // src/digest/sha512.ts
238
+ var K2 = new Uint32Array([
239
+ 1116352408,
240
+ 3609767458,
241
+ 1899447441,
242
+ 602891725,
243
+ 3049323471,
244
+ 3964484399,
245
+ 3921009573,
246
+ 2173295548,
247
+ 961987163,
248
+ 4081628472,
249
+ 1508970993,
250
+ 3053834265,
251
+ 2453635748,
252
+ 2937671579,
253
+ 2870763221,
254
+ 3664609560,
255
+ 3624381080,
256
+ 2734883394,
257
+ 310598401,
258
+ 1164996542,
259
+ 607225278,
260
+ 1323610764,
261
+ 1426881987,
262
+ 3590304994,
263
+ 1925078388,
264
+ 4068182383,
265
+ 2162078206,
266
+ 991336113,
267
+ 2614888103,
268
+ 633803317,
269
+ 3248222580,
270
+ 3479774868,
271
+ 3835390401,
272
+ 2666613458,
273
+ 4022224774,
274
+ 944711139,
275
+ 264347078,
276
+ 2341262773,
277
+ 604807628,
278
+ 2007800933,
279
+ 770255983,
280
+ 1495990901,
281
+ 1249150122,
282
+ 1856431235,
283
+ 1555081692,
284
+ 3175218132,
285
+ 1996064986,
286
+ 2198950837,
287
+ 2554220882,
288
+ 3999719339,
289
+ 2821834349,
290
+ 766784016,
291
+ 2952996808,
292
+ 2566594879,
293
+ 3210313671,
294
+ 3203337956,
295
+ 3336571891,
296
+ 1034457026,
297
+ 3584528711,
298
+ 2466948901,
299
+ 113926993,
300
+ 3758326383,
301
+ 338241895,
302
+ 168717936,
303
+ 666307205,
304
+ 1188179964,
305
+ 773529912,
306
+ 1546045734,
307
+ 1294757372,
308
+ 1522805485,
309
+ 1396182291,
310
+ 2643833823,
311
+ 1695183700,
312
+ 2343527390,
313
+ 1986661051,
314
+ 1014477480,
315
+ 2177026350,
316
+ 1206759142,
317
+ 2456956037,
318
+ 344077627,
319
+ 2730485921,
320
+ 1290863460,
321
+ 2820302411,
322
+ 3158454273,
323
+ 3259730800,
324
+ 3505952657,
325
+ 3345764771,
326
+ 106217008,
327
+ 3516065817,
328
+ 3606008344,
329
+ 3600352804,
330
+ 1432725776,
331
+ 4094571909,
332
+ 1467031594,
333
+ 275423344,
334
+ 851169720,
335
+ 430227734,
336
+ 3100823752,
337
+ 506948616,
338
+ 1363258195,
339
+ 659060556,
340
+ 3750685593,
341
+ 883997877,
342
+ 3785050280,
343
+ 958139571,
344
+ 3318307427,
345
+ 1322822218,
346
+ 3812723403,
347
+ 1537002063,
348
+ 2003034995,
349
+ 1747873779,
350
+ 3602036899,
351
+ 1955562222,
352
+ 1575990012,
353
+ 2024104815,
354
+ 1125592928,
355
+ 2227730452,
356
+ 2716904306,
357
+ 2361852424,
358
+ 442776044,
359
+ 2428436474,
360
+ 593698344,
361
+ 2756734187,
362
+ 3733110249,
363
+ 3204031479,
364
+ 2999351573,
365
+ 3329325298,
366
+ 3815920427,
367
+ 3391569614,
368
+ 3928383900,
369
+ 3515267271,
370
+ 566280711,
371
+ 3940187606,
372
+ 3454069534,
373
+ 4118630271,
374
+ 4000239992,
375
+ 116418474,
376
+ 1914138554,
377
+ 174292421,
378
+ 2731055270,
379
+ 289380356,
380
+ 3203993006,
381
+ 460393269,
382
+ 320620315,
383
+ 685471733,
384
+ 587496836,
385
+ 852142971,
386
+ 1086792851,
387
+ 1017036298,
388
+ 365543100,
389
+ 1126000580,
390
+ 2618297676,
391
+ 1288033470,
392
+ 3409855158,
393
+ 1501505948,
394
+ 4234509866,
395
+ 1607167915,
396
+ 987167468,
397
+ 1816402316,
398
+ 1246189591
399
+ ]);
400
+ var IV_512 = [
401
+ 1779033703,
402
+ 4089235720,
403
+ 3144134277,
404
+ 2227873595,
405
+ 1013904242,
406
+ 4271175723,
407
+ 2773480762,
408
+ 1595750129,
409
+ 1359893119,
410
+ 2917565137,
411
+ 2600822924,
412
+ 725511199,
413
+ 528734635,
414
+ 4215389547,
415
+ 1541459225,
416
+ 327033209
417
+ ];
418
+ var IV_384 = [
419
+ 3418070365,
420
+ 3238371032,
421
+ 1654270250,
422
+ 914150663,
423
+ 2438529370,
424
+ 812702999,
425
+ 355462360,
426
+ 4144912697,
427
+ 1731405415,
428
+ 4290775857,
429
+ 2394180231,
430
+ 1750603025,
431
+ 3675008525,
432
+ 1694076839,
433
+ 1203062813,
434
+ 3204075428
435
+ ];
436
+ var W3 = new Uint32Array(160);
437
+ function compress3(h, data, offset) {
438
+ for (let i = 0; i < 32; i++) {
439
+ const o = offset + i * 4;
440
+ W3[i] = (data[o] << 24 | data[o + 1] << 16 | data[o + 2] << 8 | data[o + 3]) >>> 0;
441
+ }
442
+ for (let i = 16; i < 80; i++) {
443
+ const xh = W3[(i - 15) * 2];
444
+ const xl = W3[(i - 15) * 2 + 1];
445
+ const s0h = (xh >>> 1 | xl << 31) ^ (xh >>> 8 | xl << 24) ^ xh >>> 7;
446
+ const s0l = (xl >>> 1 | xh << 31) ^ (xl >>> 8 | xh << 24) ^ (xl >>> 7 | xh << 25);
447
+ const yh = W3[(i - 2) * 2];
448
+ const yl = W3[(i - 2) * 2 + 1];
449
+ const s1h = (yh >>> 19 | yl << 13) ^ (yl >>> 29 | yh << 3) ^ yh >>> 6;
450
+ const s1l = (yl >>> 19 | yh << 13) ^ (yh >>> 29 | yl << 3) ^ (yl >>> 6 | yh << 26);
451
+ let lo = (s0l >>> 0) + (s1l >>> 0) + W3[(i - 7) * 2 + 1] + W3[(i - 16) * 2 + 1];
452
+ const hi = s0h + s1h + W3[(i - 7) * 2] + W3[(i - 16) * 2] + Math.floor(lo / 4294967296);
453
+ lo >>>= 0;
454
+ W3[i * 2] = hi >>> 0;
455
+ W3[i * 2 + 1] = lo;
456
+ }
457
+ 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];
458
+ let eh = h[8], el = h[9], fh = h[10], fl = h[11], gh = h[12], gl = h[13], hh = h[14], hl = h[15];
459
+ for (let i = 0; i < 80; i++) {
460
+ const S1h = (eh >>> 14 | el << 18) ^ (eh >>> 18 | el << 14) ^ (el >>> 9 | eh << 23);
461
+ const S1l = (el >>> 14 | eh << 18) ^ (el >>> 18 | eh << 14) ^ (eh >>> 9 | el << 23);
462
+ const chh = eh & fh ^ ~eh & gh;
463
+ const chl = el & fl ^ ~el & gl;
464
+ let t1l = (hl >>> 0) + (S1l >>> 0) + (chl >>> 0) + K2[i * 2 + 1] + W3[i * 2 + 1];
465
+ const t1h = hh + S1h + chh + K2[i * 2] + W3[i * 2] + Math.floor(t1l / 4294967296);
466
+ t1l >>>= 0;
467
+ const S0h = (ah >>> 28 | al << 4) ^ (al >>> 2 | ah << 30) ^ (al >>> 7 | ah << 25);
468
+ const S0l = (al >>> 28 | ah << 4) ^ (ah >>> 2 | al << 30) ^ (ah >>> 7 | al << 25);
469
+ const majh = ah & bh ^ ah & ch ^ bh & ch;
470
+ const majl = al & bl ^ al & cl ^ bl & cl;
471
+ let t2l = (S0l >>> 0) + (majl >>> 0);
472
+ const t2h = S0h + majh + Math.floor(t2l / 4294967296);
473
+ t2l >>>= 0;
474
+ hh = gh;
475
+ hl = gl;
476
+ gh = fh;
477
+ gl = fl;
478
+ fh = eh;
479
+ fl = el;
480
+ let nl = (dl >>> 0) + t1l;
481
+ eh = dh + t1h + Math.floor(nl / 4294967296) >>> 0;
482
+ el = nl >>> 0;
483
+ dh = ch;
484
+ dl = cl;
485
+ ch = bh;
486
+ cl = bl;
487
+ bh = ah;
488
+ bl = al;
489
+ nl = t1l + t2l;
490
+ ah = t1h + t2h + Math.floor(nl / 4294967296) >>> 0;
491
+ al = nl >>> 0;
492
+ }
493
+ const add = (i, xh, xl) => {
494
+ const lo = (h[i + 1] >>> 0) + (xl >>> 0);
495
+ h[i] = h[i] + xh + Math.floor(lo / 4294967296) >>> 0;
496
+ h[i + 1] = lo >>> 0;
497
+ };
498
+ add(0, ah, al);
499
+ add(2, bh, bl);
500
+ add(4, ch, cl);
501
+ add(6, dh, dl);
502
+ add(8, eh, el);
503
+ add(10, fh, fl);
504
+ add(12, gh, gl);
505
+ add(14, hh, hl);
506
+ }
507
+ function digest64(data, iv, bytes) {
508
+ const h = new Uint32Array(iv);
509
+ const padded = new Uint8Array(Math.ceil((data.length + 17) / 128) * 128);
510
+ padded.set(data);
511
+ padded[data.length] = 128;
512
+ const bits = data.length * 8;
513
+ const view = new DataView(padded.buffer);
514
+ view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
515
+ view.setUint32(padded.length - 4, bits >>> 0);
516
+ for (let offset = 0; offset < padded.length; offset += 128) compress3(h, padded, offset);
517
+ const out = new Uint8Array(bytes);
518
+ const outView = new DataView(out.buffer);
519
+ for (let i = 0; i < bytes / 4; i++) outView.setUint32(i * 4, h[i]);
520
+ return out;
521
+ }
522
+ var sha512 = (data) => digest64(data, IV_512, 64);
523
+ var sha384 = (data) => digest64(data, IV_384, 48);
524
+
525
+ // src/digest/digest.ts
526
+ var DIGESTS = {
527
+ "SHA-1": sha1,
528
+ "SHA-256": sha256,
529
+ "SHA-384": sha384,
530
+ "SHA-512": sha512
531
+ };
532
+ function digestFunction(name) {
533
+ const canonical = normalizeDigestAlgorithmName(name);
534
+ return canonical && canonical in DIGESTS ? DIGESTS[canonical] : void 0;
535
+ }
536
+ function digestSync(name, data) {
537
+ return digestFunction(name)?.(data);
538
+ }
539
+
540
+ // src/digest/password-hash.ts
541
+ var MAX_SPIN_COUNT = 1e7;
542
+ var validSpinCount = (spinCount) => spinCount === void 0 || Number.isInteger(spinCount) && spinCount >= 0 && spinCount <= MAX_SPIN_COUNT;
543
+ function spin(password, salt, spinCount, digest) {
544
+ const input = new Uint8Array(salt.length + password.length * 2);
545
+ input.set(salt);
546
+ for (let i = 0; i < password.length; i++) {
547
+ const code = password.charCodeAt(i);
548
+ input[salt.length + i * 2] = code & 255;
549
+ input[salt.length + i * 2 + 1] = code >> 8;
550
+ }
551
+ let value = digest(input);
552
+ const buffer = new Uint8Array(value.length + 4);
553
+ const view = new DataView(buffer.buffer);
554
+ for (let i = 0; i < spinCount; i++) {
555
+ buffer.set(value);
556
+ view.setUint32(value.length, i, true);
557
+ value = digest(buffer);
558
+ }
559
+ return value;
560
+ }
561
+ function hashBytes(password, { algorithmName, saltValue, spinCount }) {
562
+ const digest = digestFunction(algorithmName);
563
+ const salt = decodeBase64(saltValue);
564
+ if (!digest || !salt || !validSpinCount(spinCount)) return void 0;
565
+ return spin(password, salt, spinCount ?? 0, digest);
566
+ }
567
+ function hashPassword(password, options) {
568
+ const bytes = hashBytes(password, options);
569
+ return bytes && encodeBase64(bytes);
570
+ }
571
+ function verifyPasswordHash(password, hash) {
572
+ if (!digestFunction(hash.algorithmName)) return void 0;
573
+ const expected = decodeBase64(hash.hashValue);
574
+ const actual = expected && hashBytes(password, hash);
575
+ if (!expected || !actual || actual.length !== expected.length) return false;
576
+ let difference = 0;
577
+ for (let i = 0; i < actual.length; i++) difference |= actual[i] ^ expected[i];
578
+ return difference === 0;
579
+ }
580
+
581
+ export { MAX_SPIN_COUNT, decodeBase64, digestFunction, digestSync, encodeBase64, hashPassword, normalizeDigestAlgorithmName, sha1, sha256, sha384, sha512, verifyPasswordHash };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * An ECMA-376 agile password hash as Office stores it on protection elements (`sheetProtection`,
3
+ * `workbookProtection`, `p:modifyVerifier`, ...): digest name, base64 salt and hash, and the
4
+ * number of extra rounds (absent means none).
5
+ */
6
+ export interface PasswordHash {
7
+ algorithmName: string;
8
+ hashValue: string;
9
+ saltValue: string;
10
+ spinCount?: number;
11
+ }
12
+ /**
13
+ * The largest `spinCount` honoured. Excel writes 100,000; anything far beyond that is a
14
+ * malformed or hostile file, and hashing it would freeze the thread.
15
+ */
16
+ export declare const MAX_SPIN_COUNT = 10000000;
17
+ /**
18
+ * The base64 ECMA-376 agile hash of `password` for the given salt, spin count and digest, as
19
+ * Excel, Word and PowerPoint store it. `undefined` when the digest is not one {@link digestSync}
20
+ * computes, the salt is not base64, or the spin count is negative, fractional, non-finite or
21
+ * above {@link MAX_SPIN_COUNT}.
22
+ */
23
+ export declare function hashPassword(password: string, options: Omit<PasswordHash, 'hashValue'>): string | undefined;
24
+ /**
25
+ * Whether `password` matches `hash`, comparing decoded bytes (so white space or missing base64
26
+ * padding in the file does not matter). `undefined` when the digest is not one this module
27
+ * computes; `false` (never a throw) for a malformed salt, hash or spin count.
28
+ */
29
+ export declare function verifyPasswordHash(password: string, hash: PasswordHash): boolean | undefined;
30
+ //# sourceMappingURL=password-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-hash.d.ts","sourceRoot":"","sources":["../../src/digest/password-hash.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,WAAa,CAAC;AA0CzC;;;;;GAKG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GACtC,MAAM,GAAG,SAAS,CAGpB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,GAAG,SAAS,CAQ5F"}
@@ -0,0 +1,3 @@
1
+ /** The SHA-1 digest (20 bytes) of `data`. */
2
+ export declare function sha1(data: Uint8Array): Uint8Array<ArrayBuffer>;
3
+ //# sourceMappingURL=sha1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha1.d.ts","sourceRoot":"","sources":["../../src/digest/sha1.ts"],"names":[],"mappings":"AA6CA,6CAA6C;AAC7C,wBAAgB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,CAK9D"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Pads `data` the Merkle-Damgard way SHA-1 and SHA-256 share (0x80, zeros, 64-bit big-endian
3
+ * bit length) into whole 64-byte blocks.
4
+ */
5
+ export declare function pad64(data: Uint8Array): DataView;
6
+ /** Writes the state words `h` big-endian into a new byte array. */
7
+ export declare function wordsOut(h: Uint32Array): Uint8Array<ArrayBuffer>;
8
+ /** The SHA-256 digest (32 bytes) of `data`. */
9
+ export declare function sha256(data: Uint8Array): Uint8Array<ArrayBuffer>;
10
+ //# sourceMappingURL=sha256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../../src/digest/sha256.ts"],"names":[],"mappings":"AAiEA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,QAAQ,CAShD;AAED,mEAAmE;AACnE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,CAKhE;AAED,+CAA+C;AAC/C,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,CAKhE"}
@@ -0,0 +1,5 @@
1
+ /** The SHA-512 digest (64 bytes) of `data`. */
2
+ export declare const sha512: (data: Uint8Array) => Uint8Array<ArrayBuffer>;
3
+ /** The SHA-384 digest (48 bytes) of `data`: the SHA-512 core with its own IV, truncated. */
4
+ export declare const sha384: (data: Uint8Array) => Uint8Array<ArrayBuffer>;
5
+ //# sourceMappingURL=sha512.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha512.d.ts","sourceRoot":"","sources":["../../src/digest/sha512.ts"],"names":[],"mappings":"AAkJA,+CAA+C;AAC/C,eAAO,MAAM,MAAM,GAAI,MAAM,UAAU,KAAG,UAAU,CAAC,WAAW,CAA+B,CAAC;AAEhG,4FAA4F;AAC5F,eAAO,MAAM,MAAM,GAAI,MAAM,UAAU,KAAG,UAAU,CAAC,WAAW,CAA+B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"block-parser.d.ts","sourceRoot":"","sources":["../../src/docx/block-parser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAY,KAAK,EAAsB,MAAM,YAAY,CAAC;AACxF,OAAO,EAON,KAAK,UAAU,EAEf,MAAM,UAAU,CAAC;AAKlB,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAqIjE,iBAAS,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAgG/D;AAED,iBAAS,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,KAAK,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACvC,SAAS,EAAE,UAAU,EACrB,QAAQ,SAAK,EACb,OAAO,CAAC,EAAE,cAAc,GACtB,KAAK,EAAE,CAcT;AAYD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"block-parser.d.ts","sourceRoot":"","sources":["../../src/docx/block-parser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAY,KAAK,EAAsB,MAAM,YAAY,CAAC;AACxF,OAAO,EAON,KAAK,UAAU,EAEf,MAAM,UAAU,CAAC;AAKlB,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAsIjE,iBAAS,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAwG/D;AAED,iBAAS,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,KAAK,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACvC,SAAS,EAAE,UAAU,EACrB,QAAQ,SAAK,EACb,OAAO,CAAC,EAAE,cAAc,GACtB,KAAK,EAAE,CAcT;AAYD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC"}