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