@pooder/kit 5.0.4 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/index.d.mts +239 -267
  3. package/dist/index.d.ts +239 -267
  4. package/dist/index.js +6603 -5936
  5. package/dist/index.mjs +6670 -5991
  6. package/package.json +2 -2
  7. package/src/{background.ts → extensions/background.ts} +1 -1
  8. package/src/{dieline.ts → extensions/dieline.ts} +39 -17
  9. package/src/{feature.ts → extensions/feature.ts} +80 -67
  10. package/src/{film.ts → extensions/film.ts} +1 -1
  11. package/src/{geometry.ts → extensions/geometry.ts} +151 -105
  12. package/src/{image.ts → extensions/image.ts} +97 -84
  13. package/src/extensions/index.ts +11 -0
  14. package/src/{maskOps.ts → extensions/maskOps.ts} +28 -10
  15. package/src/{mirror.ts → extensions/mirror.ts} +1 -1
  16. package/src/{ruler.ts → extensions/ruler.ts} +5 -3
  17. package/src/extensions/sceneLayout.ts +140 -0
  18. package/src/{sceneLayoutModel.ts → extensions/sceneLayoutModel.ts} +17 -10
  19. package/src/extensions/sceneVisibility.ts +71 -0
  20. package/src/{size.ts → extensions/size.ts} +23 -13
  21. package/src/{tracer.ts → extensions/tracer.ts} +374 -45
  22. package/src/{white-ink.ts → extensions/white-ink.ts} +620 -236
  23. package/src/index.ts +2 -14
  24. package/src/{ViewportSystem.ts → services/ViewportSystem.ts} +5 -2
  25. package/src/services/index.ts +3 -0
  26. package/src/sceneLayout.ts +0 -121
  27. package/src/sceneVisibility.ts +0 -49
  28. /package/src/{bridgeSelection.ts → extensions/bridgeSelection.ts} +0 -0
  29. /package/src/{constraints.ts → extensions/constraints.ts} +0 -0
  30. /package/src/{edgeScale.ts → extensions/edgeScale.ts} +0 -0
  31. /package/src/{featureComplete.ts → extensions/featureComplete.ts} +0 -0
  32. /package/src/{wrappedOffsets.ts → extensions/wrappedOffsets.ts} +0 -0
  33. /package/src/{CanvasService.ts → services/CanvasService.ts} +0 -0
  34. /package/src/{renderSpec.ts → services/renderSpec.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @pooder/kit
2
2
 
3
+ ## 5.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - service
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @pooder/core@2.2.0
13
+
3
14
  ## 5.0.4
4
15
 
5
16
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Extension, ExtensionContext, ContributionPointIds, ConfigurationContribution, CommandContribution, Service, EventBus, ConfigurationService } from '@pooder/core';
1
+ import { Extension, ExtensionContext, ContributionPointIds, ConfigurationContribution, CommandContribution, Service, EventBus, ServiceContext } from '@pooder/core';
2
2
  import { Canvas, Group, FabricObject } from 'fabric';
3
3
 
4
4
  declare class BackgroundTool implements Extension {
@@ -23,6 +23,137 @@ declare class BackgroundTool implements Extension {
23
23
  private updateBackground;
24
24
  }
25
25
 
26
+ interface ImageItem {
27
+ id: string;
28
+ url: string;
29
+ opacity: number;
30
+ scale?: number;
31
+ angle?: number;
32
+ left?: number;
33
+ top?: number;
34
+ sourceUrl?: string;
35
+ committedUrl?: string;
36
+ }
37
+ declare class ImageTool implements Extension {
38
+ id: string;
39
+ metadata: {
40
+ name: string;
41
+ };
42
+ private items;
43
+ private workingItems;
44
+ private hasWorkingChanges;
45
+ private loadResolvers;
46
+ private sourceSizeBySrc;
47
+ private canvasService?;
48
+ private context?;
49
+ private isUpdatingConfig;
50
+ private isToolActive;
51
+ private isImageSelectionActive;
52
+ private focusedImageId;
53
+ private renderSeq;
54
+ private dirtyTrackerDisposable?;
55
+ activate(context: ExtensionContext): void;
56
+ deactivate(context: ExtensionContext): void;
57
+ private onToolActivated;
58
+ private onSelectionChanged;
59
+ private onSelectionCleared;
60
+ private onSceneLayoutChanged;
61
+ private syncToolActiveFromWorkbench;
62
+ private isImageEditingVisible;
63
+ private isDebugEnabled;
64
+ private debug;
65
+ contribute(): {
66
+ [ContributionPointIds.TOOLS]: {
67
+ id: string;
68
+ name: string;
69
+ interaction: string;
70
+ commands: {
71
+ begin: string;
72
+ commit: string;
73
+ rollback: string;
74
+ };
75
+ session: {
76
+ autoBegin: boolean;
77
+ leavePolicy: string;
78
+ };
79
+ }[];
80
+ [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
81
+ [ContributionPointIds.COMMANDS]: CommandContribution[];
82
+ };
83
+ private normalizeItem;
84
+ private normalizeItems;
85
+ private cloneItems;
86
+ private emitWorkingChange;
87
+ private generateId;
88
+ private hasImageItem;
89
+ private setImageFocus;
90
+ private addImageEntry;
91
+ private upsertImageEntry;
92
+ private addItemToWorkingSessionIfNeeded;
93
+ private updateImage;
94
+ private getConfig;
95
+ private updateConfig;
96
+ private getFrameRect;
97
+ private resolveDefaultFitArea;
98
+ private fitImageToDefaultArea;
99
+ private getImageObjects;
100
+ private getOverlayObjects;
101
+ private getImageObject;
102
+ private clearRenderedImages;
103
+ private purgeSourceSizeCacheForItem;
104
+ private rememberSourceSize;
105
+ private getSourceSize;
106
+ private getCoverScale;
107
+ private getFrameVisualConfig;
108
+ private resolveRenderImageState;
109
+ private computeCanvasProps;
110
+ private getCurrentSrc;
111
+ private upsertImageObject;
112
+ private syncImageZOrder;
113
+ private buildOverlaySpecs;
114
+ private updateImages;
115
+ private updateImagesAsync;
116
+ private clampNormalized;
117
+ private onObjectModified;
118
+ private updateImageInWorking;
119
+ private updateImageInConfig;
120
+ private waitImageLoaded;
121
+ private refitImageToFrame;
122
+ private fitImageToArea;
123
+ private commitWorkingImagesAsCropped;
124
+ private exportCroppedImageByIds;
125
+ private exportUserCroppedImage;
126
+ }
127
+
128
+ declare class SizeTool implements Extension {
129
+ id: string;
130
+ metadata: {
131
+ name: string;
132
+ };
133
+ private context?;
134
+ private canvasService?;
135
+ activate(context: ExtensionContext): void;
136
+ deactivate(_context: ExtensionContext): void;
137
+ contribute(): {
138
+ [ContributionPointIds.TOOLS]: {
139
+ id: string;
140
+ name: string;
141
+ interaction: string;
142
+ }[];
143
+ [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
144
+ [ContributionPointIds.COMMANDS]: CommandContribution[];
145
+ };
146
+ private getConfigService;
147
+ private ensureDefaults;
148
+ private emitStateChanged;
149
+ private getStateForUI;
150
+ private updateDimensions;
151
+ private setConstraintMode;
152
+ private setUnit;
153
+ private setCut;
154
+ private getSelectedImageSize;
155
+ }
156
+
26
157
  interface Point {
27
158
  x: number;
28
159
  y: number;
@@ -138,28 +269,6 @@ declare class DielineTool implements Extension {
138
269
  }): Promise<string | null>;
139
270
  }
140
271
 
141
- declare class FilmTool implements Extension {
142
- id: string;
143
- metadata: {
144
- name: string;
145
- };
146
- private url;
147
- private opacity;
148
- private canvasService?;
149
- constructor(options?: Partial<{
150
- url: string;
151
- opacity: number;
152
- }>);
153
- activate(context: ExtensionContext): void;
154
- deactivate(context: ExtensionContext): void;
155
- contribute(): {
156
- [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
157
- [ContributionPointIds.COMMANDS]: CommandContribution[];
158
- };
159
- private initLayer;
160
- private updateFilm;
161
- }
162
-
163
272
  interface ConstraintFeature extends DielineFeature {
164
273
  constraints?: Array<{
165
274
  type: string;
@@ -233,106 +342,83 @@ declare class FeatureTool implements Extension {
233
342
  private enforceConstraints;
234
343
  }
235
344
 
236
- interface ImageItem {
345
+ declare class FilmTool implements Extension {
237
346
  id: string;
238
- url: string;
239
- opacity: number;
240
- scale?: number;
241
- angle?: number;
242
- left?: number;
243
- top?: number;
244
- sourceUrl?: string;
245
- committedUrl?: string;
347
+ metadata: {
348
+ name: string;
349
+ };
350
+ private url;
351
+ private opacity;
352
+ private canvasService?;
353
+ constructor(options?: Partial<{
354
+ url: string;
355
+ opacity: number;
356
+ }>);
357
+ activate(context: ExtensionContext): void;
358
+ deactivate(context: ExtensionContext): void;
359
+ contribute(): {
360
+ [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
361
+ [ContributionPointIds.COMMANDS]: CommandContribution[];
362
+ };
363
+ private initLayer;
364
+ private updateFilm;
246
365
  }
247
- declare class ImageTool implements Extension {
366
+
367
+ declare class MirrorTool implements Extension {
248
368
  id: string;
249
369
  metadata: {
250
370
  name: string;
251
371
  };
252
- private items;
253
- private workingItems;
254
- private hasWorkingChanges;
255
- private loadResolvers;
256
- private sourceSizeBySrc;
372
+ private enabled;
373
+ private canvasService?;
374
+ constructor(options?: Partial<{
375
+ enabled: boolean;
376
+ }>);
377
+ toJSON(): {
378
+ enabled: boolean;
379
+ };
380
+ loadFromJSON(json: any): void;
381
+ activate(context: ExtensionContext): void;
382
+ deactivate(context: ExtensionContext): void;
383
+ contribute(): {
384
+ [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
385
+ [ContributionPointIds.COMMANDS]: CommandContribution[];
386
+ };
387
+ private applyMirror;
388
+ }
389
+
390
+ declare class RulerTool implements Extension {
391
+ id: string;
392
+ metadata: {
393
+ name: string;
394
+ };
395
+ private thickness;
396
+ private gap;
397
+ private backgroundColor;
398
+ private textColor;
399
+ private lineColor;
400
+ private fontSize;
257
401
  private canvasService?;
258
402
  private context?;
259
- private isUpdatingConfig;
260
- private isToolActive;
261
- private isImageSelectionActive;
262
- private focusedImageId;
263
- private renderSeq;
264
- private dirtyTrackerDisposable?;
403
+ private onCanvasResized;
404
+ constructor(options?: Partial<{
405
+ thickness: number;
406
+ backgroundColor: string;
407
+ textColor: string;
408
+ lineColor: string;
409
+ fontSize: number;
410
+ }>);
265
411
  activate(context: ExtensionContext): void;
266
412
  deactivate(context: ExtensionContext): void;
267
- private onToolActivated;
268
- private onSelectionChanged;
269
- private onSelectionCleared;
270
- private onSceneLayoutChanged;
271
- private syncToolActiveFromWorkbench;
272
- private isImageEditingVisible;
273
- private isDebugEnabled;
274
- private debug;
275
413
  contribute(): {
276
- [ContributionPointIds.TOOLS]: {
277
- id: string;
278
- name: string;
279
- interaction: string;
280
- commands: {
281
- begin: string;
282
- commit: string;
283
- rollback: string;
284
- };
285
- session: {
286
- autoBegin: boolean;
287
- leavePolicy: string;
288
- };
289
- }[];
290
414
  [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
291
415
  [ContributionPointIds.COMMANDS]: CommandContribution[];
292
416
  };
293
- private normalizeItem;
294
- private normalizeItems;
295
- private cloneItems;
296
- private emitWorkingChange;
297
- private generateId;
298
- private hasImageItem;
299
- private setImageFocus;
300
- private addImageEntry;
301
- private upsertImageEntry;
302
- private addItemToWorkingSessionIfNeeded;
303
- private updateImage;
304
- private getConfig;
305
- private updateConfig;
306
- private getFrameRect;
307
- private resolveDefaultFitArea;
308
- private fitImageToDefaultArea;
309
- private getImageObjects;
310
- private getOverlayObjects;
311
- private getImageObject;
312
- private clearRenderedImages;
313
- private purgeSourceSizeCacheForItem;
314
- private rememberSourceSize;
315
- private getSourceSize;
316
- private getCoverScale;
317
- private getFrameVisualConfig;
318
- private resolveRenderImageState;
319
- private computeCanvasProps;
320
- private getCurrentSrc;
321
- private upsertImageObject;
322
- private syncImageZOrder;
323
- private buildOverlaySpecs;
324
- private updateImages;
325
- private updateImagesAsync;
326
- private clampNormalized;
327
- private onObjectModified;
328
- private updateImageInWorking;
329
- private updateImageInConfig;
330
- private waitImageLoaded;
331
- private refitImageToFrame;
332
- private fitImageToArea;
333
- private commitWorkingImagesAsCropped;
334
- private exportCroppedImageByIds;
335
- private exportImageFrameUrl;
417
+ private getLayer;
418
+ private createLayer;
419
+ private destroyLayer;
420
+ private createArrowLine;
421
+ private updateRuler;
336
422
  }
337
423
 
338
424
  interface WhiteInkItem {
@@ -383,16 +469,19 @@ declare class WhiteInkTool implements Extension {
383
469
  private onToolActivated;
384
470
  private onSceneLayoutChanged;
385
471
  private onObjectAdded;
472
+ private onObjectModified;
473
+ private onObjectRemoved;
474
+ private onImageWorkingChanged;
386
475
  private migrateLegacyConfigIfNeeded;
387
476
  private syncToolActiveFromWorkbench;
388
477
  private isPreviewActive;
389
478
  private isDebugEnabled;
390
479
  private debug;
391
480
  private resolveSourceUrl;
392
- private clampOpacity;
393
481
  private normalizeItem;
394
482
  private normalizeItems;
395
483
  private cloneItems;
484
+ private getEffectiveWhiteInkItem;
396
485
  private generateId;
397
486
  private getConfig;
398
487
  private resolveReplaceTargetId;
@@ -407,134 +496,34 @@ declare class WhiteInkTool implements Extension {
407
496
  private clearWhiteInks;
408
497
  private completeWhiteInks;
409
498
  private getFrameRect;
410
- private getWhiteInkObjects;
411
- private getWhiteInkObject;
412
- private clearRenderedWhiteInks;
413
- private purgeSourceCaches;
499
+ private getImageObjects;
500
+ private getPrimaryImageObject;
501
+ private getPrimaryImageSource;
502
+ private getCurrentSrc;
503
+ private getImageSnapshot;
504
+ private getImageElementFromObject;
414
505
  private rememberSourceSize;
415
506
  private getSourceSize;
416
- private getCoverScale;
417
- private resolveRenderState;
418
- private computeCanvasProps;
419
- private getCurrentSrc;
420
- private upsertWhiteInkObject;
507
+ private computeWhiteScaleAdjust;
508
+ private computeCoverOpacity;
509
+ private buildCloneImageSpec;
510
+ private buildFrameSpecs;
511
+ private applyImageVisibilityForWhiteInk;
512
+ private resolveRenderItems;
513
+ private resolveRenderSources;
514
+ private resolveDefaultInsertIndex;
421
515
  private syncZOrder;
422
- private applyImagePreviewVisibility;
516
+ private clearRenderedWhiteInks;
517
+ private purgeSourceCaches;
423
518
  private updateWhiteInks;
424
519
  private updateWhiteInksAsync;
520
+ private getMaskCacheKey;
425
521
  private getPreviewMaskSource;
522
+ private getElementSize;
426
523
  private createOpaqueMaskSource;
427
524
  private loadImageElement;
428
525
  }
429
526
 
430
- declare class RulerTool implements Extension {
431
- id: string;
432
- metadata: {
433
- name: string;
434
- };
435
- private thickness;
436
- private gap;
437
- private backgroundColor;
438
- private textColor;
439
- private lineColor;
440
- private fontSize;
441
- private canvasService?;
442
- private context?;
443
- private onCanvasResized;
444
- constructor(options?: Partial<{
445
- thickness: number;
446
- backgroundColor: string;
447
- textColor: string;
448
- lineColor: string;
449
- fontSize: number;
450
- }>);
451
- activate(context: ExtensionContext): void;
452
- deactivate(context: ExtensionContext): void;
453
- contribute(): {
454
- [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
455
- [ContributionPointIds.COMMANDS]: CommandContribution[];
456
- };
457
- private getLayer;
458
- private createLayer;
459
- private destroyLayer;
460
- private createArrowLine;
461
- private updateRuler;
462
- }
463
-
464
- declare class MirrorTool implements Extension {
465
- id: string;
466
- metadata: {
467
- name: string;
468
- };
469
- private enabled;
470
- private canvasService?;
471
- constructor(options?: Partial<{
472
- enabled: boolean;
473
- }>);
474
- toJSON(): {
475
- enabled: boolean;
476
- };
477
- loadFromJSON(json: any): void;
478
- activate(context: ExtensionContext): void;
479
- deactivate(context: ExtensionContext): void;
480
- contribute(): {
481
- [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
482
- [ContributionPointIds.COMMANDS]: CommandContribution[];
483
- };
484
- private applyMirror;
485
- }
486
-
487
- declare class SizeTool implements Extension {
488
- id: string;
489
- metadata: {
490
- name: string;
491
- };
492
- private context?;
493
- private canvasService?;
494
- activate(context: ExtensionContext): void;
495
- deactivate(_context: ExtensionContext): void;
496
- contribute(): {
497
- [ContributionPointIds.TOOLS]: {
498
- id: string;
499
- name: string;
500
- interaction: string;
501
- }[];
502
- [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
503
- [ContributionPointIds.COMMANDS]: CommandContribution[];
504
- };
505
- private getConfigService;
506
- private ensureDefaults;
507
- private emitStateChanged;
508
- private getStateForUI;
509
- private updateDimensions;
510
- private setConstraintMode;
511
- private setUnit;
512
- private setCut;
513
- private getSelectedImageSize;
514
- }
515
-
516
- declare class SceneLayoutService implements Extension {
517
- id: string;
518
- metadata: {
519
- name: string;
520
- };
521
- private context?;
522
- private canvasService?;
523
- private configService?;
524
- private lastLayout;
525
- private lastGeometry;
526
- private onConfigChange?;
527
- activate(context: ExtensionContext): void;
528
- deactivate(context: ExtensionContext): void;
529
- contribute(): {
530
- [ContributionPointIds.COMMANDS]: CommandContribution[];
531
- };
532
- private onCanvasResized;
533
- private refresh;
534
- private getLayout;
535
- private getGeometry;
536
- }
537
-
538
527
  declare class ViewportSystem {
539
528
  private _containerSize;
540
529
  private _physicalSize;
@@ -602,21 +591,7 @@ declare class CanvasService implements Service {
602
591
  private createFabricObject;
603
592
  }
604
593
 
605
- type SizeConstraintMode = "free" | "lockAspect" | "equal";
606
594
  type CutMode = "trim" | "outset" | "inset";
607
- interface SizeState {
608
- unit: Unit;
609
- actualWidthMm: number;
610
- actualHeightMm: number;
611
- constraintMode: SizeConstraintMode;
612
- aspectRatio: number;
613
- cutMode: CutMode;
614
- cutMarginMm: number;
615
- viewPadding: number | string;
616
- minMm: number;
617
- maxMm: number;
618
- stepMm: number;
619
- }
620
595
  interface SceneRect {
621
596
  left: number;
622
597
  top: number;
@@ -652,36 +627,33 @@ interface SceneGeometrySnapshot {
652
627
  scale: number;
653
628
  pathData?: string;
654
629
  }
655
- declare function sanitizeMmValue(valueMm: number, limits: {
656
- minMm: number;
657
- maxMm: number;
658
- stepMm: number;
659
- }): number;
660
- declare function normalizeUnit(value: unknown): Unit;
661
- declare function normalizeConstraintMode(value: unknown): SizeConstraintMode;
662
- declare function normalizeCutMode(value: unknown): CutMode;
663
- declare function toMm(value: number, fromUnit: Unit): number;
664
- declare function fromMm(valueMm: number, toUnit: Unit): number;
665
- declare function resolvePaddingPx(raw: number | string, containerWidth: number, containerHeight: number): number;
666
- declare function readSizeState(configService: ConfigurationService): SizeState;
667
- declare function computeSceneLayout(canvasService: CanvasService, size: SizeState): SceneLayoutSnapshot | null;
668
- declare function buildSceneGeometry(configService: ConfigurationService, layout: SceneLayoutSnapshot): SceneGeometrySnapshot;
669
630
 
670
- declare class SceneVisibilityService implements Extension {
671
- id: string;
672
- metadata: {
673
- name: string;
674
- };
631
+ declare class SceneLayoutService implements Service {
632
+ private context?;
675
633
  private canvasService?;
634
+ private configService?;
635
+ private lastLayout;
636
+ private lastGeometry;
637
+ private onConfigChange?;
638
+ private commandDisposables;
639
+ init(context: ServiceContext): void;
640
+ dispose(context: ServiceContext): void;
641
+ private onCanvasResized;
642
+ private onConfigChanged;
643
+ private refresh;
644
+ getLayout(forceRefresh?: boolean): SceneLayoutSnapshot | null;
645
+ getGeometry(forceRefresh?: boolean): SceneGeometrySnapshot | null;
646
+ }
647
+
648
+ declare class SceneVisibilityService implements Service {
649
+ private context?;
676
650
  private activeToolId;
677
- activate(context: ExtensionContext): void;
678
- deactivate(context: ExtensionContext): void;
651
+ private canvasService?;
652
+ init(context: ServiceContext): void;
653
+ dispose(context: ServiceContext): void;
679
654
  private onToolActivated;
680
655
  private onObjectAdded;
681
656
  private apply;
682
657
  }
683
658
 
684
- declare function parseLengthToMm(input: number | string, defaultUnit: Unit): number;
685
- declare function formatMm(valueMm: number, displayUnit: Unit, fractionDigits?: number): string;
686
-
687
- export { BackgroundTool, CanvasService, type CutMode, type DielineGeometry, type DielineState, DielineTool, FeatureTool, FilmTool, type ImageItem, ImageTool, type LineStyle, MirrorTool, RulerTool, type SceneGeometrySnapshot, SceneLayoutService, type SceneLayoutSnapshot, type SceneRect, SceneVisibilityService, type SizeConstraintMode, type SizeState, SizeTool, type WhiteInkItem, WhiteInkTool, buildSceneGeometry, computeSceneLayout, formatMm, fromMm, normalizeConstraintMode, normalizeCutMode, normalizeUnit, parseLengthToMm, readSizeState, resolvePaddingPx, sanitizeMmValue, toMm };
659
+ export { BackgroundTool, CanvasService, type DielineGeometry, type DielineState, DielineTool, FeatureTool, FilmTool, type ImageItem, ImageTool, type LineStyle, MirrorTool, type RenderLayerSpec, type RenderObjectSpec, type RenderObjectType, type RenderProps, RulerTool, SceneLayoutService, SceneVisibilityService, SizeTool, ViewportSystem, type WhiteInkItem, WhiteInkTool };