@idraw/util 0.4.0-alpha.5 → 0.4.0-alpha.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.
@@ -7,16 +7,16 @@ export { istype } from './lib/istype';
7
7
  export { loadImage, loadSVG, loadHTML } from './lib/load';
8
8
  export { is } from './lib/is';
9
9
  export { check } from './lib/check';
10
- export { createBoardContexts, createContext2D, createOffscreenContext2D } from './lib/canvas';
10
+ export { createViewContent, createContext2D, createOffscreenContext2D } from './lib/canvas';
11
11
  export { EventEmitter } from './lib/event';
12
12
  export { calcDistance, calcSpeed, equalPoint, equalTouchPoint, vaildPoint, vaildTouchPoint, getCenterFromTwoPoints } from './lib/point';
13
13
  export { Store } from './lib/store';
14
14
  export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
15
15
  export { Context2D } from './lib/context2d';
16
16
  export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
17
- export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, updateElementInList, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement } from './lib/element';
17
+ export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementsFromListByPositions, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement, getElementPositionFromList } from './lib/element';
18
18
  export { checkRectIntersect } from './lib/rect';
19
- export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView } from './lib/view-calc';
19
+ export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo } from './lib/view-calc';
20
20
  export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
21
21
  export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
22
22
  export { calcElementSizeController } from './lib/controller';
@@ -25,5 +25,6 @@ export { generateHTML, parseHTML } from './lib/html';
25
25
  export { compressImage } from './lib/image';
26
26
  export { formatNumber } from './lib/number';
27
27
  export { matrixToAngle, matrixToRadian } from './lib/matrix';
28
- export { getDefaultElementDetailConfig } from './lib/config';
28
+ export { getDefaultElementDetailConfig, getDefaultElementRectDetail } from './lib/config';
29
29
  export { calcViewBoxSize } from './lib/view-box';
30
+ export { createElement, insertElementToListByPosition, deleteElementInListByPosition, deleteElementInList, moveElementPosition, updateElementInList } from './lib/handle-element';
package/dist/esm/index.js CHANGED
@@ -7,16 +7,16 @@ export { istype } from './lib/istype';
7
7
  export { loadImage, loadSVG, loadHTML } from './lib/load';
8
8
  export { is } from './lib/is';
9
9
  export { check } from './lib/check';
10
- export { createBoardContexts, createContext2D, createOffscreenContext2D } from './lib/canvas';
10
+ export { createViewContent, createContext2D, createOffscreenContext2D } from './lib/canvas';
11
11
  export { EventEmitter } from './lib/event';
12
12
  export { calcDistance, calcSpeed, equalPoint, equalTouchPoint, vaildPoint, vaildTouchPoint, getCenterFromTwoPoints } from './lib/point';
13
13
  export { Store } from './lib/store';
14
14
  export { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from './lib/middleware';
15
15
  export { Context2D } from './lib/context2d';
16
16
  export { rotateElement, parseRadianToAngle, parseAngleToRadian, rotateElementVertexes, getElementRotateVertexes, calcElementCenter, calcElementCenterFromVertexes, rotatePointInGroup, limitAngle } from './lib/rotate';
17
- export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, updateElementInList, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement } from './lib/element';
17
+ export { getSelectedElementUUIDs, validateElements, calcElementsContextSize, calcElementsViewInfo, getElemenetsAssetIds, findElementFromList, findElementsFromList, findElementFromListByPosition, findElementsFromListByPositions, getGroupQueueFromList, getElementSize, mergeElementAsset, filterElementAsset, isResourceElement, getElementPositionFromList } from './lib/element';
18
18
  export { checkRectIntersect } from './lib/rect';
19
- export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView } from './lib/view-calc';
19
+ export { viewScale, viewScroll, calcViewElementSize, calcViewPointSize, calcViewVertexes, isViewPointInElement, getViewPointAtElement, isElementInView, calcViewScaleInfo } from './lib/view-calc';
20
20
  export { rotatePoint, rotateVertexes, rotateByCenter } from './lib/rotate';
21
21
  export { getElementVertexes, calcElementVertexesInGroup, calcElementVertexesQueueInGroup, calcElementQueueVertexesQueueInGroup } from './lib/vertex';
22
22
  export { calcElementSizeController } from './lib/controller';
@@ -25,5 +25,6 @@ export { generateHTML, parseHTML } from './lib/html';
25
25
  export { compressImage } from './lib/image';
26
26
  export { formatNumber } from './lib/number';
27
27
  export { matrixToAngle, matrixToRadian } from './lib/matrix';
28
- export { getDefaultElementDetailConfig } from './lib/config';
28
+ export { getDefaultElementDetailConfig, getDefaultElementRectDetail } from './lib/config';
29
29
  export { calcViewBoxSize } from './lib/view-box';
30
+ export { createElement, insertElementToListByPosition, deleteElementInListByPosition, deleteElementInList, moveElementPosition, updateElementInList } from './lib/handle-element';
@@ -9,7 +9,11 @@ export declare function createContext2D(opts: {
9
9
  export declare function createOffscreenContext2D(opts: {
10
10
  width: number;
11
11
  height: number;
12
- }): CanvasRenderingContext2D | OffscreenRenderingContext;
13
- export declare function createBoardContexts(ctx: CanvasRenderingContext2D, opts?: {
14
12
  devicePixelRatio: number;
13
+ }): Context2D;
14
+ export declare function createViewContent(canvas: HTMLCanvasElement, opts: {
15
+ width: number;
16
+ height: number;
17
+ devicePixelRatio: number;
18
+ offscreen?: boolean;
15
19
  }): ViewContent;
@@ -12,27 +12,70 @@ export function createContext2D(opts) {
12
12
  return context2d;
13
13
  }
14
14
  export function createOffscreenContext2D(opts) {
15
- const { width, height } = opts;
16
- const offCanvas = new OffscreenCanvas(width, height);
15
+ const { width, height, devicePixelRatio } = opts;
16
+ const offCanvas = new OffscreenCanvas(width * devicePixelRatio, height * devicePixelRatio);
17
17
  const offRenderCtx = offCanvas.getContext('2d');
18
18
  const offCtx = offRenderCtx.canvas.getContext('2d');
19
- return offCtx;
19
+ const context2d = new Context2D(offCtx, {
20
+ devicePixelRatio,
21
+ offscreenCanvas: offCanvas
22
+ });
23
+ return context2d;
20
24
  }
21
- export function createBoardContexts(ctx, opts) {
25
+ export function createViewContent(canvas, opts) {
26
+ const { width, height, devicePixelRatio, offscreen } = opts;
22
27
  const ctxOpts = {
23
- width: ctx.canvas.width,
24
- height: ctx.canvas.height,
25
- devicePixelRatio: (opts === null || opts === void 0 ? void 0 : opts.devicePixelRatio) || 1
26
- };
27
- const viewContext = createContext2D(ctxOpts);
28
- const helperContext = createContext2D(ctxOpts);
29
- const underContext = createContext2D(ctxOpts);
30
- const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
31
- const content = {
32
- underContext,
33
- viewContext,
34
- helperContext,
35
- boardContext
28
+ width,
29
+ height,
30
+ devicePixelRatio
36
31
  };
37
- return content;
32
+ if (offscreen === true) {
33
+ const ctx = canvas.getContext('2d');
34
+ const viewContext = createOffscreenContext2D(ctxOpts);
35
+ const helperContext = createOffscreenContext2D(ctxOpts);
36
+ const underContext = createOffscreenContext2D(ctxOpts);
37
+ const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
38
+ const drawView = () => {
39
+ const { width: w, height: h } = viewContext.$getSize();
40
+ boardContext.clearRect(0, 0, w, h);
41
+ boardContext.drawImage(underContext.canvas, 0, 0, w, h);
42
+ boardContext.drawImage(viewContext.canvas, 0, 0, w, h);
43
+ boardContext.drawImage(helperContext.canvas, 0, 0, w, h);
44
+ underContext.clearRect(0, 0, w, h);
45
+ viewContext.clearRect(0, 0, w, h);
46
+ helperContext.clearRect(0, 0, w, h);
47
+ };
48
+ const content = {
49
+ underContext,
50
+ viewContext,
51
+ helperContext,
52
+ boardContext,
53
+ drawView
54
+ };
55
+ return content;
56
+ }
57
+ else {
58
+ const ctx = canvas.getContext('2d');
59
+ const viewContext = createContext2D(ctxOpts);
60
+ const helperContext = createContext2D(ctxOpts);
61
+ const underContext = createContext2D(ctxOpts);
62
+ const boardContext = createContext2D(Object.assign({ ctx }, ctxOpts));
63
+ const drawView = () => {
64
+ boardContext.clearRect(0, 0, width, height);
65
+ boardContext.drawImage(underContext.canvas, 0, 0, width, height);
66
+ boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
67
+ boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
68
+ underContext.clearRect(0, 0, width, height);
69
+ viewContext.clearRect(0, 0, width, height);
70
+ helperContext.clearRect(0, 0, width, height);
71
+ };
72
+ const content = {
73
+ underContext,
74
+ viewContext,
75
+ helperContext,
76
+ boardContext,
77
+ drawView
78
+ };
79
+ return content;
80
+ }
38
81
  }
@@ -1,2 +1,14 @@
1
- import type { DefaultElementDetailConfig } from '@idraw/types';
1
+ import type { ViewScaleInfo, DefaultElementDetailConfig, ElementRectDetail, ElementCircleDetail, ElementTextDetail, ElementSVGDetail, ElementImageDetail, ElementGroupDetail } from '@idraw/types';
2
2
  export declare function getDefaultElementDetailConfig(): DefaultElementDetailConfig;
3
+ export declare function getDefaultElementRectDetail(): ElementRectDetail;
4
+ export declare function getDefaultElementCircleDetail(opts: {
5
+ radius: number;
6
+ }): ElementCircleDetail;
7
+ export declare function getDefaultElementTextDetail(opts?: {
8
+ viewScaleInfo: ViewScaleInfo;
9
+ }): ElementTextDetail;
10
+ export declare function getDefaultElementSVGDetail(): ElementSVGDetail;
11
+ export declare function getDefaultElementImageDetail(): ElementImageDetail;
12
+ export declare function getDefaultElementGroupDetail(opts?: {
13
+ viewScaleInfo: ViewScaleInfo;
14
+ }): ElementGroupDetail;
@@ -1,6 +1,6 @@
1
1
  export function getDefaultElementDetailConfig() {
2
2
  const config = {
3
- boxSizing: 'center-line',
3
+ boxSizing: 'border-box',
4
4
  borderWidth: 0,
5
5
  borderColor: '#000000',
6
6
  shadowColor: '#000000',
@@ -16,7 +16,57 @@ export function getDefaultElementDetailConfig() {
16
16
  fontSize: 16,
17
17
  lineHeight: 20,
18
18
  fontFamily: 'sans-serif',
19
- fontWeight: 400
19
+ fontWeight: 400,
20
+ overflow: 'hidden'
20
21
  };
21
22
  return config;
22
23
  }
24
+ export function getDefaultElementRectDetail() {
25
+ const detail = {
26
+ background: '#D9D9D9'
27
+ };
28
+ return detail;
29
+ }
30
+ export function getDefaultElementCircleDetail(opts) {
31
+ const detail = {
32
+ background: '#D9D9D9',
33
+ radius: 0
34
+ };
35
+ return detail;
36
+ }
37
+ export function getDefaultElementTextDetail(opts) {
38
+ var _a;
39
+ const detailConfig = getDefaultElementDetailConfig();
40
+ const scale = ((_a = opts === null || opts === void 0 ? void 0 : opts.viewScaleInfo) === null || _a === void 0 ? void 0 : _a.scale) || 1;
41
+ const detail = {
42
+ text: 'Text Element',
43
+ color: detailConfig.color,
44
+ fontFamily: detailConfig.fontFamily,
45
+ fontWeight: detailConfig.fontWeight,
46
+ lineHeight: detailConfig.fontSize * scale,
47
+ fontSize: detailConfig.fontSize * scale,
48
+ textAlign: 'center',
49
+ verticalAlign: 'middle'
50
+ };
51
+ return detail;
52
+ }
53
+ export function getDefaultElementSVGDetail() {
54
+ const detail = {
55
+ svg: '<svg t="1701004189871" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3-12.3 12.7-12.1 32.9 0.6 45.3l183.7 179.1-43.4 252.9c-1.2 6.9-0.1 14.1 3.2 20.3 8.2 15.6 27.6 21.7 43.2 13.4L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3zM664.8 561.6l36.1 210.3L512 672.7 323.1 772l36.1-210.3-152.8-149L417.6 382 512 190.7 606.4 382l211.2 30.7-152.8 148.9z" fill="#2c2c2c"></path></svg>'
56
+ };
57
+ return detail;
58
+ }
59
+ export function getDefaultElementImageDetail() {
60
+ const detail = {
61
+ src: 'data:image/svg+xml;base64,PHN2ZyAgIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiPjxwYXRoIGQ9Ik05MjggMTYwSDk2Yy0xNy43IDAtMzIgMTQuMy0zMiAzMnY2NDBjMCAxNy43IDE0LjMgMzIgMzIgMzJoODMyYzE3LjcgMCAzMi0xNC4zIDMyLTMyVjE5MmMwLTE3LjctMTQuMy0zMi0zMi0zMnogbS00MCA2MzJIMTM2di0zOS45bDEzOC41LTE2NC4zIDE1MC4xIDE3OEw2NTguMSA0ODkgODg4IDc2MS42Vjc5MnogbTAtMTI5LjhMNjY0LjIgMzk2LjhjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDQyNC42IDY2Ni40bC0xNDQtMTcwLjdjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDEzNiA2NTIuN1YyMzJoNzUydjQzMC4yeiIgIGZpbGw9IiM1MTUxNTEiPjwvcGF0aD48cGF0aCBkPSJNMzA0IDQ1NmM0OC42IDAgODgtMzkuNCA4OC04OHMtMzkuNC04OC04OC04OC04OCAzOS40LTg4IDg4IDM5LjQgODggODggODh6IG0wLTExNmMxNS41IDAgMjggMTIuNSAyOCAyOHMtMTIuNSAyOC0yOCAyOC0yOC0xMi41LTI4LTI4IDEyLjUtMjggMjgtMjh6IiAgZmlsbD0iIzUxNTE1MSI+PC9wYXRoPjwvc3ZnPg=='
62
+ };
63
+ return detail;
64
+ }
65
+ export function getDefaultElementGroupDetail(opts) {
66
+ const detail = {
67
+ children: [],
68
+ background: '#D9D9D9',
69
+ overflow: 'hidden'
70
+ };
71
+ return detail;
72
+ }
@@ -1,8 +1,7 @@
1
1
  import type { ViewContext2D, ViewContext2DOptions } from '@idraw/types';
2
2
  export declare class Context2D implements ViewContext2D {
3
- private _ctx;
4
- private _devicePixelRatio;
5
- constructor(ctx: CanvasRenderingContext2D, opts: ViewContext2DOptions);
3
+ #private;
4
+ constructor(ctx: CanvasRenderingContext2D | OffscreenRenderingContext, opts: ViewContext2DOptions);
6
5
  $undoPixelRatio(num: number): number;
7
6
  $doPixelRatio(num: number): number;
8
7
  $getContext(): CanvasRenderingContext2D;
@@ -11,11 +10,18 @@ export declare class Context2D implements ViewContext2D {
11
10
  fontFamily?: string;
12
11
  fontWeight?: 'bold' | number | string;
13
12
  }): void;
13
+ $getOffscreenCanvas(): OffscreenCanvas | null;
14
14
  $resize(opts: {
15
15
  width: number;
16
16
  height: number;
17
17
  devicePixelRatio: number;
18
+ resetStyle?: boolean;
18
19
  }): void;
20
+ $getSize(): {
21
+ width: number;
22
+ height: number;
23
+ devicePixelRatio: number;
24
+ };
19
25
  get canvas(): HTMLCanvasElement;
20
26
  get fillStyle(): string | CanvasGradient | CanvasPattern;
21
27
  set fillStyle(value: string | CanvasGradient | CanvasPattern);
@@ -1,18 +1,30 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Context2D_ctx, _Context2D_opts;
1
13
  export class Context2D {
2
14
  constructor(ctx, opts) {
3
- this._devicePixelRatio = 1;
4
- const { devicePixelRatio = 1 } = opts;
5
- this._ctx = ctx;
6
- this._devicePixelRatio = devicePixelRatio;
15
+ _Context2D_ctx.set(this, void 0);
16
+ _Context2D_opts.set(this, void 0);
17
+ __classPrivateFieldSet(this, _Context2D_ctx, ctx, "f");
18
+ __classPrivateFieldSet(this, _Context2D_opts, Object.assign({ devicePixelRatio: 1, offscreenCanvas: null }, opts), "f");
7
19
  }
8
20
  $undoPixelRatio(num) {
9
- return num / this._devicePixelRatio;
21
+ return num / __classPrivateFieldGet(this, _Context2D_opts, "f").devicePixelRatio;
10
22
  }
11
23
  $doPixelRatio(num) {
12
- return this._devicePixelRatio * num;
24
+ return __classPrivateFieldGet(this, _Context2D_opts, "f").devicePixelRatio * num;
13
25
  }
14
26
  $getContext() {
15
- return this._ctx;
27
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f");
16
28
  }
17
29
  $setFont(opts) {
18
30
  const strList = [];
@@ -21,135 +33,153 @@ export class Context2D {
21
33
  }
22
34
  strList.push(`${this.$doPixelRatio(opts.fontSize || 12)}px`);
23
35
  strList.push(`${opts.fontFamily || 'sans-serif'}`);
24
- this._ctx.font = `${strList.join(' ')}`;
36
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").font = `${strList.join(' ')}`;
37
+ }
38
+ $getOffscreenCanvas() {
39
+ return __classPrivateFieldGet(this, _Context2D_opts, "f").offscreenCanvas;
25
40
  }
26
41
  $resize(opts) {
27
- const { width, height, devicePixelRatio } = opts;
28
- const { canvas } = this._ctx;
42
+ const { width, height, devicePixelRatio, resetStyle } = opts;
43
+ const { canvas } = __classPrivateFieldGet(this, _Context2D_ctx, "f");
29
44
  canvas.width = width * devicePixelRatio;
30
45
  canvas.height = height * devicePixelRatio;
31
- this._devicePixelRatio = devicePixelRatio;
46
+ __classPrivateFieldSet(this, _Context2D_opts, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Context2D_opts, "f")), {
47
+ devicePixelRatio
48
+ }), "f");
49
+ if (resetStyle === true) {
50
+ canvas.style.width = `${width}px`;
51
+ canvas.style.height = `${height}px`;
52
+ }
53
+ }
54
+ $getSize() {
55
+ const { devicePixelRatio } = __classPrivateFieldGet(this, _Context2D_opts, "f");
56
+ const { width, height } = __classPrivateFieldGet(this, _Context2D_ctx, "f").canvas;
57
+ return {
58
+ width: width / devicePixelRatio,
59
+ height: height / devicePixelRatio,
60
+ devicePixelRatio
61
+ };
32
62
  }
33
63
  get canvas() {
34
- return this._ctx.canvas;
64
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").canvas;
35
65
  }
36
66
  get fillStyle() {
37
- return this._ctx.fillStyle;
67
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").fillStyle;
38
68
  }
39
69
  set fillStyle(value) {
40
- this._ctx.fillStyle = value;
70
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").fillStyle = value;
41
71
  }
42
72
  get strokeStyle() {
43
- return this._ctx.strokeStyle;
73
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").strokeStyle;
44
74
  }
45
75
  set strokeStyle(color) {
46
- this._ctx.strokeStyle = color;
76
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").strokeStyle = color;
47
77
  }
48
78
  get lineWidth() {
49
- return this.$undoPixelRatio(this._ctx.lineWidth);
79
+ return this.$undoPixelRatio(__classPrivateFieldGet(this, _Context2D_ctx, "f").lineWidth);
50
80
  }
51
81
  set lineWidth(w) {
52
- this._ctx.lineWidth = this.$doPixelRatio(w);
82
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").lineWidth = this.$doPixelRatio(w);
53
83
  }
54
84
  get textAlign() {
55
- return this._ctx.textAlign;
85
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").textAlign;
56
86
  }
57
87
  set textAlign(align) {
58
- this._ctx.textAlign = align;
88
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").textAlign = align;
59
89
  }
60
90
  get textBaseline() {
61
- return this._ctx.textBaseline;
91
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").textBaseline;
62
92
  }
63
93
  set textBaseline(baseline) {
64
- this._ctx.textBaseline = baseline;
94
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").textBaseline = baseline;
65
95
  }
66
96
  get globalAlpha() {
67
- return this._ctx.globalAlpha;
97
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").globalAlpha;
68
98
  }
69
99
  set globalAlpha(alpha) {
70
- this._ctx.globalAlpha = alpha;
100
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").globalAlpha = alpha;
71
101
  }
72
102
  get shadowColor() {
73
- return this._ctx.shadowColor;
103
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").shadowColor;
74
104
  }
75
105
  set shadowColor(color) {
76
- this._ctx.shadowColor = color;
106
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").shadowColor = color;
77
107
  }
78
108
  get shadowOffsetX() {
79
- return this.$undoPixelRatio(this._ctx.shadowOffsetX);
109
+ return this.$undoPixelRatio(__classPrivateFieldGet(this, _Context2D_ctx, "f").shadowOffsetX);
80
110
  }
81
111
  set shadowOffsetX(offsetX) {
82
- this._ctx.shadowOffsetX = this.$doPixelRatio(offsetX);
112
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").shadowOffsetX = this.$doPixelRatio(offsetX);
83
113
  }
84
114
  get shadowOffsetY() {
85
- return this.$undoPixelRatio(this._ctx.shadowOffsetY);
115
+ return this.$undoPixelRatio(__classPrivateFieldGet(this, _Context2D_ctx, "f").shadowOffsetY);
86
116
  }
87
117
  set shadowOffsetY(offsetY) {
88
- this._ctx.shadowOffsetY = this.$doPixelRatio(offsetY);
118
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").shadowOffsetY = this.$doPixelRatio(offsetY);
89
119
  }
90
120
  get shadowBlur() {
91
- return this.$undoPixelRatio(this._ctx.shadowBlur);
121
+ return this.$undoPixelRatio(__classPrivateFieldGet(this, _Context2D_ctx, "f").shadowBlur);
92
122
  }
93
123
  set shadowBlur(blur) {
94
- this._ctx.shadowBlur = this.$doPixelRatio(blur);
124
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").shadowBlur = this.$doPixelRatio(blur);
95
125
  }
96
126
  get lineCap() {
97
- return this._ctx.lineCap;
127
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").lineCap;
98
128
  }
99
129
  set lineCap(lineCap) {
100
- this._ctx.lineCap = lineCap;
130
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").lineCap = lineCap;
101
131
  }
102
132
  get globalCompositeOperation() {
103
- return this._ctx.globalCompositeOperation;
133
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").globalCompositeOperation;
104
134
  }
105
135
  set globalCompositeOperation(operations) {
106
- this._ctx.globalCompositeOperation = operations;
136
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").globalCompositeOperation = operations;
107
137
  }
108
138
  fill(...args) {
109
- return this._ctx.fill(...args);
139
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").fill(...args);
110
140
  }
111
141
  arc(x, y, radius, startAngle, endAngle, anticlockwise) {
112
- return this._ctx.arc(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(radius), startAngle, endAngle, anticlockwise);
142
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").arc(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(radius), startAngle, endAngle, anticlockwise);
113
143
  }
114
144
  rect(x, y, w, h) {
115
- return this._ctx.rect(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(w), this.$doPixelRatio(h));
145
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").rect(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(w), this.$doPixelRatio(h));
116
146
  }
117
147
  fillRect(x, y, w, h) {
118
- return this._ctx.fillRect(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(w), this.$doPixelRatio(h));
148
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").fillRect(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(w), this.$doPixelRatio(h));
119
149
  }
120
150
  clearRect(x, y, w, h) {
121
- return this._ctx.clearRect(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(w), this.$doPixelRatio(h));
151
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").clearRect(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(w), this.$doPixelRatio(h));
122
152
  }
123
153
  beginPath() {
124
- return this._ctx.beginPath();
154
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").beginPath();
125
155
  }
126
156
  closePath() {
127
- return this._ctx.closePath();
157
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").closePath();
128
158
  }
129
159
  lineTo(x, y) {
130
- return this._ctx.lineTo(this.$doPixelRatio(x), this.$doPixelRatio(y));
160
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").lineTo(this.$doPixelRatio(x), this.$doPixelRatio(y));
131
161
  }
132
162
  moveTo(x, y) {
133
- return this._ctx.moveTo(this.$doPixelRatio(x), this.$doPixelRatio(y));
163
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").moveTo(this.$doPixelRatio(x), this.$doPixelRatio(y));
134
164
  }
135
165
  arcTo(x1, y1, x2, y2, radius) {
136
- return this._ctx.arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
166
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
137
167
  }
138
168
  getLineDash() {
139
- return this._ctx.getLineDash();
169
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").getLineDash();
140
170
  }
141
171
  setLineDash(nums) {
142
172
  const dash = nums.map((n) => this.$doPixelRatio(n));
143
- return this._ctx.setLineDash(dash);
173
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").setLineDash(dash);
144
174
  }
145
175
  stroke(path) {
146
- return path ? this._ctx.stroke(path) : this._ctx.stroke();
176
+ return path ? __classPrivateFieldGet(this, _Context2D_ctx, "f").stroke(path) : __classPrivateFieldGet(this, _Context2D_ctx, "f").stroke();
147
177
  }
148
178
  translate(x, y) {
149
- return this._ctx.translate(this.$doPixelRatio(x), this.$doPixelRatio(y));
179
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").translate(this.$doPixelRatio(x), this.$doPixelRatio(y));
150
180
  }
151
181
  rotate(angle) {
152
- return this._ctx.rotate(angle);
182
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").rotate(angle);
153
183
  }
154
184
  drawImage(...args) {
155
185
  const image = args[0];
@@ -162,66 +192,67 @@ export class Context2D {
162
192
  const dw = args[args.length - 2];
163
193
  const dh = args[args.length - 1];
164
194
  if (args.length === 9) {
165
- return this._ctx.drawImage(image, this.$doPixelRatio(sx), this.$doPixelRatio(sy), this.$doPixelRatio(sw), this.$doPixelRatio(sh), this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
195
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").drawImage(image, this.$doPixelRatio(sx), this.$doPixelRatio(sy), this.$doPixelRatio(sw), this.$doPixelRatio(sh), this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
166
196
  }
167
197
  else {
168
- return this._ctx.drawImage(image, this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
198
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").drawImage(image, this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
169
199
  }
170
200
  }
171
201
  createPattern(image, repetition) {
172
- return this._ctx.createPattern(image, repetition);
202
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").createPattern(image, repetition);
173
203
  }
174
204
  measureText(text) {
175
- const textMetrics = this._ctx.measureText(text);
205
+ const textMetrics = __classPrivateFieldGet(this, _Context2D_ctx, "f").measureText(text);
176
206
  return textMetrics;
177
207
  }
178
208
  fillText(text, x, y, maxWidth) {
179
209
  if (maxWidth !== undefined) {
180
- return this._ctx.fillText(text, this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(maxWidth));
210
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").fillText(text, this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(maxWidth));
181
211
  }
182
212
  else {
183
- return this._ctx.fillText(text, this.$doPixelRatio(x), this.$doPixelRatio(y));
213
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").fillText(text, this.$doPixelRatio(x), this.$doPixelRatio(y));
184
214
  }
185
215
  }
186
216
  strokeText(text, x, y, maxWidth) {
187
217
  if (maxWidth !== undefined) {
188
- return this._ctx.strokeText(text, this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(maxWidth));
218
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").strokeText(text, this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(maxWidth));
189
219
  }
190
220
  else {
191
- return this._ctx.strokeText(text, this.$doPixelRatio(x), this.$doPixelRatio(y));
221
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").strokeText(text, this.$doPixelRatio(x), this.$doPixelRatio(y));
192
222
  }
193
223
  }
194
224
  save() {
195
- this._ctx.save();
225
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").save();
196
226
  }
197
227
  restore() {
198
- this._ctx.restore();
228
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").restore();
199
229
  }
200
230
  scale(ratioX, ratioY) {
201
- this._ctx.scale(ratioX, ratioY);
231
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").scale(ratioX, ratioY);
202
232
  }
203
233
  circle(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
204
- this._ctx.ellipse(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(radiusX), this.$doPixelRatio(radiusY), rotation, startAngle, endAngle, counterclockwise);
234
+ __classPrivateFieldGet(this, _Context2D_ctx, "f").ellipse(this.$doPixelRatio(x), this.$doPixelRatio(y), this.$doPixelRatio(radiusX), this.$doPixelRatio(radiusY), rotation, startAngle, endAngle, counterclockwise);
205
235
  }
206
236
  isPointInPath(x, y) {
207
- return this._ctx.isPointInPath(this.$doPixelRatio(x), this.$doPixelRatio(y));
237
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").isPointInPath(this.$doPixelRatio(x), this.$doPixelRatio(y));
208
238
  }
209
239
  clip(...args) {
210
- return this._ctx.clip(...args);
240
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").clip(...args);
211
241
  }
212
242
  setTransform(a, b, c, d, e, f) {
213
- return this._ctx.setTransform(a, b, c, d, e, f);
243
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").setTransform(a, b, c, d, e, f);
214
244
  }
215
245
  getTransform() {
216
- return this._ctx.getTransform();
246
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").getTransform();
217
247
  }
218
248
  createLinearGradient(x0, y0, x1, y1) {
219
- return this._ctx.createLinearGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(x1), this.$doPixelRatio(y1));
249
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").createLinearGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(x1), this.$doPixelRatio(y1));
220
250
  }
221
251
  createRadialGradient(x0, y0, r0, x1, y1, r1) {
222
- return this._ctx.createRadialGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(r0), this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(r1));
252
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").createRadialGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(r0), this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(r1));
223
253
  }
224
254
  createConicGradient(startAngle, x, y) {
225
- return this._ctx.createConicGradient(startAngle, this.$doPixelRatio(x), this.$doPixelRatio(y));
255
+ return __classPrivateFieldGet(this, _Context2D_ctx, "f").createConicGradient(startAngle, this.$doPixelRatio(x), this.$doPixelRatio(y));
226
256
  }
227
257
  }
258
+ _Context2D_ctx = new WeakMap(), _Context2D_opts = new WeakMap();
@@ -1,4 +1,4 @@
1
- import type { Data, Element, Elements, ElementType, ElementSize, ViewContextSize, ViewSizeInfo, RecursivePartial, ElementAssets, ElementAssetsItem, LoadElementType } from '@idraw/types';
1
+ import type { Data, Element, Elements, ElementType, ElementSize, ViewContextSize, ViewSizeInfo, ElementAssets, ElementAssetsItem, LoadElementType, ElementPosition } from '@idraw/types';
2
2
  export declare function getSelectedElementUUIDs(data: Data, indexes: Array<number | string>): string[];
3
3
  export declare function validateElements(elements: Array<Element<ElementType>>): boolean;
4
4
  export declare function calcElementsContextSize(elements: Array<Element<ElementType>>, opts?: {
@@ -15,7 +15,6 @@ export declare function getElemenetsAssetIds(elements: Elements): string[];
15
15
  export declare function findElementFromList(uuid: string, list: Element<ElementType>[]): Element<ElementType> | null;
16
16
  export declare function findElementsFromList(uuids: string[], list: Element<ElementType>[]): Element<ElementType>[];
17
17
  export declare function getGroupQueueFromList(uuid: string, elements: Element<ElementType>[]): Element<'group'>[];
18
- export declare function updateElementInList(uuid: string, updateContent: RecursivePartial<Element<ElementType>>, elements: Element[]): Element | null;
19
18
  export declare function getElementSize(elem: Element): ElementSize;
20
19
  export declare function mergeElementAsset<T extends Element<LoadElementType>>(element: T, assets: ElementAssets): T;
21
20
  export declare function filterElementAsset<T extends Element<LoadElementType>>(element: T): {
@@ -24,3 +23,6 @@ export declare function filterElementAsset<T extends Element<LoadElementType>>(e
24
23
  assetItem: ElementAssetsItem | null;
25
24
  };
26
25
  export declare function isResourceElement(elem: Element): boolean;
26
+ export declare function findElementsFromListByPositions(positions: ElementPosition[], list: Element[]): Element[];
27
+ export declare function findElementFromListByPosition(position: ElementPosition, list: Element[]): Element | null;
28
+ export declare function getElementPositionFromList(uuid: string, elements: Element<ElementType>[]): ElementPosition;