@idraw/core 0.4.0-alpha.3 → 0.4.0-alpha.5
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/index.d.ts +5 -6
- package/dist/esm/index.js +38 -16
- package/dist/esm/middleware/ruler/index.d.ts +3 -0
- package/dist/esm/middleware/ruler/index.js +44 -0
- package/dist/esm/middleware/ruler/util.d.ts +33 -0
- package/dist/esm/middleware/ruler/util.js +187 -0
- package/dist/esm/middleware/scaler/index.d.ts +3 -2
- package/dist/esm/middleware/scaler/index.js +10 -1
- package/dist/esm/middleware/scroller/util.js +63 -56
- package/dist/esm/middleware/selector/draw-wrapper.js +0 -4
- package/dist/esm/middleware/selector/index.d.ts +1 -0
- package/dist/esm/middleware/selector/index.js +12 -3
- package/dist/esm/middleware/text-editor/index.d.ts +3 -0
- package/dist/esm/middleware/text-editor/index.js +132 -0
- package/dist/index.global.js +975 -272
- package/dist/index.global.min.js +1 -1
- package/package.json +8 -7
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Data, PointSize, CoreOptions, BoardMiddleware, ViewSizeInfo, CoreEvent } from '@idraw/types';
|
|
2
|
-
export { MiddlewareSelector } from './middleware/selector';
|
|
2
|
+
export { MiddlewareSelector, middlewareEventSelect } from './middleware/selector';
|
|
3
3
|
export { MiddlewareScroller } from './middleware/scroller';
|
|
4
|
-
export { MiddlewareScaler } from './middleware/scaler';
|
|
4
|
+
export { MiddlewareScaler, middlewareEventScale } from './middleware/scaler';
|
|
5
|
+
export { MiddlewareRuler, middlewareEventRuler } from './middleware/ruler';
|
|
6
|
+
export { MiddlewareTextEditor, middlewareEventTextEdit } from './middleware/text-editor';
|
|
5
7
|
export declare class Core {
|
|
6
|
-
private
|
|
7
|
-
private _opts;
|
|
8
|
-
private _container;
|
|
9
|
-
private _canvas;
|
|
8
|
+
#private;
|
|
10
9
|
constructor(container: HTMLDivElement, opts: CoreOptions);
|
|
11
10
|
use(middleware: BoardMiddleware<any, any>): void;
|
|
12
11
|
setData(data: Data): void;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
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 _Core_instances, _Core_board, _Core_container, _Core_initContainer;
|
|
1
13
|
import { Board } from '@idraw/board';
|
|
2
14
|
import { createBoardContexts, validateElements } from '@idraw/util';
|
|
3
15
|
import { Cursor } from './lib/cursor';
|
|
4
|
-
export { MiddlewareSelector } from './middleware/selector';
|
|
16
|
+
export { MiddlewareSelector, middlewareEventSelect } from './middleware/selector';
|
|
5
17
|
export { MiddlewareScroller } from './middleware/scroller';
|
|
6
|
-
export { MiddlewareScaler } from './middleware/scaler';
|
|
18
|
+
export { MiddlewareScaler, middlewareEventScale } from './middleware/scaler';
|
|
19
|
+
export { MiddlewareRuler, middlewareEventRuler } from './middleware/ruler';
|
|
20
|
+
export { MiddlewareTextEditor, middlewareEventTextEdit } from './middleware/text-editor';
|
|
7
21
|
export class Core {
|
|
8
22
|
constructor(container, opts) {
|
|
23
|
+
_Core_instances.add(this);
|
|
24
|
+
_Core_board.set(this, void 0);
|
|
25
|
+
_Core_container.set(this, void 0);
|
|
9
26
|
const { devicePixelRatio = 1, width, height } = opts;
|
|
10
|
-
this
|
|
11
|
-
this._container = container;
|
|
27
|
+
__classPrivateFieldSet(this, _Core_container, container, "f");
|
|
12
28
|
const canvas = document.createElement('canvas');
|
|
13
|
-
this
|
|
29
|
+
__classPrivateFieldGet(this, _Core_instances, "m", _Core_initContainer).call(this);
|
|
14
30
|
container.appendChild(canvas);
|
|
15
31
|
const ctx = canvas.getContext('2d');
|
|
16
32
|
const viewContent = createBoardContexts(ctx, { devicePixelRatio });
|
|
17
|
-
const board = new Board({ viewContent });
|
|
33
|
+
const board = new Board({ viewContent, container });
|
|
18
34
|
const sharer = board.getSharer();
|
|
19
35
|
sharer.setActiveViewSizeInfo({
|
|
20
36
|
width,
|
|
@@ -23,7 +39,7 @@ export class Core {
|
|
|
23
39
|
contextWidth: width,
|
|
24
40
|
contextHeight: height
|
|
25
41
|
});
|
|
26
|
-
this
|
|
42
|
+
__classPrivateFieldSet(this, _Core_board, board, "f");
|
|
27
43
|
this.resize(sharer.getActiveViewSizeInfo());
|
|
28
44
|
const eventHub = board.getEventHub();
|
|
29
45
|
new Cursor(container, {
|
|
@@ -31,37 +47,43 @@ export class Core {
|
|
|
31
47
|
});
|
|
32
48
|
}
|
|
33
49
|
use(middleware) {
|
|
34
|
-
this.
|
|
50
|
+
__classPrivateFieldGet(this, _Core_board, "f").use(middleware);
|
|
35
51
|
}
|
|
36
52
|
setData(data) {
|
|
37
53
|
validateElements((data === null || data === void 0 ? void 0 : data.elements) || []);
|
|
38
|
-
this.
|
|
54
|
+
__classPrivateFieldGet(this, _Core_board, "f").setData(data);
|
|
39
55
|
}
|
|
40
56
|
getData() {
|
|
41
|
-
return this.
|
|
57
|
+
return __classPrivateFieldGet(this, _Core_board, "f").getData();
|
|
42
58
|
}
|
|
43
59
|
scale(opts) {
|
|
44
|
-
this.
|
|
60
|
+
__classPrivateFieldGet(this, _Core_board, "f").scale(opts);
|
|
61
|
+
const viewer = __classPrivateFieldGet(this, _Core_board, "f").getViewer();
|
|
62
|
+
viewer.drawFrame();
|
|
45
63
|
}
|
|
46
64
|
resize(newViewSize) {
|
|
47
|
-
const
|
|
65
|
+
const board = __classPrivateFieldGet(this, _Core_board, "f");
|
|
48
66
|
const sharer = board.getSharer();
|
|
49
67
|
const viewSizeInfo = sharer.getActiveViewSizeInfo();
|
|
50
68
|
board.resize(Object.assign(Object.assign({}, viewSizeInfo), newViewSize));
|
|
51
69
|
}
|
|
52
70
|
clear() {
|
|
53
|
-
this.
|
|
71
|
+
__classPrivateFieldGet(this, _Core_board, "f").clear();
|
|
54
72
|
}
|
|
55
73
|
on(name, callback) {
|
|
56
|
-
const eventHub = this.
|
|
74
|
+
const eventHub = __classPrivateFieldGet(this, _Core_board, "f").getEventHub();
|
|
57
75
|
eventHub.on(name, callback);
|
|
58
76
|
}
|
|
59
77
|
off(name, callback) {
|
|
60
|
-
const eventHub = this.
|
|
78
|
+
const eventHub = __classPrivateFieldGet(this, _Core_board, "f").getEventHub();
|
|
61
79
|
eventHub.off(name, callback);
|
|
62
80
|
}
|
|
63
81
|
trigger(name, e) {
|
|
64
|
-
const eventHub = this.
|
|
82
|
+
const eventHub = __classPrivateFieldGet(this, _Core_board, "f").getEventHub();
|
|
65
83
|
eventHub.trigger(name, e);
|
|
66
84
|
}
|
|
67
85
|
}
|
|
86
|
+
_Core_board = new WeakMap(), _Core_container = new WeakMap(), _Core_instances = new WeakSet(), _Core_initContainer = function _Core_initContainer() {
|
|
87
|
+
const container = __classPrivateFieldGet(this, _Core_container, "f");
|
|
88
|
+
container.style.position = 'relative';
|
|
89
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
|
|
2
|
+
import { drawRulerBackground, drawXRuler, drawYRuler, calcXRulerScaleList, calcYRulerScaleList, drawUnderGrid } from './util';
|
|
3
|
+
export const middlewareEventRuler = '@middleware/show-ruler';
|
|
4
|
+
export const MiddlewareRuler = (opts) => {
|
|
5
|
+
const key = 'RULE';
|
|
6
|
+
const { viewContent, viewer, eventHub } = opts;
|
|
7
|
+
const { helperContext, underContext } = viewContent;
|
|
8
|
+
let show = true;
|
|
9
|
+
let showGrid = true;
|
|
10
|
+
eventHub.on(middlewareEventRuler, (e) => {
|
|
11
|
+
if (typeof (e === null || e === void 0 ? void 0 : e.show) === 'boolean') {
|
|
12
|
+
show = e.show;
|
|
13
|
+
}
|
|
14
|
+
if (typeof (e === null || e === void 0 ? void 0 : e.showGrid) === 'boolean') {
|
|
15
|
+
showGrid = e.showGrid;
|
|
16
|
+
}
|
|
17
|
+
if (typeof (e === null || e === void 0 ? void 0 : e.show) === 'boolean' || typeof (e === null || e === void 0 ? void 0 : e.showGrid) === 'boolean') {
|
|
18
|
+
viewer.drawFrame();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
mode: key,
|
|
23
|
+
isDefault: true,
|
|
24
|
+
beforeDrawFrame: ({ snapshot }) => {
|
|
25
|
+
if (show === true) {
|
|
26
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
27
|
+
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
28
|
+
drawRulerBackground(helperContext, { viewScaleInfo, viewSizeInfo });
|
|
29
|
+
const xList = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
30
|
+
drawXRuler(helperContext, { scaleList: xList });
|
|
31
|
+
const yList = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
32
|
+
drawYRuler(helperContext, { scaleList: yList });
|
|
33
|
+
if (showGrid === true) {
|
|
34
|
+
drawUnderGrid(underContext, {
|
|
35
|
+
xList,
|
|
36
|
+
yList,
|
|
37
|
+
viewScaleInfo,
|
|
38
|
+
viewSizeInfo
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D } from '@idraw/types';
|
|
2
|
+
interface RulerScale {
|
|
3
|
+
num: number;
|
|
4
|
+
showNum: boolean;
|
|
5
|
+
position: number;
|
|
6
|
+
isKeyNum: boolean;
|
|
7
|
+
isSubKeyNum: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function calcXRulerScaleList(opts: {
|
|
10
|
+
viewScaleInfo: ViewScaleInfo;
|
|
11
|
+
viewSizeInfo: ViewSizeInfo;
|
|
12
|
+
}): RulerScale[];
|
|
13
|
+
export declare function calcYRulerScaleList(opts: {
|
|
14
|
+
viewScaleInfo: ViewScaleInfo;
|
|
15
|
+
viewSizeInfo: ViewSizeInfo;
|
|
16
|
+
}): RulerScale[];
|
|
17
|
+
export declare function drawXRuler(ctx: ViewContext2D, opts: {
|
|
18
|
+
scaleList: RulerScale[];
|
|
19
|
+
}): void;
|
|
20
|
+
export declare function drawYRuler(ctx: ViewContext2D, opts: {
|
|
21
|
+
scaleList: RulerScale[];
|
|
22
|
+
}): void;
|
|
23
|
+
export declare function drawRulerBackground(ctx: ViewContext2D, opts: {
|
|
24
|
+
viewScaleInfo: ViewScaleInfo;
|
|
25
|
+
viewSizeInfo: ViewSizeInfo;
|
|
26
|
+
}): void;
|
|
27
|
+
export declare function drawUnderGrid(ctx: ViewContext2D, opts: {
|
|
28
|
+
xList: RulerScale[];
|
|
29
|
+
yList: RulerScale[];
|
|
30
|
+
viewScaleInfo: ViewScaleInfo;
|
|
31
|
+
viewSizeInfo: ViewSizeInfo;
|
|
32
|
+
}): void;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { formatNumber, rotateByCenter } from '@idraw/util';
|
|
2
|
+
const rulerSize = 16;
|
|
3
|
+
const background = '#FFFFFFA8';
|
|
4
|
+
const borderColor = '#00000080';
|
|
5
|
+
const scaleColor = '#000000';
|
|
6
|
+
const textColor = '#00000080';
|
|
7
|
+
const fontFamily = 'monospace';
|
|
8
|
+
const fontSize = 10;
|
|
9
|
+
const fontWeight = 100;
|
|
10
|
+
const gridColor = '#AAAAAA30';
|
|
11
|
+
const gridKeyColor = '#AAAAAA70';
|
|
12
|
+
const lineSize = 1;
|
|
13
|
+
function calcRulerScaleList(opts) {
|
|
14
|
+
const { scale, viewLength, viewOffset } = opts;
|
|
15
|
+
const list = [];
|
|
16
|
+
let rulerUnit = 10;
|
|
17
|
+
rulerUnit = formatNumber(rulerUnit / scale, { decimalPlaces: 0 });
|
|
18
|
+
rulerUnit = Math.max(10, Math.min(rulerUnit, 1000));
|
|
19
|
+
const rulerKeyUnit = rulerUnit * 10;
|
|
20
|
+
const rulerSubKeyUnit = rulerUnit * 5;
|
|
21
|
+
let index = 0;
|
|
22
|
+
const viewUnit = rulerUnit * scale;
|
|
23
|
+
const startNum = 0 - viewOffset;
|
|
24
|
+
const startPosition = 0;
|
|
25
|
+
const remainderNum = startNum % viewUnit;
|
|
26
|
+
const firstNum = (startNum - remainderNum + viewUnit) / scale;
|
|
27
|
+
const firstPosition = startPosition + (viewUnit - remainderNum);
|
|
28
|
+
while (firstPosition + index * viewUnit < viewLength) {
|
|
29
|
+
const num = formatNumber(firstNum + index * rulerUnit, { decimalPlaces: 0 });
|
|
30
|
+
const position = formatNumber(firstPosition + index * viewUnit, { decimalPlaces: 0 });
|
|
31
|
+
const rulerScale = {
|
|
32
|
+
num,
|
|
33
|
+
position,
|
|
34
|
+
showNum: num % rulerKeyUnit === 0,
|
|
35
|
+
isKeyNum: num % rulerKeyUnit === 0,
|
|
36
|
+
isSubKeyNum: num % rulerSubKeyUnit === 0
|
|
37
|
+
};
|
|
38
|
+
list.push(rulerScale);
|
|
39
|
+
index++;
|
|
40
|
+
}
|
|
41
|
+
return list;
|
|
42
|
+
}
|
|
43
|
+
export function calcXRulerScaleList(opts) {
|
|
44
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
45
|
+
const { scale, offsetLeft } = viewScaleInfo;
|
|
46
|
+
const { width } = viewSizeInfo;
|
|
47
|
+
return calcRulerScaleList({
|
|
48
|
+
axis: 'X',
|
|
49
|
+
scale,
|
|
50
|
+
viewLength: width,
|
|
51
|
+
viewOffset: offsetLeft
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function calcYRulerScaleList(opts) {
|
|
55
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
56
|
+
const { scale, offsetTop } = viewScaleInfo;
|
|
57
|
+
const { height } = viewSizeInfo;
|
|
58
|
+
return calcRulerScaleList({
|
|
59
|
+
axis: 'Y',
|
|
60
|
+
scale,
|
|
61
|
+
viewLength: height,
|
|
62
|
+
viewOffset: offsetTop
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export function drawXRuler(ctx, opts) {
|
|
66
|
+
const { scaleList } = opts;
|
|
67
|
+
const scaleDrawStart = rulerSize;
|
|
68
|
+
const scaleDrawEnd = (rulerSize * 4) / 5;
|
|
69
|
+
const subKeyScaleDrawEnd = (rulerSize * 2) / 5;
|
|
70
|
+
const keyScaleDrawEnd = (rulerSize * 1) / 5;
|
|
71
|
+
const fontStart = rulerSize / 5;
|
|
72
|
+
for (let i = 0; i < scaleList.length; i++) {
|
|
73
|
+
const item = scaleList[i];
|
|
74
|
+
if (item.position < rulerSize) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
ctx.beginPath();
|
|
78
|
+
ctx.moveTo(item.position, scaleDrawStart);
|
|
79
|
+
ctx.lineTo(item.position, item.isKeyNum ? keyScaleDrawEnd : item.isSubKeyNum ? subKeyScaleDrawEnd : scaleDrawEnd);
|
|
80
|
+
ctx.closePath();
|
|
81
|
+
ctx.lineWidth = lineSize;
|
|
82
|
+
ctx.setLineDash([]);
|
|
83
|
+
ctx.fillStyle = scaleColor;
|
|
84
|
+
ctx.stroke();
|
|
85
|
+
if (item.isKeyNum) {
|
|
86
|
+
ctx.fillStyle = textColor;
|
|
87
|
+
ctx.textBaseline = 'top';
|
|
88
|
+
ctx.$setFont({
|
|
89
|
+
fontWeight,
|
|
90
|
+
fontSize,
|
|
91
|
+
fontFamily
|
|
92
|
+
});
|
|
93
|
+
ctx.fillText(`${item.num}`, item.position + fontStart, fontStart);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export function drawYRuler(ctx, opts) {
|
|
98
|
+
const { scaleList } = opts;
|
|
99
|
+
const scaleDrawStart = rulerSize;
|
|
100
|
+
const scaleDrawEnd = (rulerSize * 4) / 5;
|
|
101
|
+
const subKeyScaleDrawEnd = (rulerSize * 2) / 5;
|
|
102
|
+
const keyScaleDrawEnd = (rulerSize * 1) / 5;
|
|
103
|
+
const fontStart = rulerSize / 5;
|
|
104
|
+
for (let i = 0; i < scaleList.length; i++) {
|
|
105
|
+
const item = scaleList[i];
|
|
106
|
+
if (item.position < rulerSize) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
ctx.beginPath();
|
|
110
|
+
ctx.moveTo(scaleDrawStart, item.position);
|
|
111
|
+
ctx.lineTo(item.isKeyNum ? keyScaleDrawEnd : item.isSubKeyNum ? subKeyScaleDrawEnd : scaleDrawEnd, item.position);
|
|
112
|
+
ctx.closePath();
|
|
113
|
+
ctx.fillStyle = scaleColor;
|
|
114
|
+
ctx.lineWidth = lineSize;
|
|
115
|
+
ctx.setLineDash([]);
|
|
116
|
+
ctx.stroke();
|
|
117
|
+
if (item.showNum === true) {
|
|
118
|
+
const textX = fontStart;
|
|
119
|
+
const textY = item.position + fontStart;
|
|
120
|
+
const numText = `${item.num}`;
|
|
121
|
+
rotateByCenter(ctx, -90, { x: textX, y: textY }, () => {
|
|
122
|
+
ctx.fillStyle = textColor;
|
|
123
|
+
ctx.textBaseline = 'top';
|
|
124
|
+
ctx.$setFont({
|
|
125
|
+
fontWeight,
|
|
126
|
+
fontSize,
|
|
127
|
+
fontFamily
|
|
128
|
+
});
|
|
129
|
+
ctx.fillText(numText, fontStart + fontSize, item.position + fontStart);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function drawRulerBackground(ctx, opts) {
|
|
135
|
+
const { viewSizeInfo } = opts;
|
|
136
|
+
const { width, height } = viewSizeInfo;
|
|
137
|
+
ctx.beginPath();
|
|
138
|
+
ctx.moveTo(0, 0);
|
|
139
|
+
ctx.lineTo(width + 1, 0);
|
|
140
|
+
ctx.lineTo(width + 1, rulerSize);
|
|
141
|
+
ctx.lineTo(rulerSize, rulerSize);
|
|
142
|
+
ctx.lineTo(rulerSize, height + 1);
|
|
143
|
+
ctx.lineTo(0, height + 1);
|
|
144
|
+
ctx.lineTo(0, 0);
|
|
145
|
+
ctx.closePath();
|
|
146
|
+
ctx.fillStyle = background;
|
|
147
|
+
ctx.fill();
|
|
148
|
+
ctx.lineWidth = lineSize;
|
|
149
|
+
ctx.setLineDash([]);
|
|
150
|
+
ctx.strokeStyle = borderColor;
|
|
151
|
+
ctx.stroke();
|
|
152
|
+
}
|
|
153
|
+
export function drawUnderGrid(ctx, opts) {
|
|
154
|
+
const { xList, yList, viewSizeInfo } = opts;
|
|
155
|
+
const { width, height } = viewSizeInfo;
|
|
156
|
+
for (let i = 0; i < xList.length; i++) {
|
|
157
|
+
const item = xList[i];
|
|
158
|
+
ctx.beginPath();
|
|
159
|
+
ctx.moveTo(item.position, 0);
|
|
160
|
+
ctx.lineTo(item.position, height);
|
|
161
|
+
if (item.isKeyNum === true || item.isSubKeyNum === true) {
|
|
162
|
+
ctx.strokeStyle = gridKeyColor;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
ctx.strokeStyle = gridColor;
|
|
166
|
+
}
|
|
167
|
+
ctx.closePath();
|
|
168
|
+
ctx.lineWidth = lineSize;
|
|
169
|
+
ctx.setLineDash([]);
|
|
170
|
+
ctx.stroke();
|
|
171
|
+
}
|
|
172
|
+
for (let i = 0; i < yList.length; i++) {
|
|
173
|
+
const item = yList[i];
|
|
174
|
+
ctx.beginPath();
|
|
175
|
+
ctx.moveTo(0, item.position);
|
|
176
|
+
ctx.lineTo(width, item.position);
|
|
177
|
+
if (item.isKeyNum === true || item.isSubKeyNum === true) {
|
|
178
|
+
ctx.strokeStyle = gridKeyColor;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
ctx.strokeStyle = gridColor;
|
|
182
|
+
}
|
|
183
|
+
ctx.lineWidth = 1;
|
|
184
|
+
ctx.closePath();
|
|
185
|
+
ctx.stroke();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { BoardMiddleware } from '@idraw/types';
|
|
2
|
-
export declare const
|
|
1
|
+
import type { BoardMiddleware, CoreEvent } from '@idraw/types';
|
|
2
|
+
export declare const middlewareEventScale = "@middleware/scale";
|
|
3
|
+
export declare const MiddlewareScaler: BoardMiddleware<Record<string, any>, CoreEvent>;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { formatNumber } from '@idraw/util';
|
|
2
|
+
export const middlewareEventScale = '@middleware/scale';
|
|
1
3
|
export const MiddlewareScaler = (opts) => {
|
|
2
4
|
const key = 'SCALE';
|
|
3
|
-
const { viewer, sharer } = opts;
|
|
5
|
+
const { viewer, sharer, eventHub } = opts;
|
|
6
|
+
const maxScale = 50;
|
|
7
|
+
const minScale = 0.05;
|
|
4
8
|
return {
|
|
5
9
|
mode: key,
|
|
6
10
|
isDefault: true,
|
|
@@ -14,9 +18,14 @@ export const MiddlewareScaler = (opts) => {
|
|
|
14
18
|
else if (deltaY > 0) {
|
|
15
19
|
newScaleNum = scale * 0.9;
|
|
16
20
|
}
|
|
21
|
+
if (newScaleNum < minScale || newScaleNum > maxScale) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
17
24
|
const { moveX, moveY } = viewer.scale({ scale: newScaleNum, point });
|
|
18
25
|
viewer.scroll({ moveX, moveY });
|
|
19
26
|
viewer.drawFrame();
|
|
27
|
+
const scaleNum = formatNumber(scale);
|
|
28
|
+
eventHub.trigger(middlewareEventScale, { scale: scaleNum });
|
|
20
29
|
}
|
|
21
30
|
};
|
|
22
31
|
};
|
|
@@ -2,12 +2,12 @@ import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idra
|
|
|
2
2
|
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect } from './config';
|
|
3
3
|
const minScrollerWidth = 12;
|
|
4
4
|
const scrollerLineWidth = 16;
|
|
5
|
-
const scrollerAlpha = 0.12;
|
|
6
5
|
const scrollerThumbAlpha = 0.36;
|
|
7
6
|
const scrollConfig = {
|
|
8
7
|
width: minScrollerWidth,
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
thumbColor: '#000000AA',
|
|
9
|
+
scrollBarColor: '#FFFFFF60',
|
|
10
|
+
showScrollBar: false
|
|
11
11
|
};
|
|
12
12
|
function isPointAtRect(helperContext, p, rect) {
|
|
13
13
|
const ctx = helperContext;
|
|
@@ -49,15 +49,15 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
49
49
|
const lineSize = scrollerLineWidth;
|
|
50
50
|
let xSize = 0;
|
|
51
51
|
let ySize = 0;
|
|
52
|
-
xSize = Math.max(sliderMinSize, width - (Math.abs(offsetLeft) + Math.abs(offsetRight)));
|
|
52
|
+
xSize = Math.max(sliderMinSize, width - lineSize * 2 - (Math.abs(offsetLeft) + Math.abs(offsetRight)));
|
|
53
53
|
if (xSize >= width) {
|
|
54
54
|
xSize = width;
|
|
55
55
|
}
|
|
56
|
-
ySize = Math.max(sliderMinSize, height - (Math.abs(offsetTop) + Math.abs(offsetBottom)));
|
|
56
|
+
ySize = Math.max(sliderMinSize, height - lineSize * 2 - (Math.abs(offsetTop) + Math.abs(offsetBottom)));
|
|
57
57
|
if (ySize >= height) {
|
|
58
58
|
ySize = height;
|
|
59
59
|
}
|
|
60
|
-
const xStart = lineSize
|
|
60
|
+
const xStart = lineSize;
|
|
61
61
|
const xEnd = width - xSize - lineSize;
|
|
62
62
|
let translateX = xStart;
|
|
63
63
|
if (offsetLeft > 0) {
|
|
@@ -67,10 +67,10 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
67
67
|
translateX = xEnd;
|
|
68
68
|
}
|
|
69
69
|
else if (offsetLeft <= 0 && xSize > 0 && !(offsetLeft === 0 && offsetRight === 0)) {
|
|
70
|
-
translateX =
|
|
71
|
-
translateX = Math.min(Math.max(0, translateX -
|
|
70
|
+
translateX = xStart + ((width - xSize) * Math.abs(offsetLeft)) / (Math.abs(offsetLeft) + Math.abs(offsetRight));
|
|
71
|
+
translateX = Math.min(Math.max(0, translateX - xStart), width - xSize);
|
|
72
72
|
}
|
|
73
|
-
const yStart = lineSize
|
|
73
|
+
const yStart = lineSize;
|
|
74
74
|
const yEnd = height - ySize - lineSize;
|
|
75
75
|
let translateY = yStart;
|
|
76
76
|
if (offsetTop > 0) {
|
|
@@ -80,8 +80,8 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
80
80
|
translateY = yEnd;
|
|
81
81
|
}
|
|
82
82
|
else if (offsetTop <= 0 && ySize > 0 && !(offsetTop === 0 && offsetBottom === 0)) {
|
|
83
|
-
translateY =
|
|
84
|
-
translateY = Math.min(Math.max(0, translateY -
|
|
83
|
+
translateY = yStart + ((height - ySize) * Math.abs(offsetTop)) / (Math.abs(offsetTop) + Math.abs(offsetBottom));
|
|
84
|
+
translateY = Math.min(Math.max(0, translateY - yStart), height - ySize);
|
|
85
85
|
}
|
|
86
86
|
const xThumbRect = {
|
|
87
87
|
x: translateX,
|
|
@@ -101,7 +101,8 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
101
101
|
ySize,
|
|
102
102
|
translateY,
|
|
103
103
|
translateX,
|
|
104
|
-
|
|
104
|
+
thumbColor: scrollConfig.thumbColor,
|
|
105
|
+
scrollBarColor: scrollConfig.scrollBarColor,
|
|
105
106
|
xThumbRect,
|
|
106
107
|
yThumbRect
|
|
107
108
|
};
|
|
@@ -109,42 +110,50 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
109
110
|
}
|
|
110
111
|
function drawScrollerThumb(ctx, opts) {
|
|
111
112
|
let { x, y, h, w } = opts;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
113
|
+
ctx.save();
|
|
114
|
+
ctx.shadowColor = '#FFFFFF';
|
|
115
|
+
ctx.shadowOffsetX = 0;
|
|
116
|
+
ctx.shadowOffsetY = 0;
|
|
117
|
+
ctx.shadowBlur = 1;
|
|
118
|
+
{
|
|
119
|
+
const { color, axis } = opts;
|
|
120
|
+
if (axis === 'X') {
|
|
121
|
+
y = y + h / 4 + 0;
|
|
122
|
+
h = h / 2;
|
|
123
|
+
}
|
|
124
|
+
else if (axis === 'Y') {
|
|
125
|
+
x = x + w / 4 + 0;
|
|
126
|
+
w = w / 2;
|
|
127
|
+
}
|
|
128
|
+
let r = opts.r;
|
|
129
|
+
r = Math.min(r, w / 2, h / 2);
|
|
130
|
+
if (w < r * 2 || h < r * 2) {
|
|
131
|
+
r = 0;
|
|
132
|
+
}
|
|
133
|
+
ctx.globalAlpha = scrollerThumbAlpha;
|
|
134
|
+
ctx.beginPath();
|
|
135
|
+
ctx.moveTo(x + r, y);
|
|
136
|
+
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
137
|
+
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
138
|
+
ctx.arcTo(x, y + h, x, y, r);
|
|
139
|
+
ctx.arcTo(x, y, x + w, y, r);
|
|
140
|
+
ctx.closePath();
|
|
141
|
+
ctx.fillStyle = color;
|
|
142
|
+
ctx.fill();
|
|
143
|
+
ctx.globalAlpha = 1;
|
|
144
|
+
ctx.beginPath();
|
|
145
|
+
ctx.lineWidth = 1;
|
|
146
|
+
ctx.strokeStyle = color;
|
|
147
|
+
ctx.setLineDash([]);
|
|
148
|
+
ctx.moveTo(x + r, y);
|
|
149
|
+
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
150
|
+
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
151
|
+
ctx.arcTo(x, y + h, x, y, r);
|
|
152
|
+
ctx.arcTo(x, y, x + w, y, r);
|
|
153
|
+
ctx.closePath();
|
|
154
|
+
ctx.stroke();
|
|
155
|
+
}
|
|
156
|
+
ctx.restore();
|
|
148
157
|
}
|
|
149
158
|
function drawScrollerInfo(helperContext, opts) {
|
|
150
159
|
const ctx = helperContext;
|
|
@@ -164,18 +173,16 @@ function drawScrollerInfo(helperContext, opts) {
|
|
|
164
173
|
yThumbRect.y = yThumbRect.y + (activePoint.y - prevPoint.y);
|
|
165
174
|
}
|
|
166
175
|
}
|
|
167
|
-
if (scrollConfig.
|
|
168
|
-
ctx.
|
|
169
|
-
ctx.fillStyle = wrapper.color;
|
|
176
|
+
if (scrollConfig.showScrollBar === true) {
|
|
177
|
+
ctx.fillStyle = wrapper.scrollBarColor;
|
|
170
178
|
ctx.fillRect(0, height - wrapper.lineSize, width, wrapper.lineSize);
|
|
171
179
|
}
|
|
172
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.
|
|
173
|
-
if (scrollConfig.
|
|
174
|
-
ctx.
|
|
175
|
-
ctx.fillStyle = wrapper.color;
|
|
180
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.thumbColor }));
|
|
181
|
+
if (scrollConfig.showScrollBar === true) {
|
|
182
|
+
ctx.fillStyle = wrapper.scrollBarColor;
|
|
176
183
|
ctx.fillRect(width - wrapper.lineSize, 0, wrapper.lineSize, height);
|
|
177
184
|
}
|
|
178
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.
|
|
185
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.thumbColor }));
|
|
179
186
|
ctx.globalAlpha = 1;
|
|
180
187
|
return {
|
|
181
188
|
xThumbRect,
|
|
@@ -32,10 +32,6 @@ export function drawSelectedElementControllersVertexes(ctx, controller, opts) {
|
|
|
32
32
|
const wrapperOpts = { borderColor: wrapperColor, borderWidth: 1, background: 'transparent', lineDash: [] };
|
|
33
33
|
const ctrlOpts = Object.assign(Object.assign({}, wrapperOpts), { borderWidth: resizeControllerBorderWidth, background: '#FFFFFF' });
|
|
34
34
|
drawVertexes(ctx, calcViewVertexes(elementWrapper, opts), wrapperOpts);
|
|
35
|
-
drawVertexes(ctx, calcViewVertexes(left.vertexes, opts), ctrlOpts);
|
|
36
|
-
drawVertexes(ctx, calcViewVertexes(right.vertexes, opts), ctrlOpts);
|
|
37
|
-
drawVertexes(ctx, calcViewVertexes(top.vertexes, opts), ctrlOpts);
|
|
38
|
-
drawVertexes(ctx, calcViewVertexes(bottom.vertexes, opts), ctrlOpts);
|
|
39
35
|
drawVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
|
|
40
36
|
drawVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
|
|
41
37
|
drawVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { CoreEvent } from '@idraw/types';
|
|
2
2
|
import type { BoardMiddleware, DeepSelectorSharedStorage } from './types';
|
|
3
|
+
export declare const middlewareEventSelect: string;
|
|
3
4
|
export declare const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, CoreEvent>;
|