@idraw/core 0.4.0-beta.4 → 0.4.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/board/index.d.ts +44 -0
- package/dist/esm/board/index.js +358 -0
- package/dist/esm/board/sharer.d.ts +21 -0
- package/dist/esm/board/sharer.js +101 -0
- package/dist/esm/board/viewer.d.ts +32 -0
- package/dist/esm/board/viewer.js +165 -0
- package/dist/esm/board/watcher.d.ts +15 -0
- package/dist/esm/board/watcher.js +218 -0
- package/dist/esm/config.d.ts +28 -0
- package/dist/esm/config.js +34 -0
- package/dist/esm/index.d.ts +37 -8
- package/dist/esm/index.js +265 -10
- package/dist/esm/lib/cursor-image.d.ts +1 -0
- package/dist/esm/lib/cursor-image.js +1 -0
- package/dist/esm/lib/cursor.d.ts +3 -12
- package/dist/esm/lib/cursor.js +137 -112
- package/dist/esm/middleware/dragger/index.d.ts +2 -2
- package/dist/esm/middleware/dragger/index.js +5 -3
- package/dist/esm/middleware/info/config.d.ts +5 -0
- package/dist/esm/middleware/info/config.js +9 -0
- package/dist/esm/middleware/info/draw-info.d.ts +29 -0
- package/dist/esm/middleware/info/draw-info.js +113 -0
- package/dist/esm/middleware/info/index.d.ts +9 -0
- package/dist/esm/middleware/info/index.js +131 -0
- package/dist/esm/middleware/info/types.d.ts +3 -0
- package/dist/esm/middleware/info/types.js +1 -0
- package/dist/esm/middleware/layout-selector/config.d.ts +11 -0
- package/dist/esm/middleware/layout-selector/config.js +12 -0
- package/dist/esm/middleware/layout-selector/index.d.ts +5 -0
- package/dist/esm/middleware/layout-selector/index.js +371 -0
- package/dist/esm/middleware/layout-selector/types.d.ts +17 -0
- package/dist/esm/middleware/layout-selector/types.js +2 -0
- package/dist/esm/middleware/layout-selector/util.d.ts +9 -0
- package/dist/esm/middleware/layout-selector/util.js +78 -0
- package/dist/esm/middleware/pointer/index.d.ts +3 -0
- package/dist/esm/middleware/pointer/index.js +42 -0
- package/dist/esm/middleware/pointer/types.d.ts +3 -0
- package/dist/esm/middleware/pointer/types.js +1 -0
- package/dist/esm/middleware/ruler/config.d.ts +7 -0
- package/dist/esm/middleware/ruler/config.js +21 -0
- package/dist/esm/middleware/ruler/index.d.ts +3 -3
- package/dist/esm/middleware/ruler/index.js +33 -14
- package/dist/esm/middleware/ruler/types.d.ts +3 -0
- package/dist/esm/middleware/ruler/types.js +1 -0
- package/dist/esm/middleware/ruler/util.d.ts +20 -4
- package/dist/esm/middleware/ruler/util.js +99 -26
- package/dist/esm/middleware/scaler/index.d.ts +2 -3
- package/dist/esm/middleware/scaler/index.js +3 -2
- package/dist/esm/middleware/scroller/config.d.ts +4 -0
- package/dist/esm/middleware/scroller/config.js +10 -0
- package/dist/esm/middleware/scroller/index.d.ts +3 -2
- package/dist/esm/middleware/scroller/index.js +48 -6
- package/dist/esm/middleware/scroller/types.d.ts +11 -0
- package/dist/esm/middleware/scroller/types.js +1 -0
- package/dist/esm/middleware/scroller/util.d.ts +3 -2
- package/dist/esm/middleware/scroller/util.js +33 -44
- package/dist/esm/middleware/selector/config.d.ts +9 -1
- package/dist/esm/middleware/selector/config.js +17 -1
- package/dist/esm/middleware/selector/draw-auxiliary.d.ts +1 -0
- package/dist/esm/middleware/selector/draw-auxiliary.js +12 -0
- package/dist/esm/middleware/selector/draw-base.d.ts +30 -0
- package/dist/esm/middleware/selector/draw-base.js +100 -0
- package/dist/esm/middleware/selector/draw-debug.d.ts +5 -0
- package/dist/esm/middleware/selector/draw-debug.js +30 -0
- package/dist/esm/middleware/selector/draw-reference.d.ts +7 -0
- package/dist/esm/middleware/selector/draw-reference.js +31 -0
- package/dist/esm/middleware/selector/draw-wrapper.d.ts +16 -1
- package/dist/esm/middleware/selector/draw-wrapper.js +70 -38
- package/dist/esm/middleware/selector/index.d.ts +11 -4
- package/dist/esm/middleware/selector/index.js +450 -70
- package/dist/esm/middleware/selector/pattern/icon-rotate.d.ts +4 -0
- package/dist/esm/middleware/selector/pattern/icon-rotate.js +88 -0
- package/dist/esm/middleware/selector/pattern/index.d.ts +8 -0
- package/dist/esm/middleware/selector/pattern/index.js +38 -0
- package/dist/esm/middleware/selector/reference.d.ts +13 -0
- package/dist/esm/middleware/selector/reference.js +267 -0
- package/dist/esm/middleware/selector/types.d.ts +11 -5
- package/dist/esm/middleware/selector/types.js +2 -1
- package/dist/esm/middleware/selector/util.d.ts +14 -7
- package/dist/esm/middleware/selector/util.js +45 -43
- package/dist/esm/middleware/text-editor/index.d.ts +20 -3
- package/dist/esm/middleware/text-editor/index.js +168 -28
- package/dist/esm/record.d.ts +5 -0
- package/dist/esm/record.js +38 -0
- package/dist/index.global.js +5729 -1519
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -6
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const EVENT_KEY_CHANGE = "change";
|
|
2
|
+
export declare const EVENT_KEY_CURSOR = "cursor";
|
|
3
|
+
export declare const EVENT_KEY_RULER = "ruler";
|
|
4
|
+
export declare const EVENT_KEY_SCALE = "scale";
|
|
5
|
+
export declare const EVENT_KEY_SELECT = "select";
|
|
6
|
+
export declare const EVENT_KEY_SELECT_LAYOUT = "selectLayout";
|
|
7
|
+
export declare const EVENT_KEY_CLEAR_SELECT = "clearSelect";
|
|
8
|
+
export declare const EVENT_KEY_TEXT_EDIT = "textEdit";
|
|
9
|
+
export declare const EVENT_KEY_TEXT_CHANGE = "textChange";
|
|
10
|
+
export declare const EVENT_KEY_CONTEXT_MENU = "contextMenu";
|
|
11
|
+
export declare const EVENT_KEY_SELECT_IN_GROUP = "selectInGroup";
|
|
12
|
+
export declare const EVENT_KEY_SNAP_TO_GRID = "snapToGrid";
|
|
13
|
+
export type CoreEventKeys = {
|
|
14
|
+
CURSOR: typeof EVENT_KEY_CURSOR;
|
|
15
|
+
CHANGE: typeof EVENT_KEY_CHANGE;
|
|
16
|
+
RULER: typeof EVENT_KEY_RULER;
|
|
17
|
+
SCALE: typeof EVENT_KEY_SCALE;
|
|
18
|
+
SELECT: typeof EVENT_KEY_SELECT;
|
|
19
|
+
SELECT_LAYOUT: typeof EVENT_KEY_SELECT_LAYOUT;
|
|
20
|
+
CLEAR_SELECT: typeof EVENT_KEY_CLEAR_SELECT;
|
|
21
|
+
TEXT_EDIT: typeof EVENT_KEY_TEXT_EDIT;
|
|
22
|
+
TEXT_CHANGE: typeof EVENT_KEY_TEXT_CHANGE;
|
|
23
|
+
CONTEXT_MENU: typeof EVENT_KEY_CONTEXT_MENU;
|
|
24
|
+
SELECT_IN_GROUP: typeof EVENT_KEY_SELECT_IN_GROUP;
|
|
25
|
+
SNAP_TO_GRID: typeof EVENT_KEY_SELECT_IN_GROUP;
|
|
26
|
+
};
|
|
27
|
+
declare const coreEventKeys: CoreEventKeys;
|
|
28
|
+
export { coreEventKeys };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const EVENT_KEY_CHANGE = 'change';
|
|
2
|
+
export const EVENT_KEY_CURSOR = 'cursor';
|
|
3
|
+
export const EVENT_KEY_RULER = 'ruler';
|
|
4
|
+
export const EVENT_KEY_SCALE = 'scale';
|
|
5
|
+
export const EVENT_KEY_SELECT = 'select';
|
|
6
|
+
export const EVENT_KEY_SELECT_LAYOUT = 'selectLayout';
|
|
7
|
+
export const EVENT_KEY_CLEAR_SELECT = 'clearSelect';
|
|
8
|
+
export const EVENT_KEY_TEXT_EDIT = 'textEdit';
|
|
9
|
+
export const EVENT_KEY_TEXT_CHANGE = 'textChange';
|
|
10
|
+
export const EVENT_KEY_CONTEXT_MENU = 'contextMenu';
|
|
11
|
+
export const EVENT_KEY_SELECT_IN_GROUP = 'selectInGroup';
|
|
12
|
+
export const EVENT_KEY_SNAP_TO_GRID = 'snapToGrid';
|
|
13
|
+
const innerEventKeys = {
|
|
14
|
+
CURSOR: EVENT_KEY_CURSOR,
|
|
15
|
+
CHANGE: EVENT_KEY_CHANGE,
|
|
16
|
+
RULER: EVENT_KEY_RULER,
|
|
17
|
+
SCALE: EVENT_KEY_SCALE,
|
|
18
|
+
SELECT_LAYOUT: EVENT_KEY_SELECT_LAYOUT,
|
|
19
|
+
SELECT: EVENT_KEY_SELECT,
|
|
20
|
+
CLEAR_SELECT: EVENT_KEY_CLEAR_SELECT,
|
|
21
|
+
TEXT_EDIT: EVENT_KEY_TEXT_EDIT,
|
|
22
|
+
TEXT_CHANGE: EVENT_KEY_TEXT_CHANGE,
|
|
23
|
+
CONTEXT_MENU: EVENT_KEY_CONTEXT_MENU,
|
|
24
|
+
SELECT_IN_GROUP: EVENT_KEY_SELECT_IN_GROUP,
|
|
25
|
+
SNAP_TO_GRID: EVENT_KEY_SELECT_IN_GROUP
|
|
26
|
+
};
|
|
27
|
+
const coreEventKeys = {};
|
|
28
|
+
Object.keys(innerEventKeys).forEach((keyName) => {
|
|
29
|
+
Object.defineProperty(coreEventKeys, keyName, {
|
|
30
|
+
value: innerEventKeys[keyName],
|
|
31
|
+
writable: false
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
export { coreEventKeys };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import type { Data, PointSize, CoreOptions,
|
|
2
|
-
|
|
1
|
+
import type { Data, PointSize, CoreOptions, Middleware, ViewSizeInfo, CoreEventMap, ViewScaleInfo, LoadItemMap, ElementType, RecursivePartial, Element, ModifyRecord, ElementPosition, DataLayout, DataGlobal } from '@idraw/types';
|
|
2
|
+
import { Board, Sharer, Calculator } from './board';
|
|
3
|
+
export { coreEventKeys } from './config';
|
|
4
|
+
export type { CoreEventKeys } from './config';
|
|
5
|
+
export { Board, Sharer, Calculator };
|
|
6
|
+
export { MiddlewareSelector } from './middleware/selector';
|
|
3
7
|
export { MiddlewareScroller } from './middleware/scroller';
|
|
4
|
-
export { MiddlewareScaler
|
|
5
|
-
export { MiddlewareRuler
|
|
6
|
-
export { MiddlewareTextEditor
|
|
8
|
+
export { MiddlewareScaler } from './middleware/scaler';
|
|
9
|
+
export { MiddlewareRuler } from './middleware/ruler';
|
|
10
|
+
export { MiddlewareTextEditor } from './middleware/text-editor';
|
|
7
11
|
export { MiddlewareDragger } from './middleware/dragger';
|
|
8
|
-
export
|
|
12
|
+
export { MiddlewareInfo } from './middleware/info';
|
|
13
|
+
export { MiddlewareLayoutSelector } from './middleware/layout-selector';
|
|
14
|
+
export { MiddlewarePointer } from './middleware/pointer';
|
|
15
|
+
export declare class Core<E extends CoreEventMap = CoreEventMap> {
|
|
9
16
|
#private;
|
|
10
17
|
constructor(container: HTMLDivElement, opts: CoreOptions);
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
isDestroyed(): boolean;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
use<C extends any = any>(middleware: Middleware<any, any, any>, config?: C): void;
|
|
21
|
+
disuse(middleware: Middleware<any, any, any>): void;
|
|
22
|
+
resetMiddlewareConfig<C extends any = any>(middleware: Middleware<any, any, any>, config?: Partial<C>): void;
|
|
13
23
|
setData(data: Data): void;
|
|
14
24
|
getData(): Data | null;
|
|
15
25
|
scale(opts: {
|
|
@@ -32,4 +42,23 @@ export declare class Core<E extends CoreEvent = CoreEvent> {
|
|
|
32
42
|
offsetY: number;
|
|
33
43
|
}): void;
|
|
34
44
|
getLoadItemMap(): LoadItemMap;
|
|
45
|
+
onBoardWatcherEvents(): void;
|
|
46
|
+
offBoardWatcherEvents(): void;
|
|
47
|
+
createElement<T extends ElementType = ElementType>(type: T, element: RecursivePartial<Element<T>>, opts?: {
|
|
48
|
+
viewCenter?: boolean;
|
|
49
|
+
}): Element<T>;
|
|
50
|
+
updateElement(element: Element): ModifyRecord<'updateElement'> | null;
|
|
51
|
+
modifyElement(element: RecursivePartial<Omit<Element, 'uuid'>> & Pick<Element, 'uuid'>): ModifyRecord<'modifyElement'> | null;
|
|
52
|
+
modifyElements(elements: Array<RecursivePartial<Omit<Element, 'uuid'>> & Pick<Element, 'uuid'>>): ModifyRecord<'modifyElements'> | null;
|
|
53
|
+
addElement(element: Element, opts?: {
|
|
54
|
+
position: ElementPosition;
|
|
55
|
+
}): ModifyRecord<'addElement'>;
|
|
56
|
+
deleteElement(uuid: string): ModifyRecord<'deleteElement'>;
|
|
57
|
+
moveElement(uuid: string, to: ElementPosition): ModifyRecord<'moveElement'>;
|
|
58
|
+
modifyLayout(layout: RecursivePartial<DataLayout> | null): ModifyRecord<'modifyLayout'>;
|
|
59
|
+
modifyGlobal(global: RecursivePartial<DataGlobal> | null): {
|
|
60
|
+
type: "modifyGlobal";
|
|
61
|
+
time: number;
|
|
62
|
+
content: import("@idraw/types").ModifyContentMap["modifyGlobal"];
|
|
63
|
+
};
|
|
35
64
|
}
|