@file-viewer/assets-ppt 3.3.0 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.en.md +3 -1
  2. package/README.md +3 -1
  3. package/README.zh-CN.md +3 -1
  4. package/package.json +96 -9
  5. package/viewer/THIRD_PARTY_LICENSES.assets.json +837 -54
  6. package/viewer/file-viewer-asset-pack.json +20 -31
  7. package/viewer/vendor/ppt/LICENSE +160 -122
  8. package/viewer/vendor/ppt/NOTICE.md +30 -0
  9. package/viewer/vendor/ppt/README.md +86 -0
  10. package/viewer/vendor/ppt/dist/core/binary.d.ts +31 -0
  11. package/viewer/vendor/ppt/dist/core/binary.js +102 -0
  12. package/viewer/vendor/ppt/dist/core/cfb.d.ts +38 -0
  13. package/viewer/vendor/ppt/dist/core/cfb.js +208 -0
  14. package/viewer/vendor/ppt/dist/core/crypto.d.ts +12 -0
  15. package/viewer/vendor/ppt/dist/core/crypto.js +64 -0
  16. package/viewer/vendor/ppt/dist/core/errors.d.ts +5 -0
  17. package/viewer/vendor/ppt/dist/core/errors.js +5 -0
  18. package/viewer/vendor/ppt/dist/core/inflate.d.ts +11 -0
  19. package/viewer/vendor/ppt/dist/core/inflate.js +337 -0
  20. package/viewer/vendor/ppt/dist/core/pict.d.ts +14 -0
  21. package/viewer/vendor/ppt/dist/core/pict.js +472 -0
  22. package/viewer/vendor/ppt/dist/core/raster.d.ts +7 -0
  23. package/viewer/vendor/ppt/dist/core/raster.js +101 -0
  24. package/viewer/vendor/ppt/dist/core/tiff.d.ts +20 -0
  25. package/viewer/vendor/ppt/dist/core/tiff.js +254 -0
  26. package/viewer/vendor/ppt/dist/core/utils.d.ts +9 -0
  27. package/viewer/vendor/ppt/dist/core/utils.js +13 -0
  28. package/viewer/vendor/ppt/dist/core/vector-font.d.ts +12 -0
  29. package/viewer/vendor/ppt/dist/core/vector-font.js +29 -0
  30. package/viewer/vendor/ppt/dist/core/vector.d.ts +19 -0
  31. package/viewer/vendor/ppt/dist/core/vector.js +1570 -0
  32. package/viewer/vendor/ppt/dist/core/xml-text.d.ts +1 -0
  33. package/viewer/vendor/ppt/dist/core/xml-text.js +6 -0
  34. package/viewer/vendor/ppt/dist/index.d.ts +12 -0
  35. package/viewer/vendor/ppt/dist/index.js +8 -0
  36. package/viewer/vendor/ppt/dist/layout/measure.d.ts +15 -0
  37. package/viewer/vendor/ppt/dist/layout/measure.js +54 -0
  38. package/viewer/vendor/ppt/dist/layout/text-layout.d.ts +48 -0
  39. package/viewer/vendor/ppt/dist/layout/text-layout.js +272 -0
  40. package/viewer/vendor/ppt/dist/manifest.json +13 -0
  41. package/viewer/vendor/ppt/dist/playback/media.d.ts +11 -0
  42. package/viewer/vendor/ppt/dist/playback/media.js +37 -0
  43. package/viewer/vendor/ppt/dist/playback/navigation.d.ts +2 -0
  44. package/viewer/vendor/ppt/dist/playback/navigation.js +14 -0
  45. package/viewer/vendor/ppt/dist/playback/timeline.d.ts +47 -0
  46. package/viewer/vendor/ppt/dist/playback/timeline.js +154 -0
  47. package/viewer/vendor/ppt/dist/playback/transitions.d.ts +14 -0
  48. package/viewer/vendor/ppt/dist/playback/transitions.js +41 -0
  49. package/viewer/vendor/ppt/dist/ppt/animation.d.ts +3 -0
  50. package/viewer/vendor/ppt/dist/ppt/animation.js +67 -0
  51. package/viewer/vendor/ppt/dist/ppt/constants.d.ts +72 -0
  52. package/viewer/vendor/ppt/dist/ppt/constants.js +21 -0
  53. package/viewer/vendor/ppt/dist/ppt/drawing.d.ts +15 -0
  54. package/viewer/vendor/ppt/dist/ppt/drawing.js +508 -0
  55. package/viewer/vendor/ppt/dist/ppt/encryption.d.ts +14 -0
  56. package/viewer/vendor/ppt/dist/ppt/encryption.js +241 -0
  57. package/viewer/vendor/ppt/dist/ppt/extras.d.ts +14 -0
  58. package/viewer/vendor/ppt/dist/ppt/extras.js +225 -0
  59. package/viewer/vendor/ppt/dist/ppt/geometry.d.ts +29 -0
  60. package/viewer/vendor/ppt/dist/ppt/geometry.js +448 -0
  61. package/viewer/vendor/ppt/dist/ppt/headers-footers.d.ts +11 -0
  62. package/viewer/vendor/ppt/dist/ppt/headers-footers.js +97 -0
  63. package/viewer/vendor/ppt/dist/ppt/interactions.d.ts +12 -0
  64. package/viewer/vendor/ppt/dist/ppt/interactions.js +104 -0
  65. package/viewer/vendor/ppt/dist/ppt/parser.d.ts +12 -0
  66. package/viewer/vendor/ppt/dist/ppt/parser.js +356 -0
  67. package/viewer/vendor/ppt/dist/ppt/pictures.d.ts +10 -0
  68. package/viewer/vendor/ppt/dist/ppt/pictures.js +215 -0
  69. package/viewer/vendor/ppt/dist/ppt/records.d.ts +13 -0
  70. package/viewer/vendor/ppt/dist/ppt/records.js +49 -0
  71. package/viewer/vendor/ppt/dist/ppt/text.d.ts +19 -0
  72. package/viewer/vendor/ppt/dist/ppt/text.js +789 -0
  73. package/viewer/vendor/ppt/dist/pptjs.browser.js +9651 -0
  74. package/viewer/vendor/ppt/dist/pptjs.mjs +9663 -0
  75. package/viewer/vendor/ppt/dist/pptjs.worker.js +9650 -0
  76. package/viewer/vendor/ppt/dist/render/effects.d.ts +23 -0
  77. package/viewer/vendor/ppt/dist/render/effects.js +125 -0
  78. package/viewer/vendor/ppt/dist/render/fields.d.ts +11 -0
  79. package/viewer/vendor/ppt/dist/render/fields.js +176 -0
  80. package/viewer/vendor/ppt/dist/render/geometry.d.ts +11 -0
  81. package/viewer/vendor/ppt/dist/render/geometry.js +131 -0
  82. package/viewer/vendor/ppt/dist/render/safe.d.ts +12 -0
  83. package/viewer/vendor/ppt/dist/render/safe.js +48 -0
  84. package/viewer/vendor/ppt/dist/render/svg.d.ts +4 -0
  85. package/viewer/vendor/ppt/dist/render/svg.js +279 -0
  86. package/viewer/vendor/ppt/dist/render/text.d.ts +9 -0
  87. package/viewer/vendor/ppt/dist/render/text.js +181 -0
  88. package/viewer/vendor/ppt/dist/render/three-d.d.ts +32 -0
  89. package/viewer/vendor/ppt/dist/render/three-d.js +219 -0
  90. package/viewer/vendor/ppt/dist/render/wordart.d.ts +16 -0
  91. package/viewer/vendor/ppt/dist/render/wordart.js +214 -0
  92. package/viewer/vendor/ppt/dist/runtime.d.ts +125 -0
  93. package/viewer/vendor/ppt/dist/runtime.js +226 -0
  94. package/viewer/vendor/ppt/dist/types.d.ts +546 -0
  95. package/viewer/vendor/ppt/dist/types.js +1 -0
  96. package/viewer/vendor/ppt/dist/viewer.d.ts +3 -0
  97. package/viewer/vendor/ppt/dist/viewer.js +264 -0
  98. package/viewer/vendor/ppt/dist/worker-client.d.ts +25 -0
  99. package/viewer/vendor/ppt/dist/worker-client.js +61 -0
  100. package/viewer/vendor/ppt/dist/worker.d.ts +1 -0
  101. package/viewer/vendor/ppt/dist/worker.js +25 -0
  102. package/viewer/vendor/ppt/package.json +40 -52
  103. package/viewer/vendor/ppt/NOTICE +0 -229
  104. package/viewer/vendor/ppt/frame-cache.mjs +0 -731
  105. package/viewer/vendor/ppt/index.mjs +0 -941
  106. package/viewer/vendor/ppt/manifest.json +0 -44
  107. package/viewer/vendor/ppt/ppt-font-cjk.otf +0 -0
  108. package/viewer/vendor/ppt/ppt-native.wasm +0 -0
  109. package/viewer/vendor/ppt/worker.mjs +0 -1720
@@ -0,0 +1,102 @@
1
+ import { textDecoder } from './utils.js';
2
+ const utf16leDecoder = textDecoder('utf-16le');
3
+ const latin1Decoder = typeof TextDecoder !== 'undefined' ? textDecoder('windows-1252') : textDecoder('latin1');
4
+ /**
5
+ * Lightweight little-endian binary reader used across the MS-DOC parser.
6
+ * The implementation intentionally returns neutral defaults for out-of-range
7
+ * reads so upper layers can stay resilient to slightly malformed documents.
8
+ */
9
+ export class BinaryReader {
10
+ bytes;
11
+ view;
12
+ length;
13
+ constructor(input) {
14
+ if (input instanceof Uint8Array) {
15
+ this.bytes = input;
16
+ }
17
+ else if (input instanceof ArrayBuffer) {
18
+ this.bytes = new Uint8Array(input);
19
+ }
20
+ else if (ArrayBuffer.isView(input)) {
21
+ this.bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
22
+ }
23
+ else {
24
+ throw new TypeError('BinaryReader expects ArrayBuffer or Uint8Array');
25
+ }
26
+ this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
27
+ this.length = this.bytes.byteLength;
28
+ }
29
+ ensure(offset, size = 1) {
30
+ return offset >= 0 && offset + size <= this.length;
31
+ }
32
+ u8(offset) { return this.ensure(offset, 1) ? this.view.getUint8(offset) : 0; }
33
+ i8(offset) { return this.ensure(offset, 1) ? this.view.getInt8(offset) : 0; }
34
+ u16(offset) { return this.ensure(offset, 2) ? this.view.getUint16(offset, true) : 0; }
35
+ i16(offset) { return this.ensure(offset, 2) ? this.view.getInt16(offset, true) : 0; }
36
+ u32(offset) { return this.ensure(offset, 4) ? this.view.getUint32(offset, true) : 0; }
37
+ i32(offset) { return this.ensure(offset, 4) ? this.view.getInt32(offset, true) : 0; }
38
+ u64(offset) {
39
+ const lo = this.u32(offset);
40
+ const hi = this.u32(offset + 4);
41
+ return hi * 0x100000000 + lo;
42
+ }
43
+ slice(offset, length) {
44
+ if (!this.ensure(offset, length)) {
45
+ return new Uint8Array(0);
46
+ }
47
+ return this.bytes.subarray(offset, offset + length);
48
+ }
49
+ array(offset, count, readFn) {
50
+ const out = [];
51
+ const width = readFn.byteWidth ?? 1;
52
+ for (let i = 0; i < count; i += 1) {
53
+ out.push(readFn.call(this, offset + i * width));
54
+ }
55
+ return out;
56
+ }
57
+ utf16le(offset, byteLength) {
58
+ if (!this.ensure(offset, byteLength))
59
+ return '';
60
+ return utf16leDecoder.decode(this.slice(offset, byteLength));
61
+ }
62
+ latin1(offset, byteLength) {
63
+ if (!this.ensure(offset, byteLength))
64
+ return '';
65
+ return latin1Decoder.decode(this.slice(offset, byteLength));
66
+ }
67
+ ascii(offset, byteLength) {
68
+ if (!this.ensure(offset, byteLength))
69
+ return '';
70
+ let out = '';
71
+ const view = this.slice(offset, byteLength);
72
+ for (let i = 0; i < view.length; i += 1)
73
+ out += String.fromCharCode(view[i] ?? 0);
74
+ return out;
75
+ }
76
+ utf16z(offset, byteLength) {
77
+ const raw = this.slice(offset, byteLength);
78
+ let end = raw.length;
79
+ for (let i = 0; i + 1 < raw.length; i += 2) {
80
+ if (raw[i] === 0 && raw[i + 1] === 0) {
81
+ end = i;
82
+ break;
83
+ }
84
+ }
85
+ return utf16leDecoder.decode(raw.subarray(0, end));
86
+ }
87
+ }
88
+ BinaryReader.prototype.u8.byteWidth = 1;
89
+ BinaryReader.prototype.i8.byteWidth = 1;
90
+ BinaryReader.prototype.u16.byteWidth = 2;
91
+ BinaryReader.prototype.i16.byteWidth = 2;
92
+ BinaryReader.prototype.u32.byteWidth = 4;
93
+ BinaryReader.prototype.i32.byteWidth = 4;
94
+ export function toUint8Array(input) {
95
+ if (input instanceof Uint8Array)
96
+ return input;
97
+ if (input instanceof ArrayBuffer)
98
+ return new Uint8Array(input);
99
+ if (ArrayBuffer.isView(input))
100
+ return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
101
+ throw new TypeError('Unsupported binary input');
102
+ }
@@ -0,0 +1,38 @@
1
+ /** CFB/OLE foundation follows msdoc-viewer's lazy stream architecture, hardened for PPT limits.
2
+ * Layout: Microsoft [MS-CFB] 2.2, 2.3, 2.6. All sectors are bounded before allocation.
3
+ */
4
+ import type { BinaryInput, Diagnostic, ParseLimits } from '../types.js';
5
+ export interface CompoundEntry {
6
+ id: number;
7
+ name: string;
8
+ type: number;
9
+ left: number;
10
+ right: number;
11
+ child: number;
12
+ start: number;
13
+ size: number;
14
+ parent: number | null;
15
+ path: string;
16
+ }
17
+ export declare function toBytes(input: BinaryInput): Uint8Array;
18
+ export declare class CompoundFile {
19
+ readonly entries: CompoundEntry[];
20
+ readonly sectorSize: number;
21
+ readonly version: number;
22
+ private readonly bytes;
23
+ private readonly view;
24
+ private readonly sectorCount;
25
+ private readonly fat;
26
+ private readonly miniFat;
27
+ private readonly root;
28
+ private readonly cache;
29
+ private readonly paths;
30
+ private readonly limits;
31
+ constructor(input: BinaryInput, limits: ParseLimits, diagnostics?: Diagnostic[], strict?: boolean);
32
+ private checkSector;
33
+ private sector;
34
+ private readChain;
35
+ private attachDirectory;
36
+ getEntry(path: string): CompoundEntry | undefined;
37
+ getStream(path: string): Uint8Array | undefined;
38
+ }
@@ -0,0 +1,208 @@
1
+ import { PptError } from './errors.js';
2
+ const FREE = 0xffffffff, END = 0xfffffffe, FAT = 0xfffffffd, DIF = 0xfffffffc;
3
+ const signature = [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1];
4
+ export function toBytes(input) {
5
+ if (input instanceof ArrayBuffer)
6
+ return new Uint8Array(input);
7
+ if (ArrayBuffer.isView(input))
8
+ return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
9
+ throw new TypeError('Expected an ArrayBuffer or ArrayBufferView');
10
+ }
11
+ export class CompoundFile {
12
+ entries = [];
13
+ sectorSize;
14
+ version;
15
+ bytes;
16
+ view;
17
+ sectorCount;
18
+ fat;
19
+ miniFat;
20
+ root;
21
+ cache = new Map();
22
+ paths = new Map();
23
+ limits;
24
+ constructor(input, limits, diagnostics = [], strict = false) {
25
+ this.bytes = toBytes(input);
26
+ this.limits = limits;
27
+ if (this.bytes.length > limits.maxFileBytes)
28
+ throw new PptError('LIMIT_FILE', 'File exceeds the configured byte limit');
29
+ if (this.bytes.length < 512 || signature.some((v, i) => this.bytes[i] !== v))
30
+ throw new PptError('NOT_CFB', 'Expected a PowerPoint 97–2003 .ppt compound file');
31
+ this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
32
+ this.version = this.view.getUint16(26, true);
33
+ const shift = this.view.getUint16(30, true);
34
+ if (this.view.getUint16(28, true) !== 0xfffe || !((this.version === 3 && shift === 9) || (this.version === 4 && shift === 12)) || this.view.getUint16(32, true) !== 6)
35
+ throw new PptError('CFB_HEADER', 'Unsupported or invalid CFB header');
36
+ this.sectorSize = 2 ** shift;
37
+ this.sectorCount = Math.ceil(this.bytes.length / this.sectorSize) - 1;
38
+ if (this.bytes.length < this.sectorSize || this.view.getUint32(56, true) !== 4096)
39
+ throw new PptError('CFB_HEADER', 'Invalid CFB sector size or mini stream cutoff');
40
+ const fatCount = this.view.getUint32(44, true), difCount = this.view.getUint32(72, true);
41
+ if (fatCount > this.sectorCount || difCount > this.sectorCount)
42
+ throw new PptError('CFB_FAT', 'FAT allocation exceeds physical file');
43
+ const fatSectors = [];
44
+ const addFat = (id) => { if (id !== FREE) {
45
+ this.checkSector(id);
46
+ if (fatSectors.length >= fatCount)
47
+ throw new PptError('CFB_FAT', 'DIFAT lists more FAT sectors than the header declares');
48
+ fatSectors.push(id);
49
+ } };
50
+ for (let i = 0; i < 109; i++)
51
+ addFat(this.view.getUint32(76 + i * 4, true));
52
+ let next = this.view.getUint32(68, true);
53
+ const seenDif = new Set();
54
+ for (let i = 0; i < difCount; i++) {
55
+ if (seenDif.has(next))
56
+ throw new PptError('CFB_CYCLE', 'Cycle in DIFAT chain');
57
+ seenDif.add(next);
58
+ const sector = this.sector(next);
59
+ const dv = new DataView(sector.buffer, sector.byteOffset, sector.length);
60
+ for (let j = 0; j < this.sectorSize / 4 - 1; j++)
61
+ addFat(dv.getUint32(j * 4, true));
62
+ next = dv.getUint32(this.sectorSize - 4, true);
63
+ }
64
+ // MS-CFB 2.5 requires ENDOFCHAIN. Some otherwise readable producers use
65
+ // FREESECT only at the final declared DIFAT sector. Accept that bounded
66
+ // terminal variant for preview, while retaining strict conformance checks.
67
+ if (difCount > 0 && next !== END) {
68
+ if (next === FREE && !strict)
69
+ diagnostics.push({ code: 'CFB_DIFAT_FREE_TERMINATOR', severity: 'warning', message: 'The final declared DIFAT sector uses FREESECT instead of the required ENDOFCHAIN; the declared FAT count and all sector bounds are still checked.' });
70
+ else
71
+ throw new PptError('CFB_DIFAT', 'DIFAT does not terminate at declared sector count');
72
+ }
73
+ if (fatSectors.length < fatCount)
74
+ throw new PptError('CFB_FAT', 'FAT sector list is truncated');
75
+ if (new Set(fatSectors.slice(0, fatCount)).size !== fatCount)
76
+ throw new PptError('CFB_FAT', 'Duplicate FAT sectors');
77
+ const entriesPerSector = this.sectorSize / 4;
78
+ if (fatCount * entriesPerSector * 4 > limits.maxStreamBytes)
79
+ throw new PptError('LIMIT_STREAM', 'FAT exceeds configured stream budget');
80
+ this.fat = new Uint32Array(fatCount * entriesPerSector);
81
+ for (let i = 0; i < fatCount; i++) {
82
+ const s = this.sector(fatSectors[i]);
83
+ const v = new DataView(s.buffer, s.byteOffset, s.length);
84
+ for (let j = 0; j < entriesPerSector; j++)
85
+ this.fat[i * entriesPerSector + j] = v.getUint32(j * 4, true);
86
+ }
87
+ const dir = this.readChain(this.view.getUint32(48, true), undefined, this.fat, this.sectorSize);
88
+ const dv = new DataView(dir.buffer, dir.byteOffset, dir.length);
89
+ const utf16 = new TextDecoder('utf-16le');
90
+ for (let p = 0; p + 128 <= dir.length; p += 128) {
91
+ const type = dv.getUint8(p + 66), nameLen = dv.getUint16(p + 64, true);
92
+ if (type !== 0 && (nameLen < 2 || nameLen > 64 || (nameLen & 1)))
93
+ throw new PptError('CFB_DIRECTORY', 'Invalid directory name length', p);
94
+ const size = dv.getUint32(p + 120, true) + (this.version === 4 ? dv.getUint32(p + 124, true) * 2 ** 32 : 0);
95
+ if (!Number.isSafeInteger(size) || size > limits.maxStreamBytes)
96
+ throw new PptError('LIMIT_STREAM', 'Directory declares an oversized stream', p);
97
+ this.entries.push({ id: p / 128, name: type === 0 ? '' : utf16.decode(dir.subarray(p, p + nameLen - 2)), type, left: dv.getUint32(p + 68, true), right: dv.getUint32(p + 72, true), child: dv.getUint32(p + 76, true), start: dv.getUint32(p + 116, true), size, parent: null, path: '' });
98
+ }
99
+ const root = this.entries[0];
100
+ if (!root || root.type !== 5)
101
+ throw new PptError('CFB_ROOT', 'Compound file root entry is missing');
102
+ this.root = root;
103
+ this.attachDirectory(root, 0, new Set());
104
+ const miniCount = this.view.getUint32(64, true);
105
+ if (miniCount > this.sectorCount || miniCount * this.sectorSize > limits.maxStreamBytes)
106
+ throw new PptError('CFB_MINIFAT', 'Invalid MiniFAT count');
107
+ const mb = miniCount ? this.readChain(this.view.getUint32(60, true), miniCount * this.sectorSize, this.fat, this.sectorSize) : new Uint8Array(0);
108
+ this.miniFat = new Uint32Array(mb.length / 4);
109
+ const mv = new DataView(mb.buffer, mb.byteOffset, mb.byteLength);
110
+ for (let i = 0; i < this.miniFat.length; i++)
111
+ this.miniFat[i] = mv.getUint32(i * 4, true);
112
+ if (this.bytes.length % this.sectorSize)
113
+ diagnostics.push({ code: 'CFB_PARTIAL_TAIL', severity: 'warning', message: 'The final physical sector is partial; each logical stream remains checked against its declared size.' });
114
+ }
115
+ checkSector(id) { if (!Number.isInteger(id) || id < 0 || id >= this.sectorCount)
116
+ throw new PptError('CFB_SECTOR', `Sector ${id} is outside the file`); }
117
+ sector(id, length = this.sectorSize) { this.checkSector(id); const p = (id + 1) * this.sectorSize; if (p + length > this.bytes.length)
118
+ throw new PptError('CFB_TRUNCATED', 'Sector payload is truncated', p); return this.bytes.subarray(p, p + length); }
119
+ readChain(start, size, table, unit, mini) {
120
+ if (size === 0)
121
+ return new Uint8Array(0);
122
+ const chain = [];
123
+ const visited = new Set();
124
+ let id = start;
125
+ const needed = size === undefined ? Infinity : Math.ceil(size / unit);
126
+ while (id !== END) {
127
+ if (id === FREE || id === FAT || id === DIF || id >= table.length)
128
+ throw new PptError('CFB_CHAIN', 'Broken sector chain');
129
+ if (visited.has(id))
130
+ throw new PptError('CFB_CYCLE', 'Cycle in sector chain');
131
+ visited.add(id);
132
+ if (!mini)
133
+ this.checkSector(id);
134
+ else if (id * unit >= mini.length)
135
+ throw new PptError('CFB_MINISTREAM', 'Mini sector outside root stream');
136
+ chain.push(id);
137
+ if (chain.length * unit > this.limits.maxStreamBytes + unit)
138
+ throw new PptError('LIMIT_STREAM', 'Sector chain exceeds configured budget');
139
+ id = table[id];
140
+ if (chain.length === needed)
141
+ break;
142
+ }
143
+ const length = size ?? chain.length * unit;
144
+ if (length > this.limits.maxStreamBytes)
145
+ throw new PptError('LIMIT_STREAM', 'Stream exceeds configured byte limit');
146
+ if (chain.length * unit < length)
147
+ throw new PptError('CFB_TRUNCATED', 'Sector chain is shorter than the declared stream');
148
+ const out = new Uint8Array(length);
149
+ let offset = 0;
150
+ for (const sid of chain) {
151
+ const count = Math.min(unit, length - offset);
152
+ const chunk = mini ? mini.subarray(sid * unit, sid * unit + count) : this.sector(sid, count);
153
+ if (chunk.length !== count)
154
+ throw new PptError('CFB_TRUNCATED', 'Truncated mini stream');
155
+ out.set(chunk, offset);
156
+ offset += count;
157
+ }
158
+ return out;
159
+ }
160
+ attachDirectory(parent, depth, assigned) {
161
+ if (depth > this.limits.maxDepth)
162
+ throw new PptError('CFB_DEPTH', 'Directory nesting exceeds configured limit');
163
+ const stack = [parent.child];
164
+ const siblings = new Set();
165
+ while (stack.length) {
166
+ const id = stack.pop();
167
+ if (id === FREE)
168
+ continue;
169
+ if (id >= this.entries.length || id === 0 || siblings.has(id) || assigned.has(id))
170
+ throw new PptError('CFB_DIRECTORY_CYCLE', 'Invalid or cyclic directory tree');
171
+ siblings.add(id);
172
+ assigned.add(id);
173
+ const entry = this.entries[id];
174
+ if (entry.type !== 1 && entry.type !== 2)
175
+ throw new PptError('CFB_DIRECTORY', 'Invalid directory object type');
176
+ entry.parent = parent.id;
177
+ entry.path = (parent.type === 5 ? '' : parent.path) + '/' + entry.name;
178
+ if (this.paths.has(entry.path.toLowerCase()))
179
+ throw new PptError('CFB_DIRECTORY', 'Duplicate stream path');
180
+ this.paths.set(entry.path.toLowerCase(), entry);
181
+ stack.push(entry.right, entry.left);
182
+ if (entry.type === 1)
183
+ this.attachDirectory(entry, depth + 1, assigned);
184
+ }
185
+ }
186
+ getEntry(path) { return this.paths.get(('/' + path.replace(/^\/+/, '')).toLowerCase()); }
187
+ getStream(path) {
188
+ const entry = this.getEntry(path);
189
+ if (!entry || entry.type !== 2)
190
+ return undefined;
191
+ const cached = this.cache.get(entry.id);
192
+ if (cached)
193
+ return cached;
194
+ let result;
195
+ if (entry.size < 4096 && entry.size > 0) {
196
+ let root = this.cache.get(this.root.id);
197
+ if (!root) {
198
+ root = this.readChain(this.root.start, this.root.size, this.fat, this.sectorSize);
199
+ this.cache.set(this.root.id, root);
200
+ }
201
+ result = this.readChain(entry.start, entry.size, this.miniFat, 64, root);
202
+ }
203
+ else
204
+ result = this.readChain(entry.start, entry.size, this.fat, this.sectorSize);
205
+ this.cache.set(entry.id, result);
206
+ return result;
207
+ }
208
+ }
@@ -0,0 +1,12 @@
1
+ export declare function concatBytes(...items: Uint8Array[]): Uint8Array;
2
+ export declare function little32(value: number): Uint8Array;
3
+ export declare function passwordBytes(password: string): Uint8Array;
4
+ export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
5
+ export declare function sha1(data: Uint8Array): Uint8Array;
6
+ export declare class Rc4 {
7
+ private readonly state;
8
+ private i;
9
+ private j;
10
+ constructor(key: Uint8Array);
11
+ crypt(bytes: Uint8Array): Uint8Array;
12
+ }
@@ -0,0 +1,64 @@
1
+ /** Cryptographic primitives for Office file interoperability only.
2
+ * Original TypeScript implementation of FIPS 180-4 SHA-1 and RC4.
3
+ * No native runtime, WASM, dynamic code, password guessing or network access.
4
+ */
5
+ import { PptError } from './errors.js';
6
+ export function concatBytes(...items) { const out = new Uint8Array(items.reduce((n, x) => n + x.length, 0)); let at = 0; for (const x of items) {
7
+ out.set(x, at);
8
+ at += x.length;
9
+ } return out; }
10
+ export function little32(value) { const b = new Uint8Array(4); new DataView(b.buffer).setUint32(0, value, true); return b; }
11
+ export function passwordBytes(password) { if (password.length > 255)
12
+ throw new PptError('PASSWORD_LENGTH', 'Office passwords may contain at most 255 UTF-16 code units'); const b = new Uint8Array(password.length * 2), v = new DataView(b.buffer); for (let i = 0; i < password.length; i++)
13
+ v.setUint16(i * 2, password.charCodeAt(i), true); return b; }
14
+ export function equalBytes(a, b) { let difference = a.length ^ b.length; for (let i = 0; i < Math.max(a.length, b.length); i++)
15
+ difference |= (a[i] ?? 0) ^ (b[i] ?? 0); return difference === 0; }
16
+ function padded(data, block, lengthBytes) { const out = new Uint8Array(Math.ceil((data.length + 1 + lengthBytes) / block) * block); out.set(data); out[data.length] = 128; const v = new DataView(out.buffer); v.setUint32(out.length - 8, Math.floor(data.length / 0x20000000)); v.setUint32(out.length - 4, (data.length * 8) >>> 0); return out; }
17
+ const rol = (x, n) => (x << n) | (x >>> (32 - n));
18
+ export function sha1(data) {
19
+ const bytes = padded(data, 64, 8), v = new DataView(bytes.buffer), w = new Uint32Array(80), h = new Uint32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
20
+ for (let at = 0; at < bytes.length; at += 64) {
21
+ for (let i = 0; i < 16; i++)
22
+ w[i] = v.getUint32(at + i * 4);
23
+ for (let i = 16; i < 80; i++)
24
+ w[i] = rol(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
25
+ let [a, b, c, d, e] = h;
26
+ for (let i = 0; i < 80; i++) {
27
+ const f = i < 20 ? (b & c) | (~b & d) : i < 40 ? b ^ c ^ d : i < 60 ? (b & c) | (b & d) | (c & d) : b ^ c ^ d, k = i < 20 ? 0x5a827999 : i < 40 ? 0x6ed9eba1 : i < 60 ? 0x8f1bbcdc : 0xca62c1d6, t = (rol(a, 5) + f + e + k + w[i]) >>> 0;
28
+ e = d;
29
+ d = c;
30
+ c = rol(b, 30);
31
+ b = a;
32
+ a = t;
33
+ }
34
+ h[0] = (h[0] + a) >>> 0;
35
+ h[1] = (h[1] + b) >>> 0;
36
+ h[2] = (h[2] + c) >>> 0;
37
+ h[3] = (h[3] + d) >>> 0;
38
+ h[4] = (h[4] + e) >>> 0;
39
+ }
40
+ const out = new Uint8Array(20), ov = new DataView(out.buffer);
41
+ for (let i = 0; i < 5; i++)
42
+ ov.setUint32(i * 4, h[i]);
43
+ return out;
44
+ }
45
+ export class Rc4 {
46
+ state = Uint8Array.from({ length: 256 }, (_, i) => i);
47
+ i = 0;
48
+ j = 0;
49
+ constructor(key) { if (key.length < 1 || key.length > 256)
50
+ throw new PptError('CRYPTO_KEY', 'Invalid RC4 key length'); let j = 0; for (let i = 0; i < 256; i++) {
51
+ j = (j + this.state[i] + key[i % key.length]) & 255;
52
+ const t = this.state[i];
53
+ this.state[i] = this.state[j];
54
+ this.state[j] = t;
55
+ } }
56
+ crypt(bytes) { const out = new Uint8Array(bytes.length); for (let at = 0; at < bytes.length; at++) {
57
+ this.i = (this.i + 1) & 255;
58
+ this.j = (this.j + this.state[this.i]) & 255;
59
+ const t = this.state[this.i];
60
+ this.state[this.i] = this.state[this.j];
61
+ this.state[this.j] = t;
62
+ out[at] = bytes[at] ^ this.state[(this.state[this.i] + this.state[this.j]) & 255];
63
+ } return out; }
64
+ }
@@ -0,0 +1,5 @@
1
+ export declare class PptError extends Error {
2
+ readonly code: string;
3
+ readonly offset?: number;
4
+ constructor(code: string, message: string, offset?: number);
5
+ }
@@ -0,0 +1,5 @@
1
+ export class PptError extends Error {
2
+ code;
3
+ offset;
4
+ constructor(code, message, offset) { super(message); this.name = 'PptError'; this.code = code; this.offset = offset; }
5
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Small RFC1950/zlib + RFC1951/DEFLATE inflater.
3
+ *
4
+ * OfficeArt stores EMF/WMF BLIPs behind OfficeArtMetafileHeader.compression=0x00
5
+ * using the zlib wrapper defined by RFC1950. Keeping this inflater dependency-free
6
+ * preserves the browser-only build while still allowing the synchronous MS-DOC
7
+ * parser to expose browser-displayable SVG assets.
8
+ */
9
+ /** Raw RFC 1951 DEFLATE for ZIP entries; the caller verifies the container CRC. */
10
+ export declare function inflateRaw(bytes: Uint8Array, expectedLength: number, maxLength?: number): Uint8Array | null;
11
+ export declare function inflateZlib(bytes: Uint8Array, expectedLength?: number, maxLength?: number): Uint8Array | null;