watermark-js-plus 1.5.8 → 1.6.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.
Files changed (62) hide show
  1. package/dist/ie/index.cjs.js +107 -78
  2. package/dist/ie/index.cjs.js.map +1 -1
  3. package/dist/ie/index.cjs.min.js +1 -1
  4. package/dist/ie/index.esm.js +107 -78
  5. package/dist/ie/index.esm.js.map +1 -1
  6. package/dist/ie/index.esm.min.js +1 -1
  7. package/dist/ie/index.iife.js +107 -78
  8. package/dist/ie/index.iife.js.map +1 -1
  9. package/dist/ie/index.iife.min.js +1 -1
  10. package/dist/ie/index.umd.js +107 -78
  11. package/dist/ie/index.umd.js.map +1 -1
  12. package/dist/ie/index.umd.min.js +1 -1
  13. package/dist/index.cjs.js +105 -76
  14. package/dist/index.cjs.js.map +1 -1
  15. package/dist/index.cjs.min.js +1 -1
  16. package/dist/index.esm.js +105 -76
  17. package/dist/index.esm.js.map +1 -1
  18. package/dist/index.esm.min.js +1 -1
  19. package/dist/index.iife.js +105 -76
  20. package/dist/index.iife.js.map +1 -1
  21. package/dist/index.iife.min.js +1 -1
  22. package/dist/index.umd.js +105 -76
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/types/{src/types → types}/index.d.ts +1 -0
  26. package/dist/{ie/types/src → types}/utils/index.d.ts +1 -0
  27. package/package.json +45 -32
  28. package/dist/ie/types/src/types/index.d.ts +0 -128
  29. package/dist/ie/types/tests/core/blind.test.d.ts +0 -1
  30. package/dist/ie/types/tests/core/image.test.d.ts +0 -1
  31. package/dist/ie/types/tests/core/watermark.test.d.ts +0 -1
  32. package/dist/ie/types/tests/utils/index.d.ts +0 -2
  33. package/dist/ie/types/tests/utils/index.test.d.ts +0 -1
  34. package/dist/types/src/core/blind.d.ts +0 -19
  35. package/dist/types/src/core/canvas.d.ts +0 -51
  36. package/dist/types/src/core/image.d.ts +0 -22
  37. package/dist/types/src/core/layout/grid.d.ts +0 -14
  38. package/dist/types/src/core/layout/index.d.ts +0 -4
  39. package/dist/types/src/core/watermark.d.ts +0 -48
  40. package/dist/types/src/index.d.ts +0 -5
  41. package/dist/types/src/index.ie.d.ts +0 -7
  42. package/dist/types/src/style/index.d.ts +0 -1
  43. package/dist/types/src/utils/index.d.ts +0 -14
  44. package/dist/types/src/utils/initialization.d.ts +0 -19
  45. package/dist/types/src/utils/protection.d.ts +0 -2
  46. package/dist/types/tests/core/blind.test.d.ts +0 -1
  47. package/dist/types/tests/core/image.test.d.ts +0 -1
  48. package/dist/types/tests/core/watermark.test.d.ts +0 -1
  49. package/dist/types/tests/utils/index.d.ts +0 -2
  50. package/dist/types/tests/utils/index.test.d.ts +0 -1
  51. /package/dist/{ie/types/src → types}/core/blind.d.ts +0 -0
  52. /package/dist/{ie/types/src → types}/core/canvas.d.ts +0 -0
  53. /package/dist/{ie/types/src → types}/core/image.d.ts +0 -0
  54. /package/dist/{ie/types/src → types}/core/layout/grid.d.ts +0 -0
  55. /package/dist/{ie/types/src → types}/core/layout/index.d.ts +0 -0
  56. /package/dist/{ie/types/src → types}/core/watermark.d.ts +0 -0
  57. /package/dist/{ie/types/src → types}/index.d.ts +0 -0
  58. /package/dist/{ie/types/src → types}/index.ie.d.ts +0 -0
  59. /package/dist/{ie/types/src → types}/style/index.d.ts +0 -0
  60. /package/dist/{ie/types/src → types}/utils/initialization.d.ts +0 -0
  61. /package/dist/types/{src/utils → utils}/polyfill.d.ts +0 -0
  62. /package/dist/{ie/types/src → types}/utils/protection.d.ts +0 -0
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * watermark-js-plus v1.5.8
2
+ * watermark-js-plus v1.6.0
3
3
  * (c) 2022-2024 Michael Sun
4
4
  * Released under the MIT License.
5
5
  */
@@ -32,7 +32,7 @@ function styleInject(css, ref) {
32
32
  }
33
33
  }
34
34
 
35
- 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}}";
35
+ var css_248z = "@keyframes watermark{0%{background-position:0 0}25%{background-position:100% 100%}50%{background-position:100% 0}75%{background-position:0 100%}to{background-position:0 0}}@keyframes watermark-horizontal{0%{background-position-x:0}to{background-position-x:100%}}@keyframes watermark-vertical{0%{background-position-y:0}to{background-position-y:100%}}";
36
36
  styleInject(css_248z);
37
37
 
38
38
  /******************************************************************************
@@ -49,7 +49,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
49
49
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
50
50
  PERFORMANCE OF THIS SOFTWARE.
51
51
  ***************************************************************************** */
52
- /* global Reflect, Promise */
52
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
53
53
 
54
54
  var extendStatics = function(d, b) {
55
55
  extendStatics = Object.setPrototypeOf ||
@@ -88,8 +88,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
88
88
  }
89
89
 
90
90
  function __generator(thisArg, body) {
91
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
92
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
91
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
92
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
93
93
  function verb(n) { return function (v) { return step([n, v]); }; }
94
94
  function step(op) {
95
95
  if (f) throw new TypeError("Generator is already executing.");
@@ -113,7 +113,12 @@ function __generator(thisArg, body) {
113
113
  } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
114
114
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
115
115
  }
116
- }
116
+ }
117
+
118
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
119
+ var e = new Error(message);
120
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
121
+ };
117
122
 
118
123
  var convertImage = function (canvas) {
119
124
  return canvas.toDataURL('image/png', 1);
@@ -164,7 +169,7 @@ var createCustomContentSVG = function (ctx, options) { return __awaiter(void 0,
164
169
  switch (_b.label) {
165
170
  case 0:
166
171
  svgElement = createSVGElement('svg', {
167
- xmlns: 'http://www.w3.org/2000/svg'
172
+ xmlns: 'http://www.w3.org/2000/svg',
168
173
  });
169
174
  bodyElement = document.createElement('div');
170
175
  bodyElement.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
@@ -186,14 +191,14 @@ var createCustomContentSVG = function (ctx, options) { return __awaiter(void 0,
186
191
  svgElement.setAttribute('height', height.toString());
187
192
  foreignObjectElement = createSVGElement('foreignObject', {
188
193
  width: width.toString(),
189
- height: height.toString()
194
+ height: height.toString(),
190
195
  });
191
196
  foreignObjectElement.appendChild(bodyElement);
192
197
  svgElement.appendChild(foreignObjectElement);
193
198
  return [2 /*return*/, {
194
199
  element: svgElement,
195
200
  width: width,
196
- height: height
201
+ height: height,
197
202
  }];
198
203
  }
199
204
  });
@@ -261,7 +266,8 @@ function convertImgToBase64(bodyElement) {
261
266
  var convertSVGToImage = function (svg) {
262
267
  var richContent = svg.outerHTML
263
268
  .replace(/<(img|br|input|hr|embed)(.*?)>/g, '<$1$2/>')
264
- .replace(/\n/g, '').replace(/\t/g, '')
269
+ .replace(/\n/g, '')
270
+ .replace(/\t/g, '')
265
271
  .replace(/#/g, '%23');
266
272
  return "data:image/svg+xml;charset=utf-8,".concat(richContent);
267
273
  };
@@ -277,7 +283,7 @@ var loadImage = function (url, width, height) {
277
283
  if (width === void 0) { width = undefined; }
278
284
  if (height === void 0) { height = undefined; }
279
285
  var image = new Image();
280
- image.setAttribute('crossOrigin', 'Anonymous');
286
+ image.setAttribute('crossOrigin', 'anonymous');
281
287
  !isUndefined(width) && (image.width = width);
282
288
  !isUndefined(height) && (image.height = height);
283
289
  image.src = url;
@@ -290,6 +296,25 @@ var loadImage = function (url, width, height) {
290
296
  var generateMatrix = function (rows, columns, value) {
291
297
  return Array.from({ length: rows }, function () { return new Array(columns).fill(value); });
292
298
  };
299
+ var generateAnimationStyle = function (movable, backgroundRepeat) {
300
+ if (!movable) {
301
+ return '';
302
+ }
303
+ var horizontalDuration = Math.random() * (8 - 2) + 2;
304
+ var verticalDuration = Math.random() * (4 - 2) + 2;
305
+ switch (backgroundRepeat) {
306
+ case 'repeat':
307
+ return 'animation: 200s linear 0s infinite alternate watermark !important;';
308
+ case 'repeat-x':
309
+ return "animation: ".concat(horizontalDuration, "s ease-in 0s infinite alternate watermark-vertical !important;'");
310
+ case 'repeat-y':
311
+ return "animation: ".concat(verticalDuration, "s ease-out 0s infinite alternate watermark-horizontal !important;'");
312
+ case 'no-repeat':
313
+ return "animation: ".concat(horizontalDuration, "s ease-in 0s infinite alternate watermark-horizontal, ").concat(verticalDuration, "s ease-out 0s infinite alternate watermark-vertical !important;");
314
+ default:
315
+ return '';
316
+ }
317
+ };
293
318
 
294
319
  var initialOptions = {
295
320
  width: 300,
@@ -325,7 +350,7 @@ var initialOptions = {
325
350
  onSuccess: function () { },
326
351
  onBeforeDestroy: function () { },
327
352
  onDestroyed: function () { },
328
- onObserveError: function () { }
353
+ onObserveError: function () { },
329
354
  };
330
355
  var generateRecommendOptions = function (canvas, options, args) {
331
356
  var ctx = canvas.getContext('2d');
@@ -338,7 +363,7 @@ var generateRecommendOptions = function (canvas, options, args) {
338
363
  ctx.letterSpacing = options.letterSpacing;
339
364
  ctx.wordSpacing = options.wordSpacing;
340
365
  if (options === null || options === void 0 ? void 0 : options.rotate) {
341
- options.rotate = (360 - options.rotate % 360) * (Math.PI / 180);
366
+ options.rotate = (360 - (options.rotate % 360)) * (Math.PI / 180);
342
367
  }
343
368
  if (isUndefined(args.textRowMaxWidth)) {
344
369
  options.textRowMaxWidth = options.width;
@@ -347,21 +372,21 @@ var generateRecommendOptions = function (canvas, options, args) {
347
372
  image: {
348
373
  rect: {
349
374
  width: options.imageWidth,
350
- height: options.imageHeight
375
+ height: options.imageHeight,
351
376
  },
352
377
  position: {
353
378
  x: 0,
354
- y: 0
355
- }
379
+ y: 0,
380
+ },
356
381
  },
357
382
  textLine: {
358
383
  data: [],
359
- yOffsetValue: 0
384
+ yOffsetValue: 0,
360
385
  },
361
386
  advancedStyleParams: {
362
387
  linear: {
363
388
  x0: 0,
364
- x1: 0
389
+ x1: 0,
365
390
  },
366
391
  radial: {
367
392
  x0: 0,
@@ -369,15 +394,15 @@ var generateRecommendOptions = function (canvas, options, args) {
369
394
  r0: 0,
370
395
  x1: 0,
371
396
  y1: 0,
372
- r1: 0
397
+ r1: 0,
373
398
  },
374
399
  conic: {
375
400
  x: 0,
376
401
  y: 0,
377
- startAngle: 0
402
+ startAngle: 0,
378
403
  },
379
- pattern: {}
380
- }
404
+ pattern: {},
405
+ },
381
406
  };
382
407
  switch (options.contentType) {
383
408
  case 'text':
@@ -427,14 +452,14 @@ var generateRecommendOptions = function (canvas, options, args) {
427
452
  result.advancedStyleParams.linear.x0 = -options.width / 2;
428
453
  result.advancedStyleParams.linear.x1 = options.width / 2;
429
454
  // result.advancedStyleParams.radial.x0 = 0
430
- result.advancedStyleParams.radial.y0 = result.textLine.data.length * options.lineHeight / 2;
455
+ result.advancedStyleParams.radial.y0 = (result.textLine.data.length * options.lineHeight) / 2;
431
456
  // result.advancedStyleParams.radial.r0 = 0
432
457
  // result.advancedStyleParams.radial.x1 = 0
433
458
  // result.advancedStyleParams.radial.y1 = 0
434
- result.advancedStyleParams.radial.y1 = result.textLine.data.length * options.lineHeight / 2;
459
+ result.advancedStyleParams.radial.y1 = (result.textLine.data.length * options.lineHeight) / 2;
435
460
  // result.advancedStyleParams.radial.r1 = options.width / 2
436
461
  // result.advancedStyleParams.conic.x = 0
437
- result.advancedStyleParams.conic.y = result.textLine.data.length * options.lineHeight / 2;
462
+ result.advancedStyleParams.conic.y = (result.textLine.data.length * options.lineHeight) / 2;
438
463
  break;
439
464
  case 'top-start':
440
465
  translateX = 0;
@@ -444,13 +469,13 @@ var generateRecommendOptions = function (canvas, options, args) {
444
469
  result.advancedStyleParams.linear.x0 = 0;
445
470
  result.advancedStyleParams.linear.x1 = options.width;
446
471
  result.advancedStyleParams.radial.x0 = options.width / 2;
447
- result.advancedStyleParams.radial.y0 = result.textLine.data.length * options.lineHeight / 2;
472
+ result.advancedStyleParams.radial.y0 = (result.textLine.data.length * options.lineHeight) / 2;
448
473
  // result.advancedStyleParams.radial.r0 = 0
449
474
  result.advancedStyleParams.radial.x1 = options.width / 2;
450
- result.advancedStyleParams.radial.y1 = result.textLine.data.length * options.lineHeight / 2;
475
+ result.advancedStyleParams.radial.y1 = (result.textLine.data.length * options.lineHeight) / 2;
451
476
  // result.advancedStyleParams.radial.r1 = options.width / 2
452
477
  result.advancedStyleParams.conic.x = options.width / 2;
453
- result.advancedStyleParams.conic.y = result.textLine.data.length * options.lineHeight / 2;
478
+ result.advancedStyleParams.conic.y = (result.textLine.data.length * options.lineHeight) / 2;
454
479
  break;
455
480
  case 'top-end':
456
481
  translateX = options.width;
@@ -460,13 +485,13 @@ var generateRecommendOptions = function (canvas, options, args) {
460
485
  result.advancedStyleParams.linear.x0 = 0;
461
486
  result.advancedStyleParams.linear.x1 = -options.width;
462
487
  result.advancedStyleParams.radial.x0 = -options.width / 2;
463
- result.advancedStyleParams.radial.y0 = result.textLine.data.length * options.lineHeight / 2;
488
+ result.advancedStyleParams.radial.y0 = (result.textLine.data.length * options.lineHeight) / 2;
464
489
  // result.advancedStyleParams.radial.r0 = 0
465
490
  result.advancedStyleParams.radial.x1 = -options.width / 2;
466
- result.advancedStyleParams.radial.y1 = result.textLine.data.length * options.lineHeight / 2;
491
+ result.advancedStyleParams.radial.y1 = (result.textLine.data.length * options.lineHeight) / 2;
467
492
  // result.advancedStyleParams.radial.r1 = options.width / 2
468
493
  result.advancedStyleParams.conic.x = -options.width / 2;
469
- result.advancedStyleParams.conic.y = result.textLine.data.length * options.lineHeight / 2;
494
+ result.advancedStyleParams.conic.y = (result.textLine.data.length * options.lineHeight) / 2;
470
495
  break;
471
496
  case 'bottom':
472
497
  translateX = options.width / 2;
@@ -476,13 +501,13 @@ var generateRecommendOptions = function (canvas, options, args) {
476
501
  result.advancedStyleParams.linear.x0 = -options.width / 2;
477
502
  result.advancedStyleParams.linear.x1 = options.width / 2;
478
503
  // result.advancedStyleParams.radial.x0 = 0
479
- result.advancedStyleParams.radial.y0 = -result.textLine.data.length * options.lineHeight / 2;
504
+ result.advancedStyleParams.radial.y0 = (-result.textLine.data.length * options.lineHeight) / 2;
480
505
  // result.advancedStyleParams.radial.r0 = 0
481
506
  // result.advancedStyleParams.radial.x1 = 0
482
- result.advancedStyleParams.radial.y1 = -result.textLine.data.length * options.lineHeight / 2;
507
+ result.advancedStyleParams.radial.y1 = (-result.textLine.data.length * options.lineHeight) / 2;
483
508
  // result.advancedStyleParams.radial.r1 = options.width / 2
484
509
  result.advancedStyleParams.conic.x = 0;
485
- result.advancedStyleParams.conic.y = -result.textLine.data.length * options.lineHeight / 2;
510
+ result.advancedStyleParams.conic.y = (-result.textLine.data.length * options.lineHeight) / 2;
486
511
  break;
487
512
  case 'bottom-start':
488
513
  translateX = 0;
@@ -492,13 +517,13 @@ var generateRecommendOptions = function (canvas, options, args) {
492
517
  result.advancedStyleParams.linear.x0 = 0;
493
518
  result.advancedStyleParams.linear.x1 = options.width;
494
519
  result.advancedStyleParams.radial.x0 = options.width / 2;
495
- result.advancedStyleParams.radial.y0 = -result.textLine.data.length * options.lineHeight / 2;
520
+ result.advancedStyleParams.radial.y0 = (-result.textLine.data.length * options.lineHeight) / 2;
496
521
  // result.advancedStyleParams.radial.r0 = 0
497
522
  result.advancedStyleParams.radial.x1 = options.width / 2;
498
- result.advancedStyleParams.radial.y1 = -result.textLine.data.length * options.lineHeight / 2;
523
+ result.advancedStyleParams.radial.y1 = (-result.textLine.data.length * options.lineHeight) / 2;
499
524
  // result.advancedStyleParams.radial.r1 = options.width / 2
500
525
  result.advancedStyleParams.conic.x = options.width / 2;
501
- result.advancedStyleParams.conic.y = -result.textLine.data.length * options.lineHeight / 2;
526
+ result.advancedStyleParams.conic.y = (-result.textLine.data.length * options.lineHeight) / 2;
502
527
  break;
503
528
  case 'bottom-end':
504
529
  translateX = options.width;
@@ -508,13 +533,13 @@ var generateRecommendOptions = function (canvas, options, args) {
508
533
  result.advancedStyleParams.linear.x0 = 0;
509
534
  result.advancedStyleParams.linear.x1 = -options.width;
510
535
  result.advancedStyleParams.radial.x0 = -options.width / 2;
511
- result.advancedStyleParams.radial.y0 = -result.textLine.data.length * options.lineHeight / 2;
536
+ result.advancedStyleParams.radial.y0 = (-result.textLine.data.length * options.lineHeight) / 2;
512
537
  // result.advancedStyleParams.radial.r0 = 0
513
538
  result.advancedStyleParams.radial.x1 = -options.width / 2;
514
- result.advancedStyleParams.radial.y1 = -result.textLine.data.length * options.lineHeight / 2;
539
+ result.advancedStyleParams.radial.y1 = (-result.textLine.data.length * options.lineHeight) / 2;
515
540
  // result.advancedStyleParams.radial.r1 = options.width / 2
516
541
  result.advancedStyleParams.conic.x = -options.width / 2;
517
- result.advancedStyleParams.conic.y = -result.textLine.data.length * options.lineHeight / 2;
542
+ result.advancedStyleParams.conic.y = (-result.textLine.data.length * options.lineHeight) / 2;
518
543
  break;
519
544
  case 'left':
520
545
  translateX = 0;
@@ -556,12 +581,13 @@ var generateRecommendOptions = function (canvas, options, args) {
556
581
  if (['text', 'multi-line-text'].includes(options.contentType)) {
557
582
  switch (options.textBaseline) {
558
583
  case 'middle':
559
- result.textLine.yOffsetValue = (result.textLine.data.length - 1) * options.lineHeight / 2;
584
+ result.textLine.yOffsetValue = ((result.textLine.data.length - 1) * options.lineHeight) / 2;
560
585
  break;
561
586
  case 'bottom':
562
587
  case 'alphabetic':
563
588
  case 'ideographic':
564
- result.textLine.yOffsetValue = (result.textLine.data.length - 1) * options.lineHeight + (options.lineHeight - parseInt(options.fontSize)) / 2;
589
+ result.textLine.yOffsetValue =
590
+ (result.textLine.data.length - 1) * options.lineHeight + (options.lineHeight - parseInt(options.fontSize)) / 2;
565
591
  break;
566
592
  case 'top':
567
593
  case 'hanging':
@@ -579,11 +605,11 @@ var protection = (function (need) {
579
605
  if (need) {
580
606
  Object.defineProperty(window, 'MutationObserver', {
581
607
  writable: false,
582
- configurable: false
608
+ configurable: false,
583
609
  });
584
610
  Object.defineProperty(window, 'requestAnimationFrame', {
585
611
  writable: false,
586
- configurable: false
612
+ configurable: false,
587
613
  });
588
614
  }
589
615
  });
@@ -712,7 +738,7 @@ var WatermarkCanvas = /** @class */ (function () {
712
738
  };
713
739
  WatermarkCanvas.prototype.createLinearGradient = function (ctx) {
714
740
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
715
- var gradient = ctx.createLinearGradient(getValue((_c = (_b = (_a = this.options.advancedStyle) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.linear) === null || _c === void 0 ? void 0 : _c.x0, this.recommendOptions.advancedStyleParams.linear.x0), getValue((_f = (_e = (_d = this.options.advancedStyle) === null || _d === void 0 ? void 0 : _d.params) === null || _e === void 0 ? void 0 : _e.linear) === null || _f === void 0 ? void 0 : _f.y0, 0), getValue((_j = (_h = (_g = this.options.advancedStyle) === null || _g === void 0 ? void 0 : _g.params) === null || _h === void 0 ? void 0 : _h.linear) === null || _j === void 0 ? void 0 : _j.x1, this.recommendOptions.advancedStyleParams.linear.x1), getValue((_m = (_l = (_k = this.options.advancedStyle) === null || _k === void 0 ? void 0 : _k.params) === null || _l === void 0 ? void 0 : _l.linear) === null || _m === void 0 ? void 0 : _m.y1, 0));
741
+ var gradient = ctx.createLinearGradient((getValue((_c = (_b = (_a = this.options.advancedStyle) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b.linear) === null || _c === void 0 ? void 0 : _c.x0, this.recommendOptions.advancedStyleParams.linear.x0)), getValue((_f = (_e = (_d = this.options.advancedStyle) === null || _d === void 0 ? void 0 : _d.params) === null || _e === void 0 ? void 0 : _e.linear) === null || _f === void 0 ? void 0 : _f.y0, 0), (getValue((_j = (_h = (_g = this.options.advancedStyle) === null || _g === void 0 ? void 0 : _g.params) === null || _h === void 0 ? void 0 : _h.linear) === null || _j === void 0 ? void 0 : _j.x1, this.recommendOptions.advancedStyleParams.linear.x1)), getValue((_m = (_l = (_k = this.options.advancedStyle) === null || _k === void 0 ? void 0 : _k.params) === null || _l === void 0 ? void 0 : _l.linear) === null || _m === void 0 ? void 0 : _m.y1, 0));
716
742
  (_q = (_p = (_o = this.options) === null || _o === void 0 ? void 0 : _o.advancedStyle) === null || _p === void 0 ? void 0 : _p.colorStops) === null || _q === void 0 ? void 0 : _q.forEach(function (item) {
717
743
  gradient.addColorStop(item.offset, item.color);
718
744
  });
@@ -720,7 +746,7 @@ var WatermarkCanvas = /** @class */ (function () {
720
746
  };
721
747
  WatermarkCanvas.prototype.createConicGradient = function (ctx) {
722
748
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
723
- var gradient = ctx.createConicGradient(getValue((_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.advancedStyle) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.conic) === null || _d === void 0 ? void 0 : _d.startAngle, 0), getValue((_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.advancedStyle) === null || _f === void 0 ? void 0 : _f.params) === null || _g === void 0 ? void 0 : _g.conic) === null || _h === void 0 ? void 0 : _h.x, this.recommendOptions.advancedStyleParams.conic.x), getValue((_m = (_l = (_k = (_j = this.options) === null || _j === void 0 ? void 0 : _j.advancedStyle) === null || _k === void 0 ? void 0 : _k.params) === null || _l === void 0 ? void 0 : _l.conic) === null || _m === void 0 ? void 0 : _m.y, this.recommendOptions.advancedStyleParams.conic.y));
749
+ var gradient = ctx.createConicGradient(getValue((_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.advancedStyle) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.conic) === null || _d === void 0 ? void 0 : _d.startAngle, 0), (getValue((_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.advancedStyle) === null || _f === void 0 ? void 0 : _f.params) === null || _g === void 0 ? void 0 : _g.conic) === null || _h === void 0 ? void 0 : _h.x, this.recommendOptions.advancedStyleParams.conic.x)), (getValue((_m = (_l = (_k = (_j = this.options) === null || _j === void 0 ? void 0 : _j.advancedStyle) === null || _k === void 0 ? void 0 : _k.params) === null || _l === void 0 ? void 0 : _l.conic) === null || _m === void 0 ? void 0 : _m.y, this.recommendOptions.advancedStyleParams.conic.y)));
724
750
  (_q = (_p = (_o = this.options) === null || _o === void 0 ? void 0 : _o.advancedStyle) === null || _p === void 0 ? void 0 : _p.colorStops) === null || _q === void 0 ? void 0 : _q.forEach(function (item) {
725
751
  gradient.addColorStop(item.offset, item.color);
726
752
  });
@@ -728,7 +754,7 @@ var WatermarkCanvas = /** @class */ (function () {
728
754
  };
729
755
  WatermarkCanvas.prototype.createRadialGradient = function (ctx) {
730
756
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
731
- var gradient = ctx.createRadialGradient(getValue((_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.advancedStyle) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.radial) === null || _d === void 0 ? void 0 : _d.x0, this.recommendOptions.advancedStyleParams.radial.x0), getValue((_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.advancedStyle) === null || _f === void 0 ? void 0 : _f.params) === null || _g === void 0 ? void 0 : _g.radial) === null || _h === void 0 ? void 0 : _h.y0, this.recommendOptions.advancedStyleParams.radial.y0), getValue((_m = (_l = (_k = (_j = this.options) === null || _j === void 0 ? void 0 : _j.advancedStyle) === null || _k === void 0 ? void 0 : _k.params) === null || _l === void 0 ? void 0 : _l.radial) === null || _m === void 0 ? void 0 : _m.r0, this.recommendOptions.advancedStyleParams.radial.r0), getValue((_r = (_q = (_p = (_o = this.options) === null || _o === void 0 ? void 0 : _o.advancedStyle) === null || _p === void 0 ? void 0 : _p.params) === null || _q === void 0 ? void 0 : _q.radial) === null || _r === void 0 ? void 0 : _r.x1, this.recommendOptions.advancedStyleParams.radial.x1), getValue((_v = (_u = (_t = (_s = this.options) === null || _s === void 0 ? void 0 : _s.advancedStyle) === null || _t === void 0 ? void 0 : _t.params) === null || _u === void 0 ? void 0 : _u.radial) === null || _v === void 0 ? void 0 : _v.y1, this.recommendOptions.advancedStyleParams.radial.y1), getValue((_z = (_y = (_x = (_w = this.options) === null || _w === void 0 ? void 0 : _w.advancedStyle) === null || _x === void 0 ? void 0 : _x.params) === null || _y === void 0 ? void 0 : _y.radial) === null || _z === void 0 ? void 0 : _z.r1, this.recommendOptions.advancedStyleParams.radial.r1));
757
+ var gradient = ctx.createRadialGradient((getValue((_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.advancedStyle) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.radial) === null || _d === void 0 ? void 0 : _d.x0, this.recommendOptions.advancedStyleParams.radial.x0)), (getValue((_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.advancedStyle) === null || _f === void 0 ? void 0 : _f.params) === null || _g === void 0 ? void 0 : _g.radial) === null || _h === void 0 ? void 0 : _h.y0, this.recommendOptions.advancedStyleParams.radial.y0)), (getValue((_m = (_l = (_k = (_j = this.options) === null || _j === void 0 ? void 0 : _j.advancedStyle) === null || _k === void 0 ? void 0 : _k.params) === null || _l === void 0 ? void 0 : _l.radial) === null || _m === void 0 ? void 0 : _m.r0, this.recommendOptions.advancedStyleParams.radial.r0)), (getValue((_r = (_q = (_p = (_o = this.options) === null || _o === void 0 ? void 0 : _o.advancedStyle) === null || _p === void 0 ? void 0 : _p.params) === null || _q === void 0 ? void 0 : _q.radial) === null || _r === void 0 ? void 0 : _r.x1, this.recommendOptions.advancedStyleParams.radial.x1)), (getValue((_v = (_u = (_t = (_s = this.options) === null || _s === void 0 ? void 0 : _s.advancedStyle) === null || _t === void 0 ? void 0 : _t.params) === null || _u === void 0 ? void 0 : _u.radial) === null || _v === void 0 ? void 0 : _v.y1, this.recommendOptions.advancedStyleParams.radial.y1)), (getValue((_z = (_y = (_x = (_w = this.options) === null || _w === void 0 ? void 0 : _w.advancedStyle) === null || _x === void 0 ? void 0 : _x.params) === null || _y === void 0 ? void 0 : _y.radial) === null || _z === void 0 ? void 0 : _z.r1, this.recommendOptions.advancedStyleParams.radial.r1)));
732
758
  (_2 = (_1 = (_0 = this.options) === null || _0 === void 0 ? void 0 : _0.advancedStyle) === null || _1 === void 0 ? void 0 : _1.colorStops) === null || _2 === void 0 ? void 0 : _2.forEach(function (item) {
733
759
  gradient.addColorStop(item.offset, item.color);
734
760
  });
@@ -736,7 +762,7 @@ var WatermarkCanvas = /** @class */ (function () {
736
762
  };
737
763
  WatermarkCanvas.prototype.createPattern = function (ctx) {
738
764
  var _a, _b, _c, _d, _e, _f, _g, _h;
739
- return ctx.createPattern((_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.advancedStyle) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.pattern) === null || _d === void 0 ? void 0 : _d.image, ((_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.advancedStyle) === null || _f === void 0 ? void 0 : _f.params) === null || _g === void 0 ? void 0 : _g.pattern) === null || _h === void 0 ? void 0 : _h.repetition) || '');
765
+ return ctx.createPattern(((_d = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.advancedStyle) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.pattern) === null || _d === void 0 ? void 0 : _d.image), ((_h = (_g = (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.advancedStyle) === null || _f === void 0 ? void 0 : _f.params) === null || _g === void 0 ? void 0 : _g.pattern) === null || _h === void 0 ? void 0 : _h.repetition) || '');
740
766
  };
741
767
  WatermarkCanvas.prototype.setText = function (ctx, params) {
742
768
  var methodName = 'fillText';
@@ -750,7 +776,7 @@ var WatermarkCanvas = /** @class */ (function () {
750
776
  text: this.options.content,
751
777
  x: 0,
752
778
  y: 0 - this.recommendOptions.textLine.yOffsetValue,
753
- maxWidth: this.options.textRowMaxWidth || this.options.width
779
+ maxWidth: this.options.textRowMaxWidth || this.options.width,
754
780
  });
755
781
  resolve(ctx.canvas);
756
782
  };
@@ -784,7 +810,12 @@ var WatermarkCanvas = /** @class */ (function () {
784
810
  var lines = this.recommendOptions.textLine.data;
785
811
  var yOffsetValue = this.recommendOptions.textLine.yOffsetValue;
786
812
  lines.forEach(function (text, index) {
787
- _this.setText(ctx, { text: text, x: 0, y: _this.options.lineHeight * index - yOffsetValue, maxWidth: _this.options.textRowMaxWidth || _this.options.width });
813
+ _this.setText(ctx, {
814
+ text: text,
815
+ x: 0,
816
+ y: _this.options.lineHeight * index - yOffsetValue,
817
+ maxWidth: _this.options.textRowMaxWidth || _this.options.width,
818
+ });
788
819
  });
789
820
  resolve(ctx.canvas);
790
821
  };
@@ -811,10 +842,10 @@ var WatermarkCanvas = /** @class */ (function () {
811
842
  var rect = { width: this.options.imageWidth || 0, height: this.options.imageHeight || 0 };
812
843
  switch (true) {
813
844
  case rect.width !== 0 && rect.height === 0:
814
- rect.height = rect.width * image.height / image.width;
845
+ rect.height = (rect.width * image.height) / image.width;
815
846
  break;
816
847
  case rect.width === 0 && rect.height !== 0:
817
- rect.width = rect.height * image.width / image.height;
848
+ rect.width = (rect.height * image.width) / image.height;
818
849
  break;
819
850
  case rect.width === 0 && rect.height === 0:
820
851
  rect.width = image.width;
@@ -827,7 +858,7 @@ var WatermarkCanvas = /** @class */ (function () {
827
858
  var _a, _b;
828
859
  var result = {
829
860
  x: -imageWidth / 2,
830
- y: -imageHeight / 2
861
+ y: -imageHeight / 2,
831
862
  };
832
863
  switch (this.options.translatePlacement) {
833
864
  case 'top':
@@ -884,7 +915,7 @@ var GridLayout = /** @class */ (function () {
884
915
  }
885
916
  GridLayout.prototype.draw = function () {
886
917
  var _a, _b, _c, _d, _e, _f, _g, _h;
887
- var layoutCanvas = WatermarkCanvas.createCanvas(((_a = this.options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.width) || (this.partialWidth * this.cols + this.gap[0] * this.cols), ((_b = this.options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.height) || (this.partialHeight * this.rows + this.gap[1] * this.rows));
918
+ var layoutCanvas = WatermarkCanvas.createCanvas(((_a = this.options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.width) || this.partialWidth * this.cols + this.gap[0] * this.cols, ((_b = this.options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.height) || this.partialHeight * this.rows + this.gap[1] * this.rows);
888
919
  var layoutContext = layoutCanvas.getContext('2d');
889
920
  if ((_c = this.options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.backgroundImage) {
890
921
  layoutContext === null || layoutContext === void 0 ? void 0 : layoutContext.drawImage((_d = this.options.gridLayoutOptions) === null || _d === void 0 ? void 0 : _d.backgroundImage, 0, 0, (_e = this.options.gridLayoutOptions) === null || _e === void 0 ? void 0 : _e.width, (_f = this.options.gridLayoutOptions) === null || _f === void 0 ? void 0 : _f.height);
@@ -913,21 +944,14 @@ var renderLayout = function (options, partialCanvas) {
913
944
  var generateBackgroundSize = function (options) {
914
945
  var _a, _b, _c;
915
946
  switch (options.layout) {
916
- case 'grid':
917
- {
918
- var cols = ((_a = options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.cols) || 1;
919
- var rows = ((_b = options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.rows) || 1;
920
- var gap = ((_c = options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.gap) || [0, 0];
921
- return [
922
- options.width * cols + gap[0] * cols,
923
- options.height * rows + gap[1] * rows
924
- ];
925
- }
947
+ case 'grid': {
948
+ var cols = ((_a = options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.cols) || 1;
949
+ var rows = ((_b = options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.rows) || 1;
950
+ var gap = ((_c = options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.gap) || [0, 0];
951
+ return [options.width * cols + gap[0] * cols, options.height * rows + gap[1] * rows];
952
+ }
926
953
  default:
927
- return [
928
- options.width,
929
- options.height
930
- ];
954
+ return [options.width, options.height];
931
955
  }
932
956
  };
933
957
 
@@ -1012,14 +1036,14 @@ var Watermark = /** @class */ (function () {
1012
1036
  parentElementType = this.checkParentElementType();
1013
1037
  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 ");
1014
1038
  backgroundSize = generateBackgroundSize(this.options);
1015
- 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 ");
1039
+ 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(generateAnimationStyle(this.options.movable, this.options.backgroundRepeat), "\n ");
1016
1040
  this.watermarkDom.appendChild(watermarkInnerDom);
1017
1041
  this.parentElement.appendChild(this.watermarkDom);
1018
1042
  if (this.options.mutationObserve) {
1019
1043
  try {
1020
1044
  this.bindMutationObserve();
1021
1045
  }
1022
- catch (e) {
1046
+ catch (_j) {
1023
1047
  (_e = (_d = this.options).onObserveError) === null || _e === void 0 ? void 0 : _e.call(_d);
1024
1048
  }
1025
1049
  }
@@ -1151,7 +1175,7 @@ var Watermark = /** @class */ (function () {
1151
1175
  attributes: true, // 属性的变动
1152
1176
  childList: true, // 子节点的变动(指新增,删除或者更改)
1153
1177
  subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
1154
- characterData: true // 节点内容或节点文本的变动。
1178
+ characterData: true, // 节点内容或节点文本的变动。
1155
1179
  });
1156
1180
  this.parentObserve = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
1157
1181
  var _i, mutationsList_1, item;
@@ -1166,7 +1190,9 @@ var Watermark = /** @class */ (function () {
1166
1190
  item = mutationsList_1[_i];
1167
1191
  if (!((item === null || item === void 0 ? void 0 : item.target) === this.watermarkDom ||
1168
1192
  ((_a = item === null || item === void 0 ? void 0 : item.removedNodes) === null || _a === void 0 ? void 0 : _a[0]) === this.watermarkDom ||
1169
- (item.type === 'childList' && item.target === this.parentElement && item.target.lastChild !== this.watermarkDom))) return [3 /*break*/, 3];
1193
+ (item.type === 'childList' &&
1194
+ item.target === this.parentElement &&
1195
+ item.target.lastChild !== this.watermarkDom))) return [3 /*break*/, 3];
1170
1196
  this.remove();
1171
1197
  return [4 /*yield*/, this.create()];
1172
1198
  case 2:
@@ -1183,7 +1209,7 @@ var Watermark = /** @class */ (function () {
1183
1209
  attributes: true, // 属性的变动
1184
1210
  childList: true, // 子节点的变动(指新增,删除或者更改)
1185
1211
  subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
1186
- characterData: true // 节点内容或节点文本的变动。
1212
+ characterData: true, // 节点内容或节点文本的变动。
1187
1213
  });
1188
1214
  };
1189
1215
  Watermark.prototype.bindCheckWatermarkElementEvent = function () {
@@ -1211,7 +1237,7 @@ var BlindWatermark = /** @class */ (function (_super) {
1211
1237
  if (props === void 0) { props = {}; }
1212
1238
  var defaultProps = {
1213
1239
  globalAlpha: 0.005,
1214
- mode: 'blind'
1240
+ mode: 'blind',
1215
1241
  };
1216
1242
  return _super.call(this, __assign(__assign({}, props), defaultProps)) || this;
1217
1243
  }
@@ -1283,12 +1309,15 @@ var ImageWatermark = /** @class */ (function () {
1283
1309
  */
1284
1310
  function ImageWatermark(args) {
1285
1311
  if (args === void 0) { args = {}; }
1286
- var _a;
1312
+ var _a, _b;
1287
1313
  this.drew = false;
1288
1314
  this.props = args;
1289
1315
  this.options = __assign(__assign({}, initialOptions), args);
1316
+ if (this.props.crossOrigin) {
1317
+ (_a = this.props.dom) === null || _a === void 0 ? void 0 : _a.setAttribute('crossOrigin', 'anonymous');
1318
+ }
1290
1319
  this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
1291
- this.originalSrc = (_a = this.props.dom) === null || _a === void 0 ? void 0 : _a.src;
1320
+ this.originalSrc = (_b = this.props.dom) === null || _b === void 0 ? void 0 : _b.src;
1292
1321
  this.backgroundImage = this.getBackgroundImage();
1293
1322
  }
1294
1323
  ImageWatermark.prototype.create = function () {