watermark-js-plus 0.11.2 → 0.12.0

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
@@ -181,7 +181,7 @@ var initialOptions = {
181
181
  imageHeight: 0,
182
182
  lineHeight: 30,
183
183
  zIndex: 2147483647,
184
- backgroundPosition: '0 0, 0 0',
184
+ backgroundPosition: '0 0',
185
185
  backgroundRepeat: 'repeat',
186
186
  fontSize: '20px',
187
187
  fontFamily: 'sans-serif',
@@ -193,7 +193,7 @@ var initialOptions = {
193
193
  globalAlpha: 0.5,
194
194
  mode: 'default',
195
195
  mutationObserve: true,
196
- unique: true,
196
+ movable: false,
197
197
  parent: 'body',
198
198
  onSuccess: function () { },
199
199
  onBeforeDestroy: function () { },
@@ -837,7 +837,7 @@ var Watermark = /** @class */ (function () {
837
837
  parentElementType = this.checkParentElementType();
838
838
  this.watermarkDom.style.cssText = "\n z-index: ".concat(this.options.zIndex, "!important;display:block!important;visibility:visible!important;transform:none!important;scale:none!important;\n ").concat(parentElementType === 'custom' ? 'top:0!important;bottom:0!important;left:0!important;right:0!important;height:100%!important;pointer-events:none!important;position:absolute!important;' : 'position:relative!important;', "\n ");
839
839
  backgroundSize = generateBackgroundSize(this.options);
840
- watermarkInnerDom.style.cssText = "\n display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;\n position:".concat(parentElementType === 'root' ? 'fixed' : 'absolute', "!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;\n z-index:").concat(this.options.zIndex, "!important;background-image:url(").concat(image, ")!important;background-repeat:").concat(this.options.backgroundRepeat, "!important;\n background-size:").concat(backgroundSize[0], "px ").concat(backgroundSize[1], "px!important;background-position:").concat(this.options.backgroundPosition, "!important;\n ");
840
+ watermarkInnerDom.style.cssText = "\n display:block!important;visibility:visible!important;pointer-events:none;top:0;bottom:0;left:0;right:0;transform:none!important;scale:none!important;\n position:".concat(parentElementType === 'root' ? 'fixed' : 'absolute', "!important;-webkit-print-color-adjust:exact!important;width:100%!important;height:100%!important;\n z-index:").concat(this.options.zIndex, "!important;background-image:url(").concat(image, ")!important;background-repeat:").concat(this.options.backgroundRepeat, "!important;\n background-size:").concat(backgroundSize[0], "px ").concat(backgroundSize[1], "px!important;background-position:").concat(this.options.backgroundPosition, ";\n ").concat(this.options.movable ? 'animation: 200s ease 0s infinite normal none running watermark !important;' : '', "\n ");
841
841
  this.watermarkDom.append(watermarkInnerDom);
842
842
  this.parentElement.appendChild(this.watermarkDom);
843
843
  if (this.options.mutationObserve) {
@@ -882,9 +882,7 @@ var Watermark = /** @class */ (function () {
882
882
  (_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
883
883
  (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
884
884
  (_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
885
- if (!isUndefined(this.checkWatermarkElementRequestID)) {
886
- cancelAnimationFrame(this.checkWatermarkElementRequestID);
887
- }
885
+ this.unbindCheckWatermarkElementEvent();
888
886
  (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.remove();
889
887
  (_g = (_f = this.options).onDestroyed) === null || _g === void 0 ? void 0 : _g.call(_f);
890
888
  };
@@ -914,17 +912,15 @@ var Watermark = /** @class */ (function () {
914
912
  };
915
913
  Watermark.prototype.validateUnique = function () {
916
914
  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
- }
915
+ this.parentElement.childNodes.forEach(function (node) {
916
+ if (!result) {
917
+ return;
918
+ }
919
+ if (Object.hasOwnProperty.call(node, '__WATERMARK__')) {
920
+ result = false;
921
+ // throw new Error('duplicate watermark error')
922
+ }
923
+ });
928
924
  return result;
929
925
  };
930
926
  Watermark.prototype.validateContent = function () {
@@ -956,7 +952,7 @@ var Watermark = /** @class */ (function () {
956
952
  _a.sent();
957
953
  _a.label = 2;
958
954
  case 2:
959
- this.checkWatermarkElementRequestID = requestAnimationFrame(this.checkWatermarkElement.bind(this));
955
+ this.bindCheckWatermarkElementEvent();
960
956
  return [2 /*return*/];
961
957
  }
962
958
  });
@@ -967,7 +963,7 @@ var Watermark = /** @class */ (function () {
967
963
  if (!this.watermarkDom) {
968
964
  return;
969
965
  }
970
- this.checkWatermarkElementRequestID = requestAnimationFrame(this.checkWatermarkElement.bind(this));
966
+ this.bindCheckWatermarkElementEvent();
971
967
  this.observer = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
972
968
  return __generator(this, function (_a) {
973
969
  switch (_a.label) {
@@ -1001,7 +997,7 @@ var Watermark = /** @class */ (function () {
1001
997
  item = mutationsList_1[_i];
1002
998
  if (!((item === null || item === void 0 ? void 0 : item.target) === this.watermarkDom ||
1003
999
  ((_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];
1000
+ (item.type === 'childList' && item.target === this.parentElement && item.target.lastChild !== this.watermarkDom))) return [3 /*break*/, 3];
1005
1001
  this.remove();
1006
1002
  return [4 /*yield*/, this.create()];
1007
1003
  case 2:
@@ -1021,6 +1017,15 @@ var Watermark = /** @class */ (function () {
1021
1017
  characterData: true // 节点内容或节点文本的变动。
1022
1018
  });
1023
1019
  };
1020
+ Watermark.prototype.bindCheckWatermarkElementEvent = function () {
1021
+ this.unbindCheckWatermarkElementEvent();
1022
+ this.checkWatermarkElementRequestID = requestAnimationFrame(this.checkWatermarkElement.bind(this));
1023
+ };
1024
+ Watermark.prototype.unbindCheckWatermarkElementEvent = function () {
1025
+ if (!isUndefined(this.checkWatermarkElementRequestID)) {
1026
+ cancelAnimationFrame(this.checkWatermarkElementRequestID);
1027
+ }
1028
+ };
1024
1029
  return Watermark;
1025
1030
  }());
1026
1031
 
@@ -1131,6 +1136,36 @@ var ImageWatermark = /** @class */ (function () {
1131
1136
  return ImageWatermark;
1132
1137
  }());
1133
1138
 
1139
+ function styleInject(css, ref) {
1140
+ if ( ref === void 0 ) ref = {};
1141
+ var insertAt = ref.insertAt;
1142
+
1143
+ if (!css || typeof document === 'undefined') { return; }
1144
+
1145
+ var head = document.head || document.getElementsByTagName('head')[0];
1146
+ var style = document.createElement('style');
1147
+ style.type = 'text/css';
1148
+
1149
+ if (insertAt === 'top') {
1150
+ if (head.firstChild) {
1151
+ head.insertBefore(style, head.firstChild);
1152
+ } else {
1153
+ head.appendChild(style);
1154
+ }
1155
+ } else {
1156
+ head.appendChild(style);
1157
+ }
1158
+
1159
+ if (style.styleSheet) {
1160
+ style.styleSheet.cssText = css;
1161
+ } else {
1162
+ style.appendChild(document.createTextNode(css));
1163
+ }
1164
+ }
1165
+
1166
+ var css_248z = "@keyframes watermark{0%{background-position:0 0}25%{background-position:100% 100%}50%{background-position:0 0}75%{background-position:100% -100%}to{background-position:0 0}}";
1167
+ styleInject(css_248z);
1168
+
1134
1169
  exports.BlindWatermark = BlindWatermark;
1135
1170
  exports.ImageWatermark = ImageWatermark;
1136
1171
  exports.Watermark = Watermark;