canvas-editor-engine 1.2.1 → 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
|
@@ -1,27 +0,0 @@
|
|
|
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';
|
|
27
|
-
export type TExcretionStyle = 'default' | 'crop';
|
package/dist/types/excretion.js
DELETED
package/dist/types/general.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
}
|
|
15
|
-
export type IGUID4 = `${number}-${number}-${number}-${number}`;
|
|
16
|
-
export interface IPosition {
|
|
17
|
-
x: number;
|
|
18
|
-
y: number;
|
|
19
|
-
}
|
|
20
|
-
export interface ISize {
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
}
|
|
24
|
-
export type TStringMatrix = string[][];
|
package/dist/types/general.js
DELETED
package/dist/types/history.d.ts
DELETED
package/dist/types/history.js
DELETED
package/dist/types/image.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { IPosition, ISize, TStringMatrix } from "./general";
|
|
2
|
-
export interface IOptionImageSize {
|
|
3
|
-
width?: number;
|
|
4
|
-
height?: number;
|
|
5
|
-
}
|
|
6
|
-
export interface IImageOptions extends IPosition, IOptionImageSize {
|
|
7
|
-
}
|
|
8
|
-
export interface IDrawImageArgs {
|
|
9
|
-
position: IArgumentImagePosition;
|
|
10
|
-
size?: TArgumentImageSize;
|
|
11
|
-
}
|
|
12
|
-
export interface IArgumentImagePosition extends IPosition {
|
|
13
|
-
}
|
|
14
|
-
export interface IPixelPosition extends IPosition {
|
|
15
|
-
}
|
|
16
|
-
export type TArgumentImageSize = IOptionImageSize | 'initial';
|
|
17
|
-
export interface IImageSize extends ISize {
|
|
18
|
-
}
|
|
19
|
-
export type TRGBABuff = TByteRGBColor[];
|
|
20
|
-
export type TByteRGBColor = [number, number, number, number];
|
|
21
|
-
export type TBuff<T> = T[][];
|
|
22
|
-
export type TQualityBuff = TStringMatrix;
|
|
23
|
-
export type TRangeCommit = IPixelPosition[][];
|
|
24
|
-
export type TFilterMethod = 'pixel';
|
|
25
|
-
export interface IFilterOptions {
|
|
26
|
-
quality: number;
|
|
27
|
-
}
|
|
28
|
-
export declare const enum E_RGBA {
|
|
29
|
-
r = 0,
|
|
30
|
-
g = 1,
|
|
31
|
-
b = 2,
|
|
32
|
-
a = 3
|
|
33
|
-
}
|
|
34
|
-
export interface IExtendedImageDataModel {
|
|
35
|
-
imageData: ImageData;
|
|
36
|
-
size: ISize;
|
|
37
|
-
}
|
|
38
|
-
export interface IImageLoggingData {
|
|
39
|
-
imageData: ImageData;
|
|
40
|
-
size: ISize;
|
|
41
|
-
position: IPosition;
|
|
42
|
-
}
|
|
43
|
-
export interface IImageLoggingDataVague extends IImageLoggingData, IFilterOptions {
|
|
44
|
-
}
|
|
45
|
-
export interface IDrawImageProcessor {
|
|
46
|
-
draw(options?: IDrawImageArgs): Promise<any>;
|
|
47
|
-
vague(options: IImageOptions, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
|
|
48
|
-
}
|
package/dist/types/image.js
DELETED
package/dist/types/log.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface ILog<A, R, P> {
|
|
2
|
-
components: ILogItem<A>[];
|
|
3
|
-
services: ILogItem<R>[];
|
|
4
|
-
planed: ILogItem<P>[];
|
|
5
|
-
}
|
|
6
|
-
export interface ILogItem<TLogPrototype> {
|
|
7
|
-
info: ILogItemInfo;
|
|
8
|
-
prototype: TLogPrototype;
|
|
9
|
-
}
|
|
10
|
-
export interface ILogItemInfo {
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
}
|
package/dist/types/log.js
DELETED
package/dist/types/pipette.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type TPipetteState = 'taken' | 'abandoned' | 'selected-color';
|
package/dist/types/pipette.js
DELETED
package/dist/types/project.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { IHistoryLine } from "./history";
|
|
2
|
-
import { IImageLoggingData } from "./image";
|
|
3
|
-
export declare class Project {
|
|
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 IUpdateProject {
|
|
16
|
-
id?: string;
|
|
17
|
-
name?: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
state?: {
|
|
20
|
-
current: IImageLoggingData;
|
|
21
|
-
history: IHistoryLine[];
|
|
22
|
-
cache: IHistoryLine[];
|
|
23
|
-
};
|
|
24
|
-
updatedAt?: string;
|
|
25
|
-
}
|
|
26
|
-
export interface IProjectModule {
|
|
27
|
-
getProjects(): Project[];
|
|
28
|
-
getProject(projectId: string): Project;
|
|
29
|
-
saveProjects(projects: Project[]): void;
|
|
30
|
-
saveProject(project: Project): void;
|
|
31
|
-
removeProject(projectId: string): void;
|
|
32
|
-
updateProject(project: Project): void;
|
|
33
|
-
}
|
|
34
|
-
export type TProjectModule = {
|
|
35
|
-
name: string;
|
|
36
|
-
instance: IProjectModule;
|
|
37
|
-
};
|
|
38
|
-
export type TProjectModuleName = 'LocalStorage' | 'File';
|
package/dist/types/project.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Project = void 0;
|
|
4
|
-
class Project {
|
|
5
|
-
id = null;
|
|
6
|
-
name = null;
|
|
7
|
-
description = null;
|
|
8
|
-
state = null;
|
|
9
|
-
createdAt = new Date(Date.now()).toString();
|
|
10
|
-
updatedAt = new Date(Date.now()).toString();
|
|
11
|
-
}
|
|
12
|
-
exports.Project = Project;
|
|
13
|
-
;
|
|
14
|
-
;
|
package/dist/utils/convert.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/utils/convert.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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;
|
package/dist/utils/filter.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { IExtendedImageDataModel, type IImageOptions, type IImageSize, type TBuff, type TRGBABuff } from "../types/image";
|
|
2
|
-
import type { ISize, THEXColor } from '../types/general';
|
|
3
|
-
export declare class Filter {
|
|
4
|
-
ctx: CanvasRenderingContext2D;
|
|
5
|
-
imageSize: IImageSize;
|
|
6
|
-
constructor(ctx: CanvasRenderingContext2D);
|
|
7
|
-
setImageSize(size: IImageSize): void;
|
|
8
|
-
copy(options: IImageOptions): ImageData;
|
|
9
|
-
copyExtendedModel(options: IImageOptions): IExtendedImageDataModel;
|
|
10
|
-
update(imgData: ImageData, options: IImageOptions): void;
|
|
11
|
-
clearEmptyPixels(imageData: ImageData): IExtendedImageDataModel;
|
|
12
|
-
getSizeOfSparseMatrix(RGBAMatrix: TBuff<number[]>, tempSize: ISize): ISize;
|
|
13
|
-
getBuffCollection(imageData: ImageData): {
|
|
14
|
-
rowRGBABuff: TRGBABuff;
|
|
15
|
-
hexBuff: `#${string}`[];
|
|
16
|
-
buff: TBuff<string>;
|
|
17
|
-
};
|
|
18
|
-
getBuff(hexBuff: THEXColor[]): TBuff<string>;
|
|
19
|
-
getRGBAMatrix(rowRGBABuff: TRGBABuff, size?: ISize): TBuff<number[]>;
|
|
20
|
-
getRowRGBABuff(imageData: ImageData): TRGBABuff;
|
|
21
|
-
}
|
package/dist/utils/filter.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Filter = void 0;
|
|
4
|
-
const config_1 = require("../config");
|
|
5
|
-
const convert_1 = require("./convert");
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
7
|
-
class Filter {
|
|
8
|
-
ctx;
|
|
9
|
-
imageSize;
|
|
10
|
-
constructor(ctx) {
|
|
11
|
-
this.ctx = ctx;
|
|
12
|
-
}
|
|
13
|
-
setImageSize(size) {
|
|
14
|
-
this.imageSize = size;
|
|
15
|
-
}
|
|
16
|
-
copy(options) {
|
|
17
|
-
const width = (options?.width) ? options.width : config_1.default.CANVAS_SIZE.width;
|
|
18
|
-
const height = (options?.height) ? options.height : config_1.default.CANVAS_SIZE.height;
|
|
19
|
-
const imgData = this.ctx.getImageData(options.x, options.y, width, height);
|
|
20
|
-
return imgData;
|
|
21
|
-
}
|
|
22
|
-
copyExtendedModel(options) {
|
|
23
|
-
const width = (options?.width) ? options.width : config_1.default.CANVAS_SIZE.width;
|
|
24
|
-
const height = (options?.height) ? options.height : config_1.default.CANVAS_SIZE.height;
|
|
25
|
-
const imgData = this.ctx.getImageData(options.x, options.y, width, height);
|
|
26
|
-
const extendedImageData = this.clearEmptyPixels(imgData);
|
|
27
|
-
return extendedImageData;
|
|
28
|
-
}
|
|
29
|
-
update(imgData, options) {
|
|
30
|
-
this.ctx.clearRect(0, 0, config_1.default.CANVAS_SIZE.width, config_1.default.CANVAS_SIZE.height);
|
|
31
|
-
this.ctx.putImageData(imgData, options.x, options.y);
|
|
32
|
-
}
|
|
33
|
-
clearEmptyPixels(imageData) {
|
|
34
|
-
const rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
35
|
-
const RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, { width: imageData.width, height: imageData.height });
|
|
36
|
-
const beforeSize = {
|
|
37
|
-
width: imageData.width,
|
|
38
|
-
height: imageData.height,
|
|
39
|
-
};
|
|
40
|
-
const tempSize = this.getSizeOfSparseMatrix(RGBAMatrix, beforeSize);
|
|
41
|
-
const cleared = rowRGBABuff.filter((byteArray) => {
|
|
42
|
-
const alpha = byteArray[3 /* E_RGBA.a */];
|
|
43
|
-
return !!alpha;
|
|
44
|
-
});
|
|
45
|
-
const clearedBuff = cleared.flat();
|
|
46
|
-
const tempCanvas = document.createElement('canvas');
|
|
47
|
-
const tempCtx = tempCanvas.getContext('2d');
|
|
48
|
-
const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
49
|
-
clearedBuff.forEach((_, i) => tempImageData.data[i] = clearedBuff[i]);
|
|
50
|
-
console.log('cleared', cleared);
|
|
51
|
-
return {
|
|
52
|
-
imageData: tempImageData,
|
|
53
|
-
size: tempSize
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
getSizeOfSparseMatrix(RGBAMatrix, tempSize) {
|
|
57
|
-
// case 1: Xcanvas -> Ximage && Ycanvas -> Yimage
|
|
58
|
-
let leftIndex;
|
|
59
|
-
let upIndex;
|
|
60
|
-
for (const [iy, row] of RGBAMatrix.entries()) {
|
|
61
|
-
for (const [ix, rowItem] of row.entries()) {
|
|
62
|
-
const isNotEmpty = rowItem[3 /* E_RGBA.a */] !== 0;
|
|
63
|
-
if (isNotEmpty) {
|
|
64
|
-
leftIndex = ix;
|
|
65
|
-
upIndex = iy;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (leftIndex !== undefined && upIndex !== undefined) {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// case 2 reverse matrix: Ximage <- Xcanvas && Yimage <- Ycanvas
|
|
74
|
-
let rightIndex;
|
|
75
|
-
let downIndex;
|
|
76
|
-
for (const [iy, row] of RGBAMatrix.reverse().entries()) {
|
|
77
|
-
for (const [ix, rowItem] of row.reverse().entries()) {
|
|
78
|
-
const isNotEmpty = rowItem[3 /* E_RGBA.a */] !== 0;
|
|
79
|
-
if (isNotEmpty) {
|
|
80
|
-
rightIndex = ix;
|
|
81
|
-
downIndex = iy;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (rightIndex !== undefined && downIndex !== undefined) {
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const reduceWidth = (tempWidth) => tempWidth - (leftIndex + rightIndex);
|
|
90
|
-
const reduceHeight = (tempHeight) => tempHeight - (upIndex + downIndex);
|
|
91
|
-
const resultSize = {
|
|
92
|
-
width: reduceWidth(tempSize.width),
|
|
93
|
-
height: reduceHeight(tempSize.height),
|
|
94
|
-
};
|
|
95
|
-
return resultSize;
|
|
96
|
-
}
|
|
97
|
-
getBuffCollection(imageData) {
|
|
98
|
-
const rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
99
|
-
const hexBuff = rowRGBABuff.map(convert_1.Convert.byteRGBToHEX);
|
|
100
|
-
const buff = this.getBuff(hexBuff);
|
|
101
|
-
return { rowRGBABuff, hexBuff, buff };
|
|
102
|
-
}
|
|
103
|
-
getBuff(hexBuff) {
|
|
104
|
-
const distanceRow = (0, lodash_1.range)(0, this.imageSize.height).map((i) => this.imageSize.width * i);
|
|
105
|
-
const buff = [];
|
|
106
|
-
let indexOfDistance = 0;
|
|
107
|
-
hexBuff.forEach((pxColor, pxIndex) => {
|
|
108
|
-
if (pxIndex >= distanceRow[indexOfDistance + 1]) {
|
|
109
|
-
indexOfDistance++;
|
|
110
|
-
}
|
|
111
|
-
buff[indexOfDistance] ??= [];
|
|
112
|
-
buff[indexOfDistance].push(pxColor);
|
|
113
|
-
});
|
|
114
|
-
return buff;
|
|
115
|
-
}
|
|
116
|
-
getRGBAMatrix(rowRGBABuff, size) {
|
|
117
|
-
const maybeSize = {
|
|
118
|
-
width: size.width || this.imageSize.width,
|
|
119
|
-
height: size.height || this.imageSize.height,
|
|
120
|
-
};
|
|
121
|
-
const distanceRow = (0, lodash_1.range)(0, maybeSize.height).map((i) => maybeSize.width * i);
|
|
122
|
-
const buff = [];
|
|
123
|
-
let indexOfDistance = 0;
|
|
124
|
-
rowRGBABuff.forEach((pxRGBA, pxIndex) => {
|
|
125
|
-
if (pxIndex >= distanceRow[indexOfDistance + 1]) {
|
|
126
|
-
indexOfDistance++;
|
|
127
|
-
}
|
|
128
|
-
buff[indexOfDistance] ??= [];
|
|
129
|
-
buff[indexOfDistance].push(pxRGBA);
|
|
130
|
-
});
|
|
131
|
-
return buff;
|
|
132
|
-
}
|
|
133
|
-
getRowRGBABuff(imageData) {
|
|
134
|
-
const rowRGBABuff = []; // [ [0, 0, 0, 0], [0, 0, 0, 0], ... ]
|
|
135
|
-
let colorIndx = 0;
|
|
136
|
-
let colorRGBAIndx = 0;
|
|
137
|
-
imageData.data.forEach((pxColor) => {
|
|
138
|
-
if (colorIndx >= 4) {
|
|
139
|
-
colorIndx = 0;
|
|
140
|
-
colorRGBAIndx++;
|
|
141
|
-
}
|
|
142
|
-
colorIndx++;
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
rowRGBABuff[colorRGBAIndx] ??= [];
|
|
145
|
-
rowRGBABuff[colorRGBAIndx].push(pxColor);
|
|
146
|
-
});
|
|
147
|
-
return rowRGBABuff;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.Filter = Filter;
|
package/dist/utils/guid4.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IGUID4 } from "../types/general";
|
|
2
|
-
export declare class Guid4 {
|
|
3
|
-
stack: IGUID4[];
|
|
4
|
-
guid4: IGUID4;
|
|
5
|
-
constructor();
|
|
6
|
-
generate(): `${number}-${number}-${number}-${number}`;
|
|
7
|
-
get finite(): IGUID4;
|
|
8
|
-
private generateWithFactor;
|
|
9
|
-
private getFactor;
|
|
10
|
-
private get attempt();
|
|
11
|
-
private get Guid4();
|
|
12
|
-
private formating;
|
|
13
|
-
}
|
package/dist/utils/guid4.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Guid4 = void 0;
|
|
4
|
-
class Guid4 {
|
|
5
|
-
stack = [];
|
|
6
|
-
guid4;
|
|
7
|
-
constructor() {
|
|
8
|
-
// generateWithFactor not working
|
|
9
|
-
// this.generateWithFactor(this.attempt);
|
|
10
|
-
}
|
|
11
|
-
generate() {
|
|
12
|
-
return this.Guid4;
|
|
13
|
-
}
|
|
14
|
-
get finite() {
|
|
15
|
-
const guid4 = this.stack[this.stack?.length];
|
|
16
|
-
if (!!guid4) {
|
|
17
|
-
return guid4;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
throw new Error("Guid4 not generate");
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
;
|
|
24
|
-
generateWithFactor(attempt) {
|
|
25
|
-
const factor = this.getFactor(this.guid4);
|
|
26
|
-
attempt.use('withError').run(factor);
|
|
27
|
-
}
|
|
28
|
-
getFactor(guid4) {
|
|
29
|
-
return (attempt) => {
|
|
30
|
-
guid4 = this.Guid4;
|
|
31
|
-
if (!this.stack.includes(guid4)) {
|
|
32
|
-
attempt.current = attempt.max;
|
|
33
|
-
this.stack.push(guid4);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
get attempt() {
|
|
38
|
-
const attemptConfig = {
|
|
39
|
-
attempt: {
|
|
40
|
-
current: 1,
|
|
41
|
-
max: 5,
|
|
42
|
-
},
|
|
43
|
-
error: {
|
|
44
|
-
message: '[Fatal Error] Guid4 module cannot generate unique guid4'
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const attempt = new GenerateAttempt(attemptConfig.attempt, attemptConfig.error);
|
|
48
|
-
return attempt;
|
|
49
|
-
}
|
|
50
|
-
get Guid4() {
|
|
51
|
-
const base = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
52
|
-
const regex = /[xy]/g;
|
|
53
|
-
const guid4 = base.replace(regex, this.formating);
|
|
54
|
-
return guid4;
|
|
55
|
-
}
|
|
56
|
-
formating(char) {
|
|
57
|
-
const preformer = Math.random() * 16 | 0;
|
|
58
|
-
const formattedChar = (char == 'x') ? preformer : (preformer & 0x3 | 0x8);
|
|
59
|
-
return formattedChar.toString(16);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.Guid4 = Guid4;
|
|
63
|
-
;
|
|
64
|
-
class GenerateAttempt {
|
|
65
|
-
_attempt;
|
|
66
|
-
_error;
|
|
67
|
-
constructor(config, error) {
|
|
68
|
-
this._attempt = config;
|
|
69
|
-
if (!!error)
|
|
70
|
-
this._error = error;
|
|
71
|
-
}
|
|
72
|
-
use(strategy = 'default') {
|
|
73
|
-
const context = this;
|
|
74
|
-
switch (strategy) {
|
|
75
|
-
case 'default':
|
|
76
|
-
return {
|
|
77
|
-
run(action) {
|
|
78
|
-
context.defaultRun(action);
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
case 'withError':
|
|
82
|
-
return {
|
|
83
|
-
run(action) {
|
|
84
|
-
context.withErrorRun(action);
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
defaultRun(action) {
|
|
90
|
-
const attemptCondition = this._attempt.current <= this._attempt.max;
|
|
91
|
-
while (attemptCondition) {
|
|
92
|
-
action(this._attempt);
|
|
93
|
-
this._attempt.current++;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
withErrorRun(action) {
|
|
97
|
-
const attemptCondition = this._attempt.current <= this._attempt.max;
|
|
98
|
-
const errorCondition = this._attempt.current === this._attempt.max;
|
|
99
|
-
const errorMessage = this._error.message;
|
|
100
|
-
while (attemptCondition) {
|
|
101
|
-
this.throwError(errorCondition, errorMessage);
|
|
102
|
-
action(this._attempt);
|
|
103
|
-
this._attempt.current++;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
throwError(condition, message) {
|
|
107
|
-
if (condition) {
|
|
108
|
-
throw new Error(message);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Project } from "../types/project";
|
|
2
|
-
export declare class ProjectFileSerializer {
|
|
3
|
-
private file;
|
|
4
|
-
private projects;
|
|
5
|
-
constructor(file: any);
|
|
6
|
-
private load;
|
|
7
|
-
saveProjects(projects: Project[]): void;
|
|
8
|
-
getProjects(): Project[];
|
|
9
|
-
getProject(projectId: string): Project;
|
|
10
|
-
saveProject(project: Project): void;
|
|
11
|
-
removeProject(projectId: string): void;
|
|
12
|
-
updateProject(project: Project): void;
|
|
13
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
const rowProjects = JSON.parse(this.file);
|
|
14
|
-
const imageDataProcessor = (temp) => {
|
|
15
|
-
let data;
|
|
16
|
-
let size;
|
|
17
|
-
if (temp?.current) {
|
|
18
|
-
data = Object.values(temp?.current.imageData.data);
|
|
19
|
-
size = temp?.current.size;
|
|
20
|
-
}
|
|
21
|
-
else if (temp?.state) {
|
|
22
|
-
data = Object.values(temp?.state.tempImageData.data);
|
|
23
|
-
size = temp?.state.size;
|
|
24
|
-
}
|
|
25
|
-
const tempImageData = new ImageData(size.width, size.height);
|
|
26
|
-
data.forEach((colorAtom, index) => {
|
|
27
|
-
tempImageData.data[index] = colorAtom;
|
|
28
|
-
});
|
|
29
|
-
return tempImageData;
|
|
30
|
-
};
|
|
31
|
-
const projects = rowProjects.map((project) => {
|
|
32
|
-
project.state.current.imageData = imageDataProcessor({ current: project.state.current });
|
|
33
|
-
project.state.history = project.state.history.map((historyLine) => {
|
|
34
|
-
historyLine.stateValue.tempImageData = imageDataProcessor({ state: historyLine.stateValue });
|
|
35
|
-
return historyLine;
|
|
36
|
-
});
|
|
37
|
-
project.state.cache = project.state.cache.map((historyLine) => {
|
|
38
|
-
historyLine.stateValue.tempImageData = imageDataProcessor({ state: historyLine.stateValue });
|
|
39
|
-
return historyLine;
|
|
40
|
-
});
|
|
41
|
-
return project;
|
|
42
|
-
});
|
|
43
|
-
return projects;
|
|
44
|
-
}
|
|
45
|
-
saveProjects(projects) {
|
|
46
|
-
this.file.save(JSON.stringify(projects));
|
|
47
|
-
}
|
|
48
|
-
getProjects() {
|
|
49
|
-
return this.projects;
|
|
50
|
-
}
|
|
51
|
-
getProject(projectId) {
|
|
52
|
-
return this.projects.find((project) => project.id === projectId);
|
|
53
|
-
}
|
|
54
|
-
saveProject(project) {
|
|
55
|
-
const index = this.projects.findIndex((p) => p.id === project.id);
|
|
56
|
-
if (index !== -1) {
|
|
57
|
-
this.projects[index] = project;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
this.projects.push(project);
|
|
61
|
-
}
|
|
62
|
-
this.saveProjects(this.projects);
|
|
63
|
-
}
|
|
64
|
-
removeProject(projectId) {
|
|
65
|
-
const index = this.projects.findIndex((p) => p.id === projectId);
|
|
66
|
-
if (index !== -1) {
|
|
67
|
-
this.projects.splice(index, 1);
|
|
68
|
-
this.saveProjects(this.projects);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
updateProject(project) {
|
|
72
|
-
const index = this.projects.findIndex((p) => p.id === project.id);
|
|
73
|
-
if (index !== -1) {
|
|
74
|
-
this.projects[index] = project;
|
|
75
|
-
this.saveProjects(this.projects);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.ProjectFileSerializer = ProjectFileSerializer;
|
package/dist/web-component.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { TComponent } from "./types/general";
|
|
2
|
-
export declare class WebComponentWrapper {
|
|
3
|
-
baseElement: HTMLDivElement;
|
|
4
|
-
editorWrapElement: HTMLDivElement;
|
|
5
|
-
stylesWrapElement: HTMLDivElement;
|
|
6
|
-
toolsWrapElement: HTMLDivElement;
|
|
7
|
-
constructor();
|
|
8
|
-
get base(): {
|
|
9
|
-
add: (component: TComponent, style?: HTMLStyleElement) => HTMLDivElement;
|
|
10
|
-
};
|
|
11
|
-
get editorWrap(): {
|
|
12
|
-
add: (component: TComponent, style?: HTMLStyleElement) => HTMLDivElement;
|
|
13
|
-
};
|
|
14
|
-
get stylesWrap(): {
|
|
15
|
-
add: (component: TComponent, style?: HTMLStyleElement) => HTMLDivElement;
|
|
16
|
-
};
|
|
17
|
-
get toolsWrap(): {
|
|
18
|
-
add: (component: TComponent, style?: HTMLStyleElement) => HTMLDivElement;
|
|
19
|
-
};
|
|
20
|
-
private _methods;
|
|
21
|
-
private _add;
|
|
22
|
-
private _baseStyle;
|
|
23
|
-
}
|
|
24
|
-
export default class WebComponent extends HTMLElement {
|
|
25
|
-
constructor();
|
|
26
|
-
}
|