@bensitu/image-editor 1.1.1 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bensitu/image-editor",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Lightweight canvas-based image editor",
5
5
  "main": "dist/image-editor.js",
6
6
  "module": "dist/image-editor.esm.js",
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @file image-editor.js
3
3
  * @module image-editor
4
- * @version 1.1.1
4
+ * @version 1.2.0
5
5
  * @author Ben Situ
6
6
  * @license MIT
7
7
  * @description Lightweight canvas-based image editor with masking/transform/export support.
@@ -45,7 +45,7 @@
45
45
  * @param {Object} [options={}] - Customization options to override defaults.
46
46
  * @param {number} [options.canvasWidth=800] - The initial canvas width in pixels.
47
47
  * @param {number} [options.canvasHeight=600] - The initial canvas height in pixels.
48
- * @param {string} [options.backgroundColor='#ffffff'] - The canvas background color.
48
+ * @param {string} [options.backgroundColor='transparent'] - The canvas background color.
49
49
  * @param {number} [options.animationDuration=300] - Duration in ms for scale/rotate animations.
50
50
  * @param {number} [options.minScale=0.1] - Minimum image scaling factor.
51
51
  * @param {number} [options.maxScale=5.0] - Maximum image scaling factor.
@@ -53,6 +53,7 @@
53
53
  * @param {number} [options.rotationStep=90] - Rotation step in degrees.
54
54
  * @param {boolean} [options.expandCanvasToImage=true] - If true, expands the canvas to fit image/mask.
55
55
  * @param {boolean} [options.fitImageToCanvas=false] - If true, fits loaded image inside canvas.
56
+ * @param {boolean} [options.coverImageToCanvas=false] - If true, scales image to cover canvas (at least one side fits, allowing overflow).
56
57
  * @param {boolean} [options.downsampleOnLoad=true] - Whether to downsample very large images on load.
57
58
  * @param {number} [options.downsampleMaxWidth=4000] - Max width for downsampling.
58
59
  * @param {number} [options.downsampleMaxHeight=3000] - Max height for downsampling.
@@ -83,7 +84,7 @@
83
84
  this.options = {
84
85
  canvasWidth: 800,
85
86
  canvasHeight: 600,
86
- backgroundColor: '#ffffff',
87
+ backgroundColor: 'transparent',
87
88
 
88
89
  animationDuration: 300,
89
90
  minScale: 0.1,
@@ -93,6 +94,7 @@
93
94
 
94
95
  expandCanvasToImage: true,
95
96
  fitImageToCanvas: false,
97
+ coverImageToCanvas: false,
96
98
 
97
99
  downsampleOnLoad: true,
98
100
  downsampleMaxWidth: 4000,
@@ -417,14 +419,23 @@
417
419
  const minH = this.containerEl ? Math.floor(this.containerEl.clientHeight || this.options.canvasHeight) : this.options.canvasHeight;
418
420
 
419
421
  if (this.options.fitImageToCanvas) {
420
- // Fit into current canvas (shrink only)
421
- const cw = Math.max(this.options.canvasWidth, minW);
422
- const ch = Math.max(this.options.canvasHeight, minH);
422
+ // Fit into current canvas (shrink only) and ensure canvas does not exceed container
423
+ const cw = Math.max(1, Math.min(this.options.canvasWidth, minW) - 1)
424
+ const ch = Math.max(1, Math.min(this.options.canvasHeight, minH) - 1);
423
425
  this._setCanvasSizeInt(cw, ch);
424
426
  const fitScale = Math.min(cw / imgW, ch / imgH, 1);
425
- fimg.set({ left: (cw - imgW * fitScale) / 2, top: (ch - imgH * fitScale) / 2 });
427
+ fimg.set({ left: 0, top: 0 });
426
428
  fimg.scale(fitScale);
427
429
  this.baseImageScale = fimg.scaleX || 1;
430
+ } else if (this.options.coverImageToCanvas) {
431
+ // Cover canvas: scale to cover, allowing overflow (at least one side fits)
432
+ const cw = Math.max(this.options.canvasWidth, minW);
433
+ const ch = Math.max(this.options.canvasHeight, minH);
434
+ this._setCanvasSizeInt(cw, ch);
435
+ const coverScale = Math.min(1, Math.max(cw / imgW, ch / imgH));
436
+ fimg.set({ left: 0, top: 0 });
437
+ fimg.scale(coverScale);
438
+ this.baseImageScale = fimg.scaleX || 1;
428
439
  } else if (this.options.expandCanvasToImage) {
429
440
  // Expand canvas so that it fully contains the image
430
441
  const cw = Math.max(minW, Math.floor(imgW));
@@ -439,7 +450,7 @@
439
450
  const ch = Math.max(this.options.canvasHeight, minH);
440
451
  this._setCanvasSizeInt(cw, ch);
441
452
  const fitScale = Math.min(cw / imgW, ch / imgH, 1);
442
- fimg.set({ left: (cw - imgW * fitScale) / 2, top: (ch - imgH * fitScale) / 2 });
453
+ fimg.set({ left: 0, top: 0 });
443
454
  fimg.scale(fitScale);
444
455
  this.baseImageScale = fimg.scaleX || 1;
445
456
  }