@idraw/core 0.3.0-beta.3 → 0.3.0-beta.7

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.
Files changed (38) hide show
  1. package/dist/esm/index.d.ts +44 -44
  2. package/dist/esm/index.js +85 -80
  3. package/dist/esm/lib/calculate.d.ts +3 -3
  4. package/dist/esm/lib/calculate.js +5 -5
  5. package/dist/esm/lib/check.d.ts +4 -4
  6. package/dist/esm/lib/check.js +1 -1
  7. package/dist/esm/lib/config.d.ts +2 -2
  8. package/dist/esm/lib/core-event.d.ts +21 -21
  9. package/dist/esm/lib/diff.d.ts +6 -6
  10. package/dist/esm/lib/diff.js +9 -7
  11. package/dist/esm/lib/draw/base.d.ts +5 -5
  12. package/dist/esm/lib/draw/wrapper.d.ts +4 -4
  13. package/dist/esm/lib/element.d.ts +8 -8
  14. package/dist/esm/lib/element.js +15 -11
  15. package/dist/esm/lib/engine-temp.d.ts +4 -4
  16. package/dist/esm/lib/engine.d.ts +5 -5
  17. package/dist/esm/lib/helper.d.ts +12 -12
  18. package/dist/esm/lib/is.d.ts +3 -3
  19. package/dist/esm/lib/mapper.d.ts +4 -4
  20. package/dist/esm/lib/parse.d.ts +2 -2
  21. package/dist/esm/lib/parse.js +6 -3
  22. package/dist/esm/lib/transform.d.ts +4 -4
  23. package/dist/esm/lib/transform.js +1 -1
  24. package/dist/esm/mixins/element.d.ts +12 -14
  25. package/dist/esm/mixins/element.js +60 -62
  26. package/dist/esm/plugins/helper.d.ts +7 -7
  27. package/dist/esm/plugins/helper.js +5 -10
  28. package/dist/index.global.js +400 -439
  29. package/dist/index.global.min.js +1 -1
  30. package/package.json +6 -6
  31. package/dist/esm/lib/element/element-base.d.ts +0 -3
  32. package/dist/esm/lib/element/element-base.js +0 -5
  33. package/dist/esm/lib/element/element-controller.d.ts +0 -3
  34. package/dist/esm/lib/element/element-controller.js +0 -3
  35. package/dist/esm/lib/element/element-hub.d.ts +0 -9
  36. package/dist/esm/lib/element/element-hub.js +0 -16
  37. package/dist/esm/names.d.ts +0 -15
  38. package/dist/esm/names.js +0 -15
@@ -81,7 +81,7 @@ export class Element {
81
81
  'bottom-left',
82
82
  'left'
83
83
  ].includes(direction)) {
84
- const p = calcuScaleElemPosition(elem, moveX, moveY, direction, scale);
84
+ const p = calcuScaleElemPosition(elem, moveX, moveY, direction);
85
85
  elem.x = p.x;
86
86
  elem.y = p.y;
87
87
  elem.w = p.w;
@@ -117,10 +117,10 @@ export class Element {
117
117
  elem.angle = limitAngle(elem.angle || 0);
118
118
  }
119
119
  }
120
- function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
120
+ function calcuScaleElemPosition(elem, moveX, moveY, direction) {
121
121
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
122
122
  const p = { x: elem.x, y: elem.y, w: elem.w, h: elem.h };
123
- let angle = elem.angle;
123
+ let angle = elem.angle || 0;
124
124
  if (angle < 0) {
125
125
  angle = Math.max(0, 360 + angle);
126
126
  }
@@ -142,7 +142,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
142
142
  break;
143
143
  }
144
144
  case 'top': {
145
- if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
145
+ if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
146
146
  if (p.h - moveY > 0) {
147
147
  p.y += moveY;
148
148
  p.h -= moveY;
@@ -152,7 +152,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
152
152
  }
153
153
  }
154
154
  }
155
- else if (elem.angle > 0 || elem.angle < 0) {
155
+ else if (elem.angle !== undefined &&
156
+ (elem.angle > 0 || elem.angle < 0)) {
156
157
  const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
157
158
  let moveDist = calcMoveDist(moveX, moveY);
158
159
  let centerX = p.x + elem.w / 2;
@@ -215,7 +216,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
215
216
  break;
216
217
  }
217
218
  case 'right': {
218
- if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
219
+ if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
219
220
  if (elem.w + moveX > 0) {
220
221
  p.w += moveX;
221
222
  if (((_e = elem.operation) === null || _e === void 0 ? void 0 : _e.limitRatio) === true) {
@@ -224,7 +225,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
224
225
  }
225
226
  }
226
227
  }
227
- else if (elem.angle > 0 || elem.angle < 0) {
228
+ else if (elem.angle !== undefined &&
229
+ (elem.angle > 0 || elem.angle < 0)) {
228
230
  const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
229
231
  let moveDist = calcMoveDist(moveX, moveY);
230
232
  let centerX = p.x + elem.w / 2;
@@ -286,7 +288,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
286
288
  break;
287
289
  }
288
290
  case 'bottom': {
289
- if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
291
+ if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
290
292
  if (elem.h + moveY > 0) {
291
293
  p.h += moveY;
292
294
  if (((_h = elem.operation) === null || _h === void 0 ? void 0 : _h.limitRatio) === true) {
@@ -295,7 +297,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
295
297
  }
296
298
  }
297
299
  }
298
- else if (elem.angle > 0 || elem.angle < 0) {
300
+ else if (elem.angle !== undefined &&
301
+ (elem.angle > 0 || elem.angle < 0)) {
299
302
  const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
300
303
  let moveDist = calcMoveDist(moveX, moveY);
301
304
  let centerX = p.x + elem.w / 2;
@@ -357,7 +360,7 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
357
360
  break;
358
361
  }
359
362
  case 'left': {
360
- if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
363
+ if (elem.angle === 0 || Math.abs(elem.angle || 0) < limitQbliqueAngle) {
361
364
  if (elem.w - moveX > 0) {
362
365
  p.x += moveX;
363
366
  p.w -= moveX;
@@ -367,7 +370,8 @@ function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
367
370
  }
368
371
  }
369
372
  }
370
- else if (elem.angle > 0 || elem.angle < 0) {
373
+ else if (elem.angle !== undefined &&
374
+ (elem.angle > 0 || elem.angle < 0)) {
371
375
  const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
372
376
  let moveDist = calcMoveDist(moveX, moveY);
373
377
  let centerX = p.x + elem.w / 2;
@@ -1,4 +1,4 @@
1
- import { TypeHelperWrapperControllerDirection, TypePoint } from '@idraw/types';
1
+ import { HelperWrapperControllerDirection, Point } from '@idraw/types';
2
2
  import { Mode, CursorStatus } from '../constant/static';
3
3
  type TempDataDesc = {
4
4
  hasInited: boolean;
@@ -7,9 +7,9 @@ type TempDataDesc = {
7
7
  selectedUUID: string | null;
8
8
  selectedUUIDList: string[];
9
9
  hoverUUID: string | null;
10
- selectedControllerDirection: TypeHelperWrapperControllerDirection | null;
11
- hoverControllerDirection: TypeHelperWrapperControllerDirection | null;
12
- prevPoint: TypePoint | null;
10
+ selectedControllerDirection: HelperWrapperControllerDirection | null;
11
+ hoverControllerDirection: HelperWrapperControllerDirection | null;
12
+ prevPoint: Point | null;
13
13
  hasChangedElement: boolean;
14
14
  };
15
15
  export declare class TempData {
@@ -1,4 +1,4 @@
1
- import { TypePoint, InterfaceHelperPlugin, TypeConfigStrict, TypeData, TypeHelperConfig } from '@idraw/types';
1
+ import { Point, InterfaceHelperPlugin, IDrawConfigStrict, IDrawData, HelperConfig } from '@idraw/types';
2
2
  import Board from '@idraw/board';
3
3
  import { TempData } from './engine-temp';
4
4
  import { Helper } from './helper';
@@ -8,9 +8,9 @@ type Options = {
8
8
  coreEvent: CoreEvent;
9
9
  board: Board;
10
10
  element: Element;
11
- config: TypeConfigStrict;
11
+ config: IDrawConfigStrict;
12
12
  drawFeekback: () => void;
13
- getDataFeekback: () => TypeData;
13
+ getDataFeekback: () => IDrawData;
14
14
  selectElementByIndex: (index: number, opts?: {
15
15
  useMode?: boolean;
16
16
  }) => void;
@@ -25,7 +25,7 @@ export declare class Engine {
25
25
  helper: Helper;
26
26
  constructor(opts: Options);
27
27
  addPlugin(plugin: InterfaceHelperPlugin): void;
28
- getHelperConfig(): TypeHelperConfig;
28
+ getHelperConfig(): HelperConfig;
29
29
  updateHelperConfig(opts: {
30
30
  width: number;
31
31
  height: number;
@@ -34,7 +34,7 @@ export declare class Engine {
34
34
  init(): void;
35
35
  private _initEvent;
36
36
  private _handleDoubleClick;
37
- _handlePoint(point: TypePoint): void;
37
+ _handlePoint(point: Point): void;
38
38
  private _handleClick;
39
39
  private _handleMoveStart;
40
40
  private _handleMove;
@@ -1,27 +1,27 @@
1
- import { TypeData, TypeHelper, TypeHelperConfig, TypeHelperUpdateOpts, TypeHelperWrapperControllerDirection, TypePoint, TypeConfigStrict } from '@idraw/types';
1
+ import { IDrawData, HelperConfig, HelperUpdateOpts, HelperWrapperControllerDirection, Point, IDrawConfigStrict } from '@idraw/types';
2
2
  import Board from '@idraw/board';
3
- export declare class Helper implements TypeHelper {
3
+ export declare class Helper {
4
4
  private _helperConfig;
5
5
  private _coreConfig;
6
6
  private _ctx;
7
7
  private _board;
8
8
  private _areaStart;
9
9
  private _areaEnd;
10
- constructor(board: Board, config: TypeConfigStrict);
11
- updateConfig(data: TypeData, opts: TypeHelperUpdateOpts): void;
12
- getConfig(): TypeHelperConfig;
10
+ constructor(board: Board, config: IDrawConfigStrict);
11
+ updateConfig(data: IDrawData, opts: HelperUpdateOpts): void;
12
+ getConfig(): HelperConfig;
13
13
  getElementIndexByUUID(uuid: string): number | null;
14
- isPointInElementWrapperController(p: TypePoint, data?: TypeData): {
14
+ isPointInElementWrapperController(p: Point, data?: IDrawData): {
15
15
  uuid: string | null | undefined;
16
- selectedControllerDirection: TypeHelperWrapperControllerDirection | null;
17
- hoverControllerDirection: TypeHelperWrapperControllerDirection | null;
16
+ selectedControllerDirection: HelperWrapperControllerDirection | null;
17
+ hoverControllerDirection: HelperWrapperControllerDirection | null;
18
18
  directIndex: number | null;
19
19
  };
20
- isPointInElementList(p: TypePoint, data: TypeData): boolean;
21
- startSelectArea(p: TypePoint): void;
22
- changeSelectArea(p: TypePoint): void;
20
+ isPointInElementList(p: Point, data: IDrawData): boolean;
21
+ startSelectArea(p: Point): void;
22
+ changeSelectArea(p: Point): void;
23
23
  clearSelectedArea(): void;
24
- calcSelectedElements(data: TypeData): string[];
24
+ calcSelectedElements(data: IDrawData): string[];
25
25
  private _calcSelectedArea;
26
26
  private _updateElementIndex;
27
27
  private _updateSelectedElementWrapper;
@@ -1,5 +1,5 @@
1
- declare const is: TypeIs;
2
- type TypeIs = {
1
+ declare const is: IsTypeUtil;
2
+ type IsTypeUtil = {
3
3
  x: (value: any) => boolean;
4
4
  y: (value: any) => boolean;
5
5
  w: (value: any) => boolean;
@@ -23,4 +23,4 @@ type TypeIs = {
23
23
  strokeWidth: (value: any) => boolean;
24
24
  };
25
25
  export default is;
26
- export { TypeIs };
26
+ export { IsTypeUtil };
@@ -1,4 +1,4 @@
1
- import { TypeData, TypePoint, TypePointCursor } from '@idraw/types';
1
+ import { IDrawData, Point, PointCursor } from '@idraw/types';
2
2
  import Board from '@idraw/board';
3
3
  import { Helper } from './helper';
4
4
  import { Element } from './element';
@@ -17,9 +17,9 @@ export declare class Mapper {
17
17
  private [_helper];
18
18
  private [_element];
19
19
  constructor(opts: Options);
20
- isEffectivePoint(p: TypePoint): boolean;
21
- judgePointCursor(p: TypePoint, data: TypeData): {
22
- cursor: TypePointCursor;
20
+ isEffectivePoint(p: Point): boolean;
21
+ judgePointCursor(p: Point, data: IDrawData): {
22
+ cursor: PointCursor;
23
23
  elementUUID: string | null;
24
24
  };
25
25
  }
@@ -1,2 +1,2 @@
1
- import { TypeData } from '@idraw/types';
2
- export declare function parseData(data: any): TypeData;
1
+ import { IDrawData } from '@idraw/types';
2
+ export declare function parseData(data: any): IDrawData;
@@ -1,7 +1,7 @@
1
1
  import { elementNames } from './../constant/element';
2
2
  export function parseData(data) {
3
3
  const result = {
4
- elements: [],
4
+ elements: []
5
5
  };
6
6
  if (Array.isArray(data === null || data === void 0 ? void 0 : data.elements)) {
7
7
  data === null || data === void 0 ? void 0 : data.elements.forEach((elem = {}) => {
@@ -16,7 +16,10 @@ export function parseData(data) {
16
16
  return result;
17
17
  }
18
18
  function isElement(elem) {
19
- if (!(isNumber(elem.x) && isNumber(elem.y) && isNumber(elem.w) && isNumber(elem.h))) {
19
+ if (!(isNumber(elem.x) &&
20
+ isNumber(elem.y) &&
21
+ isNumber(elem.w) &&
22
+ isNumber(elem.h))) {
20
23
  return false;
21
24
  }
22
25
  if (!(typeof elem.type === 'string' && elementNames.includes(elem.type))) {
@@ -25,5 +28,5 @@ function isElement(elem) {
25
28
  return true;
26
29
  }
27
30
  function isNumber(num) {
28
- return (num >= 0 || num < 0);
31
+ return num >= 0 || num < 0;
29
32
  }
@@ -1,4 +1,4 @@
1
- import { TypeContext, TypePoint, TypeElement, TypeElemDesc } from '@idraw/types';
2
- declare function rotateElement(ctx: TypeContext, elem: TypeElement<keyof TypeElemDesc>, callback: (ctx: TypeContext) => void): void;
3
- declare function rotateContext(ctx: TypeContext, center: TypePoint | undefined, radian: number, callback: (ctx: TypeContext) => void): void;
4
- export { rotateContext, rotateElement, };
1
+ import { IDrawContext, Point, DataElement, DataElemDesc } from '@idraw/types';
2
+ declare function rotateElement(ctx: IDrawContext, elem: DataElement<keyof DataElemDesc>, callback: (ctx: IDrawContext) => void): void;
3
+ declare function rotateContext(ctx: IDrawContext, center: Point | undefined, radian: number, callback: (ctx: IDrawContext) => void): void;
4
+ export { rotateContext, rotateElement };
@@ -17,4 +17,4 @@ function rotateContext(ctx, center, radian, callback) {
17
17
  ctx.translate(-center.x, -center.y);
18
18
  }
19
19
  }
20
- export { rotateContext, rotateElement, };
20
+ export { rotateContext, rotateElement };
@@ -1,20 +1,18 @@
1
- import { TypeElement, TypeElemDesc, TypeElementBase } from '@idraw/types';
2
- import Core from './../index';
3
- export declare function getSelectedElements(core: Core): TypeElement<keyof TypeElemDesc>[];
4
- export declare function getElement(core: Core, uuid: string): TypeElement<keyof TypeElemDesc> | null;
5
- export declare function getElementByIndex(core: Core, index: number): TypeElement<keyof TypeElemDesc> | null;
6
- export declare function updateElement(core: Core, elem: TypeElement<keyof TypeElemDesc>): void;
1
+ import { DataElement, DataElemDesc, DataElementBase } from '@idraw/types';
2
+ import Core from '../index';
3
+ export declare function getSelectedElements(core: Core): DataElement<keyof DataElemDesc>[];
4
+ export declare function getElement(core: Core, uuid: string): DataElement<keyof DataElemDesc> | null;
5
+ export declare function getElementByIndex(core: Core, index: number): DataElement<keyof DataElemDesc> | null;
6
+ export declare function updateElement(core: Core, elem: DataElement<keyof DataElemDesc>): void;
7
7
  export declare function selectElementByIndex(core: Core, index: number): void;
8
8
  export declare function selectElement(core: Core, uuid: string): void;
9
9
  export declare function cancelElementByIndex(core: Core, index: number): void;
10
- export declare function cancelElement(core: Core, uuid: string, opts?: {
11
- useMode?: boolean;
12
- }): void;
10
+ export declare function cancelElement(core: Core, uuid: string): void;
13
11
  export declare function moveUpElement(core: Core, uuid: string): void;
14
12
  export declare function moveDownElement(core: Core, uuid: string): void;
15
- export declare function addElement(core: Core, elem: TypeElementBase<keyof TypeElemDesc>): string | null;
13
+ export declare function addElement(core: Core, elem: DataElementBase<keyof DataElemDesc>): string | null;
16
14
  export declare function deleteElement(core: Core, uuid: string): void;
17
- export declare function insertElementBefore(core: Core, elem: TypeElementBase<keyof TypeElemDesc>, beforeUUID: string): any;
18
- export declare function insertElementBeforeIndex(core: Core, elem: TypeElementBase<keyof TypeElemDesc>, index: number): any;
19
- export declare function insertElementAfter(core: Core, elem: TypeElementBase<keyof TypeElemDesc>, beforeUUID: string): any;
20
- export declare function insertElementAfterIndex(core: Core, elem: TypeElementBase<keyof TypeElemDesc>, index: number): any;
15
+ export declare function insertElementBefore(core: Core, elem: DataElementBase<keyof DataElemDesc>, beforeUUID: string): any;
16
+ export declare function insertElementBeforeIndex(core: Core, elem: DataElementBase<keyof DataElemDesc>, index: number): any;
17
+ export declare function insertElementAfter(core: Core, elem: DataElementBase<keyof DataElemDesc>, beforeUUID: string): any;
18
+ export declare function insertElementAfterIndex(core: Core, elem: DataElementBase<keyof DataElemDesc>, index: number): any;
@@ -1,22 +1,20 @@
1
1
  import { deepClone, createUUID } from '@idraw/util';
2
- import { _data, _element, _engine, _draw, _emitChangeData } from './../names';
3
- import { diffElementResourceChange } from './../lib/diff';
4
- import { Mode } from './../constant/static';
2
+ import { diffElementResourceChange } from '../lib/diff';
3
+ import { Mode } from '../constant/static';
5
4
  export function getSelectedElements(core) {
6
5
  const elems = [];
7
6
  let list = [];
8
- const uuid = core[_engine].temp.get('selectedUUID');
7
+ const uuid = core.getEngine().temp.get('selectedUUID');
9
8
  if (typeof uuid === 'string' && uuid) {
10
9
  list.push(uuid);
11
10
  }
12
11
  else {
13
- list = core[_engine].temp.get('selectedUUIDList');
12
+ list = core.getEngine().temp.get('selectedUUIDList');
14
13
  }
15
14
  list.forEach((uuid) => {
16
- var _a;
17
- const index = core[_engine].helper.getElementIndexByUUID(uuid);
15
+ const index = core.getEngine().helper.getElementIndexByUUID(uuid);
18
16
  if (index !== null && index >= 0) {
19
- const elem = (_a = core[_data]) === null || _a === void 0 ? void 0 : _a.elements[index];
17
+ const elem = core.$data.elements[index];
20
18
  if (elem)
21
19
  elems.push(elem);
22
20
  }
@@ -25,23 +23,23 @@ export function getSelectedElements(core) {
25
23
  }
26
24
  export function getElement(core, uuid) {
27
25
  let elem = null;
28
- const index = core[_engine].helper.getElementIndexByUUID(uuid);
29
- if (index !== null && core[_data].elements[index]) {
30
- elem = deepClone(core[_data].elements[index]);
26
+ const index = core.getEngine().helper.getElementIndexByUUID(uuid);
27
+ if (index !== null && core.$data.elements[index]) {
28
+ elem = deepClone(core.$data.elements[index]);
31
29
  }
32
30
  return elem;
33
31
  }
34
32
  export function getElementByIndex(core, index) {
35
33
  let elem = null;
36
- if (index >= 0 && core[_data].elements[index]) {
37
- elem = deepClone(core[_data].elements[index]);
34
+ if (index >= 0 && core.$data.elements[index]) {
35
+ elem = deepClone(core.$data.elements[index]);
38
36
  }
39
37
  return elem;
40
38
  }
41
39
  export function updateElement(core, elem) {
42
40
  var _a;
43
41
  const _elem = deepClone(elem);
44
- const data = core[_data];
42
+ const data = core.getData();
45
43
  const resourceChangeUUIDs = [];
46
44
  for (let i = 0; i < data.elements.length; i++) {
47
45
  if (_elem.uuid === ((_a = data.elements[i]) === null || _a === void 0 ? void 0 : _a.uuid)) {
@@ -53,86 +51,86 @@ export function updateElement(core, elem) {
53
51
  break;
54
52
  }
55
53
  }
56
- core[_emitChangeData]();
57
- core[_draw]({ resourceChangeUUIDs });
54
+ core.$emitChangeData();
55
+ core.$draw({ resourceChangeUUIDs });
58
56
  }
59
57
  export function selectElementByIndex(core, index) {
60
- if (core[_data].elements[index]) {
61
- const uuid = core[_data].elements[index].uuid;
62
- core[_engine].temp.set('mode', Mode.NULL);
58
+ if (core.$data.elements[index]) {
59
+ const uuid = core.$data.elements[index].uuid;
60
+ core.getEngine().temp.set('mode', Mode.NULL);
63
61
  if (typeof uuid === 'string') {
64
- core[_engine].temp.set('selectedUUID', uuid);
65
- core[_engine].temp.set('selectedUUIDList', []);
62
+ core.getEngine().temp.set('selectedUUID', uuid);
63
+ core.getEngine().temp.set('selectedUUIDList', []);
66
64
  }
67
- core[_draw]();
65
+ core.$draw();
68
66
  }
69
67
  }
70
68
  export function selectElement(core, uuid) {
71
- const index = core[_engine].helper.getElementIndexByUUID(uuid);
69
+ const index = core.getEngine().helper.getElementIndexByUUID(uuid);
72
70
  if (typeof index === 'number' && index >= 0) {
73
71
  core.selectElementByIndex(index);
74
72
  }
75
73
  }
76
74
  export function cancelElementByIndex(core, index) {
77
- if (core[_data].elements[index]) {
78
- const uuid = core[_data].elements[index].uuid;
79
- const selectedUUID = core[_engine].temp.get('selectedUUID');
75
+ if (core.$data.elements[index]) {
76
+ const uuid = core.$data.elements[index].uuid;
77
+ const selectedUUID = core.getEngine().temp.get('selectedUUID');
80
78
  if (typeof uuid === 'string' && uuid === selectedUUID) {
81
- core[_engine].temp.set('mode', Mode.NULL);
82
- core[_engine].temp.set('selectedUUID', null);
83
- core[_engine].temp.set('selectedUUIDList', []);
79
+ core.getEngine().temp.set('mode', Mode.NULL);
80
+ core.getEngine().temp.set('selectedUUID', null);
81
+ core.getEngine().temp.set('selectedUUIDList', []);
84
82
  }
85
- core[_draw]();
83
+ core.$draw();
86
84
  }
87
85
  }
88
- export function cancelElement(core, uuid, opts) {
89
- const index = core[_engine].helper.getElementIndexByUUID(uuid);
86
+ export function cancelElement(core, uuid) {
87
+ const index = core.getEngine().helper.getElementIndexByUUID(uuid);
90
88
  if (typeof index === 'number' && index >= 0) {
91
- core.cancelElementByIndex(index, opts);
89
+ core.cancelElementByIndex(index);
92
90
  }
93
91
  }
94
92
  export function moveUpElement(core, uuid) {
95
- const index = core[_engine].helper.getElementIndexByUUID(uuid);
93
+ const index = core.getEngine().helper.getElementIndexByUUID(uuid);
96
94
  if (typeof index === 'number' &&
97
95
  index >= 0 &&
98
- index < core[_data].elements.length - 1) {
99
- const temp = core[_data].elements[index];
100
- core[_data].elements[index] = core[_data].elements[index + 1];
101
- core[_data].elements[index + 1] = temp;
96
+ index < core.$data.elements.length - 1) {
97
+ const temp = core.$data.elements[index];
98
+ core.$data.elements[index] = core.$data.elements[index + 1];
99
+ core.$data.elements[index + 1] = temp;
102
100
  }
103
- core[_emitChangeData]();
104
- core[_draw]();
101
+ core.$emitChangeData();
102
+ core.$draw();
105
103
  }
106
104
  export function moveDownElement(core, uuid) {
107
- const index = core[_engine].helper.getElementIndexByUUID(uuid);
105
+ const index = core.getEngine().helper.getElementIndexByUUID(uuid);
108
106
  if (typeof index === 'number' &&
109
107
  index > 0 &&
110
- index < core[_data].elements.length) {
111
- const temp = core[_data].elements[index];
112
- core[_data].elements[index] = core[_data].elements[index - 1];
113
- core[_data].elements[index - 1] = temp;
108
+ index < core.$data.elements.length) {
109
+ const temp = core.$data.elements[index];
110
+ core.$data.elements[index] = core.$data.elements[index - 1];
111
+ core.$data.elements[index - 1] = temp;
114
112
  }
115
- core[_emitChangeData]();
116
- core[_draw]();
113
+ core.$emitChangeData();
114
+ core.$draw();
117
115
  }
118
116
  export function addElement(core, elem) {
119
117
  const _elem = deepClone(elem);
120
118
  _elem.uuid = createUUID();
121
- core[_data].elements.push(_elem);
122
- core[_emitChangeData]();
123
- core[_draw]();
119
+ core.$data.elements.push(_elem);
120
+ core.$emitChangeData();
121
+ core.$draw();
124
122
  return _elem.uuid;
125
123
  }
126
124
  export function deleteElement(core, uuid) {
127
- const index = core[_element].getElementIndex(core[_data], uuid);
125
+ const index = core.$getElementHandler().getElementIndex(core.getData(), uuid);
128
126
  if (index >= 0) {
129
- core[_data].elements.splice(index, 1);
130
- core[_emitChangeData]();
131
- core[_draw]();
127
+ core.$data.elements.splice(index, 1);
128
+ core.$emitChangeData();
129
+ core.$draw();
132
130
  }
133
131
  }
134
132
  export function insertElementBefore(core, elem, beforeUUID) {
135
- const index = core[_engine].helper.getElementIndexByUUID(beforeUUID);
133
+ const index = core.getEngine().helper.getElementIndexByUUID(beforeUUID);
136
134
  if (index !== null) {
137
135
  return core.insertElementBeforeIndex(elem, index);
138
136
  }
@@ -142,15 +140,15 @@ export function insertElementBeforeIndex(core, elem, index) {
142
140
  const _elem = deepClone(elem);
143
141
  _elem.uuid = createUUID();
144
142
  if (index >= 0) {
145
- core[_data].elements.splice(index, 0, _elem);
146
- core[_emitChangeData]();
147
- core[_draw]();
143
+ core.$data.elements.splice(index, 0, _elem);
144
+ core.$emitChangeData();
145
+ core.$draw();
148
146
  return _elem.uuid;
149
147
  }
150
148
  return null;
151
149
  }
152
150
  export function insertElementAfter(core, elem, beforeUUID) {
153
- const index = core[_engine].helper.getElementIndexByUUID(beforeUUID);
151
+ const index = core.getEngine().helper.getElementIndexByUUID(beforeUUID);
154
152
  if (index !== null) {
155
153
  return core.insertElementAfterIndex(elem, index);
156
154
  }
@@ -160,9 +158,9 @@ export function insertElementAfterIndex(core, elem, index) {
160
158
  const _elem = deepClone(elem);
161
159
  _elem.uuid = createUUID();
162
160
  if (index >= 0) {
163
- core[_data].elements.splice(index + 1, 0, _elem);
164
- core[_emitChangeData]();
165
- core[_draw]();
161
+ core.$data.elements.splice(index + 1, 0, _elem);
162
+ core.$emitChangeData();
163
+ core.$draw();
166
164
  return _elem.uuid;
167
165
  }
168
166
  return null;
@@ -1,12 +1,12 @@
1
- import { InterfaceHelperPlugin, TypeHelperPluginEventDetail, TypeHelperPluginEventResult } from '@idraw/types';
1
+ import { InterfaceHelperPlugin, HelperPluginEventDetail, HelperPluginEventResult } from '@idraw/types';
2
2
  export declare class HelperPlugin implements Required<InterfaceHelperPlugin> {
3
3
  readonly name: string;
4
4
  readonly uuid: string;
5
5
  constructor();
6
- onHover(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult;
7
- onPoint(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult;
8
- onClick(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult;
9
- onMoveStart(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult;
10
- onMove(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult;
11
- onMoveEnd(detail: TypeHelperPluginEventDetail): void | TypeHelperPluginEventResult;
6
+ onHover(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
7
+ onPoint(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
8
+ onClick(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
9
+ onMoveStart(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
10
+ onMove(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
11
+ onMoveEnd(detail: HelperPluginEventDetail): void | HelperPluginEventResult;
12
12
  }
@@ -8,14 +8,9 @@ export class HelperPlugin {
8
8
  if (detail.controller === null) {
9
9
  }
10
10
  }
11
- onPoint(detail) {
12
- }
13
- onClick(detail) {
14
- }
15
- onMoveStart(detail) {
16
- }
17
- onMove(detail) {
18
- }
19
- onMoveEnd(detail) {
20
- }
11
+ onPoint(detail) { }
12
+ onClick(detail) { }
13
+ onMoveStart(detail) { }
14
+ onMove(detail) { }
15
+ onMoveEnd(detail) { }
21
16
  }