canvas-editor-engine 1.1.22 → 1.1.24
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.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/services/draw.service.d.ts +6 -5
- package/dist/services/draw.service.js +46 -7
- package/dist/services/projects.service.d.ts +11 -0
- package/dist/services/projects.service.js +98 -0
- package/dist/store/history.state.js +1 -0
- package/dist/types/image.d.ts +4 -0
- package/dist/types/project.d.ts +27 -0
- package/dist/types/project.js +2 -0
- package/dist/utils/project-file-serializer.d.ts +13 -0
- package/dist/utils/project-file-serializer.js +49 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import DownloadService from "./services/download.service";
|
|
|
13
13
|
import ToolLayerService from "./services/tool-layers.service";
|
|
14
14
|
import EventService from "./services/event.service";
|
|
15
15
|
import ThroughHistoryService from "./services/through-history.service";
|
|
16
|
+
import ProjectsService from "./services/projects.service";
|
|
16
17
|
import AppStore from "./store/store";
|
|
17
18
|
declare class CanvasEditorEngine {
|
|
18
19
|
constructor(webComponentTagName?: string);
|
|
@@ -30,4 +31,4 @@ declare class VueCanvasEditorEngine extends CanvasEditorEngine {
|
|
|
30
31
|
getContext2D(): CanvasRenderingContext2D;
|
|
31
32
|
getCanvas(): HTMLCanvasElement;
|
|
32
33
|
}
|
|
33
|
-
export { AppConfig, PipetteComponent, CanvasComponent, ExcretionComponent, SlotComponent, LoadingComponent, ToolService, DrawService, LoggerService, CropService, DownloadService, ToolLayerService, EventService, ThroughHistoryService, StaticCanvasEditorEngine, VueCanvasEditorEngine, AppStore, };
|
|
34
|
+
export { AppConfig, PipetteComponent, CanvasComponent, ExcretionComponent, SlotComponent, LoadingComponent, ToolService, DrawService, LoggerService, CropService, DownloadService, ToolLayerService, EventService, ThroughHistoryService, ProjectsService, StaticCanvasEditorEngine, VueCanvasEditorEngine, AppStore, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppStore = exports.VueCanvasEditorEngine = exports.StaticCanvasEditorEngine = exports.ThroughHistoryService = exports.EventService = exports.ToolLayerService = exports.DownloadService = exports.CropService = exports.LoggerService = exports.DrawService = exports.ToolService = exports.LoadingComponent = exports.SlotComponent = exports.ExcretionComponent = exports.CanvasComponent = exports.PipetteComponent = exports.AppConfig = void 0;
|
|
3
|
+
exports.AppStore = exports.VueCanvasEditorEngine = exports.StaticCanvasEditorEngine = exports.ProjectsService = exports.ThroughHistoryService = exports.EventService = exports.ToolLayerService = exports.DownloadService = exports.CropService = exports.LoggerService = exports.DrawService = exports.ToolService = exports.LoadingComponent = exports.SlotComponent = exports.ExcretionComponent = exports.CanvasComponent = exports.PipetteComponent = exports.AppConfig = void 0;
|
|
4
4
|
const config_1 = require("./config");
|
|
5
5
|
exports.AppConfig = config_1.default;
|
|
6
6
|
const web_component_1 = require("./web-component");
|
|
@@ -30,6 +30,8 @@ const event_service_1 = require("./services/event.service");
|
|
|
30
30
|
exports.EventService = event_service_1.default;
|
|
31
31
|
const through_history_service_1 = require("./services/through-history.service");
|
|
32
32
|
exports.ThroughHistoryService = through_history_service_1.default;
|
|
33
|
+
const projects_service_1 = require("./services/projects.service");
|
|
34
|
+
exports.ProjectsService = projects_service_1.default;
|
|
33
35
|
const store_1 = require("./store/store");
|
|
34
36
|
exports.AppStore = store_1.default;
|
|
35
37
|
class CanvasEditorEngine {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import type { IDrawImageArgs, IFilterOptions, IImageLoggingDataVague, IImageOptions } from "../types/image";
|
|
1
|
+
import type { IDrawImageArgs, IDrawImageProcessor, IFilterOptions, IImageLoggingDataVague, IImageOptions } from "../types/image";
|
|
2
|
+
import { IProject } from "../types/project";
|
|
2
3
|
export default class DrawService {
|
|
3
|
-
static
|
|
4
|
+
static imageProcessor: IDrawImageProcessor;
|
|
4
5
|
static drawImage(ctx: CanvasRenderingContext2D, src: string, options: IDrawImageArgs): void;
|
|
6
|
+
static drawProject(ctx: CanvasRenderingContext2D, project: IProject): void;
|
|
5
7
|
static drawSmoothImage(useStore: boolean, options: IDrawImageArgs, filterOptions: IFilterOptions): void;
|
|
6
8
|
private static updateImageStateAfterVague;
|
|
7
9
|
private static getFilterArgs;
|
|
8
10
|
}
|
|
9
|
-
export declare class SCImage {
|
|
11
|
+
export declare class SCImage implements IDrawImageProcessor {
|
|
10
12
|
private img;
|
|
11
13
|
private ctx;
|
|
12
14
|
constructor(src: string, ctx: CanvasRenderingContext2D);
|
|
13
|
-
|
|
14
|
-
draw(options: IDrawImageArgs): Promise<unknown>;
|
|
15
|
+
draw(options?: IDrawImageArgs): Promise<unknown>;
|
|
15
16
|
vague(options: IImageOptions, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
|
|
16
17
|
}
|
|
@@ -7,10 +7,10 @@ const store_1 = require("../store/store");
|
|
|
7
7
|
const filter_1 = require("../utils/filter");
|
|
8
8
|
const event_service_1 = require("./event.service");
|
|
9
9
|
class DrawService {
|
|
10
|
-
static
|
|
10
|
+
static imageProcessor;
|
|
11
11
|
static drawImage(ctx, src, options) {
|
|
12
|
-
DrawService.
|
|
13
|
-
DrawService.
|
|
12
|
+
DrawService.imageProcessor = new SCImage(src, ctx);
|
|
13
|
+
DrawService.imageProcessor.draw(options).then(() => {
|
|
14
14
|
const filter = new filter_1.Filter(ctx);
|
|
15
15
|
const zeroPosition = {
|
|
16
16
|
x: 0,
|
|
@@ -24,10 +24,26 @@ class DrawService {
|
|
|
24
24
|
}, "Loaded image");
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
+
static drawProject(ctx, project) {
|
|
28
|
+
// const { imageData, position, size } = project.state.current;
|
|
29
|
+
const imageData = project.state.current.imageData;
|
|
30
|
+
const position = project.state.current.position;
|
|
31
|
+
const size = project.state.current.size;
|
|
32
|
+
DrawService.imageProcessor = new PCImage(project, ctx);
|
|
33
|
+
DrawService.imageProcessor.draw();
|
|
34
|
+
store_1.default.store.imageState.reduce({
|
|
35
|
+
tempImageData: imageData,
|
|
36
|
+
position: position,
|
|
37
|
+
size: size,
|
|
38
|
+
}, "Loaded project");
|
|
39
|
+
}
|
|
27
40
|
static drawSmoothImage(useStore, options, filterOptions) {
|
|
28
41
|
const filterArgs = DrawService.getFilterArgs(useStore, options);
|
|
29
42
|
event_service_1.default.dispatch('loading-start');
|
|
30
|
-
|
|
43
|
+
if (!DrawService.imageProcessor) {
|
|
44
|
+
throw new Error('No valid ImageProcessor instance found');
|
|
45
|
+
}
|
|
46
|
+
DrawService.imageProcessor.vague(filterArgs, filterOptions)
|
|
31
47
|
.then(DrawService.updateImageStateAfterVague)
|
|
32
48
|
.finally(() => event_service_1.default.dispatch('loading-end'));
|
|
33
49
|
}
|
|
@@ -76,9 +92,6 @@ class SCImage {
|
|
|
76
92
|
this.ctx = ctx;
|
|
77
93
|
}
|
|
78
94
|
;
|
|
79
|
-
get() {
|
|
80
|
-
return this.img;
|
|
81
|
-
}
|
|
82
95
|
draw(options) {
|
|
83
96
|
const proto = this;
|
|
84
97
|
const protoImg = this.img;
|
|
@@ -111,3 +124,29 @@ class SCImage {
|
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
126
|
exports.SCImage = SCImage;
|
|
127
|
+
class PCImage {
|
|
128
|
+
project;
|
|
129
|
+
ctx;
|
|
130
|
+
constructor(project, ctx) {
|
|
131
|
+
this.project = project;
|
|
132
|
+
this.ctx = ctx;
|
|
133
|
+
}
|
|
134
|
+
draw(options) {
|
|
135
|
+
const { imageData, position } = this.project.state.current;
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
try {
|
|
138
|
+
const filter = new filter_1.Filter(this.ctx);
|
|
139
|
+
filter.update(imageData, position);
|
|
140
|
+
this.ctx.save();
|
|
141
|
+
resolve(this);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
reject(error);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
vague(options, filterOptions) {
|
|
149
|
+
const filter = new filters_1.VagueFilter(this.ctx, options);
|
|
150
|
+
return filter.on('pixel', filterOptions);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IProjectModule, TProjectModuleName } from "../types/project";
|
|
2
|
+
import { ProjectFileSerializer } from "../utils/project-file-serializer";
|
|
3
|
+
export default class ProjectsService {
|
|
4
|
+
private static _modules;
|
|
5
|
+
private static _serializer;
|
|
6
|
+
static on(moduleName: TProjectModuleName): {
|
|
7
|
+
getSerializerInstance: (file: any) => ProjectFileSerializer;
|
|
8
|
+
instance: IProjectModule;
|
|
9
|
+
};
|
|
10
|
+
private static _addModule;
|
|
11
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const project_file_serializer_1 = require("../utils/project-file-serializer");
|
|
4
|
+
class LocalStorageProjectModule {
|
|
5
|
+
projectsKey = 'cee-projects';
|
|
6
|
+
getProjectsFromLocalStorage() {
|
|
7
|
+
const projects = localStorage.getItem(this.projectsKey);
|
|
8
|
+
return projects ? JSON.parse(projects) : [];
|
|
9
|
+
}
|
|
10
|
+
getProjectFromLocalStorage(projectId) {
|
|
11
|
+
const projects = this.getProjectsFromLocalStorage();
|
|
12
|
+
return projects.find((project) => project.id === projectId);
|
|
13
|
+
}
|
|
14
|
+
saveProjectsToLocalStorage(projects) {
|
|
15
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
16
|
+
}
|
|
17
|
+
saveProjectToLocalStorage(project) {
|
|
18
|
+
const projects = this.getProjectsFromLocalStorage();
|
|
19
|
+
projects.push(project);
|
|
20
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
21
|
+
}
|
|
22
|
+
removeProjectFromLocalStorage(projectId) {
|
|
23
|
+
const projects = this.getProjectsFromLocalStorage();
|
|
24
|
+
const index = projects.findIndex((project) => project.id === projectId);
|
|
25
|
+
projects.splice(index, 1);
|
|
26
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
27
|
+
}
|
|
28
|
+
updateProjectInLocalStorage(project) {
|
|
29
|
+
const projects = this.getProjectsFromLocalStorage();
|
|
30
|
+
const index = projects.findIndex((p) => p.id === project.id);
|
|
31
|
+
projects[index] = project;
|
|
32
|
+
localStorage.setItem(this.projectsKey, JSON.stringify(projects));
|
|
33
|
+
}
|
|
34
|
+
getProjects() {
|
|
35
|
+
return this.getProjectsFromLocalStorage();
|
|
36
|
+
}
|
|
37
|
+
getProject(projectId) {
|
|
38
|
+
return this.getProjectFromLocalStorage(projectId);
|
|
39
|
+
}
|
|
40
|
+
saveProjects(projects) {
|
|
41
|
+
this.saveProjectsToLocalStorage(projects);
|
|
42
|
+
}
|
|
43
|
+
saveProject(project) {
|
|
44
|
+
this.saveProjectToLocalStorage(project);
|
|
45
|
+
}
|
|
46
|
+
removeProject(projectId) {
|
|
47
|
+
this.removeProjectFromLocalStorage(projectId);
|
|
48
|
+
}
|
|
49
|
+
updateProject(project) {
|
|
50
|
+
this.updateProjectInLocalStorage(project);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class ProjectFileProjectModule {
|
|
54
|
+
static _serializer;
|
|
55
|
+
static setSerializer(serializer) {
|
|
56
|
+
ProjectFileProjectModule._serializer = serializer;
|
|
57
|
+
}
|
|
58
|
+
getProjects() {
|
|
59
|
+
return ProjectFileProjectModule._serializer.getProjects();
|
|
60
|
+
}
|
|
61
|
+
getProject(projectId) {
|
|
62
|
+
return ProjectFileProjectModule._serializer.getProject(projectId);
|
|
63
|
+
}
|
|
64
|
+
saveProject(project) {
|
|
65
|
+
return ProjectFileProjectModule._serializer.saveProject(project);
|
|
66
|
+
}
|
|
67
|
+
saveProjects(projects) {
|
|
68
|
+
return ProjectFileProjectModule._serializer.saveProjects(projects);
|
|
69
|
+
}
|
|
70
|
+
removeProject(projectId) {
|
|
71
|
+
return ProjectFileProjectModule._serializer.removeProject(projectId);
|
|
72
|
+
}
|
|
73
|
+
updateProject(project) {
|
|
74
|
+
return ProjectFileProjectModule._serializer.updateProject(project);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
class ProjectsService {
|
|
78
|
+
static _modules = [];
|
|
79
|
+
static _serializer = project_file_serializer_1.ProjectFileSerializer;
|
|
80
|
+
static on(moduleName) {
|
|
81
|
+
const module = ProjectsService._modules.find((module) => module.name === moduleName);
|
|
82
|
+
if (!module) {
|
|
83
|
+
throw new Error(`Module ${moduleName} not found`);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
getSerializerInstance: (file) => new ProjectsService._serializer(file),
|
|
87
|
+
instance: module.instance,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
static {
|
|
91
|
+
ProjectsService._addModule('LocalStorage', new LocalStorageProjectModule());
|
|
92
|
+
ProjectsService._addModule('File', new ProjectFileProjectModule());
|
|
93
|
+
}
|
|
94
|
+
static _addModule(name, module) {
|
|
95
|
+
ProjectsService._modules.push({ name, instance: module });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.default = ProjectsService;
|
package/dist/types/image.d.ts
CHANGED
|
@@ -42,3 +42,7 @@ export interface IImageLoggingData {
|
|
|
42
42
|
}
|
|
43
43
|
export interface IImageLoggingDataVague extends IImageLoggingData, IFilterOptions {
|
|
44
44
|
}
|
|
45
|
+
export interface IDrawImageProcessor {
|
|
46
|
+
draw(options?: IDrawImageArgs): Promise<any>;
|
|
47
|
+
vague(options: IImageOptions, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IHistoryLine } from "./history";
|
|
2
|
+
import { IImageLoggingData } from "./image";
|
|
3
|
+
export interface IProject {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
state: {
|
|
8
|
+
current: IImageLoggingData;
|
|
9
|
+
history: IHistoryLine[];
|
|
10
|
+
cache: IHistoryLine[];
|
|
11
|
+
};
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IProjectModule {
|
|
16
|
+
getProjects(): IProject[];
|
|
17
|
+
getProject(projectId: string): IProject;
|
|
18
|
+
saveProjects(projects: IProject[]): void;
|
|
19
|
+
saveProject(project: IProject): void;
|
|
20
|
+
removeProject(projectId: string): void;
|
|
21
|
+
updateProject(project: IProject): void;
|
|
22
|
+
}
|
|
23
|
+
export type TProjectModule = {
|
|
24
|
+
name: string;
|
|
25
|
+
instance: IProjectModule;
|
|
26
|
+
};
|
|
27
|
+
export type TProjectModuleName = 'LocalStorage' | 'File';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IProject } from "../types/project";
|
|
2
|
+
export declare class ProjectFileSerializer {
|
|
3
|
+
private file;
|
|
4
|
+
private projects;
|
|
5
|
+
constructor(file: any);
|
|
6
|
+
private load;
|
|
7
|
+
saveProjects(projects: IProject[]): void;
|
|
8
|
+
getProjects(): IProject[];
|
|
9
|
+
getProject(projectId: string): IProject;
|
|
10
|
+
saveProject(project: IProject): void;
|
|
11
|
+
removeProject(projectId: string): void;
|
|
12
|
+
updateProject(project: IProject): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProjectFileSerializer = void 0;
|
|
4
|
+
class ProjectFileSerializer {
|
|
5
|
+
file;
|
|
6
|
+
projects;
|
|
7
|
+
constructor(file) {
|
|
8
|
+
this.file = file;
|
|
9
|
+
this.projects = this.load();
|
|
10
|
+
}
|
|
11
|
+
;
|
|
12
|
+
load() {
|
|
13
|
+
return JSON.parse(this.file);
|
|
14
|
+
}
|
|
15
|
+
saveProjects(projects) {
|
|
16
|
+
this.file.save(JSON.stringify(projects));
|
|
17
|
+
}
|
|
18
|
+
getProjects() {
|
|
19
|
+
return this.projects;
|
|
20
|
+
}
|
|
21
|
+
getProject(projectId) {
|
|
22
|
+
return this.projects.find((project) => project.id === projectId);
|
|
23
|
+
}
|
|
24
|
+
saveProject(project) {
|
|
25
|
+
const index = this.projects.findIndex((p) => p.id === project.id);
|
|
26
|
+
if (index !== -1) {
|
|
27
|
+
this.projects[index] = project;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.projects.push(project);
|
|
31
|
+
}
|
|
32
|
+
this.saveProjects(this.projects);
|
|
33
|
+
}
|
|
34
|
+
removeProject(projectId) {
|
|
35
|
+
const index = this.projects.findIndex((p) => p.id === projectId);
|
|
36
|
+
if (index !== -1) {
|
|
37
|
+
this.projects.splice(index, 1);
|
|
38
|
+
this.saveProjects(this.projects);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
updateProject(project) {
|
|
42
|
+
const index = this.projects.findIndex((p) => p.id === project.id);
|
|
43
|
+
if (index !== -1) {
|
|
44
|
+
this.projects[index] = project;
|
|
45
|
+
this.saveProjects(this.projects);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ProjectFileSerializer = ProjectFileSerializer;
|