@leapfrog/interactive-canvas 2.0.23-beta-4 → 2.0.23-beta-6
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 +124 -117
- package/dist/interactive-canvas.js +124 -117
- 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>;
|
|
206
205
|
/**
|
|
207
206
|
* @override
|
|
208
207
|
* @inheritDoc
|
|
209
208
|
*/
|
|
209
|
+
addImageObject(imageUrl: string): Promise<IImage>;
|
|
210
210
|
/**
|
|
211
211
|
* @override
|
|
212
212
|
* @inheritDoc
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _, { round, each, values, reduce, clone, max, isEqual } from 'lodash';
|
|
2
2
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
3
|
-
import { createCanvas, loadImage } from 'canvas';
|
|
4
3
|
import * as fabric from 'fabric';
|
|
5
4
|
|
|
6
5
|
const PIXELS_PER_MM$2 = 3.937;
|
|
@@ -3034,122 +3033,49 @@ class AbstractInteractiveCanvas {
|
|
|
3034
3033
|
this.fabricCanvas.requestRenderAll();
|
|
3035
3034
|
}
|
|
3036
3035
|
}
|
|
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
|
-
createCanvas(1, 1);
|
|
3046
|
-
//const ctx = canvas.getContext("2d");
|
|
3047
|
-
const image = yield loadImage(imageUrl);
|
|
3048
|
-
const id = this.randomId();
|
|
3049
|
-
let newScale = 1;
|
|
3050
|
-
const curWidth = newScale * image.width;
|
|
3051
|
-
if (curWidth > maxWidth) {
|
|
3052
|
-
newScale = maxWidth / curWidth;
|
|
3053
|
-
}
|
|
3054
|
-
// Set image properties and add to the canvas
|
|
3055
|
-
const fabricImage = new this.fabric.Image(image, {
|
|
3056
|
-
id: id,
|
|
3057
|
-
scaleX: newScale,
|
|
3058
|
-
scaleY: newScale,
|
|
3059
|
-
originX: "left",
|
|
3060
|
-
originY: "top",
|
|
3061
|
-
crossOrigin: options.crossOrigin,
|
|
3062
|
-
src: imageUrl
|
|
3063
|
-
});
|
|
3064
|
-
this.fabricCanvas.add(fabricImage);
|
|
3065
|
-
const object = new Image(this, fabricImage);
|
|
3066
|
-
this.trackNewObject(object);
|
|
3067
|
-
this.syncObjectList();
|
|
3068
|
-
return object;
|
|
3069
|
-
}
|
|
3070
|
-
else {
|
|
3071
|
-
// Browser-side logic
|
|
3072
|
-
return yield new Promise((resolve) => {
|
|
3073
|
-
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage) => {
|
|
3074
|
-
const id = this.randomId();
|
|
3075
|
-
let newScale = 1;
|
|
3076
|
-
const curWidth = newScale * fabricImage.width;
|
|
3077
|
-
if (curWidth > maxWidth) {
|
|
3078
|
-
newScale = maxWidth / curWidth;
|
|
3079
|
-
}
|
|
3080
|
-
fabricImage.set({
|
|
3081
|
-
id: id,
|
|
3082
|
-
scaleX: newScale,
|
|
3083
|
-
scaleY: newScale,
|
|
3084
|
-
originX: "left",
|
|
3085
|
-
originY: "top",
|
|
3086
|
-
});
|
|
3087
|
-
this.fabricCanvas.add(fabricImage);
|
|
3088
|
-
const object = new Image(this, fabricImage);
|
|
3089
|
-
this.trackNewObject(object);
|
|
3090
|
-
this.selectFabricObject(fabricImage);
|
|
3091
|
-
this.syncObjectList();
|
|
3092
|
-
resolve(object);
|
|
3093
|
-
});
|
|
3094
|
-
});
|
|
3095
|
-
}
|
|
3096
|
-
});
|
|
3097
|
-
}
|
|
3098
3036
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3113
|
-
});
|
|
3114
|
-
});
|
|
3115
|
-
}
|
|
3116
|
-
}
|
|
3117
|
-
|
|
3118
|
-
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3119
|
-
const id = this.randomId();
|
|
3120
|
-
console.log("image inside createfabricimage-->",image)
|
|
3121
|
-
let newScale = 1;
|
|
3122
|
-
const curWidth = newScale * image.width;
|
|
3123
|
-
if (curWidth > maxWidth) {
|
|
3124
|
-
newScale = maxWidth / curWidth;
|
|
3125
|
-
}
|
|
3126
|
-
|
|
3127
|
-
const fabricImage = new FabricImage(image, {
|
|
3128
|
-
id: id,
|
|
3129
|
-
scaleX: newScale,
|
|
3130
|
-
scaleY: newScale,
|
|
3131
|
-
originX: "left",
|
|
3132
|
-
originY: "top",
|
|
3133
|
-
});
|
|
3134
|
-
|
|
3135
|
-
this.fabricCanvas.add(fabricImage);
|
|
3136
|
-
|
|
3137
|
-
const object = new Image(this, fabricImage);
|
|
3138
|
-
this.trackNewObject(object);
|
|
3139
|
-
this.syncObjectList();
|
|
3140
|
-
|
|
3141
|
-
return object;
|
|
3142
|
-
}*/
|
|
3143
|
-
/**
|
|
3144
|
-
* @override
|
|
3145
|
-
* @inheritDoc
|
|
3146
|
-
*/
|
|
3147
|
-
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3148
|
-
//Don't let the image be more than half the canvas in size.
|
|
3149
|
-
const maxSizeScale = 2;
|
|
3150
|
-
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3037
|
+
// Don't let the image be more than half the canvas in size.
|
|
3038
|
+
const maxSizeScale = 2;
|
|
3039
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3040
|
+
|
|
3041
|
+
const options = { crossOrigin: "anonymous" };
|
|
3042
|
+
|
|
3043
|
+
if (this.headless) {
|
|
3044
|
+
// Server-side logic without mock DOM
|
|
3045
|
+
//const canvas = createCanvas(1, 1);
|
|
3046
|
+
//const ctx = canvas.getContext("2d");
|
|
3047
|
+
|
|
3048
|
+
const image = await loadImage(imageUrl);
|
|
3049
|
+
const id = this.randomId();
|
|
3151
3050
|
|
|
3152
|
-
|
|
3051
|
+
let newScale = 1;
|
|
3052
|
+
const curWidth = newScale * image.width;
|
|
3053
|
+
if (curWidth > maxWidth) {
|
|
3054
|
+
newScale = maxWidth / curWidth;
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
// Set image properties and add to the canvas
|
|
3058
|
+
//const fabricImage = new FabricImage(imageUrl, {
|
|
3059
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3060
|
+
const fabricImage = new FabricImage(image as any, {
|
|
3061
|
+
id: id,
|
|
3062
|
+
scaleX: newScale,
|
|
3063
|
+
scaleY: newScale,
|
|
3064
|
+
originX: "left",
|
|
3065
|
+
originY: "top",
|
|
3066
|
+
crossOrigin: options.crossOrigin,
|
|
3067
|
+
src: imageUrl
|
|
3068
|
+
} as any);
|
|
3069
|
+
|
|
3070
|
+
this.fabricCanvas.add(fabricImage);
|
|
3071
|
+
|
|
3072
|
+
const object = new Image(this, fabricImage);
|
|
3073
|
+
this.trackNewObject(object);
|
|
3074
|
+
this.syncObjectList();
|
|
3075
|
+
|
|
3076
|
+
return object;
|
|
3077
|
+
} else {
|
|
3078
|
+
// Browser-side logic
|
|
3153
3079
|
return await new Promise((resolve) => {
|
|
3154
3080
|
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3155
3081
|
const id = this.randomId();
|
|
@@ -3166,7 +3092,7 @@ class AbstractInteractiveCanvas {
|
|
|
3166
3092
|
scaleX: newScale,
|
|
3167
3093
|
scaleY: newScale,
|
|
3168
3094
|
originX: "left",
|
|
3169
|
-
originY: "top"
|
|
3095
|
+
originY: "top",
|
|
3170
3096
|
} as any);
|
|
3171
3097
|
|
|
3172
3098
|
this.fabricCanvas.add(fabricImage);
|
|
@@ -3181,7 +3107,88 @@ class AbstractInteractiveCanvas {
|
|
|
3181
3107
|
});
|
|
3182
3108
|
});
|
|
3183
3109
|
}
|
|
3184
|
-
*/
|
|
3110
|
+
}*/
|
|
3111
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3112
|
+
const maxSizeScale = 2;
|
|
3113
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3114
|
+
|
|
3115
|
+
const options = { crossOrigin: "anonymous" };
|
|
3116
|
+
|
|
3117
|
+
if (this.headless) {
|
|
3118
|
+
const image = await loadImage(imageUrl);
|
|
3119
|
+
console.log("image-->",image)
|
|
3120
|
+
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3121
|
+
return this.createFabricImage(image, maxWidth);
|
|
3122
|
+
} else {
|
|
3123
|
+
return await new Promise((resolve) => {
|
|
3124
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3125
|
+
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3126
|
+
});
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3132
|
+
const id = this.randomId();
|
|
3133
|
+
console.log("image inside createfabricimage-->",image)
|
|
3134
|
+
let newScale = 1;
|
|
3135
|
+
const curWidth = newScale * image.width;
|
|
3136
|
+
if (curWidth > maxWidth) {
|
|
3137
|
+
newScale = maxWidth / curWidth;
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
const fabricImage = new FabricImage(image, {
|
|
3141
|
+
id: id,
|
|
3142
|
+
scaleX: newScale,
|
|
3143
|
+
scaleY: newScale,
|
|
3144
|
+
originX: "left",
|
|
3145
|
+
originY: "top",
|
|
3146
|
+
});
|
|
3147
|
+
|
|
3148
|
+
this.fabricCanvas.add(fabricImage);
|
|
3149
|
+
|
|
3150
|
+
const object = new Image(this, fabricImage);
|
|
3151
|
+
this.trackNewObject(object);
|
|
3152
|
+
this.syncObjectList();
|
|
3153
|
+
|
|
3154
|
+
return object;
|
|
3155
|
+
}*/
|
|
3156
|
+
/**
|
|
3157
|
+
* @override
|
|
3158
|
+
* @inheritDoc
|
|
3159
|
+
*/
|
|
3160
|
+
addImageObject(imageUrl) {
|
|
3161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3162
|
+
//Don't let the image be more than half the canvas in size.
|
|
3163
|
+
const maxSizeScale = 2;
|
|
3164
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3165
|
+
const options = { crossOrigin: "anonymous" };
|
|
3166
|
+
return yield new Promise((resolve) => {
|
|
3167
|
+
const fabricImage = this.fabric.Image.fromURL(imageUrl, options);
|
|
3168
|
+
const id = this.randomId();
|
|
3169
|
+
let newScale = 1;
|
|
3170
|
+
const curWidth = newScale * fabricImage.width;
|
|
3171
|
+
if (curWidth > maxWidth) {
|
|
3172
|
+
newScale = maxWidth / curWidth;
|
|
3173
|
+
}
|
|
3174
|
+
fabricImage.set({
|
|
3175
|
+
id: id,
|
|
3176
|
+
scaleX: newScale,
|
|
3177
|
+
scaleY: newScale,
|
|
3178
|
+
originX: "left",
|
|
3179
|
+
originY: "top"
|
|
3180
|
+
});
|
|
3181
|
+
this.fabricCanvas.add(fabricImage);
|
|
3182
|
+
const object = new Image(this, fabricImage);
|
|
3183
|
+
this.trackNewObject(object);
|
|
3184
|
+
this.selectFabricObject(fabricImage);
|
|
3185
|
+
this.syncObjectList();
|
|
3186
|
+
// resolve(object);
|
|
3187
|
+
return object;
|
|
3188
|
+
});
|
|
3189
|
+
// });
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3185
3192
|
/**
|
|
3186
3193
|
* @override
|
|
3187
3194
|
* @inheritDoc
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
|
-
var canvas = require('canvas');
|
|
6
5
|
var fabric = require('fabric');
|
|
7
6
|
|
|
8
7
|
function _interopNamespaceDefault(e) {
|
|
@@ -3055,122 +3054,49 @@ class AbstractInteractiveCanvas {
|
|
|
3055
3054
|
this.fabricCanvas.requestRenderAll();
|
|
3056
3055
|
}
|
|
3057
3056
|
}
|
|
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
|
-
canvas.createCanvas(1, 1);
|
|
3067
|
-
//const ctx = canvas.getContext("2d");
|
|
3068
|
-
const image = yield canvas.loadImage(imageUrl);
|
|
3069
|
-
const id = this.randomId();
|
|
3070
|
-
let newScale = 1;
|
|
3071
|
-
const curWidth = newScale * image.width;
|
|
3072
|
-
if (curWidth > maxWidth) {
|
|
3073
|
-
newScale = maxWidth / curWidth;
|
|
3074
|
-
}
|
|
3075
|
-
// Set image properties and add to the canvas
|
|
3076
|
-
const fabricImage = new this.fabric.Image(image, {
|
|
3077
|
-
id: id,
|
|
3078
|
-
scaleX: newScale,
|
|
3079
|
-
scaleY: newScale,
|
|
3080
|
-
originX: "left",
|
|
3081
|
-
originY: "top",
|
|
3082
|
-
crossOrigin: options.crossOrigin,
|
|
3083
|
-
src: imageUrl
|
|
3084
|
-
});
|
|
3085
|
-
this.fabricCanvas.add(fabricImage);
|
|
3086
|
-
const object = new Image(this, fabricImage);
|
|
3087
|
-
this.trackNewObject(object);
|
|
3088
|
-
this.syncObjectList();
|
|
3089
|
-
return object;
|
|
3090
|
-
}
|
|
3091
|
-
else {
|
|
3092
|
-
// Browser-side logic
|
|
3093
|
-
return yield new Promise((resolve) => {
|
|
3094
|
-
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage) => {
|
|
3095
|
-
const id = this.randomId();
|
|
3096
|
-
let newScale = 1;
|
|
3097
|
-
const curWidth = newScale * fabricImage.width;
|
|
3098
|
-
if (curWidth > maxWidth) {
|
|
3099
|
-
newScale = maxWidth / curWidth;
|
|
3100
|
-
}
|
|
3101
|
-
fabricImage.set({
|
|
3102
|
-
id: id,
|
|
3103
|
-
scaleX: newScale,
|
|
3104
|
-
scaleY: newScale,
|
|
3105
|
-
originX: "left",
|
|
3106
|
-
originY: "top",
|
|
3107
|
-
});
|
|
3108
|
-
this.fabricCanvas.add(fabricImage);
|
|
3109
|
-
const object = new Image(this, fabricImage);
|
|
3110
|
-
this.trackNewObject(object);
|
|
3111
|
-
this.selectFabricObject(fabricImage);
|
|
3112
|
-
this.syncObjectList();
|
|
3113
|
-
resolve(object);
|
|
3114
|
-
});
|
|
3115
|
-
});
|
|
3116
|
-
}
|
|
3117
|
-
});
|
|
3118
|
-
}
|
|
3119
3057
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3134
|
-
});
|
|
3135
|
-
});
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3138
|
-
|
|
3139
|
-
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3140
|
-
const id = this.randomId();
|
|
3141
|
-
console.log("image inside createfabricimage-->",image)
|
|
3142
|
-
let newScale = 1;
|
|
3143
|
-
const curWidth = newScale * image.width;
|
|
3144
|
-
if (curWidth > maxWidth) {
|
|
3145
|
-
newScale = maxWidth / curWidth;
|
|
3146
|
-
}
|
|
3147
|
-
|
|
3148
|
-
const fabricImage = new FabricImage(image, {
|
|
3149
|
-
id: id,
|
|
3150
|
-
scaleX: newScale,
|
|
3151
|
-
scaleY: newScale,
|
|
3152
|
-
originX: "left",
|
|
3153
|
-
originY: "top",
|
|
3154
|
-
});
|
|
3155
|
-
|
|
3156
|
-
this.fabricCanvas.add(fabricImage);
|
|
3157
|
-
|
|
3158
|
-
const object = new Image(this, fabricImage);
|
|
3159
|
-
this.trackNewObject(object);
|
|
3160
|
-
this.syncObjectList();
|
|
3161
|
-
|
|
3162
|
-
return object;
|
|
3163
|
-
}*/
|
|
3164
|
-
/**
|
|
3165
|
-
* @override
|
|
3166
|
-
* @inheritDoc
|
|
3167
|
-
*/
|
|
3168
|
-
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3169
|
-
//Don't let the image be more than half the canvas in size.
|
|
3170
|
-
const maxSizeScale = 2;
|
|
3171
|
-
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3058
|
+
// Don't let the image be more than half the canvas in size.
|
|
3059
|
+
const maxSizeScale = 2;
|
|
3060
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3061
|
+
|
|
3062
|
+
const options = { crossOrigin: "anonymous" };
|
|
3063
|
+
|
|
3064
|
+
if (this.headless) {
|
|
3065
|
+
// Server-side logic without mock DOM
|
|
3066
|
+
//const canvas = createCanvas(1, 1);
|
|
3067
|
+
//const ctx = canvas.getContext("2d");
|
|
3068
|
+
|
|
3069
|
+
const image = await loadImage(imageUrl);
|
|
3070
|
+
const id = this.randomId();
|
|
3172
3071
|
|
|
3173
|
-
|
|
3072
|
+
let newScale = 1;
|
|
3073
|
+
const curWidth = newScale * image.width;
|
|
3074
|
+
if (curWidth > maxWidth) {
|
|
3075
|
+
newScale = maxWidth / curWidth;
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
// Set image properties and add to the canvas
|
|
3079
|
+
//const fabricImage = new FabricImage(imageUrl, {
|
|
3080
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3081
|
+
const fabricImage = new FabricImage(image as any, {
|
|
3082
|
+
id: id,
|
|
3083
|
+
scaleX: newScale,
|
|
3084
|
+
scaleY: newScale,
|
|
3085
|
+
originX: "left",
|
|
3086
|
+
originY: "top",
|
|
3087
|
+
crossOrigin: options.crossOrigin,
|
|
3088
|
+
src: imageUrl
|
|
3089
|
+
} as any);
|
|
3090
|
+
|
|
3091
|
+
this.fabricCanvas.add(fabricImage);
|
|
3092
|
+
|
|
3093
|
+
const object = new Image(this, fabricImage);
|
|
3094
|
+
this.trackNewObject(object);
|
|
3095
|
+
this.syncObjectList();
|
|
3096
|
+
|
|
3097
|
+
return object;
|
|
3098
|
+
} else {
|
|
3099
|
+
// Browser-side logic
|
|
3174
3100
|
return await new Promise((resolve) => {
|
|
3175
3101
|
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3176
3102
|
const id = this.randomId();
|
|
@@ -3187,7 +3113,7 @@ class AbstractInteractiveCanvas {
|
|
|
3187
3113
|
scaleX: newScale,
|
|
3188
3114
|
scaleY: newScale,
|
|
3189
3115
|
originX: "left",
|
|
3190
|
-
originY: "top"
|
|
3116
|
+
originY: "top",
|
|
3191
3117
|
} as any);
|
|
3192
3118
|
|
|
3193
3119
|
this.fabricCanvas.add(fabricImage);
|
|
@@ -3202,7 +3128,88 @@ class AbstractInteractiveCanvas {
|
|
|
3202
3128
|
});
|
|
3203
3129
|
});
|
|
3204
3130
|
}
|
|
3205
|
-
*/
|
|
3131
|
+
}*/
|
|
3132
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3133
|
+
const maxSizeScale = 2;
|
|
3134
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3135
|
+
|
|
3136
|
+
const options = { crossOrigin: "anonymous" };
|
|
3137
|
+
|
|
3138
|
+
if (this.headless) {
|
|
3139
|
+
const image = await loadImage(imageUrl);
|
|
3140
|
+
console.log("image-->",image)
|
|
3141
|
+
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3142
|
+
return this.createFabricImage(image, maxWidth);
|
|
3143
|
+
} else {
|
|
3144
|
+
return await new Promise((resolve) => {
|
|
3145
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3146
|
+
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3147
|
+
});
|
|
3148
|
+
});
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3152
|
+
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3153
|
+
const id = this.randomId();
|
|
3154
|
+
console.log("image inside createfabricimage-->",image)
|
|
3155
|
+
let newScale = 1;
|
|
3156
|
+
const curWidth = newScale * image.width;
|
|
3157
|
+
if (curWidth > maxWidth) {
|
|
3158
|
+
newScale = maxWidth / curWidth;
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3161
|
+
const fabricImage = new FabricImage(image, {
|
|
3162
|
+
id: id,
|
|
3163
|
+
scaleX: newScale,
|
|
3164
|
+
scaleY: newScale,
|
|
3165
|
+
originX: "left",
|
|
3166
|
+
originY: "top",
|
|
3167
|
+
});
|
|
3168
|
+
|
|
3169
|
+
this.fabricCanvas.add(fabricImage);
|
|
3170
|
+
|
|
3171
|
+
const object = new Image(this, fabricImage);
|
|
3172
|
+
this.trackNewObject(object);
|
|
3173
|
+
this.syncObjectList();
|
|
3174
|
+
|
|
3175
|
+
return object;
|
|
3176
|
+
}*/
|
|
3177
|
+
/**
|
|
3178
|
+
* @override
|
|
3179
|
+
* @inheritDoc
|
|
3180
|
+
*/
|
|
3181
|
+
addImageObject(imageUrl) {
|
|
3182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3183
|
+
//Don't let the image be more than half the canvas in size.
|
|
3184
|
+
const maxSizeScale = 2;
|
|
3185
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3186
|
+
const options = { crossOrigin: "anonymous" };
|
|
3187
|
+
return yield new Promise((resolve) => {
|
|
3188
|
+
const fabricImage = this.fabric.Image.fromURL(imageUrl, options);
|
|
3189
|
+
const id = this.randomId();
|
|
3190
|
+
let newScale = 1;
|
|
3191
|
+
const curWidth = newScale * fabricImage.width;
|
|
3192
|
+
if (curWidth > maxWidth) {
|
|
3193
|
+
newScale = maxWidth / curWidth;
|
|
3194
|
+
}
|
|
3195
|
+
fabricImage.set({
|
|
3196
|
+
id: id,
|
|
3197
|
+
scaleX: newScale,
|
|
3198
|
+
scaleY: newScale,
|
|
3199
|
+
originX: "left",
|
|
3200
|
+
originY: "top"
|
|
3201
|
+
});
|
|
3202
|
+
this.fabricCanvas.add(fabricImage);
|
|
3203
|
+
const object = new Image(this, fabricImage);
|
|
3204
|
+
this.trackNewObject(object);
|
|
3205
|
+
this.selectFabricObject(fabricImage);
|
|
3206
|
+
this.syncObjectList();
|
|
3207
|
+
// resolve(object);
|
|
3208
|
+
return object;
|
|
3209
|
+
});
|
|
3210
|
+
// });
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3206
3213
|
/**
|
|
3207
3214
|
* @override
|
|
3208
3215
|
* @inheritDoc
|