canvas-editor-engine 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/Readme.md +118 -0
- package/dist/components/canvas.component.d.ts +21 -0
- package/dist/components/canvas.component.js +75 -0
- package/dist/components/excretions.component.d.ts +24 -0
- package/dist/components/excretions.component.js +192 -0
- package/dist/components/pipette.component.d.ts +23 -0
- package/dist/components/pipette.component.js +138 -0
- package/dist/components/slot.component.d.ts +10 -0
- package/dist/components/slot.component.js +20 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.js +29 -0
- package/dist/filters/collection/vague.d.ts +12 -0
- package/dist/filters/collection/vague.js +107 -0
- package/dist/filters/index.d.ts +2 -0
- package/dist/filters/index.js +5 -0
- package/dist/images/image.png +0 -0
- package/dist/images/sample.png +0 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +49 -0
- package/dist/services/component.service.d.ts +5 -0
- package/dist/services/component.service.js +37 -0
- package/dist/services/draw.service.d.ts +13 -0
- package/dist/services/draw.service.js +71 -0
- package/dist/services/tool.service.d.ts +10 -0
- package/dist/services/tool.service.js +58 -0
- package/dist/types/canvas.d.ts +10 -0
- package/dist/types/canvas.js +3 -0
- package/dist/types/cursor.d.ts +9 -0
- package/dist/types/cursor.js +3 -0
- package/dist/types/excreation.d.ts +24 -0
- package/dist/types/excreation.js +5 -0
- package/dist/types/excretion.d.ts +26 -0
- package/dist/types/excretion.js +5 -0
- package/dist/types/general.d.ts +14 -0
- package/dist/types/general.js +4 -0
- package/dist/types/image.d.ts +36 -0
- package/dist/types/image.js +7 -0
- package/dist/types/pipette.d.ts +1 -0
- package/dist/types/pipette.js +2 -0
- package/dist/utils/convert.d.ts +12 -0
- package/dist/utils/convert.js +27 -0
- package/dist/utils/filter.d.ts +16 -0
- package/dist/utils/filter.js +61 -0
- package/dist/web-component.d.ts +10 -0
- package/dist/web-component.js +60 -0
- package/package.json +30 -0
@@ -0,0 +1,107 @@
|
|
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
|
+
constructor(ctx, options) {
|
8
|
+
super(ctx);
|
9
|
+
this.filterList = ['pixel'];
|
10
|
+
this.options = options;
|
11
|
+
}
|
12
|
+
on(action, filterOptions) {
|
13
|
+
const imageData = this.copy(this.options);
|
14
|
+
const rowImageData = this[action](imageData, filterOptions);
|
15
|
+
this.update(rowImageData, this.options);
|
16
|
+
}
|
17
|
+
pixel(imageData, filterOptions) {
|
18
|
+
const imageSize = {
|
19
|
+
w: imageData.width,
|
20
|
+
h: imageData.height,
|
21
|
+
};
|
22
|
+
this.setImageSize(imageSize);
|
23
|
+
const { quality } = filterOptions;
|
24
|
+
console.log('quality', quality);
|
25
|
+
const { rowRGBABuff, buff } = this.getBuffCollection(imageData);
|
26
|
+
const { qualityBuff, rangeCommit } = this.getQualityBuff(buff, +quality);
|
27
|
+
const qualityBuffWithMostCommonElement = this.getMostCommonQuanlityBuff(qualityBuff, rangeCommit);
|
28
|
+
const rowQualityBuffWithMostCommonElement = qualityBuffWithMostCommonElement.flat();
|
29
|
+
if (rowRGBABuff.length >= rowQualityBuffWithMostCommonElement.length) {
|
30
|
+
const occurrenceRGBAbuff = rowQualityBuffWithMostCommonElement.map((hexColor, index) => {
|
31
|
+
const { r, g, b } = convert_1.Convert.hexToRgb(hexColor);
|
32
|
+
const a = rowRGBABuff[index][3];
|
33
|
+
return [r, g, b, a];
|
34
|
+
});
|
35
|
+
const rowBuff = occurrenceRGBAbuff.flat();
|
36
|
+
rowBuff.forEach((color, index) => {
|
37
|
+
imageData.data[index] = color;
|
38
|
+
});
|
39
|
+
console.log('imageData', imageData);
|
40
|
+
}
|
41
|
+
return imageData;
|
42
|
+
}
|
43
|
+
getQualityBuff(buff, quality) {
|
44
|
+
const wq = Math.floor(this.imageSize.w / quality);
|
45
|
+
const hq = Math.floor(this.imageSize.h / quality);
|
46
|
+
const qualityBuff = [];
|
47
|
+
const rangeCommit = [];
|
48
|
+
let i = 0;
|
49
|
+
let xStart = 0;
|
50
|
+
let xEnd = quality;
|
51
|
+
let yStart = 0;
|
52
|
+
let yEnd = quality;
|
53
|
+
(0, lodash_1.range)(0, hq).forEach((hqi) => {
|
54
|
+
(0, lodash_1.range)(0, wq).forEach((wqi) => {
|
55
|
+
var _a, _b;
|
56
|
+
const dy = (0, lodash_1.range)(yStart, yEnd);
|
57
|
+
const dx = (0, lodash_1.range)(xStart, xEnd);
|
58
|
+
const items = [];
|
59
|
+
const coords = [];
|
60
|
+
dy.forEach((y) => {
|
61
|
+
dx.forEach((x) => {
|
62
|
+
items.push(buff[y][x]);
|
63
|
+
coords.push({ y, x });
|
64
|
+
});
|
65
|
+
});
|
66
|
+
xStart += quality;
|
67
|
+
xEnd += quality;
|
68
|
+
(_a = rangeCommit[i]) !== null && _a !== void 0 ? _a : (rangeCommit[i] = coords);
|
69
|
+
(_b = qualityBuff[i]) !== null && _b !== void 0 ? _b : (qualityBuff[i] = items);
|
70
|
+
i++;
|
71
|
+
});
|
72
|
+
xStart = 0;
|
73
|
+
xEnd = quality;
|
74
|
+
yStart += quality;
|
75
|
+
yEnd += quality;
|
76
|
+
});
|
77
|
+
return { qualityBuff, rangeCommit };
|
78
|
+
}
|
79
|
+
getMostCommonQuanlityBuff(qualityBuff, rangeCommit) {
|
80
|
+
const mostCommonQuanlityBuff = [];
|
81
|
+
const qualityBuffWithMostCommonElement = qualityBuff.map((newPixel) => {
|
82
|
+
const color = this.getMostCommonElement(newPixel);
|
83
|
+
return newPixel.map(() => color);
|
84
|
+
});
|
85
|
+
qualityBuffWithMostCommonElement.forEach((qPixel, pixelIndex) => {
|
86
|
+
qPixel.forEach((pixelColor, pixelColorIndex) => {
|
87
|
+
var _a, _b;
|
88
|
+
var _c;
|
89
|
+
const { x, y } = rangeCommit[pixelIndex][pixelColorIndex];
|
90
|
+
(_a = mostCommonQuanlityBuff[y]) !== null && _a !== void 0 ? _a : (mostCommonQuanlityBuff[y] = []);
|
91
|
+
(_b = (_c = mostCommonQuanlityBuff[y])[x]) !== null && _b !== void 0 ? _b : (_c[x] = pixelColor);
|
92
|
+
});
|
93
|
+
});
|
94
|
+
return mostCommonQuanlityBuff;
|
95
|
+
}
|
96
|
+
getMostCommonElement(array) {
|
97
|
+
function mostCommon(a, b) {
|
98
|
+
const diffA = array.filter((v) => v === a).length;
|
99
|
+
const diffB = array.filter((v) => v === b).length;
|
100
|
+
return diffA - diffB;
|
101
|
+
}
|
102
|
+
const arraySorted = array.sort(mostCommon);
|
103
|
+
const mostCommonElement = arraySorted[arraySorted.length - 1];
|
104
|
+
return mostCommonElement;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
exports.default = VagueFilter;
|
Binary file
|
Binary file
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
import AppConfig from "./config";
|
2
|
+
import WebComponent from "./web-component";
|
3
|
+
import CanvasComponent from "./components/canvas.component";
|
4
|
+
import PipetteComponent from "./components/pipette.component";
|
5
|
+
import ExcretionComponent from "./components/excretions.component";
|
6
|
+
import SlotComponent from "./components/slot.component";
|
7
|
+
import DrawService from "./services/draw.service";
|
8
|
+
import ToolService from "./services/tool.service";
|
9
|
+
declare class CanvasEditorEngine {
|
10
|
+
constructor(webComponentTagName?: string);
|
11
|
+
getInitial(): {
|
12
|
+
tag: string;
|
13
|
+
component: typeof WebComponent;
|
14
|
+
};
|
15
|
+
}
|
16
|
+
declare class StaticCanvasEditorEngine extends CanvasEditorEngine {
|
17
|
+
constructor(webComponentTagName?: string);
|
18
|
+
init(): void;
|
19
|
+
}
|
20
|
+
declare class VueCanvasEditorEngine extends CanvasEditorEngine {
|
21
|
+
constructor(webComponentTagName?: string);
|
22
|
+
getContext2D(): CanvasRenderingContext2D;
|
23
|
+
getCanvas(): HTMLCanvasElement;
|
24
|
+
}
|
25
|
+
export { AppConfig, PipetteComponent, CanvasComponent, ExcretionComponent, SlotComponent, ToolService, DrawService, StaticCanvasEditorEngine, VueCanvasEditorEngine, };
|
package/dist/index.js
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.VueCanvasEditorEngine = exports.StaticCanvasEditorEngine = exports.DrawService = exports.ToolService = 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 draw_service_1 = require("./services/draw.service");
|
16
|
+
exports.DrawService = draw_service_1.default;
|
17
|
+
const tool_service_1 = require("./services/tool.service");
|
18
|
+
exports.ToolService = tool_service_1.default;
|
19
|
+
class CanvasEditorEngine {
|
20
|
+
constructor(webComponentTagName) {
|
21
|
+
config_1.default.WEB_COMPONENT_TAG_NAME = webComponentTagName;
|
22
|
+
}
|
23
|
+
getInitial() {
|
24
|
+
return { tag: config_1.default.WEB_COMPONENT_TAG_NAME, component: web_component_1.default };
|
25
|
+
}
|
26
|
+
}
|
27
|
+
class StaticCanvasEditorEngine extends CanvasEditorEngine {
|
28
|
+
constructor(webComponentTagName) {
|
29
|
+
super(webComponentTagName);
|
30
|
+
}
|
31
|
+
init() {
|
32
|
+
const customElementRegistry = window.customElements;
|
33
|
+
const { tag, component } = this.getInitial();
|
34
|
+
customElementRegistry.define(tag, component);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
exports.StaticCanvasEditorEngine = StaticCanvasEditorEngine;
|
38
|
+
class VueCanvasEditorEngine extends CanvasEditorEngine {
|
39
|
+
constructor(webComponentTagName) {
|
40
|
+
super(webComponentTagName);
|
41
|
+
}
|
42
|
+
getContext2D() {
|
43
|
+
return canvas_component_1.default.ctx;
|
44
|
+
}
|
45
|
+
getCanvas() {
|
46
|
+
return canvas_component_1.default.canvas;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
exports.VueCanvasEditorEngine = VueCanvasEditorEngine;
|
@@ -0,0 +1,37 @@
|
|
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;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { IDrawImageArgs, IFilterOptions, IImageOptions } from "../types/image";
|
2
|
+
export default class DrawService {
|
3
|
+
static drawImage(ctx: CanvasRenderingContext2D, src: string, options: IDrawImageArgs): void;
|
4
|
+
static drawSmoothImage(ctx: CanvasRenderingContext2D, src: string, options: IDrawImageArgs, filterOptions: IFilterOptions): void;
|
5
|
+
}
|
6
|
+
export declare class SCImage {
|
7
|
+
private img;
|
8
|
+
private ctx;
|
9
|
+
constructor(src: string, ctx: CanvasRenderingContext2D);
|
10
|
+
get(): HTMLImageElement;
|
11
|
+
draw(options: IDrawImageArgs): Promise<unknown>;
|
12
|
+
vague(options: IImageOptions, filterOptions: IFilterOptions): void;
|
13
|
+
}
|
@@ -0,0 +1,71 @@
|
|
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
|
+
class DrawService {
|
7
|
+
static drawImage(ctx, src, options) {
|
8
|
+
const img = new SCImage(src, ctx);
|
9
|
+
img.draw(options);
|
10
|
+
}
|
11
|
+
static drawSmoothImage(ctx, src, options, filterOptions) {
|
12
|
+
var _a, _b;
|
13
|
+
const img = new SCImage(src, ctx);
|
14
|
+
const filterArgs = {
|
15
|
+
x: options.position.x,
|
16
|
+
y: options.position.y,
|
17
|
+
};
|
18
|
+
if (options.size !== 'initial') {
|
19
|
+
if (!!((_a = options.size) === null || _a === void 0 ? void 0 : _a.width) && !!((_b = options.size) === null || _b === void 0 ? void 0 : _b.height)) {
|
20
|
+
filterArgs.width = options.size.width;
|
21
|
+
filterArgs.height = options.size.height;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
console.log('filterArgs', filterArgs);
|
25
|
+
img.draw(options).then(() => img.vague(filterArgs, filterOptions));
|
26
|
+
}
|
27
|
+
}
|
28
|
+
exports.default = DrawService;
|
29
|
+
class SCImage {
|
30
|
+
constructor(src, ctx) {
|
31
|
+
this.img = new Image();
|
32
|
+
this.img.src = src;
|
33
|
+
this.ctx = ctx;
|
34
|
+
}
|
35
|
+
;
|
36
|
+
get() {
|
37
|
+
return this.img;
|
38
|
+
}
|
39
|
+
draw(options) {
|
40
|
+
const proto = this;
|
41
|
+
const protoImg = this.img;
|
42
|
+
return new Promise((resolve, reject) => {
|
43
|
+
try {
|
44
|
+
protoImg.addEventListener("load", () => {
|
45
|
+
var _a, _b;
|
46
|
+
let drawImageArgs = [options.position.x, options.position.y];
|
47
|
+
if (options.size !== 'initial') {
|
48
|
+
if (!!((_a = options.size) === null || _a === void 0 ? void 0 : _a.width) && !!((_b = options.size) === null || _b === void 0 ? void 0 : _b.height)) {
|
49
|
+
drawImageArgs = drawImageArgs.concat([options.size.width, options.size.height]);
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
drawImageArgs = drawImageArgs.concat([config_1.default.CANVAS_SIZE.width, config_1.default.CANVAS_SIZE.height]);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
// @ts-ignore
|
56
|
+
this.ctx.drawImage(protoImg, ...drawImageArgs);
|
57
|
+
this.ctx.save();
|
58
|
+
resolve(proto);
|
59
|
+
});
|
60
|
+
}
|
61
|
+
catch (error) {
|
62
|
+
reject(error);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
}
|
66
|
+
vague(options, filterOptions) {
|
67
|
+
const filter = new filters_1.VagueFilter(this.ctx, options);
|
68
|
+
filter.on('pixel', filterOptions);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
exports.SCImage = SCImage;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { ITool } from "../types/general";
|
2
|
+
export default class ToolService {
|
3
|
+
static before: ITool | null;
|
4
|
+
static active: ITool | null;
|
5
|
+
static registry: ITool[];
|
6
|
+
static add(tool: ITool): boolean;
|
7
|
+
static setActive(id: ITool['id']): void;
|
8
|
+
static offActive(id?: ITool['id']): void;
|
9
|
+
private static off;
|
10
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const canvas_component_1 = require("../components/canvas.component");
|
4
|
+
class ToolService {
|
5
|
+
static add(tool) {
|
6
|
+
const hasRegisteredTool = ToolService.registry.find((registeredTool) => registeredTool.id === tool.id);
|
7
|
+
if (hasRegisteredTool) {
|
8
|
+
console.warn('Tool has been previously registered!');
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
ToolService.registry.push(tool);
|
12
|
+
return true;
|
13
|
+
}
|
14
|
+
static setActive(id) {
|
15
|
+
var _a, _b, _c;
|
16
|
+
if (((_a = ToolService.active) === null || _a === void 0 ? void 0 : _a.id) === id)
|
17
|
+
return console.warn('Tool is already active');
|
18
|
+
if (!!((_b = ToolService.active) === null || _b === void 0 ? void 0 : _b.offAction)) {
|
19
|
+
ToolService.active.offAction();
|
20
|
+
}
|
21
|
+
const registeredTool = ToolService.registry.find((registeredTool) => registeredTool.id === id);
|
22
|
+
if (!!registeredTool) {
|
23
|
+
ToolService.active = registeredTool;
|
24
|
+
if (!!((_c = ToolService.active) === null || _c === void 0 ? void 0 : _c.onAction)) {
|
25
|
+
ToolService.active.onAction();
|
26
|
+
}
|
27
|
+
}
|
28
|
+
else {
|
29
|
+
console.warn('Tool has not previously been registered with this identifier');
|
30
|
+
}
|
31
|
+
}
|
32
|
+
static offActive(id) {
|
33
|
+
if (!!id) {
|
34
|
+
if (ToolService.active.id === id) {
|
35
|
+
ToolService.off();
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
return console.warn(`ID active tool is not "${id}"`);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
ToolService.off();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
static off() {
|
46
|
+
var _a;
|
47
|
+
if (!!((_a = ToolService.active) === null || _a === void 0 ? void 0 : _a.offAction)) {
|
48
|
+
ToolService.active.offAction();
|
49
|
+
}
|
50
|
+
ToolService.before = ToolService.active;
|
51
|
+
ToolService.active = null;
|
52
|
+
canvas_component_1.default.cursorStyle = 'default';
|
53
|
+
}
|
54
|
+
}
|
55
|
+
ToolService.before = null;
|
56
|
+
ToolService.active = null;
|
57
|
+
ToolService.registry = [];
|
58
|
+
exports.default = ToolService;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { ICursorPosition } from "./cursor";
|
2
|
+
export interface ICanvasSize {
|
3
|
+
width: number;
|
4
|
+
height: number;
|
5
|
+
}
|
6
|
+
export type TSubscriptionTypes = 'click' | 'mousemove' | 'mousedown' | 'mouseup';
|
7
|
+
export type TSubscribeAction = (event: MouseEvent, cursorPosition?: ICursorPosition) => void;
|
8
|
+
export type TSubscriptions = {
|
9
|
+
[key in TSubscriptionTypes]: TSubscribeAction[];
|
10
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export interface ICursorPosition {
|
2
|
+
x: number;
|
3
|
+
y: number;
|
4
|
+
}
|
5
|
+
export interface ICursorStyle {
|
6
|
+
before: TCursorStyleName | null;
|
7
|
+
current: TCursorStyleName | null;
|
8
|
+
}
|
9
|
+
export type TCursorStyleName = 'default' | 'context-menu' | 'help' | 'pointer' | 'progress' | 'wait' | 'cell' | 'crosshair' | 'text' | 'vertical-text' | 'copy' | 'alias' | 'move' | 'not-allowed' | 'grab' | 'grabbing' | 'zoom-in' | 'zoom-out';
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export interface IExcretionsCoords {
|
2
|
+
start?: {
|
3
|
+
x: number;
|
4
|
+
y: number;
|
5
|
+
};
|
6
|
+
end?: {
|
7
|
+
x: number;
|
8
|
+
y: number;
|
9
|
+
};
|
10
|
+
}
|
11
|
+
export interface IExcretionTempStart {
|
12
|
+
start: {
|
13
|
+
x: number;
|
14
|
+
y: number;
|
15
|
+
};
|
16
|
+
}
|
17
|
+
export interface IExcretionTempEnd {
|
18
|
+
end: {
|
19
|
+
x: number;
|
20
|
+
y: number;
|
21
|
+
};
|
22
|
+
}
|
23
|
+
export type TExcretionTempCoords = (IExcretionTempStart | IExcretionTempEnd)[];
|
24
|
+
export type TExcretionState = 'create' | 'add' | 'remove' | 'end' | 'abandoned';
|
@@ -0,0 +1,26 @@
|
|
1
|
+
export interface IExcretionsCoords {
|
2
|
+
start?: {
|
3
|
+
x: number;
|
4
|
+
y: number;
|
5
|
+
};
|
6
|
+
end?: {
|
7
|
+
x: number;
|
8
|
+
y: number;
|
9
|
+
};
|
10
|
+
}
|
11
|
+
export interface IExcretionTempStart {
|
12
|
+
start: {
|
13
|
+
x: number;
|
14
|
+
y: number;
|
15
|
+
};
|
16
|
+
}
|
17
|
+
export interface IExcretionTempEnd {
|
18
|
+
end: {
|
19
|
+
x: number;
|
20
|
+
y: number;
|
21
|
+
};
|
22
|
+
}
|
23
|
+
export type TExcretionTempCoords = (IExcretionTempStart | IExcretionTempEnd)[];
|
24
|
+
export type TExcretionToolState = 'taken' | 'abandoned';
|
25
|
+
export type TExcretionState = 'create' | 'add' | 'remove' | 'abandoned';
|
26
|
+
export type TExcretionActivity = 'active' | 'end' | 'abandoned';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export type THEXColor = `#${string}`;
|
2
|
+
export type TComponent = HTMLElement | HTMLDivElement | HTMLCanvasElement;
|
3
|
+
export interface IWrapOptions {
|
4
|
+
tag?: string;
|
5
|
+
className?: string;
|
6
|
+
id?: string;
|
7
|
+
}
|
8
|
+
export interface ITool {
|
9
|
+
id: number;
|
10
|
+
name: string;
|
11
|
+
onAction?: (...args: any) => void;
|
12
|
+
offAction?: (...args: any) => void;
|
13
|
+
support?: (...args: any) => void;
|
14
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
export interface IImageOptions {
|
2
|
+
x: number;
|
3
|
+
y: number;
|
4
|
+
width?: number;
|
5
|
+
height?: number;
|
6
|
+
}
|
7
|
+
export interface IDrawImageArgs {
|
8
|
+
position: IArgumentImagePosition;
|
9
|
+
size?: TArgumentImageSize;
|
10
|
+
}
|
11
|
+
export interface IArgumentImagePosition {
|
12
|
+
x: number;
|
13
|
+
y: number;
|
14
|
+
}
|
15
|
+
export type TArgumentImageSize = IOptionImageSize | 'initial';
|
16
|
+
export interface IOptionImageSize {
|
17
|
+
width?: number;
|
18
|
+
height?: number;
|
19
|
+
}
|
20
|
+
export interface IImageSize {
|
21
|
+
w: number;
|
22
|
+
h: number;
|
23
|
+
}
|
24
|
+
export interface IPixelPosition {
|
25
|
+
x: number;
|
26
|
+
y: number;
|
27
|
+
}
|
28
|
+
export type TRGBABuff = TByteRGBColor[];
|
29
|
+
export type TByteRGBColor = [number, number, number, number];
|
30
|
+
export type TBuff = string[][];
|
31
|
+
export type TQualityBuff = string[][];
|
32
|
+
export type TRangeCommit = IPixelPosition[][];
|
33
|
+
export type TFilterMethod = 'pixel';
|
34
|
+
export interface IFilterOptions {
|
35
|
+
quality: number;
|
36
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export type TPipetteState = 'taken' | 'abandoned' | 'selected-color';
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { TByteRGBColor } from "../types/image";
|
2
|
+
import type { THEXColor } from "../types/general";
|
3
|
+
export declare class Convert {
|
4
|
+
static byteRGBToHEX(color: TByteRGBColor): THEXColor;
|
5
|
+
static rgbToHex(r: number, g: number, b: number): THEXColor;
|
6
|
+
static hexToRgb(hex: string): {
|
7
|
+
r: number;
|
8
|
+
g: number;
|
9
|
+
b: number;
|
10
|
+
};
|
11
|
+
private static componentToHEX;
|
12
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Convert = void 0;
|
4
|
+
class Convert {
|
5
|
+
static byteRGBToHEX(color) {
|
6
|
+
const red = color[0];
|
7
|
+
const green = color[1];
|
8
|
+
const blue = color[2];
|
9
|
+
return Convert.rgbToHex(red, green, blue);
|
10
|
+
}
|
11
|
+
static rgbToHex(r, g, b) {
|
12
|
+
return `#${Convert.componentToHEX(r)}${Convert.componentToHEX(g)}${Convert.componentToHEX(b)}`;
|
13
|
+
}
|
14
|
+
static hexToRgb(hex) {
|
15
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
16
|
+
return result ? {
|
17
|
+
r: parseInt(result[1], 16),
|
18
|
+
g: parseInt(result[2], 16),
|
19
|
+
b: parseInt(result[3], 16)
|
20
|
+
} : null;
|
21
|
+
}
|
22
|
+
static componentToHEX(colorComponent) {
|
23
|
+
const hex = colorComponent.toString(16);
|
24
|
+
return hex.length == 1 ? "0" + hex : hex;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
exports.Convert = Convert;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { IImageOptions, IImageSize, TBuff, TRGBABuff } from "../types/image";
|
2
|
+
export declare class Filter {
|
3
|
+
ctx: CanvasRenderingContext2D;
|
4
|
+
imageSize: IImageSize;
|
5
|
+
constructor(ctx: CanvasRenderingContext2D);
|
6
|
+
setImageSize(size: IImageSize): void;
|
7
|
+
copy(options: IImageOptions): ImageData;
|
8
|
+
update(imgData: ImageData, options: IImageOptions): void;
|
9
|
+
getBuffCollection(imageData: ImageData): {
|
10
|
+
rowRGBABuff: TRGBABuff;
|
11
|
+
hexBuff: `#${string}`[];
|
12
|
+
buff: TBuff;
|
13
|
+
};
|
14
|
+
private getBuff;
|
15
|
+
private getRowRGBABuff;
|
16
|
+
}
|