canvas-editor-engine 1.1.48 → 1.2.2
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 +574 -18
- package/dist/index.mjs.js +2 -0
- package/dist/index.mjs.js.LICENSE.txt +8 -0
- package/package.json +36 -30
- package/dist/components/canvas.component.d.ts +0 -21
- package/dist/components/canvas.component.js +0 -90
- package/dist/components/excretions.component.d.ts +0 -32
- package/dist/components/excretions.component.js +0 -280
- package/dist/components/loading.component.d.ts +0 -14
- package/dist/components/loading.component.js +0 -96
- package/dist/components/pipette.component.d.ts +0 -23
- package/dist/components/pipette.component.js +0 -149
- package/dist/components/slot.component.d.ts +0 -10
- package/dist/components/slot.component.js +0 -31
- package/dist/config.d.ts +0 -23
- package/dist/config.js +0 -67
- package/dist/filters/collection/vague.d.ts +0 -13
- package/dist/filters/collection/vague.js +0 -150
- package/dist/filters/index.d.ts +0 -2
- package/dist/filters/index.js +0 -5
- package/dist/index.js +0 -69
- package/dist/services/component.service.d.ts +0 -5
- package/dist/services/component.service.js +0 -37
- package/dist/services/crop.service.d.ts +0 -7
- package/dist/services/crop.service.js +0 -50
- package/dist/services/download.service.d.ts +0 -4
- package/dist/services/download.service.js +0 -15
- package/dist/services/draw.service.d.ts +0 -17
- package/dist/services/draw.service.js +0 -152
- package/dist/services/event.service.d.ts +0 -16
- package/dist/services/event.service.js +0 -35
- package/dist/services/logger.service.d.ts +0 -20
- package/dist/services/logger.service.js +0 -38
- package/dist/services/projects.service.d.ts +0 -11
- package/dist/services/projects.service.js +0 -98
- package/dist/services/pull-project.service.d.ts +0 -8
- package/dist/services/pull-project.service.js +0 -34
- package/dist/services/store.service.d.ts +0 -6
- package/dist/services/store.service.js +0 -11
- package/dist/services/through-history.service.d.ts +0 -12
- package/dist/services/through-history.service.js +0 -49
- package/dist/services/tool-layers.service.d.ts +0 -4
- package/dist/services/tool-layers.service.js +0 -12
- package/dist/services/tool.service.d.ts +0 -10
- package/dist/services/tool.service.js +0 -56
- package/dist/store/history.state.d.ts +0 -15
- package/dist/store/history.state.js +0 -76
- package/dist/store/image.state.d.ts +0 -30
- package/dist/store/image.state.js +0 -70
- package/dist/store/store.d.ts +0 -13
- package/dist/store/store.js +0 -31
- package/dist/types/canvas.d.ts +0 -10
- package/dist/types/canvas.js +0 -3
- package/dist/types/cursor.d.ts +0 -9
- package/dist/types/cursor.js +0 -3
- package/dist/types/excretion.d.ts +0 -27
- package/dist/types/excretion.js +0 -5
- package/dist/types/general.d.ts +0 -24
- package/dist/types/general.js +0 -5
- package/dist/types/history.d.ts +0 -7
- package/dist/types/history.js +0 -2
- package/dist/types/image.d.ts +0 -48
- package/dist/types/image.js +0 -10
- package/dist/types/log.d.ts +0 -13
- package/dist/types/log.js +0 -5
- package/dist/types/pipette.d.ts +0 -1
- package/dist/types/pipette.js +0 -2
- package/dist/types/project.d.ts +0 -38
- package/dist/types/project.js +0 -14
- package/dist/utils/convert.d.ts +0 -12
- package/dist/utils/convert.js +0 -27
- package/dist/utils/filter.d.ts +0 -21
- package/dist/utils/filter.js +0 -150
- package/dist/utils/guid4.d.ts +0 -13
- package/dist/utils/guid4.js +0 -111
- package/dist/utils/project-file-serializer.d.ts +0 -13
- package/dist/utils/project-file-serializer.js +0 -79
- package/dist/web-component.d.ts +0 -26
- package/dist/web-component.js +0 -108
package/dist/config.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigFabric = exports.ConfigStore = void 0;
|
|
4
|
-
;
|
|
5
|
-
class ConfigStore {
|
|
6
|
-
static _WEB_COMPONENT_TAG_NAME;
|
|
7
|
-
static _CANVAS_SIZE;
|
|
8
|
-
static _LAYERS;
|
|
9
|
-
}
|
|
10
|
-
exports.ConfigStore = ConfigStore;
|
|
11
|
-
class ConfigFabric {
|
|
12
|
-
static _WEB_COMPONENT_TAG_NAME;
|
|
13
|
-
static _CANVAS_SIZE;
|
|
14
|
-
static _LAYERS;
|
|
15
|
-
}
|
|
16
|
-
exports.ConfigFabric = ConfigFabric;
|
|
17
|
-
class AppConfig extends ConfigFabric {
|
|
18
|
-
static {
|
|
19
|
-
AppConfig._CANVAS_SIZE = {
|
|
20
|
-
width: 300,
|
|
21
|
-
height: 150,
|
|
22
|
-
};
|
|
23
|
-
AppConfig._WEB_COMPONENT_TAG_NAME = 'canvas-editor-engine';
|
|
24
|
-
AppConfig._LAYERS = [
|
|
25
|
-
{
|
|
26
|
-
name: 'low',
|
|
27
|
-
index: 1,
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: 'normal',
|
|
31
|
-
index: 2,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'high',
|
|
35
|
-
index: 3,
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
static get WEB_COMPONENT_TAG_NAME() {
|
|
40
|
-
return AppConfig._WEB_COMPONENT_TAG_NAME;
|
|
41
|
-
}
|
|
42
|
-
static set WEB_COMPONENT_TAG_NAME(value) {
|
|
43
|
-
if (!!value && typeof value === 'string') {
|
|
44
|
-
AppConfig._WEB_COMPONENT_TAG_NAME = value;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
static get CANVAS_SIZE() {
|
|
48
|
-
return AppConfig._CANVAS_SIZE;
|
|
49
|
-
}
|
|
50
|
-
static set CANVAS_SIZE(value) {
|
|
51
|
-
if (!!value && !!value?.width && !!value?.height) {
|
|
52
|
-
AppConfig._CANVAS_SIZE = value;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
console.warn('CANVAS_SIZE denied');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
static get LAYERS() {
|
|
59
|
-
return AppConfig._LAYERS;
|
|
60
|
-
}
|
|
61
|
-
static set LAYERS(value) {
|
|
62
|
-
if (!!value && !!value?.length) {
|
|
63
|
-
AppConfig._LAYERS = value;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.default = AppConfig;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { IFilterOptions, IImageLoggingDataVague, IImageOptions, TFilterMethod } from "../../types/image";
|
|
2
|
-
import { Filter } from "../../utils/filter";
|
|
3
|
-
export default class VagueFilter extends Filter {
|
|
4
|
-
options: IImageOptions;
|
|
5
|
-
filterList: TFilterMethod[];
|
|
6
|
-
constructor(ctx: CanvasRenderingContext2D, options: IImageOptions);
|
|
7
|
-
on(action: TFilterMethod, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
|
|
8
|
-
pixel(imageData: ImageData, filterOptions: IFilterOptions): ImageData;
|
|
9
|
-
private getQualityProcessedRemainder;
|
|
10
|
-
private getQualityBuff;
|
|
11
|
-
private getMostCommonQuanlityBuff;
|
|
12
|
-
private getMostCommonElement;
|
|
13
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const filter_1 = require("../../utils/filter");
|
|
4
|
-
const convert_1 = require("../../utils/convert");
|
|
5
|
-
const lodash_1 = require("lodash");
|
|
6
|
-
class VagueFilter extends filter_1.Filter {
|
|
7
|
-
options;
|
|
8
|
-
filterList = ['pixel'];
|
|
9
|
-
constructor(ctx, options) {
|
|
10
|
-
super(ctx);
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
on(action, filterOptions) {
|
|
14
|
-
return new Promise((resolve) => {
|
|
15
|
-
const options = this.options;
|
|
16
|
-
const imageData = this.copy(options);
|
|
17
|
-
// TODO: rewrite on pattern Strategies
|
|
18
|
-
const rowImageData = this[action](imageData, filterOptions);
|
|
19
|
-
this.update(rowImageData, options);
|
|
20
|
-
return resolve({
|
|
21
|
-
imageData: rowImageData,
|
|
22
|
-
position: {
|
|
23
|
-
x: options.x,
|
|
24
|
-
y: options.y,
|
|
25
|
-
},
|
|
26
|
-
size: {
|
|
27
|
-
width: rowImageData.width,
|
|
28
|
-
height: rowImageData.height,
|
|
29
|
-
},
|
|
30
|
-
quality: filterOptions.quality,
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
pixel(imageData, filterOptions) {
|
|
35
|
-
const { quality } = filterOptions;
|
|
36
|
-
console.log('quality', quality);
|
|
37
|
-
// expansion strategy
|
|
38
|
-
const processedImageData = this.getQualityProcessedRemainder(imageData, +quality);
|
|
39
|
-
// TODO: add compression strategy and use register strategies;
|
|
40
|
-
const imageSize = {
|
|
41
|
-
width: processedImageData.width,
|
|
42
|
-
height: processedImageData.height,
|
|
43
|
-
};
|
|
44
|
-
console.log('imageSize', imageSize);
|
|
45
|
-
this.setImageSize(imageSize);
|
|
46
|
-
const { rowRGBABuff, buff } = this.getBuffCollection(processedImageData);
|
|
47
|
-
const { qualityBuff, rangeCommit } = this.getQualityBuff(buff, +quality);
|
|
48
|
-
const qualityBuffWithMostCommonElement = this.getMostCommonQuanlityBuff(qualityBuff, rangeCommit);
|
|
49
|
-
const rowQualityBuffWithMostCommonElement = qualityBuffWithMostCommonElement.flat();
|
|
50
|
-
if (rowRGBABuff.length >= rowQualityBuffWithMostCommonElement.length) {
|
|
51
|
-
const occurrenceRGBAbuff = rowQualityBuffWithMostCommonElement.map((hexColor, index) => {
|
|
52
|
-
const { r, g, b } = convert_1.Convert.hexToRgb(hexColor);
|
|
53
|
-
const a = rowRGBABuff[index][3];
|
|
54
|
-
return [r, g, b, a];
|
|
55
|
-
});
|
|
56
|
-
const rowBuff = occurrenceRGBAbuff.flat();
|
|
57
|
-
rowBuff.forEach((color, index) => {
|
|
58
|
-
processedImageData.data[index] = color;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return processedImageData;
|
|
62
|
-
}
|
|
63
|
-
getQualityProcessedRemainder(imageData, quality) {
|
|
64
|
-
const rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
65
|
-
const RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, { width: imageData.width, height: imageData.height });
|
|
66
|
-
const cqx = quality - (imageData.width % quality);
|
|
67
|
-
const cqy = quality - (imageData.height % quality);
|
|
68
|
-
const xCommit = (0, lodash_1.range)(0, cqx);
|
|
69
|
-
const yCommit = (0, lodash_1.range)(0, cqy);
|
|
70
|
-
const tempSize = {
|
|
71
|
-
width: imageData.width + cqx,
|
|
72
|
-
height: imageData.height + cqy,
|
|
73
|
-
};
|
|
74
|
-
const xLastIndex = RGBAMatrix[0].length - 1;
|
|
75
|
-
RGBAMatrix.forEach((row, y) => {
|
|
76
|
-
const xLastRGBAByte = row[xLastIndex];
|
|
77
|
-
xCommit.forEach(() => RGBAMatrix[y].push(xLastRGBAByte));
|
|
78
|
-
});
|
|
79
|
-
const yLastIndex = RGBAMatrix.length - 1;
|
|
80
|
-
const yLastRGBARow = RGBAMatrix[yLastIndex];
|
|
81
|
-
yCommit.forEach(() => RGBAMatrix.push(yLastRGBARow));
|
|
82
|
-
const buffWithRemainder = RGBAMatrix.flat(2);
|
|
83
|
-
const tempCanvas = document.createElement('canvas');
|
|
84
|
-
const tempCtx = tempCanvas.getContext('2d');
|
|
85
|
-
const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
86
|
-
buffWithRemainder.forEach((_, i) => tempImageData.data[i] = buffWithRemainder[i]);
|
|
87
|
-
return tempImageData;
|
|
88
|
-
}
|
|
89
|
-
getQualityBuff(buff, quality) {
|
|
90
|
-
const wq = Math.floor(this.imageSize.width / quality);
|
|
91
|
-
const hq = Math.floor(this.imageSize.height / quality);
|
|
92
|
-
const qualityBuff = [];
|
|
93
|
-
const rangeCommit = [];
|
|
94
|
-
let i = 0;
|
|
95
|
-
let xStart = 0;
|
|
96
|
-
let xEnd = quality;
|
|
97
|
-
let yStart = 0;
|
|
98
|
-
let yEnd = quality;
|
|
99
|
-
(0, lodash_1.range)(0, hq).forEach((hqi) => {
|
|
100
|
-
(0, lodash_1.range)(0, wq).forEach((wqi) => {
|
|
101
|
-
const dy = (0, lodash_1.range)(yStart, yEnd);
|
|
102
|
-
const dx = (0, lodash_1.range)(xStart, xEnd);
|
|
103
|
-
const items = [];
|
|
104
|
-
const coords = [];
|
|
105
|
-
dy.forEach((y) => {
|
|
106
|
-
dx.forEach((x) => {
|
|
107
|
-
items.push(buff[y][x]);
|
|
108
|
-
coords.push({ y, x });
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
xStart += quality;
|
|
112
|
-
xEnd += quality;
|
|
113
|
-
rangeCommit[i] ??= coords;
|
|
114
|
-
qualityBuff[i] ??= items;
|
|
115
|
-
i++;
|
|
116
|
-
});
|
|
117
|
-
xStart = 0;
|
|
118
|
-
xEnd = quality;
|
|
119
|
-
yStart += quality;
|
|
120
|
-
yEnd += quality;
|
|
121
|
-
});
|
|
122
|
-
return { qualityBuff, rangeCommit };
|
|
123
|
-
}
|
|
124
|
-
getMostCommonQuanlityBuff(qualityBuff, rangeCommit) {
|
|
125
|
-
const mostCommonQuanlityBuff = [];
|
|
126
|
-
const qualityBuffWithMostCommonElement = qualityBuff.map((newPixel) => {
|
|
127
|
-
const color = this.getMostCommonElement(newPixel);
|
|
128
|
-
return newPixel.map(() => color);
|
|
129
|
-
});
|
|
130
|
-
qualityBuffWithMostCommonElement.forEach((qPixel, pixelIndex) => {
|
|
131
|
-
qPixel.forEach((pixelColor, pixelColorIndex) => {
|
|
132
|
-
const { x, y } = rangeCommit[pixelIndex][pixelColorIndex];
|
|
133
|
-
mostCommonQuanlityBuff[y] ??= [];
|
|
134
|
-
mostCommonQuanlityBuff[y][x] ??= pixelColor;
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
return mostCommonQuanlityBuff;
|
|
138
|
-
}
|
|
139
|
-
getMostCommonElement(array) {
|
|
140
|
-
function mostCommon(a, b) {
|
|
141
|
-
const diffA = array.filter((v) => v === a).length;
|
|
142
|
-
const diffB = array.filter((v) => v === b).length;
|
|
143
|
-
return diffA - diffB;
|
|
144
|
-
}
|
|
145
|
-
const arraySorted = array.sort(mostCommon);
|
|
146
|
-
const mostCommonElement = arraySorted[arraySorted.length - 1];
|
|
147
|
-
return mostCommonElement;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.default = VagueFilter;
|
package/dist/filters/index.d.ts
DELETED
package/dist/filters/index.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppStore = exports.VueCanvasEditorEngine = exports.StaticCanvasEditorEngine = exports.PullProjectService = 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
|
-
const config_1 = require("./config");
|
|
5
|
-
exports.AppConfig = config_1.default;
|
|
6
|
-
const web_component_1 = require("./web-component");
|
|
7
|
-
const canvas_component_1 = require("./components/canvas.component");
|
|
8
|
-
exports.CanvasComponent = canvas_component_1.default;
|
|
9
|
-
const pipette_component_1 = require("./components/pipette.component");
|
|
10
|
-
exports.PipetteComponent = pipette_component_1.default;
|
|
11
|
-
const excretions_component_1 = require("./components/excretions.component");
|
|
12
|
-
exports.ExcretionComponent = excretions_component_1.default;
|
|
13
|
-
const slot_component_1 = require("./components/slot.component");
|
|
14
|
-
exports.SlotComponent = slot_component_1.default;
|
|
15
|
-
const loading_component_1 = require("./components/loading.component");
|
|
16
|
-
exports.LoadingComponent = loading_component_1.default;
|
|
17
|
-
const draw_service_1 = require("./services/draw.service");
|
|
18
|
-
exports.DrawService = draw_service_1.default;
|
|
19
|
-
const tool_service_1 = require("./services/tool.service");
|
|
20
|
-
exports.ToolService = tool_service_1.default;
|
|
21
|
-
const logger_service_1 = require("./services/logger.service");
|
|
22
|
-
exports.LoggerService = logger_service_1.default;
|
|
23
|
-
const crop_service_1 = require("./services/crop.service");
|
|
24
|
-
exports.CropService = crop_service_1.default;
|
|
25
|
-
const download_service_1 = require("./services/download.service");
|
|
26
|
-
exports.DownloadService = download_service_1.default;
|
|
27
|
-
const tool_layers_service_1 = require("./services/tool-layers.service");
|
|
28
|
-
exports.ToolLayerService = tool_layers_service_1.default;
|
|
29
|
-
const event_service_1 = require("./services/event.service");
|
|
30
|
-
exports.EventService = event_service_1.default;
|
|
31
|
-
const through_history_service_1 = require("./services/through-history.service");
|
|
32
|
-
exports.ThroughHistoryService = through_history_service_1.default;
|
|
33
|
-
const projects_service_1 = require("./services/projects.service");
|
|
34
|
-
exports.ProjectsService = projects_service_1.default;
|
|
35
|
-
const pull_project_service_1 = require("./services/pull-project.service");
|
|
36
|
-
exports.PullProjectService = pull_project_service_1.default;
|
|
37
|
-
const store_1 = require("./store/store");
|
|
38
|
-
exports.AppStore = store_1.default;
|
|
39
|
-
class CanvasEditorEngine {
|
|
40
|
-
constructor(webComponentTagName) {
|
|
41
|
-
config_1.default.WEB_COMPONENT_TAG_NAME = webComponentTagName;
|
|
42
|
-
}
|
|
43
|
-
getInitial() {
|
|
44
|
-
return { tag: config_1.default.WEB_COMPONENT_TAG_NAME, component: web_component_1.default };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
class StaticCanvasEditorEngine extends CanvasEditorEngine {
|
|
48
|
-
constructor(webComponentTagName) {
|
|
49
|
-
super(webComponentTagName);
|
|
50
|
-
}
|
|
51
|
-
init() {
|
|
52
|
-
const customElementRegistry = window.customElements;
|
|
53
|
-
const { tag, component } = this.getInitial();
|
|
54
|
-
customElementRegistry.define(tag, component);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.StaticCanvasEditorEngine = StaticCanvasEditorEngine;
|
|
58
|
-
class VueCanvasEditorEngine extends CanvasEditorEngine {
|
|
59
|
-
constructor(webComponentTagName) {
|
|
60
|
-
super(webComponentTagName);
|
|
61
|
-
}
|
|
62
|
-
getContext2D() {
|
|
63
|
-
return canvas_component_1.default.ctx;
|
|
64
|
-
}
|
|
65
|
-
getCanvas() {
|
|
66
|
-
return canvas_component_1.default.canvas;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.VueCanvasEditorEngine = VueCanvasEditorEngine;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class ComponentService {
|
|
4
|
-
static getTemplate(template, wrapOptions) {
|
|
5
|
-
const options = {
|
|
6
|
-
tag: 'div',
|
|
7
|
-
};
|
|
8
|
-
if (!!wrapOptions) {
|
|
9
|
-
Object.keys(wrapOptions).forEach((key) => {
|
|
10
|
-
if (!!wrapOptions[key]) {
|
|
11
|
-
options[key] = wrapOptions[key];
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
const wrap = document.createElement(options.tag);
|
|
16
|
-
if (!!options) {
|
|
17
|
-
Object.keys(options).forEach((key) => {
|
|
18
|
-
if (!!options[key] && key !== 'tag') {
|
|
19
|
-
wrap[key] = options[key];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (!!template) {
|
|
24
|
-
wrap.innerHTML = template;
|
|
25
|
-
}
|
|
26
|
-
return wrap;
|
|
27
|
-
}
|
|
28
|
-
static getStyle(css) {
|
|
29
|
-
if (!!css === false)
|
|
30
|
-
return null;
|
|
31
|
-
const style = document.createElement('style');
|
|
32
|
-
style.type = 'text/css';
|
|
33
|
-
style.appendChild(document.createTextNode(css));
|
|
34
|
-
return style;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.default = ComponentService;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const excretions_component_1 = require("../components/excretions.component");
|
|
4
|
-
const config_1 = require("../config");
|
|
5
|
-
const store_1 = require("../store/store");
|
|
6
|
-
const filter_1 = require("../utils/filter");
|
|
7
|
-
class CropService {
|
|
8
|
-
static setup() {
|
|
9
|
-
excretions_component_1.default.additionStyle = 'crop';
|
|
10
|
-
}
|
|
11
|
-
static crop(ctx) {
|
|
12
|
-
if (!!excretions_component_1.default.excretionsCoords?.length === false)
|
|
13
|
-
return;
|
|
14
|
-
const filter = new filter_1.Filter(ctx);
|
|
15
|
-
const options = CropService.options;
|
|
16
|
-
const { imageData, size } = filter.copyExtendedModel(options);
|
|
17
|
-
const position = {
|
|
18
|
-
x: (config_1.default.CANVAS_SIZE.width / 2) - (size.width / 2),
|
|
19
|
-
y: (config_1.default.CANVAS_SIZE.height / 2) - (size.height / 2),
|
|
20
|
-
};
|
|
21
|
-
filter.update(imageData, position);
|
|
22
|
-
store_1.default.store.imageState.reduce({
|
|
23
|
-
tempImageData: imageData,
|
|
24
|
-
position: position,
|
|
25
|
-
size: {
|
|
26
|
-
width: size.width,
|
|
27
|
-
height: size.height,
|
|
28
|
-
}
|
|
29
|
-
}, "Use crop");
|
|
30
|
-
}
|
|
31
|
-
static viewCropButton() {
|
|
32
|
-
const cropButtons = excretions_component_1.default.excretionWrap.querySelectorAll('.crop-button');
|
|
33
|
-
const lastCropButtonIndex = cropButtons.length - 1;
|
|
34
|
-
const cropButton = cropButtons[lastCropButtonIndex];
|
|
35
|
-
cropButton.classList.add('crop-button--view');
|
|
36
|
-
}
|
|
37
|
-
static get options() {
|
|
38
|
-
const excretionLastIndex = excretions_component_1.default.excretionsCoords.length - 1;
|
|
39
|
-
const coords = excretions_component_1.default.excretionsCoords[excretionLastIndex];
|
|
40
|
-
const excWidth = Math.abs(coords.start.x - coords.end.x);
|
|
41
|
-
const excHeight = Math.abs(coords.start.y - coords.end.y);
|
|
42
|
-
return {
|
|
43
|
-
x: coords.start.x,
|
|
44
|
-
y: coords.start.y,
|
|
45
|
-
width: excWidth,
|
|
46
|
-
height: excHeight,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.default = CropService;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const canvas_component_1 = require("../components/canvas.component");
|
|
4
|
-
class DownloadService {
|
|
5
|
-
static getDataUrl() {
|
|
6
|
-
return canvas_component_1.default.canvas.toDataURL();
|
|
7
|
-
}
|
|
8
|
-
static download(filename) {
|
|
9
|
-
const link = document.createElement('a');
|
|
10
|
-
link.download = `${filename || 'image'}.png`;
|
|
11
|
-
link.href = DownloadService.getDataUrl();
|
|
12
|
-
link.click();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.default = DownloadService;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { IDrawImageArgs, IDrawImageProcessor, IFilterOptions, IImageLoggingDataVague, IImageOptions } from "../types/image";
|
|
2
|
-
import { Project } from "../types/project";
|
|
3
|
-
export default class DrawService {
|
|
4
|
-
static imageProcessor: IDrawImageProcessor;
|
|
5
|
-
static drawImage(ctx: CanvasRenderingContext2D, src: string, options: IDrawImageArgs): void;
|
|
6
|
-
static drawProject(ctx: CanvasRenderingContext2D, project: Project): void;
|
|
7
|
-
static drawSmoothImage(useStore: boolean, options: IDrawImageArgs, filterOptions: IFilterOptions): void;
|
|
8
|
-
private static updateImageStateAfterVague;
|
|
9
|
-
private static getFilterArgs;
|
|
10
|
-
}
|
|
11
|
-
export declare class SCImage implements IDrawImageProcessor {
|
|
12
|
-
private img;
|
|
13
|
-
private ctx;
|
|
14
|
-
constructor(src: string, ctx: CanvasRenderingContext2D);
|
|
15
|
-
draw(options?: IDrawImageArgs): Promise<unknown>;
|
|
16
|
-
vague(options: IImageOptions, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
|
|
17
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SCImage = void 0;
|
|
4
|
-
const config_1 = require("../config");
|
|
5
|
-
const filters_1 = require("../filters");
|
|
6
|
-
const store_1 = require("../store/store");
|
|
7
|
-
const filter_1 = require("../utils/filter");
|
|
8
|
-
const event_service_1 = require("./event.service");
|
|
9
|
-
class DrawService {
|
|
10
|
-
static imageProcessor;
|
|
11
|
-
static drawImage(ctx, src, options) {
|
|
12
|
-
DrawService.imageProcessor = new SCImage(src, ctx);
|
|
13
|
-
DrawService.imageProcessor.draw(options).then(() => {
|
|
14
|
-
const filter = new filter_1.Filter(ctx);
|
|
15
|
-
const zeroPosition = {
|
|
16
|
-
x: 0,
|
|
17
|
-
y: 0,
|
|
18
|
-
};
|
|
19
|
-
const imageData = filter.copy(zeroPosition);
|
|
20
|
-
store_1.default.store.imageState.reduce({
|
|
21
|
-
tempImageData: imageData,
|
|
22
|
-
position: zeroPosition,
|
|
23
|
-
size: config_1.default.CANVAS_SIZE,
|
|
24
|
-
}, "Loaded image");
|
|
25
|
-
});
|
|
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
|
-
}
|
|
40
|
-
static drawSmoothImage(useStore, options, filterOptions) {
|
|
41
|
-
const filterArgs = DrawService.getFilterArgs(useStore, options);
|
|
42
|
-
event_service_1.default.dispatch('loading-start');
|
|
43
|
-
if (!DrawService.imageProcessor) {
|
|
44
|
-
throw new Error('No valid ImageProcessor instance found');
|
|
45
|
-
}
|
|
46
|
-
DrawService.imageProcessor.vague(filterArgs, filterOptions)
|
|
47
|
-
.then(DrawService.updateImageStateAfterVague)
|
|
48
|
-
.finally(() => event_service_1.default.dispatch('loading-end'));
|
|
49
|
-
}
|
|
50
|
-
static updateImageStateAfterVague(data) {
|
|
51
|
-
const { imageData, position, size, quality } = data;
|
|
52
|
-
store_1.default.store.imageState.reduce({
|
|
53
|
-
tempImageData: imageData,
|
|
54
|
-
position: position,
|
|
55
|
-
size: size,
|
|
56
|
-
}, `[Filter Vague] quality: ${quality}`);
|
|
57
|
-
}
|
|
58
|
-
static getFilterArgs(useStore, options) {
|
|
59
|
-
let filterArgs;
|
|
60
|
-
const store = store_1.default.store.imageState;
|
|
61
|
-
if (useStore) {
|
|
62
|
-
filterArgs = {
|
|
63
|
-
x: store.position.x,
|
|
64
|
-
y: store.position.y,
|
|
65
|
-
};
|
|
66
|
-
if (!!store.size.width && !!store.size.height) {
|
|
67
|
-
filterArgs.width = store.size.width;
|
|
68
|
-
filterArgs.height = store.size.height;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
filterArgs = {
|
|
73
|
-
x: options.position.x,
|
|
74
|
-
y: options.position.y,
|
|
75
|
-
};
|
|
76
|
-
if (options.size !== 'initial') {
|
|
77
|
-
if (!!options.size?.width && !!options.size?.height) {
|
|
78
|
-
filterArgs.width = options.size.width;
|
|
79
|
-
filterArgs.height = options.size.height;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return filterArgs;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.default = DrawService;
|
|
87
|
-
class SCImage {
|
|
88
|
-
img = new Image();
|
|
89
|
-
ctx;
|
|
90
|
-
constructor(src, ctx) {
|
|
91
|
-
this.img.src = src;
|
|
92
|
-
this.ctx = ctx;
|
|
93
|
-
}
|
|
94
|
-
;
|
|
95
|
-
draw(options) {
|
|
96
|
-
const proto = this;
|
|
97
|
-
const protoImg = this.img;
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
try {
|
|
100
|
-
protoImg.addEventListener("load", () => {
|
|
101
|
-
let drawImageArgs = [options.position.x, options.position.y];
|
|
102
|
-
if (options.size !== 'initial') {
|
|
103
|
-
if (!!options.size?.width && !!options.size?.height) {
|
|
104
|
-
drawImageArgs = drawImageArgs.concat([options.size.width, options.size.height]);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
drawImageArgs = drawImageArgs.concat([config_1.default.CANVAS_SIZE.width, config_1.default.CANVAS_SIZE.height]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
this.ctx.drawImage(protoImg, ...drawImageArgs);
|
|
112
|
-
this.ctx.save();
|
|
113
|
-
resolve(proto);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
reject(error);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
vague(options, filterOptions) {
|
|
122
|
-
const filter = new filters_1.VagueFilter(this.ctx, options);
|
|
123
|
-
return filter.on('pixel', filterOptions);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
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
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { IGUID4 } from "../types/general";
|
|
2
|
-
export declare abstract class ControlEvent {
|
|
3
|
-
name: string;
|
|
4
|
-
action: (args?: any) => any;
|
|
5
|
-
}
|
|
6
|
-
export declare class EventAtom implements ControlEvent {
|
|
7
|
-
id: IGUID4;
|
|
8
|
-
name: string;
|
|
9
|
-
action: (args?: any) => any;
|
|
10
|
-
}
|
|
11
|
-
export default class EventService {
|
|
12
|
-
static eventList: EventAtom[];
|
|
13
|
-
static subcribe(controlEvent: ControlEvent): void;
|
|
14
|
-
static dispatch(name: ControlEvent['name'], eventArgs?: any): void;
|
|
15
|
-
static applyEvents(baseElement: HTMLDivElement): void;
|
|
16
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventAtom = exports.ControlEvent = void 0;
|
|
4
|
-
const guid4_1 = require("../utils/guid4");
|
|
5
|
-
class ControlEvent {
|
|
6
|
-
name;
|
|
7
|
-
action;
|
|
8
|
-
}
|
|
9
|
-
exports.ControlEvent = ControlEvent;
|
|
10
|
-
class EventAtom {
|
|
11
|
-
id;
|
|
12
|
-
name;
|
|
13
|
-
action;
|
|
14
|
-
}
|
|
15
|
-
exports.EventAtom = EventAtom;
|
|
16
|
-
class EventService {
|
|
17
|
-
static eventList = [];
|
|
18
|
-
static subcribe(controlEvent) {
|
|
19
|
-
const eventAtom = {
|
|
20
|
-
id: new guid4_1.Guid4().generate(),
|
|
21
|
-
...controlEvent
|
|
22
|
-
};
|
|
23
|
-
EventService.eventList.push(eventAtom);
|
|
24
|
-
}
|
|
25
|
-
static dispatch(name, eventArgs) {
|
|
26
|
-
const eventAtom = EventService.eventList.find((event) => event.name === name);
|
|
27
|
-
eventAtom.action(eventArgs);
|
|
28
|
-
}
|
|
29
|
-
static applyEvents(baseElement) {
|
|
30
|
-
EventService.eventList?.forEach((event) => {
|
|
31
|
-
baseElement.addEventListener(event.name, event.action);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = EventService;
|