watermark-js-plus 1.5.9 → 1.6.1
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 +277 -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 +285 -0
- package/dist/es/src/utils/protection.js +17 -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 +277 -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 +285 -0
- package/dist/ie/es/src/utils/polyfill.js +5 -0
- package/dist/ie/es/src/utils/protection.js +17 -0
- package/dist/ie/es/style.css +1 -0
- package/dist/ie/index.cjs.js +24 -5
- package/dist/ie/index.cjs.js.map +1 -1
- package/dist/ie/index.cjs.min.js +1 -1
- package/dist/ie/index.esm.js +24 -5
- package/dist/ie/index.esm.js.map +1 -1
- package/dist/ie/index.esm.min.js +1 -1
- package/dist/ie/index.iife.js +24 -5
- package/dist/ie/index.iife.js.map +1 -1
- package/dist/ie/index.iife.min.js +1 -1
- package/dist/ie/index.umd.js +24 -5
- package/dist/ie/index.umd.js.map +1 -1
- package/dist/ie/index.umd.min.js +1 -1
- package/dist/index.cjs.js +22 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.esm.js +22 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.iife.js +22 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.umd.js +22 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/types/style/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +37 -19
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
+
|
|
17
|
+
var extendStatics = function(d, b) {
|
|
18
|
+
extendStatics = Object.setPrototypeOf ||
|
|
19
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
20
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
21
|
+
return extendStatics(d, b);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function __extends(d, b) {
|
|
25
|
+
if (typeof b !== "function" && b !== null)
|
|
26
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
27
|
+
extendStatics(d, b);
|
|
28
|
+
function __() { this.constructor = d; }
|
|
29
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var __assign = function() {
|
|
33
|
+
__assign = Object.assign || function __assign(t) {
|
|
34
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
35
|
+
s = arguments[i];
|
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
};
|
|
40
|
+
return __assign.apply(this, arguments);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
44
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
45
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
46
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
47
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
48
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
49
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function __generator(thisArg, body) {
|
|
54
|
+
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);
|
|
55
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
56
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
57
|
+
function step(op) {
|
|
58
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
59
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
60
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
61
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
62
|
+
switch (op[0]) {
|
|
63
|
+
case 0: case 1: t = op; break;
|
|
64
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
65
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
66
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
67
|
+
default:
|
|
68
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
69
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
70
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
71
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
72
|
+
if (t[2]) _.ops.pop();
|
|
73
|
+
_.trys.pop(); continue;
|
|
74
|
+
}
|
|
75
|
+
op = body.call(thisArg, _);
|
|
76
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
77
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
82
|
+
var e = new Error(message);
|
|
83
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export { __assign, __awaiter, __extends, __generator };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { __extends, __assign, __awaiter, __generator } from '../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { convertImage, isFunction } from '../utils/index.js';
|
|
3
|
+
import { Watermark } from './watermark.js';
|
|
4
|
+
import { WatermarkCanvas } from './canvas.js';
|
|
5
|
+
import protection from '../utils/protection.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* BlindWatermark class
|
|
9
|
+
*/
|
|
10
|
+
var BlindWatermark = /** @class */ (function (_super) {
|
|
11
|
+
__extends(BlindWatermark, _super);
|
|
12
|
+
/**
|
|
13
|
+
* BlindWatermark constructor
|
|
14
|
+
* @param props - blind watermark options
|
|
15
|
+
*/
|
|
16
|
+
function BlindWatermark(props) {
|
|
17
|
+
if (props === void 0) { props = {}; }
|
|
18
|
+
var defaultProps = {
|
|
19
|
+
globalAlpha: 0.005,
|
|
20
|
+
mode: 'blind',
|
|
21
|
+
};
|
|
22
|
+
return _super.call(this, __assign(__assign({}, props), defaultProps)) || this;
|
|
23
|
+
}
|
|
24
|
+
BlindWatermark.prototype.changeOptions = function () {
|
|
25
|
+
return __awaiter(this, arguments, void 0, function (args, mode, redraw) {
|
|
26
|
+
if (args === void 0) { args = {}; }
|
|
27
|
+
if (mode === void 0) { mode = 'overwrite'; }
|
|
28
|
+
if (redraw === void 0) { redraw = true; }
|
|
29
|
+
return __generator(this, function (_a) {
|
|
30
|
+
switch (_a.label) {
|
|
31
|
+
case 0:
|
|
32
|
+
args.globalAlpha = 0.005;
|
|
33
|
+
args.mode = 'blind';
|
|
34
|
+
this.initConfigData(args, mode);
|
|
35
|
+
protection(this.options.monitorProtection);
|
|
36
|
+
if (!redraw) return [3 /*break*/, 2];
|
|
37
|
+
this.remove();
|
|
38
|
+
return [4 /*yield*/, this.create()];
|
|
39
|
+
case 1:
|
|
40
|
+
_a.sent();
|
|
41
|
+
_a.label = 2;
|
|
42
|
+
case 2: return [2 /*return*/];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Decode blind watermark.
|
|
49
|
+
* @param props - decode options
|
|
50
|
+
*/
|
|
51
|
+
BlindWatermark.decode = function (props) {
|
|
52
|
+
var _a = props.url, url = _a === void 0 ? '' : _a, _b = props.fillColor, fillColor = _b === void 0 ? '#000' : _b, _c = props.compositeOperation, compositeOperation = _c === void 0 ? 'color-burn' : _c, _d = props.mode, mode = _d === void 0 ? 'canvas' : _d, _e = props.compositeTimes, compositeTimes = _e === void 0 ? 3 : _e, onSuccess = props.onSuccess;
|
|
53
|
+
if (!url) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (mode === 'canvas') {
|
|
57
|
+
var img_1 = new Image();
|
|
58
|
+
img_1.src = url;
|
|
59
|
+
img_1.addEventListener('load', function () {
|
|
60
|
+
var width = img_1.width, height = img_1.height;
|
|
61
|
+
var canvas = WatermarkCanvas.createCanvas(width, height);
|
|
62
|
+
var ctx = canvas.getContext('2d');
|
|
63
|
+
if (!ctx) {
|
|
64
|
+
throw new Error('get context error');
|
|
65
|
+
}
|
|
66
|
+
ctx.drawImage(img_1, 0, 0, width, height);
|
|
67
|
+
ctx.globalCompositeOperation = compositeOperation;
|
|
68
|
+
ctx.fillStyle = fillColor;
|
|
69
|
+
for (var i = 0; i < compositeTimes; i++) {
|
|
70
|
+
ctx.fillRect(0, 0, width, height);
|
|
71
|
+
}
|
|
72
|
+
var resultImage = convertImage(canvas);
|
|
73
|
+
if (isFunction(onSuccess)) {
|
|
74
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resultImage);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return BlindWatermark;
|
|
80
|
+
}(Watermark));
|
|
81
|
+
|
|
82
|
+
export { BlindWatermark };
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { __awaiter, __generator } from '../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { getValue, isFunction, loadImage, isUndefined, convertSVGToImage, createCustomContentSVG } from '../utils/index.js';
|
|
3
|
+
import { generateRecommendOptions } from '../utils/initialization.js';
|
|
4
|
+
|
|
5
|
+
var WatermarkCanvas = /** @class */ (function () {
|
|
6
|
+
function WatermarkCanvas(args, options) {
|
|
7
|
+
this.props = args;
|
|
8
|
+
this.options = options;
|
|
9
|
+
this.canvas = WatermarkCanvas.createCanvas(this.options.width, this.options.height);
|
|
10
|
+
this.recommendOptions = generateRecommendOptions(this.canvas, this.options, this.props);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create an HD canvas.
|
|
14
|
+
* @param width - width of canvas
|
|
15
|
+
* @param height - height of canvas
|
|
16
|
+
*/
|
|
17
|
+
WatermarkCanvas.createCanvas = function (width, height) {
|
|
18
|
+
var _a;
|
|
19
|
+
var ratio = window.devicePixelRatio || 1;
|
|
20
|
+
var canvas = document.createElement('canvas');
|
|
21
|
+
canvas.width = width * ratio; // actual rendered pixel
|
|
22
|
+
canvas.height = height * ratio; // actual rendered pixel
|
|
23
|
+
canvas.style.width = "".concat(width, "px"); // control display size
|
|
24
|
+
canvas.style.height = "".concat(height, "px"); // control display size
|
|
25
|
+
(_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
26
|
+
return canvas;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Clean the canvas
|
|
30
|
+
* @param canvas
|
|
31
|
+
*/
|
|
32
|
+
WatermarkCanvas.clearCanvas = function (canvas) {
|
|
33
|
+
var ctx = canvas.getContext('2d');
|
|
34
|
+
if (ctx === null) {
|
|
35
|
+
throw new Error('get context error');
|
|
36
|
+
}
|
|
37
|
+
ctx.restore();
|
|
38
|
+
ctx.resetTransform();
|
|
39
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
40
|
+
var ratio = window.devicePixelRatio || 1;
|
|
41
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
42
|
+
};
|
|
43
|
+
WatermarkCanvas.prototype.getCanvas = function () {
|
|
44
|
+
return this.canvas;
|
|
45
|
+
};
|
|
46
|
+
WatermarkCanvas.prototype.clear = function () {
|
|
47
|
+
WatermarkCanvas.clearCanvas(this.canvas);
|
|
48
|
+
};
|
|
49
|
+
WatermarkCanvas.prototype.draw = function () {
|
|
50
|
+
var _this = this;
|
|
51
|
+
var ctx = this.canvas.getContext('2d');
|
|
52
|
+
if (ctx === null) {
|
|
53
|
+
throw new Error('get context error');
|
|
54
|
+
}
|
|
55
|
+
if (this.options.auxiliaryLine) {
|
|
56
|
+
ctx.beginPath();
|
|
57
|
+
ctx.rect(0, 0, this.options.width, this.options.height);
|
|
58
|
+
ctx.lineWidth = 1;
|
|
59
|
+
ctx.strokeStyle = '#000';
|
|
60
|
+
ctx.stroke();
|
|
61
|
+
ctx.closePath();
|
|
62
|
+
ctx.beginPath();
|
|
63
|
+
ctx.rect(this.options.translateX, this.options.translateY, 1, 1);
|
|
64
|
+
ctx.lineWidth = 1;
|
|
65
|
+
ctx.strokeStyle = '#f00';
|
|
66
|
+
ctx.stroke();
|
|
67
|
+
ctx.closePath();
|
|
68
|
+
}
|
|
69
|
+
this.setStyle(ctx);
|
|
70
|
+
ctx.save();
|
|
71
|
+
ctx.translate(this.options.translateX, this.options.translateY);
|
|
72
|
+
ctx.rotate(this.options.rotate);
|
|
73
|
+
return new Promise(function (resolve) {
|
|
74
|
+
switch (_this.options.contentType) {
|
|
75
|
+
case 'text':
|
|
76
|
+
_this.drawText(ctx, resolve);
|
|
77
|
+
break;
|
|
78
|
+
case 'image':
|
|
79
|
+
_this.drawImage(ctx, resolve);
|
|
80
|
+
break;
|
|
81
|
+
case 'multi-line-text':
|
|
82
|
+
_this.drawMultiLineText(ctx, resolve);
|
|
83
|
+
break;
|
|
84
|
+
case 'rich-text':
|
|
85
|
+
_this.drawRichText(ctx, resolve);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
WatermarkCanvas.prototype.setStyle = function (ctx) {
|
|
91
|
+
var _a;
|
|
92
|
+
var propName = 'fillStyle';
|
|
93
|
+
if (this.options.textType === 'stroke') {
|
|
94
|
+
propName = 'strokeStyle';
|
|
95
|
+
}
|
|
96
|
+
var style = this.options.fontColor;
|
|
97
|
+
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.advancedStyle) {
|
|
98
|
+
switch (this.options.advancedStyle.type) {
|
|
99
|
+
case 'linear':
|
|
100
|
+
style = this.createLinearGradient(ctx);
|
|
101
|
+
break;
|
|
102
|
+
case 'radial':
|
|
103
|
+
style = this.createRadialGradient(ctx);
|
|
104
|
+
break;
|
|
105
|
+
case 'conic':
|
|
106
|
+
style = this.createConicGradient(ctx);
|
|
107
|
+
break;
|
|
108
|
+
case 'pattern':
|
|
109
|
+
style = this.createPattern(ctx);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
ctx[propName] && style && (ctx[propName] = style);
|
|
114
|
+
this.options.textAlign && (ctx.textAlign = this.options.textAlign);
|
|
115
|
+
this.options.textBaseline && (ctx.textBaseline = this.options.textBaseline);
|
|
116
|
+
ctx.globalAlpha = this.options.globalAlpha;
|
|
117
|
+
if (this.options.shadowStyle) {
|
|
118
|
+
ctx.shadowBlur = getValue(this.options.shadowStyle.shadowBlur, 0);
|
|
119
|
+
ctx.shadowColor = getValue(this.options.shadowStyle.shadowColor, '#00000000');
|
|
120
|
+
ctx.shadowOffsetX = getValue(this.options.shadowStyle.shadowOffsetX, 0);
|
|
121
|
+
ctx.shadowOffsetY = getValue(this.options.shadowStyle.shadowOffsetY, 0);
|
|
122
|
+
}
|
|
123
|
+
if (isFunction(this.options.extraDrawFunc)) {
|
|
124
|
+
this.options.extraDrawFunc(ctx);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
WatermarkCanvas.prototype.createLinearGradient = function (ctx) {
|
|
128
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
129
|
+
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));
|
|
130
|
+
(_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) {
|
|
131
|
+
gradient.addColorStop(item.offset, item.color);
|
|
132
|
+
});
|
|
133
|
+
return gradient;
|
|
134
|
+
};
|
|
135
|
+
WatermarkCanvas.prototype.createConicGradient = function (ctx) {
|
|
136
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
137
|
+
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)));
|
|
138
|
+
(_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) {
|
|
139
|
+
gradient.addColorStop(item.offset, item.color);
|
|
140
|
+
});
|
|
141
|
+
return gradient;
|
|
142
|
+
};
|
|
143
|
+
WatermarkCanvas.prototype.createRadialGradient = function (ctx) {
|
|
144
|
+
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;
|
|
145
|
+
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)));
|
|
146
|
+
(_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) {
|
|
147
|
+
gradient.addColorStop(item.offset, item.color);
|
|
148
|
+
});
|
|
149
|
+
return gradient;
|
|
150
|
+
};
|
|
151
|
+
WatermarkCanvas.prototype.createPattern = function (ctx) {
|
|
152
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
153
|
+
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) || '');
|
|
154
|
+
};
|
|
155
|
+
WatermarkCanvas.prototype.setText = function (ctx, params) {
|
|
156
|
+
var methodName = 'fillText';
|
|
157
|
+
if (this.options.textType === 'stroke') {
|
|
158
|
+
methodName = 'strokeText';
|
|
159
|
+
}
|
|
160
|
+
ctx[methodName] && ctx[methodName](params.text, params.x, params.y, params.maxWidth);
|
|
161
|
+
};
|
|
162
|
+
WatermarkCanvas.prototype.drawText = function (ctx, resolve) {
|
|
163
|
+
this.setText(ctx, {
|
|
164
|
+
text: this.options.content,
|
|
165
|
+
x: 0,
|
|
166
|
+
y: 0 - this.recommendOptions.textLine.yOffsetValue,
|
|
167
|
+
maxWidth: this.options.textRowMaxWidth || this.options.width,
|
|
168
|
+
});
|
|
169
|
+
resolve(ctx.canvas);
|
|
170
|
+
};
|
|
171
|
+
WatermarkCanvas.prototype.drawImage = function (ctx, resolve) {
|
|
172
|
+
var _this = this;
|
|
173
|
+
loadImage(this.options.image).then(function (image) {
|
|
174
|
+
var _a = _this.getImageRect(image), imageWidth = _a.width, imageHeight = _a.height;
|
|
175
|
+
var imagePosition = _this.getDrawImagePosition(imageWidth, imageHeight);
|
|
176
|
+
ctx.drawImage(image, imagePosition.x, imagePosition.y, imageWidth, imageHeight);
|
|
177
|
+
resolve(ctx.canvas);
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
WatermarkCanvas.prototype.drawMultiLineText = function (ctx, resolve) {
|
|
181
|
+
var _this = this;
|
|
182
|
+
// image.width = this.options.width
|
|
183
|
+
// image.height = this.options.height
|
|
184
|
+
// const element = createCustomContentSvg(context, this.options)
|
|
185
|
+
// image.src = convertSVGToImage(element)
|
|
186
|
+
// image.onload = () => {
|
|
187
|
+
// context.translate(this.options.width / 2, this.options.height / 2)
|
|
188
|
+
// context.rotate(this.options.rotate)
|
|
189
|
+
// context.drawImage(
|
|
190
|
+
// image,
|
|
191
|
+
// -this.options.width / 2,
|
|
192
|
+
// -this.options.height / 2,
|
|
193
|
+
// context.canvas.width,
|
|
194
|
+
// context.canvas.height
|
|
195
|
+
// )
|
|
196
|
+
// resolve(canvas)
|
|
197
|
+
// }
|
|
198
|
+
var lines = this.recommendOptions.textLine.data;
|
|
199
|
+
var yOffsetValue = this.recommendOptions.textLine.yOffsetValue;
|
|
200
|
+
lines.forEach(function (text, index) {
|
|
201
|
+
_this.setText(ctx, {
|
|
202
|
+
text: text,
|
|
203
|
+
x: 0,
|
|
204
|
+
y: _this.options.lineHeight * index - yOffsetValue,
|
|
205
|
+
maxWidth: _this.options.textRowMaxWidth || _this.options.width,
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
resolve(ctx.canvas);
|
|
209
|
+
};
|
|
210
|
+
WatermarkCanvas.prototype.drawRichText = function (ctx, resolve) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
212
|
+
var obj;
|
|
213
|
+
var _this = this;
|
|
214
|
+
return __generator(this, function (_a) {
|
|
215
|
+
switch (_a.label) {
|
|
216
|
+
case 0: return [4 /*yield*/, createCustomContentSVG(ctx, this.options)];
|
|
217
|
+
case 1:
|
|
218
|
+
obj = _a.sent();
|
|
219
|
+
loadImage(convertSVGToImage(obj.element), obj.width, obj.height).then(function (image) {
|
|
220
|
+
var imagePosition = _this.getDrawImagePosition(image.width, image.height);
|
|
221
|
+
ctx.drawImage(image, imagePosition.x, imagePosition.y, image.width, image.height);
|
|
222
|
+
resolve(ctx.canvas);
|
|
223
|
+
});
|
|
224
|
+
return [2 /*return*/];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
WatermarkCanvas.prototype.getImageRect = function (image) {
|
|
230
|
+
var rect = { width: this.options.imageWidth || 0, height: this.options.imageHeight || 0 };
|
|
231
|
+
switch (true) {
|
|
232
|
+
case rect.width !== 0 && rect.height === 0:
|
|
233
|
+
rect.height = (rect.width * image.height) / image.width;
|
|
234
|
+
break;
|
|
235
|
+
case rect.width === 0 && rect.height !== 0:
|
|
236
|
+
rect.width = (rect.height * image.width) / image.height;
|
|
237
|
+
break;
|
|
238
|
+
case rect.width === 0 && rect.height === 0:
|
|
239
|
+
rect.width = image.width;
|
|
240
|
+
rect.height = image.height;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
return rect;
|
|
244
|
+
};
|
|
245
|
+
WatermarkCanvas.prototype.getDrawImagePosition = function (imageWidth, imageHeight) {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
var result = {
|
|
248
|
+
x: -imageWidth / 2,
|
|
249
|
+
y: -imageHeight / 2,
|
|
250
|
+
};
|
|
251
|
+
switch (this.options.translatePlacement) {
|
|
252
|
+
case 'top':
|
|
253
|
+
result.x = -imageWidth / 2;
|
|
254
|
+
result.y = 0;
|
|
255
|
+
break;
|
|
256
|
+
case 'top-start':
|
|
257
|
+
result.x = 0;
|
|
258
|
+
result.y = 0;
|
|
259
|
+
break;
|
|
260
|
+
case 'top-end':
|
|
261
|
+
result.x = -imageWidth;
|
|
262
|
+
result.y = 0;
|
|
263
|
+
break;
|
|
264
|
+
case 'bottom':
|
|
265
|
+
result.x = -imageWidth / 2;
|
|
266
|
+
result.y = -imageHeight;
|
|
267
|
+
break;
|
|
268
|
+
case 'bottom-start':
|
|
269
|
+
result.x = 0;
|
|
270
|
+
result.y = -imageHeight;
|
|
271
|
+
break;
|
|
272
|
+
case 'bottom-end':
|
|
273
|
+
result.x = -imageWidth;
|
|
274
|
+
result.y = -imageHeight;
|
|
275
|
+
break;
|
|
276
|
+
case 'left':
|
|
277
|
+
result.x = 0;
|
|
278
|
+
result.y = -imageHeight / 2;
|
|
279
|
+
break;
|
|
280
|
+
case 'right':
|
|
281
|
+
result.x = -imageWidth;
|
|
282
|
+
result.y = -imageHeight / 2;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
!isUndefined((_a = this.props) === null || _a === void 0 ? void 0 : _a.translateX) && (result.x = 0);
|
|
286
|
+
!isUndefined((_b = this.props) === null || _b === void 0 ? void 0 : _b.translateY) && (result.y = 0);
|
|
287
|
+
return result;
|
|
288
|
+
};
|
|
289
|
+
return WatermarkCanvas;
|
|
290
|
+
}());
|
|
291
|
+
|
|
292
|
+
export { WatermarkCanvas };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { __awaiter, __assign, __generator } from '../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { WatermarkCanvas } from './canvas.js';
|
|
3
|
+
import { initialOptions } from '../utils/initialization.js';
|
|
4
|
+
import { renderLayout } from './layout/index.js';
|
|
5
|
+
import { convertImage } from '../utils/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ImageWatermark class
|
|
9
|
+
*/
|
|
10
|
+
var ImageWatermark = /** @class */ (function () {
|
|
11
|
+
/**
|
|
12
|
+
* ImageWatermark constructor
|
|
13
|
+
* @param args - image watermark args
|
|
14
|
+
*/
|
|
15
|
+
function ImageWatermark(args) {
|
|
16
|
+
if (args === void 0) { args = {}; }
|
|
17
|
+
var _a, _b;
|
|
18
|
+
this.drew = false;
|
|
19
|
+
this.props = args;
|
|
20
|
+
this.options = __assign(__assign({}, initialOptions), args);
|
|
21
|
+
if (this.props.crossOrigin) {
|
|
22
|
+
(_a = this.props.dom) === null || _a === void 0 ? void 0 : _a.setAttribute('crossOrigin', 'anonymous');
|
|
23
|
+
}
|
|
24
|
+
this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
|
|
25
|
+
this.originalSrc = (_b = this.props.dom) === null || _b === void 0 ? void 0 : _b.src;
|
|
26
|
+
this.backgroundImage = this.getBackgroundImage();
|
|
27
|
+
}
|
|
28
|
+
ImageWatermark.prototype.create = function () {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
30
|
+
var _a, _b, _c, _d, _e;
|
|
31
|
+
return __generator(this, function (_f) {
|
|
32
|
+
switch (_f.label) {
|
|
33
|
+
case 0:
|
|
34
|
+
if (this.drew) {
|
|
35
|
+
return [2 /*return*/];
|
|
36
|
+
}
|
|
37
|
+
return [4 /*yield*/, ((_a = this.watermarkCanvas) === null || _a === void 0 ? void 0 : _a.draw())];
|
|
38
|
+
case 1:
|
|
39
|
+
_f.sent();
|
|
40
|
+
this.options.layout = 'grid';
|
|
41
|
+
this.options.gridLayoutOptions = __assign(__assign({}, this.options.gridLayoutOptions), { width: (_b = this.backgroundImage) === null || _b === void 0 ? void 0 : _b.width, height: (_c = this.backgroundImage) === null || _c === void 0 ? void 0 : _c.height, backgroundImage: this.backgroundImage });
|
|
42
|
+
this.layoutCanvas = renderLayout(this.options, (_d = this.watermarkCanvas) === null || _d === void 0 ? void 0 : _d.getCanvas());
|
|
43
|
+
this.options.dom.src = convertImage(this.layoutCanvas);
|
|
44
|
+
(_e = this.watermarkCanvas) === null || _e === void 0 ? void 0 : _e.clear();
|
|
45
|
+
this.drew = true;
|
|
46
|
+
return [2 /*return*/];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
ImageWatermark.prototype.destroy = function () {
|
|
52
|
+
this.options.dom.src = this.originalSrc;
|
|
53
|
+
this.drew = false;
|
|
54
|
+
};
|
|
55
|
+
ImageWatermark.prototype.getBackgroundImage = function () {
|
|
56
|
+
if (this.options.dom) {
|
|
57
|
+
return this.options.dom;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return ImageWatermark;
|
|
61
|
+
}());
|
|
62
|
+
|
|
63
|
+
export { ImageWatermark };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { generateMatrix } from '../../utils/index.js';
|
|
2
|
+
import { WatermarkCanvas } from '../canvas.js';
|
|
3
|
+
|
|
4
|
+
var GridLayout = /** @class */ (function () {
|
|
5
|
+
function GridLayout(args, partialCanvas) {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
this.options = args;
|
|
8
|
+
this.partialWidth = this.options.width;
|
|
9
|
+
this.partialHeight = this.options.height;
|
|
10
|
+
this.rows = ((_a = this.options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.rows) || 1;
|
|
11
|
+
this.cols = ((_b = this.options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.cols) || 1;
|
|
12
|
+
this.matrix = ((_c = this.options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.matrix) || generateMatrix(this.rows, this.cols, 1);
|
|
13
|
+
this.gap = ((_d = this.options.gridLayoutOptions) === null || _d === void 0 ? void 0 : _d.gap) || [0, 0];
|
|
14
|
+
this.partialCanvas = partialCanvas;
|
|
15
|
+
}
|
|
16
|
+
GridLayout.prototype.draw = function () {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
18
|
+
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);
|
|
19
|
+
var layoutContext = layoutCanvas.getContext('2d');
|
|
20
|
+
if ((_c = this.options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.backgroundImage) {
|
|
21
|
+
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);
|
|
22
|
+
}
|
|
23
|
+
for (var rowIndex = 0; rowIndex < this.rows; rowIndex++) {
|
|
24
|
+
for (var colIndex = 0; colIndex < this.cols; colIndex++) {
|
|
25
|
+
if (!((_h = (_g = this.matrix) === null || _g === void 0 ? void 0 : _g[rowIndex]) === null || _h === void 0 ? void 0 : _h[colIndex])) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
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);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return layoutCanvas;
|
|
32
|
+
};
|
|
33
|
+
return GridLayout;
|
|
34
|
+
}());
|
|
35
|
+
|
|
36
|
+
export { GridLayout };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GridLayout } from './grid.js';
|
|
2
|
+
|
|
3
|
+
var renderLayout = function (options, partialCanvas) {
|
|
4
|
+
switch (options.layout) {
|
|
5
|
+
case 'grid':
|
|
6
|
+
return new GridLayout(options, partialCanvas).draw();
|
|
7
|
+
default:
|
|
8
|
+
return partialCanvas;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var generateBackgroundSize = function (options) {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
switch (options.layout) {
|
|
14
|
+
case 'grid': {
|
|
15
|
+
var cols = ((_a = options.gridLayoutOptions) === null || _a === void 0 ? void 0 : _a.cols) || 1;
|
|
16
|
+
var rows = ((_b = options.gridLayoutOptions) === null || _b === void 0 ? void 0 : _b.rows) || 1;
|
|
17
|
+
var gap = ((_c = options.gridLayoutOptions) === null || _c === void 0 ? void 0 : _c.gap) || [0, 0];
|
|
18
|
+
return [options.width * cols + gap[0] * cols, options.height * rows + gap[1] * rows];
|
|
19
|
+
}
|
|
20
|
+
default:
|
|
21
|
+
return [options.width, options.height];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { generateBackgroundSize, renderLayout };
|