@meta2d/core 1.0.78 → 1.0.80

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/src/core.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Canvas } from './canvas';
3
3
  import { Options, PenPlugin, PluginOptions } from './options';
4
4
  import { calcTextDrawRect, calcTextLines, calcTextRect, facePen, getWords, LockState, Pen, renderPenRaw, IValue, setElemPosition } from './pen';
5
5
  import { Point } from './point';
6
- import { EditAction, register, registerAnchors, registerCanvasDraw, Meta2dData, Meta2dStore, Network, HttpOptions, Sql } from './store';
6
+ import { EditAction, register, registerAnchors, registerCanvasDraw, registerLineAnimateDraws, Meta2dData, Meta2dStore, Network, HttpOptions, Sql } from './store';
7
7
  import { Padding } from './utils';
8
8
  import { Rect } from './rect';
9
9
  import { Event, TriggerCondition } from './event';
@@ -103,6 +103,7 @@ export declare class Meta2d {
103
103
  open(data?: Meta2dData, render?: boolean): void;
104
104
  cacheData(id: string): void;
105
105
  loadCacheData(id: string): void;
106
+ loadLineAnimateDraws(): void;
106
107
  statistics(): {
107
108
  图元总数量: number;
108
109
  图片图元数量: number;
@@ -148,6 +149,7 @@ export declare class Meta2d {
148
149
  register: typeof register;
149
150
  registerCanvasDraw: typeof registerCanvasDraw;
150
151
  registerAnchors: typeof registerAnchors;
152
+ registerLineAnimateDraws: typeof registerLineAnimateDraws;
151
153
  registerMoveDock(dock: (store: Meta2dStore, rect: Rect, pens: Pen[], offset: Point) => {
152
154
  xDock: Point;
153
155
  yDock: Point;
@@ -278,6 +280,7 @@ export declare class Meta2d {
278
280
  topic?: string;
279
281
  url?: string;
280
282
  method?: string;
283
+ name?: string;
281
284
  }): void;
282
285
  setDatas(datas: {
283
286
  dataId?: string;
package/src/core.js CHANGED
@@ -2,7 +2,7 @@ import { commonAnchors, commonPens, cube, reset, updateFormData } from './diagra
2
2
  import { Canvas } from './canvas';
3
3
  import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers, isInteraction, calcWorldAnchors, isDomShapes, } from './pen';
4
4
  import { rotatePoint } from './point';
5
- import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
5
+ import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, registerLineAnimateDraws, useStore, } from './store';
6
6
  import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
7
7
  import { calcCenter, calcRelativeRect, calcRightBottom, getRect, rectInRect, } from './rect';
8
8
  import { deepClone } from './utils/clone';
@@ -876,6 +876,7 @@ export class Meta2d {
876
876
  this.initBindDatas();
877
877
  this.initBinds();
878
878
  this.doInitFn();
879
+ this.loadLineAnimateDraws();
879
880
  this.initMessageEvents();
880
881
  this.initGlobalTriggers();
881
882
  this.startAnimate();
@@ -954,6 +955,11 @@ export class Meta2d {
954
955
  });
955
956
  this.render();
956
957
  }
958
+ loadLineAnimateDraws() {
959
+ Object.entries(this.store.data.lineAnimateDraws).forEach(([key, drawFunc]) => {
960
+ globalStore.lineAnimateDraws[key] = eval(drawFunc);
961
+ });
962
+ }
957
963
  statistics() {
958
964
  const num = this.store.data.pens.length;
959
965
  const imgNum = this.store.data.pens.filter((pen) => pen.image).length;
@@ -1320,6 +1326,7 @@ export class Meta2d {
1320
1326
  register = register;
1321
1327
  registerCanvasDraw = registerCanvasDraw;
1322
1328
  registerAnchors = registerAnchors;
1329
+ registerLineAnimateDraws = registerLineAnimateDraws;
1323
1330
  // customeDock = (store, rect, pens, offset) => {xDock, yDock}
1324
1331
  // customDock return:
1325
1332
  // {
@@ -1885,6 +1892,9 @@ export class Meta2d {
1885
1892
  ...Object.keys(this.store.bind),
1886
1893
  ...Object.keys(this.store.bindDatas),
1887
1894
  ];
1895
+ Object.entries(globalStore.lineAnimateDraws).forEach(([key, drawFunc]) => {
1896
+ data.lineAnimateDraws[key] = drawFunc.toString();
1897
+ });
1888
1898
  return data;
1889
1899
  }
1890
1900
  copy(pens) {
@@ -2291,7 +2301,7 @@ export class Meta2d {
2291
2301
  connectSSE(net) {
2292
2302
  this.eventSources[net.index] = new EventSource(net.url, { withCredentials: net.withCredentials });
2293
2303
  this.eventSources[net.index].onmessage = (e) => {
2294
- this.socketCallback(e.data, { type: 'SSE', url: net.url });
2304
+ this.socketCallback(e.data, { type: 'SSE', url: net.url, name: net.name });
2295
2305
  };
2296
2306
  this.eventSources[net.index].onerror = (error) => {
2297
2307
  this.store.emitter.emit('error', { type: 'SSE', error });
@@ -2326,6 +2336,7 @@ export class Meta2d {
2326
2336
  topic,
2327
2337
  type: 'mqtt',
2328
2338
  url: net.url,
2339
+ name: net.name
2329
2340
  });
2330
2341
  });
2331
2342
  this.mqttClients[net.index].on('error', (error) => {
@@ -2361,7 +2372,7 @@ export class Meta2d {
2361
2372
  }
2362
2373
  this.websockets[net.index] = new WebSocket(url, net.protocols || undefined);
2363
2374
  this.websockets[net.index].onmessage = (e) => {
2364
- this.socketCallback(e.data, { type: 'websocket', url: net.url });
2375
+ this.socketCallback(e.data, { type: 'websocket', url: net.url, name: net.name });
2365
2376
  };
2366
2377
  this.websockets[net.index].onerror = (error) => {
2367
2378
  this.store.emitter.emit('error', { type: 'websocket', error });
@@ -2735,7 +2746,7 @@ export class Meta2d {
2735
2746
  });
2736
2747
  if (res.ok) {
2737
2748
  const data = await res.text();
2738
- this.socketCallback(data, { type: 'http', url: req.url });
2749
+ this.socketCallback(data, { type: 'http', url: req.url, name: req.name });
2739
2750
  }
2740
2751
  else {
2741
2752
  _req.times++;
@@ -3936,7 +3947,7 @@ export class Meta2d {
3936
3947
  else {
3937
3948
  right = 0;
3938
3949
  }
3939
- let ratio = (this.canvas.width - left - right) / (rect.width);
3950
+ let ratio = (this.canvas.width - left - right) / (rect.width - left - right);
3940
3951
  pens.forEach((pen) => {
3941
3952
  if (pen.image && pen.imageRatio) {
3942
3953
  if (pen.calculative.worldRect.width / this.canvas.width > 0.1) {
@@ -3959,7 +3970,7 @@ export class Meta2d {
3959
3970
  if (pen.externElement) {
3960
3971
  pen.onResize?.(pen);
3961
3972
  }
3962
- if (pen.children.length) {
3973
+ if (pen.children?.length) {
3963
3974
  const cPens = getAllChildren(pen, this.store);
3964
3975
  cPens.forEach((cPen) => {
3965
3976
  if (cPen.externElement) {