@meta2d/core 1.1.21 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meta2d/core",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "description": "@meta2d/core: Powerful, Beautiful, Simple, Open - Web-Based 2D At Its Best .",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -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;
@@ -4695,7 +4696,9 @@ export class Canvas {
4695
4696
  ctx.translate(0.5, 0.5);
4696
4697
  ctx.strokeStyle = pen.anchorColor || this.store.styles.anchorColor;
4697
4698
  ctx.fillStyle = pen.anchorBackground || this.store.options.anchorBackground;
4698
- pen.calculative.worldAnchors.forEach((anchor) => {
4699
+ const { fontStyle, fontWeight, fontSize, fontFamily, lineHeight } = pen.calculative;
4700
+ const scale = this.store.data.scale;
4701
+ pen.calculative.worldAnchors.forEach((anchor, index) => {
4699
4702
  if (anchor.hidden || anchor.locked > LockState.DisableEdit) {
4700
4703
  return;
4701
4704
  }
@@ -4760,6 +4763,71 @@ export class Canvas {
4760
4763
  else if (anchor.color || anchor.background) {
4761
4764
  ctx.restore();
4762
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
+ }
4763
4831
  //根父节点
4764
4832
  if (!pen.parentId && pen.children && pen.children.length > 0) {
4765
4833
  if (anchor === this.store.hoverAnchor) {
@@ -7019,7 +7087,9 @@ export class Canvas {
7019
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;}');
7020
7088
  sheet.insertRule('.meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}');
7021
7089
  sheet.insertRule('.meta2d-input ul li:hover{background: #eeeeee;}');
7022
- sheet.insertRule(`.input-div::-webkit-scrollbar {display:none}`);
7090
+ if (CSS.supports?.('selector(.input-div::-webkit-scrollbar)')) {
7091
+ sheet.insertRule(`.input-div::-webkit-scrollbar {display:none}`);
7092
+ }
7023
7093
  sheet.insertRule(`.input-div{scrollbar-width: none;}`);
7024
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;}');
7025
7095
  sheet.insertRule(`.input-div div{}`);