watermark-js-plus 0.11.2 → 0.11.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/dist/index.cjs.js CHANGED
@@ -193,7 +193,6 @@ var initialOptions = {
193
193
  globalAlpha: 0.5,
194
194
  mode: 'default',
195
195
  mutationObserve: true,
196
- unique: true,
197
196
  parent: 'body',
198
197
  onSuccess: function () { },
199
198
  onBeforeDestroy: function () { },
@@ -882,9 +881,7 @@ var Watermark = /** @class */ (function () {
882
881
  (_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
883
882
  (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
884
883
  (_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
885
- if (!isUndefined(this.checkWatermarkElementRequestID)) {
886
- cancelAnimationFrame(this.checkWatermarkElementRequestID);
887
- }
884
+ this.unbindCheckWatermarkElementEvent();
888
885
  (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.remove();
889
886
  (_g = (_f = this.options).onDestroyed) === null || _g === void 0 ? void 0 : _g.call(_f);
890
887
  };
@@ -914,17 +911,15 @@ var Watermark = /** @class */ (function () {
914
911
  };
915
912
  Watermark.prototype.validateUnique = function () {
916
913
  var result = true;
917
- if (this.options.unique) {
918
- this.parentElement.childNodes.forEach(function (node) {
919
- if (!result) {
920
- return;
921
- }
922
- if (Object.hasOwnProperty.call(node, '__WATERMARK__')) {
923
- result = false;
924
- // throw new Error('duplicate watermark error')
925
- }
926
- });
927
- }
914
+ this.parentElement.childNodes.forEach(function (node) {
915
+ if (!result) {
916
+ return;
917
+ }
918
+ if (Object.hasOwnProperty.call(node, '__WATERMARK__')) {
919
+ result = false;
920
+ // throw new Error('duplicate watermark error')
921
+ }
922
+ });
928
923
  return result;
929
924
  };
930
925
  Watermark.prototype.validateContent = function () {
@@ -956,7 +951,7 @@ var Watermark = /** @class */ (function () {
956
951
  _a.sent();
957
952
  _a.label = 2;
958
953
  case 2:
959
- this.checkWatermarkElementRequestID = requestAnimationFrame(this.checkWatermarkElement.bind(this));
954
+ this.bindCheckWatermarkElementEvent();
960
955
  return [2 /*return*/];
961
956
  }
962
957
  });
@@ -967,7 +962,7 @@ var Watermark = /** @class */ (function () {
967
962
  if (!this.watermarkDom) {
968
963
  return;
969
964
  }
970
- this.checkWatermarkElementRequestID = requestAnimationFrame(this.checkWatermarkElement.bind(this));
965
+ this.bindCheckWatermarkElementEvent();
971
966
  this.observer = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
972
967
  return __generator(this, function (_a) {
973
968
  switch (_a.label) {
@@ -1001,7 +996,7 @@ var Watermark = /** @class */ (function () {
1001
996
  item = mutationsList_1[_i];
1002
997
  if (!((item === null || item === void 0 ? void 0 : item.target) === this.watermarkDom ||
1003
998
  ((_a = item === null || item === void 0 ? void 0 : item.removedNodes) === null || _a === void 0 ? void 0 : _a[0]) === this.watermarkDom ||
1004
- (item.type === 'childList' && item.target === this.parentElement && (this.options.unique ? (item.target.lastChild !== this.watermarkDom) : false)))) return [3 /*break*/, 3];
999
+ (item.type === 'childList' && item.target === this.parentElement && item.target.lastChild !== this.watermarkDom))) return [3 /*break*/, 3];
1005
1000
  this.remove();
1006
1001
  return [4 /*yield*/, this.create()];
1007
1002
  case 2:
@@ -1021,6 +1016,15 @@ var Watermark = /** @class */ (function () {
1021
1016
  characterData: true // 节点内容或节点文本的变动。
1022
1017
  });
1023
1018
  };
1019
+ Watermark.prototype.bindCheckWatermarkElementEvent = function () {
1020
+ this.unbindCheckWatermarkElementEvent();
1021
+ this.checkWatermarkElementRequestID = requestAnimationFrame(this.checkWatermarkElement.bind(this));
1022
+ };
1023
+ Watermark.prototype.unbindCheckWatermarkElementEvent = function () {
1024
+ if (!isUndefined(this.checkWatermarkElementRequestID)) {
1025
+ cancelAnimationFrame(this.checkWatermarkElementRequestID);
1026
+ }
1027
+ };
1024
1028
  return Watermark;
1025
1029
  }());
1026
1030