@leapfrog/interactive-canvas 2.0.23-beta-6 → 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.
- package/dist/abstract-interactive-canvas.d.ts +1 -1
- package/dist/interactive-canvas.es.js +153 -107
- package/dist/interactive-canvas.js +153 -107
- package/package.json +1 -1
|
@@ -202,11 +202,11 @@ export declare abstract class AbstractInteractiveCanvas implements IInteractiveC
|
|
|
202
202
|
* @inheritDoc
|
|
203
203
|
*/
|
|
204
204
|
sendObjectToBack(target: FabricObject): void;
|
|
205
|
+
addImageObject(imageUrl: string): Promise<IImage>;
|
|
205
206
|
/**
|
|
206
207
|
* @override
|
|
207
208
|
* @inheritDoc
|
|
208
209
|
*/
|
|
209
|
-
addImageObject(imageUrl: string): Promise<IImage>;
|
|
210
210
|
/**
|
|
211
211
|
* @override
|
|
212
212
|
* @inheritDoc
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _, { round, each, values, reduce, clone, max, isEqual } from 'lodash';
|
|
2
2
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
3
|
+
import { loadImage } from 'canvas';
|
|
3
4
|
import * as fabric from 'fabric';
|
|
4
5
|
|
|
5
6
|
const PIXELS_PER_MM$2 = 3.937;
|
|
@@ -3033,81 +3034,82 @@ class AbstractInteractiveCanvas {
|
|
|
3033
3034
|
this.fabricCanvas.requestRenderAll();
|
|
3034
3035
|
}
|
|
3035
3036
|
}
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3037
|
+
addImageObject(imageUrl) {
|
|
3038
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3039
|
+
// Don't let the image be more than half the canvas in size.
|
|
3040
|
+
const maxSizeScale = 2;
|
|
3041
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3042
|
+
const options = { crossOrigin: "anonymous" };
|
|
3043
|
+
if (this.headless) {
|
|
3044
|
+
// Server-side logic without mock DOM
|
|
3045
|
+
//const canvas = createCanvas(1, 1);
|
|
3046
|
+
//const ctx = canvas.getContext("2d");
|
|
3047
|
+
const image = yield loadImage(imageUrl);
|
|
3048
|
+
const fabricImage = new this.fabric.Image(image, { src: imageUrl, crossOrigin: "anonymous" });
|
|
3049
|
+
const id = this.randomId();
|
|
3050
|
+
let newScale = 1;
|
|
3051
|
+
const curWidth = newScale * fabricImage.width;
|
|
3052
|
+
if (curWidth > maxWidth) {
|
|
3053
|
+
newScale = maxWidth / curWidth;
|
|
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
|
+
});*/
|
|
3065
|
+
// Set image properties and add to the canvas
|
|
3066
|
+
// const fabricImage = new FabricImage(imageUrl, {
|
|
3067
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3068
|
+
// const fabricImage = new FabricImage(image as any, {
|
|
3069
|
+
fabricImage.set({
|
|
3070
|
+
id: id,
|
|
3071
|
+
scaleX: newScale,
|
|
3072
|
+
scaleY: newScale,
|
|
3073
|
+
originX: "left",
|
|
3074
|
+
originY: "top"
|
|
3075
|
+
});
|
|
3076
|
+
console.log("headless image-->", fabricImage);
|
|
3077
|
+
this.fabricCanvas.add(fabricImage);
|
|
3078
|
+
const canvasObjectData = new CanvasObjectData(ObjectType.IMAGE, id);
|
|
3079
|
+
canvasObjectData.imagePath = imageUrl;
|
|
3080
|
+
const object = new Image(this, fabricImage, canvasObjectData);
|
|
3081
|
+
this.trackNewObject(object);
|
|
3082
|
+
this.syncObjectList();
|
|
3083
|
+
return object;
|
|
3084
|
+
}
|
|
3085
|
+
else {
|
|
3086
|
+
// Browser-side logic
|
|
3087
|
+
return yield new Promise((resolve) => {
|
|
3088
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage) => {
|
|
3089
|
+
const id = this.randomId();
|
|
3090
|
+
let newScale = 1;
|
|
3091
|
+
const curWidth = newScale * fabricImage.width;
|
|
3092
|
+
if (curWidth > maxWidth) {
|
|
3093
|
+
newScale = maxWidth / curWidth;
|
|
3094
|
+
}
|
|
3095
|
+
fabricImage.set({
|
|
3096
|
+
id: id,
|
|
3097
|
+
scaleX: newScale,
|
|
3098
|
+
scaleY: newScale,
|
|
3099
|
+
originX: "left",
|
|
3100
|
+
originY: "top",
|
|
3101
|
+
});
|
|
3102
|
+
this.fabricCanvas.add(fabricImage);
|
|
3103
|
+
const object = new Image(this, fabricImage);
|
|
3104
|
+
this.trackNewObject(object);
|
|
3105
|
+
this.selectFabricObject(fabricImage);
|
|
3106
|
+
this.syncObjectList();
|
|
3107
|
+
resolve(object);
|
|
3108
|
+
});
|
|
3109
|
+
});
|
|
3110
|
+
}
|
|
3111
|
+
});
|
|
3112
|
+
}
|
|
3111
3113
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3112
3114
|
const maxSizeScale = 2;
|
|
3113
3115
|
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
@@ -3153,42 +3155,86 @@ class AbstractInteractiveCanvas {
|
|
|
3153
3155
|
|
|
3154
3156
|
return object;
|
|
3155
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
|
+
}*/
|
|
3156
3197
|
/**
|
|
3157
3198
|
* @override
|
|
3158
3199
|
* @inheritDoc
|
|
3159
3200
|
*/
|
|
3160
|
-
addImageObject(imageUrl) {
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3201
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3202
|
+
//Don't let the image be more than half the canvas in size.
|
|
3203
|
+
const maxSizeScale = 2;
|
|
3204
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3205
|
+
|
|
3206
|
+
const options = {crossOrigin: "anonymous"};
|
|
3207
|
+
return await new Promise((resolve) => {
|
|
3208
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3209
|
+
const id = this.randomId();
|
|
3210
|
+
|
|
3211
|
+
let newScale = 1;
|
|
3212
|
+
|
|
3213
|
+
const curWidth = newScale * fabricImage.width;
|
|
3214
|
+
if (curWidth > maxWidth) {
|
|
3215
|
+
newScale = maxWidth / curWidth;
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
fabricImage.set({
|
|
3219
|
+
id: id,
|
|
3220
|
+
scaleX: newScale,
|
|
3221
|
+
scaleY: newScale,
|
|
3222
|
+
originX: "left",
|
|
3223
|
+
originY: "top"
|
|
3224
|
+
} as any);
|
|
3225
|
+
|
|
3226
|
+
this.fabricCanvas.add(fabricImage);
|
|
3227
|
+
|
|
3228
|
+
const object = new Image(this, fabricImage);
|
|
3229
|
+
this.trackNewObject(object);
|
|
3230
|
+
this.selectFabricObject(fabricImage);
|
|
3231
|
+
|
|
3232
|
+
this.syncObjectList();
|
|
3233
|
+
|
|
3234
|
+
resolve(object);
|
|
3235
|
+
});
|
|
3236
|
+
});
|
|
3237
|
+
}*/
|
|
3192
3238
|
/**
|
|
3193
3239
|
* @override
|
|
3194
3240
|
* @inheritDoc
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
|
+
var canvas = require('canvas');
|
|
5
6
|
var fabric = require('fabric');
|
|
6
7
|
|
|
7
8
|
function _interopNamespaceDefault(e) {
|
|
@@ -3054,81 +3055,82 @@ class AbstractInteractiveCanvas {
|
|
|
3054
3055
|
this.fabricCanvas.requestRenderAll();
|
|
3055
3056
|
}
|
|
3056
3057
|
}
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3058
|
+
addImageObject(imageUrl) {
|
|
3059
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3060
|
+
// Don't let the image be more than half the canvas in size.
|
|
3061
|
+
const maxSizeScale = 2;
|
|
3062
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3063
|
+
const options = { crossOrigin: "anonymous" };
|
|
3064
|
+
if (this.headless) {
|
|
3065
|
+
// Server-side logic without mock DOM
|
|
3066
|
+
//const canvas = createCanvas(1, 1);
|
|
3067
|
+
//const ctx = canvas.getContext("2d");
|
|
3068
|
+
const image = yield canvas.loadImage(imageUrl);
|
|
3069
|
+
const fabricImage = new this.fabric.Image(image, { src: imageUrl, crossOrigin: "anonymous" });
|
|
3070
|
+
const id = this.randomId();
|
|
3071
|
+
let newScale = 1;
|
|
3072
|
+
const curWidth = newScale * fabricImage.width;
|
|
3073
|
+
if (curWidth > maxWidth) {
|
|
3074
|
+
newScale = maxWidth / curWidth;
|
|
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
|
+
});*/
|
|
3086
|
+
// Set image properties and add to the canvas
|
|
3087
|
+
// const fabricImage = new FabricImage(imageUrl, {
|
|
3088
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3089
|
+
// const fabricImage = new FabricImage(image as any, {
|
|
3090
|
+
fabricImage.set({
|
|
3091
|
+
id: id,
|
|
3092
|
+
scaleX: newScale,
|
|
3093
|
+
scaleY: newScale,
|
|
3094
|
+
originX: "left",
|
|
3095
|
+
originY: "top"
|
|
3096
|
+
});
|
|
3097
|
+
console.log("headless image-->", fabricImage);
|
|
3098
|
+
this.fabricCanvas.add(fabricImage);
|
|
3099
|
+
const canvasObjectData = new CanvasObjectData(exports.ObjectType.IMAGE, id);
|
|
3100
|
+
canvasObjectData.imagePath = imageUrl;
|
|
3101
|
+
const object = new Image(this, fabricImage, canvasObjectData);
|
|
3102
|
+
this.trackNewObject(object);
|
|
3103
|
+
this.syncObjectList();
|
|
3104
|
+
return object;
|
|
3105
|
+
}
|
|
3106
|
+
else {
|
|
3107
|
+
// Browser-side logic
|
|
3108
|
+
return yield new Promise((resolve) => {
|
|
3109
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage) => {
|
|
3110
|
+
const id = this.randomId();
|
|
3111
|
+
let newScale = 1;
|
|
3112
|
+
const curWidth = newScale * fabricImage.width;
|
|
3113
|
+
if (curWidth > maxWidth) {
|
|
3114
|
+
newScale = maxWidth / curWidth;
|
|
3115
|
+
}
|
|
3116
|
+
fabricImage.set({
|
|
3117
|
+
id: id,
|
|
3118
|
+
scaleX: newScale,
|
|
3119
|
+
scaleY: newScale,
|
|
3120
|
+
originX: "left",
|
|
3121
|
+
originY: "top",
|
|
3122
|
+
});
|
|
3123
|
+
this.fabricCanvas.add(fabricImage);
|
|
3124
|
+
const object = new Image(this, fabricImage);
|
|
3125
|
+
this.trackNewObject(object);
|
|
3126
|
+
this.selectFabricObject(fabricImage);
|
|
3127
|
+
this.syncObjectList();
|
|
3128
|
+
resolve(object);
|
|
3129
|
+
});
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3132
3134
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3133
3135
|
const maxSizeScale = 2;
|
|
3134
3136
|
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
@@ -3174,42 +3176,86 @@ class AbstractInteractiveCanvas {
|
|
|
3174
3176
|
|
|
3175
3177
|
return object;
|
|
3176
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
|
+
}*/
|
|
3177
3218
|
/**
|
|
3178
3219
|
* @override
|
|
3179
3220
|
* @inheritDoc
|
|
3180
3221
|
*/
|
|
3181
|
-
addImageObject(imageUrl) {
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3222
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3223
|
+
//Don't let the image be more than half the canvas in size.
|
|
3224
|
+
const maxSizeScale = 2;
|
|
3225
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3226
|
+
|
|
3227
|
+
const options = {crossOrigin: "anonymous"};
|
|
3228
|
+
return await new Promise((resolve) => {
|
|
3229
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3230
|
+
const id = this.randomId();
|
|
3231
|
+
|
|
3232
|
+
let newScale = 1;
|
|
3233
|
+
|
|
3234
|
+
const curWidth = newScale * fabricImage.width;
|
|
3235
|
+
if (curWidth > maxWidth) {
|
|
3236
|
+
newScale = maxWidth / curWidth;
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
fabricImage.set({
|
|
3240
|
+
id: id,
|
|
3241
|
+
scaleX: newScale,
|
|
3242
|
+
scaleY: newScale,
|
|
3243
|
+
originX: "left",
|
|
3244
|
+
originY: "top"
|
|
3245
|
+
} as any);
|
|
3246
|
+
|
|
3247
|
+
this.fabricCanvas.add(fabricImage);
|
|
3248
|
+
|
|
3249
|
+
const object = new Image(this, fabricImage);
|
|
3250
|
+
this.trackNewObject(object);
|
|
3251
|
+
this.selectFabricObject(fabricImage);
|
|
3252
|
+
|
|
3253
|
+
this.syncObjectList();
|
|
3254
|
+
|
|
3255
|
+
resolve(object);
|
|
3256
|
+
});
|
|
3257
|
+
});
|
|
3258
|
+
}*/
|
|
3213
3259
|
/**
|
|
3214
3260
|
* @override
|
|
3215
3261
|
* @inheritDoc
|