watermark-js-plus 1.6.0 → 1.6.2
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/es/node_modules/tslib/tslib.es6.js +86 -0
- package/dist/es/src/core/blind.js +82 -0
- package/dist/es/src/core/canvas.js +292 -0
- package/dist/es/src/core/image.js +63 -0
- package/dist/es/src/core/layout/grid.js +36 -0
- package/dist/es/src/core/layout/index.js +25 -0
- package/dist/es/src/core/watermark.js +248 -0
- package/dist/es/src/index.js +3 -0
- package/dist/es/src/utils/index.js +199 -0
- package/dist/es/src/utils/initialization.js +284 -0
- package/dist/es/src/utils/protection.js +13 -0
- package/dist/es/style.css +1 -0
- package/dist/ie/es/_virtual/_commonjsHelpers.js +3 -0
- package/dist/ie/es/_virtual/es.array.fill.js +3 -0
- package/dist/ie/es/_virtual/es.array.fill2.js +3 -0
- package/dist/ie/es/_virtual/es.array.from.js +3 -0
- package/dist/ie/es/_virtual/es.array.from2.js +3 -0
- package/dist/ie/es/_virtual/es.array.includes.js +3 -0
- package/dist/ie/es/_virtual/es.array.includes2.js +3 -0
- package/dist/ie/es/_virtual/es.promise.all.js +3 -0
- package/dist/ie/es/_virtual/es.promise.catch.js +3 -0
- package/dist/ie/es/_virtual/es.promise.constructor.js +3 -0
- package/dist/ie/es/_virtual/es.promise.js +3 -0
- package/dist/ie/es/_virtual/es.promise.race.js +3 -0
- package/dist/ie/es/_virtual/es.promise.reject.js +3 -0
- package/dist/ie/es/_virtual/es.promise.resolve.js +3 -0
- package/dist/ie/es/_virtual/es.promise2.js +3 -0
- package/dist/ie/es/_virtual/make-built-in.js +3 -0
- package/dist/ie/es/_virtual/new-promise-capability.js +3 -0
- package/dist/ie/es/_virtual/object-define-properties.js +3 -0
- package/dist/ie/es/_virtual/object-define-property.js +3 -0
- package/dist/ie/es/_virtual/object-get-own-property-descriptor.js +3 -0
- package/dist/ie/es/_virtual/object-get-own-property-names.js +3 -0
- package/dist/ie/es/_virtual/object-get-own-property-symbols.js +3 -0
- package/dist/ie/es/_virtual/object-property-is-enumerable.js +3 -0
- package/dist/ie/es/_virtual/shared-store.js +3 -0
- package/dist/ie/es/node_modules/core-js/internals/a-callable.js +23 -0
- package/dist/ie/es/node_modules/core-js/internals/a-constructor.js +23 -0
- package/dist/ie/es/node_modules/core-js/internals/a-possible-prototype.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/add-to-unscopables.js +34 -0
- package/dist/ie/es/node_modules/core-js/internals/an-instance.js +20 -0
- package/dist/ie/es/node_modules/core-js/internals/an-object.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/array-fill.js +30 -0
- package/dist/ie/es/node_modules/core-js/internals/array-from.js +66 -0
- package/dist/ie/es/node_modules/core-js/internals/array-includes.js +47 -0
- package/dist/ie/es/node_modules/core-js/internals/array-slice.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/call-with-safe-iteration-closing.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/check-correctness-of-iteration.js +52 -0
- package/dist/ie/es/node_modules/core-js/internals/classof-raw.js +20 -0
- package/dist/ie/es/node_modules/core-js/internals/classof.js +44 -0
- package/dist/ie/es/node_modules/core-js/internals/copy-constructor-properties.js +31 -0
- package/dist/ie/es/node_modules/core-js/internals/create-non-enumerable-property.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/create-property-descriptor.js +18 -0
- package/dist/ie/es/node_modules/core-js/internals/create-property.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/define-built-in-accessor.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/define-built-in.js +42 -0
- package/dist/ie/es/node_modules/core-js/internals/define-global-property.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/descriptors.js +19 -0
- package/dist/ie/es/node_modules/core-js/internals/document-create-element.js +23 -0
- package/dist/ie/es/node_modules/core-js/internals/enum-bug-keys.js +20 -0
- package/dist/ie/es/node_modules/core-js/internals/environment-is-ios-pebble.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/environment-is-ios.js +16 -0
- package/dist/ie/es/node_modules/core-js/internals/environment-is-node.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/environment-is-webos-webkit.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/environment-user-agent.js +18 -0
- package/dist/ie/es/node_modules/core-js/internals/environment-v8-version.js +40 -0
- package/dist/ie/es/node_modules/core-js/internals/environment.js +34 -0
- package/dist/ie/es/node_modules/core-js/internals/export.js +72 -0
- package/dist/ie/es/node_modules/core-js/internals/fails.js +17 -0
- package/dist/ie/es/node_modules/core-js/internals/function-apply.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/function-bind-context.js +27 -0
- package/dist/ie/es/node_modules/core-js/internals/function-bind-native.js +20 -0
- package/dist/ie/es/node_modules/core-js/internals/function-call.js +19 -0
- package/dist/ie/es/node_modules/core-js/internals/function-name.js +30 -0
- package/dist/ie/es/node_modules/core-js/internals/function-uncurry-this-accessor.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/function-uncurry-this-clause.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/function-uncurry-this.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/get-built-in.js +23 -0
- package/dist/ie/es/node_modules/core-js/internals/get-iterator-method.js +29 -0
- package/dist/ie/es/node_modules/core-js/internals/get-iterator.js +29 -0
- package/dist/ie/es/node_modules/core-js/internals/get-method.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/global-this.js +27 -0
- package/dist/ie/es/node_modules/core-js/internals/has-own-property.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/hidden-keys.js +11 -0
- package/dist/ie/es/node_modules/core-js/internals/host-report-errors.js +16 -0
- package/dist/ie/es/node_modules/core-js/internals/html.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/ie8-dom-define.js +25 -0
- package/dist/ie/es/node_modules/core-js/internals/indexed-object.js +29 -0
- package/dist/ie/es/node_modules/core-js/internals/inspect-source.js +28 -0
- package/dist/ie/es/node_modules/core-js/internals/internal-state.js +89 -0
- package/dist/ie/es/node_modules/core-js/internals/is-array-iterator-method.js +23 -0
- package/dist/ie/es/node_modules/core-js/internals/is-callable.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/is-constructor.js +68 -0
- package/dist/ie/es/node_modules/core-js/internals/is-forced.js +35 -0
- package/dist/ie/es/node_modules/core-js/internals/is-null-or-undefined.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/is-object.js +17 -0
- package/dist/ie/es/node_modules/core-js/internals/is-possible-prototype.js +17 -0
- package/dist/ie/es/node_modules/core-js/internals/is-pure.js +11 -0
- package/dist/ie/es/node_modules/core-js/internals/is-symbol.js +28 -0
- package/dist/ie/es/node_modules/core-js/internals/iterate.js +89 -0
- package/dist/ie/es/node_modules/core-js/internals/iterator-close.js +37 -0
- package/dist/ie/es/node_modules/core-js/internals/iterators.js +11 -0
- package/dist/ie/es/node_modules/core-js/internals/length-of-array-like.js +19 -0
- package/dist/ie/es/node_modules/core-js/internals/make-built-in.js +73 -0
- package/dist/ie/es/node_modules/core-js/internals/math-trunc.js +20 -0
- package/dist/ie/es/node_modules/core-js/internals/microtask.js +98 -0
- package/dist/ie/es/node_modules/core-js/internals/new-promise-capability.js +32 -0
- package/dist/ie/es/node_modules/core-js/internals/object-create.js +102 -0
- package/dist/ie/es/node_modules/core-js/internals/object-define-properties.js +37 -0
- package/dist/ie/es/node_modules/core-js/internals/object-define-property.js +59 -0
- package/dist/ie/es/node_modules/core-js/internals/object-get-own-property-descriptor.js +41 -0
- package/dist/ie/es/node_modules/core-js/internals/object-get-own-property-names.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/object-get-own-property-symbols.js +13 -0
- package/dist/ie/es/node_modules/core-js/internals/object-is-prototype-of.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/object-keys-internal.js +36 -0
- package/dist/ie/es/node_modules/core-js/internals/object-keys.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/object-property-is-enumerable.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/object-set-prototype-of.js +43 -0
- package/dist/ie/es/node_modules/core-js/internals/ordinary-to-primitive.js +29 -0
- package/dist/ie/es/node_modules/core-js/internals/own-keys.js +30 -0
- package/dist/ie/es/node_modules/core-js/internals/perform.js +17 -0
- package/dist/ie/es/node_modules/core-js/internals/promise-constructor-detection.js +66 -0
- package/dist/ie/es/node_modules/core-js/internals/promise-native-constructor.js +15 -0
- package/dist/ie/es/node_modules/core-js/internals/promise-resolve.js +26 -0
- package/dist/ie/es/node_modules/core-js/internals/promise-statics-incorrect-iteration.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/queue.js +34 -0
- package/dist/ie/es/node_modules/core-js/internals/require-object-coercible.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/safe-get-built-in.js +25 -0
- package/dist/ie/es/node_modules/core-js/internals/set-species.js +32 -0
- package/dist/ie/es/node_modules/core-js/internals/set-to-string-tag.js +26 -0
- package/dist/ie/es/node_modules/core-js/internals/shared-key.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/shared-store.js +28 -0
- package/dist/ie/es/node_modules/core-js/internals/shared.js +17 -0
- package/dist/ie/es/node_modules/core-js/internals/species-constructor.js +29 -0
- package/dist/ie/es/node_modules/core-js/internals/symbol-constructor-detection.js +32 -0
- package/dist/ie/es/node_modules/core-js/internals/task.js +139 -0
- package/dist/ie/es/node_modules/core-js/internals/to-absolute-index.js +24 -0
- package/dist/ie/es/node_modules/core-js/internals/to-indexed-object.js +20 -0
- package/dist/ie/es/node_modules/core-js/internals/to-integer-or-infinity.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/to-length.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/to-object.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/to-primitive.js +42 -0
- package/dist/ie/es/node_modules/core-js/internals/to-property-key.js +22 -0
- package/dist/ie/es/node_modules/core-js/internals/to-string-tag-support.js +20 -0
- package/dist/ie/es/node_modules/core-js/internals/try-to-string.js +19 -0
- package/dist/ie/es/node_modules/core-js/internals/uid.js +21 -0
- package/dist/ie/es/node_modules/core-js/internals/use-symbol-as-uid.js +18 -0
- package/dist/ie/es/node_modules/core-js/internals/v8-prototype-define-bug.js +25 -0
- package/dist/ie/es/node_modules/core-js/internals/validate-arguments-length.js +16 -0
- package/dist/ie/es/node_modules/core-js/internals/weak-map-basic-detection.js +19 -0
- package/dist/ie/es/node_modules/core-js/internals/well-known-symbol.js +35 -0
- package/dist/ie/es/node_modules/core-js/modules/es.array.fill.js +26 -0
- package/dist/ie/es/node_modules/core-js/modules/es.array.from.js +28 -0
- package/dist/ie/es/node_modules/core-js/modules/es.array.includes.js +36 -0
- package/dist/ie/es/node_modules/core-js/modules/es.promise.all.js +56 -0
- package/dist/ie/es/node_modules/core-js/modules/es.promise.catch.js +43 -0
- package/dist/ie/es/node_modules/core-js/modules/es.promise.constructor.js +323 -0
- package/dist/ie/es/node_modules/core-js/modules/es.promise.js +24 -0
- package/dist/ie/es/node_modules/core-js/modules/es.promise.race.js +43 -0
- package/dist/ie/es/node_modules/core-js/modules/es.promise.reject.js +28 -0
- package/dist/ie/es/node_modules/core-js/modules/es.promise.resolve.js +34 -0
- package/dist/ie/es/node_modules/tslib/tslib.es6.js +86 -0
- package/dist/ie/es/node_modules/whatwg-fetch/fetch.js +643 -0
- package/dist/ie/es/src/core/blind.js +82 -0
- package/dist/ie/es/src/core/canvas.js +292 -0
- package/dist/ie/es/src/core/image.js +63 -0
- package/dist/ie/es/src/core/layout/grid.js +36 -0
- package/dist/ie/es/src/core/layout/index.js +25 -0
- package/dist/ie/es/src/core/watermark.js +248 -0
- package/dist/ie/es/src/index.ie.js +9 -0
- package/dist/ie/es/src/utils/index.js +199 -0
- package/dist/ie/es/src/utils/initialization.js +284 -0
- package/dist/ie/es/src/utils/polyfill.js +5 -0
- package/dist/ie/es/src/utils/protection.js +13 -0
- package/dist/ie/es/style.css +1 -0
- package/dist/ie/index.cjs.js +3 -37
- package/dist/ie/index.cjs.js.map +1 -1
- package/dist/ie/index.cjs.min.js +1 -1
- package/dist/ie/index.esm.js +3 -37
- package/dist/ie/index.esm.js.map +1 -1
- package/dist/ie/index.esm.min.js +1 -1
- package/dist/ie/index.iife.js +3 -37
- package/dist/ie/index.iife.js.map +1 -1
- package/dist/ie/index.iife.min.js +1 -1
- package/dist/ie/index.umd.js +3 -37
- package/dist/ie/index.umd.js.map +1 -1
- package/dist/ie/index.umd.min.js +1 -1
- package/dist/index.cjs.js +1 -35
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.esm.js +1 -35
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.iife.js +1 -35
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.umd.js +1 -35
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/types/core/watermark.d.ts +0 -4
- package/dist/types/style/index.d.ts +1 -1
- package/package.json +41 -22
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { __awaiter, __assign, __generator } from '../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { convertImage, generateAnimationStyle, isUndefined } from '../utils/index.js';
|
|
3
|
+
import { initialOptions } from '../utils/initialization.js';
|
|
4
|
+
import protection from '../utils/protection.js';
|
|
5
|
+
import { renderLayout, generateBackgroundSize } from './layout/index.js';
|
|
6
|
+
import { WatermarkCanvas } from './canvas.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Watermark class
|
|
10
|
+
*/
|
|
11
|
+
var Watermark = /** @class */ (function () {
|
|
12
|
+
/**
|
|
13
|
+
* Watermark constructor
|
|
14
|
+
* @param args - watermark args
|
|
15
|
+
*/
|
|
16
|
+
function Watermark(args) {
|
|
17
|
+
if (args === void 0) { args = {}; }
|
|
18
|
+
this.parentElement = document.body;
|
|
19
|
+
this.isCreating = false;
|
|
20
|
+
this.props = args;
|
|
21
|
+
this.options = __assign(__assign({}, initialOptions), args);
|
|
22
|
+
this.changeParentElement(this.options.parent);
|
|
23
|
+
this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
|
|
24
|
+
protection(this.options.monitorProtection);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Change watermark options
|
|
28
|
+
* @param args
|
|
29
|
+
* @param mode
|
|
30
|
+
* @param redraw
|
|
31
|
+
*/
|
|
32
|
+
Watermark.prototype.changeOptions = function () {
|
|
33
|
+
return __awaiter(this, arguments, void 0, function (args, mode, redraw) {
|
|
34
|
+
if (args === void 0) { args = {}; }
|
|
35
|
+
if (mode === void 0) { mode = 'overwrite'; }
|
|
36
|
+
if (redraw === void 0) { redraw = true; }
|
|
37
|
+
return __generator(this, function (_a) {
|
|
38
|
+
switch (_a.label) {
|
|
39
|
+
case 0:
|
|
40
|
+
this.initConfigData(args, mode);
|
|
41
|
+
protection(this.options.monitorProtection);
|
|
42
|
+
if (!redraw) return [3 /*break*/, 2];
|
|
43
|
+
this.remove();
|
|
44
|
+
return [4 /*yield*/, this.create()];
|
|
45
|
+
case 1:
|
|
46
|
+
_a.sent();
|
|
47
|
+
_a.label = 2;
|
|
48
|
+
case 2: return [2 /*return*/];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Creating a watermark.
|
|
55
|
+
*/
|
|
56
|
+
Watermark.prototype.create = function () {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var firstDraw, image, watermarkInnerDom, parentElementType, backgroundSize;
|
|
59
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
60
|
+
return __generator(this, function (_h) {
|
|
61
|
+
switch (_h.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
if (this.isCreating) {
|
|
64
|
+
return [2 /*return*/];
|
|
65
|
+
}
|
|
66
|
+
this.isCreating = true;
|
|
67
|
+
if (!this.validateUnique()) {
|
|
68
|
+
this.isCreating = false;
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
if (!this.validateContent()) {
|
|
72
|
+
this.isCreating = false;
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
firstDraw = isUndefined(this.watermarkDom);
|
|
76
|
+
return [4 /*yield*/, ((_a = this.watermarkCanvas) === null || _a === void 0 ? void 0 : _a.draw())];
|
|
77
|
+
case 1:
|
|
78
|
+
_h.sent();
|
|
79
|
+
this.layoutCanvas = renderLayout(this.options, (_b = this.watermarkCanvas) === null || _b === void 0 ? void 0 : _b.getCanvas());
|
|
80
|
+
image = convertImage(this.layoutCanvas);
|
|
81
|
+
(_c = this.watermarkCanvas) === null || _c === void 0 ? void 0 : _c.clear();
|
|
82
|
+
this.watermarkDom = document.createElement('div');
|
|
83
|
+
watermarkInnerDom = document.createElement('div');
|
|
84
|
+
this.watermarkDom.__WATERMARK__ = 'watermark';
|
|
85
|
+
this.watermarkDom.__WATERMARK__INSTANCE__ = this;
|
|
86
|
+
parentElementType = this.checkParentElementType();
|
|
87
|
+
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 ");
|
|
88
|
+
backgroundSize = generateBackgroundSize(this.options);
|
|
89
|
+
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 ");
|
|
90
|
+
this.watermarkDom.appendChild(watermarkInnerDom);
|
|
91
|
+
this.parentElement.appendChild(this.watermarkDom);
|
|
92
|
+
if (this.options.mutationObserve) {
|
|
93
|
+
try {
|
|
94
|
+
this.bindMutationObserve();
|
|
95
|
+
}
|
|
96
|
+
catch (_j) {
|
|
97
|
+
(_e = (_d = this.options).onObserveError) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
firstDraw && ((_g = (_f = this.options).onSuccess) === null || _g === void 0 ? void 0 : _g.call(_f));
|
|
101
|
+
this.isCreating = false;
|
|
102
|
+
return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Delete this watermark.
|
|
109
|
+
*/
|
|
110
|
+
Watermark.prototype.destroy = function () {
|
|
111
|
+
this.remove();
|
|
112
|
+
this.watermarkDom = undefined;
|
|
113
|
+
};
|
|
114
|
+
Watermark.prototype.check = function () {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
return [2 /*return*/, this.parentElement.contains(this.watermarkDom)];
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
Watermark.prototype.remove = function () {
|
|
122
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
123
|
+
(_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
124
|
+
(_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
125
|
+
(_d = this.parentObserve) === null || _d === void 0 ? void 0 : _d.disconnect();
|
|
126
|
+
(_f = (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.parentNode) === null || _f === void 0 ? void 0 : _f.removeChild(this.watermarkDom);
|
|
127
|
+
(_h = (_g = this.options).onDestroyed) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
128
|
+
};
|
|
129
|
+
Watermark.prototype.initConfigData = function (args, mode) {
|
|
130
|
+
var _this = this;
|
|
131
|
+
if (mode === void 0) { mode = 'overwrite'; }
|
|
132
|
+
if (mode === 'append') {
|
|
133
|
+
Object.keys(args).forEach(function (key) {
|
|
134
|
+
_this.props && (_this.props[key] = args[key]);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.props = args;
|
|
139
|
+
}
|
|
140
|
+
this.options = __assign(__assign({}, initialOptions), this.props);
|
|
141
|
+
this.changeParentElement(this.options.parent);
|
|
142
|
+
this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
|
|
143
|
+
};
|
|
144
|
+
Watermark.prototype.changeParentElement = function (parent) {
|
|
145
|
+
if (typeof parent === 'string') {
|
|
146
|
+
var parentElement = document.querySelector(parent);
|
|
147
|
+
parentElement && (this.parentElement = parentElement);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
this.parentElement = parent;
|
|
151
|
+
}
|
|
152
|
+
if (!this.parentElement) {
|
|
153
|
+
console.error('[WatermarkJsPlus]: please pass a valid parent element.');
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
Watermark.prototype.validateUnique = function () {
|
|
157
|
+
var result = true;
|
|
158
|
+
Array.from(this.parentElement.childNodes).forEach(function (node) {
|
|
159
|
+
if (!result) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (Object.hasOwnProperty.call(node, '__WATERMARK__')) {
|
|
163
|
+
result = false;
|
|
164
|
+
// throw new Error('duplicate watermark error')
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return result;
|
|
168
|
+
};
|
|
169
|
+
Watermark.prototype.validateContent = function () {
|
|
170
|
+
switch (this.options.contentType) {
|
|
171
|
+
case 'image':
|
|
172
|
+
return Object.hasOwnProperty.call(this.options, 'image');
|
|
173
|
+
case 'multi-line-text':
|
|
174
|
+
case 'rich-text':
|
|
175
|
+
case 'text':
|
|
176
|
+
return this.options.content.length > 0;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
Watermark.prototype.checkParentElementType = function () {
|
|
180
|
+
if (['html', 'body'].includes(this.parentElement.tagName.toLocaleLowerCase())) {
|
|
181
|
+
return 'root';
|
|
182
|
+
}
|
|
183
|
+
return 'custom';
|
|
184
|
+
};
|
|
185
|
+
Watermark.prototype.bindMutationObserve = function () {
|
|
186
|
+
var _this = this;
|
|
187
|
+
if (!this.watermarkDom) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.observer = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
|
|
191
|
+
return __generator(this, function (_a) {
|
|
192
|
+
switch (_a.label) {
|
|
193
|
+
case 0:
|
|
194
|
+
if (!(mutationsList.length > 0)) return [3 /*break*/, 2];
|
|
195
|
+
this.remove();
|
|
196
|
+
return [4 /*yield*/, this.create()];
|
|
197
|
+
case 1:
|
|
198
|
+
_a.sent();
|
|
199
|
+
_a.label = 2;
|
|
200
|
+
case 2: return [2 /*return*/];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}); });
|
|
204
|
+
this.observer.observe(this.watermarkDom, {
|
|
205
|
+
attributes: true, // 属性的变动
|
|
206
|
+
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
207
|
+
subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
|
|
208
|
+
characterData: true, // 节点内容或节点文本的变动。
|
|
209
|
+
});
|
|
210
|
+
this.parentObserve = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
|
|
211
|
+
var _i, mutationsList_1, item;
|
|
212
|
+
var _a;
|
|
213
|
+
return __generator(this, function (_b) {
|
|
214
|
+
switch (_b.label) {
|
|
215
|
+
case 0:
|
|
216
|
+
_i = 0, mutationsList_1 = mutationsList;
|
|
217
|
+
_b.label = 1;
|
|
218
|
+
case 1:
|
|
219
|
+
if (!(_i < mutationsList_1.length)) return [3 /*break*/, 4];
|
|
220
|
+
item = mutationsList_1[_i];
|
|
221
|
+
if (!((item === null || item === void 0 ? void 0 : item.target) === this.watermarkDom ||
|
|
222
|
+
((_a = item === null || item === void 0 ? void 0 : item.removedNodes) === null || _a === void 0 ? void 0 : _a[0]) === this.watermarkDom ||
|
|
223
|
+
(item.type === 'childList' &&
|
|
224
|
+
item.target === this.parentElement &&
|
|
225
|
+
item.target.lastChild !== this.watermarkDom))) return [3 /*break*/, 3];
|
|
226
|
+
this.remove();
|
|
227
|
+
return [4 /*yield*/, this.create()];
|
|
228
|
+
case 2:
|
|
229
|
+
_b.sent();
|
|
230
|
+
_b.label = 3;
|
|
231
|
+
case 3:
|
|
232
|
+
_i++;
|
|
233
|
+
return [3 /*break*/, 1];
|
|
234
|
+
case 4: return [2 /*return*/];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}); });
|
|
238
|
+
this.parentObserve.observe(this.parentElement, {
|
|
239
|
+
attributes: true, // 属性的变动
|
|
240
|
+
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
241
|
+
subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
|
|
242
|
+
characterData: true, // 节点内容或节点文本的变动。
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
return Watermark;
|
|
246
|
+
}());
|
|
247
|
+
|
|
248
|
+
export { Watermark };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { __awaiter, __generator } from '../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
|
|
3
|
+
var convertImage = function (canvas) {
|
|
4
|
+
return canvas.toDataURL('image/png', 1);
|
|
5
|
+
};
|
|
6
|
+
var isFunction = function (value) {
|
|
7
|
+
return typeof value === 'function';
|
|
8
|
+
};
|
|
9
|
+
var isUndefined = function (value) {
|
|
10
|
+
return value === undefined;
|
|
11
|
+
};
|
|
12
|
+
var isString = function (value) {
|
|
13
|
+
return typeof value === 'string';
|
|
14
|
+
};
|
|
15
|
+
var createSVGElement = function (tagName, attrs, namespaceURI) {
|
|
16
|
+
if (attrs === void 0) { attrs = {}; }
|
|
17
|
+
if (namespaceURI === void 0) { namespaceURI = 'http://www.w3.org/2000/svg'; }
|
|
18
|
+
var element = document.createElementNS(namespaceURI, tagName);
|
|
19
|
+
for (var attr in attrs) {
|
|
20
|
+
element.setAttribute(attr, attrs[attr]);
|
|
21
|
+
}
|
|
22
|
+
return element;
|
|
23
|
+
};
|
|
24
|
+
var getMultiLineData = function (ctx, text, maxWidth) {
|
|
25
|
+
var result = [];
|
|
26
|
+
var str = '';
|
|
27
|
+
var word = '';
|
|
28
|
+
for (var i = 0, len = text.length; i < len; i++) {
|
|
29
|
+
word = text.charAt(i);
|
|
30
|
+
if (word === '\n') {
|
|
31
|
+
result.push(str);
|
|
32
|
+
str = '';
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
str += word;
|
|
36
|
+
if (ctx.measureText(str).width > maxWidth) {
|
|
37
|
+
result.push(str.substring(0, str.length - 1));
|
|
38
|
+
str = '';
|
|
39
|
+
i--;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
result.push(str);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
var createCustomContentSVG = function (ctx, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var svgElement, bodyElement, rect, rectWidth, rectHeight, width, height, foreignObjectElement;
|
|
47
|
+
var _a;
|
|
48
|
+
return __generator(this, function (_b) {
|
|
49
|
+
switch (_b.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
svgElement = createSVGElement('svg', {
|
|
52
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
53
|
+
});
|
|
54
|
+
bodyElement = document.createElement('div');
|
|
55
|
+
bodyElement.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
56
|
+
bodyElement.style.cssText = "\n text-align: center;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n font: ".concat(ctx.font, ";\n color: ").concat(options.fontColor, ";\n");
|
|
57
|
+
bodyElement.innerHTML = "<div class='rich-text-content'>".concat(options.content, "</div>");
|
|
58
|
+
document.body.appendChild(bodyElement);
|
|
59
|
+
// convert all images to base64
|
|
60
|
+
return [4 /*yield*/, convertImgToBase64(bodyElement)];
|
|
61
|
+
case 1:
|
|
62
|
+
// convert all images to base64
|
|
63
|
+
_b.sent();
|
|
64
|
+
rect = (_a = bodyElement.querySelector('.rich-text-content')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
65
|
+
rectWidth = rect === null || rect === void 0 ? void 0 : rect.width;
|
|
66
|
+
rectHeight = rect === null || rect === void 0 ? void 0 : rect.height;
|
|
67
|
+
document.body.removeChild(bodyElement);
|
|
68
|
+
width = options.richTextWidth || rectWidth || options.width;
|
|
69
|
+
height = options.richTextHeight || rectHeight || options.height;
|
|
70
|
+
svgElement.setAttribute('width', width.toString());
|
|
71
|
+
svgElement.setAttribute('height', height.toString());
|
|
72
|
+
foreignObjectElement = createSVGElement('foreignObject', {
|
|
73
|
+
width: width.toString(),
|
|
74
|
+
height: height.toString(),
|
|
75
|
+
});
|
|
76
|
+
foreignObjectElement.appendChild(bodyElement);
|
|
77
|
+
svgElement.appendChild(foreignObjectElement);
|
|
78
|
+
return [2 /*return*/, {
|
|
79
|
+
element: svgElement,
|
|
80
|
+
width: width,
|
|
81
|
+
height: height,
|
|
82
|
+
}];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}); };
|
|
86
|
+
function convertImgToBase64(bodyElement) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
88
|
+
var imgElements, _loop_1, _i, _a, img;
|
|
89
|
+
return __generator(this, function (_b) {
|
|
90
|
+
switch (_b.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
imgElements = bodyElement.querySelectorAll('img');
|
|
93
|
+
_loop_1 = function (img) {
|
|
94
|
+
var src, response, blob_1, imgData, error_1;
|
|
95
|
+
return __generator(this, function (_c) {
|
|
96
|
+
switch (_c.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
src = img.getAttribute('src');
|
|
99
|
+
if (!src) return [3 /*break*/, 6];
|
|
100
|
+
_c.label = 1;
|
|
101
|
+
case 1:
|
|
102
|
+
_c.trys.push([1, 5, , 6]);
|
|
103
|
+
return [4 /*yield*/, fetch(src)];
|
|
104
|
+
case 2:
|
|
105
|
+
response = _c.sent();
|
|
106
|
+
return [4 /*yield*/, response.blob()];
|
|
107
|
+
case 3:
|
|
108
|
+
blob_1 = _c.sent();
|
|
109
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
110
|
+
var reader = new FileReader();
|
|
111
|
+
reader.onloadend = function () { return resolve(reader.result); };
|
|
112
|
+
reader.onerror = reject;
|
|
113
|
+
reader.readAsDataURL(blob_1);
|
|
114
|
+
})];
|
|
115
|
+
case 4:
|
|
116
|
+
imgData = _c.sent();
|
|
117
|
+
if (isString(imgData)) {
|
|
118
|
+
img.setAttribute('src', imgData);
|
|
119
|
+
}
|
|
120
|
+
return [3 /*break*/, 6];
|
|
121
|
+
case 5:
|
|
122
|
+
error_1 = _c.sent();
|
|
123
|
+
console.error("Error converting ".concat(src, " to base64:"), error_1);
|
|
124
|
+
return [3 /*break*/, 6];
|
|
125
|
+
case 6: return [2 /*return*/];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
_i = 0, _a = Array.from(imgElements);
|
|
130
|
+
_b.label = 1;
|
|
131
|
+
case 1:
|
|
132
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
133
|
+
img = _a[_i];
|
|
134
|
+
return [5 /*yield**/, _loop_1(img)];
|
|
135
|
+
case 2:
|
|
136
|
+
_b.sent();
|
|
137
|
+
_b.label = 3;
|
|
138
|
+
case 3:
|
|
139
|
+
_i++;
|
|
140
|
+
return [3 /*break*/, 1];
|
|
141
|
+
case 4: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
var convertSVGToImage = function (svg) {
|
|
147
|
+
var richContent = svg.outerHTML
|
|
148
|
+
.replace(/<(img|br|input|hr|embed)(.*?)>/g, '<$1$2/>')
|
|
149
|
+
.replace(/\n/g, '')
|
|
150
|
+
.replace(/\t/g, '')
|
|
151
|
+
.replace(/#/g, '%23');
|
|
152
|
+
return "data:image/svg+xml;charset=utf-8,".concat(richContent);
|
|
153
|
+
};
|
|
154
|
+
var getValue = function (v1, v2) {
|
|
155
|
+
if (isUndefined(v1)) {
|
|
156
|
+
return v2;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return v1;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var loadImage = function (url, width, height) {
|
|
163
|
+
if (width === void 0) { width = undefined; }
|
|
164
|
+
if (height === void 0) { height = undefined; }
|
|
165
|
+
var image = new Image();
|
|
166
|
+
image.setAttribute('crossOrigin', 'anonymous');
|
|
167
|
+
!isUndefined(width) && (image.width = width);
|
|
168
|
+
!isUndefined(height) && (image.height = height);
|
|
169
|
+
image.src = url;
|
|
170
|
+
return new Promise(function (resolve) {
|
|
171
|
+
image.onload = function () {
|
|
172
|
+
resolve(image);
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
var generateMatrix = function (rows, columns, value) {
|
|
177
|
+
return Array.from({ length: rows }, function () { return new Array(columns).fill(value); });
|
|
178
|
+
};
|
|
179
|
+
var generateAnimationStyle = function (movable, backgroundRepeat) {
|
|
180
|
+
if (!movable) {
|
|
181
|
+
return '';
|
|
182
|
+
}
|
|
183
|
+
var horizontalDuration = Math.random() * (8 - 2) + 2;
|
|
184
|
+
var verticalDuration = Math.random() * (4 - 2) + 2;
|
|
185
|
+
switch (backgroundRepeat) {
|
|
186
|
+
case 'repeat':
|
|
187
|
+
return 'animation: 200s linear 0s infinite alternate watermark !important;';
|
|
188
|
+
case 'repeat-x':
|
|
189
|
+
return "animation: ".concat(horizontalDuration, "s ease-in 0s infinite alternate watermark-vertical !important;'");
|
|
190
|
+
case 'repeat-y':
|
|
191
|
+
return "animation: ".concat(verticalDuration, "s ease-out 0s infinite alternate watermark-horizontal !important;'");
|
|
192
|
+
case 'no-repeat':
|
|
193
|
+
return "animation: ".concat(horizontalDuration, "s ease-in 0s infinite alternate watermark-horizontal, ").concat(verticalDuration, "s ease-out 0s infinite alternate watermark-vertical !important;");
|
|
194
|
+
default:
|
|
195
|
+
return '';
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export { convertImage, convertSVGToImage, createCustomContentSVG, createSVGElement, generateAnimationStyle, generateMatrix, getMultiLineData, getValue, isFunction, isString, isUndefined, loadImage };
|