@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,219 @@
1
+ import { mapPathToBounds, presetGeometry } from './geometry.js';
2
+ import { color, finite, n } from './safe.js';
3
+ const rad = Math.PI / 180;
4
+ /** Bounded SVG path flattening, including endpoint-parameterized elliptical arcs. */
5
+ export function flattenPath(path, maxPoints = 4096) {
6
+ const tokens = [];
7
+ for (const match of path.matchAll(/[a-df-zA-DF-Z]|[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/g)) {
8
+ if (tokens.length > 100000)
9
+ throw new RangeError('Path token limit');
10
+ tokens.push(match[0]);
11
+ }
12
+ const contours = [];
13
+ let current, point = { x: 0, y: 0 }, start = point, control, previous = '', command = '', at = 0, count = 0;
14
+ const add = (p) => { if (!Number.isFinite(p.x) || !Number.isFinite(p.y) || ++count > maxPoints)
15
+ throw new RangeError('Path point limit'); if (!current) {
16
+ current = { points: [], closed: false };
17
+ contours.push(current);
18
+ } current.points.push(p); point = p; };
19
+ const read = () => { const value = Number(tokens[at++]); if (!Number.isFinite(value))
20
+ throw new RangeError('Invalid path coordinate'); return value; };
21
+ const counts = { M: 2, L: 2, H: 1, V: 1, C: 6, S: 4, Q: 4, T: 2, A: 7 };
22
+ while (at < tokens.length) {
23
+ if (/^[a-zA-Z]$/.test(tokens[at]))
24
+ command = tokens[at++];
25
+ const upper = command.toUpperCase(), relative = command !== upper;
26
+ if (upper === 'Z') {
27
+ if (current) {
28
+ current.closed = true;
29
+ point = start;
30
+ }
31
+ current = undefined;
32
+ control = undefined;
33
+ previous = upper;
34
+ command = '';
35
+ continue;
36
+ }
37
+ const need = counts[upper];
38
+ if (need == null || at + need > tokens.length)
39
+ throw new RangeError('Invalid SVG path');
40
+ const origin = point, coords = [];
41
+ const xy = () => ({ x: read() + (relative ? origin.x : 0), y: read() + (relative ? origin.y : 0) });
42
+ if (upper === 'M') {
43
+ point = xy();
44
+ current = { points: [], closed: false };
45
+ contours.push(current);
46
+ start = point;
47
+ add(point);
48
+ command = relative ? 'l' : 'L';
49
+ }
50
+ else if (upper === 'L')
51
+ add(xy());
52
+ else if (upper === 'H')
53
+ add({ x: read() + (relative ? origin.x : 0), y: origin.y });
54
+ else if (upper === 'V')
55
+ add({ x: origin.x, y: read() + (relative ? origin.y : 0) });
56
+ else if (upper === 'C' || upper === 'S') {
57
+ const c1 = upper === 'C' ? xy() : previous === 'C' || previous === 'S' ? { x: 2 * origin.x - (control?.x ?? origin.x), y: 2 * origin.y - (control?.y ?? origin.y) } : origin, c2 = xy(), end = xy();
58
+ for (let i = 1; i <= 16; i++) {
59
+ const t = i / 16, s = 1 - t;
60
+ coords.push({ x: s * s * s * origin.x + 3 * s * s * t * c1.x + 3 * s * t * t * c2.x + t * t * t * end.x, y: s * s * s * origin.y + 3 * s * s * t * c1.y + 3 * s * t * t * c2.y + t * t * t * end.y });
61
+ }
62
+ coords.forEach(add);
63
+ control = c2;
64
+ }
65
+ else if (upper === 'Q' || upper === 'T') {
66
+ const c = upper === 'Q' ? xy() : previous === 'Q' || previous === 'T' ? { x: 2 * origin.x - (control?.x ?? origin.x), y: 2 * origin.y - (control?.y ?? origin.y) } : origin, end = xy();
67
+ for (let i = 1; i <= 16; i++) {
68
+ const t = i / 16, s = 1 - t;
69
+ add({ x: s * s * origin.x + 2 * s * t * c.x + t * t * end.x, y: s * s * origin.y + 2 * s * t * c.y + t * t * end.y });
70
+ }
71
+ control = c;
72
+ }
73
+ else if (upper === 'A') {
74
+ let rx = Math.abs(read()), ry = Math.abs(read());
75
+ const angle = read() * rad, large = read() !== 0, sweep = read() !== 0, end = xy();
76
+ if (!rx || !ry || origin.x === end.x && origin.y === end.y)
77
+ add(end);
78
+ else {
79
+ const cos = Math.cos(angle), sin = Math.sin(angle), dx = (origin.x - end.x) / 2, dy = (origin.y - end.y) / 2, xp = cos * dx + sin * dy, yp = -sin * dx + cos * dy;
80
+ const scale = xp * xp / (rx * rx) + yp * yp / (ry * ry);
81
+ if (scale > 1) {
82
+ rx *= Math.sqrt(scale);
83
+ ry *= Math.sqrt(scale);
84
+ }
85
+ const q = Math.sqrt(Math.max(0, (rx * rx * ry * ry - rx * rx * yp * yp - ry * ry * xp * xp) / (rx * rx * yp * yp + ry * ry * xp * xp))) * (large === sweep ? -1 : 1);
86
+ const cxp = q * rx * yp / ry, cyp = -q * ry * xp / rx, cx = cos * cxp - sin * cyp + (origin.x + end.x) / 2, cy = sin * cxp + cos * cyp + (origin.y + end.y) / 2;
87
+ const a0 = Math.atan2((yp - cyp) / ry, (xp - cxp) / rx), a1 = Math.atan2((-yp - cyp) / ry, (-xp - cxp) / rx);
88
+ let delta = a1 - a0;
89
+ if (sweep && delta < 0)
90
+ delta += Math.PI * 2;
91
+ if (!sweep && delta > 0)
92
+ delta -= Math.PI * 2;
93
+ const steps = Math.max(1, Math.ceil(Math.abs(delta) * 16 / Math.PI));
94
+ for (let i = 1; i <= steps; i++) {
95
+ const a = a0 + delta * i / steps;
96
+ add({ x: cx + cos * rx * Math.cos(a) - sin * ry * Math.sin(a), y: cy + sin * rx * Math.cos(a) + cos * ry * Math.sin(a) });
97
+ }
98
+ }
99
+ }
100
+ if (!['C', 'S', 'Q', 'T'].includes(upper))
101
+ control = undefined;
102
+ previous = upper;
103
+ }
104
+ return contours;
105
+ }
106
+ function shapePath(shape) {
107
+ const w = shape.bounds.width, h = shape.bounds.height;
108
+ if (shape.path)
109
+ return mapPathToBounds(shape.path, shape.pathBounds ?? { x: 0, y: 0, width: w, height: h }, w, h);
110
+ const geometry = presetGeometry(shape.preset, w, h, shape.source?.properties);
111
+ if (geometry.tag === 'path')
112
+ return /\bd="([^"]*)"/.exec(geometry.attrs)?.[1] ?? '';
113
+ if (geometry.tag === 'ellipse')
114
+ return `M${w} ${h / 2} A${w / 2} ${h / 2} 0 1 1 0 ${h / 2} A${w / 2} ${h / 2} 0 1 1 ${w} ${h / 2} Z`;
115
+ const rx = Number(/\brx="([^"]*)"/.exec(geometry.attrs)?.[1] ?? 0);
116
+ return rx ? `M${rx} 0 H${w - rx} A${rx} ${rx} 0 0 1 ${w} ${rx} V${h - rx} A${rx} ${rx} 0 0 1 ${w - rx} ${h} H${rx} A${rx} ${rx} 0 0 1 0 ${h - rx} V${rx} A${rx} ${rx} 0 0 1 ${rx} 0 Z` : `M0 0 H${w} V${h} H0 Z`;
117
+ }
118
+ class ExtrusionCameraError extends RangeError {
119
+ }
120
+ function extrusionProjector(e, width, height) {
121
+ const yr = finite(e.rotationY) * rad, xr = finite(e.rotationX) * rad, cy = Math.cos(yr), sy = Math.sin(yr), cx = Math.cos(xr), sx = Math.sin(xr);
122
+ const skew = e.skewAngle === 0 ? 0 : finite(e.skewAmount) / 100, kx = Math.cos(finite(e.skewAngle) * rad) * skew, ky = Math.sin(finite(e.skewAngle) * rad) * skew;
123
+ const rotate = (point) => {
124
+ const x = point.x - width / 2, y = point.y - height / 2, x1 = x * cy + point.z * sy, z1 = -x * sy + point.z * cy;
125
+ return { x: width / 2 + x1, y: height / 2 + y * cx - z1 * sx, z: y * sx + z1 * cx };
126
+ };
127
+ let camera;
128
+ if (!e.parallel) {
129
+ if (!e.camera || ![e.camera.x, e.camera.y, e.camera.z].every(Number.isFinite) || e.camera.z <= 0)
130
+ throw new ExtrusionCameraError('Perspective camera is missing or has a nonpositive distance');
131
+ camera = { x: width / 2 + finite(e.origin?.x, .5) * width + e.camera.x, y: height / 2 + finite(e.origin?.y, -.5) * height + e.camera.y, z: e.camera.z };
132
+ }
133
+ const project = (point) => {
134
+ const p = rotate(point);
135
+ if (!camera)
136
+ return { x: p.x + p.z * kx, y: p.y + p.z * ky, z: p.z };
137
+ const distance = camera.z - p.z;
138
+ if (distance <= Math.max(1e-6, camera.z * 1e-6))
139
+ throw new ExtrusionCameraError('Perspective extrusion crosses the camera plane');
140
+ const scale = camera.z / distance;
141
+ return { x: camera.x + (p.x - camera.x) * scale, y: camera.y + (p.y - camera.y) * scale, z: p.z };
142
+ };
143
+ return { rotate, project, view: p => camera ? { x: camera.x - p.x, y: camera.y - p.y, z: camera.z - p.z } : { x: -kx, y: -ky, z: 1 } };
144
+ }
145
+ /** Constrained Y-then-X rotation followed by the selected projection. */
146
+ export function projectExtrusionPoint(point, e, width, height) {
147
+ return extrusionProjector(e, width, height).project(point);
148
+ }
149
+ /** Closed contours produce true side quads; the original vector painting is the front face. */
150
+ export function buildExtrusionMesh(shape) {
151
+ const e = shape.extrusion;
152
+ if (!e)
153
+ return undefined;
154
+ const w = finite(shape.bounds.width), h = finite(shape.bounds.height), contours = flattenPath(shapePath(shape)), faces = [];
155
+ const projector = extrusionProjector(e, w, h), project = (p, z) => projector.project({ ...p, z }), rotate = (p, z) => projector.rotate({ ...p, z }), forward = Math.max(0, finite(e.forward)), back = -Math.max(0, finite(e.depth));
156
+ for (const contour of contours) {
157
+ if (!contour.closed || contour.points.length < 3)
158
+ continue;
159
+ const points = contour.points, orientation = contours.length === 1 && points.reduce((area, a, i) => { const b = points[(i + 1) % points.length]; return area + a.x * b.y - b.x * a.y; }, 0) < 0 ? -1 : 1;
160
+ for (let i = 0; i < points.length; i++) {
161
+ const a = points[i], b = points[(i + 1) % points.length];
162
+ if (a.x === b.x && a.y === b.y)
163
+ continue;
164
+ const p = [project(a, back), project(b, back), project(b, forward), project(a, forward)];
165
+ // Projection changes screen-space slopes, not physical surface normals.
166
+ const r0 = rotate(a, back), r1 = rotate(b, back), r3 = rotate(a, forward), ux = r1.x - r0.x, uy = r1.y - r0.y, uz = r1.z - r0.z, vx = r3.x - r0.x, vy = r3.y - r0.y, vz = r3.z - r0.z;
167
+ const nx = (uy * vz - uz * vy) * orientation, ny = (uz * vx - ux * vz) * orientation, nz = (ux * vy - uy * vx) * orientation, length = Math.hypot(nx, ny, nz) || 1, light = Math.max(0, (-.4 * nx - .6 * ny + nz) / (length * Math.sqrt(1.52)));
168
+ const intensity = Math.max(0, Math.min(1, finite(e.ambient, .3) + finite(e.diffuse, 1) * light));
169
+ const view = projector.view({ x: r0.x + (ux + vx) / 2, y: r0.y + (uy + vy) / 2, z: r0.z + (uz + vz) / 2 });
170
+ faces.push({ points: p, depth: p.reduce((sum, q) => sum + q.z, 0) / 4, intensity, visible: contours.length > 1 || nx * view.x + ny * view.y + nz * view.z > 1e-8 });
171
+ }
172
+ }
173
+ faces.sort((a, b) => a.depth - b.depth);
174
+ const dx = w || 1, dy = h || 1, p = project({ x: 0, y: 0 }, forward), x = project({ x: dx, y: 0 }, forward), y = project({ x: 0, y: dy }, forward);
175
+ return { faces, frontMatrix: [(x.x - p.x) / dx, (x.y - p.y) / dx, (y.x - p.x) / dy, (y.y - p.y) / dy, p.x, p.y], contours };
176
+ }
177
+ function litColor(value, intensity) {
178
+ const safe = color(value, '#808080');
179
+ let rgb = safe.slice(1);
180
+ if (rgb.length === 3)
181
+ rgb = rgb.split('').map(v => v + v).join('');
182
+ if (!/^[\da-f]{6,8}$/i.test(rgb))
183
+ return '#808080';
184
+ return '#' + [0, 2, 4].map(i => Math.round(parseInt(rgb.slice(i, i + 2), 16) * intensity).toString(16).padStart(2, '0')).join('');
185
+ }
186
+ export function renderExtrusion(shape, frontMarkup, ctx) {
187
+ const e = shape.extrusion;
188
+ if (!e || e.depth + e.forward <= 0)
189
+ return frontMarkup;
190
+ const warning = (code, message) => ctx.warnings?.push({ code, severity: 'warning', message, shapeId: shape.id, slideId: ctx.slideId });
191
+ if (shape.wordArt) {
192
+ warning('WORDART_EXTRUSION_UNSUPPORTED', 'WordArt envelope is rendered, but glyph contour extrusion requires font outline data');
193
+ return frontMarkup;
194
+ }
195
+ let mesh;
196
+ try {
197
+ mesh = buildExtrusionMesh(shape);
198
+ }
199
+ catch (error) {
200
+ if (error instanceof ExtrusionCameraError)
201
+ warning('EXTRUSION_CAMERA_UNSUPPORTED', error.message + '; the saved foreground is retained');
202
+ else
203
+ warning('EXTRUSION_PATH_LIMIT', 'Extrusion contour is invalid or exceeds its 4,096-point rendering limit');
204
+ return frontMarkup;
205
+ }
206
+ if (!mesh || !mesh.faces.length) {
207
+ warning('EXTRUSION_OPEN_CONTOUR', '3D extrusion requires a supported closed shape contour');
208
+ return frontMarkup;
209
+ }
210
+ if (!e.parallel && (e.rotationX !== 0 || e.rotationY !== 0))
211
+ warning('EXTRUSION_PERSPECTIVE_APPROXIMATED', 'Rotated perspective side faces use the saved camera; the projective front plane uses a three-corner affine approximation');
212
+ if (e.metallic)
213
+ warning('EXTRUSION_MATERIAL_APPROXIMATED', 'Metallic material uses diffuse vector shading; specular highlights are not reproduced');
214
+ if (mesh.contours.length > 1)
215
+ warning('EXTRUSION_COMPLEX_CONTOUR_APPROXIMATED', 'Compound extrusion contours use sorted side faces; exact hidden-surface removal is not implemented');
216
+ const c = ctx.resolveColor(e.color, e.colorIndex, shape.fill.color ?? '#808080');
217
+ const sides = mesh.faces.filter(face => face.visible).map(face => `<polygon points="${face.points.map(p => `${n(p.x)},${n(p.y)}`).join(' ')}" fill="${litColor(c, face.intensity)}" stroke="${litColor(c, face.intensity)}" stroke-width=".25" stroke-linejoin="round"/>`).join('');
218
+ return `<g data-ppt-extrusion="mesh">${sides}<g transform="matrix(${mesh.frontMatrix.map(n).join(' ')})">${frontMarkup}</g></g>`;
219
+ }
@@ -0,0 +1,16 @@
1
+ import type { PptShape } from '../types.js';
2
+ import type { EffectContext } from './effects.js';
3
+ export interface WarpPoint {
4
+ x: number;
5
+ y: number;
6
+ }
7
+ export declare const SUPPORTED_WORDART_PRESETS: Set<number>;
8
+ /** Continuous envelope maps. u/v describe the unwarped text rectangle, in [0,1].
9
+ * Curves are sampled into affine triangles by renderWordArt; the browser supplies glyph outlines.
10
+ * These analytic envelopes follow MSOSPT's shape families, not Office's unpublished font engine.
11
+ */
12
+ export declare function warpPoint(preset: number, u: number, v: number, adjustments?: readonly number[]): WarpPoint;
13
+ /** Affine map from a triangle in the unit source square to a target triangle. */
14
+ export declare function triangleMatrix(source: readonly [WarpPoint, WarpPoint, WarpPoint], target: readonly [WarpPoint, WarpPoint, WarpPoint]): [number, number, number, number, number, number] | undefined;
15
+ /** Paints deformed browser glyphs, rather than laying undeformed letters on a textPath. */
16
+ export declare function renderWordArt(shape: PptShape, fillAttrs: string, strokeAttrs: string, ctx: EffectContext): string | undefined;
@@ -0,0 +1,214 @@
1
+ import { cssFont, escapeXml, finite, n } from './safe.js';
2
+ import { createCanvasTextMeasurer } from '../layout/measure.js';
3
+ const clamp = (n, low = 0, high = 1) => Math.max(low, Math.min(high, n));
4
+ export const SUPPORTED_WORDART_PRESETS = new Set([24, 25, 26, 27, 28, 29, 30, 31, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175]);
5
+ /** Continuous envelope maps. u/v describe the unwarped text rectangle, in [0,1].
6
+ * Curves are sampled into affine triangles by renderWordArt; the browser supplies glyph outlines.
7
+ * These analytic envelopes follow MSOSPT's shape families, not Office's unpublished font engine.
8
+ */
9
+ export function warpPoint(preset, u, v, adjustments = []) {
10
+ const amount = clamp(Math.abs(finite(adjustments[0], 5400)) / 21600, 0, .48), bell = 4 * u * (1 - u), triangle = 1 - Math.abs(2 * u - 1);
11
+ let top = 0, bottom = 1, x = u;
12
+ switch (preset) {
13
+ case 24:
14
+ case 136: break;
15
+ case 25:
16
+ case 137:
17
+ top = amount * Math.abs(2 * u - 1);
18
+ bottom = 1 - top;
19
+ break;
20
+ case 26:
21
+ top = amount * Math.max(0, Math.abs(2 * u - 1) - .5) * 2;
22
+ bottom = 1 - top;
23
+ break;
24
+ case 138:
25
+ top = 1 - triangle;
26
+ break;
27
+ case 139:
28
+ bottom = triangle;
29
+ break;
30
+ case 140:
31
+ top = amount * triangle;
32
+ bottom = 1 - amount + amount * triangle;
33
+ break;
34
+ case 141:
35
+ top = amount * (1 - triangle);
36
+ bottom = 1 - amount * triangle;
37
+ break;
38
+ case 27:
39
+ case 30:
40
+ case 152:
41
+ top = amount * (1 - bell);
42
+ bottom = 1 - amount * bell;
43
+ break;
44
+ case 153:
45
+ top = amount * bell;
46
+ bottom = 1 - amount + amount * bell;
47
+ break;
48
+ case 154:
49
+ case 172:
50
+ top = amount * (1 - u);
51
+ bottom = 1 - amount * u;
52
+ break;
53
+ case 155:
54
+ case 173:
55
+ top = amount * u;
56
+ bottom = 1 - amount * (1 - u);
57
+ break;
58
+ case 28:
59
+ case 156:
60
+ case 157:
61
+ case 158:
62
+ case 159: {
63
+ const cycles = preset === 158 || preset === 159 ? 2 : 1, phase = finite(adjustments[1]) / 21600 * Math.PI * 2;
64
+ const wave = Math.sin(u * Math.PI * 2 * cycles + phase) * (preset === 157 || preset === 159 ? -1 : 1);
65
+ top = amount * (1 + wave) / 2;
66
+ bottom = 1 - amount + top;
67
+ break;
68
+ }
69
+ case 160:
70
+ top = amount * (1 - bell);
71
+ bottom = 1 - top;
72
+ break;
73
+ case 161:
74
+ top = amount * bell;
75
+ bottom = 1 - top;
76
+ break;
77
+ case 162:
78
+ bottom = 1 - amount + amount * bell;
79
+ break;
80
+ case 163:
81
+ bottom = 1 - amount * bell;
82
+ break;
83
+ case 164:
84
+ top = amount * (1 - bell);
85
+ break;
86
+ case 165:
87
+ top = amount * bell;
88
+ break;
89
+ case 166: {
90
+ const q = Math.sin(2 * Math.PI * u);
91
+ top = amount * (1 + q) / 2;
92
+ bottom = 1 - top;
93
+ break;
94
+ }
95
+ case 167: {
96
+ const q = Math.cos(4 * Math.PI * u);
97
+ top = amount * (1 + q) / 2;
98
+ bottom = 1 - top;
99
+ break;
100
+ }
101
+ case 168:
102
+ top = amount * u;
103
+ bottom = 1 - top;
104
+ break;
105
+ case 169:
106
+ top = amount * (1 - u);
107
+ bottom = 1 - top;
108
+ break;
109
+ case 170:
110
+ x = amount * (1 - v) + u * (1 - 2 * amount * (1 - v));
111
+ break;
112
+ case 171:
113
+ x = amount * v + u * (1 - 2 * amount * v);
114
+ break;
115
+ case 174:
116
+ top = amount * (1 - bell);
117
+ bottom = 1 - amount * bell;
118
+ break;
119
+ case 175:
120
+ top = amount * bell;
121
+ bottom = 1 - amount + amount * bell;
122
+ break;
123
+ case 29:
124
+ case 31:
125
+ case 142:
126
+ case 143:
127
+ case 144:
128
+ case 145:
129
+ case 146:
130
+ case 147:
131
+ case 148:
132
+ case 149:
133
+ case 150:
134
+ case 151: {
135
+ const full = [29, 31, 142, 143, 146, 147, 150, 151].includes(preset), down = preset === 145 || preset === 149;
136
+ const sweep = full ? 2 * Math.PI : Math.PI;
137
+ const theta = (down ? 0 : Math.PI) + u * sweep, radius = .5 - (.16 + .5 * amount) * (preset === 142 ? 1 - v : v);
138
+ const y = .5 + Math.sin(theta) * radius;
139
+ return { x: .5 + Math.cos(theta) * radius, y: full ? y : down ? (y - .5) * 2 : y * 2 };
140
+ }
141
+ default: break;
142
+ }
143
+ return { x, y: top + (bottom - top) * v };
144
+ }
145
+ /** Affine map from a triangle in the unit source square to a target triangle. */
146
+ export function triangleMatrix(source, target) {
147
+ const [a, b, c] = source, [p, q, r] = target, ux = b.x - a.x, uy = b.y - a.y, vx = c.x - a.x, vy = c.y - a.y, d = ux * vy - uy * vx;
148
+ if (Math.abs(d) < 1e-12)
149
+ return undefined;
150
+ const aa = ((q.x - p.x) * vy - (r.x - p.x) * uy) / d, cc = ((r.x - p.x) * ux - (q.x - p.x) * vx) / d;
151
+ const bb = ((q.y - p.y) * vy - (r.y - p.y) * uy) / d, dd = ((r.y - p.y) * ux - (q.y - p.y) * vx) / d;
152
+ return [aa, bb, cc, dd, p.x - aa * a.x - cc * a.y, p.y - bb * a.x - dd * a.y];
153
+ }
154
+ /** Paints deformed browser glyphs, rather than laying undeformed letters on a textPath. */
155
+ export function renderWordArt(shape, fillAttrs, strokeAttrs, ctx) {
156
+ const art = shape.wordArt;
157
+ if (!art)
158
+ return undefined;
159
+ const w = Math.max(0, finite(shape.bounds.width)), h = Math.max(0, finite(shape.bounds.height));
160
+ if (!w || !h || !art.text)
161
+ return '';
162
+ const supported = SUPPORTED_WORDART_PRESETS.has(art.warpPreset), preset = supported ? art.warpPreset : 136;
163
+ if (!supported)
164
+ ctx.warnings?.push({ code: 'WORDART_WARP_UNSUPPORTED', severity: 'warning', message: `WordArt envelope ${art.warpPreset} is shown without warping`, shapeId: shape.id, slideId: ctx.slideId });
165
+ const textId = `${ctx.id}-glyphs`, lines = art.text.replace(/\r\n/g, '\n').split(/[\r\n]/, 1025);
166
+ if (lines.length > 1024) {
167
+ lines.length = 1024;
168
+ ctx.warnings?.push({ code: 'WORDART_RENDER_LIMIT', severity: 'warning', message: 'WordArt rendering is limited to 1,024 rows; the full source text remains available in the model', shapeId: shape.id, slideId: ctx.slideId });
169
+ }
170
+ const rows = Math.max(1, lines.length), fontSize = 1000, letterSpacing = (Math.max(0, finite(art.spacing, 1)) - 1) * fontSize * .5, measurer = ctx.textMeasurer ?? createCanvasTextMeasurer();
171
+ const style = { fontFamily: art.fontFamily, fontSize, bold: art.bold, italic: art.italic, letterSpacing };
172
+ let approximate = false;
173
+ const metrics = lines.map(text => {
174
+ const measured = measurer?.measure(text, style);
175
+ if (measured && Number.isFinite(measured.width) && measured.width > 0 && measured.ascent + measured.descent > 0)
176
+ return measured;
177
+ approximate = true;
178
+ let width = 0, count = 0;
179
+ for (const c of text) {
180
+ count++;
181
+ width += (c.codePointAt(0) >= 0x2E80 ? 1 : /[MW@]/.test(c) ? 1 : /[mw]/.test(c) ? .9 : /[ilI.,'!|]/.test(c) ? .28 : /[frjt]/.test(c) ? .42 : /\s/.test(c) ? .33 : /[A-Z]/.test(c) ? .72 : .62) * fontSize;
182
+ }
183
+ return { width: Math.max(1, width * 1.2 + Math.max(0, count - 1) * letterSpacing), ascent: fontSize * .8, descent: fontSize * .2 };
184
+ });
185
+ if (approximate)
186
+ ctx.warnings?.push({ code: 'WORDART_METRICS_APPROXIMATED', severity: 'warning', message: 'Font measurement is unavailable; WordArt source fitting uses conservative character widths', shapeId: shape.id, slideId: ctx.slideId });
187
+ const maxWidth = metrics.reduce((max, m) => Math.max(max, m.width), 1), body = lines.map((text, index) => {
188
+ const metric = metrics[index], length = art.alignment === 'justify' ? 1000 : 1000 * metric.width / maxWidth, tx = art.alignment === 'right' ? 1000 - length : art.alignment === 'center' ? (1000 - length) / 2 : 0, sx = length / Math.max(1, metric.width), sy = 1000 / rows / (metric.ascent + metric.descent), anchor = art.alignment === 'right' ? 'end' : art.alignment === 'center' ? 'middle' : 'start', x = anchor === 'end' ? metric.width : anchor === 'middle' ? metric.width / 2 : 0;
189
+ return `<g transform="translate(${n(tx)} ${n(index * 1000 / rows)}) scale(${n(sx)} ${n(sy)})"><text x="${n(x)}" y="${n(metric.ascent)}" text-anchor="${anchor}" font-size="${fontSize}" vector-effect="non-scaling-stroke" letter-spacing="${n(letterSpacing)}">${escapeXml(text)}</text></g>`;
190
+ }).join('');
191
+ // Scale to a unit square before clipping; all strips reference this one glyph object.
192
+ ctx.defs.push(`<g id="${textId}" transform="scale(.001)" text-rendering="geometricPrecision" font-family="${escapeXml(cssFont(art.fontFamily))}"${art.bold ? ' font-weight="700"' : ''}${art.italic ? ' font-style="italic"' : ''} ${fillAttrs} ${strokeAttrs}>${body}</g>`);
193
+ const columns = preset === 136 || preset === 24 ? 1 : 48, parts = [];
194
+ if (columns > 1)
195
+ ctx.warnings?.push({ code: 'WORDART_MESH_RASTERIZATION_APPROXIMATED', severity: 'warning', message: 'WordArt is deformed through clipped affine glyph slices; some SVG rasterizers can show fine seams at slice boundaries', shapeId: shape.id, slideId: ctx.slideId });
196
+ for (let i = 0; i < columns; i++) {
197
+ const x0 = i / columns, x1 = (i + 1) / columns;
198
+ const a = { x: x0, y: 0 }, b = { x: x1, y: 0 }, c = { x: x1, y: 1 }, d = { x: x0, y: 1 };
199
+ for (const [j, source] of [[a, b, c], [a, c, d]].entries()) {
200
+ const target = source.map(p => { const q = warpPoint(preset, p.x, p.y, art.adjustments); return art.vertical ? { x: (1 - q.y) * w, y: q.x * h } : { x: q.x * w, y: q.y * h }; });
201
+ const m = triangleMatrix(source, target);
202
+ if (!m || !m.every(Number.isFinite))
203
+ continue;
204
+ const clipId = `${ctx.id}-clip-${i}-${j}`;
205
+ // Overlap reduces clip-edge antialiasing gaps. Independent glyph hinting in
206
+ // some SVG rasterizers can still expose seams; report that rendering limit.
207
+ const center = { x: source.reduce((s, p) => s + p.x, 0) / 3, y: source.reduce((s, p) => s + p.y, 0) / 3 }, epsilon = .0025;
208
+ const clip = source.map(p => ({ x: p.x + Math.sign(p.x - center.x) * epsilon, y: p.y + Math.sign(p.y - center.y) * epsilon }));
209
+ ctx.defs.push(`<clipPath id="${clipId}" clipPathUnits="userSpaceOnUse"><path d="M${clip.map(p => `${n(p.x)} ${n(p.y)}`).join('L')}Z"/></clipPath>`);
210
+ parts.push(`<g transform="matrix(${m.map(n).join(' ')})"><g clip-path="url(#${clipId})"><use href="#${textId}" xlink:href="#${textId}"/></g></g>`);
211
+ }
212
+ }
213
+ return `<g data-ppt-wordart="${art.warpPreset}" aria-label="${escapeXml(art.text)}"><g aria-hidden="true">${parts.join('')}</g></g>`;
214
+ }
@@ -0,0 +1,125 @@
1
+ import type { PptDocument as ParsedPptDocument, ParseOptions, PptViewer, ViewerOptions } from './types.js';
2
+ export interface PptRenderOptions {
3
+ scale?: number;
4
+ pixelRatio?: number;
5
+ }
6
+ export interface PptMountOptions extends PptRenderOptions {
7
+ replace?: boolean;
8
+ className?: string;
9
+ virtualize?: boolean;
10
+ scrollRoot?: Element | Document | null;
11
+ rootMargin?: string;
12
+ releaseDelayMs?: number;
13
+ }
14
+ export type PptAssetSource = string | URL | Response | ArrayBuffer | Uint8Array;
15
+ export interface PptFrameCacheOptions {
16
+ enabled?: boolean;
17
+ dbName?: string;
18
+ maxBytes?: number;
19
+ maxEntries?: number;
20
+ maxEntryBytes?: number;
21
+ }
22
+ export interface LoadPptViewerOptions {
23
+ worker?: 'auto' | boolean;
24
+ workerUrl?: string | URL;
25
+ transferInputOwnership?: boolean;
26
+ parseOptions?: ParseOptions;
27
+ /** Accepted for migration. The TypeScript runtime does not load native WASM or bundled fonts. */
28
+ wasmUrl?: PptAssetSource;
29
+ fontUrl?: PptAssetSource;
30
+ /** Accepted for migration. Persistent raster caching is not used by the SVG runtime. */
31
+ cache?: false | PptFrameCacheOptions;
32
+ }
33
+ export interface PptFrameCacheStats {
34
+ readonly enabled: boolean;
35
+ readonly available: boolean;
36
+ readonly disabledReason: string | null;
37
+ readonly entries: number;
38
+ readonly bytes: number;
39
+ readonly maxBytes: number;
40
+ readonly maxEntries: number;
41
+ readonly maxEntryBytes: number;
42
+ readonly hits: number;
43
+ readonly misses: number;
44
+ readonly writes: number;
45
+ readonly nativeRenders: number;
46
+ readonly svgRenders: number;
47
+ readonly cancellations: number;
48
+ readonly attachedCanvases: number;
49
+ readonly activeCanvases: number;
50
+ readonly wasmMemoryBytes: number;
51
+ }
52
+ export interface PptRenderResult {
53
+ readonly cancelled?: boolean;
54
+ readonly slideIndex: number;
55
+ readonly width: number;
56
+ readonly height: number;
57
+ readonly logicalWidth: number;
58
+ readonly logicalHeight: number;
59
+ readonly scale: number;
60
+ readonly pixelRatio: number;
61
+ readonly source: 'svg';
62
+ }
63
+ export interface PptDocument {
64
+ readonly mode: 'worker' | 'direct';
65
+ readonly documentId: string;
66
+ readonly slideCount: number;
67
+ readonly width: number;
68
+ readonly height: number;
69
+ readonly closed: boolean;
70
+ readonly model: ParsedPptDocument;
71
+ renderSlide(index: number, canvas: HTMLCanvasElement | OffscreenCanvas, options?: PptRenderOptions): Promise<PptRenderResult>;
72
+ releaseSlide(index: number): Promise<boolean>;
73
+ cacheStats(): Promise<PptFrameCacheStats>;
74
+ close(): Promise<void>;
75
+ }
76
+ export interface MountedPptViewer {
77
+ readonly document: PptDocument;
78
+ readonly root: HTMLElement;
79
+ readonly canvases: readonly HTMLCanvasElement[];
80
+ readonly virtualized: boolean;
81
+ renderSlide(index: number): Promise<PptRenderResult | void>;
82
+ cacheStats(): Promise<PptFrameCacheStats>;
83
+ close(): Promise<void>;
84
+ }
85
+ export interface PptViewerRuntime {
86
+ readonly mode: 'worker' | 'direct';
87
+ readonly license: Readonly<PptRuntimeLicenseSummary>;
88
+ readonly watermark: Readonly<PptWatermarkSummary>;
89
+ open(input: ArrayBuffer | Uint8Array): Promise<PptDocument>;
90
+ mount(target: string | HTMLElement, input: ArrayBuffer | Uint8Array, options?: PptMountOptions): Promise<MountedPptViewer>;
91
+ cacheStats(): Promise<PptFrameCacheStats>;
92
+ close(): Promise<void>;
93
+ }
94
+ export interface PptRuntimeLicenseSummary {
95
+ readonly id: 'FV-PPT-TYPESCRIPT-APACHE-2.0';
96
+ readonly edition: 'public';
97
+ readonly holder: 'Individuals and Organizations';
98
+ readonly policy: 'Apache-2.0';
99
+ readonly commercialUse: true;
100
+ readonly apacheLicenseApplies: true;
101
+ readonly redistributionAllowed: true;
102
+ readonly standaloneRedistributionAllowed: true;
103
+ }
104
+ export interface PptWatermarkSummary {
105
+ readonly required: false;
106
+ readonly text: '';
107
+ }
108
+ export interface PptPackageManifest {
109
+ readonly kind: 'flyfish-ppt-typescript-v1';
110
+ readonly product: 'Flyfish PPT Viewer';
111
+ readonly format: 'PowerPoint 97-2003 (.ppt)';
112
+ readonly packageName: '@file-viewer/ppt';
113
+ readonly packageVersion: string;
114
+ readonly renderer: 'typescript-svg-canvas';
115
+ readonly license: 'Apache-2.0';
116
+ readonly watermarkRequired: false;
117
+ readonly wasmRequired: false;
118
+ readonly workerFile: 'worker.mjs';
119
+ readonly sourceRepositoryPrivate: true;
120
+ }
121
+ export declare function getPptPackageManifest(): PptPackageManifest;
122
+ export declare function loadPptViewer(options?: LoadPptViewerOptions): Promise<PptViewerRuntime>;
123
+ /** The container overload is the single-slide SVG viewer; options alone retains the existing Canvas API. */
124
+ export declare function createPptViewer(container: HTMLElement, options?: ViewerOptions): PptViewer;
125
+ export declare function createPptViewer(options?: LoadPptViewerOptions): Promise<PptViewerRuntime>;