@pooder/kit 4.3.1 → 5.0.1
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/.test-dist/src/CanvasService.js +249 -0
- package/.test-dist/src/ViewportSystem.js +75 -0
- package/.test-dist/src/background.js +203 -0
- package/.test-dist/src/bridgeSelection.js +20 -0
- package/.test-dist/src/constraints.js +237 -0
- package/.test-dist/src/coordinate.js +74 -0
- package/.test-dist/src/dieline.js +818 -0
- package/.test-dist/src/edgeScale.js +12 -0
- package/.test-dist/src/feature.js +754 -0
- package/.test-dist/src/featureComplete.js +32 -0
- package/.test-dist/src/film.js +167 -0
- package/.test-dist/src/geometry.js +506 -0
- package/.test-dist/src/image.js +1234 -0
- package/.test-dist/src/index.js +35 -0
- package/.test-dist/src/maskOps.js +270 -0
- package/.test-dist/src/mirror.js +104 -0
- package/.test-dist/src/renderSpec.js +2 -0
- package/.test-dist/src/ruler.js +343 -0
- package/.test-dist/src/sceneLayout.js +99 -0
- package/.test-dist/src/sceneLayoutModel.js +196 -0
- package/.test-dist/src/sceneView.js +40 -0
- package/.test-dist/src/sceneVisibility.js +42 -0
- package/.test-dist/src/size.js +332 -0
- package/.test-dist/src/tracer.js +544 -0
- package/.test-dist/src/units.js +30 -0
- package/.test-dist/src/white-ink.js +829 -0
- package/.test-dist/src/wrappedOffsets.js +33 -0
- package/.test-dist/tests/run.js +94 -0
- package/CHANGELOG.md +17 -0
- package/dist/index.d.mts +342 -37
- package/dist/index.d.ts +342 -37
- package/dist/index.js +3679 -865
- package/dist/index.mjs +3673 -868
- package/package.json +2 -2
- package/src/CanvasService.ts +300 -96
- package/src/ViewportSystem.ts +92 -92
- package/src/background.ts +230 -230
- package/src/bridgeSelection.ts +17 -0
- package/src/coordinate.ts +106 -106
- package/src/dieline.ts +1005 -973
- package/src/edgeScale.ts +19 -0
- package/src/feature.ts +83 -30
- package/src/film.ts +194 -194
- package/src/geometry.ts +242 -84
- package/src/image.ts +1582 -512
- package/src/index.ts +14 -10
- package/src/maskOps.ts +326 -0
- package/src/mirror.ts +128 -128
- package/src/renderSpec.ts +18 -0
- package/src/ruler.ts +449 -508
- package/src/sceneLayout.ts +121 -0
- package/src/sceneLayoutModel.ts +335 -0
- package/src/sceneVisibility.ts +49 -0
- package/src/size.ts +379 -0
- package/src/tracer.ts +719 -570
- package/src/units.ts +27 -27
- package/src/white-ink.ts +1018 -373
- package/src/wrappedOffsets.ts +33 -0
- package/tests/run.ts +118 -0
- package/tsconfig.test.json +15 -15
package/src/dieline.ts
CHANGED
|
@@ -1,973 +1,1005 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Extension,
|
|
3
|
-
ExtensionContext,
|
|
4
|
-
ContributionPointIds,
|
|
5
|
-
CommandContribution,
|
|
6
|
-
ConfigurationContribution,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
DielineFeature,
|
|
19
|
-
} from "./geometry";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
s.
|
|
138
|
-
s.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
s.
|
|
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
|
-
s.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
s.
|
|
186
|
-
s.
|
|
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
|
-
case "dieline.
|
|
218
|
-
s.
|
|
219
|
-
break;
|
|
220
|
-
case "dieline.
|
|
221
|
-
s.
|
|
222
|
-
break;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
case "dieline.
|
|
228
|
-
s.
|
|
229
|
-
break;
|
|
230
|
-
case "dieline.
|
|
231
|
-
s.
|
|
232
|
-
break;
|
|
233
|
-
case "dieline.
|
|
234
|
-
s.
|
|
235
|
-
break;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
case "dieline.
|
|
241
|
-
s.
|
|
242
|
-
break;
|
|
243
|
-
case "dieline.
|
|
244
|
-
s.
|
|
245
|
-
break;
|
|
246
|
-
case "dieline.
|
|
247
|
-
s.
|
|
248
|
-
break;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
default: s.
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
id: "dieline.radius",
|
|
307
|
-
type: "number",
|
|
308
|
-
label: "Corner Radius (mm)",
|
|
309
|
-
min: 0,
|
|
310
|
-
max: 500,
|
|
311
|
-
default: s.radius,
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
id: "dieline.
|
|
315
|
-
type: "
|
|
316
|
-
label: "
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
default: s.
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
id: "dieline.
|
|
330
|
-
type: "
|
|
331
|
-
label: "
|
|
332
|
-
default: s.
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
id: "dieline.
|
|
336
|
-
type: "number",
|
|
337
|
-
label: "
|
|
338
|
-
min:
|
|
339
|
-
max:
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
default: s.mainLine.
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
id: "dieline.
|
|
351
|
-
type: "number",
|
|
352
|
-
label: "
|
|
353
|
-
min: 1,
|
|
354
|
-
max:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
default: s.
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
id: "dieline.
|
|
366
|
-
type: "number",
|
|
367
|
-
label: "Offset
|
|
368
|
-
min:
|
|
369
|
-
max:
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
default: s.offsetLine.
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
id: "dieline.
|
|
381
|
-
type: "
|
|
382
|
-
label: "
|
|
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
|
-
if (
|
|
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
|
-
|
|
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
|
-
if (
|
|
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
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
this.canvasService.
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
const
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
const
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
this.
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
if (
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
const
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
const
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
const
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
ContributionPointIds,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
ConfigurationContribution,
|
|
7
|
+
ConfigurationService,
|
|
8
|
+
} from "@pooder/core";
|
|
9
|
+
import { Canvas as FabricCanvas, Path, Pattern } from "fabric";
|
|
10
|
+
import CanvasService from "./CanvasService";
|
|
11
|
+
import { ImageTracer } from "./tracer";
|
|
12
|
+
import { Unit } from "./coordinate";
|
|
13
|
+
import { parseLengthToMm } from "./units";
|
|
14
|
+
import {
|
|
15
|
+
generateDielinePath,
|
|
16
|
+
generateMaskPath,
|
|
17
|
+
generateBleedZonePath,
|
|
18
|
+
DielineFeature,
|
|
19
|
+
} from "./geometry";
|
|
20
|
+
import {
|
|
21
|
+
buildSceneGeometry,
|
|
22
|
+
computeSceneLayout,
|
|
23
|
+
readSizeState,
|
|
24
|
+
} from "./sceneLayoutModel";
|
|
25
|
+
|
|
26
|
+
export interface DielineGeometry {
|
|
27
|
+
shape: "rect" | "circle" | "ellipse" | "custom";
|
|
28
|
+
unit: "mm";
|
|
29
|
+
displayUnit: Unit;
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
radius: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
borderLength?: number;
|
|
37
|
+
scale?: number;
|
|
38
|
+
strokeWidth?: number;
|
|
39
|
+
pathData?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface LineStyle {
|
|
43
|
+
width: number;
|
|
44
|
+
color: string;
|
|
45
|
+
dashLength: number;
|
|
46
|
+
style: "solid" | "dashed" | "hidden";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface DielineState {
|
|
50
|
+
displayUnit: Unit;
|
|
51
|
+
shape: "rect" | "circle" | "ellipse" | "custom";
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
radius: number;
|
|
55
|
+
offset: number;
|
|
56
|
+
padding: number | string;
|
|
57
|
+
mainLine: LineStyle;
|
|
58
|
+
offsetLine: LineStyle;
|
|
59
|
+
insideColor: string;
|
|
60
|
+
outsideColor: string;
|
|
61
|
+
showBleedLines: boolean;
|
|
62
|
+
features: DielineFeature[];
|
|
63
|
+
pathData?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const IMAGE_OBJECT_LAYER_ID = "image.user";
|
|
67
|
+
|
|
68
|
+
export class DielineTool implements Extension {
|
|
69
|
+
id = "pooder.kit.dieline";
|
|
70
|
+
public metadata = {
|
|
71
|
+
name: "DielineTool",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
private state: DielineState = {
|
|
75
|
+
displayUnit: "mm",
|
|
76
|
+
shape: "rect",
|
|
77
|
+
width: 500,
|
|
78
|
+
height: 500,
|
|
79
|
+
radius: 0,
|
|
80
|
+
offset: 0,
|
|
81
|
+
padding: 140,
|
|
82
|
+
mainLine: {
|
|
83
|
+
width: 2.7,
|
|
84
|
+
color: "#FF0000",
|
|
85
|
+
dashLength: 5,
|
|
86
|
+
style: "solid",
|
|
87
|
+
},
|
|
88
|
+
offsetLine: {
|
|
89
|
+
width: 2.7,
|
|
90
|
+
color: "#FF0000",
|
|
91
|
+
dashLength: 5,
|
|
92
|
+
style: "solid",
|
|
93
|
+
},
|
|
94
|
+
insideColor: "rgba(0,0,0,0)",
|
|
95
|
+
outsideColor: "#ffffff",
|
|
96
|
+
showBleedLines: true,
|
|
97
|
+
features: [],
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
private canvasService?: CanvasService;
|
|
101
|
+
private context?: ExtensionContext;
|
|
102
|
+
private onCanvasResized = () => {
|
|
103
|
+
this.updateDieline();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
constructor(options?: Partial<DielineState>) {
|
|
107
|
+
if (options) {
|
|
108
|
+
// Deep merge for styles to avoid overwriting defaults with partial objects
|
|
109
|
+
if (options.mainLine) {
|
|
110
|
+
Object.assign(this.state.mainLine, options.mainLine);
|
|
111
|
+
delete options.mainLine;
|
|
112
|
+
}
|
|
113
|
+
if (options.offsetLine) {
|
|
114
|
+
Object.assign(this.state.offsetLine, options.offsetLine);
|
|
115
|
+
delete options.offsetLine;
|
|
116
|
+
}
|
|
117
|
+
Object.assign(this.state, options);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
activate(context: ExtensionContext) {
|
|
122
|
+
this.context = context;
|
|
123
|
+
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
124
|
+
if (!this.canvasService) {
|
|
125
|
+
console.warn("CanvasService not found for DielineTool");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const configService = context.services.get<ConfigurationService>(
|
|
130
|
+
"ConfigurationService",
|
|
131
|
+
);
|
|
132
|
+
if (configService) {
|
|
133
|
+
// Load initial config
|
|
134
|
+
const s = this.state;
|
|
135
|
+
const sizeState = readSizeState(configService);
|
|
136
|
+
s.displayUnit = sizeState.unit;
|
|
137
|
+
s.shape = configService.get("dieline.shape", s.shape);
|
|
138
|
+
s.width = sizeState.actualWidthMm;
|
|
139
|
+
s.height = sizeState.actualHeightMm;
|
|
140
|
+
s.radius = parseLengthToMm(
|
|
141
|
+
configService.get("dieline.radius", s.radius),
|
|
142
|
+
"mm",
|
|
143
|
+
);
|
|
144
|
+
s.padding = sizeState.viewPadding;
|
|
145
|
+
s.offset =
|
|
146
|
+
sizeState.cutMode === "outset"
|
|
147
|
+
? sizeState.cutMarginMm
|
|
148
|
+
: sizeState.cutMode === "inset"
|
|
149
|
+
? -sizeState.cutMarginMm
|
|
150
|
+
: 0;
|
|
151
|
+
|
|
152
|
+
// Main Line
|
|
153
|
+
s.mainLine.width = configService.get(
|
|
154
|
+
"dieline.strokeWidth",
|
|
155
|
+
s.mainLine.width,
|
|
156
|
+
);
|
|
157
|
+
s.mainLine.color = configService.get(
|
|
158
|
+
"dieline.strokeColor",
|
|
159
|
+
s.mainLine.color,
|
|
160
|
+
);
|
|
161
|
+
s.mainLine.dashLength = configService.get(
|
|
162
|
+
"dieline.dashLength",
|
|
163
|
+
s.mainLine.dashLength,
|
|
164
|
+
);
|
|
165
|
+
s.mainLine.style = configService.get("dieline.style", s.mainLine.style);
|
|
166
|
+
|
|
167
|
+
// Offset Line
|
|
168
|
+
s.offsetLine.width = configService.get(
|
|
169
|
+
"dieline.offsetStrokeWidth",
|
|
170
|
+
s.offsetLine.width,
|
|
171
|
+
);
|
|
172
|
+
s.offsetLine.color = configService.get(
|
|
173
|
+
"dieline.offsetStrokeColor",
|
|
174
|
+
s.offsetLine.color,
|
|
175
|
+
);
|
|
176
|
+
s.offsetLine.dashLength = configService.get(
|
|
177
|
+
"dieline.offsetDashLength",
|
|
178
|
+
s.offsetLine.dashLength,
|
|
179
|
+
);
|
|
180
|
+
s.offsetLine.style = configService.get(
|
|
181
|
+
"dieline.offsetStyle",
|
|
182
|
+
s.offsetLine.style,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
s.insideColor = configService.get("dieline.insideColor", s.insideColor);
|
|
186
|
+
s.outsideColor = configService.get(
|
|
187
|
+
"dieline.outsideColor",
|
|
188
|
+
s.outsideColor,
|
|
189
|
+
);
|
|
190
|
+
s.showBleedLines = configService.get(
|
|
191
|
+
"dieline.showBleedLines",
|
|
192
|
+
s.showBleedLines,
|
|
193
|
+
);
|
|
194
|
+
s.features = configService.get("dieline.features", s.features);
|
|
195
|
+
s.pathData = configService.get("dieline.pathData", s.pathData);
|
|
196
|
+
|
|
197
|
+
// Listen for changes
|
|
198
|
+
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
199
|
+
if (e.key.startsWith("size.")) {
|
|
200
|
+
const nextSize = readSizeState(configService);
|
|
201
|
+
s.displayUnit = nextSize.unit;
|
|
202
|
+
s.width = nextSize.actualWidthMm;
|
|
203
|
+
s.height = nextSize.actualHeightMm;
|
|
204
|
+
s.padding = nextSize.viewPadding;
|
|
205
|
+
s.offset =
|
|
206
|
+
nextSize.cutMode === "outset"
|
|
207
|
+
? nextSize.cutMarginMm
|
|
208
|
+
: nextSize.cutMode === "inset"
|
|
209
|
+
? -nextSize.cutMarginMm
|
|
210
|
+
: 0;
|
|
211
|
+
this.updateDieline();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (e.key.startsWith("dieline.")) {
|
|
216
|
+
switch (e.key) {
|
|
217
|
+
case "dieline.shape":
|
|
218
|
+
s.shape = e.value;
|
|
219
|
+
break;
|
|
220
|
+
case "dieline.radius":
|
|
221
|
+
s.radius = parseLengthToMm(e.value, "mm");
|
|
222
|
+
break;
|
|
223
|
+
|
|
224
|
+
case "dieline.strokeWidth":
|
|
225
|
+
s.mainLine.width = e.value;
|
|
226
|
+
break;
|
|
227
|
+
case "dieline.strokeColor":
|
|
228
|
+
s.mainLine.color = e.value;
|
|
229
|
+
break;
|
|
230
|
+
case "dieline.dashLength":
|
|
231
|
+
s.mainLine.dashLength = e.value;
|
|
232
|
+
break;
|
|
233
|
+
case "dieline.style":
|
|
234
|
+
s.mainLine.style = e.value;
|
|
235
|
+
break;
|
|
236
|
+
|
|
237
|
+
case "dieline.offsetStrokeWidth":
|
|
238
|
+
s.offsetLine.width = e.value;
|
|
239
|
+
break;
|
|
240
|
+
case "dieline.offsetStrokeColor":
|
|
241
|
+
s.offsetLine.color = e.value;
|
|
242
|
+
break;
|
|
243
|
+
case "dieline.offsetDashLength":
|
|
244
|
+
s.offsetLine.dashLength = e.value;
|
|
245
|
+
break;
|
|
246
|
+
case "dieline.offsetStyle":
|
|
247
|
+
s.offsetLine.style = e.value;
|
|
248
|
+
break;
|
|
249
|
+
|
|
250
|
+
case "dieline.insideColor":
|
|
251
|
+
s.insideColor = e.value;
|
|
252
|
+
break;
|
|
253
|
+
case "dieline.outsideColor":
|
|
254
|
+
s.outsideColor = e.value;
|
|
255
|
+
break;
|
|
256
|
+
case "dieline.showBleedLines":
|
|
257
|
+
s.showBleedLines = e.value;
|
|
258
|
+
break;
|
|
259
|
+
case "dieline.features":
|
|
260
|
+
s.features = e.value;
|
|
261
|
+
break;
|
|
262
|
+
case "dieline.pathData":
|
|
263
|
+
s.pathData = e.value;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
this.updateDieline();
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
context.eventBus.on("canvas:resized", this.onCanvasResized);
|
|
272
|
+
this.createLayer();
|
|
273
|
+
this.updateDieline();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
deactivate(context: ExtensionContext) {
|
|
277
|
+
context.eventBus.off("canvas:resized", this.onCanvasResized);
|
|
278
|
+
this.destroyLayer();
|
|
279
|
+
this.canvasService = undefined;
|
|
280
|
+
this.context = undefined;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
contribute() {
|
|
284
|
+
const s = this.state;
|
|
285
|
+
return {
|
|
286
|
+
[ContributionPointIds.TOOLS]: [
|
|
287
|
+
{
|
|
288
|
+
id: this.id,
|
|
289
|
+
name: "Dieline",
|
|
290
|
+
interaction: "session",
|
|
291
|
+
session: {
|
|
292
|
+
autoBegin: false,
|
|
293
|
+
leavePolicy: "block",
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
[ContributionPointIds.CONFIGURATIONS]: [
|
|
298
|
+
{
|
|
299
|
+
id: "dieline.shape",
|
|
300
|
+
type: "select",
|
|
301
|
+
label: "Shape",
|
|
302
|
+
options: ["rect", "circle", "ellipse", "custom"],
|
|
303
|
+
default: s.shape,
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
id: "dieline.radius",
|
|
307
|
+
type: "number",
|
|
308
|
+
label: "Corner Radius (mm)",
|
|
309
|
+
min: 0,
|
|
310
|
+
max: 500,
|
|
311
|
+
default: s.radius,
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: "dieline.showBleedLines",
|
|
315
|
+
type: "boolean",
|
|
316
|
+
label: "Show Bleed Lines",
|
|
317
|
+
default: s.showBleedLines,
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
id: "dieline.strokeWidth",
|
|
321
|
+
type: "number",
|
|
322
|
+
label: "Line Width",
|
|
323
|
+
min: 0.1,
|
|
324
|
+
max: 10,
|
|
325
|
+
step: 0.1,
|
|
326
|
+
default: s.mainLine.width,
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
id: "dieline.strokeColor",
|
|
330
|
+
type: "color",
|
|
331
|
+
label: "Line Color",
|
|
332
|
+
default: s.mainLine.color,
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
id: "dieline.dashLength",
|
|
336
|
+
type: "number",
|
|
337
|
+
label: "Dash Length",
|
|
338
|
+
min: 1,
|
|
339
|
+
max: 50,
|
|
340
|
+
default: s.mainLine.dashLength,
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
id: "dieline.style",
|
|
344
|
+
type: "select",
|
|
345
|
+
label: "Line Style",
|
|
346
|
+
options: ["solid", "dashed", "hidden"],
|
|
347
|
+
default: s.mainLine.style,
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
id: "dieline.offsetStrokeWidth",
|
|
351
|
+
type: "number",
|
|
352
|
+
label: "Offset Line Width",
|
|
353
|
+
min: 0.1,
|
|
354
|
+
max: 10,
|
|
355
|
+
step: 0.1,
|
|
356
|
+
default: s.offsetLine.width,
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
id: "dieline.offsetStrokeColor",
|
|
360
|
+
type: "color",
|
|
361
|
+
label: "Offset Line Color",
|
|
362
|
+
default: s.offsetLine.color,
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
id: "dieline.offsetDashLength",
|
|
366
|
+
type: "number",
|
|
367
|
+
label: "Offset Dash Length",
|
|
368
|
+
min: 1,
|
|
369
|
+
max: 50,
|
|
370
|
+
default: s.offsetLine.dashLength,
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
id: "dieline.offsetStyle",
|
|
374
|
+
type: "select",
|
|
375
|
+
label: "Offset Line Style",
|
|
376
|
+
options: ["solid", "dashed", "hidden"],
|
|
377
|
+
default: s.offsetLine.style,
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
id: "dieline.insideColor",
|
|
381
|
+
type: "color",
|
|
382
|
+
label: "Inside Color",
|
|
383
|
+
default: s.insideColor,
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
id: "dieline.outsideColor",
|
|
387
|
+
type: "color",
|
|
388
|
+
label: "Outside Color",
|
|
389
|
+
default: s.outsideColor,
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
id: "dieline.features",
|
|
393
|
+
type: "json",
|
|
394
|
+
label: "Edge Features",
|
|
395
|
+
default: s.features,
|
|
396
|
+
},
|
|
397
|
+
] as ConfigurationContribution[],
|
|
398
|
+
[ContributionPointIds.COMMANDS]: [
|
|
399
|
+
{
|
|
400
|
+
command: "updateFeaturePosition",
|
|
401
|
+
title: "Update Feature Position",
|
|
402
|
+
handler: (groupId: string, x: number, y: number) => {
|
|
403
|
+
const configService = this.context?.services.get<any>(
|
|
404
|
+
"ConfigurationService",
|
|
405
|
+
);
|
|
406
|
+
if (!configService) return;
|
|
407
|
+
|
|
408
|
+
const features = configService.get("dieline.features") || [];
|
|
409
|
+
|
|
410
|
+
let changed = false;
|
|
411
|
+
const newFeatures = features.map((f: any) => {
|
|
412
|
+
if (f.groupId === groupId) {
|
|
413
|
+
if (f.x !== x || f.y !== y) {
|
|
414
|
+
changed = true;
|
|
415
|
+
return { ...f, x, y };
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return f;
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
if (changed) {
|
|
422
|
+
configService.update("dieline.features", newFeatures);
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
command: "exportCutImage",
|
|
428
|
+
title: "Export Cut Image",
|
|
429
|
+
handler: (options?: { debug?: boolean }) => {
|
|
430
|
+
return this.exportCutImage(options);
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
command: "detectEdge",
|
|
435
|
+
title: "Detect Edge from Image",
|
|
436
|
+
handler: async (imageUrl: string, options?: any) => {
|
|
437
|
+
try {
|
|
438
|
+
const detectOptions = options || {};
|
|
439
|
+
const debug = detectOptions.debug === true;
|
|
440
|
+
|
|
441
|
+
// Helper to get image dimensions
|
|
442
|
+
const loadImage = (url: string): Promise<HTMLImageElement> => {
|
|
443
|
+
return new Promise((resolve, reject) => {
|
|
444
|
+
const img = new Image();
|
|
445
|
+
img.crossOrigin = "Anonymous";
|
|
446
|
+
img.onload = () => resolve(img);
|
|
447
|
+
img.onerror = (e) => reject(e);
|
|
448
|
+
img.src = url;
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const [img, traced] = await Promise.all([
|
|
453
|
+
loadImage(imageUrl),
|
|
454
|
+
ImageTracer.traceWithBounds(imageUrl, detectOptions),
|
|
455
|
+
]);
|
|
456
|
+
const { pathData, baseBounds, bounds } = traced;
|
|
457
|
+
|
|
458
|
+
if (debug) {
|
|
459
|
+
console.info("[DielineTool] detectEdge", {
|
|
460
|
+
imageWidth: img.width,
|
|
461
|
+
imageHeight: img.height,
|
|
462
|
+
baseBounds,
|
|
463
|
+
expandedBounds: bounds,
|
|
464
|
+
currentDielineWidth: s.width,
|
|
465
|
+
currentDielineHeight: s.height,
|
|
466
|
+
options: {
|
|
467
|
+
expand: detectOptions.expand ?? 0,
|
|
468
|
+
morphologyRadius: detectOptions.morphologyRadius,
|
|
469
|
+
smoothing: detectOptions.smoothing,
|
|
470
|
+
simplifyTolerance: detectOptions.simplifyTolerance,
|
|
471
|
+
threshold: detectOptions.threshold,
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
pathData,
|
|
478
|
+
rawBounds: bounds,
|
|
479
|
+
baseBounds,
|
|
480
|
+
imageWidth: img.width,
|
|
481
|
+
imageHeight: img.height,
|
|
482
|
+
};
|
|
483
|
+
} catch (e) {
|
|
484
|
+
console.error("Edge detection failed", e);
|
|
485
|
+
throw e;
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
] as CommandContribution[],
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
private getLayer() {
|
|
494
|
+
return this.canvasService?.getLayer("dieline-overlay");
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
private createLayer() {
|
|
498
|
+
if (!this.canvasService) return;
|
|
499
|
+
const width = this.canvasService.canvas.width || 800;
|
|
500
|
+
const height = this.canvasService.canvas.height || 600;
|
|
501
|
+
|
|
502
|
+
const layer = this.canvasService.createLayer("dieline-overlay", {
|
|
503
|
+
width,
|
|
504
|
+
height,
|
|
505
|
+
selectable: false,
|
|
506
|
+
evented: false,
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
this.canvasService.canvas.bringObjectToFront(layer);
|
|
510
|
+
|
|
511
|
+
// Ensure above user layer
|
|
512
|
+
const userLayer = this.canvasService.getLayer("user");
|
|
513
|
+
if (userLayer) {
|
|
514
|
+
const userIndex = this.canvasService.canvas
|
|
515
|
+
.getObjects()
|
|
516
|
+
.indexOf(userLayer);
|
|
517
|
+
this.canvasService.canvas.moveObjectTo(layer, userIndex + 1);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private destroyLayer() {
|
|
522
|
+
if (!this.canvasService) return;
|
|
523
|
+
const layer = this.getLayer();
|
|
524
|
+
if (layer) {
|
|
525
|
+
this.canvasService.canvas.remove(layer);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
private createHatchPattern(color: string = "rgba(0, 0, 0, 0.3)") {
|
|
530
|
+
if (typeof document === "undefined") {
|
|
531
|
+
return undefined;
|
|
532
|
+
}
|
|
533
|
+
const size = 20;
|
|
534
|
+
const canvas = document.createElement("canvas");
|
|
535
|
+
canvas.width = size;
|
|
536
|
+
canvas.height = size;
|
|
537
|
+
const ctx = canvas.getContext("2d");
|
|
538
|
+
if (ctx) {
|
|
539
|
+
// Transparent background
|
|
540
|
+
ctx.clearRect(0, 0, size, size);
|
|
541
|
+
|
|
542
|
+
// Draw diagonal /
|
|
543
|
+
ctx.strokeStyle = color;
|
|
544
|
+
ctx.lineWidth = 1;
|
|
545
|
+
ctx.beginPath();
|
|
546
|
+
ctx.moveTo(0, size);
|
|
547
|
+
ctx.lineTo(size, 0);
|
|
548
|
+
ctx.stroke();
|
|
549
|
+
}
|
|
550
|
+
// @ts-ignore
|
|
551
|
+
return new Pattern({ source: canvas, repetition: "repeat" });
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
private getConfigService(): ConfigurationService | undefined {
|
|
555
|
+
return this.context?.services.get<ConfigurationService>("ConfigurationService");
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
private syncSizeState(configService: ConfigurationService) {
|
|
559
|
+
const sizeState = readSizeState(configService);
|
|
560
|
+
this.state.displayUnit = sizeState.unit;
|
|
561
|
+
this.state.width = sizeState.actualWidthMm;
|
|
562
|
+
this.state.height = sizeState.actualHeightMm;
|
|
563
|
+
this.state.padding = sizeState.viewPadding;
|
|
564
|
+
this.state.offset =
|
|
565
|
+
sizeState.cutMode === "outset"
|
|
566
|
+
? sizeState.cutMarginMm
|
|
567
|
+
: sizeState.cutMode === "inset"
|
|
568
|
+
? -sizeState.cutMarginMm
|
|
569
|
+
: 0;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
private bringFeatureMarkersToFront() {
|
|
573
|
+
if (!this.canvasService) return;
|
|
574
|
+
const canvas = this.canvasService.canvas;
|
|
575
|
+
canvas
|
|
576
|
+
.getObjects()
|
|
577
|
+
.filter((obj: any) => obj?.data?.type === "feature-marker")
|
|
578
|
+
.forEach((obj: any) => canvas.bringObjectToFront(obj));
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
public updateDieline(_emitEvent: boolean = true) {
|
|
582
|
+
if (!this.canvasService) return;
|
|
583
|
+
const layer = this.getLayer();
|
|
584
|
+
if (!layer) return;
|
|
585
|
+
const configService = this.getConfigService();
|
|
586
|
+
if (!configService) return;
|
|
587
|
+
|
|
588
|
+
this.syncSizeState(configService);
|
|
589
|
+
const sceneLayout = computeSceneLayout(
|
|
590
|
+
this.canvasService,
|
|
591
|
+
readSizeState(configService),
|
|
592
|
+
);
|
|
593
|
+
if (!sceneLayout) return;
|
|
594
|
+
|
|
595
|
+
const {
|
|
596
|
+
shape,
|
|
597
|
+
radius,
|
|
598
|
+
mainLine,
|
|
599
|
+
offsetLine,
|
|
600
|
+
insideColor,
|
|
601
|
+
outsideColor,
|
|
602
|
+
showBleedLines,
|
|
603
|
+
features,
|
|
604
|
+
} = this.state;
|
|
605
|
+
|
|
606
|
+
const canvasW = sceneLayout.canvasWidth || this.canvasService.canvas.width || 800;
|
|
607
|
+
const canvasH = sceneLayout.canvasHeight || this.canvasService.canvas.height || 600;
|
|
608
|
+
const scale = sceneLayout.scale;
|
|
609
|
+
const cx = sceneLayout.trimRect.centerX;
|
|
610
|
+
const cy = sceneLayout.trimRect.centerY;
|
|
611
|
+
|
|
612
|
+
const visualWidth = sceneLayout.trimRect.width;
|
|
613
|
+
const visualHeight = sceneLayout.trimRect.height;
|
|
614
|
+
const visualRadius = radius * scale;
|
|
615
|
+
const cutW = sceneLayout.cutRect.width;
|
|
616
|
+
const cutH = sceneLayout.cutRect.height;
|
|
617
|
+
const visualOffset = (cutW - visualWidth) / 2;
|
|
618
|
+
const cutR =
|
|
619
|
+
visualRadius === 0 ? 0 : Math.max(0, visualRadius + visualOffset);
|
|
620
|
+
|
|
621
|
+
layer.remove(...layer.getObjects());
|
|
622
|
+
|
|
623
|
+
const absoluteFeatures = (features || []).map((f) => ({
|
|
624
|
+
...f,
|
|
625
|
+
x: f.x,
|
|
626
|
+
y: f.y,
|
|
627
|
+
width: (f.width || 0) * scale,
|
|
628
|
+
height: (f.height || 0) * scale,
|
|
629
|
+
radius: (f.radius || 0) * scale,
|
|
630
|
+
}));
|
|
631
|
+
const cutFeatures = absoluteFeatures.filter((f) => !f.skipCut);
|
|
632
|
+
|
|
633
|
+
const maskPathData = generateMaskPath({
|
|
634
|
+
canvasWidth: canvasW,
|
|
635
|
+
canvasHeight: canvasH,
|
|
636
|
+
shape,
|
|
637
|
+
width: cutW,
|
|
638
|
+
height: cutH,
|
|
639
|
+
radius: cutR,
|
|
640
|
+
x: cx,
|
|
641
|
+
y: cy,
|
|
642
|
+
features: cutFeatures,
|
|
643
|
+
pathData: this.state.pathData,
|
|
644
|
+
});
|
|
645
|
+
const mask = new Path(maskPathData, {
|
|
646
|
+
fill: outsideColor,
|
|
647
|
+
stroke: null,
|
|
648
|
+
selectable: false,
|
|
649
|
+
evented: false,
|
|
650
|
+
originX: "left" as const,
|
|
651
|
+
originY: "top" as const,
|
|
652
|
+
left: 0,
|
|
653
|
+
top: 0,
|
|
654
|
+
});
|
|
655
|
+
layer.add(mask);
|
|
656
|
+
|
|
657
|
+
if (
|
|
658
|
+
insideColor &&
|
|
659
|
+
insideColor !== "transparent" &&
|
|
660
|
+
insideColor !== "rgba(0,0,0,0)"
|
|
661
|
+
) {
|
|
662
|
+
const productPathData = generateDielinePath({
|
|
663
|
+
shape,
|
|
664
|
+
width: cutW,
|
|
665
|
+
height: cutH,
|
|
666
|
+
radius: cutR,
|
|
667
|
+
x: cx,
|
|
668
|
+
y: cy,
|
|
669
|
+
features: cutFeatures,
|
|
670
|
+
pathData: this.state.pathData,
|
|
671
|
+
canvasWidth: canvasW,
|
|
672
|
+
canvasHeight: canvasH,
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
const insideObj = new Path(productPathData, {
|
|
676
|
+
fill: insideColor,
|
|
677
|
+
stroke: null,
|
|
678
|
+
selectable: false,
|
|
679
|
+
evented: false,
|
|
680
|
+
originX: "left",
|
|
681
|
+
originY: "top",
|
|
682
|
+
});
|
|
683
|
+
layer.add(insideObj);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if (Math.abs(visualOffset) > 0.0001) {
|
|
687
|
+
const bleedPathData = generateBleedZonePath(
|
|
688
|
+
{
|
|
689
|
+
shape,
|
|
690
|
+
width: visualWidth,
|
|
691
|
+
height: visualHeight,
|
|
692
|
+
radius: visualRadius,
|
|
693
|
+
x: cx,
|
|
694
|
+
y: cy,
|
|
695
|
+
features: cutFeatures,
|
|
696
|
+
pathData: this.state.pathData,
|
|
697
|
+
canvasWidth: canvasW,
|
|
698
|
+
canvasHeight: canvasH,
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
shape,
|
|
702
|
+
width: cutW,
|
|
703
|
+
height: cutH,
|
|
704
|
+
radius: cutR,
|
|
705
|
+
x: cx,
|
|
706
|
+
y: cy,
|
|
707
|
+
features: cutFeatures,
|
|
708
|
+
pathData: this.state.pathData,
|
|
709
|
+
canvasWidth: canvasW,
|
|
710
|
+
canvasHeight: canvasH,
|
|
711
|
+
},
|
|
712
|
+
visualOffset,
|
|
713
|
+
);
|
|
714
|
+
|
|
715
|
+
if (showBleedLines !== false) {
|
|
716
|
+
const pattern = this.createHatchPattern(mainLine.color);
|
|
717
|
+
if (pattern) {
|
|
718
|
+
const bleedObj = new Path(bleedPathData, {
|
|
719
|
+
fill: pattern,
|
|
720
|
+
stroke: null,
|
|
721
|
+
selectable: false,
|
|
722
|
+
evented: false,
|
|
723
|
+
objectCaching: false,
|
|
724
|
+
originX: "left",
|
|
725
|
+
originY: "top",
|
|
726
|
+
});
|
|
727
|
+
layer.add(bleedObj);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const offsetPathData = generateDielinePath({
|
|
732
|
+
shape,
|
|
733
|
+
width: cutW,
|
|
734
|
+
height: cutH,
|
|
735
|
+
radius: cutR,
|
|
736
|
+
x: cx,
|
|
737
|
+
y: cy,
|
|
738
|
+
features: cutFeatures,
|
|
739
|
+
pathData: this.state.pathData,
|
|
740
|
+
canvasWidth: canvasW,
|
|
741
|
+
canvasHeight: canvasH,
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
const offsetBorderObj = new Path(offsetPathData, {
|
|
745
|
+
fill: null,
|
|
746
|
+
stroke: offsetLine.style === "hidden" ? null : offsetLine.color,
|
|
747
|
+
strokeWidth: offsetLine.width,
|
|
748
|
+
strokeDashArray:
|
|
749
|
+
offsetLine.style === "dashed"
|
|
750
|
+
? [offsetLine.dashLength, offsetLine.dashLength]
|
|
751
|
+
: undefined,
|
|
752
|
+
selectable: false,
|
|
753
|
+
evented: false,
|
|
754
|
+
originX: "left",
|
|
755
|
+
originY: "top",
|
|
756
|
+
});
|
|
757
|
+
layer.add(offsetBorderObj);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
const borderPathData = generateDielinePath({
|
|
761
|
+
shape,
|
|
762
|
+
width: visualWidth,
|
|
763
|
+
height: visualHeight,
|
|
764
|
+
radius: visualRadius,
|
|
765
|
+
x: cx,
|
|
766
|
+
y: cy,
|
|
767
|
+
features: absoluteFeatures,
|
|
768
|
+
pathData: this.state.pathData,
|
|
769
|
+
canvasWidth: canvasW,
|
|
770
|
+
canvasHeight: canvasH,
|
|
771
|
+
});
|
|
772
|
+
const borderObj = new Path(borderPathData, {
|
|
773
|
+
fill: "transparent",
|
|
774
|
+
stroke: mainLine.style === "hidden" ? null : mainLine.color,
|
|
775
|
+
strokeWidth: mainLine.width,
|
|
776
|
+
strokeDashArray:
|
|
777
|
+
mainLine.style === "dashed"
|
|
778
|
+
? [mainLine.dashLength, mainLine.dashLength]
|
|
779
|
+
: undefined,
|
|
780
|
+
selectable: false,
|
|
781
|
+
evented: false,
|
|
782
|
+
originX: "left",
|
|
783
|
+
originY: "top",
|
|
784
|
+
});
|
|
785
|
+
layer.add(borderObj);
|
|
786
|
+
|
|
787
|
+
const userLayer = this.canvasService.getLayer("user");
|
|
788
|
+
if (layer && userLayer) {
|
|
789
|
+
const layerIndex = this.canvasService.canvas.getObjects().indexOf(layer);
|
|
790
|
+
const userIndex = this.canvasService.canvas
|
|
791
|
+
.getObjects()
|
|
792
|
+
.indexOf(userLayer);
|
|
793
|
+
if (layerIndex < userIndex) {
|
|
794
|
+
this.canvasService.canvas.moveObjectTo(layer, userIndex + 1);
|
|
795
|
+
}
|
|
796
|
+
} else {
|
|
797
|
+
this.canvasService.canvas.bringObjectToFront(layer);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// Feature tool markers can extend outside trim. Keep them above dieline mask.
|
|
801
|
+
this.bringFeatureMarkersToFront();
|
|
802
|
+
|
|
803
|
+
const rulerLayer = this.canvasService.getLayer("ruler-overlay");
|
|
804
|
+
if (rulerLayer) {
|
|
805
|
+
this.canvasService.canvas.bringObjectToFront(rulerLayer);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
layer.dirty = true;
|
|
809
|
+
this.canvasService.requestRenderAll();
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
public getGeometry(): DielineGeometry | null {
|
|
813
|
+
if (!this.canvasService) return null;
|
|
814
|
+
const configService = this.getConfigService();
|
|
815
|
+
if (!configService) return null;
|
|
816
|
+
const sceneLayout = computeSceneLayout(
|
|
817
|
+
this.canvasService,
|
|
818
|
+
readSizeState(configService),
|
|
819
|
+
);
|
|
820
|
+
if (!sceneLayout) return null;
|
|
821
|
+
const sceneGeometry = buildSceneGeometry(configService, sceneLayout);
|
|
822
|
+
return {
|
|
823
|
+
...sceneGeometry,
|
|
824
|
+
strokeWidth: this.state.mainLine.width,
|
|
825
|
+
pathData: this.state.pathData,
|
|
826
|
+
} as DielineGeometry;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
public async exportCutImage(options?: { debug?: boolean }) {
|
|
830
|
+
const debug = options?.debug === true;
|
|
831
|
+
|
|
832
|
+
if (!this.canvasService) {
|
|
833
|
+
console.warn("[DielineTool] exportCutImage returned null: canvas-not-ready");
|
|
834
|
+
return null;
|
|
835
|
+
}
|
|
836
|
+
const configService = this.getConfigService();
|
|
837
|
+
if (!configService) {
|
|
838
|
+
console.warn(
|
|
839
|
+
"[DielineTool] exportCutImage returned null: config-service-not-ready",
|
|
840
|
+
);
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
this.syncSizeState(configService);
|
|
845
|
+
const sceneLayout = computeSceneLayout(
|
|
846
|
+
this.canvasService,
|
|
847
|
+
readSizeState(configService),
|
|
848
|
+
);
|
|
849
|
+
if (!sceneLayout) {
|
|
850
|
+
console.warn("[DielineTool] exportCutImage returned null: scene-layout-null");
|
|
851
|
+
return null;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const { shape, radius, features, pathData } = this.state;
|
|
855
|
+
const canvasW = sceneLayout.canvasWidth || this.canvasService.canvas.width || 800;
|
|
856
|
+
const canvasH = sceneLayout.canvasHeight || this.canvasService.canvas.height || 600;
|
|
857
|
+
const scale = sceneLayout.scale;
|
|
858
|
+
const cx = sceneLayout.trimRect.centerX;
|
|
859
|
+
const cy = sceneLayout.trimRect.centerY;
|
|
860
|
+
const cutW = sceneLayout.cutRect.width;
|
|
861
|
+
const cutH = sceneLayout.cutRect.height;
|
|
862
|
+
const visualRadius = radius * scale;
|
|
863
|
+
const visualOffset = (cutW - sceneLayout.trimRect.width) / 2;
|
|
864
|
+
const cutR =
|
|
865
|
+
visualRadius === 0 ? 0 : Math.max(0, visualRadius + visualOffset);
|
|
866
|
+
|
|
867
|
+
const absoluteFeatures = (features || []).map((f) => ({
|
|
868
|
+
...f,
|
|
869
|
+
x: f.x,
|
|
870
|
+
y: f.y,
|
|
871
|
+
width: (f.width || 0) * scale,
|
|
872
|
+
height: (f.height || 0) * scale,
|
|
873
|
+
radius: (f.radius || 0) * scale,
|
|
874
|
+
}));
|
|
875
|
+
const cutFeatures = absoluteFeatures.filter((f) => !f.skipCut);
|
|
876
|
+
|
|
877
|
+
const generatedPathData = generateDielinePath({
|
|
878
|
+
shape,
|
|
879
|
+
width: cutW,
|
|
880
|
+
height: cutH,
|
|
881
|
+
radius: cutR,
|
|
882
|
+
x: cx,
|
|
883
|
+
y: cy,
|
|
884
|
+
features: cutFeatures,
|
|
885
|
+
pathData,
|
|
886
|
+
canvasWidth: canvasW,
|
|
887
|
+
canvasHeight: canvasH,
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
const clipPath = new Path(generatedPathData, {
|
|
891
|
+
originX: "center",
|
|
892
|
+
originY: "center",
|
|
893
|
+
left: cx,
|
|
894
|
+
top: cy,
|
|
895
|
+
absolutePositioned: true,
|
|
896
|
+
});
|
|
897
|
+
const pathOffsetX = Number((clipPath as any)?.pathOffset?.x);
|
|
898
|
+
const pathOffsetY = Number((clipPath as any)?.pathOffset?.y);
|
|
899
|
+
const centerX = Number.isFinite(pathOffsetX) ? pathOffsetX : cx;
|
|
900
|
+
const centerY = Number.isFinite(pathOffsetY) ? pathOffsetY : cy;
|
|
901
|
+
clipPath.set({
|
|
902
|
+
originX: "center",
|
|
903
|
+
originY: "center",
|
|
904
|
+
left: centerX,
|
|
905
|
+
top: centerY,
|
|
906
|
+
absolutePositioned: true,
|
|
907
|
+
});
|
|
908
|
+
clipPath.setCoords();
|
|
909
|
+
|
|
910
|
+
const pathBounds = clipPath.getBoundingRect();
|
|
911
|
+
if (
|
|
912
|
+
!Number.isFinite(pathBounds.left) ||
|
|
913
|
+
!Number.isFinite(pathBounds.top) ||
|
|
914
|
+
!Number.isFinite(pathBounds.width) ||
|
|
915
|
+
!Number.isFinite(pathBounds.height) ||
|
|
916
|
+
pathBounds.width <= 0 ||
|
|
917
|
+
pathBounds.height <= 0
|
|
918
|
+
) {
|
|
919
|
+
console.warn("[DielineTool] exportCutImage returned null: invalid-cut-bounds", {
|
|
920
|
+
bounds: pathBounds,
|
|
921
|
+
});
|
|
922
|
+
return null;
|
|
923
|
+
}
|
|
924
|
+
const exportBounds = pathBounds;
|
|
925
|
+
|
|
926
|
+
const sourceImages = this.canvasService.canvas.getObjects().filter((obj: any) => {
|
|
927
|
+
return obj?.data?.layerId === IMAGE_OBJECT_LAYER_ID;
|
|
928
|
+
});
|
|
929
|
+
if (!sourceImages.length) {
|
|
930
|
+
console.warn(
|
|
931
|
+
"[DielineTool] exportCutImage returned null: no-image-objects-on-canvas",
|
|
932
|
+
);
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
const sourceCanvasWidth = Number(
|
|
937
|
+
this.canvasService.canvas.width || sceneLayout.canvasWidth || canvasW,
|
|
938
|
+
);
|
|
939
|
+
const sourceCanvasHeight = Number(
|
|
940
|
+
this.canvasService.canvas.height || sceneLayout.canvasHeight || canvasH,
|
|
941
|
+
);
|
|
942
|
+
|
|
943
|
+
const el = document.createElement("canvas");
|
|
944
|
+
const exportCanvas = new FabricCanvas(el, {
|
|
945
|
+
renderOnAddRemove: false,
|
|
946
|
+
selection: false,
|
|
947
|
+
enableRetinaScaling: false,
|
|
948
|
+
preserveObjectStacking: true,
|
|
949
|
+
} as any);
|
|
950
|
+
exportCanvas.setDimensions({
|
|
951
|
+
width: Math.max(1, sourceCanvasWidth),
|
|
952
|
+
height: Math.max(1, sourceCanvasHeight),
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
try {
|
|
956
|
+
for (const source of sourceImages as any[]) {
|
|
957
|
+
const clone = await source.clone();
|
|
958
|
+
clone.set({
|
|
959
|
+
selectable: false,
|
|
960
|
+
evented: false,
|
|
961
|
+
});
|
|
962
|
+
clone.setCoords();
|
|
963
|
+
exportCanvas.add(clone);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
exportCanvas.clipPath = clipPath;
|
|
967
|
+
exportCanvas.renderAll();
|
|
968
|
+
|
|
969
|
+
const dataUrl = exportCanvas.toDataURL({
|
|
970
|
+
format: "png",
|
|
971
|
+
multiplier: 2,
|
|
972
|
+
left: exportBounds.left,
|
|
973
|
+
top: exportBounds.top,
|
|
974
|
+
width: exportBounds.width,
|
|
975
|
+
height: exportBounds.height,
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
if (debug) {
|
|
979
|
+
console.info("[DielineTool] exportCutImage success", {
|
|
980
|
+
sourceCount: sourceImages.length,
|
|
981
|
+
bounds: exportBounds,
|
|
982
|
+
rawPathBounds: pathBounds,
|
|
983
|
+
pathOffset: {
|
|
984
|
+
x: Number.isFinite(pathOffsetX) ? pathOffsetX : null,
|
|
985
|
+
y: Number.isFinite(pathOffsetY) ? pathOffsetY : null,
|
|
986
|
+
},
|
|
987
|
+
clipPathCenter: {
|
|
988
|
+
x: centerX,
|
|
989
|
+
y: centerY,
|
|
990
|
+
},
|
|
991
|
+
cutRect: sceneLayout.cutRect,
|
|
992
|
+
canvasSize: {
|
|
993
|
+
width: Math.max(1, sourceCanvasWidth),
|
|
994
|
+
height: Math.max(1, sourceCanvasHeight),
|
|
995
|
+
},
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
return dataUrl;
|
|
1000
|
+
} finally {
|
|
1001
|
+
exportCanvas.dispose();
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
}
|