canvas-editor-engine 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/Readme.md +118 -0
  2. package/dist/components/canvas.component.d.ts +21 -0
  3. package/dist/components/canvas.component.js +75 -0
  4. package/dist/components/excretions.component.d.ts +24 -0
  5. package/dist/components/excretions.component.js +192 -0
  6. package/dist/components/pipette.component.d.ts +23 -0
  7. package/dist/components/pipette.component.js +138 -0
  8. package/dist/components/slot.component.d.ts +10 -0
  9. package/dist/components/slot.component.js +20 -0
  10. package/dist/config.d.ts +9 -0
  11. package/dist/config.js +29 -0
  12. package/dist/filters/collection/vague.d.ts +12 -0
  13. package/dist/filters/collection/vague.js +107 -0
  14. package/dist/filters/index.d.ts +2 -0
  15. package/dist/filters/index.js +5 -0
  16. package/dist/images/image.png +0 -0
  17. package/dist/images/sample.png +0 -0
  18. package/dist/index.d.ts +25 -0
  19. package/dist/index.js +49 -0
  20. package/dist/services/component.service.d.ts +5 -0
  21. package/dist/services/component.service.js +37 -0
  22. package/dist/services/draw.service.d.ts +13 -0
  23. package/dist/services/draw.service.js +71 -0
  24. package/dist/services/tool.service.d.ts +10 -0
  25. package/dist/services/tool.service.js +58 -0
  26. package/dist/types/canvas.d.ts +10 -0
  27. package/dist/types/canvas.js +3 -0
  28. package/dist/types/cursor.d.ts +9 -0
  29. package/dist/types/cursor.js +3 -0
  30. package/dist/types/excreation.d.ts +24 -0
  31. package/dist/types/excreation.js +5 -0
  32. package/dist/types/excretion.d.ts +26 -0
  33. package/dist/types/excretion.js +5 -0
  34. package/dist/types/general.d.ts +14 -0
  35. package/dist/types/general.js +4 -0
  36. package/dist/types/image.d.ts +36 -0
  37. package/dist/types/image.js +7 -0
  38. package/dist/types/pipette.d.ts +1 -0
  39. package/dist/types/pipette.js +2 -0
  40. package/dist/utils/convert.d.ts +12 -0
  41. package/dist/utils/convert.js +27 -0
  42. package/dist/utils/filter.d.ts +16 -0
  43. package/dist/utils/filter.js +61 -0
  44. package/dist/web-component.d.ts +10 -0
  45. package/dist/web-component.js +60 -0
  46. package/package.json +30 -0
@@ -0,0 +1,61 @@
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
+ constructor(ctx) {
9
+ this.ctx = ctx;
10
+ }
11
+ setImageSize(size) {
12
+ this.imageSize = size;
13
+ }
14
+ copy(options) {
15
+ const width = (options === null || options === void 0 ? void 0 : options.width) ? options.width : config_1.default.CANVAS_SIZE.width;
16
+ const height = (options === null || options === void 0 ? void 0 : options.height) ? options.height : config_1.default.CANVAS_SIZE.height;
17
+ const imgData = this.ctx.getImageData(options.x, options.y, width, height);
18
+ return imgData;
19
+ }
20
+ update(imgData, options) {
21
+ this.ctx.putImageData(imgData, options.x, options.y);
22
+ }
23
+ getBuffCollection(imageData) {
24
+ const rowRGBABuff = this.getRowRGBABuff(imageData);
25
+ const hexBuff = rowRGBABuff.map(convert_1.Convert.byteRGBToHEX);
26
+ const buff = this.getBuff(hexBuff);
27
+ return { rowRGBABuff, hexBuff, buff };
28
+ }
29
+ getBuff(hexBuff) {
30
+ const distanceRow = (0, lodash_1.range)(0, this.imageSize.h).map((i) => this.imageSize.w * i);
31
+ const buff = [];
32
+ let indexOfDistance = 0;
33
+ hexBuff.forEach((pxColor, pxIndex) => {
34
+ var _a;
35
+ if (pxIndex >= distanceRow[indexOfDistance + 1]) {
36
+ indexOfDistance++;
37
+ }
38
+ (_a = buff[indexOfDistance]) !== null && _a !== void 0 ? _a : (buff[indexOfDistance] = []);
39
+ buff[indexOfDistance].push(pxColor);
40
+ });
41
+ return buff;
42
+ }
43
+ getRowRGBABuff(imageData) {
44
+ const rowRGBABuff = []; // [ [0, 0, 0, 0], [0, 0, 0, 0], ... ]
45
+ let colorIndx = 0;
46
+ let colorRGBAIndx = 0;
47
+ imageData.data.forEach((pxColor) => {
48
+ var _a;
49
+ if (colorIndx >= 4) {
50
+ colorIndx = 0;
51
+ colorRGBAIndx++;
52
+ }
53
+ colorIndx++;
54
+ // @ts-ignore
55
+ (_a = rowRGBABuff[colorRGBAIndx]) !== null && _a !== void 0 ? _a : (rowRGBABuff[colorRGBAIndx] = []);
56
+ rowRGBABuff[colorRGBAIndx].push(pxColor);
57
+ });
58
+ return rowRGBABuff;
59
+ }
60
+ }
61
+ exports.Filter = Filter;
@@ -0,0 +1,10 @@
1
+ import { TComponent } from "./types/general";
2
+ export declare class WebComponentWrapper {
3
+ element: HTMLDivElement;
4
+ constructor();
5
+ add(component: TComponent, style?: HTMLStyleElement): HTMLDivElement;
6
+ private _stylish;
7
+ }
8
+ export default class WebComponent extends HTMLElement {
9
+ constructor();
10
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebComponentWrapper = void 0;
4
+ const canvas_component_1 = require("./components/canvas.component");
5
+ const excretions_component_1 = require("./components/excretions.component");
6
+ const pipette_component_1 = require("./components/pipette.component");
7
+ const slot_component_1 = require("./components/slot.component");
8
+ class WebComponentWrapper {
9
+ constructor() {
10
+ const webComponentWrapper = document.createElement('div');
11
+ webComponentWrapper.className = 'editor-wrap';
12
+ webComponentWrapper.style.position = 'relative';
13
+ webComponentWrapper.style.display = 'flex';
14
+ this.element = webComponentWrapper;
15
+ this._stylish();
16
+ }
17
+ add(component, style) {
18
+ const componentElement = this.element.appendChild(component);
19
+ if (!!style) {
20
+ this.element.appendChild(style);
21
+ }
22
+ return componentElement;
23
+ }
24
+ _stylish() {
25
+ const style = document.createElement('style');
26
+ style.innerHTML = `
27
+ * {
28
+ user-select: none;
29
+ }
30
+ `;
31
+ this.element.appendChild(style);
32
+ }
33
+ }
34
+ exports.WebComponentWrapper = WebComponentWrapper;
35
+ class WebComponent extends HTMLElement {
36
+ constructor() {
37
+ super();
38
+ const shadowRoot = this.attachShadow({ mode: "open" });
39
+ const webComponentWrapper = new WebComponentWrapper();
40
+ const { canvasTemplate, canvasStyle } = canvas_component_1.default.getComponent();
41
+ const canvasElement = webComponentWrapper.add(canvasTemplate, canvasStyle);
42
+ const { pipetteTemplate, pipetteStyle } = pipette_component_1.default.getComponent();
43
+ webComponentWrapper.add(pipetteTemplate, pipetteStyle);
44
+ const { slotTemplate, slotStyle } = slot_component_1.default.getComponent('tools');
45
+ webComponentWrapper.add(slotTemplate, slotStyle);
46
+ const { excretionsTemplate, excretionsStyle } = excretions_component_1.default.getComponent();
47
+ webComponentWrapper.add(excretionsTemplate, excretionsStyle);
48
+ shadowRoot.appendChild(webComponentWrapper.element);
49
+ canvas_component_1.default.simulateSubscriptions();
50
+ this.addEventListener('initial', () => {
51
+ this.dispatchEvent(new CustomEvent('get-editor-element', {
52
+ detail: {
53
+ editorElement: canvasElement,
54
+ canvasSelector: canvas_component_1.default.getCanvasSelector(),
55
+ }
56
+ }));
57
+ });
58
+ }
59
+ }
60
+ exports.default = WebComponent;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "canvas-editor-engine",
3
+ "version": "1.0.1",
4
+ "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "test": "node test/test.js",
12
+ "build": "tsc",
13
+ "realise": "npm version patch && npm publish"
14
+ },
15
+ "keywords": [
16
+ "typescript",
17
+ "canvas",
18
+ "library"
19
+ ],
20
+ "author": "SavaFeeD",
21
+ "license": "ISC",
22
+ "devDependencies": {
23
+ "@types/lodash": "^4.17.10",
24
+ "@types/node": "^22.7.4",
25
+ "typescript": "^5.6.2"
26
+ },
27
+ "dependencies": {
28
+ "lodash": "^4.17.21"
29
+ }
30
+ }