@leapfrog/interactive-canvas 2.0.23-beta-7 → 2.0.23-beta-8

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.
@@ -1,8 +1,7 @@
1
1
  import _, { round, each, values, reduce, clone, max, isEqual } from 'lodash';
2
2
  import { BehaviorSubject, Subject } from 'rxjs';
3
- import * as fabric from 'fabric';
4
- import { FabricImage } from 'fabric';
5
3
  import { loadImage } from 'canvas';
4
+ import * as fabric from 'fabric';
6
5
 
7
6
  const PIXELS_PER_MM$2 = 3.937;
8
7
  class MillimeterDimensions {
@@ -3046,26 +3045,39 @@ class AbstractInteractiveCanvas {
3046
3045
  //const canvas = createCanvas(1, 1);
3047
3046
  //const ctx = canvas.getContext("2d");
3048
3047
  const image = yield loadImage(imageUrl);
3048
+ const fabricImage = new this.fabric.Image(image, { src: imageUrl, crossOrigin: "anonymous" });
3049
3049
  const id = this.randomId();
3050
3050
  let newScale = 1;
3051
- const curWidth = newScale * image.width;
3051
+ const curWidth = newScale * fabricImage.width;
3052
3052
  if (curWidth > maxWidth) {
3053
3053
  newScale = maxWidth / curWidth;
3054
3054
  }
3055
+ /*const fabricImage = new this.fabric.Image(image as any, {
3056
+ src: imageUrl,
3057
+ crossOrigin: "anonymous",
3058
+ toObject: function () {
3059
+ return {
3060
+ ...this.callSuper("toObject"),
3061
+ src: this.src,
3062
+ };
3063
+ },
3064
+ });*/
3055
3065
  // Set image properties and add to the canvas
3056
- //const fabricImage = new FabricImage(imageUrl, {
3066
+ // const fabricImage = new FabricImage(imageUrl, {
3057
3067
  //const fabricImage = new this.fabric.Image(image, {
3058
- const fabricImage = new FabricImage(image, {
3068
+ // const fabricImage = new FabricImage(image as any, {
3069
+ fabricImage.set({
3059
3070
  id: id,
3060
3071
  scaleX: newScale,
3061
3072
  scaleY: newScale,
3062
3073
  originX: "left",
3063
- originY: "top",
3064
- crossOrigin: options.crossOrigin,
3065
- src: imageUrl
3074
+ originY: "top"
3066
3075
  });
3076
+ console.log("headless image-->", fabricImage);
3067
3077
  this.fabricCanvas.add(fabricImage);
3068
- const object = new Image(this, fabricImage);
3078
+ const canvasObjectData = new CanvasObjectData(ObjectType.IMAGE, id);
3079
+ canvasObjectData.imagePath = imageUrl;
3080
+ const object = new Image(this, fabricImage, canvasObjectData);
3069
3081
  this.trackNewObject(object);
3070
3082
  this.syncObjectList();
3071
3083
  return object;
@@ -3143,6 +3155,45 @@ class AbstractInteractiveCanvas {
3143
3155
 
3144
3156
  return object;
3145
3157
  }*/
3158
+ /* public async addImageObject(imageUrl: string): Promise<IImage> {
3159
+ const maxSizeScale = 2;
3160
+ const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
3161
+
3162
+ // 1. Safe Isomorphic Options: Prevent browser configurations from cracking Server runs
3163
+ const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
3164
+ const options = isBrowser ? { crossOrigin: "anonymous" } : {};
3165
+
3166
+ // 2. Fabric v6 Asynchronous Image Loader
3167
+ const fabricImage = await this.fabric.Image.fromURL(imageUrl, options);
3168
+
3169
+ const id = this.randomId();
3170
+ let newScale = 1;
3171
+ const curWidth = newScale * fabricImage.width;
3172
+
3173
+ if (curWidth > maxWidth) {
3174
+ newScale = maxWidth / curWidth;
3175
+ }
3176
+
3177
+ fabricImage.set({
3178
+ id: id,
3179
+ scaleX: newScale,
3180
+ scaleY: newScale,
3181
+ originX: "left",
3182
+ originY: "top"
3183
+ } as any);
3184
+
3185
+ this.fabricCanvas.add(fabricImage);
3186
+
3187
+ // Ensure 'Image' resolves to your internal custom class wrapper, not the native DOM global
3188
+ // If your 'Image' class is a domain wrapper (e.g., CustomImageWrapper), name it distinctly to prevent collision.
3189
+ const object = new (Image as any)(this, fabricImage);
3190
+
3191
+ this.trackNewObject(object);
3192
+ this.selectFabricObject(fabricImage);
3193
+ this.syncObjectList();
3194
+
3195
+ return object;
3196
+ }*/
3146
3197
  /**
3147
3198
  * @override
3148
3199
  * @inheritDoc
@@ -2,8 +2,8 @@
2
2
 
3
3
  var _ = require('lodash');
4
4
  var rxjs = require('rxjs');
5
- var fabric = require('fabric');
6
5
  var canvas = require('canvas');
6
+ var fabric = require('fabric');
7
7
 
8
8
  function _interopNamespaceDefault(e) {
9
9
  var n = Object.create(null);
@@ -3066,26 +3066,39 @@ class AbstractInteractiveCanvas {
3066
3066
  //const canvas = createCanvas(1, 1);
3067
3067
  //const ctx = canvas.getContext("2d");
3068
3068
  const image = yield canvas.loadImage(imageUrl);
3069
+ const fabricImage = new this.fabric.Image(image, { src: imageUrl, crossOrigin: "anonymous" });
3069
3070
  const id = this.randomId();
3070
3071
  let newScale = 1;
3071
- const curWidth = newScale * image.width;
3072
+ const curWidth = newScale * fabricImage.width;
3072
3073
  if (curWidth > maxWidth) {
3073
3074
  newScale = maxWidth / curWidth;
3074
3075
  }
3076
+ /*const fabricImage = new this.fabric.Image(image as any, {
3077
+ src: imageUrl,
3078
+ crossOrigin: "anonymous",
3079
+ toObject: function () {
3080
+ return {
3081
+ ...this.callSuper("toObject"),
3082
+ src: this.src,
3083
+ };
3084
+ },
3085
+ });*/
3075
3086
  // Set image properties and add to the canvas
3076
- //const fabricImage = new FabricImage(imageUrl, {
3087
+ // const fabricImage = new FabricImage(imageUrl, {
3077
3088
  //const fabricImage = new this.fabric.Image(image, {
3078
- const fabricImage = new fabric.FabricImage(image, {
3089
+ // const fabricImage = new FabricImage(image as any, {
3090
+ fabricImage.set({
3079
3091
  id: id,
3080
3092
  scaleX: newScale,
3081
3093
  scaleY: newScale,
3082
3094
  originX: "left",
3083
- originY: "top",
3084
- crossOrigin: options.crossOrigin,
3085
- src: imageUrl
3095
+ originY: "top"
3086
3096
  });
3097
+ console.log("headless image-->", fabricImage);
3087
3098
  this.fabricCanvas.add(fabricImage);
3088
- const object = new Image(this, fabricImage);
3099
+ const canvasObjectData = new CanvasObjectData(exports.ObjectType.IMAGE, id);
3100
+ canvasObjectData.imagePath = imageUrl;
3101
+ const object = new Image(this, fabricImage, canvasObjectData);
3089
3102
  this.trackNewObject(object);
3090
3103
  this.syncObjectList();
3091
3104
  return object;
@@ -3163,6 +3176,45 @@ class AbstractInteractiveCanvas {
3163
3176
 
3164
3177
  return object;
3165
3178
  }*/
3179
+ /* public async addImageObject(imageUrl: string): Promise<IImage> {
3180
+ const maxSizeScale = 2;
3181
+ const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
3182
+
3183
+ // 1. Safe Isomorphic Options: Prevent browser configurations from cracking Server runs
3184
+ const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
3185
+ const options = isBrowser ? { crossOrigin: "anonymous" } : {};
3186
+
3187
+ // 2. Fabric v6 Asynchronous Image Loader
3188
+ const fabricImage = await this.fabric.Image.fromURL(imageUrl, options);
3189
+
3190
+ const id = this.randomId();
3191
+ let newScale = 1;
3192
+ const curWidth = newScale * fabricImage.width;
3193
+
3194
+ if (curWidth > maxWidth) {
3195
+ newScale = maxWidth / curWidth;
3196
+ }
3197
+
3198
+ fabricImage.set({
3199
+ id: id,
3200
+ scaleX: newScale,
3201
+ scaleY: newScale,
3202
+ originX: "left",
3203
+ originY: "top"
3204
+ } as any);
3205
+
3206
+ this.fabricCanvas.add(fabricImage);
3207
+
3208
+ // Ensure 'Image' resolves to your internal custom class wrapper, not the native DOM global
3209
+ // If your 'Image' class is a domain wrapper (e.g., CustomImageWrapper), name it distinctly to prevent collision.
3210
+ const object = new (Image as any)(this, fabricImage);
3211
+
3212
+ this.trackNewObject(object);
3213
+ this.selectFabricObject(fabricImage);
3214
+ this.syncObjectList();
3215
+
3216
+ return object;
3217
+ }*/
3166
3218
  /**
3167
3219
  * @override
3168
3220
  * @inheritDoc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "2.0.23-beta-7",
3
+ "version": "2.0.23-beta-8",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"