@idraw/core 0.4.0-beta.23 → 0.4.0-beta.24
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/middleware/info/index.js +4 -4
- package/dist/esm/middleware/layout-selector/index.js +2 -2
- package/dist/esm/middleware/ruler/index.js +10 -9
- package/dist/esm/middleware/ruler/util.d.ts +9 -3
- package/dist/esm/middleware/ruler/util.js +26 -3
- package/dist/esm/middleware/scroller/index.js +3 -3
- package/dist/esm/middleware/scroller/util.d.ts +1 -1
- package/dist/esm/middleware/scroller/util.js +7 -7
- package/dist/esm/middleware/selector/index.js +15 -15
- package/dist/index.global.js +142 -80
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
|
@@ -7,7 +7,7 @@ const infoFontSize = 10;
|
|
|
7
7
|
const infoLineHeight = 16;
|
|
8
8
|
export const MiddlewareInfo = (opts) => {
|
|
9
9
|
const { boardContent, calculator } = opts;
|
|
10
|
-
const {
|
|
10
|
+
const { overlayContext } = boardContent;
|
|
11
11
|
return {
|
|
12
12
|
name: '@middleware/info',
|
|
13
13
|
beforeDrawFrame({ snapshot }) {
|
|
@@ -63,7 +63,7 @@ export const MiddlewareInfo = (opts) => {
|
|
|
63
63
|
const xyText = `${formatNumber(x, { decimalPlaces: 0 })},${formatNumber(y, { decimalPlaces: 0 })}`;
|
|
64
64
|
const whText = `${formatNumber(w, { decimalPlaces: 0 })}x${formatNumber(h, { decimalPlaces: 0 })}`;
|
|
65
65
|
const angleText = `${formatNumber(elem.angle || 0, { decimalPlaces: 0 })}°`;
|
|
66
|
-
drawSizeInfoText(
|
|
66
|
+
drawSizeInfoText(overlayContext, {
|
|
67
67
|
point: {
|
|
68
68
|
x: rectInfo.bottom.x,
|
|
69
69
|
y: rectInfo.bottom.y + infoFontSize
|
|
@@ -76,7 +76,7 @@ export const MiddlewareInfo = (opts) => {
|
|
|
76
76
|
color: infoTextColor,
|
|
77
77
|
background: infoBackground
|
|
78
78
|
});
|
|
79
|
-
drawPositionInfoText(
|
|
79
|
+
drawPositionInfoText(overlayContext, {
|
|
80
80
|
point: {
|
|
81
81
|
x: rectInfo.topLeft.x,
|
|
82
82
|
y: rectInfo.topLeft.y - infoFontSize * 2
|
|
@@ -89,7 +89,7 @@ export const MiddlewareInfo = (opts) => {
|
|
|
89
89
|
color: infoTextColor,
|
|
90
90
|
background: infoBackground
|
|
91
91
|
});
|
|
92
|
-
drawAngleInfoText(
|
|
92
|
+
drawAngleInfoText(overlayContext, {
|
|
93
93
|
point: {
|
|
94
94
|
x: rectInfo.top.x + infoFontSize,
|
|
95
95
|
y: rectInfo.top.y - infoFontSize * 2
|
|
@@ -5,7 +5,7 @@ import { drawLayoutController } from './util';
|
|
|
5
5
|
import { eventChange } from '../../config';
|
|
6
6
|
export const MiddlewareLayoutSelector = (opts) => {
|
|
7
7
|
const { sharer, boardContent, calculator, viewer, eventHub } = opts;
|
|
8
|
-
const {
|
|
8
|
+
const { overlayContext } = boardContent;
|
|
9
9
|
let prevPoint = null;
|
|
10
10
|
const clear = () => {
|
|
11
11
|
prevPoint = null;
|
|
@@ -234,7 +234,7 @@ export const MiddlewareLayoutSelector = (opts) => {
|
|
|
234
234
|
const { x, y, w, h } = activeStore.data.layout;
|
|
235
235
|
const size = { x, y, w, h };
|
|
236
236
|
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
|
|
237
|
-
drawLayoutController(
|
|
237
|
+
drawLayoutController(overlayContext, { controller, operations: activeStore.data.layout.operations || {} });
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
|
|
2
|
-
import { drawRulerBackground, drawXRuler, drawYRuler, calcXRulerScaleList, calcYRulerScaleList,
|
|
2
|
+
import { drawRulerBackground, drawXRuler, drawYRuler, calcXRulerScaleList, calcYRulerScaleList, drawGrid, drawScrollerSelectedArea } from './util';
|
|
3
3
|
export const middlewareEventRuler = '@middleware/show-ruler';
|
|
4
4
|
export const MiddlewareRuler = (opts) => {
|
|
5
5
|
const { boardContent, viewer, eventHub, calculator } = opts;
|
|
6
|
-
const {
|
|
6
|
+
const { overlayContext, underlayContext } = boardContent;
|
|
7
7
|
let show = true;
|
|
8
8
|
let showGrid = true;
|
|
9
9
|
const rulerCallback = (e) => {
|
|
@@ -29,14 +29,15 @@ export const MiddlewareRuler = (opts) => {
|
|
|
29
29
|
if (show === true) {
|
|
30
30
|
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
31
31
|
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
32
|
-
drawScrollerSelectedArea(
|
|
33
|
-
drawRulerBackground(
|
|
34
|
-
const xList = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
35
|
-
drawXRuler(
|
|
36
|
-
const yList = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
37
|
-
drawYRuler(
|
|
32
|
+
drawScrollerSelectedArea(overlayContext, { snapshot, calculator });
|
|
33
|
+
drawRulerBackground(overlayContext, { viewScaleInfo, viewSizeInfo });
|
|
34
|
+
const { list: xList, rulerUnit } = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
35
|
+
drawXRuler(overlayContext, { scaleList: xList });
|
|
36
|
+
const { list: yList } = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
37
|
+
drawYRuler(overlayContext, { scaleList: yList });
|
|
38
38
|
if (showGrid === true) {
|
|
39
|
-
|
|
39
|
+
const ctx = rulerUnit === 1 ? overlayContext : underlayContext;
|
|
40
|
+
drawGrid(ctx, {
|
|
40
41
|
xList,
|
|
41
42
|
yList,
|
|
42
43
|
viewScaleInfo,
|
|
@@ -10,11 +10,17 @@ interface RulerScale {
|
|
|
10
10
|
export declare function calcXRulerScaleList(opts: {
|
|
11
11
|
viewScaleInfo: ViewScaleInfo;
|
|
12
12
|
viewSizeInfo: ViewSizeInfo;
|
|
13
|
-
}):
|
|
13
|
+
}): {
|
|
14
|
+
list: RulerScale[];
|
|
15
|
+
rulerUnit: number;
|
|
16
|
+
};
|
|
14
17
|
export declare function calcYRulerScaleList(opts: {
|
|
15
18
|
viewScaleInfo: ViewScaleInfo;
|
|
16
19
|
viewSizeInfo: ViewSizeInfo;
|
|
17
|
-
}):
|
|
20
|
+
}): {
|
|
21
|
+
list: RulerScale[];
|
|
22
|
+
rulerUnit: number;
|
|
23
|
+
};
|
|
18
24
|
export declare function drawXRuler(ctx: ViewContext2D, opts: {
|
|
19
25
|
scaleList: RulerScale[];
|
|
20
26
|
}): void;
|
|
@@ -25,7 +31,7 @@ export declare function drawRulerBackground(ctx: ViewContext2D, opts: {
|
|
|
25
31
|
viewScaleInfo: ViewScaleInfo;
|
|
26
32
|
viewSizeInfo: ViewSizeInfo;
|
|
27
33
|
}): void;
|
|
28
|
-
export declare function
|
|
34
|
+
export declare function drawGrid(ctx: ViewContext2D, opts: {
|
|
29
35
|
xList: RulerScale[];
|
|
30
36
|
yList: RulerScale[];
|
|
31
37
|
viewScaleInfo: ViewScaleInfo;
|
|
@@ -12,12 +12,35 @@ const gridColor = '#AAAAAA20';
|
|
|
12
12
|
const gridKeyColor = '#AAAAAA40';
|
|
13
13
|
const lineSize = 1;
|
|
14
14
|
const selectedAreaColor = '#196097';
|
|
15
|
+
const limitRulerUnitList = [1, 2, 5, 10, 20, 50, 100, 200, 500];
|
|
16
|
+
function limitRulerUnit(unit) {
|
|
17
|
+
unit = Math.max(limitRulerUnitList[0], Math.min(unit, limitRulerUnitList[limitRulerUnitList.length - 1]));
|
|
18
|
+
for (let i = 0; i < limitRulerUnitList.length - 1; i++) {
|
|
19
|
+
const thisUnit = limitRulerUnitList[i];
|
|
20
|
+
const nextUnit = limitRulerUnitList[i + 1];
|
|
21
|
+
if (unit > nextUnit) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (unit === thisUnit) {
|
|
25
|
+
return unit;
|
|
26
|
+
}
|
|
27
|
+
if (unit === nextUnit) {
|
|
28
|
+
return unit;
|
|
29
|
+
}
|
|
30
|
+
const mid = (thisUnit + nextUnit) / 2;
|
|
31
|
+
if (unit <= mid) {
|
|
32
|
+
return thisUnit;
|
|
33
|
+
}
|
|
34
|
+
return nextUnit;
|
|
35
|
+
}
|
|
36
|
+
return unit;
|
|
37
|
+
}
|
|
15
38
|
function calcRulerScaleList(opts) {
|
|
16
39
|
const { scale, viewLength, viewOffset } = opts;
|
|
17
40
|
const list = [];
|
|
18
41
|
let rulerUnit = 10;
|
|
19
42
|
rulerUnit = formatNumber(rulerUnit / scale, { decimalPlaces: 0 });
|
|
20
|
-
rulerUnit =
|
|
43
|
+
rulerUnit = limitRulerUnit(rulerUnit);
|
|
21
44
|
const rulerKeyUnit = rulerUnit * 10;
|
|
22
45
|
const rulerSubKeyUnit = rulerUnit * 5;
|
|
23
46
|
let index = 0;
|
|
@@ -40,7 +63,7 @@ function calcRulerScaleList(opts) {
|
|
|
40
63
|
list.push(rulerScale);
|
|
41
64
|
index++;
|
|
42
65
|
}
|
|
43
|
-
return list;
|
|
66
|
+
return { list, rulerUnit };
|
|
44
67
|
}
|
|
45
68
|
export function calcXRulerScaleList(opts) {
|
|
46
69
|
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
@@ -152,7 +175,7 @@ export function drawRulerBackground(ctx, opts) {
|
|
|
152
175
|
ctx.strokeStyle = borderColor;
|
|
153
176
|
ctx.stroke();
|
|
154
177
|
}
|
|
155
|
-
export function
|
|
178
|
+
export function drawGrid(ctx, opts) {
|
|
156
179
|
const { xList, yList, viewSizeInfo } = opts;
|
|
157
180
|
const { width, height } = viewSizeInfo;
|
|
158
181
|
for (let i = 0; i < xList.length; i++) {
|
|
@@ -2,7 +2,7 @@ import { drawScroller, isPointInScrollThumb } from './util';
|
|
|
2
2
|
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
3
3
|
export const MiddlewareScroller = (opts) => {
|
|
4
4
|
const { viewer, boardContent, sharer } = opts;
|
|
5
|
-
const {
|
|
5
|
+
const { overlayContext } = boardContent;
|
|
6
6
|
sharer.setSharedStorage(keyXThumbRect, null);
|
|
7
7
|
sharer.setSharedStorage(keyYThumbRect, null);
|
|
8
8
|
const clear = () => {
|
|
@@ -36,7 +36,7 @@ export const MiddlewareScroller = (opts) => {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
const getThumbType = (p) => {
|
|
39
|
-
return isPointInScrollThumb(
|
|
39
|
+
return isPointInScrollThumb(overlayContext, p, {
|
|
40
40
|
xThumbRect: sharer.getSharedStorage(keyXThumbRect),
|
|
41
41
|
yThumbRect: sharer.getSharedStorage(keyYThumbRect)
|
|
42
42
|
});
|
|
@@ -84,7 +84,7 @@ export const MiddlewareScroller = (opts) => {
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
beforeDrawFrame({ snapshot }) {
|
|
87
|
-
const { xThumbRect, yThumbRect } = drawScroller(
|
|
87
|
+
const { xThumbRect, yThumbRect } = drawScroller(overlayContext, { snapshot });
|
|
88
88
|
sharer.setSharedStorage(keyXThumbRect, xThumbRect);
|
|
89
89
|
sharer.setSharedStorage(keyYThumbRect, yThumbRect);
|
|
90
90
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Point, BoardViewerFrameSnapshot, ViewContext2D, ElementSize } from '@idraw/types';
|
|
2
2
|
export type ScrollbarThumbType = 'X' | 'Y';
|
|
3
|
-
export declare function isPointInScrollThumb(
|
|
3
|
+
export declare function isPointInScrollThumb(overlayContext: ViewContext2D, p: Point, opts: {
|
|
4
4
|
xThumbRect?: ElementSize | null;
|
|
5
5
|
yThumbRect?: ElementSize | null;
|
|
6
6
|
}): ScrollbarThumbType | null;
|
|
@@ -9,8 +9,8 @@ const scrollConfig = {
|
|
|
9
9
|
scrollBarColor: '#FFFFFF60',
|
|
10
10
|
showScrollBar: false
|
|
11
11
|
};
|
|
12
|
-
function isPointAtRect(
|
|
13
|
-
const ctx =
|
|
12
|
+
function isPointAtRect(overlayContext, p, rect) {
|
|
13
|
+
const ctx = overlayContext;
|
|
14
14
|
const { x, y, w, h } = rect;
|
|
15
15
|
ctx.beginPath();
|
|
16
16
|
ctx.rect(x, y, w, h);
|
|
@@ -20,13 +20,13 @@ function isPointAtRect(helperContext, p, rect) {
|
|
|
20
20
|
}
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
|
-
export function isPointInScrollThumb(
|
|
23
|
+
export function isPointInScrollThumb(overlayContext, p, opts) {
|
|
24
24
|
let thumbType = null;
|
|
25
25
|
const { xThumbRect, yThumbRect } = opts;
|
|
26
|
-
if (xThumbRect && isPointAtRect(
|
|
26
|
+
if (xThumbRect && isPointAtRect(overlayContext, p, xThumbRect)) {
|
|
27
27
|
thumbType = 'X';
|
|
28
28
|
}
|
|
29
|
-
else if (yThumbRect && isPointAtRect(
|
|
29
|
+
else if (yThumbRect && isPointAtRect(overlayContext, p, yThumbRect)) {
|
|
30
30
|
thumbType = 'Y';
|
|
31
31
|
}
|
|
32
32
|
return thumbType;
|
|
@@ -155,8 +155,8 @@ function drawScrollerThumb(ctx, opts) {
|
|
|
155
155
|
}
|
|
156
156
|
ctx.restore();
|
|
157
157
|
}
|
|
158
|
-
function drawScrollerInfo(
|
|
159
|
-
const ctx =
|
|
158
|
+
function drawScrollerInfo(overlayContext, opts) {
|
|
159
|
+
const ctx = overlayContext;
|
|
160
160
|
const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
|
|
161
161
|
const { activeThumbType, prevPoint, activePoint } = scrollInfo;
|
|
162
162
|
const { width, height } = viewSizeInfo;
|
|
@@ -10,7 +10,7 @@ export { keySelectedElementList, keyActionType, keyResizeType, keyGroupQueue };
|
|
|
10
10
|
export { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup };
|
|
11
11
|
export const MiddlewareSelector = (opts) => {
|
|
12
12
|
const { viewer, sharer, boardContent, calculator, eventHub } = opts;
|
|
13
|
-
const {
|
|
13
|
+
const { overlayContext } = boardContent;
|
|
14
14
|
let prevPoint = null;
|
|
15
15
|
let inBusyMode = null;
|
|
16
16
|
sharer.setSharedStorage(keyActionType, null);
|
|
@@ -70,7 +70,7 @@ export const MiddlewareSelector = (opts) => {
|
|
|
70
70
|
};
|
|
71
71
|
const pointTargetBaseOptions = () => {
|
|
72
72
|
return {
|
|
73
|
-
ctx:
|
|
73
|
+
ctx: overlayContext,
|
|
74
74
|
calculator,
|
|
75
75
|
data: sharer.getActiveStorage('data'),
|
|
76
76
|
selectedElements: getActiveElements(),
|
|
@@ -163,7 +163,7 @@ export const MiddlewareSelector = (opts) => {
|
|
|
163
163
|
};
|
|
164
164
|
if ((groupQueue === null || groupQueue === void 0 ? void 0 : groupQueue.length) > 0) {
|
|
165
165
|
const isInActiveGroup = isPointInViewActiveGroup(e.point, {
|
|
166
|
-
ctx:
|
|
166
|
+
ctx: overlayContext,
|
|
167
167
|
viewScaleInfo: sharer.getActiveViewScaleInfo(),
|
|
168
168
|
viewSizeInfo: sharer.getActiveViewSizeInfo(),
|
|
169
169
|
groupQueue: sharer.getSharedStorage(keyGroupQueue)
|
|
@@ -243,7 +243,7 @@ export const MiddlewareSelector = (opts) => {
|
|
|
243
243
|
const groupQueue = sharer.getSharedStorage(keyGroupQueue);
|
|
244
244
|
if ((groupQueue === null || groupQueue === void 0 ? void 0 : groupQueue.length) > 0) {
|
|
245
245
|
if (isPointInViewActiveGroup(e.point, {
|
|
246
|
-
ctx:
|
|
246
|
+
ctx: overlayContext,
|
|
247
247
|
viewScaleInfo: sharer.getActiveViewScaleInfo(),
|
|
248
248
|
viewSizeInfo: sharer.getActiveViewSizeInfo(),
|
|
249
249
|
groupQueue
|
|
@@ -608,25 +608,25 @@ export const MiddlewareSelector = (opts) => {
|
|
|
608
608
|
: null;
|
|
609
609
|
const isLock = !!((_a = hoverElement === null || hoverElement === void 0 ? void 0 : hoverElement.operations) === null || _a === void 0 ? void 0 : _a.lock);
|
|
610
610
|
if ((groupQueue === null || groupQueue === void 0 ? void 0 : groupQueue.length) > 0) {
|
|
611
|
-
drawGroupQueueVertexesWrappers(
|
|
611
|
+
drawGroupQueueVertexesWrappers(overlayContext, groupQueueVertexesList, drawBaseOpts);
|
|
612
612
|
if (hoverElement && actionType !== 'drag') {
|
|
613
613
|
if (isLock) {
|
|
614
|
-
drawLockVertexesWrapper(
|
|
614
|
+
drawLockVertexesWrapper(overlayContext, hoverElementVertexes, Object.assign(Object.assign({}, drawBaseOpts), { controller: calcElementSizeController(hoverElement, {
|
|
615
615
|
groupQueue,
|
|
616
616
|
controllerSize: 10,
|
|
617
617
|
viewScaleInfo
|
|
618
618
|
}) }));
|
|
619
619
|
}
|
|
620
620
|
else {
|
|
621
|
-
drawHoverVertexesWrapper(
|
|
621
|
+
drawHoverVertexesWrapper(overlayContext, hoverElementVertexes, drawBaseOpts);
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
624
|
if (!isLock && elem && ['select', 'drag', 'resize'].includes(actionType)) {
|
|
625
|
-
drawSelectedElementControllersVertexes(
|
|
625
|
+
drawSelectedElementControllersVertexes(overlayContext, selectedElementController, Object.assign(Object.assign({}, drawBaseOpts), { element: elem, calculator, hideControllers: !!isMoving && actionType === 'drag' }));
|
|
626
626
|
if (actionType === 'drag') {
|
|
627
627
|
const xLines = sharer.getSharedStorage(keySelectedReferenceXLines);
|
|
628
628
|
const yLines = sharer.getSharedStorage(keySelectedReferenceYLines);
|
|
629
|
-
drawReferenceLines(
|
|
629
|
+
drawReferenceLines(overlayContext, {
|
|
630
630
|
xLines,
|
|
631
631
|
yLines
|
|
632
632
|
});
|
|
@@ -636,29 +636,29 @@ export const MiddlewareSelector = (opts) => {
|
|
|
636
636
|
else {
|
|
637
637
|
if (hoverElement && actionType !== 'drag') {
|
|
638
638
|
if (isLock) {
|
|
639
|
-
drawLockVertexesWrapper(
|
|
639
|
+
drawLockVertexesWrapper(overlayContext, hoverElementVertexes, Object.assign(Object.assign({}, drawBaseOpts), { controller: calcElementSizeController(hoverElement, {
|
|
640
640
|
groupQueue,
|
|
641
641
|
controllerSize: 10,
|
|
642
642
|
viewScaleInfo
|
|
643
643
|
}) }));
|
|
644
644
|
}
|
|
645
645
|
else {
|
|
646
|
-
drawHoverVertexesWrapper(
|
|
646
|
+
drawHoverVertexesWrapper(overlayContext, hoverElementVertexes, drawBaseOpts);
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
if (!isLock && elem && ['select', 'drag', 'resize'].includes(actionType)) {
|
|
650
|
-
drawSelectedElementControllersVertexes(
|
|
650
|
+
drawSelectedElementControllersVertexes(overlayContext, selectedElementController, Object.assign(Object.assign({}, drawBaseOpts), { element: elem, calculator, hideControllers: !!isMoving && actionType === 'drag' }));
|
|
651
651
|
if (actionType === 'drag') {
|
|
652
652
|
const xLines = sharer.getSharedStorage(keySelectedReferenceXLines);
|
|
653
653
|
const yLines = sharer.getSharedStorage(keySelectedReferenceYLines);
|
|
654
|
-
drawReferenceLines(
|
|
654
|
+
drawReferenceLines(overlayContext, {
|
|
655
655
|
xLines,
|
|
656
656
|
yLines
|
|
657
657
|
});
|
|
658
658
|
}
|
|
659
659
|
}
|
|
660
660
|
else if (actionType === 'area' && areaStart && areaEnd) {
|
|
661
|
-
drawArea(
|
|
661
|
+
drawArea(overlayContext, { start: areaStart, end: areaEnd });
|
|
662
662
|
}
|
|
663
663
|
else if (['drag-list', 'drag-list-end'].includes(actionType)) {
|
|
664
664
|
const listAreaSize = calcSelectedElementsArea(getActiveElements(), {
|
|
@@ -667,7 +667,7 @@ export const MiddlewareSelector = (opts) => {
|
|
|
667
667
|
calculator
|
|
668
668
|
});
|
|
669
669
|
if (listAreaSize) {
|
|
670
|
-
drawListArea(
|
|
670
|
+
drawListArea(overlayContext, { areaSize: listAreaSize });
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
}
|