@leapfrog/interactive-canvas 2.0.23-beta-5 → 2.0.23-beta-7
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/interactive-canvas.es.js +78 -77
- package/dist/interactive-canvas.js +78 -77
- package/package.json +1 -1
|
@@ -3053,7 +3053,9 @@ class AbstractInteractiveCanvas {
|
|
|
3053
3053
|
newScale = maxWidth / curWidth;
|
|
3054
3054
|
}
|
|
3055
3055
|
// Set image properties and add to the canvas
|
|
3056
|
-
const fabricImage = new FabricImage(imageUrl, {
|
|
3056
|
+
//const fabricImage = new FabricImage(imageUrl, {
|
|
3057
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3058
|
+
const fabricImage = new FabricImage(image, {
|
|
3057
3059
|
id: id,
|
|
3058
3060
|
scaleX: newScale,
|
|
3059
3061
|
scaleY: newScale,
|
|
@@ -3096,93 +3098,92 @@ class AbstractInteractiveCanvas {
|
|
|
3096
3098
|
}
|
|
3097
3099
|
});
|
|
3098
3100
|
}
|
|
3101
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3102
|
+
const maxSizeScale = 2;
|
|
3103
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3104
|
+
|
|
3105
|
+
const options = { crossOrigin: "anonymous" };
|
|
3106
|
+
|
|
3107
|
+
if (this.headless) {
|
|
3108
|
+
const image = await loadImage(imageUrl);
|
|
3109
|
+
console.log("image-->",image)
|
|
3110
|
+
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3111
|
+
return this.createFabricImage(image, maxWidth);
|
|
3112
|
+
} else {
|
|
3113
|
+
return await new Promise((resolve) => {
|
|
3114
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3115
|
+
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3116
|
+
});
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3122
|
+
const id = this.randomId();
|
|
3123
|
+
console.log("image inside createfabricimage-->",image)
|
|
3124
|
+
let newScale = 1;
|
|
3125
|
+
const curWidth = newScale * image.width;
|
|
3126
|
+
if (curWidth > maxWidth) {
|
|
3127
|
+
newScale = maxWidth / curWidth;
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
const fabricImage = new FabricImage(image, {
|
|
3131
|
+
id: id,
|
|
3132
|
+
scaleX: newScale,
|
|
3133
|
+
scaleY: newScale,
|
|
3134
|
+
originX: "left",
|
|
3135
|
+
originY: "top",
|
|
3136
|
+
});
|
|
3137
|
+
|
|
3138
|
+
this.fabricCanvas.add(fabricImage);
|
|
3139
|
+
|
|
3140
|
+
const object = new Image(this, fabricImage);
|
|
3141
|
+
this.trackNewObject(object);
|
|
3142
|
+
this.syncObjectList();
|
|
3143
|
+
|
|
3144
|
+
return object;
|
|
3145
|
+
}*/
|
|
3146
|
+
/**
|
|
3147
|
+
* @override
|
|
3148
|
+
* @inheritDoc
|
|
3149
|
+
*/
|
|
3099
3150
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3151
|
+
//Don't let the image be more than half the canvas in size.
|
|
3100
3152
|
const maxSizeScale = 2;
|
|
3101
3153
|
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3102
3154
|
|
|
3103
|
-
const options = {
|
|
3155
|
+
const options = {crossOrigin: "anonymous"};
|
|
3156
|
+
return await new Promise((resolve) => {
|
|
3157
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3158
|
+
const id = this.randomId();
|
|
3104
3159
|
|
|
3105
|
-
|
|
3106
|
-
const image = await loadImage(imageUrl);
|
|
3107
|
-
console.log("image-->",image)
|
|
3108
|
-
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3109
|
-
return this.createFabricImage(image, maxWidth);
|
|
3110
|
-
} else {
|
|
3111
|
-
return await new Promise((resolve) => {
|
|
3112
|
-
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3113
|
-
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3114
|
-
});
|
|
3115
|
-
});
|
|
3116
|
-
}
|
|
3117
|
-
}
|
|
3160
|
+
let newScale = 1;
|
|
3118
3161
|
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
const curWidth = newScale * image.width;
|
|
3124
|
-
if (curWidth > maxWidth) {
|
|
3125
|
-
newScale = maxWidth / curWidth;
|
|
3126
|
-
}
|
|
3162
|
+
const curWidth = newScale * fabricImage.width;
|
|
3163
|
+
if (curWidth > maxWidth) {
|
|
3164
|
+
newScale = maxWidth / curWidth;
|
|
3165
|
+
}
|
|
3127
3166
|
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3167
|
+
fabricImage.set({
|
|
3168
|
+
id: id,
|
|
3169
|
+
scaleX: newScale,
|
|
3170
|
+
scaleY: newScale,
|
|
3171
|
+
originX: "left",
|
|
3172
|
+
originY: "top"
|
|
3173
|
+
} as any);
|
|
3174
|
+
|
|
3175
|
+
this.fabricCanvas.add(fabricImage);
|
|
3135
3176
|
|
|
3136
|
-
|
|
3177
|
+
const object = new Image(this, fabricImage);
|
|
3178
|
+
this.trackNewObject(object);
|
|
3179
|
+
this.selectFabricObject(fabricImage);
|
|
3137
3180
|
|
|
3138
|
-
|
|
3139
|
-
this.trackNewObject(object);
|
|
3140
|
-
this.syncObjectList();
|
|
3181
|
+
this.syncObjectList();
|
|
3141
3182
|
|
|
3142
|
-
|
|
3183
|
+
resolve(object);
|
|
3184
|
+
});
|
|
3185
|
+
});
|
|
3143
3186
|
}*/
|
|
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;
|
|
3152
|
-
|
|
3153
|
-
const options = {crossOrigin: "anonymous"};
|
|
3154
|
-
return await new Promise((resolve) => {
|
|
3155
|
-
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3156
|
-
const id = this.randomId();
|
|
3157
|
-
|
|
3158
|
-
let newScale = 1;
|
|
3159
|
-
|
|
3160
|
-
const curWidth = newScale * fabricImage.width;
|
|
3161
|
-
if (curWidth > maxWidth) {
|
|
3162
|
-
newScale = maxWidth / curWidth;
|
|
3163
|
-
}
|
|
3164
|
-
|
|
3165
|
-
fabricImage.set({
|
|
3166
|
-
id: id,
|
|
3167
|
-
scaleX: newScale,
|
|
3168
|
-
scaleY: newScale,
|
|
3169
|
-
originX: "left",
|
|
3170
|
-
originY: "top"
|
|
3171
|
-
} as any);
|
|
3172
|
-
|
|
3173
|
-
this.fabricCanvas.add(fabricImage);
|
|
3174
|
-
|
|
3175
|
-
const object = new Image(this, fabricImage);
|
|
3176
|
-
this.trackNewObject(object);
|
|
3177
|
-
this.selectFabricObject(fabricImage);
|
|
3178
|
-
|
|
3179
|
-
this.syncObjectList();
|
|
3180
|
-
|
|
3181
|
-
resolve(object);
|
|
3182
|
-
});
|
|
3183
|
-
});
|
|
3184
|
-
}
|
|
3185
|
-
*/
|
|
3186
3187
|
/**
|
|
3187
3188
|
* @override
|
|
3188
3189
|
* @inheritDoc
|
|
@@ -3073,7 +3073,9 @@ class AbstractInteractiveCanvas {
|
|
|
3073
3073
|
newScale = maxWidth / curWidth;
|
|
3074
3074
|
}
|
|
3075
3075
|
// Set image properties and add to the canvas
|
|
3076
|
-
const fabricImage = new
|
|
3076
|
+
//const fabricImage = new FabricImage(imageUrl, {
|
|
3077
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3078
|
+
const fabricImage = new fabric.FabricImage(image, {
|
|
3077
3079
|
id: id,
|
|
3078
3080
|
scaleX: newScale,
|
|
3079
3081
|
scaleY: newScale,
|
|
@@ -3116,93 +3118,92 @@ class AbstractInteractiveCanvas {
|
|
|
3116
3118
|
}
|
|
3117
3119
|
});
|
|
3118
3120
|
}
|
|
3121
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3122
|
+
const maxSizeScale = 2;
|
|
3123
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3124
|
+
|
|
3125
|
+
const options = { crossOrigin: "anonymous" };
|
|
3126
|
+
|
|
3127
|
+
if (this.headless) {
|
|
3128
|
+
const image = await loadImage(imageUrl);
|
|
3129
|
+
console.log("image-->",image)
|
|
3130
|
+
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3131
|
+
return this.createFabricImage(image, maxWidth);
|
|
3132
|
+
} else {
|
|
3133
|
+
return await new Promise((resolve) => {
|
|
3134
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3135
|
+
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3136
|
+
});
|
|
3137
|
+
});
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3142
|
+
const id = this.randomId();
|
|
3143
|
+
console.log("image inside createfabricimage-->",image)
|
|
3144
|
+
let newScale = 1;
|
|
3145
|
+
const curWidth = newScale * image.width;
|
|
3146
|
+
if (curWidth > maxWidth) {
|
|
3147
|
+
newScale = maxWidth / curWidth;
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
const fabricImage = new FabricImage(image, {
|
|
3151
|
+
id: id,
|
|
3152
|
+
scaleX: newScale,
|
|
3153
|
+
scaleY: newScale,
|
|
3154
|
+
originX: "left",
|
|
3155
|
+
originY: "top",
|
|
3156
|
+
});
|
|
3157
|
+
|
|
3158
|
+
this.fabricCanvas.add(fabricImage);
|
|
3159
|
+
|
|
3160
|
+
const object = new Image(this, fabricImage);
|
|
3161
|
+
this.trackNewObject(object);
|
|
3162
|
+
this.syncObjectList();
|
|
3163
|
+
|
|
3164
|
+
return object;
|
|
3165
|
+
}*/
|
|
3166
|
+
/**
|
|
3167
|
+
* @override
|
|
3168
|
+
* @inheritDoc
|
|
3169
|
+
*/
|
|
3119
3170
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3171
|
+
//Don't let the image be more than half the canvas in size.
|
|
3120
3172
|
const maxSizeScale = 2;
|
|
3121
3173
|
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3122
3174
|
|
|
3123
|
-
const options = {
|
|
3175
|
+
const options = {crossOrigin: "anonymous"};
|
|
3176
|
+
return await new Promise((resolve) => {
|
|
3177
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3178
|
+
const id = this.randomId();
|
|
3124
3179
|
|
|
3125
|
-
|
|
3126
|
-
const image = await loadImage(imageUrl);
|
|
3127
|
-
console.log("image-->",image)
|
|
3128
|
-
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3129
|
-
return this.createFabricImage(image, maxWidth);
|
|
3130
|
-
} else {
|
|
3131
|
-
return await new Promise((resolve) => {
|
|
3132
|
-
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3133
|
-
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3134
|
-
});
|
|
3135
|
-
});
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3180
|
+
let newScale = 1;
|
|
3138
3181
|
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
const curWidth = newScale * image.width;
|
|
3144
|
-
if (curWidth > maxWidth) {
|
|
3145
|
-
newScale = maxWidth / curWidth;
|
|
3146
|
-
}
|
|
3182
|
+
const curWidth = newScale * fabricImage.width;
|
|
3183
|
+
if (curWidth > maxWidth) {
|
|
3184
|
+
newScale = maxWidth / curWidth;
|
|
3185
|
+
}
|
|
3147
3186
|
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3187
|
+
fabricImage.set({
|
|
3188
|
+
id: id,
|
|
3189
|
+
scaleX: newScale,
|
|
3190
|
+
scaleY: newScale,
|
|
3191
|
+
originX: "left",
|
|
3192
|
+
originY: "top"
|
|
3193
|
+
} as any);
|
|
3194
|
+
|
|
3195
|
+
this.fabricCanvas.add(fabricImage);
|
|
3155
3196
|
|
|
3156
|
-
|
|
3197
|
+
const object = new Image(this, fabricImage);
|
|
3198
|
+
this.trackNewObject(object);
|
|
3199
|
+
this.selectFabricObject(fabricImage);
|
|
3157
3200
|
|
|
3158
|
-
|
|
3159
|
-
this.trackNewObject(object);
|
|
3160
|
-
this.syncObjectList();
|
|
3201
|
+
this.syncObjectList();
|
|
3161
3202
|
|
|
3162
|
-
|
|
3203
|
+
resolve(object);
|
|
3204
|
+
});
|
|
3205
|
+
});
|
|
3163
3206
|
}*/
|
|
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;
|
|
3172
|
-
|
|
3173
|
-
const options = {crossOrigin: "anonymous"};
|
|
3174
|
-
return await new Promise((resolve) => {
|
|
3175
|
-
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3176
|
-
const id = this.randomId();
|
|
3177
|
-
|
|
3178
|
-
let newScale = 1;
|
|
3179
|
-
|
|
3180
|
-
const curWidth = newScale * fabricImage.width;
|
|
3181
|
-
if (curWidth > maxWidth) {
|
|
3182
|
-
newScale = maxWidth / curWidth;
|
|
3183
|
-
}
|
|
3184
|
-
|
|
3185
|
-
fabricImage.set({
|
|
3186
|
-
id: id,
|
|
3187
|
-
scaleX: newScale,
|
|
3188
|
-
scaleY: newScale,
|
|
3189
|
-
originX: "left",
|
|
3190
|
-
originY: "top"
|
|
3191
|
-
} as any);
|
|
3192
|
-
|
|
3193
|
-
this.fabricCanvas.add(fabricImage);
|
|
3194
|
-
|
|
3195
|
-
const object = new Image(this, fabricImage);
|
|
3196
|
-
this.trackNewObject(object);
|
|
3197
|
-
this.selectFabricObject(fabricImage);
|
|
3198
|
-
|
|
3199
|
-
this.syncObjectList();
|
|
3200
|
-
|
|
3201
|
-
resolve(object);
|
|
3202
|
-
});
|
|
3203
|
-
});
|
|
3204
|
-
}
|
|
3205
|
-
*/
|
|
3206
3207
|
/**
|
|
3207
3208
|
* @override
|
|
3208
3209
|
* @inheritDoc
|