watermark-js-plus 1.5.2 → 1.5.4

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.
Files changed (47) hide show
  1. package/dist/ie/index.cjs.js +4461 -0
  2. package/dist/ie/index.cjs.js.map +1 -0
  3. package/dist/ie/index.cjs.min.js +1 -0
  4. package/dist/ie/index.esm.js +4457 -0
  5. package/dist/ie/index.esm.js.map +1 -0
  6. package/dist/ie/index.esm.min.js +1 -0
  7. package/dist/ie/index.iife.js +4466 -0
  8. package/dist/ie/index.iife.js.map +1 -0
  9. package/dist/ie/index.iife.min.js +1 -0
  10. package/dist/ie/index.umd.js +4467 -0
  11. package/dist/ie/index.umd.js.map +1 -0
  12. package/dist/ie/index.umd.min.js +1 -0
  13. package/dist/ie/types/src/core/blind.d.ts +18 -0
  14. package/dist/ie/types/src/core/canvas.d.ts +51 -0
  15. package/dist/ie/types/src/core/image.d.ts +22 -0
  16. package/dist/ie/types/src/core/layout/grid.d.ts +14 -0
  17. package/dist/ie/types/src/core/layout/index.d.ts +4 -0
  18. package/dist/ie/types/src/core/watermark.d.ts +48 -0
  19. package/dist/ie/types/src/index.d.ts +5 -0
  20. package/dist/ie/types/src/index.ie.d.ts +6 -0
  21. package/dist/ie/types/src/style/index.d.ts +1 -0
  22. package/dist/ie/types/src/types/index.d.ts +127 -0
  23. package/dist/ie/types/src/utils/bootstrap.d.ts +2 -0
  24. package/dist/ie/types/src/utils/index.d.ts +14 -0
  25. package/dist/ie/types/src/utils/initialization.d.ts +19 -0
  26. package/dist/ie/types/tests/core/blind.test.d.ts +1 -0
  27. package/dist/ie/types/tests/core/image.test.d.ts +1 -0
  28. package/dist/ie/types/tests/core/watermark.test.d.ts +1 -0
  29. package/dist/ie/types/tests/utils/index.d.ts +1 -0
  30. package/dist/ie/types/tests/utils/index.test.d.ts +1 -0
  31. package/dist/index.cjs.js +33 -12
  32. package/dist/index.cjs.js.map +1 -1
  33. package/dist/index.cjs.min.js +1 -1
  34. package/dist/index.esm.js +33 -12
  35. package/dist/index.esm.js.map +1 -1
  36. package/dist/index.esm.min.js +1 -1
  37. package/dist/index.iife.js +33 -12
  38. package/dist/index.iife.js.map +1 -1
  39. package/dist/index.iife.min.js +1 -1
  40. package/dist/index.umd.js +33 -12
  41. package/dist/index.umd.js.map +1 -1
  42. package/dist/index.umd.min.js +1 -1
  43. package/dist/types/src/core/watermark.d.ts +1 -0
  44. package/dist/types/src/index.ie.d.ts +6 -0
  45. package/package.json +35 -26
  46. package/dist/types/docs/components/config.d.ts +0 -72
  47. package/dist/types/jest.setup.d.ts +0 -1
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * watermark-js-plus v1.5.2
2
+ * watermark-js-plus v1.5.4
3
3
  * (c) 2022-2024 Michael Sun
4
4
  * Released under the MIT License.
5
5
  */
@@ -139,8 +139,15 @@ var createSVGElement = function (tagName, attrs, namespaceURI) {
139
139
  var getMultiLineData = function (ctx, text, maxWidth) {
140
140
  var result = [];
141
141
  var str = '';
142
+ var word = '';
142
143
  for (var i = 0, len = text.length; i < len; i++) {
143
- str += text.charAt(i);
144
+ word = text.charAt(i);
145
+ if (word === '\n') {
146
+ result.push(str);
147
+ str = '';
148
+ continue;
149
+ }
150
+ str += word;
144
151
  if (ctx.measureText(str).width > maxWidth) {
145
152
  result.push(str.substring(0, str.length - 1));
146
153
  str = '';
@@ -252,7 +259,10 @@ function convertImgToBase64(bodyElement) {
252
259
  });
253
260
  }
254
261
  var convertSVGToImage = function (svg) {
255
- var richContent = svg.outerHTML.replace(/<img(.*?)>/g, '<img$1/>').replace(/\n/g, '').replace(/\t/g, '').replace(/#/g, '%23');
262
+ var richContent = svg.outerHTML
263
+ .replace(/<(img|br|input|hr|embed)(.*?)>/g, '<$1$2/>')
264
+ .replace(/\n/g, '').replace(/\t/g, '')
265
+ .replace(/#/g, '%23');
256
266
  return "data:image/svg+xml;charset=utf-8,".concat(richContent);
257
267
  };
258
268
  var getValue = function (v1, v2) {
@@ -767,7 +777,7 @@ var WatermarkCanvas = /** @class */ (function () {
767
777
  var lines = this.recommendOptions.textLine.data;
768
778
  var yOffsetValue = this.recommendOptions.textLine.yOffsetValue;
769
779
  lines.forEach(function (text, index) {
770
- _this.setText(ctx, { text: text, x: 0, y: _this.options.lineHeight * index - yOffsetValue });
780
+ _this.setText(ctx, { text: text, x: 0, y: _this.options.lineHeight * index - yOffsetValue, maxWidth: _this.options.textRowMaxWidth || _this.options.width });
771
781
  });
772
782
  resolve(ctx.canvas);
773
783
  };
@@ -925,8 +935,9 @@ var Watermark = /** @class */ (function () {
925
935
  function Watermark(args) {
926
936
  if (args === void 0) { args = {}; }
927
937
  this.parentElement = document.body;
938
+ this.isCreating = false;
928
939
  this.props = args;
929
- this.options = Object.assign({}, initialOptions, args);
940
+ this.options = __assign(__assign({}, initialOptions), args);
930
941
  this.changeParentElement(this.options.parent);
931
942
  this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
932
943
  bootstrap();
@@ -967,10 +978,16 @@ var Watermark = /** @class */ (function () {
967
978
  return __generator(this, function (_h) {
968
979
  switch (_h.label) {
969
980
  case 0:
981
+ if (this.isCreating) {
982
+ return [2 /*return*/];
983
+ }
984
+ this.isCreating = true;
970
985
  if (!this.validateUnique()) {
986
+ this.isCreating = false;
971
987
  return [2 /*return*/];
972
988
  }
973
989
  if (!this.validateContent()) {
990
+ this.isCreating = false;
974
991
  return [2 /*return*/];
975
992
  }
976
993
  firstDraw = isUndefined(this.watermarkDom);
@@ -988,7 +1005,7 @@ var Watermark = /** @class */ (function () {
988
1005
  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 ");
989
1006
  backgroundSize = generateBackgroundSize(this.options);
990
1007
  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 ");
991
- this.watermarkDom.append(watermarkInnerDom);
1008
+ this.watermarkDom.appendChild(watermarkInnerDom);
992
1009
  this.parentElement.appendChild(this.watermarkDom);
993
1010
  if (this.options.mutationObserve) {
994
1011
  try {
@@ -999,6 +1016,7 @@ var Watermark = /** @class */ (function () {
999
1016
  }
1000
1017
  }
1001
1018
  firstDraw && ((_g = (_f = this.options).onSuccess) === null || _g === void 0 ? void 0 : _g.call(_f));
1019
+ this.isCreating = false;
1002
1020
  return [2 /*return*/];
1003
1021
  }
1004
1022
  });
@@ -1028,13 +1046,13 @@ var Watermark = /** @class */ (function () {
1028
1046
  });
1029
1047
  };
1030
1048
  Watermark.prototype.remove = function () {
1031
- var _a, _b, _c, _d, _e, _f, _g;
1049
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1032
1050
  (_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
1033
1051
  (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
1034
1052
  (_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
1035
1053
  this.unbindCheckWatermarkElementEvent();
1036
- (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.remove();
1037
- (_g = (_f = this.options).onDestroyed) === null || _g === void 0 ? void 0 : _g.call(_f);
1054
+ (_f = (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.parentNode) === null || _f === void 0 ? void 0 : _f.removeChild(this.watermarkDom);
1055
+ (_h = (_g = this.options).onDestroyed) === null || _h === void 0 ? void 0 : _h.call(_g);
1038
1056
  };
1039
1057
  Watermark.prototype.initConfigData = function (args, mode) {
1040
1058
  var _this = this;
@@ -1047,7 +1065,7 @@ var Watermark = /** @class */ (function () {
1047
1065
  else {
1048
1066
  this.props = args;
1049
1067
  }
1050
- this.options = Object.assign({}, initialOptions, this.props);
1068
+ this.options = __assign(__assign({}, initialOptions), this.props);
1051
1069
  this.changeParentElement(this.options.parent);
1052
1070
  this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
1053
1071
  };
@@ -1059,10 +1077,13 @@ var Watermark = /** @class */ (function () {
1059
1077
  else {
1060
1078
  this.parentElement = parent;
1061
1079
  }
1080
+ if (!this.parentElement) {
1081
+ console.error('[WatermarkJsPlus]: please pass a valid parent element.');
1082
+ }
1062
1083
  };
1063
1084
  Watermark.prototype.validateUnique = function () {
1064
1085
  var result = true;
1065
- this.parentElement.childNodes.forEach(function (node) {
1086
+ Array.from(this.parentElement.childNodes).forEach(function (node) {
1066
1087
  if (!result) {
1067
1088
  return;
1068
1089
  }
@@ -1244,7 +1265,7 @@ var ImageWatermark = /** @class */ (function () {
1244
1265
  var _a;
1245
1266
  this.drew = false;
1246
1267
  this.props = args;
1247
- this.options = Object.assign({}, initialOptions, args);
1268
+ this.options = __assign(__assign({}, initialOptions), args);
1248
1269
  this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
1249
1270
  this.originalSrc = (_a = this.props.dom) === null || _a === void 0 ? void 0 : _a.src;
1250
1271
  this.backgroundImage = this.getBackgroundImage();