@meta2d/core 1.0.29 → 1.0.31

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
@@ -341,6 +341,11 @@ export declare class Meta2d {
341
341
  * @param pens 本次改变的 pens
342
342
  */
343
343
  initImageCanvas(pens: Pen[]): void;
344
+ /**
345
+ * 模版图元图层改变
346
+ * @param pens 本次改变的 pens
347
+ */
348
+ initTemplateCanvas(pens: Pen[]): void;
344
349
  /**
345
350
  * 该画笔置底,即放到数组最前,最后绘制即在底部
346
351
  * @param pens 画笔们,注意 pen 必须在该数组内才有效
package/src/core.js CHANGED
@@ -347,6 +347,21 @@ var Meta2d = /** @class */ (function () {
347
347
  });
348
348
  Meta2d.prototype.setOptions = function (opts) {
349
349
  if (opts === void 0) { opts = {}; }
350
+ if (opts.grid !== undefined ||
351
+ opts.gridColor !== undefined ||
352
+ opts.gridSize !== undefined) {
353
+ this.setGrid({
354
+ grid: opts.grid,
355
+ gridColor: opts.gridColor,
356
+ gridSize: opts.gridSize,
357
+ });
358
+ }
359
+ if (opts.rule !== undefined || opts.ruleColor !== undefined) {
360
+ this.setRule({
361
+ rule: opts.rule,
362
+ ruleColor: opts.ruleColor,
363
+ });
364
+ }
350
365
  this.store.options = Object.assign(this.store.options, opts);
351
366
  if (this.canvas && opts.scroll !== undefined) {
352
367
  if (opts.scroll) {
@@ -403,7 +418,7 @@ var Meta2d = /** @class */ (function () {
403
418
  // TODO: 若频繁地触发,重复 render 可能带来性能问题,待考虑
404
419
  var value = e.value;
405
420
  if (value && typeof value === 'object') {
406
- var pens = e.params ? _this.find(e.params) : [pen];
421
+ var pens = e.params ? _this.find(e.params) : _this.find(pen.id);
407
422
  pens.forEach(function (pen) {
408
423
  if (value.hasOwnProperty('visible')) {
409
424
  _this.setVisible(pen, value.visible);
@@ -786,11 +801,11 @@ var Meta2d = /** @class */ (function () {
786
801
  width = this.store.data.width || this.store.options.width;
787
802
  height = this.store.data.height || this.store.options.height;
788
803
  if (width && height) {
789
- this.canvas.canvasImageBottom.canvas.style.backgroundImage = null;
804
+ this.canvas.canvasTemplate.canvas.style.backgroundImage = null;
790
805
  this.canvas && (this.canvas.canvasTemplate.bgPatchFlags = true);
791
806
  }
792
807
  else {
793
- this.canvas.canvasImageBottom.canvas.style.backgroundImage = url
808
+ this.canvas.canvasTemplate.canvas.style.backgroundImage = url
794
809
  ? "url('" + url + "')"
795
810
  : '';
796
811
  }
@@ -800,6 +815,12 @@ var Meta2d = /** @class */ (function () {
800
815
  img = _a.sent();
801
816
  // 用作 toPng 的绘制
802
817
  this.store.bkImg = img;
818
+ if (width && height) {
819
+ if (this.canvas) {
820
+ this.canvas.canvasTemplate.init();
821
+ this.render();
822
+ }
823
+ }
803
824
  return [3 /*break*/, 3];
804
825
  case 2:
805
826
  this.store.bkImg = null;
@@ -2937,15 +2958,36 @@ var Meta2d = /** @class */ (function () {
2937
2958
  };
2938
2959
  Meta2d.prototype.clearFormatPainter = function () {
2939
2960
  var _this = this;
2940
- var attrs = {};
2961
+ var pens = this.store.active;
2962
+ var initPens = deepClone(pens);
2941
2963
  formatAttrs.forEach(function (attr) {
2942
- attrs[attr] =
2943
- _this.store.options.defaultFormat[attr] ||
2944
- _this.store.options[attr] ||
2945
- undefined;
2964
+ for (var i = 0; i < pens.length; i++) {
2965
+ var pen = pens[i];
2966
+ var _a = _this.store.options, fontSize = _a.fontSize, lineHeight = _a.lineHeight;
2967
+ if (attr === 'lineWidth') {
2968
+ pen.lineWidth = 1;
2969
+ pen.calculative.lineWidth = 1;
2970
+ }
2971
+ else if (attr === 'fontSize') {
2972
+ pen.fontSize = fontSize;
2973
+ pen.calculative.fontSize = fontSize;
2974
+ }
2975
+ else if (attr === 'lineHeight') {
2976
+ pen.lineHeight = lineHeight;
2977
+ pen.calculative.lineHeight = lineHeight;
2978
+ }
2979
+ else {
2980
+ delete pen[attr];
2981
+ delete pen.calculative[attr];
2982
+ }
2983
+ }
2984
+ });
2985
+ this.render();
2986
+ this.pushHistory({
2987
+ type: EditType.Update,
2988
+ initPens: initPens,
2989
+ pens: pens,
2946
2990
  });
2947
- localStorage.setItem('meta2d-formatPainter', JSON.stringify(attrs));
2948
- this.formatPainter();
2949
2991
  };
2950
2992
  Meta2d.prototype.alignNodes = function (align, pens, rect) {
2951
2993
  var e_8, _a;
@@ -3256,6 +3298,7 @@ var Meta2d = /** @class */ (function () {
3256
3298
  if (index > -1) {
3257
3299
  _pens.push(_pens[index]);
3258
3300
  _pens.splice(index, 1);
3301
+ _this.initTemplateCanvas([pen]);
3259
3302
  _this.initImageCanvas([pen]);
3260
3303
  }
3261
3304
  _this.specificLayerMove(pen, 'top');
@@ -3284,6 +3327,13 @@ var Meta2d = /** @class */ (function () {
3284
3327
  Meta2d.prototype.initImageCanvas = function (pens) {
3285
3328
  this.canvas.initImageCanvas(pens);
3286
3329
  };
3330
+ /**
3331
+ * 模版图元图层改变
3332
+ * @param pens 本次改变的 pens
3333
+ */
3334
+ Meta2d.prototype.initTemplateCanvas = function (pens) {
3335
+ this.canvas.initTemplateCanvas(pens);
3336
+ };
3287
3337
  /**
3288
3338
  * 该画笔置底,即放到数组最前,最后绘制即在底部
3289
3339
  * @param pens 画笔们,注意 pen 必须在该数组内才有效
@@ -3304,6 +3354,7 @@ var Meta2d = /** @class */ (function () {
3304
3354
  if (index > -1) {
3305
3355
  _pens.unshift(_pens[index]);
3306
3356
  _pens.splice(index + 1, 1);
3357
+ this_2.initTemplateCanvas([pen_1]);
3307
3358
  this_2.initImageCanvas([pen_1]);
3308
3359
  }
3309
3360
  this_2.specificLayerMove(pen_1, 'bottom');
@@ -3464,6 +3515,7 @@ var Meta2d = /** @class */ (function () {
3464
3515
  _this.specificLayerMove(_pen, 'up');
3465
3516
  });
3466
3517
  _pens.splice.apply(_pens, __spreadArray([lastIndex_1 + 1, 0], __read(orderPens), false));
3518
+ this_4.initTemplateCanvas(orderPens);
3467
3519
  this_4.initImageCanvas(orderPens);
3468
3520
  }
3469
3521
  else {
@@ -3471,6 +3523,7 @@ var Meta2d = /** @class */ (function () {
3471
3523
  if (index > -1 && index !== _pens.length - 1) {
3472
3524
  _pens.splice(index + 2, 0, _pens[index]);
3473
3525
  _pens.splice(index, 1);
3526
+ this_4.initTemplateCanvas([pen]);
3474
3527
  this_4.initImageCanvas([pen]);
3475
3528
  }
3476
3529
  this_4.specificLayerMove(pen, 'up');
@@ -3532,6 +3585,7 @@ var Meta2d = /** @class */ (function () {
3532
3585
  _this.specificLayerMove(_pen, 'down');
3533
3586
  });
3534
3587
  _pens.splice.apply(_pens, __spreadArray([firstIndex_1 - 1, 0], __read(orderPens), false));
3588
+ this_5.initTemplateCanvas(orderPens);
3535
3589
  this_5.initImageCanvas(orderPens);
3536
3590
  }
3537
3591
  else {
@@ -3539,6 +3593,7 @@ var Meta2d = /** @class */ (function () {
3539
3593
  if (index > -1 && index !== 0) {
3540
3594
  _pens.splice(index - 1, 0, _pens[index]);
3541
3595
  _pens.splice(index + 1, 1);
3596
+ this_5.initTemplateCanvas([pen]);
3542
3597
  this_5.initImageCanvas([pen]);
3543
3598
  }
3544
3599
  this_5.specificLayerMove(pen, 'down');