@file-viewer/assets-ppt 3.3.1 → 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.
- package/README.en.md +3 -1
- package/README.md +3 -1
- package/README.zh-CN.md +3 -1
- package/package.json +96 -9
- package/viewer/THIRD_PARTY_LICENSES.assets.json +837 -54
- package/viewer/file-viewer-asset-pack.json +20 -31
- package/viewer/vendor/ppt/LICENSE +160 -122
- package/viewer/vendor/ppt/NOTICE.md +30 -0
- package/viewer/vendor/ppt/README.md +86 -0
- package/viewer/vendor/ppt/dist/core/binary.d.ts +31 -0
- package/viewer/vendor/ppt/dist/core/binary.js +102 -0
- package/viewer/vendor/ppt/dist/core/cfb.d.ts +38 -0
- package/viewer/vendor/ppt/dist/core/cfb.js +208 -0
- package/viewer/vendor/ppt/dist/core/crypto.d.ts +12 -0
- package/viewer/vendor/ppt/dist/core/crypto.js +64 -0
- package/viewer/vendor/ppt/dist/core/errors.d.ts +5 -0
- package/viewer/vendor/ppt/dist/core/errors.js +5 -0
- package/viewer/vendor/ppt/dist/core/inflate.d.ts +11 -0
- package/viewer/vendor/ppt/dist/core/inflate.js +337 -0
- package/viewer/vendor/ppt/dist/core/pict.d.ts +14 -0
- package/viewer/vendor/ppt/dist/core/pict.js +472 -0
- package/viewer/vendor/ppt/dist/core/raster.d.ts +7 -0
- package/viewer/vendor/ppt/dist/core/raster.js +101 -0
- package/viewer/vendor/ppt/dist/core/tiff.d.ts +20 -0
- package/viewer/vendor/ppt/dist/core/tiff.js +254 -0
- package/viewer/vendor/ppt/dist/core/utils.d.ts +9 -0
- package/viewer/vendor/ppt/dist/core/utils.js +13 -0
- package/viewer/vendor/ppt/dist/core/vector-font.d.ts +12 -0
- package/viewer/vendor/ppt/dist/core/vector-font.js +29 -0
- package/viewer/vendor/ppt/dist/core/vector.d.ts +19 -0
- package/viewer/vendor/ppt/dist/core/vector.js +1570 -0
- package/viewer/vendor/ppt/dist/core/xml-text.d.ts +1 -0
- package/viewer/vendor/ppt/dist/core/xml-text.js +6 -0
- package/viewer/vendor/ppt/dist/index.d.ts +12 -0
- package/viewer/vendor/ppt/dist/index.js +8 -0
- package/viewer/vendor/ppt/dist/layout/measure.d.ts +15 -0
- package/viewer/vendor/ppt/dist/layout/measure.js +54 -0
- package/viewer/vendor/ppt/dist/layout/text-layout.d.ts +48 -0
- package/viewer/vendor/ppt/dist/layout/text-layout.js +272 -0
- package/viewer/vendor/ppt/dist/manifest.json +13 -0
- package/viewer/vendor/ppt/dist/playback/media.d.ts +11 -0
- package/viewer/vendor/ppt/dist/playback/media.js +37 -0
- package/viewer/vendor/ppt/dist/playback/navigation.d.ts +2 -0
- package/viewer/vendor/ppt/dist/playback/navigation.js +14 -0
- package/viewer/vendor/ppt/dist/playback/timeline.d.ts +47 -0
- package/viewer/vendor/ppt/dist/playback/timeline.js +154 -0
- package/viewer/vendor/ppt/dist/playback/transitions.d.ts +14 -0
- package/viewer/vendor/ppt/dist/playback/transitions.js +41 -0
- package/viewer/vendor/ppt/dist/ppt/animation.d.ts +3 -0
- package/viewer/vendor/ppt/dist/ppt/animation.js +67 -0
- package/viewer/vendor/ppt/dist/ppt/constants.d.ts +72 -0
- package/viewer/vendor/ppt/dist/ppt/constants.js +21 -0
- package/viewer/vendor/ppt/dist/ppt/drawing.d.ts +15 -0
- package/viewer/vendor/ppt/dist/ppt/drawing.js +508 -0
- package/viewer/vendor/ppt/dist/ppt/encryption.d.ts +14 -0
- package/viewer/vendor/ppt/dist/ppt/encryption.js +241 -0
- package/viewer/vendor/ppt/dist/ppt/extras.d.ts +14 -0
- package/viewer/vendor/ppt/dist/ppt/extras.js +225 -0
- package/viewer/vendor/ppt/dist/ppt/geometry.d.ts +29 -0
- package/viewer/vendor/ppt/dist/ppt/geometry.js +448 -0
- package/viewer/vendor/ppt/dist/ppt/headers-footers.d.ts +11 -0
- package/viewer/vendor/ppt/dist/ppt/headers-footers.js +97 -0
- package/viewer/vendor/ppt/dist/ppt/interactions.d.ts +12 -0
- package/viewer/vendor/ppt/dist/ppt/interactions.js +104 -0
- package/viewer/vendor/ppt/dist/ppt/parser.d.ts +12 -0
- package/viewer/vendor/ppt/dist/ppt/parser.js +356 -0
- package/viewer/vendor/ppt/dist/ppt/pictures.d.ts +10 -0
- package/viewer/vendor/ppt/dist/ppt/pictures.js +215 -0
- package/viewer/vendor/ppt/dist/ppt/records.d.ts +13 -0
- package/viewer/vendor/ppt/dist/ppt/records.js +49 -0
- package/viewer/vendor/ppt/dist/ppt/text.d.ts +19 -0
- package/viewer/vendor/ppt/dist/ppt/text.js +789 -0
- package/viewer/vendor/ppt/dist/pptjs.browser.js +9651 -0
- package/viewer/vendor/ppt/dist/pptjs.mjs +9663 -0
- package/viewer/vendor/ppt/dist/pptjs.worker.js +9650 -0
- package/viewer/vendor/ppt/dist/render/effects.d.ts +23 -0
- package/viewer/vendor/ppt/dist/render/effects.js +125 -0
- package/viewer/vendor/ppt/dist/render/fields.d.ts +11 -0
- package/viewer/vendor/ppt/dist/render/fields.js +176 -0
- package/viewer/vendor/ppt/dist/render/geometry.d.ts +11 -0
- package/viewer/vendor/ppt/dist/render/geometry.js +131 -0
- package/viewer/vendor/ppt/dist/render/safe.d.ts +12 -0
- package/viewer/vendor/ppt/dist/render/safe.js +48 -0
- package/viewer/vendor/ppt/dist/render/svg.d.ts +4 -0
- package/viewer/vendor/ppt/dist/render/svg.js +279 -0
- package/viewer/vendor/ppt/dist/render/text.d.ts +9 -0
- package/viewer/vendor/ppt/dist/render/text.js +181 -0
- package/viewer/vendor/ppt/dist/render/three-d.d.ts +32 -0
- package/viewer/vendor/ppt/dist/render/three-d.js +219 -0
- package/viewer/vendor/ppt/dist/render/wordart.d.ts +16 -0
- package/viewer/vendor/ppt/dist/render/wordart.js +214 -0
- package/viewer/vendor/ppt/dist/runtime.d.ts +125 -0
- package/viewer/vendor/ppt/dist/runtime.js +226 -0
- package/viewer/vendor/ppt/dist/types.d.ts +546 -0
- package/viewer/vendor/ppt/dist/types.js +1 -0
- package/viewer/vendor/ppt/dist/viewer.d.ts +3 -0
- package/viewer/vendor/ppt/dist/viewer.js +264 -0
- package/viewer/vendor/ppt/dist/worker-client.d.ts +25 -0
- package/viewer/vendor/ppt/dist/worker-client.js +61 -0
- package/viewer/vendor/ppt/dist/worker.d.ts +1 -0
- package/viewer/vendor/ppt/dist/worker.js +25 -0
- package/viewer/vendor/ppt/package.json +40 -52
- package/viewer/vendor/ppt/NOTICE +0 -229
- package/viewer/vendor/ppt/frame-cache.mjs +0 -731
- package/viewer/vendor/ppt/index.mjs +0 -941
- package/viewer/vendor/ppt/manifest.json +0 -44
- package/viewer/vendor/ppt/ppt-font-cjk.otf +0 -0
- package/viewer/vendor/ppt/ppt-native.wasm +0 -0
- package/viewer/vendor/ppt/worker.mjs +0 -1720
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
/** An OfficeArt complex array includes its six-byte IMsoArray header. */
|
|
2
|
+
export function officeArray(bytes) {
|
|
3
|
+
if (bytes.length < 6)
|
|
4
|
+
return undefined;
|
|
5
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
6
|
+
const count = view.getUint16(0, true), rawSize = view.getUint16(4, true), size = rawSize === 0xFFF0 ? 4 : rawSize;
|
|
7
|
+
if (!size || count > view.getUint16(2, true) || 6 + count * size > bytes.length)
|
|
8
|
+
return undefined;
|
|
9
|
+
return { view, count, size };
|
|
10
|
+
}
|
|
11
|
+
/** Evaluate the 17 SG operations; references are limited to preceding guides. */
|
|
12
|
+
export function evaluateGuides(bytes, values, geometry, bounds) {
|
|
13
|
+
const arr = officeArray(bytes);
|
|
14
|
+
if (!arr || arr.size !== 8 || arr.count > 128)
|
|
15
|
+
return undefined;
|
|
16
|
+
const guides = [], rad = Math.PI / (180 * 65536);
|
|
17
|
+
const reference = (n) => {
|
|
18
|
+
if (n >= 0x400 && n <= 0x47F)
|
|
19
|
+
return guides[n - 0x400];
|
|
20
|
+
if (n >= 327 && n <= 334)
|
|
21
|
+
return (values.get(n) ?? 0) | 0;
|
|
22
|
+
if (n === 339 || n === 340)
|
|
23
|
+
return (values.get(n) ?? 0x80000000) | 0;
|
|
24
|
+
switch (n) {
|
|
25
|
+
case 320: return geometry.x + geometry.width / 2;
|
|
26
|
+
case 321: return geometry.y + geometry.height / 2;
|
|
27
|
+
case 322: return geometry.width;
|
|
28
|
+
case 323: return geometry.height;
|
|
29
|
+
case 508: {
|
|
30
|
+
const b = values.get(511);
|
|
31
|
+
return b !== undefined && (b & 0x80000) ? (b & 8 ? 1 : 0) : 1;
|
|
32
|
+
}
|
|
33
|
+
case 1271: return (values.get(0x01CB) ?? 9525) / 9525;
|
|
34
|
+
case 1272: return bounds?.width;
|
|
35
|
+
case 1273: return bounds?.height;
|
|
36
|
+
case 1276: return bounds ? bounds.width * 9525 : undefined;
|
|
37
|
+
case 1277: return bounds ? bounds.height * 9525 : undefined;
|
|
38
|
+
case 1278: return bounds ? bounds.width * 9525 / 2 : undefined;
|
|
39
|
+
case 1279: return bounds ? bounds.height * 9525 / 2 : undefined;
|
|
40
|
+
default: return undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
for (let i = 0; i < arr.count; i++) {
|
|
44
|
+
const at = 6 + i * 8, flags = arr.view.getUint16(at, true), params = [];
|
|
45
|
+
for (let p = 0; p < 3; p++) {
|
|
46
|
+
const raw = arr.view.getUint16(at + 2 + p * 2, true), value = flags & (1 << (13 + p)) ? reference(raw) : raw;
|
|
47
|
+
if (value === undefined)
|
|
48
|
+
return undefined;
|
|
49
|
+
params.push(value);
|
|
50
|
+
}
|
|
51
|
+
const [a, b, c] = params;
|
|
52
|
+
let result;
|
|
53
|
+
switch (flags & 0x1FFF) {
|
|
54
|
+
case 0:
|
|
55
|
+
result = a + b - c;
|
|
56
|
+
break;
|
|
57
|
+
case 1:
|
|
58
|
+
result = a * b / c;
|
|
59
|
+
break;
|
|
60
|
+
case 2:
|
|
61
|
+
result = (a + b) / 2;
|
|
62
|
+
break;
|
|
63
|
+
case 3:
|
|
64
|
+
result = Math.abs(a);
|
|
65
|
+
break;
|
|
66
|
+
case 4:
|
|
67
|
+
result = Math.min(a, b);
|
|
68
|
+
break;
|
|
69
|
+
case 5:
|
|
70
|
+
result = Math.max(a, b);
|
|
71
|
+
break;
|
|
72
|
+
case 6:
|
|
73
|
+
result = a > 0 ? b : c;
|
|
74
|
+
break;
|
|
75
|
+
case 7:
|
|
76
|
+
result = Math.hypot(a, b, c);
|
|
77
|
+
break;
|
|
78
|
+
case 8:
|
|
79
|
+
result = Math.atan2(b, a) / rad;
|
|
80
|
+
break;
|
|
81
|
+
case 9:
|
|
82
|
+
result = a * Math.sin(b * rad);
|
|
83
|
+
break;
|
|
84
|
+
case 10:
|
|
85
|
+
result = a * Math.cos(b * rad);
|
|
86
|
+
break;
|
|
87
|
+
case 11:
|
|
88
|
+
result = a * Math.cos(Math.atan2(c, b));
|
|
89
|
+
break;
|
|
90
|
+
case 12:
|
|
91
|
+
result = a * Math.sin(Math.atan2(c, b));
|
|
92
|
+
break;
|
|
93
|
+
case 13:
|
|
94
|
+
result = Math.sqrt(a);
|
|
95
|
+
break;
|
|
96
|
+
case 14:
|
|
97
|
+
result = a + (b + c) * 65536;
|
|
98
|
+
break;
|
|
99
|
+
case 15:
|
|
100
|
+
result = c * Math.sqrt(1 - (a / b) ** 2);
|
|
101
|
+
break;
|
|
102
|
+
case 16:
|
|
103
|
+
result = a * Math.tan(b * rad);
|
|
104
|
+
break;
|
|
105
|
+
default: return undefined;
|
|
106
|
+
}
|
|
107
|
+
if (!Number.isFinite(result))
|
|
108
|
+
return undefined;
|
|
109
|
+
guides.push(result);
|
|
110
|
+
}
|
|
111
|
+
return guides;
|
|
112
|
+
}
|
|
113
|
+
/** Stored vertices, SG guides, common path opcodes and elliptical arc escapes. */
|
|
114
|
+
export function customGeometry(values, complex, diagnostics, shapeId, offset, bounds) {
|
|
115
|
+
const raw = complex.get(325);
|
|
116
|
+
if (!raw)
|
|
117
|
+
return {};
|
|
118
|
+
const arr = officeArray(raw);
|
|
119
|
+
if (!arr || arr.size !== 4 && arr.size !== 8) {
|
|
120
|
+
diagnostics.push({ code: 'GEOMETRY_VERTICES', severity: 'warning', message: 'Invalid OfficeArt vertices array', shapeId, offset });
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
123
|
+
const left = (values.get(320) ?? 0) | 0, top = (values.get(321) ?? 0) | 0;
|
|
124
|
+
const right = (values.get(322) ?? 21600) | 0, bottom = (values.get(323) ?? 21600) | 0;
|
|
125
|
+
const pathBounds = { x: left, y: top, width: right - left || 21600, height: bottom - top || 21600 };
|
|
126
|
+
const recoverX = right === left, recoverY = bottom === top, recover = recoverX || recoverY;
|
|
127
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
128
|
+
const include = (p) => { if (recover) {
|
|
129
|
+
minX = Math.min(minX, p[0]);
|
|
130
|
+
maxX = Math.max(maxX, p[0]);
|
|
131
|
+
minY = Math.min(minY, p[1]);
|
|
132
|
+
maxY = Math.max(maxY, p[1]);
|
|
133
|
+
} };
|
|
134
|
+
const guidesBytes = complex.get(342), guides = guidesBytes ? evaluateGuides(guidesBytes, values, pathBounds, bounds) : undefined;
|
|
135
|
+
const resolveCoordinate = (n) => n >= -2147483648 && n <= -2147483521 ? guides?.[n + 0x80000000] : n;
|
|
136
|
+
const points = [];
|
|
137
|
+
for (let i = 0; i < arr.count; i++) {
|
|
138
|
+
const p = 6 + i * arr.size;
|
|
139
|
+
const x = resolveCoordinate(arr.size === 4 ? arr.view.getInt16(p, true) : arr.view.getInt32(p, true));
|
|
140
|
+
const y = resolveCoordinate(arr.size === 4 ? arr.view.getInt16(p + 2, true) : arr.view.getInt32(p + 4, true));
|
|
141
|
+
if (x === undefined || y === undefined) {
|
|
142
|
+
diagnostics.push({ code: 'GEOMETRY_GUIDE', severity: 'warning', message: 'Custom path references an invalid or unsupported formula guide', shapeId, offset });
|
|
143
|
+
return {};
|
|
144
|
+
}
|
|
145
|
+
points.push([x, y]);
|
|
146
|
+
}
|
|
147
|
+
if (!points.length)
|
|
148
|
+
return {};
|
|
149
|
+
const segBytes = complex.get(326), segments = segBytes ? officeArray(segBytes) : undefined;
|
|
150
|
+
if (segBytes && !segments) {
|
|
151
|
+
diagnostics.push({ code: 'GEOMETRY_SEGMENTS', severity: 'warning', message: 'Invalid OfficeArt segment array; custom path is not guessed from vertices alone', shapeId, offset });
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
let parts = [];
|
|
155
|
+
let index = 0, noFill = false, noLine = false, valid = true;
|
|
156
|
+
const pathParts = [];
|
|
157
|
+
let current, start;
|
|
158
|
+
const finish = () => {
|
|
159
|
+
if (parts.length)
|
|
160
|
+
pathParts.push({ path: parts.join(' '), noFill, noLine });
|
|
161
|
+
parts = [];
|
|
162
|
+
noFill = false;
|
|
163
|
+
noLine = false;
|
|
164
|
+
current = undefined;
|
|
165
|
+
start = undefined;
|
|
166
|
+
};
|
|
167
|
+
const next = () => { const p = points[index++]; if (!p) {
|
|
168
|
+
valid = false;
|
|
169
|
+
return [0, 0];
|
|
170
|
+
} return p; };
|
|
171
|
+
const format = (p) => `${Math.round(p[0] * 1e6) / 1e6} ${Math.round(p[1] * 1e6) / 1e6}`;
|
|
172
|
+
const point = () => { current = next(); include(current); return format(current); };
|
|
173
|
+
const begin = (p, connect = false) => {
|
|
174
|
+
if (connect && current)
|
|
175
|
+
parts.push(`L${format(p)}`);
|
|
176
|
+
else {
|
|
177
|
+
parts.push(`M${format(p)}`);
|
|
178
|
+
start = p;
|
|
179
|
+
}
|
|
180
|
+
current = p;
|
|
181
|
+
include(p);
|
|
182
|
+
};
|
|
183
|
+
const cubic = () => {
|
|
184
|
+
const a = next(), b = next(), end = next(), origin = current;
|
|
185
|
+
if (!origin) {
|
|
186
|
+
valid = false;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
include(end);
|
|
190
|
+
if (recover)
|
|
191
|
+
for (let axis = 0; axis < 2; axis++) {
|
|
192
|
+
const p0 = origin[axis], p1 = a[axis], p2 = b[axis], p3 = end[axis], aa = -p0 + 3 * p1 - 3 * p2 + p3, bb = 2 * (p0 - 2 * p1 + p2), cc = p1 - p0;
|
|
193
|
+
const discriminant = bb * bb - 4 * aa * cc;
|
|
194
|
+
const roots = Math.abs(aa) < 1e-12 ? (Math.abs(bb) > 1e-12 ? [-cc / bb] : []) : discriminant >= 0 ? [(-bb - Math.sqrt(discriminant)) / (2 * aa), (-bb + Math.sqrt(discriminant)) / (2 * aa)] : [];
|
|
195
|
+
for (const t of roots)
|
|
196
|
+
if (t > 0 && t < 1) {
|
|
197
|
+
const s = 1 - t;
|
|
198
|
+
include([s * s * s * origin[0] + 3 * s * s * t * a[0] + 3 * s * t * t * b[0] + t * t * t * end[0], s * s * s * origin[1] + 3 * s * s * t * a[1] + 3 * s * t * t * b[1] + t * t * t * end[1]]);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
parts.push(`C${format(a)} ${format(b)} ${format(end)}`);
|
|
202
|
+
current = end;
|
|
203
|
+
};
|
|
204
|
+
const arc = (escape, count) => {
|
|
205
|
+
if (escape >= 3 && escape <= 6) {
|
|
206
|
+
if (count % 4) {
|
|
207
|
+
valid = false;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
for (let j = 0; j < count / 4; j++) {
|
|
211
|
+
const p0 = next(), p1 = next(), a = next(), b = next(), cx = (p0[0] + p1[0]) / 2, cy = (p0[1] + p1[1]) / 2, rx = Math.abs(p1[0] - p0[0]) / 2, ry = Math.abs(p1[1] - p0[1]) / 2;
|
|
212
|
+
if (!rx || !ry) {
|
|
213
|
+
valid = false;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const t0 = Math.atan2((a[1] - cy) / ry, (a[0] - cx) / rx), t1 = Math.atan2((b[1] - cy) / ry, (b[0] - cx) / rx);
|
|
217
|
+
const start = [cx + rx * Math.cos(t0), cy + ry * Math.sin(t0)], end = [cx + rx * Math.cos(t1), cy + ry * Math.sin(t1)];
|
|
218
|
+
const clockwise = escape >= 5, sweep = clockwise ? 1 : 0, tau = Math.PI * 2, delta = ((clockwise ? t1 - t0 : t0 - t1) % tau + tau) % tau;
|
|
219
|
+
begin(start, escape === 3 || escape === 5);
|
|
220
|
+
include(end);
|
|
221
|
+
if (recover)
|
|
222
|
+
for (let k = 0; k < 4; k++) {
|
|
223
|
+
const angle = k * Math.PI / 2, distance = ((clockwise ? angle - t0 : t0 - angle) % tau + tau) % tau;
|
|
224
|
+
if (delta < 1e-9 || distance <= delta + 1e-9)
|
|
225
|
+
include([cx + rx * Math.cos(angle), cy + ry * Math.sin(angle)]);
|
|
226
|
+
}
|
|
227
|
+
if (delta < 1e-9) {
|
|
228
|
+
const middle = [2 * cx - start[0], 2 * cy - start[1]];
|
|
229
|
+
parts.push(`A${rx} ${ry} 0 0 ${sweep} ${format(middle)}`);
|
|
230
|
+
parts.push(`A${rx} ${ry} 0 0 ${sweep} ${format(end)}`);
|
|
231
|
+
}
|
|
232
|
+
else
|
|
233
|
+
parts.push(`A${rx} ${ry} 0 ${delta > Math.PI ? 1 : 0} ${sweep} ${format(end)}`);
|
|
234
|
+
current = end;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else if (escape === 7 || escape === 8) {
|
|
238
|
+
for (let j = 0; j < count; j++) {
|
|
239
|
+
if (!current) {
|
|
240
|
+
valid = false;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const end = next(), dx = end[0] - current[0], dy = end[1] - current[1];
|
|
244
|
+
const sweep = escape === 7 ? (dx * dy > 0 ? 1 : 0) : (dx * dy < 0 ? 1 : 0);
|
|
245
|
+
if (dx === 0 || dy === 0)
|
|
246
|
+
parts.push(`L${format(end)}`);
|
|
247
|
+
else
|
|
248
|
+
parts.push(`A${Math.abs(dx)} ${Math.abs(dy)} 0 0 ${sweep} ${format(end)}`);
|
|
249
|
+
current = end;
|
|
250
|
+
include(end);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else if (escape === 9) {
|
|
254
|
+
// A quadratic chain contains control points followed by one terminal point.
|
|
255
|
+
// Consecutive off-curve controls have an implicit midpoint, as documented
|
|
256
|
+
// for Microsoft's VML quadraticbezier command and MS-ODRAW's escape 9.
|
|
257
|
+
if (count < 2 || index + count > points.length) {
|
|
258
|
+
valid = false;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const vertices = points.slice(index, index + count);
|
|
262
|
+
index += count;
|
|
263
|
+
const end = vertices[count - 1], closed = !current;
|
|
264
|
+
if (closed)
|
|
265
|
+
begin(end);
|
|
266
|
+
for (let j = 0; j < count - 1; j++) {
|
|
267
|
+
const control = vertices[j], following = vertices[j + 1];
|
|
268
|
+
const endpoint = j === count - 2 ? end : [(control[0] + following[0]) / 2, (control[1] + following[1]) / 2];
|
|
269
|
+
include(endpoint);
|
|
270
|
+
if (recover && current)
|
|
271
|
+
for (let axis = 0; axis < 2; axis++) {
|
|
272
|
+
const divisor = current[axis] - 2 * control[axis] + endpoint[axis], t = divisor ? (current[axis] - control[axis]) / divisor : 0;
|
|
273
|
+
if (t > 0 && t < 1) {
|
|
274
|
+
const s = 1 - t;
|
|
275
|
+
include([s * s * current[0] + 2 * s * t * control[0] + t * t * endpoint[0], s * s * current[1] + 2 * s * t * control[1] + t * t * endpoint[1]]);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
parts.push(`Q${format(control)} ${format(endpoint)}`);
|
|
279
|
+
current = endpoint;
|
|
280
|
+
}
|
|
281
|
+
if (closed) {
|
|
282
|
+
parts.push('Z');
|
|
283
|
+
current = start;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else
|
|
287
|
+
valid = false;
|
|
288
|
+
};
|
|
289
|
+
if (!segments) {
|
|
290
|
+
begin(next());
|
|
291
|
+
const pathType = values.get(324) ?? 1;
|
|
292
|
+
if (pathType === 2 || pathType === 3) {
|
|
293
|
+
if ((points.length - index) % 3)
|
|
294
|
+
valid = false;
|
|
295
|
+
else
|
|
296
|
+
while (index + 2 < points.length)
|
|
297
|
+
cubic();
|
|
298
|
+
}
|
|
299
|
+
else if (pathType === 0 || pathType === 1)
|
|
300
|
+
while (index < points.length)
|
|
301
|
+
parts.push(`L${point()}`);
|
|
302
|
+
else {
|
|
303
|
+
diagnostics.push({ code: 'GEOMETRY_SEGMENTS', severity: 'warning', message: 'A complex shapePath requires its segment array; geometry is not inferred from vertices alone', shapeId, offset });
|
|
304
|
+
valid = false;
|
|
305
|
+
}
|
|
306
|
+
if (pathType === 1 || pathType === 3)
|
|
307
|
+
parts.push('Z');
|
|
308
|
+
}
|
|
309
|
+
else if (segments.size === 2) {
|
|
310
|
+
for (let i = 0; i < segments.count && valid; i++) {
|
|
311
|
+
const segment = segments.view.getUint16(6 + i * 2, true), op = segment >>> 13, count = segment & 0x1FFF;
|
|
312
|
+
if (op === 0)
|
|
313
|
+
for (let n = 0; n < count; n++)
|
|
314
|
+
parts.push(`L${point()}`);
|
|
315
|
+
else if (op === 1)
|
|
316
|
+
for (let n = 0; n < count && valid; n++)
|
|
317
|
+
cubic();
|
|
318
|
+
else if (op === 2)
|
|
319
|
+
begin(next());
|
|
320
|
+
else if (op === 3) {
|
|
321
|
+
parts.push('Z');
|
|
322
|
+
current = start;
|
|
323
|
+
}
|
|
324
|
+
else if (op === 4)
|
|
325
|
+
finish();
|
|
326
|
+
else if (op === 5 && ((segment >>> 8) & 31) === 10)
|
|
327
|
+
noFill = true;
|
|
328
|
+
else if (op === 5 && ((segment >>> 8) & 31) === 11)
|
|
329
|
+
noLine = true;
|
|
330
|
+
else if (op === 5 && ((segment >>> 8) & 31) >= 3 && ((segment >>> 8) & 31) <= 9)
|
|
331
|
+
arc((segment >>> 8) & 31, segment & 255);
|
|
332
|
+
else if (op === 5 && ((segment >>> 8) & 31) >= 12 && ((segment >>> 8) & 31) <= 20) { /* Editing tangent metadata; geometry comes from following path segments. */ }
|
|
333
|
+
else {
|
|
334
|
+
diagnostics.push({ code: 'GEOMETRY_SEGMENT', severity: 'warning', message: `Custom path opcode ${op}/${(segment >>> 8) & 31} requires an unsupported geometry escape`, shapeId, offset });
|
|
335
|
+
valid = false;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else
|
|
340
|
+
valid = false;
|
|
341
|
+
if (!valid) {
|
|
342
|
+
diagnostics.push({ code: 'GEOMETRY_INCOMPLETE', severity: 'warning', message: 'Custom path could not be rendered completely; shape geometry fallback will be used', shapeId, offset });
|
|
343
|
+
return {};
|
|
344
|
+
}
|
|
345
|
+
if (recover) {
|
|
346
|
+
// MS-ODRAW defines scaling through the geometry rectangle, but does not
|
|
347
|
+
// define a zero-size rectangle. Preserve usable producer output by fitting
|
|
348
|
+
// only its degenerate axes to exact path extrema, with an explicit warning.
|
|
349
|
+
if (recoverX && Number.isFinite(minX) && maxX > minX) {
|
|
350
|
+
pathBounds.x = minX;
|
|
351
|
+
pathBounds.width = maxX - minX;
|
|
352
|
+
}
|
|
353
|
+
if (recoverY && Number.isFinite(minY) && maxY > minY) {
|
|
354
|
+
pathBounds.y = minY;
|
|
355
|
+
pathBounds.height = maxY - minY;
|
|
356
|
+
}
|
|
357
|
+
diagnostics.push({ code: 'GEOMETRY_BOUNDS_RECOVERED', severity: 'warning', message: 'Zero-size geometry axes use the saved path extent; the original coordinate-system mapping is not specified', shapeId, offset, details: { x: recoverX, y: recoverY } });
|
|
358
|
+
}
|
|
359
|
+
finish();
|
|
360
|
+
return { path: pathParts.map(p => p.path).join(' '), pathParts, pathBounds, noFill: pathParts.every(p => p.noFill), noLine: pathParts.every(p => p.noLine) };
|
|
361
|
+
}
|
|
362
|
+
/** Saved adjustment handles use the 21,600-unit OfficeArt geometry space.
|
|
363
|
+
* Right-arrow construction is independently described by Microsoft's VML handles example.
|
|
364
|
+
* Other analytic envelopes remain explicitly labelled where their complete Office recipe
|
|
365
|
+
* is not published in MS-ODRAW. A stored pVertices/pGuides path always takes precedence.
|
|
366
|
+
*/
|
|
367
|
+
export function adjustedPresetGeometry(preset, values, bounds) {
|
|
368
|
+
if (!Array.from({ length: 8 }, (_, i) => values.has(327 + i)).some(Boolean))
|
|
369
|
+
return undefined;
|
|
370
|
+
const size = 21600, half = 10800, clamp = (v, min = 0, max = size) => Math.max(min, Math.min(max, v));
|
|
371
|
+
const a = (i, fallback, min = 0, max = size) => clamp((values.get(327 + i) ?? fallback) | 0, min, max);
|
|
372
|
+
const pathBounds = { x: 0, y: 0, width: size, height: size };
|
|
373
|
+
const result = (path, approximate = true) => ({ path, pathBounds, approximate });
|
|
374
|
+
const polygon = (points, approximate = true) => result('M' + points.map(p => p.join(' ')).join(' L') + ' Z', approximate);
|
|
375
|
+
if (preset === 2) {
|
|
376
|
+
const amount = a(0, 2592, 0, half), min = Math.max(0, Math.min(bounds.width, bounds.height)), rx = bounds.width ? amount * min / bounds.width : amount, ry = bounds.height ? amount * min / bounds.height : amount;
|
|
377
|
+
return result(`M${rx} 0 H${size - rx} A${rx} ${ry} 0 0 1 ${size} ${ry} V${size - ry} A${rx} ${ry} 0 0 1 ${size - rx} ${size} H${rx} A${rx} ${ry} 0 0 1 0 ${size - ry} V${ry} A${rx} ${ry} 0 0 1 ${rx} 0 Z`, false);
|
|
378
|
+
}
|
|
379
|
+
if (preset === 5)
|
|
380
|
+
return polygon([[a(0, half), 0], [size, size], [0, size]]);
|
|
381
|
+
if (preset === 7) {
|
|
382
|
+
const x = a(0, 5400, 0, half);
|
|
383
|
+
return polygon([[x, 0], [size, 0], [size - x, size], [0, size]]);
|
|
384
|
+
}
|
|
385
|
+
if (preset === 8) {
|
|
386
|
+
const x = a(0, 5400, 0, half);
|
|
387
|
+
return polygon([[x, 0], [size - x, 0], [size, size], [0, size]]);
|
|
388
|
+
}
|
|
389
|
+
if (preset === 9) {
|
|
390
|
+
const x = a(0, 5400, 0, half);
|
|
391
|
+
return polygon([[x, 0], [size - x, 0], [size, half], [size - x, size], [x, size], [0, half]]);
|
|
392
|
+
}
|
|
393
|
+
if (preset === 10) {
|
|
394
|
+
const x = a(0, 6326, 0, half);
|
|
395
|
+
return polygon([[x, 0], [size - x, 0], [size, x], [size, size - x], [size - x, size], [x, size], [0, size - x], [0, x]]);
|
|
396
|
+
}
|
|
397
|
+
if (preset === 11) {
|
|
398
|
+
const x = a(0, 5400, 0, half), r = size - x;
|
|
399
|
+
return polygon([[x, 0], [r, 0], [r, x], [size, x], [size, r], [r, r], [r, size], [x, size], [x, r], [0, r], [0, x], [x, x]]);
|
|
400
|
+
}
|
|
401
|
+
if (preset === 13) {
|
|
402
|
+
const neck = a(0, 16200), shaft = a(1, 5400, 0, half);
|
|
403
|
+
return polygon([[neck, 0], [neck, shaft], [0, shaft], [0, size - shaft], [neck, size - shaft], [neck, size], [size, half]], false);
|
|
404
|
+
}
|
|
405
|
+
if (preset === 15) {
|
|
406
|
+
const neck = a(0, 16200);
|
|
407
|
+
return polygon([[0, 0], [neck, 0], [size, half], [neck, size], [0, size]]);
|
|
408
|
+
}
|
|
409
|
+
if (preset === 66) {
|
|
410
|
+
const neck = a(0, 5400), shaft = a(1, 5400, 0, half);
|
|
411
|
+
return polygon([[neck, 0], [neck, shaft], [size, shaft], [size, size - shaft], [neck, size - shaft], [neck, size], [0, half]]);
|
|
412
|
+
}
|
|
413
|
+
if (preset === 67) {
|
|
414
|
+
const neck = a(0, 16200), shaft = a(1, 5400, 0, half);
|
|
415
|
+
return polygon([[shaft, 0], [size - shaft, 0], [size - shaft, neck], [size, neck], [half, size], [0, neck], [shaft, neck]]);
|
|
416
|
+
}
|
|
417
|
+
if (preset === 68) {
|
|
418
|
+
const neck = a(0, 5400), shaft = a(1, 5400, 0, half);
|
|
419
|
+
return polygon([[shaft, size], [size - shaft, size], [size - shaft, neck], [size, neck], [half, 0], [0, neck], [shaft, neck]]);
|
|
420
|
+
}
|
|
421
|
+
if (preset === 69) {
|
|
422
|
+
const neck = a(0, 5400, 0, half), shaft = a(1, 5400, 0, half);
|
|
423
|
+
return polygon([[0, half], [neck, 0], [neck, shaft], [size - neck, shaft], [size - neck, 0], [size, half], [size - neck, size], [size - neck, size - shaft], [neck, size - shaft], [neck, size]]);
|
|
424
|
+
}
|
|
425
|
+
if (preset === 70) {
|
|
426
|
+
const shaft = a(0, 5400, 0, half), neck = a(1, 5400, 0, half);
|
|
427
|
+
return polygon([[half, 0], [size, neck], [size - shaft, neck], [size - shaft, size - neck], [size, size - neck], [half, size], [0, size - neck], [shaft, size - neck], [shaft, neck], [0, neck]]);
|
|
428
|
+
}
|
|
429
|
+
if (preset === 55) {
|
|
430
|
+
const x = a(0, 5400, 0, half);
|
|
431
|
+
return polygon([[0, 0], [size - x, 0], [size, half], [size - x, size], [0, size], [x, half]]);
|
|
432
|
+
}
|
|
433
|
+
if (preset === 23) {
|
|
434
|
+
const inset = a(0, 5400, 0, half), r = half - inset;
|
|
435
|
+
if (!r)
|
|
436
|
+
return result(`M${half} 0 A${half} ${half} 0 1 1 ${half} ${size} A${half} ${half} 0 1 1 ${half} 0 Z`);
|
|
437
|
+
return result(`M${half} 0 A${half} ${half} 0 1 1 ${half} ${size} A${half} ${half} 0 1 1 ${half} 0 Z M${half} ${inset} A${r} ${r} 0 1 0 ${half} ${size - inset} A${r} ${r} 0 1 0 ${half} ${inset} Z`);
|
|
438
|
+
}
|
|
439
|
+
if (preset >= 34 && preset <= 36) {
|
|
440
|
+
const x = a(0, half, -size, size * 2), y = a(1, half, -size, size * 2), z = a(2, half, -size, size * 2);
|
|
441
|
+
return result(preset === 34 ? `M0 0 H${x} V${size} H${size}` : preset === 35 ? `M0 0 H${x} V${y} H${size} V${size}` : `M0 0 H${x} V${y} H${z} V${size} H${size}`);
|
|
442
|
+
}
|
|
443
|
+
if (preset === 37 || preset === 38) {
|
|
444
|
+
const x = a(0, half, -size, size * 2);
|
|
445
|
+
return result(`M0 0 C${x} 0 ${x} ${size} ${size} ${size}`);
|
|
446
|
+
}
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Independent [MS-PPT] 2.4.15 and 2.5.16 header/footer settings parser. */
|
|
2
|
+
import type { PptHeaderFooter, RecordNode, TextContext } from '../types.js';
|
|
3
|
+
export type HeaderFooterContext = Pick<TextContext, 'bytes' | 'limits' | 'diagnostics'>;
|
|
4
|
+
export type HeaderFooterInstance = 0 | 3 | 4;
|
|
5
|
+
/**
|
|
6
|
+
* Read immediate children only: instance 3 is document slide defaults, 4 notes
|
|
7
|
+
* defaults, and 0 a per-slide/master override. Absent values remain absent.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseHeaderFooter(records: readonly RecordNode[], ctx: HeaderFooterContext, instance?: HeaderFooterInstance): PptHeaderFooter | undefined;
|
|
10
|
+
/** Resolve document → master → local settings without mutating source objects. */
|
|
11
|
+
export declare function resolveHeaderFooter(...levels: readonly (PptHeaderFooter | undefined)[]): PptHeaderFooter | undefined;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PptError } from '../core/errors.js';
|
|
2
|
+
import { trimTrailingNulls } from '../core/utils.js';
|
|
3
|
+
import { RT } from './constants.js';
|
|
4
|
+
function warning(ctx, code, message, record) {
|
|
5
|
+
ctx.diagnostics.push({ code, severity: 'warning', message, offset: record.offset });
|
|
6
|
+
}
|
|
7
|
+
function bounded(record, ctx, minimum) {
|
|
8
|
+
if (record.dataOffset < 0 || record.end > ctx.bytes.length || record.end - record.dataOffset < minimum) {
|
|
9
|
+
warning(ctx, 'HEADER_FOOTER_TRUNCATED', 'A header/footer record is truncated or outside its stream', record);
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
function stringValue(record, ctx) {
|
|
15
|
+
if (!bounded(record, ctx, 0))
|
|
16
|
+
return undefined;
|
|
17
|
+
if (record.length / 2 > ctx.limits.maxTextLength)
|
|
18
|
+
throw new PptError('LIMIT_TEXT', 'Header/footer text exceeds the configured character limit', record.offset);
|
|
19
|
+
if (record.length % 2)
|
|
20
|
+
warning(ctx, 'HEADER_FOOTER_UTF16', 'An odd trailing byte in header/footer text was ignored', record);
|
|
21
|
+
if (record.instance === 0 && record.length > 510)
|
|
22
|
+
warning(ctx, 'HEADER_FOOTER_DATE_LENGTH', 'Custom date text exceeds the specification length of 255 UTF-16 units', record);
|
|
23
|
+
const view = new DataView(ctx.bytes.buffer, ctx.bytes.byteOffset, ctx.bytes.byteLength);
|
|
24
|
+
const pieces = [];
|
|
25
|
+
const count = Math.floor(record.length / 2);
|
|
26
|
+
for (let from = 0; from < count; from += 8192) {
|
|
27
|
+
const values = [];
|
|
28
|
+
for (let i = from; i < Math.min(count, from + 8192); i++)
|
|
29
|
+
values.push(view.getUint16(record.dataOffset + i * 2, true));
|
|
30
|
+
pieces.push(String.fromCharCode(...values));
|
|
31
|
+
}
|
|
32
|
+
return trimTrailingNulls(pieces.join(''));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Read immediate children only: instance 3 is document slide defaults, 4 notes
|
|
36
|
+
* defaults, and 0 a per-slide/master override. Absent values remain absent.
|
|
37
|
+
*/
|
|
38
|
+
export function parseHeaderFooter(records, ctx, instance = 0) {
|
|
39
|
+
const containers = records.filter(record => record.type === RT.HeadersFooters && record.instance === instance);
|
|
40
|
+
const container = containers[0];
|
|
41
|
+
if (!container)
|
|
42
|
+
return undefined;
|
|
43
|
+
if (containers.length > 1)
|
|
44
|
+
warning(ctx, 'HEADER_FOOTER_DUPLICATE', 'Duplicate header/footer containers were ignored', containers[1]);
|
|
45
|
+
const atom = container.children.find(record => record.type === RT.HeadersFootersAtom);
|
|
46
|
+
if (!atom) {
|
|
47
|
+
warning(ctx, 'HEADER_FOOTER_ATOM', 'Header/footer options atom is missing', container);
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (!bounded(atom, ctx, 4))
|
|
51
|
+
return undefined;
|
|
52
|
+
const view = new DataView(ctx.bytes.buffer, ctx.bytes.byteOffset + atom.dataOffset, 4);
|
|
53
|
+
const format = view.getInt16(0, true), flags = view.getUint16(2, true);
|
|
54
|
+
const result = {
|
|
55
|
+
showDate: !!(flags & 1), useCurrentDate: !!(flags & 2), useUserDate: !!(flags & 4),
|
|
56
|
+
showSlideNumber: !!(flags & 8), showHeader: instance !== 3 && !!(flags & 16),
|
|
57
|
+
showFooter: !!(flags & 32), format,
|
|
58
|
+
};
|
|
59
|
+
// The ten reserved bits have no payload and MUST be ignored by readers.
|
|
60
|
+
if (atom.length !== 4)
|
|
61
|
+
warning(ctx, 'HEADER_FOOTER_LENGTH', 'Extra bytes in header/footer options were ignored', atom);
|
|
62
|
+
if (result.useCurrentDate && (format < 0 || format > 13))
|
|
63
|
+
warning(ctx, 'HEADER_FOOTER_DATE_FORMAT', `Unsupported current-date format ${format}`, atom);
|
|
64
|
+
if (result.useCurrentDate && result.useUserDate)
|
|
65
|
+
warning(ctx, 'HEADER_FOOTER_DATE_MODE', 'Both current-date and custom-date flags are enabled', atom);
|
|
66
|
+
const seen = new Set();
|
|
67
|
+
for (const record of container.children) {
|
|
68
|
+
if (record.type !== RT.CString || record.instance > 2)
|
|
69
|
+
continue;
|
|
70
|
+
if (seen.has(record.instance)) {
|
|
71
|
+
warning(ctx, 'HEADER_FOOTER_STRING_DUPLICATE', 'Duplicate header/footer text record was ignored', record);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
seen.add(record.instance);
|
|
75
|
+
const value = stringValue(record, ctx);
|
|
76
|
+
if (value === undefined)
|
|
77
|
+
continue;
|
|
78
|
+
if (record.instance === 0)
|
|
79
|
+
result.userDate = value;
|
|
80
|
+
else if (record.instance === 1 && instance === 4)
|
|
81
|
+
result.header = value;
|
|
82
|
+
else if (record.instance === 2)
|
|
83
|
+
result.footer = value;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** Resolve document → master → local settings without mutating source objects. */
|
|
88
|
+
export function resolveHeaderFooter(...levels) {
|
|
89
|
+
let result;
|
|
90
|
+
for (const level of levels) {
|
|
91
|
+
if (!level)
|
|
92
|
+
continue;
|
|
93
|
+
result = { ...result, ...level };
|
|
94
|
+
// Explicit empty strings replace inherited text; absent strings inherit it.
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Diagnostic, PptDocumentExtras, PptHyperlink, PptShape, RecordNode } from '../types.js';
|
|
2
|
+
/** MS-PPT 2.6.10, 2.13.13–15; no executable actions are promoted to links. */
|
|
3
|
+
export declare function interactionHref(record: RecordNode, bytes: Uint8Array, targets?: ReadonlyMap<number, string>): string | undefined;
|
|
4
|
+
/** PowerPoint stores its slide locator in LocationAtom as ID,number,title.
|
|
5
|
+
* The stable ID wins over the stale displayed number after a slide reorder.
|
|
6
|
+
* Unknown locator strings stay metadata; never reinterpret another-file targets.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveSlideLinks(links: PptHyperlink[], slides: readonly {
|
|
9
|
+
id: number;
|
|
10
|
+
}[], targets: Map<number, string>, diagnostics: Diagnostic[]): void;
|
|
11
|
+
/** Bind shape actions and embedded sounds to their document-owned asset IDs. */
|
|
12
|
+
export declare function bindShapeInteractions(records: readonly RecordNode[], bytes: Uint8Array, shapes: readonly PptShape[], extras: PptDocumentExtras, targets: Map<number, string>, diagnostics: Diagnostic[], slideId: number): void;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { walkRecords } from './records.js';
|
|
2
|
+
const relative = ['#pptjs-next', '#pptjs-previous', '#pptjs-first', '#pptjs-last'];
|
|
3
|
+
/** MS-PPT 2.6.10, 2.13.13–15; no executable actions are promoted to links. */
|
|
4
|
+
export function interactionHref(record, bytes, targets) {
|
|
5
|
+
if (record.type !== 0x0ff3 || record.length !== 16)
|
|
6
|
+
return undefined;
|
|
7
|
+
const v = new DataView(bytes.buffer, bytes.byteOffset + record.dataOffset, 16), id = v.getUint32(4, true), action = v.getUint8(8), jump = v.getUint8(10), type = v.getUint8(12);
|
|
8
|
+
if (action === 3) {
|
|
9
|
+
if (jump >= 1 && jump <= 4)
|
|
10
|
+
return relative[jump - 1];
|
|
11
|
+
if (jump === 5)
|
|
12
|
+
return '#pptjs-back';
|
|
13
|
+
if (jump === 6)
|
|
14
|
+
return '#pptjs-end';
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
if (action === 4) {
|
|
18
|
+
if (type <= 3)
|
|
19
|
+
return relative[type];
|
|
20
|
+
if (type === 7 || type === 8)
|
|
21
|
+
return targets?.get(id);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/** PowerPoint stores its slide locator in LocationAtom as ID,number,title.
|
|
26
|
+
* The stable ID wins over the stale displayed number after a slide reorder.
|
|
27
|
+
* Unknown locator strings stay metadata; never reinterpret another-file targets.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveSlideLinks(links, slides, targets, diagnostics) {
|
|
30
|
+
const byId = new Map(slides.map((s, index) => [s.id, index]));
|
|
31
|
+
const unresolved = new Map();
|
|
32
|
+
for (const diagnostic of diagnostics)
|
|
33
|
+
if (diagnostic.code === 'INTERNAL_LINK_UNRESOLVED' && diagnostic.offset !== undefined && !unresolved.has(diagnostic.offset))
|
|
34
|
+
unresolved.set(diagnostic.offset, diagnostic);
|
|
35
|
+
for (const link of links) {
|
|
36
|
+
if (link.target.trim() || !link.location)
|
|
37
|
+
continue;
|
|
38
|
+
const text = link.location.trim();
|
|
39
|
+
let index;
|
|
40
|
+
const location = /^(\d+),(\d+),(.*)$/s.exec(text);
|
|
41
|
+
if (location) {
|
|
42
|
+
const id = Number(location[1]), number = Number(location[2]);
|
|
43
|
+
index = byId.get(id);
|
|
44
|
+
if (index === undefined && id === 0 && number >= 1 && number <= slides.length)
|
|
45
|
+
index = number - 1;
|
|
46
|
+
}
|
|
47
|
+
else if (/^\d+$/.test(text)) {
|
|
48
|
+
const value = Number(text);
|
|
49
|
+
index = byId.get(value);
|
|
50
|
+
if (index === undefined && value >= 1 && value <= slides.length)
|
|
51
|
+
index = value - 1;
|
|
52
|
+
}
|
|
53
|
+
if (index === undefined)
|
|
54
|
+
continue;
|
|
55
|
+
const href = `#pptjs-slide=${index}`;
|
|
56
|
+
link.href = href;
|
|
57
|
+
link.blocked = false;
|
|
58
|
+
targets.set(link.id, href);
|
|
59
|
+
const prior = unresolved.get(link.sourceOffset);
|
|
60
|
+
if (prior) {
|
|
61
|
+
prior.code = 'INTERNAL_LINK_RESOLVED';
|
|
62
|
+
prior.severity = 'info';
|
|
63
|
+
prior.message = 'Internal hyperlink resolved against the current slide order';
|
|
64
|
+
prior.details = { slideIndex: index, slideId: slides[index].id };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Bind shape actions and embedded sounds to their document-owned asset IDs. */
|
|
69
|
+
export function bindShapeInteractions(records, bytes, shapes, extras, targets, diagnostics, slideId) {
|
|
70
|
+
const byOffset = new Map();
|
|
71
|
+
for (const r of walkRecords(records))
|
|
72
|
+
byOffset.set(r.offset, r);
|
|
73
|
+
const mediaById = new Map(extras.media.map(m => [m.id, m])), soundById = new Map(extras.sounds.map(s => [s.id, s]));
|
|
74
|
+
const visit = (items) => {
|
|
75
|
+
for (const shape of items) {
|
|
76
|
+
if (shape.children)
|
|
77
|
+
visit(shape.children);
|
|
78
|
+
const node = shape.source ? byOffset.get(shape.source.offset) : undefined;
|
|
79
|
+
const clients = node?.children.filter(n => n.type === 0xf011) ?? [];
|
|
80
|
+
for (const client of clients) {
|
|
81
|
+
const click = client.children.find(r => r.type === 0x0ff2 && r.instance === 0), atom = click?.children.find(r => r.type === 0x0ff3);
|
|
82
|
+
if (atom) {
|
|
83
|
+
shape.hyperlink = interactionHref(atom, bytes, targets);
|
|
84
|
+
if (!shape.hyperlink && atom.length >= 16) {
|
|
85
|
+
const action = bytes[atom.dataOffset + 8];
|
|
86
|
+
if (action && action !== 6)
|
|
87
|
+
diagnostics.push({ code: 'INTERACTION_UNSUPPORTED', severity: 'warning', message: 'The source click action is retained as metadata and has no preview action', slideId, shapeId: shape.id, offset: atom.offset, details: { action } });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const ref = client.children.find(r => r.type === 3009);
|
|
91
|
+
if (!ref || ref.length < 4)
|
|
92
|
+
continue;
|
|
93
|
+
const id = new DataView(bytes.buffer, bytes.byteOffset + ref.dataOffset, 4).getUint32(0, true), media = mediaById.get(id);
|
|
94
|
+
if (!media)
|
|
95
|
+
continue;
|
|
96
|
+
const sound = media.soundId === undefined ? undefined : soundById.get(media.soundId);
|
|
97
|
+
shape.media = { mediaId: id, kind: media.kind, assetId: sound?.assetId, posterAssetId: shape.image?.assetId, loop: media.loop };
|
|
98
|
+
if (!sound?.assetId)
|
|
99
|
+
diagnostics.push({ code: 'MEDIA_SOURCE_UNAVAILABLE', severity: 'warning', message: 'The media source is external or has no supported embedded payload', slideId, shapeId: shape.id, offset: ref.offset, details: { mediaId: id } });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
visit(shapes);
|
|
104
|
+
}
|