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.cjs
CHANGED
|
@@ -60,8 +60,8 @@ function parseOle2(buffer) {
|
|
|
60
60
|
if (data.length < 512) {
|
|
61
61
|
throw new Ole2ParseError("Truncated OLE2 compound file header");
|
|
62
62
|
}
|
|
63
|
-
for (let
|
|
64
|
-
if (data[
|
|
63
|
+
for (let i2 = 0; i2 < OLE_MAGIC.length; i2++) {
|
|
64
|
+
if (data[i2] !== OLE_MAGIC[i2]) {
|
|
65
65
|
throw new Ole2ParseError("Not a valid OLE2 compound file");
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -103,8 +103,8 @@ function parseOle2(buffer) {
|
|
|
103
103
|
return data.subarray(offset, offset + sectorSize);
|
|
104
104
|
}
|
|
105
105
|
const fatSectors = [];
|
|
106
|
-
for (let
|
|
107
|
-
const sector = view.getUint32(76 +
|
|
106
|
+
for (let i2 = 0; i2 < 109 && fatSectors.length < totalFATSectors; i2++) {
|
|
107
|
+
const sector = view.getUint32(76 + i2 * 4, true);
|
|
108
108
|
if (sector <= MAXREGSECT) {
|
|
109
109
|
fatSectors.push(sector);
|
|
110
110
|
}
|
|
@@ -118,8 +118,8 @@ function parseOle2(buffer) {
|
|
|
118
118
|
const difatData = readSector(difatSector);
|
|
119
119
|
const difatView = new DataView(difatData.buffer, difatData.byteOffset, difatData.byteLength);
|
|
120
120
|
const entriesPerSector = (sectorSize - 4) / 4;
|
|
121
|
-
for (let
|
|
122
|
-
const sector = difatView.getUint32(
|
|
121
|
+
for (let i2 = 0; i2 < entriesPerSector && fatSectors.length < totalFATSectors; i2++) {
|
|
122
|
+
const sector = difatView.getUint32(i2 * 4, true);
|
|
123
123
|
if (sector <= MAXREGSECT) {
|
|
124
124
|
fatSectors.push(sector);
|
|
125
125
|
}
|
|
@@ -133,8 +133,8 @@ function parseOle2(buffer) {
|
|
|
133
133
|
for (const fatSector of fatSectors) {
|
|
134
134
|
const fatData = readSector(fatSector);
|
|
135
135
|
const fatView = new DataView(fatData.buffer, fatData.byteOffset, fatData.byteLength);
|
|
136
|
-
for (let
|
|
137
|
-
fatEntries.push(fatView.getUint32(
|
|
136
|
+
for (let i2 = 0; i2 < sectorSize / 4 && fatEntries.length < sectorCount; i2++) {
|
|
137
|
+
fatEntries.push(fatView.getUint32(i2 * 4, true));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
function readSectorChain(startSector) {
|
|
@@ -175,8 +175,8 @@ function parseOle2(buffer) {
|
|
|
175
175
|
const dirRaw = readSectorChain(firstDirectorySector);
|
|
176
176
|
const numEntries = Math.floor(dirRaw.length / DIR_ENTRY_SIZE);
|
|
177
177
|
const entries = [];
|
|
178
|
-
for (let
|
|
179
|
-
const entryOffset =
|
|
178
|
+
for (let i2 = 0; i2 < numEntries; i2++) {
|
|
179
|
+
const entryOffset = i2 * DIR_ENTRY_SIZE;
|
|
180
180
|
const entryView = new DataView(dirRaw.buffer, dirRaw.byteOffset + entryOffset, DIR_ENTRY_SIZE);
|
|
181
181
|
const nameLen = entryView.getUint16(64, true);
|
|
182
182
|
const objectType = entryView.getUint8(66);
|
|
@@ -232,8 +232,8 @@ function parseOle2(buffer) {
|
|
|
232
232
|
}
|
|
233
233
|
const miniFatView = new DataView(miniFatRaw.buffer, miniFatRaw.byteOffset, miniFatRaw.byteLength);
|
|
234
234
|
const miniCapacity = Math.floor((miniStreamData?.length ?? 0) / miniSectorSize);
|
|
235
|
-
for (let
|
|
236
|
-
miniFatEntries.push(miniFatView.getUint32(
|
|
235
|
+
for (let i2 = 0; i2 < miniFatRaw.length / 4 && i2 < miniCapacity; i2++) {
|
|
236
|
+
miniFatEntries.push(miniFatView.getUint32(i2 * 4, true));
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
function readMiniStream(startSector, size) {
|
|
@@ -298,10 +298,10 @@ function getCrypto() {
|
|
|
298
298
|
}
|
|
299
299
|
function encodePasswordUtf16LE(password) {
|
|
300
300
|
const buf = new Uint8Array(password.length * 2);
|
|
301
|
-
for (let
|
|
302
|
-
const code = password.charCodeAt(
|
|
303
|
-
buf[
|
|
304
|
-
buf[
|
|
301
|
+
for (let i2 = 0; i2 < password.length; i2++) {
|
|
302
|
+
const code = password.charCodeAt(i2);
|
|
303
|
+
buf[i2 * 2] = code & 255;
|
|
304
|
+
buf[i2 * 2 + 1] = code >> 8 & 255;
|
|
305
305
|
}
|
|
306
306
|
return buf;
|
|
307
307
|
}
|
|
@@ -327,15 +327,15 @@ function uint32LE(value) {
|
|
|
327
327
|
function base64Decode(str) {
|
|
328
328
|
const binary = atob(str);
|
|
329
329
|
const bytes = new Uint8Array(binary.length);
|
|
330
|
-
for (let
|
|
331
|
-
bytes[
|
|
330
|
+
for (let i2 = 0; i2 < binary.length; i2++) {
|
|
331
|
+
bytes[i2] = binary.charCodeAt(i2);
|
|
332
332
|
}
|
|
333
333
|
return bytes;
|
|
334
334
|
}
|
|
335
335
|
function base64Encode(bytes) {
|
|
336
336
|
let binary = "";
|
|
337
|
-
for (let
|
|
338
|
-
binary += String.fromCharCode(bytes[
|
|
337
|
+
for (let i2 = 0; i2 < bytes.length; i2++) {
|
|
338
|
+
binary += String.fromCharCode(bytes[i2]);
|
|
339
339
|
}
|
|
340
340
|
return btoa(binary);
|
|
341
341
|
}
|
|
@@ -454,6 +454,846 @@ function normalizeDigestAlgorithmName(name) {
|
|
|
454
454
|
return Object.hasOwn(CANONICAL_BY_LOOKUP_KEY, key) ? CANONICAL_BY_LOOKUP_KEY[key] : void 0;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
+
// digest/md2.ts
|
|
458
|
+
var S = [
|
|
459
|
+
41,
|
|
460
|
+
46,
|
|
461
|
+
67,
|
|
462
|
+
201,
|
|
463
|
+
162,
|
|
464
|
+
216,
|
|
465
|
+
124,
|
|
466
|
+
1,
|
|
467
|
+
61,
|
|
468
|
+
54,
|
|
469
|
+
84,
|
|
470
|
+
161,
|
|
471
|
+
236,
|
|
472
|
+
240,
|
|
473
|
+
6,
|
|
474
|
+
19,
|
|
475
|
+
98,
|
|
476
|
+
167,
|
|
477
|
+
5,
|
|
478
|
+
243,
|
|
479
|
+
192,
|
|
480
|
+
199,
|
|
481
|
+
115,
|
|
482
|
+
140,
|
|
483
|
+
152,
|
|
484
|
+
147,
|
|
485
|
+
43,
|
|
486
|
+
217,
|
|
487
|
+
188,
|
|
488
|
+
76,
|
|
489
|
+
130,
|
|
490
|
+
202,
|
|
491
|
+
30,
|
|
492
|
+
155,
|
|
493
|
+
87,
|
|
494
|
+
60,
|
|
495
|
+
253,
|
|
496
|
+
212,
|
|
497
|
+
224,
|
|
498
|
+
22,
|
|
499
|
+
103,
|
|
500
|
+
66,
|
|
501
|
+
111,
|
|
502
|
+
24,
|
|
503
|
+
138,
|
|
504
|
+
23,
|
|
505
|
+
229,
|
|
506
|
+
18,
|
|
507
|
+
190,
|
|
508
|
+
78,
|
|
509
|
+
196,
|
|
510
|
+
214,
|
|
511
|
+
218,
|
|
512
|
+
158,
|
|
513
|
+
222,
|
|
514
|
+
73,
|
|
515
|
+
160,
|
|
516
|
+
251,
|
|
517
|
+
245,
|
|
518
|
+
142,
|
|
519
|
+
187,
|
|
520
|
+
47,
|
|
521
|
+
238,
|
|
522
|
+
122,
|
|
523
|
+
169,
|
|
524
|
+
104,
|
|
525
|
+
121,
|
|
526
|
+
145,
|
|
527
|
+
21,
|
|
528
|
+
178,
|
|
529
|
+
7,
|
|
530
|
+
63,
|
|
531
|
+
148,
|
|
532
|
+
194,
|
|
533
|
+
16,
|
|
534
|
+
137,
|
|
535
|
+
11,
|
|
536
|
+
34,
|
|
537
|
+
95,
|
|
538
|
+
33,
|
|
539
|
+
128,
|
|
540
|
+
127,
|
|
541
|
+
93,
|
|
542
|
+
154,
|
|
543
|
+
90,
|
|
544
|
+
144,
|
|
545
|
+
50,
|
|
546
|
+
39,
|
|
547
|
+
53,
|
|
548
|
+
62,
|
|
549
|
+
204,
|
|
550
|
+
231,
|
|
551
|
+
191,
|
|
552
|
+
247,
|
|
553
|
+
151,
|
|
554
|
+
3,
|
|
555
|
+
255,
|
|
556
|
+
25,
|
|
557
|
+
48,
|
|
558
|
+
179,
|
|
559
|
+
72,
|
|
560
|
+
165,
|
|
561
|
+
181,
|
|
562
|
+
209,
|
|
563
|
+
215,
|
|
564
|
+
94,
|
|
565
|
+
146,
|
|
566
|
+
42,
|
|
567
|
+
172,
|
|
568
|
+
86,
|
|
569
|
+
170,
|
|
570
|
+
198,
|
|
571
|
+
79,
|
|
572
|
+
184,
|
|
573
|
+
56,
|
|
574
|
+
210,
|
|
575
|
+
150,
|
|
576
|
+
164,
|
|
577
|
+
125,
|
|
578
|
+
182,
|
|
579
|
+
118,
|
|
580
|
+
252,
|
|
581
|
+
107,
|
|
582
|
+
226,
|
|
583
|
+
156,
|
|
584
|
+
116,
|
|
585
|
+
4,
|
|
586
|
+
241,
|
|
587
|
+
69,
|
|
588
|
+
157,
|
|
589
|
+
112,
|
|
590
|
+
89,
|
|
591
|
+
100,
|
|
592
|
+
113,
|
|
593
|
+
135,
|
|
594
|
+
32,
|
|
595
|
+
134,
|
|
596
|
+
91,
|
|
597
|
+
207,
|
|
598
|
+
101,
|
|
599
|
+
230,
|
|
600
|
+
45,
|
|
601
|
+
168,
|
|
602
|
+
2,
|
|
603
|
+
27,
|
|
604
|
+
96,
|
|
605
|
+
37,
|
|
606
|
+
173,
|
|
607
|
+
174,
|
|
608
|
+
176,
|
|
609
|
+
185,
|
|
610
|
+
246,
|
|
611
|
+
28,
|
|
612
|
+
70,
|
|
613
|
+
97,
|
|
614
|
+
105,
|
|
615
|
+
52,
|
|
616
|
+
64,
|
|
617
|
+
126,
|
|
618
|
+
15,
|
|
619
|
+
85,
|
|
620
|
+
71,
|
|
621
|
+
163,
|
|
622
|
+
35,
|
|
623
|
+
221,
|
|
624
|
+
81,
|
|
625
|
+
175,
|
|
626
|
+
58,
|
|
627
|
+
195,
|
|
628
|
+
92,
|
|
629
|
+
249,
|
|
630
|
+
206,
|
|
631
|
+
186,
|
|
632
|
+
197,
|
|
633
|
+
234,
|
|
634
|
+
38,
|
|
635
|
+
44,
|
|
636
|
+
83,
|
|
637
|
+
13,
|
|
638
|
+
110,
|
|
639
|
+
133,
|
|
640
|
+
40,
|
|
641
|
+
132,
|
|
642
|
+
9,
|
|
643
|
+
211,
|
|
644
|
+
223,
|
|
645
|
+
205,
|
|
646
|
+
244,
|
|
647
|
+
65,
|
|
648
|
+
129,
|
|
649
|
+
77,
|
|
650
|
+
82,
|
|
651
|
+
106,
|
|
652
|
+
220,
|
|
653
|
+
55,
|
|
654
|
+
200,
|
|
655
|
+
108,
|
|
656
|
+
193,
|
|
657
|
+
171,
|
|
658
|
+
250,
|
|
659
|
+
36,
|
|
660
|
+
225,
|
|
661
|
+
123,
|
|
662
|
+
8,
|
|
663
|
+
12,
|
|
664
|
+
189,
|
|
665
|
+
177,
|
|
666
|
+
74,
|
|
667
|
+
120,
|
|
668
|
+
136,
|
|
669
|
+
149,
|
|
670
|
+
139,
|
|
671
|
+
227,
|
|
672
|
+
99,
|
|
673
|
+
232,
|
|
674
|
+
109,
|
|
675
|
+
233,
|
|
676
|
+
203,
|
|
677
|
+
213,
|
|
678
|
+
254,
|
|
679
|
+
59,
|
|
680
|
+
0,
|
|
681
|
+
29,
|
|
682
|
+
57,
|
|
683
|
+
242,
|
|
684
|
+
239,
|
|
685
|
+
183,
|
|
686
|
+
14,
|
|
687
|
+
102,
|
|
688
|
+
88,
|
|
689
|
+
208,
|
|
690
|
+
228,
|
|
691
|
+
166,
|
|
692
|
+
119,
|
|
693
|
+
114,
|
|
694
|
+
248,
|
|
695
|
+
235,
|
|
696
|
+
117,
|
|
697
|
+
75,
|
|
698
|
+
10,
|
|
699
|
+
49,
|
|
700
|
+
68,
|
|
701
|
+
80,
|
|
702
|
+
180,
|
|
703
|
+
143,
|
|
704
|
+
237,
|
|
705
|
+
31,
|
|
706
|
+
26,
|
|
707
|
+
219,
|
|
708
|
+
153,
|
|
709
|
+
141,
|
|
710
|
+
51,
|
|
711
|
+
159,
|
|
712
|
+
17,
|
|
713
|
+
131,
|
|
714
|
+
20
|
|
715
|
+
];
|
|
716
|
+
function transform(state, checksum, block) {
|
|
717
|
+
const x = new Uint8Array(48);
|
|
718
|
+
x.set(state, 0);
|
|
719
|
+
x.set(block, 16);
|
|
720
|
+
for (let k = 0; k < 16; k++) {
|
|
721
|
+
x[32 + k] = state[k] ^ block[k];
|
|
722
|
+
}
|
|
723
|
+
let t = 0;
|
|
724
|
+
for (let round2 = 0; round2 < 18; round2++) {
|
|
725
|
+
for (let k = 0; k < 48; k++) {
|
|
726
|
+
x[k] = x[k] ^ S[t];
|
|
727
|
+
t = x[k];
|
|
728
|
+
}
|
|
729
|
+
t = t + round2 & 255;
|
|
730
|
+
}
|
|
731
|
+
state.set(x.subarray(0, 16));
|
|
732
|
+
t = checksum[15];
|
|
733
|
+
for (let k = 0; k < 16; k++) {
|
|
734
|
+
checksum[k] = checksum[k] ^ S[block[k] ^ t];
|
|
735
|
+
t = checksum[k];
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
function md2(message) {
|
|
739
|
+
const padLength = 16 - message.length % 16;
|
|
740
|
+
const padded = new Uint8Array(message.length + padLength);
|
|
741
|
+
padded.set(message);
|
|
742
|
+
padded.fill(padLength, message.length);
|
|
743
|
+
const state = new Uint8Array(16);
|
|
744
|
+
const checksum = new Uint8Array(16);
|
|
745
|
+
for (let offset = 0; offset < padded.length; offset += 16) {
|
|
746
|
+
transform(state, checksum, padded.subarray(offset, offset + 16));
|
|
747
|
+
}
|
|
748
|
+
transform(state, checksum, checksum.slice());
|
|
749
|
+
return state;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// digest/bit-ops.ts
|
|
753
|
+
function rotl32(x, n) {
|
|
754
|
+
return (x << n | x >>> 32 - n) >>> 0;
|
|
755
|
+
}
|
|
756
|
+
function add32(...values) {
|
|
757
|
+
let sum = 0;
|
|
758
|
+
for (const value of values) sum = sum + value >>> 0;
|
|
759
|
+
return sum;
|
|
760
|
+
}
|
|
761
|
+
function padMd4Style(message) {
|
|
762
|
+
const paddedLength = message.length + 9 + 63 & -64;
|
|
763
|
+
const padded = new Uint8Array(paddedLength);
|
|
764
|
+
padded.set(message);
|
|
765
|
+
padded[message.length] = 128;
|
|
766
|
+
new DataView(padded.buffer).setBigUint64(paddedLength - 8, BigInt(message.length) * 8n, true);
|
|
767
|
+
return padded;
|
|
768
|
+
}
|
|
769
|
+
function applyRotatingRound(r, ops, f6, x, feedback = false) {
|
|
770
|
+
let target = 0;
|
|
771
|
+
for (const [k, s, addConst] of ops) {
|
|
772
|
+
const i1 = target + 1 & 3;
|
|
773
|
+
const next = r[i1];
|
|
774
|
+
const rotated = rotl32(
|
|
775
|
+
add32(r[target], f6(next, r[target + 2 & 3], r[target + 3 & 3]), x[k], addConst),
|
|
776
|
+
s
|
|
777
|
+
);
|
|
778
|
+
r[target] = feedback ? add32(next, rotated) : rotated;
|
|
779
|
+
target = target + 3 & 3;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function mdStyleDigest(message, initialState, transform6) {
|
|
783
|
+
const padded = padMd4Style(message);
|
|
784
|
+
const view = new DataView(padded.buffer);
|
|
785
|
+
const state = [...initialState];
|
|
786
|
+
const words2 = new Array(16).fill(0);
|
|
787
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
788
|
+
for (let i2 = 0; i2 < 16; i2++) words2[i2] = view.getUint32(offset + i2 * 4, true);
|
|
789
|
+
transform6(state, words2);
|
|
790
|
+
}
|
|
791
|
+
const out = new Uint8Array(state.length * 4);
|
|
792
|
+
const outView = new DataView(out.buffer);
|
|
793
|
+
for (let i2 = 0; i2 < state.length; i2++) outView.setUint32(i2 * 4, state[i2], true);
|
|
794
|
+
return out;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// digest/md4.ts
|
|
798
|
+
var INITIAL_STATE = [1732584193, 4023233417, 2562383102, 271733878];
|
|
799
|
+
var K2 = 1518500249;
|
|
800
|
+
var K3 = 1859775393;
|
|
801
|
+
var f1 = (x, y, z) => x & y | ~x & z;
|
|
802
|
+
var f2 = (x, y, z) => x & y | x & z | y & z;
|
|
803
|
+
var f3 = (x, y, z) => x ^ y ^ z;
|
|
804
|
+
function round(order, shifts, k) {
|
|
805
|
+
return order.map((word, i2) => [word, shifts[i2 % 4], k]);
|
|
806
|
+
}
|
|
807
|
+
var SEQUENTIAL = Array.from({ length: 16 }, (_, i2) => i2);
|
|
808
|
+
var COLUMNS = Array.from({ length: 16 }, (_, i2) => i2 % 4 * 4 + (i2 >> 2));
|
|
809
|
+
var BIT_REVERSED = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15];
|
|
810
|
+
var ROUND1 = round(SEQUENTIAL, [3, 7, 11, 19], 0);
|
|
811
|
+
var ROUND2 = round(COLUMNS, [3, 5, 9, 13], K2);
|
|
812
|
+
var ROUND3 = round(BIT_REVERSED, [3, 9, 11, 15], K3);
|
|
813
|
+
function transform2(state, x) {
|
|
814
|
+
const r = [...state];
|
|
815
|
+
applyRotatingRound(r, ROUND1, f1, x);
|
|
816
|
+
applyRotatingRound(r, ROUND2, f2, x);
|
|
817
|
+
applyRotatingRound(r, ROUND3, f3, x);
|
|
818
|
+
for (let i2 = 0; i2 < 4; i2++) state[i2] = add32(state[i2], r[i2]);
|
|
819
|
+
}
|
|
820
|
+
function md4(message) {
|
|
821
|
+
return mdStyleDigest(message, INITIAL_STATE, transform2);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// digest/md5.ts
|
|
825
|
+
var INITIAL_STATE2 = [1732584193, 4023233417, 2562383102, 271733878];
|
|
826
|
+
function f(x, y, z) {
|
|
827
|
+
return x & y | ~x & z;
|
|
828
|
+
}
|
|
829
|
+
function g(x, y, z) {
|
|
830
|
+
return x & z | y & ~z;
|
|
831
|
+
}
|
|
832
|
+
function h(x, y, z) {
|
|
833
|
+
return x ^ y ^ z;
|
|
834
|
+
}
|
|
835
|
+
function i(x, y, z) {
|
|
836
|
+
return y ^ (x | ~z);
|
|
837
|
+
}
|
|
838
|
+
var T = Array.from(
|
|
839
|
+
{ length: 64 },
|
|
840
|
+
(_, index) => Math.floor(Math.abs(Math.sin(index + 1)) * 2 ** 32)
|
|
841
|
+
);
|
|
842
|
+
var SHIFTS = [
|
|
843
|
+
[7, 12, 17, 22],
|
|
844
|
+
[5, 9, 14, 20],
|
|
845
|
+
[4, 11, 16, 23],
|
|
846
|
+
[6, 10, 15, 21]
|
|
847
|
+
];
|
|
848
|
+
var WORD_INDEX = [
|
|
849
|
+
(idx) => idx,
|
|
850
|
+
(idx) => (5 * idx + 1) % 16,
|
|
851
|
+
(idx) => (3 * idx + 5) % 16,
|
|
852
|
+
(idx) => 7 * idx % 16
|
|
853
|
+
];
|
|
854
|
+
var ROUND_FNS = [f, g, h, i];
|
|
855
|
+
function buildOps(round2) {
|
|
856
|
+
const shifts = SHIFTS[round2];
|
|
857
|
+
const wordIndex = WORD_INDEX[round2];
|
|
858
|
+
return Array.from({ length: 16 }, (_, idx) => {
|
|
859
|
+
const opNumber = round2 * 16 + idx;
|
|
860
|
+
return [wordIndex(idx), shifts[idx % 4], T[opNumber]];
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
var ROUNDS = [0, 1, 2, 3].map(buildOps);
|
|
864
|
+
function transform3(state, x) {
|
|
865
|
+
const r = [...state];
|
|
866
|
+
for (let round2 = 0; round2 < 4; round2++) {
|
|
867
|
+
applyRotatingRound(r, ROUNDS[round2], ROUND_FNS[round2], x, true);
|
|
868
|
+
}
|
|
869
|
+
for (let idx = 0; idx < 4; idx++) {
|
|
870
|
+
state[idx] = add32(state[idx], r[idx]);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
function md5(message) {
|
|
874
|
+
return mdStyleDigest(message, INITIAL_STATE2, transform3);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// digest/ripemd-functions.ts
|
|
878
|
+
function f12(x, y, z) {
|
|
879
|
+
return x ^ y ^ z;
|
|
880
|
+
}
|
|
881
|
+
function f22(x, y, z) {
|
|
882
|
+
return x & y | ~x & z;
|
|
883
|
+
}
|
|
884
|
+
function f32(x, y, z) {
|
|
885
|
+
return (x | ~y) ^ z;
|
|
886
|
+
}
|
|
887
|
+
function f4(x, y, z) {
|
|
888
|
+
return z & x | ~z & y;
|
|
889
|
+
}
|
|
890
|
+
function f5(x, y, z) {
|
|
891
|
+
return x ^ (y | ~z);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// digest/ripemd128.ts
|
|
895
|
+
var INITIAL_STATE3 = [1732584193, 4023233417, 2562383102, 271733878];
|
|
896
|
+
var LEFT_ROUNDS = [
|
|
897
|
+
[
|
|
898
|
+
[0, 11, 0],
|
|
899
|
+
[1, 14, 0],
|
|
900
|
+
[2, 15, 0],
|
|
901
|
+
[3, 12, 0],
|
|
902
|
+
[4, 5, 0],
|
|
903
|
+
[5, 8, 0],
|
|
904
|
+
[6, 7, 0],
|
|
905
|
+
[7, 9, 0],
|
|
906
|
+
[8, 11, 0],
|
|
907
|
+
[9, 13, 0],
|
|
908
|
+
[10, 14, 0],
|
|
909
|
+
[11, 15, 0],
|
|
910
|
+
[12, 6, 0],
|
|
911
|
+
[13, 7, 0],
|
|
912
|
+
[14, 9, 0],
|
|
913
|
+
[15, 8, 0]
|
|
914
|
+
],
|
|
915
|
+
[
|
|
916
|
+
[7, 7, 1518500249],
|
|
917
|
+
[4, 6, 1518500249],
|
|
918
|
+
[13, 8, 1518500249],
|
|
919
|
+
[1, 13, 1518500249],
|
|
920
|
+
[10, 11, 1518500249],
|
|
921
|
+
[6, 9, 1518500249],
|
|
922
|
+
[15, 7, 1518500249],
|
|
923
|
+
[3, 15, 1518500249],
|
|
924
|
+
[12, 7, 1518500249],
|
|
925
|
+
[0, 12, 1518500249],
|
|
926
|
+
[9, 15, 1518500249],
|
|
927
|
+
[5, 9, 1518500249],
|
|
928
|
+
[2, 11, 1518500249],
|
|
929
|
+
[14, 7, 1518500249],
|
|
930
|
+
[11, 13, 1518500249],
|
|
931
|
+
[8, 12, 1518500249]
|
|
932
|
+
],
|
|
933
|
+
[
|
|
934
|
+
[3, 11, 1859775393],
|
|
935
|
+
[10, 13, 1859775393],
|
|
936
|
+
[14, 6, 1859775393],
|
|
937
|
+
[4, 7, 1859775393],
|
|
938
|
+
[9, 14, 1859775393],
|
|
939
|
+
[15, 9, 1859775393],
|
|
940
|
+
[8, 13, 1859775393],
|
|
941
|
+
[1, 15, 1859775393],
|
|
942
|
+
[2, 14, 1859775393],
|
|
943
|
+
[7, 8, 1859775393],
|
|
944
|
+
[0, 13, 1859775393],
|
|
945
|
+
[6, 6, 1859775393],
|
|
946
|
+
[13, 5, 1859775393],
|
|
947
|
+
[11, 12, 1859775393],
|
|
948
|
+
[5, 7, 1859775393],
|
|
949
|
+
[12, 5, 1859775393]
|
|
950
|
+
],
|
|
951
|
+
[
|
|
952
|
+
[1, 11, 2400959708],
|
|
953
|
+
[9, 12, 2400959708],
|
|
954
|
+
[11, 14, 2400959708],
|
|
955
|
+
[10, 15, 2400959708],
|
|
956
|
+
[0, 14, 2400959708],
|
|
957
|
+
[8, 15, 2400959708],
|
|
958
|
+
[12, 9, 2400959708],
|
|
959
|
+
[4, 8, 2400959708],
|
|
960
|
+
[13, 9, 2400959708],
|
|
961
|
+
[3, 14, 2400959708],
|
|
962
|
+
[7, 5, 2400959708],
|
|
963
|
+
[15, 6, 2400959708],
|
|
964
|
+
[14, 8, 2400959708],
|
|
965
|
+
[5, 6, 2400959708],
|
|
966
|
+
[6, 5, 2400959708],
|
|
967
|
+
[2, 12, 2400959708]
|
|
968
|
+
]
|
|
969
|
+
];
|
|
970
|
+
var RIGHT_ROUNDS = [
|
|
971
|
+
[
|
|
972
|
+
[5, 8, 1352829926],
|
|
973
|
+
[14, 9, 1352829926],
|
|
974
|
+
[7, 9, 1352829926],
|
|
975
|
+
[0, 11, 1352829926],
|
|
976
|
+
[9, 13, 1352829926],
|
|
977
|
+
[2, 15, 1352829926],
|
|
978
|
+
[11, 15, 1352829926],
|
|
979
|
+
[4, 5, 1352829926],
|
|
980
|
+
[13, 7, 1352829926],
|
|
981
|
+
[6, 7, 1352829926],
|
|
982
|
+
[15, 8, 1352829926],
|
|
983
|
+
[8, 11, 1352829926],
|
|
984
|
+
[1, 14, 1352829926],
|
|
985
|
+
[10, 14, 1352829926],
|
|
986
|
+
[3, 12, 1352829926],
|
|
987
|
+
[12, 6, 1352829926]
|
|
988
|
+
],
|
|
989
|
+
[
|
|
990
|
+
[6, 9, 1548603684],
|
|
991
|
+
[11, 13, 1548603684],
|
|
992
|
+
[3, 15, 1548603684],
|
|
993
|
+
[7, 7, 1548603684],
|
|
994
|
+
[0, 12, 1548603684],
|
|
995
|
+
[13, 8, 1548603684],
|
|
996
|
+
[5, 9, 1548603684],
|
|
997
|
+
[10, 11, 1548603684],
|
|
998
|
+
[14, 7, 1548603684],
|
|
999
|
+
[15, 7, 1548603684],
|
|
1000
|
+
[8, 12, 1548603684],
|
|
1001
|
+
[12, 7, 1548603684],
|
|
1002
|
+
[4, 6, 1548603684],
|
|
1003
|
+
[9, 15, 1548603684],
|
|
1004
|
+
[1, 13, 1548603684],
|
|
1005
|
+
[2, 11, 1548603684]
|
|
1006
|
+
],
|
|
1007
|
+
[
|
|
1008
|
+
[15, 9, 1836072691],
|
|
1009
|
+
[5, 7, 1836072691],
|
|
1010
|
+
[1, 15, 1836072691],
|
|
1011
|
+
[3, 11, 1836072691],
|
|
1012
|
+
[7, 8, 1836072691],
|
|
1013
|
+
[14, 6, 1836072691],
|
|
1014
|
+
[6, 6, 1836072691],
|
|
1015
|
+
[9, 14, 1836072691],
|
|
1016
|
+
[11, 12, 1836072691],
|
|
1017
|
+
[8, 13, 1836072691],
|
|
1018
|
+
[12, 5, 1836072691],
|
|
1019
|
+
[2, 14, 1836072691],
|
|
1020
|
+
[10, 13, 1836072691],
|
|
1021
|
+
[0, 13, 1836072691],
|
|
1022
|
+
[4, 7, 1836072691],
|
|
1023
|
+
[13, 5, 1836072691]
|
|
1024
|
+
],
|
|
1025
|
+
[
|
|
1026
|
+
[8, 15, 0],
|
|
1027
|
+
[6, 5, 0],
|
|
1028
|
+
[4, 8, 0],
|
|
1029
|
+
[1, 11, 0],
|
|
1030
|
+
[3, 14, 0],
|
|
1031
|
+
[11, 14, 0],
|
|
1032
|
+
[15, 6, 0],
|
|
1033
|
+
[0, 14, 0],
|
|
1034
|
+
[5, 6, 0],
|
|
1035
|
+
[12, 9, 0],
|
|
1036
|
+
[2, 12, 0],
|
|
1037
|
+
[13, 9, 0],
|
|
1038
|
+
[9, 12, 0],
|
|
1039
|
+
[7, 5, 0],
|
|
1040
|
+
[10, 15, 0],
|
|
1041
|
+
[14, 8, 0]
|
|
1042
|
+
]
|
|
1043
|
+
];
|
|
1044
|
+
var LEFT_FNS = [f12, f22, f32, f4];
|
|
1045
|
+
var RIGHT_FNS = [f4, f32, f22, f12];
|
|
1046
|
+
function transform4(state, x) {
|
|
1047
|
+
const left = [...state];
|
|
1048
|
+
const right = [...state];
|
|
1049
|
+
for (let round2 = 0; round2 < 4; round2++) {
|
|
1050
|
+
applyRotatingRound(left, LEFT_ROUNDS[round2], LEFT_FNS[round2], x);
|
|
1051
|
+
applyRotatingRound(right, RIGHT_ROUNDS[round2], RIGHT_FNS[round2], x);
|
|
1052
|
+
}
|
|
1053
|
+
const orig = state;
|
|
1054
|
+
const newState = [
|
|
1055
|
+
add32(right[3], left[2], orig[1]),
|
|
1056
|
+
add32(orig[2], left[3], right[0]),
|
|
1057
|
+
add32(orig[3], left[0], right[1]),
|
|
1058
|
+
add32(orig[0], left[1], right[2])
|
|
1059
|
+
];
|
|
1060
|
+
for (let i2 = 0; i2 < 4; i2++) {
|
|
1061
|
+
state[i2] = newState[i2];
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
function ripemd128(message) {
|
|
1065
|
+
return mdStyleDigest(message, INITIAL_STATE3, transform4);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// digest/ripemd160.ts
|
|
1069
|
+
var INITIAL_STATE4 = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
1070
|
+
var LEFT_ROUNDS2 = [
|
|
1071
|
+
[
|
|
1072
|
+
[0, 11, 0],
|
|
1073
|
+
[1, 14, 0],
|
|
1074
|
+
[2, 15, 0],
|
|
1075
|
+
[3, 12, 0],
|
|
1076
|
+
[4, 5, 0],
|
|
1077
|
+
[5, 8, 0],
|
|
1078
|
+
[6, 7, 0],
|
|
1079
|
+
[7, 9, 0],
|
|
1080
|
+
[8, 11, 0],
|
|
1081
|
+
[9, 13, 0],
|
|
1082
|
+
[10, 14, 0],
|
|
1083
|
+
[11, 15, 0],
|
|
1084
|
+
[12, 6, 0],
|
|
1085
|
+
[13, 7, 0],
|
|
1086
|
+
[14, 9, 0],
|
|
1087
|
+
[15, 8, 0]
|
|
1088
|
+
],
|
|
1089
|
+
[
|
|
1090
|
+
[7, 7, 1518500249],
|
|
1091
|
+
[4, 6, 1518500249],
|
|
1092
|
+
[13, 8, 1518500249],
|
|
1093
|
+
[1, 13, 1518500249],
|
|
1094
|
+
[10, 11, 1518500249],
|
|
1095
|
+
[6, 9, 1518500249],
|
|
1096
|
+
[15, 7, 1518500249],
|
|
1097
|
+
[3, 15, 1518500249],
|
|
1098
|
+
[12, 7, 1518500249],
|
|
1099
|
+
[0, 12, 1518500249],
|
|
1100
|
+
[9, 15, 1518500249],
|
|
1101
|
+
[5, 9, 1518500249],
|
|
1102
|
+
[2, 11, 1518500249],
|
|
1103
|
+
[14, 7, 1518500249],
|
|
1104
|
+
[11, 13, 1518500249],
|
|
1105
|
+
[8, 12, 1518500249]
|
|
1106
|
+
],
|
|
1107
|
+
[
|
|
1108
|
+
[3, 11, 1859775393],
|
|
1109
|
+
[10, 13, 1859775393],
|
|
1110
|
+
[14, 6, 1859775393],
|
|
1111
|
+
[4, 7, 1859775393],
|
|
1112
|
+
[9, 14, 1859775393],
|
|
1113
|
+
[15, 9, 1859775393],
|
|
1114
|
+
[8, 13, 1859775393],
|
|
1115
|
+
[1, 15, 1859775393],
|
|
1116
|
+
[2, 14, 1859775393],
|
|
1117
|
+
[7, 8, 1859775393],
|
|
1118
|
+
[0, 13, 1859775393],
|
|
1119
|
+
[6, 6, 1859775393],
|
|
1120
|
+
[13, 5, 1859775393],
|
|
1121
|
+
[11, 12, 1859775393],
|
|
1122
|
+
[5, 7, 1859775393],
|
|
1123
|
+
[12, 5, 1859775393]
|
|
1124
|
+
],
|
|
1125
|
+
[
|
|
1126
|
+
[1, 11, 2400959708],
|
|
1127
|
+
[9, 12, 2400959708],
|
|
1128
|
+
[11, 14, 2400959708],
|
|
1129
|
+
[10, 15, 2400959708],
|
|
1130
|
+
[0, 14, 2400959708],
|
|
1131
|
+
[8, 15, 2400959708],
|
|
1132
|
+
[12, 9, 2400959708],
|
|
1133
|
+
[4, 8, 2400959708],
|
|
1134
|
+
[13, 9, 2400959708],
|
|
1135
|
+
[3, 14, 2400959708],
|
|
1136
|
+
[7, 5, 2400959708],
|
|
1137
|
+
[15, 6, 2400959708],
|
|
1138
|
+
[14, 8, 2400959708],
|
|
1139
|
+
[5, 6, 2400959708],
|
|
1140
|
+
[6, 5, 2400959708],
|
|
1141
|
+
[2, 12, 2400959708]
|
|
1142
|
+
],
|
|
1143
|
+
[
|
|
1144
|
+
[4, 9, 2840853838],
|
|
1145
|
+
[0, 15, 2840853838],
|
|
1146
|
+
[5, 5, 2840853838],
|
|
1147
|
+
[9, 11, 2840853838],
|
|
1148
|
+
[7, 6, 2840853838],
|
|
1149
|
+
[12, 8, 2840853838],
|
|
1150
|
+
[2, 13, 2840853838],
|
|
1151
|
+
[10, 12, 2840853838],
|
|
1152
|
+
[14, 5, 2840853838],
|
|
1153
|
+
[1, 12, 2840853838],
|
|
1154
|
+
[3, 13, 2840853838],
|
|
1155
|
+
[8, 14, 2840853838],
|
|
1156
|
+
[11, 11, 2840853838],
|
|
1157
|
+
[6, 8, 2840853838],
|
|
1158
|
+
[15, 5, 2840853838],
|
|
1159
|
+
[13, 6, 2840853838]
|
|
1160
|
+
]
|
|
1161
|
+
];
|
|
1162
|
+
var RIGHT_ROUNDS2 = [
|
|
1163
|
+
[
|
|
1164
|
+
[5, 8, 1352829926],
|
|
1165
|
+
[14, 9, 1352829926],
|
|
1166
|
+
[7, 9, 1352829926],
|
|
1167
|
+
[0, 11, 1352829926],
|
|
1168
|
+
[9, 13, 1352829926],
|
|
1169
|
+
[2, 15, 1352829926],
|
|
1170
|
+
[11, 15, 1352829926],
|
|
1171
|
+
[4, 5, 1352829926],
|
|
1172
|
+
[13, 7, 1352829926],
|
|
1173
|
+
[6, 7, 1352829926],
|
|
1174
|
+
[15, 8, 1352829926],
|
|
1175
|
+
[8, 11, 1352829926],
|
|
1176
|
+
[1, 14, 1352829926],
|
|
1177
|
+
[10, 14, 1352829926],
|
|
1178
|
+
[3, 12, 1352829926],
|
|
1179
|
+
[12, 6, 1352829926]
|
|
1180
|
+
],
|
|
1181
|
+
[
|
|
1182
|
+
[6, 9, 1548603684],
|
|
1183
|
+
[11, 13, 1548603684],
|
|
1184
|
+
[3, 15, 1548603684],
|
|
1185
|
+
[7, 7, 1548603684],
|
|
1186
|
+
[0, 12, 1548603684],
|
|
1187
|
+
[13, 8, 1548603684],
|
|
1188
|
+
[5, 9, 1548603684],
|
|
1189
|
+
[10, 11, 1548603684],
|
|
1190
|
+
[14, 7, 1548603684],
|
|
1191
|
+
[15, 7, 1548603684],
|
|
1192
|
+
[8, 12, 1548603684],
|
|
1193
|
+
[12, 7, 1548603684],
|
|
1194
|
+
[4, 6, 1548603684],
|
|
1195
|
+
[9, 15, 1548603684],
|
|
1196
|
+
[1, 13, 1548603684],
|
|
1197
|
+
[2, 11, 1548603684]
|
|
1198
|
+
],
|
|
1199
|
+
[
|
|
1200
|
+
[15, 9, 1836072691],
|
|
1201
|
+
[5, 7, 1836072691],
|
|
1202
|
+
[1, 15, 1836072691],
|
|
1203
|
+
[3, 11, 1836072691],
|
|
1204
|
+
[7, 8, 1836072691],
|
|
1205
|
+
[14, 6, 1836072691],
|
|
1206
|
+
[6, 6, 1836072691],
|
|
1207
|
+
[9, 14, 1836072691],
|
|
1208
|
+
[11, 12, 1836072691],
|
|
1209
|
+
[8, 13, 1836072691],
|
|
1210
|
+
[12, 5, 1836072691],
|
|
1211
|
+
[2, 14, 1836072691],
|
|
1212
|
+
[10, 13, 1836072691],
|
|
1213
|
+
[0, 13, 1836072691],
|
|
1214
|
+
[4, 7, 1836072691],
|
|
1215
|
+
[13, 5, 1836072691]
|
|
1216
|
+
],
|
|
1217
|
+
[
|
|
1218
|
+
[8, 15, 2053994217],
|
|
1219
|
+
[6, 5, 2053994217],
|
|
1220
|
+
[4, 8, 2053994217],
|
|
1221
|
+
[1, 11, 2053994217],
|
|
1222
|
+
[3, 14, 2053994217],
|
|
1223
|
+
[11, 14, 2053994217],
|
|
1224
|
+
[15, 6, 2053994217],
|
|
1225
|
+
[0, 14, 2053994217],
|
|
1226
|
+
[5, 6, 2053994217],
|
|
1227
|
+
[12, 9, 2053994217],
|
|
1228
|
+
[2, 12, 2053994217],
|
|
1229
|
+
[13, 9, 2053994217],
|
|
1230
|
+
[9, 12, 2053994217],
|
|
1231
|
+
[7, 5, 2053994217],
|
|
1232
|
+
[10, 15, 2053994217],
|
|
1233
|
+
[14, 8, 2053994217]
|
|
1234
|
+
],
|
|
1235
|
+
[
|
|
1236
|
+
[12, 8, 0],
|
|
1237
|
+
[15, 5, 0],
|
|
1238
|
+
[10, 12, 0],
|
|
1239
|
+
[4, 9, 0],
|
|
1240
|
+
[1, 12, 0],
|
|
1241
|
+
[5, 5, 0],
|
|
1242
|
+
[8, 14, 0],
|
|
1243
|
+
[7, 6, 0],
|
|
1244
|
+
[6, 8, 0],
|
|
1245
|
+
[2, 13, 0],
|
|
1246
|
+
[13, 6, 0],
|
|
1247
|
+
[14, 5, 0],
|
|
1248
|
+
[0, 15, 0],
|
|
1249
|
+
[3, 13, 0],
|
|
1250
|
+
[9, 11, 0],
|
|
1251
|
+
[11, 11, 0]
|
|
1252
|
+
]
|
|
1253
|
+
];
|
|
1254
|
+
var LEFT_FNS2 = [f12, f22, f32, f4, f5];
|
|
1255
|
+
var RIGHT_FNS2 = [f5, f4, f32, f22, f12];
|
|
1256
|
+
function applyLane(r, ops, f6, x, startTarget) {
|
|
1257
|
+
let target = startTarget;
|
|
1258
|
+
for (const [k, s, addConst] of ops) {
|
|
1259
|
+
const i1 = (target + 1) % 5;
|
|
1260
|
+
const i2 = (target + 2) % 5;
|
|
1261
|
+
const i3 = (target + 3) % 5;
|
|
1262
|
+
const i4 = (target + 4) % 5;
|
|
1263
|
+
const sum = r[target] + f6(r[i1], r[i2], r[i3]) + x[k] + addConst >>> 0;
|
|
1264
|
+
const newTarget = (sum << s | sum >>> 32 - s) + r[i4] >>> 0;
|
|
1265
|
+
const c = r[i2];
|
|
1266
|
+
r[i2] = (c << 10 | c >>> 22) >>> 0;
|
|
1267
|
+
r[target] = newTarget;
|
|
1268
|
+
target = (target + 4) % 5;
|
|
1269
|
+
}
|
|
1270
|
+
return target;
|
|
1271
|
+
}
|
|
1272
|
+
function transform5(state, x) {
|
|
1273
|
+
const left = [...state];
|
|
1274
|
+
const right = [...state];
|
|
1275
|
+
let leftTarget = 0;
|
|
1276
|
+
let rightTarget = 0;
|
|
1277
|
+
for (let round2 = 0; round2 < 5; round2++) {
|
|
1278
|
+
leftTarget = applyLane(left, LEFT_ROUNDS2[round2], LEFT_FNS2[round2], x, leftTarget);
|
|
1279
|
+
rightTarget = applyLane(right, RIGHT_ROUNDS2[round2], RIGHT_FNS2[round2], x, rightTarget);
|
|
1280
|
+
}
|
|
1281
|
+
const orig = state;
|
|
1282
|
+
const newState = [
|
|
1283
|
+
add32(right[3], left[2], orig[1]),
|
|
1284
|
+
add32(orig[2], left[3], right[4]),
|
|
1285
|
+
add32(orig[3], left[4], right[0]),
|
|
1286
|
+
add32(orig[4], left[0], right[1]),
|
|
1287
|
+
add32(orig[0], left[1], right[2])
|
|
1288
|
+
];
|
|
1289
|
+
for (let i2 = 0; i2 < 5; i2++) {
|
|
1290
|
+
state[i2] = newState[i2];
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
function ripemd160(message) {
|
|
1294
|
+
return mdStyleDigest(message, INITIAL_STATE4, transform5);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
457
1297
|
// digest/sha256.ts
|
|
458
1298
|
var K = new Uint32Array([
|
|
459
1299
|
1116352408,
|
|
@@ -533,40 +1373,40 @@ var IV = [
|
|
|
533
1373
|
];
|
|
534
1374
|
var W = new Uint32Array(64);
|
|
535
1375
|
var rotr = (x, n) => x >>> n | x << 32 - n;
|
|
536
|
-
function compress(
|
|
537
|
-
for (let
|
|
538
|
-
for (let
|
|
539
|
-
const a2 = W[
|
|
540
|
-
const b2 = W[
|
|
1376
|
+
function compress(h2, view, offset) {
|
|
1377
|
+
for (let i2 = 0; i2 < 16; i2++) W[i2] = view.getUint32(offset + i2 * 4);
|
|
1378
|
+
for (let i2 = 16; i2 < 64; i2++) {
|
|
1379
|
+
const a2 = W[i2 - 15];
|
|
1380
|
+
const b2 = W[i2 - 2];
|
|
541
1381
|
const s0 = rotr(a2, 7) ^ rotr(a2, 18) ^ a2 >>> 3;
|
|
542
1382
|
const s1 = rotr(b2, 17) ^ rotr(b2, 19) ^ b2 >>> 10;
|
|
543
|
-
W[
|
|
1383
|
+
W[i2] = W[i2 - 16] + s0 + W[i2 - 7] + s1 >>> 0;
|
|
544
1384
|
}
|
|
545
|
-
let a =
|
|
546
|
-
for (let
|
|
1385
|
+
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];
|
|
1386
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
547
1387
|
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
548
|
-
const ch = e &
|
|
549
|
-
const t1 = k + S1 + ch + K[
|
|
1388
|
+
const ch = e & f6 ^ ~e & g2;
|
|
1389
|
+
const t1 = k + S1 + ch + K[i2] + W[i2] >>> 0;
|
|
550
1390
|
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
551
1391
|
const maj = a & b ^ a & c ^ b & c;
|
|
552
1392
|
const t2 = S0 + maj >>> 0;
|
|
553
|
-
k =
|
|
554
|
-
|
|
555
|
-
|
|
1393
|
+
k = g2;
|
|
1394
|
+
g2 = f6;
|
|
1395
|
+
f6 = e;
|
|
556
1396
|
e = d + t1 >>> 0;
|
|
557
1397
|
d = c;
|
|
558
1398
|
c = b;
|
|
559
1399
|
b = a;
|
|
560
1400
|
a = t1 + t2 >>> 0;
|
|
561
1401
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
1402
|
+
h2[0] = h2[0] + a >>> 0;
|
|
1403
|
+
h2[1] = h2[1] + b >>> 0;
|
|
1404
|
+
h2[2] = h2[2] + c >>> 0;
|
|
1405
|
+
h2[3] = h2[3] + d >>> 0;
|
|
1406
|
+
h2[4] = h2[4] + e >>> 0;
|
|
1407
|
+
h2[5] = h2[5] + f6 >>> 0;
|
|
1408
|
+
h2[6] = h2[6] + g2 >>> 0;
|
|
1409
|
+
h2[7] = h2[7] + k >>> 0;
|
|
570
1410
|
}
|
|
571
1411
|
function pad64(data) {
|
|
572
1412
|
const padded = new Uint8Array(Math.ceil((data.length + 9) / 64) * 64);
|
|
@@ -578,64 +1418,64 @@ function pad64(data) {
|
|
|
578
1418
|
view.setUint32(padded.length - 4, bits >>> 0);
|
|
579
1419
|
return view;
|
|
580
1420
|
}
|
|
581
|
-
function wordsOut(
|
|
582
|
-
const out = new Uint8Array(
|
|
1421
|
+
function wordsOut(h2) {
|
|
1422
|
+
const out = new Uint8Array(h2.length * 4);
|
|
583
1423
|
const view = new DataView(out.buffer);
|
|
584
|
-
for (let
|
|
1424
|
+
for (let i2 = 0; i2 < h2.length; i2++) view.setUint32(i2 * 4, h2[i2]);
|
|
585
1425
|
return out;
|
|
586
1426
|
}
|
|
587
1427
|
function sha256(data) {
|
|
588
|
-
const
|
|
1428
|
+
const h2 = new Uint32Array(IV);
|
|
589
1429
|
const view = pad64(data);
|
|
590
|
-
for (let offset = 0; offset < view.byteLength; offset += 64) compress(
|
|
591
|
-
return wordsOut(
|
|
1430
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) compress(h2, view, offset);
|
|
1431
|
+
return wordsOut(h2);
|
|
592
1432
|
}
|
|
593
1433
|
|
|
594
1434
|
// digest/sha1.ts
|
|
595
1435
|
var W2 = new Uint32Array(80);
|
|
596
1436
|
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
597
|
-
function compress2(
|
|
598
|
-
for (let
|
|
599
|
-
for (let
|
|
600
|
-
let a =
|
|
601
|
-
for (let
|
|
602
|
-
let
|
|
1437
|
+
function compress2(h2, view, offset) {
|
|
1438
|
+
for (let i2 = 0; i2 < 16; i2++) W2[i2] = view.getUint32(offset + i2 * 4);
|
|
1439
|
+
for (let i2 = 16; i2 < 80; i2++) W2[i2] = rotl(W2[i2 - 3] ^ W2[i2 - 8] ^ W2[i2 - 14] ^ W2[i2 - 16], 1);
|
|
1440
|
+
let a = h2[0], b = h2[1], c = h2[2], d = h2[3], e = h2[4];
|
|
1441
|
+
for (let i2 = 0; i2 < 80; i2++) {
|
|
1442
|
+
let f6;
|
|
603
1443
|
let k;
|
|
604
|
-
if (
|
|
605
|
-
|
|
1444
|
+
if (i2 < 20) {
|
|
1445
|
+
f6 = b & c | ~b & d;
|
|
606
1446
|
k = 1518500249;
|
|
607
|
-
} else if (
|
|
608
|
-
|
|
1447
|
+
} else if (i2 < 40) {
|
|
1448
|
+
f6 = b ^ c ^ d;
|
|
609
1449
|
k = 1859775393;
|
|
610
|
-
} else if (
|
|
611
|
-
|
|
1450
|
+
} else if (i2 < 60) {
|
|
1451
|
+
f6 = b & c | b & d | c & d;
|
|
612
1452
|
k = 2400959708;
|
|
613
1453
|
} else {
|
|
614
|
-
|
|
1454
|
+
f6 = b ^ c ^ d;
|
|
615
1455
|
k = 3395469782;
|
|
616
1456
|
}
|
|
617
|
-
const t = rotl(a, 5) +
|
|
1457
|
+
const t = rotl(a, 5) + f6 + e + k + W2[i2] >>> 0;
|
|
618
1458
|
e = d;
|
|
619
1459
|
d = c;
|
|
620
1460
|
c = rotl(b, 30) >>> 0;
|
|
621
1461
|
b = a;
|
|
622
1462
|
a = t;
|
|
623
1463
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
1464
|
+
h2[0] = h2[0] + a >>> 0;
|
|
1465
|
+
h2[1] = h2[1] + b >>> 0;
|
|
1466
|
+
h2[2] = h2[2] + c >>> 0;
|
|
1467
|
+
h2[3] = h2[3] + d >>> 0;
|
|
1468
|
+
h2[4] = h2[4] + e >>> 0;
|
|
629
1469
|
}
|
|
630
1470
|
function sha1(data) {
|
|
631
|
-
const
|
|
1471
|
+
const h2 = new Uint32Array([1732584193, 4023233417, 2562383102, 271733878, 3285377520]);
|
|
632
1472
|
const view = pad64(data);
|
|
633
|
-
for (let offset = 0; offset < view.byteLength; offset += 64) compress2(
|
|
634
|
-
return wordsOut(
|
|
1473
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) compress2(h2, view, offset);
|
|
1474
|
+
return wordsOut(h2);
|
|
635
1475
|
}
|
|
636
1476
|
|
|
637
1477
|
// digest/sha512.ts
|
|
638
|
-
var
|
|
1478
|
+
var K4 = new Uint32Array([
|
|
639
1479
|
1116352408,
|
|
640
1480
|
3609767458,
|
|
641
1481
|
1899447441,
|
|
@@ -834,35 +1674,35 @@ var IV_384 = [
|
|
|
834
1674
|
3204075428
|
|
835
1675
|
];
|
|
836
1676
|
var W3 = new Uint32Array(160);
|
|
837
|
-
function compress3(
|
|
838
|
-
for (let
|
|
839
|
-
const o = offset +
|
|
840
|
-
W3[
|
|
841
|
-
}
|
|
842
|
-
for (let
|
|
843
|
-
const xh = W3[(
|
|
844
|
-
const xl = W3[(
|
|
1677
|
+
function compress3(h2, data, offset) {
|
|
1678
|
+
for (let i2 = 0; i2 < 32; i2++) {
|
|
1679
|
+
const o = offset + i2 * 4;
|
|
1680
|
+
W3[i2] = (data[o] << 24 | data[o + 1] << 16 | data[o + 2] << 8 | data[o + 3]) >>> 0;
|
|
1681
|
+
}
|
|
1682
|
+
for (let i2 = 16; i2 < 80; i2++) {
|
|
1683
|
+
const xh = W3[(i2 - 15) * 2];
|
|
1684
|
+
const xl = W3[(i2 - 15) * 2 + 1];
|
|
845
1685
|
const s0h = (xh >>> 1 | xl << 31) ^ (xh >>> 8 | xl << 24) ^ xh >>> 7;
|
|
846
1686
|
const s0l = (xl >>> 1 | xh << 31) ^ (xl >>> 8 | xh << 24) ^ (xl >>> 7 | xh << 25);
|
|
847
|
-
const yh = W3[(
|
|
848
|
-
const yl = W3[(
|
|
1687
|
+
const yh = W3[(i2 - 2) * 2];
|
|
1688
|
+
const yl = W3[(i2 - 2) * 2 + 1];
|
|
849
1689
|
const s1h = (yh >>> 19 | yl << 13) ^ (yl >>> 29 | yh << 3) ^ yh >>> 6;
|
|
850
1690
|
const s1l = (yl >>> 19 | yh << 13) ^ (yh >>> 29 | yl << 3) ^ (yl >>> 6 | yh << 26);
|
|
851
|
-
let lo = (s0l >>> 0) + (s1l >>> 0) + W3[(
|
|
852
|
-
const hi = s0h + s1h + W3[(
|
|
1691
|
+
let lo = (s0l >>> 0) + (s1l >>> 0) + W3[(i2 - 7) * 2 + 1] + W3[(i2 - 16) * 2 + 1];
|
|
1692
|
+
const hi = s0h + s1h + W3[(i2 - 7) * 2] + W3[(i2 - 16) * 2] + Math.floor(lo / 4294967296);
|
|
853
1693
|
lo >>>= 0;
|
|
854
|
-
W3[
|
|
855
|
-
W3[
|
|
1694
|
+
W3[i2 * 2] = hi >>> 0;
|
|
1695
|
+
W3[i2 * 2 + 1] = lo;
|
|
856
1696
|
}
|
|
857
|
-
let ah =
|
|
858
|
-
let eh =
|
|
859
|
-
for (let
|
|
1697
|
+
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];
|
|
1698
|
+
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];
|
|
1699
|
+
for (let i2 = 0; i2 < 80; i2++) {
|
|
860
1700
|
const S1h = (eh >>> 14 | el3 << 18) ^ (eh >>> 18 | el3 << 14) ^ (el3 >>> 9 | eh << 23);
|
|
861
1701
|
const S1l = (el3 >>> 14 | eh << 18) ^ (el3 >>> 18 | eh << 14) ^ (eh >>> 9 | el3 << 23);
|
|
862
1702
|
const chh = eh & fh ^ ~eh & gh;
|
|
863
1703
|
const chl = el3 & fl ^ ~el3 & gl;
|
|
864
|
-
let t1l = (hl >>> 0) + (S1l >>> 0) + (chl >>> 0) +
|
|
865
|
-
const t1h = hh + S1h + chh +
|
|
1704
|
+
let t1l = (hl >>> 0) + (S1l >>> 0) + (chl >>> 0) + K4[i2 * 2 + 1] + W3[i2 * 2 + 1];
|
|
1705
|
+
const t1h = hh + S1h + chh + K4[i2 * 2] + W3[i2 * 2] + Math.floor(t1l / 4294967296);
|
|
866
1706
|
t1l >>>= 0;
|
|
867
1707
|
const S0h = (ah >>> 28 | al << 4) ^ (al >>> 2 | ah << 30) ^ (al >>> 7 | ah << 25);
|
|
868
1708
|
const S0l = (al >>> 28 | ah << 4) ^ (ah >>> 2 | al << 30) ^ (ah >>> 7 | al << 25);
|
|
@@ -890,10 +1730,10 @@ function compress3(h, data, offset) {
|
|
|
890
1730
|
ah = t1h + t2h + Math.floor(nl / 4294967296) >>> 0;
|
|
891
1731
|
al = nl >>> 0;
|
|
892
1732
|
}
|
|
893
|
-
const add2 = (
|
|
894
|
-
const lo = (
|
|
895
|
-
|
|
896
|
-
|
|
1733
|
+
const add2 = (i2, xh, xl) => {
|
|
1734
|
+
const lo = (h2[i2 + 1] >>> 0) + (xl >>> 0);
|
|
1735
|
+
h2[i2] = h2[i2] + xh + Math.floor(lo / 4294967296) >>> 0;
|
|
1736
|
+
h2[i2 + 1] = lo >>> 0;
|
|
897
1737
|
};
|
|
898
1738
|
add2(0, ah, al);
|
|
899
1739
|
add2(2, bh, bl);
|
|
@@ -905,7 +1745,7 @@ function compress3(h, data, offset) {
|
|
|
905
1745
|
add2(14, hh, hl);
|
|
906
1746
|
}
|
|
907
1747
|
function digest64(data, iv, bytes) {
|
|
908
|
-
const
|
|
1748
|
+
const h2 = new Uint32Array(iv);
|
|
909
1749
|
const padded = new Uint8Array(Math.ceil((data.length + 17) / 128) * 128);
|
|
910
1750
|
padded.set(data);
|
|
911
1751
|
padded[data.length] = 128;
|
|
@@ -913,25 +1753,407 @@ function digest64(data, iv, bytes) {
|
|
|
913
1753
|
const view = new DataView(padded.buffer);
|
|
914
1754
|
view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
|
|
915
1755
|
view.setUint32(padded.length - 4, bits >>> 0);
|
|
916
|
-
for (let offset = 0; offset < padded.length; offset += 128) compress3(
|
|
1756
|
+
for (let offset = 0; offset < padded.length; offset += 128) compress3(h2, padded, offset);
|
|
917
1757
|
const out = new Uint8Array(bytes);
|
|
918
1758
|
const outView = new DataView(out.buffer);
|
|
919
|
-
for (let
|
|
1759
|
+
for (let i2 = 0; i2 < bytes / 4; i2++) outView.setUint32(i2 * 4, h2[i2]);
|
|
920
1760
|
return out;
|
|
921
1761
|
}
|
|
922
1762
|
var sha512 = (data) => digest64(data, IV_512, 64);
|
|
923
1763
|
var sha384 = (data) => digest64(data, IV_384, 48);
|
|
924
1764
|
|
|
1765
|
+
// digest/whirlpool-sbox.ts
|
|
1766
|
+
var TABLE0 = [
|
|
1767
|
+
0x18186018c07830d8n,
|
|
1768
|
+
0x23238c2305af4626n,
|
|
1769
|
+
0xc6c63fc67ef991b8n,
|
|
1770
|
+
0xe8e887e8136fcdfbn,
|
|
1771
|
+
0x878726874ca113cbn,
|
|
1772
|
+
0xb8b8dab8a9626d11n,
|
|
1773
|
+
0x0101040108050209n,
|
|
1774
|
+
0x4f4f214f426e9e0dn,
|
|
1775
|
+
0x3636d836adee6c9bn,
|
|
1776
|
+
0xa6a6a2a6590451ffn,
|
|
1777
|
+
0xd2d26fd2debdb90cn,
|
|
1778
|
+
0xf5f5f3f5fb06f70en,
|
|
1779
|
+
0x7979f979ef80f296n,
|
|
1780
|
+
0x6f6fa16f5fcede30n,
|
|
1781
|
+
0x91917e91fcef3f6dn,
|
|
1782
|
+
0x52525552aa07a4f8n,
|
|
1783
|
+
0x60609d6027fdc047n,
|
|
1784
|
+
0xbcbccabc89766535n,
|
|
1785
|
+
0x9b9b569baccd2b37n,
|
|
1786
|
+
0x8e8e028e048c018an,
|
|
1787
|
+
0xa3a3b6a371155bd2n,
|
|
1788
|
+
0x0c0c300c603c186cn,
|
|
1789
|
+
0x7b7bf17bff8af684n,
|
|
1790
|
+
0x3535d435b5e16a80n,
|
|
1791
|
+
0x1d1d741de8693af5n,
|
|
1792
|
+
0xe0e0a7e05347ddb3n,
|
|
1793
|
+
0xd7d77bd7f6acb321n,
|
|
1794
|
+
0xc2c22fc25eed999cn,
|
|
1795
|
+
0x2e2eb82e6d965c43n,
|
|
1796
|
+
0x4b4b314b627a9629n,
|
|
1797
|
+
0xfefedffea321e15dn,
|
|
1798
|
+
0x575741578216aed5n,
|
|
1799
|
+
0x15155415a8412abdn,
|
|
1800
|
+
0x7777c1779fb6eee8n,
|
|
1801
|
+
0x3737dc37a5eb6e92n,
|
|
1802
|
+
0xe5e5b3e57b56d79en,
|
|
1803
|
+
0x9f9f469f8cd92313n,
|
|
1804
|
+
0xf0f0e7f0d317fd23n,
|
|
1805
|
+
0x4a4a354a6a7f9420n,
|
|
1806
|
+
0xdada4fda9e95a944n,
|
|
1807
|
+
0x58587d58fa25b0a2n,
|
|
1808
|
+
0xc9c903c906ca8fcfn,
|
|
1809
|
+
0x2929a429558d527cn,
|
|
1810
|
+
0x0a0a280a5022145an,
|
|
1811
|
+
0xb1b1feb1e14f7f50n,
|
|
1812
|
+
0xa0a0baa0691a5dc9n,
|
|
1813
|
+
0x6b6bb16b7fdad614n,
|
|
1814
|
+
0x85852e855cab17d9n,
|
|
1815
|
+
0xbdbdcebd8173673cn,
|
|
1816
|
+
0x5d5d695dd234ba8fn,
|
|
1817
|
+
0x1010401080502090n,
|
|
1818
|
+
0xf4f4f7f4f303f507n,
|
|
1819
|
+
0xcbcb0bcb16c08bddn,
|
|
1820
|
+
0x3e3ef83eedc67cd3n,
|
|
1821
|
+
0x0505140528110a2dn,
|
|
1822
|
+
0x676781671fe6ce78n,
|
|
1823
|
+
0xe4e4b7e47353d597n,
|
|
1824
|
+
0x27279c2725bb4e02n,
|
|
1825
|
+
0x4141194132588273n,
|
|
1826
|
+
0x8b8b168b2c9d0ba7n,
|
|
1827
|
+
0xa7a7a6a7510153f6n,
|
|
1828
|
+
0x7d7de97dcf94fab2n,
|
|
1829
|
+
0x95956e95dcfb3749n,
|
|
1830
|
+
0xd8d847d88e9fad56n,
|
|
1831
|
+
0xfbfbcbfb8b30eb70n,
|
|
1832
|
+
0xeeee9fee2371c1cdn,
|
|
1833
|
+
0x7c7ced7cc791f8bbn,
|
|
1834
|
+
0x6666856617e3cc71n,
|
|
1835
|
+
0xdddd53dda68ea77bn,
|
|
1836
|
+
0x17175c17b84b2eafn,
|
|
1837
|
+
0x4747014702468e45n,
|
|
1838
|
+
0x9e9e429e84dc211an,
|
|
1839
|
+
0xcaca0fca1ec589d4n,
|
|
1840
|
+
0x2d2db42d75995a58n,
|
|
1841
|
+
0xbfbfc6bf9179632en,
|
|
1842
|
+
0x07071c07381b0e3fn,
|
|
1843
|
+
0xadad8ead012347acn,
|
|
1844
|
+
0x5a5a755aea2fb4b0n,
|
|
1845
|
+
0x838336836cb51befn,
|
|
1846
|
+
0x3333cc3385ff66b6n,
|
|
1847
|
+
0x636391633ff2c65cn,
|
|
1848
|
+
0x02020802100a0412n,
|
|
1849
|
+
0xaaaa92aa39384993n,
|
|
1850
|
+
0x7171d971afa8e2den,
|
|
1851
|
+
0xc8c807c80ecf8dc6n,
|
|
1852
|
+
0x19196419c87d32d1n,
|
|
1853
|
+
0x494939497270923bn,
|
|
1854
|
+
0xd9d943d9869aaf5fn,
|
|
1855
|
+
0xf2f2eff2c31df931n,
|
|
1856
|
+
0xe3e3abe34b48dba8n,
|
|
1857
|
+
0x5b5b715be22ab6b9n,
|
|
1858
|
+
0x88881a8834920dbcn,
|
|
1859
|
+
0x9a9a529aa4c8293en,
|
|
1860
|
+
0x262698262dbe4c0bn,
|
|
1861
|
+
0x3232c8328dfa64bfn,
|
|
1862
|
+
0xb0b0fab0e94a7d59n,
|
|
1863
|
+
0xe9e983e91b6acff2n,
|
|
1864
|
+
0x0f0f3c0f78331e77n,
|
|
1865
|
+
0xd5d573d5e6a6b733n,
|
|
1866
|
+
0x80803a8074ba1df4n,
|
|
1867
|
+
0xbebec2be997c6127n,
|
|
1868
|
+
0xcdcd13cd26de87ebn,
|
|
1869
|
+
0x3434d034bde46889n,
|
|
1870
|
+
0x48483d487a759032n,
|
|
1871
|
+
0xffffdbffab24e354n,
|
|
1872
|
+
0x7a7af57af78ff48dn,
|
|
1873
|
+
0x90907a90f4ea3d64n,
|
|
1874
|
+
0x5f5f615fc23ebe9dn,
|
|
1875
|
+
0x202080201da0403dn,
|
|
1876
|
+
0x6868bd6867d5d00fn,
|
|
1877
|
+
0x1a1a681ad07234can,
|
|
1878
|
+
0xaeae82ae192c41b7n,
|
|
1879
|
+
0xb4b4eab4c95e757dn,
|
|
1880
|
+
0x54544d549a19a8cen,
|
|
1881
|
+
0x93937693ece53b7fn,
|
|
1882
|
+
0x222288220daa442fn,
|
|
1883
|
+
0x64648d6407e9c863n,
|
|
1884
|
+
0xf1f1e3f1db12ff2an,
|
|
1885
|
+
0x7373d173bfa2e6ccn,
|
|
1886
|
+
0x12124812905a2482n,
|
|
1887
|
+
0x40401d403a5d807an,
|
|
1888
|
+
0x0808200840281048n,
|
|
1889
|
+
0xc3c32bc356e89b95n,
|
|
1890
|
+
0xecec97ec337bc5dfn,
|
|
1891
|
+
0xdbdb4bdb9690ab4dn,
|
|
1892
|
+
0xa1a1bea1611f5fc0n,
|
|
1893
|
+
0x8d8d0e8d1c830791n,
|
|
1894
|
+
0x3d3df43df5c97ac8n,
|
|
1895
|
+
0x97976697ccf1335bn,
|
|
1896
|
+
0x0000000000000000n,
|
|
1897
|
+
0xcfcf1bcf36d483f9n,
|
|
1898
|
+
0x2b2bac2b4587566en,
|
|
1899
|
+
0x7676c57697b3ece1n,
|
|
1900
|
+
0x8282328264b019e6n,
|
|
1901
|
+
0xd6d67fd6fea9b128n,
|
|
1902
|
+
0x1b1b6c1bd87736c3n,
|
|
1903
|
+
0xb5b5eeb5c15b7774n,
|
|
1904
|
+
0xafaf86af112943ben,
|
|
1905
|
+
0x6a6ab56a77dfd41dn,
|
|
1906
|
+
0x50505d50ba0da0ean,
|
|
1907
|
+
0x45450945124c8a57n,
|
|
1908
|
+
0xf3f3ebf3cb18fb38n,
|
|
1909
|
+
0x3030c0309df060adn,
|
|
1910
|
+
0xefef9bef2b74c3c4n,
|
|
1911
|
+
0x3f3ffc3fe5c37edan,
|
|
1912
|
+
0x55554955921caac7n,
|
|
1913
|
+
0xa2a2b2a2791059dbn,
|
|
1914
|
+
0xeaea8fea0365c9e9n,
|
|
1915
|
+
0x656589650fecca6an,
|
|
1916
|
+
0xbabad2bab9686903n,
|
|
1917
|
+
0x2f2fbc2f65935e4an,
|
|
1918
|
+
0xc0c027c04ee79d8en,
|
|
1919
|
+
0xdede5fdebe81a160n,
|
|
1920
|
+
0x1c1c701ce06c38fcn,
|
|
1921
|
+
0xfdfdd3fdbb2ee746n,
|
|
1922
|
+
0x4d4d294d52649a1fn,
|
|
1923
|
+
0x92927292e4e03976n,
|
|
1924
|
+
0x7575c9758fbceafan,
|
|
1925
|
+
0x06061806301e0c36n,
|
|
1926
|
+
0x8a8a128a249809aen,
|
|
1927
|
+
0xb2b2f2b2f940794bn,
|
|
1928
|
+
0xe6e6bfe66359d185n,
|
|
1929
|
+
0x0e0e380e70361c7en,
|
|
1930
|
+
0x1f1f7c1ff8633ee7n,
|
|
1931
|
+
0x6262956237f7c455n,
|
|
1932
|
+
0xd4d477d4eea3b53an,
|
|
1933
|
+
0xa8a89aa829324d81n,
|
|
1934
|
+
0x96966296c4f43152n,
|
|
1935
|
+
0xf9f9c3f99b3aef62n,
|
|
1936
|
+
0xc5c533c566f697a3n,
|
|
1937
|
+
0x2525942535b14a10n,
|
|
1938
|
+
0x59597959f220b2abn,
|
|
1939
|
+
0x84842a8454ae15d0n,
|
|
1940
|
+
0x7272d572b7a7e4c5n,
|
|
1941
|
+
0x3939e439d5dd72ecn,
|
|
1942
|
+
0x4c4c2d4c5a619816n,
|
|
1943
|
+
0x5e5e655eca3bbc94n,
|
|
1944
|
+
0x7878fd78e785f09fn,
|
|
1945
|
+
0x3838e038ddd870e5n,
|
|
1946
|
+
0x8c8c0a8c14860598n,
|
|
1947
|
+
0xd1d163d1c6b2bf17n,
|
|
1948
|
+
0xa5a5aea5410b57e4n,
|
|
1949
|
+
0xe2e2afe2434dd9a1n,
|
|
1950
|
+
0x616199612ff8c24en,
|
|
1951
|
+
0xb3b3f6b3f1457b42n,
|
|
1952
|
+
0x2121842115a54234n,
|
|
1953
|
+
0x9c9c4a9c94d62508n,
|
|
1954
|
+
0x1e1e781ef0663ceen,
|
|
1955
|
+
0x4343114322528661n,
|
|
1956
|
+
0xc7c73bc776fc93b1n,
|
|
1957
|
+
0xfcfcd7fcb32be54fn,
|
|
1958
|
+
0x0404100420140824n,
|
|
1959
|
+
0x51515951b208a2e3n,
|
|
1960
|
+
0x99995e99bcc72f25n,
|
|
1961
|
+
0x6d6da96d4fc4da22n,
|
|
1962
|
+
0x0d0d340d68391a65n,
|
|
1963
|
+
0xfafacffa8335e979n,
|
|
1964
|
+
0xdfdf5bdfb684a369n,
|
|
1965
|
+
0x7e7ee57ed79bfca9n,
|
|
1966
|
+
0x242490243db44819n,
|
|
1967
|
+
0x3b3bec3bc5d776fen,
|
|
1968
|
+
0xabab96ab313d4b9an,
|
|
1969
|
+
0xcece1fce3ed181f0n,
|
|
1970
|
+
0x1111441188552299n,
|
|
1971
|
+
0x8f8f068f0c890383n,
|
|
1972
|
+
0x4e4e254e4a6b9c04n,
|
|
1973
|
+
0xb7b7e6b7d1517366n,
|
|
1974
|
+
0xebeb8beb0b60cbe0n,
|
|
1975
|
+
0x3c3cf03cfdcc78c1n,
|
|
1976
|
+
0x81813e817cbf1ffdn,
|
|
1977
|
+
0x94946a94d4fe3540n,
|
|
1978
|
+
0xf7f7fbf7eb0cf31cn,
|
|
1979
|
+
0xb9b9deb9a1676f18n,
|
|
1980
|
+
0x13134c13985f268bn,
|
|
1981
|
+
0x2c2cb02c7d9c5851n,
|
|
1982
|
+
0xd3d36bd3d6b8bb05n,
|
|
1983
|
+
0xe7e7bbe76b5cd38cn,
|
|
1984
|
+
0x6e6ea56e57cbdc39n,
|
|
1985
|
+
0xc4c437c46ef395aan,
|
|
1986
|
+
0x03030c03180f061bn,
|
|
1987
|
+
0x565645568a13acdcn,
|
|
1988
|
+
0x44440d441a49885en,
|
|
1989
|
+
0x7f7fe17fdf9efea0n,
|
|
1990
|
+
0xa9a99ea921374f88n,
|
|
1991
|
+
0x2a2aa82a4d825467n,
|
|
1992
|
+
0xbbbbd6bbb16d6b0an,
|
|
1993
|
+
0xc1c123c146e29f87n,
|
|
1994
|
+
0x53535153a202a6f1n,
|
|
1995
|
+
0xdcdc57dcae8ba572n,
|
|
1996
|
+
0x0b0b2c0b58271653n,
|
|
1997
|
+
0x9d9d4e9d9cd32701n,
|
|
1998
|
+
0x6c6cad6c47c1d82bn,
|
|
1999
|
+
0x3131c43195f562a4n,
|
|
2000
|
+
0x7474cd7487b9e8f3n,
|
|
2001
|
+
0xf6f6fff6e309f115n,
|
|
2002
|
+
0x464605460a438c4cn,
|
|
2003
|
+
0xacac8aac092645a5n,
|
|
2004
|
+
0x89891e893c970fb5n,
|
|
2005
|
+
0x14145014a04428b4n,
|
|
2006
|
+
0xe1e1a3e15b42dfban,
|
|
2007
|
+
0x16165816b04e2ca6n,
|
|
2008
|
+
0x3a3ae83acdd274f7n,
|
|
2009
|
+
0x6969b9696fd0d206n,
|
|
2010
|
+
0x09092409482d1241n,
|
|
2011
|
+
0x7070dd70a7ade0d7n,
|
|
2012
|
+
0xb6b6e2b6d954716fn,
|
|
2013
|
+
0xd0d067d0ceb7bd1en,
|
|
2014
|
+
0xeded93ed3b7ec7d6n,
|
|
2015
|
+
0xcccc17cc2edb85e2n,
|
|
2016
|
+
0x424215422a578468n,
|
|
2017
|
+
0x98985a98b4c22d2cn,
|
|
2018
|
+
0xa4a4aaa4490e55edn,
|
|
2019
|
+
0x2828a0285d885075n,
|
|
2020
|
+
0x5c5c6d5cda31b886n,
|
|
2021
|
+
0xf8f8c7f8933fed6bn,
|
|
2022
|
+
0x8686228644a411c2n
|
|
2023
|
+
];
|
|
2024
|
+
|
|
2025
|
+
// digest/whirlpool-table.ts
|
|
2026
|
+
var WORD_MASK = (1n << 64n) - 1n;
|
|
2027
|
+
var LOW_MASK = 0xffffffffn;
|
|
2028
|
+
function rotateBytesRight(value, bytes) {
|
|
2029
|
+
const bits = BigInt(bytes) * 8n;
|
|
2030
|
+
return (value >> bits | value << 64n - bits) & WORD_MASK;
|
|
2031
|
+
}
|
|
2032
|
+
var TABLES_HI = new Uint32Array(8 * 256);
|
|
2033
|
+
var TABLES_LO = new Uint32Array(8 * 256);
|
|
2034
|
+
for (let t = 0; t < 8; t++) {
|
|
2035
|
+
for (let x = 0; x < 256; x++) {
|
|
2036
|
+
const value = t === 0 ? TABLE0[x] : rotateBytesRight(TABLE0[x], t);
|
|
2037
|
+
TABLES_HI[t * 256 + x] = Number(value >> 32n);
|
|
2038
|
+
TABLES_LO[t * 256 + x] = Number(value & LOW_MASK);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
var ROUND_CONSTANTS = [
|
|
2042
|
+
0x1823c6e887b8014fn,
|
|
2043
|
+
0x36a6d2f5796f9152n,
|
|
2044
|
+
0x60bc9b8ea30c7b35n,
|
|
2045
|
+
0x1de0d7c22e4bfe57n,
|
|
2046
|
+
0x157737e59ff04adan,
|
|
2047
|
+
0x58c9290ab1a06b85n,
|
|
2048
|
+
0xbd5d10f4cb3e0567n,
|
|
2049
|
+
0xe427418ba77d95d8n,
|
|
2050
|
+
0xfbee7c66dd17479en,
|
|
2051
|
+
0xca2dbf07ad5a8333n
|
|
2052
|
+
];
|
|
2053
|
+
var ROUND_CONSTANTS_HI = Uint32Array.from(ROUND_CONSTANTS, (c) => Number(c >> 32n));
|
|
2054
|
+
var ROUND_CONSTANTS_LO = Uint32Array.from(ROUND_CONSTANTS, (c) => Number(c & LOW_MASK));
|
|
2055
|
+
|
|
2056
|
+
// digest/whirlpool.ts
|
|
2057
|
+
var TABLES_HI2 = TABLES_HI;
|
|
2058
|
+
var TABLES_LO2 = TABLES_LO;
|
|
2059
|
+
var ROUND_CONSTANTS_HI2 = ROUND_CONSTANTS_HI;
|
|
2060
|
+
var ROUND_CONSTANTS_LO2 = ROUND_CONSTANTS_LO;
|
|
2061
|
+
var BLOCK_BYTES = 64;
|
|
2062
|
+
var WORDS = 8;
|
|
2063
|
+
var ROUNDS2 = 10;
|
|
2064
|
+
var words = () => ({ hi: new Uint32Array(WORDS), lo: new Uint32Array(WORDS) });
|
|
2065
|
+
function op(src, column, out) {
|
|
2066
|
+
const { hi: h2, lo: l } = src;
|
|
2067
|
+
const b0 = h2[column] >>> 24;
|
|
2068
|
+
const b1 = h2[column + 7 & 7] >>> 16 & 255;
|
|
2069
|
+
const b2 = h2[column + 6 & 7] >>> 8 & 255;
|
|
2070
|
+
const b3 = h2[column + 5 & 7] & 255;
|
|
2071
|
+
const b4 = l[column + 4 & 7] >>> 24;
|
|
2072
|
+
const b5 = l[column + 3 & 7] >>> 16 & 255;
|
|
2073
|
+
const b6 = l[column + 2 & 7] >>> 8 & 255;
|
|
2074
|
+
const b7 = l[column + 1 & 7] & 255;
|
|
2075
|
+
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];
|
|
2076
|
+
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];
|
|
2077
|
+
}
|
|
2078
|
+
var scratch = { key: words(), state: words(), initial: words(), nextKey: words(), next: words() };
|
|
2079
|
+
function processBlock(hash2, block) {
|
|
2080
|
+
const { key, state, initial, nextKey, next } = scratch;
|
|
2081
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2082
|
+
initial.hi[i2] = block.hi[i2] ^ hash2.hi[i2];
|
|
2083
|
+
initial.lo[i2] = block.lo[i2] ^ hash2.lo[i2];
|
|
2084
|
+
}
|
|
2085
|
+
key.hi.set(hash2.hi);
|
|
2086
|
+
key.lo.set(hash2.lo);
|
|
2087
|
+
state.hi.set(initial.hi);
|
|
2088
|
+
state.lo.set(initial.lo);
|
|
2089
|
+
for (let round2 = 0; round2 < ROUNDS2; round2++) {
|
|
2090
|
+
for (let j = 0; j < WORDS; j++) op(key, j, nextKey);
|
|
2091
|
+
nextKey.hi[0] = nextKey.hi[0] ^ ROUND_CONSTANTS_HI2[round2];
|
|
2092
|
+
nextKey.lo[0] = nextKey.lo[0] ^ ROUND_CONSTANTS_LO2[round2];
|
|
2093
|
+
for (let j = 0; j < WORDS; j++) {
|
|
2094
|
+
op(state, j, next);
|
|
2095
|
+
next.hi[j] = next.hi[j] ^ nextKey.hi[j];
|
|
2096
|
+
next.lo[j] = next.lo[j] ^ nextKey.lo[j];
|
|
2097
|
+
}
|
|
2098
|
+
key.hi.set(nextKey.hi);
|
|
2099
|
+
key.lo.set(nextKey.lo);
|
|
2100
|
+
state.hi.set(next.hi);
|
|
2101
|
+
state.lo.set(next.lo);
|
|
2102
|
+
}
|
|
2103
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2104
|
+
hash2.hi[i2] = initial.hi[i2] ^ state.hi[i2];
|
|
2105
|
+
hash2.lo[i2] = initial.lo[i2] ^ state.lo[i2];
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
function pad(message) {
|
|
2109
|
+
let total = message.length + 1;
|
|
2110
|
+
while (total % BLOCK_BYTES !== 32) {
|
|
2111
|
+
total++;
|
|
2112
|
+
}
|
|
2113
|
+
total += 32;
|
|
2114
|
+
const padded = new Uint8Array(total);
|
|
2115
|
+
padded.set(message);
|
|
2116
|
+
padded[message.length] = 128;
|
|
2117
|
+
new DataView(padded.buffer).setBigUint64(total - 8, BigInt(message.length) * 8n, false);
|
|
2118
|
+
return padded;
|
|
2119
|
+
}
|
|
2120
|
+
function whirlpool(message) {
|
|
2121
|
+
const padded = pad(message);
|
|
2122
|
+
const view = new DataView(padded.buffer);
|
|
2123
|
+
const hash2 = words();
|
|
2124
|
+
const block = words();
|
|
2125
|
+
for (let offset = 0; offset < padded.length; offset += BLOCK_BYTES) {
|
|
2126
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2127
|
+
block.hi[i2] = view.getUint32(offset + i2 * 8, false);
|
|
2128
|
+
block.lo[i2] = view.getUint32(offset + i2 * 8 + 4, false);
|
|
2129
|
+
}
|
|
2130
|
+
processBlock(hash2, block);
|
|
2131
|
+
}
|
|
2132
|
+
const out = new Uint8Array(BLOCK_BYTES);
|
|
2133
|
+
const outView = new DataView(out.buffer);
|
|
2134
|
+
for (let i2 = 0; i2 < WORDS; i2++) {
|
|
2135
|
+
outView.setUint32(i2 * 8, hash2.hi[i2], false);
|
|
2136
|
+
outView.setUint32(i2 * 8 + 4, hash2.lo[i2], false);
|
|
2137
|
+
}
|
|
2138
|
+
return out;
|
|
2139
|
+
}
|
|
2140
|
+
|
|
925
2141
|
// digest/digest.ts
|
|
926
2142
|
var DIGESTS = {
|
|
927
2143
|
"SHA-1": sha1,
|
|
928
2144
|
"SHA-256": sha256,
|
|
929
2145
|
"SHA-384": sha384,
|
|
930
|
-
"SHA-512": sha512
|
|
2146
|
+
"SHA-512": sha512,
|
|
2147
|
+
MD2: md2,
|
|
2148
|
+
MD4: md4,
|
|
2149
|
+
MD5: md5,
|
|
2150
|
+
"RIPEMD-128": ripemd128,
|
|
2151
|
+
"RIPEMD-160": ripemd160,
|
|
2152
|
+
WHIRLPOOL: whirlpool
|
|
931
2153
|
};
|
|
932
2154
|
function digestFunction(name) {
|
|
933
2155
|
const canonical = normalizeDigestAlgorithmName(name);
|
|
934
|
-
return canonical &&
|
|
2156
|
+
return canonical && DIGESTS[canonical];
|
|
935
2157
|
}
|
|
936
2158
|
|
|
937
2159
|
// crypto/key-derivation.ts
|
|
@@ -950,56 +2172,56 @@ async function spinPassword(password, salt, spinCount, hashAlgorithm) {
|
|
|
950
2172
|
const passwordBytes = encodePasswordUtf16LE(password);
|
|
951
2173
|
const digest = digestFunction(hashAlgorithm);
|
|
952
2174
|
if (digest) {
|
|
953
|
-
let
|
|
954
|
-
const buffer = new Uint8Array(4 +
|
|
2175
|
+
let h3 = digest(concatArrays(salt, passwordBytes));
|
|
2176
|
+
const buffer = new Uint8Array(4 + h3.length);
|
|
955
2177
|
const view = new DataView(buffer.buffer);
|
|
956
|
-
for (let
|
|
957
|
-
view.setUint32(0,
|
|
958
|
-
buffer.set(
|
|
959
|
-
|
|
2178
|
+
for (let i2 = 0; i2 < spinCount; i2++) {
|
|
2179
|
+
view.setUint32(0, i2, true);
|
|
2180
|
+
buffer.set(h3, 4);
|
|
2181
|
+
h3 = digest(buffer);
|
|
960
2182
|
}
|
|
961
|
-
return
|
|
2183
|
+
return h3;
|
|
962
2184
|
}
|
|
963
|
-
let
|
|
964
|
-
for (let
|
|
965
|
-
|
|
2185
|
+
let h2 = await hash(hashAlgorithm, concatArrays(salt, passwordBytes));
|
|
2186
|
+
for (let i2 = 0; i2 < spinCount; i2++) {
|
|
2187
|
+
h2 = await hash(hashAlgorithm, concatArrays(uint32LE(i2), h2));
|
|
966
2188
|
}
|
|
967
|
-
return
|
|
2189
|
+
return h2;
|
|
968
2190
|
}
|
|
969
|
-
async function extendKey(
|
|
970
|
-
const
|
|
2191
|
+
async function extendKey(h2, hashAlgorithm, keyLength) {
|
|
2192
|
+
const pad2 = async (value) => {
|
|
971
2193
|
const input = new Uint8Array(64).fill(value);
|
|
972
|
-
for (let
|
|
2194
|
+
for (let i2 = 0; i2 < h2.length && i2 < 64; i2++) input[i2] = h2[i2] ^ value;
|
|
973
2195
|
return hash(hashAlgorithm, input);
|
|
974
2196
|
};
|
|
975
|
-
const x3 = concatArrays(await
|
|
2197
|
+
const x3 = concatArrays(await pad2(54), await pad2(92));
|
|
976
2198
|
return x3.subarray(0, keyLength);
|
|
977
2199
|
}
|
|
978
2200
|
function computeAgileKeyBase(password, salt, spinCount, hashAlgorithm) {
|
|
979
2201
|
return spinPassword(password, salt, spinCount, hashAlgorithm);
|
|
980
2202
|
}
|
|
981
2203
|
async function deriveAgileKeyFromBase(base, hashAlgorithm, blockKey, keyBits, hashSize) {
|
|
982
|
-
const
|
|
2204
|
+
const h2 = await hash(hashAlgorithm, concatArrays(base, blockKey));
|
|
983
2205
|
const keyLength = keyBits / 8;
|
|
984
|
-
if (hashSize >= keyLength) return
|
|
985
|
-
return extendKey(
|
|
2206
|
+
if (hashSize >= keyLength) return h2.subarray(0, keyLength);
|
|
2207
|
+
return extendKey(h2, hashAlgorithm, keyLength);
|
|
986
2208
|
}
|
|
987
2209
|
function computeStandardKeyBase(password, salt) {
|
|
988
2210
|
return spinPassword(password, salt, 5e4, "SHA-1");
|
|
989
2211
|
}
|
|
990
2212
|
async function deriveStandardKeyFromBase(base, keySize, blockNumber = 0) {
|
|
991
|
-
const
|
|
992
|
-
return extendKey(
|
|
2213
|
+
const h2 = await hash("SHA-1", concatArrays(base, uint32LE(blockNumber)));
|
|
2214
|
+
return extendKey(h2, "SHA-1", keySize / 8);
|
|
993
2215
|
}
|
|
994
2216
|
async function deriveStandardKey(password, salt, keySize, _algIdHash, blockNumber = 0) {
|
|
995
2217
|
const base = await computeStandardKeyBase(password, salt);
|
|
996
2218
|
return deriveStandardKeyFromBase(base, keySize, blockNumber);
|
|
997
2219
|
}
|
|
998
2220
|
async function generateIV(hashAlgorithm, salt, blockKey, blockSize) {
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
2221
|
+
const h2 = await hash(hashAlgorithm, concatArrays(salt, blockKey));
|
|
2222
|
+
if (h2.length >= blockSize) return h2.subarray(0, blockSize);
|
|
1001
2223
|
const padded = new Uint8Array(blockSize).fill(54);
|
|
1002
|
-
padded.set(
|
|
2224
|
+
padded.set(h2);
|
|
1003
2225
|
return padded;
|
|
1004
2226
|
}
|
|
1005
2227
|
|
|
@@ -1021,7 +2243,7 @@ async function verifyAgilePassword(info, password) {
|
|
|
1021
2243
|
const computedHash = await hash(pke.hashAlgorithm, verifierHashInput.subarray(0, pke.saltSize));
|
|
1022
2244
|
if (computedHash.length < pke.hashSize || verifierHashValue.length < pke.hashSize) return null;
|
|
1023
2245
|
let difference = 0;
|
|
1024
|
-
for (let
|
|
2246
|
+
for (let i2 = 0; i2 < pke.hashSize; i2++) difference |= verifierHashValue[i2] ^ computedHash[i2];
|
|
1025
2247
|
if (difference !== 0) return null;
|
|
1026
2248
|
const decryptedKey = await aesCbcDecryptRaw(
|
|
1027
2249
|
await blockKey(BLOCK_KEYS.encryptedKeyValue),
|
|
@@ -1042,8 +2264,8 @@ async function verifyStandardPassword(info, password) {
|
|
|
1042
2264
|
const computedHash = await hash("SHA-1", decryptedVerifier);
|
|
1043
2265
|
const hashSize = info.verifier.verifierHashSize;
|
|
1044
2266
|
let match = true;
|
|
1045
|
-
for (let
|
|
1046
|
-
if (computedHash[
|
|
2267
|
+
for (let i2 = 0; i2 < Math.min(hashSize, 20); i2++) {
|
|
2268
|
+
if (computedHash[i2] !== decryptedHash[i2]) {
|
|
1047
2269
|
match = false;
|
|
1048
2270
|
break;
|
|
1049
2271
|
}
|
|
@@ -1084,8 +2306,8 @@ async function verifyAgileDataIntegrity(info, key, encryptedPackage) {
|
|
|
1084
2306
|
if (computedHmac.length < keyData.hashSize) {
|
|
1085
2307
|
match = false;
|
|
1086
2308
|
} else {
|
|
1087
|
-
for (let
|
|
1088
|
-
if (computedHmac[
|
|
2309
|
+
for (let i2 = 0; i2 < keyData.hashSize; i2++) {
|
|
2310
|
+
if (computedHmac[i2] !== expectedHmac[i2]) {
|
|
1089
2311
|
match = false;
|
|
1090
2312
|
break;
|
|
1091
2313
|
}
|
|
@@ -1179,8 +2401,8 @@ function compareDirEntryNames(a, b) {
|
|
|
1179
2401
|
if (a.length !== b.length) {
|
|
1180
2402
|
return a.length - b.length;
|
|
1181
2403
|
}
|
|
1182
|
-
for (let
|
|
1183
|
-
const diff = ua.charCodeAt(
|
|
2404
|
+
for (let i2 = 0; i2 < ua.length; i2++) {
|
|
2405
|
+
const diff = ua.charCodeAt(i2) - ub.charCodeAt(i2);
|
|
1184
2406
|
if (diff !== 0) {
|
|
1185
2407
|
return diff;
|
|
1186
2408
|
}
|
|
@@ -1189,9 +2411,9 @@ function compareDirEntryNames(a, b) {
|
|
|
1189
2411
|
}
|
|
1190
2412
|
function encodeName(name) {
|
|
1191
2413
|
const bytes = new Uint8Array((name.length + 1) * 2);
|
|
1192
|
-
for (let
|
|
1193
|
-
bytes[
|
|
1194
|
-
bytes[
|
|
2414
|
+
for (let i2 = 0; i2 < name.length; i2++) {
|
|
2415
|
+
bytes[i2 * 2] = name.charCodeAt(i2) & 255;
|
|
2416
|
+
bytes[i2 * 2 + 1] = name.charCodeAt(i2) >> 8 & 255;
|
|
1195
2417
|
}
|
|
1196
2418
|
return bytes;
|
|
1197
2419
|
}
|
|
@@ -1214,21 +2436,21 @@ function buildDirectoryTree(entryCount) {
|
|
|
1214
2436
|
return { root: build(1, entryCount - 1, 0), links };
|
|
1215
2437
|
}
|
|
1216
2438
|
function writeFatChain(fat, chain2) {
|
|
1217
|
-
for (let
|
|
1218
|
-
fat[chain2.sectors[
|
|
2439
|
+
for (let i2 = 0; i2 < chain2.sectors.length; i2++) {
|
|
2440
|
+
fat[chain2.sectors[i2]] = i2 < chain2.sectors.length - 1 ? chain2.sectors[i2 + 1] : ENDOFCHAIN;
|
|
1219
2441
|
}
|
|
1220
2442
|
}
|
|
1221
2443
|
function writeFatRun(fat, firstSector, count) {
|
|
1222
|
-
for (let
|
|
1223
|
-
const sector = firstSector +
|
|
1224
|
-
fat[sector] =
|
|
2444
|
+
for (let i2 = 0; i2 < count; i2++) {
|
|
2445
|
+
const sector = firstSector + i2;
|
|
2446
|
+
fat[sector] = i2 < count - 1 ? sector + 1 : ENDOFCHAIN;
|
|
1225
2447
|
}
|
|
1226
2448
|
}
|
|
1227
2449
|
function writeInt32Sectors(outBytes, int32Data, firstSector, numSectors, sectorSize) {
|
|
1228
2450
|
const entriesPerSector = sectorSize / 4;
|
|
1229
|
-
for (let
|
|
1230
|
-
const sectorOff = (firstSector +
|
|
1231
|
-
const start =
|
|
2451
|
+
for (let i2 = 0; i2 < numSectors; i2++) {
|
|
2452
|
+
const sectorOff = (firstSector + i2 + 1) * sectorSize;
|
|
2453
|
+
const start = i2 * entriesPerSector;
|
|
1232
2454
|
const end = start + entriesPerSector;
|
|
1233
2455
|
const chunk = int32Data.subarray(start, end);
|
|
1234
2456
|
const chunkBytes = new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
@@ -1254,11 +2476,11 @@ function writeHeader(outView, outBytes, params) {
|
|
|
1254
2476
|
const numDIFATSectors = params.numDIFATSectors ?? 0;
|
|
1255
2477
|
outView.setUint32(68, numDIFATSectors > 0 ? params.firstDIFATSector ?? ENDOFCHAIN : ENDOFCHAIN, true);
|
|
1256
2478
|
outView.setUint32(72, numDIFATSectors, true);
|
|
1257
|
-
for (let
|
|
1258
|
-
if (
|
|
1259
|
-
outView.setUint32(76 +
|
|
2479
|
+
for (let i2 = 0; i2 < HEADER_DIFAT_ENTRIES; i2++) {
|
|
2480
|
+
if (i2 < params.numFATSectors) {
|
|
2481
|
+
outView.setUint32(76 + i2 * 4, params.firstFATSector + i2, true);
|
|
1260
2482
|
} else {
|
|
1261
|
-
outView.setUint32(76 +
|
|
2483
|
+
outView.setUint32(76 + i2 * 4, FREESECT, true);
|
|
1262
2484
|
}
|
|
1263
2485
|
}
|
|
1264
2486
|
}
|
|
@@ -1295,24 +2517,24 @@ function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
|
|
|
1295
2517
|
const dirData = new Uint8Array(numDirSectors * sectorSize);
|
|
1296
2518
|
const dirView = new DataView(dirData.buffer);
|
|
1297
2519
|
const tree = buildDirectoryTree(dirEntries.length);
|
|
1298
|
-
for (let
|
|
1299
|
-
const entry = dirEntries[
|
|
1300
|
-
const entryOffset =
|
|
2520
|
+
for (let i2 = 0; i2 < dirEntries.length; i2++) {
|
|
2521
|
+
const entry = dirEntries[i2];
|
|
2522
|
+
const entryOffset = i2 * DIR_ENTRY_SIZE;
|
|
1301
2523
|
const nameBytes = encodeName(entry.name);
|
|
1302
2524
|
dirData.set(nameBytes.subarray(0, Math.min(nameBytes.length, 64)), entryOffset);
|
|
1303
2525
|
dirView.setUint16(entryOffset + 64, Math.min((entry.name.length + 1) * 2, 64), true);
|
|
1304
2526
|
dirData[entryOffset + 66] = entry.type;
|
|
1305
|
-
dirData[entryOffset + 67] =
|
|
2527
|
+
dirData[entryOffset + 67] = i2 === 0 ? 1 : tree.links.get(i2).color;
|
|
1306
2528
|
if (entry.clsid) {
|
|
1307
2529
|
dirData.set(entry.clsid.subarray(0, 16), entryOffset + 80);
|
|
1308
2530
|
}
|
|
1309
|
-
if (
|
|
2531
|
+
if (i2 === 0) {
|
|
1310
2532
|
dirView.setUint32(entryOffset + 68, 4294967295, true);
|
|
1311
2533
|
dirView.setUint32(entryOffset + 72, 4294967295, true);
|
|
1312
2534
|
dirView.setUint32(entryOffset + 76, tree.root, true);
|
|
1313
2535
|
} else {
|
|
1314
|
-
dirView.setUint32(entryOffset + 68, tree.links.get(
|
|
1315
|
-
dirView.setUint32(entryOffset + 72, tree.links.get(
|
|
2536
|
+
dirView.setUint32(entryOffset + 68, tree.links.get(i2).left, true);
|
|
2537
|
+
dirView.setUint32(entryOffset + 72, tree.links.get(i2).right, true);
|
|
1316
2538
|
dirView.setUint32(entryOffset + 76, 4294967295, true);
|
|
1317
2539
|
}
|
|
1318
2540
|
dirView.setUint32(entryOffset + 116, entry.startSector, true);
|
|
@@ -1321,9 +2543,9 @@ function serializeDirectoryEntries(dirEntries, numDirSectors, sectorSize) {
|
|
|
1321
2543
|
return dirData;
|
|
1322
2544
|
}
|
|
1323
2545
|
function writeStreamSectors(outBytes, streamData, chain2, sectorSize) {
|
|
1324
|
-
for (let
|
|
1325
|
-
const sectorOffset = (chain2.sectors[
|
|
1326
|
-
const srcOffset =
|
|
2546
|
+
for (let i2 = 0; i2 < chain2.sectors.length; i2++) {
|
|
2547
|
+
const sectorOffset = (chain2.sectors[i2] + 1) * sectorSize;
|
|
2548
|
+
const srcOffset = i2 * sectorSize;
|
|
1327
2549
|
const srcEnd = Math.min(srcOffset + sectorSize, streamData.length);
|
|
1328
2550
|
outBytes.set(streamData.subarray(srcOffset, srcEnd), sectorOffset);
|
|
1329
2551
|
}
|
|
@@ -1334,15 +2556,15 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1334
2556
|
const sectorSize = 512;
|
|
1335
2557
|
const miniSectorSize = 64;
|
|
1336
2558
|
const names = [...streams2.keys()].sort(compareDirEntryNames);
|
|
1337
|
-
for (let
|
|
1338
|
-
const name = names[
|
|
2559
|
+
for (let i2 = 0; i2 < names.length; i2++) {
|
|
2560
|
+
const name = names[i2];
|
|
1339
2561
|
if (name.toUpperCase().length !== name.length) {
|
|
1340
2562
|
throw new Error("CFB stream names with expanding uppercase mappings are unsupported");
|
|
1341
2563
|
}
|
|
1342
2564
|
if (!name.length || name.length > 31 || /[\x00\\/:!]/.test(name)) {
|
|
1343
2565
|
throw new Error("CFB stream names must be 1-31 UTF-16 code units without NUL, \\, /, :, or !");
|
|
1344
2566
|
}
|
|
1345
|
-
if (
|
|
2567
|
+
if (i2 > 0 && compareDirEntryNames(names[i2 - 1], name) === 0) {
|
|
1346
2568
|
throw new Error("Duplicate CFB stream names");
|
|
1347
2569
|
}
|
|
1348
2570
|
}
|
|
@@ -1360,7 +2582,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1360
2582
|
for (const stream of regularStreams) {
|
|
1361
2583
|
const numSectors = Math.ceil(stream.data.length / sectorSize);
|
|
1362
2584
|
const sectors = [];
|
|
1363
|
-
for (let
|
|
2585
|
+
for (let i2 = 0; i2 < numSectors; i2++) {
|
|
1364
2586
|
sectors.push(nextSector++);
|
|
1365
2587
|
}
|
|
1366
2588
|
fatChains.set(stream.name, { start: sectors[0] ?? ENDOFCHAIN, sectors });
|
|
@@ -1378,9 +2600,9 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1378
2600
|
for (const stream of miniStreams) {
|
|
1379
2601
|
const numMiniSectors = Math.ceil(stream.data.length / miniSectorSize);
|
|
1380
2602
|
const miniSectors = [];
|
|
1381
|
-
for (let
|
|
2603
|
+
for (let i2 = 0; i2 < numMiniSectors; i2++) {
|
|
1382
2604
|
miniSectors.push(nextMiniSector++);
|
|
1383
|
-
const srcOffset =
|
|
2605
|
+
const srcOffset = i2 * miniSectorSize;
|
|
1384
2606
|
const srcEnd = Math.min(srcOffset + miniSectorSize, stream.data.length);
|
|
1385
2607
|
miniStreamContainer.set(stream.data.subarray(srcOffset, srcEnd), miniOffset);
|
|
1386
2608
|
miniOffset += miniSectorSize;
|
|
@@ -1396,7 +2618,7 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1396
2618
|
if (miniStreamContainer.length > 0) {
|
|
1397
2619
|
const numSectors = Math.ceil(miniStreamContainer.length / sectorSize);
|
|
1398
2620
|
rootStartSector = nextSector;
|
|
1399
|
-
for (let
|
|
2621
|
+
for (let i2 = 0; i2 < numSectors; i2++) {
|
|
1400
2622
|
rootSectors.push(nextSector++);
|
|
1401
2623
|
}
|
|
1402
2624
|
}
|
|
@@ -1455,11 +2677,11 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1455
2677
|
if (numMiniFATSectors > 0) {
|
|
1456
2678
|
writeFatRun(fat, firstMiniFATSector, numMiniFATSectors);
|
|
1457
2679
|
}
|
|
1458
|
-
for (let
|
|
1459
|
-
fat[firstFATSector +
|
|
2680
|
+
for (let i2 = 0; i2 < numFATSectors; i2++) {
|
|
2681
|
+
fat[firstFATSector + i2] = FATSECT;
|
|
1460
2682
|
}
|
|
1461
|
-
for (let
|
|
1462
|
-
fat[firstDIFATSector +
|
|
2683
|
+
for (let i2 = 0; i2 < numDIFATSectors; i2++) {
|
|
2684
|
+
fat[firstDIFATSector + i2] = DIFSECT;
|
|
1463
2685
|
}
|
|
1464
2686
|
let miniFat;
|
|
1465
2687
|
if (miniStreams.length > 0) {
|
|
@@ -1490,9 +2712,9 @@ function buildOle2(streams2, rootClsid, miniStreamCutoff = 4096) {
|
|
|
1490
2712
|
writeStreamSectors(outBytes, miniStreamContainer, { start: rootSectors[0] ?? 0, sectors: rootSectors }, sectorSize);
|
|
1491
2713
|
}
|
|
1492
2714
|
const dirData = serializeDirectoryEntries(sortedDirEntries, numDirSectors, sectorSize);
|
|
1493
|
-
for (let
|
|
1494
|
-
const sectorOff = (firstDirSector +
|
|
1495
|
-
outBytes.set(dirData.subarray(
|
|
2715
|
+
for (let i2 = 0; i2 < numDirSectors; i2++) {
|
|
2716
|
+
const sectorOff = (firstDirSector + i2 + 1) * sectorSize;
|
|
2717
|
+
outBytes.set(dirData.subarray(i2 * sectorSize, (i2 + 1) * sectorSize), sectorOff);
|
|
1496
2718
|
}
|
|
1497
2719
|
if (miniFat) {
|
|
1498
2720
|
writeInt32Sectors(outBytes, miniFat, firstMiniFATSector, numMiniFATSectors, sectorSize);
|
|
@@ -1545,10 +2767,10 @@ function buildStandardEncryptionInfoStream(keyBits, salt, encryptedVerifier, enc
|
|
|
1545
2767
|
);
|
|
1546
2768
|
}
|
|
1547
2769
|
const cspNameBytes = new Uint8Array((STANDARD_CSP_NAME.length + 1) * 2);
|
|
1548
|
-
for (let
|
|
1549
|
-
const code = STANDARD_CSP_NAME.charCodeAt(
|
|
1550
|
-
cspNameBytes[
|
|
1551
|
-
cspNameBytes[
|
|
2770
|
+
for (let i2 = 0; i2 < STANDARD_CSP_NAME.length; i2++) {
|
|
2771
|
+
const code = STANDARD_CSP_NAME.charCodeAt(i2);
|
|
2772
|
+
cspNameBytes[i2 * 2] = code & 255;
|
|
2773
|
+
cspNameBytes[i2 * 2 + 1] = code >> 8 & 255;
|
|
1552
2774
|
}
|
|
1553
2775
|
const headerFixedSize = 32;
|
|
1554
2776
|
const headerSize = headerFixedSize + cspNameBytes.length;
|
|
@@ -1560,16 +2782,16 @@ function buildStandardEncryptionInfoStream(keyBits, salt, encryptedVerifier, enc
|
|
|
1560
2782
|
view.setUint16(2, 2, true);
|
|
1561
2783
|
view.setUint32(4, STANDARD_FLAGS, true);
|
|
1562
2784
|
view.setUint32(8, headerSize, true);
|
|
1563
|
-
const
|
|
1564
|
-
view.setUint32(
|
|
1565
|
-
view.setUint32(
|
|
1566
|
-
view.setUint32(
|
|
1567
|
-
view.setUint32(
|
|
1568
|
-
view.setUint32(
|
|
1569
|
-
view.setUint32(
|
|
1570
|
-
view.setUint32(
|
|
1571
|
-
view.setUint32(
|
|
1572
|
-
data.set(cspNameBytes,
|
|
2785
|
+
const h2 = 12;
|
|
2786
|
+
view.setUint32(h2, STANDARD_FLAGS, true);
|
|
2787
|
+
view.setUint32(h2 + 4, 0, true);
|
|
2788
|
+
view.setUint32(h2 + 8, algId, true);
|
|
2789
|
+
view.setUint32(h2 + 12, STANDARD_ALG_ID_HASH_SHA1, true);
|
|
2790
|
+
view.setUint32(h2 + 16, keyBits, true);
|
|
2791
|
+
view.setUint32(h2 + 20, STANDARD_PROVIDER_TYPE_RSA_AES, true);
|
|
2792
|
+
view.setUint32(h2 + 24, 0, true);
|
|
2793
|
+
view.setUint32(h2 + 28, 0, true);
|
|
2794
|
+
data.set(cspNameBytes, h2 + 32);
|
|
1573
2795
|
const v = 12 + headerSize;
|
|
1574
2796
|
view.setUint32(v, 16, true);
|
|
1575
2797
|
data.set(salt.subarray(0, 16), v + 4);
|
|
@@ -1726,8 +2948,8 @@ function parseStandardEncryptionInfo(data) {
|
|
|
1726
2948
|
const providerType = view.getUint32(headerOffset + 20, true);
|
|
1727
2949
|
let cspName = "";
|
|
1728
2950
|
const cspEnd = headerOffset + headerSize;
|
|
1729
|
-
for (let
|
|
1730
|
-
const ch = view.getUint16(
|
|
2951
|
+
for (let i2 = headerOffset + 32; i2 < cspEnd - 1; i2 += 2) {
|
|
2952
|
+
const ch = view.getUint16(i2, true);
|
|
1731
2953
|
if (ch === 0) break;
|
|
1732
2954
|
cspName += String.fromCharCode(ch);
|
|
1733
2955
|
}
|
|
@@ -2208,7 +3430,7 @@ function setAttribute(element, local, value) {
|
|
|
2208
3430
|
}
|
|
2209
3431
|
function paraIdFor(id, index) {
|
|
2210
3432
|
let hash2 = index + 1 >>> 0;
|
|
2211
|
-
for (let
|
|
3433
|
+
for (let i2 = 0; i2 < id.length; i2++) hash2 = Math.imul(hash2, 31) + id.charCodeAt(i2) >>> 0;
|
|
2212
3434
|
return hash2.toString(16).padStart(8, "0").toUpperCase();
|
|
2213
3435
|
}
|
|
2214
3436
|
function buildCommentsDocument(comments) {
|
|
@@ -2399,6 +3621,27 @@ function expectDefined(value, context) {
|
|
|
2399
3621
|
return value;
|
|
2400
3622
|
}
|
|
2401
3623
|
|
|
3624
|
+
// color/color-primitives.ts
|
|
3625
|
+
function toHex(value) {
|
|
3626
|
+
return Math.min(255, Math.max(0, Math.round(value))).toString(16).padStart(2, "0").toUpperCase();
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
// drawingml/theme-model.ts
|
|
3630
|
+
var THEME_COLOR_SLOTS = [
|
|
3631
|
+
"dk1",
|
|
3632
|
+
"lt1",
|
|
3633
|
+
"dk2",
|
|
3634
|
+
"lt2",
|
|
3635
|
+
"accent1",
|
|
3636
|
+
"accent2",
|
|
3637
|
+
"accent3",
|
|
3638
|
+
"accent4",
|
|
3639
|
+
"accent5",
|
|
3640
|
+
"accent6",
|
|
3641
|
+
"hlink",
|
|
3642
|
+
"folHlink"
|
|
3643
|
+
];
|
|
3644
|
+
|
|
2402
3645
|
// docx/generated/wml-simple-types.ts
|
|
2403
3646
|
var ST_HighlightColor = ["black", "blue", "cyan", "green", "magenta", "red", "yellow", "white", "darkBlue", "darkCyan", "darkGreen", "darkMagenta", "darkRed", "darkYellow", "darkGray", "lightGray", "none"];
|
|
2404
3647
|
function isStHighlightColor(value) {
|
|
@@ -2485,9 +3728,6 @@ function isStRelFromV(value) {
|
|
|
2485
3728
|
function isThemeColorToken(value) {
|
|
2486
3729
|
return isStThemeColor(value);
|
|
2487
3730
|
}
|
|
2488
|
-
function toHex(value) {
|
|
2489
|
-
return Math.min(255, Math.max(0, Math.round(value))).toString(16).padStart(2, "0").toUpperCase();
|
|
2490
|
-
}
|
|
2491
3731
|
function fractionToThemeByte(fraction) {
|
|
2492
3732
|
return toHex(Math.round(Math.min(1, Math.max(0, fraction)) * 255));
|
|
2493
3733
|
}
|
|
@@ -4554,9 +5794,9 @@ function buildWatermarkRun(doc, spec, uniqueId) {
|
|
|
4554
5794
|
type.setAttribute("path", "m@7,l@8,m@5,21600l@6,21600e");
|
|
4555
5795
|
const formulas = v("formulas");
|
|
4556
5796
|
for (const eqn of FORMULAS) {
|
|
4557
|
-
const
|
|
4558
|
-
|
|
4559
|
-
formulas.appendChild(
|
|
5797
|
+
const f6 = v("f");
|
|
5798
|
+
f6.setAttribute("eqn", eqn);
|
|
5799
|
+
formulas.appendChild(f6);
|
|
4560
5800
|
}
|
|
4561
5801
|
const path = v("path");
|
|
4562
5802
|
path.setAttribute("textpathok", "t");
|
|
@@ -4901,7 +6141,7 @@ var DIAGRAM_RELATIONSHIP_TYPES = {
|
|
|
4901
6141
|
drawing: RELATIONSHIP_TYPES.diagramDrawing
|
|
4902
6142
|
};
|
|
4903
6143
|
|
|
4904
|
-
//
|
|
6144
|
+
// drawingml/dom.ts
|
|
4905
6145
|
function attributeReader(element) {
|
|
4906
6146
|
return (name) => {
|
|
4907
6147
|
if (!element) return void 0;
|
|
@@ -5057,7 +6297,7 @@ function parseDiagramDataModel(source, part) {
|
|
|
5057
6297
|
};
|
|
5058
6298
|
}
|
|
5059
6299
|
|
|
5060
|
-
//
|
|
6300
|
+
// drawingml/drawing-color.ts
|
|
5061
6301
|
var COLOR_ELEMENTS = {
|
|
5062
6302
|
srgbClr: "srgb",
|
|
5063
6303
|
schemeClr: "scheme",
|
|
@@ -5196,7 +6436,7 @@ function parseDiagramLayoutSummary(source) {
|
|
|
5196
6436
|
};
|
|
5197
6437
|
}
|
|
5198
6438
|
|
|
5199
|
-
//
|
|
6439
|
+
// drawingml/drawing-fill.ts
|
|
5200
6440
|
var FILL_ELEMENTS = /* @__PURE__ */ new Set([
|
|
5201
6441
|
"noFill",
|
|
5202
6442
|
"solidFill",
|
|
@@ -5288,7 +6528,7 @@ function parseDrawingLine(ln) {
|
|
|
5288
6528
|
return line;
|
|
5289
6529
|
}
|
|
5290
6530
|
|
|
5291
|
-
//
|
|
6531
|
+
// drawingml/drawing-text.ts
|
|
5292
6532
|
function parseSpacing(parent) {
|
|
5293
6533
|
for (const [name, unit, divisor] of [
|
|
5294
6534
|
["spcPts", "points", 100],
|
|
@@ -5367,7 +6607,7 @@ function parseDrawingTextBody(body) {
|
|
|
5367
6607
|
return result;
|
|
5368
6608
|
}
|
|
5369
6609
|
|
|
5370
|
-
//
|
|
6610
|
+
// drawingml/drawing-geometry.ts
|
|
5371
6611
|
var int = (element, name) => Number.parseInt(element?.getAttribute(name) ?? "", 10);
|
|
5372
6612
|
function parseFrame(container2) {
|
|
5373
6613
|
const off = first(container2, "off", NS.a);
|
|
@@ -5512,12 +6752,12 @@ function groupTransform(group, parent) {
|
|
|
5512
6752
|
}
|
|
5513
6753
|
function parseShape(sp, index, group, issues) {
|
|
5514
6754
|
const spPr = first(sp, "spPr", NS.dsp);
|
|
5515
|
-
const
|
|
5516
|
-
if (!
|
|
6755
|
+
const transform6 = parseTransform(first(spPr, "xfrm", NS.a));
|
|
6756
|
+
if (!transform6) return void 0;
|
|
5517
6757
|
const modelId = stringAttribute(sp, "modelId") ?? stringAttribute(first(first(sp, "nvSpPr", NS.dsp), "cNvPr", NS.dsp), "id") ?? `dsp-${index}`;
|
|
5518
6758
|
const { geometry, adjustments, paths, issue } = parseDrawingGeometry(spPr);
|
|
5519
6759
|
if (issue) issues.push({ code: issue, message: `Shape ${modelId}: ${issue}.` });
|
|
5520
|
-
const frame = applyGroup(
|
|
6760
|
+
const frame = applyGroup(transform6.frame, group);
|
|
5521
6761
|
if ((frame.width <= 0 || frame.height <= 0) && geometry !== "line") return void 0;
|
|
5522
6762
|
const shape = {
|
|
5523
6763
|
modelId,
|
|
@@ -5525,9 +6765,9 @@ function parseShape(sp, index, group, issues) {
|
|
|
5525
6765
|
geometry,
|
|
5526
6766
|
has3d: Boolean(first(spPr, "scene3d", NS.a) || first(spPr, "sp3d", NS.a))
|
|
5527
6767
|
};
|
|
5528
|
-
if (
|
|
5529
|
-
if (
|
|
5530
|
-
if (
|
|
6768
|
+
if (transform6.rotation !== void 0) shape.rotation = transform6.rotation;
|
|
6769
|
+
if (transform6.flipHorizontal) shape.flipHorizontal = true;
|
|
6770
|
+
if (transform6.flipVertical) shape.flipVertical = true;
|
|
5531
6771
|
if (adjustments) shape.adjustments = adjustments;
|
|
5532
6772
|
if (paths) shape.paths = paths;
|
|
5533
6773
|
const fill = parseDrawingFill(spPr);
|
|
@@ -6169,6 +7409,23 @@ function parseRunPropertiesSnapshot(xml) {
|
|
|
6169
7409
|
return parsePropertiesSnapshot(xml, "rPr");
|
|
6170
7410
|
}
|
|
6171
7411
|
|
|
7412
|
+
// docx/field-flags.ts
|
|
7413
|
+
function parseFieldFlags(element) {
|
|
7414
|
+
const locked = onOffAttribute(element, "fldLock");
|
|
7415
|
+
const dirty = onOffAttribute(element, "dirty");
|
|
7416
|
+
if (locked === void 0 && dirty === void 0) return void 0;
|
|
7417
|
+
return { ...locked !== void 0 && { locked }, ...dirty !== void 0 && { dirty } };
|
|
7418
|
+
}
|
|
7419
|
+
function writeFieldFlags(element, flags) {
|
|
7420
|
+
for (const [name, value] of [
|
|
7421
|
+
["fldLock", flags?.locked],
|
|
7422
|
+
["dirty", flags?.dirty]
|
|
7423
|
+
]) {
|
|
7424
|
+
if (value === void 0) element.removeAttributeNS(WORD_NS, name);
|
|
7425
|
+
else element.setAttributeNS(WORD_NS, `w:${name}`, value ? "true" : "false");
|
|
7426
|
+
}
|
|
7427
|
+
}
|
|
7428
|
+
|
|
6172
7429
|
// docx/write-run.ts
|
|
6173
7430
|
function setAttribute6(element, local, value) {
|
|
6174
7431
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
@@ -6354,6 +7611,7 @@ function createRun(doc, run, base, old, allocator) {
|
|
|
6354
7611
|
if (run.fieldChar) {
|
|
6355
7612
|
const marker = makeW(doc, "fldChar");
|
|
6356
7613
|
setAttribute6(marker, "fldCharType", run.fieldChar);
|
|
7614
|
+
writeFieldFlags(marker, run.fieldFlags);
|
|
6357
7615
|
node.appendChild(marker);
|
|
6358
7616
|
return node;
|
|
6359
7617
|
}
|
|
@@ -6434,6 +7692,11 @@ function takeSimpleFieldCommentEdges(doc, runs, start, end, opens, closes) {
|
|
|
6434
7692
|
after: take(closes, end - 1).reverse().flatMap((edge) => rangeEndNodes(doc, edge))
|
|
6435
7693
|
};
|
|
6436
7694
|
}
|
|
7695
|
+
|
|
7696
|
+
// docx/field-lock.ts
|
|
7697
|
+
function sameFieldFlags(a, b) {
|
|
7698
|
+
return a?.locked === b?.locked && a?.dirty === b?.dirty;
|
|
7699
|
+
}
|
|
6437
7700
|
var MATH_NAMESPACES = /* @__PURE__ */ new Set([
|
|
6438
7701
|
"http://schemas.openxmlformats.org/officeDocument/2006/math",
|
|
6439
7702
|
"http://purl.oclc.org/ooxml/officeDocument/math"
|
|
@@ -6758,6 +8021,7 @@ function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
|
|
|
6758
8021
|
container2 = makeW(doc, "fldSimple");
|
|
6759
8022
|
setW6(container2, "instr", ` ${group.instr} `);
|
|
6760
8023
|
}
|
|
8024
|
+
if (group.kind === "simpleField") writeFieldFlags(container2, runAt(start).fieldFlags);
|
|
6761
8025
|
const edges = group.kind === "simpleField" ? takeSimpleFieldCommentEdges(doc, runs, start, index, opens, closes) : { before: [], after: [] };
|
|
6762
8026
|
for (let item = start; item < index; item++)
|
|
6763
8027
|
for (const node of nodesFor(item)) container2.appendChild(node);
|
|
@@ -6768,13 +8032,18 @@ function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
|
|
|
6768
8032
|
function containerGroup(run) {
|
|
6769
8033
|
if (run.link) return { kind: "link", link: run.link };
|
|
6770
8034
|
if (run.field?.simple)
|
|
6771
|
-
return {
|
|
8035
|
+
return {
|
|
8036
|
+
kind: "simpleField",
|
|
8037
|
+
instr: run.field.instr,
|
|
8038
|
+
instanceId: run.fieldInstanceId,
|
|
8039
|
+
fieldFlags: run.fieldFlags
|
|
8040
|
+
};
|
|
6772
8041
|
return void 0;
|
|
6773
8042
|
}
|
|
6774
8043
|
function sameGroup(a, b) {
|
|
6775
8044
|
if (!a || !b) return a === b;
|
|
6776
8045
|
if (a.kind === "link" && b.kind === "link") return sameLink(a.link, b.link);
|
|
6777
|
-
return a.kind === "simpleField" && b.kind === "simpleField" && a.instr === b.instr && a.instanceId === b.instanceId;
|
|
8046
|
+
return a.kind === "simpleField" && b.kind === "simpleField" && a.instr === b.instr && a.instanceId === b.instanceId && sameFieldFlags(a.fieldFlags, b.fieldFlags);
|
|
6778
8047
|
}
|
|
6779
8048
|
|
|
6780
8049
|
// docx/paragraph-styles.ts
|
|
@@ -7206,8 +8475,8 @@ function replaceSlots(doc, parent, oldNodes, nextNodes, insertionAnchor = null)
|
|
|
7206
8475
|
return marker;
|
|
7207
8476
|
});
|
|
7208
8477
|
const shared = Math.min(placeholders.length, nextNodes.length);
|
|
7209
|
-
for (const [
|
|
7210
|
-
const next = nextNodes[
|
|
8478
|
+
for (const [i2, marker] of placeholders.slice(0, shared).entries()) {
|
|
8479
|
+
const next = nextNodes[i2];
|
|
7211
8480
|
if (next) parent.replaceChild(next, marker);
|
|
7212
8481
|
}
|
|
7213
8482
|
for (const marker of placeholders.slice(shared)) parent.removeChild(marker);
|
|
@@ -7815,6 +9084,217 @@ async function registerNumberingPart(zip) {
|
|
|
7815
9084
|
zip.file(relsPath, buildXml(relsDoc));
|
|
7816
9085
|
}
|
|
7817
9086
|
|
|
9087
|
+
// docx/numbering-parse.ts
|
|
9088
|
+
var integer2 = (value, fallback) => parseInteger(value) ?? fallback;
|
|
9089
|
+
var flag = (element) => onOffElement(element) === true;
|
|
9090
|
+
function byName(root, local) {
|
|
9091
|
+
return Array.from(root.getElementsByTagName("*")).filter(
|
|
9092
|
+
(node) => node.nodeType === 1 && named2(node, local)
|
|
9093
|
+
);
|
|
9094
|
+
}
|
|
9095
|
+
function parseMarkerFormat(rPr) {
|
|
9096
|
+
if (!rPr) return void 0;
|
|
9097
|
+
const format = {};
|
|
9098
|
+
const family = getW(first2(rPr, "rFonts"), "ascii");
|
|
9099
|
+
if (family) format.fontFamily = family;
|
|
9100
|
+
const size = parseInteger(getW(first2(rPr, "sz"), "val"));
|
|
9101
|
+
if (size !== void 0 && size > 0) format.fontSizeHalfPoints = size;
|
|
9102
|
+
if (onOffElement(first2(rPr, "b")) === true) format.bold = true;
|
|
9103
|
+
if (onOffElement(first2(rPr, "i")) === true) format.italic = true;
|
|
9104
|
+
const color = getW(first2(rPr, "color"), "val");
|
|
9105
|
+
if (color && /^[0-9a-f]{6}$/i.test(color)) format.color = `#${color.toLowerCase()}`;
|
|
9106
|
+
return Object.keys(format).length ? format : void 0;
|
|
9107
|
+
}
|
|
9108
|
+
function parseNumberingLevel(lvl) {
|
|
9109
|
+
const level = integer2(getW(lvl, "ilvl"), 0);
|
|
9110
|
+
const start = integer2(getW(first2(lvl, "start"), "val"), 1);
|
|
9111
|
+
const numFmt = enumValue(isStNumberFormat, getW(first2(lvl, "numFmt"), "val"), "w:numFmt") ?? "decimal";
|
|
9112
|
+
const lvlText = getW(first2(lvl, "lvlText"), "val") ?? "";
|
|
9113
|
+
const jc = getW(first2(lvl, "lvlJc"), "val");
|
|
9114
|
+
const ind = first2(first2(lvl, "pPr"), "ind");
|
|
9115
|
+
const suffRaw = getW(first2(lvl, "suff"), "val");
|
|
9116
|
+
const result = { level, start, numFmt, lvlText };
|
|
9117
|
+
if (!first2(lvl, "start")) result.startWasOmitted = true;
|
|
9118
|
+
const paragraphStyleId = getW(first2(lvl, "pStyle"), "val");
|
|
9119
|
+
if (paragraphStyleId) result.paragraphStyleId = paragraphStyleId;
|
|
9120
|
+
if (jc === "left" || jc === "center" || jc === "right") result.lvlJc = jc;
|
|
9121
|
+
const left = getW(ind, "left") ?? getW(ind, "start");
|
|
9122
|
+
if (left !== void 0) result.indentLeftTwips = parseSignedTwips(left) ?? signedTwips(0);
|
|
9123
|
+
const hanging = getW(ind, "hanging");
|
|
9124
|
+
if (hanging !== void 0) result.hangingTwips = parseTwips(hanging) ?? twips(0);
|
|
9125
|
+
const firstLine = getW(ind, "firstLine");
|
|
9126
|
+
if (firstLine !== void 0) result.firstLineTwips = parseTwips(firstLine) ?? twips(0);
|
|
9127
|
+
const tabs = first2(first2(lvl, "pPr"), "tabs");
|
|
9128
|
+
const tab = tabs ? children2(tabs, "tab").find((stop) => getW(stop, "val") !== "clear") : void 0;
|
|
9129
|
+
const tabPos = tab ? parseTwips(getW(tab, "pos")) : void 0;
|
|
9130
|
+
if (tabPos !== void 0) result.tabStopTwips = tabPos;
|
|
9131
|
+
if (flag(first2(lvl, "isLgl"))) result.isLgl = true;
|
|
9132
|
+
const restart = getW(first2(lvl, "lvlRestart"), "val");
|
|
9133
|
+
if (restart !== void 0) result.lvlRestart = integer2(restart, 0);
|
|
9134
|
+
const marker = parseMarkerFormat(first2(lvl, "rPr"));
|
|
9135
|
+
if (marker) result.markerFormat = marker;
|
|
9136
|
+
result.suffix = suffRaw === "space" ? "space" : suffRaw === "nothing" ? "none" : "tab";
|
|
9137
|
+
return result;
|
|
9138
|
+
}
|
|
9139
|
+
function parseAbstractNum(element) {
|
|
9140
|
+
const id = getW(element, "abstractNumId");
|
|
9141
|
+
if (!id) return void 0;
|
|
9142
|
+
const levels = {};
|
|
9143
|
+
for (const lvl of children2(element, "lvl")) {
|
|
9144
|
+
const parsed = parseNumberingLevel(lvl);
|
|
9145
|
+
levels[parsed.level] = parsed;
|
|
9146
|
+
}
|
|
9147
|
+
return { id, levels };
|
|
9148
|
+
}
|
|
9149
|
+
function parseNum(element) {
|
|
9150
|
+
const id = getW(element, "numId");
|
|
9151
|
+
if (!id) return void 0;
|
|
9152
|
+
const abstractNumId = getW(first2(element, "abstractNumId"), "val") ?? "";
|
|
9153
|
+
const levelOverrides = {};
|
|
9154
|
+
for (const override of children2(element, "lvlOverride")) {
|
|
9155
|
+
const level = integer2(getW(override, "ilvl"), 0);
|
|
9156
|
+
const entry = {};
|
|
9157
|
+
const startOverride = getW(first2(override, "startOverride"), "val");
|
|
9158
|
+
if (startOverride !== void 0) entry.startOverride = integer2(startOverride, 1);
|
|
9159
|
+
const lvl = first2(override, "lvl");
|
|
9160
|
+
if (lvl) entry.lvl = parseNumberingLevel(lvl);
|
|
9161
|
+
if (Object.keys(entry).length) levelOverrides[level] = entry;
|
|
9162
|
+
}
|
|
9163
|
+
return {
|
|
9164
|
+
id,
|
|
9165
|
+
abstractNumId,
|
|
9166
|
+
...Object.keys(levelOverrides).length ? { levelOverrides } : {}
|
|
9167
|
+
};
|
|
9168
|
+
}
|
|
9169
|
+
function parseNumberingCatalog(xml) {
|
|
9170
|
+
const document = parseXml2(xml);
|
|
9171
|
+
const root = document.documentElement;
|
|
9172
|
+
const abstractNums = {};
|
|
9173
|
+
const warnings = [];
|
|
9174
|
+
for (const element of byName(root, "abstractNum")) {
|
|
9175
|
+
const parsed = parseAbstractNum(element);
|
|
9176
|
+
if (!parsed) continue;
|
|
9177
|
+
abstractNums[parsed.id] = parsed;
|
|
9178
|
+
const link = getW(first2(element, "numStyleLink"), "val");
|
|
9179
|
+
if (link)
|
|
9180
|
+
warnings.push(
|
|
9181
|
+
`Numbering definition abstractNum ${parsed.id} links to style "${link}"; style-linked numbering levels are not resolved.`
|
|
9182
|
+
);
|
|
9183
|
+
if (byName(element, "lvlPicBulletId").length)
|
|
9184
|
+
warnings.push(
|
|
9185
|
+
`Numbering definition abstractNum ${parsed.id} uses a picture bullet; picture bullets are not rendered.`
|
|
9186
|
+
);
|
|
9187
|
+
}
|
|
9188
|
+
const nums = {};
|
|
9189
|
+
for (const element of byName(root, "num")) {
|
|
9190
|
+
const parsed = parseNum(element);
|
|
9191
|
+
if (parsed) nums[parsed.id] = parsed;
|
|
9192
|
+
}
|
|
9193
|
+
return { abstractNums, nums, warnings: [...new Set(warnings)] };
|
|
9194
|
+
}
|
|
9195
|
+
function resolveNumberingLevel(catalog, numId, level) {
|
|
9196
|
+
const num = catalog.nums[numId];
|
|
9197
|
+
if (!num) return void 0;
|
|
9198
|
+
const override = num.levelOverrides?.[level];
|
|
9199
|
+
const sourceAbstract = catalog.abstractNums[num.abstractNumId]?.levels[level];
|
|
9200
|
+
const abstract = sourceAbstract?.startWasOmitted && sourceAbstract.start === 1 ? { ...sourceAbstract, start: 0 } : sourceAbstract;
|
|
9201
|
+
let base = override?.lvl ?? abstract;
|
|
9202
|
+
if (!base) return void 0;
|
|
9203
|
+
if (override?.lvl) {
|
|
9204
|
+
const { lvlRestart: _ignored, ...properties } = base;
|
|
9205
|
+
base = {
|
|
9206
|
+
...properties,
|
|
9207
|
+
...abstract?.lvlRestart !== void 0 ? { lvlRestart: abstract.lvlRestart } : {}
|
|
9208
|
+
};
|
|
9209
|
+
}
|
|
9210
|
+
let start = override?.startOverride ?? base.start;
|
|
9211
|
+
if (override?.lvl) {
|
|
9212
|
+
if (abstract?.lvlRestart === 0 && override.startOverride === void 0) start = abstract.start;
|
|
9213
|
+
else if (!override.lvl.startWasOmitted || override.lvl.start !== 1) start = override.lvl.start;
|
|
9214
|
+
else start = override.startOverride ?? 0;
|
|
9215
|
+
}
|
|
9216
|
+
return start !== base.start ? { ...base, start } : base;
|
|
9217
|
+
}
|
|
9218
|
+
|
|
9219
|
+
// docx/numbering-start-edit.ts
|
|
9220
|
+
function assertListStartValue(level, start) {
|
|
9221
|
+
if (!Number.isInteger(level) || level < 0 || level > 8)
|
|
9222
|
+
throw new Error("List level must be an integer from 0 through 8.");
|
|
9223
|
+
if (!Number.isInteger(start) || start < 0 || start > 2147483647)
|
|
9224
|
+
throw new Error("List start must be an integer from 0 through 2147483647.");
|
|
9225
|
+
}
|
|
9226
|
+
|
|
9227
|
+
// docx/numbering-start-patch.ts
|
|
9228
|
+
function withoutStarts(num) {
|
|
9229
|
+
const { levelOverrides, ...properties } = num;
|
|
9230
|
+
const kept = {};
|
|
9231
|
+
for (const [level, override] of Object.entries(levelOverrides ?? {})) {
|
|
9232
|
+
const { startOverride: _start, ...rest } = override;
|
|
9233
|
+
if (Object.keys(rest).length) kept[level] = rest;
|
|
9234
|
+
}
|
|
9235
|
+
return { ...properties, ...Object.keys(kept).length ? { levelOverrides: kept } : {} };
|
|
9236
|
+
}
|
|
9237
|
+
function numberingStartChanges(prior, next) {
|
|
9238
|
+
const changes = [];
|
|
9239
|
+
for (const [id, previous] of Object.entries(prior?.nums ?? {})) {
|
|
9240
|
+
const current = next.nums[id];
|
|
9241
|
+
if (!current || JSON.stringify(withoutStarts(current)) !== JSON.stringify(withoutStarts(previous)))
|
|
9242
|
+
throw new Error(
|
|
9243
|
+
`Cannot edit numbering definition num "${id}" except its supported start overrides.`
|
|
9244
|
+
);
|
|
9245
|
+
for (const key of /* @__PURE__ */ new Set([
|
|
9246
|
+
...Object.keys(previous.levelOverrides ?? {}),
|
|
9247
|
+
...Object.keys(current.levelOverrides ?? {})
|
|
9248
|
+
])) {
|
|
9249
|
+
const level = Number(key);
|
|
9250
|
+
const old = previous.levelOverrides?.[level];
|
|
9251
|
+
const value = current.levelOverrides?.[level];
|
|
9252
|
+
if (old?.startOverride === value?.startOverride) continue;
|
|
9253
|
+
if (value?.startOverride === void 0)
|
|
9254
|
+
throw new Error("Removing a list start override is unsupported.");
|
|
9255
|
+
assertListStartValue(level, value.startOverride);
|
|
9256
|
+
if (String(level) !== key || !prior || !resolveNumberingLevel(prior, id, level))
|
|
9257
|
+
throw new Error("List instance or level does not exist.");
|
|
9258
|
+
if (old?.lvl || value.lvl)
|
|
9259
|
+
throw new Error("Changing starts with a full level override is unsupported.");
|
|
9260
|
+
changes.push({ numId: id, level, start: value.startOverride });
|
|
9261
|
+
}
|
|
9262
|
+
}
|
|
9263
|
+
return changes;
|
|
9264
|
+
}
|
|
9265
|
+
function patchNumberingStarts(doc, changes) {
|
|
9266
|
+
const sameNumber = (source, expected) => source !== void 0 && /^[+-]?\d+$/.test(source) && Number(source) === Number(expected);
|
|
9267
|
+
const prepared = changes.map((change) => {
|
|
9268
|
+
const nums = children2(doc.documentElement, "num").filter(
|
|
9269
|
+
(num2) => sameNumber(getW(num2, "numId"), change.numId)
|
|
9270
|
+
);
|
|
9271
|
+
if (nums.length !== 1 || getW(nums[0], "numId") !== change.numId)
|
|
9272
|
+
throw new Error("Cannot patch an ambiguous or missing source list instance.");
|
|
9273
|
+
const num = nums[0];
|
|
9274
|
+
const overrides = children2(num, "lvlOverride").filter(
|
|
9275
|
+
(node) => sameNumber(getW(node, "ilvl"), String(change.level))
|
|
9276
|
+
);
|
|
9277
|
+
if (overrides.length > 1) throw new Error("Cannot patch duplicate source level overrides.");
|
|
9278
|
+
const override = overrides[0];
|
|
9279
|
+
if (override && getW(override, "ilvl") !== String(change.level))
|
|
9280
|
+
throw new Error("Cannot patch a noncanonical source level override.");
|
|
9281
|
+
if (override && (children2(override, "lvl").length || children2(override, "startOverride").length > 1))
|
|
9282
|
+
throw new Error("Cannot patch a full or ambiguous source level override.");
|
|
9283
|
+
return { change, num, override };
|
|
9284
|
+
});
|
|
9285
|
+
for (const { change, num, override: existing } of prepared) {
|
|
9286
|
+
const override = existing ?? makeW(doc, "lvlOverride");
|
|
9287
|
+
if (!existing) {
|
|
9288
|
+
override.setAttributeNS(WORD_NS, "w:ilvl", String(change.level));
|
|
9289
|
+
const after = children2(num, "lvlOverride").at(-1) ?? children2(num, "abstractNumId")[0];
|
|
9290
|
+
num.insertBefore(override, after?.nextSibling ?? null);
|
|
9291
|
+
}
|
|
9292
|
+
const start = children2(override, "startOverride")[0] ?? makeW(doc, "startOverride");
|
|
9293
|
+
start.setAttributeNS(WORD_NS, "w:val", String(change.start));
|
|
9294
|
+
if (!start.parentNode) override.insertBefore(start, override.firstChild);
|
|
9295
|
+
}
|
|
9296
|
+
}
|
|
9297
|
+
|
|
7818
9298
|
// docx/numbering-package.ts
|
|
7819
9299
|
function setAttribute8(element, local, value) {
|
|
7820
9300
|
element.setAttributeNS(WORD_NS, `w:${local}`, value);
|
|
@@ -7919,17 +9399,14 @@ async function applyNumberingCatalog(zip, model, binding) {
|
|
|
7919
9399
|
throw new Error(
|
|
7920
9400
|
`Cannot edit numbering definition abstractNum "${id}"; the original numbering.xml is preserved unchanged.`
|
|
7921
9401
|
);
|
|
7922
|
-
|
|
7923
|
-
if (JSON.stringify(next.nums[id]) !== JSON.stringify(prior?.nums[id]))
|
|
7924
|
-
throw new Error(
|
|
7925
|
-
`Cannot edit numbering definition num "${id}"; the original numbering.xml is preserved unchanged.`
|
|
7926
|
-
);
|
|
9402
|
+
const startChanges = numberingStartChanges(prior, next);
|
|
7927
9403
|
const newAbstractIds = Object.keys(next.abstractNums).filter((id) => !prior?.abstractNums[id]);
|
|
7928
9404
|
const newNumIds = Object.keys(next.nums).filter((id) => !prior?.nums[id]);
|
|
7929
|
-
if (!newAbstractIds.length && !newNumIds.length) return;
|
|
9405
|
+
if (!newAbstractIds.length && !newNumIds.length && !startChanges.length) return;
|
|
7930
9406
|
const existingFile = zip.file("word/numbering.xml");
|
|
7931
9407
|
const doc = existingFile ? parseXml2(await existingFile.async("string")) : parseXml2(`<w:numbering xmlns:w="${WORD_NS}"/>`);
|
|
7932
9408
|
const root = doc.documentElement;
|
|
9409
|
+
patchNumberingStarts(doc, startChanges);
|
|
7933
9410
|
const cleanup = children2(root, "numIdMacAtCleanup")[0] ?? null;
|
|
7934
9411
|
const firstNum = children2(root, "num")[0] ?? cleanup;
|
|
7935
9412
|
for (const id of newAbstractIds) {
|
|
@@ -8942,23 +10419,31 @@ function createFieldTracker() {
|
|
|
8942
10419
|
const stack = [];
|
|
8943
10420
|
return (element, run) => {
|
|
8944
10421
|
let resultInstr;
|
|
10422
|
+
let resultLocked;
|
|
8945
10423
|
for (const child3 of Array.from(element.childNodes)) {
|
|
8946
10424
|
if (!isElement(child3)) continue;
|
|
8947
10425
|
if (named2(child3, "fldChar")) {
|
|
8948
10426
|
const type = getW(child3, "fldCharType");
|
|
8949
|
-
if (type === "begin")
|
|
8950
|
-
|
|
10427
|
+
if (type === "begin") {
|
|
10428
|
+
const locked = parseFieldFlags(child3)?.locked;
|
|
10429
|
+
stack.push({ instr: "", inResult: false, ...locked !== void 0 && { locked } });
|
|
10430
|
+
} else if (type === "separate") {
|
|
8951
10431
|
const top = stack.at(-1);
|
|
8952
10432
|
if (top) top.inResult = true;
|
|
8953
10433
|
} else if (type === "end") stack.pop();
|
|
8954
10434
|
} else {
|
|
8955
10435
|
const top = stack.at(-1);
|
|
8956
10436
|
if (named2(child3, "instrText") && top && !top.inResult) top.instr += textContent(child3);
|
|
8957
|
-
else if ((named2(child3, "t") || named2(child3, "delText")) && top?.inResult)
|
|
10437
|
+
else if ((named2(child3, "t") || named2(child3, "delText")) && top?.inResult) {
|
|
8958
10438
|
resultInstr = top.instr.trim();
|
|
10439
|
+
resultLocked = top.locked;
|
|
10440
|
+
}
|
|
8959
10441
|
}
|
|
8960
10442
|
}
|
|
8961
|
-
if (resultInstr)
|
|
10443
|
+
if (resultInstr) {
|
|
10444
|
+
run.field = { instr: resultInstr };
|
|
10445
|
+
if (resultLocked !== void 0) run.fieldFlags = { locked: resultLocked };
|
|
10446
|
+
}
|
|
8962
10447
|
return run;
|
|
8963
10448
|
};
|
|
8964
10449
|
}
|
|
@@ -8969,7 +10454,11 @@ function storyFieldResults(container2) {
|
|
|
8969
10454
|
if (named2(element, "fldSimple") || named2(element, "txbxContent")) return;
|
|
8970
10455
|
if (named2(element, "r")) {
|
|
8971
10456
|
const run = trackField(element, { text: "" });
|
|
8972
|
-
if (run.field)
|
|
10457
|
+
if (run.field)
|
|
10458
|
+
metadata.set(element, {
|
|
10459
|
+
field: run.field,
|
|
10460
|
+
...run.fieldFlags && { fieldFlags: run.fieldFlags }
|
|
10461
|
+
});
|
|
8973
10462
|
return;
|
|
8974
10463
|
}
|
|
8975
10464
|
for (const child3 of Array.from(element.childNodes)) if (isElement(child3)) visit(child3);
|
|
@@ -9061,7 +10550,11 @@ function parseRun2(node, revision) {
|
|
|
9061
10550
|
if (breakKind) run.break = breakKind;
|
|
9062
10551
|
if (noteReference) run.noteReference = noteReference;
|
|
9063
10552
|
if (noteMark) run.noteMark = noteMark;
|
|
9064
|
-
if (fieldChar)
|
|
10553
|
+
if (fieldChar) {
|
|
10554
|
+
run.fieldChar = fieldChar;
|
|
10555
|
+
const flags = parseFieldFlags(only);
|
|
10556
|
+
if (flags) run.fieldFlags = flags;
|
|
10557
|
+
}
|
|
9065
10558
|
if (fieldCode !== void 0) run.fieldCode = fieldCode;
|
|
9066
10559
|
const runRevision = revision ?? runFormatRevision(props);
|
|
9067
10560
|
if (runRevision) run.revision = runRevision;
|
|
@@ -9080,8 +10573,11 @@ function parseParagraph2(node, id, fields) {
|
|
|
9080
10573
|
(element, revision) => {
|
|
9081
10574
|
const run = parseRun2(element, revision);
|
|
9082
10575
|
if (!fields) return trackField(element, run);
|
|
9083
|
-
const
|
|
9084
|
-
if (
|
|
10576
|
+
const metadata = fields.get(element);
|
|
10577
|
+
if (metadata) {
|
|
10578
|
+
run.field = { ...metadata.field };
|
|
10579
|
+
if (metadata.fieldFlags) run.fieldFlags = { ...metadata.fieldFlags };
|
|
10580
|
+
}
|
|
9085
10581
|
return run;
|
|
9086
10582
|
},
|
|
9087
10583
|
(item) => {
|
|
@@ -9103,20 +10599,23 @@ function parseParagraph2(node, id, fields) {
|
|
|
9103
10599
|
);
|
|
9104
10600
|
if (link) return results.map((run) => ({ ...run, link }));
|
|
9105
10601
|
const field = { instr: instr.trim(), simple: true };
|
|
10602
|
+
const flags = parseFieldFlags(item);
|
|
10603
|
+
const fieldState = flags ? { fieldFlags: flags } : {};
|
|
9106
10604
|
const fieldInstanceId = `${id}:simple-field-${simpleFieldIndex++}`;
|
|
9107
|
-
if (!results.length)
|
|
10605
|
+
if (!results.length)
|
|
10606
|
+
return [{ text: fieldPlaceholderText(instr), field, fieldInstanceId, ...fieldState }];
|
|
9108
10607
|
if (results.every(
|
|
9109
10608
|
(run) => !run.text && !run.equation && !run.image && !run.break && !run.noteReference && !run.noteMark && !run.fieldChar && run.fieldCode === void 0
|
|
9110
10609
|
)) {
|
|
9111
10610
|
return [
|
|
9112
|
-
{ text: "", fieldChar: "begin" },
|
|
10611
|
+
{ text: "", fieldChar: "begin", ...fieldState },
|
|
9113
10612
|
{ text: "", fieldCode: instr },
|
|
9114
10613
|
{ text: "", fieldChar: "separate" },
|
|
9115
10614
|
...results,
|
|
9116
10615
|
{ text: "", fieldChar: "end" }
|
|
9117
10616
|
];
|
|
9118
10617
|
}
|
|
9119
|
-
return results.map((run) => ({ ...run, field, fieldInstanceId }));
|
|
10618
|
+
return results.map((run) => ({ ...run, field, fieldInstanceId, ...fieldState }));
|
|
9120
10619
|
},
|
|
9121
10620
|
(hyperlink) => {
|
|
9122
10621
|
if (!activeContext) return void 0;
|
|
@@ -9418,115 +10917,6 @@ async function parseDocumentParts(zip, body, blocks, drawings) {
|
|
|
9418
10917
|
};
|
|
9419
10918
|
}
|
|
9420
10919
|
|
|
9421
|
-
// docx/numbering-parse.ts
|
|
9422
|
-
var integer2 = (value, fallback) => parseInteger(value) ?? fallback;
|
|
9423
|
-
var flag = (element) => onOffElement(element) === true;
|
|
9424
|
-
function byName(root, local) {
|
|
9425
|
-
return Array.from(root.getElementsByTagName("*")).filter(
|
|
9426
|
-
(node) => node.nodeType === 1 && named2(node, local)
|
|
9427
|
-
);
|
|
9428
|
-
}
|
|
9429
|
-
function parseMarkerFormat(rPr) {
|
|
9430
|
-
if (!rPr) return void 0;
|
|
9431
|
-
const format = {};
|
|
9432
|
-
const family = getW(first2(rPr, "rFonts"), "ascii");
|
|
9433
|
-
if (family) format.fontFamily = family;
|
|
9434
|
-
const size = parseInteger(getW(first2(rPr, "sz"), "val"));
|
|
9435
|
-
if (size !== void 0 && size > 0) format.fontSizeHalfPoints = size;
|
|
9436
|
-
if (onOffElement(first2(rPr, "b")) === true) format.bold = true;
|
|
9437
|
-
if (onOffElement(first2(rPr, "i")) === true) format.italic = true;
|
|
9438
|
-
const color = getW(first2(rPr, "color"), "val");
|
|
9439
|
-
if (color && /^[0-9a-f]{6}$/i.test(color)) format.color = `#${color.toLowerCase()}`;
|
|
9440
|
-
return Object.keys(format).length ? format : void 0;
|
|
9441
|
-
}
|
|
9442
|
-
function parseNumberingLevel(lvl) {
|
|
9443
|
-
const level = integer2(getW(lvl, "ilvl"), 0);
|
|
9444
|
-
const start = integer2(getW(first2(lvl, "start"), "val"), 1);
|
|
9445
|
-
const numFmt = enumValue(isStNumberFormat, getW(first2(lvl, "numFmt"), "val"), "w:numFmt") ?? "decimal";
|
|
9446
|
-
const lvlText = getW(first2(lvl, "lvlText"), "val") ?? "";
|
|
9447
|
-
const jc = getW(first2(lvl, "lvlJc"), "val");
|
|
9448
|
-
const ind = first2(first2(lvl, "pPr"), "ind");
|
|
9449
|
-
const suffRaw = getW(first2(lvl, "suff"), "val");
|
|
9450
|
-
const result = { level, start, numFmt, lvlText };
|
|
9451
|
-
if (!first2(lvl, "start")) result.startWasOmitted = true;
|
|
9452
|
-
const paragraphStyleId = getW(first2(lvl, "pStyle"), "val");
|
|
9453
|
-
if (paragraphStyleId) result.paragraphStyleId = paragraphStyleId;
|
|
9454
|
-
if (jc === "left" || jc === "center" || jc === "right") result.lvlJc = jc;
|
|
9455
|
-
const left = getW(ind, "left") ?? getW(ind, "start");
|
|
9456
|
-
if (left !== void 0) result.indentLeftTwips = parseSignedTwips(left) ?? signedTwips(0);
|
|
9457
|
-
const hanging = getW(ind, "hanging");
|
|
9458
|
-
if (hanging !== void 0) result.hangingTwips = parseTwips(hanging) ?? twips(0);
|
|
9459
|
-
const firstLine = getW(ind, "firstLine");
|
|
9460
|
-
if (firstLine !== void 0) result.firstLineTwips = parseTwips(firstLine) ?? twips(0);
|
|
9461
|
-
const tabs = first2(first2(lvl, "pPr"), "tabs");
|
|
9462
|
-
const tab = tabs ? children2(tabs, "tab").find((stop) => getW(stop, "val") !== "clear") : void 0;
|
|
9463
|
-
const tabPos = tab ? parseTwips(getW(tab, "pos")) : void 0;
|
|
9464
|
-
if (tabPos !== void 0) result.tabStopTwips = tabPos;
|
|
9465
|
-
if (flag(first2(lvl, "isLgl"))) result.isLgl = true;
|
|
9466
|
-
const restart = getW(first2(lvl, "lvlRestart"), "val");
|
|
9467
|
-
if (restart !== void 0) result.lvlRestart = integer2(restart, 0);
|
|
9468
|
-
const marker = parseMarkerFormat(first2(lvl, "rPr"));
|
|
9469
|
-
if (marker) result.markerFormat = marker;
|
|
9470
|
-
result.suffix = suffRaw === "space" ? "space" : suffRaw === "nothing" ? "none" : "tab";
|
|
9471
|
-
return result;
|
|
9472
|
-
}
|
|
9473
|
-
function parseAbstractNum(element) {
|
|
9474
|
-
const id = getW(element, "abstractNumId");
|
|
9475
|
-
if (!id) return void 0;
|
|
9476
|
-
const levels = {};
|
|
9477
|
-
for (const lvl of children2(element, "lvl")) {
|
|
9478
|
-
const parsed = parseNumberingLevel(lvl);
|
|
9479
|
-
levels[parsed.level] = parsed;
|
|
9480
|
-
}
|
|
9481
|
-
return { id, levels };
|
|
9482
|
-
}
|
|
9483
|
-
function parseNum(element) {
|
|
9484
|
-
const id = getW(element, "numId");
|
|
9485
|
-
if (!id) return void 0;
|
|
9486
|
-
const abstractNumId = getW(first2(element, "abstractNumId"), "val") ?? "";
|
|
9487
|
-
const levelOverrides = {};
|
|
9488
|
-
for (const override of children2(element, "lvlOverride")) {
|
|
9489
|
-
const level = integer2(getW(override, "ilvl"), 0);
|
|
9490
|
-
const entry = {};
|
|
9491
|
-
const startOverride = getW(first2(override, "startOverride"), "val");
|
|
9492
|
-
if (startOverride !== void 0) entry.startOverride = integer2(startOverride, 1);
|
|
9493
|
-
const lvl = first2(override, "lvl");
|
|
9494
|
-
if (lvl) entry.lvl = parseNumberingLevel(lvl);
|
|
9495
|
-
if (Object.keys(entry).length) levelOverrides[level] = entry;
|
|
9496
|
-
}
|
|
9497
|
-
return {
|
|
9498
|
-
id,
|
|
9499
|
-
abstractNumId,
|
|
9500
|
-
...Object.keys(levelOverrides).length ? { levelOverrides } : {}
|
|
9501
|
-
};
|
|
9502
|
-
}
|
|
9503
|
-
function parseNumberingCatalog(xml) {
|
|
9504
|
-
const document = parseXml2(xml);
|
|
9505
|
-
const root = document.documentElement;
|
|
9506
|
-
const abstractNums = {};
|
|
9507
|
-
const warnings = [];
|
|
9508
|
-
for (const element of byName(root, "abstractNum")) {
|
|
9509
|
-
const parsed = parseAbstractNum(element);
|
|
9510
|
-
if (!parsed) continue;
|
|
9511
|
-
abstractNums[parsed.id] = parsed;
|
|
9512
|
-
const link = getW(first2(element, "numStyleLink"), "val");
|
|
9513
|
-
if (link)
|
|
9514
|
-
warnings.push(
|
|
9515
|
-
`Numbering definition abstractNum ${parsed.id} links to style "${link}"; style-linked numbering levels are not resolved.`
|
|
9516
|
-
);
|
|
9517
|
-
if (byName(element, "lvlPicBulletId").length)
|
|
9518
|
-
warnings.push(
|
|
9519
|
-
`Numbering definition abstractNum ${parsed.id} uses a picture bullet; picture bullets are not rendered.`
|
|
9520
|
-
);
|
|
9521
|
-
}
|
|
9522
|
-
const nums = {};
|
|
9523
|
-
for (const element of byName(root, "num")) {
|
|
9524
|
-
const parsed = parseNum(element);
|
|
9525
|
-
if (parsed) nums[parsed.id] = parsed;
|
|
9526
|
-
}
|
|
9527
|
-
return { abstractNums, nums, warnings: [...new Set(warnings)] };
|
|
9528
|
-
}
|
|
9529
|
-
|
|
9530
10920
|
// docx/comments.ts
|
|
9531
10921
|
var W14_NS2 = "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
9532
10922
|
var W15_NS2 = "http://schemas.microsoft.com/office/word/2012/wordml";
|
|
@@ -9570,62 +10960,88 @@ function parseComments(commentsXml, extendedXml) {
|
|
|
9570
10960
|
return comments;
|
|
9571
10961
|
}
|
|
9572
10962
|
|
|
9573
|
-
//
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9581
|
-
"
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
"hlink",
|
|
9587
|
-
"folHlink"
|
|
9588
|
-
];
|
|
9589
|
-
function drawingChild(parent, local) {
|
|
9590
|
-
if (!parent) return void 0;
|
|
9591
|
-
for (const node of Array.from(parent.childNodes)) {
|
|
9592
|
-
const element = node;
|
|
9593
|
-
if (element.nodeType === 1 && element.localName === local && element.namespaceURI === DRAWING_NS)
|
|
9594
|
-
return element;
|
|
10963
|
+
// drawingml/theme.ts
|
|
10964
|
+
new Set(THEME_COLOR_SLOTS);
|
|
10965
|
+
function nonEmpty(value) {
|
|
10966
|
+
return value ? value : void 0;
|
|
10967
|
+
}
|
|
10968
|
+
function parseThemeColorScheme(scheme) {
|
|
10969
|
+
const result = { colors: {} };
|
|
10970
|
+
if (!scheme) return result;
|
|
10971
|
+
const name = nonEmpty(scheme.getAttribute("name"));
|
|
10972
|
+
if (name) result.name = name;
|
|
10973
|
+
for (const slot2 of THEME_COLOR_SLOTS) {
|
|
10974
|
+
const color = parseDrawingColorIn(first(scheme, slot2, NS.a));
|
|
10975
|
+
if (color) result.colors[slot2] = color;
|
|
9595
10976
|
}
|
|
9596
|
-
return
|
|
10977
|
+
return result;
|
|
9597
10978
|
}
|
|
9598
|
-
function
|
|
9599
|
-
const
|
|
9600
|
-
if (
|
|
9601
|
-
const
|
|
9602
|
-
|
|
9603
|
-
|
|
10979
|
+
function parseFontCollection(collection) {
|
|
10980
|
+
const result = { scripts: {} };
|
|
10981
|
+
if (!collection) return result;
|
|
10982
|
+
const typeface = (local) => nonEmpty(first(collection, local, NS.a)?.getAttribute("typeface"));
|
|
10983
|
+
const latin = typeface("latin");
|
|
10984
|
+
const eastAsia = typeface("ea");
|
|
10985
|
+
const complexScript = typeface("cs");
|
|
10986
|
+
if (latin) result.latin = latin;
|
|
10987
|
+
if (eastAsia) result.eastAsia = eastAsia;
|
|
10988
|
+
if (complexScript) result.complexScript = complexScript;
|
|
10989
|
+
for (const font of elements(collection)) {
|
|
10990
|
+
if (font.localName !== "font") continue;
|
|
10991
|
+
const script = nonEmpty(font.getAttribute("script"));
|
|
10992
|
+
const face = nonEmpty(font.getAttribute("typeface"));
|
|
10993
|
+
if (script && face && !Object.hasOwn(result.scripts, script)) result.scripts[script] = face;
|
|
10994
|
+
}
|
|
10995
|
+
return result;
|
|
9604
10996
|
}
|
|
9605
|
-
function
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
10997
|
+
function parseThemeFontScheme(scheme) {
|
|
10998
|
+
const result = {
|
|
10999
|
+
major: parseFontCollection(first(scheme, "majorFont", NS.a)),
|
|
11000
|
+
minor: parseFontCollection(first(scheme, "minorFont", NS.a))
|
|
11001
|
+
};
|
|
11002
|
+
const name = nonEmpty(scheme?.getAttribute("name"));
|
|
11003
|
+
if (name) result.name = name;
|
|
11004
|
+
return result;
|
|
11005
|
+
}
|
|
11006
|
+
function rootOf2(source) {
|
|
11007
|
+
return "documentElement" in source ? source.documentElement : source;
|
|
11008
|
+
}
|
|
11009
|
+
function parseTheme(source) {
|
|
11010
|
+
const root = rootOf2(source);
|
|
11011
|
+
const holder = first(root, "themeElements", NS.a) ?? root;
|
|
11012
|
+
const theme = {
|
|
11013
|
+
colorScheme: parseThemeColorScheme(first(holder, "clrScheme", NS.a)),
|
|
11014
|
+
fontScheme: parseThemeFontScheme(first(holder, "fontScheme", NS.a))
|
|
11015
|
+
};
|
|
11016
|
+
const name = nonEmpty(root.getAttribute("name"));
|
|
11017
|
+
if (name) theme.name = name;
|
|
11018
|
+
return theme;
|
|
11019
|
+
}
|
|
11020
|
+
|
|
11021
|
+
// drawingml/theme-color.ts
|
|
11022
|
+
function themeSlotHex(color) {
|
|
11023
|
+
if (!color) return void 0;
|
|
11024
|
+
const value = color.kind === "srgb" ? color.value : color.kind === "system" ? color.fallback : void 0;
|
|
11025
|
+
return value ? value.toUpperCase() : void 0;
|
|
11026
|
+
}
|
|
11027
|
+
|
|
11028
|
+
// docx/theme.ts
|
|
11029
|
+
function fontSetOf(collection) {
|
|
11030
|
+
const { latin, eastAsia, complexScript } = collection;
|
|
9610
11031
|
return {
|
|
9611
11032
|
...latin ? { latin } : {},
|
|
9612
|
-
...
|
|
9613
|
-
...
|
|
11033
|
+
...eastAsia ? { eastAsia } : {},
|
|
11034
|
+
...complexScript ? { complexScript } : {}
|
|
9614
11035
|
};
|
|
9615
11036
|
}
|
|
9616
|
-
function
|
|
9617
|
-
const
|
|
9618
|
-
const root = document.documentElement;
|
|
9619
|
-
const clrScheme = Array.from(root.getElementsByTagNameNS(DRAWING_NS, "clrScheme"))[0];
|
|
11037
|
+
function parseTheme2(xml) {
|
|
11038
|
+
const theme = parseTheme(parseXml2(xml));
|
|
9620
11039
|
const colors = {};
|
|
9621
|
-
for (const
|
|
9622
|
-
const
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
}
|
|
9626
|
-
const fontScheme = Array.from(root.getElementsByTagNameNS(DRAWING_NS, "fontScheme"))[0];
|
|
9627
|
-
const major = drawingChild(fontScheme, "majorFont");
|
|
9628
|
-
const minor = drawingChild(fontScheme, "minorFont");
|
|
11040
|
+
for (const slot2 of THEME_COLOR_SLOTS) {
|
|
11041
|
+
const value = themeSlotHex(theme.colorScheme.colors[slot2]);
|
|
11042
|
+
if (value) colors[slot2] = value;
|
|
11043
|
+
}
|
|
11044
|
+
const { major, minor } = theme.fontScheme;
|
|
9629
11045
|
return { colors, colorMapping: {}, fonts: { major: fontSetOf(major), minor: fontSetOf(minor) } };
|
|
9630
11046
|
}
|
|
9631
11047
|
var MAPPING_KEYS = ["bg1", "tx1", "bg2", "tx2"];
|
|
@@ -9850,7 +11266,7 @@ async function readPackage(input) {
|
|
|
9850
11266
|
const themeFile = zip.file("word/theme/theme1.xml");
|
|
9851
11267
|
const settingsFile = zip.file("word/settings.xml");
|
|
9852
11268
|
if (themeFile) {
|
|
9853
|
-
model.theme =
|
|
11269
|
+
model.theme = parseTheme2(await themeFile.async("string"));
|
|
9854
11270
|
if (settingsFile) {
|
|
9855
11271
|
const settingsXml = await settingsFile.async("string");
|
|
9856
11272
|
model.theme.colorMapping = withParseWarnings(
|
|
@@ -10025,7 +11441,7 @@ function readDocFib(wordDoc) {
|
|
|
10025
11441
|
if (expectedCounts.get(nFib) !== fibRgFcLcbCount || cswNew !== 0 && cswNew !== (nFib === 274 ? 5 : 2))
|
|
10026
11442
|
throw new Error("Word FIB version and array counts disagree");
|
|
10027
11443
|
const ccpText = view.getInt32(fibRgLw97Offset + 12, true);
|
|
10028
|
-
const otherStories = [4, 5, 7, 8, 9, 10].map((
|
|
11444
|
+
const otherStories = [4, 5, 7, 8, 9, 10].map((i2) => view.getInt32(fibRgLw97Offset + i2 * 4, true));
|
|
10029
11445
|
if (ccpText < 0 || otherStories.some((cp) => cp < 0))
|
|
10030
11446
|
throw new Error("Negative Word story length");
|
|
10031
11447
|
function fcLcbPair(index) {
|
|
@@ -10139,14 +11555,14 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10139
11555
|
};
|
|
10140
11556
|
const fatCount = read32(44), difatCount = read32(72), difatStart = read32(68);
|
|
10141
11557
|
const fatIds = [];
|
|
10142
|
-
for (let
|
|
10143
|
-
const id = read32(76 + 4 *
|
|
11558
|
+
for (let i2 = 0; i2 < 109 && fatIds.length < fatCount; i2++) {
|
|
11559
|
+
const id = read32(76 + 4 * i2);
|
|
10144
11560
|
if (id <= MAX)
|
|
10145
11561
|
fatIds.push(id);
|
|
10146
11562
|
}
|
|
10147
11563
|
let difat = difatStart;
|
|
10148
11564
|
const difatIds = /* @__PURE__ */ new Set();
|
|
10149
|
-
for (let
|
|
11565
|
+
for (let i2 = 0; i2 < difatCount; i2++) {
|
|
10150
11566
|
if (difatIds.has(difat) || difat > MAX)
|
|
10151
11567
|
return reject();
|
|
10152
11568
|
difatIds.add(difat);
|
|
@@ -10169,7 +11585,7 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10169
11585
|
const exactChain = (table, start, bytes, unit) => chain(table, start, Math.ceil(bytes / unit));
|
|
10170
11586
|
const dirStart = read32(48), dirSectors = chainToEnd(fat, dirStart, sectorCount);
|
|
10171
11587
|
const dirBytes = new Uint8Array(dirSectors.length * sectorSize);
|
|
10172
|
-
dirSectors.forEach((id,
|
|
11588
|
+
dirSectors.forEach((id, i2) => dirBytes.set(sector(id), i2 * sectorSize));
|
|
10173
11589
|
const dvDir = new DataView(dirBytes.buffer);
|
|
10174
11590
|
const entries = [];
|
|
10175
11591
|
for (let p = 0, id = 0; p + SIZE <= dirBytes.length; p += SIZE, id++) {
|
|
@@ -10180,8 +11596,8 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10180
11596
|
if (nameLength < 2 || nameLength > 64 || nameLength % 2)
|
|
10181
11597
|
return reject();
|
|
10182
11598
|
let name = "";
|
|
10183
|
-
for (let
|
|
10184
|
-
name += String.fromCharCode(dvDir.getUint16(p +
|
|
11599
|
+
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
11600
|
+
name += String.fromCharCode(dvDir.getUint16(p + i2, true));
|
|
10185
11601
|
const sizeLow = dvDir.getUint32(p + 120, true), sizeHigh = dvDir.getUint32(p + 124, true);
|
|
10186
11602
|
if (sizeHigh !== 0)
|
|
10187
11603
|
return reject();
|
|
@@ -10296,19 +11712,19 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10296
11712
|
if (target.size >= miniCutoff) {
|
|
10297
11713
|
const ids2 = exactChain(fat, target.start, target.size, sectorSize);
|
|
10298
11714
|
const result2 = new Uint8Array(ids2.length * sectorSize);
|
|
10299
|
-
ids2.forEach((id,
|
|
11715
|
+
ids2.forEach((id, i2) => result2.set(sector(id), i2 * sectorSize));
|
|
10300
11716
|
return result2.slice(0, target.size);
|
|
10301
11717
|
}
|
|
10302
11718
|
const ids = exactChain(miniFat, target.start, target.size, miniSize);
|
|
10303
11719
|
const rootSectors = exactChain(fat, rootMini.start, rootMini.size, sectorSize);
|
|
10304
11720
|
const result = new Uint8Array(ids.length * miniSize);
|
|
10305
|
-
ids.forEach((id,
|
|
11721
|
+
ids.forEach((id, i2) => {
|
|
10306
11722
|
const start = id * miniSize;
|
|
10307
11723
|
if (start + miniSize > rootMini.size)
|
|
10308
11724
|
throw new Error("Mini stream out of bounds");
|
|
10309
11725
|
const rootSector = rootSectors[Math.floor(start / sectorSize)];
|
|
10310
11726
|
const source = sector(rootSector).subarray(start % sectorSize, start % sectorSize + miniSize);
|
|
10311
|
-
result.set(source,
|
|
11727
|
+
result.set(source, i2 * miniSize);
|
|
10312
11728
|
});
|
|
10313
11729
|
return result.slice(0, target.size);
|
|
10314
11730
|
}
|
|
@@ -10318,8 +11734,8 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10318
11734
|
if (target.size >= miniCutoff) {
|
|
10319
11735
|
const sectors = exactChain(fat, target.start, target.size, sectorSize);
|
|
10320
11736
|
sectors.forEach((id) => sector(id));
|
|
10321
|
-
for (let
|
|
10322
|
-
output.set(replacement.subarray(
|
|
11737
|
+
for (let i2 = 0; i2 < sectors.length; i2++)
|
|
11738
|
+
output.set(replacement.subarray(i2 * sectorSize, Math.min((i2 + 1) * sectorSize, replacement.length)), offset(sectors[i2]));
|
|
10323
11739
|
} else {
|
|
10324
11740
|
if (!miniFat.length)
|
|
10325
11741
|
return reject();
|
|
@@ -10328,9 +11744,9 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10328
11744
|
const rootSectors = exactChain(fat, rootMini2.start, rootMini2.size, sectorSize);
|
|
10329
11745
|
rootSectors.forEach((id) => sector(id));
|
|
10330
11746
|
const rootData = new Uint8Array(rootMini2.size);
|
|
10331
|
-
rootSectors.forEach((id,
|
|
10332
|
-
for (let
|
|
10333
|
-
const miniOffset = miniSectors[Math.floor(
|
|
11747
|
+
rootSectors.forEach((id, i2) => rootData.set(sector(id).subarray(0, Math.min(sectorSize, rootData.length - i2 * sectorSize)), i2 * sectorSize));
|
|
11748
|
+
for (let i2 = 0; i2 < replacement.length; i2++) {
|
|
11749
|
+
const miniOffset = miniSectors[Math.floor(i2 / miniSize)] * miniSize + i2 % miniSize;
|
|
10334
11750
|
if (miniOffset >= rootData.length)
|
|
10335
11751
|
return reject();
|
|
10336
11752
|
const rootSectorIndex = Math.floor(miniOffset / sectorSize);
|
|
@@ -10338,7 +11754,7 @@ function processCompoundFileStream(input, path, replacement) {
|
|
|
10338
11754
|
if (rootSector === void 0)
|
|
10339
11755
|
return reject();
|
|
10340
11756
|
const physical = offset(rootSector) + miniOffset % sectorSize;
|
|
10341
|
-
output[physical] = replacement[
|
|
11757
|
+
output[physical] = replacement[i2];
|
|
10342
11758
|
}
|
|
10343
11759
|
}
|
|
10344
11760
|
return output;
|
|
@@ -10468,11 +11884,11 @@ function resizeCompoundFileStreamV4(input, path, replacement) {
|
|
|
10468
11884
|
const sectorCount = input.length / SECTOR3 - 1, fatCount = read(44);
|
|
10469
11885
|
if (sectorCount > fatCount * FAT_ENTRIES2)
|
|
10470
11886
|
return fail("unsafe-edit");
|
|
10471
|
-
const fatIds = Array.from({ length: fatCount }, (_,
|
|
11887
|
+
const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
|
|
10472
11888
|
const fat = [];
|
|
10473
11889
|
for (const id of fatIds) {
|
|
10474
|
-
for (let
|
|
10475
|
-
fat.push(read((id + 1) * SECTOR3 +
|
|
11890
|
+
for (let i2 = 0; i2 < FAT_ENTRIES2 && fat.length < sectorCount; i2++)
|
|
11891
|
+
fat.push(read((id + 1) * SECTOR3 + i2 * 4));
|
|
10476
11892
|
}
|
|
10477
11893
|
if (fatIds.some((id) => fat[id] !== FAT))
|
|
10478
11894
|
return fail("unsafe-edit");
|
|
@@ -10489,8 +11905,8 @@ function resizeCompoundFileStreamV4(input, path, replacement) {
|
|
|
10489
11905
|
if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
|
|
10490
11906
|
return fail("unsafe-edit");
|
|
10491
11907
|
let name2 = "";
|
|
10492
|
-
for (let
|
|
10493
|
-
name2 += String.fromCharCode(view.getUint16(offset +
|
|
11908
|
+
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
11909
|
+
name2 += String.fromCharCode(view.getUint16(offset + i2, true));
|
|
10494
11910
|
if (read(offset + 124) !== 0)
|
|
10495
11911
|
return fail("unsafe-edit");
|
|
10496
11912
|
const id = block * DIRECTORY_ENTRIES + entry;
|
|
@@ -10519,18 +11935,18 @@ function resizeCompoundFileStreamV4(input, path, replacement) {
|
|
|
10519
11935
|
output.set(input);
|
|
10520
11936
|
output.set(replacement, (sectorCount + 1) * SECTOR3);
|
|
10521
11937
|
const outView = new DataView(output.buffer);
|
|
10522
|
-
for (let
|
|
10523
|
-
const id = sectorCount + payloadSectors +
|
|
11938
|
+
for (let i2 = fatCount; i2 < newFatCount; i2++) {
|
|
11939
|
+
const id = sectorCount + payloadSectors + i2 - fatCount;
|
|
10524
11940
|
fatIds.push(id);
|
|
10525
11941
|
output.fill(255, (id + 1) * SECTOR3, (id + 2) * SECTOR3);
|
|
10526
|
-
outView.setUint32(76 +
|
|
11942
|
+
outView.setUint32(76 + i2 * 4, id, true);
|
|
10527
11943
|
}
|
|
10528
11944
|
outView.setUint32(44, newFatCount, true);
|
|
10529
11945
|
const writeFat = (id, value) => outView.setUint32((fatIds[Math.floor(id / FAT_ENTRIES2)] + 1) * SECTOR3 + id % FAT_ENTRIES2 * 4, value, true);
|
|
10530
11946
|
for (const id of oldChain)
|
|
10531
11947
|
writeFat(id, FREE);
|
|
10532
|
-
for (let
|
|
10533
|
-
writeFat(sectorCount +
|
|
11948
|
+
for (let i2 = 0; i2 < payloadSectors; i2++)
|
|
11949
|
+
writeFat(sectorCount + i2, i2 + 1 === payloadSectors ? END2 : sectorCount + i2 + 1);
|
|
10534
11950
|
for (const id of fatIds)
|
|
10535
11951
|
writeFat(id, FAT);
|
|
10536
11952
|
outView.setUint32(target.offset + 116, payloadSectors ? sectorCount : END2, true);
|
|
@@ -10556,11 +11972,11 @@ function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize =
|
|
|
10556
11972
|
const bytes = new Uint8Array((totalSectors + 1) * sectorSize);
|
|
10557
11973
|
bytes.set(input);
|
|
10558
11974
|
const view = new DataView(bytes.buffer), fatIds = [...existingFatIds];
|
|
10559
|
-
for (let
|
|
10560
|
-
const id = sectorCount + payloadSectors +
|
|
11975
|
+
for (let i2 = existingFatIds.length; i2 < fatCount; i2++) {
|
|
11976
|
+
const id = sectorCount + payloadSectors + i2 - existingFatIds.length;
|
|
10561
11977
|
fatIds.push(id);
|
|
10562
11978
|
bytes.fill(255, (id + 1) * sectorSize, (id + 2) * sectorSize);
|
|
10563
|
-
view.setUint32(76 +
|
|
11979
|
+
view.setUint32(76 + i2 * 4, id, true);
|
|
10564
11980
|
}
|
|
10565
11981
|
view.setUint32(44, fatCount, true);
|
|
10566
11982
|
const writeFat = (id, value) => view.setUint32((fatIds[Math.floor(id / entriesPerFat)] + 1) * sectorSize + id % entriesPerFat * 4, value, true);
|
|
@@ -10568,8 +11984,8 @@ function appendCompoundAllocations(input, existingFatIds, payloads, sectorSize =
|
|
|
10568
11984
|
let next = sectorCount;
|
|
10569
11985
|
for (let payload = 0; payload < payloads.length; payload++) {
|
|
10570
11986
|
bytes.set(payloads[payload], (next + 1) * sectorSize);
|
|
10571
|
-
const chain2 = Array.from({ length: counts[payload] }, (_,
|
|
10572
|
-
chain2.forEach((id,
|
|
11987
|
+
const chain2 = Array.from({ length: counts[payload] }, (_, i2) => next + i2);
|
|
11988
|
+
chain2.forEach((id, i2) => writeFat(id, chain2[i2 + 1] ?? 4294967294));
|
|
10573
11989
|
chains.push(chain2);
|
|
10574
11990
|
next += counts[payload];
|
|
10575
11991
|
}
|
|
@@ -10634,18 +12050,18 @@ function resizeMiniCompoundStream(input, fat, fatIds, root, target, replacement,
|
|
|
10634
12050
|
const firstMini = Math.ceil(root.size / MINI), count = Math.ceil(replacement.length / MINI);
|
|
10635
12051
|
const newRootSize = count ? (firstMini + count) * MINI : root.size;
|
|
10636
12052
|
const newRoot = new Uint8Array(newRootSize);
|
|
10637
|
-
rootSectors.forEach((id,
|
|
12053
|
+
rootSectors.forEach((id, i2) => newRoot.set(input.subarray((id + 1) * SECTOR, (id + 1) * SECTOR + Math.min(SECTOR, root.size - i2 * SECTOR)), i2 * SECTOR));
|
|
10638
12054
|
if (count)
|
|
10639
12055
|
newRoot.set(replacement, firstMini * MINI);
|
|
10640
12056
|
const newMiniFatCount = Math.max(miniFatCount, Math.ceil((firstMini + count) / 128));
|
|
10641
12057
|
const newMiniFat = new Uint8Array(newMiniFatCount * SECTOR).fill(255);
|
|
10642
|
-
miniFatSectors.forEach((id,
|
|
12058
|
+
miniFatSectors.forEach((id, i2) => newMiniFat.set(input.subarray((id + 1) * SECTOR, (id + 2) * SECTOR), i2 * SECTOR));
|
|
10643
12059
|
const miniView = new DataView(newMiniFat.buffer);
|
|
10644
12060
|
if (wasMini)
|
|
10645
12061
|
for (const id of oldChain)
|
|
10646
12062
|
miniView.setUint32(id * 4, FREE2, true);
|
|
10647
|
-
for (let
|
|
10648
|
-
miniView.setUint32((firstMini +
|
|
12063
|
+
for (let i2 = 0; i2 < count; i2++)
|
|
12064
|
+
miniView.setUint32((firstMini + i2) * 4, i2 + 1 === count ? END3 : firstMini + i2 + 1, true);
|
|
10649
12065
|
const output = appendCompoundAllocations(input, fatIds, [newRoot, newMiniFat]);
|
|
10650
12066
|
if (!output)
|
|
10651
12067
|
return void 0;
|
|
@@ -10773,11 +12189,11 @@ function resizeCompoundFileStream(input, path, replacement) {
|
|
|
10773
12189
|
const sectorCount = input.length / SECTOR2 - 1, fatCount = read(44);
|
|
10774
12190
|
if (sectorCount > fatCount * FAT_ENTRIES)
|
|
10775
12191
|
return fail("unsafe-edit");
|
|
10776
|
-
const fatIds = Array.from({ length: fatCount }, (_,
|
|
12192
|
+
const fatIds = Array.from({ length: fatCount }, (_, i2) => read(76 + 4 * i2));
|
|
10777
12193
|
const fat = [];
|
|
10778
12194
|
for (const id of fatIds) {
|
|
10779
|
-
for (let
|
|
10780
|
-
fat.push(read((id + 1) * SECTOR2 +
|
|
12195
|
+
for (let i2 = 0; i2 < FAT_ENTRIES && fat.length < sectorCount; i2++)
|
|
12196
|
+
fat.push(read((id + 1) * SECTOR2 + i2 * 4));
|
|
10781
12197
|
}
|
|
10782
12198
|
if (fatIds.some((id) => fat[id] !== FAT2))
|
|
10783
12199
|
return fail("unsafe-edit");
|
|
@@ -10791,8 +12207,8 @@ function resizeCompoundFileStream(input, path, replacement) {
|
|
|
10791
12207
|
if (![1, 2, 5].includes(type) || nameLength < 2 || nameLength > 64 || nameLength % 2 || view.getUint16(offset + nameLength - 2, true))
|
|
10792
12208
|
return fail("unsafe-edit");
|
|
10793
12209
|
let name2 = "";
|
|
10794
|
-
for (let
|
|
10795
|
-
name2 += String.fromCharCode(view.getUint16(offset +
|
|
12210
|
+
for (let i2 = 0; i2 < nameLength - 2; i2 += 2)
|
|
12211
|
+
name2 += String.fromCharCode(view.getUint16(offset + i2, true));
|
|
10796
12212
|
const id = block * 4 + entry;
|
|
10797
12213
|
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 });
|
|
10798
12214
|
}
|
|
@@ -10859,7 +12275,7 @@ function unwrapDocBytes(bytes) {
|
|
|
10859
12275
|
const patchedWord = replaceCompoundFileStream(bytes, ["WordDocument"], editedWordDocBytes);
|
|
10860
12276
|
if (patchedWord === bytes)
|
|
10861
12277
|
throw new DocCfbRewriteError("Cannot safely patch WordDocument");
|
|
10862
|
-
if (editedTableBytes.every((value,
|
|
12278
|
+
if (editedTableBytes.every((value, i2) => value === tableBytes[i2]))
|
|
10863
12279
|
return patchedWord;
|
|
10864
12280
|
const patchedTable = replaceCompoundFileStream(patchedWord, [fib.tableStreamName], editedTableBytes);
|
|
10865
12281
|
if (patchedTable === patchedWord)
|
|
@@ -10888,15 +12304,15 @@ function parseBteTable(tableStream, at) {
|
|
|
10888
12304
|
throw new Error("Invalid BTE table bounds");
|
|
10889
12305
|
const n = (at.lcb - 4) / 8;
|
|
10890
12306
|
const fcs = [];
|
|
10891
|
-
for (let
|
|
10892
|
-
const fc = view.getInt32(at.fc +
|
|
10893
|
-
if (fc < 0 ||
|
|
12307
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12308
|
+
const fc = view.getInt32(at.fc + i2 * 4, true);
|
|
12309
|
+
if (fc < 0 || i2 > 0 && fc <= fcs[i2 - 1])
|
|
10894
12310
|
throw new Error("Invalid BTE FC boundaries");
|
|
10895
12311
|
fcs.push(fc);
|
|
10896
12312
|
}
|
|
10897
12313
|
const pns = [];
|
|
10898
|
-
for (let
|
|
10899
|
-
pns.push(view.getUint32(at.fc + (n + 1) * 4 +
|
|
12314
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12315
|
+
pns.push(view.getUint32(at.fc + (n + 1) * 4 + i2 * 4, true));
|
|
10900
12316
|
}
|
|
10901
12317
|
return { fcs, pns };
|
|
10902
12318
|
}
|
|
@@ -10904,11 +12320,11 @@ function buildBteTableBytes(table) {
|
|
|
10904
12320
|
const n = table.pns.length;
|
|
10905
12321
|
const bytes = new Uint8Array((n + 1) * 4 + n * 4);
|
|
10906
12322
|
const view = new DataView(bytes.buffer);
|
|
10907
|
-
for (let
|
|
10908
|
-
view.setInt32(
|
|
12323
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12324
|
+
view.setInt32(i2 * 4, table.fcs[i2], true);
|
|
10909
12325
|
}
|
|
10910
|
-
for (let
|
|
10911
|
-
view.setUint32((n + 1) * 4 +
|
|
12326
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12327
|
+
view.setUint32((n + 1) * 4 + i2 * 4, table.pns[i2], true);
|
|
10912
12328
|
}
|
|
10913
12329
|
return bytes;
|
|
10914
12330
|
}
|
|
@@ -10946,11 +12362,11 @@ function extractPapxBlob(wordDoc, papxBte, fc) {
|
|
|
10946
12362
|
throw new Error("Invalid PAPX run count");
|
|
10947
12363
|
const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
|
|
10948
12364
|
const rgbxOffset = (crun + 1) * 4;
|
|
10949
|
-
for (let
|
|
10950
|
-
const runFcStart = pageView.getInt32(
|
|
10951
|
-
const runFcEnd = pageView.getInt32((
|
|
12365
|
+
for (let i2 = 0; i2 < crun; i2++) {
|
|
12366
|
+
const runFcStart = pageView.getInt32(i2 * 4, true);
|
|
12367
|
+
const runFcEnd = pageView.getInt32((i2 + 1) * 4, true);
|
|
10952
12368
|
if (fc >= runFcStart && fc < runFcEnd) {
|
|
10953
|
-
const bOffsetWord = page[rgbxOffset +
|
|
12369
|
+
const bOffsetWord = page[rgbxOffset + i2 * 13];
|
|
10954
12370
|
if (bOffsetWord === 0)
|
|
10955
12371
|
return new Uint8Array();
|
|
10956
12372
|
const blobOffset = bOffsetWord * 2;
|
|
@@ -10973,11 +12389,11 @@ function extractChpxBlob(wordDoc, chpxBte, fc) {
|
|
|
10973
12389
|
throw new Error("Invalid CHPX run count");
|
|
10974
12390
|
const pageView = new DataView(page.buffer, page.byteOffset, page.byteLength);
|
|
10975
12391
|
const rgbOffset = (crun + 1) * 4;
|
|
10976
|
-
for (let
|
|
10977
|
-
const runFcStart = pageView.getInt32(
|
|
10978
|
-
const runFcEnd = pageView.getInt32((
|
|
12392
|
+
for (let i2 = 0; i2 < crun; i2++) {
|
|
12393
|
+
const runFcStart = pageView.getInt32(i2 * 4, true);
|
|
12394
|
+
const runFcEnd = pageView.getInt32((i2 + 1) * 4, true);
|
|
10979
12395
|
if (fc >= runFcStart && fc < runFcEnd) {
|
|
10980
|
-
const bOffsetWord = page[rgbOffset +
|
|
12396
|
+
const bOffsetWord = page[rgbOffset + i2];
|
|
10981
12397
|
if (bOffsetWord === 0) {
|
|
10982
12398
|
return new Uint8Array(0);
|
|
10983
12399
|
}
|
|
@@ -11056,7 +12472,7 @@ var CP1252_HIGH_BLOCK = [
|
|
|
11056
12472
|
382,
|
|
11057
12473
|
376
|
|
11058
12474
|
];
|
|
11059
|
-
var CP1252_HIGH_BLOCK_REVERSE = new Map(CP1252_HIGH_BLOCK.map((codePoint,
|
|
12475
|
+
var CP1252_HIGH_BLOCK_REVERSE = new Map(CP1252_HIGH_BLOCK.map((codePoint, i2) => [codePoint, 128 + i2]));
|
|
11060
12476
|
function decodeCp1252Byte(byte) {
|
|
11061
12477
|
if (byte >= 128 && byte <= 159) {
|
|
11062
12478
|
return CP1252_HIGH_BLOCK[byte - 128];
|
|
@@ -11141,16 +12557,16 @@ function parseDocClx(tableStream, clx, maxPieces) {
|
|
|
11141
12557
|
function parsePlcPcd(view, plcStart, lcb) {
|
|
11142
12558
|
const n = Math.floor((lcb - 4) / (4 + 8));
|
|
11143
12559
|
const cps = [];
|
|
11144
|
-
for (let
|
|
11145
|
-
const cp = view.getInt32(plcStart +
|
|
11146
|
-
if (
|
|
12560
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12561
|
+
const cp = view.getInt32(plcStart + i2 * 4, true);
|
|
12562
|
+
if (i2 === 0 && cp !== 0 || i2 > 0 && cp <= cps[i2 - 1])
|
|
11147
12563
|
throw new Error("Piece CPs must start at zero and increase");
|
|
11148
12564
|
cps.push(cp);
|
|
11149
12565
|
}
|
|
11150
12566
|
const pcdStart = plcStart + (n + 1) * 4;
|
|
11151
12567
|
const pieces = [];
|
|
11152
|
-
for (let
|
|
11153
|
-
const pOff = pcdStart +
|
|
12568
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12569
|
+
const pOff = pcdStart + i2 * 8;
|
|
11154
12570
|
const flagsWord = view.getUint16(pOff, true);
|
|
11155
12571
|
const fcRaw = view.getUint32(pOff + 2, true);
|
|
11156
12572
|
if ((fcRaw & 2147483648) !== 0)
|
|
@@ -11159,8 +12575,8 @@ function parsePlcPcd(view, plcStart, lcb) {
|
|
|
11159
12575
|
const compressed = (fcRaw >>> 30 & 1) === 1;
|
|
11160
12576
|
const fcField = fcRaw & 1073741823;
|
|
11161
12577
|
pieces.push({
|
|
11162
|
-
cpStart: cps[
|
|
11163
|
-
cpEnd: cps[
|
|
12578
|
+
cpStart: cps[i2],
|
|
12579
|
+
cpEnd: cps[i2 + 1],
|
|
11164
12580
|
fc: compressed ? fcField >>> 1 : fcField,
|
|
11165
12581
|
compressed,
|
|
11166
12582
|
flagsWord,
|
|
@@ -11179,8 +12595,8 @@ function decodePieceText(wordDoc, piece) {
|
|
|
11179
12595
|
}
|
|
11180
12596
|
const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
|
|
11181
12597
|
let out = "";
|
|
11182
|
-
for (let
|
|
11183
|
-
out += String.fromCharCode(view.getUint16(piece.fc +
|
|
12598
|
+
for (let i2 = 0; i2 < charLen; i2++) {
|
|
12599
|
+
out += String.fromCharCode(view.getUint16(piece.fc + i2 * 2, true));
|
|
11184
12600
|
}
|
|
11185
12601
|
return out;
|
|
11186
12602
|
}
|
|
@@ -11205,8 +12621,8 @@ function encodePieceText(text) {
|
|
|
11205
12621
|
}
|
|
11206
12622
|
const bytes = new Uint8Array(text.length * 2);
|
|
11207
12623
|
const view = new DataView(bytes.buffer);
|
|
11208
|
-
for (let
|
|
11209
|
-
view.setUint16(
|
|
12624
|
+
for (let i2 = 0; i2 < text.length; i2++) {
|
|
12625
|
+
view.setUint16(i2 * 2, text.charCodeAt(i2), true);
|
|
11210
12626
|
}
|
|
11211
12627
|
return { bytes, compressed: false };
|
|
11212
12628
|
}
|
|
@@ -11353,9 +12769,9 @@ function shiftDocMainFieldCps(table, at, body, editStart, editEnd, delta, maxFie
|
|
|
11353
12769
|
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
11354
12770
|
const markers = [];
|
|
11355
12771
|
let previous = -1;
|
|
11356
|
-
for (let
|
|
11357
|
-
const cp = view.getInt32(
|
|
11358
|
-
const ch = source[(n + 1) * 4 +
|
|
12772
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12773
|
+
const cp = view.getInt32(i2 * 4, true);
|
|
12774
|
+
const ch = source[(n + 1) * 4 + i2 * 2] & 31;
|
|
11359
12775
|
if (cp <= previous || cp >= body.length || ![19, 20, 21].includes(ch) || body.charCodeAt(cp) !== ch)
|
|
11360
12776
|
throw new Error("Invalid main-story field marker");
|
|
11361
12777
|
markers.push({ cp, ch });
|
|
@@ -11368,12 +12784,12 @@ function shiftDocMainFieldCps(table, at, body, editStart, editEnd, delta, maxFie
|
|
|
11368
12784
|
const result = source.slice();
|
|
11369
12785
|
const out = new DataView(result.buffer);
|
|
11370
12786
|
let shiftedLast = -1;
|
|
11371
|
-
for (let
|
|
11372
|
-
const cp = markers[
|
|
12787
|
+
for (let i2 = 0; i2 < n; i2++) {
|
|
12788
|
+
const cp = markers[i2].cp;
|
|
11373
12789
|
const shifted = cp >= editEnd ? cp + delta : cp;
|
|
11374
12790
|
if (shifted < 0 || shifted >= body.length + delta || shifted <= shiftedLast)
|
|
11375
12791
|
throw new Error("Field position shifts outside the main story");
|
|
11376
|
-
out.setInt32(
|
|
12792
|
+
out.setInt32(i2 * 4, shifted, true);
|
|
11377
12793
|
shiftedLast = shifted;
|
|
11378
12794
|
}
|
|
11379
12795
|
let shiftedSentinel = sentinel >= editEnd ? sentinel + delta : sentinel;
|
|
@@ -11432,9 +12848,9 @@ function pieceAndFcAtCp(pieces, cp) {
|
|
|
11432
12848
|
}
|
|
11433
12849
|
function paragraphBoundaries(bodyText) {
|
|
11434
12850
|
const boundaries = [];
|
|
11435
|
-
for (let
|
|
11436
|
-
if (bodyText[
|
|
11437
|
-
boundaries.push(
|
|
12851
|
+
for (let i2 = 0; i2 < bodyText.length; i2++) {
|
|
12852
|
+
if (bodyText[i2] === "\r") {
|
|
12853
|
+
boundaries.push(i2 + 1);
|
|
11438
12854
|
}
|
|
11439
12855
|
}
|
|
11440
12856
|
if (boundaries[boundaries.length - 1] !== bodyText.length && bodyText.length > 0) {
|
|
@@ -11445,8 +12861,8 @@ function paragraphBoundaries(bodyText) {
|
|
|
11445
12861
|
function encodePieceTextUtf16(text) {
|
|
11446
12862
|
const bytes = new Uint8Array(text.length * 2);
|
|
11447
12863
|
const view = new DataView(bytes.buffer);
|
|
11448
|
-
for (let
|
|
11449
|
-
view.setUint16(
|
|
12864
|
+
for (let i2 = 0; i2 < text.length; i2++)
|
|
12865
|
+
view.setUint16(i2 * 2, text.charCodeAt(i2), true);
|
|
11450
12866
|
return bytes;
|
|
11451
12867
|
}
|
|
11452
12868
|
function readOleDocParagraphs(docBytes, limits) {
|
|
@@ -11485,8 +12901,8 @@ function shiftSectionTableCps(tableBytes, sed, editEndCp, delta) {
|
|
|
11485
12901
|
if (sed.lcb < 4 || (sed.lcb - 4) % 16 !== 0 || sed.fc > tableBytes.length - sed.lcb)
|
|
11486
12902
|
throw new Error("Invalid section table");
|
|
11487
12903
|
const n = (sed.lcb - 4) / 16;
|
|
11488
|
-
for (let
|
|
11489
|
-
const off = sed.fc +
|
|
12904
|
+
for (let i2 = 0; i2 <= n; i2++) {
|
|
12905
|
+
const off = sed.fc + i2 * 4;
|
|
11490
12906
|
const cp = view.getInt32(off, true);
|
|
11491
12907
|
if (cp >= editEndCp) {
|
|
11492
12908
|
view.setInt32(off, cp + delta, true);
|
|
@@ -11760,13 +13176,13 @@ async function loadLegacyDoc(input) {
|
|
|
11760
13176
|
"Adding or removing paragraphs in legacy .doc files is unsupported."
|
|
11761
13177
|
);
|
|
11762
13178
|
let output = original;
|
|
11763
|
-
for (let
|
|
11764
|
-
if (updated[
|
|
11765
|
-
if (/[\r\n]/u.test(updated[
|
|
13179
|
+
for (let i2 = 0; i2 < updated.length; i2++) {
|
|
13180
|
+
if (updated[i2] === paragraphs[i2]) continue;
|
|
13181
|
+
if (/[\r\n]/u.test(updated[i2]))
|
|
11766
13182
|
throw new LegacyDocError(
|
|
11767
13183
|
"Adding line breaks in legacy .doc paragraph text is unsupported."
|
|
11768
13184
|
);
|
|
11769
|
-
const result = writeOleDocParagraphEdit(output,
|
|
13185
|
+
const result = writeOleDocParagraphEdit(output, i2, updated[i2]);
|
|
11770
13186
|
if (result === output)
|
|
11771
13187
|
throw new LegacyDocError(
|
|
11772
13188
|
"This .doc uses structures that prevent safe paragraph text editing."
|