pptx-angular-viewer 4.24.2 → 4.25.0

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 (41) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +9 -9
  3. package/ng-package.json +25 -0
  4. package/package.json +45 -20
  5. package/scripts/finalize-dist.mjs +24 -0
  6. package/scripts/inline-shared.mjs +43 -0
  7. package/tsconfig.lib.json +13 -0
  8. package/vitest-setup.ts +12 -0
  9. package/fesm2022/pptx-angular-viewer-bar-chart-3d-hit-test-B6eCwecE.mjs +0 -9855
  10. package/fesm2022/pptx-angular-viewer-bar-chart-3d-hit-test-B6eCwecE.mjs.map +0 -1
  11. package/fesm2022/pptx-angular-viewer-chart-3d-view-scene-IqColhvd.mjs +0 -1594
  12. package/fesm2022/pptx-angular-viewer-chart-3d-view-scene-IqColhvd.mjs.map +0 -1
  13. package/fesm2022/pptx-angular-viewer-chat-history-idb-7dzD77Ju.mjs +0 -73
  14. package/fesm2022/pptx-angular-viewer-chat-history-idb-7dzD77Ju.mjs.map +0 -1
  15. package/fesm2022/pptx-angular-viewer-chat-history-store-Ckeu-olx.mjs +0 -121
  16. package/fesm2022/pptx-angular-viewer-chat-history-store-Ckeu-olx.mjs.map +0 -1
  17. package/fesm2022/pptx-angular-viewer-view-overflow-BBD8nZlq.mjs +0 -1418
  18. package/fesm2022/pptx-angular-viewer-view-overflow-BBD8nZlq.mjs.map +0 -1
  19. package/fesm2022/pptx-angular-viewer-view-scene-htTUkvvA.mjs +0 -836
  20. package/fesm2022/pptx-angular-viewer-view-scene-htTUkvvA.mjs.map +0 -1
  21. package/fesm2022/pptx-angular-viewer.mjs +0 -169787
  22. package/fesm2022/pptx-angular-viewer.mjs.map +0 -1
  23. package/i18n/de.cjs +0 -4165
  24. package/i18n/de.d.cts +0 -3
  25. package/i18n/de.d.mts +0 -3
  26. package/i18n/de.mjs +0 -4138
  27. package/i18n/es.cjs +0 -4165
  28. package/i18n/es.d.cts +0 -3
  29. package/i18n/es.d.mts +0 -3
  30. package/i18n/es.mjs +0 -4138
  31. package/i18n/fr.cjs +0 -4165
  32. package/i18n/fr.d.cts +0 -3
  33. package/i18n/fr.d.mts +0 -3
  34. package/i18n/fr.mjs +0 -4138
  35. package/i18n/zh-CN.cjs +0 -4198
  36. package/i18n/zh-CN.d.cts +0 -3
  37. package/i18n/zh-CN.d.mts +0 -3
  38. package/i18n/zh-CN.mjs +0 -4171
  39. package/pptx-angular-viewer.css +0 -2
  40. package/types/pptx-angular-viewer.d.ts +0 -59990
  41. package/types/pptx-angular-viewer.d.ts.map +0 -1
@@ -1,836 +0,0 @@
1
- import { a as overflowViewOffset, f as smartArt3DGradientColor, g as resolveSmartArt3DLightModel, h as shadeSmartArt3DVertices, m as hexToRgb, n as hasThreeViewOverflow, p as smartArt3DGradientCoordinate, s as threeViewOverflowFromNdc, t as NO_THREE_VIEW_OVERFLOW, v as smartArt3DCameraMatrix, y as smartArt3DEyeInDiagram } from "./pptx-angular-viewer-view-overflow-BBD8nZlq.mjs";
2
- const CLEAR_FACE_ALPHA = .2;
3
- const CLEAR_EDGE_GAIN = 2;
4
- const CLEAR_EDGE_EXPONENT = 1;
5
- function isSmartArt3DGlassMaterial(material) {
6
- return material === "clear";
7
- }
8
- function smartArt3DSurfaceAlpha(material, opacity, facing) {
9
- if (!isSmartArt3DGlassMaterial(material)) return opacity;
10
- const tilt = 1 - Math.max(0, Math.min(1, facing));
11
- const share = CLEAR_FACE_ALPHA + CLEAR_EDGE_GAIN * tilt ** CLEAR_EDGE_EXPONENT;
12
- return Math.max(0, Math.min(1, opacity * share));
13
- }
14
- function smartArt3DVertexAlphas(positions, normals, material, opacity, eye) {
15
- const out = new Float32Array(positions.length / 3);
16
- for (let i = 0, v = 0; i < positions.length; i += 3, v++) {
17
- let view = {
18
- x: 0,
19
- y: 0,
20
- z: 1
21
- };
22
- if (eye) {
23
- const dx = eye.x - positions[i];
24
- const dy = eye.y - positions[i + 1];
25
- const dz = eye.z - positions[i + 2];
26
- const len = Math.hypot(dx, dy, dz) || 1;
27
- view = {
28
- x: dx / len,
29
- y: dy / len,
30
- z: dz / len
31
- };
32
- }
33
- const facing = normals[i] * view.x + normals[i + 1] * view.y + normals[i + 2] * view.z;
34
- out[v] = smartArt3DSurfaceAlpha(material, opacity, facing);
35
- }
36
- return out;
37
- }
38
- function orientSmartArt3DTriangles(triangles) {
39
- const { positions: p, normals: n } = triangles;
40
- for (let t = 0; t + 9 <= p.length; t += 9) {
41
- const ux = p[t + 3] - p[t];
42
- const uy = p[t + 4] - p[t + 1];
43
- const uz = p[t + 5] - p[t + 2];
44
- const vx = p[t + 6] - p[t];
45
- const vy = p[t + 7] - p[t + 1];
46
- const vz = p[t + 8] - p[t + 2];
47
- const cx = uy * vz - uz * vy;
48
- const cy = uz * vx - ux * vz;
49
- const cz = ux * vy - uy * vx;
50
- const nx = n[t] + n[t + 3] + n[t + 6];
51
- const ny = n[t + 1] + n[t + 4] + n[t + 7];
52
- const nz = n[t + 2] + n[t + 5] + n[t + 8];
53
- if (cx * nx + cy * ny + cz * nz < 0) for (const arr of [p, n]) for (let c = 0; c < 3; c++) {
54
- const b = arr[t + 3 + c];
55
- arr[t + 3 + c] = arr[t + 6 + c];
56
- arr[t + 6 + c] = b;
57
- }
58
- }
59
- }
60
- function isSmartArt3DTranslucentMesh(mesh) {
61
- return !mesh.fillNone && (mesh.opacity < 1 || isSmartArt3DGlassMaterial(mesh.solid?.material));
62
- }
63
- function smartArt3DGlassLightModel(model) {
64
- return {
65
- ...model,
66
- ambient: 1,
67
- diffuse: 0
68
- };
69
- }
70
- const SUPERSAMPLE = 3;
71
- function buildTextBlockTexture(three, block) {
72
- if (typeof document === "undefined" || block.lines.every((l) => l.text.length === 0)) return null;
73
- const worldWidth = Math.max(1, block.maxWidth);
74
- const worldHeight = Math.max(1, block.maxHeight);
75
- const canvas = document.createElement("canvas");
76
- canvas.width = Math.max(8, Math.round(worldWidth * SUPERSAMPLE));
77
- canvas.height = Math.max(8, Math.round(worldHeight * SUPERSAMPLE));
78
- const ctx2d = canvas.getContext("2d");
79
- if (!ctx2d) return null;
80
- const weight = block.fontWeight ?? 400;
81
- const italic = block.fontStyle === "italic" ? "italic " : "";
82
- const family = block.fontFamily ? `${block.fontFamily}, system-ui, sans-serif` : "system-ui, -apple-system, Segoe UI, Roboto, sans-serif";
83
- const px = Math.max(6, block.fontSize) * SUPERSAMPLE;
84
- ctx2d.clearRect(0, 0, canvas.width, canvas.height);
85
- ctx2d.fillStyle = block.color;
86
- ctx2d.textAlign = "center";
87
- ctx2d.textBaseline = "middle";
88
- ctx2d.font = `${italic}${weight} ${px}px ${family}`;
89
- const centerX = canvas.width / 2;
90
- const centerY = canvas.height / 2;
91
- for (const line of block.lines) {
92
- if (!line.text) continue;
93
- ctx2d.fillText(line.text, centerX, centerY - line.dy * SUPERSAMPLE);
94
- }
95
- const texture = new three.CanvasTexture(canvas);
96
- texture.colorSpace = three.SRGBColorSpace;
97
- texture.minFilter = three.LinearFilter;
98
- texture.magFilter = three.LinearFilter;
99
- texture.flipY = false;
100
- texture.premultiplyAlpha = false;
101
- texture.wrapT = three.RepeatWrapping;
102
- texture.repeat.set(1, -1);
103
- texture.offset.set(0, 1);
104
- texture.needsUpdate = true;
105
- return {
106
- texture,
107
- worldWidth,
108
- worldHeight
109
- };
110
- }
111
- const STROKE_Z_LIFT = .05;
112
- function buildShape(three, mesh) {
113
- const shape = new three.Shape(mesh.outline.map((p) => new three.Vector2(p.x, p.y)));
114
- for (const hole of mesh.holes ?? []) shape.holes.push(new three.Path(hole.map((p) => new three.Vector2(p.x, p.y))));
115
- return shape;
116
- }
117
- function buildFlatFill(three, mesh, shape, disposables) {
118
- if (mesh.fillNone) return null;
119
- const geometry = new three.ShapeGeometry(shape);
120
- const material = new three.MeshBasicMaterial({
121
- color: mesh.fill,
122
- side: three.DoubleSide,
123
- transparent: mesh.opacity < 1,
124
- opacity: mesh.opacity
125
- });
126
- disposables.push(geometry, material);
127
- return new three.Mesh(geometry, material);
128
- }
129
- function buildStrokeLines(three, mesh, disposables) {
130
- if (mesh.strokeWidth <= 0 || mesh.stroke === "transparent") return [];
131
- const material = new three.LineBasicMaterial({ color: mesh.stroke });
132
- disposables.push(material);
133
- return [mesh.outline, ...mesh.holes ?? []].map((loop) => {
134
- const geometry = new three.BufferGeometry().setFromPoints(loop.map((p) => new three.Vector3(p.x, p.y, STROKE_Z_LIFT)));
135
- disposables.push(geometry);
136
- return new three.LineLoop(geometry, material);
137
- });
138
- }
139
- function buildTextPlane(three, mesh, group, disposables) {
140
- if (!mesh.textBlock) return;
141
- const built = buildTextBlockTexture(three, mesh.textBlock);
142
- if (!built) return;
143
- disposables.push(built.texture);
144
- const geometry = new three.PlaneGeometry(built.worldWidth, built.worldHeight);
145
- const material = new three.MeshBasicMaterial({
146
- map: built.texture,
147
- transparent: true,
148
- depthWrite: false
149
- });
150
- disposables.push(geometry, material);
151
- const plane = new three.Mesh(geometry, material);
152
- plane.position.set(mesh.textBlock.x - mesh.position.x, mesh.textBlock.y - mesh.position.y, mesh.textBlock.z - mesh.position.z);
153
- group.add(plane);
154
- }
155
- function buildFlatMeshObject(three, mesh) {
156
- const disposables = [];
157
- const group = new three.Group();
158
- group.position.set(mesh.position.x, mesh.position.y, mesh.position.z);
159
- const fill = buildFlatFill(three, mesh, buildShape(three, mesh), disposables);
160
- if (fill) group.add(fill);
161
- for (const line of buildStrokeLines(three, mesh, disposables)) group.add(line);
162
- buildTextPlane(three, mesh, group, disposables);
163
- return {
164
- group,
165
- disposables
166
- };
167
- }
168
- const EPSILON = 1e-6;
169
- const MITER_LIMIT = 4;
170
- function cleanRing(points) {
171
- const out = [];
172
- for (const p of points) {
173
- const last = out[out.length - 1];
174
- if (!last || Math.hypot(p.x - last.x, p.y - last.y) > EPSILON) out.push({
175
- x: p.x,
176
- y: p.y
177
- });
178
- }
179
- while (out.length > 1) {
180
- const first = out[0];
181
- const last = out[out.length - 1];
182
- if (Math.hypot(first.x - last.x, first.y - last.y) > EPSILON) break;
183
- out.pop();
184
- }
185
- return out;
186
- }
187
- function ringSignedArea(ring) {
188
- let area = 0;
189
- for (let i = 0; i < ring.length; i++) {
190
- const a = ring[i];
191
- const b = ring[(i + 1) % ring.length];
192
- area += a.x * b.y - b.x * a.y;
193
- }
194
- return area / 2;
195
- }
196
- function toCcwRing(points) {
197
- const ring = cleanRing(points);
198
- return ringSignedArea(ring) < 0 ? ring.reverse() : ring;
199
- }
200
- function ringEdgeNormals(ring) {
201
- return ring.map((a, i) => {
202
- const b = ring[(i + 1) % ring.length];
203
- const dx = b.x - a.x;
204
- const dy = b.y - a.y;
205
- const len = Math.hypot(dx, dy) || 1;
206
- return {
207
- x: -dy / len,
208
- y: dx / len
209
- };
210
- });
211
- }
212
- function offsetRing(ring, distance) {
213
- if (distance === 0) return ring.map((p) => ({
214
- x: p.x,
215
- y: p.y
216
- }));
217
- const normals = ringEdgeNormals(ring);
218
- const n = ring.length;
219
- return ring.map((p, i) => {
220
- const prev = normals[(i - 1 + n) % n];
221
- const next = normals[i];
222
- const denom = Math.max(.05, 1 + prev.x * next.x + prev.y * next.y);
223
- let ox = (prev.x + next.x) / denom * distance;
224
- let oy = (prev.y + next.y) / denom * distance;
225
- const len = Math.hypot(ox, oy);
226
- const max = Math.abs(distance) * MITER_LIMIT;
227
- if (len > max) {
228
- ox = ox / len * max;
229
- oy = oy / len * max;
230
- }
231
- return {
232
- x: p.x + ox,
233
- y: p.y + oy
234
- };
235
- });
236
- }
237
- function ringShadingNormals(ring, smoothDeg = 30) {
238
- const normals = ringEdgeNormals(ring);
239
- const n = ring.length;
240
- const cosLimit = Math.cos(smoothDeg * Math.PI / 180);
241
- const vertexNormal = (own, other) => {
242
- if (own.x * other.x + own.y * other.y < cosLimit) return own;
243
- const x = own.x + other.x;
244
- const y = own.y + other.y;
245
- const len = Math.hypot(x, y) || 1;
246
- return {
247
- x: x / len,
248
- y: y / len
249
- };
250
- };
251
- return normals.map((own, i) => [vertexNormal(own, normals[(i - 1 + n) % n]), vertexNormal(own, normals[(i + 1) % n])]);
252
- }
253
- const CURVE_SEGMENTS = 8;
254
- function sampleCurve(fn) {
255
- const points = [];
256
- for (let i = 0; i <= CURVE_SEGMENTS; i++) points.push(fn(i / CURVE_SEGMENTS));
257
- return points;
258
- }
259
- const QUARTER = Math.PI / 2;
260
- const PROFILES = {
261
- circle: () => sampleCurve((u) => ({
262
- s: 1 - Math.cos(u * QUARTER),
263
- t: Math.sin(u * QUARTER)
264
- })),
265
- convex: () => sampleCurve((u) => ({
266
- s: u,
267
- t: Math.sin(u * QUARTER)
268
- })),
269
- softRound: () => sampleCurve((u) => ({
270
- s: u,
271
- t: 1 - (1 - u) * (1 - u)
272
- })),
273
- relaxedInset: () => sampleCurve((u) => ({
274
- s: u,
275
- t: u * u * (3 - 2 * u) - .3 * Math.sin(Math.PI * u) * (1 - u)
276
- })),
277
- divot: () => sampleCurve((u) => ({
278
- s: u,
279
- t: u - .5 * Math.sin(Math.PI * u)
280
- })),
281
- angle: () => [{
282
- s: 0,
283
- t: 0
284
- }, {
285
- s: 1,
286
- t: 1
287
- }],
288
- slope: () => [{
289
- s: 0,
290
- t: 0
291
- }, {
292
- s: 1,
293
- t: 1
294
- }],
295
- coolSlant: () => [
296
- {
297
- s: 0,
298
- t: 0
299
- },
300
- {
301
- s: .3,
302
- t: .75
303
- },
304
- {
305
- s: 1,
306
- t: 1
307
- }
308
- ],
309
- hardEdge: () => [
310
- {
311
- s: 0,
312
- t: 0
313
- },
314
- {
315
- s: .2,
316
- t: .9
317
- },
318
- {
319
- s: 1,
320
- t: 1
321
- }
322
- ],
323
- cross: () => [
324
- {
325
- s: 0,
326
- t: 0
327
- },
328
- {
329
- s: .5,
330
- t: 1
331
- },
332
- {
333
- s: 1,
334
- t: 1
335
- }
336
- ],
337
- riblet: () => [
338
- {
339
- s: 0,
340
- t: 0
341
- },
342
- {
343
- s: .33,
344
- t: 1
345
- },
346
- {
347
- s: .66,
348
- t: .5
349
- },
350
- {
351
- s: 1,
352
- t: 1
353
- }
354
- ],
355
- artDeco: () => [
356
- {
357
- s: 0,
358
- t: 0
359
- },
360
- {
361
- s: .25,
362
- t: .5
363
- },
364
- {
365
- s: .5,
366
- t: .5
367
- },
368
- {
369
- s: .75,
370
- t: 1
371
- },
372
- {
373
- s: 1,
374
- t: 1
375
- }
376
- ]
377
- };
378
- function getSmartArtBevelProfile(profile) {
379
- return (profile && PROFILES[profile] || PROFILES.circle)();
380
- }
381
- const CONTOUR_Z_LIFT = .05;
382
- const VERTICAL_SLOPE = 1e3;
383
- function emptyTriangles() {
384
- return {
385
- positions: [],
386
- normals: []
387
- };
388
- }
389
- function pushVertex(out, p, z, n) {
390
- out.positions.push(p.x, p.y, z);
391
- out.normals.push(n[0], n[1], n[2]);
392
- }
393
- function normalize(x, y, z) {
394
- const len = Math.hypot(x, y, z) || 1;
395
- return [
396
- x / len,
397
- y / len,
398
- z / len
399
- ];
400
- }
401
- function pushQuad(out, corners) {
402
- const [a, b, c, d] = corners;
403
- for (const v of [
404
- a,
405
- b,
406
- c,
407
- a,
408
- c,
409
- d
410
- ]) pushVertex(out, v.p, v.z, v.n);
411
- }
412
- function addBand(out, ring, bevel, zOuter, facing) {
413
- const profile = getSmartArtBevelProfile(bevel.profile);
414
- const rings = profile.map((pt) => offsetRing(ring, bevel.width * pt.s));
415
- const shading = ringShadingNormals(ring);
416
- const n = ring.length;
417
- for (let k = 0; k < profile.length - 1; k++) {
418
- const ds = profile[k + 1].s - profile[k].s;
419
- const dt = profile[k + 1].t - profile[k].t;
420
- const slope = Math.abs(ds) < 1e-6 ? Math.sign(dt || 1) * VERTICAL_SLOPE : bevel.height * dt / (bevel.width * ds);
421
- const z0 = zOuter + facing * bevel.height * profile[k].t;
422
- const z1 = zOuter + facing * bevel.height * profile[k + 1].t;
423
- for (let i = 0; i < n; i++) {
424
- const j = (i + 1) % n;
425
- const [mi, mj] = shading[i];
426
- const ni = normalize(-slope * mi.x, -slope * mi.y, facing);
427
- const nj = normalize(-slope * mj.x, -slope * mj.y, facing);
428
- pushQuad(out, [
429
- {
430
- p: rings[k][i],
431
- z: z0,
432
- n: ni
433
- },
434
- {
435
- p: rings[k][j],
436
- z: z0,
437
- n: nj
438
- },
439
- {
440
- p: rings[k + 1][j],
441
- z: z1,
442
- n: nj
443
- },
444
- {
445
- p: rings[k + 1][i],
446
- z: z1,
447
- n: ni
448
- }
449
- ]);
450
- }
451
- }
452
- return rings[rings.length - 1];
453
- }
454
- function addWalls(out, ring, zTop, zBottom) {
455
- if (zTop - zBottom <= 0) return;
456
- const shading = ringShadingNormals(ring);
457
- const n = ring.length;
458
- for (let i = 0; i < n; i++) {
459
- const j = (i + 1) % n;
460
- const [mi, mj] = shading[i];
461
- const ni = normalize(-mi.x, -mi.y, 0);
462
- const nj = normalize(-mj.x, -mj.y, 0);
463
- pushQuad(out, [
464
- {
465
- p: ring[i],
466
- z: zTop,
467
- n: ni
468
- },
469
- {
470
- p: ring[j],
471
- z: zTop,
472
- n: nj
473
- },
474
- {
475
- p: ring[j],
476
- z: zBottom,
477
- n: nj
478
- },
479
- {
480
- p: ring[i],
481
- z: zBottom,
482
- n: ni
483
- }
484
- ]);
485
- }
486
- }
487
- function buildSmartArt3DSolidGeometry(outline, holes, solid) {
488
- const ring = toCcwRing(outline);
489
- const body = emptyTriangles();
490
- const sides = emptyTriangles();
491
- const zShoulder = -(solid.bevelTop?.height ?? 0);
492
- const zBackShoulder = zShoulder - solid.extrusion;
493
- const zBack = zBackShoulder - (solid.bevelBottom?.height ?? 0);
494
- const holeRings = holes.map((hole) => toCcwRing(hole)).filter((hole) => hole.length >= 3);
495
- const frontRing = solid.bevelTop ? addBand(body, ring, solid.bevelTop, zShoulder, 1) : ring;
496
- addWalls(sides, ring, zShoulder, zBackShoulder);
497
- const hasDepth = zBack < 0;
498
- const backRing = hasDepth && solid.bevelBottom ? addBand(sides, ring, solid.bevelBottom, zBackShoulder, -1) : ring;
499
- const contourCaps = [];
500
- if (solid.contourWidth > 0) {
501
- const rim = offsetRing(ring, -solid.contourWidth);
502
- const inner = [...ring].reverse();
503
- contourCaps.push({
504
- ring: rim,
505
- holes: [inner],
506
- z: zShoulder + CONTOUR_Z_LIFT,
507
- facing: 1
508
- });
509
- if (hasDepth) contourCaps.push({
510
- ring: rim,
511
- holes: [inner],
512
- z: zBack - CONTOUR_Z_LIFT,
513
- facing: -1
514
- });
515
- }
516
- return {
517
- body,
518
- sides,
519
- frontCap: {
520
- ring: frontRing,
521
- holes: holeRings,
522
- z: 0,
523
- facing: 1
524
- },
525
- ...hasDepth ? { backCap: {
526
- ring: backRing,
527
- holes: holeRings,
528
- z: zBack,
529
- facing: -1
530
- } } : {},
531
- contourCaps
532
- };
533
- }
534
- const TEXT_LAYER_STEP = .4;
535
- const MAX_TEXT_LAYERS = 32;
536
- const TEXT_SIDE_SHADE = .69;
537
- function shadeHex(hex, factor) {
538
- const match = /^#?([0-9a-f]{6})$/iu.exec(hex.trim());
539
- if (!match) return hex;
540
- const n = Number.parseInt(match[1], 16);
541
- const channel = (shift) => Math.round((n >> shift & 255) * factor).toString(16).padStart(2, "0");
542
- return `#${channel(16)}${channel(8)}${channel(0)}`;
543
- }
544
- function smartArt3DTextLayers(block) {
545
- const depth = block.extrusion ?? 0;
546
- if (!(depth > 0)) return;
547
- const count = Math.max(1, Math.min(MAX_TEXT_LAYERS, Math.ceil(depth / TEXT_LAYER_STEP)));
548
- const sideZ = [];
549
- for (let i = 0; i < count; i++) sideZ.push(block.z + depth * i / count);
550
- return {
551
- sideZ,
552
- frontZ: block.z + depth,
553
- sideColor: shadeHex(block.extrusionColor ?? block.color, TEXT_SIDE_SHADE)
554
- };
555
- }
556
- function textPlanes(three, mesh, block, zs, light, disposables) {
557
- const built = zs.length > 0 ? buildTextBlockTexture(three, block) : null;
558
- if (!built) return [];
559
- const geometry = new three.PlaneGeometry(built.worldWidth, built.worldHeight);
560
- const material = new three.MeshBasicMaterial({
561
- map: built.texture,
562
- transparent: true,
563
- depthWrite: false
564
- });
565
- material.color.setRGB(light.tint[0], light.tint[1], light.tint[2]);
566
- disposables.push(built.texture, geometry, material);
567
- return zs.map((z) => {
568
- const plane = new three.Mesh(geometry, material);
569
- plane.position.set(block.x - mesh.position.x, block.y - mesh.position.y, z - mesh.position.z);
570
- return plane;
571
- });
572
- }
573
- function buildLitTextObject(three, mesh, group, light, disposables) {
574
- const block = mesh.textBlock;
575
- if (!block) return;
576
- const layers = smartArt3DTextLayers(block);
577
- const planes = [...layers ? textPlanes(three, mesh, {
578
- ...block,
579
- color: layers.sideColor
580
- }, layers.sideZ, light, disposables) : [], ...textPlanes(three, mesh, block, [layers?.frontZ ?? block.z], light, disposables)];
581
- for (const plane of planes) group.add(plane);
582
- }
583
- const LABEL_RENDER_ORDER = 3;
584
- const GRADIENT_TEXELS = 256;
585
- function appendCap(three, out, cap) {
586
- if (cap.ring.length < 3) return;
587
- const contour = cap.ring.map((p) => new three.Vector2(p.x, p.y));
588
- const holes = cap.holes.map((hole) => hole.map((p) => new three.Vector2(p.x, p.y)));
589
- const all = [...contour, ...holes.flat()];
590
- for (const face of three.ShapeUtils.triangulateShape(contour, holes)) for (const index of face) {
591
- const p = all[index];
592
- out.positions.push(p.x, p.y, cap.z);
593
- out.normals.push(0, 0, cap.facing);
594
- }
595
- }
596
- function buildGradientTexture(three, gradient) {
597
- if (typeof document === "undefined") return null;
598
- const canvas = document.createElement("canvas");
599
- canvas.width = GRADIENT_TEXELS;
600
- canvas.height = 1;
601
- const ctx = canvas.getContext("2d");
602
- if (!ctx) return null;
603
- const paint = ctx.createLinearGradient(0, 0, GRADIENT_TEXELS, 0);
604
- for (const stop of gradient.stops) paint.addColorStop(stop.offset, stop.color);
605
- ctx.fillStyle = paint;
606
- ctx.fillRect(0, 0, GRADIENT_TEXELS, 1);
607
- const texture = new three.CanvasTexture(canvas);
608
- texture.colorSpace = three.SRGBColorSpace;
609
- texture.wrapS = three.ClampToEdgeWrapping;
610
- texture.needsUpdate = true;
611
- return texture;
612
- }
613
- function withAlpha(rgb, alpha) {
614
- const out = new Float32Array(alpha.length * 4);
615
- for (let v = 0; v < alpha.length; v++) {
616
- out.set(rgb.subarray(v * 3, v * 3 + 3), v * 4);
617
- out[v * 4 + 3] = alpha[v];
618
- }
619
- return out;
620
- }
621
- function buildPart(three, part, light, eye, disposables) {
622
- if (part.triangles.positions.length === 0) return null;
623
- const glass = isSmartArt3DGlassMaterial(part.material);
624
- const translucent = part.opacity < 1 || glass;
625
- if (translucent) orientSmartArt3DTriangles(part.triangles);
626
- const { positions, normals } = part.triangles;
627
- const gradient = part.gradient;
628
- const flatColor = hexToRgb(part.color);
629
- const baseAt = (p) => gradient ? smartArt3DGradientColor(gradient, p) : flatColor;
630
- const geometry = new three.BufferGeometry();
631
- geometry.setAttribute("position", new three.Float32BufferAttribute(positions, 3));
632
- const shading = shadeSmartArt3DVertices(positions, normals, baseAt, glass ? smartArt3DGlassLightModel(light) : light, eye);
633
- geometry.setAttribute("color", glass ? new three.BufferAttribute(withAlpha(shading, smartArt3DVertexAlphas(positions, normals, part.material, part.opacity, eye)), 4) : new three.BufferAttribute(shading, 3));
634
- const texture = gradient ? buildGradientTexture(three, gradient) : null;
635
- if (gradient && texture) {
636
- const uv = [];
637
- for (let i = 0; i < positions.length; i += 3) uv.push(smartArt3DGradientCoordinate({
638
- x: positions[i],
639
- y: positions[i + 1]
640
- }, gradient), .5);
641
- geometry.setAttribute("uv", new three.Float32BufferAttribute(uv, 2));
642
- disposables.push(texture);
643
- }
644
- const material = new three.MeshBasicMaterial({
645
- color: texture ? "#ffffff" : part.color,
646
- map: texture,
647
- vertexColors: true,
648
- side: translucent ? three.FrontSide : three.DoubleSide,
649
- transparent: translucent,
650
- opacity: glass ? 1 : part.opacity,
651
- depthWrite: !translucent
652
- });
653
- disposables.push(geometry, material);
654
- return new three.Mesh(geometry, material);
655
- }
656
- function buildLitMeshObject(three, mesh, light, eye) {
657
- const localEye = eye ? {
658
- x: eye.x - mesh.position.x,
659
- y: eye.y - mesh.position.y,
660
- z: eye.z - mesh.position.z
661
- } : void 0;
662
- const disposables = [];
663
- const group = new three.Group();
664
- group.position.set(mesh.position.x, mesh.position.y, mesh.position.z);
665
- if (!mesh.fillNone && mesh.outline.length >= 3) {
666
- const holes = mesh.holes ?? [];
667
- const geometry = mesh.solid ? buildSmartArt3DSolidGeometry(mesh.outline, holes, mesh.solid) : void 0;
668
- const body = geometry?.body ?? {
669
- positions: [],
670
- normals: []
671
- };
672
- appendCap(three, body, geometry?.frontCap ?? {
673
- ring: toCcwRing(mesh.outline),
674
- holes,
675
- z: 0,
676
- facing: 1
677
- });
678
- const sides = geometry?.sides ?? {
679
- positions: [],
680
- normals: []
681
- };
682
- if (geometry?.backCap) appendCap(three, sides, geometry.backCap);
683
- const contour = {
684
- positions: [],
685
- normals: []
686
- };
687
- for (const cap of geometry?.contourCaps ?? []) appendCap(three, contour, cap);
688
- const material = mesh.solid?.material;
689
- [
690
- {
691
- triangles: body,
692
- color: mesh.fill,
693
- gradient: mesh.gradient,
694
- opacity: mesh.opacity,
695
- material
696
- },
697
- {
698
- triangles: sides,
699
- color: mesh.solid?.extrusionColor ?? mesh.fill,
700
- opacity: mesh.opacity,
701
- material
702
- },
703
- {
704
- triangles: contour,
705
- color: mesh.solid?.contourColor ?? mesh.fill,
706
- opacity: mesh.opacity
707
- }
708
- ].forEach((part, order) => {
709
- const built = buildPart(three, part, light, localEye, disposables);
710
- if (built) {
711
- built.renderOrder = order;
712
- group.add(built);
713
- }
714
- });
715
- }
716
- for (const line of buildStrokeLines(three, mesh, disposables)) group.add(line);
717
- const labelsFrom = group.children.length;
718
- buildLitTextObject(three, mesh, group, light, disposables);
719
- for (const label of group.children.slice(labelsFrom)) label.renderOrder = LABEL_RENDER_ORDER;
720
- return {
721
- group,
722
- disposables
723
- };
724
- }
725
- const ORTHO_DISTANCE = 1e3;
726
- function frameHalfExtents(bounds, size) {
727
- const halfW = Math.max(1, bounds.width) / 2;
728
- const halfH = Math.max(1, bounds.height) / 2;
729
- const aspect = Math.max(1, size.pixelWidth) / Math.max(1, size.pixelHeight);
730
- const fitHalfH = Math.max(halfH, halfW / aspect);
731
- return {
732
- halfW: fitHalfH * aspect,
733
- halfH: fitHalfH
734
- };
735
- }
736
- function buildSmartArtViewCamera(three, bounds, sceneCamera, size) {
737
- let camera;
738
- if (sceneCamera?.projection === "perspective") {
739
- const distance = Math.max(1, sceneCamera.distance);
740
- camera = new three.PerspectiveCamera(30, 1, distance / 20, distance * 20);
741
- camera.position.set(0, 0, distance);
742
- } else {
743
- camera = new three.OrthographicCamera(-1, 1, 1, -1, -2e3, ORTHO_DISTANCE * 2);
744
- camera.position.set(0, 0, ORTHO_DISTANCE);
745
- }
746
- camera.zoom = sceneCamera?.zoom ?? 1;
747
- camera.lookAt(0, 0, 0);
748
- fitSmartArtViewCamera(camera, bounds, size);
749
- return camera;
750
- }
751
- function fitSmartArtViewCamera(camera, bounds, size) {
752
- const { halfW, halfH } = frameHalfExtents(bounds, size);
753
- if ("isPerspectiveCamera" in camera && camera.isPerspectiveCamera) {
754
- camera.aspect = halfW / halfH;
755
- camera.fov = 2 * Math.atan(halfH / camera.position.length()) * 180 / Math.PI;
756
- } else {
757
- const ortho = camera;
758
- ortho.left = -halfW;
759
- ortho.right = halfW;
760
- ortho.top = halfH;
761
- ortho.bottom = -halfH;
762
- }
763
- camera.updateProjectionMatrix();
764
- }
765
- function measureOverflow(three, root, camera) {
766
- root.updateMatrixWorld(true);
767
- camera.updateMatrixWorld(true);
768
- const points = [];
769
- const corner = new three.Vector3();
770
- root.traverse((object) => {
771
- const geometry = object.geometry;
772
- if (!geometry?.getAttribute?.("position")) return;
773
- if (!geometry.boundingBox) geometry.computeBoundingBox();
774
- const box = geometry.boundingBox;
775
- if (!box || box.isEmpty()) return;
776
- for (let i = 0; i < 8; i++) {
777
- corner.set(i & 1 ? box.max.x : box.min.x, i & 2 ? box.max.y : box.min.y, i & 4 ? box.max.z : box.min.z).applyMatrix4(object.matrixWorld).project(camera);
778
- points.push({
779
- x: corner.x,
780
- y: corner.y
781
- });
782
- }
783
- });
784
- return threeViewOverflowFromNdc(points);
785
- }
786
- function frameSmartArtOverflow(three, root, camera, size, turned) {
787
- camera.clearViewOffset();
788
- if (!turned) return NO_THREE_VIEW_OVERFLOW;
789
- const overflow = measureOverflow(three, root, camera);
790
- if (hasThreeViewOverflow(overflow)) {
791
- const offset = overflowViewOffset(size, overflow);
792
- camera.setViewOffset(offset.fullWidth, offset.fullHeight, offset.x, offset.y, offset.width, offset.height);
793
- }
794
- return overflow;
795
- }
796
- async function mountSmartArt3DView(model, ctx) {
797
- const { three } = ctx;
798
- const scene = new three.Scene();
799
- if (model.background) scene.background = new three.Color(model.background);
800
- const disposables = [];
801
- const lit = model.styleCategory === "bevel" || model.styleCategory === "scene";
802
- const view = model.camera ? smartArt3DCameraMatrix(model.camera) : void 0;
803
- const eye = model.camera ? smartArt3DEyeInDiagram(model.camera) : void 0;
804
- const root = new three.Group();
805
- if (view) {
806
- root.matrixAutoUpdate = false;
807
- root.matrix.set(view[0], view[1], view[2], 0, view[3], view[4], view[5], 0, view[6], view[7], view[8], 0, 0, 0, 0, 1);
808
- }
809
- scene.add(root);
810
- model.meshes.forEach((mesh, index) => {
811
- const built = lit ? buildLitMeshObject(three, mesh, resolveSmartArt3DLightModel(model.lighting, mesh.solid?.material, eye !== void 0, model.camera !== void 0), eye) : buildFlatMeshObject(three, mesh);
812
- if (lit && isSmartArt3DTranslucentMesh(mesh)) built.group.renderOrder = index + 1;
813
- root.add(built.group);
814
- disposables.push(...built.disposables);
815
- });
816
- const camera = buildSmartArtViewCamera(three, model.bounds, model.camera, ctx.size);
817
- let overflow = frameSmartArtOverflow(three, root, camera, ctx.size, Boolean(model.camera));
818
- return {
819
- render(renderer) {
820
- renderer.render(scene, camera);
821
- },
822
- resize(size) {
823
- fitSmartArtViewCamera(camera, model.bounds, size);
824
- overflow = frameSmartArtOverflow(three, root, camera, size, Boolean(model.camera));
825
- },
826
- overflow() {
827
- return overflow;
828
- },
829
- dispose() {
830
- for (const d of disposables) d.dispose();
831
- }
832
- };
833
- }
834
- export { mountSmartArt3DView };
835
-
836
- //# sourceMappingURL=pptx-angular-viewer-view-scene-htTUkvvA.mjs.map