@leapfrog/interactive-canvas 2.0.23-beta-6 → 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/abstract-interactive-canvas.d.ts +1 -1
- package/dist/interactive-canvas.es.js +102 -107
- package/dist/interactive-canvas.js +101 -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,6 +1,8 @@
|
|
|
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';
|
|
4
6
|
|
|
5
7
|
const PIXELS_PER_MM$2 = 3.937;
|
|
6
8
|
class MillimeterDimensions {
|
|
@@ -3033,81 +3035,69 @@ class AbstractInteractiveCanvas {
|
|
|
3033
3035
|
this.fabricCanvas.requestRenderAll();
|
|
3034
3036
|
}
|
|
3035
3037
|
}
|
|
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
|
-
const object = new Image(this, fabricImage);
|
|
3101
|
-
this.trackNewObject(object);
|
|
3102
|
-
this.selectFabricObject(fabricImage);
|
|
3103
|
-
|
|
3104
|
-
this.syncObjectList();
|
|
3105
|
-
|
|
3106
|
-
resolve(object);
|
|
3107
|
-
});
|
|
3108
|
-
});
|
|
3109
|
-
}
|
|
3110
|
-
}*/
|
|
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
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3058
|
+
const fabricImage = new FabricImage(image, {
|
|
3059
|
+
id: id,
|
|
3060
|
+
scaleX: newScale,
|
|
3061
|
+
scaleY: newScale,
|
|
3062
|
+
originX: "left",
|
|
3063
|
+
originY: "top",
|
|
3064
|
+
crossOrigin: options.crossOrigin,
|
|
3065
|
+
src: imageUrl
|
|
3066
|
+
});
|
|
3067
|
+
this.fabricCanvas.add(fabricImage);
|
|
3068
|
+
const object = new Image(this, fabricImage);
|
|
3069
|
+
this.trackNewObject(object);
|
|
3070
|
+
this.syncObjectList();
|
|
3071
|
+
return object;
|
|
3072
|
+
}
|
|
3073
|
+
else {
|
|
3074
|
+
// Browser-side logic
|
|
3075
|
+
return yield new Promise((resolve) => {
|
|
3076
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage) => {
|
|
3077
|
+
const id = this.randomId();
|
|
3078
|
+
let newScale = 1;
|
|
3079
|
+
const curWidth = newScale * fabricImage.width;
|
|
3080
|
+
if (curWidth > maxWidth) {
|
|
3081
|
+
newScale = maxWidth / curWidth;
|
|
3082
|
+
}
|
|
3083
|
+
fabricImage.set({
|
|
3084
|
+
id: id,
|
|
3085
|
+
scaleX: newScale,
|
|
3086
|
+
scaleY: newScale,
|
|
3087
|
+
originX: "left",
|
|
3088
|
+
originY: "top",
|
|
3089
|
+
});
|
|
3090
|
+
this.fabricCanvas.add(fabricImage);
|
|
3091
|
+
const object = new Image(this, fabricImage);
|
|
3092
|
+
this.trackNewObject(object);
|
|
3093
|
+
this.selectFabricObject(fabricImage);
|
|
3094
|
+
this.syncObjectList();
|
|
3095
|
+
resolve(object);
|
|
3096
|
+
});
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3111
3101
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3112
3102
|
const maxSizeScale = 2;
|
|
3113
3103
|
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
@@ -3157,38 +3147,43 @@ class AbstractInteractiveCanvas {
|
|
|
3157
3147
|
* @override
|
|
3158
3148
|
* @inheritDoc
|
|
3159
3149
|
*/
|
|
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
|
-
|
|
3150
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3151
|
+
//Don't let the image be more than half the canvas in size.
|
|
3152
|
+
const maxSizeScale = 2;
|
|
3153
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3154
|
+
|
|
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();
|
|
3159
|
+
|
|
3160
|
+
let newScale = 1;
|
|
3161
|
+
|
|
3162
|
+
const curWidth = newScale * fabricImage.width;
|
|
3163
|
+
if (curWidth > maxWidth) {
|
|
3164
|
+
newScale = maxWidth / curWidth;
|
|
3165
|
+
}
|
|
3166
|
+
|
|
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);
|
|
3176
|
+
|
|
3177
|
+
const object = new Image(this, fabricImage);
|
|
3178
|
+
this.trackNewObject(object);
|
|
3179
|
+
this.selectFabricObject(fabricImage);
|
|
3180
|
+
|
|
3181
|
+
this.syncObjectList();
|
|
3182
|
+
|
|
3183
|
+
resolve(object);
|
|
3184
|
+
});
|
|
3185
|
+
});
|
|
3186
|
+
}*/
|
|
3192
3187
|
/**
|
|
3193
3188
|
* @override
|
|
3194
3189
|
* @inheritDoc
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
5
|
var fabric = require('fabric');
|
|
6
|
+
var canvas = require('canvas');
|
|
6
7
|
|
|
7
8
|
function _interopNamespaceDefault(e) {
|
|
8
9
|
var n = Object.create(null);
|
|
@@ -3054,81 +3055,69 @@ 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
|
-
const object = new Image(this, fabricImage);
|
|
3122
|
-
this.trackNewObject(object);
|
|
3123
|
-
this.selectFabricObject(fabricImage);
|
|
3124
|
-
|
|
3125
|
-
this.syncObjectList();
|
|
3126
|
-
|
|
3127
|
-
resolve(object);
|
|
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 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 FabricImage(imageUrl, {
|
|
3077
|
+
//const fabricImage = new this.fabric.Image(image, {
|
|
3078
|
+
const fabricImage = new fabric.FabricImage(image, {
|
|
3079
|
+
id: id,
|
|
3080
|
+
scaleX: newScale,
|
|
3081
|
+
scaleY: newScale,
|
|
3082
|
+
originX: "left",
|
|
3083
|
+
originY: "top",
|
|
3084
|
+
crossOrigin: options.crossOrigin,
|
|
3085
|
+
src: imageUrl
|
|
3086
|
+
});
|
|
3087
|
+
this.fabricCanvas.add(fabricImage);
|
|
3088
|
+
const object = new Image(this, fabricImage);
|
|
3089
|
+
this.trackNewObject(object);
|
|
3090
|
+
this.syncObjectList();
|
|
3091
|
+
return object;
|
|
3092
|
+
}
|
|
3093
|
+
else {
|
|
3094
|
+
// Browser-side logic
|
|
3095
|
+
return yield new Promise((resolve) => {
|
|
3096
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage) => {
|
|
3097
|
+
const id = this.randomId();
|
|
3098
|
+
let newScale = 1;
|
|
3099
|
+
const curWidth = newScale * fabricImage.width;
|
|
3100
|
+
if (curWidth > maxWidth) {
|
|
3101
|
+
newScale = maxWidth / curWidth;
|
|
3102
|
+
}
|
|
3103
|
+
fabricImage.set({
|
|
3104
|
+
id: id,
|
|
3105
|
+
scaleX: newScale,
|
|
3106
|
+
scaleY: newScale,
|
|
3107
|
+
originX: "left",
|
|
3108
|
+
originY: "top",
|
|
3109
|
+
});
|
|
3110
|
+
this.fabricCanvas.add(fabricImage);
|
|
3111
|
+
const object = new Image(this, fabricImage);
|
|
3112
|
+
this.trackNewObject(object);
|
|
3113
|
+
this.selectFabricObject(fabricImage);
|
|
3114
|
+
this.syncObjectList();
|
|
3115
|
+
resolve(object);
|
|
3116
|
+
});
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
});
|
|
3120
|
+
}
|
|
3132
3121
|
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3133
3122
|
const maxSizeScale = 2;
|
|
3134
3123
|
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
@@ -3178,38 +3167,43 @@ class AbstractInteractiveCanvas {
|
|
|
3178
3167
|
* @override
|
|
3179
3168
|
* @inheritDoc
|
|
3180
3169
|
*/
|
|
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
|
-
|
|
3170
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3171
|
+
//Don't let the image be more than half the canvas in size.
|
|
3172
|
+
const maxSizeScale = 2;
|
|
3173
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3174
|
+
|
|
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();
|
|
3179
|
+
|
|
3180
|
+
let newScale = 1;
|
|
3181
|
+
|
|
3182
|
+
const curWidth = newScale * fabricImage.width;
|
|
3183
|
+
if (curWidth > maxWidth) {
|
|
3184
|
+
newScale = maxWidth / curWidth;
|
|
3185
|
+
}
|
|
3186
|
+
|
|
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);
|
|
3196
|
+
|
|
3197
|
+
const object = new Image(this, fabricImage);
|
|
3198
|
+
this.trackNewObject(object);
|
|
3199
|
+
this.selectFabricObject(fabricImage);
|
|
3200
|
+
|
|
3201
|
+
this.syncObjectList();
|
|
3202
|
+
|
|
3203
|
+
resolve(object);
|
|
3204
|
+
});
|
|
3205
|
+
});
|
|
3206
|
+
}*/
|
|
3213
3207
|
/**
|
|
3214
3208
|
* @override
|
|
3215
3209
|
* @inheritDoc
|