@idraw/core 0.4.0-beta.39 → 0.4.0-beta.40

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.
@@ -0,0 +1,165 @@
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 _Viewer_instances, _Viewer_opts, _Viewer_drawFrameSnapshotQueue, _Viewer_drawFrameStatus, _Viewer_init, _Viewer_drawAnimationFrame;
13
+ import { EventEmitter, viewScale, viewScroll, calcViewScaleInfo } from '@idraw/util';
14
+ const { requestAnimationFrame } = window;
15
+ export class Viewer extends EventEmitter {
16
+ constructor(opts) {
17
+ super();
18
+ _Viewer_instances.add(this);
19
+ _Viewer_opts.set(this, void 0);
20
+ _Viewer_drawFrameSnapshotQueue.set(this, []);
21
+ _Viewer_drawFrameStatus.set(this, 'FREE');
22
+ __classPrivateFieldSet(this, _Viewer_opts, opts, "f");
23
+ __classPrivateFieldGet(this, _Viewer_instances, "m", _Viewer_init).call(this);
24
+ }
25
+ resetVirtualFlatItemMap(data, opts) {
26
+ if (data) {
27
+ __classPrivateFieldGet(this, _Viewer_opts, "f").calculator.resetVirtualFlatItemMap(data, opts);
28
+ }
29
+ }
30
+ drawFrame() {
31
+ const { sharer } = __classPrivateFieldGet(this, _Viewer_opts, "f");
32
+ const activeStore = sharer.getActiveStoreSnapshot();
33
+ const sharedStore = sharer.getSharedStoreSnapshot();
34
+ __classPrivateFieldGet(this, _Viewer_drawFrameSnapshotQueue, "f").push({
35
+ activeStore,
36
+ sharedStore
37
+ });
38
+ __classPrivateFieldGet(this, _Viewer_instances, "m", _Viewer_drawAnimationFrame).call(this);
39
+ }
40
+ scale(opts) {
41
+ const { scale, point, ignoreUpdateVisibleStatus } = opts;
42
+ const { sharer } = __classPrivateFieldGet(this, _Viewer_opts, "f");
43
+ const { moveX, moveY } = viewScale({
44
+ scale,
45
+ point,
46
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
47
+ viewSizeInfo: sharer.getActiveViewSizeInfo()
48
+ });
49
+ sharer.setActiveStorage('scale', scale);
50
+ if (!ignoreUpdateVisibleStatus) {
51
+ __classPrivateFieldGet(this, _Viewer_opts, "f").calculator.updateVisiableStatus({
52
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
53
+ viewSizeInfo: sharer.getActiveViewSizeInfo()
54
+ });
55
+ }
56
+ return { moveX, moveY };
57
+ }
58
+ scroll(opts) {
59
+ const { sharer } = __classPrivateFieldGet(this, _Viewer_opts, "f");
60
+ const prevViewScaleInfo = sharer.getActiveViewScaleInfo();
61
+ const { moveX, moveY, ignoreUpdateVisibleStatus } = opts;
62
+ const viewSizeInfo = sharer.getActiveViewSizeInfo();
63
+ const viewScaleInfo = viewScroll({
64
+ moveX,
65
+ moveY,
66
+ viewScaleInfo: prevViewScaleInfo,
67
+ viewSizeInfo
68
+ });
69
+ sharer.setActiveViewScaleInfo(viewScaleInfo);
70
+ if (!ignoreUpdateVisibleStatus) {
71
+ __classPrivateFieldGet(this, _Viewer_opts, "f").calculator.updateVisiableStatus({
72
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
73
+ viewSizeInfo: sharer.getActiveViewSizeInfo()
74
+ });
75
+ }
76
+ return viewScaleInfo;
77
+ }
78
+ updateViewScaleInfo(opts) {
79
+ const { sharer } = __classPrivateFieldGet(this, _Viewer_opts, "f");
80
+ const viewScaleInfo = calcViewScaleInfo(opts, {
81
+ viewSizeInfo: sharer.getActiveViewSizeInfo()
82
+ });
83
+ sharer.setActiveViewScaleInfo(viewScaleInfo);
84
+ __classPrivateFieldGet(this, _Viewer_opts, "f").calculator.updateVisiableStatus({
85
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
86
+ viewSizeInfo: sharer.getActiveViewSizeInfo()
87
+ });
88
+ return viewScaleInfo;
89
+ }
90
+ resize(viewSize = {}, opts) {
91
+ const { sharer } = __classPrivateFieldGet(this, _Viewer_opts, "f");
92
+ const originViewSize = sharer.getActiveViewSizeInfo();
93
+ const newViewSize = Object.assign(Object.assign({}, originViewSize), viewSize);
94
+ const { width, height, devicePixelRatio } = newViewSize;
95
+ const { underlayContext, boardContext, overlayContext, viewContext } = __classPrivateFieldGet(this, _Viewer_opts, "f").boardContent;
96
+ boardContext.canvas.width = width * devicePixelRatio;
97
+ boardContext.canvas.height = height * devicePixelRatio;
98
+ boardContext.canvas.style.width = `${width}px`;
99
+ boardContext.canvas.style.height = `${height}px`;
100
+ underlayContext.canvas.width = width * devicePixelRatio;
101
+ underlayContext.canvas.height = height * devicePixelRatio;
102
+ overlayContext.canvas.width = width * devicePixelRatio;
103
+ overlayContext.canvas.height = height * devicePixelRatio;
104
+ viewContext.canvas.width = width * devicePixelRatio;
105
+ viewContext.canvas.height = height * devicePixelRatio;
106
+ sharer.setActiveViewSizeInfo(newViewSize);
107
+ if (!(opts === null || opts === void 0 ? void 0 : opts.ignoreUpdateVisibleStatus)) {
108
+ __classPrivateFieldGet(this, _Viewer_opts, "f").calculator.updateVisiableStatus({
109
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
110
+ viewSizeInfo: sharer.getActiveViewSizeInfo()
111
+ });
112
+ }
113
+ return newViewSize;
114
+ }
115
+ }
116
+ _Viewer_opts = new WeakMap(), _Viewer_drawFrameSnapshotQueue = new WeakMap(), _Viewer_drawFrameStatus = new WeakMap(), _Viewer_instances = new WeakSet(), _Viewer_init = function _Viewer_init() {
117
+ const { renderer } = __classPrivateFieldGet(this, _Viewer_opts, "f");
118
+ renderer.on('load', () => {
119
+ this.drawFrame();
120
+ });
121
+ }, _Viewer_drawAnimationFrame = function _Viewer_drawAnimationFrame() {
122
+ if (__classPrivateFieldGet(this, _Viewer_drawFrameStatus, "f") === 'DRAWING' || __classPrivateFieldGet(this, _Viewer_drawFrameSnapshotQueue, "f").length === 0) {
123
+ return;
124
+ }
125
+ else {
126
+ __classPrivateFieldSet(this, _Viewer_drawFrameStatus, 'DRAWING', "f");
127
+ }
128
+ const snapshot = __classPrivateFieldGet(this, _Viewer_drawFrameSnapshotQueue, "f").shift();
129
+ const { renderer, boardContent, beforeDrawFrame, afterDrawFrame } = __classPrivateFieldGet(this, _Viewer_opts, "f");
130
+ if (snapshot) {
131
+ const { scale, offsetTop, offsetBottom, offsetLeft, offsetRight, width, height, contextHeight, contextWidth, devicePixelRatio } = snapshot.activeStore;
132
+ const viewScaleInfo = {
133
+ scale,
134
+ offsetTop,
135
+ offsetBottom,
136
+ offsetLeft,
137
+ offsetRight
138
+ };
139
+ const viewSizeInfo = {
140
+ width,
141
+ height,
142
+ contextHeight,
143
+ contextWidth,
144
+ devicePixelRatio
145
+ };
146
+ if (snapshot === null || snapshot === void 0 ? void 0 : snapshot.activeStore.data) {
147
+ renderer.drawData(snapshot.activeStore.data, {
148
+ viewScaleInfo,
149
+ viewSizeInfo
150
+ });
151
+ }
152
+ beforeDrawFrame({ snapshot });
153
+ boardContent.drawView();
154
+ afterDrawFrame({ snapshot });
155
+ }
156
+ if (__classPrivateFieldGet(this, _Viewer_drawFrameSnapshotQueue, "f").length === 0) {
157
+ __classPrivateFieldSet(this, _Viewer_drawFrameStatus, 'COMPLETE', "f");
158
+ return;
159
+ }
160
+ if ((__classPrivateFieldSet(this, _Viewer_drawFrameStatus, 'DRAWING', "f"))) {
161
+ requestAnimationFrame(() => {
162
+ __classPrivateFieldGet(this, _Viewer_instances, "m", _Viewer_drawAnimationFrame).call(this);
163
+ });
164
+ }
165
+ };
@@ -0,0 +1,15 @@
1
+ import type { Point, BoardWatcherEventMap, Data, Element, ElementType, BoardWatcherOptions } from '@idraw/types';
2
+ import { EventEmitter } from '@idraw/util';
3
+ export declare class BoardWatcher extends EventEmitter<BoardWatcherEventMap> {
4
+ #private;
5
+ constructor(opts: BoardWatcherOptions);
6
+ onEvents(): void;
7
+ offEvents(): void;
8
+ destroy(): void;
9
+ }
10
+ interface PointResult {
11
+ index: number;
12
+ element: Element<ElementType> | null;
13
+ }
14
+ export declare function getPointResult(p: Point, data: Data): PointResult;
15
+ export {};
@@ -0,0 +1,218 @@
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 _BoardWatcher_instances, _BoardWatcher_opts, _BoardWatcher_store, _BoardWatcher_hasDestroyed, _BoardWatcher_init, _BoardWatcher_onWheel, _BoardWatcher_onContextMenu, _BoardWatcher_onClick, _BoardWatcher_onPointLeave, _BoardWatcher_onPointEnd, _BoardWatcher_onPointMove, _BoardWatcher_onPointStart, _BoardWatcher_onHover, _BoardWatcher_isInTarget, _BoardWatcher_getPoint, _BoardWatcher_isVaildPoint;
13
+ import { EventEmitter, Store } from '@idraw/util';
14
+ function isBoardAvailableNum(num) {
15
+ return num > 0 || num < 0 || num === 0;
16
+ }
17
+ export class BoardWatcher extends EventEmitter {
18
+ constructor(opts) {
19
+ super();
20
+ _BoardWatcher_instances.add(this);
21
+ _BoardWatcher_opts.set(this, void 0);
22
+ _BoardWatcher_store.set(this, void 0);
23
+ _BoardWatcher_hasDestroyed.set(this, false);
24
+ _BoardWatcher_onWheel.set(this, (e) => {
25
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isInTarget).call(this, e)) {
26
+ return;
27
+ }
28
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
29
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isVaildPoint).call(this, point)) {
30
+ return;
31
+ }
32
+ e.preventDefault();
33
+ e.stopPropagation();
34
+ const deltaX = e.deltaX > 0 || e.deltaX < 0 ? e.deltaX : 0;
35
+ const deltaY = e.deltaY > 0 || e.deltaY < 0 ? e.deltaY : 0;
36
+ if (e.ctrlKey === true && this.has('wheelScale')) {
37
+ this.trigger('wheelScale', { deltaX, deltaY, point });
38
+ }
39
+ else if (this.has('wheel')) {
40
+ this.trigger('wheel', { deltaX, deltaY, point });
41
+ }
42
+ });
43
+ _BoardWatcher_onContextMenu.set(this, (e) => {
44
+ if (e.button !== 2) {
45
+ return;
46
+ }
47
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isInTarget).call(this, e)) {
48
+ return;
49
+ }
50
+ e.preventDefault();
51
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
52
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isVaildPoint).call(this, point)) {
53
+ return;
54
+ }
55
+ this.trigger('contextMenu', { point });
56
+ });
57
+ _BoardWatcher_onClick.set(this, (e) => {
58
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isInTarget).call(this, e)) {
59
+ return;
60
+ }
61
+ e.preventDefault();
62
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
63
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isVaildPoint).call(this, point)) {
64
+ return;
65
+ }
66
+ const maxLimitTime = 500;
67
+ const t = Date.now();
68
+ const preClickPoint = __classPrivateFieldGet(this, _BoardWatcher_store, "f").get('prevClickPoint');
69
+ if (preClickPoint &&
70
+ t - preClickPoint.t <= maxLimitTime &&
71
+ Math.abs(preClickPoint.x - point.x) <= 5 &&
72
+ Math.abs(preClickPoint.y - point.y) <= 5) {
73
+ this.trigger('doubleClick', { point });
74
+ }
75
+ else {
76
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").set('prevClickPoint', point);
77
+ }
78
+ });
79
+ _BoardWatcher_onPointLeave.set(this, (e) => {
80
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").set('hasPointDown', false);
81
+ e.preventDefault();
82
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
83
+ this.trigger('pointLeave', { point });
84
+ });
85
+ _BoardWatcher_onPointEnd.set(this, (e) => {
86
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").set('hasPointDown', false);
87
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isInTarget).call(this, e)) {
88
+ return;
89
+ }
90
+ e.preventDefault();
91
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
92
+ this.trigger('pointEnd', { point });
93
+ });
94
+ _BoardWatcher_onPointMove.set(this, (e) => {
95
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isInTarget).call(this, e)) {
96
+ return;
97
+ }
98
+ e.preventDefault();
99
+ e.stopPropagation();
100
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
101
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isVaildPoint).call(this, point)) {
102
+ if (__classPrivateFieldGet(this, _BoardWatcher_store, "f").get('hasPointDown')) {
103
+ this.trigger('pointLeave', { point });
104
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").set('hasPointDown', false);
105
+ }
106
+ return;
107
+ }
108
+ if (__classPrivateFieldGet(this, _BoardWatcher_store, "f").get('hasPointDown') !== true) {
109
+ return;
110
+ }
111
+ this.trigger('pointMove', { point });
112
+ });
113
+ _BoardWatcher_onPointStart.set(this, (e) => {
114
+ if (e.button !== 0) {
115
+ return;
116
+ }
117
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isInTarget).call(this, e)) {
118
+ return;
119
+ }
120
+ e.preventDefault();
121
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
122
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isVaildPoint).call(this, point)) {
123
+ return;
124
+ }
125
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").set('hasPointDown', true);
126
+ this.trigger('pointStart', { point });
127
+ });
128
+ _BoardWatcher_onHover.set(this, (e) => {
129
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isInTarget).call(this, e)) {
130
+ if (__classPrivateFieldGet(this, _BoardWatcher_store, "f").get('inCanvas') === true) {
131
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").set('inCanvas', false);
132
+ __classPrivateFieldGet(this, _BoardWatcher_onPointLeave, "f").call(this, e);
133
+ }
134
+ return;
135
+ }
136
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").set('inCanvas', true);
137
+ e.preventDefault();
138
+ const point = __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_getPoint).call(this, e);
139
+ if (!__classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_isVaildPoint).call(this, point)) {
140
+ return;
141
+ }
142
+ this.trigger('hover', { point });
143
+ });
144
+ const store = new Store({
145
+ defaultStorage: { hasPointDown: false, prevClickPoint: null, inCanvas: true }
146
+ });
147
+ __classPrivateFieldSet(this, _BoardWatcher_store, store, "f");
148
+ __classPrivateFieldSet(this, _BoardWatcher_opts, opts, "f");
149
+ __classPrivateFieldGet(this, _BoardWatcher_instances, "m", _BoardWatcher_init).call(this);
150
+ }
151
+ onEvents() {
152
+ if (__classPrivateFieldGet(this, _BoardWatcher_hasDestroyed, "f")) {
153
+ return;
154
+ }
155
+ const canvas = __classPrivateFieldGet(this, _BoardWatcher_opts, "f").boardContent.boardContext.canvas;
156
+ const container = window;
157
+ container.addEventListener('mousemove', __classPrivateFieldGet(this, _BoardWatcher_onHover, "f"));
158
+ container.addEventListener('mousedown', __classPrivateFieldGet(this, _BoardWatcher_onPointStart, "f"));
159
+ container.addEventListener('mousemove', __classPrivateFieldGet(this, _BoardWatcher_onPointMove, "f"));
160
+ container.addEventListener('mouseup', __classPrivateFieldGet(this, _BoardWatcher_onPointEnd, "f"));
161
+ canvas.addEventListener('wheel', __classPrivateFieldGet(this, _BoardWatcher_onWheel, "f"), { passive: false });
162
+ container.addEventListener('click', __classPrivateFieldGet(this, _BoardWatcher_onClick, "f"));
163
+ container.addEventListener('contextmenu', __classPrivateFieldGet(this, _BoardWatcher_onContextMenu, "f"));
164
+ }
165
+ offEvents() {
166
+ const container = window;
167
+ const canvas = __classPrivateFieldGet(this, _BoardWatcher_opts, "f").boardContent.boardContext.canvas;
168
+ container.removeEventListener('mousemove', __classPrivateFieldGet(this, _BoardWatcher_onHover, "f"));
169
+ container.removeEventListener('mousedown', __classPrivateFieldGet(this, _BoardWatcher_onPointStart, "f"));
170
+ container.removeEventListener('mousemove', __classPrivateFieldGet(this, _BoardWatcher_onPointMove, "f"));
171
+ container.removeEventListener('mouseup', __classPrivateFieldGet(this, _BoardWatcher_onPointEnd, "f"));
172
+ container.removeEventListener('mouseleave', __classPrivateFieldGet(this, _BoardWatcher_onPointLeave, "f"));
173
+ canvas.removeEventListener('wheel', __classPrivateFieldGet(this, _BoardWatcher_onWheel, "f"));
174
+ container.removeEventListener('click', __classPrivateFieldGet(this, _BoardWatcher_onClick, "f"));
175
+ container.removeEventListener('contextmenu', __classPrivateFieldGet(this, _BoardWatcher_onContextMenu, "f"));
176
+ }
177
+ destroy() {
178
+ this.offEvents();
179
+ __classPrivateFieldGet(this, _BoardWatcher_store, "f").destroy();
180
+ __classPrivateFieldSet(this, _BoardWatcher_hasDestroyed, true, "f");
181
+ }
182
+ }
183
+ _BoardWatcher_opts = new WeakMap(), _BoardWatcher_store = new WeakMap(), _BoardWatcher_hasDestroyed = new WeakMap(), _BoardWatcher_onWheel = new WeakMap(), _BoardWatcher_onContextMenu = new WeakMap(), _BoardWatcher_onClick = new WeakMap(), _BoardWatcher_onPointLeave = new WeakMap(), _BoardWatcher_onPointEnd = new WeakMap(), _BoardWatcher_onPointMove = new WeakMap(), _BoardWatcher_onPointStart = new WeakMap(), _BoardWatcher_onHover = new WeakMap(), _BoardWatcher_instances = new WeakSet(), _BoardWatcher_init = function _BoardWatcher_init() {
184
+ this.onEvents();
185
+ }, _BoardWatcher_isInTarget = function _BoardWatcher_isInTarget(e) {
186
+ return e.target === __classPrivateFieldGet(this, _BoardWatcher_opts, "f").boardContent.boardContext.canvas;
187
+ }, _BoardWatcher_getPoint = function _BoardWatcher_getPoint(e) {
188
+ const boardCanvas = __classPrivateFieldGet(this, _BoardWatcher_opts, "f").boardContent.boardContext.canvas;
189
+ const rect = boardCanvas.getBoundingClientRect();
190
+ const p = {
191
+ x: e.clientX - rect.left,
192
+ y: e.clientY - rect.top,
193
+ t: Date.now()
194
+ };
195
+ return p;
196
+ }, _BoardWatcher_isVaildPoint = function _BoardWatcher_isVaildPoint(p) {
197
+ const viewSize = __classPrivateFieldGet(this, _BoardWatcher_opts, "f").sharer.getActiveViewSizeInfo();
198
+ const { width, height } = viewSize;
199
+ if (isBoardAvailableNum(p.x) && isBoardAvailableNum(p.y) && p.x <= width && p.y <= height) {
200
+ return true;
201
+ }
202
+ return false;
203
+ };
204
+ export function getPointResult(p, data) {
205
+ const result = {
206
+ index: -1,
207
+ element: null
208
+ };
209
+ for (let i = 0; i < data.elements.length; i++) {
210
+ const elem = data.elements[i];
211
+ if (p.x >= elem.x && p.x <= elem.x + elem.w && p.y >= elem.y && p.y <= elem.y + elem.h) {
212
+ result.index = i;
213
+ result.element = elem;
214
+ break;
215
+ }
216
+ }
217
+ return result;
218
+ }
@@ -3,6 +3,7 @@ export declare const EVENT_KEY_CURSOR = "cursor";
3
3
  export declare const EVENT_KEY_RULER = "ruler";
4
4
  export declare const EVENT_KEY_SCALE = "scale";
5
5
  export declare const EVENT_KEY_SELECT = "select";
6
+ export declare const EVENT_KEY_SELECT_LAYOUT = "selectLayout";
6
7
  export declare const EVENT_KEY_CLEAR_SELECT = "clearSelect";
7
8
  export declare const EVENT_KEY_TEXT_EDIT = "textEdit";
8
9
  export declare const EVENT_KEY_TEXT_CHANGE = "textChange";
@@ -15,6 +16,7 @@ export type CoreEventKeys = {
15
16
  RULER: typeof EVENT_KEY_RULER;
16
17
  SCALE: typeof EVENT_KEY_SCALE;
17
18
  SELECT: typeof EVENT_KEY_SELECT;
19
+ SELECT_LAYOUT: typeof EVENT_KEY_SELECT_LAYOUT;
18
20
  CLEAR_SELECT: typeof EVENT_KEY_CLEAR_SELECT;
19
21
  TEXT_EDIT: typeof EVENT_KEY_TEXT_EDIT;
20
22
  TEXT_CHANGE: typeof EVENT_KEY_TEXT_CHANGE;
@@ -3,6 +3,7 @@ export const EVENT_KEY_CURSOR = 'cursor';
3
3
  export const EVENT_KEY_RULER = 'ruler';
4
4
  export const EVENT_KEY_SCALE = 'scale';
5
5
  export const EVENT_KEY_SELECT = 'select';
6
+ export const EVENT_KEY_SELECT_LAYOUT = 'selectLayout';
6
7
  export const EVENT_KEY_CLEAR_SELECT = 'clearSelect';
7
8
  export const EVENT_KEY_TEXT_EDIT = 'textEdit';
8
9
  export const EVENT_KEY_TEXT_CHANGE = 'textChange';
@@ -14,6 +15,7 @@ const innerEventKeys = {
14
15
  CHANGE: EVENT_KEY_CHANGE,
15
16
  RULER: EVENT_KEY_RULER,
16
17
  SCALE: EVENT_KEY_SCALE,
18
+ SELECT_LAYOUT: EVENT_KEY_SELECT_LAYOUT,
17
19
  SELECT: EVENT_KEY_SELECT,
18
20
  CLEAR_SELECT: EVENT_KEY_CLEAR_SELECT,
19
21
  TEXT_EDIT: EVENT_KEY_TEXT_EDIT,
@@ -1,6 +1,8 @@
1
1
  import type { Data, PointSize, CoreOptions, BoardMiddleware, ViewSizeInfo, CoreEventMap, ViewScaleInfo, LoadItemMap, ModifyOptions } from '@idraw/types';
2
+ import { Board, Sharer, Calculator } from './board';
2
3
  export { coreEventKeys } from './config';
3
4
  export type { CoreEventKeys } from './config';
5
+ export { Board, Sharer, Calculator };
4
6
  export { MiddlewareSelector } from './middleware/selector';
5
7
  export { MiddlewareScroller } from './middleware/scroller';
6
8
  export { MiddlewareScaler } from './middleware/scaler';
package/dist/esm/index.js CHANGED
@@ -10,10 +10,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _Core_instances, _Core_board, _Core_canvas, _Core_container, _Core_initContainer;
13
- import { Board } from '@idraw/board';
13
+ import { Board, Sharer, Calculator } from './board';
14
14
  import { createBoardContent, validateElements } from '@idraw/util';
15
15
  import { Cursor } from './lib/cursor';
16
16
  export { coreEventKeys } from './config';
17
+ export { Board, Sharer, Calculator };
17
18
  export { MiddlewareSelector } from './middleware/selector';
18
19
  export { MiddlewareScroller } from './middleware/scroller';
19
20
  export { MiddlewareScaler } from './middleware/scaler';
@@ -29,14 +30,14 @@ export class Core {
29
30
  _Core_board.set(this, void 0);
30
31
  _Core_canvas.set(this, void 0);
31
32
  _Core_container.set(this, void 0);
32
- const { devicePixelRatio = 1, width, height, createCustomContext2D } = opts;
33
+ const { devicePixelRatio = 1, width, height } = opts;
33
34
  __classPrivateFieldSet(this, _Core_container, container, "f");
34
35
  const canvas = document.createElement('canvas');
35
36
  canvas.setAttribute('tabindex', '0');
36
37
  __classPrivateFieldSet(this, _Core_canvas, canvas, "f");
37
38
  __classPrivateFieldGet(this, _Core_instances, "m", _Core_initContainer).call(this);
38
39
  container.appendChild(canvas);
39
- const boardContent = createBoardContent(canvas, { width, height, devicePixelRatio, offscreen: true, createCustomContext2D });
40
+ const boardContent = createBoardContent(canvas, { width, height, devicePixelRatio });
40
41
  const board = new Board({ boardContent, container });
41
42
  const sharer = board.getSharer();
42
43
  sharer.setActiveViewSizeInfo({
@@ -187,6 +187,7 @@ export const MiddlewareLayoutSelector = (opts, config) => {
187
187
  }
188
188
  if (sharer.getSharedStorage(keyLayoutIsSelected) === true && !prevIsSelected) {
189
189
  viewer.drawFrame();
190
+ eventHub.trigger(coreEventKeys.SELECT_LAYOUT);
190
191
  }
191
192
  prevIsSelected = sharer.getSharedStorage(keyLayoutIsSelected);
192
193
  if (sharer.getSharedStorage(keyLayoutIsHoverController) === true) {
@@ -300,10 +301,12 @@ export const MiddlewareLayoutSelector = (opts, config) => {
300
301
  const data = sharer.getActiveStorage('data');
301
302
  if (data && layoutActionType === 'resize' && layoutControlType) {
302
303
  eventHub.trigger(coreEventKeys.CHANGE, {
303
- type: 'changeLayout',
304
+ type: 'dragLayout',
304
305
  data
305
306
  });
306
307
  }
308
+ sharer.setSharedStorage(keyLayoutActionType, null);
309
+ sharer.setSharedStorage(keyLayoutControlType, null);
307
310
  if (sharer.getSharedStorage(keyLayoutIsHoverController) === true) {
308
311
  return false;
309
312
  }
@@ -108,7 +108,8 @@ function calcScrollerInfo(opts) {
108
108
  return scrollWrapper;
109
109
  }
110
110
  function drawScrollerThumb(ctx, opts) {
111
- let { x, y, h, w, background, borderColor } = opts;
111
+ let { x, y, h, w } = opts;
112
+ const { background, borderColor } = opts;
112
113
  ctx.save();
113
114
  ctx.shadowColor = '#FFFFFF';
114
115
  ctx.shadowOffsetX = 0;
@@ -86,7 +86,11 @@ export const MiddlewareSelector = (opts, config) => {
86
86
  const uuids = list.map((elem) => elem.uuid);
87
87
  const data = sharer.getActiveStorage('data');
88
88
  const positionMap = getElementPositionMapFromList(uuids, (data === null || data === void 0 ? void 0 : data.elements) || []);
89
- eventHub.trigger(coreEventKeys.SELECT, { uuids, positions: list.map((elem) => [...positionMap[elem.uuid]]) });
89
+ eventHub.trigger(coreEventKeys.SELECT, {
90
+ type: 'clickCanvas',
91
+ uuids,
92
+ positions: list.map((elem) => [...positionMap[elem.uuid]])
93
+ });
90
94
  }
91
95
  };
92
96
  const pointTargetBaseOptions = () => {
@@ -365,7 +369,12 @@ export const MiddlewareSelector = (opts, config) => {
365
369
  hasChangedData = true;
366
370
  inBusyMode = 'drag';
367
371
  eventHub.trigger(MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE, { show: false });
368
- if (data && (elems === null || elems === void 0 ? void 0 : elems.length) === 1 && moveOriginalStartElementSize && originalStart && end && ((_b = (_a = elems[0]) === null || _a === void 0 ? void 0 : _a.operations) === null || _b === void 0 ? void 0 : _b.locked) !== true) {
372
+ if (data &&
373
+ (elems === null || elems === void 0 ? void 0 : elems.length) === 1 &&
374
+ moveOriginalStartElementSize &&
375
+ originalStart &&
376
+ end &&
377
+ ((_b = (_a = elems[0]) === null || _a === void 0 ? void 0 : _a.operations) === null || _b === void 0 ? void 0 : _b.locked) !== true) {
369
378
  const { moveX, moveY } = calcPointMoveElementInGroup(originalStart, end, groupQueue);
370
379
  let totalMoveX = calculator.toGridNum(moveX / scale);
371
380
  let totalMoveY = calculator.toGridNum(moveY / scale);
@@ -394,7 +403,7 @@ export const MiddlewareSelector = (opts, config) => {
394
403
  elems[0].x = calculator.toGridNum(moveOriginalStartElementSize.x + totalMoveX);
395
404
  elems[0].y = calculator.toGridNum(moveOriginalStartElementSize.y + totalMoveY);
396
405
  updateSelectedElementList([elems[0]]);
397
- calculator.modifyViewVisibleInfoMap(data, {
406
+ calculator.modifyVirtualFlatItemMap(data, {
398
407
  modifyOptions: {
399
408
  type: 'updateElement',
400
409
  content: {
@@ -419,7 +428,7 @@ export const MiddlewareSelector = (opts, config) => {
419
428
  if (elem && ((_a = elem === null || elem === void 0 ? void 0 : elem.operations) === null || _a === void 0 ? void 0 : _a.locked) !== true) {
420
429
  elem.x = calculator.toGridNum(elem.x + moveX);
421
430
  elem.y = calculator.toGridNum(elem.y + moveY);
422
- calculator.modifyViewVisibleInfoMap(data, {
431
+ calculator.modifyVirtualFlatItemMap(data, {
423
432
  modifyOptions: {
424
433
  type: 'updateElement',
425
434
  content: {
@@ -437,7 +446,11 @@ export const MiddlewareSelector = (opts, config) => {
437
446
  viewer.drawFrame();
438
447
  }
439
448
  else if (actionType === 'resize') {
440
- if (data && (elems === null || elems === void 0 ? void 0 : elems.length) === 1 && originalStart && moveOriginalStartElementSize && (resizeType === null || resizeType === void 0 ? void 0 : resizeType.startsWith('resize-'))) {
449
+ if (data &&
450
+ (elems === null || elems === void 0 ? void 0 : elems.length) === 1 &&
451
+ originalStart &&
452
+ moveOriginalStartElementSize &&
453
+ (resizeType === null || resizeType === void 0 ? void 0 : resizeType.startsWith('resize-'))) {
441
454
  hasChangedData = true;
442
455
  inBusyMode = 'resize';
443
456
  const pointGroupQueue = [];
@@ -478,7 +491,7 @@ export const MiddlewareSelector = (opts, config) => {
478
491
  elems[0].angle = calculator.toGridNum(resizedElemSize.angle || 0);
479
492
  }
480
493
  else {
481
- const resizedElemSize = resizeElement(moveOriginalStartElementSize, { scale, start: resizeStart, end: resizeEnd, resizeType, sharer });
494
+ const resizedElemSize = resizeElement(Object.assign(Object.assign({}, moveOriginalStartElementSize), { operations: elems[0].operations }), { scale, start: resizeStart, end: resizeEnd, resizeType, sharer });
482
495
  const calcOpts = { ignore: !!moveOriginalStartElementSize.angle };
483
496
  elems[0].x = calculator.toGridNum(resizedElemSize.x, calcOpts);
484
497
  elems[0].y = calculator.toGridNum(resizedElemSize.y, calcOpts);
@@ -494,7 +507,7 @@ export const MiddlewareSelector = (opts, config) => {
494
507
  }
495
508
  }
496
509
  updateSelectedElementList([elems[0]]);
497
- calculator.modifyViewVisibleInfoMap(data, {
510
+ calculator.modifyVirtualFlatItemMap(data, {
498
511
  modifyOptions: {
499
512
  type: 'updateElement',
500
513
  content: {
@@ -627,7 +640,9 @@ export const MiddlewareSelector = (opts, config) => {
627
640
  return;
628
641
  }
629
642
  }
630
- else if (target.elements.length === 1 && ((_d = target.elements[0]) === null || _d === void 0 ? void 0 : _d.type) === 'text' && !((_f = (_e = target.elements[0]) === null || _e === void 0 ? void 0 : _e.operations) === null || _f === void 0 ? void 0 : _f.invisible)) {
643
+ else if (target.elements.length === 1 &&
644
+ ((_d = target.elements[0]) === null || _d === void 0 ? void 0 : _d.type) === 'text' &&
645
+ !((_f = (_e = target.elements[0]) === null || _e === void 0 ? void 0 : _e.operations) === null || _f === void 0 ? void 0 : _f.invisible)) {
631
646
  eventHub.trigger(coreEventKeys.TEXT_EDIT, {
632
647
  element: target.elements[0],
633
648
  groupQueue: sharer.getSharedStorage(keyGroupQueue) || [],
@@ -1,4 +1,4 @@
1
- import type { ViewRectVertexes, ElementSizeController, StoreSharer, ViewScaleInfo, ViewSizeInfo } from '@idraw/types';
1
+ import type { ViewRectVertexes, ElementSizeController, StoreSharer, ViewScaleInfo, ViewSizeInfo, ElementOperations } from '@idraw/types';
2
2
  import type { Data, Element, ViewContext2D, Point, PointSize, PointTarget, ViewCalculator, ElementType, ElementSize, ResizeType, AreaSize } from './types';
3
3
  export declare function isPointInViewActiveVertexes(p: PointSize, opts: {
4
4
  ctx: ViewContext2D;
@@ -23,7 +23,9 @@ export declare function getPointTarget(p: PointSize, opts: {
23
23
  groupQueue: Element<'group'>[] | null;
24
24
  selectedElementController: ElementSizeController | null;
25
25
  }): PointTarget;
26
- export declare function resizeElement(elem: ElementSize, opts: {
26
+ export declare function resizeElement(elem: ElementSize & {
27
+ operations?: ElementOperations;
28
+ }, opts: {
27
29
  start: PointSize;
28
30
  end: PointSize;
29
31
  resizeType: ResizeType;
@@ -413,7 +413,8 @@ export function resizeElement(elem, opts) {
413
413
  let centerY = elemCenter.y;
414
414
  if (angle < 90) {
415
415
  moveVerticalDist = 0 - changeMoveDistDirect(moveVerticalDist, moveVerticalY);
416
- moveHorizontalDist = 0 - changeMoveDistDirect(moveHorizontalDist, limitRatio ? 0 - moveVerticalDist : moveHorizontalX);
416
+ moveHorizontalDist =
417
+ 0 - changeMoveDistDirect(moveHorizontalDist, limitRatio ? 0 - moveVerticalDist : moveHorizontalX);
417
418
  const centerMoveVerticalDist = moveVerticalDist / 2;
418
419
  centerX = centerX + centerMoveVerticalDist * Math.sin(radian);
419
420
  centerY = centerY - centerMoveVerticalDist * Math.cos(radian);
@@ -548,7 +549,8 @@ export function resizeElement(elem, opts) {
548
549
  let centerY = elemCenter.y;
549
550
  if (angle < 90) {
550
551
  moveVerticalDist = changeMoveDistDirect(moveVerticalDist, moveVerticalY);
551
- moveHorizontalDist = 0 - changeMoveDistDirect(moveHorizontalDist, limitRatio ? 0 - moveVerticalDist : moveHorizontalX);
552
+ moveHorizontalDist =
553
+ 0 - changeMoveDistDirect(moveHorizontalDist, limitRatio ? 0 - moveVerticalDist : moveHorizontalX);
552
554
  const radian = parseRadian(angle);
553
555
  const centerMoveVerticalDist = moveVerticalDist / 2;
554
556
  centerX = centerX - centerMoveVerticalDist * Math.sin(radian);
@@ -696,7 +698,7 @@ export function getSelectedListArea(data, opts) {
696
698
  const indexes = [];
697
699
  const uuids = [];
698
700
  const elements = [];
699
- const { viewScaleInfo, viewSizeInfo, start, end } = opts;
701
+ const { viewScaleInfo, start, end } = opts;
700
702
  if (!(Array.isArray(data.elements) && start && end)) {
701
703
  return { indexes, uuids, elements };
702
704
  }