@meta2d/core 1.1.1 → 1.1.3

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
@@ -74,7 +74,7 @@ export declare class Meta2d {
74
74
  private init;
75
75
  initEventFns(): void;
76
76
  getSendData(data: any[], cpen?: Pen): any;
77
- convertType(value: string, type: string): string | number | boolean;
77
+ convertType(value: string, type: string): any;
78
78
  getEventData(list: any, pen: Pen): any;
79
79
  message(options: MessageOptions): void;
80
80
  closeAll(): void;
@@ -87,6 +87,7 @@ export declare class Meta2d {
87
87
  * @param emit 是否发送消息
88
88
  */
89
89
  addPen(pen: Pen, history?: boolean, emit?: boolean, abs?: boolean): Promise<Pen>;
90
+ addPenSync(pen: Pen, history?: boolean, emit?: boolean, abs?: boolean): Pen;
90
91
  addPens(pens: Pen[], history?: boolean, abs?: boolean): Promise<Pen[]>;
91
92
  render(patchFlags?: boolean | number): void;
92
93
  setBackgroundImage(url: string, data?: any): Promise<void>;
@@ -214,6 +215,7 @@ export declare class Meta2d {
214
215
  * @param canDelLocked 是否删除已经锁住的画笔
215
216
  */
216
217
  delete(pens?: Pen[], canDelLocked?: boolean, history?: boolean): void;
218
+ deleteSync(pens?: Pen[], canDelLocked?: boolean, history?: boolean): void;
217
219
  scale(scale: number, center?: {
218
220
  x: number;
219
221
  y: number;
package/src/core.js CHANGED
@@ -611,6 +611,16 @@ export class Meta2d {
611
611
  }
612
612
  }
613
613
  }
614
+ else if (typeof value === 'object') {
615
+ let bodyStr = JSON.stringify(value);
616
+ let keys = bodyStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
617
+ if (keys?.length) {
618
+ for (let i = 0; i < keys.length; i++) {
619
+ bodyStr = bodyStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
620
+ }
621
+ }
622
+ return JSON.parse(bodyStr);
623
+ }
614
624
  return value;
615
625
  }
616
626
  getEventData(list, pen) {
@@ -862,6 +872,9 @@ export class Meta2d {
862
872
  async addPen(pen, history, emit = true, abs = false) {
863
873
  return await this.canvas.addPen(pen, history, emit, abs);
864
874
  }
875
+ addPenSync(pen, history, emit = true, abs = false) {
876
+ return this.canvas.addPenSync(pen, history, emit, abs);
877
+ }
865
878
  async addPens(pens, history, abs = false) {
866
879
  return await this.canvas.addPens(pens, history, abs);
867
880
  }
@@ -1180,33 +1193,36 @@ export class Meta2d {
1180
1193
  // key: realTime.key,
1181
1194
  // });
1182
1195
  //JetLinks
1196
+ const Jet = this.store.data.networks?.some((item) => item.protocol === 'ADIIOT');
1183
1197
  let productId = realTime.productId || pen.productId;
1184
1198
  let deviceId = realTime.deviceId || pen.deviceId;
1185
1199
  let propertyId = realTime.propertyId;
1186
1200
  let flag = false;
1187
- if (productId && productId.indexOf('${') > -1) {
1188
- let keys = productId.match(/(?<=\$\{).*?(?=\})/g);
1189
- if (keys?.length) {
1190
- productId = this.getDynamicParam(keys[0]) || productId;
1201
+ if (Jet) {
1202
+ if (productId && typeof productId === 'string' && productId.indexOf('${') > -1) {
1203
+ let keys = productId.match(/(?<=\$\{).*?(?=\})/g);
1204
+ if (keys?.length) {
1205
+ productId = this.getDynamicParam(keys[0]) || productId;
1206
+ }
1207
+ flag = true;
1191
1208
  }
1192
- flag = true;
1193
- }
1194
- if (deviceId && deviceId.indexOf('${') > -1) {
1195
- let keys = deviceId.match(/(?<=\$\{).*?(?=\})/g);
1196
- if (keys?.length) {
1197
- deviceId = this.getDynamicParam(keys[0]) || deviceId;
1209
+ if (deviceId && typeof deviceId === 'string' && deviceId.indexOf('${') > -1) {
1210
+ let keys = deviceId.match(/(?<=\$\{).*?(?=\})/g);
1211
+ if (keys?.length) {
1212
+ deviceId = this.getDynamicParam(keys[0]) || deviceId;
1213
+ }
1214
+ flag = true;
1198
1215
  }
1199
- flag = true;
1200
- }
1201
- if (propertyId && propertyId.indexOf('${') > -1) {
1202
- let keys = propertyId.match(/(?<=\$\{).*?(?=\})/g);
1203
- if (keys?.length) {
1204
- propertyId = this.getDynamicParam(keys[0]) || propertyId;
1216
+ if (propertyId && typeof propertyId === 'string' && propertyId.indexOf('${') > -1) {
1217
+ let keys = propertyId.match(/(?<=\$\{).*?(?=\})/g);
1218
+ if (keys?.length) {
1219
+ propertyId = this.getDynamicParam(keys[0]) || propertyId;
1220
+ }
1221
+ flag = true;
1222
+ }
1223
+ if (flag) {
1224
+ realTime.bind && (realTime.bind.id = productId + '#' + deviceId + '#' + propertyId);
1205
1225
  }
1206
- flag = true;
1207
- }
1208
- if (flag) {
1209
- realTime.bind && (realTime.bind.id = productId + '#' + deviceId + '#' + propertyId);
1210
1226
  }
1211
1227
  if (!this.store.bind[realTime.bind.id]) {
1212
1228
  this.store.bind[realTime.bind.id] = [];
@@ -1215,20 +1231,22 @@ export class Meta2d {
1215
1231
  id: pen.id,
1216
1232
  key: realTime.key,
1217
1233
  });
1218
- if (productId && deviceId && propertyId) {
1219
- const index = this.jetLinksList.findIndex((item) => item.topic.startsWith(`/${productId}/${deviceId}`));
1220
- if (index > -1) {
1221
- const properties = this.jetLinksList[index].properties;
1222
- if (!properties.includes(realTime.propertyId)) {
1223
- this.jetLinksList[index].properties.push(realTime.propertyId);
1234
+ if (Jet) {
1235
+ if (productId && deviceId && propertyId) {
1236
+ const index = this.jetLinksList.findIndex((item) => item.topic.startsWith(`/${productId}/${deviceId}`));
1237
+ if (index > -1) {
1238
+ const properties = this.jetLinksList[index].properties;
1239
+ if (!properties.includes(realTime.propertyId)) {
1240
+ this.jetLinksList[index].properties.push(realTime.propertyId);
1241
+ }
1242
+ }
1243
+ else {
1244
+ this.jetLinksList.push({
1245
+ topic: `/${productId}/${deviceId}`,
1246
+ deviceId,
1247
+ properties: [realTime.propertyId],
1248
+ });
1224
1249
  }
1225
- }
1226
- else {
1227
- this.jetLinksList.push({
1228
- topic: `/${productId}/${deviceId}`,
1229
- deviceId,
1230
- properties: [realTime.propertyId],
1231
- });
1232
1250
  }
1233
1251
  }
1234
1252
  if (realTime.bind.class === 'iot') {
@@ -2039,6 +2057,9 @@ export class Meta2d {
2039
2057
  delete(pens, canDelLocked = false, history = true) {
2040
2058
  this.canvas.delete(pens, canDelLocked, history);
2041
2059
  }
2060
+ deleteSync(pens, canDelLocked = false, history = true) {
2061
+ this.canvas.deleteSync(pens, canDelLocked, history);
2062
+ }
2042
2063
  scale(scale, center = { x: 0, y: 0 }) {
2043
2064
  this.canvas.scale(scale, center);
2044
2065
  }
@@ -4348,13 +4369,13 @@ export class Meta2d {
4348
4369
  let left = fit.leftValue;
4349
4370
  let right = fit.rightValue;
4350
4371
  if (left) {
4351
- left = Math.abs(left) < 1 ? left * this.canvas.width : left;
4372
+ left = Math.abs(left) < 1 ? left * rect.width : left;
4352
4373
  }
4353
4374
  else {
4354
4375
  left = 0;
4355
4376
  }
4356
4377
  if (right) {
4357
- right = Math.abs(right) < 1 ? right * this.canvas.width : right;
4378
+ right = Math.abs(right) < 1 ? right * rect.width : right;
4358
4379
  }
4359
4380
  else {
4360
4381
  right = 0;
@@ -4375,11 +4396,20 @@ export class Meta2d {
4375
4396
  }
4376
4397
  });
4377
4398
  }
4378
- pen.calculative.worldRect.x =
4379
- rect.x -
4380
- wGap / 2 +
4381
- left +
4382
- (pen.calculative.worldRect.x - rect.x) * ratio; //(fit.leftValue || 0)+ (pen.calculative.worldRect.x + pen.calculative.worldRect.width/2)-( pen.calculative.worldRect.width*ratio)*(range/2- (fit.rightValue || 0))/(range- (fit.leftValue || 0)-(fit.rightValue || 0));
4399
+ if (Math.abs(fit.leftValue) < 1) {
4400
+ pen.calculative.worldRect.x =
4401
+ rect.x -
4402
+ wGap / 2 +
4403
+ left +
4404
+ (pen.calculative.worldRect.x - rect.x - left) * ratio;
4405
+ }
4406
+ else {
4407
+ pen.calculative.worldRect.x =
4408
+ rect.x -
4409
+ wGap / 2 +
4410
+ left +
4411
+ (pen.calculative.worldRect.x - rect.x) * ratio;
4412
+ }
4383
4413
  pen.calculative.worldRect.width *= ratio;
4384
4414
  pen.calculative.worldRect.ex =
4385
4415
  pen.calculative.worldRect.x + pen.calculative.worldRect.width;