canvas-editor-engine 2.2.6 → 2.3.1
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/index.mjs
CHANGED
@@ -2120,6 +2120,25 @@ var VagueFilter = function(_super) {
|
|
2120
2120
|
return VagueFilter;
|
2121
2121
|
}(Filter);
|
2122
2122
|
|
2123
|
+
var TempCanvas = function() {
|
2124
|
+
function TempCanvas() {
|
2125
|
+
this.canvas = document.createElement("canvas");
|
2126
|
+
this.ctx = this.canvas.getContext("2d");
|
2127
|
+
}
|
2128
|
+
TempCanvas.prototype.bindOptions = function(options) {
|
2129
|
+
this.canvas.width = options.width;
|
2130
|
+
this.canvas.height = options.height;
|
2131
|
+
this.ctx = this.canvas.getContext("2d");
|
2132
|
+
};
|
2133
|
+
TempCanvas.prototype.destroy = function() {
|
2134
|
+
this.canvas.remove();
|
2135
|
+
};
|
2136
|
+
TempCanvas.prototype.getImageData = function() {
|
2137
|
+
return this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height);
|
2138
|
+
};
|
2139
|
+
return TempCanvas;
|
2140
|
+
}();
|
2141
|
+
|
2123
2142
|
var DrawAccumulator = function() {
|
2124
2143
|
function DrawAccumulator(appConfig, appStoreRepository, eventService, drawLayersService) {
|
2125
2144
|
this.appConfig = appConfig;
|
@@ -2156,7 +2175,7 @@ var DrawAccumulator = function() {
|
|
2156
2175
|
}
|
2157
2176
|
});
|
2158
2177
|
}
|
2159
|
-
DrawAccumulator.prototype.add = function(layerId, drawType, options) {
|
2178
|
+
DrawAccumulator.prototype.add = function(layerId, drawType, options, initialSize) {
|
2160
2179
|
return __awaiter(this, void 0, void 0, (function() {
|
2161
2180
|
var id, painter, inStore;
|
2162
2181
|
return __generator(this, (function(_a) {
|
@@ -2167,6 +2186,7 @@ var DrawAccumulator = function() {
|
|
2167
2186
|
id
|
2168
2187
|
};
|
2169
2188
|
painter.drawService.bindOptions(drawType, options);
|
2189
|
+
painter.drawService.tempCanvas.bindOptions(initialSize);
|
2170
2190
|
this.painters.push({
|
2171
2191
|
object: painter,
|
2172
2192
|
update: this.update.bind(this)
|
@@ -2231,7 +2251,7 @@ var DrawAccumulator = function() {
|
|
2231
2251
|
}));
|
2232
2252
|
if (!layer) return;
|
2233
2253
|
if (!stash.includes(painter) && layer.order === order) {
|
2234
|
-
_this.
|
2254
|
+
_this.invokePainterWithTempCtx(painter.drawType, painter.drawService);
|
2235
2255
|
stash.push(painter);
|
2236
2256
|
}
|
2237
2257
|
}));
|
@@ -2275,6 +2295,23 @@ var DrawAccumulator = function() {
|
|
2275
2295
|
}));
|
2276
2296
|
}));
|
2277
2297
|
};
|
2298
|
+
DrawAccumulator.prototype.invokePainterWithTempCtx = function(drawType, painter) {
|
2299
|
+
return __awaiter(this, void 0, void 0, (function() {
|
2300
|
+
var imageData, ctx, x, y;
|
2301
|
+
return __generator(this, (function(_a) {
|
2302
|
+
imageData = painter.tempCanvas.getImageData();
|
2303
|
+
ctx = this.appConfig.canvas.getContext("2d");
|
2304
|
+
if (drawType === "image") {
|
2305
|
+
x = painter.options.image.drawImageArgs.position.x;
|
2306
|
+
y = painter.options.image.drawImageArgs.position.y;
|
2307
|
+
ctx.putImageData(imageData, x, y);
|
2308
|
+
} else if (drawType === "project") {
|
2309
|
+
ctx.putImageData(imageData, 0, 0);
|
2310
|
+
}
|
2311
|
+
return [ 2 ];
|
2312
|
+
}));
|
2313
|
+
}));
|
2314
|
+
};
|
2278
2315
|
return DrawAccumulator;
|
2279
2316
|
}();
|
2280
2317
|
|
@@ -2287,6 +2324,7 @@ var DrawService = function() {
|
|
2287
2324
|
image: null,
|
2288
2325
|
project: null
|
2289
2326
|
};
|
2327
|
+
this.tempCanvas = new TempCanvas;
|
2290
2328
|
this.id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
2291
2329
|
}
|
2292
2330
|
DrawService.prototype.bindOptions = function(drawType, options) {
|
@@ -2303,7 +2341,7 @@ var DrawService = function() {
|
|
2303
2341
|
switch (_b.label) {
|
2304
2342
|
case 0:
|
2305
2343
|
_a = this.options.image, src = _a.src, drawImageArgs = _a.drawImageArgs;
|
2306
|
-
ctx = this.
|
2344
|
+
ctx = this.tempCanvas.ctx;
|
2307
2345
|
this.imageProcessor = new ImageObject(this.appConfig, src, ctx);
|
2308
2346
|
return [ 4, this.imageProcessor.draw(drawImageArgs).then((function() {
|
2309
2347
|
var responseData = {
|
@@ -2341,7 +2379,7 @@ var DrawService = function() {
|
|
2341
2379
|
}
|
2342
2380
|
return __generator(this, (function(_a) {
|
2343
2381
|
project = this.options.project;
|
2344
|
-
ctx = this.
|
2382
|
+
ctx = this.tempCanvas.ctx;
|
2345
2383
|
imageData = project.state.current.imageData;
|
2346
2384
|
position = project.state.current.position;
|
2347
2385
|
size = project.state.current.size;
|
@@ -2729,7 +2767,7 @@ var WebComponent = function(_super) {
|
|
2729
2767
|
var projectProcessor = this.projectsService.on("File");
|
2730
2768
|
var serializer = projectProcessor.getSerializerInstance(jsonProjects);
|
2731
2769
|
var projects = serializer.getProjects();
|
2732
|
-
this.drawAccumulator.add(layerId, "project", projects[0]);
|
2770
|
+
this.drawAccumulator.add(layerId, "project", projects[0], projects[0].state.current.size);
|
2733
2771
|
this.throughHistoryService.recovery(projects[0]);
|
2734
2772
|
};
|
2735
2773
|
return WebComponent;
|
@@ -5,6 +5,8 @@ import { ILayer } from "../types/draw-layers";
|
|
5
5
|
import { IPainter, TDrawType } from "../types/draw-service";
|
6
6
|
import type { IDrawImageArgs, IDrawImageProcessor, IFilterOptions, IImageLoggingDataVague, IImageOptions } from "../types/image";
|
7
7
|
import { Project } from "../types/project";
|
8
|
+
import { ITempCanvasOptions } from "../types/temp-canvas";
|
9
|
+
import { TempCanvas } from "../utils/temp-canvas";
|
8
10
|
import DrawLayersService from "./draw-leayers.service";
|
9
11
|
import EventService from "./event.service";
|
10
12
|
export declare class DrawAccumulator {
|
@@ -14,13 +16,14 @@ export declare class DrawAccumulator {
|
|
14
16
|
private drawLayersService;
|
15
17
|
painters: IPainter[];
|
16
18
|
constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService, drawLayersService: DrawLayersService);
|
17
|
-
add<DrawType extends TDrawType>(layerId: ILayer['id'], drawType: DrawType, options: DrawService['options'][DrawType]): Promise<void>;
|
19
|
+
add<DrawType extends TDrawType>(layerId: ILayer['id'], drawType: DrawType, options: DrawService['options'][DrawType], initialSize: ITempCanvasOptions): Promise<void>;
|
18
20
|
remove(id: string): Promise<void>;
|
19
21
|
private update;
|
20
22
|
private get gradient();
|
21
23
|
private clearCanvas;
|
22
24
|
private invokePaintersOnLayers;
|
23
25
|
private invokePainter;
|
26
|
+
private invokePainterWithTempCtx;
|
24
27
|
}
|
25
28
|
export default class DrawService {
|
26
29
|
private appConfig;
|
@@ -35,6 +38,7 @@ export default class DrawService {
|
|
35
38
|
} | null;
|
36
39
|
project: Project | null;
|
37
40
|
};
|
41
|
+
tempCanvas: TempCanvas;
|
38
42
|
constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService);
|
39
43
|
bindOptions<DrawType extends TDrawType>(drawType: DrawType, options: DrawService['options'][DrawType]): void;
|
40
44
|
drawImage(isReturnReduceData?: boolean): Promise<{
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ITempCanvasOptions } from "../types/temp-canvas";
|
2
|
+
export declare class TempCanvas {
|
3
|
+
ctx: CanvasRenderingContext2D;
|
4
|
+
canvas: HTMLCanvasElement;
|
5
|
+
constructor();
|
6
|
+
bindOptions(options: ITempCanvasOptions): void;
|
7
|
+
destroy(): void;
|
8
|
+
getImageData(): ImageData;
|
9
|
+
}
|