@pooder/kit 4.3.1 → 5.0.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 (60) hide show
  1. package/.test-dist/src/CanvasService.js +249 -0
  2. package/.test-dist/src/ViewportSystem.js +75 -0
  3. package/.test-dist/src/background.js +203 -0
  4. package/.test-dist/src/bridgeSelection.js +20 -0
  5. package/.test-dist/src/constraints.js +237 -0
  6. package/.test-dist/src/coordinate.js +74 -0
  7. package/.test-dist/src/dieline.js +723 -0
  8. package/.test-dist/src/edgeScale.js +12 -0
  9. package/.test-dist/src/feature.js +752 -0
  10. package/.test-dist/src/featureComplete.js +32 -0
  11. package/.test-dist/src/film.js +167 -0
  12. package/.test-dist/src/geometry.js +506 -0
  13. package/.test-dist/src/image.js +1234 -0
  14. package/.test-dist/src/index.js +35 -0
  15. package/.test-dist/src/maskOps.js +270 -0
  16. package/.test-dist/src/mirror.js +104 -0
  17. package/.test-dist/src/renderSpec.js +2 -0
  18. package/.test-dist/src/ruler.js +343 -0
  19. package/.test-dist/src/sceneLayout.js +99 -0
  20. package/.test-dist/src/sceneLayoutModel.js +196 -0
  21. package/.test-dist/src/sceneView.js +40 -0
  22. package/.test-dist/src/sceneVisibility.js +42 -0
  23. package/.test-dist/src/size.js +332 -0
  24. package/.test-dist/src/tracer.js +544 -0
  25. package/.test-dist/src/units.js +30 -0
  26. package/.test-dist/src/white-ink.js +829 -0
  27. package/.test-dist/src/wrappedOffsets.js +33 -0
  28. package/.test-dist/tests/run.js +94 -0
  29. package/CHANGELOG.md +11 -0
  30. package/dist/index.d.mts +339 -36
  31. package/dist/index.d.ts +339 -36
  32. package/dist/index.js +3572 -850
  33. package/dist/index.mjs +3565 -852
  34. package/package.json +2 -2
  35. package/src/CanvasService.ts +300 -96
  36. package/src/ViewportSystem.ts +92 -92
  37. package/src/background.ts +230 -230
  38. package/src/bridgeSelection.ts +17 -0
  39. package/src/coordinate.ts +106 -106
  40. package/src/dieline.ts +897 -973
  41. package/src/edgeScale.ts +19 -0
  42. package/src/feature.ts +83 -30
  43. package/src/film.ts +194 -194
  44. package/src/geometry.ts +242 -84
  45. package/src/image.ts +1582 -512
  46. package/src/index.ts +14 -10
  47. package/src/maskOps.ts +326 -0
  48. package/src/mirror.ts +128 -128
  49. package/src/renderSpec.ts +18 -0
  50. package/src/ruler.ts +449 -508
  51. package/src/sceneLayout.ts +121 -0
  52. package/src/sceneLayoutModel.ts +335 -0
  53. package/src/sceneVisibility.ts +49 -0
  54. package/src/size.ts +379 -0
  55. package/src/tracer.ts +719 -570
  56. package/src/units.ts +27 -27
  57. package/src/white-ink.ts +1018 -373
  58. package/src/wrappedOffsets.ts +33 -0
  59. package/tests/run.ts +118 -0
  60. package/tsconfig.test.json +15 -15
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Extension, ExtensionContext, ContributionPointIds, ConfigurationContribution, CommandContribution, Service, EventBus } from '@pooder/core';
1
+ import { Extension, ExtensionContext, ContributionPointIds, ConfigurationContribution, CommandContribution, Service, EventBus, ConfigurationService } from '@pooder/core';
2
2
  import { Canvas, Group, FabricObject } from 'fabric';
3
3
 
4
4
  declare class BackgroundTool implements Extension {
@@ -107,10 +107,20 @@ declare class DielineTool implements Extension {
107
107
  private state;
108
108
  private canvasService?;
109
109
  private context?;
110
+ private onCanvasResized;
110
111
  constructor(options?: Partial<DielineState>);
111
112
  activate(context: ExtensionContext): void;
112
113
  deactivate(context: ExtensionContext): void;
113
114
  contribute(): {
115
+ [ContributionPointIds.TOOLS]: {
116
+ id: string;
117
+ name: string;
118
+ interaction: string;
119
+ session: {
120
+ autoBegin: boolean;
121
+ leavePolicy: string;
122
+ };
123
+ }[];
114
124
  [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
115
125
  [ContributionPointIds.COMMANDS]: CommandContribution[];
116
126
  };
@@ -118,8 +128,10 @@ declare class DielineTool implements Extension {
118
128
  private createLayer;
119
129
  private destroyLayer;
120
130
  private createHatchPattern;
121
- private resolvePadding;
122
- updateDieline(emitEvent?: boolean): void;
131
+ private getConfigService;
132
+ private syncSizeState;
133
+ private bringFeatureMarkersToFront;
134
+ updateDieline(_emitEvent?: boolean): void;
123
135
  getGeometry(): DielineGeometry | null;
124
136
  exportCutImage(): Promise<string | null>;
125
137
  }
@@ -164,9 +176,11 @@ declare class FeatureTool implements Extension {
164
176
  private context?;
165
177
  private isUpdatingConfig;
166
178
  private isToolActive;
179
+ private hasWorkingChanges;
180
+ private dirtyTrackerDisposable?;
167
181
  private handleMoving;
168
182
  private handleModified;
169
- private handleDielineChange;
183
+ private handleSceneGeometryChange;
170
184
  private currentGeometry;
171
185
  constructor(options?: Partial<{
172
186
  features: ConstraintFeature[];
@@ -176,6 +190,20 @@ declare class FeatureTool implements Extension {
176
190
  private onToolActivated;
177
191
  private updateVisibility;
178
192
  contribute(): {
193
+ [ContributionPointIds.TOOLS]: {
194
+ id: string;
195
+ name: string;
196
+ interaction: string;
197
+ commands: {
198
+ begin: string;
199
+ commit: string;
200
+ rollback: string;
201
+ };
202
+ session: {
203
+ autoBegin: boolean;
204
+ leavePolicy: string;
205
+ };
206
+ }[];
179
207
  [ContributionPointIds.COMMANDS]: CommandContribution[];
180
208
  };
181
209
  private cloneFeatures;
@@ -203,6 +231,8 @@ interface ImageItem {
203
231
  angle?: number;
204
232
  left?: number;
205
233
  top?: number;
234
+ sourceUrl?: string;
235
+ committedUrl?: string;
206
236
  }
207
237
  declare class ImageTool implements Extension {
208
238
  id: string;
@@ -210,59 +240,182 @@ declare class ImageTool implements Extension {
210
240
  name: string;
211
241
  };
212
242
  private items;
213
- private objectMap;
243
+ private workingItems;
244
+ private hasWorkingChanges;
214
245
  private loadResolvers;
246
+ private sourceSizeBySrc;
215
247
  private canvasService?;
216
248
  private context?;
217
249
  private isUpdatingConfig;
218
250
  private isToolActive;
251
+ private isImageSelectionActive;
252
+ private focusedImageId;
253
+ private suppressSelectionClearUntil;
254
+ private renderSeq;
255
+ private dirtyTrackerDisposable?;
219
256
  activate(context: ExtensionContext): void;
220
257
  deactivate(context: ExtensionContext): void;
221
258
  private onToolActivated;
222
- private updateInteractivity;
259
+ private onSelectionChanged;
260
+ private onSelectionCleared;
261
+ private onSceneLayoutChanged;
262
+ private syncToolActiveFromWorkbench;
263
+ private isImageEditingVisible;
264
+ private isDebugEnabled;
265
+ private debug;
223
266
  contribute(): {
267
+ [ContributionPointIds.TOOLS]: {
268
+ id: string;
269
+ name: string;
270
+ interaction: string;
271
+ commands: {
272
+ begin: string;
273
+ commit: string;
274
+ rollback: string;
275
+ };
276
+ session: {
277
+ autoBegin: boolean;
278
+ leavePolicy: string;
279
+ };
280
+ }[];
224
281
  [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
225
282
  [ContributionPointIds.COMMANDS]: CommandContribution[];
226
283
  };
284
+ private normalizeItem;
285
+ private normalizeItems;
286
+ private cloneItems;
227
287
  private generateId;
288
+ private getImageIdFromActiveObject;
289
+ private resolveReplaceTargetId;
290
+ private addImageEntry;
291
+ private upsertImageEntry;
292
+ private addItemToWorkingSessionIfNeeded;
293
+ private updateImage;
294
+ private getConfig;
228
295
  private updateConfig;
229
- private ensureLayer;
230
- private getLayoutInfo;
296
+ private getFrameRect;
297
+ private resolveDefaultFitArea;
298
+ private fitImageToDefaultArea;
299
+ private getImageObjects;
300
+ private getOverlayObjects;
301
+ private getImageObject;
302
+ private clearRenderedImages;
303
+ private purgeSourceSizeCacheForItem;
304
+ private rememberSourceSize;
305
+ private getSourceSize;
306
+ private getCoverScale;
307
+ private getFrameVisualConfig;
308
+ private resolveRenderImageState;
309
+ private computeCanvasProps;
310
+ private getCurrentSrc;
311
+ private upsertImageObject;
312
+ private syncImageZOrder;
313
+ private buildOverlaySpecs;
231
314
  private updateImages;
232
- private updateObjectProperties;
233
- private loadImage;
234
- private handleObjectModified;
315
+ private updateImagesAsync;
316
+ private clampNormalized;
317
+ private onObjectModified;
318
+ private updateImageInWorking;
235
319
  private updateImageInConfig;
320
+ private waitImageLoaded;
321
+ private refitImageToFrame;
322
+ private focusImageSelection;
323
+ private fitImageToArea;
324
+ private commitWorkingImagesAsCropped;
325
+ private exportCroppedImageByIds;
326
+ private exportImageFrameUrl;
236
327
  }
237
328
 
329
+ interface WhiteInkItem {
330
+ id: string;
331
+ sourceUrl?: string;
332
+ url?: string;
333
+ opacity: number;
334
+ }
238
335
  declare class WhiteInkTool implements Extension {
239
336
  id: string;
240
337
  metadata: {
241
338
  name: string;
242
339
  };
243
- private customMask;
244
- private opacity;
245
- private enableClip;
340
+ private items;
341
+ private workingItems;
342
+ private hasWorkingChanges;
343
+ private sourceSizeBySrc;
344
+ private previewMaskBySource;
345
+ private pendingPreviewMaskBySource;
246
346
  private canvasService?;
247
- private syncHandler;
248
- private _loadingUrl;
249
- constructor(options?: Partial<{
250
- customMask: string;
251
- opacity: number;
252
- enableClip: boolean;
253
- }>);
347
+ private context?;
348
+ private isUpdatingConfig;
349
+ private isToolActive;
350
+ private printWithWhiteInk;
351
+ private previewImageVisible;
352
+ private renderSeq;
353
+ private dirtyTrackerDisposable?;
254
354
  activate(context: ExtensionContext): void;
255
355
  deactivate(context: ExtensionContext): void;
256
356
  contribute(): {
357
+ [ContributionPointIds.TOOLS]: {
358
+ id: string;
359
+ name: string;
360
+ interaction: string;
361
+ commands: {
362
+ begin: string;
363
+ commit: string;
364
+ rollback: string;
365
+ };
366
+ session: {
367
+ autoBegin: boolean;
368
+ leavePolicy: string;
369
+ };
370
+ }[];
257
371
  [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
258
372
  [ContributionPointIds.COMMANDS]: CommandContribution[];
259
373
  };
260
- private setup;
261
- private teardown;
262
- private updateWhiteInk;
263
- private loadWhiteInk;
264
- private applyClipPath;
265
- private syncWithUserImage;
374
+ private onToolActivated;
375
+ private onSceneLayoutChanged;
376
+ private onObjectAdded;
377
+ private migrateLegacyConfigIfNeeded;
378
+ private syncToolActiveFromWorkbench;
379
+ private isPreviewActive;
380
+ private isDebugEnabled;
381
+ private debug;
382
+ private resolveSourceUrl;
383
+ private clampOpacity;
384
+ private normalizeItem;
385
+ private normalizeItems;
386
+ private cloneItems;
387
+ private generateId;
388
+ private getConfig;
389
+ private resolveReplaceTargetId;
390
+ private updateConfig;
391
+ private addWhiteInkEntry;
392
+ private upsertWhiteInkEntry;
393
+ private addItemToWorkingSessionIfNeeded;
394
+ private updateWhiteInkItem;
395
+ private updateWhiteInkInWorking;
396
+ private updateWhiteInkInConfig;
397
+ private removeWhiteInk;
398
+ private clearWhiteInks;
399
+ private completeWhiteInks;
400
+ private getFrameRect;
401
+ private getWhiteInkObjects;
402
+ private getWhiteInkObject;
403
+ private clearRenderedWhiteInks;
404
+ private purgeSourceCaches;
405
+ private rememberSourceSize;
406
+ private getSourceSize;
407
+ private getCoverScale;
408
+ private resolveRenderState;
409
+ private computeCanvasProps;
410
+ private getCurrentSrc;
411
+ private upsertWhiteInkObject;
412
+ private syncZOrder;
413
+ private applyImagePreviewVisibility;
414
+ private updateWhiteInks;
415
+ private updateWhiteInksAsync;
416
+ private getPreviewMaskSource;
417
+ private createOpaqueMaskSource;
418
+ private loadImageElement;
266
419
  }
267
420
 
268
421
  declare class RulerTool implements Extension {
@@ -276,12 +429,9 @@ declare class RulerTool implements Extension {
276
429
  private textColor;
277
430
  private lineColor;
278
431
  private fontSize;
279
- private dielineWidth;
280
- private dielineHeight;
281
- private dielineDisplayUnit;
282
- private dielinePadding;
283
- private dielineOffset;
284
432
  private canvasService?;
433
+ private context?;
434
+ private onCanvasResized;
285
435
  constructor(options?: Partial<{
286
436
  thickness: number;
287
437
  backgroundColor: string;
@@ -299,7 +449,6 @@ declare class RulerTool implements Extension {
299
449
  private createLayer;
300
450
  private destroyLayer;
301
451
  private createArrowLine;
302
- private resolvePadding;
303
452
  private updateRuler;
304
453
  }
305
454
 
@@ -326,8 +475,56 @@ declare class MirrorTool implements Extension {
326
475
  private applyMirror;
327
476
  }
328
477
 
329
- declare function parseLengthToMm(input: number | string, defaultUnit: Unit): number;
330
- declare function formatMm(valueMm: number, displayUnit: Unit, fractionDigits?: number): string;
478
+ declare class SizeTool implements Extension {
479
+ id: string;
480
+ metadata: {
481
+ name: string;
482
+ };
483
+ private context?;
484
+ private canvasService?;
485
+ activate(context: ExtensionContext): void;
486
+ deactivate(_context: ExtensionContext): void;
487
+ contribute(): {
488
+ [ContributionPointIds.TOOLS]: {
489
+ id: string;
490
+ name: string;
491
+ interaction: string;
492
+ }[];
493
+ [ContributionPointIds.CONFIGURATIONS]: ConfigurationContribution[];
494
+ [ContributionPointIds.COMMANDS]: CommandContribution[];
495
+ };
496
+ private getConfigService;
497
+ private ensureDefaults;
498
+ private emitStateChanged;
499
+ private getStateForUI;
500
+ private updateDimensions;
501
+ private setConstraintMode;
502
+ private setUnit;
503
+ private setCut;
504
+ private getSelectedImageSize;
505
+ }
506
+
507
+ declare class SceneLayoutService implements Extension {
508
+ id: string;
509
+ metadata: {
510
+ name: string;
511
+ };
512
+ private context?;
513
+ private canvasService?;
514
+ private configService?;
515
+ private lastLayout;
516
+ private lastGeometry;
517
+ private onConfigChange?;
518
+ activate(context: ExtensionContext): void;
519
+ deactivate(context: ExtensionContext): void;
520
+ contribute(): {
521
+ [ContributionPointIds.COMMANDS]: CommandContribution[];
522
+ };
523
+ private onCanvasResized;
524
+ private refresh;
525
+ private getLayout;
526
+ private getGeometry;
527
+ }
331
528
 
332
529
  declare class ViewportSystem {
333
530
  private _containerSize;
@@ -348,6 +545,21 @@ declare class ViewportSystem {
348
545
  toPhysicalPoint(point: Point): Point;
349
546
  }
350
547
 
548
+ type RenderObjectType = "rect" | "image" | "path";
549
+ type RenderProps = Record<string, any>;
550
+ interface RenderObjectSpec {
551
+ id: string;
552
+ type: RenderObjectType;
553
+ props: RenderProps;
554
+ data?: Record<string, any>;
555
+ src?: string;
556
+ }
557
+ interface RenderLayerSpec {
558
+ id: string;
559
+ objects: RenderObjectSpec[];
560
+ props?: RenderProps;
561
+ }
562
+
351
563
  declare class CanvasService implements Service {
352
564
  canvas: Canvas;
353
565
  viewport: ViewportSystem;
@@ -370,6 +582,97 @@ declare class CanvasService implements Service {
370
582
  */
371
583
  getObject(id: string, layerId?: string): FabricObject | undefined;
372
584
  requestRenderAll(): void;
585
+ resize(width: number, height: number): void;
586
+ applyLayerSpec(spec: RenderLayerSpec): Promise<void>;
587
+ applyObjectSpecsToLayer(layerId: string, objects: RenderObjectSpec[]): Promise<void>;
588
+ getRootLayerObjects(layerId: string): FabricObject[];
589
+ applyObjectSpecsToRootLayer(layerId: string, specs: RenderObjectSpec[]): Promise<void>;
590
+ private applyObjectSpecsToContainer;
591
+ private patchFabricObject;
592
+ private moveObjectInContainer;
593
+ private createFabricObject;
594
+ }
595
+
596
+ type SizeConstraintMode = "free" | "lockAspect" | "equal";
597
+ type CutMode = "trim" | "outset" | "inset";
598
+ interface SizeState {
599
+ unit: Unit;
600
+ actualWidthMm: number;
601
+ actualHeightMm: number;
602
+ constraintMode: SizeConstraintMode;
603
+ aspectRatio: number;
604
+ cutMode: CutMode;
605
+ cutMarginMm: number;
606
+ viewPadding: number | string;
607
+ minMm: number;
608
+ maxMm: number;
609
+ stepMm: number;
610
+ }
611
+ interface SceneRect {
612
+ left: number;
613
+ top: number;
614
+ width: number;
615
+ height: number;
616
+ centerX: number;
617
+ centerY: number;
618
+ }
619
+ interface SceneLayoutSnapshot {
620
+ scale: number;
621
+ canvasWidth: number;
622
+ canvasHeight: number;
623
+ trimRect: SceneRect;
624
+ cutRect: SceneRect;
625
+ bleedRect: SceneRect;
626
+ trimWidthMm: number;
627
+ trimHeightMm: number;
628
+ cutWidthMm: number;
629
+ cutHeightMm: number;
630
+ cutMode: CutMode;
631
+ cutMarginMm: number;
632
+ }
633
+ interface SceneGeometrySnapshot {
634
+ shape: "rect" | "circle" | "ellipse" | "custom";
635
+ unit: "mm";
636
+ displayUnit: Unit;
637
+ x: number;
638
+ y: number;
639
+ width: number;
640
+ height: number;
641
+ radius: number;
642
+ offset: number;
643
+ scale: number;
644
+ pathData?: string;
645
+ }
646
+ declare function sanitizeMmValue(valueMm: number, limits: {
647
+ minMm: number;
648
+ maxMm: number;
649
+ stepMm: number;
650
+ }): number;
651
+ declare function normalizeUnit(value: unknown): Unit;
652
+ declare function normalizeConstraintMode(value: unknown): SizeConstraintMode;
653
+ declare function normalizeCutMode(value: unknown): CutMode;
654
+ declare function toMm(value: number, fromUnit: Unit): number;
655
+ declare function fromMm(valueMm: number, toUnit: Unit): number;
656
+ declare function resolvePaddingPx(raw: number | string, containerWidth: number, containerHeight: number): number;
657
+ declare function readSizeState(configService: ConfigurationService): SizeState;
658
+ declare function computeSceneLayout(canvasService: CanvasService, size: SizeState): SceneLayoutSnapshot | null;
659
+ declare function buildSceneGeometry(configService: ConfigurationService, layout: SceneLayoutSnapshot): SceneGeometrySnapshot;
660
+
661
+ declare class SceneVisibilityService implements Extension {
662
+ id: string;
663
+ metadata: {
664
+ name: string;
665
+ };
666
+ private canvasService?;
667
+ private activeToolId;
668
+ activate(context: ExtensionContext): void;
669
+ deactivate(context: ExtensionContext): void;
670
+ private onToolActivated;
671
+ private onObjectAdded;
672
+ private apply;
373
673
  }
374
674
 
375
- export { BackgroundTool, CanvasService, type DielineGeometry, type DielineState, DielineTool, FeatureTool, FilmTool, type ImageItem, ImageTool, type LineStyle, MirrorTool, RulerTool, WhiteInkTool, formatMm, parseLengthToMm };
675
+ declare function parseLengthToMm(input: number | string, defaultUnit: Unit): number;
676
+ declare function formatMm(valueMm: number, displayUnit: Unit, fractionDigits?: number): string;
677
+
678
+ 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 };