canvas-editor-engine 2.3.71 → 2.3.73

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.mjs CHANGED
@@ -2659,7 +2659,8 @@ var DrawLayersService = function() {
2659
2659
  }();
2660
2660
 
2661
2661
  var Painter = function() {
2662
- function Painter(drawLayersService, createModel) {
2662
+ function Painter(canvasComponent, drawLayersService, createModel) {
2663
+ this.canvasComponent = canvasComponent;
2663
2664
  this.drawLayersService = drawLayersService;
2664
2665
  this.drawService = createModel.drawService;
2665
2666
  this.drawType = createModel.drawType;
@@ -2670,7 +2671,56 @@ var Painter = function() {
2670
2671
  view: new Date,
2671
2672
  digital: Date.now()
2672
2673
  };
2674
+ this.subscribeOnCanvas();
2673
2675
  }
2676
+ Painter.prototype.subscribeOnCanvas = function() {
2677
+ var _this = this;
2678
+ this.canvasComponent.subscribe("mousedown", (function() {
2679
+ _this.focusTimer = setTimeout((function() {
2680
+ _this.focusPainter();
2681
+ }), 800);
2682
+ }));
2683
+ this.canvasComponent.subscribe("mouseup", (function() {
2684
+ _this.blurPainter();
2685
+ _this.focusTimer = null;
2686
+ }));
2687
+ this.canvasComponent.subscribe("mousemove", (function(event, cursorPosition) {
2688
+ if (!_this.isFocused) return;
2689
+ var x = cursorPosition.x, y = cursorPosition.y;
2690
+ var size = _this.drawService.options.image.drawImageArgs.size;
2691
+ var condition = size && size !== "initial";
2692
+ var position = {
2693
+ x: condition ? x - size.width / 2 : x,
2694
+ y: condition ? y - size.height / 2 : y
2695
+ };
2696
+ _this.changePainterPosition(position);
2697
+ }));
2698
+ };
2699
+ Painter.prototype.focusPainter = function() {
2700
+ this.isFocused = true;
2701
+ };
2702
+ Painter.prototype.blurPainter = function() {
2703
+ this.isFocused = false;
2704
+ };
2705
+ Painter.prototype.selectPainter = function() {
2706
+ this.isSelected = true;
2707
+ };
2708
+ Painter.prototype.unselectPainter = function() {
2709
+ this.isSelected = false;
2710
+ };
2711
+ Painter.prototype.changePainterPosition = function(position) {
2712
+ return __awaiter(this, void 0, void 0, (function() {
2713
+ var _this = this;
2714
+ return __generator(this, (function(_a) {
2715
+ return [ 2, new Promise((function(resolve, reject) {
2716
+ if (!position) return reject(false);
2717
+ _this.drawService.options.image.drawImageArgs.position = position;
2718
+ _this.drawLayersService.updatePainterData(_this);
2719
+ resolve(true);
2720
+ })) ];
2721
+ }));
2722
+ }));
2723
+ };
2674
2724
  Painter.prototype.putPainter = function(painter) {
2675
2725
  return __awaiter(this, void 0, void 0, (function() {
2676
2726
  var _this = this;
@@ -2740,11 +2790,12 @@ function createDynamicPainterStore() {
2740
2790
  }
2741
2791
 
2742
2792
  var DrawAccumulatorService = function() {
2743
- function DrawAccumulatorService(appConfig, appStoreRepository, eventService, drawLayersService) {
2793
+ function DrawAccumulatorService(appConfig, appStoreRepository, eventService, drawLayersService, canvasComponent) {
2744
2794
  this.appConfig = appConfig;
2745
2795
  this.appStoreRepository = appStoreRepository;
2746
2796
  this.eventService = eventService;
2747
2797
  this.drawLayersService = drawLayersService;
2798
+ this.canvasComponent = canvasComponent;
2748
2799
  this.painters = createDynamicPainterStore();
2749
2800
  }
2750
2801
  DrawAccumulatorService.prototype.add = function(layerId, drawType, options, initialSize) {
@@ -2752,7 +2803,7 @@ var DrawAccumulatorService = function() {
2752
2803
  var id, painter;
2753
2804
  return __generator(this, (function(_a) {
2754
2805
  id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
2755
- painter = new Painter(this.drawLayersService, {
2806
+ painter = new Painter(this.canvasComponent, this.drawLayersService, {
2756
2807
  drawService: new DrawService(this.appConfig, this.appStoreRepository, this.eventService),
2757
2808
  name: "Painter ".concat(id),
2758
2809
  drawType,
@@ -3112,7 +3163,7 @@ var WebComponent = function(_super) {
3112
3163
  this.pullProjectService = new PullProjectService(this.throughHistoryService, this.appStoreRepository);
3113
3164
  this.drawService = new DrawService(this.appConfig, this.appStoreRepository, this.eventService);
3114
3165
  this.drawLayersService = new DrawLayersService(this.appStoreRepository);
3115
- this.drawAccumulatorService = new DrawAccumulatorService(this.appConfig, this.appStoreRepository, this.eventService, this.drawLayersService);
3166
+ this.drawAccumulatorService = new DrawAccumulatorService(this.appConfig, this.appStoreRepository, this.eventService, this.drawLayersService, this.canvasComponent);
3116
3167
  this.downloadService = new DownloadService(this.canvasComponent);
3117
3168
  var _a = this.canvasComponent.getComponent(), canvasTemplate = _a.canvasTemplate, canvasStyle = _a.canvasStyle;
3118
3169
  this.canvasElement = this.webComponentWrapper.editorWrap.add(canvasTemplate, canvasStyle);
@@ -1,7 +1,8 @@
1
+ import CanvasComponent from "../components/canvas.component";
1
2
  import AppConfig from "../config";
2
3
  import AppStoreRepository from "../store/storeRepository";
3
4
  import { ILayer, ILayerUpdate, IUpdateLayerOptions } from "../types/draw-layers";
4
- import { IPainter, ISmoothFilterOptions, TDrawType } from "../types/draw-service";
5
+ import { ISmoothFilterOptions, TDrawType } from "../types/draw-service";
5
6
  import { ITempCanvasOptions } from "../types/temp-canvas";
6
7
  import Painter from "../utils/painter";
7
8
  import DrawLayersService from "./draw-layers.service";
@@ -12,14 +13,15 @@ export default class DrawAccumulatorService {
12
13
  private appStoreRepository;
13
14
  private eventService;
14
15
  private drawLayersService;
16
+ private canvasComponent;
15
17
  painters: Painter[];
16
- constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService, drawLayersService: DrawLayersService);
18
+ constructor(appConfig: AppConfig, appStoreRepository: AppStoreRepository, eventService: EventService, drawLayersService: DrawLayersService, canvasComponent: CanvasComponent);
17
19
  add<DrawType extends TDrawType>(layerId: ILayer['id'], drawType: DrawType, options: DrawService['options'][DrawType], initialSize: ITempCanvasOptions): Promise<void>;
18
20
  getPainterById(painterId: string): Painter;
19
21
  removePainter(painterId: string): Promise<void>;
20
22
  changePainterOrder(painterId: Painter['id'], order: Painter['order']): void;
21
- renamePainter(painterId: IPainter['id'], name: IPainter['name']): void;
22
- smoothFilter(painterId: IPainter['id'], smoothFilterOptions: ISmoothFilterOptions): Promise<void>;
23
+ renamePainter(painterId: Painter['id'], name: Painter['name']): void;
24
+ smoothFilter(painterId: Painter['id'], smoothFilterOptions: ISmoothFilterOptions): Promise<void>;
23
25
  renameLayer(id: ILayer["id"], newName: ILayerUpdate['name']): Promise<void>;
24
26
  removeLayer(layerId: ILayer['id']): Promise<void>;
25
27
  changeLayerOrder(layerId: ILayer['id'], options: IUpdateLayerOptions): void;
@@ -1,6 +1,5 @@
1
1
  import AppStoreRepository from "../store/storeRepository";
2
2
  import { ILayer, ILayerUpdate, IUpdateLayerOptions } from "../types/draw-layers";
3
- import { IPainter } from "../types/draw-service";
4
3
  import Painter from "../utils/painter";
5
4
  export default class DrawLayersService {
6
5
  private appStoreRepository;
@@ -8,15 +7,15 @@ export default class DrawLayersService {
8
7
  constructor(appStoreRepository: AppStoreRepository);
9
8
  addLayer(layerOptions?: {
10
9
  layerName?: string;
11
- painter?: IPainter;
10
+ painter?: Painter;
12
11
  }): ILayer;
13
12
  getLayerByOrder(order: number): ILayer;
14
13
  getLayersByOrder(order: number): ILayer[];
15
14
  getLayerById(layerId: ILayer['id']): ILayer;
16
- getLayerByPainterId(painterId: IPainter['id']): ILayer;
17
- addToLayer(id: ILayer['id'], painter: IPainter): void;
15
+ getLayerByPainterId(painterId: Painter['id']): ILayer;
16
+ addToLayer(id: ILayer['id'], painter: Painter): void;
18
17
  updateLayer(id: ILayer['id'], updateData?: ILayerUpdate): Promise<unknown>;
19
- removePainter(id: IPainter['id']): void;
18
+ removePainter(id: Painter['id']): void;
20
19
  updatePainterData(painter: Painter): void;
21
20
  removeLayer(id: ILayer['id']): Promise<unknown>;
22
21
  /**
@@ -1,7 +1,7 @@
1
- import { IPainter } from "./draw-service";
1
+ import Painter from "../utils/painter";
2
2
  export interface ILayer {
3
3
  id: string;
4
- painters: IPainter[];
4
+ painters: Painter[];
5
5
  order: number;
6
6
  name: string;
7
7
  }
@@ -1,7 +1,8 @@
1
1
  import DrawService from "../services/draw.service";
2
+ import Painter from "../utils/painter";
2
3
  import { IDrawImageArgs, IFilterOptions } from "./image";
3
4
  export type TDrawType = keyof DrawService['options'];
4
- export interface IPainter {
5
+ export interface ICreatePainter {
5
6
  drawService: DrawService;
6
7
  drawType: TDrawType;
7
8
  id: string;
@@ -9,8 +10,8 @@ export interface IPainter {
9
10
  order?: number;
10
11
  }
11
12
  export interface IPutPainter {
12
- name?: IPainter['name'];
13
- order?: IPainter['order'];
13
+ name?: Painter['name'];
14
+ order?: Painter['order'];
14
15
  }
15
16
  export interface ISmoothFilterOptions {
16
17
  useStore: boolean;
@@ -1,7 +1,10 @@
1
+ import CanvasComponent from "../components/canvas.component";
1
2
  import DrawLayersService from "../services/draw-layers.service";
2
3
  import DrawService from "../services/draw.service";
3
- import { IPainter, IPutPainter, TDrawType } from "../types/draw-service";
4
+ import { ICreatePainter, IPutPainter, TDrawType } from "../types/draw-service";
5
+ import { IPosition } from "../types/general";
4
6
  export default class Painter {
7
+ private canvasComponent;
5
8
  private drawLayersService;
6
9
  drawService: DrawService;
7
10
  drawType: TDrawType;
@@ -12,6 +15,15 @@ export default class Painter {
12
15
  view: Date;
13
16
  digital: number;
14
17
  };
15
- constructor(drawLayersService: DrawLayersService, createModel: IPainter);
18
+ isFocused: boolean;
19
+ isSelected: boolean;
20
+ private focusTimer;
21
+ constructor(canvasComponent: CanvasComponent, drawLayersService: DrawLayersService, createModel: ICreatePainter);
22
+ private subscribeOnCanvas;
23
+ focusPainter(): void;
24
+ blurPainter(): void;
25
+ selectPainter(): void;
26
+ unselectPainter(): void;
27
+ changePainterPosition(position: IPosition): Promise<unknown>;
16
28
  putPainter(painter: IPutPainter): Promise<unknown>;
17
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "2.3.71",
3
+ "version": "2.3.73",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",