@meta2d/core 1.0.32 → 1.0.33

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
@@ -232,14 +232,14 @@ export declare class Meta2d {
232
232
  judgeCondition(pen: Pen, key: string, condition: TriggerCondition): boolean;
233
233
  pushChildren(parent: Pen, children: Pen[]): void;
234
234
  renderPenRaw: typeof renderPenRaw;
235
- toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean): string;
235
+ toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
236
236
  activeToPng(padding?: Padding): string;
237
237
  /**
238
238
  * 下载 png
239
239
  * @param name 传入参数自带文件后缀名 例如:'test.png'
240
240
  * @param padding 上右下左的内边距
241
241
  */
242
- downloadPng(name?: string, padding?: Padding): void;
242
+ downloadPng(name?: string, padding?: Padding, maxWidth?: number): void;
243
243
  downloadSvg(): void;
244
244
  getRect(pens?: Pen[]): Rect;
245
245
  hiddenTemplate(): void;
package/src/core.js CHANGED
@@ -97,6 +97,7 @@ import { lockedError } from './utils/error';
97
97
  import { Scroll } from './scroll';
98
98
  import { getter } from './utils/object';
99
99
  import { queryURLParams } from './utils/url';
100
+ import { HotkeyType } from './data';
100
101
  var Meta2d = /** @class */ (function () {
101
102
  function Meta2d(parent, opts) {
102
103
  var _this = this;
@@ -186,11 +187,32 @@ var Meta2d = /** @class */ (function () {
186
187
  (_a = pen.events) === null || _a === void 0 ? void 0 : _a.forEach(function (event) {
187
188
  var _a;
188
189
  if (event.actions && event.actions.length) {
189
- event.actions.forEach(function (action) {
190
- if (_this.events[action.action] && event.name === eventName) {
191
- _this.events[action.action](pen, action);
190
+ if (event.name === eventName) {
191
+ //条件成立
192
+ var flag = false;
193
+ if (event.conditions && event.conditions.length) {
194
+ if (event.conditionType === 'and') {
195
+ flag = event.conditions.every(function (condition) {
196
+ return _this.judgeCondition(pen, condition.key, condition);
197
+ });
198
+ }
199
+ else if (event.conditionType === 'or') {
200
+ flag = event.conditions.some(function (condition) {
201
+ return _this.judgeCondition(pen, condition.key, condition);
202
+ });
203
+ }
192
204
  }
193
- });
205
+ else {
206
+ flag = true;
207
+ }
208
+ if (flag) {
209
+ event.actions.forEach(function (action) {
210
+ if (_this.events[action.action]) {
211
+ _this.events[action.action](pen, action);
212
+ }
213
+ });
214
+ }
215
+ }
194
216
  }
195
217
  else {
196
218
  if (_this.events[event.action] && event.name === eventName) {
@@ -362,6 +384,11 @@ var Meta2d = /** @class */ (function () {
362
384
  ruleColor: opts.ruleColor,
363
385
  });
364
386
  }
387
+ if (opts.resizeMode !== undefined) {
388
+ if (!opts.resizeMode) {
389
+ this.canvas.hotkeyType = HotkeyType.None;
390
+ }
391
+ }
365
392
  this.store.options = Object.assign(this.store.options, opts);
366
393
  if (this.canvas && opts.scroll !== undefined) {
367
394
  if (opts.scroll) {
@@ -623,7 +650,7 @@ var Meta2d = /** @class */ (function () {
623
650
  window.location.href = arr[0] + 'id=' + id;
624
651
  }
625
652
  else {
626
- window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx + 1);
653
+ window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx);
627
654
  }
628
655
  }
629
656
  };
@@ -2495,9 +2522,9 @@ var Meta2d = /** @class */ (function () {
2495
2522
  step: step,
2496
2523
  });
2497
2524
  };
2498
- Meta2d.prototype.toPng = function (padding, callback, containBkImg) {
2525
+ Meta2d.prototype.toPng = function (padding, callback, containBkImg, maxWidth) {
2499
2526
  if (containBkImg === void 0) { containBkImg = false; }
2500
- return this.canvas.toPng(padding, callback, containBkImg);
2527
+ return this.canvas.toPng(padding, callback, containBkImg, maxWidth);
2501
2528
  };
2502
2529
  Meta2d.prototype.activeToPng = function (padding) {
2503
2530
  return this.canvas.activeToPng(padding);
@@ -2507,7 +2534,7 @@ var Meta2d = /** @class */ (function () {
2507
2534
  * @param name 传入参数自带文件后缀名 例如:'test.png'
2508
2535
  * @param padding 上右下左的内边距
2509
2536
  */
2510
- Meta2d.prototype.downloadPng = function (name, padding) {
2537
+ Meta2d.prototype.downloadPng = function (name, padding, maxWidth) {
2511
2538
  var e_6, _a;
2512
2539
  var _this = this;
2513
2540
  var _b;
@@ -2530,7 +2557,7 @@ var Meta2d = /** @class */ (function () {
2530
2557
  setTimeout(function () {
2531
2558
  var a = document.createElement('a');
2532
2559
  a.setAttribute('download', (name || _this.store.data.name || 'le5le.meta2d') + '.png');
2533
- a.setAttribute('href', _this.toPng(padding, undefined, true));
2560
+ a.setAttribute('href', _this.toPng(padding, undefined, true, maxWidth));
2534
2561
  var evt = document.createEvent('MouseEvents');
2535
2562
  evt.initEvent('click', true, true);
2536
2563
  a.dispatchEvent(evt);