@file-viewer/assets-ppt 3.3.1 → 3.3.4

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,508 @@
1
+ import { PptError } from '../core/errors.js';
2
+ import { trimTrailingNulls } from '../core/utils.js';
3
+ import { RT } from './constants.js';
4
+ import { readRecords } from './records.js';
5
+ import { adjustedPresetGeometry, customGeometry, officeArray } from './geometry.js';
6
+ import { parseTextFrames } from './text.js';
7
+ import { parseInlinePicture } from './pictures.js';
8
+ const boolProps = new Set([127, 191, 255, 319, 383, 447, 511, 575, 639, 703, 767, 831, 895, 959, 1023]);
9
+ const dataView = (bytes, record) => new DataView(bytes.buffer, bytes.byteOffset + record.dataOffset, record.length);
10
+ const fixed = (value) => (value | 0) / 65536;
11
+ const colorIndex = (value) => value & 0x08000000 ? value & 255 : undefined;
12
+ const clamp = (n, min = 0, max = 1) => Math.max(min, Math.min(max, n));
13
+ const utf16 = new TextDecoder('utf-16le');
14
+ const assetBudgets = new WeakMap();
15
+ // Complex properties participate in the same default/master/shape cascade as
16
+ // scalar values. Keep their byte views in a parse-scoped ephemeron: the resulting
17
+ // document must not retain its complete source buffer merely to render a shape.
18
+ const defaultComplexProperties = new WeakMap();
19
+ const shapeComplexProperties = new WeakMap();
20
+ // These properties have an IMsoArray payload with a defined element width.
21
+ // Some binary producers store only the element-data length in op, excluding
22
+ // the six-byte array header. Do not apply that convention to strings or BLIPs.
23
+ const arrayElementSizes = new Map([[325, [4, 8, 0xFFF0]], [326, [2]], [337, [8, 0xFFF0]], [338, [4]], [341, [36]], [342, [8]], [343, [16]], [407, [8]]]);
24
+ function warn(ctx, code, message, record, shapeId) {
25
+ ctx.diagnostics.push({ code, severity: 'warning', message, offset: record.offset, shapeId });
26
+ }
27
+ /** fUse bits occupy the upper half-word. Unspecified Boolean bits inherit. */
28
+ function mergeProperty(id, base, next) {
29
+ if (base === undefined || !boolProps.has(id))
30
+ return next;
31
+ const used = next >>> 16;
32
+ return (((base & 0xFFFF & ~used) | (next & used)) | (((base >>> 16) | used) << 16)) >>> 0;
33
+ }
34
+ export function readProperties(record, bytes, diagnostics) {
35
+ const values = new Map(), complex = new Map();
36
+ const count = record.instance;
37
+ if (count * 6 > record.length) {
38
+ diagnostics.push({ code: 'FOPT_LENGTH', severity: 'warning', message: 'Property entries exceed FOPT payload', offset: record.offset });
39
+ return { values, complex };
40
+ }
41
+ const view = dataView(bytes, record);
42
+ let extra = record.dataOffset + count * 6;
43
+ let declared = 0;
44
+ for (let i = 0; i < count; i++)
45
+ if (view.getUint16(i * 6, true) & 0x8000)
46
+ declared += view.getUint32(i * 6 + 2, true);
47
+ // An omitted header can only consume otherwise unassigned bytes. Reserving
48
+ // every subsequent declared payload prevents recovery from stealing it.
49
+ let spare = record.end - extra - declared;
50
+ const recovered = [];
51
+ for (let i = 0; i < count; i++) {
52
+ const op = view.getUint16(i * 6, true), id = op & 0x3FFF, value = view.getUint32(i * 6 + 2, true);
53
+ values.set(id, mergeProperty(id, values.get(id), value));
54
+ complex.delete(id);
55
+ if (op & 0x8000) {
56
+ let length = value;
57
+ if (spare >= 6 && extra + 6 <= record.end && arrayElementSizes.has(id)) {
58
+ const at = extra - record.dataOffset, n = view.getUint16(at, true), allocated = view.getUint16(at + 2, true), rawSize = view.getUint16(at + 4, true), size = rawSize === 0xFFF0 ? 4 : rawSize;
59
+ if (n <= allocated && arrayElementSizes.get(id).includes(rawSize) && n * size === value) {
60
+ length += 6;
61
+ spare -= 6;
62
+ recovered.push(id);
63
+ }
64
+ }
65
+ if (extra + length > record.end) {
66
+ diagnostics.push({ code: 'FOPT_COMPLEX_LENGTH', severity: 'warning', message: `Complex property ${id} exceeds FOPT payload`, offset: record.offset });
67
+ break;
68
+ }
69
+ complex.set(id, bytes.subarray(extra, extra + length));
70
+ extra += length;
71
+ }
72
+ }
73
+ if (recovered.length)
74
+ diagnostics.push({ code: 'FOPT_ARRAY_LENGTH_COMPAT', severity: 'info', message: 'OfficeArt array lengths exclude their six-byte headers; bounded array headers were included when locating complex properties', offset: record.offset, details: { properties: recovered } });
75
+ return { values, complex };
76
+ }
77
+ function nested(record, ctx) {
78
+ if (record.children.length || !record.length)
79
+ return record.children;
80
+ const reader = { ...ctx, count: ctx.recordCount?.value ?? 0 };
81
+ try {
82
+ record.children = readRecords(reader, record.dataOffset, record.end);
83
+ return record.children;
84
+ }
85
+ finally {
86
+ if (ctx.recordCount)
87
+ ctx.recordCount.value = reader.count;
88
+ }
89
+ }
90
+ export function readDrawingDefaults(drawingGroup, bytes, diagnostics, limits, recordCount) {
91
+ const defaults = {};
92
+ if (!drawingGroup)
93
+ return defaults;
94
+ const complex = new Map();
95
+ const roots = nested(drawingGroup, { bytes, diagnostics, limits, recordCount });
96
+ const group = roots.find(r => r.type === RT.OfficeArtDggContainer);
97
+ for (const r of group?.children ?? [])
98
+ if (r.type === RT.OfficeArtFOPT || r.type === RT.OfficeArtTertiaryFOPT) {
99
+ const properties = readProperties(r, bytes, diagnostics);
100
+ for (const [id, value] of properties.values) {
101
+ defaults[String(id)] = mergeProperty(id, defaults[String(id)], value);
102
+ complex.delete(id);
103
+ }
104
+ for (const [id, blob] of properties.complex)
105
+ complex.set(id, blob);
106
+ }
107
+ defaultComplexProperties.set(defaults, complex);
108
+ return defaults;
109
+ }
110
+ function boolValue(values, id, bit, fallback) {
111
+ const flags = values.get(id);
112
+ return flags !== undefined && (flags & (1 << (bit + 16))) !== 0 ? (flags & (1 << bit)) !== 0 : fallback;
113
+ }
114
+ export function officeColor(value, colors, fallback = '#000000') {
115
+ if (value & 0x08000000) {
116
+ const scheme = colors[value & 255];
117
+ if (scheme === undefined)
118
+ return fallback;
119
+ value = scheme;
120
+ }
121
+ else if (value & 0x10000000) {
122
+ // System palette entries are machine-dependent. The two standard window colors are stable.
123
+ if ((value & 255) === 5)
124
+ return '#ffffff';
125
+ if ((value & 255) === 8)
126
+ return '#000000';
127
+ return fallback;
128
+ }
129
+ return '#' + [value & 255, (value >>> 8) & 255, (value >>> 16) & 255].map(x => x.toString(16).padStart(2, '0')).join('');
130
+ }
131
+ function inlinePicture(blob, ctx, record, property) {
132
+ const offset = blob.byteOffset - ctx.bytes.byteOffset, id = `inline-image-${offset}-${property}`;
133
+ let budget = assetBudgets.get(ctx.assets);
134
+ if (!budget) {
135
+ budget = { count: 0, bytes: 0, ids: new Set() };
136
+ assetBudgets.set(ctx.assets, budget);
137
+ }
138
+ // A shared asset array can also receive sounds/OLE previews. Account for every new item.
139
+ while (budget.count < ctx.assets.length) {
140
+ const asset = ctx.assets[budget.count++];
141
+ budget.bytes += asset.bytes.byteLength;
142
+ budget.ids.add(asset.id);
143
+ }
144
+ if (budget.ids.has(id))
145
+ return id;
146
+ try {
147
+ const asset = parseInlinePicture(ctx.bytes, offset, blob.byteLength, id, ctx.diagnostics, ctx.limits.maxAssetBytes - budget.bytes);
148
+ ctx.assets.push(asset);
149
+ budget.count++;
150
+ budget.bytes += asset.bytes.byteLength;
151
+ budget.ids.add(id);
152
+ return id;
153
+ }
154
+ catch (error) {
155
+ if (error instanceof PptError && error.code === 'LIMIT_ASSETS')
156
+ throw error;
157
+ warn(ctx, 'INLINE_BLIP_INVALID', error instanceof Error ? error.message : String(error), record);
158
+ return undefined;
159
+ }
160
+ }
161
+ function fill(values, complex, ctx, record, preset) {
162
+ const open = preset === 20 || preset >= 32 && preset <= 40;
163
+ if (!boolValue(values, 447, 4, !open && preset !== 202 && preset !== 75))
164
+ return { kind: 'none' };
165
+ const rawColor = values.get(385) ?? 0xFFFFFF, rawBack = values.get(387) ?? 0xFFFFFF;
166
+ const color = officeColor(rawColor, ctx.colors, '#ffffff'), opacity = clamp(fixed(values.get(386) ?? 65536));
167
+ const type = values.get(384) ?? 0;
168
+ if (type >= 1 && type <= 3) {
169
+ const embedded = complex.get(390), assetId = embedded ? inlinePicture(embedded, ctx, record, 390) : ctx.pictureIds.get(values.get(390) ?? 0);
170
+ if (assetId)
171
+ return { kind: 'image', assetId, opacity, imageStyle: type === 1 ? 'pattern' : type === 2 ? 'texture' : 'picture', ...(type === 1 ? { color, colorIndex: colorIndex(rawColor), backColor: officeColor(rawBack, ctx.colors, '#ffffff'), backColorIndex: colorIndex(rawBack), backOpacity: clamp(fixed(values.get(388) ?? 65536)) } : {}) };
172
+ warn(ctx, 'FILL_IMAGE_MISSING', 'Pattern or picture fill has no usable embedded image; using its saved foreground color', record);
173
+ }
174
+ if (type >= 4 && type <= 8) {
175
+ const back = officeColor(rawBack, ctx.colors, '#ffffff'), backOpacity = clamp(fixed(values.get(388) ?? 65536));
176
+ let stops = [{ position: 0, color, colorIndex: colorIndex(rawColor), opacity }, { position: 1, color: back, colorIndex: colorIndex(rawBack), opacity: backOpacity }];
177
+ const shade = complex.get(407), arr = shade ? officeArray(shade) : undefined;
178
+ if (arr && arr.size === 8) {
179
+ stops = [];
180
+ for (let i = 0; i < arr.count; i++) {
181
+ const raw = arr.view.getUint32(6 + i * 8, true), position = clamp(fixed(arr.view.getUint32(6 + i * 8 + 4, true)));
182
+ stops.push({ position, color: officeColor(raw, ctx.colors), colorIndex: colorIndex(raw), opacity: opacity + (backOpacity - opacity) * position });
183
+ }
184
+ stops.sort((a, b) => a.position - b.position);
185
+ if (stops.length < 2)
186
+ stops = [{ position: 0, color, colorIndex: colorIndex(rawColor), opacity }, { position: 1, color: back, colorIndex: colorIndex(rawBack), opacity: backOpacity }];
187
+ }
188
+ // MS-ODRAW 2.3.7.15 Figure 5: positive focus puts the last color inside,
189
+ // negative focus puts the first color inside; +/-100 reverse the gradient.
190
+ const focus = clamp((values.get(396) ?? 0) | 0, -100, 100);
191
+ if (Math.abs(focus) === 100)
192
+ stops = stops.map(s => ({ ...s, position: 1 - s.position })).reverse();
193
+ else if (focus !== 0) {
194
+ const center = focus > 0 ? 1 - focus / 100 : -focus / 100;
195
+ const left = focus > 0 ? stops : [...stops].reverse().map(s => ({ ...s, position: 1 - s.position }));
196
+ const right = [...left].reverse().map(s => ({ ...s, position: 1 - s.position }));
197
+ stops = [...left.map(s => ({ ...s, position: s.position * center })), ...right.slice(1).map(s => ({ ...s, position: center + s.position * (1 - center) }))];
198
+ }
199
+ const gradientRect = { left: clamp(fixed(values.get(397) ?? 0)), top: clamp(fixed(values.get(398) ?? 0)), right: clamp(fixed(values.get(399) ?? 0)), bottom: clamp(fixed(values.get(400) ?? 0)) };
200
+ const gradientType = type === 5 ? 'rectangular' : type === 6 ? 'shape' : 'linear';
201
+ if (type === 8)
202
+ warn(ctx, 'FILL_GRADIENT_TITLE_APPROXIMATED', 'Host-defined title gradient uses its saved linear angle and stops', record);
203
+ if (type === 5 || type === 6)
204
+ ctx.diagnostics.push({ code: 'FILL_GRADIENT_SAMPLED', severity: 'info', message: 'Concentric gradient is rendered with 96 bounded color intervals', offset: record.offset, details: { fillType: type, steps: 96 } });
205
+ return { kind: 'gradient', gradientType, gradientScaled: type === 7, gradientRect, gradientCenter: { x: (gradientRect.left + gradientRect.right) / 2, y: (gradientRect.top + gradientRect.bottom) / 2 }, rotateWithShape: boolValue(values, 447, 5, false), angle: -90 - fixed(values.get(395) ?? 0), stops, opacity: 1 };
206
+ }
207
+ if (type === 9)
208
+ return { kind: 'none' };
209
+ return { kind: 'solid', color, colorIndex: colorIndex(rawColor), opacity };
210
+ }
211
+ function line(values, ctx, preset) {
212
+ if (!boolValue(values, 511, 3, preset !== 202 && preset !== 75))
213
+ return undefined;
214
+ const width = Math.max(0, ((values.get(0x01CB) ?? 9525) | 0) / 9525);
215
+ const rawColor = values.get(448) ?? 0;
216
+ const result = { color: officeColor(rawColor, ctx.colors), colorIndex: colorIndex(rawColor), width, opacity: clamp(fixed(values.get(449) ?? 65536)) };
217
+ const dashes = { 1: [3, 1], 2: [1, 1], 3: [3, 1, 1, 1], 4: [3, 1, 1, 1, 1, 1], 5: [1, 3], 6: [4, 3], 7: [8, 3], 8: [4, 3, 1, 3], 9: [8, 3, 1, 3], 10: [8, 3, 1, 3, 1, 3] };
218
+ const dash = dashes[values.get(0x01CE) ?? 0];
219
+ if (dash)
220
+ result.dash = dash.map(x => x * (width || 1));
221
+ const arrows = { 1: 'triangle', 2: 'stealth', 3: 'diamond', 4: 'oval', 5: 'open' };
222
+ result.startArrow = arrows[values.get(0x01D0) ?? 0];
223
+ result.endArrow = arrows[values.get(0x01D1) ?? 0];
224
+ result.cap = values.get(0x01D7) === 0 ? 'round' : values.get(0x01D7) === 1 ? 'square' : 'butt';
225
+ return result;
226
+ }
227
+ function shadow(values, ctx) {
228
+ if (!boolValue(values, 575, 1, false))
229
+ return undefined;
230
+ const type = values.get(512) ?? 0;
231
+ if (![0, 1, 5].includes(type))
232
+ return undefined;
233
+ const rawColor = values.get(513) ?? 0x00808080;
234
+ // MS-ODRAW 2.3.13.22 recommends ignoring shadowSoftness; ordinary binary shadows are hard-edged.
235
+ const offsetX = ((values.get(517) ?? 25400) | 0) / 9525, offsetY = ((values.get(518) ?? 25400) | 0) / 9525, highlight = values.get(514) ?? 0x00CBCBCB;
236
+ if (type === 0 && !boolValue(values, 575, 0, false))
237
+ return { type: 0, color: officeColor(rawColor, ctx.colors, '#808080'), colorIndex: colorIndex(rawColor), opacity: clamp(fixed(values.get(516) ?? 65536)), offsetX, offsetY, blur: 0 };
238
+ return { type: type, color: officeColor(rawColor, ctx.colors, '#808080'), colorIndex: colorIndex(rawColor), opacity: clamp(fixed(values.get(516) ?? 65536)), offsetX, offsetY, blur: 0, secondOffsetX: type === 5 ? -offsetX : ((values.get(519) ?? 0) | 0) / 9525, secondOffsetY: type === 5 ? -offsetY : ((values.get(520) ?? 0) | 0) / 9525, highlightColor: officeColor(highlight, ctx.colors, '#cbcbcb'), highlightColorIndex: colorIndex(highlight), originX: fixed(values.get(528) ?? 0) / 9525, originY: fixed(values.get(529) ?? 0) / 9525, obscured: boolValue(values, 575, 0, false) };
239
+ }
240
+ function wordArt(values, complex, ctx, preset, record) {
241
+ const bytes = complex.get(192);
242
+ if (!bytes || !boolValue(values, 255, 14, true))
243
+ return undefined;
244
+ if (bytes.byteLength > ctx.limits.maxTextLength * 2)
245
+ throw new PptError('LIMIT_TEXT', 'WordArt text exceeds the configured character limit', record.offset);
246
+ const font = complex.get(197), align = values.get(194) ?? 1;
247
+ return { text: trimTrailingNulls(utf16.decode(bytes)), fontFamily: font ? trimTrailingNulls(utf16.decode(font)) : 'Arial', fontSize: Math.max(1, fixed(values.get(195) ?? 36 * 65536) * 4 / 3), spacing: clamp(fixed(values.get(196) ?? 65536), 0, 5), bold: boolValue(values, 255, 5, false), italic: boolValue(values, 255, 4, false), vertical: boolValue(values, 255, 13, false), alignment: align === 2 ? 'left' : align === 3 ? 'right' : align === 0 || align === 4 || align === 5 ? 'justify' : 'center', warpPreset: preset, adjustments: Array.from({ length: 8 }, (_, i) => (values.get(327 + i) ?? (i === 0 ? 5400 : 0)) | 0) };
248
+ }
249
+ function extrusion(values, ctx, record, id) {
250
+ if (!boolValue(values, 703, 3, false))
251
+ return undefined;
252
+ const constrain = boolValue(values, 767, 4, true), parallel = boolValue(values, 767, 2, true), useColor = boolValue(values, 703, 1, false), rawColor = useColor ? (values.get(647) ?? 0x100000F7) : (values.get(385) ?? 0xFFFFFF), base = officeColor(values.get(385) ?? 0xFFFFFF, ctx.colors, '#ffffff');
253
+ const unsupported = [...values.keys()].filter(key => key >= 640 && key <= 767 && ![641, 644, 645, 647, 703, 704, 705, 715, 716, 717, 718, 719, 720, 721, 722, 767].includes(key));
254
+ if (!constrain || unsupported.length)
255
+ ctx.diagnostics.push({ code: 'EXTRUSION_PARAMETERS_UNSUPPORTED', severity: 'warning', message: 'Custom rotation axes, light vectors, bevel, or specular parameters are retained; supported extrusion uses constrained rotations and diffuse shading', offset: record.offset, shapeId: id, details: { properties: unsupported, constrainedRotation: constrain } });
256
+ ctx.diagnostics.push({ code: 'EXTRUSION_SHADING_APPROXIMATED', severity: 'warning', message: '3D shape uses a tessellated side mesh with diffuse lighting; Office material and lighting parity is not claimed', offset: record.offset, shapeId: id });
257
+ // The published viewpoint pages describe FixedPoint EMUs, but their default
258
+ // constants and independently rendered binary files use signed EMU magnitudes.
259
+ // Keep this compatibility interpretation visible until PowerPoint validation.
260
+ if (!parallel)
261
+ ctx.diagnostics.push({ code: 'EXTRUSION_CAMERA_UNITS_COMPAT', severity: 'warning', message: 'Perspective camera uses signed EMU magnitudes consistent with saved binary defaults; the published FixedPoint unit wording is ambiguous', offset: record.offset, shapeId: id });
262
+ return { depth: clamp(((values.get(645) ?? 457200) | 0), 0, 0x07445A00) / 9525, forward: clamp(((values.get(644) ?? 0) | 0), 0, 0x007445A0) / 9525, rotationY: constrain ? clamp(fixed(values.get(704) ?? 0), -90, 90) : 0, rotationX: constrain ? clamp(fixed(values.get(705) ?? 0), -90, 90) : 0, skewAngle: fixed(values.get(720) ?? 0xFF790000), skewAmount: clamp((values.get(721) ?? 50) | 0, -100, 100), color: officeColor(rawColor, ctx.colors, base), colorIndex: colorIndex(rawColor), ambient: clamp(fixed(values.get(722) ?? 20000)), diffuse: clamp(fixed(values.get(641) ?? 65536)), metallic: boolValue(values, 703, 2, false), parallel, camera: parallel ? undefined : { x: ((values.get(715) ?? 1250000) | 0) / 9525, y: ((values.get(716) ?? -1250000) | 0) / 9525, z: ((values.get(717) ?? 9000000) | 0) / 9525 }, origin: parallel ? undefined : { x: fixed(values.get(718) ?? 32768), y: fixed(values.get(719) ?? -32768) } };
263
+ }
264
+ /** PPT client anchors differ from ODRAW child anchors: top comes before left. */
265
+ export function readAnchor(record, bytes) {
266
+ const v = dataView(bytes, record);
267
+ let left, top, right, bottom;
268
+ if (record.type === RT.OfficeArtClientAnchor && record.length === 8) {
269
+ top = v.getInt16(0, true);
270
+ left = v.getInt16(2, true);
271
+ right = v.getInt16(4, true);
272
+ bottom = v.getInt16(6, true);
273
+ }
274
+ else if (record.length >= 16) {
275
+ if (record.type === RT.OfficeArtClientAnchor) {
276
+ top = v.getInt32(0, true);
277
+ left = v.getInt32(4, true);
278
+ }
279
+ else {
280
+ left = v.getInt32(0, true);
281
+ top = v.getInt32(4, true);
282
+ }
283
+ right = v.getInt32(8, true);
284
+ bottom = v.getInt32(12, true);
285
+ }
286
+ else
287
+ return undefined;
288
+ return { x: left / 6, y: top / 6, width: (right - left) / 6, height: (bottom - top) / 6 };
289
+ }
290
+ function cloneText(text) {
291
+ return { ...text, margins: { ...text.margins }, paragraphs: text.paragraphs.map(p => ({ ...p, style: { ...p.style, bullet: p.style.bullet ? { ...p.style.bullet } : undefined }, runs: p.runs.map(r => ({ ...r, style: { ...r.style } })) })) };
292
+ }
293
+ function textForShape(records, values, complex, ctx, record) {
294
+ let frame;
295
+ for (const box of records.filter(r => r.type === RT.OfficeArtClientTextBox)) {
296
+ const content = nested(box, ctx), outline = content.find(r => r.type === RT.OutlineTextRefAtom);
297
+ if (outline && outline.length >= 4) {
298
+ const index = dataView(ctx.bytes, outline).getUint32(0, true), found = ctx.slideTexts[index];
299
+ if (found)
300
+ frame = cloneText(found);
301
+ else
302
+ warn(ctx, 'OUTLINE_TEXT_MISSING', `Text outline index ${index} is not present in the slide text list`, outline);
303
+ }
304
+ const own = parseTextFrames(content, ctx);
305
+ if (own.length)
306
+ frame = own[0];
307
+ }
308
+ const wordart = complex.get(192);
309
+ if (!frame && wordart) {
310
+ if (wordart.byteLength > ctx.limits.maxTextLength * 2)
311
+ throw new PptError('LIMIT_TEXT', 'WordArt text exceeds the configured character limit', record.offset);
312
+ const text = trimTrailingNulls(utf16.decode(wordart));
313
+ const font = complex.get(197), fontFamily = font ? trimTrailingNulls(utf16.decode(font)) : undefined;
314
+ frame = { paragraphs: [{ level: 0, style: { alignment: 'center' }, runs: [{ text, style: { fontFamily, fontSize: fixed(values.get(195) ?? 36 * 65536) * 4 / 3, color: officeColor(values.get(385) ?? 0, ctx.colors), colorIndex: colorIndex(values.get(385) ?? 0) } }] }], margins: { left: 0, top: 0, right: 0, bottom: 0 }, verticalAlignment: 'middle', wrap: true, sourceText: text };
315
+ }
316
+ if (!frame)
317
+ return undefined;
318
+ for (const p of frame.paragraphs) {
319
+ for (const r of p.runs)
320
+ if (r.style.colorIndex !== undefined)
321
+ r.style.color = officeColor(0x08000000 | r.style.colorIndex, ctx.colors, r.style.color);
322
+ if (p.style.bullet?.colorIndex !== undefined)
323
+ p.style.bullet.color = officeColor(0x08000000 | p.style.bullet.colorIndex, ctx.colors, p.style.bullet.color);
324
+ }
325
+ frame.margins = { left: ((values.get(129) ?? 91440) | 0) / 9525, top: ((values.get(130) ?? 45720) | 0) / 9525, right: ((values.get(131) ?? 91440) | 0) / 9525, bottom: ((values.get(132) ?? 45720) | 0) / 9525 };
326
+ const anchor = values.get(135) ?? 0;
327
+ frame.verticalAlignment = anchor === 1 || anchor === 4 ? 'middle' : anchor === 2 || anchor === 5 || anchor === 7 || anchor === 9 ? 'bottom' : 'top';
328
+ frame.wrap = (values.get(133) ?? 0) !== 2;
329
+ // MS-ODRAW 2.3.21.15: fFitShapeToText is low bit 1 / use bit 17.
330
+ // The neighboring low bit 0 is reserved; it is not evidence for text shrinking.
331
+ frame.autofit = boolValue(values, 191, 1, false) ? 'resize' : 'none';
332
+ const flow = values.get(136) ?? 0;
333
+ if (flow === 1 || flow === 3 || flow === 5)
334
+ frame.direction = 'vertical';
335
+ else if (flow === 2)
336
+ frame.direction = 'vertical270';
337
+ return frame;
338
+ }
339
+ function getPlaceholder(records, ctx) {
340
+ for (const client of records.filter(r => r.type === RT.OfficeArtClientData))
341
+ for (const r of nested(client, ctx))
342
+ if (r.type === RT.OEPlaceholderAtom && r.length >= 8) {
343
+ const v = dataView(ctx.bytes, r);
344
+ return { position: v.getUint32(0, true), type: v.getUint8(4) };
345
+ }
346
+ return undefined;
347
+ }
348
+ function flatten(shapes) { const out = []; for (const s of shapes) {
349
+ out.push(s);
350
+ if (s.children)
351
+ out.push(...flatten(s.children));
352
+ } return out; }
353
+ function shape(record, ctx, masters) {
354
+ const records = record.children, fsp = records.find(r => r.type === RT.OfficeArtFSP);
355
+ if (!fsp || fsp.length < 8) {
356
+ warn(ctx, 'SHAPE_HEADER', 'Shape container is missing its OfficeArtFSP', record);
357
+ return undefined;
358
+ }
359
+ if (++ctx.shapeCount.value > ctx.limits.maxShapes)
360
+ throw new PptError('LIMIT_SHAPES', 'Shape count exceeds the configured limit', record.offset);
361
+ const v = dataView(ctx.bytes, fsp), id = v.getUint32(0, true), flags = v.getUint32(4, true), preset = fsp.instance;
362
+ if (flags & 8)
363
+ return undefined;
364
+ const values = new Map(), complex = new Map();
365
+ const defaults = ctx.drawingDefaults;
366
+ for (const [key, value] of Object.entries(defaults ?? {}))
367
+ values.set(Number(key), value);
368
+ for (const [key, blob] of defaults ? defaultComplexProperties.get(defaults) ?? [] : [])
369
+ complex.set(key, blob);
370
+ const own = { values: new Map(), complex: new Map() };
371
+ for (const r of records)
372
+ if (r.type === RT.OfficeArtFOPT || r.type === RT.OfficeArtSecondaryFOPT || r.type === RT.OfficeArtTertiaryFOPT) {
373
+ const prop = readProperties(r, ctx.bytes, ctx.diagnostics);
374
+ for (const [key, value] of prop.values) {
375
+ own.values.set(key, mergeProperty(key, own.values.get(key), value));
376
+ own.complex.delete(key);
377
+ }
378
+ for (const [key, value] of prop.complex)
379
+ own.complex.set(key, value);
380
+ }
381
+ const placeholder = getPlaceholder(records, ctx);
382
+ const masterId = own.values.get(769) || undefined;
383
+ const master = masters.find(s => masterId !== undefined ? s.id === masterId : placeholder && s.placeholder && s.placeholder.type === placeholder.type && (s.placeholder.position === placeholder.position || placeholder.position === 0xFFFFFFFF));
384
+ for (const [key, value] of Object.entries(master?.source?.properties ?? {}))
385
+ if (/^\d+$/.test(key)) {
386
+ values.set(Number(key), mergeProperty(Number(key), values.get(Number(key)), value));
387
+ complex.delete(Number(key));
388
+ }
389
+ if (master)
390
+ for (const [key, blob] of shapeComplexProperties.get(ctx.bytes)?.get(master) ?? [])
391
+ complex.set(key, blob);
392
+ for (const [key, value] of own.values) {
393
+ values.set(key, mergeProperty(key, values.get(key), value));
394
+ complex.delete(key);
395
+ }
396
+ for (const [key, value] of own.complex)
397
+ complex.set(key, value);
398
+ const anchor = records.find(r => r.type === RT.OfficeArtChildAnchor) || records.find(r => r.type === RT.OfficeArtClientAnchor);
399
+ const bounds = (anchor ? readAnchor(anchor, ctx.bytes) : undefined) ?? (master ? { ...master.bounds } : undefined) ?? { x: 0, y: 0, width: 0, height: 0 };
400
+ if (!anchor && !master && !(flags & 5) && !(flags & 0x400))
401
+ warn(ctx, 'SHAPE_ANCHOR_MISSING', 'Shape has no usable anchor or matching master placeholder', record, id);
402
+ let flipH = !!(flags & 64), flipV = !!(flags & 128);
403
+ if (bounds.width < 0) {
404
+ bounds.x += bounds.width;
405
+ bounds.width = -bounds.width;
406
+ flipH = !flipH;
407
+ }
408
+ if (bounds.height < 0) {
409
+ bounds.y += bounds.height;
410
+ bounds.height = -bounds.height;
411
+ flipV = !flipV;
412
+ }
413
+ const nameBytes = complex.get(896), name = nameBytes ? trimTrailingNulls(utf16.decode(nameBytes)) : undefined;
414
+ const result = { id, kind: flags & 1 ? 'group' : 'shape', name, bounds, rotation: fixed(values.get(4) ?? 0), flipH, flipV, preset, fill: fill(values, complex, ctx, record, preset), line: line(values, ctx, preset), shadow: shadow(values, ctx), placeholder, hidden: boolValue(values, 959, 1, false), source: { offset: record.offset, recordType: record.type, shapeType: preset, properties: { ...Object.fromEntries(values), fspFlags: flags, hasAnchor: anchor ? 1 : 0 } } };
415
+ const group = records.find(r => r.type === RT.OfficeArtFSPGR);
416
+ if (group)
417
+ result.groupBounds = readAnchor(group, ctx.bytes);
418
+ result.text = textForShape(records, values, complex, ctx, record);
419
+ result.wordArt = wordArt(values, complex, ctx, preset, record);
420
+ if (result.wordArt)
421
+ warn(ctx, 'WORDART_ENVELOPE_APPROXIMATED', 'WordArt is rendered by deforming browser glyphs through a bounded envelope mesh; Office-specific font fitting and custom envelope formulas are not fully reproduced', record, id);
422
+ result.extrusion = extrusion(values, ctx, record, id);
423
+ const geometry = customGeometry(values, complex, ctx.diagnostics, id, record.offset, bounds);
424
+ if (geometry.path) {
425
+ result.path = geometry.path;
426
+ result.pathParts = geometry.pathParts;
427
+ result.pathBounds = geometry.pathBounds;
428
+ }
429
+ else if (!result.wordArt) {
430
+ const adjusted = adjustedPresetGeometry(preset, values, bounds);
431
+ if (adjusted) {
432
+ result.path = adjusted.path;
433
+ result.pathBounds = adjusted.pathBounds;
434
+ if (adjusted.approximate)
435
+ warn(ctx, 'PRESET_ADJUSTMENT_APPROXIMATED', `Preset ${preset} uses an analytic adjustable envelope; exact Office preset construction is not fully specified`, record, id);
436
+ }
437
+ }
438
+ if (geometry.noFill)
439
+ result.fill = { kind: 'none' };
440
+ if (geometry.noLine)
441
+ result.line = undefined;
442
+ const imageIndex = values.get(260), embeddedImage = complex.get(260);
443
+ if (imageIndex || embeddedImage) {
444
+ const assetId = embeddedImage ? inlinePicture(embeddedImage, ctx, record, 260) : ctx.pictureIds.get(imageIndex);
445
+ if (assetId) {
446
+ result.kind = 'image';
447
+ result.image = { assetId, crop: { top: fixed(values.get(256) ?? 0), bottom: fixed(values.get(257) ?? 0), left: fixed(values.get(258) ?? 0), right: fixed(values.get(259) ?? 0) }, brightness: clamp(((values.get(265) ?? 0) | 0) / 32768, -1, 1), contrast: Math.max(0, fixed(values.get(264) ?? 65536)) };
448
+ }
449
+ else {
450
+ result.kind = 'unsupported';
451
+ warn(ctx, 'SHAPE_IMAGE_MISSING', `Picture index ${imageIndex} has no available image bytes`, record, id);
452
+ }
453
+ }
454
+ // Content that needs dedicated semantic renderers remains visible in diagnostics.
455
+ const shadowActive = boolValue(values, 575, 1, false);
456
+ const shadowUnsupported = shadowActive && (!result.shadow || ![0, 1, 5].includes(result.shadow.type) || boolValue(values, 575, 0, false) && result.fill.kind === 'none');
457
+ const effectProperties = [...values.keys()].filter(key => shadowUnsupported && key >= 512 && key <= 575);
458
+ if (effectProperties.length) {
459
+ result.source.unsupportedProperties = effectProperties;
460
+ warn(ctx, 'SHAPE_EFFECT_UNSUPPORTED', 'Rich/shape/drawing shadow transforms or obscured unfilled interiors are preserved but not fully rendered', record, id);
461
+ }
462
+ if (own.complex.has(937))
463
+ ctx.diagnostics.push({ code: 'DRAWINGML_ALTERNATE_IGNORED', severity: 'info', message: 'Alternative DrawingML package is ignored as recommended by MS-ODRAW; its binary OfficeArt shape is used', offset: record.offset, shapeId: id, details: { property: 937, byteLength: own.complex.get(937).byteLength } });
464
+ if (flags & 16)
465
+ warn(ctx, 'OLE_PREVIEW_ONLY', 'OLE object uses its saved presentation preview; embedded application behavior is not executed', record, id);
466
+ let cache = shapeComplexProperties.get(ctx.bytes);
467
+ if (!cache) {
468
+ cache = new WeakMap();
469
+ shapeComplexProperties.set(ctx.bytes, cache);
470
+ }
471
+ cache.set(result, complex);
472
+ return result;
473
+ }
474
+ /** Shape tree order is paint order; patriarch groups only establish the drawing root. */
475
+ export function parseDrawing(record, ctx) {
476
+ const masters = flatten(ctx.masterShapes ?? []);
477
+ const collect = (nodes, depth) => {
478
+ if (depth > ctx.limits.maxDepth)
479
+ throw new PptError('LIMIT_DEPTH', 'OfficeArt group nesting exceeds limit', record.offset);
480
+ const out = [];
481
+ for (const node of nodes) {
482
+ if (node.type === RT.OfficeArtSpgrContainer) {
483
+ const first = node.children.find(r => r.type === RT.OfficeArtSpContainer), header = first ? shape(first, ctx, masters) : undefined;
484
+ const children = collect(node.children.filter(r => r !== first), depth + 1);
485
+ if (header && !(header.source.properties.fspFlags & 4)) {
486
+ header.kind = 'group';
487
+ header.children = children;
488
+ header.fill = { kind: 'none' };
489
+ header.line = undefined;
490
+ if (header.bounds.width === 0 && header.bounds.height === 0 && header.groupBounds)
491
+ header.bounds = { ...header.groupBounds };
492
+ out.push(header);
493
+ }
494
+ else
495
+ out.push(...children);
496
+ }
497
+ else if (node.type === RT.OfficeArtSpContainer) {
498
+ const s = shape(node, ctx, masters);
499
+ if (s)
500
+ out.push(s);
501
+ }
502
+ else if (node.type === RT.OfficeArtDgContainer || node.type === RT.PPDrawing)
503
+ out.push(...collect(nested(node, ctx), depth + 1));
504
+ }
505
+ return out;
506
+ };
507
+ return collect(record.type === RT.OfficeArtDgContainer ? [record] : nested(record, ctx), 0);
508
+ }
@@ -0,0 +1,14 @@
1
+ /** Password-based legacy PPT decryption, independently implemented from:
2
+ * [MS-PPT] 2.3.7 CryptSession10Container;
3
+ * [MS-OFFCRYPTO] 2.3.5 RC4 CryptoAPI, 2.3.2 header, 2.3.3 verifier;
4
+ * [MS-ODRAW] 2.2.22–2.2.32 picture field layouts.
5
+ * Only the supplied password is tested. Source CFB streams are never modified. */
6
+ import type { Diagnostic, ParseLimits } from '../types.js';
7
+ import type { CompoundFile } from '../core/cfb.js';
8
+ export interface DecryptedPptStreams {
9
+ document: Uint8Array;
10
+ currentUser: Uint8Array;
11
+ pictures: Uint8Array;
12
+ }
13
+ /** Return owned plaintext streams, or undefined for an unencrypted presentation. */
14
+ export declare function decryptPptStreams(cfb: CompoundFile, password: string | undefined, limits: ParseLimits, diagnostics: Diagnostic[]): DecryptedPptStreams | undefined;