watermark-js-plus 0.9.9 → 0.9.11

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/dist/index.cjs.js CHANGED
@@ -444,6 +444,31 @@ var bootstrap = (function () {
444
444
  }
445
445
  });
446
446
 
447
+ // import { WatermarkOptions } from '../types'
448
+ var WatermarkCanvas = /** @class */ (function () {
449
+ function WatermarkCanvas() {
450
+ }
451
+ // constructor (args: Partial<WatermarkOptions> = {}) {
452
+ // }
453
+ /**
454
+ * Create an HD canvas.
455
+ * @param width - width of canvas
456
+ * @param height - height of canvas
457
+ */
458
+ WatermarkCanvas.createCanvas = function (width, height) {
459
+ var _a;
460
+ var ratio = window.devicePixelRatio || 1;
461
+ var canvas = document.createElement('canvas');
462
+ canvas.width = width * ratio; // actual rendered pixel
463
+ canvas.height = height * ratio; // actual rendered pixel
464
+ canvas.style.width = "".concat(width, "px"); // control display size
465
+ canvas.style.height = "".concat(height, "px"); // control display size
466
+ (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.setTransform(ratio, 0, 0, ratio, 0, 0);
467
+ return canvas;
468
+ };
469
+ return WatermarkCanvas;
470
+ }());
471
+
447
472
  var GridLayout = /** @class */ (function () {
448
473
  function GridLayout(args, partialCanvas) {
449
474
  var _a, _b, _c, _d;
@@ -458,7 +483,7 @@ var GridLayout = /** @class */ (function () {
458
483
  }
459
484
  GridLayout.prototype.draw = function () {
460
485
  var _a, _b;
461
- var layoutCanvas = Watermark.createCanvas(this.partialWidth * this.cols + this.gap[0] * this.cols, this.partialHeight * this.rows + this.gap[1] * this.rows);
486
+ var layoutCanvas = WatermarkCanvas.createCanvas(this.partialWidth * this.cols + this.gap[0] * this.cols, this.partialHeight * this.rows + this.gap[1] * this.rows);
462
487
  var layoutContext = layoutCanvas.getContext('2d');
463
488
  for (var rowIndex = 0; rowIndex < this.rows; rowIndex++) {
464
489
  for (var colIndex = 0; colIndex < this.cols; colIndex++) {
@@ -516,26 +541,10 @@ var Watermark = /** @class */ (function () {
516
541
  this.props = args;
517
542
  this.options = Object.assign({}, initialOptions, args);
518
543
  this.changeParentElement(this.options.parent);
519
- this.canvas = Watermark.createCanvas(this.options.width, this.options.height);
544
+ this.canvas = WatermarkCanvas.createCanvas(this.options.width, this.options.height);
520
545
  this.recommendOptions = generateRecommendOptions(this.canvas, this.options, this.props);
521
546
  bootstrap();
522
547
  }
523
- /**
524
- * Create an HD canvas.
525
- * @param width - width of canvas
526
- * @param height - height of canvas
527
- */
528
- Watermark.createCanvas = function (width, height) {
529
- var _a;
530
- var ratio = window.devicePixelRatio || 1;
531
- var canvas = document.createElement('canvas');
532
- canvas.width = width * ratio; // actual rendered pixel
533
- canvas.height = height * ratio; // actual rendered pixel
534
- canvas.style.width = "".concat(width, "px"); // control display size
535
- canvas.style.height = "".concat(height, "px"); // control display size
536
- (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.setTransform(ratio, 0, 0, ratio, 0, 0);
537
- return canvas;
538
- };
539
548
  Watermark.prototype.changeOptions = function (args, mode) {
540
549
  if (args === void 0) { args = {}; }
541
550
  if (mode === void 0) { mode = 'overwrite'; }
@@ -592,15 +601,8 @@ var Watermark = /** @class */ (function () {
592
601
  * Delete this watermark.
593
602
  */
594
603
  Watermark.prototype.destroy = function () {
595
- var _a, _b, _c, _d, _e, _f, _g;
596
- (_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
597
- (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
598
- (_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
599
- if (!isUndefined(this.checkWatermarkElementRequestID)) {
600
- cancelAnimationFrame(this.checkWatermarkElementRequestID);
601
- }
602
- (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.remove();
603
- (_g = (_f = this.options).onDestroyed) === null || _g === void 0 ? void 0 : _g.call(_f);
604
+ this.remove();
605
+ this.watermarkDom = undefined;
604
606
  };
605
607
  Watermark.prototype.check = function () {
606
608
  return __awaiter(this, void 0, void 0, function () {
@@ -608,7 +610,7 @@ var Watermark = /** @class */ (function () {
608
610
  switch (_a.label) {
609
611
  case 0:
610
612
  if (!!document.body.contains(this.watermarkDom)) return [3 /*break*/, 2];
611
- this.destroy();
613
+ this.remove();
612
614
  return [4 /*yield*/, this.create()];
613
615
  case 1:
614
616
  _a.sent();
@@ -618,6 +620,17 @@ var Watermark = /** @class */ (function () {
618
620
  });
619
621
  });
620
622
  };
623
+ Watermark.prototype.remove = function () {
624
+ var _a, _b, _c, _d, _e, _f, _g;
625
+ (_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
626
+ (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
627
+ (_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
628
+ if (!isUndefined(this.checkWatermarkElementRequestID)) {
629
+ cancelAnimationFrame(this.checkWatermarkElementRequestID);
630
+ }
631
+ (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.remove();
632
+ (_g = (_f = this.options).onDestroyed) === null || _g === void 0 ? void 0 : _g.call(_f);
633
+ };
621
634
  Watermark.prototype.initConfigData = function (args, mode) {
622
635
  var _this = this;
623
636
  if (mode === void 0) { mode = 'overwrite'; }
@@ -631,7 +644,7 @@ var Watermark = /** @class */ (function () {
631
644
  });
632
645
  }
633
646
  this.changeParentElement(this.options.parent);
634
- this.canvas = Watermark.createCanvas(this.options.width, this.options.height);
647
+ this.canvas = WatermarkCanvas.createCanvas(this.options.width, this.options.height);
635
648
  this.recommendOptions = generateRecommendOptions(this.canvas, this.options, this.props);
636
649
  // document.body?.appendChild(this.canvas)
637
650
  };
@@ -907,7 +920,7 @@ var Watermark = /** @class */ (function () {
907
920
  switch (_a.label) {
908
921
  case 0:
909
922
  if (!!document.body.contains(this.watermarkDom)) return [3 /*break*/, 2];
910
- this.destroy();
923
+ this.remove();
911
924
  return [4 /*yield*/, this.create()];
912
925
  case 1:
913
926
  _a.sent();
@@ -930,7 +943,7 @@ var Watermark = /** @class */ (function () {
930
943
  switch (_a.label) {
931
944
  case 0:
932
945
  if (!(mutationsList.length > 0)) return [3 /*break*/, 2];
933
- this.destroy();
946
+ this.remove();
934
947
  return [4 /*yield*/, this.create()];
935
948
  case 1:
936
949
  _a.sent();
@@ -959,7 +972,7 @@ var Watermark = /** @class */ (function () {
959
972
  if (!((item === null || item === void 0 ? void 0 : item.target) === this.watermarkDom ||
960
973
  ((_a = item === null || item === void 0 ? void 0 : item.removedNodes) === null || _a === void 0 ? void 0 : _a[0]) === this.watermarkDom ||
961
974
  (item.type === 'childList' && item.target === this.parentElement && item.target.lastChild !== this.watermarkDom))) return [3 /*break*/, 3];
962
- this.destroy();
975
+ this.remove();
963
976
  return [4 /*yield*/, this.create()];
964
977
  case 2:
965
978
  _b.sent();
@@ -1025,7 +1038,7 @@ var BlindWatermark = /** @class */ (function (_super) {
1025
1038
  img_1.onload = function () {
1026
1039
  var _a;
1027
1040
  var width = img_1.width, height = img_1.height;
1028
- var canvas = Watermark.createCanvas(width, height);
1041
+ var canvas = WatermarkCanvas.createCanvas(width, height);
1029
1042
  var ctx = canvas.getContext('2d');
1030
1043
  if (ctx === null) {
1031
1044
  throw new Error('get context error');