@meta2d/core 1.1.1 → 1.1.2

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
@@ -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
@@ -862,6 +862,9 @@ export class Meta2d {
862
862
  async addPen(pen, history, emit = true, abs = false) {
863
863
  return await this.canvas.addPen(pen, history, emit, abs);
864
864
  }
865
+ addPenSync(pen, history, emit = true, abs = false) {
866
+ return this.canvas.addPenSync(pen, history, emit, abs);
867
+ }
865
868
  async addPens(pens, history, abs = false) {
866
869
  return await this.canvas.addPens(pens, history, abs);
867
870
  }
@@ -1180,33 +1183,36 @@ export class Meta2d {
1180
1183
  // key: realTime.key,
1181
1184
  // });
1182
1185
  //JetLinks
1186
+ const Jet = this.store.data.networks?.some((item) => item.protocol === 'ADIIOT');
1183
1187
  let productId = realTime.productId || pen.productId;
1184
1188
  let deviceId = realTime.deviceId || pen.deviceId;
1185
1189
  let propertyId = realTime.propertyId;
1186
1190
  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;
1191
+ if (Jet) {
1192
+ if (productId && typeof productId === 'string' && productId.indexOf('${') > -1) {
1193
+ let keys = productId.match(/(?<=\$\{).*?(?=\})/g);
1194
+ if (keys?.length) {
1195
+ productId = this.getDynamicParam(keys[0]) || productId;
1196
+ }
1197
+ flag = true;
1191
1198
  }
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;
1199
+ if (deviceId && typeof deviceId === 'string' && deviceId.indexOf('${') > -1) {
1200
+ let keys = deviceId.match(/(?<=\$\{).*?(?=\})/g);
1201
+ if (keys?.length) {
1202
+ deviceId = this.getDynamicParam(keys[0]) || deviceId;
1203
+ }
1204
+ flag = true;
1198
1205
  }
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;
1206
+ if (propertyId && typeof propertyId === 'string' && propertyId.indexOf('${') > -1) {
1207
+ let keys = propertyId.match(/(?<=\$\{).*?(?=\})/g);
1208
+ if (keys?.length) {
1209
+ propertyId = this.getDynamicParam(keys[0]) || propertyId;
1210
+ }
1211
+ flag = true;
1212
+ }
1213
+ if (flag) {
1214
+ realTime.bind && (realTime.bind.id = productId + '#' + deviceId + '#' + propertyId);
1205
1215
  }
1206
- flag = true;
1207
- }
1208
- if (flag) {
1209
- realTime.bind && (realTime.bind.id = productId + '#' + deviceId + '#' + propertyId);
1210
1216
  }
1211
1217
  if (!this.store.bind[realTime.bind.id]) {
1212
1218
  this.store.bind[realTime.bind.id] = [];
@@ -1215,20 +1221,22 @@ export class Meta2d {
1215
1221
  id: pen.id,
1216
1222
  key: realTime.key,
1217
1223
  });
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);
1224
+ if (Jet) {
1225
+ if (productId && deviceId && propertyId) {
1226
+ const index = this.jetLinksList.findIndex((item) => item.topic.startsWith(`/${productId}/${deviceId}`));
1227
+ if (index > -1) {
1228
+ const properties = this.jetLinksList[index].properties;
1229
+ if (!properties.includes(realTime.propertyId)) {
1230
+ this.jetLinksList[index].properties.push(realTime.propertyId);
1231
+ }
1232
+ }
1233
+ else {
1234
+ this.jetLinksList.push({
1235
+ topic: `/${productId}/${deviceId}`,
1236
+ deviceId,
1237
+ properties: [realTime.propertyId],
1238
+ });
1224
1239
  }
1225
- }
1226
- else {
1227
- this.jetLinksList.push({
1228
- topic: `/${productId}/${deviceId}`,
1229
- deviceId,
1230
- properties: [realTime.propertyId],
1231
- });
1232
1240
  }
1233
1241
  }
1234
1242
  if (realTime.bind.class === 'iot') {
@@ -2039,6 +2047,9 @@ export class Meta2d {
2039
2047
  delete(pens, canDelLocked = false, history = true) {
2040
2048
  this.canvas.delete(pens, canDelLocked, history);
2041
2049
  }
2050
+ deleteSync(pens, canDelLocked = false, history = true) {
2051
+ this.canvas.deleteSync(pens, canDelLocked, history);
2052
+ }
2042
2053
  scale(scale, center = { x: 0, y: 0 }) {
2043
2054
  this.canvas.scale(scale, center);
2044
2055
  }
@@ -4348,13 +4359,13 @@ export class Meta2d {
4348
4359
  let left = fit.leftValue;
4349
4360
  let right = fit.rightValue;
4350
4361
  if (left) {
4351
- left = Math.abs(left) < 1 ? left * this.canvas.width : left;
4362
+ left = Math.abs(left) < 1 ? left * rect.width : left;
4352
4363
  }
4353
4364
  else {
4354
4365
  left = 0;
4355
4366
  }
4356
4367
  if (right) {
4357
- right = Math.abs(right) < 1 ? right * this.canvas.width : right;
4368
+ right = Math.abs(right) < 1 ? right * rect.width : right;
4358
4369
  }
4359
4370
  else {
4360
4371
  right = 0;
@@ -4375,11 +4386,20 @@ export class Meta2d {
4375
4386
  }
4376
4387
  });
4377
4388
  }
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));
4389
+ if (Math.abs(fit.leftValue) < 1) {
4390
+ pen.calculative.worldRect.x =
4391
+ rect.x -
4392
+ wGap / 2 +
4393
+ left +
4394
+ (pen.calculative.worldRect.x - rect.x - left) * ratio;
4395
+ }
4396
+ else {
4397
+ pen.calculative.worldRect.x =
4398
+ rect.x -
4399
+ wGap / 2 +
4400
+ left +
4401
+ (pen.calculative.worldRect.x - rect.x) * ratio;
4402
+ }
4383
4403
  pen.calculative.worldRect.width *= ratio;
4384
4404
  pen.calculative.worldRect.ex =
4385
4405
  pen.calculative.worldRect.x + pen.calculative.worldRect.width;