@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.
@@ -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
- /* public async addImageObject(imageUrl: string): Promise<IImage> {
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();
3050
-
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
3079
- return await new Promise((resolve) => {
3080
- this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
3081
- const id = this.randomId();
3082
-
3083
- let newScale = 1;
3084
-
3085
- const curWidth = newScale * fabricImage.width;
3086
- if (curWidth > maxWidth) {
3087
- newScale = maxWidth / curWidth;
3088
- }
3089
-
3090
- fabricImage.set({
3091
- id: id,
3092
- scaleX: newScale,
3093
- scaleY: newScale,
3094
- originX: "left",
3095
- originY: "top",
3096
- } as any);
3097
-
3098
- this.fabricCanvas.add(fabricImage);
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
- 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
- }
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
- /* public async addImageObject(imageUrl: string): Promise<IImage> {
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();
3071
-
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
3100
- return await new Promise((resolve) => {
3101
- this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
3102
- const id = this.randomId();
3103
-
3104
- let newScale = 1;
3105
-
3106
- const curWidth = newScale * fabricImage.width;
3107
- if (curWidth > maxWidth) {
3108
- newScale = maxWidth / curWidth;
3109
- }
3110
-
3111
- fabricImage.set({
3112
- id: id,
3113
- scaleX: newScale,
3114
- scaleY: newScale,
3115
- originX: "left",
3116
- originY: "top",
3117
- } as any);
3118
-
3119
- this.fabricCanvas.add(fabricImage);
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
- 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
- }
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapfrog/interactive-canvas",
3
- "version": "2.0.23-beta-6",
3
+ "version": "2.0.23-beta-7",
4
4
  "description": "Leapfrog interactive canvas",
5
5
  "files": [
6
6
  "dist"