watermark-js-plus 0.9.10 → 0.9.12
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 +42 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.esm.js +42 -30
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.iife.js +42 -30
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.umd.js +42 -30
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/types/src/core/canvas.d.ts +14 -0
- package/dist/types/src/core/watermark.d.ts +0 -7
- package/package.json +5 -5
package/dist/index.cjs.js
CHANGED
|
@@ -444,6 +444,43 @@ var bootstrap = (function () {
|
|
|
444
444
|
}
|
|
445
445
|
});
|
|
446
446
|
|
|
447
|
+
// import { WatermarkOptions } from '../types'
|
|
448
|
+
var WatermarkCanvas = /** @class */ (function () {
|
|
449
|
+
function WatermarkCanvas() {
|
|
450
|
+
}
|
|
451
|
+
// constructor (args: Partial<WatermarkOptions> = {}) {
|
|
452
|
+
// }
|
|
453
|
+
/**
|
|
454
|
+
* Create an HD canvas.
|
|
455
|
+
* @param width - width of canvas
|
|
456
|
+
* @param height - height of canvas
|
|
457
|
+
*/
|
|
458
|
+
WatermarkCanvas.createCanvas = function (width, height) {
|
|
459
|
+
var _a;
|
|
460
|
+
var ratio = window.devicePixelRatio || 1;
|
|
461
|
+
var canvas = document.createElement('canvas');
|
|
462
|
+
canvas.width = width * ratio; // actual rendered pixel
|
|
463
|
+
canvas.height = height * ratio; // actual rendered pixel
|
|
464
|
+
canvas.style.width = "".concat(width, "px"); // control display size
|
|
465
|
+
canvas.style.height = "".concat(height, "px"); // control display size
|
|
466
|
+
(_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
467
|
+
return canvas;
|
|
468
|
+
};
|
|
469
|
+
/**
|
|
470
|
+
* Clean the canvas
|
|
471
|
+
* @param canvas
|
|
472
|
+
*/
|
|
473
|
+
WatermarkCanvas.clearCanvas = function (canvas) {
|
|
474
|
+
var ctx = canvas.getContext('2d');
|
|
475
|
+
if (ctx === null) {
|
|
476
|
+
throw new Error('get context error');
|
|
477
|
+
}
|
|
478
|
+
ctx.restore();
|
|
479
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
480
|
+
};
|
|
481
|
+
return WatermarkCanvas;
|
|
482
|
+
}());
|
|
483
|
+
|
|
447
484
|
var GridLayout = /** @class */ (function () {
|
|
448
485
|
function GridLayout(args, partialCanvas) {
|
|
449
486
|
var _a, _b, _c, _d;
|
|
@@ -458,7 +495,7 @@ var GridLayout = /** @class */ (function () {
|
|
|
458
495
|
}
|
|
459
496
|
GridLayout.prototype.draw = function () {
|
|
460
497
|
var _a, _b;
|
|
461
|
-
var layoutCanvas =
|
|
498
|
+
var layoutCanvas = WatermarkCanvas.createCanvas(this.partialWidth * this.cols + this.gap[0] * this.cols, this.partialHeight * this.rows + this.gap[1] * this.rows);
|
|
462
499
|
var layoutContext = layoutCanvas.getContext('2d');
|
|
463
500
|
for (var rowIndex = 0; rowIndex < this.rows; rowIndex++) {
|
|
464
501
|
for (var colIndex = 0; colIndex < this.cols; colIndex++) {
|
|
@@ -516,26 +553,10 @@ var Watermark = /** @class */ (function () {
|
|
|
516
553
|
this.props = args;
|
|
517
554
|
this.options = Object.assign({}, initialOptions, args);
|
|
518
555
|
this.changeParentElement(this.options.parent);
|
|
519
|
-
this.canvas =
|
|
556
|
+
this.canvas = WatermarkCanvas.createCanvas(this.options.width, this.options.height);
|
|
520
557
|
this.recommendOptions = generateRecommendOptions(this.canvas, this.options, this.props);
|
|
521
558
|
bootstrap();
|
|
522
559
|
}
|
|
523
|
-
/**
|
|
524
|
-
* Create an HD canvas.
|
|
525
|
-
* @param width - width of canvas
|
|
526
|
-
* @param height - height of canvas
|
|
527
|
-
*/
|
|
528
|
-
Watermark.createCanvas = function (width, height) {
|
|
529
|
-
var _a;
|
|
530
|
-
var ratio = window.devicePixelRatio || 1;
|
|
531
|
-
var canvas = document.createElement('canvas');
|
|
532
|
-
canvas.width = width * ratio; // actual rendered pixel
|
|
533
|
-
canvas.height = height * ratio; // actual rendered pixel
|
|
534
|
-
canvas.style.width = "".concat(width, "px"); // control display size
|
|
535
|
-
canvas.style.height = "".concat(height, "px"); // control display size
|
|
536
|
-
(_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
537
|
-
return canvas;
|
|
538
|
-
};
|
|
539
560
|
Watermark.prototype.changeOptions = function (args, mode) {
|
|
540
561
|
if (args === void 0) { args = {}; }
|
|
541
562
|
if (mode === void 0) { mode = 'overwrite'; }
|
|
@@ -563,7 +584,7 @@ var Watermark = /** @class */ (function () {
|
|
|
563
584
|
_e.sent();
|
|
564
585
|
this.layoutCanvas = renderLayout(this.options, this.canvas);
|
|
565
586
|
image = convertImage(this.layoutCanvas);
|
|
566
|
-
|
|
587
|
+
WatermarkCanvas.clearCanvas(this.canvas);
|
|
567
588
|
this.watermarkDom = document.createElement('div');
|
|
568
589
|
watermarkInnerDom = document.createElement('div');
|
|
569
590
|
this.watermarkDom.__WATERMARK__ = 'watermark';
|
|
@@ -635,7 +656,7 @@ var Watermark = /** @class */ (function () {
|
|
|
635
656
|
});
|
|
636
657
|
}
|
|
637
658
|
this.changeParentElement(this.options.parent);
|
|
638
|
-
this.canvas =
|
|
659
|
+
this.canvas = WatermarkCanvas.createCanvas(this.options.width, this.options.height);
|
|
639
660
|
this.recommendOptions = generateRecommendOptions(this.canvas, this.options, this.props);
|
|
640
661
|
// document.body?.appendChild(this.canvas)
|
|
641
662
|
};
|
|
@@ -982,15 +1003,6 @@ var Watermark = /** @class */ (function () {
|
|
|
982
1003
|
characterData: true // 节点内容或节点文本的变动。
|
|
983
1004
|
});
|
|
984
1005
|
};
|
|
985
|
-
Watermark.prototype.clearCanvas = function () {
|
|
986
|
-
var ctx = this.canvas.getContext('2d');
|
|
987
|
-
if (ctx === null) {
|
|
988
|
-
throw new Error('get context error');
|
|
989
|
-
}
|
|
990
|
-
ctx.restore();
|
|
991
|
-
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
992
|
-
// this.canvas.width = this.options.w
|
|
993
|
-
};
|
|
994
1006
|
return Watermark;
|
|
995
1007
|
}());
|
|
996
1008
|
|
|
@@ -1029,7 +1041,7 @@ var BlindWatermark = /** @class */ (function (_super) {
|
|
|
1029
1041
|
img_1.onload = function () {
|
|
1030
1042
|
var _a;
|
|
1031
1043
|
var width = img_1.width, height = img_1.height;
|
|
1032
|
-
var canvas =
|
|
1044
|
+
var canvas = WatermarkCanvas.createCanvas(width, height);
|
|
1033
1045
|
var ctx = canvas.getContext('2d');
|
|
1034
1046
|
if (ctx === null) {
|
|
1035
1047
|
throw new Error('get context error');
|