@leapfrog/interactive-canvas 2.0.23-beta-1 → 2.0.23-beta-3
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.
|
@@ -3042,9 +3042,8 @@ class AbstractInteractiveCanvas {
|
|
|
3042
3042
|
const options = { crossOrigin: "anonymous" };
|
|
3043
3043
|
if (this.headless) {
|
|
3044
3044
|
// Server-side logic without mock DOM
|
|
3045
|
-
|
|
3046
|
-
const
|
|
3047
|
-
canvas.getContext("2d");
|
|
3045
|
+
createCanvas(1, 1);
|
|
3046
|
+
//const ctx = canvas.getContext("2d");
|
|
3048
3047
|
const image = yield loadImage(imageUrl);
|
|
3049
3048
|
const id = this.randomId();
|
|
3050
3049
|
let newScale = 1;
|
|
@@ -3094,6 +3093,51 @@ class AbstractInteractiveCanvas {
|
|
|
3094
3093
|
}
|
|
3095
3094
|
});
|
|
3096
3095
|
}
|
|
3096
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3097
|
+
const maxSizeScale = 2;
|
|
3098
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3099
|
+
|
|
3100
|
+
const options = { crossOrigin: "anonymous" };
|
|
3101
|
+
|
|
3102
|
+
if (this.headless) {
|
|
3103
|
+
const image = await loadImage(imageUrl);
|
|
3104
|
+
console.log("image-->",image)
|
|
3105
|
+
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3106
|
+
return this.createFabricImage(image, maxWidth);
|
|
3107
|
+
} else {
|
|
3108
|
+
return await new Promise((resolve) => {
|
|
3109
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3110
|
+
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3111
|
+
});
|
|
3112
|
+
});
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3117
|
+
const id = this.randomId();
|
|
3118
|
+
console.log("image inside createfabricimage-->",image)
|
|
3119
|
+
let newScale = 1;
|
|
3120
|
+
const curWidth = newScale * image.width;
|
|
3121
|
+
if (curWidth > maxWidth) {
|
|
3122
|
+
newScale = maxWidth / curWidth;
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
const fabricImage = new FabricImage(image, {
|
|
3126
|
+
id: id,
|
|
3127
|
+
scaleX: newScale,
|
|
3128
|
+
scaleY: newScale,
|
|
3129
|
+
originX: "left",
|
|
3130
|
+
originY: "top",
|
|
3131
|
+
});
|
|
3132
|
+
|
|
3133
|
+
this.fabricCanvas.add(fabricImage);
|
|
3134
|
+
|
|
3135
|
+
const object = new Image(this, fabricImage);
|
|
3136
|
+
this.trackNewObject(object);
|
|
3137
|
+
this.syncObjectList();
|
|
3138
|
+
|
|
3139
|
+
return object;
|
|
3140
|
+
}*/
|
|
3097
3141
|
/**
|
|
3098
3142
|
* @override
|
|
3099
3143
|
* @inheritDoc
|
|
@@ -3063,9 +3063,8 @@ class AbstractInteractiveCanvas {
|
|
|
3063
3063
|
const options = { crossOrigin: "anonymous" };
|
|
3064
3064
|
if (this.headless) {
|
|
3065
3065
|
// Server-side logic without mock DOM
|
|
3066
|
-
|
|
3067
|
-
const
|
|
3068
|
-
canvas$1.getContext("2d");
|
|
3066
|
+
canvas.createCanvas(1, 1);
|
|
3067
|
+
//const ctx = canvas.getContext("2d");
|
|
3069
3068
|
const image = yield canvas.loadImage(imageUrl);
|
|
3070
3069
|
const id = this.randomId();
|
|
3071
3070
|
let newScale = 1;
|
|
@@ -3115,6 +3114,51 @@ class AbstractInteractiveCanvas {
|
|
|
3115
3114
|
}
|
|
3116
3115
|
});
|
|
3117
3116
|
}
|
|
3117
|
+
/* public async addImageObject(imageUrl: string): Promise<IImage> {
|
|
3118
|
+
const maxSizeScale = 2;
|
|
3119
|
+
const maxWidth = this.dimensions$.value.widthPx / maxSizeScale;
|
|
3120
|
+
|
|
3121
|
+
const options = { crossOrigin: "anonymous" };
|
|
3122
|
+
|
|
3123
|
+
if (this.headless) {
|
|
3124
|
+
const image = await loadImage(imageUrl);
|
|
3125
|
+
console.log("image-->",image)
|
|
3126
|
+
console.log("Loaded image:", imageUrl, "Width:", image.width, "Height:", image.height);
|
|
3127
|
+
return this.createFabricImage(image, maxWidth);
|
|
3128
|
+
} else {
|
|
3129
|
+
return await new Promise((resolve) => {
|
|
3130
|
+
this.fabric.Image.fromURL(imageUrl, options).then((fabricImage: FabricImage) => {
|
|
3131
|
+
resolve(this.createFabricImage(fabricImage, maxWidth));
|
|
3132
|
+
});
|
|
3133
|
+
});
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
|
|
3137
|
+
private createFabricImage(image: any, maxWidth: number): IImage {
|
|
3138
|
+
const id = this.randomId();
|
|
3139
|
+
console.log("image inside createfabricimage-->",image)
|
|
3140
|
+
let newScale = 1;
|
|
3141
|
+
const curWidth = newScale * image.width;
|
|
3142
|
+
if (curWidth > maxWidth) {
|
|
3143
|
+
newScale = maxWidth / curWidth;
|
|
3144
|
+
}
|
|
3145
|
+
|
|
3146
|
+
const fabricImage = new FabricImage(image, {
|
|
3147
|
+
id: id,
|
|
3148
|
+
scaleX: newScale,
|
|
3149
|
+
scaleY: newScale,
|
|
3150
|
+
originX: "left",
|
|
3151
|
+
originY: "top",
|
|
3152
|
+
});
|
|
3153
|
+
|
|
3154
|
+
this.fabricCanvas.add(fabricImage);
|
|
3155
|
+
|
|
3156
|
+
const object = new Image(this, fabricImage);
|
|
3157
|
+
this.trackNewObject(object);
|
|
3158
|
+
this.syncObjectList();
|
|
3159
|
+
|
|
3160
|
+
return object;
|
|
3161
|
+
}*/
|
|
3118
3162
|
/**
|
|
3119
3163
|
* @override
|
|
3120
3164
|
* @inheritDoc
|