@pooder/kit 5.3.1 → 5.4.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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +243 -36
- package/dist/index.d.ts +243 -36
- package/dist/index.js +2278 -1041
- package/dist/index.mjs +2278 -1041
- package/package.json +1 -1
- package/src/coordinate.ts +106 -106
- package/src/extensions/background.ts +323 -230
- package/src/extensions/bridgeSelection.ts +17 -17
- package/src/extensions/constraints.ts +322 -322
- package/src/extensions/dieline.ts +1149 -1076
- package/src/extensions/dielineShape.ts +109 -0
- package/src/extensions/edgeScale.ts +19 -19
- package/src/extensions/feature.ts +1137 -1021
- package/src/extensions/featureComplete.ts +46 -46
- package/src/extensions/film.ts +266 -194
- package/src/extensions/geometry.ts +885 -752
- package/src/extensions/image.ts +2054 -1926
- package/src/extensions/index.ts +11 -11
- package/src/extensions/maskOps.ts +283 -283
- package/src/extensions/mirror.ts +128 -128
- package/src/extensions/ruler.ts +654 -451
- package/src/extensions/sceneLayout.ts +140 -140
- package/src/extensions/sceneLayoutModel.ts +364 -352
- package/src/extensions/sceneVisibility.ts +64 -71
- package/src/extensions/size.ts +389 -389
- package/src/extensions/tracer.ts +1019 -1019
- package/src/extensions/white-ink.ts +1567 -1514
- package/src/extensions/wrappedOffsets.ts +33 -33
- package/src/index.ts +2 -2
- package/src/services/CanvasService.ts +832 -300
- package/src/services/ViewportSystem.ts +95 -95
- package/src/services/index.ts +3 -3
- package/src/services/renderSpec.ts +53 -18
- package/src/units.ts +27 -27
- package/tests/run.ts +118 -118
- package/tsconfig.test.json +15 -15
- package/.test-dist/src/CanvasService.js +0 -249
- package/.test-dist/src/ViewportSystem.js +0 -75
- package/.test-dist/src/background.js +0 -203
- package/.test-dist/src/bridgeSelection.js +0 -20
- package/.test-dist/src/constraints.js +0 -237
- package/.test-dist/src/coordinate.js +0 -74
- package/.test-dist/src/dieline.js +0 -818
- package/.test-dist/src/edgeScale.js +0 -12
- package/.test-dist/src/extensions/background.js +0 -203
- package/.test-dist/src/extensions/bridgeSelection.js +0 -20
- package/.test-dist/src/extensions/constraints.js +0 -237
- package/.test-dist/src/extensions/dieline.js +0 -828
- package/.test-dist/src/extensions/edgeScale.js +0 -12
- package/.test-dist/src/extensions/feature.js +0 -825
- package/.test-dist/src/extensions/featureComplete.js +0 -32
- package/.test-dist/src/extensions/film.js +0 -167
- package/.test-dist/src/extensions/geometry.js +0 -545
- package/.test-dist/src/extensions/image.js +0 -1529
- package/.test-dist/src/extensions/index.js +0 -30
- package/.test-dist/src/extensions/maskOps.js +0 -279
- package/.test-dist/src/extensions/mirror.js +0 -104
- package/.test-dist/src/extensions/ruler.js +0 -345
- package/.test-dist/src/extensions/sceneLayout.js +0 -96
- package/.test-dist/src/extensions/sceneLayoutModel.js +0 -196
- package/.test-dist/src/extensions/sceneVisibility.js +0 -62
- package/.test-dist/src/extensions/size.js +0 -331
- package/.test-dist/src/extensions/tracer.js +0 -538
- package/.test-dist/src/extensions/white-ink.js +0 -1190
- package/.test-dist/src/extensions/wrappedOffsets.js +0 -33
- package/.test-dist/src/feature.js +0 -826
- package/.test-dist/src/featureComplete.js +0 -32
- package/.test-dist/src/film.js +0 -167
- package/.test-dist/src/geometry.js +0 -506
- package/.test-dist/src/image.js +0 -1250
- package/.test-dist/src/index.js +0 -18
- package/.test-dist/src/maskOps.js +0 -270
- package/.test-dist/src/mirror.js +0 -104
- package/.test-dist/src/renderSpec.js +0 -2
- package/.test-dist/src/ruler.js +0 -343
- package/.test-dist/src/sceneLayout.js +0 -99
- package/.test-dist/src/sceneLayoutModel.js +0 -196
- package/.test-dist/src/sceneView.js +0 -40
- package/.test-dist/src/sceneVisibility.js +0 -42
- package/.test-dist/src/services/CanvasService.js +0 -249
- package/.test-dist/src/services/ViewportSystem.js +0 -76
- package/.test-dist/src/services/index.js +0 -24
- package/.test-dist/src/services/renderSpec.js +0 -2
- package/.test-dist/src/size.js +0 -332
- package/.test-dist/src/tracer.js +0 -544
- package/.test-dist/src/units.js +0 -30
- package/.test-dist/src/white-ink.js +0 -829
- package/.test-dist/src/wrappedOffsets.js +0 -33
- package/.test-dist/tests/run.js +0 -94
package/src/extensions/image.ts
CHANGED
|
@@ -1,1926 +1,2054 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Extension,
|
|
3
|
-
ExtensionContext,
|
|
4
|
-
ContributionPointIds,
|
|
5
|
-
CommandContribution,
|
|
6
|
-
ConfigurationContribution,
|
|
7
|
-
ConfigurationService,
|
|
8
|
-
ToolSessionService,
|
|
9
|
-
WorkbenchService,
|
|
10
|
-
} from "@pooder/core";
|
|
11
|
-
import {
|
|
12
|
-
Canvas as FabricCanvas,
|
|
13
|
-
Image as FabricImage,
|
|
14
|
-
Pattern,
|
|
15
|
-
Point,
|
|
16
|
-
} from "fabric";
|
|
17
|
-
import { CanvasService, RenderObjectSpec } from "../services";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
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
|
-
private
|
|
125
|
-
private
|
|
126
|
-
private
|
|
127
|
-
private
|
|
128
|
-
private
|
|
129
|
-
private
|
|
130
|
-
private
|
|
131
|
-
private
|
|
132
|
-
private
|
|
133
|
-
private
|
|
134
|
-
private
|
|
135
|
-
private
|
|
136
|
-
private
|
|
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
|
-
this.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
this.
|
|
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
|
-
|
|
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
|
-
private
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
[ContributionPointIds.
|
|
338
|
-
{
|
|
339
|
-
id:
|
|
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
|
-
default: "
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
id: "image.frame.
|
|
374
|
-
type: "number",
|
|
375
|
-
label: "Image Frame
|
|
376
|
-
min:
|
|
377
|
-
max:
|
|
378
|
-
step:
|
|
379
|
-
default:
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
id: "image.frame.
|
|
383
|
-
type: "
|
|
384
|
-
label: "Image Frame
|
|
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
|
-
this.
|
|
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
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
id
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
private
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
);
|
|
741
|
-
configService
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (!
|
|
760
|
-
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
left:
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
const
|
|
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
|
-
if (
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
private
|
|
850
|
-
if (!this.canvasService) return;
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
private
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const width = Number(obj?.width || 0);
|
|
877
|
-
const height = Number(obj?.height || 0);
|
|
878
|
-
if (src && width > 0 && height > 0) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
const
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
);
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
this.getConfig<string>("image.frame.
|
|
926
|
-
"#
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const
|
|
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
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
if (
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
const
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
this.
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
private
|
|
1324
|
-
if (
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
)
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
const
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
const
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
const
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
const
|
|
1695
|
-
const
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
this.
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
this.
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
)
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
const
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
const
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
const
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
this.
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
ContributionPointIds,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
ConfigurationContribution,
|
|
7
|
+
ConfigurationService,
|
|
8
|
+
ToolSessionService,
|
|
9
|
+
WorkbenchService,
|
|
10
|
+
} from "@pooder/core";
|
|
11
|
+
import {
|
|
12
|
+
Canvas as FabricCanvas,
|
|
13
|
+
Image as FabricImage,
|
|
14
|
+
Pattern,
|
|
15
|
+
Point,
|
|
16
|
+
} from "fabric";
|
|
17
|
+
import { CanvasService, RenderLayoutRect, RenderObjectSpec } from "../services";
|
|
18
|
+
import { isDielineShape, normalizeShapeStyle } from "./dielineShape";
|
|
19
|
+
import type { DielineShape, DielineShapeStyle } from "./dielineShape";
|
|
20
|
+
import { generateDielinePath, getPathBounds } from "./geometry";
|
|
21
|
+
import {
|
|
22
|
+
buildSceneGeometry,
|
|
23
|
+
computeSceneLayout,
|
|
24
|
+
readSizeState,
|
|
25
|
+
} from "./sceneLayoutModel";
|
|
26
|
+
|
|
27
|
+
export interface ImageItem {
|
|
28
|
+
id: string;
|
|
29
|
+
url: string;
|
|
30
|
+
opacity: number;
|
|
31
|
+
scale?: number;
|
|
32
|
+
angle?: number;
|
|
33
|
+
left?: number;
|
|
34
|
+
top?: number;
|
|
35
|
+
sourceUrl?: string;
|
|
36
|
+
committedUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface FrameRect {
|
|
40
|
+
left: number;
|
|
41
|
+
top: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface SourceSize {
|
|
47
|
+
width: number;
|
|
48
|
+
height: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface RenderImageState {
|
|
52
|
+
src: string;
|
|
53
|
+
left: number;
|
|
54
|
+
top: number;
|
|
55
|
+
scale: number;
|
|
56
|
+
angle: number;
|
|
57
|
+
opacity: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface FrameVisualConfig {
|
|
61
|
+
strokeColor: string;
|
|
62
|
+
strokeWidth: number;
|
|
63
|
+
strokeStyle: "solid" | "dashed" | "hidden";
|
|
64
|
+
dashLength: number;
|
|
65
|
+
innerBackground: string;
|
|
66
|
+
outerBackground: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type ShapeOverlayShape = Exclude<DielineShape, "custom">;
|
|
70
|
+
|
|
71
|
+
interface SceneGeometryLike {
|
|
72
|
+
shape: DielineShape;
|
|
73
|
+
shapeStyle: DielineShapeStyle;
|
|
74
|
+
radius: number;
|
|
75
|
+
offset: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface UpsertImageOptions {
|
|
79
|
+
id?: string;
|
|
80
|
+
mode?: "replace" | "add";
|
|
81
|
+
addOptions?: Partial<ImageItem>;
|
|
82
|
+
fitOnAdd?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface DielineFitArea {
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
left: number;
|
|
89
|
+
top: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface UpdateImageOptions {
|
|
93
|
+
target?: "auto" | "config" | "working";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface ExportCroppedImageOptions {
|
|
97
|
+
multiplier?: number;
|
|
98
|
+
format?: "png" | "jpeg";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface ExportUserCroppedImageOptions extends ExportCroppedImageOptions {
|
|
102
|
+
imageIds?: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface ExportUserCroppedImageResult {
|
|
106
|
+
url: string;
|
|
107
|
+
width: number;
|
|
108
|
+
height: number;
|
|
109
|
+
multiplier: number;
|
|
110
|
+
format: "png" | "jpeg";
|
|
111
|
+
imageIds: string[];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const IMAGE_OBJECT_LAYER_ID = "image.user";
|
|
115
|
+
const IMAGE_OVERLAY_LAYER_ID = "image-overlay";
|
|
116
|
+
|
|
117
|
+
export class ImageTool implements Extension {
|
|
118
|
+
id = "pooder.kit.image";
|
|
119
|
+
|
|
120
|
+
metadata = {
|
|
121
|
+
name: "ImageTool",
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
private items: ImageItem[] = [];
|
|
125
|
+
private workingItems: ImageItem[] = [];
|
|
126
|
+
private hasWorkingChanges = false;
|
|
127
|
+
private loadResolvers: Map<string, () => void> = new Map();
|
|
128
|
+
private sourceSizeBySrc: Map<string, SourceSize> = new Map();
|
|
129
|
+
private canvasService?: CanvasService;
|
|
130
|
+
private context?: ExtensionContext;
|
|
131
|
+
private isUpdatingConfig = false;
|
|
132
|
+
private isToolActive = false;
|
|
133
|
+
private isImageSelectionActive = false;
|
|
134
|
+
private focusedImageId: string | null = null;
|
|
135
|
+
private renderSeq = 0;
|
|
136
|
+
private dirtyTrackerDisposable?: { dispose(): void };
|
|
137
|
+
private cropShapeHatchPattern?: Pattern;
|
|
138
|
+
private cropShapeHatchPatternColor?: string;
|
|
139
|
+
private cropShapeHatchPatternKey?: string;
|
|
140
|
+
private overlaySpecs: RenderObjectSpec[] = [];
|
|
141
|
+
private renderProducerDisposable?: { dispose: () => void };
|
|
142
|
+
|
|
143
|
+
activate(context: ExtensionContext) {
|
|
144
|
+
this.context = context;
|
|
145
|
+
this.canvasService = context.services.get<CanvasService>("CanvasService");
|
|
146
|
+
if (!this.canvasService) {
|
|
147
|
+
console.warn("CanvasService not found for ImageTool");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.renderProducerDisposable?.dispose();
|
|
151
|
+
this.renderProducerDisposable = this.canvasService.registerRenderProducer(
|
|
152
|
+
this.id,
|
|
153
|
+
() => ({
|
|
154
|
+
rootLayerSpecs: {
|
|
155
|
+
[IMAGE_OVERLAY_LAYER_ID]: this.overlaySpecs,
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
158
|
+
{ priority: 300 },
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
context.eventBus.on("tool:activated", this.onToolActivated);
|
|
162
|
+
context.eventBus.on("object:modified", this.onObjectModified);
|
|
163
|
+
context.eventBus.on("selection:created", this.onSelectionChanged);
|
|
164
|
+
context.eventBus.on("selection:updated", this.onSelectionChanged);
|
|
165
|
+
context.eventBus.on("selection:cleared", this.onSelectionCleared);
|
|
166
|
+
context.eventBus.on("scene:layout:change", this.onSceneLayoutChanged);
|
|
167
|
+
context.eventBus.on("scene:geometry:change", this.onSceneGeometryChanged);
|
|
168
|
+
|
|
169
|
+
const configService = context.services.get<ConfigurationService>(
|
|
170
|
+
"ConfigurationService",
|
|
171
|
+
);
|
|
172
|
+
if (configService) {
|
|
173
|
+
this.items = this.normalizeItems(
|
|
174
|
+
configService.get("image.items", []) || [],
|
|
175
|
+
);
|
|
176
|
+
this.workingItems = this.cloneItems(this.items);
|
|
177
|
+
this.hasWorkingChanges = false;
|
|
178
|
+
|
|
179
|
+
configService.onAnyChange((e: { key: string; value: any }) => {
|
|
180
|
+
if (this.isUpdatingConfig) return;
|
|
181
|
+
|
|
182
|
+
if (e.key === "image.items") {
|
|
183
|
+
this.items = this.normalizeItems(e.value || []);
|
|
184
|
+
if (!this.isToolActive || !this.hasWorkingChanges) {
|
|
185
|
+
this.workingItems = this.cloneItems(this.items);
|
|
186
|
+
this.hasWorkingChanges = false;
|
|
187
|
+
}
|
|
188
|
+
this.updateImages();
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (e.key.startsWith("size.") || e.key.startsWith("image.frame.")) {
|
|
193
|
+
this.updateImages();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const toolSessionService =
|
|
199
|
+
context.services.get<ToolSessionService>("ToolSessionService");
|
|
200
|
+
this.dirtyTrackerDisposable = toolSessionService?.registerDirtyTracker(
|
|
201
|
+
this.id,
|
|
202
|
+
() => this.hasWorkingChanges,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
this.updateImages();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
deactivate(context: ExtensionContext) {
|
|
209
|
+
context.eventBus.off("tool:activated", this.onToolActivated);
|
|
210
|
+
context.eventBus.off("object:modified", this.onObjectModified);
|
|
211
|
+
context.eventBus.off("selection:created", this.onSelectionChanged);
|
|
212
|
+
context.eventBus.off("selection:updated", this.onSelectionChanged);
|
|
213
|
+
context.eventBus.off("selection:cleared", this.onSelectionCleared);
|
|
214
|
+
context.eventBus.off("scene:layout:change", this.onSceneLayoutChanged);
|
|
215
|
+
context.eventBus.off("scene:geometry:change", this.onSceneGeometryChanged);
|
|
216
|
+
this.dirtyTrackerDisposable?.dispose();
|
|
217
|
+
this.dirtyTrackerDisposable = undefined;
|
|
218
|
+
this.cropShapeHatchPattern = undefined;
|
|
219
|
+
this.cropShapeHatchPatternColor = undefined;
|
|
220
|
+
this.cropShapeHatchPatternKey = undefined;
|
|
221
|
+
this.overlaySpecs = [];
|
|
222
|
+
|
|
223
|
+
this.clearRenderedImages();
|
|
224
|
+
this.renderProducerDisposable?.dispose();
|
|
225
|
+
this.renderProducerDisposable = undefined;
|
|
226
|
+
if (this.canvasService) {
|
|
227
|
+
void this.canvasService.flushRenderFromProducers();
|
|
228
|
+
this.canvasService = undefined;
|
|
229
|
+
}
|
|
230
|
+
this.context = undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private onToolActivated = (event: {
|
|
234
|
+
id: string | null;
|
|
235
|
+
previous?: string | null;
|
|
236
|
+
reason?: string;
|
|
237
|
+
}) => {
|
|
238
|
+
const before = this.isToolActive;
|
|
239
|
+
this.syncToolActiveFromWorkbench(event.id);
|
|
240
|
+
if (!this.isToolActive) {
|
|
241
|
+
this.setImageFocus(null, {
|
|
242
|
+
syncCanvasSelection: true,
|
|
243
|
+
skipRender: true,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
this.debug("tool:activated", {
|
|
247
|
+
id: event.id,
|
|
248
|
+
previous: event.previous,
|
|
249
|
+
reason: event.reason,
|
|
250
|
+
before,
|
|
251
|
+
isToolActive: this.isToolActive,
|
|
252
|
+
focusedImageId: this.focusedImageId,
|
|
253
|
+
});
|
|
254
|
+
if (!this.isToolActive && this.isDebugEnabled()) {
|
|
255
|
+
console.trace("[ImageTool] tool deactivated trace");
|
|
256
|
+
}
|
|
257
|
+
this.updateImages();
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
private onSelectionChanged = (e: any) => {
|
|
261
|
+
const list: any[] = [];
|
|
262
|
+
if (Array.isArray(e?.selected)) {
|
|
263
|
+
list.push(...e.selected);
|
|
264
|
+
}
|
|
265
|
+
if (Array.isArray(e?.target?._objects)) {
|
|
266
|
+
list.push(...e.target._objects);
|
|
267
|
+
}
|
|
268
|
+
if (e?.target && !Array.isArray(e?.target?._objects)) {
|
|
269
|
+
list.push(e.target);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const selectedImage = list.find(
|
|
273
|
+
(obj: any) => obj?.data?.layerId === IMAGE_OBJECT_LAYER_ID,
|
|
274
|
+
);
|
|
275
|
+
this.isImageSelectionActive = !!selectedImage;
|
|
276
|
+
if (selectedImage?.data?.id) {
|
|
277
|
+
this.focusedImageId = selectedImage.data.id;
|
|
278
|
+
} else if (list.length > 0) {
|
|
279
|
+
this.focusedImageId = null;
|
|
280
|
+
}
|
|
281
|
+
this.debug("selection:changed", {
|
|
282
|
+
listSize: list.length,
|
|
283
|
+
isImageSelectionActive: this.isImageSelectionActive,
|
|
284
|
+
focusedImageId: this.focusedImageId,
|
|
285
|
+
});
|
|
286
|
+
this.updateImages();
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
private onSelectionCleared = () => {
|
|
290
|
+
this.setImageFocus(null, {
|
|
291
|
+
syncCanvasSelection: false,
|
|
292
|
+
skipRender: true,
|
|
293
|
+
});
|
|
294
|
+
this.debug("selection:cleared applied");
|
|
295
|
+
this.updateImages();
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
private onSceneLayoutChanged = () => {
|
|
299
|
+
this.updateImages();
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
private onSceneGeometryChanged = () => {
|
|
303
|
+
this.updateImages();
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
private syncToolActiveFromWorkbench(fallbackId?: string | null) {
|
|
307
|
+
const wb = this.context?.services.get<WorkbenchService>("WorkbenchService");
|
|
308
|
+
const activeId = wb?.activeToolId;
|
|
309
|
+
if (typeof activeId === "string" || activeId === null) {
|
|
310
|
+
this.isToolActive = activeId === this.id;
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
this.isToolActive = fallbackId === this.id;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private isImageEditingVisible(): boolean {
|
|
317
|
+
return (
|
|
318
|
+
this.isToolActive || this.isImageSelectionActive || !!this.focusedImageId
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
private isDebugEnabled(): boolean {
|
|
323
|
+
return !!this.getConfig<boolean>("image.debug", false);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private debug(message: string, payload?: any) {
|
|
327
|
+
if (!this.isDebugEnabled()) return;
|
|
328
|
+
if (payload === undefined) {
|
|
329
|
+
console.log(`[ImageTool] ${message}`);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
console.log(`[ImageTool] ${message}`, payload);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
contribute() {
|
|
336
|
+
return {
|
|
337
|
+
[ContributionPointIds.TOOLS]: [
|
|
338
|
+
{
|
|
339
|
+
id: this.id,
|
|
340
|
+
name: "Image",
|
|
341
|
+
interaction: "session",
|
|
342
|
+
commands: {
|
|
343
|
+
begin: "resetWorkingImages",
|
|
344
|
+
commit: "completeImages",
|
|
345
|
+
rollback: "resetWorkingImages",
|
|
346
|
+
},
|
|
347
|
+
session: {
|
|
348
|
+
autoBegin: true,
|
|
349
|
+
leavePolicy: "block",
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
[ContributionPointIds.CONFIGURATIONS]: [
|
|
354
|
+
{
|
|
355
|
+
id: "image.items",
|
|
356
|
+
type: "array",
|
|
357
|
+
label: "Images",
|
|
358
|
+
default: [],
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
id: "image.debug",
|
|
362
|
+
type: "boolean",
|
|
363
|
+
label: "Image Debug Log",
|
|
364
|
+
default: false,
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
id: "image.frame.strokeColor",
|
|
368
|
+
type: "color",
|
|
369
|
+
label: "Image Frame Stroke Color",
|
|
370
|
+
default: "#808080",
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
id: "image.frame.strokeWidth",
|
|
374
|
+
type: "number",
|
|
375
|
+
label: "Image Frame Stroke Width",
|
|
376
|
+
min: 0,
|
|
377
|
+
max: 20,
|
|
378
|
+
step: 0.5,
|
|
379
|
+
default: 2,
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
id: "image.frame.strokeStyle",
|
|
383
|
+
type: "select",
|
|
384
|
+
label: "Image Frame Stroke Style",
|
|
385
|
+
options: ["solid", "dashed", "hidden"],
|
|
386
|
+
default: "dashed",
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
id: "image.frame.dashLength",
|
|
390
|
+
type: "number",
|
|
391
|
+
label: "Image Frame Dash Length",
|
|
392
|
+
min: 1,
|
|
393
|
+
max: 40,
|
|
394
|
+
step: 1,
|
|
395
|
+
default: 8,
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
id: "image.frame.innerBackground",
|
|
399
|
+
type: "color",
|
|
400
|
+
label: "Image Frame Inner Background",
|
|
401
|
+
default: "rgba(0,0,0,0)",
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
id: "image.frame.outerBackground",
|
|
405
|
+
type: "color",
|
|
406
|
+
label: "Image Frame Outer Background",
|
|
407
|
+
default: "#f5f5f5",
|
|
408
|
+
},
|
|
409
|
+
] as ConfigurationContribution[],
|
|
410
|
+
[ContributionPointIds.COMMANDS]: [
|
|
411
|
+
{
|
|
412
|
+
command: "addImage",
|
|
413
|
+
title: "Add Image",
|
|
414
|
+
handler: async (url: string, options?: Partial<ImageItem>) => {
|
|
415
|
+
const result = await this.upsertImageEntry(url, {
|
|
416
|
+
mode: "add",
|
|
417
|
+
addOptions: options,
|
|
418
|
+
});
|
|
419
|
+
return result.id;
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
command: "upsertImage",
|
|
424
|
+
title: "Upsert Image",
|
|
425
|
+
handler: async (url: string, options: UpsertImageOptions = {}) => {
|
|
426
|
+
return await this.upsertImageEntry(url, options);
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
command: "getWorkingImages",
|
|
431
|
+
title: "Get Working Images",
|
|
432
|
+
handler: () => {
|
|
433
|
+
return this.cloneItems(this.workingItems);
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
command: "setWorkingImage",
|
|
438
|
+
title: "Set Working Image",
|
|
439
|
+
handler: (id: string, updates: Partial<ImageItem>) => {
|
|
440
|
+
this.updateImageInWorking(id, updates);
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
command: "resetWorkingImages",
|
|
445
|
+
title: "Reset Working Images",
|
|
446
|
+
handler: () => {
|
|
447
|
+
this.workingItems = this.cloneItems(this.items);
|
|
448
|
+
this.hasWorkingChanges = false;
|
|
449
|
+
this.updateImages();
|
|
450
|
+
this.emitWorkingChange();
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
command: "completeImages",
|
|
455
|
+
title: "Complete Images",
|
|
456
|
+
handler: async () => {
|
|
457
|
+
return await this.commitWorkingImagesAsCropped();
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
command: "exportUserCroppedImage",
|
|
462
|
+
title: "Export User Cropped Image",
|
|
463
|
+
handler: async (options: ExportUserCroppedImageOptions = {}) => {
|
|
464
|
+
return await this.exportUserCroppedImage(options);
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
command: "fitImageToArea",
|
|
469
|
+
title: "Fit Image to Area",
|
|
470
|
+
handler: async (
|
|
471
|
+
id: string,
|
|
472
|
+
area: {
|
|
473
|
+
width: number;
|
|
474
|
+
height: number;
|
|
475
|
+
left?: number;
|
|
476
|
+
top?: number;
|
|
477
|
+
},
|
|
478
|
+
) => {
|
|
479
|
+
await this.fitImageToArea(id, area);
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
command: "fitImageToDefaultArea",
|
|
484
|
+
title: "Fit Image to Default Area",
|
|
485
|
+
handler: async (id: string) => {
|
|
486
|
+
await this.fitImageToDefaultArea(id);
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
command: "focusImage",
|
|
491
|
+
title: "Focus Image",
|
|
492
|
+
handler: (
|
|
493
|
+
id: string | null,
|
|
494
|
+
options: { syncCanvasSelection?: boolean } = {},
|
|
495
|
+
) => {
|
|
496
|
+
return this.setImageFocus(id, options);
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
command: "removeImage",
|
|
501
|
+
title: "Remove Image",
|
|
502
|
+
handler: (id: string) => {
|
|
503
|
+
const removed = this.items.find((item) => item.id === id);
|
|
504
|
+
const next = this.items.filter((item) => item.id !== id);
|
|
505
|
+
if (next.length !== this.items.length) {
|
|
506
|
+
this.purgeSourceSizeCacheForItem(removed);
|
|
507
|
+
if (this.focusedImageId === id) {
|
|
508
|
+
this.setImageFocus(null, {
|
|
509
|
+
syncCanvasSelection: true,
|
|
510
|
+
skipRender: true,
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
this.updateConfig(next);
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
command: "updateImage",
|
|
519
|
+
title: "Update Image",
|
|
520
|
+
handler: async (
|
|
521
|
+
id: string,
|
|
522
|
+
updates: Partial<ImageItem>,
|
|
523
|
+
options: UpdateImageOptions = {},
|
|
524
|
+
) => {
|
|
525
|
+
await this.updateImage(id, updates, options);
|
|
526
|
+
},
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
command: "clearImages",
|
|
530
|
+
title: "Clear Images",
|
|
531
|
+
handler: () => {
|
|
532
|
+
this.sourceSizeBySrc.clear();
|
|
533
|
+
this.setImageFocus(null, {
|
|
534
|
+
syncCanvasSelection: true,
|
|
535
|
+
skipRender: true,
|
|
536
|
+
});
|
|
537
|
+
this.updateConfig([]);
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
command: "bringToFront",
|
|
542
|
+
title: "Bring Image to Front",
|
|
543
|
+
handler: (id: string) => {
|
|
544
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
545
|
+
if (index !== -1 && index < this.items.length - 1) {
|
|
546
|
+
const next = [...this.items];
|
|
547
|
+
const [item] = next.splice(index, 1);
|
|
548
|
+
next.push(item);
|
|
549
|
+
this.updateConfig(next);
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
command: "sendToBack",
|
|
555
|
+
title: "Send Image to Back",
|
|
556
|
+
handler: (id: string) => {
|
|
557
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
558
|
+
if (index > 0) {
|
|
559
|
+
const next = [...this.items];
|
|
560
|
+
const [item] = next.splice(index, 1);
|
|
561
|
+
next.unshift(item);
|
|
562
|
+
this.updateConfig(next);
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
] as CommandContribution[],
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
private normalizeItem(item: ImageItem): ImageItem {
|
|
571
|
+
const url = typeof item.url === "string" ? item.url : "";
|
|
572
|
+
const sourceUrl =
|
|
573
|
+
typeof item.sourceUrl === "string" && item.sourceUrl.length > 0
|
|
574
|
+
? item.sourceUrl
|
|
575
|
+
: url;
|
|
576
|
+
const committedUrl =
|
|
577
|
+
typeof item.committedUrl === "string" && item.committedUrl.length > 0
|
|
578
|
+
? item.committedUrl
|
|
579
|
+
: undefined;
|
|
580
|
+
|
|
581
|
+
return {
|
|
582
|
+
...item,
|
|
583
|
+
url: url || sourceUrl,
|
|
584
|
+
sourceUrl,
|
|
585
|
+
committedUrl,
|
|
586
|
+
opacity: Number.isFinite(item.opacity as any) ? item.opacity : 1,
|
|
587
|
+
scale: Number.isFinite(item.scale as any) ? item.scale : 1,
|
|
588
|
+
angle: Number.isFinite(item.angle as any) ? item.angle : 0,
|
|
589
|
+
left: Number.isFinite(item.left as any) ? item.left : 0.5,
|
|
590
|
+
top: Number.isFinite(item.top as any) ? item.top : 0.5,
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
private normalizeItems(items: ImageItem[]): ImageItem[] {
|
|
595
|
+
return (items || []).map((item) => this.normalizeItem(item));
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
private cloneItems(items: ImageItem[]): ImageItem[] {
|
|
599
|
+
return this.normalizeItems((items || []).map((i) => ({ ...i })));
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
private emitWorkingChange(changedId: string | null = null) {
|
|
603
|
+
this.context?.eventBus.emit("image:working:change", {
|
|
604
|
+
changedId,
|
|
605
|
+
items: this.cloneItems(this.workingItems),
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
private generateId(): string {
|
|
610
|
+
return Math.random().toString(36).substring(2, 9);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
private hasImageItem(id: string): boolean {
|
|
614
|
+
return (
|
|
615
|
+
this.items.some((item) => item.id === id) ||
|
|
616
|
+
this.workingItems.some((item) => item.id === id)
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
private setImageFocus(
|
|
621
|
+
id: string | null,
|
|
622
|
+
options: { syncCanvasSelection?: boolean; skipRender?: boolean } = {},
|
|
623
|
+
) {
|
|
624
|
+
const syncCanvasSelection = options.syncCanvasSelection !== false;
|
|
625
|
+
|
|
626
|
+
if (id && !this.hasImageItem(id)) {
|
|
627
|
+
return { ok: false, reason: "image-not-found" as const };
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
this.focusedImageId = id;
|
|
631
|
+
this.isImageSelectionActive = !!id;
|
|
632
|
+
|
|
633
|
+
if (syncCanvasSelection && this.canvasService) {
|
|
634
|
+
const canvas = this.canvasService.canvas;
|
|
635
|
+
if (!id) {
|
|
636
|
+
canvas.discardActiveObject();
|
|
637
|
+
} else {
|
|
638
|
+
const obj = this.getImageObject(id);
|
|
639
|
+
if (obj) {
|
|
640
|
+
obj.set({
|
|
641
|
+
selectable: true,
|
|
642
|
+
evented: true,
|
|
643
|
+
hasControls: true,
|
|
644
|
+
hasBorders: true,
|
|
645
|
+
});
|
|
646
|
+
canvas.setActiveObject(obj);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
this.canvasService.requestRenderAll();
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (!options.skipRender) {
|
|
653
|
+
this.updateImages();
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
return { ok: true, id };
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
private async addImageEntry(
|
|
660
|
+
url: string,
|
|
661
|
+
options?: Partial<ImageItem>,
|
|
662
|
+
fitOnAdd = true,
|
|
663
|
+
): Promise<string> {
|
|
664
|
+
const id = this.generateId();
|
|
665
|
+
const newItem = this.normalizeItem({
|
|
666
|
+
id,
|
|
667
|
+
url,
|
|
668
|
+
opacity: 1,
|
|
669
|
+
...options,
|
|
670
|
+
} as ImageItem);
|
|
671
|
+
|
|
672
|
+
const sessionDirtyBeforeAdd = this.isToolActive && this.hasWorkingChanges;
|
|
673
|
+
const waitLoaded = this.waitImageLoaded(id, true);
|
|
674
|
+
this.updateConfig([...this.items, newItem]);
|
|
675
|
+
this.addItemToWorkingSessionIfNeeded(newItem, sessionDirtyBeforeAdd);
|
|
676
|
+
const loaded = await waitLoaded;
|
|
677
|
+
if (loaded && fitOnAdd) {
|
|
678
|
+
await this.fitImageToDefaultArea(id);
|
|
679
|
+
}
|
|
680
|
+
if (loaded) {
|
|
681
|
+
this.setImageFocus(id);
|
|
682
|
+
}
|
|
683
|
+
return id;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
private async upsertImageEntry(
|
|
687
|
+
url: string,
|
|
688
|
+
options: UpsertImageOptions = {},
|
|
689
|
+
): Promise<{ id: string; mode: "replace" | "add" }> {
|
|
690
|
+
const mode = options.mode || (options.id ? "replace" : "add");
|
|
691
|
+
const fitOnAdd = options.fitOnAdd !== false;
|
|
692
|
+
if (mode === "replace") {
|
|
693
|
+
if (!options.id) {
|
|
694
|
+
throw new Error("replace-target-id-required");
|
|
695
|
+
}
|
|
696
|
+
const targetId = options.id;
|
|
697
|
+
if (!this.hasImageItem(targetId)) {
|
|
698
|
+
throw new Error("replace-target-not-found");
|
|
699
|
+
}
|
|
700
|
+
await this.updateImageInConfig(targetId, { url });
|
|
701
|
+
return { id: targetId, mode: "replace" };
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const id = await this.addImageEntry(url, options.addOptions, fitOnAdd);
|
|
705
|
+
return { id, mode: "add" };
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
private addItemToWorkingSessionIfNeeded(
|
|
709
|
+
item: ImageItem,
|
|
710
|
+
sessionDirtyBeforeAdd: boolean,
|
|
711
|
+
) {
|
|
712
|
+
if (!sessionDirtyBeforeAdd || !this.isToolActive) return;
|
|
713
|
+
if (this.workingItems.some((existing) => existing.id === item.id)) return;
|
|
714
|
+
this.workingItems = this.cloneItems([...this.workingItems, item]);
|
|
715
|
+
this.updateImages();
|
|
716
|
+
this.emitWorkingChange(item.id);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
private async updateImage(
|
|
720
|
+
id: string,
|
|
721
|
+
updates: Partial<ImageItem>,
|
|
722
|
+
options: UpdateImageOptions = {},
|
|
723
|
+
) {
|
|
724
|
+
this.syncToolActiveFromWorkbench();
|
|
725
|
+
const target = options.target || "auto";
|
|
726
|
+
|
|
727
|
+
if (target === "working" || (target === "auto" && this.isToolActive)) {
|
|
728
|
+
this.updateImageInWorking(id, updates);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
await this.updateImageInConfig(id, updates);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
private getConfig<T>(key: string, fallback?: T): T | undefined {
|
|
736
|
+
if (!this.context) return fallback;
|
|
737
|
+
const configService = this.context.services.get<ConfigurationService>(
|
|
738
|
+
"ConfigurationService",
|
|
739
|
+
);
|
|
740
|
+
if (!configService) return fallback;
|
|
741
|
+
return (configService.get(key, fallback) as T) ?? fallback;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
private updateConfig(newItems: ImageItem[], skipCanvasUpdate = false) {
|
|
745
|
+
if (!this.context) return;
|
|
746
|
+
|
|
747
|
+
this.isUpdatingConfig = true;
|
|
748
|
+
this.items = this.normalizeItems(newItems);
|
|
749
|
+
if (!this.isToolActive || !this.hasWorkingChanges) {
|
|
750
|
+
this.workingItems = this.cloneItems(this.items);
|
|
751
|
+
this.hasWorkingChanges = false;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
const configService = this.context.services.get<ConfigurationService>(
|
|
755
|
+
"ConfigurationService",
|
|
756
|
+
);
|
|
757
|
+
configService?.update("image.items", this.items);
|
|
758
|
+
|
|
759
|
+
if (!skipCanvasUpdate) {
|
|
760
|
+
this.updateImages();
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
setTimeout(() => {
|
|
764
|
+
this.isUpdatingConfig = false;
|
|
765
|
+
}, 50);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
private getFrameRect(): FrameRect {
|
|
769
|
+
if (!this.canvasService) {
|
|
770
|
+
return { left: 0, top: 0, width: 0, height: 0 };
|
|
771
|
+
}
|
|
772
|
+
const configService = this.context?.services.get<ConfigurationService>(
|
|
773
|
+
"ConfigurationService",
|
|
774
|
+
);
|
|
775
|
+
if (!configService) {
|
|
776
|
+
return { left: 0, top: 0, width: 0, height: 0 };
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
const sizeState = readSizeState(configService);
|
|
780
|
+
const layout = computeSceneLayout(this.canvasService, sizeState);
|
|
781
|
+
if (!layout) {
|
|
782
|
+
return { left: 0, top: 0, width: 0, height: 0 };
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
return this.canvasService.toSceneRect({
|
|
786
|
+
left: layout.cutRect.left,
|
|
787
|
+
top: layout.cutRect.top,
|
|
788
|
+
width: layout.cutRect.width,
|
|
789
|
+
height: layout.cutRect.height,
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
private getFrameRectScreen(frame?: FrameRect): FrameRect {
|
|
794
|
+
if (!this.canvasService) {
|
|
795
|
+
return { left: 0, top: 0, width: 0, height: 0 };
|
|
796
|
+
}
|
|
797
|
+
return this.canvasService.toScreenRect(frame || this.getFrameRect());
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
private toLayoutSceneRect(rect: FrameRect): RenderLayoutRect {
|
|
801
|
+
return {
|
|
802
|
+
left: rect.left,
|
|
803
|
+
top: rect.top,
|
|
804
|
+
width: rect.width,
|
|
805
|
+
height: rect.height,
|
|
806
|
+
space: "scene",
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
private async resolveDefaultFitArea(): Promise<DielineFitArea | null> {
|
|
811
|
+
if (!this.canvasService) return null;
|
|
812
|
+
const frame = this.getFrameRect();
|
|
813
|
+
if (frame.width <= 0 || frame.height <= 0) return null;
|
|
814
|
+
return {
|
|
815
|
+
width: Math.max(1, frame.width),
|
|
816
|
+
height: Math.max(1, frame.height),
|
|
817
|
+
left: frame.left + frame.width / 2,
|
|
818
|
+
top: frame.top + frame.height / 2,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
private async fitImageToDefaultArea(id: string) {
|
|
823
|
+
if (!this.canvasService) return;
|
|
824
|
+
const area = await this.resolveDefaultFitArea();
|
|
825
|
+
|
|
826
|
+
if (area) {
|
|
827
|
+
await this.fitImageToArea(id, area);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const viewport = this.canvasService.getSceneViewportRect();
|
|
832
|
+
const canvasW = Math.max(1, viewport.width || 0);
|
|
833
|
+
const canvasH = Math.max(1, viewport.height || 0);
|
|
834
|
+
await this.fitImageToArea(id, {
|
|
835
|
+
width: canvasW,
|
|
836
|
+
height: canvasH,
|
|
837
|
+
left: viewport.left + canvasW / 2,
|
|
838
|
+
top: viewport.top + canvasH / 2,
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
private getImageObjects(): any[] {
|
|
843
|
+
if (!this.canvasService) return [];
|
|
844
|
+
return this.canvasService.canvas.getObjects().filter((obj: any) => {
|
|
845
|
+
return obj?.data?.layerId === IMAGE_OBJECT_LAYER_ID;
|
|
846
|
+
}) as any[];
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
private getOverlayObjects(): any[] {
|
|
850
|
+
if (!this.canvasService) return [];
|
|
851
|
+
return this.canvasService.getRootLayerObjects(
|
|
852
|
+
IMAGE_OVERLAY_LAYER_ID,
|
|
853
|
+
) as any[];
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
private getImageObject(id: string): any | undefined {
|
|
857
|
+
return this.getImageObjects().find((obj: any) => obj?.data?.id === id);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
private clearRenderedImages() {
|
|
861
|
+
if (!this.canvasService) return;
|
|
862
|
+
const canvas = this.canvasService.canvas;
|
|
863
|
+
this.getImageObjects().forEach((obj) => canvas.remove(obj));
|
|
864
|
+
this.canvasService.requestRenderAll();
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
private purgeSourceSizeCacheForItem(item?: ImageItem) {
|
|
868
|
+
if (!item) return;
|
|
869
|
+
const sources = [item.url, item.sourceUrl, item.committedUrl].filter(
|
|
870
|
+
(value): value is string => typeof value === "string" && value.length > 0,
|
|
871
|
+
);
|
|
872
|
+
sources.forEach((src) => this.sourceSizeBySrc.delete(src));
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
private rememberSourceSize(src: string, obj: any) {
|
|
876
|
+
const width = Number(obj?.width || 0);
|
|
877
|
+
const height = Number(obj?.height || 0);
|
|
878
|
+
if (src && width > 0 && height > 0) {
|
|
879
|
+
this.sourceSizeBySrc.set(src, { width, height });
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
private getSourceSize(src: string, obj?: any): SourceSize {
|
|
884
|
+
const cached = src ? this.sourceSizeBySrc.get(src) : undefined;
|
|
885
|
+
if (cached) return cached;
|
|
886
|
+
|
|
887
|
+
const width = Number(obj?.width || 0);
|
|
888
|
+
const height = Number(obj?.height || 0);
|
|
889
|
+
if (src && width > 0 && height > 0) {
|
|
890
|
+
const size = { width, height };
|
|
891
|
+
this.sourceSizeBySrc.set(src, size);
|
|
892
|
+
return size;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
return { width: 1, height: 1 };
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
private getCoverScale(frame: FrameRect, size: SourceSize): number {
|
|
899
|
+
const sw = Math.max(1, size.width);
|
|
900
|
+
const sh = Math.max(1, size.height);
|
|
901
|
+
const fw = Math.max(1, frame.width);
|
|
902
|
+
const fh = Math.max(1, frame.height);
|
|
903
|
+
return Math.max(fw / sw, fh / sh);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
private getFrameVisualConfig(): FrameVisualConfig {
|
|
907
|
+
const strokeStyleRaw = (this.getConfig<string>(
|
|
908
|
+
"image.frame.strokeStyle",
|
|
909
|
+
"dashed",
|
|
910
|
+
) || "dashed") as string;
|
|
911
|
+
const strokeStyle: "solid" | "dashed" | "hidden" =
|
|
912
|
+
strokeStyleRaw === "dashed" || strokeStyleRaw === "hidden"
|
|
913
|
+
? strokeStyleRaw
|
|
914
|
+
: "dashed";
|
|
915
|
+
|
|
916
|
+
const strokeWidth = Number(
|
|
917
|
+
this.getConfig<number>("image.frame.strokeWidth", 2) ?? 2,
|
|
918
|
+
);
|
|
919
|
+
const dashLength = Number(
|
|
920
|
+
this.getConfig<number>("image.frame.dashLength", 8) ?? 8,
|
|
921
|
+
);
|
|
922
|
+
|
|
923
|
+
return {
|
|
924
|
+
strokeColor:
|
|
925
|
+
this.getConfig<string>("image.frame.strokeColor", "#808080") ||
|
|
926
|
+
"#808080",
|
|
927
|
+
strokeWidth: Number.isFinite(strokeWidth) ? Math.max(0, strokeWidth) : 2,
|
|
928
|
+
strokeStyle,
|
|
929
|
+
dashLength: Number.isFinite(dashLength) ? Math.max(1, dashLength) : 8,
|
|
930
|
+
innerBackground:
|
|
931
|
+
this.getConfig<string>(
|
|
932
|
+
"image.frame.innerBackground",
|
|
933
|
+
"rgba(0,0,0,0)",
|
|
934
|
+
) || "rgba(0,0,0,0)",
|
|
935
|
+
outerBackground:
|
|
936
|
+
this.getConfig<string>("image.frame.outerBackground", "#f5f5f5") ||
|
|
937
|
+
"#f5f5f5",
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
private toSceneGeometryLike(raw: any): SceneGeometryLike | null {
|
|
942
|
+
const shape = raw?.shape;
|
|
943
|
+
if (!isDielineShape(shape)) {
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
const radiusRaw = Number(raw?.radius);
|
|
948
|
+
const offsetRaw = Number(raw?.offset);
|
|
949
|
+
const unit = typeof raw?.unit === "string" ? raw.unit : "px";
|
|
950
|
+
const radius =
|
|
951
|
+
unit === "scene" || !this.canvasService
|
|
952
|
+
? radiusRaw
|
|
953
|
+
: this.canvasService.toSceneLength(radiusRaw);
|
|
954
|
+
const offset =
|
|
955
|
+
unit === "scene" || !this.canvasService
|
|
956
|
+
? offsetRaw
|
|
957
|
+
: this.canvasService.toSceneLength(offsetRaw);
|
|
958
|
+
return {
|
|
959
|
+
shape,
|
|
960
|
+
shapeStyle: normalizeShapeStyle(raw?.shapeStyle),
|
|
961
|
+
radius: Number.isFinite(radius) ? radius : 0,
|
|
962
|
+
offset: Number.isFinite(offset) ? offset : 0,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
private async resolveSceneGeometryForOverlay(): Promise<SceneGeometryLike | null> {
|
|
967
|
+
if (!this.context) return null;
|
|
968
|
+
const commandService = this.context.services.get<any>("CommandService");
|
|
969
|
+
if (commandService) {
|
|
970
|
+
try {
|
|
971
|
+
const raw = await Promise.resolve(
|
|
972
|
+
commandService.executeCommand("getSceneGeometry"),
|
|
973
|
+
);
|
|
974
|
+
const geometry = this.toSceneGeometryLike(raw);
|
|
975
|
+
if (geometry) {
|
|
976
|
+
this.debug("overlay:sceneGeometry:command", geometry);
|
|
977
|
+
return geometry;
|
|
978
|
+
}
|
|
979
|
+
this.debug("overlay:sceneGeometry:command:invalid", { raw });
|
|
980
|
+
} catch (error) {
|
|
981
|
+
this.debug("overlay:sceneGeometry:command:error", {
|
|
982
|
+
error: error instanceof Error ? error.message : String(error),
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
if (!this.canvasService) return null;
|
|
988
|
+
const configService = this.context.services.get<ConfigurationService>(
|
|
989
|
+
"ConfigurationService",
|
|
990
|
+
);
|
|
991
|
+
if (!configService) return null;
|
|
992
|
+
|
|
993
|
+
const sizeState = readSizeState(configService);
|
|
994
|
+
const layout = computeSceneLayout(this.canvasService, sizeState);
|
|
995
|
+
if (!layout) {
|
|
996
|
+
this.debug("overlay:sceneGeometry:fallback:missing-layout");
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
const geometry = this.toSceneGeometryLike(
|
|
1001
|
+
buildSceneGeometry(configService, layout),
|
|
1002
|
+
);
|
|
1003
|
+
if (geometry) {
|
|
1004
|
+
this.debug("overlay:sceneGeometry:fallback", geometry);
|
|
1005
|
+
}
|
|
1006
|
+
return geometry;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
private resolveCutShapeRadius(
|
|
1010
|
+
geometry: SceneGeometryLike,
|
|
1011
|
+
frame: FrameRect,
|
|
1012
|
+
): number {
|
|
1013
|
+
const visualRadius = Number.isFinite(geometry.radius)
|
|
1014
|
+
? Math.max(0, geometry.radius)
|
|
1015
|
+
: 0;
|
|
1016
|
+
const visualOffset = Number.isFinite(geometry.offset) ? geometry.offset : 0;
|
|
1017
|
+
const rawCutRadius =
|
|
1018
|
+
visualRadius === 0 ? 0 : Math.max(0, visualRadius + visualOffset);
|
|
1019
|
+
const maxRadius = Math.max(0, Math.min(frame.width, frame.height) / 2);
|
|
1020
|
+
return Math.max(0, Math.min(maxRadius, rawCutRadius));
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
private getCropShapeHatchPattern(
|
|
1024
|
+
color = "rgba(255, 0, 0, 0.6)",
|
|
1025
|
+
): Pattern | undefined {
|
|
1026
|
+
if (typeof document === "undefined") return undefined;
|
|
1027
|
+
const sceneScale = this.canvasService?.getSceneScale() || 1;
|
|
1028
|
+
const cacheKey = `${color}::${sceneScale.toFixed(6)}`;
|
|
1029
|
+
if (
|
|
1030
|
+
this.cropShapeHatchPattern &&
|
|
1031
|
+
this.cropShapeHatchPatternColor === color &&
|
|
1032
|
+
this.cropShapeHatchPatternKey === cacheKey
|
|
1033
|
+
) {
|
|
1034
|
+
return this.cropShapeHatchPattern;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
const size = 16;
|
|
1038
|
+
const patternCanvas = document.createElement("canvas");
|
|
1039
|
+
patternCanvas.width = size;
|
|
1040
|
+
patternCanvas.height = size;
|
|
1041
|
+
const ctx = patternCanvas.getContext("2d");
|
|
1042
|
+
if (!ctx) return undefined;
|
|
1043
|
+
|
|
1044
|
+
ctx.clearRect(0, 0, size, size);
|
|
1045
|
+
ctx.fillStyle = "rgba(255, 0, 0, 0.08)";
|
|
1046
|
+
ctx.fillRect(0, 0, size, size);
|
|
1047
|
+
ctx.strokeStyle = color;
|
|
1048
|
+
ctx.lineWidth = 1.5;
|
|
1049
|
+
ctx.beginPath();
|
|
1050
|
+
ctx.moveTo(-size, size);
|
|
1051
|
+
ctx.lineTo(size, -size);
|
|
1052
|
+
ctx.moveTo(-size / 2, size + size / 2);
|
|
1053
|
+
ctx.lineTo(size + size / 2, -size / 2);
|
|
1054
|
+
ctx.moveTo(0, size);
|
|
1055
|
+
ctx.lineTo(size, 0);
|
|
1056
|
+
ctx.moveTo(size / 2, size + size / 2);
|
|
1057
|
+
ctx.lineTo(size + size + size / 2, -size / 2);
|
|
1058
|
+
ctx.stroke();
|
|
1059
|
+
|
|
1060
|
+
const pattern = new Pattern({
|
|
1061
|
+
source: patternCanvas,
|
|
1062
|
+
// @ts-ignore: Fabric Pattern accepts canvas source here.
|
|
1063
|
+
repetition: "repeat",
|
|
1064
|
+
});
|
|
1065
|
+
// Scene specs are scaled to screen by CanvasService; keep hatch density in screen pixels.
|
|
1066
|
+
(pattern as any).patternTransform = [
|
|
1067
|
+
1 / sceneScale,
|
|
1068
|
+
0,
|
|
1069
|
+
0,
|
|
1070
|
+
1 / sceneScale,
|
|
1071
|
+
0,
|
|
1072
|
+
0,
|
|
1073
|
+
];
|
|
1074
|
+
this.cropShapeHatchPattern = pattern;
|
|
1075
|
+
this.cropShapeHatchPatternColor = color;
|
|
1076
|
+
this.cropShapeHatchPatternKey = cacheKey;
|
|
1077
|
+
return pattern;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
private buildCropShapeOverlaySpecs(
|
|
1081
|
+
frame: FrameRect,
|
|
1082
|
+
sceneGeometry: SceneGeometryLike | null,
|
|
1083
|
+
): RenderObjectSpec[] {
|
|
1084
|
+
if (!sceneGeometry) {
|
|
1085
|
+
this.debug("overlay:shape:skip", { reason: "scene-geometry-missing" });
|
|
1086
|
+
return [];
|
|
1087
|
+
}
|
|
1088
|
+
if (sceneGeometry.shape === "custom") {
|
|
1089
|
+
this.debug("overlay:shape:skip", { reason: "shape-custom" });
|
|
1090
|
+
return [];
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
const shape = sceneGeometry.shape as ShapeOverlayShape;
|
|
1094
|
+
const shapeStyle = sceneGeometry.shapeStyle;
|
|
1095
|
+
const inset = 0;
|
|
1096
|
+
const shapeWidth = Math.max(1, frame.width);
|
|
1097
|
+
const shapeHeight = Math.max(1, frame.height);
|
|
1098
|
+
const radius = this.resolveCutShapeRadius(sceneGeometry, frame);
|
|
1099
|
+
|
|
1100
|
+
this.debug("overlay:shape:geometry", {
|
|
1101
|
+
shape,
|
|
1102
|
+
frameWidth: frame.width,
|
|
1103
|
+
frameHeight: frame.height,
|
|
1104
|
+
offset: sceneGeometry.offset,
|
|
1105
|
+
shapeStyle,
|
|
1106
|
+
inset,
|
|
1107
|
+
shapeWidth,
|
|
1108
|
+
shapeHeight,
|
|
1109
|
+
baseRadius: sceneGeometry.radius,
|
|
1110
|
+
radius,
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
const isSameAsFrame =
|
|
1114
|
+
Math.abs(shapeWidth - frame.width) <= 0.0001 &&
|
|
1115
|
+
Math.abs(shapeHeight - frame.height) <= 0.0001;
|
|
1116
|
+
if (shape === "rect" && radius <= 0.0001 && isSameAsFrame) {
|
|
1117
|
+
this.debug("overlay:shape:skip", {
|
|
1118
|
+
reason: "shape-rect-no-radius",
|
|
1119
|
+
});
|
|
1120
|
+
return [];
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
const baseOptions = {
|
|
1124
|
+
shape,
|
|
1125
|
+
width: shapeWidth,
|
|
1126
|
+
height: shapeHeight,
|
|
1127
|
+
radius,
|
|
1128
|
+
x: frame.width / 2,
|
|
1129
|
+
y: frame.height / 2,
|
|
1130
|
+
features: [],
|
|
1131
|
+
shapeStyle,
|
|
1132
|
+
canvasWidth: frame.width,
|
|
1133
|
+
canvasHeight: frame.height,
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
try {
|
|
1137
|
+
const shapePathData = generateDielinePath(baseOptions);
|
|
1138
|
+
const outerRectPathData = `M 0 0 L ${frame.width} 0 L ${frame.width} ${frame.height} L 0 ${frame.height} Z`;
|
|
1139
|
+
const hatchPathData = `${outerRectPathData} ${shapePathData}`;
|
|
1140
|
+
if (!shapePathData || !hatchPathData) {
|
|
1141
|
+
this.debug("overlay:shape:skip", {
|
|
1142
|
+
reason: "path-generation-empty",
|
|
1143
|
+
shape,
|
|
1144
|
+
radius,
|
|
1145
|
+
});
|
|
1146
|
+
return [];
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
const patternFill = this.getCropShapeHatchPattern();
|
|
1150
|
+
const hatchFill = patternFill || "rgba(255, 0, 0, 0.22)";
|
|
1151
|
+
const shapeBounds = getPathBounds(shapePathData);
|
|
1152
|
+
const hatchBounds = getPathBounds(hatchPathData);
|
|
1153
|
+
const frameRect = this.toLayoutSceneRect(frame);
|
|
1154
|
+
const hatchPathLength = hatchPathData.length;
|
|
1155
|
+
const shapePathLength = shapePathData.length;
|
|
1156
|
+
const specs: RenderObjectSpec[] = [
|
|
1157
|
+
{
|
|
1158
|
+
id: "image.cropShapeHatch",
|
|
1159
|
+
type: "path",
|
|
1160
|
+
data: { id: "image.cropShapeHatch", zIndex: 5 },
|
|
1161
|
+
layout: {
|
|
1162
|
+
reference: "custom",
|
|
1163
|
+
referenceRect: frameRect,
|
|
1164
|
+
alignX: "start",
|
|
1165
|
+
alignY: "start",
|
|
1166
|
+
offsetX: hatchBounds.x,
|
|
1167
|
+
offsetY: hatchBounds.y,
|
|
1168
|
+
},
|
|
1169
|
+
props: {
|
|
1170
|
+
pathData: hatchPathData,
|
|
1171
|
+
originX: "left",
|
|
1172
|
+
originY: "top",
|
|
1173
|
+
fill: hatchFill,
|
|
1174
|
+
opacity: patternFill ? 1 : 0.8,
|
|
1175
|
+
stroke: null,
|
|
1176
|
+
fillRule: "evenodd",
|
|
1177
|
+
selectable: false,
|
|
1178
|
+
evented: false,
|
|
1179
|
+
excludeFromExport: true,
|
|
1180
|
+
objectCaching: false,
|
|
1181
|
+
},
|
|
1182
|
+
},
|
|
1183
|
+
{
|
|
1184
|
+
id: "image.cropShapePath",
|
|
1185
|
+
type: "path",
|
|
1186
|
+
data: { id: "image.cropShapePath", zIndex: 6 },
|
|
1187
|
+
layout: {
|
|
1188
|
+
reference: "custom",
|
|
1189
|
+
referenceRect: frameRect,
|
|
1190
|
+
alignX: "start",
|
|
1191
|
+
alignY: "start",
|
|
1192
|
+
offsetX: shapeBounds.x,
|
|
1193
|
+
offsetY: shapeBounds.y,
|
|
1194
|
+
},
|
|
1195
|
+
props: {
|
|
1196
|
+
pathData: shapePathData,
|
|
1197
|
+
originX: "left",
|
|
1198
|
+
originY: "top",
|
|
1199
|
+
fill: "rgba(0,0,0,0)",
|
|
1200
|
+
stroke: "rgba(255, 0, 0, 0.9)",
|
|
1201
|
+
strokeWidth: this.canvasService?.toSceneLength(1) ?? 1,
|
|
1202
|
+
selectable: false,
|
|
1203
|
+
evented: false,
|
|
1204
|
+
excludeFromExport: true,
|
|
1205
|
+
objectCaching: false,
|
|
1206
|
+
},
|
|
1207
|
+
},
|
|
1208
|
+
];
|
|
1209
|
+
this.debug("overlay:shape:built", {
|
|
1210
|
+
shape,
|
|
1211
|
+
radius,
|
|
1212
|
+
inset,
|
|
1213
|
+
shapeWidth,
|
|
1214
|
+
shapeHeight,
|
|
1215
|
+
fillRule: "evenodd",
|
|
1216
|
+
shapePathLength,
|
|
1217
|
+
hatchPathLength,
|
|
1218
|
+
shapeBounds,
|
|
1219
|
+
hatchBounds,
|
|
1220
|
+
hatchFillType:
|
|
1221
|
+
hatchFill && typeof hatchFill === "object" ? "pattern" : "color",
|
|
1222
|
+
ids: specs.map((spec) => spec.id),
|
|
1223
|
+
});
|
|
1224
|
+
return specs;
|
|
1225
|
+
} catch (error) {
|
|
1226
|
+
this.debug("overlay:shape:error", {
|
|
1227
|
+
shape,
|
|
1228
|
+
radius,
|
|
1229
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1230
|
+
});
|
|
1231
|
+
return [];
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
private resolveRenderImageState(item: ImageItem): RenderImageState {
|
|
1236
|
+
const active = this.isToolActive;
|
|
1237
|
+
const sourceUrl = item.sourceUrl || item.url;
|
|
1238
|
+
const committedUrl = item.committedUrl;
|
|
1239
|
+
|
|
1240
|
+
if (!active && committedUrl) {
|
|
1241
|
+
return {
|
|
1242
|
+
src: committedUrl,
|
|
1243
|
+
left: 0.5,
|
|
1244
|
+
top: 0.5,
|
|
1245
|
+
scale: 1,
|
|
1246
|
+
angle: 0,
|
|
1247
|
+
opacity: item.opacity,
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
return {
|
|
1252
|
+
src: sourceUrl || item.url,
|
|
1253
|
+
left: Number.isFinite(item.left as any) ? (item.left as number) : 0.5,
|
|
1254
|
+
top: Number.isFinite(item.top as any) ? (item.top as number) : 0.5,
|
|
1255
|
+
scale: Math.max(0.05, item.scale ?? 1),
|
|
1256
|
+
angle: Number.isFinite(item.angle as any) ? (item.angle as number) : 0,
|
|
1257
|
+
opacity: item.opacity,
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
private computeCanvasProps(
|
|
1262
|
+
render: RenderImageState,
|
|
1263
|
+
size: SourceSize,
|
|
1264
|
+
frame: FrameRect,
|
|
1265
|
+
) {
|
|
1266
|
+
const left = render.left;
|
|
1267
|
+
const top = render.top;
|
|
1268
|
+
const zoom = render.scale;
|
|
1269
|
+
const angle = render.angle;
|
|
1270
|
+
|
|
1271
|
+
const centerX = frame.left + left * frame.width;
|
|
1272
|
+
const centerY = frame.top + top * frame.height;
|
|
1273
|
+
const scale = this.getCoverScale(frame, size) * zoom;
|
|
1274
|
+
|
|
1275
|
+
return {
|
|
1276
|
+
left: centerX,
|
|
1277
|
+
top: centerY,
|
|
1278
|
+
scaleX: scale,
|
|
1279
|
+
scaleY: scale,
|
|
1280
|
+
angle,
|
|
1281
|
+
originX: "center" as const,
|
|
1282
|
+
originY: "center" as const,
|
|
1283
|
+
uniformScaling: true,
|
|
1284
|
+
lockScalingFlip: true,
|
|
1285
|
+
selectable: this.isImageEditingVisible(),
|
|
1286
|
+
evented: this.isImageEditingVisible(),
|
|
1287
|
+
hasControls: this.isImageEditingVisible(),
|
|
1288
|
+
hasBorders: this.isImageEditingVisible(),
|
|
1289
|
+
opacity: render.opacity,
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
private toScreenObjectProps(props: Record<string, any>): Record<string, any> {
|
|
1294
|
+
if (!this.canvasService) return props;
|
|
1295
|
+
const next = { ...props };
|
|
1296
|
+
if (Number.isFinite(next.left) || Number.isFinite(next.top)) {
|
|
1297
|
+
const mapped = this.canvasService.toScreenPoint({
|
|
1298
|
+
x: Number.isFinite(next.left) ? Number(next.left) : 0,
|
|
1299
|
+
y: Number.isFinite(next.top) ? Number(next.top) : 0,
|
|
1300
|
+
});
|
|
1301
|
+
if (Number.isFinite(next.left)) next.left = mapped.x;
|
|
1302
|
+
if (Number.isFinite(next.top)) next.top = mapped.y;
|
|
1303
|
+
}
|
|
1304
|
+
const sceneScale = this.canvasService.getSceneScale();
|
|
1305
|
+
const sx = Number.isFinite(next.scaleX) ? Number(next.scaleX) : 1;
|
|
1306
|
+
const sy = Number.isFinite(next.scaleY) ? Number(next.scaleY) : 1;
|
|
1307
|
+
next.scaleX = sx * sceneScale;
|
|
1308
|
+
next.scaleY = sy * sceneScale;
|
|
1309
|
+
return next;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
private toSceneObjectScale(value: number): number {
|
|
1313
|
+
if (!this.canvasService) return value;
|
|
1314
|
+
return value / this.canvasService.getSceneScale();
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
private getCurrentSrc(obj: any): string | undefined {
|
|
1318
|
+
if (!obj) return undefined;
|
|
1319
|
+
if (typeof obj.getSrc === "function") return obj.getSrc();
|
|
1320
|
+
return obj?._originalElement?.src;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
private applyImageControlVisibility(obj: any) {
|
|
1324
|
+
if (typeof obj?.setControlsVisibility !== "function") return;
|
|
1325
|
+
obj.setControlsVisibility({
|
|
1326
|
+
mt: false,
|
|
1327
|
+
mb: false,
|
|
1328
|
+
ml: false,
|
|
1329
|
+
mr: false,
|
|
1330
|
+
tl: true,
|
|
1331
|
+
tr: true,
|
|
1332
|
+
bl: true,
|
|
1333
|
+
br: true,
|
|
1334
|
+
mtr: true,
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
private async upsertImageObject(
|
|
1339
|
+
item: ImageItem,
|
|
1340
|
+
frame: FrameRect,
|
|
1341
|
+
seq: number,
|
|
1342
|
+
) {
|
|
1343
|
+
if (!this.canvasService) return;
|
|
1344
|
+
const canvas = this.canvasService.canvas;
|
|
1345
|
+
const render = this.resolveRenderImageState(item);
|
|
1346
|
+
if (!render.src) return;
|
|
1347
|
+
|
|
1348
|
+
let obj = this.getImageObject(item.id);
|
|
1349
|
+
const currentSrc = this.getCurrentSrc(obj);
|
|
1350
|
+
|
|
1351
|
+
if (obj && currentSrc && currentSrc !== render.src) {
|
|
1352
|
+
canvas.remove(obj);
|
|
1353
|
+
obj = undefined;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
if (!obj) {
|
|
1357
|
+
const created = await FabricImage.fromURL(render.src, {
|
|
1358
|
+
crossOrigin: "anonymous",
|
|
1359
|
+
});
|
|
1360
|
+
if (seq !== this.renderSeq) return;
|
|
1361
|
+
|
|
1362
|
+
created.set({
|
|
1363
|
+
data: {
|
|
1364
|
+
id: item.id,
|
|
1365
|
+
layerId: IMAGE_OBJECT_LAYER_ID,
|
|
1366
|
+
type: "image-item",
|
|
1367
|
+
},
|
|
1368
|
+
} as any);
|
|
1369
|
+
canvas.add(created as any);
|
|
1370
|
+
obj = created as any;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
this.rememberSourceSize(render.src, obj);
|
|
1374
|
+
const sourceSize = this.getSourceSize(render.src, obj);
|
|
1375
|
+
const props = this.computeCanvasProps(render, sourceSize, frame);
|
|
1376
|
+
const screenProps = this.toScreenObjectProps(props);
|
|
1377
|
+
|
|
1378
|
+
obj.set({
|
|
1379
|
+
...screenProps,
|
|
1380
|
+
data: {
|
|
1381
|
+
...(obj.data || {}),
|
|
1382
|
+
id: item.id,
|
|
1383
|
+
layerId: IMAGE_OBJECT_LAYER_ID,
|
|
1384
|
+
type: "image-item",
|
|
1385
|
+
},
|
|
1386
|
+
});
|
|
1387
|
+
this.applyImageControlVisibility(obj);
|
|
1388
|
+
obj.setCoords();
|
|
1389
|
+
|
|
1390
|
+
const resolver = this.loadResolvers.get(item.id);
|
|
1391
|
+
if (resolver) {
|
|
1392
|
+
resolver();
|
|
1393
|
+
this.loadResolvers.delete(item.id);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
private syncImageZOrder(items: ImageItem[]) {
|
|
1398
|
+
if (!this.canvasService) return;
|
|
1399
|
+
const canvas = this.canvasService.canvas;
|
|
1400
|
+
|
|
1401
|
+
const objects = canvas.getObjects();
|
|
1402
|
+
let insertIndex = 0;
|
|
1403
|
+
|
|
1404
|
+
const backgroundLayer = this.canvasService.getLayer("background");
|
|
1405
|
+
if (backgroundLayer) {
|
|
1406
|
+
const bgIndex = objects.indexOf(backgroundLayer as any);
|
|
1407
|
+
if (bgIndex >= 0) insertIndex = bgIndex + 1;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
items.forEach((item) => {
|
|
1411
|
+
const obj = this.getImageObject(item.id);
|
|
1412
|
+
if (!obj) return;
|
|
1413
|
+
canvas.moveObjectTo(obj, insertIndex);
|
|
1414
|
+
insertIndex += 1;
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
const overlayObjects = this.getOverlayObjects().sort((a: any, b: any) => {
|
|
1418
|
+
const az = Number(a?.data?.zIndex ?? 0);
|
|
1419
|
+
const bz = Number(b?.data?.zIndex ?? 0);
|
|
1420
|
+
return az - bz;
|
|
1421
|
+
});
|
|
1422
|
+
overlayObjects.forEach((obj) => {
|
|
1423
|
+
canvas.bringObjectToFront(obj);
|
|
1424
|
+
});
|
|
1425
|
+
|
|
1426
|
+
if (this.isDebugEnabled()) {
|
|
1427
|
+
const stack = canvas
|
|
1428
|
+
.getObjects()
|
|
1429
|
+
.map((obj: any, index: number) => ({
|
|
1430
|
+
index,
|
|
1431
|
+
id: obj?.data?.id,
|
|
1432
|
+
layerId: obj?.data?.layerId,
|
|
1433
|
+
zIndex: obj?.data?.zIndex,
|
|
1434
|
+
}))
|
|
1435
|
+
.filter((item) => item.layerId === IMAGE_OVERLAY_LAYER_ID);
|
|
1436
|
+
this.debug("overlay:stack", stack);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
private buildOverlaySpecs(
|
|
1441
|
+
frame: FrameRect,
|
|
1442
|
+
sceneGeometry: SceneGeometryLike | null,
|
|
1443
|
+
): RenderObjectSpec[] {
|
|
1444
|
+
const visible = this.isImageEditingVisible();
|
|
1445
|
+
if (
|
|
1446
|
+
!visible ||
|
|
1447
|
+
frame.width <= 0 ||
|
|
1448
|
+
frame.height <= 0 ||
|
|
1449
|
+
!this.canvasService
|
|
1450
|
+
) {
|
|
1451
|
+
this.debug("overlay:hidden", {
|
|
1452
|
+
visible,
|
|
1453
|
+
frame,
|
|
1454
|
+
isToolActive: this.isToolActive,
|
|
1455
|
+
isImageSelectionActive: this.isImageSelectionActive,
|
|
1456
|
+
focusedImageId: this.focusedImageId,
|
|
1457
|
+
});
|
|
1458
|
+
return [];
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
const viewport = this.canvasService.getSceneViewportRect();
|
|
1462
|
+
const canvasW = viewport.width || 0;
|
|
1463
|
+
const canvasH = viewport.height || 0;
|
|
1464
|
+
const canvasLeft = viewport.left || 0;
|
|
1465
|
+
const canvasTop = viewport.top || 0;
|
|
1466
|
+
const visual = this.getFrameVisualConfig();
|
|
1467
|
+
const strokeWidthScene = this.canvasService.toSceneLength(
|
|
1468
|
+
visual.strokeWidth,
|
|
1469
|
+
);
|
|
1470
|
+
const dashLengthScene = this.canvasService.toSceneLength(visual.dashLength);
|
|
1471
|
+
|
|
1472
|
+
const frameLeft = Math.max(
|
|
1473
|
+
canvasLeft,
|
|
1474
|
+
Math.min(canvasLeft + canvasW, frame.left),
|
|
1475
|
+
);
|
|
1476
|
+
const frameTop = Math.max(
|
|
1477
|
+
canvasTop,
|
|
1478
|
+
Math.min(canvasTop + canvasH, frame.top),
|
|
1479
|
+
);
|
|
1480
|
+
const frameRight = Math.max(
|
|
1481
|
+
frameLeft,
|
|
1482
|
+
Math.min(canvasLeft + canvasW, frame.left + frame.width),
|
|
1483
|
+
);
|
|
1484
|
+
const frameBottom = Math.max(
|
|
1485
|
+
frameTop,
|
|
1486
|
+
Math.min(canvasTop + canvasH, frame.top + frame.height),
|
|
1487
|
+
);
|
|
1488
|
+
const visibleFrameH = Math.max(0, frameBottom - frameTop);
|
|
1489
|
+
|
|
1490
|
+
const topH = Math.max(0, frameTop - canvasTop);
|
|
1491
|
+
const bottomH = Math.max(0, canvasTop + canvasH - frameBottom);
|
|
1492
|
+
const leftW = Math.max(0, frameLeft - canvasLeft);
|
|
1493
|
+
const rightW = Math.max(0, canvasLeft + canvasW - frameRight);
|
|
1494
|
+
const viewportRect = this.toLayoutSceneRect({
|
|
1495
|
+
left: canvasLeft,
|
|
1496
|
+
top: canvasTop,
|
|
1497
|
+
width: canvasW,
|
|
1498
|
+
height: canvasH,
|
|
1499
|
+
});
|
|
1500
|
+
const visibleFrameBandRect = this.toLayoutSceneRect({
|
|
1501
|
+
left: canvasLeft,
|
|
1502
|
+
top: frameTop,
|
|
1503
|
+
width: canvasW,
|
|
1504
|
+
height: visibleFrameH,
|
|
1505
|
+
});
|
|
1506
|
+
const frameRect = this.toLayoutSceneRect(frame);
|
|
1507
|
+
const shapeOverlay = this.buildCropShapeOverlaySpecs(frame, sceneGeometry);
|
|
1508
|
+
|
|
1509
|
+
const mask: RenderObjectSpec[] = [
|
|
1510
|
+
{
|
|
1511
|
+
id: "image.cropMask.top",
|
|
1512
|
+
type: "rect",
|
|
1513
|
+
data: { id: "image.cropMask.top", zIndex: 1 },
|
|
1514
|
+
layout: {
|
|
1515
|
+
reference: "custom",
|
|
1516
|
+
referenceRect: viewportRect,
|
|
1517
|
+
alignX: "start",
|
|
1518
|
+
alignY: "start",
|
|
1519
|
+
width: "100%",
|
|
1520
|
+
height: topH,
|
|
1521
|
+
},
|
|
1522
|
+
props: {
|
|
1523
|
+
originX: "left",
|
|
1524
|
+
originY: "top",
|
|
1525
|
+
fill: visual.outerBackground,
|
|
1526
|
+
selectable: false,
|
|
1527
|
+
evented: false,
|
|
1528
|
+
},
|
|
1529
|
+
},
|
|
1530
|
+
{
|
|
1531
|
+
id: "image.cropMask.bottom",
|
|
1532
|
+
type: "rect",
|
|
1533
|
+
data: { id: "image.cropMask.bottom", zIndex: 2 },
|
|
1534
|
+
layout: {
|
|
1535
|
+
reference: "custom",
|
|
1536
|
+
referenceRect: viewportRect,
|
|
1537
|
+
alignX: "start",
|
|
1538
|
+
alignY: "end",
|
|
1539
|
+
width: "100%",
|
|
1540
|
+
height: bottomH,
|
|
1541
|
+
},
|
|
1542
|
+
props: {
|
|
1543
|
+
originX: "left",
|
|
1544
|
+
originY: "top",
|
|
1545
|
+
fill: visual.outerBackground,
|
|
1546
|
+
selectable: false,
|
|
1547
|
+
evented: false,
|
|
1548
|
+
},
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
id: "image.cropMask.left",
|
|
1552
|
+
type: "rect",
|
|
1553
|
+
data: { id: "image.cropMask.left", zIndex: 3 },
|
|
1554
|
+
layout: {
|
|
1555
|
+
reference: "custom",
|
|
1556
|
+
referenceRect: visibleFrameBandRect,
|
|
1557
|
+
alignX: "start",
|
|
1558
|
+
alignY: "start",
|
|
1559
|
+
width: leftW,
|
|
1560
|
+
height: "100%",
|
|
1561
|
+
},
|
|
1562
|
+
props: {
|
|
1563
|
+
originX: "left",
|
|
1564
|
+
originY: "top",
|
|
1565
|
+
fill: visual.outerBackground,
|
|
1566
|
+
selectable: false,
|
|
1567
|
+
evented: false,
|
|
1568
|
+
},
|
|
1569
|
+
},
|
|
1570
|
+
{
|
|
1571
|
+
id: "image.cropMask.right",
|
|
1572
|
+
type: "rect",
|
|
1573
|
+
data: { id: "image.cropMask.right", zIndex: 4 },
|
|
1574
|
+
layout: {
|
|
1575
|
+
reference: "custom",
|
|
1576
|
+
referenceRect: visibleFrameBandRect,
|
|
1577
|
+
alignX: "end",
|
|
1578
|
+
alignY: "start",
|
|
1579
|
+
width: rightW,
|
|
1580
|
+
height: "100%",
|
|
1581
|
+
},
|
|
1582
|
+
props: {
|
|
1583
|
+
originX: "left",
|
|
1584
|
+
originY: "top",
|
|
1585
|
+
fill: visual.outerBackground,
|
|
1586
|
+
selectable: false,
|
|
1587
|
+
evented: false,
|
|
1588
|
+
},
|
|
1589
|
+
},
|
|
1590
|
+
];
|
|
1591
|
+
|
|
1592
|
+
const frameSpec: RenderObjectSpec = {
|
|
1593
|
+
id: "image.cropFrame",
|
|
1594
|
+
type: "rect",
|
|
1595
|
+
data: { id: "image.cropFrame", zIndex: 7 },
|
|
1596
|
+
layout: {
|
|
1597
|
+
reference: "custom",
|
|
1598
|
+
referenceRect: frameRect,
|
|
1599
|
+
alignX: "start",
|
|
1600
|
+
alignY: "start",
|
|
1601
|
+
width: "100%",
|
|
1602
|
+
height: "100%",
|
|
1603
|
+
},
|
|
1604
|
+
props: {
|
|
1605
|
+
originX: "left",
|
|
1606
|
+
originY: "top",
|
|
1607
|
+
fill: visual.innerBackground,
|
|
1608
|
+
stroke:
|
|
1609
|
+
visual.strokeStyle === "hidden"
|
|
1610
|
+
? "rgba(0,0,0,0)"
|
|
1611
|
+
: visual.strokeColor,
|
|
1612
|
+
strokeWidth: visual.strokeStyle === "hidden" ? 0 : strokeWidthScene,
|
|
1613
|
+
strokeDashArray:
|
|
1614
|
+
visual.strokeStyle === "dashed"
|
|
1615
|
+
? [dashLengthScene, dashLengthScene]
|
|
1616
|
+
: undefined,
|
|
1617
|
+
selectable: false,
|
|
1618
|
+
evented: false,
|
|
1619
|
+
},
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
const specs = [...mask, ...shapeOverlay, frameSpec];
|
|
1623
|
+
this.debug("overlay:built", {
|
|
1624
|
+
frame,
|
|
1625
|
+
shape: sceneGeometry?.shape,
|
|
1626
|
+
overlayIds: specs.map((spec) => ({
|
|
1627
|
+
id: spec.id,
|
|
1628
|
+
zIndex: spec.data?.zIndex,
|
|
1629
|
+
})),
|
|
1630
|
+
});
|
|
1631
|
+
return specs;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
private updateImages() {
|
|
1635
|
+
void this.updateImagesAsync();
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
private async updateImagesAsync() {
|
|
1639
|
+
if (!this.canvasService) return;
|
|
1640
|
+
this.syncToolActiveFromWorkbench();
|
|
1641
|
+
const seq = ++this.renderSeq;
|
|
1642
|
+
|
|
1643
|
+
const renderItems = this.isToolActive ? this.workingItems : this.items;
|
|
1644
|
+
const frame = this.getFrameRect();
|
|
1645
|
+
const desiredIds = new Set(renderItems.map((item) => item.id));
|
|
1646
|
+
if (this.focusedImageId && !desiredIds.has(this.focusedImageId)) {
|
|
1647
|
+
this.setImageFocus(null, {
|
|
1648
|
+
syncCanvasSelection: false,
|
|
1649
|
+
skipRender: true,
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
this.getImageObjects().forEach((obj: any) => {
|
|
1654
|
+
const id = obj?.data?.id;
|
|
1655
|
+
if (typeof id === "string" && !desiredIds.has(id)) {
|
|
1656
|
+
this.canvasService?.canvas.remove(obj);
|
|
1657
|
+
}
|
|
1658
|
+
});
|
|
1659
|
+
|
|
1660
|
+
for (const item of renderItems) {
|
|
1661
|
+
if (seq !== this.renderSeq) return;
|
|
1662
|
+
await this.upsertImageObject(item, frame, seq);
|
|
1663
|
+
}
|
|
1664
|
+
if (seq !== this.renderSeq) return;
|
|
1665
|
+
|
|
1666
|
+
this.syncImageZOrder(renderItems);
|
|
1667
|
+
const sceneGeometry = await this.resolveSceneGeometryForOverlay();
|
|
1668
|
+
if (seq !== this.renderSeq) return;
|
|
1669
|
+
|
|
1670
|
+
const overlaySpecs = this.buildOverlaySpecs(frame, sceneGeometry);
|
|
1671
|
+
this.overlaySpecs = overlaySpecs;
|
|
1672
|
+
await this.canvasService.flushRenderFromProducers();
|
|
1673
|
+
this.syncImageZOrder(renderItems);
|
|
1674
|
+
const overlayCanvasCount = this.getOverlayObjects().length;
|
|
1675
|
+
|
|
1676
|
+
this.debug("render:done", {
|
|
1677
|
+
seq,
|
|
1678
|
+
renderCount: renderItems.length,
|
|
1679
|
+
overlayCount: overlaySpecs.length,
|
|
1680
|
+
overlayCanvasCount,
|
|
1681
|
+
isToolActive: this.isToolActive,
|
|
1682
|
+
isImageSelectionActive: this.isImageSelectionActive,
|
|
1683
|
+
focusedImageId: this.focusedImageId,
|
|
1684
|
+
});
|
|
1685
|
+
this.canvasService.requestRenderAll();
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
private clampNormalized(value: number): number {
|
|
1689
|
+
return Math.max(-1, Math.min(2, value));
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
private onObjectModified = (e: any) => {
|
|
1693
|
+
if (!this.isToolActive) return;
|
|
1694
|
+
const target = e?.target;
|
|
1695
|
+
const id = target?.data?.id;
|
|
1696
|
+
const layerId = target?.data?.layerId;
|
|
1697
|
+
if (typeof id !== "string" || layerId !== IMAGE_OBJECT_LAYER_ID) return;
|
|
1698
|
+
|
|
1699
|
+
const frame = this.getFrameRect();
|
|
1700
|
+
if (!frame.width || !frame.height) return;
|
|
1701
|
+
|
|
1702
|
+
const center = target.getCenterPoint
|
|
1703
|
+
? target.getCenterPoint()
|
|
1704
|
+
: new Point(target.left ?? 0, target.top ?? 0);
|
|
1705
|
+
const centerScene = this.canvasService
|
|
1706
|
+
? this.canvasService.toScenePoint({ x: center.x, y: center.y })
|
|
1707
|
+
: { x: center.x, y: center.y };
|
|
1708
|
+
|
|
1709
|
+
const objectScale = Number.isFinite(target?.scaleX) ? target.scaleX : 1;
|
|
1710
|
+
const objectScaleScene = this.toSceneObjectScale(objectScale || 1);
|
|
1711
|
+
|
|
1712
|
+
const workingItem = this.workingItems.find((item) => item.id === id);
|
|
1713
|
+
const sourceKey = workingItem?.sourceUrl || workingItem?.url || "";
|
|
1714
|
+
const sourceSize = this.getSourceSize(sourceKey, target);
|
|
1715
|
+
const coverScale = this.getCoverScale(frame, sourceSize);
|
|
1716
|
+
|
|
1717
|
+
const updates: Partial<ImageItem> = {
|
|
1718
|
+
left: this.clampNormalized((centerScene.x - frame.left) / frame.width),
|
|
1719
|
+
top: this.clampNormalized((centerScene.y - frame.top) / frame.height),
|
|
1720
|
+
angle: Number.isFinite(target.angle) ? target.angle : 0,
|
|
1721
|
+
scale: Math.max(0.05, objectScaleScene / coverScale),
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
this.focusedImageId = id;
|
|
1725
|
+
this.updateImageInWorking(id, updates);
|
|
1726
|
+
};
|
|
1727
|
+
|
|
1728
|
+
private updateImageInWorking(id: string, updates: Partial<ImageItem>) {
|
|
1729
|
+
const index = this.workingItems.findIndex((item) => item.id === id);
|
|
1730
|
+
if (index < 0) return;
|
|
1731
|
+
|
|
1732
|
+
const next = [...this.workingItems];
|
|
1733
|
+
next[index] = this.normalizeItem({ ...next[index], ...updates });
|
|
1734
|
+
this.workingItems = next;
|
|
1735
|
+
this.hasWorkingChanges = true;
|
|
1736
|
+
this.setImageFocus(id, {
|
|
1737
|
+
syncCanvasSelection: false,
|
|
1738
|
+
skipRender: true,
|
|
1739
|
+
});
|
|
1740
|
+
if (this.isToolActive) {
|
|
1741
|
+
this.updateImages();
|
|
1742
|
+
}
|
|
1743
|
+
this.emitWorkingChange(id);
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
private async updateImageInConfig(id: string, updates: Partial<ImageItem>) {
|
|
1747
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
1748
|
+
if (index < 0) return;
|
|
1749
|
+
|
|
1750
|
+
const replacingSource =
|
|
1751
|
+
typeof updates.url === "string" && updates.url.length > 0;
|
|
1752
|
+
const next = [...this.items];
|
|
1753
|
+
const base = next[index];
|
|
1754
|
+
const replacingUrl = replacingSource ? (updates.url as string) : undefined;
|
|
1755
|
+
|
|
1756
|
+
next[index] = this.normalizeItem({
|
|
1757
|
+
...base,
|
|
1758
|
+
...updates,
|
|
1759
|
+
...(replacingSource
|
|
1760
|
+
? {
|
|
1761
|
+
url: replacingUrl,
|
|
1762
|
+
sourceUrl: replacingUrl,
|
|
1763
|
+
committedUrl: undefined,
|
|
1764
|
+
scale: updates.scale ?? 1,
|
|
1765
|
+
angle: updates.angle ?? 0,
|
|
1766
|
+
left: updates.left ?? 0.5,
|
|
1767
|
+
top: updates.top ?? 0.5,
|
|
1768
|
+
}
|
|
1769
|
+
: {}),
|
|
1770
|
+
});
|
|
1771
|
+
|
|
1772
|
+
this.updateConfig(next);
|
|
1773
|
+
|
|
1774
|
+
if (replacingSource) {
|
|
1775
|
+
this.debug("replace:image:begin", { id, replacingUrl });
|
|
1776
|
+
this.purgeSourceSizeCacheForItem(base);
|
|
1777
|
+
const loaded = await this.waitImageLoaded(id, true);
|
|
1778
|
+
this.debug("replace:image:loaded", { id, loaded });
|
|
1779
|
+
if (loaded) {
|
|
1780
|
+
await this.refitImageToFrame(id);
|
|
1781
|
+
this.setImageFocus(id);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
private waitImageLoaded(id: string, forceWait = false): Promise<boolean> {
|
|
1787
|
+
if (!forceWait && this.getImageObject(id)) {
|
|
1788
|
+
return Promise.resolve(true);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
return new Promise<boolean>((resolve) => {
|
|
1792
|
+
const timeout = setTimeout(() => {
|
|
1793
|
+
this.loadResolvers.delete(id);
|
|
1794
|
+
resolve(false);
|
|
1795
|
+
}, 4000);
|
|
1796
|
+
|
|
1797
|
+
this.loadResolvers.set(id, () => {
|
|
1798
|
+
clearTimeout(timeout);
|
|
1799
|
+
resolve(true);
|
|
1800
|
+
});
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
private async refitImageToFrame(id: string) {
|
|
1805
|
+
const obj = this.getImageObject(id);
|
|
1806
|
+
if (!obj || !this.canvasService) return;
|
|
1807
|
+
const current = this.items.find((item) => item.id === id);
|
|
1808
|
+
if (!current) return;
|
|
1809
|
+
const render = this.resolveRenderImageState(current);
|
|
1810
|
+
|
|
1811
|
+
this.rememberSourceSize(render.src, obj);
|
|
1812
|
+
const source = this.getSourceSize(render.src, obj);
|
|
1813
|
+
const frame = this.getFrameRect();
|
|
1814
|
+
const coverScale = this.getCoverScale(frame, source);
|
|
1815
|
+
|
|
1816
|
+
const currentScale = this.toSceneObjectScale(obj.scaleX || 1);
|
|
1817
|
+
const zoom = Math.max(0.05, currentScale / coverScale);
|
|
1818
|
+
|
|
1819
|
+
const updated: Partial<ImageItem> = {
|
|
1820
|
+
scale: Number.isFinite(zoom) ? zoom : 1,
|
|
1821
|
+
angle: 0,
|
|
1822
|
+
left: 0.5,
|
|
1823
|
+
top: 0.5,
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
1827
|
+
if (index < 0) return;
|
|
1828
|
+
|
|
1829
|
+
const next = [...this.items];
|
|
1830
|
+
next[index] = this.normalizeItem({ ...next[index], ...updated });
|
|
1831
|
+
this.updateConfig(next);
|
|
1832
|
+
this.workingItems = this.cloneItems(next);
|
|
1833
|
+
this.hasWorkingChanges = false;
|
|
1834
|
+
this.updateImages();
|
|
1835
|
+
this.emitWorkingChange(id);
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
private async fitImageToArea(
|
|
1839
|
+
id: string,
|
|
1840
|
+
area: { width: number; height: number; left?: number; top?: number },
|
|
1841
|
+
) {
|
|
1842
|
+
if (!this.canvasService) return;
|
|
1843
|
+
|
|
1844
|
+
const loaded = await this.waitImageLoaded(id, false);
|
|
1845
|
+
if (!loaded) return;
|
|
1846
|
+
|
|
1847
|
+
const obj = this.getImageObject(id);
|
|
1848
|
+
if (!obj) return;
|
|
1849
|
+
const renderItems = this.isToolActive ? this.workingItems : this.items;
|
|
1850
|
+
const current = renderItems.find((item) => item.id === id);
|
|
1851
|
+
if (!current) return;
|
|
1852
|
+
const render = this.resolveRenderImageState(current);
|
|
1853
|
+
|
|
1854
|
+
this.rememberSourceSize(render.src, obj);
|
|
1855
|
+
const source = this.getSourceSize(render.src, obj);
|
|
1856
|
+
const frame = this.getFrameRect();
|
|
1857
|
+
const baseCover = this.getCoverScale(frame, source);
|
|
1858
|
+
|
|
1859
|
+
const desiredScale = Math.max(
|
|
1860
|
+
Math.max(1, area.width) / Math.max(1, source.width),
|
|
1861
|
+
Math.max(1, area.height) / Math.max(1, source.height),
|
|
1862
|
+
);
|
|
1863
|
+
|
|
1864
|
+
const viewport = this.canvasService.getSceneViewportRect();
|
|
1865
|
+
const canvasW = viewport.width || 1;
|
|
1866
|
+
const canvasH = viewport.height || 1;
|
|
1867
|
+
|
|
1868
|
+
const areaLeftInput = area.left ?? 0.5;
|
|
1869
|
+
const areaTopInput = area.top ?? 0.5;
|
|
1870
|
+
|
|
1871
|
+
const areaLeftPx =
|
|
1872
|
+
areaLeftInput <= 1.5
|
|
1873
|
+
? viewport.left + areaLeftInput * canvasW
|
|
1874
|
+
: areaLeftInput;
|
|
1875
|
+
const areaTopPx =
|
|
1876
|
+
areaTopInput <= 1.5
|
|
1877
|
+
? viewport.top + areaTopInput * canvasH
|
|
1878
|
+
: areaTopInput;
|
|
1879
|
+
|
|
1880
|
+
const updates: Partial<ImageItem> = {
|
|
1881
|
+
scale: Math.max(0.05, desiredScale / baseCover),
|
|
1882
|
+
left: this.clampNormalized(
|
|
1883
|
+
(areaLeftPx - frame.left) / Math.max(1, frame.width),
|
|
1884
|
+
),
|
|
1885
|
+
top: this.clampNormalized(
|
|
1886
|
+
(areaTopPx - frame.top) / Math.max(1, frame.height),
|
|
1887
|
+
),
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1890
|
+
if (this.isToolActive) {
|
|
1891
|
+
this.updateImageInWorking(id, updates);
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
await this.updateImageInConfig(id, updates);
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
private async commitWorkingImagesAsCropped() {
|
|
1899
|
+
if (!this.canvasService) {
|
|
1900
|
+
return { ok: false, reason: "canvas-not-ready" };
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
await this.updateImagesAsync();
|
|
1904
|
+
|
|
1905
|
+
const frame = this.getFrameRect();
|
|
1906
|
+
if (!frame.width || !frame.height) {
|
|
1907
|
+
return { ok: false, reason: "frame-not-ready" };
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
const next: ImageItem[] = [];
|
|
1911
|
+
for (const item of this.workingItems) {
|
|
1912
|
+
const exported = await this.exportCroppedImageByIds([item.id], {
|
|
1913
|
+
multiplier: 2,
|
|
1914
|
+
format: "png",
|
|
1915
|
+
});
|
|
1916
|
+
const url = exported.url;
|
|
1917
|
+
|
|
1918
|
+
const sourceUrl = item.sourceUrl || item.url;
|
|
1919
|
+
const previousCommitted = item.committedUrl;
|
|
1920
|
+
next.push(
|
|
1921
|
+
this.normalizeItem({
|
|
1922
|
+
...item,
|
|
1923
|
+
url,
|
|
1924
|
+
// Keep original source for next image-tool session editing,
|
|
1925
|
+
// and use committedUrl as non-image-tools render source.
|
|
1926
|
+
sourceUrl,
|
|
1927
|
+
committedUrl: url,
|
|
1928
|
+
}),
|
|
1929
|
+
);
|
|
1930
|
+
if (previousCommitted && previousCommitted !== url) {
|
|
1931
|
+
this.sourceSizeBySrc.delete(previousCommitted);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
this.hasWorkingChanges = false;
|
|
1936
|
+
this.workingItems = this.cloneItems(next);
|
|
1937
|
+
this.updateConfig(next);
|
|
1938
|
+
this.emitWorkingChange(this.focusedImageId);
|
|
1939
|
+
return { ok: true };
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
private async exportCroppedImageByIds(
|
|
1943
|
+
imageIds: string[],
|
|
1944
|
+
options: ExportCroppedImageOptions,
|
|
1945
|
+
): Promise<ExportUserCroppedImageResult> {
|
|
1946
|
+
if (!this.canvasService) {
|
|
1947
|
+
throw new Error("CanvasService not initialized");
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
const normalizedIds = [...new Set(imageIds)].filter(
|
|
1951
|
+
(id): id is string => typeof id === "string" && id.length > 0,
|
|
1952
|
+
);
|
|
1953
|
+
if (!normalizedIds.length) {
|
|
1954
|
+
throw new Error("image-ids-required");
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
const frameScene = this.getFrameRect();
|
|
1958
|
+
const frame = this.getFrameRectScreen(frameScene);
|
|
1959
|
+
const multiplier = Math.max(1, options.multiplier ?? 2);
|
|
1960
|
+
const format: "png" | "jpeg" = options.format === "jpeg" ? "jpeg" : "png";
|
|
1961
|
+
|
|
1962
|
+
const width = Math.max(1, Math.round(frame.width * multiplier));
|
|
1963
|
+
const height = Math.max(1, Math.round(frame.height * multiplier));
|
|
1964
|
+
|
|
1965
|
+
const el = document.createElement("canvas");
|
|
1966
|
+
const tempCanvas = new FabricCanvas(el, {
|
|
1967
|
+
renderOnAddRemove: false,
|
|
1968
|
+
selection: false,
|
|
1969
|
+
enableRetinaScaling: false,
|
|
1970
|
+
preserveObjectStacking: true,
|
|
1971
|
+
} as any);
|
|
1972
|
+
tempCanvas.setDimensions({ width, height });
|
|
1973
|
+
|
|
1974
|
+
try {
|
|
1975
|
+
const idSet = new Set(normalizedIds);
|
|
1976
|
+
const sourceObjects = this.canvasService.canvas
|
|
1977
|
+
.getObjects()
|
|
1978
|
+
.filter((obj: any) => {
|
|
1979
|
+
return (
|
|
1980
|
+
obj?.data?.layerId === IMAGE_OBJECT_LAYER_ID &&
|
|
1981
|
+
typeof obj?.data?.id === "string" &&
|
|
1982
|
+
idSet.has(obj.data.id)
|
|
1983
|
+
);
|
|
1984
|
+
});
|
|
1985
|
+
|
|
1986
|
+
if (!sourceObjects.length) {
|
|
1987
|
+
throw new Error("image-objects-not-found");
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
for (const source of sourceObjects as any[]) {
|
|
1991
|
+
const clone = await source.clone();
|
|
1992
|
+
const center = source.getCenterPoint
|
|
1993
|
+
? source.getCenterPoint()
|
|
1994
|
+
: new Point(source.left ?? 0, source.top ?? 0);
|
|
1995
|
+
|
|
1996
|
+
clone.set({
|
|
1997
|
+
originX: "center",
|
|
1998
|
+
originY: "center",
|
|
1999
|
+
left: (center.x - frame.left) * multiplier,
|
|
2000
|
+
top: (center.y - frame.top) * multiplier,
|
|
2001
|
+
scaleX: (source.scaleX || 1) * multiplier,
|
|
2002
|
+
scaleY: (source.scaleY || 1) * multiplier,
|
|
2003
|
+
angle: source.angle || 0,
|
|
2004
|
+
selectable: false,
|
|
2005
|
+
evented: false,
|
|
2006
|
+
});
|
|
2007
|
+
clone.setCoords();
|
|
2008
|
+
tempCanvas.add(clone);
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
tempCanvas.renderAll();
|
|
2012
|
+
const blob = await tempCanvas.toBlob({ format, multiplier: 1 });
|
|
2013
|
+
if (!blob) {
|
|
2014
|
+
throw new Error("image-export-failed");
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
return {
|
|
2018
|
+
url: URL.createObjectURL(blob),
|
|
2019
|
+
width,
|
|
2020
|
+
height,
|
|
2021
|
+
multiplier,
|
|
2022
|
+
format,
|
|
2023
|
+
imageIds: (sourceObjects as any[])
|
|
2024
|
+
.map((obj: any) => obj?.data?.id)
|
|
2025
|
+
.filter((id: any): id is string => typeof id === "string"),
|
|
2026
|
+
};
|
|
2027
|
+
} finally {
|
|
2028
|
+
tempCanvas.dispose();
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
private async exportUserCroppedImage(
|
|
2033
|
+
options: ExportUserCroppedImageOptions = {},
|
|
2034
|
+
): Promise<ExportUserCroppedImageResult> {
|
|
2035
|
+
if (!this.canvasService) {
|
|
2036
|
+
throw new Error("CanvasService not initialized");
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
await this.updateImagesAsync();
|
|
2040
|
+
this.syncToolActiveFromWorkbench();
|
|
2041
|
+
|
|
2042
|
+
const imageIds =
|
|
2043
|
+
options.imageIds && options.imageIds.length > 0
|
|
2044
|
+
? options.imageIds
|
|
2045
|
+
: (this.isToolActive ? this.workingItems : this.items).map(
|
|
2046
|
+
(item) => item.id,
|
|
2047
|
+
);
|
|
2048
|
+
if (!imageIds.length) {
|
|
2049
|
+
throw new Error("no-images-to-export");
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
return await this.exportCroppedImageByIds(imageIds, options);
|
|
2053
|
+
}
|
|
2054
|
+
}
|