@meta2d/core 1.1.20 → 1.1.22
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/package.json +1 -1
- package/src/canvas/canvas.js +87 -15
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +3 -3
- package/src/core.js +65 -18
- package/src/core.js.map +1 -1
- package/src/diagrams/htmlDom.d.ts +12 -0
- package/src/diagrams/htmlDom.js +66 -0
- package/src/diagrams/htmlDom.js.map +1 -0
- package/src/diagrams/index.d.ts +3 -0
- package/src/diagrams/index.js +3 -0
- package/src/diagrams/index.js.map +1 -1
- package/src/options.d.ts +1 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/render.js +157 -65
- package/src/pen/render.js.map +1 -1
- package/src/point/point.d.ts +3 -0
- package/src/point/point.js.map +1 -1
- package/src/store/store.d.ts +2 -0
- package/src/store/store.js.map +1 -1
package/package.json
CHANGED
package/src/canvas/canvas.js
CHANGED
|
@@ -4,7 +4,7 @@ import { calcRotate, distance, getDistance, hitPoint, PointType, PrevNextType, r
|
|
|
4
4
|
import { calcCenter, calcRightBottom, calcRelativePoint, getRect, getRectOfPoints, pointInRect, pointInSimpleRect, rectInRect, rectToPoints, resizeRect, translateRect, pointInPolygon } from '../rect';
|
|
5
5
|
import { EditType, globalStore, } from '../store';
|
|
6
6
|
import { deepClone, fileToBase64, uploadFile, formatPadding, rgba, s8, toNumber, } from '../utils';
|
|
7
|
-
import { inheritanceProps, defaultCursors, defaultDrawLineFns, HotkeyType, HoverType, MouseRight, rotatedCursors, } from '../data';
|
|
7
|
+
import { inheritanceProps, defaultCursors, defaultDrawLineFns, HotkeyType, HoverType, MouseRight, rotatedCursors, Direction, } from '../data';
|
|
8
8
|
import { createOffscreen } from './offscreen';
|
|
9
9
|
import { curve, mind, getLineLength, getLineRect, pointInLine, simplify, smoothLine, lineSegment, getLineR, lineInRect, } from '../diagrams';
|
|
10
10
|
import { polyline, translatePolylineAnchor } from '../diagrams/line/polyline';
|
|
@@ -21,6 +21,7 @@ import { CanvasTemplate } from './canvasTemplate';
|
|
|
21
21
|
import { getLinePoints } from '../diagrams/line';
|
|
22
22
|
import { Popconfirm } from '../popconfirm';
|
|
23
23
|
import { le5leTheme, themeKeys } from '../theme';
|
|
24
|
+
import { getFont } from '../pen/render';
|
|
24
25
|
export const movingSuffix = '-moving';
|
|
25
26
|
export class Canvas {
|
|
26
27
|
parent;
|
|
@@ -4368,20 +4369,22 @@ export class Canvas {
|
|
|
4368
4369
|
if (!this.patchFlags) {
|
|
4369
4370
|
return;
|
|
4370
4371
|
}
|
|
4371
|
-
if (
|
|
4372
|
-
if (
|
|
4373
|
-
this.store.options.interval
|
|
4374
|
-
|
|
4372
|
+
if (patchFlags != null) {
|
|
4373
|
+
if (now - this.lastRender < this.store.options.interval) {
|
|
4374
|
+
if (this.store.options.interval > this.store.options.minFPSNumber && this.store.options.autoFPS) {
|
|
4375
|
+
this.store.options.interval--;
|
|
4376
|
+
this.store.options.animateInterval = this.store.options.interval;
|
|
4377
|
+
}
|
|
4378
|
+
if (this.renderTimer) {
|
|
4379
|
+
cancelAnimationFrame(this.renderTimer);
|
|
4380
|
+
}
|
|
4381
|
+
this.renderTimer = requestAnimationFrame(this.render);
|
|
4382
|
+
return;
|
|
4375
4383
|
}
|
|
4376
|
-
if (this.
|
|
4377
|
-
|
|
4384
|
+
else if (now - this.lastRender - this.store.options.interval > 10 && this.store.options.autoFPS && document.visibilityState === 'visible') {
|
|
4385
|
+
this.store.options.interval++;
|
|
4386
|
+
this.store.options.animateInterval = this.store.options.interval;
|
|
4378
4387
|
}
|
|
4379
|
-
this.renderTimer = requestAnimationFrame(this.render);
|
|
4380
|
-
return;
|
|
4381
|
-
}
|
|
4382
|
-
else if (now - this.lastRender - this.store.options.interval > 10 && this.store.options.autoFPS && document.visibilityState === 'visible') {
|
|
4383
|
-
this.store.options.interval++;
|
|
4384
|
-
this.store.options.animateInterval = this.store.options.interval;
|
|
4385
4388
|
}
|
|
4386
4389
|
this.renderTimer = undefined;
|
|
4387
4390
|
this.lastRender = now;
|
|
@@ -4693,7 +4696,9 @@ export class Canvas {
|
|
|
4693
4696
|
ctx.translate(0.5, 0.5);
|
|
4694
4697
|
ctx.strokeStyle = pen.anchorColor || this.store.styles.anchorColor;
|
|
4695
4698
|
ctx.fillStyle = pen.anchorBackground || this.store.options.anchorBackground;
|
|
4696
|
-
pen.calculative
|
|
4699
|
+
const { fontStyle, fontWeight, fontSize, fontFamily, lineHeight } = pen.calculative;
|
|
4700
|
+
const scale = this.store.data.scale;
|
|
4701
|
+
pen.calculative.worldAnchors.forEach((anchor, index) => {
|
|
4697
4702
|
if (anchor.hidden || anchor.locked > LockState.DisableEdit) {
|
|
4698
4703
|
return;
|
|
4699
4704
|
}
|
|
@@ -4758,6 +4763,71 @@ export class Canvas {
|
|
|
4758
4763
|
else if (anchor.color || anchor.background) {
|
|
4759
4764
|
ctx.restore();
|
|
4760
4765
|
}
|
|
4766
|
+
if (anchor.label) {
|
|
4767
|
+
ctx.save();
|
|
4768
|
+
ctx.font = getFont({
|
|
4769
|
+
fontStyle,
|
|
4770
|
+
fontWeight,
|
|
4771
|
+
fontFamily,
|
|
4772
|
+
fontSize,
|
|
4773
|
+
lineHeight,
|
|
4774
|
+
});
|
|
4775
|
+
const rX = pen.anchors[index].x;
|
|
4776
|
+
const rY = pen.anchors[index].y;
|
|
4777
|
+
let xGap = 0;
|
|
4778
|
+
let yGap = 0;
|
|
4779
|
+
if (anchor.labelDirection !== undefined) {
|
|
4780
|
+
if (anchor.labelDirection === Direction.Left) {
|
|
4781
|
+
ctx.textAlign = 'right';
|
|
4782
|
+
ctx.textBaseline = 'middle';
|
|
4783
|
+
xGap = -(anchor.labelGap || 10) * scale;
|
|
4784
|
+
}
|
|
4785
|
+
else if (anchor.labelDirection === Direction.Right) {
|
|
4786
|
+
ctx.textAlign = 'left';
|
|
4787
|
+
ctx.textBaseline = 'middle';
|
|
4788
|
+
xGap = (anchor.labelGap || 10) * scale;
|
|
4789
|
+
}
|
|
4790
|
+
else if (anchor.labelDirection === Direction.Up) {
|
|
4791
|
+
ctx.textAlign = 'center';
|
|
4792
|
+
ctx.textBaseline = 'bottom';
|
|
4793
|
+
yGap = -(anchor.labelGap || 5) * scale;
|
|
4794
|
+
}
|
|
4795
|
+
else if (anchor.labelDirection === Direction.Bottom) {
|
|
4796
|
+
ctx.textAlign = 'center';
|
|
4797
|
+
ctx.textBaseline = 'top';
|
|
4798
|
+
yGap = (anchor.labelGap || 5) * scale;
|
|
4799
|
+
}
|
|
4800
|
+
}
|
|
4801
|
+
else {
|
|
4802
|
+
if (rX < 0.1) {
|
|
4803
|
+
ctx.textAlign = 'left';
|
|
4804
|
+
ctx.textBaseline = 'middle';
|
|
4805
|
+
xGap = (anchor.labelGap || 10) * scale;
|
|
4806
|
+
}
|
|
4807
|
+
else if (rX > 0.9) {
|
|
4808
|
+
ctx.textAlign = 'right';
|
|
4809
|
+
ctx.textBaseline = 'middle';
|
|
4810
|
+
xGap = -(anchor.labelGap || 10) * scale;
|
|
4811
|
+
}
|
|
4812
|
+
else {
|
|
4813
|
+
ctx.textAlign = 'center';
|
|
4814
|
+
if (rY < 0.1) {
|
|
4815
|
+
ctx.textBaseline = 'top';
|
|
4816
|
+
yGap = (anchor.labelGap || 5) * scale;
|
|
4817
|
+
}
|
|
4818
|
+
else if (rY > 0.9) {
|
|
4819
|
+
ctx.textBaseline = 'bottom';
|
|
4820
|
+
yGap = -(anchor.labelGap || 5) * scale;
|
|
4821
|
+
}
|
|
4822
|
+
else {
|
|
4823
|
+
ctx.textBaseline = 'middle';
|
|
4824
|
+
}
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
ctx.fillStyle = getTextColor(pen, this.store);
|
|
4828
|
+
ctx.fillText(anchor.label, anchor.x + xGap, anchor.y + yGap);
|
|
4829
|
+
ctx.restore();
|
|
4830
|
+
}
|
|
4761
4831
|
//根父节点
|
|
4762
4832
|
if (!pen.parentId && pen.children && pen.children.length > 0) {
|
|
4763
4833
|
if (anchor === this.store.hoverAnchor) {
|
|
@@ -7017,7 +7087,9 @@ export class Canvas {
|
|
|
7017
7087
|
sheet.insertRule('.meta2d-input ul{position:absolute;top:100%;margin-top:4px; width:calc(100% + 10px);min-height:30px;border-radius: 2px;box-shadow: 0 2px 8px #00000026;list-style-type: none;background-color: #fff;padding: 4px 0;max-height: 105px;overflow-y: auto;}');
|
|
7018
7088
|
sheet.insertRule('.meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}');
|
|
7019
7089
|
sheet.insertRule('.meta2d-input ul li:hover{background: #eeeeee;}');
|
|
7020
|
-
|
|
7090
|
+
if (CSS.supports?.('selector(.input-div::-webkit-scrollbar)')) {
|
|
7091
|
+
sheet.insertRule(`.input-div::-webkit-scrollbar {display:none}`);
|
|
7092
|
+
}
|
|
7021
7093
|
sheet.insertRule(`.input-div{scrollbar-width: none;}`);
|
|
7022
7094
|
sheet.insertRule('.meta2d-input .input-div{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;width: 100%;left:0;top:0;display:flex;text-align: center;justify-content: center;flex-direction: column;}');
|
|
7023
7095
|
sheet.insertRule(`.input-div div{}`);
|