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