@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,254 @@
1
+ /** TIFF 6.0, sections 2–9, 13–19. Original implementation from the format specification. */
2
+ import { PptError } from './errors.js';
3
+ import { inflateZlib } from './inflate.js';
4
+ import { encodeRgbaPng, unpackBits } from './raster.js';
5
+ /** TIFF's MSB-first LZW with the early code-width change, unlike GIF. */
6
+ export function decodeTiffLzw(bytes, expected) {
7
+ if (!Number.isSafeInteger(expected) || expected < 0 || expected > 256 * 1024 * 1024)
8
+ throw new PptError('LIMIT_ASSETS', 'LZW output exceeds the raster limit');
9
+ const out = new Uint8Array(expected), prefix = new Int16Array(4096), suffix = new Uint8Array(4096), stack = new Uint8Array(4097);
10
+ let bit = 0, bits = 9, next = 258, previous = -1, q = 0, ended = false;
11
+ const code = () => { if (bit + bits > bytes.length * 8)
12
+ throw new PptError('TIFF_LZW', 'Truncated LZW code'); let value = 0; for (let i = 0; i < bits; i++, bit++)
13
+ value = (value << 1) | ((bytes[bit >>> 3] >> (7 - (bit & 7))) & 1); return value; };
14
+ const expand = (value) => { let length = 0; while (value >= 256) {
15
+ if (value >= next || length >= 4096)
16
+ throw new PptError('TIFF_LZW', 'Invalid LZW dictionary reference');
17
+ stack[length++] = suffix[value];
18
+ value = prefix[value];
19
+ } stack[length++] = value; return length; };
20
+ if (code() !== 256)
21
+ throw new PptError('TIFF_LZW', 'LZW strip must start with a clear code');
22
+ while (bit + bits <= bytes.length * 8) {
23
+ const value = code();
24
+ if (value === 257) {
25
+ ended = true;
26
+ break;
27
+ }
28
+ if (value === 256) {
29
+ bits = 9;
30
+ next = 258;
31
+ previous = -1;
32
+ continue;
33
+ }
34
+ if (value > next || value === next && previous < 0)
35
+ throw new PptError('TIFF_LZW', 'Invalid LZW code');
36
+ const special = value === next, length = expand(special ? previous : value), first = stack[length - 1];
37
+ if (q + length + (special ? 1 : 0) > expected)
38
+ throw new PptError('TIFF_LZW', 'LZW expands beyond the declared strip');
39
+ for (let i = length - 1; i >= 0; i--)
40
+ out[q++] = stack[i];
41
+ if (special)
42
+ out[q++] = first;
43
+ if (previous >= 0 && next < 4096) {
44
+ prefix[next] = previous;
45
+ suffix[next] = first;
46
+ next++;
47
+ if (next === (1 << bits) - 1 && bits < 12)
48
+ bits++;
49
+ }
50
+ previous = value;
51
+ }
52
+ if (!ended || q !== expected)
53
+ throw new PptError('TIFF_LZW', 'LZW end marker or decoded size is invalid');
54
+ return out;
55
+ }
56
+ /** Decode a chosen IFD; all pixel/strip/tile allocations are preflighted. */
57
+ export function decodeTiff(bytes, options = {}) {
58
+ const limit = options.maxDecodedBytes ?? 128 * 1024 * 1024;
59
+ if (!Number.isSafeInteger(limit) || limit < 1)
60
+ throw new PptError('INVALID_LIMIT', 'Invalid TIFF byte budget');
61
+ if (bytes.length < 8)
62
+ throw new PptError('TIFF_HEADER', 'Truncated TIFF header');
63
+ const little = bytes[0] === 73 && bytes[1] === 73;
64
+ if (!little && !(bytes[0] === 77 && bytes[1] === 77))
65
+ throw new PptError('TIFF_HEADER', 'TIFF must start with II or MM');
66
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
67
+ const need = (at, size) => { if (!Number.isSafeInteger(at) || !Number.isSafeInteger(size) || at < 0 || size < 0 || at + size > bytes.length)
68
+ throw new PptError('TIFF_BOUNDS', 'TIFF field points outside the image', at); };
69
+ const u16 = (at) => { need(at, 2); return view.getUint16(at, little); }, u32 = (at) => { need(at, 4); return view.getUint32(at, little); };
70
+ if (u16(2) !== 42)
71
+ throw new PptError('TIFF_VERSION', 'BigTIFF and unknown TIFF versions are not supported');
72
+ const offsets = [], seen = new Set();
73
+ let at = u32(4);
74
+ while (at) {
75
+ if (seen.has(at))
76
+ throw new PptError('TIFF_IFD_CYCLE', 'Cycle in TIFF image directories', at);
77
+ if (offsets.length >= 4096)
78
+ throw new PptError('LIMIT_ASSETS', 'Too many TIFF image directories');
79
+ seen.add(at);
80
+ offsets.push(at);
81
+ const count = u16(at);
82
+ need(at + 2, count * 12 + 4);
83
+ at = u32(at + 2 + count * 12);
84
+ }
85
+ const page = options.page ?? 0;
86
+ if (!Number.isInteger(page) || page < 0 || page >= offsets.length)
87
+ throw new PptError('TIFF_PAGE', 'TIFF page is out of range');
88
+ at = offsets[page];
89
+ const tags = new Map(), fieldSizes = [0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8];
90
+ for (let i = 0, count = u16(at); i < count; i++) {
91
+ const p = at + 2 + i * 12, tag = u16(p), type = u16(p + 2), count = u32(p + 4), unit = fieldSizes[type];
92
+ if (!unit)
93
+ continue;
94
+ const size = count * unit, base = size <= 4 ? p + 8 : u32(p + 8);
95
+ need(base, size);
96
+ // Only numeric fields used below are materialized; unknown large metadata stays opaque.
97
+ if (![256, 257, 258, 259, 262, 266, 273, 274, 277, 278, 279, 284, 317, 320, 322, 323, 324, 325, 338, 339].includes(tag))
98
+ continue;
99
+ if (count > Math.min(1_000_000, limit / 8))
100
+ throw new PptError('LIMIT_ASSETS', 'TIFF numeric field exceeds the metadata budget');
101
+ if (![1, 3, 4].includes(type))
102
+ throw new PptError('TIFF_FIELD', 'Unsupported type for a required numeric TIFF field', p);
103
+ if (tags.has(tag))
104
+ throw new PptError('TIFF_FIELD', 'Duplicate required TIFF field', p);
105
+ tags.set(tag, Array.from({ length: count }, (_, j) => type === 1 ? bytes[base + j] : type === 3 ? u16(base + j * 2) : u32(base + j * 4)));
106
+ }
107
+ const get = (id, fallback = 0) => tags.get(id)?.[0] ?? fallback;
108
+ const width = get(256), height = get(257), samples = get(277, 1), bits = tags.get(258) ?? [1], photo = get(262), compression = get(259, 1), planar = get(284, 1), predictor = get(317, 1), orientation = get(274, 1), fillOrder = get(266, 1), warnings = [];
109
+ if (!width || !height || width > 1000000 || height > 1000000 || samples < 1 || samples > 8 || width * height * (4 + samples * 2) > limit)
110
+ throw new PptError('LIMIT_ASSETS', 'TIFF raster exceeds the configured allocation budget');
111
+ if (bits.length !== 1 && bits.length !== samples || bits.some(b => ![1, 2, 4, 8, 16].includes(b)) || bits.some(b => b !== bits[0]))
112
+ throw new PptError('TIFF_BITS', 'Unsupported mixed or non-integer TIFF component depth');
113
+ if (![0, 1, 2, 3, 5].includes(photo))
114
+ throw new PptError('TIFF_COLORSPACE', `TIFF photometric interpretation ${photo} is not supported`);
115
+ if (photo === 2 && samples < 3 || photo === 5 && samples < 4 || photo === 3 && bits[0] > 8)
116
+ throw new PptError('TIFF_SAMPLES', 'Invalid TIFF component count or palette depth');
117
+ if (![1, 2].includes(planar) || ![1, 2].includes(predictor) || ![1, 2].includes(fillOrder) || orientation < 1 || orientation > 8 || (tags.get(339) ?? [1]).some(x => x !== 1))
118
+ throw new PptError('TIFF_LAYOUT', 'Unsupported TIFF planar, predictor, orientation, or sample layout');
119
+ if (![1, 5, 8, 32946, 32773].includes(compression))
120
+ throw new PptError('TIFF_COMPRESSION', `TIFF compression ${compression} is not implemented`);
121
+ const depth = bits[0], components = new Uint16Array(width * height * samples), tiled = tags.has(324), bw = tiled ? get(322) : width, bh = tiled ? get(323) : Math.min(height, get(278, height)), positions = tags.get(tiled ? 324 : 273), counts = tags.get(tiled ? 325 : 279);
122
+ if (!bw || !bh || !positions || !counts || positions.length !== counts.length)
123
+ throw new PptError('TIFF_STRIPS', 'Missing or inconsistent TIFF strips/tiles');
124
+ const nx = Math.ceil(width / bw), ny = Math.ceil(height / bh), perPlane = nx * ny, planes = planar === 2 ? samples : 1;
125
+ if (perPlane * planes !== positions.length)
126
+ throw new PptError('TIFF_STRIPS', 'TIFF strip/tile count does not match dimensions');
127
+ const channels = planar === 2 ? 1 : samples, rowBytes = Math.ceil(bw * channels * depth / 8);
128
+ for (let block = 0; block < positions.length; block++) {
129
+ const plane = Math.floor(block / perPlane), index = block % perPlane, x0 = index % nx * bw, y0 = Math.floor(index / nx) * bh, rows = tiled ? bh : Math.min(bh, height - y0), expected = rowBytes * rows;
130
+ if (expected > limit)
131
+ throw new PptError('LIMIT_ASSETS', 'TIFF tile/strip exceeds the raster budget');
132
+ need(positions[block], counts[block]);
133
+ let raw = bytes.subarray(positions[block], positions[block] + counts[block]);
134
+ if (compression === 1) {
135
+ if (raw.length !== expected)
136
+ throw new PptError('TIFF_STRIPS', 'Uncompressed TIFF strip has an inconsistent byte count');
137
+ raw = new Uint8Array(raw);
138
+ }
139
+ else if (compression === 32773)
140
+ raw = unpackBits(raw, expected);
141
+ else if (compression === 5)
142
+ raw = decodeTiffLzw(raw, expected);
143
+ else {
144
+ const decoded = inflateZlib(raw, expected, expected);
145
+ if (!decoded || decoded.length !== expected)
146
+ throw new PptError('TIFF_DEFLATE', 'Invalid Deflate TIFF strip');
147
+ raw = decoded;
148
+ }
149
+ if (fillOrder === 2) {
150
+ for (let k = 0; k < raw.length; k++) {
151
+ let b = raw[k];
152
+ b = ((b & 0x55) << 1) | ((b >>> 1) & 0x55);
153
+ b = ((b & 0x33) << 2) | ((b >>> 2) & 0x33);
154
+ raw[k] = ((b & 15) << 4) | (b >>> 4);
155
+ }
156
+ }
157
+ const rv = new DataView(raw.buffer, raw.byteOffset, raw.length), mask = 2 ** depth - 1, previous = new Uint16Array(channels);
158
+ for (let y = 0; y < rows; y++) {
159
+ previous.fill(0);
160
+ for (let x = 0; x < bw; x++)
161
+ for (let c = 0; c < channels; c++) {
162
+ const bpos = (x * channels + c) * depth, byte = y * rowBytes + (bpos >>> 3);
163
+ let value = depth === 16 ? rv.getUint16(byte, little) : depth === 8 ? raw[byte] : (raw[byte] >>> (8 - depth - (bpos & 7))) & mask;
164
+ if (predictor === 2) {
165
+ value = (value + previous[c]) & mask;
166
+ previous[c] = value;
167
+ }
168
+ if (x + x0 < width && y + y0 < height)
169
+ components[((y + y0) * width + x + x0) * samples + (planar === 2 ? plane : c)] = value;
170
+ }
171
+ }
172
+ }
173
+ const rotated = orientation >= 5, outWidth = rotated ? height : width, outHeight = rotated ? width : height, rgba = new Uint8Array(width * height * 4), max = 2 ** depth - 1, palette = tags.get(320), baseSamples = photo === 2 ? 3 : photo === 5 ? 4 : 1, extra = tags.get(338) ?? [], alphaIndex = extra.findIndex(v => v === 1 || v === 2), hasAlpha = alphaIndex >= 0 && baseSamples + alphaIndex < samples;
174
+ if (photo === 3 && (!palette || palette.length !== 3 * 2 ** depth))
175
+ throw new PptError('TIFF_PALETTE', 'TIFF color table is missing or incomplete');
176
+ if (photo === 5)
177
+ warnings.push('TIFF_CMYK_APPROXIMATION');
178
+ for (let y = 0; y < height; y++)
179
+ for (let x = 0; x < width; x++) {
180
+ let ox = x, oy = y;
181
+ switch (orientation) {
182
+ case 2:
183
+ ox = width - 1 - x;
184
+ break;
185
+ case 3:
186
+ ox = width - 1 - x;
187
+ oy = height - 1 - y;
188
+ break;
189
+ case 4:
190
+ oy = height - 1 - y;
191
+ break;
192
+ case 5:
193
+ ox = y;
194
+ oy = x;
195
+ break;
196
+ case 6:
197
+ ox = height - 1 - y;
198
+ oy = x;
199
+ break;
200
+ case 7:
201
+ ox = height - 1 - y;
202
+ oy = width - 1 - x;
203
+ break;
204
+ case 8:
205
+ ox = y;
206
+ oy = width - 1 - x;
207
+ break;
208
+ }
209
+ // Keep source precision through alpha unassociation, especially for low-alpha 16-bit pixels.
210
+ const p = (y * width + x) * samples, q = (oy * outWidth + ox) * 4, val = (c) => components[p + c] / max * 255;
211
+ let r = 0, g = 0, b = 0;
212
+ if (photo === 2) {
213
+ r = val(0);
214
+ g = val(1);
215
+ b = val(2);
216
+ }
217
+ else if (photo === 5) {
218
+ const k = val(3) / 255;
219
+ r = (255 - val(0)) * (1 - k);
220
+ g = (255 - val(1)) * (1 - k);
221
+ b = (255 - val(2)) * (1 - k);
222
+ }
223
+ else if (photo === 3) {
224
+ const index = components[p], size = 2 ** depth;
225
+ r = palette[index] >>> 8;
226
+ g = palette[index + size] >>> 8;
227
+ b = palette[index + size * 2] >>> 8;
228
+ }
229
+ else
230
+ r = g = b = photo === 0 ? 255 - val(0) : val(0);
231
+ const a = hasAlpha ? val(baseSamples + alphaIndex) : 255;
232
+ if (hasAlpha && extra[alphaIndex] === 1) {
233
+ const alpha = components[p + baseSamples + alphaIndex];
234
+ if (photo === 2) {
235
+ r = alpha ? components[p] / alpha * 255 : 0;
236
+ g = alpha ? components[p + 1] / alpha * 255 : 0;
237
+ b = alpha ? components[p + 2] / alpha * 255 : 0;
238
+ }
239
+ else {
240
+ r = a ? r * 255 / a : 0;
241
+ g = a ? g * 255 / a : 0;
242
+ b = a ? b * 255 / a : 0;
243
+ }
244
+ }
245
+ rgba.set([Math.round(Math.min(255, r)), Math.round(Math.min(255, g)), Math.round(Math.min(255, b)), Math.round(a)], q);
246
+ }
247
+ if (offsets.length > 1)
248
+ warnings.push('TIFF_MULTIPAGE');
249
+ return { width: outWidth, height: outHeight, rgba, pageCount: offsets.length, warnings };
250
+ }
251
+ export function tiffToPng(bytes, options = {}) {
252
+ const { rgba, ...image } = decodeTiff(bytes, options);
253
+ return { ...image, bytes: encodeRgbaPng(image.width, image.height, rgba, options.maxOutputBytes), mimeType: 'image/png' };
254
+ }
@@ -0,0 +1,9 @@
1
+ /** Small browser/Node utilities adapted from msdoc-viewer a42f4a2. */
2
+ import type { BinaryInput } from '../types.js';
3
+ /** Strip trailing NUL padding in linear time, preserving embedded NULs. */
4
+ export declare function trimTrailingNulls(value: string): string;
5
+ export declare function textDecoder(label?: string): TextDecoder;
6
+ export declare function escapeHtml(value: unknown): string;
7
+ export declare function bytesToBase64(input: BinaryInput): string;
8
+ export declare function dataUrlFromBytes(bytes: BinaryInput, mime?: string): string;
9
+ export declare function escapeXmlText(text: unknown): string;
@@ -0,0 +1,13 @@
1
+ /** Strip trailing NUL padding in linear time, preserving embedded NULs. */
2
+ export function trimTrailingNulls(value) {
3
+ let end = value.length;
4
+ while (end > 0 && value.charCodeAt(end - 1) === 0)
5
+ end--;
6
+ return end === value.length ? value : value.slice(0, end);
7
+ }
8
+ export function textDecoder(label = 'utf-8') { return new TextDecoder(label, { fatal: false }); }
9
+ export function escapeHtml(value) { return String(value).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;'); }
10
+ export function bytesToBase64(input) { const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : new Uint8Array(input.buffer, input.byteOffset, input.byteLength); let text = ''; for (let i = 0; i < bytes.length; i += 0x8000)
11
+ text += String.fromCharCode(...bytes.subarray(i, i + 0x8000)); return btoa(text); }
12
+ export function dataUrlFromBytes(bytes, mime = 'application/octet-stream') { return `data:${mime};base64,${bytesToBase64(bytes)}`; }
13
+ export function escapeXmlText(text) { return escapeHtml(String(text).replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, '')); }
@@ -0,0 +1,12 @@
1
+ import { BinaryReader } from '../core/binary.js';
2
+ export interface VectorFont {
3
+ family: string;
4
+ size: number;
5
+ weight?: number;
6
+ italic?: boolean;
7
+ underline?: boolean;
8
+ strike?: boolean;
9
+ escapement?: number;
10
+ }
11
+ export declare function readEmfFont(record: BinaryReader): VectorFont | null;
12
+ export declare function readWmfFont(record: BinaryReader): VectorFont | null;
@@ -0,0 +1,29 @@
1
+ export function readEmfFont(record) {
2
+ if (!record.ensure(12, 92))
3
+ return null;
4
+ const family = new TextDecoder('utf-16le').decode(record.slice(40, 64)).split('\0')[0] || 'sans-serif';
5
+ return {
6
+ family,
7
+ size: Math.abs(record.i32(12)) || 12,
8
+ escapement: record.i32(20),
9
+ weight: record.i32(28),
10
+ italic: Boolean(record.u8(32)),
11
+ underline: Boolean(record.u8(33)),
12
+ strike: Boolean(record.u8(34)),
13
+ };
14
+ }
15
+ export function readWmfFont(record) {
16
+ if (!record.ensure(6, 18))
17
+ return null;
18
+ const family = new TextDecoder('windows-1252').decode(record.slice(24, Math.min(32, record.length - 24)))
19
+ .split('\0')[0] || 'sans-serif';
20
+ return {
21
+ family,
22
+ size: Math.abs(record.i16(6)) || 12,
23
+ escapement: record.i16(10),
24
+ weight: record.i16(14),
25
+ italic: Boolean(record.u8(16)),
26
+ underline: Boolean(record.u8(17)),
27
+ strike: Boolean(record.u8(18)),
28
+ };
29
+ }
@@ -0,0 +1,19 @@
1
+ export interface VectorConversionLimits {
2
+ maxOutputBytes?: number;
3
+ maxRecords?: number;
4
+ maxPoints?: number;
5
+ maxObjects?: number;
6
+ maxStateDepth?: number;
7
+ }
8
+ export interface ConvertedVectorImage {
9
+ mime: 'image/svg+xml';
10
+ bytes: Uint8Array;
11
+ dataUrl: string;
12
+ width: number;
13
+ height: number;
14
+ sourceMime: 'image/emf' | 'image/wmf';
15
+ recordCount: number;
16
+ unresolvedGlyphRuns: number;
17
+ unsupportedRecordTypes: number[];
18
+ }
19
+ export declare function convertMetafileToSvg(mime: string, bytes: Uint8Array, options?: VectorConversionLimits): ConvertedVectorImage | null;