ooxml-core 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PptxHandler-G63S6YZU.mjs → PptxHandler-75LOVF7I.mjs} +2 -2
- package/dist/automation/index.cjs +2559 -1169
- package/dist/automation/index.mjs +2559 -1169
- package/dist/chart/gradient-definition.d.ts +2 -2
- package/dist/chart/gradient-definition.d.ts.map +1 -1
- package/dist/chart/index.cjs +7 -7
- package/dist/chart/index.mjs +7 -7
- package/dist/{chunk-BICQYRPW.mjs → chunk-75LA7H3F.mjs} +1339 -1435
- package/dist/{chunk-CKJSWE7N.mjs → chunk-LA7D6ZYQ.mjs} +244 -115
- package/dist/{chunk-ROM5MZ7O.mjs → chunk-OMGH6IKY.mjs} +3 -3
- package/dist/{chunk-RWXFQJVF.mjs → chunk-Q27H4HFS.mjs} +1 -1
- package/dist/{chunk-DDG5HTGX.mjs → chunk-RFX7AJDZ.mjs} +1 -1
- package/dist/crypto/index.cjs +1406 -184
- package/dist/crypto/index.mjs +1406 -184
- package/dist/diagram/dom.d.ts +1 -14
- package/dist/diagram/dom.d.ts.map +1 -1
- package/dist/diagram/index.cjs +15 -15
- package/dist/diagram/index.d.ts +12 -12
- package/dist/diagram/index.d.ts.map +1 -1
- package/dist/diagram/index.mjs +15 -15
- package/dist/diagram/types.d.ts +12 -148
- package/dist/diagram/types.d.ts.map +1 -1
- package/dist/digest/algorithm-names.d.ts +2 -2
- package/dist/digest/algorithm-names.d.ts.map +1 -1
- package/dist/digest/bit-ops.d.ts +30 -0
- package/dist/digest/bit-ops.d.ts.map +1 -0
- package/dist/digest/digest.d.ts +2 -2
- package/dist/digest/digest.d.ts.map +1 -1
- package/dist/digest/index.cjs +1319 -90
- package/dist/digest/index.d.ts +7 -1
- package/dist/digest/index.d.ts.map +1 -1
- package/dist/digest/index.mjs +1313 -91
- package/dist/digest/md2.d.ts +22 -0
- package/dist/digest/md2.d.ts.map +1 -0
- package/dist/digest/md4.d.ts +3 -0
- package/dist/digest/md4.d.ts.map +1 -0
- package/dist/digest/md5.d.ts +3 -0
- package/dist/digest/md5.d.ts.map +1 -0
- package/dist/digest/password-hash.d.ts +7 -0
- package/dist/digest/password-hash.d.ts.map +1 -1
- package/dist/digest/ripemd-functions.d.ts +18 -0
- package/dist/digest/ripemd-functions.d.ts.map +1 -0
- package/dist/digest/ripemd128.d.ts +3 -0
- package/dist/digest/ripemd128.d.ts.map +1 -0
- package/dist/digest/ripemd160.d.ts +3 -0
- package/dist/digest/ripemd160.d.ts.map +1 -0
- package/dist/digest/whirlpool-sbox.d.ts +15 -0
- package/dist/digest/whirlpool-sbox.d.ts.map +1 -0
- package/dist/digest/whirlpool-table.d.ts +12 -0
- package/dist/digest/whirlpool-table.d.ts.map +1 -0
- package/dist/digest/whirlpool.d.ts +3 -0
- package/dist/digest/whirlpool.d.ts.map +1 -0
- package/dist/docx/block-parser.d.ts.map +1 -1
- package/dist/docx/diagram-theme.d.ts +3 -3
- package/dist/docx/diagram-theme.d.ts.map +1 -1
- package/dist/docx/embedded.cjs +470 -276
- package/dist/docx/embedded.mjs +470 -276
- package/dist/docx/field-flags.d.ts +8 -0
- package/dist/docx/field-flags.d.ts.map +1 -0
- package/dist/docx/field-lock.d.ts +6 -0
- package/dist/docx/field-lock.d.ts.map +1 -0
- package/dist/docx/field-runs.d.ts +4 -1
- package/dist/docx/field-runs.d.ts.map +1 -1
- package/dist/docx/index.cjs +1029 -850
- package/dist/docx/index.d.ts +2 -0
- package/dist/docx/index.d.ts.map +1 -1
- package/dist/docx/index.mjs +1027 -850
- package/dist/docx/layout/adapter.d.ts.map +1 -1
- package/dist/docx/layout/index.cjs +61 -47
- package/dist/docx/layout/index.mjs +61 -47
- package/dist/docx/layout/page-fields.d.ts.map +1 -1
- package/dist/docx/load/index.cjs +1883 -467
- package/dist/docx/load/index.mjs +1883 -467
- package/dist/docx/model-run.d.ts +5 -0
- package/dist/docx/model-run.d.ts.map +1 -1
- package/dist/docx/numbering-model.d.ts +1 -1
- package/dist/docx/numbering-model.d.ts.map +1 -1
- package/dist/docx/numbering-package.d.ts +4 -4
- package/dist/docx/numbering-package.d.ts.map +1 -1
- package/dist/docx/numbering-start-edit.d.ts +8 -0
- package/dist/docx/numbering-start-edit.d.ts.map +1 -0
- package/dist/docx/numbering-start-patch.d.ts +13 -0
- package/dist/docx/numbering-start-patch.d.ts.map +1 -0
- package/dist/docx/theme-color.d.ts.map +1 -1
- package/dist/docx/theme-model.d.ts +3 -2
- package/dist/docx/theme-model.d.ts.map +1 -1
- package/dist/docx/theme.d.ts +5 -1
- package/dist/docx/theme.d.ts.map +1 -1
- package/dist/docx/ui/field-guard.d.ts +2 -0
- package/dist/docx/ui/field-guard.d.ts.map +1 -1
- package/dist/docx/ui/field-results.d.ts.map +1 -1
- package/dist/docx/ui/index.cjs +547 -375
- package/dist/docx/ui/index.mjs +547 -376
- package/dist/docx/ui/review-commands.d.ts.map +1 -1
- package/dist/docx/ui/run-extra-mark.d.ts +1 -1
- package/dist/docx/ui/run-extra-mark.d.ts.map +1 -1
- package/dist/docx/ui/simple-field-input.d.ts +3 -0
- package/dist/docx/ui/simple-field-input.d.ts.map +1 -1
- package/dist/docx/ui/track-changes-mode.d.ts.map +1 -1
- package/dist/docx/ui/track-paragraph-boundaries.d.ts +5 -0
- package/dist/docx/ui/track-paragraph-boundaries.d.ts.map +1 -0
- package/dist/docx/write-inline.d.ts.map +1 -1
- package/dist/docx/write-run.d.ts.map +1 -1
- package/dist/drawingml/dom.d.ts +15 -0
- package/dist/drawingml/dom.d.ts.map +1 -0
- package/dist/drawingml/drawing-color-brightness.d.ts +6 -0
- package/dist/drawingml/drawing-color-brightness.d.ts.map +1 -0
- package/dist/drawingml/drawing-color-css.d.ts.map +1 -0
- package/dist/{diagram → drawingml}/drawing-color.d.ts +5 -5
- package/dist/drawingml/drawing-color.d.ts.map +1 -0
- package/dist/{diagram → drawingml}/drawing-fill.d.ts +3 -3
- package/dist/drawingml/drawing-fill.d.ts.map +1 -0
- package/dist/{diagram → drawingml}/drawing-geometry.d.ts +4 -4
- package/dist/drawingml/drawing-geometry.d.ts.map +1 -0
- package/dist/drawingml/drawing-shadow.d.ts.map +1 -0
- package/dist/{diagram → drawingml}/drawing-text.d.ts +2 -2
- package/dist/drawingml/drawing-text.d.ts.map +1 -0
- package/dist/{diagram → drawingml}/gradient-geometry.d.ts +2 -2
- package/dist/drawingml/gradient-geometry.d.ts.map +1 -0
- package/dist/drawingml/gradient-preset-data.d.ts.map +1 -0
- package/dist/{diagram → drawingml}/gradient-presets.d.ts +3 -3
- package/dist/drawingml/gradient-presets.d.ts.map +1 -0
- package/dist/drawingml/index.cjs +1545 -0
- package/dist/drawingml/index.d.ts +19 -0
- package/dist/drawingml/index.d.ts.map +1 -0
- package/dist/drawingml/index.mjs +1497 -0
- package/dist/{diagram → drawingml}/ordered-color-transforms.d.ts +2 -2
- package/dist/drawingml/ordered-color-transforms.d.ts.map +1 -0
- package/dist/drawingml/rect-path-gradient.d.ts.map +1 -0
- package/dist/drawingml/theme-color.d.ts +19 -0
- package/dist/drawingml/theme-color.d.ts.map +1 -0
- package/dist/drawingml/theme-model.d.ts +40 -0
- package/dist/drawingml/theme-model.d.ts.map +1 -0
- package/dist/drawingml/theme.d.ts +21 -0
- package/dist/drawingml/theme.d.ts.map +1 -0
- package/dist/drawingml/types.d.ts +152 -0
- package/dist/drawingml/types.d.ts.map +1 -0
- package/dist/drawingml/write-color.d.ts +4 -0
- package/dist/drawingml/write-color.d.ts.map +1 -0
- package/dist/{diagram → drawingml}/write-fill.d.ts +2 -2
- package/dist/drawingml/write-fill.d.ts.map +1 -0
- package/dist/geometry/connector-elbow-geometry.d.ts +14 -0
- package/dist/geometry/connector-elbow-geometry.d.ts.map +1 -1
- package/dist/geometry/index.cjs +43 -0
- package/dist/geometry/index.mjs +42 -1
- package/dist/i18n/dictionary.d.ts +13 -0
- package/dist/i18n/dictionary.d.ts.map +1 -0
- package/dist/i18n/index.cjs +68 -0
- package/dist/i18n/index.d.ts +4 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.mjs +60 -0
- package/dist/i18n/locale.d.ts +17 -0
- package/dist/i18n/locale.d.ts.map +1 -0
- package/dist/i18n/translator.d.ts +18 -0
- package/dist/i18n/translator.d.ts.map +1 -0
- package/dist/index.cjs +3712 -2178
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +3711 -2179
- package/dist/pptx/automation/index.cjs +2852 -1568
- package/dist/pptx/automation/index.d.ts +3 -3
- package/dist/pptx/automation/index.mjs +5 -5
- package/dist/pptx/chunks/{index-C4mfzVoY.d.ts → index-BHqL5KXH.d.ts} +2 -2
- package/dist/pptx/chunks/{index-C4mfzVoY.d.ts.map → index-BHqL5KXH.d.ts.map} +1 -1
- package/dist/pptx/chunks/{index-lk7dyOPS.d.ts → index-BYkdcS8J.d.ts} +12 -16
- package/dist/pptx/chunks/index-BYkdcS8J.d.ts.map +1 -0
- package/dist/pptx/chunks/smart-art-CO2jmJFf.d.ts.map +1 -1
- package/dist/pptx/chunks/{text-operations-CDLx4hD5.d.ts → text-operations-DEJ7alZR.d.ts} +2 -2
- package/dist/pptx/chunks/text-operations-DEJ7alZR.d.ts.map +1 -0
- package/dist/pptx/cli/index.cjs +2680 -1396
- package/dist/pptx/cli/index.d.ts +1 -1
- package/dist/pptx/cli/index.mjs +4 -4
- package/dist/pptx/converter/index.d.ts +1 -1
- package/dist/pptx/converter/index.mjs +2 -2
- package/dist/pptx/index.cjs +1771 -1756
- package/dist/pptx/index.d.ts +3 -3
- package/dist/pptx/index.mjs +5 -5
- package/dist/teams/index.cjs +144 -74
- package/dist/teams/index.mjs +144 -74
- package/dist/visio/ui/index.cjs +14 -3
- package/dist/visio/ui/index.mjs +14 -3
- package/dist/visio/ui/shape-rotation.d.ts +1 -1
- package/dist/visio/ui/shape-rotation.d.ts.map +1 -1
- package/dist/xlsx/edit/chart-series-gradient.d.ts +1 -1
- package/dist/xlsx/edit/chart-series-gradient.d.ts.map +1 -1
- package/dist/xlsx/edit/protection.d.ts +1 -1
- package/dist/xlsx/index.cjs +3222 -1886
- package/dist/xlsx/index.mjs +3222 -1886
- package/dist/xlsx/layout/chart-appearance.d.ts +1 -1
- package/dist/xlsx/layout/chart-appearance.d.ts.map +1 -1
- package/dist/xlsx/layout/chart-scale.d.ts +5 -1
- package/dist/xlsx/layout/chart-scale.d.ts.map +1 -1
- package/dist/xlsx/layout/chart-svg-legend.d.ts +13 -0
- package/dist/xlsx/layout/chart-svg-legend.d.ts.map +1 -0
- package/dist/xlsx/layout/chart-svg.d.ts.map +1 -1
- package/dist/xlsx/layout/chart-view.d.ts +3 -1
- package/dist/xlsx/layout/chart-view.d.ts.map +1 -1
- package/dist/xlsx/load/index.cjs +2110 -838
- package/dist/xlsx/load/index.mjs +2110 -838
- package/dist/xlsx/read/theme.d.ts +2 -4
- package/dist/xlsx/read/theme.d.ts.map +1 -1
- package/dist/xlsx/ui/index.cjs +2017 -771
- package/dist/xlsx/ui/index.mjs +2017 -771
- package/dist/xlsx/ui/locales/merge.d.ts +2 -1
- package/dist/xlsx/ui/locales/merge.d.ts.map +1 -1
- package/dist/xlsx/ui/localization.d.ts.map +1 -1
- package/dist/xlsx/write/theme.d.ts.map +1 -1
- package/package.json +11 -1
- package/dist/diagram/drawing-color-brightness.d.ts +0 -6
- package/dist/diagram/drawing-color-brightness.d.ts.map +0 -1
- package/dist/diagram/drawing-color-css.d.ts.map +0 -1
- package/dist/diagram/drawing-color.d.ts.map +0 -1
- package/dist/diagram/drawing-fill.d.ts.map +0 -1
- package/dist/diagram/drawing-geometry.d.ts.map +0 -1
- package/dist/diagram/drawing-shadow.d.ts.map +0 -1
- package/dist/diagram/drawing-text.d.ts.map +0 -1
- package/dist/diagram/gradient-geometry.d.ts.map +0 -1
- package/dist/diagram/gradient-preset-data.d.ts.map +0 -1
- package/dist/diagram/gradient-presets.d.ts.map +0 -1
- package/dist/diagram/ordered-color-transforms.d.ts.map +0 -1
- package/dist/diagram/rect-path-gradient.d.ts.map +0 -1
- package/dist/diagram/write-color.d.ts +0 -4
- package/dist/diagram/write-color.d.ts.map +0 -1
- package/dist/diagram/write-fill.d.ts.map +0 -1
- package/dist/pptx/chunks/index-lk7dyOPS.d.ts.map +0 -1
- package/dist/pptx/chunks/text-operations-CDLx4hD5.d.ts.map +0 -1
- /package/dist/{diagram → drawingml}/drawing-color-css.d.ts +0 -0
- /package/dist/{diagram → drawingml}/drawing-shadow.d.ts +0 -0
- /package/dist/{diagram → drawingml}/gradient-preset-data.d.ts +0 -0
- /package/dist/{diagram → drawingml}/rect-path-gradient.d.ts +0 -0
package/dist/docx/load/index.mjs
CHANGED
|
@@ -54,8 +54,8 @@ function parseOle2(buffer) {
|
|
|
54
54
|
if (data.length < 512) {
|
|
55
55
|
throw new Ole2ParseError("Truncated OLE2 compound file header");
|
|
56
56
|
}
|
|
57
|
-
for (let
|
|
58
|
-
if (data[
|
|
57
|
+
for (let i2 = 0; i2 < OLE_MAGIC.length; i2++) {
|
|
58
|
+
if (data[i2] !== OLE_MAGIC[i2]) {
|
|
59
59
|
throw new Ole2ParseError("Not a valid OLE2 compound file");
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -97,8 +97,8 @@ function parseOle2(buffer) {
|
|
|
97
97
|
return data.subarray(offset, offset + sectorSize);
|
|
98
98
|
}
|
|
99
99
|
const fatSectors = [];
|
|
100
|
-
for (let
|
|
101
|
-
const sector = view.getUint32(76 +
|
|
100
|
+
for (let i2 = 0; i2 < 109 && fatSectors.length < totalFATSectors; i2++) {
|
|
101
|
+
const sector = view.getUint32(76 + i2 * 4, true);
|
|
102
102
|
if (sector <= MAXREGSECT) {
|
|
103
103
|
fatSectors.push(sector);
|
|
104
104
|
}
|
|
@@ -112,8 +112,8 @@ function parseOle2(buffer) {
|
|
|
112
112
|
const difatData = readSector(difatSector);
|
|
113
113
|
const difatView = new DataView(difatData.buffer, difatData.byteOffset, difatData.byteLength);
|
|
114
114
|
const entriesPerSector = (sectorSize - 4) / 4;
|
|
115
|
-
for (let
|
|
116
|
-
const sector = difatView.getUint32(
|
|
115
|
+
for (let i2 = 0; i2 < entriesPerSector && fatSectors.length < totalFATSectors; i2++) {
|
|
116
|
+
const sector = difatView.getUint32(i2 * 4, true);
|
|
117
117
|
if (sector <= MAXREGSECT) {
|
|
118
118
|
fatSectors.push(sector);
|
|
119
119
|
}
|
|
@@ -127,8 +127,8 @@ function parseOle2(buffer) {
|
|
|
127
127
|
for (const fatSector of fatSectors) {
|
|
128
128
|
const fatData = readSector(fatSector);
|
|
129
129
|
const fatView = new DataView(fatData.buffer, fatData.byteOffset, fatData.byteLength);
|
|
130
|
-
for (let
|
|
131
|
-
fatEntries.push(fatView.getUint32(
|
|
130
|
+
for (let i2 = 0; i2 < sectorSize / 4 && fatEntries.length < sectorCount; i2++) {
|
|
131
|
+
fatEntries.push(fatView.getUint32(i2 * 4, true));
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
function readSectorChain(startSector) {
|
|
@@ -169,8 +169,8 @@ function parseOle2(buffer) {
|
|
|
169
169
|
const dirRaw = readSectorChain(firstDirectorySector);
|
|
170
170
|
const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
|
|
171
171
|
const entries = [];
|
|
172
|
-
for (let
|
|
173
|
-
const entryOffset =
|
|
172
|
+
for (let i2 = 0; i2 < numEntries; i2++) {
|
|
173
|
+
const entryOffset = i2 * DIR_ENTRY_SIZE;
|
|
174
174
|
const entryView = new DataView(dirRaw.buffer, dirRaw.byteOffset + entryOffset, DIR_ENTRY_SIZE);
|
|
175
175
|
const nameLen = entryView.getUint16(64, true);
|
|
176
176
|
const objectType = entryView.getUint8(66);
|
|
@@ -226,8 +226,8 @@ function parseOle2(buffer) {
|
|
|
226
226
|
}
|
|
227
227
|
const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
|
|
228
228
|
const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
|
|
229
|
-
for (let
|
|
230
|
-
miniFatEntries.push(miniFatView.getUint32(
|
|
229
|
+
for (let i2 = 0; i2 < miniFatRaw.length / 4 && i2 < miniCapacity; i2++) {
|
|
230
|
+
miniFatEntries.push(miniFatView.getUint32(i2 * 4, true));
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
function readMiniStream(startSector, size) {
|
|
@@ -292,10 +292,10 @@ function getCrypto() {
|
|
|
292
292
|
}
|
|
293
293
|
function encodePasswordUtf16LE(password) {
|
|
294
294
|
const buf = new Uint8Array(password.length * 2);
|
|
295
|
-
for (let
|
|
296
|
-
const code = password.charCodeAt(
|
|
297
|
-
buf[
|
|
298
|
-
buf[
|
|
295
|
+
for (let i2 = 0; i2 < password.length; i2++) {
|
|
296
|
+
const code = password.charCodeAt(i2);
|
|
297
|
+
buf[i2 * 2] = code & 255;
|
|
298
|
+
buf[i2 * 2 + 1] = code >> 8 & 255;
|
|
299
299
|
}
|
|
300
300
|
return buf;
|
|
301
301
|
}
|
|
@@ -321,15 +321,15 @@ function uint32LE(value) {
|
|
|
321
321
|
function base64Decode(str) {
|
|
322
322
|
const binary = atob(str);
|
|
323
323
|
const bytes = new Uint8Array(binary.length);
|
|
324
|
-
for (let
|
|
325
|
-
bytes[
|
|
324
|
+
for (let i2 = 0; i2 < binary.length; i2++) {
|
|
325
|
+
bytes[i2] = binary.charCodeAt(i2);
|
|
326
326
|
}
|
|
327
327
|
return bytes;
|
|
328
328
|
}
|
|
329
329
|
function base64Encode(bytes) {
|
|
330
330
|
let binary = "";
|
|
331
|
-
for (let
|
|
332
|
-
binary += String.fromCharCode(bytes[
|
|
331
|
+
for (let i2 = 0; i2 < bytes.length; i2++) {
|
|
332
|
+
binary += String.fromCharCode(bytes[i2]);
|
|
333
333
|
}
|
|
334
334
|
return btoa(binary);
|
|
335
335
|
}
|
|
@@ -448,6 +448,846 @@ function normalizeDigestAlgorithmName(name) {
|
|
|
448
448
|
return Object.hasOwn(CANONICAL_BY_LOOKUP_KEY, key) ? CANONICAL_BY_LOOKUP_KEY[key] : void 0;
|
|
449
449
|
}
|
|
450
450
|
|
|
451
|
+
// digest/md2.ts
|
|
452
|
+
var S = [
|
|
453
|
+
41,
|
|
454
|
+
46,
|
|
455
|
+
67,
|
|
456
|
+
201,
|
|
457
|
+
162,
|
|
458
|
+
216,
|
|
459
|
+
124,
|
|
460
|
+
1,
|
|
461
|
+
61,
|
|
462
|
+
54,
|
|
463
|
+
84,
|
|
464
|
+
161,
|
|
465
|
+
236,
|
|
466
|
+
240,
|
|
467
|
+
6,
|
|
468
|
+
19,
|
|
469
|
+
98,
|
|
470
|
+
167,
|
|
471
|
+
5,
|
|
472
|
+
243,
|
|
473
|
+
192,
|
|
474
|
+
199,
|
|
475
|
+
115,
|
|
476
|
+
140,
|
|
477
|
+
152,
|
|
478
|
+
147,
|
|
479
|
+
43,
|
|
480
|
+
217,
|
|
481
|
+
188,
|
|
482
|
+
76,
|
|
483
|
+
130,
|
|
484
|
+
202,
|
|
485
|
+
30,
|
|
486
|
+
155,
|
|
487
|
+
87,
|
|
488
|
+
60,
|
|
489
|
+
253,
|
|
490
|
+
212,
|
|
491
|
+
224,
|
|
492
|
+
22,
|
|
493
|
+
103,
|
|
494
|
+
66,
|
|
495
|
+
111,
|
|
496
|
+
24,
|
|
497
|
+
138,
|
|
498
|
+
23,
|
|
499
|
+
229,
|
|
500
|
+
18,
|
|
501
|
+
190,
|
|
502
|
+
78,
|
|
503
|
+
196,
|
|
504
|
+
214,
|
|
505
|
+
218,
|
|
506
|
+
158,
|
|
507
|
+
222,
|
|
508
|
+
73,
|
|
509
|
+
160,
|
|
510
|
+
251,
|
|
511
|
+
245,
|
|
512
|
+
142,
|
|
513
|
+
187,
|
|
514
|
+
47,
|
|
515
|
+
238,
|
|
516
|
+
122,
|
|
517
|
+
169,
|
|
518
|
+
104,
|
|
519
|
+
121,
|
|
520
|
+
145,
|
|
521
|
+
21,
|
|
522
|
+
178,
|
|
523
|
+
7,
|
|
524
|
+
63,
|
|
525
|
+
148,
|
|
526
|
+
194,
|
|
527
|
+
16,
|
|
528
|
+
137,
|
|
529
|
+
11,
|
|
530
|
+
34,
|
|
531
|
+
95,
|
|
532
|
+
33,
|
|
533
|
+
128,
|
|
534
|
+
127,
|
|
535
|
+
93,
|
|
536
|
+
154,
|
|
537
|
+
90,
|
|
538
|
+
144,
|
|
539
|
+
50,
|
|
540
|
+
39,
|
|
541
|
+
53,
|
|
542
|
+
62,
|
|
543
|
+
204,
|
|
544
|
+
231,
|
|
545
|
+
191,
|
|
546
|
+
247,
|
|
547
|
+
151,
|
|
548
|
+
3,
|
|
549
|
+
255,
|
|
550
|
+
25,
|
|
551
|
+
48,
|
|
552
|
+
179,
|
|
553
|
+
72,
|
|
554
|
+
165,
|
|
555
|
+
181,
|
|
556
|
+
209,
|
|
557
|
+
215,
|
|
558
|
+
94,
|
|
559
|
+
146,
|
|
560
|
+
42,
|
|
561
|
+
172,
|
|
562
|
+
86,
|
|
563
|
+
170,
|
|
564
|
+
198,
|
|
565
|
+
79,
|
|
566
|
+
184,
|
|
567
|
+
56,
|
|
568
|
+
210,
|
|
569
|
+
150,
|
|
570
|
+
164,
|
|
571
|
+
125,
|
|
572
|
+
182,
|
|
573
|
+
118,
|
|
574
|
+
252,
|
|
575
|
+
107,
|
|
576
|
+
226,
|
|
577
|
+
156,
|
|
578
|
+
116,
|
|
579
|
+
4,
|
|
580
|
+
241,
|
|
581
|
+
69,
|
|
582
|
+
157,
|
|
583
|
+
112,
|
|
584
|
+
89,
|
|
585
|
+
100,
|
|
586
|
+
113,
|
|
587
|
+
135,
|
|
588
|
+
32,
|
|
589
|
+
134,
|
|
590
|
+
91,
|
|
591
|
+
207,
|
|
592
|
+
101,
|
|
593
|
+
230,
|
|
594
|
+
45,
|
|
595
|
+
168,
|
|
596
|
+
2,
|
|
597
|
+
27,
|
|
598
|
+
96,
|
|
599
|
+
37,
|
|
600
|
+
173,
|
|
601
|
+
174,
|
|
602
|
+
176,
|
|
603
|
+
185,
|
|
604
|
+
246,
|
|
605
|
+
28,
|
|
606
|
+
70,
|
|
607
|
+
97,
|
|
608
|
+
105,
|
|
609
|
+
52,
|
|
610
|
+
64,
|
|
611
|
+
126,
|
|
612
|
+
15,
|
|
613
|
+
85,
|
|
614
|
+
71,
|
|
615
|
+
163,
|
|
616
|
+
35,
|
|
617
|
+
221,
|
|
618
|
+
81,
|
|
619
|
+
175,
|
|
620
|
+
58,
|
|
621
|
+
195,
|
|
622
|
+
92,
|
|
623
|
+
249,
|
|
624
|
+
206,
|
|
625
|
+
186,
|
|
626
|
+
197,
|
|
627
|
+
234,
|
|
628
|
+
38,
|
|
629
|
+
44,
|
|
630
|
+
83,
|
|
631
|
+
13,
|
|
632
|
+
110,
|
|
633
|
+
133,
|
|
634
|
+
40,
|
|
635
|
+
132,
|
|
636
|
+
9,
|
|
637
|
+
211,
|
|
638
|
+
223,
|
|
639
|
+
205,
|
|
640
|
+
244,
|
|
641
|
+
65,
|
|
642
|
+
129,
|
|
643
|
+
77,
|
|
644
|
+
82,
|
|
645
|
+
106,
|
|
646
|
+
220,
|
|
647
|
+
55,
|
|
648
|
+
200,
|
|
649
|
+
108,
|
|
650
|
+
193,
|
|
651
|
+
171,
|
|
652
|
+
250,
|
|
653
|
+
36,
|
|
654
|
+
225,
|
|
655
|
+
123,
|
|
656
|
+
8,
|
|
657
|
+
12,
|
|
658
|
+
189,
|
|
659
|
+
177,
|
|
660
|
+
74,
|
|
661
|
+
120,
|
|
662
|
+
136,
|
|
663
|
+
149,
|
|
664
|
+
139,
|
|
665
|
+
227,
|
|
666
|
+
99,
|
|
667
|
+
232,
|
|
668
|
+
109,
|
|
669
|
+
233,
|
|
670
|
+
203,
|
|
671
|
+
213,
|
|
672
|
+
254,
|
|
673
|
+
59,
|
|
674
|
+
0,
|
|
675
|
+
29,
|
|
676
|
+
57,
|
|
677
|
+
242,
|
|
678
|
+
239,
|
|
679
|
+
183,
|
|
680
|
+
14,
|
|
681
|
+
102,
|
|
682
|
+
88,
|
|
683
|
+
208,
|
|
684
|
+
228,
|
|
685
|
+
166,
|
|
686
|
+
119,
|
|
687
|
+
114,
|
|
688
|
+
248,
|
|
689
|
+
235,
|
|
690
|
+
117,
|
|
691
|
+
75,
|
|
692
|
+
10,
|
|
693
|
+
49,
|
|
694
|
+
68,
|
|
695
|
+
80,
|
|
696
|
+
180,
|
|
697
|
+
143,
|
|
698
|
+
237,
|
|
699
|
+
31,
|
|
700
|
+
26,
|
|
701
|
+
219,
|
|
702
|
+
153,
|
|
703
|
+
141,
|
|
704
|
+
51,
|
|
705
|
+
159,
|
|
706
|
+
17,
|
|
707
|
+
131,
|
|
708
|
+
20
|
|
709
|
+
];
|
|
710
|
+
function transform(state, checksum, block) {
|
|
711
|
+
const x = new Uint8Array(48);
|
|
712
|
+
x.set(state, 0);
|
|
713
|
+
x.set(block, 16);
|
|
714
|
+
for (let k = 0; k < 16; k++) {
|
|
715
|
+
x[32 + k] = state[k] ^ block[k];
|
|
716
|
+
}
|
|
717
|
+
let t = 0;
|
|
718
|
+
for (let round2 = 0; round2 < 18; round2++) {
|
|
719
|
+
for (let k = 0; k < 48; k++) {
|
|
720
|
+
x[k] = x[k] ^ S[t];
|
|
721
|
+
t = x[k];
|
|
722
|
+
}
|
|
723
|
+
t = t + round2 & 255;
|
|
724
|
+
}
|
|
725
|
+
state.set(x.subarray(0, 16));
|
|
726
|
+
t = checksum[15];
|
|
727
|
+
for (let k = 0; k < 16; k++) {
|
|
728
|
+
checksum[k] = checksum[k] ^ S[block[k] ^ t];
|
|
729
|
+
t = checksum[k];
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
function md2(message) {
|
|
733
|
+
const padLength = 16 - message.length % 16;
|
|
734
|
+
const padded = new Uint8Array(message.length + padLength);
|
|
735
|
+
padded.set(message);
|
|
736
|
+
padded.fill(padLength, message.length);
|
|
737
|
+
const state = new Uint8Array(16);
|
|
738
|
+
const checksum = new Uint8Array(16);
|
|
739
|
+
for (let offset = 0; offset < padded.length; offset += 16) {
|
|
740
|
+
transform(state, checksum, padded.subarray(offset, offset + 16));
|
|
741
|
+
}
|
|
742
|
+
transform(state, checksum, checksum.slice());
|
|
743
|
+
return state;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// digest/bit-ops.ts
|
|
747
|
+
function rotl32(x, n) {
|
|
748
|
+
return (x << n | x >>> 32 - n) >>> 0;
|
|
749
|
+
}
|
|
750
|
+
function add32(...values) {
|
|
751
|
+
let sum = 0;
|
|
752
|
+
for (const value of values) sum = sum + value >>> 0;
|
|
753
|
+
return sum;
|
|
754
|
+
}
|
|
755
|
+
function padMd4Style(message) {
|
|
756
|
+
const paddedLength = message.length + 9 + 63 & -64;
|
|
757
|
+
const padded = new Uint8Array(paddedLength);
|
|
758
|
+
padded.set(message);
|
|
759
|
+
padded[message.length] = 128;
|
|
760
|
+
new DataView(padded.buffer).setBigUint64(paddedLength - 8, BigInt(message.length) * 8n, true);
|
|
761
|
+
return padded;
|
|
762
|
+
}
|
|
763
|
+
function applyRotatingRound(r, ops, f6, x, feedback = false) {
|
|
764
|
+
let target = 0;
|
|
765
|
+
for (const [k, s, addConst] of ops) {
|
|
766
|
+
const i1 = target + 1 & 3;
|
|
767
|
+
const next = r[i1];
|
|
768
|
+
const rotated = rotl32(
|
|
769
|
+
add32(r[target], f6(next, r[target + 2 & 3], r[target + 3 & 3]), x[k], addConst),
|
|
770
|
+
s
|
|
771
|
+
);
|
|
772
|
+
r[target] = feedback ? add32(next, rotated) : rotated;
|
|
773
|
+
target = target + 3 & 3;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function mdStyleDigest(message, initialState, transform6) {
|
|
777
|
+
const padded = padMd4Style(message);
|
|
778
|
+
const view = new DataView(padded.buffer);
|
|
779
|
+
const state = [...initialState];
|
|
780
|
+
const words2 = new Array(16).fill(0);
|
|
781
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
782
|
+
for (let i2 = 0; i2 < 16; i2++) words2[i2] = view.getUint32(offset + i2 * 4, true);
|
|
783
|
+
transform6(state, words2);
|
|
784
|
+
}
|
|
785
|
+
const out = new Uint8Array(state.length * 4);
|
|
786
|
+
const outView = new DataView(out.buffer);
|
|
787
|
+
for (let i2 = 0; i2 < state.length; i2++) outView.setUint32(i2 * 4, state[i2], true);
|
|
788
|
+
return out;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// digest/md4.ts
|
|
792
|
+
var INITIAL_STATE = [1732584193, 4023233417, 2562383102, 271733878];
|
|
793
|
+
var K2 = 1518500249;
|
|
794
|
+
var K3 = 1859775393;
|
|
795
|
+
var f1 = (x, y, z) => x & y | ~x & z;
|
|
796
|
+
var f2 = (x, y, z) => x & y | x & z | y & z;
|
|
797
|
+
var f3 = (x, y, z) => x ^ y ^ z;
|
|
798
|
+
function round(order, shifts, k) {
|
|
799
|
+
return order.map((word, i2) => [word, shifts[i2 % 4], k]);
|
|
800
|
+
}
|
|
801
|
+
var SEQUENTIAL = Array.from({ length: 16 }, (_, i2) => i2);
|
|
802
|
+
var COLUMNS = Array.from({ length: 16 }, (_, i2) => i2 % 4 * 4 + (i2 >> 2));
|
|
803
|
+
var BIT_REVERSED = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15];
|
|
804
|
+
var ROUND1 = round(SEQUENTIAL, [3, 7, 11, 19], 0);
|
|
805
|
+
var ROUND2 = round(COLUMNS, [3, 5, 9, 13], K2);
|
|
806
|
+
var ROUND3 = round(BIT_REVERSED, [3, 9, 11, 15], K3);
|
|
807
|
+
function transform2(state, x) {
|
|
808
|
+
const r = [...state];
|
|
809
|
+
applyRotatingRound(r, ROUND1, f1, x);
|
|
810
|
+
applyRotatingRound(r, ROUND2, f2, x);
|
|
811
|
+
applyRotatingRound(r, ROUND3, f3, x);
|
|
812
|
+
for (let i2 = 0; i2 < 4; i2++) state[i2] = add32(state[i2], r[i2]);
|
|
813
|
+
}
|
|
814
|
+
function md4(message) {
|
|
815
|
+
return mdStyleDigest(message, INITIAL_STATE, transform2);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// digest/md5.ts
|
|
819
|
+
var INITIAL_STATE2 = [1732584193, 4023233417, 2562383102, 271733878];
|
|
820
|
+
function f(x, y, z) {
|
|
821
|
+
return x & y | ~x & z;
|
|
822
|
+
}
|
|
823
|
+
function g(x, y, z) {
|
|
824
|
+
return x & z | y & ~z;
|
|
825
|
+
}
|
|
826
|
+
function h(x, y, z) {
|
|
827
|
+
return x ^ y ^ z;
|
|
828
|
+
}
|
|
829
|
+
function i(x, y, z) {
|
|
830
|
+
return y ^ (x | ~z);
|
|
831
|
+
}
|
|
832
|
+
var T = Array.from(
|
|
833
|
+
{ length: 64 },
|
|
834
|
+
(_, index) => Math.floor(Math.abs(Math.sin(index + 1)) * 2 ** 32)
|
|
835
|
+
);
|
|
836
|
+
var SHIFTS = [
|
|
837
|
+
[7, 12, 17, 22],
|
|
838
|
+
[5, 9, 14, 20],
|
|
839
|
+
[4, 11, 16, 23],
|
|
840
|
+
[6, 10, 15, 21]
|
|
841
|
+
];
|
|
842
|
+
var WORD_INDEX = [
|
|
843
|
+
(idx) => idx,
|
|
844
|
+
(idx) => (5 * idx + 1) % 16,
|
|
845
|
+
(idx) => (3 * idx + 5) % 16,
|
|
846
|
+
(idx) => 7 * idx % 16
|
|
847
|
+
];
|
|
848
|
+
var ROUND_FNS = [f, g, h, i];
|
|
849
|
+
function buildOps(round2) {
|
|
850
|
+
const shifts = SHIFTS[round2];
|
|
851
|
+
const wordIndex = WORD_INDEX[round2];
|
|
852
|
+
return Array.from({ length: 16 }, (_, idx) => {
|
|
853
|
+
const opNumber = round2 * 16 + idx;
|
|
854
|
+
return [wordIndex(idx), shifts[idx % 4], T[opNumber]];
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
var ROUNDS = [0, 1, 2, 3].map(buildOps);
|
|
858
|
+
function transform3(state, x) {
|
|
859
|
+
const r = [...state];
|
|
860
|
+
for (let round2 = 0; round2 < 4; round2++) {
|
|
861
|
+
applyRotatingRound(r, ROUNDS[round2], ROUND_FNS[round2], x, true);
|
|
862
|
+
}
|
|
863
|
+
for (let idx = 0; idx < 4; idx++) {
|
|
864
|
+
state[idx] = add32(state[idx], r[idx]);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
function md5(message) {
|
|
868
|
+
return mdStyleDigest(message, INITIAL_STATE2, transform3);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// digest/ripemd-functions.ts
|
|
872
|
+
function f12(x, y, z) {
|
|
873
|
+
return x ^ y ^ z;
|
|
874
|
+
}
|
|
875
|
+
function f22(x, y, z) {
|
|
876
|
+
return x & y | ~x & z;
|
|
877
|
+
}
|
|
878
|
+
function f32(x, y, z) {
|
|
879
|
+
return (x | ~y) ^ z;
|
|
880
|
+
}
|
|
881
|
+
function f4(x, y, z) {
|
|
882
|
+
return z & x | ~z & y;
|
|
883
|
+
}
|
|
884
|
+
function f5(x, y, z) {
|
|
885
|
+
return x ^ (y | ~z);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// digest/ripemd128.ts
|
|
889
|
+
var INITIAL_STATE3 = [1732584193, 4023233417, 2562383102, 271733878];
|
|
890
|
+
var LEFT_ROUNDS = [
|
|
891
|
+
[
|
|
892
|
+
[0, 11, 0],
|
|
893
|
+
[1, 14, 0],
|
|
894
|
+
[2, 15, 0],
|
|
895
|
+
[3, 12, 0],
|
|
896
|
+
[4, 5, 0],
|
|
897
|
+
[5, 8, 0],
|
|
898
|
+
[6, 7, 0],
|
|
899
|
+
[7, 9, 0],
|
|
900
|
+
[8, 11, 0],
|
|
901
|
+
[9, 13, 0],
|
|
902
|
+
[10, 14, 0],
|
|
903
|
+
[11, 15, 0],
|
|
904
|
+
[12, 6, 0],
|
|
905
|
+
[13, 7, 0],
|
|
906
|
+
[14, 9, 0],
|
|
907
|
+
[15, 8, 0]
|
|
908
|
+
],
|
|
909
|
+
[
|
|
910
|
+
[7, 7, 1518500249],
|
|
911
|
+
[4, 6, 1518500249],
|
|
912
|
+
[13, 8, 1518500249],
|
|
913
|
+
[1, 13, 1518500249],
|
|
914
|
+
[10, 11, 1518500249],
|
|
915
|
+
[6, 9, 1518500249],
|
|
916
|
+
[15, 7, 1518500249],
|
|
917
|
+
[3, 15, 1518500249],
|
|
918
|
+
[12, 7, 1518500249],
|
|
919
|
+
[0, 12, 1518500249],
|
|
920
|
+
[9, 15, 1518500249],
|
|
921
|
+
[5, 9, 1518500249],
|
|
922
|
+
[2, 11, 1518500249],
|
|
923
|
+
[14, 7, 1518500249],
|
|
924
|
+
[11, 13, 1518500249],
|
|
925
|
+
[8, 12, 1518500249]
|
|
926
|
+
],
|
|
927
|
+
[
|
|
928
|
+
[3, 11, 1859775393],
|
|
929
|
+
[10, 13, 1859775393],
|
|
930
|
+
[14, 6, 1859775393],
|
|
931
|
+
[4, 7, 1859775393],
|
|
932
|
+
[9, 14, 1859775393],
|
|
933
|
+
[15, 9, 1859775393],
|
|
934
|
+
[8, 13, 1859775393],
|
|
935
|
+
[1, 15, 1859775393],
|
|
936
|
+
[2, 14, 1859775393],
|
|
937
|
+
[7, 8, 1859775393],
|
|
938
|
+
[0, 13, 1859775393],
|
|
939
|
+
[6, 6, 1859775393],
|
|
940
|
+
[13, 5, 1859775393],
|
|
941
|
+
[11, 12, 1859775393],
|
|
942
|
+
[5, 7, 1859775393],
|
|
943
|
+
[12, 5, 1859775393]
|
|
944
|
+
],
|
|
945
|
+
[
|
|
946
|
+
[1, 11, 2400959708],
|
|
947
|
+
[9, 12, 2400959708],
|
|
948
|
+
[11, 14, 2400959708],
|
|
949
|
+
[10, 15, 2400959708],
|
|
950
|
+
[0, 14, 2400959708],
|
|
951
|
+
[8, 15, 2400959708],
|
|
952
|
+
[12, 9, 2400959708],
|
|
953
|
+
[4, 8, 2400959708],
|
|
954
|
+
[13, 9, 2400959708],
|
|
955
|
+
[3, 14, 2400959708],
|
|
956
|
+
[7, 5, 2400959708],
|
|
957
|
+
[15, 6, 2400959708],
|
|
958
|
+
[14, 8, 2400959708],
|
|
959
|
+
[5, 6, 2400959708],
|
|
960
|
+
[6, 5, 2400959708],
|
|
961
|
+
[2, 12, 2400959708]
|
|
962
|
+
]
|
|
963
|
+
];
|
|
964
|
+
var RIGHT_ROUNDS = [
|
|
965
|
+
[
|
|
966
|
+
[5, 8, 1352829926],
|
|
967
|
+
[14, 9, 1352829926],
|
|
968
|
+
[7, 9, 1352829926],
|
|
969
|
+
[0, 11, 1352829926],
|
|
970
|
+
[9, 13, 1352829926],
|
|
971
|
+
[2, 15, 1352829926],
|
|
972
|
+
[11, 15, 1352829926],
|
|
973
|
+
[4, 5, 1352829926],
|
|
974
|
+
[13, 7, 1352829926],
|
|
975
|
+
[6, 7, 1352829926],
|
|
976
|
+
[15, 8, 1352829926],
|
|
977
|
+
[8, 11, 1352829926],
|
|
978
|
+
[1, 14, 1352829926],
|
|
979
|
+
[10, 14, 1352829926],
|
|
980
|
+
[3, 12, 1352829926],
|
|
981
|
+
[12, 6, 1352829926]
|
|
982
|
+
],
|
|
983
|
+
[
|
|
984
|
+
[6, 9, 1548603684],
|
|
985
|
+
[11, 13, 1548603684],
|
|
986
|
+
[3, 15, 1548603684],
|
|
987
|
+
[7, 7, 1548603684],
|
|
988
|
+
[0, 12, 1548603684],
|
|
989
|
+
[13, 8, 1548603684],
|
|
990
|
+
[5, 9, 1548603684],
|
|
991
|
+
[10, 11, 1548603684],
|
|
992
|
+
[14, 7, 1548603684],
|
|
993
|
+
[15, 7, 1548603684],
|
|
994
|
+
[8, 12, 1548603684],
|
|
995
|
+
[12, 7, 1548603684],
|
|
996
|
+
[4, 6, 1548603684],
|
|
997
|
+
[9, 15, 1548603684],
|
|
998
|
+
[1, 13, 1548603684],
|
|
999
|
+
[2, 11, 1548603684]
|
|
1000
|
+
],
|
|
1001
|
+
[
|
|
1002
|
+
[15, 9, 1836072691],
|
|
1003
|
+
[5, 7, 1836072691],
|
|
1004
|
+
[1, 15, 1836072691],
|
|
1005
|
+
[3, 11, 1836072691],
|
|
1006
|
+
[7, 8, 1836072691],
|
|
1007
|
+
[14, 6, 1836072691],
|
|
1008
|
+
[6, 6, 1836072691],
|
|
1009
|
+
[9, 14, 1836072691],
|
|
1010
|
+
[11, 12, 1836072691],
|
|
1011
|
+
[8, 13, 1836072691],
|
|
1012
|
+
[12, 5, 1836072691],
|
|
1013
|
+
[2, 14, 1836072691],
|
|
1014
|
+
[10, 13, 1836072691],
|
|
1015
|
+
[0, 13, 1836072691],
|
|
1016
|
+
[4, 7, 1836072691],
|
|
1017
|
+
[13, 5, 1836072691]
|
|
1018
|
+
],
|
|
1019
|
+
[
|
|
1020
|
+
[8, 15, 0],
|
|
1021
|
+
[6, 5, 0],
|
|
1022
|
+
[4, 8, 0],
|
|
1023
|
+
[1, 11, 0],
|
|
1024
|
+
[3, 14, 0],
|
|
1025
|
+
[11, 14, 0],
|
|
1026
|
+
[15, 6, 0],
|
|
1027
|
+
[0, 14, 0],
|
|
1028
|
+
[5, 6, 0],
|
|
1029
|
+
[12, 9, 0],
|
|
1030
|
+
[2, 12, 0],
|
|
1031
|
+
[13, 9, 0],
|
|
1032
|
+
[9, 12, 0],
|
|
1033
|
+
[7, 5, 0],
|
|
1034
|
+
[10, 15, 0],
|
|
1035
|
+
[14, 8, 0]
|
|
1036
|
+
]
|
|
1037
|
+
];
|
|
1038
|
+
var LEFT_FNS = [f12, f22, f32, f4];
|
|
1039
|
+
var RIGHT_FNS = [f4, f32, f22, f12];
|
|
1040
|
+
function transform4(state, x) {
|
|
1041
|
+
const left = [...state];
|
|
1042
|
+
const right = [...state];
|
|
1043
|
+
for (let round2 = 0; round2 < 4; round2++) {
|
|
1044
|
+
applyRotatingRound(left, LEFT_ROUNDS[round2], LEFT_FNS[round2], x);
|
|
1045
|
+
applyRotatingRound(right, RIGHT_ROUNDS[round2], RIGHT_FNS[round2], x);
|
|
1046
|
+
}
|
|
1047
|
+
const orig = state;
|
|
1048
|
+
const newState = [
|
|
1049
|
+
add32(right[3], left[2], orig[1]),
|
|
1050
|
+
add32(orig[2], left[3], right[0]),
|
|
1051
|
+
add32(orig[3], left[0], right[1]),
|
|
1052
|
+
add32(orig[0], left[1], right[2])
|
|
1053
|
+
];
|
|
1054
|
+
for (let i2 = 0; i2 < 4; i2++) {
|
|
1055
|
+
state[i2] = newState[i2];
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
function ripemd128(message) {
|
|
1059
|
+
return mdStyleDigest(message, INITIAL_STATE3, transform4);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// digest/ripemd160.ts
|
|
1063
|
+
var INITIAL_STATE4 = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
1064
|
+
var LEFT_ROUNDS2 = [
|
|
1065
|
+
[
|
|
1066
|
+
[0, 11, 0],
|
|
1067
|
+
[1, 14, 0],
|
|
1068
|
+
[2, 15, 0],
|
|
1069
|
+
[3, 12, 0],
|
|
1070
|
+
[4, 5, 0],
|
|
1071
|
+
[5, 8, 0],
|
|
1072
|
+
[6, 7, 0],
|
|
1073
|
+
[7, 9, 0],
|
|
1074
|
+
[8, 11, 0],
|
|
1075
|
+
[9, 13, 0],
|
|
1076
|
+
[10, 14, 0],
|
|
1077
|
+
[11, 15, 0],
|
|
1078
|
+
[12, 6, 0],
|
|
1079
|
+
[13, 7, 0],
|
|
1080
|
+
[14, 9, 0],
|
|
1081
|
+
[15, 8, 0]
|
|
1082
|
+
],
|
|
1083
|
+
[
|
|
1084
|
+
[7, 7, 1518500249],
|
|
1085
|
+
[4, 6, 1518500249],
|
|
1086
|
+
[13, 8, 1518500249],
|
|
1087
|
+
[1, 13, 1518500249],
|
|
1088
|
+
[10, 11, 1518500249],
|
|
1089
|
+
[6, 9, 1518500249],
|
|
1090
|
+
[15, 7, 1518500249],
|
|
1091
|
+
[3, 15, 1518500249],
|
|
1092
|
+
[12, 7, 1518500249],
|
|
1093
|
+
[0, 12, 1518500249],
|
|
1094
|
+
[9, 15, 1518500249],
|
|
1095
|
+
[5, 9, 1518500249],
|
|
1096
|
+
[2, 11, 1518500249],
|
|
1097
|
+
[14, 7, 1518500249],
|
|
1098
|
+
[11, 13, 1518500249],
|
|
1099
|
+
[8, 12, 1518500249]
|
|
1100
|
+
],
|
|
1101
|
+
[
|
|
1102
|
+
[3, 11, 1859775393],
|
|
1103
|
+
[10, 13, 1859775393],
|
|
1104
|
+
[14, 6, 1859775393],
|
|
1105
|
+
[4, 7, 1859775393],
|
|
1106
|
+
[9, 14, 1859775393],
|
|
1107
|
+
[15, 9, 1859775393],
|
|
1108
|
+
[8, 13, 1859775393],
|
|
1109
|
+
[1, 15, 1859775393],
|
|
1110
|
+
[2, 14, 1859775393],
|
|
1111
|
+
[7, 8, 1859775393],
|
|
1112
|
+
[0, 13, 1859775393],
|
|
1113
|
+
[6, 6, 1859775393],
|
|
1114
|
+
[13, 5, 1859775393],
|
|
1115
|
+
[11, 12, 1859775393],
|
|
1116
|
+
[5, 7, 1859775393],
|
|
1117
|
+
[12, 5, 1859775393]
|
|
1118
|
+
],
|
|
1119
|
+
[
|
|
1120
|
+
[1, 11, 2400959708],
|
|
1121
|
+
[9, 12, 2400959708],
|
|
1122
|
+
[11, 14, 2400959708],
|
|
1123
|
+
[10, 15, 2400959708],
|
|
1124
|
+
[0, 14, 2400959708],
|
|
1125
|
+
[8, 15, 2400959708],
|
|
1126
|
+
[12, 9, 2400959708],
|
|
1127
|
+
[4, 8, 2400959708],
|
|
1128
|
+
[13, 9, 2400959708],
|
|
1129
|
+
[3, 14, 2400959708],
|
|
1130
|
+
[7, 5, 2400959708],
|
|
1131
|
+
[15, 6, 2400959708],
|
|
1132
|
+
[14, 8, 2400959708],
|
|
1133
|
+
[5, 6, 2400959708],
|
|
1134
|
+
[6, 5, 2400959708],
|
|
1135
|
+
[2, 12, 2400959708]
|
|
1136
|
+
],
|
|
1137
|
+
[
|
|
1138
|
+
[4, 9, 2840853838],
|
|
1139
|
+
[0, 15, 2840853838],
|
|
1140
|
+
[5, 5, 2840853838],
|
|
1141
|
+
[9, 11, 2840853838],
|
|
1142
|
+
[7, 6, 2840853838],
|
|
1143
|
+
[12, 8, 2840853838],
|
|
1144
|
+
[2, 13, 2840853838],
|
|
1145
|
+
[10, 12, 2840853838],
|
|
1146
|
+
[14, 5, 2840853838],
|
|
1147
|
+
[1, 12, 2840853838],
|
|
1148
|
+
[3, 13, 2840853838],
|
|
1149
|
+
[8, 14, 2840853838],
|
|
1150
|
+
[11, 11, 2840853838],
|
|
1151
|
+
[6, 8, 2840853838],
|
|
1152
|
+
[15, 5, 2840853838],
|
|
1153
|
+
[13, 6, 2840853838]
|
|
1154
|
+
]
|
|
1155
|
+
];
|
|
1156
|
+
var RIGHT_ROUNDS2 = [
|
|
1157
|
+
[
|
|
1158
|
+
[5, 8, 1352829926],
|
|
1159
|
+
[14, 9, 1352829926],
|
|
1160
|
+
[7, 9, 1352829926],
|
|
1161
|
+
[0, 11, 1352829926],
|
|
1162
|
+
[9, 13, 1352829926],
|
|
1163
|
+
[2, 15, 1352829926],
|
|
1164
|
+
[11, 15, 1352829926],
|
|
1165
|
+
[4, 5, 1352829926],
|
|
1166
|
+
[13, 7, 1352829926],
|
|
1167
|
+
[6, 7, 1352829926],
|
|
1168
|
+
[15, 8, 1352829926],
|
|
1169
|
+
[8, 11, 1352829926],
|
|
1170
|
+
[1, 14, 1352829926],
|
|
1171
|
+
[10, 14, 1352829926],
|
|
1172
|
+
[3, 12, 1352829926],
|
|
1173
|
+
[12, 6, 1352829926]
|
|
1174
|
+
],
|
|
1175
|
+
[
|
|
1176
|
+
[6, 9, 1548603684],
|
|
1177
|
+
[11, 13, 1548603684],
|
|
1178
|
+
[3, 15, 1548603684],
|
|
1179
|
+
[7, 7, 1548603684],
|
|
1180
|
+
[0, 12, 1548603684],
|
|
1181
|
+
[13, 8, 1548603684],
|
|
1182
|
+
[5, 9, 1548603684],
|
|
1183
|
+
[10, 11, 1548603684],
|
|
1184
|
+
[14, 7, 1548603684],
|
|
1185
|
+
[15, 7, 1548603684],
|
|
1186
|
+
[8, 12, 1548603684],
|
|
1187
|
+
[12, 7, 1548603684],
|
|
1188
|
+
[4, 6, 1548603684],
|
|
1189
|
+
[9, 15, 1548603684],
|
|
1190
|
+
[1, 13, 1548603684],
|
|
1191
|
+
[2, 11, 1548603684]
|
|
1192
|
+
],
|
|
1193
|
+
[
|
|
1194
|
+
[15, 9, 1836072691],
|
|
1195
|
+
[5, 7, 1836072691],
|
|
1196
|
+
[1, 15, 1836072691],
|
|
1197
|
+
[3, 11, 1836072691],
|
|
1198
|
+
[7, 8, 1836072691],
|
|
1199
|
+
[14, 6, 1836072691],
|
|
1200
|
+
[6, 6, 1836072691],
|
|
1201
|
+
[9, 14, 1836072691],
|
|
1202
|
+
[11, 12, 1836072691],
|
|
1203
|
+
[8, 13, 1836072691],
|
|
1204
|
+
[12, 5, 1836072691],
|
|
1205
|
+
[2, 14, 1836072691],
|
|
1206
|
+
[10, 13, 1836072691],
|
|
1207
|
+
[0, 13, 1836072691],
|
|
1208
|
+
[4, 7, 1836072691],
|
|
1209
|
+
[13, 5, 1836072691]
|
|
1210
|
+
],
|
|
1211
|
+
[
|
|
1212
|
+
[8, 15, 2053994217],
|
|
1213
|
+
[6, 5, 2053994217],
|
|
1214
|
+
[4, 8, 2053994217],
|
|
1215
|
+
[1, 11, 2053994217],
|
|
1216
|
+
[3, 14, 2053994217],
|
|
1217
|
+
[11, 14, 2053994217],
|
|
1218
|
+
[15, 6, 2053994217],
|
|
1219
|
+
[0, 14, 2053994217],
|
|
1220
|
+
[5, 6, 2053994217],
|
|
1221
|
+
[12, 9, 2053994217],
|
|
1222
|
+
[2, 12, 2053994217],
|
|
1223
|
+
[13, 9, 2053994217],
|
|
1224
|
+
[9, 12, 2053994217],
|
|
1225
|
+
[7, 5, 2053994217],
|
|
1226
|
+
[10, 15, 2053994217],
|
|
1227
|
+
[14, 8, 2053994217]
|
|
1228
|
+
],
|
|
1229
|
+
[
|
|
1230
|
+
[12, 8, 0],
|
|
1231
|
+
[15, 5, 0],
|
|
1232
|
+
[10, 12, 0],
|
|
1233
|
+
[4, 9, 0],
|
|
1234
|
+
[1, 12, 0],
|
|
1235
|
+
[5, 5, 0],
|
|
1236
|
+
[8, 14, 0],
|
|
1237
|
+
[7, 6, 0],
|
|
1238
|
+
[6, 8, 0],
|
|
1239
|
+
[2, 13, 0],
|
|
1240
|
+
[13, 6, 0],
|
|
1241
|
+
[14, 5, 0],
|
|
1242
|
+
[0, 15, 0],
|
|
1243
|
+
[3, 13, 0],
|
|
1244
|
+
[9, 11, 0],
|
|
1245
|
+
[11, 11, 0]
|
|
1246
|
+
]
|
|
1247
|
+
];
|
|
1248
|
+
var LEFT_FNS2 = [f12, f22, f32, f4, f5];
|
|
1249
|
+
var RIGHT_FNS2 = [f5, f4, f32, f22, f12];
|
|
1250
|
+
function applyLane(r, ops, f6, x, startTarget) {
|
|
1251
|
+
let target = startTarget;
|
|
1252
|
+
for (const [k, s, addConst] of ops) {
|
|
1253
|
+
const i1 = (target + 1) % 5;
|
|
1254
|
+
const i2 = (target + 2) % 5;
|
|
1255
|
+
const i3 = (target + 3) % 5;
|
|
1256
|
+
const i4 = (target + 4) % 5;
|
|
1257
|
+
const sum = r[target] + f6(r[i1], r[i2], r[i3]) + x[k] + addConst >>> 0;
|
|
1258
|
+
const newTarget = (sum << s | sum >>> 32 - s) + r[i4] >>> 0;
|
|
1259
|
+
const c = r[i2];
|
|
1260
|
+
r[i2] = (c << 10 | c >>> 22) >>> 0;
|
|
1261
|
+
r[target] = newTarget;
|
|
1262
|
+
target = (target + 4) % 5;
|
|
1263
|
+
}
|
|
1264
|
+
return target;
|
|
1265
|
+
}
|
|
1266
|
+
function transform5(state, x) {
|
|
1267
|
+
const left = [...state];
|
|
1268
|
+
const right = [...state];
|
|
1269
|
+
let leftTarget = 0;
|
|
1270
|
+
let rightTarget = 0;
|
|
1271
|
+
for (let round2 = 0; round2 < 5; round2++) {
|
|
1272
|
+
leftTarget = applyLane(left, LEFT_ROUNDS2[round2], LEFT_FNS2[round2], x, leftTarget);
|
|
1273
|
+
rightTarget = applyLane(right, RIGHT_ROUNDS2[round2], RIGHT_FNS2[round2], x, rightTarget);
|
|
1274
|
+
}
|
|
1275
|
+
const orig = state;
|
|
1276
|
+
const newState = [
|
|
1277
|
+
add32(right[3], left[2], orig[1]),
|
|
1278
|
+
add32(orig[2], left[3], right[4]),
|
|
1279
|
+
add32(orig[3], left[4], right[0]),
|
|
1280
|
+
add32(orig[4], left[0], right[1]),
|
|
1281
|
+
add32(orig[0], left[1], right[2])
|
|
1282
|
+
];
|
|
1283
|
+
for (let i2 = 0; i2 < 5; i2++) {
|
|
1284
|
+
state[i2] = newState[i2];
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
function ripemd160(message) {
|
|
1288
|
+
return mdStyleDigest(message, INITIAL_STATE4, transform5);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
451
1291
|
// digest/sha256.ts
|
|
452
1292
|
var K = new Uint32Array([
|
|
453
1293
|
1116352408,
|
|
@@ -527,40 +1367,40 @@ var IV = [
|
|
|
527
1367
|
];
|
|
528
1368
|
var W = new Uint32Array(64);
|
|
529
1369
|
var rotr = (x, n) => x >>> n | x << 32 - n;
|
|
530
|
-
function compress(
|
|
531
|
-
for (let
|
|
532
|
-
for (let
|
|
533
|
-
const a2 = W[
|
|
534
|
-
const b2 = W[
|
|
1370
|
+
function compress(h2, view, offset) {
|
|
1371
|
+
for (let i2 = 0; i2 < 16; i2++) W[i2] = view.getUint32(offset + i2 * 4);
|
|
1372
|
+
for (let i2 = 16; i2 < 64; i2++) {
|
|
1373
|
+
const a2 = W[i2 - 15];
|
|
1374
|
+
const b2 = W[i2 - 2];
|
|
535
1375
|
const s0 = rotr(a2, 7) ^ rotr(a2, 18) ^ a2 >>> 3;
|
|
536
1376
|
const s1 = rotr(b2, 17) ^ rotr(b2, 19) ^ b2 >>> 10;
|
|
537
|
-
W[
|
|
1377
|
+
W[i2] = W[i2 - 16] + s0 + W[i2 - 7] + s1 >>> 0;
|
|
538
1378
|
}
|
|
539
|
-
let a =
|
|
540
|
-
for (let
|
|
1379
|
+
let a = h2[0], b = h2[1], c = h2[2], d = h2[3], e = h2[4], f6 = h2[5], g2 = h2[6], k = h2[7];
|
|
1380
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
541
1381
|
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
542
|
-
const ch = e &
|
|
543
|
-
const t1 = k + S1 + ch + K[
|
|
1382
|
+
const ch = e & f6 ^ ~e & g2;
|
|
1383
|
+
const t1 = k + S1 + ch + K[i2] + W[i2] >>> 0;
|
|
544
1384
|
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
545
1385
|
const maj = a & b ^ a & c ^ b & c;
|
|
546
1386
|
const t2 = S0 + maj >>> 0;
|
|
547
|
-
k =
|
|
548
|
-
|
|
549
|
-
|
|
1387
|
+
k = g2;
|
|
1388
|
+
g2 = f6;
|
|
1389
|
+
f6 = e;
|
|
550
1390
|
e = d + t1 >>> 0;
|
|
551
1391
|
d = c;
|
|
552
1392
|
c = b;
|
|
553
1393
|
b = a;
|
|
554
1394
|
a = t1 + t2 >>> 0;
|
|
555
1395
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
1396
|
+
h2[0] = h2[0] + a >>> 0;
|
|
1397
|
+
h2[1] = h2[1] + b >>> 0;
|
|
1398
|
+
h2[2] = h2[2] + c >>> 0;
|
|
1399
|
+
h2[3] = h2[3] + d >>> 0;
|
|
1400
|
+
h2[4] = h2[4] + e >>> 0;
|
|
1401
|
+
h2[5] = h2[5] + f6 >>> 0;
|
|
1402
|
+
h2[6] = h2[6] + g2 >>> 0;
|
|
1403
|
+
h2[7] = h2[7] + k >>> 0;
|
|
564
1404
|
}
|
|
565
1405
|
function pad64(data) {
|
|
566
1406
|
const padded = new Uint8Array(Math.ceil((data.length + 9) / 64) * 64);
|
|
@@ -572,64 +1412,64 @@ function pad64(data) {
|
|
|
572
1412
|
view.setUint32(padded.length - 4, bits >>> 0);
|
|
573
1413
|
return view;
|
|
574
1414
|
}
|
|
575
|
-
function wordsOut(
|
|
576
|
-
const out = new Uint8Array(
|
|
1415
|
+
function wordsOut(h2) {
|
|
1416
|
+
const out = new Uint8Array(h2.length * 4);
|
|
577
1417
|
const view = new DataView(out.buffer);
|
|
578
|
-
for (let
|
|
1418
|
+
for (let i2 = 0; i2 < h2.length; i2++) view.setUint32(i2 * 4, h2[i2]);
|
|
579
1419
|
return out;
|
|
580
1420
|
}
|
|
581
1421
|
function sha256(data) {
|
|
582
|
-
const
|
|
1422
|
+
const h2 = new Uint32Array(IV);
|
|
583
1423
|
const view = pad64(data);
|
|
584
|
-
for (let offset = 0; offset < view.byteLength; offset += 64) compress(
|
|
585
|
-
return wordsOut(
|
|
1424
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) compress(h2, view, offset);
|
|
1425
|
+
return wordsOut(h2);
|
|
586
1426
|
}
|
|
587
1427
|
|
|
588
1428
|
// digest/sha1.ts
|
|
589
1429
|
var W2 = new Uint32Array(80);
|
|
590
1430
|
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
591
|
-
function compress2(
|
|
592
|
-
for (let
|
|
593
|
-
for (let
|
|
594
|
-
let a =
|
|
595
|
-
for (let
|
|
596
|
-
let
|
|
1431
|
+
function compress2(h2, view, offset) {
|
|
1432
|
+
for (let i2 = 0; i2 < 16; i2++) W2[i2] = view.getUint32(offset + i2 * 4);
|
|
1433
|
+
for (let i2 = 16; i2 < 80; i2++) W2[i2] = rotl(W2[i2 - 3] ^ W2[i2 - 8] ^ W2[i2 - 14] ^ W2[i2 - 16], 1);
|
|
1434
|
+
let a = h2[0], b = h2[1], c = h2[2], d = h2[3], e = h2[4];
|
|
1435
|
+
for (let i2 = 0; i2 < 80; i2++) {
|
|
1436
|
+
let f6;
|
|
597
1437
|
let k;
|
|
598
|
-
if (
|
|
599
|
-
|
|
1438
|
+
if (i2 < 20) {
|
|
1439
|
+
f6 = b & c | ~b & d;
|
|
600
1440
|
k = 1518500249;
|
|
601
|
-
} else if (
|
|
602
|
-
|
|
1441
|
+
} else if (i2 < 40) {
|
|
1442
|
+
f6 = b ^ c ^ d;
|
|
603
1443
|
k = 1859775393;
|
|
604
|
-
} else if (
|
|
605
|
-
|
|
1444
|
+
} else if (i2 < 60) {
|
|
1445
|
+
f6 = b & c | b & d | c & d;
|
|
606
1446
|
k = 2400959708;
|
|
607
1447
|
} else {
|
|
608
|
-
|
|
1448
|
+
f6 = b ^ c ^ d;
|
|
609
1449
|
k = 3395469782;
|
|
610
1450
|
}
|
|
611
|
-
const t = rotl(a, 5) +
|
|
1451
|
+
const t = rotl(a, 5) + f6 + e + k + W2[i2] >>> 0;
|
|
612
1452
|
e = d;
|
|
613
1453
|
d = c;
|
|
614
1454
|
c = rotl(b, 30) >>> 0;
|
|
615
1455
|
b = a;
|
|
616
1456
|
a = t;
|
|
617
1457
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
1458
|
+
h2[0] = h2[0] + a >>> 0;
|
|
1459
|
+
h2[1] = h2[1] + b >>> 0;
|
|
1460
|
+
h2[2] = h2[2] + c >>> 0;
|
|
1461
|
+
h2[3] = h2[3] + d >>> 0;
|
|
1462
|
+
h2[4] = h2[4] + e >>> 0;
|
|
623
1463
|
}
|
|
624
1464
|
function sha1(data) {
|
|
625
|
-
const
|
|
1465
|
+
const h2 = new Uint32Array([1732584193, 4023233417, 2562383102, 271733878, 3285377520]);
|
|
626
1466
|
const view = pad64(data);
|
|
627
|
-
for (let offset = 0; offset < view.byteLength; offset += 64) compress2(
|
|
628
|
-
return wordsOut(
|
|
1467
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) compress2(h2, view, offset);
|
|
1468
|
+
return wordsOut(h2);
|
|
629
1469
|
}
|
|
630
1470
|
|
|
631
1471
|
// digest/sha512.ts
|
|
632
|
-
var
|
|
1472
|
+
var K4 = new Uint32Array([
|
|
633
1473
|
1116352408,
|
|
634
1474
|
3609767458,
|
|
635
1475
|
1899447441,
|
|
@@ -828,35 +1668,35 @@ var IV_384 = [
|
|
|
828
1668
|
3204075428
|
|
829
1669
|
];
|
|
830
1670
|
var W3 = new Uint32Array(160);
|
|
831
|
-
function compress3(
|
|
832
|
-
for (let
|
|
833
|
-
const o = offset +
|
|
834
|
-
W3[
|
|
835
|
-
}
|
|
836
|
-
for (let
|
|
837
|
-
const xh = W3[(
|
|
838
|
-
const xl = W3[(
|
|
1671
|
+
function compress3(h2, data, offset) {
|
|
1672
|
+
for (let i2 = 0; i2 < 32; i2++) {
|
|
1673
|
+
const o = offset + i2 * 4;
|
|
1674
|
+
W3[i2] = (data[o] << 24 | data[o + 1] << 16 | data[o + 2] << 8 | data[o + 3]) >>> 0;
|
|
1675
|
+
}
|
|
1676
|
+
for (let i2 = 16; i2 < 80; i2++) {
|
|
1677
|
+
const xh = W3[(i2 - 15) * 2];
|
|
1678
|
+
const xl = W3[(i2 - 15) * 2 + 1];
|
|
839
1679
|
const s0h = (xh >>> 1 | xl << 31) ^ (xh >>> 8 | xl << 24) ^ xh >>> 7;
|
|
840
1680
|
const s0l = (xl >>> 1 | xh << 31) ^ (xl >>> 8 | xh << 24) ^ (xl >>> 7 | xh << 25);
|
|
841
|
-
const yh = W3[(
|
|
842
|
-
const yl = W3[(
|
|
1681
|
+
const yh = W3[(i2 - 2) * 2];
|
|
1682
|
+
const yl = W3[(i2 - 2) * 2 + 1];
|
|
843
1683
|
const s1h = (yh >>> 19 | yl << 13) ^ (yl >>> 29 | yh << 3) ^ yh >>> 6;
|
|
844
1684
|
const s1l = (yl >>> 19 | yh << 13) ^ (yh >>> 29 | yl << 3) ^ (yl >>> 6 | yh << 26);
|
|
845
|
-
let lo = (s0l >>> 0) + (s1l >>> 0) + W3[(
|
|
846
|
-
const hi = s0h + s1h + W3[(
|
|
1685
|
+
let lo = (s0l >>> 0) + (s1l >>> 0) + W3[(i2 - 7) * 2 + 1] + W3[(i2 - 16) * 2 + 1];
|
|
1686
|
+
const hi = s0h + s1h + W3[(i2 - 7) * 2] + W3[(i2 - 16) * 2] + Math.floor(lo / 4294967296);
|
|
847
1687
|
lo >>>= 0;
|
|
848
|
-
W3[
|
|
849
|
-
W3[
|
|
1688
|
+
W3[i2 * 2] = hi >>> 0;
|
|
1689
|
+
W3[i2 * 2 + 1] = lo;
|
|
850
1690
|
}
|
|
851
|
-
let ah =
|
|
852
|
-
let eh =
|
|
853
|
-
for (let
|
|
1691
|
+
let ah = h2[0], al = h2[1], bh = h2[2], bl = h2[3], ch = h2[4], cl = h2[5], dh = h2[6], dl = h2[7];
|
|
1692
|
+
let eh = h2[8], el3 = h2[9], fh = h2[10], fl = h2[11], gh = h2[12], gl = h2[13], hh = h2[14], hl = h2[15];
|
|
1693
|
+
for (let i2 = 0; i2 < 80; i2++) {
|
|
854
1694
|
const S1h = (eh >>> 14 | el3 << 18) ^ (eh >>> 18 | el3 << 14) ^ (el3 >>> 9 | eh << 23);
|
|
855
1695
|
const S1l = (el3 >>> 14 | eh << 18) ^ (el3 >>> 18 | eh << 14) ^ (eh >>> 9 | el3 << 23);
|
|
856
1696
|
const chh = eh & fh ^ ~eh & gh;
|
|
857
1697
|
const chl = el3 & fl ^ ~el3 & gl;
|
|
858
|
-
let t1l = (hl >>> 0) + (S1l >>> 0) + (chl >>> 0) +
|
|
859
|
-
const t1h = hh + S1h + chh +
|
|
1698
|
+
let t1l = (hl >>> 0) + (S1l >>> 0) + (chl >>> 0) + K4[i2 * 2 + 1] + W3[i2 * 2 + 1];
|
|
1699
|
+
const t1h = hh + S1h + chh + K4[i2 * 2] + W3[i2 * 2] + Math.floor(t1l / 4294967296);
|
|
860
1700
|
t1l >>>= 0;
|
|
861
1701
|
const S0h = (ah >>> 28 | al << 4) ^ (al >>> 2 | ah << 30) ^ (al >>> 7 | ah << 25);
|
|
862
1702
|
const S0l = (al >>> 28 | ah << 4) ^ (ah >>> 2 | al << 30) ^ (ah >>> 7 | al << 25);
|
|
@@ -884,10 +1724,10 @@ function compress3(h, data, offset) {
|
|
|
884
1724
|
ah = t1h + t2h + Math.floor(nl / 4294967296) >>> 0;
|
|
885
1725
|
al = nl >>> 0;
|
|
886
1726
|
}
|
|
887
|
-
const add2 = (
|
|
888
|
-
const lo = (
|
|
889
|
-
|
|
890
|
-
|
|
1727
|
+
const add2 = (i2, xh, xl) => {
|
|
1728
|
+
const lo = (h2[i2 + 1] >>> 0) + (xl >>> 0);
|
|
1729
|
+
h2[i2] = h2[i2] + xh + Math.floor(lo / 4294967296) >>> 0;
|
|
1730
|
+
h2[i2 + 1] = lo >>> 0;
|
|
891
1731
|
};
|
|
892
1732
|
add2(0, ah, al);
|
|
893
1733
|
add2(2, bh, bl);
|
|
@@ -899,7 +1739,7 @@ function compress3(h, data, offset) {
|
|
|
899
1739
|
add2(14, hh, hl);
|
|
900
1740
|
}
|
|
901
1741
|
function digest64(data, iv, bytes) {
|
|
902
|
-
const
|
|
1742
|
+
const h2 = new Uint32Array(iv);
|
|
903
1743
|
const padded = new Uint8Array(Math.ceil((data.length + 17) / 128) * 128);
|
|
904
1744
|
padded.set(data);
|
|
905
1745
|
padded[data.length] = 128;
|
|
@@ -907,25 +1747,407 @@ function digest64(data, iv, bytes) {
|
|
|
907
1747
|
const view = new DataView(padded.buffer);
|
|
908
1748
|
view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
|
|
909
1749
|
view.setUint32(padded.length - 4, bits >>> 0);
|
|
910
|
-
for (let offset = 0; offset < padded.length; offset += 128) compress3(
|
|
1750
|
+
for (let offset = 0; offset < padded.length; offset += 128) compress3(h2, padded, offset);
|
|
911
1751
|
const out = new Uint8Array(bytes);
|
|
912
1752
|
const outView = new DataView(out.buffer);
|
|
913
|
-
for (let
|
|
1753
|
+
for (let i2 = 0; i2 < bytes / 4; i2++) outView.setUint32(i2 * 4, h2[i2]);
|
|
914
1754
|
return out;
|
|
915
1755
|
}
|
|
916
1756
|
var sha512 = (data) => digest64(data, IV_512, 64);
|
|
917
1757
|
var sha384 = (data) => digest64(data, IV_384, 48);
|
|
918
1758
|
|
|
1759
|
+
// digest/whirlpool-sbox.ts
|
|
1760
|
+
var TABLE0 = [
|
|
1761
|
+
0x18186018c07830d8n,
|
|
1762
|
+
0x23238c2305af4626n,
|
|
1763
|
+
0xc6c63fc67ef991b8n,
|
|
1764
|
+
0xe8e887e8136fcdfbn,
|
|
1765
|
+
0x878726874ca113cbn,
|
|
1766
|
+
0xb8b8dab8a9626d11n,
|
|
1767
|
+
0x0101040108050209n,
|
|
1768
|
+
0x4f4f214f426e9e0dn,
|
|
1769
|
+
0x3636d836adee6c9bn,
|
|
1770
|
+
0xa6a6a2a6590451ffn,
|
|
1771
|
+
0xd2d26fd2debdb90cn,
|
|
1772
|
+
0xf5f5f3f5fb06f70en,
|
|
1773
|
+
0x7979f979ef80f296n,
|
|
1774
|
+
0x6f6fa16f5fcede30n,
|
|
1775
|
+
0x91917e91fcef3f6dn,
|
|
1776
|
+
0x52525552aa07a4f8n,
|
|
1777
|
+
0x60609d6027fdc047n,
|
|
1778
|
+
0xbcbccabc89766535n,
|
|
1779
|
+
0x9b9b569baccd2b37n,
|
|
1780
|
+
0x8e8e028e048c018an,
|
|
1781
|
+
0xa3a3b6a371155bd2n,
|
|
1782
|
+
0x0c0c300c603c186cn,
|
|
1783
|
+
0x7b7bf17bff8af684n,
|
|
1784
|
+
0x3535d435b5e16a80n,
|
|
1785
|
+
0x1d1d741de8693af5n,
|
|
1786
|
+
0xe0e0a7e05347ddb3n,
|
|
1787
|
+
0xd7d77bd7f6acb321n,
|
|
1788
|
+
0xc2c22fc25eed999cn,
|
|
1789
|
+
0x2e2eb82e6d965c43n,
|
|
1790
|
+
0x4b4b314b627a9629n,
|
|
1791
|
+
0xfefedffea321e15dn,
|
|
1792
|
+
0x575741578216aed5n,
|
|
1793
|
+
0x15155415a8412abdn,
|
|
1794
|
+
0x7777c1779fb6eee8n,
|
|
1795
|
+
0x3737dc37a5eb6e92n,
|
|
1796
|
+
0xe5e5b3e57b56d79en,
|
|
1797
|
+
0x9f9f469f8cd92313n,
|
|
1798
|
+
0xf0f0e7f0d317fd23n,
|
|
1799
|
+
0x4a4a354a6a7f9420n,
|
|
1800
|
+
0xdada4fda9e95a944n,
|
|
1801
|
+
0x58587d58fa25b0a2n,
|
|
1802
|
+
0xc9c903c906ca8fcfn,
|
|
1803
|
+
0x2929a429558d527cn,
|
|
1804
|
+
0x0a0a280a5022145an,
|
|
1805
|
+
0xb1b1feb1e14f7f50n,
|
|
1806
|
+
0xa0a0baa0691a5dc9n,
|
|
1807
|
+
0x6b6bb16b7fdad614n,
|
|
1808
|
+
0x85852e855cab17d9n,
|
|
1809
|
+
0xbdbdcebd8173673cn,
|
|
1810
|
+
0x5d5d695dd234ba8fn,
|
|
1811
|
+
0x1010401080502090n,
|
|
1812
|
+
0xf4f4f7f4f303f507n,
|
|
1813
|
+
0xcbcb0bcb16c08bddn,
|
|
1814
|
+
0x3e3ef83eedc67cd3n,
|
|
1815
|
+
0x0505140528110a2dn,
|
|
1816
|
+
0x676781671fe6ce78n,
|
|
1817
|
+
0xe4e4b7e47353d597n,
|
|
1818
|
+
0x27279c2725bb4e02n,
|
|
1819
|
+
0x4141194132588273n,
|
|
1820
|
+
0x8b8b168b2c9d0ba7n,
|
|
1821
|
+
0xa7a7a6a7510153f6n,
|
|
1822
|
+
0x7d7de97dcf94fab2n,
|
|
1823
|
+
0x95956e95dcfb3749n,
|
|
1824
|
+
0xd8d847d88e9fad56n,
|
|
1825
|
+
0xfbfbcbfb8b30eb70n,
|
|
1826
|
+
0xeeee9fee2371c1cdn,
|
|
1827
|
+
0x7c7ced7cc791f8bbn,
|
|
1828
|
+
0x6666856617e3cc71n,
|
|
1829
|
+
0xdddd53dda68ea77bn,
|
|
1830
|
+
0x17175c17b84b2eafn,
|
|
1831
|
+
0x4747014702468e45n,
|
|
1832
|
+
0x9e9e429e84dc211an,
|
|
1833
|
+
0xcaca0fca1ec589d4n,
|
|
1834
|
+
0x2d2db42d75995a58n,
|
|
1835
|
+
0xbfbfc6bf9179632en,
|
|
1836
|
+
0x07071c07381b0e3fn,
|
|
1837
|
+
0xadad8ead012347acn,
|
|
1838
|
+
0x5a5a755aea2fb4b0n,
|
|
1839
|
+
0x838336836cb51befn,
|
|
1840
|
+
0x3333cc3385ff66b6n,
|
|
1841
|
+
0x636391633ff2c65cn,
|
|
1842
|
+
0x02020802100a0412n,
|
|
1843
|
+
0xaaaa92aa39384993n,
|
|
1844
|
+
0x7171d971afa8e2den,
|
|
1845
|
+
0xc8c807c80ecf8dc6n,
|
|
1846
|
+
0x19196419c87d32d1n,
|
|
1847
|
+
0x494939497270923bn,
|
|
1848
|
+
0xd9d943d9869aaf5fn,
|
|
1849
|
+
0xf2f2eff2c31df931n,
|
|
1850
|
+
0xe3e3abe34b48dba8n,
|
|
1851
|
+
0x5b5b715be22ab6b9n,
|
|
1852
|
+
0x88881a8834920dbcn,
|
|
1853
|
+
0x9a9a529aa4c8293en,
|
|
1854
|
+
0x262698262dbe4c0bn,
|
|
1855
|
+
0x3232c8328dfa64bfn,
|
|
1856
|
+
0xb0b0fab0e94a7d59n,
|
|
1857
|
+
0xe9e983e91b6acff2n,
|
|
1858
|
+
0x0f0f3c0f78331e77n,
|
|
1859
|
+
0xd5d573d5e6a6b733n,
|
|
1860
|
+
0x80803a8074ba1df4n,
|
|
1861
|
+
0xbebec2be997c6127n,
|
|
1862
|
+
0xcdcd13cd26de87ebn,
|
|
1863
|
+
0x3434d034bde46889n,
|
|
1864
|
+
0x48483d487a759032n,
|
|
1865
|
+
0xffffdbffab24e354n,
|
|
1866
|
+
0x7a7af57af78ff48dn,
|
|
1867
|
+
0x90907a90f4ea3d64n,
|
|
1868
|
+
0x5f5f615fc23ebe9dn,
|
|
1869
|
+
0x202080201da0403dn,
|
|
1870
|
+
0x6868bd6867d5d00fn,
|
|
1871
|
+
0x1a1a681ad07234can,
|
|
1872
|
+
0xaeae82ae192c41b7n,
|
|
1873
|
+
0xb4b4eab4c95e757dn,
|
|
1874
|
+
0x54544d549a19a8cen,
|
|
1875
|
+
0x93937693ece53b7fn,
|
|
1876
|
+
0x222288220daa442fn,
|
|
1877
|
+
0x64648d6407e9c863n,
|
|
1878
|
+
0xf1f1e3f1db12ff2an,
|
|
1879
|
+
0x7373d173bfa2e6ccn,
|
|
1880
|
+
0x12124812905a2482n,
|
|
1881
|
+
0x40401d403a5d807an,
|
|
1882
|
+
0x0808200840281048n,
|
|
1883
|
+
0xc3c32bc356e89b95n,
|
|
1884
|
+
0xecec97ec337bc5dfn,
|
|
1885
|
+
0xdbdb4bdb9690ab4dn,
|
|
1886
|
+
0xa1a1bea1611f5fc0n,
|
|
1887
|
+
0x8d8d0e8d1c830791n,
|
|
1888
|
+
0x3d3df43df5c97ac8n,
|
|
1889
|
+
0x97976697ccf1335bn,
|
|
1890
|
+
0x0000000000000000n,
|
|
1891
|
+
0xcfcf1bcf36d483f9n,
|
|
1892
|
+
0x2b2bac2b4587566en,
|
|
1893
|
+
0x7676c57697b3ece1n,
|
|
1894
|
+
0x8282328264b019e6n,
|
|
1895
|
+
0xd6d67fd6fea9b128n,
|
|
1896
|
+
0x1b1b6c1bd87736c3n,
|
|
1897
|
+
0xb5b5eeb5c15b7774n,
|
|
1898
|
+
0xafaf86af112943ben,
|
|
1899
|
+
0x6a6ab56a77dfd41dn,
|
|
1900
|
+
0x50505d50ba0da0ean,
|
|
1901
|
+
0x45450945124c8a57n,
|
|
1902
|
+
0xf3f3ebf3cb18fb38n,
|
|
1903
|
+
0x3030c0309df060adn,
|
|
1904
|
+
0xefef9bef2b74c3c4n,
|
|
1905
|
+
0x3f3ffc3fe5c37edan,
|
|
1906
|
+
0x55554955921caac7n,
|
|
1907
|
+
0xa2a2b2a2791059dbn,
|
|
1908
|
+
0xeaea8fea0365c9e9n,
|
|
1909
|
+
0x656589650fecca6an,
|
|
1910
|
+
0xbabad2bab9686903n,
|
|
1911
|
+
0x2f2fbc2f65935e4an,
|
|
1912
|
+
0xc0c027c04ee79d8en,
|
|
1913
|
+
0xdede5fdebe81a160n,
|
|
1914
|
+
0x1c1c701ce06c38fcn,
|
|
1915
|
+
0xfdfdd3fdbb2ee746n,
|
|
1916
|
+
0x4d4d294d52649a1fn,
|
|
1917
|
+
0x92927292e4e03976n,
|
|
1918
|
+
0x7575c9758fbceafan,
|
|
1919
|
+
0x06061806301e0c36n,
|
|
1920
|
+
0x8a8a128a249809aen,
|
|
1921
|
+
0xb2b2f2b2f940794bn,
|
|
1922
|
+
0xe6e6bfe66359d185n,
|
|
1923
|
+
0x0e0e380e70361c7en,
|
|
1924
|
+
0x1f1f7c1ff8633ee7n,
|
|
1925
|
+
0x6262956237f7c455n,
|
|
1926
|
+
0xd4d477d4eea3b53an,
|
|
1927
|
+
0xa8a89aa829324d81n,
|
|
1928
|
+
0x96966296c4f43152n,
|
|
1929
|
+
0xf9f9c3f99b3aef62n,
|
|
1930
|
+
0xc5c533c566f697a3n,
|
|
1931
|
+
0x2525942535b14a10n,
|
|
1932
|
+
0x59597959f220b2abn,
|
|
1933
|
+
0x84842a8454ae15d0n,
|
|
1934
|
+
0x7272d572b7a7e4c5n,
|
|
1935
|
+
0x3939e439d5dd72ecn,
|
|
1936
|
+
0x4c4c2d4c5a619816n,
|
|
1937
|
+
0x5e5e655eca3bbc94n,
|
|
1938
|
+
0x7878fd78e785f09fn,
|
|
1939
|
+
0x3838e038ddd870e5n,
|
|
1940
|
+
0x8c8c0a8c14860598n,
|
|
1941
|
+
0xd1d163d1c6b2bf17n,
|
|
1942
|
+
0xa5a5aea5410b57e4n,
|
|
1943
|
+
0xe2e2afe2434dd9a1n,
|
|
1944
|
+
0x616199612ff8c24en,
|
|
1945
|
+
0xb3b3f6b3f1457b42n,
|
|
1946
|
+
0x2121842115a54234n,
|
|
1947
|
+
0x9c9c4a9c94d62508n,
|
|
1948
|
+
0x1e1e781ef0663ceen,
|
|
1949
|
+
0x4343114322528661n,
|
|
1950
|
+
0xc7c73bc776fc93b1n,
|
|
1951
|
+
0xfcfcd7fcb32be54fn,
|
|
1952
|
+
0x0404100420140824n,
|
|
1953
|
+
0x51515951b208a2e3n,
|
|
1954
|
+
0x99995e99bcc72f25n,
|
|
1955
|
+
0x6d6da96d4fc4da22n,
|
|
1956
|
+
0x0d0d340d68391a65n,
|
|
1957
|
+
0xfafacffa8335e979n,
|
|
1958
|
+
0xdfdf5bdfb684a369n,
|
|
1959
|
+
0x7e7ee57ed79bfca9n,
|
|
1960
|
+
0x242490243db44819n,
|
|
1961
|
+
0x3b3bec3bc5d776fen,
|
|
1962
|
+
0xabab96ab313d4b9an,
|
|
1963
|
+
0xcece1fce3ed181f0n,
|
|
1964
|
+
0x1111441188552299n,
|
|
1965
|
+
0x8f8f068f0c890383n,
|
|
1966
|
+
0x4e4e254e4a6b9c04n,
|
|
1967
|
+
0xb7b7e6b7d1517366n,
|
|
1968
|
+
0xebeb8beb0b60cbe0n,
|
|
1969
|
+
0x3c3cf03cfdcc78c1n,
|
|
1970
|
+
0x81813e817cbf1ffdn,
|
|
1971
|
+
0x94946a94d4fe3540n,
|
|
1972
|
+
0xf7f7fbf7eb0cf31cn,
|
|
1973
|
+
0xb9b9deb9a1676f18n,
|
|
1974
|
+
0x13134c13985f268bn,
|
|
1975
|
+
0x2c2cb02c7d9c5851n,
|
|
1976
|
+
0xd3d36bd3d6b8bb05n,
|
|
1977
|
+
0xe7e7bbe76b5cd38cn,
|
|
1978
|
+
0x6e6ea56e57cbdc39n,
|
|
1979
|
+
0xc4c437c46ef395aan,
|
|
1980
|
+
0x03030c03180f061bn,
|
|
1981
|
+
0x565645568a13acdcn,
|
|
1982
|
+
0x44440d441a49885en,
|
|
1983
|
+
0x7f7fe17fdf9efea0n,
|
|
1984
|
+
0xa9a99ea921374f88n,
|
|
1985
|
+
0x2a2aa82a4d825467n,
|
|
1986
|
+
0xbbbbd6bbb16d6b0an,
|
|
1987
|
+
0xc1c123c146e29f87n,
|
|
1988
|
+
0x53535153a202a6f1n,
|
|
1989
|
+
0xdcdc57dcae8ba572n,
|
|
1990
|
+
0x0b0b2c0b58271653n,
|
|
1991
|
+
0x9d9d4e9d9cd32701n,
|
|
1992
|
+
0x6c6cad6c47c1d82bn,
|
|
1993
|
+
0x3131c43195f562a4n,
|
|
1994
|
+
0x7474cd7487b9e8f3n,
|
|
1995
|
+
0xf6f6fff6e309f115n,
|
|
1996
|
+
0x464605460a438c4cn,
|
|
1997
|
+
0xacac8aac092645a5n,
|
|
1998
|
+
0x89891e893c970fb5n,
|
|
1999
|
+
0x14145014a04428b4n,
|
|
2000
|
+
0xe1e1a3e15b42dfban,
|
|
2001
|
+
0x16165816b04e2ca6n,
|
|
2002
|
+
0x3a3ae83acdd274f7n,
|
|
2003
|
+
0x6969b9696fd0d206n,
|
|
2004
|
+
0x09092409482d1241n,
|
|
2005
|
+
0x7070dd70a7ade0d7n,
|
|
2006
|
+
0xb6b6e2b6d954716fn,
|
|
2007
|
+
0xd0d067d0ceb7bd1en,
|
|
2008
|
+
0xeded93ed3b7ec7d6n,
|
|
2009
|
+
0xcccc17cc2edb85e2n,
|
|
2010
|
+
0x424215422a578468n,
|
|
2011
|
+
0x98985a98b4c22d2cn,
|
|
2012
|
+
0xa4a4aaa4490e55edn,
|
|
2013
|
+
0x2828a0285d885075n,
|
|
2014
|
+
0x5c5c6d5cda31b886n,
|
|
2015
|
+
0xf8f8c7f8933fed6bn,
|
|
2016
|
+
0x8686228644a411c2n
|
|
2017
|
+
];
|
|
2018
|
+
|
|
2019
|
+
// digest/whirlpool-table.ts
|
|
2020
|
+
var WORD_MASK = (1n << 64n) - 1n;
|
|
2021
|
+
var LOW_MASK = 0xffffffffn;
|
|
2022
|
+
function rotateBytesRight(value, bytes) {
|
|
2023
|
+
const bits = BigInt(bytes) * 8n;
|
|
2024
|
+
return (value >> bits | value << 64n - bits) & WORD_MASK;
|
|
2025
|
+
}
|
|
2026
|
+
var TABLES_HI = new Uint32Array(8 * 256);
|
|
2027
|
+
var TABLES_LO = new Uint32Array(8 * 256);
|
|
2028
|
+
for (let t = 0; t < 8; t++) {
|
|
2029
|
+
for (let x = 0; x < 256; x++) {
|
|
2030
|
+
const value = t === 0 ? TABLE0[x] : rotateBytesRight(TABLE0[x], t);
|
|
2031
|
+
TABLES_HI[t * 256 + x] = Number(value >> 32n);
|
|
2032
|
+
TABLES_LO[t * 256 + x] = Number(value & LOW_MASK);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
var ROUND_CONSTANTS = [
|
|
2036
|
+
0x1823c6e887b8014fn,
|
|
2037
|
+
0x36a6d2f5796f9152n,
|
|
2038
|
+
0x60bc9b8ea30c7b35n,
|
|
2039
|
+
0x1de0d7c22e4bfe57n,
|
|
2040
|
+
0x157737e59ff04adan,
|
|
2041
|
+
0x58c9290ab1a06b85n,
|
|
2042
|
+
0xbd5d10f4cb3e0567n,
|
|
2043
|
+
0xe427418ba77d95d8n,
|
|
2044
|
+
0xfbee7c66dd17479en,
|
|
2045
|
+
0xca2dbf07ad5a8333n
|
|
2046
|
+
];
|
|
2047
|
+
var ROUND_CONSTANTS_HI = Uint32Array.from(ROUND_CONSTANTS, (c) => Number(c >> 32n));
|
|
2048
|
+
var ROUND_CONSTANTS_LO = Uint32Array.from(ROUND_CONSTANTS, (c) => Number(c & LOW_MASK));
|
|
2049
|
+
|
|
2050
|
+
// digest/whirlpool.ts
|
|
2051
|
+
var TABLES_HI2 = TABLES_HI;
|
|
2052
|
+
var TABLES_LO2 = TABLES_LO;
|
|
2053
|
+
var ROUND_CONSTANTS_HI2 = ROUND_CONSTANTS_HI;
|
|
2054
|
+
var ROUND_CONSTANTS_LO2 = ROUND_CONSTANTS_LO;
|
|
2055
|
+
var BLOCK_BYTES = 64;
|
|
2056
|
+
var WORDS = 8;
|
|
2057
|
+
var ROUNDS2 = 10;
|
|
2058
|
+
var words = () => ({ hi: new Uint32Array(WORDS), lo: new Uint32Array(WORDS) });
|
|
2059
|
+
function op(src, column, out) {
|
|
2060
|
+
const { hi: h2, lo: l } = src;
|
|
2061
|
+
const b0 = h2[column] >>> 24;
|
|
2062
|
+
const b1 = h2[column + 7 & 7] >>> 16 & 255;
|
|
2063
|
+
const b2 = h2[column + 6 & 7] >>> 8 & 255;
|
|
2064
|
+
const b3 = h2[column + 5 & 7] & 255;
|
|
2065
|
+
const b4 = l[column + 4 & 7] >>> 24;
|
|
2066
|
+
const b5 = l[column + 3 & 7] >>> 16 & 255;
|
|
2067
|
+
const b6 = l[column + 2 & 7] >>> 8 & 255;
|
|
2068
|
+
const b7 = l[column + 1 & 7] & 255;
|
|
2069
|
+
out.hi[column] = TABLES_HI2[b0] ^ TABLES_HI2[256 + b1] ^ TABLES_HI2[512 + b2] ^ TABLES_HI2[768 + b3] ^ TABLES_HI2[1024 + b4] ^ TABLES_HI2[1280 + b5] ^ TABLES_HI2[1536 + b6] ^ TABLES_HI2[1792 + b7];
|
|
2070
|
+
out.lo[column] = TABLES_LO2[b0] ^ TABLES_LO2[256 + b1] ^ TABLES_LO2[512 + b2] ^ TABLES_LO2[768 + b3] ^ TABLES_LO2[1024 + b4] ^ TABLES_LO2[1280 + b5] ^ TABLES_LO2[1536 + b6] ^ TABLES_LO2[1792 + b7];
|
|
2071
|
+
}
|
|
2072
|
+
var scratch = { key: words(), state: words(), initial: words(), nextKey: words(), next: words() };
|
|
2073
|
+
function processBlock(hash2, block) {
|
|
2074
|
+
const { key, state, initial, nextKey, next } = scratch;
|
|
2075
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2076
|
+
initial.hi[i2] = block.hi[i2] ^ hash2.hi[i2];
|
|
2077
|
+
initial.lo[i2] = block.lo[i2] ^ hash2.lo[i2];
|
|
2078
|
+
}
|
|
2079
|
+
key.hi.set(hash2.hi);
|
|
2080
|
+
key.lo.set(hash2.lo);
|
|
2081
|
+
state.hi.set(initial.hi);
|
|
2082
|
+
state.lo.set(initial.lo);
|
|
2083
|
+
for (let round2 = 0; round2 < ROUNDS2; round2++) {
|
|
2084
|
+
for (let j = 0; j < WORDS; j++) op(key, j, nextKey);
|
|
2085
|
+
nextKey.hi[0] = nextKey.hi[0] ^ ROUND_CONSTANTS_HI2[round2];
|
|
2086
|
+
nextKey.lo[0] = nextKey.lo[0] ^ ROUND_CONSTANTS_LO2[round2];
|
|
2087
|
+
for (let j = 0; j < WORDS; j++) {
|
|
2088
|
+
op(state, j, next);
|
|
2089
|
+
next.hi[j] = next.hi[j] ^ nextKey.hi[j];
|
|
2090
|
+
next.lo[j] = next.lo[j] ^ nextKey.lo[j];
|
|
2091
|
+
}
|
|
2092
|
+
key.hi.set(nextKey.hi);
|
|
2093
|
+
key.lo.set(nextKey.lo);
|
|
2094
|
+
state.hi.set(next.hi);
|
|
2095
|
+
state.lo.set(next.lo);
|
|
2096
|
+
}
|
|
2097
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2098
|
+
hash2.hi[i2] = initial.hi[i2] ^ state.hi[i2];
|
|
2099
|
+
hash2.lo[i2] = initial.lo[i2] ^ state.lo[i2];
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
function pad(message) {
|
|
2103
|
+
let total = message.length + 1;
|
|
2104
|
+
while (total % BLOCK_BYTES !== 32) {
|
|
2105
|
+
total++;
|
|
2106
|
+
}
|
|
2107
|
+
total += 32;
|
|
2108
|
+
const padded = new Uint8Array(total);
|
|
2109
|
+
padded.set(message);
|
|
2110
|
+
padded[message.length] = 128;
|
|
2111
|
+
new DataView(padded.buffer).setBigUint64(total - 8, BigInt(message.length) * 8n, false);
|
|
2112
|
+
return padded;
|
|
2113
|
+
}
|
|
2114
|
+
function whirlpool(message) {
|
|
2115
|
+
const padded = pad(message);
|
|
2116
|
+
const view = new DataView(padded.buffer);
|
|
2117
|
+
const hash2 = words();
|
|
2118
|
+
const block = words();
|
|
2119
|
+
for (let offset = 0; offset < padded.length; offset += BLOCK_BYTES) {
|
|
2120
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2121
|
+
block.hi[i2] = view.getUint32(offset + i2 * 8, false);
|
|
2122
|
+
block.lo[i2] = view.getUint32(offset + i2 * 8 + 4, false);
|
|
2123
|
+
}
|
|
2124
|
+
processBlock(hash2, block);
|
|
2125
|
+
}
|
|
2126
|
+
const out = new Uint8Array(BLOCK_BYTES);
|
|
2127
|
+
const outView = new DataView(out.buffer);
|
|
2128
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2129
|
+
outView.setUint32(i2 * 8, hash2.hi[i2], false);
|
|
2130
|
+
outView.setUint32(i2 * 8 + 4, hash2.lo[i2], false);
|
|
2131
|
+
}
|
|
2132
|
+
return out;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
919
2135
|
// digest/digest.ts
|
|
920
2136
|
var DIGESTS = {
|
|
921
2137
|
"SHA-1": sha1,
|
|
922
2138
|
"SHA-256": sha256,
|
|
923
2139
|
"SHA-384": sha384,
|
|
924
|
-
"SHA-512": sha512
|
|
2140
|
+
"SHA-512": sha512,
|
|
2141
|
+
MD2: md2,
|
|
2142
|
+
MD4: md4,
|
|
2143
|
+
MD5: md5,
|
|
2144
|
+
"RIPEMD-128": ripemd128,
|
|
2145
|
+
"RIPEMD-160": ripemd160,
|
|
2146
|
+
WHIRLPOOL: whirlpool
|
|
925
2147
|
};
|
|
926
2148
|
function digestFunction(name) {
|
|
927
2149
|
const canonical = normalizeDigestAlgorithmName(name);
|
|
928
|
-
return canonical &&
|
|
2150
|
+
return canonical && DIGESTS[canonical];
|
|
929
2151
|
}
|
|
930
2152
|
|
|
931
2153
|
// crypto/key-derivation.ts
|
|
@@ -944,56 +2166,56 @@ async function spinPassword(password, salt, spinCount, hashAlgorithm) {
|
|
|
944
2166
|
const passwordBytes = encodePasswordUtf16LE(password);
|
|
945
2167
|
const digest = digestFunction(hashAlgorithm);
|
|
946
2168
|
if (digest) {
|
|
947
|
-
let
|
|
948
|
-
const buffer = new Uint8Array(4 +
|
|
2169
|
+
let h3 = digest(concatArrays(salt, passwordBytes));
|
|
2170
|
+
const buffer = new Uint8Array(4 + h3.length);
|
|
949
2171
|
const view = new DataView(buffer.buffer);
|
|
950
|
-
for (let
|
|
951
|
-
view.setUint32(0,
|
|
952
|
-
buffer.set(
|
|
953
|
-
|
|
2172
|
+
for (let i2 = 0; i2 < spinCount; i2++) {
|
|
2173
|
+
view.setUint32(0, i2, true);
|
|
2174
|
+
buffer.set(h3, 4);
|
|
2175
|
+
h3 = digest(buffer);
|
|
954
2176
|
}
|
|
955
|
-
return
|
|
2177
|
+
return h3;
|
|
956
2178
|
}
|
|
957
|
-
let
|
|
958
|
-
for (let
|
|
959
|
-
|
|
2179
|
+
let h2 = await hash(hashAlgorithm, concatArrays(salt, passwordBytes));
|
|
2180
|
+
for (let i2 = 0; i2 < spinCount; i2++) {
|
|
2181
|
+
h2 = await hash(hashAlgorithm, concatArrays(uint32LE(i2), h2));
|
|
960
2182
|
}
|
|
961
|
-
return
|
|
2183
|
+
return h2;
|
|
962
2184
|
}
|
|
963
|
-
async function extendKey(
|
|
964
|
-
const
|
|
2185
|
+
async function extendKey(h2, hashAlgorithm, keyLength) {
|
|
2186
|
+
const pad2 = async (value) => {
|
|
965
2187
|
const input = new Uint8Array(64).fill(value);
|
|
966
|
-
for (let
|
|
2188
|
+
for (let i2 = 0; i2 < h2.length && i2 < 64; i2++) input[i2] = h2[i2] ^ value;
|
|
967
2189
|
return hash(hashAlgorithm, input);
|
|
968
2190
|
};
|
|
969
|
-
const x3 = concatArrays(await
|
|
2191
|
+
const x3 = concatArrays(await pad2(54), await pad2(92));
|
|
970
2192
|
return x3.subarray(0, keyLength);
|
|
971
2193
|
}
|
|
972
2194
|
function computeAgileKeyBase(password, salt, spinCount, hashAlgorithm) {
|
|
973
2195
|
return spinPassword(password, salt, spinCount, hashAlgorithm);
|
|
974
2196
|
}
|
|
975
2197
|
async function deriveAgileKeyFromBase(base, hashAlgorithm, blockKey, keyBits, hashSize) {
|
|
976
|
-
const
|
|
2198
|
+
const h2 = await hash(hashAlgorithm, concatArrays(base, blockKey));
|
|
977
2199
|
const keyLength = keyBits / 8;
|
|
978
|
-
if (hashSize >= keyLength) return
|
|
979
|
-
return extendKey(
|
|
2200
|
+
if (hashSize >= keyLength) return h2.subarray(0, keyLength);
|
|
2201
|
+
return extendKey(h2, hashAlgorithm, keyLength);
|
|
980
2202
|
}
|
|
981
2203
|
function computeStandardKeyBase(password, salt) {
|
|
982
2204
|
return spinPassword(password, salt, 5e4, "SHA-1");
|
|
983
2205
|
}
|
|
984
2206
|
async function deriveStandardKeyFromBase(base, keySize, blockNumber = 0) {
|
|
985
|
-
const
|
|
986
|
-
return extendKey(
|
|
2207
|
+
const h2 = await hash("SHA-1", concatArrays(base, uint32LE(blockNumber)));
|
|
2208
|
+
return extendKey(h2, "SHA-1", keySize / 8);
|
|
987
2209
|
}
|
|
988
2210
|
async function deriveStandardKey(password, salt, keySize, _algIdHash, blockNumber = 0) {
|
|
989
2211
|
const base = await computeStandardKeyBase(password, salt);
|
|
990
2212
|
return deriveStandardKeyFromBase(base, keySize, blockNumber);
|
|
991
2213
|
}
|
|
992
2214
|
async function generateIV(hashAlgorithm, salt, blockKey, blockSize) {
|
|
993
|
-
const
|
|
994
|
-
if (
|
|
2215
|
+
const h2 = await hash(hashAlgorithm, concatArrays(salt, blockKey));
|
|
2216
|
+
if (h2.length >= blockSize) return h2.subarray(0, blockSize);
|
|
995
2217
|
const padded = new Uint8Array(blockSize).fill(54);
|
|
996
|
-
padded.set(
|
|
2218
|
+
padded.set(h2);
|
|
997
2219
|
return padded;
|
|
998
2220
|
}
|
|
999
2221
|
|
|
@@ -1015,7 +2237,7 @@ async function verifyAgilePassword(info, password) {
|
|
|
1015
2237
|
const computedHash = await hash(pke.hashAlgorithm, verifierHashInput.subarray(0, pke.saltSize));
|
|
1016
2238
|
if (computedHash.length < pke.hashSize || verifierHashValue.length < pke.hashSize) return null;
|
|
1017
2239
|
let difference = 0;
|
|
1018
|
-
for (let
|
|
2240
|
+
for (let i2 = 0; i2 < pke.hashSize; i2++) difference |= verifierHashValue[i2] ^ computedHash[i2];
|
|
1019
2241
|
if (difference !== 0) return null;
|
|
1020
2242
|
const decryptedKey = await aesCbcDecryptRaw(
|
|
1021
2243
|
await blockKey(BLOCK_KEYS.encryptedKeyValue),
|
|
@@ -1036,8 +2258,8 @@ async function verifyStandardPassword(info, password) {
|
|
|
1036
2258
|
const computedHash = await hash("SHA-1", decryptedVerifier);
|
|
1037
2259
|
const hashSize = info.verifier.verifierHashSize;
|
|
1038
2260
|
let match = true;
|
|
1039
|
-
for (let
|
|
1040
|
-
if (computedHash[
|
|
2261
|
+
for (let i2 = 0; i2 < Math.min(hashSize, 20); i2++) {
|
|
2262
|
+
if (computedHash[i2] !== decryptedHash[i2]) {
|
|
1041
2263
|
match = false;
|
|
1042
2264
|
break;
|
|
1043
2265
|
}
|
|
@@ -1078,8 +2300,8 @@ async function verifyAgileDataIntegrity(info, key, encryptedPackage) {
|
|
|
1078
2300
|
if (computedHmac.length < keyData.hashSize) {
|
|
1079
2301
|
match = false;
|
|
1080
2302
|
} else {
|
|
1081
|
-
for (let
|
|
1082
|
-
if (computedHmac[
|
|
2303
|
+
for (let i2 = 0; i2 < keyData.hashSize; i2++) {
|
|
2304
|
+
if (computedHmac[i2] !== expectedHmac[i2]) {
|
|
1083
2305
|
match = false;
|
|
1084
2306
|
break;
|
|
1085
2307
|
}
|
|
@@ -1173,8 +2395,8 @@ function compareDirEntryNames(a, b) {
|
|
|
1173
2395
|
if (a.length !== b.length) {
|
|
1174
2396
|
return a.length - b.length;
|
|
1175
2397
|
}
|
|
1176
|
-
for (let
|
|
1177
|
-
const diff = ua.charCodeAt(
|
|
2398
|
+
for (let i2 = 0; i2 < ua.length; i2++) {
|
|
2399
|
+
const diff = ua.charCodeAt(i2) - ub.charCodeAt(i2);
|
|
1178
2400
|
if (diff !== 0) {
|
|
1179
2401
|
return diff;
|
|
1180
2402
|
}
|
|
@@ -1183,9 +2405,9 @@ function compareDirEntryNames(a, b) {
|
|
|
1183
2405
|
}
|
|
1184
2406
|
function encodeName(name) {
|
|
1185
2407
|
const bytes = new Uint8Array((name.length + 1) * 2);
|
|
1186
|
-
for (let
|
|
1187
|
-
bytes[
|
|
1188
|
-
bytes[
|
|
2408
|
+
for (let i2 = 0; i2 < name.length; i2++) {
|
|
2409
|
+
bytes[i2 * 2] = name.charCodeAt(i2) & 255;
|
|
2410
|
+
bytes[i2 * 2 + 1] = name.charCodeAt(i2) >> 8 & 255;
|
|
1189
2411
|
}
|
|
1190
2412
|
return bytes;
|
|
1191
2413
|
}
|
|
@@ -1208,21 +2430,21 @@ function buildDirectoryTree(entryCount) {
|
|
|
1208
2430
|
return { root: build(1, entryCount - 1, 0), links };
|
|
1209
2431
|
}
|
|
1210
2432
|
function writeFatChain(fat, chain2) {
|
|
1211
|
-
for (let
|
|
1212
|
-
fat[chain2.sectors[
|
|
2433
|
+
for (let i2 = 0; i2 < chain2.sectors.length; i2++) {
|
|
2434
|
+
fat[chain2.sectors[i2]] = i2 < chain2.sectors.length - 1 ? chain2.sectors[i2 + 1] : ENDOFCHAIN;
|
|
1213
2435
|
}
|
|
1214
2436
|
}
|
|
1215
2437
|
function writeFatRun(fat, firstSector, count) {
|
|
1216
|
-
for (let
|
|
1217
|
-
const sector = firstSector +
|
|
1218
|
-
fat[sector] =
|
|
2438
|
+
for (let i2 = 0; i2 < count; i2++) {
|
|
2439
|
+
const sector = firstSector + i2;
|
|
2440
|
+
fat[sector] = i2 < count - 1 ? sector + 1 : ENDOFCHAIN;
|
|
1219
2441
|
}
|
|
1220
2442
|
}
|
|
1221
2443
|
function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorSize) {
|
|
1222
2444
|
const entriesPerSector = sectorSize / 4;
|
|
1223
|
-
for (let
|
|
1224
|
-
const sectorOff = (firstSector +
|
|
1225
|
-
const start =
|
|
2445
|
+
for (let i2 = 0; i2 < numSectors; i2++) {
|
|
2446
|
+
const sectorOff = (firstSector + i2 + 1) * sectorSize;
|
|
2447
|
+
const start = i2 * entriesPerSector;
|
|
1226
2448
|
const end = start + entriesPerSector;
|
|
1227
2449
|
const chunk = int32Data.subarray(start, end);
|
|
1228
2450
|
const chunkBytes = new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
@@ -1248,11 +2470,11 @@ function writeHeader(outView, outBytes, params) {
|
|
|
1248
2470
|
const numDIFATSectors = params.numDIFATSectors ?? 0;
|
|
1249
2471
|
outView.setUint32(68, numDIFATSectors > 0 ? params.firstDIFATSector ?? ENDOFCHAIN : ENDOFCHAIN, true);
|
|
1250
2472
|
outView.setUint32(72, numDIFATSectors, true);
|
|
1251
|
-
for (let
|
|
1252
|
-
if (
|
|
1253
|
-
outView.setUint32(76 +
|
|
2473
|
+
for (let i2 = 0; i2 < HEADER_DIFAT_ENTRIES; i2++) {
|
|
2474
|
+
if (i2 < params.numFATSectors) {
|
|
2475
|
+
outView.setUint32(76 + i2 * 4, params.firstFATSector + i2, true);
|
|
1254
2476
|
} else {
|
|
1255
|
-
outView.setUint32(76 +
|
|
2477
|
+
outView.setUint32(76 + i2 * 4, FREESECT, true);
|
|
1256
2478
|
}
|
|
1257
2479
|
}
|
|
1258
2480
|
}
|
|
@@ -1289,24 +2511,24 @@ function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
|
|
|
1289
2511
|
const dirData = new Uint8Array(numDirSectors * sectorSize);
|
|
1290
2512
|
const dirView = new DataView(dirData.buffer);
|
|
1291
2513
|
const tree = buildDirectoryTree(dirEntries.length);
|
|
1292
|
-
for (let
|
|
1293
|
-
const entry = dirEntries[
|
|
1294
|
-
const entryOffset =
|
|
2514
|
+
for (let i2 = 0; i2 < dirEntries.length; i2++) {
|
|
2515
|
+
const entry = dirEntries[i2];
|
|
2516
|
+
const entryOffset = i2 * DIR_ENTRY_SIZE;
|
|
1295
2517
|
const nameBytes = encodeName(entry.name);
|
|
1296
2518
|
dirData.set(nameBytes.subarray(0, Math.min(nameBytes.length, 64)), entryOffset);
|
|
1297
2519
|
dirView.setUint16(entryOffset + 64, Math.min((entry.name.length + 1) * 2, 64), true);
|
|
1298
2520
|
dirData[entryOffset + 66] = entry.type;
|
|
1299
|
-
dirData[entryOffset + 67] =
|
|
2521
|
+
dirData[entryOffset + 67] = i2 === 0 ? 1 : tree.links.get(i2).color;
|
|
1300
2522
|
if (entry.clsid) {
|
|
1301
2523
|
dirData.set(entry.clsid.subarray(0, 16), entryOffset + 80);
|
|
1302
2524
|
}
|
|
1303
|
-
if (
|
|
2525
|
+
if (i2 === 0) {
|
|
1304
2526
|
dirView.setUint32(entryOffset + 68, 4294967295, true);
|
|
1305
2527
|
dirView.setUint32(entryOffset + 72, 4294967295, true);
|
|
1306
2528
|
dirView.setUint32(entryOffset + 76, tree.root, true);
|
|
1307
2529
|
} else {
|
|
1308
|
-
dirView.setUint32(entryOffset + 68, tree.links.get(
|
|
1309
|
-
dirView.setUint32(entryOffset + 72, tree.links.get(
|
|
2530
|
+
dirView.setUint32(entryOffset + 68, tree.links.get(i2).left, true);
|
|
2531
|
+
dirView.setUint32(entryOffset + 72, tree.links.get(i2).right, true);
|
|
1310
2532
|
dirView.setUint32(entryOffset + 76, 4294967295, true);
|
|
1311
2533
|
}
|
|
1312
2534
|
dirView.setUint32(entryOffset + 116, entry.startSector, true);
|
|
@@ -1315,9 +2537,9 @@ function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
|
|
|
1315
2537
|
return dirData;
|
|
1316
2538
|
}
|
|
1317
2539
|
function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
|
|
1318
|
-
for (let
|
|
1319
|
-
const sectorOffset = (chain2.sectors[
|
|
1320
|
-
const srcOffset =
|
|
2540
|
+
for (let i2 = 0; i2 < chain2.sectors.length; i2++) {
|
|
2541
|
+
const sectorOffset = (chain2.sectors[i2] + 1) * sectorSize;
|
|
2542
|
+
const srcOffset = i2 * sectorSize;
|
|
1321
2543
|
const srcEnd = Math.min(srcOffset + sectorSize, streamData.length);
|
|
1322
2544
|
outBytes.set(streamData.subarray(srcOffset, srcEnd), sectorOffset);
|
|
1323
2545
|
}
|
|
@@ -1328,15 +2550,15 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1328
2550
|
const sectorSize = 512;
|
|
1329
2551
|
const miniSectorSize = 64;
|
|
1330
2552
|
const names = [...streams2.keys()].sort(compareDirEntryNames);
|
|
1331
|
-
for (let
|
|
1332
|
-
const name = names[
|
|
2553
|
+
for (let i2 = 0; i2 < names.length; i2++) {
|
|
2554
|
+
const name = names[i2];
|
|
1333
2555
|
if (name.toUpperCase().length !== name.length) {
|
|
1334
2556
|
throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
|
|
1335
2557
|
}
|
|
1336
2558
|
if (!name.length || name.length > 31 || /[\x00\\/:!]/.test(name)) {
|
|
1337
2559
|
throw new Error("CFB stream names must be 1-31 UTF-16 code units without NUL, \\, /, :, or !");
|
|
1338
2560
|
}
|
|
1339
|
-
if (
|
|
2561
|
+
if (i2 > 0 && compareDirEntryNames(names[i2 - 1], name) === 0) {
|
|
1340
2562
|
throw new Error("Duplicate CFB stream names");
|
|
1341
2563
|
}
|
|
1342
2564
|
}
|
|
@@ -1354,7 +2576,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1354
2576
|
for (const stream of regularStreams) {
|
|
1355
2577
|
const numSectors = Math.ceil(stream.data.length / sectorSize);
|
|
1356
2578
|
const sectors = [];
|
|
1357
|
-
for (let
|
|
2579
|
+
for (let i2 = 0; i2 < numSectors; i2++) {
|
|
1358
2580
|
sectors.push(nextSector++);
|
|
1359
2581
|
}
|
|
1360
2582
|
fatChains.set(stream.name, { start: sectors[0] ?? ENDOFCHAIN, sectors });
|
|
@@ -1372,9 +2594,9 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1372
2594
|
for (const stream of miniStreams) {
|
|
1373
2595
|
const numMiniSectors = Math.ceil(stream.data.length / miniSectorSize);
|
|
1374
2596
|
const miniSectors = [];
|
|
1375
|
-
for (let
|
|
2597
|
+
for (let i2 = 0; i2 < numMiniSectors; i2++) {
|
|
1376
2598
|
miniSectors.push(nextMiniSector++);
|
|
1377
|
-
const srcOffset =
|
|
2599
|
+
const srcOffset = i2 * miniSectorSize;
|
|
1378
2600
|
const srcEnd = Math.min(srcOffset + miniSectorSize, stream.data.length);
|
|
1379
2601
|
miniStreamContainer.set(stream.data.subarray(srcOffset, srcEnd), miniOffset);
|
|
1380
2602
|
miniOffset += miniSectorSize;
|
|
@@ -1390,7 +2612,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1390
2612
|
if (miniStreamContainer.length > 0) {
|
|
1391
2613
|
const numSectors = Math.ceil(miniStreamContainer.length / sectorSize);
|
|
1392
2614
|
rootStartSector = nextSector;
|
|
1393
|
-
for (let
|
|
2615
|
+
for (let i2 = 0; i2 < numSectors; i2++) {
|
|
1394
2616
|
rootSectors.push(nextSector++);
|
|
1395
2617
|
}
|
|
1396
2618
|
}
|
|
@@ -1449,11 +2671,11 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1449
2671
|
if (numMiniFATSectors > 0) {
|
|
1450
2672
|
writeFatRun(fat, firstMiniFATSector, numMiniFATSectors);
|
|
1451
2673
|
}
|
|
1452
|
-
for (let
|
|
1453
|
-
fat[firstFATSector +
|
|
2674
|
+
for (let i2 = 0; i2 < numFATSectors; i2++) {
|
|
2675
|
+
fat[firstFATSector + i2] = FATSECT;
|
|
1454
2676
|
}
|
|
1455
|
-
for (let
|
|
1456
|
-
fat[firstDIFATSector +
|
|
2677
|
+
for (let i2 = 0; i2 < numDIFATSectors; i2++) {
|
|
2678
|
+
fat[firstDIFATSector + i2] = DIFSECT;
|
|
1457
2679
|
}
|
|
1458
2680
|
let miniFat;
|
|
1459
2681
|
if (miniStreams.length > 0) {
|
|
@@ -1484,9 +2706,9 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1484
2706
|
writeStreamSectors(outBytes, miniStreamContainer, { start: rootSectors[0] ?? 0, sectors: rootSectors }, sectorSize);
|
|
1485
2707
|
}
|
|
1486
2708
|
const dirData = serializeDirectoryEntries(sortedDirEntries, numDirSectors, sectorSize);
|
|
1487
|
-
for (let
|
|
1488
|
-
const sectorOff = (firstDirSector +
|
|
1489
|
-
outBytes.set(dirData.subarray(
|
|
2709
|
+
for (let i2 = 0; i2 < numDirSectors; i2++) {
|
|
2710
|
+
const sectorOff = (firstDirSector + i2 + 1) * sectorSize;
|
|
2711
|
+
outBytes.set(dirData.subarray(i2 * sectorSize, (i2 + 1) * sectorSize), sectorOff);
|
|
1490
2712
|
}
|
|
1491
2713
|
if (miniFat) {
|
|
1492
2714
|
writeInt32Sectors(outBytes, miniFat, firstMiniFATSector, numMiniFATSectors, sectorSize);
|
|
@@ -1539,10 +2761,10 @@ function buildStandardEncryptionInfoStream(keyBits, salt, encryptedVerifier, enc
|
|
|
1539
2761
|
);
|
|
1540
2762
|
}
|
|
1541
2763
|
const cspNameBytes = new Uint8Array((STANDARD_CSP_NAME.length + 1) * 2);
|
|
1542
|
-
for (let
|
|
1543
|
-
const code = STANDARD_CSP_NAME.charCodeAt(
|
|
1544
|
-
cspNameBytes[
|
|
1545
|
-
cspNameBytes[
|
|
2764
|
+
for (let i2 = 0; i2 < STANDARD_CSP_NAME.length; i2++) {
|
|
2765
|
+
const code = STANDARD_CSP_NAME.charCodeAt(i2);
|
|
2766
|
+
cspNameBytes[i2 * 2] = code & 255;
|
|
2767
|
+
cspNameBytes[i2 * 2 + 1] = code >> 8 & 255;
|
|
1546
2768
|
}
|
|
1547
2769
|
const headerFixedSize = 32;
|
|
1548
2770
|
const headerSize = headerFixedSize + cspNameBytes.length;
|
|
@@ -1554,16 +2776,16 @@ function buildStandardEncryptionInfoStream(keyBits, salt, encryptedVerifier, enc
|
|
|
1554
2776
|
view.setUint16(2, 2, true);
|
|
1555
2777
|
view.setUint32(4, STANDARD_FLAGS, true);
|
|
1556
2778
|
view.setUint32(8, headerSize, true);
|
|
1557
|
-
const
|
|
1558
|
-
view.setUint32(
|
|
1559
|
-
view.setUint32(
|
|
1560
|
-
view.setUint32(
|
|
1561
|
-
view.setUint32(
|
|
1562
|
-
view.setUint32(
|
|
1563
|
-
view.setUint32(
|
|
1564
|
-
view.setUint32(
|
|
1565
|
-
view.setUint32(
|
|
1566
|
-
data.set(cspNameBytes,
|
|
2779
|
+
const h2 = 12;
|
|
2780
|
+
view.setUint32(h2, STANDARD_FLAGS, true);
|
|
2781
|
+
view.setUint32(h2 + 4, 0, true);
|
|
2782
|
+
view.setUint32(h2 + 8, algId, true);
|
|
2783
|
+
view.setUint32(h2 + 12, STANDARD_ALG_ID_HASH_SHA1, true);
|
|
2784
|
+
view.setUint32(h2 + 16, keyBits, true);
|
|
2785
|
+
view.setUint32(h2 + 20, STANDARD_PROVIDER_TYPE_RSA_AES, true);
|
|
2786
|
+
view.setUint32(h2 + 24, 0, true);
|
|
2787
|
+
view.setUint32(h2 + 28, 0, true);
|
|
2788
|
+
data.set(cspNameBytes, h2 + 32);
|
|
1567
2789
|
const v = 12 + headerSize;
|
|
1568
2790
|
view.setUint32(v, 16, true);
|
|
1569
2791
|
data.set(salt.subarray(0, 16), v + 4);
|
|
@@ -1720,8 +2942,8 @@ function parseStandardEncryptionInfo(data) {
|
|
|
1720
2942
|
const providerType = view.getUint32(headerOffset + 20, true);
|
|
1721
2943
|
let cspName = "";
|
|
1722
2944
|
const cspEnd = headerOffset + headerSize;
|
|
1723
|
-
for (let
|
|
1724
|
-
const ch = view.getUint16(
|
|
2945
|
+
for (let i2 = headerOffset + 32; i2 < cspEnd - 1; i2 += 2) {
|
|
2946
|
+
const ch = view.getUint16(i2, true);
|
|
1725
2947
|
if (ch === 0) break;
|
|
1726
2948
|
cspName += String.fromCharCode(ch);
|
|
1727
2949
|
}
|
|
@@ -2202,7 +3424,7 @@ function setAttribute(element, local, value) {
|
|
|
2202
3424
|
}
|
|
2203
3425
|
function paraIdFor(id, index) {
|
|
2204
3426
|
let hash2 = index + 1 >>> 0;
|
|
2205
|
-
for (let
|
|
3427
|
+
for (let i2 = 0; i2 < id.length; i2++) hash2 = Math.imul(hash2, 31) + id.charCodeAt(i2) >>> 0;
|
|
2206
3428
|
return hash2.toString(16).padStart(8, "0").toUpperCase();
|
|
2207
3429
|
}
|
|
2208
3430
|
function buildCommentsDocument(comments) {
|
|
@@ -2393,6 +3615,27 @@ function expectDefined(value, context) {
|
|
|
2393
3615
|
return value;
|
|
2394
3616
|
}
|
|
2395
3617
|
|
|
3618
|
+
// color/color-primitives.ts
|
|
3619
|
+
function toHex(value) {
|
|
3620
|
+
return Math.min(255, Math.max(0, Math.round(value))).toString(16).padStart(2, "0").toUpperCase();
|
|
3621
|
+
}
|
|
3622
|
+
|
|
3623
|
+
// drawingml/theme-model.ts
|
|
3624
|
+
var THEME_COLOR_SLOTS = [
|
|
3625
|
+
"dk1",
|
|
3626
|
+
"lt1",
|
|
3627
|
+
"dk2",
|
|
3628
|
+
"lt2",
|
|
3629
|
+
"accent1",
|
|
3630
|
+
"accent2",
|
|
3631
|
+
"accent3",
|
|
3632
|
+
"accent4",
|
|
3633
|
+
"accent5",
|
|
3634
|
+
"accent6",
|
|
3635
|
+
"hlink",
|
|
3636
|
+
"folHlink"
|
|
3637
|
+
];
|
|
3638
|
+
|
|
2396
3639
|
// docx/generated/wml-simple-types.ts
|
|
2397
3640
|
var ST_HighlightColor = ["black", "blue", "cyan", "green", "magenta", "red", "yellow", "white", "darkBlue", "darkCyan", "darkGreen", "darkMagenta", "darkRed", "darkYellow", "darkGray", "lightGray", "none"];
|
|
2398
3641
|
function isStHighlightColor(value) {
|
|
@@ -2479,9 +3722,6 @@ function isStRelFromV(value) {
|
|
|
2479
3722
|
function isThemeColorToken(value) {
|
|
2480
3723
|
return isStThemeColor(value);
|
|
2481
3724
|
}
|
|
2482
|
-
function toHex(value) {
|
|
2483
|
-
return Math.min(255, Math.max(0, Math.round(value))).toString(16).padStart(2, "0").toUpperCase();
|
|
2484
|
-
}
|
|
2485
3725
|
function fractionToThemeByte(fraction) {
|
|
2486
3726
|
return toHex(Math.round(Math.min(1, Math.max(0, fraction)) * 255));
|
|
2487
3727
|
}
|
|
@@ -4548,9 +5788,9 @@ function buildWatermarkRun(doc, spec, uniqueId) {
|
|
|
4548
5788
|
type.setAttribute("path", "m@7,l@8,m@5,21600l@6,21600e");
|
|
4549
5789
|
const formulas = v("formulas");
|
|
4550
5790
|
for (const eqn of FORMULAS) {
|
|
4551
|
-
const
|
|
4552
|
-
|
|
4553
|
-
formulas.appendChild(
|
|
5791
|
+
const f6 = v("f");
|
|
5792
|
+
f6.setAttribute("eqn", eqn);
|
|
5793
|
+
formulas.appendChild(f6);
|
|
4554
5794
|
}
|
|
4555
5795
|
const path = v("path");
|
|
4556
5796
|
path.setAttribute("textpathok", "t");
|
|
@@ -4895,7 +6135,7 @@ var DIAGRAM_RELATIONSHIP_TYPES = {
|
|
|
4895
6135
|
drawing: RELATIONSHIP_TYPES.diagramDrawing
|
|
4896
6136
|
};
|
|
4897
6137
|
|
|
4898
|
-
//
|
|
6138
|
+
// drawingml/dom.ts
|
|
4899
6139
|
function attributeReader(element) {
|
|
4900
6140
|
return (name) => {
|
|
4901
6141
|
if (!element) return void 0;
|
|
@@ -5051,7 +6291,7 @@ function parseDiagramDataModel(source, part) {
|
|
|
5051
6291
|
};
|
|
5052
6292
|
}
|
|
5053
6293
|
|
|
5054
|
-
//
|
|
6294
|
+
// drawingml/drawing-color.ts
|
|
5055
6295
|
var COLOR_ELEMENTS = {
|
|
5056
6296
|
srgbClr: "srgb",
|
|
5057
6297
|
schemeClr: "scheme",
|
|
@@ -5190,7 +6430,7 @@ function parseDiagramLayoutSummary(source) {
|
|
|
5190
6430
|
};
|
|
5191
6431
|
}
|
|
5192
6432
|
|
|
5193
|
-
//
|
|
6433
|
+
// drawingml/drawing-fill.ts
|
|
5194
6434
|
var FILL_ELEMENTS = /* @__PURE__ */ new Set([
|
|
5195
6435
|
"noFill",
|
|
5196
6436
|
"solidFill",
|
|
@@ -5282,7 +6522,7 @@ function parseDrawingLine(ln) {
|
|
|
5282
6522
|
return line;
|
|
5283
6523
|
}
|
|
5284
6524
|
|
|
5285
|
-
//
|
|
6525
|
+
// drawingml/drawing-text.ts
|
|
5286
6526
|
function parseSpacing(parent) {
|
|
5287
6527
|
for (const [name, unit, divisor] of [
|
|
5288
6528
|
["spcPts", "points", 100],
|
|
@@ -5361,7 +6601,7 @@ function parseDrawingTextBody(body) {
|
|
|
5361
6601
|
return result;
|
|
5362
6602
|
}
|
|
5363
6603
|
|
|
5364
|
-
//
|
|
6604
|
+
// drawingml/drawing-geometry.ts
|
|
5365
6605
|
var int = (element, name) => Number.parseInt(element?.getAttribute(name) ?? "", 10);
|
|
5366
6606
|
function parseFrame(container2) {
|
|
5367
6607
|
const off = first(container2, "off", NS.a);
|
|
@@ -5506,12 +6746,12 @@ function groupTransform(group, parent) {
|
|
|
5506
6746
|
}
|
|
5507
6747
|
function parseShape(sp, index, group, issues) {
|
|
5508
6748
|
const spPr = first(sp, "spPr", NS.dsp);
|
|
5509
|
-
const
|
|
5510
|
-
if (!
|
|
6749
|
+
const transform6 = parseTransform(first(spPr, "xfrm", NS.a));
|
|
6750
|
+
if (!transform6) return void 0;
|
|
5511
6751
|
const modelId = stringAttribute(sp, "modelId") ?? stringAttribute(first(first(sp, "nvSpPr", NS.dsp), "cNvPr", NS.dsp), "id") ?? `dsp-${index}`;
|
|
5512
6752
|
const { geometry, adjustments, paths, issue } = parseDrawingGeometry(spPr);
|
|
5513
6753
|
if (issue) issues.push({ code: issue, message: `Shape ${modelId}: ${issue}.` });
|
|
5514
|
-
const frame = applyGroup(
|
|
6754
|
+
const frame = applyGroup(transform6.frame, group);
|
|
5515
6755
|
if ((frame.width <= 0 || frame.height <= 0) && geometry !== "line") return void 0;
|
|
5516
6756
|
const shape = {
|
|
5517
6757
|
modelId,
|
|
@@ -5519,9 +6759,9 @@ function parseShape(sp, index, group, issues) {
|
|
|
5519
6759
|
geometry,
|
|
5520
6760
|
has3d: Boolean(first(spPr, "scene3d", NS.a) || first(spPr, "sp3d", NS.a))
|
|
5521
6761
|
};
|
|
5522
|
-
if (
|
|
5523
|
-
if (
|
|
5524
|
-
if (
|
|
6762
|
+
if (transform6.rotation !== void 0) shape.rotation = transform6.rotation;
|
|
6763
|
+
if (transform6.flipHorizontal) shape.flipHorizontal = true;
|
|
6764
|
+
if (transform6.flipVertical) shape.flipVertical = true;
|
|
5525
6765
|
if (adjustments) shape.adjustments = adjustments;
|
|
5526
6766
|
if (paths) shape.paths = paths;
|
|
5527
6767
|
const fill = parseDrawingFill(spPr);
|
|
@@ -6163,6 +7403,23 @@ function parseRunPropertiesSnapshot(xml) {
|
|
|
6163
7403
|
return parsePropertiesSnapshot(xml, "rPr");
|
|
6164
7404
|
}
|
|
6165
7405
|
|
|
7406
|
+
// docx/field-flags.ts
|
|
7407
|
+
function parseFieldFlags(element) {
|
|
7408
|
+
const locked = onOffAttribute(element, "fldLock");
|
|
7409
|
+
const dirty = onOffAttribute(element, "dirty");
|
|
7410
|
+
if (locked === void 0 && dirty === void 0) return void 0;
|
|
7411
|
+
return { ...locked !== void 0 && { locked }, ...dirty !== void 0 && { dirty } };
|
|
7412
|
+
}
|
|
7413
|
+
function writeFieldFlags(element, flags) {
|
|
7414
|
+
for (const [name, value] of [
|
|
7415
|
+
["fldLock", flags?.locked],
|
|
7416
|
+
["dirty", flags?.dirty]
|
|
7417
|
+
]) {
|
|
7418
|
+
if (value === void 0) element.removeAttributeNS(WORD_NS, name);
|
|
7419
|
+
else element.setAttributeNS(WORD_NS, `w:${name}`, value ? "true" : "false");
|
|
7420
|
+
}
|
|
7421
|
+
}
|
|
7422
|
+
|
|
6166
7423
|
// docx/write-run.ts
|
|
6167
7424
|
function setAttribute6(element, local, value) {
|
|
6168
7425
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
@@ -6348,6 +7605,7 @@ function createRun(doc, run, base, old, allocator) {
|
|
|
6348
7605
|
if (run.fieldChar) {
|
|
6349
7606
|
const marker = makeW(doc, "fldChar");
|
|
6350
7607
|
setAttribute6(marker, "fldCharType", run.fieldChar);
|
|
7608
|
+
writeFieldFlags(marker, run.fieldFlags);
|
|
6351
7609
|
node.appendChild(marker);
|
|
6352
7610
|
return node;
|
|
6353
7611
|
}
|
|
@@ -6428,6 +7686,11 @@ function takeSimpleFieldCommentEdges(doc, runs, start, end, opens, closes) {
|
|
|
6428
7686
|
after: take(closes, end - 1).reverse().flatMap((edge) => rangeEndNodes(doc, edge))
|
|
6429
7687
|
};
|
|
6430
7688
|
}
|
|
7689
|
+
|
|
7690
|
+
// docx/field-lock.ts
|
|
7691
|
+
function sameFieldFlags(a, b) {
|
|
7692
|
+
return a?.locked === b?.locked && a?.dirty === b?.dirty;
|
|
7693
|
+
}
|
|
6431
7694
|
var MATH_NAMESPACES = /* @__PURE__ */ new Set([
|
|
6432
7695
|
"http://schemas.openxmlformats.org/officeDocument/2006/math",
|
|
6433
7696
|
"http://purl.oclc.org/ooxml/officeDocument/math"
|
|
@@ -6752,6 +8015,7 @@ function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
|
|
|
6752
8015
|
container2 = makeW(doc, "fldSimple");
|
|
6753
8016
|
setW6(container2, "instr", ` ${group.instr} `);
|
|
6754
8017
|
}
|
|
8018
|
+
if (group.kind === "simpleField") writeFieldFlags(container2, runAt(start).fieldFlags);
|
|
6755
8019
|
const edges = group.kind === "simpleField" ? takeSimpleFieldCommentEdges(doc, runs, start, index, opens, closes) : { before: [], after: [] };
|
|
6756
8020
|
for (let item = start; item < index; item++)
|
|
6757
8021
|
for (const node of nodesFor(item)) container2.appendChild(node);
|
|
@@ -6762,13 +8026,18 @@ function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
|
|
|
6762
8026
|
function containerGroup(run) {
|
|
6763
8027
|
if (run.link) return { kind: "link", link: run.link };
|
|
6764
8028
|
if (run.field?.simple)
|
|
6765
|
-
return {
|
|
8029
|
+
return {
|
|
8030
|
+
kind: "simpleField",
|
|
8031
|
+
instr: run.field.instr,
|
|
8032
|
+
instanceId: run.fieldInstanceId,
|
|
8033
|
+
fieldFlags: run.fieldFlags
|
|
8034
|
+
};
|
|
6766
8035
|
return void 0;
|
|
6767
8036
|
}
|
|
6768
8037
|
function sameGroup(a, b) {
|
|
6769
8038
|
if (!a || !b) return a === b;
|
|
6770
8039
|
if (a.kind === "link" && b.kind === "link") return sameLink(a.link, b.link);
|
|
6771
|
-
return a.kind === "simpleField" && b.kind === "simpleField" && a.instr === b.instr && a.instanceId === b.instanceId;
|
|
8040
|
+
return a.kind === "simpleField" && b.kind === "simpleField" && a.instr === b.instr && a.instanceId === b.instanceId && sameFieldFlags(a.fieldFlags, b.fieldFlags);
|
|
6772
8041
|
}
|
|
6773
8042
|
|
|
6774
8043
|
// docx/paragraph-styles.ts
|
|
@@ -7200,8 +8469,8 @@ function replaceSlots(doc, parent, oldNodes, nextNodes, insertionAnchor = null)
|
|
|
7200
8469
|
return marker;
|
|
7201
8470
|
});
|
|
7202
8471
|
const shared = Math.min(placeholders.length, nextNodes.length);
|
|
7203
|
-
for (const [
|
|
7204
|
-
const next = nextNodes[
|
|
8472
|
+
for (const [i2, marker] of placeholders.slice(0, shared).entries()) {
|
|
8473
|
+
const next = nextNodes[i2];
|
|
7205
8474
|
if (next) parent.replaceChild(next, marker);
|
|
7206
8475
|
}
|
|
7207
8476
|
for (const marker of placeholders.slice(shared)) parent.removeChild(marker);
|
|
@@ -7809,6 +9078,217 @@ async function registerNumberingPart(zip) {
|
|
|
7809
9078
|
zip.file(relsPath, buildXml(relsDoc));
|
|
7810
9079
|
}
|
|
7811
9080
|
|
|
9081
|
+
// docx/numbering-parse.ts
|
|
9082
|
+
var integer2 = (value, fallback) => parseInteger(value) ?? fallback;
|
|
9083
|
+
var flag = (element) => onOffElement(element) === true;
|
|
9084
|
+
function byName(root, local) {
|
|
9085
|
+
return Array.from(root.getElementsByTagName("*")).filter(
|
|
9086
|
+
(node) => node.nodeType === 1 && named2(node, local)
|
|
9087
|
+
);
|
|
9088
|
+
}
|
|
9089
|
+
function parseMarkerFormat(rPr) {
|
|
9090
|
+
if (!rPr) return void 0;
|
|
9091
|
+
const format = {};
|
|
9092
|
+
const family = getW(first2(rPr, "rFonts"), "ascii");
|
|
9093
|
+
if (family) format.fontFamily = family;
|
|
9094
|
+
const size = parseInteger(getW(first2(rPr, "sz"), "val"));
|
|
9095
|
+
if (size !== void 0 && size > 0) format.fontSizeHalfPoints = size;
|
|
9096
|
+
if (onOffElement(first2(rPr, "b")) === true) format.bold = true;
|
|
9097
|
+
if (onOffElement(first2(rPr, "i")) === true) format.italic = true;
|
|
9098
|
+
const color = getW(first2(rPr, "color"), "val");
|
|
9099
|
+
if (color && /^[0-9a-f]{6}$/i.test(color)) format.color = `#${color.toLowerCase()}`;
|
|
9100
|
+
return Object.keys(format).length ? format : void 0;
|
|
9101
|
+
}
|
|
9102
|
+
function parseNumberingLevel(lvl) {
|
|
9103
|
+
const level = integer2(getW(lvl, "ilvl"), 0);
|
|
9104
|
+
const start = integer2(getW(first2(lvl, "start"), "val"), 1);
|
|
9105
|
+
const numFmt = enumValue(isStNumberFormat, getW(first2(lvl, "numFmt"), "val"), "w:numFmt") ?? "decimal";
|
|
9106
|
+
const lvlText = getW(first2(lvl, "lvlText"), "val") ?? "";
|
|
9107
|
+
const jc = getW(first2(lvl, "lvlJc"), "val");
|
|
9108
|
+
const ind = first2(first2(lvl, "pPr"), "ind");
|
|
9109
|
+
const suffRaw = getW(first2(lvl, "suff"), "val");
|
|
9110
|
+
const result = { level, start, numFmt, lvlText };
|
|
9111
|
+
if (!first2(lvl, "start")) result.startWasOmitted = true;
|
|
9112
|
+
const paragraphStyleId = getW(first2(lvl, "pStyle"), "val");
|
|
9113
|
+
if (paragraphStyleId) result.paragraphStyleId = paragraphStyleId;
|
|
9114
|
+
if (jc === "left" || jc === "center" || jc === "right") result.lvlJc = jc;
|
|
9115
|
+
const left = getW(ind, "left") ?? getW(ind, "start");
|
|
9116
|
+
if (left !== void 0) result.indentLeftTwips = parseSignedTwips(left) ?? signedTwips(0);
|
|
9117
|
+
const hanging = getW(ind, "hanging");
|
|
9118
|
+
if (hanging !== void 0) result.hangingTwips = parseTwips(hanging) ?? twips(0);
|
|
9119
|
+
const firstLine = getW(ind, "firstLine");
|
|
9120
|
+
if (firstLine !== void 0) result.firstLineTwips = parseTwips(firstLine) ?? twips(0);
|
|
9121
|
+
const tabs = first2(first2(lvl, "pPr"), "tabs");
|
|
9122
|
+
const tab = tabs ? children2(tabs, "tab").find((stop) => getW(stop, "val") !== "clear") : void 0;
|
|
9123
|
+
const tabPos = tab ? parseTwips(getW(tab, "pos")) : void 0;
|
|
9124
|
+
if (tabPos !== void 0) result.tabStopTwips = tabPos;
|
|
9125
|
+
if (flag(first2(lvl, "isLgl"))) result.isLgl = true;
|
|
9126
|
+
const restart = getW(first2(lvl, "lvlRestart"), "val");
|
|
9127
|
+
if (restart !== void 0) result.lvlRestart = integer2(restart, 0);
|
|
9128
|
+
const marker = parseMarkerFormat(first2(lvl, "rPr"));
|
|
9129
|
+
if (marker) result.markerFormat = marker;
|
|
9130
|
+
result.suffix = suffRaw === "space" ? "space" : suffRaw === "nothing" ? "none" : "tab";
|
|
9131
|
+
return result;
|
|
9132
|
+
}
|
|
9133
|
+
function parseAbstractNum(element) {
|
|
9134
|
+
const id = getW(element, "abstractNumId");
|
|
9135
|
+
if (!id) return void 0;
|
|
9136
|
+
const levels = {};
|
|
9137
|
+
for (const lvl of children2(element, "lvl")) {
|
|
9138
|
+
const parsed = parseNumberingLevel(lvl);
|
|
9139
|
+
levels[parsed.level] = parsed;
|
|
9140
|
+
}
|
|
9141
|
+
return { id, levels };
|
|
9142
|
+
}
|
|
9143
|
+
function parseNum(element) {
|
|
9144
|
+
const id = getW(element, "numId");
|
|
9145
|
+
if (!id) return void 0;
|
|
9146
|
+
const abstractNumId = getW(first2(element, "abstractNumId"), "val") ?? "";
|
|
9147
|
+
const levelOverrides = {};
|
|
9148
|
+
for (const override of children2(element, "lvlOverride")) {
|
|
9149
|
+
const level = integer2(getW(override, "ilvl"), 0);
|
|
9150
|
+
const entry = {};
|
|
9151
|
+
const startOverride = getW(first2(override, "startOverride"), "val");
|
|
9152
|
+
if (startOverride !== void 0) entry.startOverride = integer2(startOverride, 1);
|
|
9153
|
+
const lvl = first2(override, "lvl");
|
|
9154
|
+
if (lvl) entry.lvl = parseNumberingLevel(lvl);
|
|
9155
|
+
if (Object.keys(entry).length) levelOverrides[level] = entry;
|
|
9156
|
+
}
|
|
9157
|
+
return {
|
|
9158
|
+
id,
|
|
9159
|
+
abstractNumId,
|
|
9160
|
+
...Object.keys(levelOverrides).length ? { levelOverrides } : {}
|
|
9161
|
+
};
|
|
9162
|
+
}
|
|
9163
|
+
function parseNumberingCatalog(xml) {
|
|
9164
|
+
const document = parseXml2(xml);
|
|
9165
|
+
const root = document.documentElement;
|
|
9166
|
+
const abstractNums = {};
|
|
9167
|
+
const warnings = [];
|
|
9168
|
+
for (const element of byName(root, "abstractNum")) {
|
|
9169
|
+
const parsed = parseAbstractNum(element);
|
|
9170
|
+
if (!parsed) continue;
|
|
9171
|
+
abstractNums[parsed.id] = parsed;
|
|
9172
|
+
const link = getW(first2(element, "numStyleLink"), "val");
|
|
9173
|
+
if (link)
|
|
9174
|
+
warnings.push(
|
|
9175
|
+
`Numbering definition abstractNum ${parsed.id} links to style "${link}"; style-linked numbering levels are not resolved.`
|
|
9176
|
+
);
|
|
9177
|
+
if (byName(element, "lvlPicBulletId").length)
|
|
9178
|
+
warnings.push(
|
|
9179
|
+
`Numbering definition abstractNum ${parsed.id} uses a picture bullet; picture bullets are not rendered.`
|
|
9180
|
+
);
|
|
9181
|
+
}
|
|
9182
|
+
const nums = {};
|
|
9183
|
+
for (const element of byName(root, "num")) {
|
|
9184
|
+
const parsed = parseNum(element);
|
|
9185
|
+
if (parsed) nums[parsed.id] = parsed;
|
|
9186
|
+
}
|
|
9187
|
+
return { abstractNums, nums, warnings: [...new Set(warnings)] };
|
|
9188
|
+
}
|
|
9189
|
+
function resolveNumberingLevel(catalog, numId, level) {
|
|
9190
|
+
const num = catalog.nums[numId];
|
|
9191
|
+
if (!num) return void 0;
|
|
9192
|
+
const override = num.levelOverrides?.[level];
|
|
9193
|
+
const sourceAbstract = catalog.abstractNums[num.abstractNumId]?.levels[level];
|
|
9194
|
+
const abstract = sourceAbstract?.startWasOmitted && sourceAbstract.start === 1 ? { ...sourceAbstract, start: 0 } : sourceAbstract;
|
|
9195
|
+
let base = override?.lvl ?? abstract;
|
|
9196
|
+
if (!base) return void 0;
|
|
9197
|
+
if (override?.lvl) {
|
|
9198
|
+
const { lvlRestart: _ignored, ...properties } = base;
|
|
9199
|
+
base = {
|
|
9200
|
+
...properties,
|
|
9201
|
+
...abstract?.lvlRestart !== void 0 ? { lvlRestart: abstract.lvlRestart } : {}
|
|
9202
|
+
};
|
|
9203
|
+
}
|
|
9204
|
+
let start = override?.startOverride ?? base.start;
|
|
9205
|
+
if (override?.lvl) {
|
|
9206
|
+
if (abstract?.lvlRestart === 0 && override.startOverride === void 0) start = abstract.start;
|
|
9207
|
+
else if (!override.lvl.startWasOmitted || override.lvl.start !== 1) start = override.lvl.start;
|
|
9208
|
+
else start = override.startOverride ?? 0;
|
|
9209
|
+
}
|
|
9210
|
+
return start !== base.start ? { ...base, start } : base;
|
|
9211
|
+
}
|
|
9212
|
+
|
|
9213
|
+
// docx/numbering-start-edit.ts
|
|
9214
|
+
function assertListStartValue(level, start) {
|
|
9215
|
+
if (!Number.isInteger(level) || level < 0 || level > 8)
|
|
9216
|
+
throw new Error("List level must be an integer from 0 through 8.");
|
|
9217
|
+
if (!Number.isInteger(start) || start < 0 || start > 2147483647)
|
|
9218
|
+
throw new Error("List start must be an integer from 0 through 2147483647.");
|
|
9219
|
+
}
|
|
9220
|
+
|
|
9221
|
+
// docx/numbering-start-patch.ts
|
|
9222
|
+
function withoutStarts(num) {
|
|
9223
|
+
const { levelOverrides, ...properties } = num;
|
|
9224
|
+
const kept = {};
|
|
9225
|
+
for (const [level, override] of Object.entries(levelOverrides ?? {})) {
|
|
9226
|
+
const { startOverride: _start, ...rest } = override;
|
|
9227
|
+
if (Object.keys(rest).length) kept[level] = rest;
|
|
9228
|
+
}
|
|
9229
|
+
return { ...properties, ...Object.keys(kept).length ? { levelOverrides: kept } : {} };
|
|
9230
|
+
}
|
|
9231
|
+
function numberingStartChanges(prior, next) {
|
|
9232
|
+
const changes = [];
|
|
9233
|
+
for (const [id, previous] of Object.entries(prior?.nums ?? {})) {
|
|
9234
|
+
const current = next.nums[id];
|
|
9235
|
+
if (!current || JSON.stringify(withoutStarts(current)) !== JSON.stringify(withoutStarts(previous)))
|
|
9236
|
+
throw new Error(
|
|
9237
|
+
`Cannot edit numbering definition num "${id}" except its supported start overrides.`
|
|
9238
|
+
);
|
|
9239
|
+
for (const key of /* @__PURE__ */ new Set([
|
|
9240
|
+
...Object.keys(previous.levelOverrides ?? {}),
|
|
9241
|
+
...Object.keys(current.levelOverrides ?? {})
|
|
9242
|
+
])) {
|
|
9243
|
+
const level = Number(key);
|
|
9244
|
+
const old = previous.levelOverrides?.[level];
|
|
9245
|
+
const value = current.levelOverrides?.[level];
|
|
9246
|
+
if (old?.startOverride === value?.startOverride) continue;
|
|
9247
|
+
if (value?.startOverride === void 0)
|
|
9248
|
+
throw new Error("Removing a list start override is unsupported.");
|
|
9249
|
+
assertListStartValue(level, value.startOverride);
|
|
9250
|
+
if (String(level) !== key || !prior || !resolveNumberingLevel(prior, id, level))
|
|
9251
|
+
throw new Error("List instance or level does not exist.");
|
|
9252
|
+
if (old?.lvl || value.lvl)
|
|
9253
|
+
throw new Error("Changing starts with a full level override is unsupported.");
|
|
9254
|
+
changes.push({ numId: id, level, start: value.startOverride });
|
|
9255
|
+
}
|
|
9256
|
+
}
|
|
9257
|
+
return changes;
|
|
9258
|
+
}
|
|
9259
|
+
function patchNumberingStarts(doc, changes) {
|
|
9260
|
+
const sameNumber = (source, expected) => source !== void 0 && /^[+-]?\d+$/.test(source) && Number(source) === Number(expected);
|
|
9261
|
+
const prepared = changes.map((change) => {
|
|
9262
|
+
const nums = children2(doc.documentElement, "num").filter(
|
|
9263
|
+
(num2) => sameNumber(getW(num2, "numId"), change.numId)
|
|
9264
|
+
);
|
|
9265
|
+
if (nums.length !== 1 || getW(nums[0], "numId") !== change.numId)
|
|
9266
|
+
throw new Error("Cannot patch an ambiguous or missing source list instance.");
|
|
9267
|
+
const num = nums[0];
|
|
9268
|
+
const overrides = children2(num, "lvlOverride").filter(
|
|
9269
|
+
(node) => sameNumber(getW(node, "ilvl"), String(change.level))
|
|
9270
|
+
);
|
|
9271
|
+
if (overrides.length > 1) throw new Error("Cannot patch duplicate source level overrides.");
|
|
9272
|
+
const override = overrides[0];
|
|
9273
|
+
if (override && getW(override, "ilvl") !== String(change.level))
|
|
9274
|
+
throw new Error("Cannot patch a noncanonical source level override.");
|
|
9275
|
+
if (override && (children2(override, "lvl").length || children2(override, "startOverride").length > 1))
|
|
9276
|
+
throw new Error("Cannot patch a full or ambiguous source level override.");
|
|
9277
|
+
return { change, num, override };
|
|
9278
|
+
});
|
|
9279
|
+
for (const { change, num, override: existing } of prepared) {
|
|
9280
|
+
const override = existing ?? makeW(doc, "lvlOverride");
|
|
9281
|
+
if (!existing) {
|
|
9282
|
+
override.setAttributeNS(WORD_NS, "w:ilvl", String(change.level));
|
|
9283
|
+
const after = children2(num, "lvlOverride").at(-1) ?? children2(num, "abstractNumId")[0];
|
|
9284
|
+
num.insertBefore(override, after?.nextSibling ?? null);
|
|
9285
|
+
}
|
|
9286
|
+
const start = children2(override, "startOverride")[0] ?? makeW(doc, "startOverride");
|
|
9287
|
+
start.setAttributeNS(WORD_NS, "w:val", String(change.start));
|
|
9288
|
+
if (!start.parentNode) override.insertBefore(start, override.firstChild);
|
|
9289
|
+
}
|
|
9290
|
+
}
|
|
9291
|
+
|
|
7812
9292
|
// docx/numbering-package.ts
|
|
7813
9293
|
function setAttribute8(element, local, value) {
|
|
7814
9294
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
@@ -7913,17 +9393,14 @@ async function applyNumberingCatalog(zip, model, binding) {
|
|
|
7913
9393
|
throw new Error(
|
|
7914
9394
|
`Cannot edit numbering definition abstractNum "${id}"; the original numbering.xml is preserved unchanged.`
|
|
7915
9395
|
);
|
|
7916
|
-
|
|
7917
|
-
if (JSON.stringify(next.nums[id]) !== JSON.stringify(prior?.nums[id]))
|
|
7918
|
-
throw new Error(
|
|
7919
|
-
`Cannot edit numbering definition num "${id}"; the original numbering.xml is preserved unchanged.`
|
|
7920
|
-
);
|
|
9396
|
+
const startChanges = numberingStartChanges(prior, next);
|
|
7921
9397
|
const newAbstractIds = Object.keys(next.abstractNums).filter((id) => !prior?.abstractNums[id]);
|
|
7922
9398
|
const newNumIds = Object.keys(next.nums).filter((id) => !prior?.nums[id]);
|
|
7923
|
-
if (!newAbstractIds.length && !newNumIds.length) return;
|
|
9399
|
+
if (!newAbstractIds.length && !newNumIds.length && !startChanges.length) return;
|
|
7924
9400
|
const existingFile = zip.file("word/numbering.xml");
|
|
7925
9401
|
const doc = existingFile ? parseXml2(await existingFile.async("string")) : parseXml2(`<w:numbering xmlns:w="${WORD_NS}"/>`);
|
|
7926
9402
|
const root = doc.documentElement;
|
|
9403
|
+
patchNumberingStarts(doc, startChanges);
|
|
7927
9404
|
const cleanup = children2(root, "numIdMacAtCleanup")[0] ?? null;
|
|
7928
9405
|
const firstNum = children2(root, "num")[0] ?? cleanup;
|
|
7929
9406
|
for (const id of newAbstractIds) {
|
|
@@ -8936,23 +10413,31 @@ function createFieldTracker() {
|
|
|
8936
10413
|
const stack = [];
|
|
8937
10414
|
return (element, run) => {
|
|
8938
10415
|
let resultInstr;
|
|
10416
|
+
let resultLocked;
|
|
8939
10417
|
for (const child3 of Array.from(element.childNodes)) {
|
|
8940
10418
|
if (!isElement(child3)) continue;
|
|
8941
10419
|
if (named2(child3, "fldChar")) {
|
|
8942
10420
|
const type = getW(child3, "fldCharType");
|
|
8943
|
-
if (type === "begin")
|
|
8944
|
-
|
|
10421
|
+
if (type === "begin") {
|
|
10422
|
+
const locked = parseFieldFlags(child3)?.locked;
|
|
10423
|
+
stack.push({ instr: "", inResult: false, ...locked !== void 0 && { locked } });
|
|
10424
|
+
} else if (type === "separate") {
|
|
8945
10425
|
const top = stack.at(-1);
|
|
8946
10426
|
if (top) top.inResult = true;
|
|
8947
10427
|
} else if (type === "end") stack.pop();
|
|
8948
10428
|
} else {
|
|
8949
10429
|
const top = stack.at(-1);
|
|
8950
10430
|
if (named2(child3, "instrText") && top && !top.inResult) top.instr += textContent(child3);
|
|
8951
|
-
else if ((named2(child3, "t") || named2(child3, "delText")) && top?.inResult)
|
|
10431
|
+
else if ((named2(child3, "t") || named2(child3, "delText")) && top?.inResult) {
|
|
8952
10432
|
resultInstr = top.instr.trim();
|
|
10433
|
+
resultLocked = top.locked;
|
|
10434
|
+
}
|
|
8953
10435
|
}
|
|
8954
10436
|
}
|
|
8955
|
-
if (resultInstr)
|
|
10437
|
+
if (resultInstr) {
|
|
10438
|
+
run.field = { instr: resultInstr };
|
|
10439
|
+
if (resultLocked !== void 0) run.fieldFlags = { locked: resultLocked };
|
|
10440
|
+
}
|
|
8956
10441
|
return run;
|
|
8957
10442
|
};
|
|
8958
10443
|
}
|
|
@@ -8963,7 +10448,11 @@ function storyFieldResults(container2) {
|
|
|
8963
10448
|
if (named2(element, "fldSimple") || named2(element, "txbxContent")) return;
|
|
8964
10449
|
if (named2(element, "r")) {
|
|
8965
10450
|
const run = trackField(element, { text: "" });
|
|
8966
|
-
if (run.field)
|
|
10451
|
+
if (run.field)
|
|
10452
|
+
metadata.set(element, {
|
|
10453
|
+
field: run.field,
|
|
10454
|
+
...run.fieldFlags && { fieldFlags: run.fieldFlags }
|
|
10455
|
+
});
|
|
8967
10456
|
return;
|
|
8968
10457
|
}
|
|
8969
10458
|
for (const child3 of Array.from(element.childNodes)) if (isElement(child3)) visit(child3);
|
|
@@ -9055,7 +10544,11 @@ function parseRun2(node, revision) {
|
|
|
9055
10544
|
if (breakKind) run.break = breakKind;
|
|
9056
10545
|
if (noteReference) run.noteReference = noteReference;
|
|
9057
10546
|
if (noteMark) run.noteMark = noteMark;
|
|
9058
|
-
if (fieldChar)
|
|
10547
|
+
if (fieldChar) {
|
|
10548
|
+
run.fieldChar = fieldChar;
|
|
10549
|
+
const flags = parseFieldFlags(only);
|
|
10550
|
+
if (flags) run.fieldFlags = flags;
|
|
10551
|
+
}
|
|
9059
10552
|
if (fieldCode !== void 0) run.fieldCode = fieldCode;
|
|
9060
10553
|
const runRevision = revision ?? runFormatRevision(props);
|
|
9061
10554
|
if (runRevision) run.revision = runRevision;
|
|
@@ -9074,8 +10567,11 @@ function parseParagraph2(node, id, fields) {
|
|
|
9074
10567
|
(element, revision) => {
|
|
9075
10568
|
const run = parseRun2(element, revision);
|
|
9076
10569
|
if (!fields) return trackField(element, run);
|
|
9077
|
-
const
|
|
9078
|
-
if (
|
|
10570
|
+
const metadata = fields.get(element);
|
|
10571
|
+
if (metadata) {
|
|
10572
|
+
run.field = { ...metadata.field };
|
|
10573
|
+
if (metadata.fieldFlags) run.fieldFlags = { ...metadata.fieldFlags };
|
|
10574
|
+
}
|
|
9079
10575
|
return run;
|
|
9080
10576
|
},
|
|
9081
10577
|
(item) => {
|
|
@@ -9097,20 +10593,23 @@ function parseParagraph2(node, id, fields) {
|
|
|
9097
10593
|
);
|
|
9098
10594
|
if (link) return results.map((run) => ({ ...run, link }));
|
|
9099
10595
|
const field = { instr: instr.trim(), simple: true };
|
|
10596
|
+
const flags = parseFieldFlags(item);
|
|
10597
|
+
const fieldState = flags ? { fieldFlags: flags } : {};
|
|
9100
10598
|
const fieldInstanceId = `${id}:simple-field-${simpleFieldIndex++}`;
|
|
9101
|
-
if (!results.length)
|
|
10599
|
+
if (!results.length)
|
|
10600
|
+
return [{ text: fieldPlaceholderText(instr), field, fieldInstanceId, ...fieldState }];
|
|
9102
10601
|
if (results.every(
|
|
9103
10602
|
(run) => !run.text && !run.equation && !run.image && !run.break && !run.noteReference && !run.noteMark && !run.fieldChar && run.fieldCode === void 0
|
|
9104
10603
|
)) {
|
|
9105
10604
|
return [
|
|
9106
|
-
{ text: "", fieldChar: "begin" },
|
|
10605
|
+
{ text: "", fieldChar: "begin", ...fieldState },
|
|
9107
10606
|
{ text: "", fieldCode: instr },
|
|
9108
10607
|
{ text: "", fieldChar: "separate" },
|
|
9109
10608
|
...results,
|
|
9110
10609
|
{ text: "", fieldChar: "end" }
|
|
9111
10610
|
];
|
|
9112
10611
|
}
|
|
9113
|
-
return results.map((run) => ({ ...run, field, fieldInstanceId }));
|
|
10612
|
+
return results.map((run) => ({ ...run, field, fieldInstanceId, ...fieldState }));
|
|
9114
10613
|
},
|
|
9115
10614
|
(hyperlink) => {
|
|
9116
10615
|
if (!activeContext) return void 0;
|
|
@@ -9412,115 +10911,6 @@ async function parseDocumentParts(zip, body, blocks, drawings) {
|
|
|
9412
10911
|
};
|
|
9413
10912
|
}
|
|
9414
10913
|
|
|
9415
|
-
// docx/numbering-parse.ts
|
|
9416
|
-
var integer2 = (value, fallback) => parseInteger(value) ?? fallback;
|
|
9417
|
-
var flag = (element) => onOffElement(element) === true;
|
|
9418
|
-
function byName(root, local) {
|
|
9419
|
-
return Array.from(root.getElementsByTagName("*")).filter(
|
|
9420
|
-
(node) => node.nodeType === 1 && named2(node, local)
|
|
9421
|
-
);
|
|
9422
|
-
}
|
|
9423
|
-
function parseMarkerFormat(rPr) {
|
|
9424
|
-
if (!rPr) return void 0;
|
|
9425
|
-
const format = {};
|
|
9426
|
-
const family = getW(first2(rPr, "rFonts"), "ascii");
|
|
9427
|
-
if (family) format.fontFamily = family;
|
|
9428
|
-
const size = parseInteger(getW(first2(rPr, "sz"), "val"));
|
|
9429
|
-
if (size !== void 0 && size > 0) format.fontSizeHalfPoints = size;
|
|
9430
|
-
if (onOffElement(first2(rPr, "b")) === true) format.bold = true;
|
|
9431
|
-
if (onOffElement(first2(rPr, "i")) === true) format.italic = true;
|
|
9432
|
-
const color = getW(first2(rPr, "color"), "val");
|
|
9433
|
-
if (color && /^[0-9a-f]{6}$/i.test(color)) format.color = `#${color.toLowerCase()}`;
|
|
9434
|
-
return Object.keys(format).length ? format : void 0;
|
|
9435
|
-
}
|
|
9436
|
-
function parseNumberingLevel(lvl) {
|
|
9437
|
-
const level = integer2(getW(lvl, "ilvl"), 0);
|
|
9438
|
-
const start = integer2(getW(first2(lvl, "start"), "val"), 1);
|
|
9439
|
-
const numFmt = enumValue(isStNumberFormat, getW(first2(lvl, "numFmt"), "val"), "w:numFmt") ?? "decimal";
|
|
9440
|
-
const lvlText = getW(first2(lvl, "lvlText"), "val") ?? "";
|
|
9441
|
-
const jc = getW(first2(lvl, "lvlJc"), "val");
|
|
9442
|
-
const ind = first2(first2(lvl, "pPr"), "ind");
|
|
9443
|
-
const suffRaw = getW(first2(lvl, "suff"), "val");
|
|
9444
|
-
const result = { level, start, numFmt, lvlText };
|
|
9445
|
-
if (!first2(lvl, "start")) result.startWasOmitted = true;
|
|
9446
|
-
const paragraphStyleId = getW(first2(lvl, "pStyle"), "val");
|
|
9447
|
-
if (paragraphStyleId) result.paragraphStyleId = paragraphStyleId;
|
|
9448
|
-
if (jc === "left" || jc === "center" || jc === "right") result.lvlJc = jc;
|
|
9449
|
-
const left = getW(ind, "left") ?? getW(ind, "start");
|
|
9450
|
-
if (left !== void 0) result.indentLeftTwips = parseSignedTwips(left) ?? signedTwips(0);
|
|
9451
|
-
const hanging = getW(ind, "hanging");
|
|
9452
|
-
if (hanging !== void 0) result.hangingTwips = parseTwips(hanging) ?? twips(0);
|
|
9453
|
-
const firstLine = getW(ind, "firstLine");
|
|
9454
|
-
if (firstLine !== void 0) result.firstLineTwips = parseTwips(firstLine) ?? twips(0);
|
|
9455
|
-
const tabs = first2(first2(lvl, "pPr"), "tabs");
|
|
9456
|
-
const tab = tabs ? children2(tabs, "tab").find((stop) => getW(stop, "val") !== "clear") : void 0;
|
|
9457
|
-
const tabPos = tab ? parseTwips(getW(tab, "pos")) : void 0;
|
|
9458
|
-
if (tabPos !== void 0) result.tabStopTwips = tabPos;
|
|
9459
|
-
if (flag(first2(lvl, "isLgl"))) result.isLgl = true;
|
|
9460
|
-
const restart = getW(first2(lvl, "lvlRestart"), "val");
|
|
9461
|
-
if (restart !== void 0) result.lvlRestart = integer2(restart, 0);
|
|
9462
|
-
const marker = parseMarkerFormat(first2(lvl, "rPr"));
|
|
9463
|
-
if (marker) result.markerFormat = marker;
|
|
9464
|
-
result.suffix = suffRaw === "space" ? "space" : suffRaw === "nothing" ? "none" : "tab";
|
|
9465
|
-
return result;
|
|
9466
|
-
}
|
|
9467
|
-
function parseAbstractNum(element) {
|
|
9468
|
-
const id = getW(element, "abstractNumId");
|
|
9469
|
-
if (!id) return void 0;
|
|
9470
|
-
const levels = {};
|
|
9471
|
-
for (const lvl of children2(element, "lvl")) {
|
|
9472
|
-
const parsed = parseNumberingLevel(lvl);
|
|
9473
|
-
levels[parsed.level] = parsed;
|
|
9474
|
-
}
|
|
9475
|
-
return { id, levels };
|
|
9476
|
-
}
|
|
9477
|
-
function parseNum(element) {
|
|
9478
|
-
const id = getW(element, "numId");
|
|
9479
|
-
if (!id) return void 0;
|
|
9480
|
-
const abstractNumId = getW(first2(element, "abstractNumId"), "val") ?? "";
|
|
9481
|
-
const levelOverrides = {};
|
|
9482
|
-
for (const override of children2(element, "lvlOverride")) {
|
|
9483
|
-
const level = integer2(getW(override, "ilvl"), 0);
|
|
9484
|
-
const entry = {};
|
|
9485
|
-
const startOverride = getW(first2(override, "startOverride"), "val");
|
|
9486
|
-
if (startOverride !== void 0) entry.startOverride = integer2(startOverride, 1);
|
|
9487
|
-
const lvl = first2(override, "lvl");
|
|
9488
|
-
if (lvl) entry.lvl = parseNumberingLevel(lvl);
|
|
9489
|
-
if (Object.keys(entry).length) levelOverrides[level] = entry;
|
|
9490
|
-
}
|
|
9491
|
-
return {
|
|
9492
|
-
id,
|
|
9493
|
-
abstractNumId,
|
|
9494
|
-
...Object.keys(levelOverrides).length ? { levelOverrides } : {}
|
|
9495
|
-
};
|
|
9496
|
-
}
|
|
9497
|
-
function parseNumberingCatalog(xml) {
|
|
9498
|
-
const document = parseXml2(xml);
|
|
9499
|
-
const root = document.documentElement;
|
|
9500
|
-
const abstractNums = {};
|
|
9501
|
-
const warnings = [];
|
|
9502
|
-
for (const element of byName(root, "abstractNum")) {
|
|
9503
|
-
const parsed = parseAbstractNum(element);
|
|
9504
|
-
if (!parsed) continue;
|
|
9505
|
-
abstractNums[parsed.id] = parsed;
|
|
9506
|
-
const link = getW(first2(element, "numStyleLink"), "val");
|
|
9507
|
-
if (link)
|
|
9508
|
-
warnings.push(
|
|
9509
|
-
`Numbering definition abstractNum ${parsed.id} links to style "${link}"; style-linked numbering levels are not resolved.`
|
|
9510
|
-
);
|
|
9511
|
-
if (byName(element, "lvlPicBulletId").length)
|
|
9512
|
-
warnings.push(
|
|
9513
|
-
`Numbering definition abstractNum ${parsed.id} uses a picture bullet; picture bullets are not rendered.`
|
|
9514
|
-
);
|
|
9515
|
-
}
|
|
9516
|
-
const nums = {};
|
|
9517
|
-
for (const element of byName(root, "num")) {
|
|
9518
|
-
const parsed = parseNum(element);
|
|
9519
|
-
if (parsed) nums[parsed.id] = parsed;
|
|
9520
|
-
}
|
|
9521
|
-
return { abstractNums, nums, warnings: [...new Set(warnings)] };
|
|
9522
|
-
}
|
|
9523
|
-
|
|
9524
10914
|
// docx/comments.ts
|
|
9525
10915
|
var W14_NS2 = "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
9526
10916
|
var W15_NS2 = "http://schemas.microsoft.com/office/word/2012/wordml";
|
|
@@ -9564,62 +10954,88 @@ function parseComments(commentsXml, extendedXml) {
|
|
|
9564
10954
|
return comments;
|
|
9565
10955
|
}
|
|
9566
10956
|
|
|
9567
|
-
//
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
"
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
"hlink",
|
|
9581
|
-
"folHlink"
|
|
9582
|
-
];
|
|
9583
|
-
function drawingChild(parent, local) {
|
|
9584
|
-
if (!parent) return void 0;
|
|
9585
|
-
for (const node of Array.from(parent.childNodes)) {
|
|
9586
|
-
const element = node;
|
|
9587
|
-
if (element.nodeType === 1 && element.localName === local && element.namespaceURI === DRAWING_NS)
|
|
9588
|
-
return element;
|
|
10957
|
+
// drawingml/theme.ts
|
|
10958
|
+
new Set(THEME_COLOR_SLOTS);
|
|
10959
|
+
function nonEmpty(value) {
|
|
10960
|
+
return value ? value : void 0;
|
|
10961
|
+
}
|
|
10962
|
+
function parseThemeColorScheme(scheme) {
|
|
10963
|
+
const result = { colors: {} };
|
|
10964
|
+
if (!scheme) return result;
|
|
10965
|
+
const name = nonEmpty(scheme.getAttribute("name"));
|
|
10966
|
+
if (name) result.name = name;
|
|
10967
|
+
for (const slot2 of THEME_COLOR_SLOTS) {
|
|
10968
|
+
const color = parseDrawingColorIn(first(scheme, slot2, NS.a));
|
|
10969
|
+
if (color) result.colors[slot2] = color;
|
|
9589
10970
|
}
|
|
9590
|
-
return
|
|
10971
|
+
return result;
|
|
9591
10972
|
}
|
|
9592
|
-
function
|
|
9593
|
-
const
|
|
9594
|
-
if (
|
|
9595
|
-
const
|
|
9596
|
-
|
|
9597
|
-
|
|
10973
|
+
function parseFontCollection(collection) {
|
|
10974
|
+
const result = { scripts: {} };
|
|
10975
|
+
if (!collection) return result;
|
|
10976
|
+
const typeface = (local) => nonEmpty(first(collection, local, NS.a)?.getAttribute("typeface"));
|
|
10977
|
+
const latin = typeface("latin");
|
|
10978
|
+
const eastAsia = typeface("ea");
|
|
10979
|
+
const complexScript = typeface("cs");
|
|
10980
|
+
if (latin) result.latin = latin;
|
|
10981
|
+
if (eastAsia) result.eastAsia = eastAsia;
|
|
10982
|
+
if (complexScript) result.complexScript = complexScript;
|
|
10983
|
+
for (const font of elements(collection)) {
|
|
10984
|
+
if (font.localName !== "font") continue;
|
|
10985
|
+
const script = nonEmpty(font.getAttribute("script"));
|
|
10986
|
+
const face = nonEmpty(font.getAttribute("typeface"));
|
|
10987
|
+
if (script && face && !Object.hasOwn(result.scripts, script)) result.scripts[script] = face;
|
|
10988
|
+
}
|
|
10989
|
+
return result;
|
|
9598
10990
|
}
|
|
9599
|
-
function
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
10991
|
+
function parseThemeFontScheme(scheme) {
|
|
10992
|
+
const result = {
|
|
10993
|
+
major: parseFontCollection(first(scheme, "majorFont", NS.a)),
|
|
10994
|
+
minor: parseFontCollection(first(scheme, "minorFont", NS.a))
|
|
10995
|
+
};
|
|
10996
|
+
const name = nonEmpty(scheme?.getAttribute("name"));
|
|
10997
|
+
if (name) result.name = name;
|
|
10998
|
+
return result;
|
|
10999
|
+
}
|
|
11000
|
+
function rootOf2(source) {
|
|
11001
|
+
return "documentElement" in source ? source.documentElement : source;
|
|
11002
|
+
}
|
|
11003
|
+
function parseTheme(source) {
|
|
11004
|
+
const root = rootOf2(source);
|
|
11005
|
+
const holder = first(root, "themeElements", NS.a) ?? root;
|
|
11006
|
+
const theme = {
|
|
11007
|
+
colorScheme: parseThemeColorScheme(first(holder, "clrScheme", NS.a)),
|
|
11008
|
+
fontScheme: parseThemeFontScheme(first(holder, "fontScheme", NS.a))
|
|
11009
|
+
};
|
|
11010
|
+
const name = nonEmpty(root.getAttribute("name"));
|
|
11011
|
+
if (name) theme.name = name;
|
|
11012
|
+
return theme;
|
|
11013
|
+
}
|
|
11014
|
+
|
|
11015
|
+
// drawingml/theme-color.ts
|
|
11016
|
+
function themeSlotHex(color) {
|
|
11017
|
+
if (!color) return void 0;
|
|
11018
|
+
const value = color.kind === "srgb" ? color.value : color.kind === "system" ? color.fallback : void 0;
|
|
11019
|
+
return value ? value.toUpperCase() : void 0;
|
|
11020
|
+
}
|
|
11021
|
+
|
|
11022
|
+
// docx/theme.ts
|
|
11023
|
+
function fontSetOf(collection) {
|
|
11024
|
+
const { latin, eastAsia, complexScript } = collection;
|
|
9604
11025
|
return {
|
|
9605
11026
|
...latin ? { latin } : {},
|
|
9606
|
-
...
|
|
9607
|
-
...
|
|
11027
|
+
...eastAsia ? { eastAsia } : {},
|
|
11028
|
+
...complexScript ? { complexScript } : {}
|
|
9608
11029
|
};
|
|
9609
11030
|
}
|
|
9610
|
-
function
|
|
9611
|
-
const
|
|
9612
|
-
const root = document.documentElement;
|
|
9613
|
-
const clrScheme = Array.from(root.getElementsByTagNameNS(DRAWING_NS, "clrScheme"))[0];
|
|
11031
|
+
function parseTheme2(xml) {
|
|
11032
|
+
const theme = parseTheme(parseXml2(xml));
|
|
9614
11033
|
const colors = {};
|
|
9615
|
-
for (const
|
|
9616
|
-
const
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
}
|
|
9620
|
-
const fontScheme = Array.from(root.getElementsByTagNameNS(DRAWING_NS, "fontScheme"))[0];
|
|
9621
|
-
const major = drawingChild(fontScheme, "majorFont");
|
|
9622
|
-
const minor = drawingChild(fontScheme, "minorFont");
|
|
11034
|
+
for (const slot2 of THEME_COLOR_SLOTS) {
|
|
11035
|
+
const value = themeSlotHex(theme.colorScheme.colors[slot2]);
|
|
11036
|
+
if (value) colors[slot2] = value;
|
|
11037
|
+
}
|
|
11038
|
+
const { major, minor } = theme.fontScheme;
|
|
9623
11039
|
return { colors, colorMapping: {}, fonts: { major: fontSetOf(major), minor: fontSetOf(minor) } };
|
|
9624
11040
|
}
|
|
9625
11041
|
var MAPPING_KEYS = ["bg1", "tx1", "bg2", "tx2"];
|
|
@@ -9844,7 +11260,7 @@ async function readPackage(input) {
|
|
|
9844
11260
|
const themeFile = zip.file("word/theme/theme1.xml");
|
|
9845
11261
|
const settingsFile = zip.file("word/settings.xml");
|
|
9846
11262
|
if (themeFile) {
|
|
9847
|
-
model.theme =
|
|
11263
|
+
model.theme = parseTheme2(await themeFile.async("string"));
|
|
9848
11264
|
if (settingsFile) {
|
|
9849
11265
|
const settingsXml = await settingsFile.async("string");
|
|
9850
11266
|
model.theme.colorMapping = withParseWarnings(
|
|
@@ -10019,7 +11435,7 @@ function readDocFib(wordDoc) {
|
|
|
10019
11435
|
if (expectedCounts.get(nFib) !== fibRgFcLcbCount || cswNew !== 0 && cswNew !== (nFib === 274 ? 5 : 2))
|
|
10020
11436
|
throw new Error("Word FIB version and array counts disagree");
|
|
10021
11437
|
const ccpText = view.getInt32(fibRgLw97Offset + 12, true);
|
|
10022
|
-
const otherStories = [4, 5, 7, 8, 9, 10].map((
|
|
11438
|
+
const otherStories = [4, 5, 7, 8, 9, 10].map((i2) => view.getInt32(fibRgLw97Offset + i2 * 4, true));
|
|
10023
11439
|
if (ccpText < 0 || otherStories.some((cp) => cp < 0))
|
|
10024
11440
|
throw new Error("Negative Word story length");
|
|
10025
11441
|
function fcLcbPair(index) {
|
|
@@ -10133,14 +11549,14 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10133
11549
|
};
|
|
10134
11550
|
const fatCount = read32(44), difatCount = read32(72), difatStart = read32(68);
|
|
10135
11551
|
const fatIds = [];
|
|
10136
|
-
for (let
|
|
10137
|
-
const id = read32(76 + 4 *
|
|
11552
|
+
for (let i2 = 0; i2 < 109 && fatIds.length < fatCount; i2++) {
|
|
11553
|
+
const id = read32(76 + 4 * i2);
|
|
10138
11554
|
if (id <= MAX)
|
|
10139
11555
|
fatIds.push(id);
|
|
10140
11556
|
}
|
|
10141
11557
|
let difat = difatStart;
|
|
10142
11558
|
const difatIds = /* @__PURE__ */ new Set();
|
|
10143
|
-
for (let
|
|
11559
|
+
for (let i2 = 0; i2 < difatCount; i2++) {
|
|
10144
11560
|
if (difatIds.has(difat) || difat > MAX)
|
|
10145
11561
|
return reject();
|
|
10146
11562
|
difatIds.add(difat);
|
|
@@ -10163,7 +11579,7 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10163
11579
|
const exactChain = (table, start, bytes, unit) => chain(table, start, Math.ceil(bytes / unit));
|
|
10164
11580
|
const dirStart = read32(48), dirSectors = chainToEnd(fat, dirStart, sectorCount);
|
|
10165
11581
|
const dirBytes = new Uint8Array(dirSectors.length * sectorSize);
|
|
10166
|
-
dirSectors.forEach((id,
|
|
11582
|
+
dirSectors.forEach((id, i2) => dirBytes.set(sector(id), i2 * sectorSize));
|
|
10167
11583
|
const dvDir = new DataView(dirBytes.buffer);
|
|
10168
11584
|
const entries = [];
|
|
10169
11585
|
for (let p = 0, id = 0; p + SIZE <= dirBytes.length; p += SIZE, id++) {
|
|
@@ -10174,8 +11590,8 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10174
11590
|
if (nameLength < 2 || nameLength > 64 || nameLength % 2)
|
|
10175
11591
|
return reject();
|
|
10176
11592
|
let name = "";
|
|
10177
|
-
for (let
|
|
10178
|
-
name += String.fromCharCode(dvDir.getUint16(p +
|
|
11593
|
+
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
11594
|
+
name += String.fromCharCode(dvDir.getUint16(p + i2, true));
|
|
10179
11595
|
const sizeLow = dvDir.getUint32(p + 120, true), sizeHigh = dvDir.getUint32(p + 124, true);
|
|
10180
11596
|
if (sizeHigh !== 0)
|
|
10181
11597
|
return reject();
|
|
@@ -10290,19 +11706,19 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10290
11706
|
if (target.size >= miniCutoff) {
|
|
10291
11707
|
const ids2 = exactChain(fat, target.start, target.size, sectorSize);
|
|
10292
11708
|
const result2 = new Uint8Array(ids2.length * sectorSize);
|
|
10293
|
-
ids2.forEach((id,
|
|
11709
|
+
ids2.forEach((id, i2) => result2.set(sector(id), i2 * sectorSize));
|
|
10294
11710
|
return result2.slice(0, target.size);
|
|
10295
11711
|
}
|
|
10296
11712
|
const ids = exactChain(miniFat, target.start, target.size, miniSize);
|
|
10297
11713
|
const rootSectors = exactChain(fat, rootMini.start, rootMini.size, sectorSize);
|
|
10298
11714
|
const result = new Uint8Array(ids.length * miniSize);
|
|
10299
|
-
ids.forEach((id,
|
|
11715
|
+
ids.forEach((id, i2) => {
|
|
10300
11716
|
const start = id * miniSize;
|
|
10301
11717
|
if (start + miniSize > rootMini.size)
|
|
10302
11718
|
throw new Error("Mini stream out of bounds");
|
|
10303
11719
|
const rootSector = rootSectors[Math.floor(start / sectorSize)];
|
|
10304
11720
|
const source = sector(rootSector).subarray(start % sectorSize, start % sectorSize + miniSize);
|
|
10305
|
-
result.set(source,
|
|
11721
|
+
result.set(source, i2 * miniSize);
|
|
10306
11722
|
});
|
|
10307
11723
|
return result.slice(0, target.size);
|
|
10308
11724
|
}
|
|
@@ -10312,8 +11728,8 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10312
11728
|
if (target.size >= miniCutoff) {
|
|
10313
11729
|
const sectors = exactChain(fat, target.start, target.size, sectorSize);
|
|
10314
11730
|
sectors.forEach((id) => sector(id));
|
|
10315
|
-
for (let
|
|
10316
|
-
output.set(replacement.subarray(
|
|
11731
|
+
for (let i2 = 0; i2 < sectors.length; i2++)
|
|
11732
|
+
output.set(replacement.subarray(i2 * sectorSize, Math.min((i2 + 1) * sectorSize, replacement.length)), offset(sectors[i2]));
|
|
10317
11733
|
} else {
|
|
10318
11734
|
if (!miniFat.length)
|
|
10319
11735
|
return reject();
|
|
@@ -10322,9 +11738,9 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10322
11738
|
const rootSectors = exactChain(fat, rootMini2.start, rootMini2.size, sectorSize);
|
|
10323
11739
|
rootSectors.forEach((id) => sector(id));
|
|
10324
11740
|
const rootData = new Uint8Array(rootMini2.size);
|
|
10325
|
-
rootSectors.forEach((id,
|
|
10326
|
-
for (let
|
|
10327
|
-
const miniOffset = miniSectors[Math.floor(
|
|
11741
|
+
rootSectors.forEach((id, i2) => rootData.set(sector(id).subarray(0, Math.min(sectorSize, rootData.length - i2 * sectorSize)), i2 * sectorSize));
|
|
11742
|
+
for (let i2 = 0; i2 < replacement.length; i2++) {
|
|
11743
|
+
const miniOffset = miniSectors[Math.floor(i2 / miniSize)] * miniSize + i2 % miniSize;
|
|
10328
11744
|
if (miniOffset >= rootData.length)
|
|
10329
11745
|
return reject();
|
|
10330
11746
|
const rootSectorIndex = Math.floor(miniOffset / sectorSize);
|
|
@@ -10332,7 +11748,7 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10332
11748
|
if (rootSector === void 0)
|
|
10333
11749
|
return reject();
|
|
10334
11750
|
const physical = offset(rootSector) + miniOffset % sectorSize;
|
|
10335
|
-
output[physical] = replacement[
|
|
11751
|
+
output[physical] = replacement[i2];
|
|
10336
11752
|
}
|
|
10337
11753
|
}
|
|
10338
11754
|
return output;
|
|
@@ -10462,11 +11878,11 @@ function resizeCompoundFileStreamV4(input, path, replacement) {
|
|
|
10462
11878
|
const sectorCount = input.length / SECTOR3 - 1, fatCount = read(44);
|
|
10463
11879
|
if (sectorCount > fatCount * FAT_ENTRIES2)
|
|
10464
11880
|
return fail("unsafe-edit");
|
|
10465
|
-
const fatIds = Array.from({ length: fatCount }, (_,
|
|
11881
|
+
const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
|
|
10466
11882
|
const fat = [];
|
|
10467
11883
|
for (const id of fatIds) {
|
|
10468
|
-
for (let
|
|
10469
|
-
fat.push(read((id + 1) * SECTOR3 +
|
|
11884
|
+
for (let i2 = 0; i2 < FAT_ENTRIES2 && fat.length < sectorCount; i2++)
|
|
11885
|
+
fat.push(read((id + 1) * SECTOR3 + i2 * 4));
|
|
10470
11886
|
}
|
|
10471
11887
|
if (fatIds.some((id) => fat[id] !== FAT))
|
|
10472
11888
|
return fail("unsafe-edit");
|
|
@@ -10483,8 +11899,8 @@ function resizeCompoundFileStreamV4(input, path, replacement) {
|
|
|
10483
11899
|
if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
|
|
10484
11900
|
return fail("unsafe-edit");
|
|
10485
11901
|
let name2 = "";
|
|
10486
|
-
for (let
|
|
10487
|
-
name2 += String.fromCharCode(view.getUint16(offset +
|
|
11902
|
+
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
11903
|
+
name2 += String.fromCharCode(view.getUint16(offset + i2, true));
|
|
10488
11904
|
if (read(offset + 124) !== 0)
|
|
10489
11905
|
return fail("unsafe-edit");
|
|
10490
11906
|
const id = block * DIRECTORY_ENTRIES + entry;
|
|
@@ -10513,18 +11929,18 @@ function resizeCompoundFileStreamV4(input, path, replacement) {
|
|
|
10513
11929
|
output.set(input);
|
|
10514
11930
|
output.set(replacement, (sectorCount + 1) * SECTOR3);
|
|
10515
11931
|
const outView = new DataView(output.buffer);
|
|
10516
|
-
for (let
|
|
10517
|
-
const id = sectorCount + payloadSectors +
|
|
11932
|
+
for (let i2 = fatCount; i2 < newFatCount; i2++) {
|
|
11933
|
+
const id = sectorCount + payloadSectors + i2 - fatCount;
|
|
10518
11934
|
fatIds.push(id);
|
|
10519
11935
|
output.fill(255, (id + 1) * SECTOR3, (id + 2) * SECTOR3);
|
|
10520
|
-
outView.setUint32(76 +
|
|
11936
|
+
outView.setUint32(76 + i2 * 4, id, true);
|
|
10521
11937
|
}
|
|
10522
11938
|
outView.setUint32(44, newFatCount, true);
|
|
10523
11939
|
const writeFat = (id, value) => outView.setUint32((fatIds[Math.floor(id / FAT_ENTRIES2)] + 1) * SECTOR3 + id % FAT_ENTRIES2 * 4, value, true);
|
|
10524
11940
|
for (const id of oldChain)
|
|
10525
11941
|
writeFat(id, FREE);
|
|
10526
|
-
for (let
|
|
10527
|
-
writeFat(sectorCount +
|
|
11942
|
+
for (let i2 = 0; i2 < payloadSectors; i2++)
|
|
11943
|
+
writeFat(sectorCount + i2, i2 + 1 === payloadSectors ? END2 : sectorCount + i2 + 1);
|
|
10528
11944
|
for (const id of fatIds)
|
|
10529
11945
|
writeFat(id, FAT);
|
|
10530
11946
|
outView.setUint32(target.offset + 116, payloadSectors ? sectorCount : END2, true);
|
|
@@ -10550,11 +11966,11 @@ function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize =
|
|
|
10550
11966
|
const bytes = new Uint8Array((totalSectors + 1) * sectorSize);
|
|
10551
11967
|
bytes.set(input);
|
|
10552
11968
|
const view = new DataView(bytes.buffer), fatIds = [...existingFatIds];
|
|
10553
|
-
for (let
|
|
10554
|
-
const id = sectorCount + payloadSectors +
|
|
11969
|
+
for (let i2 = existingFatIds.length; i2 < fatCount; i2++) {
|
|
11970
|
+
const id = sectorCount + payloadSectors + i2 - existingFatIds.length;
|
|
10555
11971
|
fatIds.push(id);
|
|
10556
11972
|
bytes.fill(255, (id + 1) * sectorSize, (id + 2) * sectorSize);
|
|
10557
|
-
view.setUint32(76 +
|
|
11973
|
+
view.setUint32(76 + i2 * 4, id, true);
|
|
10558
11974
|
}
|
|
10559
11975
|
view.setUint32(44, fatCount, true);
|
|
10560
11976
|
const writeFat = (id, value) => view.setUint32((fatIds[Math.floor(id / entriesPerFat)] + 1) * sectorSize + id % entriesPerFat * 4, value, true);
|
|
@@ -10562,8 +11978,8 @@ function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize =
|
|
|
10562
11978
|
let next = sectorCount;
|
|
10563
11979
|
for (let payload = 0; payload < payloads.length; payload++) {
|
|
10564
11980
|
bytes.set(payloads[payload], (next + 1) * sectorSize);
|
|
10565
|
-
const chain2 = Array.from({ length: counts[payload] }, (_,
|
|
10566
|
-
chain2.forEach((id,
|
|
11981
|
+
const chain2 = Array.from({ length: counts[payload] }, (_, i2) => next + i2);
|
|
11982
|
+
chain2.forEach((id, i2) => writeFat(id, chain2[i2 + 1] ?? 4294967294));
|
|
10567
11983
|
chains.push(chain2);
|
|
10568
11984
|
next += counts[payload];
|
|
10569
11985
|
}
|
|
@@ -10628,18 +12044,18 @@ function resizeMiniCompoundStream(input, fat, fatIds, root, target, replacement,
|
|
|
10628
12044
|
const firstMini = Math.ceil(root.size / MINI), count = Math.ceil(replacement.length / MINI);
|
|
10629
12045
|
const newRootSize = count ? (firstMini + count) * MINI : root.size;
|
|
10630
12046
|
const newRoot = new Uint8Array(newRootSize);
|
|
10631
|
-
rootSectors.forEach((id,
|
|
12047
|
+
rootSectors.forEach((id, i2) => newRoot.set(input.subarray((id + 1) * SECTOR, (id + 1) * SECTOR + Math.min(SECTOR, root.size - i2 * SECTOR)), i2 * SECTOR));
|
|
10632
12048
|
if (count)
|
|
10633
12049
|
newRoot.set(replacement, firstMini * MINI);
|
|
10634
12050
|
const newMiniFatCount = Math.max(miniFatCount, Math.ceil((firstMini + count) / 128));
|
|
10635
12051
|
const newMiniFat = new Uint8Array(newMiniFatCount * SECTOR).fill(255);
|
|
10636
|
-
miniFatSectors.forEach((id,
|
|
12052
|
+
miniFatSectors.forEach((id, i2) => newMiniFat.set(input.subarray((id + 1) * SECTOR, (id + 2) * SECTOR), i2 * SECTOR));
|
|
10637
12053
|
const miniView = new DataView(newMiniFat.buffer);
|
|
10638
12054
|
if (wasMini)
|
|
10639
12055
|
for (const id of oldChain)
|
|
10640
12056
|
miniView.setUint32(id * 4, FREE2, true);
|
|
10641
|
-
for (let
|
|
10642
|
-
miniView.setUint32((firstMini +
|
|
12057
|
+
for (let i2 = 0; i2 < count; i2++)
|
|
12058
|
+
miniView.setUint32((firstMini + i2) * 4, i2 + 1 === count ? END3 : firstMini + i2 + 1, true);
|
|
10643
12059
|
const output = appendCompoundAllocations(input, fatIds, [newRoot, newMiniFat]);
|
|
10644
12060
|
if (!output)
|
|
10645
12061
|
return void 0;
|
|
@@ -10767,11 +12183,11 @@ function resizeCompoundFileStream(input, path, replacement) {
|
|
|
10767
12183
|
const sectorCount = input.length / SECTOR2 - 1, fatCount = read(44);
|
|
10768
12184
|
if (sectorCount > fatCount * FAT_ENTRIES)
|
|
10769
12185
|
return fail("unsafe-edit");
|
|
10770
|
-
const fatIds = Array.from({ length: fatCount }, (_,
|
|
12186
|
+
const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
|
|
10771
12187
|
const fat = [];
|
|
10772
12188
|
for (const id of fatIds) {
|
|
10773
|
-
for (let
|
|
10774
|
-
fat.push(read((id + 1) * SECTOR2 +
|
|
12189
|
+
for (let i2 = 0; i2 < FAT_ENTRIES && fat.length < sectorCount; i2++)
|
|
12190
|
+
fat.push(read((id + 1) * SECTOR2 + i2 * 4));
|
|
10775
12191
|
}
|
|
10776
12192
|
if (fatIds.some((id) => fat[id] !== FAT2))
|
|
10777
12193
|
return fail("unsafe-edit");
|
|
@@ -10785,8 +12201,8 @@ function resizeCompoundFileStream(input, path, replacement) {
|
|
|
10785
12201
|
if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
|
|
10786
12202
|
return fail("unsafe-edit");
|
|
10787
12203
|
let name2 = "";
|
|
10788
|
-
for (let
|
|
10789
|
-
name2 += String.fromCharCode(view.getUint16(offset +
|
|
12204
|
+
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
12205
|
+
name2 += String.fromCharCode(view.getUint16(offset + i2, true));
|
|
10790
12206
|
const id = block * 4 + entry;
|
|
10791
12207
|
slots.set(id, { id, name: name2, type, left: read(offset + 68), right: read(offset + 72), child: read(offset + 76), start: read(offset + 116), size: read(offset + 120), offset });
|
|
10792
12208
|
}
|
|
@@ -10853,7 +12269,7 @@ function unwrapDocBytes(bytes) {
|
|
|
10853
12269
|
const patchedWord = replaceCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
|
|
10854
12270
|
if (patchedWord === bytes)
|
|
10855
12271
|
throw new DocCfbRewriteError("Cannot safely patch WordDocument");
|
|
10856
|
-
if (editedTableBytes.every((value,
|
|
12272
|
+
if (editedTableBytes.every((value, i2) => value === tableBytes[i2]))
|
|
10857
12273
|
return patchedWord;
|
|
10858
12274
|
const patchedTable = replaceCompoundFileStream(patchedWord, [fib.tableStreamName], editedTableBytes);
|
|
10859
12275
|
if (patchedTable === patchedWord)
|
|
@@ -10882,15 +12298,15 @@ function parseBteTable(tableStream, at) {
|
|
|
10882
12298
|
throw new Error("Invalid BTE table bounds");
|
|
10883
12299
|
const n = (at.lcb - 4) / 8;
|
|
10884
12300
|
const fcs = [];
|
|
10885
|
-
for (let
|
|
10886
|
-
const fc = view.getInt32(at.fc +
|
|
10887
|
-
if (fc < 0 ||
|
|
12301
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12302
|
+
const fc = view.getInt32(at.fc + i2 * 4, true);
|
|
12303
|
+
if (fc < 0 || i2 > 0 && fc <= fcs[i2 - 1])
|
|
10888
12304
|
throw new Error("Invalid BTE FC boundaries");
|
|
10889
12305
|
fcs.push(fc);
|
|
10890
12306
|
}
|
|
10891
12307
|
const pns = [];
|
|
10892
|
-
for (let
|
|
10893
|
-
pns.push(view.getUint32(at.fc + (n + 1) * 4 +
|
|
12308
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12309
|
+
pns.push(view.getUint32(at.fc + (n + 1) * 4 + i2 * 4, true));
|
|
10894
12310
|
}
|
|
10895
12311
|
return { fcs, pns };
|
|
10896
12312
|
}
|
|
@@ -10898,11 +12314,11 @@ function buildBteTableBytes(table) {
|
|
|
10898
12314
|
const n = table.pns.length;
|
|
10899
12315
|
const bytes = new Uint8Array((n + 1) * 4 + n * 4);
|
|
10900
12316
|
const view = new DataView(bytes.buffer);
|
|
10901
|
-
for (let
|
|
10902
|
-
view.setInt32(
|
|
12317
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12318
|
+
view.setInt32(i2 * 4, table.fcs[i2], true);
|
|
10903
12319
|
}
|
|
10904
|
-
for (let
|
|
10905
|
-
view.setUint32((n + 1) * 4 +
|
|
12320
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12321
|
+
view.setUint32((n + 1) * 4 + i2 * 4, table.pns[i2], true);
|
|
10906
12322
|
}
|
|
10907
12323
|
return bytes;
|
|
10908
12324
|
}
|
|
@@ -10940,11 +12356,11 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
|
|
|
10940
12356
|
throw new Error("Invalid PAPX run count");
|
|
10941
12357
|
const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
|
|
10942
12358
|
const rgbxOffset = (crun + 1) * 4;
|
|
10943
|
-
for (let
|
|
10944
|
-
const runFcStart = pageView.getInt32(
|
|
10945
|
-
const runFcEnd = pageView.getInt32((
|
|
12359
|
+
for (let i2 = 0; i2 < crun; i2++) {
|
|
12360
|
+
const runFcStart = pageView.getInt32(i2 * 4, true);
|
|
12361
|
+
const runFcEnd = pageView.getInt32((i2 + 1) * 4, true);
|
|
10946
12362
|
if (fc >= runFcStart && fc < runFcEnd) {
|
|
10947
|
-
const bOffsetWord = page[rgbxOffset +
|
|
12363
|
+
const bOffsetWord = page[rgbxOffset + i2 * 13];
|
|
10948
12364
|
if (bOffsetWord === 0)
|
|
10949
12365
|
return new Uint8Array();
|
|
10950
12366
|
const blobOffset = bOffsetWord * 2;
|
|
@@ -10967,11 +12383,11 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
|
|
|
10967
12383
|
throw new Error("Invalid CHPX run count");
|
|
10968
12384
|
const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
|
|
10969
12385
|
const rgbOffset = (crun + 1) * 4;
|
|
10970
|
-
for (let
|
|
10971
|
-
const runFcStart = pageView.getInt32(
|
|
10972
|
-
const runFcEnd = pageView.getInt32((
|
|
12386
|
+
for (let i2 = 0; i2 < crun; i2++) {
|
|
12387
|
+
const runFcStart = pageView.getInt32(i2 * 4, true);
|
|
12388
|
+
const runFcEnd = pageView.getInt32((i2 + 1) * 4, true);
|
|
10973
12389
|
if (fc >= runFcStart && fc < runFcEnd) {
|
|
10974
|
-
const bOffsetWord = page[rgbOffset +
|
|
12390
|
+
const bOffsetWord = page[rgbOffset + i2];
|
|
10975
12391
|
if (bOffsetWord === 0) {
|
|
10976
12392
|
return new Uint8Array(0);
|
|
10977
12393
|
}
|
|
@@ -11050,7 +12466,7 @@ var CP1252_HIGH_BLOCK = [
|
|
|
11050
12466
|
382,
|
|
11051
12467
|
376
|
|
11052
12468
|
];
|
|
11053
|
-
var CP1252_HIGH_BLOCK_REVERSE = new Map(CP1252_HIGH_BLOCK.map((codePoint,
|
|
12469
|
+
var CP1252_HIGH_BLOCK_REVERSE = new Map(CP1252_HIGH_BLOCK.map((codePoint, i2) => [codePoint, 128 + i2]));
|
|
11054
12470
|
function decodeCp1252Byte(byte) {
|
|
11055
12471
|
if (byte >= 128 && byte <= 159) {
|
|
11056
12472
|
return CP1252_HIGH_BLOCK[byte - 128];
|
|
@@ -11135,16 +12551,16 @@ function parseDocClx(tableStream, clx, maxPieces) {
|
|
|
11135
12551
|
function parsePlcPcd(view, plcStart, lcb) {
|
|
11136
12552
|
const n = Math.floor((lcb - 4) / (4 + 8));
|
|
11137
12553
|
const cps = [];
|
|
11138
|
-
for (let
|
|
11139
|
-
const cp = view.getInt32(plcStart +
|
|
11140
|
-
if (
|
|
12554
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12555
|
+
const cp = view.getInt32(plcStart + i2 * 4, true);
|
|
12556
|
+
if (i2 === 0 && cp !== 0 || i2 > 0 && cp <= cps[i2 - 1])
|
|
11141
12557
|
throw new Error("Piece CPs must start at zero and increase");
|
|
11142
12558
|
cps.push(cp);
|
|
11143
12559
|
}
|
|
11144
12560
|
const pcdStart = plcStart + (n + 1) * 4;
|
|
11145
12561
|
const pieces = [];
|
|
11146
|
-
for (let
|
|
11147
|
-
const pOff = pcdStart +
|
|
12562
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12563
|
+
const pOff = pcdStart + i2 * 8;
|
|
11148
12564
|
const flagsWord = view.getUint16(pOff, true);
|
|
11149
12565
|
const fcRaw = view.getUint32(pOff + 2, true);
|
|
11150
12566
|
if ((fcRaw & 2147483648) !== 0)
|
|
@@ -11153,8 +12569,8 @@ function parsePlcPcd(view, plcStart, lcb) {
|
|
|
11153
12569
|
const compressed = (fcRaw >>> 30 & 1) === 1;
|
|
11154
12570
|
const fcField = fcRaw & 1073741823;
|
|
11155
12571
|
pieces.push({
|
|
11156
|
-
cpStart: cps[
|
|
11157
|
-
cpEnd: cps[
|
|
12572
|
+
cpStart: cps[i2],
|
|
12573
|
+
cpEnd: cps[i2 + 1],
|
|
11158
12574
|
fc: compressed ? fcField >>> 1 : fcField,
|
|
11159
12575
|
compressed,
|
|
11160
12576
|
flagsWord,
|
|
@@ -11173,8 +12589,8 @@ function decodePieceText(wordDoc, piece) {
|
|
|
11173
12589
|
}
|
|
11174
12590
|
const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
|
|
11175
12591
|
let out = "";
|
|
11176
|
-
for (let
|
|
11177
|
-
out += String.fromCharCode(view.getUint16(piece.fc +
|
|
12592
|
+
for (let i2 = 0; i2 < charLen; i2++) {
|
|
12593
|
+
out += String.fromCharCode(view.getUint16(piece.fc + i2 * 2, true));
|
|
11178
12594
|
}
|
|
11179
12595
|
return out;
|
|
11180
12596
|
}
|
|
@@ -11199,8 +12615,8 @@ function encodePieceText(text) {
|
|
|
11199
12615
|
}
|
|
11200
12616
|
const bytes = new Uint8Array(text.length * 2);
|
|
11201
12617
|
const view = new DataView(bytes.buffer);
|
|
11202
|
-
for (let
|
|
11203
|
-
view.setUint16(
|
|
12618
|
+
for (let i2 = 0; i2 < text.length; i2++) {
|
|
12619
|
+
view.setUint16(i2 * 2, text.charCodeAt(i2), true);
|
|
11204
12620
|
}
|
|
11205
12621
|
return { bytes, compressed: false };
|
|
11206
12622
|
}
|
|
@@ -11347,9 +12763,9 @@ function shiftDocMainFieldCps(table, at, body, editStart, editEnd, delta, maxFie
|
|
|
11347
12763
|
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
11348
12764
|
const markers = [];
|
|
11349
12765
|
let previous = -1;
|
|
11350
|
-
for (let
|
|
11351
|
-
const cp = view.getInt32(
|
|
11352
|
-
const ch = source[(n + 1) * 4 +
|
|
12766
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12767
|
+
const cp = view.getInt32(i2 * 4, true);
|
|
12768
|
+
const ch = source[(n + 1) * 4 + i2 * 2] & 31;
|
|
11353
12769
|
if (cp <= previous || cp >= body.length || ![19, 20, 21].includes(ch) || body.charCodeAt(cp) !== ch)
|
|
11354
12770
|
throw new Error("Invalid main-story field marker");
|
|
11355
12771
|
markers.push({ cp, ch });
|
|
@@ -11362,12 +12778,12 @@ function shiftDocMainFieldCps(table, at, body, editStart, editEnd, delta, maxFie
|
|
|
11362
12778
|
const result = source.slice();
|
|
11363
12779
|
const out = new DataView(result.buffer);
|
|
11364
12780
|
let shiftedLast = -1;
|
|
11365
|
-
for (let
|
|
11366
|
-
const cp = markers[
|
|
12781
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12782
|
+
const cp = markers[i2].cp;
|
|
11367
12783
|
const shifted = cp >= editEnd ? cp + delta : cp;
|
|
11368
12784
|
if (shifted < 0 || shifted >= body.length + delta || shifted <= shiftedLast)
|
|
11369
12785
|
throw new Error("Field position shifts outside the main story");
|
|
11370
|
-
out.setInt32(
|
|
12786
|
+
out.setInt32(i2 * 4, shifted, true);
|
|
11371
12787
|
shiftedLast = shifted;
|
|
11372
12788
|
}
|
|
11373
12789
|
let shiftedSentinel = sentinel >= editEnd ? sentinel + delta : sentinel;
|
|
@@ -11426,9 +12842,9 @@ function pieceAndFcAtCp(pieces, cp) {
|
|
|
11426
12842
|
}
|
|
11427
12843
|
function paragraphBoundaries(bodyText) {
|
|
11428
12844
|
const boundaries = [];
|
|
11429
|
-
for (let
|
|
11430
|
-
if (bodyText[
|
|
11431
|
-
boundaries.push(
|
|
12845
|
+
for (let i2 = 0; i2 < bodyText.length; i2++) {
|
|
12846
|
+
if (bodyText[i2] === "\r") {
|
|
12847
|
+
boundaries.push(i2 + 1);
|
|
11432
12848
|
}
|
|
11433
12849
|
}
|
|
11434
12850
|
if (boundaries[boundaries.length - 1] !== bodyText.length && bodyText.length > 0) {
|
|
@@ -11439,8 +12855,8 @@ function paragraphBoundaries(bodyText) {
|
|
|
11439
12855
|
function encodePieceTextUtf16(text) {
|
|
11440
12856
|
const bytes = new Uint8Array(text.length * 2);
|
|
11441
12857
|
const view = new DataView(bytes.buffer);
|
|
11442
|
-
for (let
|
|
11443
|
-
view.setUint16(
|
|
12858
|
+
for (let i2 = 0; i2 < text.length; i2++)
|
|
12859
|
+
view.setUint16(i2 * 2, text.charCodeAt(i2), true);
|
|
11444
12860
|
return bytes;
|
|
11445
12861
|
}
|
|
11446
12862
|
function readOleDocParagraphs(docBytes, limits) {
|
|
@@ -11479,8 +12895,8 @@ function shiftSectionTableCps(tableBytes, sed, editEndCp, delta) {
|
|
|
11479
12895
|
if (sed.lcb < 4 || (sed.lcb - 4) % 16 !== 0 || sed.fc > tableBytes.length - sed.lcb)
|
|
11480
12896
|
throw new Error("Invalid section table");
|
|
11481
12897
|
const n = (sed.lcb - 4) / 16;
|
|
11482
|
-
for (let
|
|
11483
|
-
const off = sed.fc +
|
|
12898
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12899
|
+
const off = sed.fc + i2 * 4;
|
|
11484
12900
|
const cp = view.getInt32(off, true);
|
|
11485
12901
|
if (cp >= editEndCp) {
|
|
11486
12902
|
view.setInt32(off, cp + delta, true);
|
|
@@ -11754,13 +13170,13 @@ async function loadLegacyDoc(input) {
|
|
|
11754
13170
|
"Adding or removing paragraphs in legacy .doc files is unsupported."
|
|
11755
13171
|
);
|
|
11756
13172
|
let output = original;
|
|
11757
|
-
for (let
|
|
11758
|
-
if (updated[
|
|
11759
|
-
if (/[\r\n]/u.test(updated[
|
|
13173
|
+
for (let i2 = 0; i2 < updated.length; i2++) {
|
|
13174
|
+
if (updated[i2] === paragraphs[i2]) continue;
|
|
13175
|
+
if (/[\r\n]/u.test(updated[i2]))
|
|
11760
13176
|
throw new LegacyDocError(
|
|
11761
13177
|
"Adding line breaks in legacy .doc paragraph text is unsupported."
|
|
11762
13178
|
);
|
|
11763
|
-
const result = writeOleDocParagraphEdit(output,
|
|
13179
|
+
const result = writeOleDocParagraphEdit(output, i2, updated[i2]);
|
|
11764
13180
|
if (result === output)
|
|
11765
13181
|
throw new LegacyDocError(
|
|
11766
13182
|
"This .doc uses structures that prevent safe paragraph text editing."
|