dom-to-pptx 1.0.6 → 1.0.7
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/CHANGELOG.md +9 -0
- package/{Readme.md → README.md} +329 -288
- package/dist/dom-to-pptx.bundle.js +16411 -27916
- package/dist/dom-to-pptx.cjs +1135 -1114
- package/dist/dom-to-pptx.min.js +1135 -1114
- package/dist/dom-to-pptx.mjs +1135 -1114
- package/package.json +1 -1
- package/rollup.config.js +13 -7
- package/src/index.js +731 -657
- package/src/utils.js +488 -479
package/src/index.js
CHANGED
|
@@ -1,657 +1,731 @@
|
|
|
1
|
-
// src/index.js
|
|
2
|
-
import * as PptxGenJSImport from 'pptxgenjs';
|
|
3
|
-
import html2canvas from 'html2canvas';
|
|
4
|
-
|
|
5
|
-
// Normalize import
|
|
6
|
-
const PptxGenJS = PptxGenJSImport?.default ?? PptxGenJSImport;
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
parseColor,
|
|
10
|
-
getTextStyle,
|
|
11
|
-
isTextContainer,
|
|
12
|
-
getVisibleShadow,
|
|
13
|
-
generateGradientSVG,
|
|
14
|
-
getRotation,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from './
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
* @param {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
if (typeof pkg === 'function') return pkg;
|
|
38
|
-
if (pkg && typeof pkg.
|
|
39
|
-
if (pkg && typeof pkg.PptxGenJS === 'function')
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
* @param {
|
|
69
|
-
* @param {PptxGenJS
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
let domOrderCounter = 0;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
borderInfo.sides
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
shapeType
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
1
|
+
// src/index.js
|
|
2
|
+
import * as PptxGenJSImport from 'pptxgenjs';
|
|
3
|
+
import html2canvas from 'html2canvas';
|
|
4
|
+
|
|
5
|
+
// Normalize import
|
|
6
|
+
const PptxGenJS = PptxGenJSImport?.default ?? PptxGenJSImport;
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
parseColor,
|
|
10
|
+
getTextStyle,
|
|
11
|
+
isTextContainer,
|
|
12
|
+
getVisibleShadow,
|
|
13
|
+
generateGradientSVG,
|
|
14
|
+
getRotation,
|
|
15
|
+
getPadding,
|
|
16
|
+
getSoftEdges,
|
|
17
|
+
generateBlurredSVG,
|
|
18
|
+
getBorderInfo,
|
|
19
|
+
generateCompositeBorderSVG,
|
|
20
|
+
isClippedByParent,
|
|
21
|
+
generateCustomShapeSVG,
|
|
22
|
+
} from './utils.js';
|
|
23
|
+
import { getProcessedImage } from './image-processor.js';
|
|
24
|
+
|
|
25
|
+
const PPI = 96;
|
|
26
|
+
const PX_TO_INCH = 1 / PPI;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Main export function. Accepts single element or an array.
|
|
30
|
+
* @param {HTMLElement | string | Array<HTMLElement | string>} target - The root element(s) to convert.
|
|
31
|
+
* @param {Object} options - { fileName: string }
|
|
32
|
+
*/
|
|
33
|
+
export async function exportToPptx(target, options = {}) {
|
|
34
|
+
const resolvePptxConstructor = (pkg) => {
|
|
35
|
+
if (!pkg) return null;
|
|
36
|
+
if (typeof pkg === 'function') return pkg;
|
|
37
|
+
if (pkg && typeof pkg.default === 'function') return pkg.default;
|
|
38
|
+
if (pkg && typeof pkg.PptxGenJS === 'function') return pkg.PptxGenJS;
|
|
39
|
+
if (pkg && pkg.PptxGenJS && typeof pkg.PptxGenJS.default === 'function')
|
|
40
|
+
return pkg.PptxGenJS.default;
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const PptxConstructor = resolvePptxConstructor(PptxGenJS);
|
|
45
|
+
if (!PptxConstructor) throw new Error('PptxGenJS constructor not found.');
|
|
46
|
+
const pptx = new PptxConstructor();
|
|
47
|
+
pptx.layout = 'LAYOUT_16x9';
|
|
48
|
+
|
|
49
|
+
const elements = Array.isArray(target) ? target : [target];
|
|
50
|
+
|
|
51
|
+
for (const el of elements) {
|
|
52
|
+
const root = typeof el === 'string' ? document.querySelector(el) : el;
|
|
53
|
+
if (!root) {
|
|
54
|
+
console.warn('Element not found, skipping slide:', el);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const slide = pptx.addSlide();
|
|
58
|
+
await processSlide(root, slide, pptx);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const fileName = options.fileName || 'export.pptx';
|
|
62
|
+
pptx.writeFile({ fileName });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Worker function to process a single DOM element into a single PPTX slide.
|
|
67
|
+
* @param {HTMLElement} root - The root element for this slide.
|
|
68
|
+
* @param {PptxGenJS.Slide} slide - The PPTX slide object to add content to.
|
|
69
|
+
* @param {PptxGenJS} pptx - The main PPTX instance.
|
|
70
|
+
*/
|
|
71
|
+
async function processSlide(root, slide, pptx) {
|
|
72
|
+
const rootRect = root.getBoundingClientRect();
|
|
73
|
+
const PPTX_WIDTH_IN = 10;
|
|
74
|
+
const PPTX_HEIGHT_IN = 5.625;
|
|
75
|
+
|
|
76
|
+
const contentWidthIn = rootRect.width * PX_TO_INCH;
|
|
77
|
+
const contentHeightIn = rootRect.height * PX_TO_INCH;
|
|
78
|
+
const scale = Math.min(PPTX_WIDTH_IN / contentWidthIn, PPTX_HEIGHT_IN / contentHeightIn);
|
|
79
|
+
|
|
80
|
+
const layoutConfig = {
|
|
81
|
+
rootX: rootRect.x,
|
|
82
|
+
rootY: rootRect.y,
|
|
83
|
+
scale: scale,
|
|
84
|
+
offX: (PPTX_WIDTH_IN - contentWidthIn * scale) / 2,
|
|
85
|
+
offY: (PPTX_HEIGHT_IN - contentHeightIn * scale) / 2,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const renderQueue = [];
|
|
89
|
+
const asyncTasks = []; // Queue for heavy operations (Images, Canvas)
|
|
90
|
+
let domOrderCounter = 0;
|
|
91
|
+
|
|
92
|
+
// Sync Traversal Function
|
|
93
|
+
function collect(node, parentZIndex) {
|
|
94
|
+
const order = domOrderCounter++;
|
|
95
|
+
|
|
96
|
+
let currentZ = parentZIndex;
|
|
97
|
+
let nodeStyle = null;
|
|
98
|
+
const nodeType = node.nodeType;
|
|
99
|
+
|
|
100
|
+
if (nodeType === 1) {
|
|
101
|
+
nodeStyle = window.getComputedStyle(node);
|
|
102
|
+
// Optimization: Skip completely hidden elements immediately
|
|
103
|
+
if (
|
|
104
|
+
nodeStyle.display === 'none' ||
|
|
105
|
+
nodeStyle.visibility === 'hidden' ||
|
|
106
|
+
nodeStyle.opacity === '0'
|
|
107
|
+
) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (nodeStyle.zIndex !== 'auto') {
|
|
111
|
+
currentZ = parseInt(nodeStyle.zIndex);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Prepare the item. If it needs async work, it returns a 'job'
|
|
116
|
+
const result = prepareRenderItem(
|
|
117
|
+
node,
|
|
118
|
+
{ ...layoutConfig, root },
|
|
119
|
+
order,
|
|
120
|
+
pptx,
|
|
121
|
+
currentZ,
|
|
122
|
+
nodeStyle
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
if (result) {
|
|
126
|
+
if (result.items) {
|
|
127
|
+
// Push items immediately to queue (data might be missing but filled later)
|
|
128
|
+
renderQueue.push(...result.items);
|
|
129
|
+
}
|
|
130
|
+
if (result.job) {
|
|
131
|
+
// Push the promise-returning function to the task list
|
|
132
|
+
asyncTasks.push(result.job);
|
|
133
|
+
}
|
|
134
|
+
if (result.stopRecursion) return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Recurse children synchronously
|
|
138
|
+
const childNodes = node.childNodes;
|
|
139
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
140
|
+
collect(childNodes[i], currentZ);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 1. Traverse and build the structure (Fast)
|
|
145
|
+
collect(root, 0);
|
|
146
|
+
|
|
147
|
+
// 2. Execute all heavy tasks in parallel (Fast)
|
|
148
|
+
if (asyncTasks.length > 0) {
|
|
149
|
+
await Promise.all(asyncTasks.map((task) => task()));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 3. Cleanup and Sort
|
|
153
|
+
// Remove items that failed to generate data (marked with skip)
|
|
154
|
+
const finalQueue = renderQueue.filter(
|
|
155
|
+
(item) => !item.skip && (item.type !== 'image' || item.options.data)
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
finalQueue.sort((a, b) => {
|
|
159
|
+
if (a.zIndex !== b.zIndex) return a.zIndex - b.zIndex;
|
|
160
|
+
return a.domOrder - b.domOrder;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// 4. Add to Slide
|
|
164
|
+
for (const item of finalQueue) {
|
|
165
|
+
if (item.type === 'shape') slide.addShape(item.shapeType, item.options);
|
|
166
|
+
if (item.type === 'image') slide.addImage(item.options);
|
|
167
|
+
if (item.type === 'text') slide.addText(item.textParts, item.options);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Optimized html2canvas wrapper
|
|
173
|
+
* Now strictly captures the node itself, not the root.
|
|
174
|
+
*/
|
|
175
|
+
async function elementToCanvasImage(node, widthPx, heightPx) {
|
|
176
|
+
return new Promise((resolve) => {
|
|
177
|
+
const width = Math.max(Math.ceil(widthPx), 1);
|
|
178
|
+
const height = Math.max(Math.ceil(heightPx), 1);
|
|
179
|
+
const style = window.getComputedStyle(node);
|
|
180
|
+
|
|
181
|
+
// Optimized: Capture ONLY the specific node
|
|
182
|
+
html2canvas(node, {
|
|
183
|
+
backgroundColor: null,
|
|
184
|
+
logging: false,
|
|
185
|
+
scale: 2, // Slight quality boost
|
|
186
|
+
})
|
|
187
|
+
.then((canvas) => {
|
|
188
|
+
const destCanvas = document.createElement('canvas');
|
|
189
|
+
destCanvas.width = width;
|
|
190
|
+
destCanvas.height = height;
|
|
191
|
+
const ctx = destCanvas.getContext('2d');
|
|
192
|
+
|
|
193
|
+
// Draw the captured canvas into our sized canvas
|
|
194
|
+
// html2canvas might return a larger canvas if scale > 1, so we fit it
|
|
195
|
+
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, width, height);
|
|
196
|
+
|
|
197
|
+
// Apply border radius clipping
|
|
198
|
+
let tl = parseFloat(style.borderTopLeftRadius) || 0;
|
|
199
|
+
let tr = parseFloat(style.borderTopRightRadius) || 0;
|
|
200
|
+
let br = parseFloat(style.borderBottomRightRadius) || 0;
|
|
201
|
+
let bl = parseFloat(style.borderBottomLeftRadius) || 0;
|
|
202
|
+
|
|
203
|
+
const f = Math.min(
|
|
204
|
+
width / (tl + tr) || Infinity,
|
|
205
|
+
height / (tr + br) || Infinity,
|
|
206
|
+
width / (br + bl) || Infinity,
|
|
207
|
+
height / (bl + tl) || Infinity
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (f < 1) {
|
|
211
|
+
tl *= f;
|
|
212
|
+
tr *= f;
|
|
213
|
+
br *= f;
|
|
214
|
+
bl *= f;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (tl + tr + br + bl > 0) {
|
|
218
|
+
ctx.globalCompositeOperation = 'destination-in';
|
|
219
|
+
ctx.beginPath();
|
|
220
|
+
ctx.moveTo(tl, 0);
|
|
221
|
+
ctx.lineTo(width - tr, 0);
|
|
222
|
+
ctx.arcTo(width, 0, width, tr, tr);
|
|
223
|
+
ctx.lineTo(width, height - br);
|
|
224
|
+
ctx.arcTo(width, height, width - br, height, br);
|
|
225
|
+
ctx.lineTo(bl, height);
|
|
226
|
+
ctx.arcTo(0, height, 0, height - bl, bl);
|
|
227
|
+
ctx.lineTo(0, tl);
|
|
228
|
+
ctx.arcTo(0, 0, tl, 0, tl);
|
|
229
|
+
ctx.closePath();
|
|
230
|
+
ctx.fill();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
resolve(destCanvas.toDataURL('image/png'));
|
|
234
|
+
})
|
|
235
|
+
.catch((e) => {
|
|
236
|
+
console.warn('Canvas capture failed for node', node, e);
|
|
237
|
+
resolve(null);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Replaces createRenderItem.
|
|
244
|
+
* Returns { items: [], job: () => Promise, stopRecursion: boolean }
|
|
245
|
+
*/
|
|
246
|
+
function prepareRenderItem(node, config, domOrder, pptx, effectiveZIndex, computedStyle) {
|
|
247
|
+
// 1. Text Node Handling
|
|
248
|
+
if (node.nodeType === 3) {
|
|
249
|
+
const textContent = node.nodeValue.trim();
|
|
250
|
+
if (!textContent) return null;
|
|
251
|
+
|
|
252
|
+
const parent = node.parentElement;
|
|
253
|
+
if (!parent) return null;
|
|
254
|
+
|
|
255
|
+
if (isTextContainer(parent)) return null; // Parent handles it
|
|
256
|
+
|
|
257
|
+
const range = document.createRange();
|
|
258
|
+
range.selectNode(node);
|
|
259
|
+
const rect = range.getBoundingClientRect();
|
|
260
|
+
range.detach();
|
|
261
|
+
|
|
262
|
+
const style = window.getComputedStyle(parent);
|
|
263
|
+
const widthPx = rect.width;
|
|
264
|
+
const heightPx = rect.height;
|
|
265
|
+
const unrotatedW = widthPx * PX_TO_INCH * config.scale;
|
|
266
|
+
const unrotatedH = heightPx * PX_TO_INCH * config.scale;
|
|
267
|
+
|
|
268
|
+
const x = config.offX + (rect.left - config.rootX) * PX_TO_INCH * config.scale;
|
|
269
|
+
const y = config.offY + (rect.top - config.rootY) * PX_TO_INCH * config.scale;
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
items: [
|
|
273
|
+
{
|
|
274
|
+
type: 'text',
|
|
275
|
+
zIndex: effectiveZIndex,
|
|
276
|
+
domOrder,
|
|
277
|
+
textParts: [
|
|
278
|
+
{
|
|
279
|
+
text: textContent,
|
|
280
|
+
options: getTextStyle(style, config.scale),
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
options: { x, y, w: unrotatedW, h: unrotatedH, margin: 0, autoFit: false },
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
stopRecursion: false,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (node.nodeType !== 1) return null;
|
|
291
|
+
const style = computedStyle; // Use pre-computed style
|
|
292
|
+
|
|
293
|
+
const rect = node.getBoundingClientRect();
|
|
294
|
+
if (rect.width < 0.5 || rect.height < 0.5) return null;
|
|
295
|
+
|
|
296
|
+
const zIndex = effectiveZIndex;
|
|
297
|
+
const rotation = getRotation(style.transform);
|
|
298
|
+
const elementOpacity = parseFloat(style.opacity);
|
|
299
|
+
const safeOpacity = isNaN(elementOpacity) ? 1 : elementOpacity;
|
|
300
|
+
|
|
301
|
+
const widthPx = node.offsetWidth || rect.width;
|
|
302
|
+
const heightPx = node.offsetHeight || rect.height;
|
|
303
|
+
const unrotatedW = widthPx * PX_TO_INCH * config.scale;
|
|
304
|
+
const unrotatedH = heightPx * PX_TO_INCH * config.scale;
|
|
305
|
+
const centerX = rect.left + rect.width / 2;
|
|
306
|
+
const centerY = rect.top + rect.height / 2;
|
|
307
|
+
|
|
308
|
+
let x = config.offX + (centerX - config.rootX) * PX_TO_INCH * config.scale - unrotatedW / 2;
|
|
309
|
+
let y = config.offY + (centerY - config.rootY) * PX_TO_INCH * config.scale - unrotatedH / 2;
|
|
310
|
+
let w = unrotatedW;
|
|
311
|
+
let h = unrotatedH;
|
|
312
|
+
|
|
313
|
+
const items = [];
|
|
314
|
+
|
|
315
|
+
// --- ASYNC JOB: SVGs / Icons ---
|
|
316
|
+
if (
|
|
317
|
+
node.nodeName.toUpperCase() === 'SVG' ||
|
|
318
|
+
node.tagName.includes('-') ||
|
|
319
|
+
node.tagName === 'ION-ICON'
|
|
320
|
+
) {
|
|
321
|
+
const item = {
|
|
322
|
+
type: 'image',
|
|
323
|
+
zIndex,
|
|
324
|
+
domOrder,
|
|
325
|
+
options: { x, y, w, h, rotate: rotation, data: null }, // Data null initially
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// Create Job
|
|
329
|
+
const job = async () => {
|
|
330
|
+
const pngData = await elementToCanvasImage(node, widthPx, heightPx);
|
|
331
|
+
if (pngData) item.options.data = pngData;
|
|
332
|
+
else item.skip = true;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
return { items: [item], job, stopRecursion: true };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// --- ASYNC JOB: IMG Tags ---
|
|
339
|
+
if (node.tagName === 'IMG') {
|
|
340
|
+
let radii = {
|
|
341
|
+
tl: parseFloat(style.borderTopLeftRadius) || 0,
|
|
342
|
+
tr: parseFloat(style.borderTopRightRadius) || 0,
|
|
343
|
+
br: parseFloat(style.borderBottomRightRadius) || 0,
|
|
344
|
+
bl: parseFloat(style.borderBottomLeftRadius) || 0,
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const hasAnyRadius = radii.tl > 0 || radii.tr > 0 || radii.br > 0 || radii.bl > 0;
|
|
348
|
+
if (!hasAnyRadius) {
|
|
349
|
+
const parent = node.parentElement;
|
|
350
|
+
const parentStyle = window.getComputedStyle(parent);
|
|
351
|
+
if (parentStyle.overflow !== 'visible') {
|
|
352
|
+
const pRadii = {
|
|
353
|
+
tl: parseFloat(parentStyle.borderTopLeftRadius) || 0,
|
|
354
|
+
tr: parseFloat(parentStyle.borderTopRightRadius) || 0,
|
|
355
|
+
br: parseFloat(parentStyle.borderBottomRightRadius) || 0,
|
|
356
|
+
bl: parseFloat(parentStyle.borderBottomLeftRadius) || 0,
|
|
357
|
+
};
|
|
358
|
+
const pRect = parent.getBoundingClientRect();
|
|
359
|
+
if (Math.abs(pRect.width - rect.width) < 5 && Math.abs(pRect.height - rect.height) < 5) {
|
|
360
|
+
radii = pRadii;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const item = {
|
|
366
|
+
type: 'image',
|
|
367
|
+
zIndex,
|
|
368
|
+
domOrder,
|
|
369
|
+
options: { x, y, w, h, rotate: rotation, data: null },
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const job = async () => {
|
|
373
|
+
const processed = await getProcessedImage(node.src, widthPx, heightPx, radii);
|
|
374
|
+
if (processed) item.options.data = processed;
|
|
375
|
+
else item.skip = true;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
return { items: [item], job, stopRecursion: true };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Radii logic
|
|
382
|
+
const borderRadiusValue = parseFloat(style.borderRadius) || 0;
|
|
383
|
+
const borderBottomLeftRadius = parseFloat(style.borderBottomLeftRadius) || 0;
|
|
384
|
+
const borderBottomRightRadius = parseFloat(style.borderBottomRightRadius) || 0;
|
|
385
|
+
const borderTopLeftRadius = parseFloat(style.borderTopLeftRadius) || 0;
|
|
386
|
+
const borderTopRightRadius = parseFloat(style.borderTopRightRadius) || 0;
|
|
387
|
+
|
|
388
|
+
const hasPartialBorderRadius =
|
|
389
|
+
(borderBottomLeftRadius > 0 && borderBottomLeftRadius !== borderRadiusValue) ||
|
|
390
|
+
(borderBottomRightRadius > 0 && borderBottomRightRadius !== borderRadiusValue) ||
|
|
391
|
+
(borderTopLeftRadius > 0 && borderTopLeftRadius !== borderRadiusValue) ||
|
|
392
|
+
(borderTopRightRadius > 0 && borderTopRightRadius !== borderRadiusValue) ||
|
|
393
|
+
(borderRadiusValue === 0 &&
|
|
394
|
+
(borderBottomLeftRadius ||
|
|
395
|
+
borderBottomRightRadius ||
|
|
396
|
+
borderTopLeftRadius ||
|
|
397
|
+
borderTopRightRadius));
|
|
398
|
+
|
|
399
|
+
// --- ASYNC JOB: Clipped Divs via Canvas ---
|
|
400
|
+
if (hasPartialBorderRadius && isClippedByParent(node)) {
|
|
401
|
+
const marginLeft = parseFloat(style.marginLeft) || 0;
|
|
402
|
+
const marginTop = parseFloat(style.marginTop) || 0;
|
|
403
|
+
x += marginLeft * PX_TO_INCH * config.scale;
|
|
404
|
+
y += marginTop * PX_TO_INCH * config.scale;
|
|
405
|
+
|
|
406
|
+
const item = {
|
|
407
|
+
type: 'image',
|
|
408
|
+
zIndex,
|
|
409
|
+
domOrder,
|
|
410
|
+
options: { x, y, w, h, rotate: rotation, data: null },
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const job = async () => {
|
|
414
|
+
const canvasImageData = await elementToCanvasImage(node, widthPx, heightPx);
|
|
415
|
+
if (canvasImageData) item.options.data = canvasImageData;
|
|
416
|
+
else item.skip = true;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
return { items: [item], job, stopRecursion: true };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// --- SYNC: Standard CSS Extraction ---
|
|
423
|
+
const bgColorObj = parseColor(style.backgroundColor);
|
|
424
|
+
const bgClip = style.webkitBackgroundClip || style.backgroundClip;
|
|
425
|
+
const isBgClipText = bgClip === 'text';
|
|
426
|
+
const hasGradient =
|
|
427
|
+
!isBgClipText && style.backgroundImage && style.backgroundImage.includes('linear-gradient');
|
|
428
|
+
|
|
429
|
+
const borderColorObj = parseColor(style.borderColor);
|
|
430
|
+
const borderWidth = parseFloat(style.borderWidth);
|
|
431
|
+
const hasBorder = borderWidth > 0 && borderColorObj.hex;
|
|
432
|
+
|
|
433
|
+
const borderInfo = getBorderInfo(style, config.scale);
|
|
434
|
+
const hasUniformBorder = borderInfo.type === 'uniform';
|
|
435
|
+
const hasCompositeBorder = borderInfo.type === 'composite';
|
|
436
|
+
|
|
437
|
+
const shadowStr = style.boxShadow;
|
|
438
|
+
const hasShadow = shadowStr && shadowStr !== 'none';
|
|
439
|
+
const softEdge = getSoftEdges(style.filter, config.scale);
|
|
440
|
+
|
|
441
|
+
let isImageWrapper = false;
|
|
442
|
+
const imgChild = Array.from(node.children).find((c) => c.tagName === 'IMG');
|
|
443
|
+
if (imgChild) {
|
|
444
|
+
const childW = imgChild.offsetWidth || imgChild.getBoundingClientRect().width;
|
|
445
|
+
const childH = imgChild.offsetHeight || imgChild.getBoundingClientRect().height;
|
|
446
|
+
if (childW >= widthPx - 2 && childH >= heightPx - 2) isImageWrapper = true;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
let textPayload = null;
|
|
450
|
+
const isText = isTextContainer(node);
|
|
451
|
+
|
|
452
|
+
if (isText) {
|
|
453
|
+
const textParts = [];
|
|
454
|
+
const isList = style.display === 'list-item';
|
|
455
|
+
if (isList) {
|
|
456
|
+
const fontSizePt = parseFloat(style.fontSize) * 0.75 * config.scale;
|
|
457
|
+
const bulletShift = (parseFloat(style.fontSize) || 16) * PX_TO_INCH * config.scale * 1.5;
|
|
458
|
+
x -= bulletShift;
|
|
459
|
+
w += bulletShift;
|
|
460
|
+
textParts.push({
|
|
461
|
+
text: ' ',
|
|
462
|
+
options: {
|
|
463
|
+
color: parseColor(style.color).hex || '000000',
|
|
464
|
+
fontSize: fontSizePt,
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
node.childNodes.forEach((child, index) => {
|
|
470
|
+
let textVal = child.nodeType === 3 ? child.nodeValue : child.textContent;
|
|
471
|
+
let nodeStyle = child.nodeType === 1 ? window.getComputedStyle(child) : style;
|
|
472
|
+
textVal = textVal.replace(/[\n\r\t]+/g, ' ').replace(/\s{2,}/g, ' ');
|
|
473
|
+
if (index === 0 && !isList) textVal = textVal.trimStart();
|
|
474
|
+
else if (index === 0) textVal = textVal.trimStart();
|
|
475
|
+
if (index === node.childNodes.length - 1) textVal = textVal.trimEnd();
|
|
476
|
+
if (nodeStyle.textTransform === 'uppercase') textVal = textVal.toUpperCase();
|
|
477
|
+
if (nodeStyle.textTransform === 'lowercase') textVal = textVal.toLowerCase();
|
|
478
|
+
|
|
479
|
+
if (textVal.length > 0) {
|
|
480
|
+
textParts.push({
|
|
481
|
+
text: textVal,
|
|
482
|
+
options: getTextStyle(nodeStyle, config.scale),
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
if (textParts.length > 0) {
|
|
488
|
+
let align = style.textAlign || 'left';
|
|
489
|
+
if (align === 'start') align = 'left';
|
|
490
|
+
if (align === 'end') align = 'right';
|
|
491
|
+
let valign = 'top';
|
|
492
|
+
if (style.alignItems === 'center') valign = 'middle';
|
|
493
|
+
if (style.justifyContent === 'center' && style.display.includes('flex')) align = 'center';
|
|
494
|
+
|
|
495
|
+
const pt = parseFloat(style.paddingTop) || 0;
|
|
496
|
+
const pb = parseFloat(style.paddingBottom) || 0;
|
|
497
|
+
if (Math.abs(pt - pb) < 2 && bgColorObj.hex) valign = 'middle';
|
|
498
|
+
|
|
499
|
+
let padding = getPadding(style, config.scale);
|
|
500
|
+
if (align === 'center' && valign === 'middle') padding = [0, 0, 0, 0];
|
|
501
|
+
|
|
502
|
+
textPayload = { text: textParts, align, valign, inset: padding };
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (hasGradient || (softEdge && bgColorObj.hex && !isImageWrapper)) {
|
|
507
|
+
let bgData = null;
|
|
508
|
+
let padIn = 0;
|
|
509
|
+
if (softEdge) {
|
|
510
|
+
const svgInfo = generateBlurredSVG(
|
|
511
|
+
widthPx,
|
|
512
|
+
heightPx,
|
|
513
|
+
bgColorObj.hex,
|
|
514
|
+
borderRadiusValue,
|
|
515
|
+
softEdge
|
|
516
|
+
);
|
|
517
|
+
bgData = svgInfo.data;
|
|
518
|
+
padIn = svgInfo.padding * PX_TO_INCH * config.scale;
|
|
519
|
+
} else {
|
|
520
|
+
bgData = generateGradientSVG(
|
|
521
|
+
widthPx,
|
|
522
|
+
heightPx,
|
|
523
|
+
style.backgroundImage,
|
|
524
|
+
borderRadiusValue,
|
|
525
|
+
hasBorder ? { color: borderColorObj.hex, width: borderWidth } : null
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (bgData) {
|
|
530
|
+
items.push({
|
|
531
|
+
type: 'image',
|
|
532
|
+
zIndex,
|
|
533
|
+
domOrder,
|
|
534
|
+
options: {
|
|
535
|
+
data: bgData,
|
|
536
|
+
x: x - padIn,
|
|
537
|
+
y: y - padIn,
|
|
538
|
+
w: w + padIn * 2,
|
|
539
|
+
h: h + padIn * 2,
|
|
540
|
+
rotate: rotation,
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
if (textPayload) {
|
|
546
|
+
items.push({
|
|
547
|
+
type: 'text',
|
|
548
|
+
zIndex: zIndex + 1,
|
|
549
|
+
domOrder,
|
|
550
|
+
textParts: textPayload.text,
|
|
551
|
+
options: {
|
|
552
|
+
x,
|
|
553
|
+
y,
|
|
554
|
+
w,
|
|
555
|
+
h,
|
|
556
|
+
align: textPayload.align,
|
|
557
|
+
valign: textPayload.valign,
|
|
558
|
+
inset: textPayload.inset,
|
|
559
|
+
rotate: rotation,
|
|
560
|
+
margin: 0,
|
|
561
|
+
wrap: true,
|
|
562
|
+
autoFit: false,
|
|
563
|
+
},
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
if (hasCompositeBorder) {
|
|
567
|
+
const borderItems = createCompositeBorderItems(
|
|
568
|
+
borderInfo.sides,
|
|
569
|
+
x,
|
|
570
|
+
y,
|
|
571
|
+
w,
|
|
572
|
+
h,
|
|
573
|
+
config.scale,
|
|
574
|
+
zIndex,
|
|
575
|
+
domOrder
|
|
576
|
+
);
|
|
577
|
+
items.push(...borderItems);
|
|
578
|
+
}
|
|
579
|
+
} else if (
|
|
580
|
+
(bgColorObj.hex && !isImageWrapper) ||
|
|
581
|
+
hasUniformBorder ||
|
|
582
|
+
hasCompositeBorder ||
|
|
583
|
+
hasShadow ||
|
|
584
|
+
textPayload
|
|
585
|
+
) {
|
|
586
|
+
const finalAlpha = safeOpacity * bgColorObj.opacity;
|
|
587
|
+
const transparency = (1 - finalAlpha) * 100;
|
|
588
|
+
const useSolidFill = bgColorObj.hex && !isImageWrapper;
|
|
589
|
+
|
|
590
|
+
if (hasPartialBorderRadius && useSolidFill && !textPayload) {
|
|
591
|
+
const shapeSvg = generateCustomShapeSVG(
|
|
592
|
+
widthPx,
|
|
593
|
+
heightPx,
|
|
594
|
+
bgColorObj.hex,
|
|
595
|
+
bgColorObj.opacity,
|
|
596
|
+
{
|
|
597
|
+
tl: parseFloat(style.borderTopLeftRadius) || 0,
|
|
598
|
+
tr: parseFloat(style.borderTopRightRadius) || 0,
|
|
599
|
+
br: parseFloat(style.borderBottomRightRadius) || 0,
|
|
600
|
+
bl: parseFloat(style.borderBottomLeftRadius) || 0,
|
|
601
|
+
}
|
|
602
|
+
);
|
|
603
|
+
|
|
604
|
+
items.push({
|
|
605
|
+
type: 'image',
|
|
606
|
+
zIndex,
|
|
607
|
+
domOrder,
|
|
608
|
+
options: { data: shapeSvg, x, y, w, h, rotate: rotation },
|
|
609
|
+
});
|
|
610
|
+
} else {
|
|
611
|
+
const shapeOpts = {
|
|
612
|
+
x,
|
|
613
|
+
y,
|
|
614
|
+
w,
|
|
615
|
+
h,
|
|
616
|
+
rotate: rotation,
|
|
617
|
+
fill: useSolidFill
|
|
618
|
+
? { color: bgColorObj.hex, transparency: transparency }
|
|
619
|
+
: { type: 'none' },
|
|
620
|
+
line: hasUniformBorder ? borderInfo.options : null,
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
if (hasShadow) shapeOpts.shadow = getVisibleShadow(shadowStr, config.scale);
|
|
624
|
+
|
|
625
|
+
const borderRadius = parseFloat(style.borderRadius) || 0;
|
|
626
|
+
const aspectRatio = Math.max(widthPx, heightPx) / Math.min(widthPx, heightPx);
|
|
627
|
+
const isCircle = aspectRatio < 1.1 && borderRadius >= Math.min(widthPx, heightPx) / 2 - 1;
|
|
628
|
+
|
|
629
|
+
let shapeType = pptx.ShapeType.rect;
|
|
630
|
+
if (isCircle) shapeType = pptx.ShapeType.ellipse;
|
|
631
|
+
else if (borderRadius > 0) {
|
|
632
|
+
shapeType = pptx.ShapeType.roundRect;
|
|
633
|
+
shapeOpts.rectRadius = Math.min(0.5, borderRadius / Math.min(widthPx, heightPx));
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (textPayload) {
|
|
637
|
+
const textOptions = {
|
|
638
|
+
shape: shapeType,
|
|
639
|
+
...shapeOpts,
|
|
640
|
+
align: textPayload.align,
|
|
641
|
+
valign: textPayload.valign,
|
|
642
|
+
inset: textPayload.inset,
|
|
643
|
+
margin: 0,
|
|
644
|
+
wrap: true,
|
|
645
|
+
autoFit: false,
|
|
646
|
+
};
|
|
647
|
+
items.push({
|
|
648
|
+
type: 'text',
|
|
649
|
+
zIndex,
|
|
650
|
+
domOrder,
|
|
651
|
+
textParts: textPayload.text,
|
|
652
|
+
options: textOptions,
|
|
653
|
+
});
|
|
654
|
+
} else if (!hasPartialBorderRadius) {
|
|
655
|
+
items.push({
|
|
656
|
+
type: 'shape',
|
|
657
|
+
zIndex,
|
|
658
|
+
domOrder,
|
|
659
|
+
shapeType,
|
|
660
|
+
options: shapeOpts,
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (hasCompositeBorder) {
|
|
666
|
+
const borderSvgData = generateCompositeBorderSVG(
|
|
667
|
+
widthPx,
|
|
668
|
+
heightPx,
|
|
669
|
+
borderRadiusValue,
|
|
670
|
+
borderInfo.sides
|
|
671
|
+
);
|
|
672
|
+
if (borderSvgData) {
|
|
673
|
+
items.push({
|
|
674
|
+
type: 'image',
|
|
675
|
+
zIndex: zIndex + 1,
|
|
676
|
+
domOrder,
|
|
677
|
+
options: { data: borderSvgData, x, y, w, h, rotate: rotation },
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
return { items, stopRecursion: !!textPayload };
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function createCompositeBorderItems(sides, x, y, w, h, scale, zIndex, domOrder) {
|
|
687
|
+
const items = [];
|
|
688
|
+
const pxToInch = 1 / 96;
|
|
689
|
+
const common = { zIndex: zIndex + 1, domOrder, shapeType: 'rect' };
|
|
690
|
+
|
|
691
|
+
if (sides.top.width > 0)
|
|
692
|
+
items.push({
|
|
693
|
+
...common,
|
|
694
|
+
options: { x, y, w, h: sides.top.width * pxToInch * scale, fill: { color: sides.top.color } },
|
|
695
|
+
});
|
|
696
|
+
if (sides.right.width > 0)
|
|
697
|
+
items.push({
|
|
698
|
+
...common,
|
|
699
|
+
options: {
|
|
700
|
+
x: x + w - sides.right.width * pxToInch * scale,
|
|
701
|
+
y,
|
|
702
|
+
w: sides.right.width * pxToInch * scale,
|
|
703
|
+
h,
|
|
704
|
+
fill: { color: sides.right.color },
|
|
705
|
+
},
|
|
706
|
+
});
|
|
707
|
+
if (sides.bottom.width > 0)
|
|
708
|
+
items.push({
|
|
709
|
+
...common,
|
|
710
|
+
options: {
|
|
711
|
+
x,
|
|
712
|
+
y: y + h - sides.bottom.width * pxToInch * scale,
|
|
713
|
+
w,
|
|
714
|
+
h: sides.bottom.width * pxToInch * scale,
|
|
715
|
+
fill: { color: sides.bottom.color },
|
|
716
|
+
},
|
|
717
|
+
});
|
|
718
|
+
if (sides.left.width > 0)
|
|
719
|
+
items.push({
|
|
720
|
+
...common,
|
|
721
|
+
options: {
|
|
722
|
+
x,
|
|
723
|
+
y,
|
|
724
|
+
w: sides.left.width * pxToInch * scale,
|
|
725
|
+
h,
|
|
726
|
+
fill: { color: sides.left.color },
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
return items;
|
|
731
|
+
}
|