watermark-js-plus 0.9.8 → 0.9.10
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 +52 -25
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.esm.js +52 -25
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.iife.js +52 -25
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.umd.js +52 -25
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/types/src/core/layout/grid.d.ts +1 -0
- package/dist/types/src/core/layout/index.d.ts +2 -1
- package/dist/types/src/core/watermark.d.ts +1 -0
- package/dist/types/src/types/index.d.ts +1 -0
- package/package.json +8 -8
package/dist/index.cjs.js
CHANGED
|
@@ -446,24 +446,26 @@ var bootstrap = (function () {
|
|
|
446
446
|
|
|
447
447
|
var GridLayout = /** @class */ (function () {
|
|
448
448
|
function GridLayout(args, partialCanvas) {
|
|
449
|
-
var _a, _b, _c;
|
|
449
|
+
var _a, _b, _c, _d;
|
|
450
450
|
this.options = args;
|
|
451
451
|
this.partialWidth = this.options.width;
|
|
452
452
|
this.partialHeight = this.options.height;
|
|
453
453
|
this.rows = ((_a = this.options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.rows) || 1;
|
|
454
454
|
this.cols = ((_b = this.options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.cols) || 1;
|
|
455
455
|
this.matrix = ((_c = this.options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.matrix) || generateMatrix(this.rows, this.cols, 1);
|
|
456
|
+
this.gap = ((_d = this.options.gridLayoutOptions) === null || _d === void 0 ? void 0 : _d.gap) || [0, 0];
|
|
456
457
|
this.partialCanvas = partialCanvas;
|
|
457
458
|
}
|
|
458
459
|
GridLayout.prototype.draw = function () {
|
|
459
|
-
var
|
|
460
|
+
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);
|
|
460
462
|
var layoutContext = layoutCanvas.getContext('2d');
|
|
461
463
|
for (var rowIndex = 0; rowIndex < this.rows; rowIndex++) {
|
|
462
464
|
for (var colIndex = 0; colIndex < this.cols; colIndex++) {
|
|
463
|
-
if (!this.matrix[rowIndex][colIndex]) {
|
|
465
|
+
if (!((_b = (_a = this.matrix) === null || _a === void 0 ? void 0 : _a[rowIndex]) === null || _b === void 0 ? void 0 : _b[colIndex])) {
|
|
464
466
|
continue;
|
|
465
467
|
}
|
|
466
|
-
layoutContext === null || layoutContext === void 0 ? void 0 : layoutContext.drawImage(this.partialCanvas, this.partialWidth *
|
|
468
|
+
layoutContext === null || layoutContext === void 0 ? void 0 : layoutContext.drawImage(this.partialCanvas, this.partialWidth * colIndex + this.gap[0] * colIndex, this.partialHeight * rowIndex + this.gap[1] * rowIndex, this.partialWidth, this.partialHeight);
|
|
467
469
|
}
|
|
468
470
|
}
|
|
469
471
|
return layoutCanvas;
|
|
@@ -479,6 +481,26 @@ var renderLayout = function (options, partialCanvas) {
|
|
|
479
481
|
return partialCanvas;
|
|
480
482
|
}
|
|
481
483
|
};
|
|
484
|
+
var generateBackgroundSize = function (options) {
|
|
485
|
+
var _a, _b, _c;
|
|
486
|
+
switch (options.layout) {
|
|
487
|
+
case 'grid':
|
|
488
|
+
{
|
|
489
|
+
var cols = ((_a = options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.cols) || 1;
|
|
490
|
+
var rows = ((_b = options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.rows) || 1;
|
|
491
|
+
var gap = ((_c = options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.gap) || [0, 0];
|
|
492
|
+
return [
|
|
493
|
+
options.width * cols + gap[0] * cols,
|
|
494
|
+
options.height * rows + gap[1] * rows
|
|
495
|
+
];
|
|
496
|
+
}
|
|
497
|
+
default:
|
|
498
|
+
return [
|
|
499
|
+
options.width,
|
|
500
|
+
options.height
|
|
501
|
+
];
|
|
502
|
+
}
|
|
503
|
+
};
|
|
482
504
|
|
|
483
505
|
/**
|
|
484
506
|
* Watermark class
|
|
@@ -523,11 +545,11 @@ var Watermark = /** @class */ (function () {
|
|
|
523
545
|
* Creating a watermark.
|
|
524
546
|
*/
|
|
525
547
|
Watermark.prototype.create = function () {
|
|
526
|
-
var _a, _b, _c, _d
|
|
548
|
+
var _a, _b, _c, _d;
|
|
527
549
|
return __awaiter(this, void 0, void 0, function () {
|
|
528
|
-
var firstDraw, image, watermarkInnerDom, parentElementType;
|
|
529
|
-
return __generator(this, function (
|
|
530
|
-
switch (
|
|
550
|
+
var firstDraw, image, watermarkInnerDom, parentElementType, backgroundSize;
|
|
551
|
+
return __generator(this, function (_e) {
|
|
552
|
+
switch (_e.label) {
|
|
531
553
|
case 0:
|
|
532
554
|
if (!this.validateUnique()) {
|
|
533
555
|
return [2 /*return*/];
|
|
@@ -538,7 +560,7 @@ var Watermark = /** @class */ (function () {
|
|
|
538
560
|
firstDraw = isUndefined(this.watermarkDom);
|
|
539
561
|
return [4 /*yield*/, this.draw()];
|
|
540
562
|
case 1:
|
|
541
|
-
|
|
563
|
+
_e.sent();
|
|
542
564
|
this.layoutCanvas = renderLayout(this.options, this.canvas);
|
|
543
565
|
image = convertImage(this.layoutCanvas);
|
|
544
566
|
this.clearCanvas();
|
|
@@ -548,7 +570,8 @@ var Watermark = /** @class */ (function () {
|
|
|
548
570
|
this.watermarkDom.__WATERMARK__INSTANCE__ = this;
|
|
549
571
|
parentElementType = this.checkParentElementType();
|
|
550
572
|
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 ");
|
|
551
|
-
|
|
573
|
+
backgroundSize = generateBackgroundSize(this.options);
|
|
574
|
+
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 ");
|
|
552
575
|
this.watermarkDom.append(watermarkInnerDom);
|
|
553
576
|
this.parentElement.appendChild(this.watermarkDom);
|
|
554
577
|
if (this.options.mutationObserve) {
|
|
@@ -556,10 +579,10 @@ var Watermark = /** @class */ (function () {
|
|
|
556
579
|
this.bindMutationObserve();
|
|
557
580
|
}
|
|
558
581
|
catch (e) {
|
|
559
|
-
(
|
|
582
|
+
(_b = (_a = this.options).onObserveError) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
560
583
|
}
|
|
561
584
|
}
|
|
562
|
-
firstDraw && ((
|
|
585
|
+
firstDraw && ((_d = (_c = this.options).onSuccess) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
563
586
|
return [2 /*return*/];
|
|
564
587
|
}
|
|
565
588
|
});
|
|
@@ -569,15 +592,8 @@ var Watermark = /** @class */ (function () {
|
|
|
569
592
|
* Delete this watermark.
|
|
570
593
|
*/
|
|
571
594
|
Watermark.prototype.destroy = function () {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
(_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
575
|
-
(_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
|
|
576
|
-
if (!isUndefined(this.checkWatermarkElementRequestID)) {
|
|
577
|
-
cancelAnimationFrame(this.checkWatermarkElementRequestID);
|
|
578
|
-
}
|
|
579
|
-
(_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.remove();
|
|
580
|
-
(_g = (_f = this.options).onDestroyed) === null || _g === void 0 ? void 0 : _g.call(_f);
|
|
595
|
+
this.remove();
|
|
596
|
+
this.watermarkDom = undefined;
|
|
581
597
|
};
|
|
582
598
|
Watermark.prototype.check = function () {
|
|
583
599
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -585,7 +601,7 @@ var Watermark = /** @class */ (function () {
|
|
|
585
601
|
switch (_a.label) {
|
|
586
602
|
case 0:
|
|
587
603
|
if (!!document.body.contains(this.watermarkDom)) return [3 /*break*/, 2];
|
|
588
|
-
this.
|
|
604
|
+
this.remove();
|
|
589
605
|
return [4 /*yield*/, this.create()];
|
|
590
606
|
case 1:
|
|
591
607
|
_a.sent();
|
|
@@ -595,6 +611,17 @@ var Watermark = /** @class */ (function () {
|
|
|
595
611
|
});
|
|
596
612
|
});
|
|
597
613
|
};
|
|
614
|
+
Watermark.prototype.remove = function () {
|
|
615
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
616
|
+
(_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
617
|
+
(_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
618
|
+
(_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
|
|
619
|
+
if (!isUndefined(this.checkWatermarkElementRequestID)) {
|
|
620
|
+
cancelAnimationFrame(this.checkWatermarkElementRequestID);
|
|
621
|
+
}
|
|
622
|
+
(_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.remove();
|
|
623
|
+
(_g = (_f = this.options).onDestroyed) === null || _g === void 0 ? void 0 : _g.call(_f);
|
|
624
|
+
};
|
|
598
625
|
Watermark.prototype.initConfigData = function (args, mode) {
|
|
599
626
|
var _this = this;
|
|
600
627
|
if (mode === void 0) { mode = 'overwrite'; }
|
|
@@ -884,7 +911,7 @@ var Watermark = /** @class */ (function () {
|
|
|
884
911
|
switch (_a.label) {
|
|
885
912
|
case 0:
|
|
886
913
|
if (!!document.body.contains(this.watermarkDom)) return [3 /*break*/, 2];
|
|
887
|
-
this.
|
|
914
|
+
this.remove();
|
|
888
915
|
return [4 /*yield*/, this.create()];
|
|
889
916
|
case 1:
|
|
890
917
|
_a.sent();
|
|
@@ -907,7 +934,7 @@ var Watermark = /** @class */ (function () {
|
|
|
907
934
|
switch (_a.label) {
|
|
908
935
|
case 0:
|
|
909
936
|
if (!(mutationsList.length > 0)) return [3 /*break*/, 2];
|
|
910
|
-
this.
|
|
937
|
+
this.remove();
|
|
911
938
|
return [4 /*yield*/, this.create()];
|
|
912
939
|
case 1:
|
|
913
940
|
_a.sent();
|
|
@@ -936,7 +963,7 @@ var Watermark = /** @class */ (function () {
|
|
|
936
963
|
if (!((item === null || item === void 0 ? void 0 : item.target) === this.watermarkDom ||
|
|
937
964
|
((_a = item === null || item === void 0 ? void 0 : item.removedNodes) === null || _a === void 0 ? void 0 : _a[0]) === this.watermarkDom ||
|
|
938
965
|
(item.type === 'childList' && item.target === this.parentElement && item.target.lastChild !== this.watermarkDom))) return [3 /*break*/, 3];
|
|
939
|
-
this.
|
|
966
|
+
this.remove();
|
|
940
967
|
return [4 /*yield*/, this.create()];
|
|
941
968
|
case 2:
|
|
942
969
|
_b.sent();
|