watermark-js-plus 1.6.4 → 1.6.5
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/src/core/watermark.js +49 -46
- package/dist/ie/es/src/core/watermark.js +49 -46
- package/dist/ie/index.cjs.js +50 -47
- package/dist/ie/index.cjs.js.map +1 -1
- package/dist/ie/index.cjs.min.js +1 -1
- package/dist/ie/index.esm.js +50 -47
- package/dist/ie/index.esm.js.map +1 -1
- package/dist/ie/index.esm.min.js +1 -1
- package/dist/ie/index.iife.js +50 -47
- package/dist/ie/index.iife.js.map +1 -1
- package/dist/ie/index.iife.min.js +1 -1
- package/dist/ie/index.umd.js +50 -47
- package/dist/ie/index.umd.js.map +1 -1
- package/dist/ie/index.umd.min.js +1 -1
- package/dist/index.cjs.js +50 -47
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.esm.js +50 -47
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.iife.js +50 -47
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.umd.js +50 -47
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/types/core/watermark.d.ts +3 -2
- package/package.json +11 -11
|
@@ -64,17 +64,18 @@ var Watermark = /** @class */ (function () {
|
|
|
64
64
|
return [2 /*return*/];
|
|
65
65
|
}
|
|
66
66
|
this.isCreating = true;
|
|
67
|
+
_h.label = 1;
|
|
68
|
+
case 1:
|
|
69
|
+
_h.trys.push([1, , 3, 4]);
|
|
67
70
|
if (!this.validateUnique()) {
|
|
68
|
-
this.isCreating = false;
|
|
69
71
|
return [2 /*return*/];
|
|
70
72
|
}
|
|
71
73
|
if (!this.validateContent()) {
|
|
72
|
-
this.isCreating = false;
|
|
73
74
|
return [2 /*return*/];
|
|
74
75
|
}
|
|
75
76
|
firstDraw = isUndefined(this.watermarkDom);
|
|
76
77
|
return [4 /*yield*/, ((_a = this.watermarkCanvas) === null || _a === void 0 ? void 0 : _a.draw())];
|
|
77
|
-
case
|
|
78
|
+
case 2:
|
|
78
79
|
_h.sent();
|
|
79
80
|
this.layoutCanvas = renderLayout(this.options, (_b = this.watermarkCanvas) === null || _b === void 0 ? void 0 : _b.getCanvas());
|
|
80
81
|
image = convertImage(this.layoutCanvas);
|
|
@@ -84,22 +85,25 @@ var Watermark = /** @class */ (function () {
|
|
|
84
85
|
this.watermarkDom.__WATERMARK__ = 'watermark';
|
|
85
86
|
this.watermarkDom.__WATERMARK__INSTANCE__ = this;
|
|
86
87
|
parentElementType = this.checkParentElementType();
|
|
87
|
-
this.watermarkDom.style.cssText = "\n
|
|
88
|
+
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
89
|
backgroundSize = generateBackgroundSize(this.options);
|
|
89
|
-
watermarkInnerDom.style.cssText = "\n
|
|
90
|
+
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
91
|
this.watermarkDom.appendChild(watermarkInnerDom);
|
|
91
92
|
this.parentElement.appendChild(this.watermarkDom);
|
|
92
93
|
if (this.options.mutationObserve) {
|
|
93
94
|
try {
|
|
94
|
-
this.
|
|
95
|
+
this.bindMutationObserver();
|
|
95
96
|
}
|
|
96
97
|
catch (_j) {
|
|
97
98
|
(_e = (_d = this.options).onObserveError) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
firstDraw && ((_g = (_f = this.options).onSuccess) === null || _g === void 0 ? void 0 : _g.call(_f));
|
|
102
|
+
return [3 /*break*/, 4];
|
|
103
|
+
case 3:
|
|
101
104
|
this.isCreating = false;
|
|
102
|
-
return [
|
|
105
|
+
return [7 /*endfinally*/];
|
|
106
|
+
case 4: return [2 /*return*/];
|
|
103
107
|
}
|
|
104
108
|
});
|
|
105
109
|
});
|
|
@@ -122,7 +126,7 @@ var Watermark = /** @class */ (function () {
|
|
|
122
126
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
123
127
|
(_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
124
128
|
(_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
125
|
-
(_d = this.
|
|
129
|
+
(_d = this.parentObserver) === null || _d === void 0 ? void 0 : _d.disconnect();
|
|
126
130
|
(_f = (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.parentNode) === null || _f === void 0 ? void 0 : _f.removeChild(this.watermarkDom);
|
|
127
131
|
(_h = (_g = this.options).onDestroyed) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
128
132
|
};
|
|
@@ -182,56 +186,55 @@ var Watermark = /** @class */ (function () {
|
|
|
182
186
|
}
|
|
183
187
|
return 'custom';
|
|
184
188
|
};
|
|
185
|
-
Watermark.prototype.
|
|
186
|
-
|
|
187
|
-
|
|
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) {
|
|
189
|
+
Watermark.prototype.recreateOnMutation = function () {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
191
|
+
var _b, _c;
|
|
192
|
+
return __generator(this, function (_d) {
|
|
193
|
+
switch (_d.label) {
|
|
193
194
|
case 0:
|
|
194
|
-
|
|
195
|
+
_d.trys.push([0, 2, , 3]);
|
|
195
196
|
this.remove();
|
|
196
197
|
return [4 /*yield*/, this.create()];
|
|
197
198
|
case 1:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
case 2:
|
|
199
|
+
_d.sent();
|
|
200
|
+
return [3 /*break*/, 3];
|
|
201
|
+
case 2:
|
|
202
|
+
_d.sent();
|
|
203
|
+
(_c = (_b = this.options).onObserveError) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
204
|
+
return [3 /*break*/, 3];
|
|
205
|
+
case 3: return [2 /*return*/];
|
|
201
206
|
}
|
|
202
207
|
});
|
|
203
|
-
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
Watermark.prototype.bindMutationObserver = function () {
|
|
211
|
+
var _this = this;
|
|
212
|
+
if (!this.watermarkDom) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.observer = new MutationObserver(function (mutationsList) {
|
|
216
|
+
if (mutationsList.length > 0) {
|
|
217
|
+
void _this.recreateOnMutation();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
204
220
|
this.observer.observe(this.watermarkDom, {
|
|
205
221
|
attributes: true, // 属性的变动
|
|
222
|
+
attributeFilter: ['style', 'class', 'hidden', 'id'], // 仅监听会影响水印展示或标识的属性
|
|
206
223
|
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
207
224
|
subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
|
|
208
225
|
characterData: true, // 节点内容或节点文本的变动。
|
|
209
226
|
});
|
|
210
|
-
this.
|
|
211
|
-
var
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (!watermarkRemoved) return [3 /*break*/, 3];
|
|
222
|
-
this.remove();
|
|
223
|
-
return [4 /*yield*/, this.create()];
|
|
224
|
-
case 2:
|
|
225
|
-
_a.sent();
|
|
226
|
-
_a.label = 3;
|
|
227
|
-
case 3:
|
|
228
|
-
_i++;
|
|
229
|
-
return [3 /*break*/, 1];
|
|
230
|
-
case 4: return [2 /*return*/];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}); });
|
|
234
|
-
this.parentObserve.observe(this.parentElement, {
|
|
227
|
+
this.parentObserver = new MutationObserver(function (mutationsList) {
|
|
228
|
+
var watermarkDom = _this.watermarkDom;
|
|
229
|
+
if (!watermarkDom) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
var watermarkRemoved = mutationsList.some(function (item) { return Array.from(item.removedNodes).includes(watermarkDom); });
|
|
233
|
+
if (watermarkRemoved) {
|
|
234
|
+
void _this.recreateOnMutation();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
this.parentObserver.observe(this.parentElement, {
|
|
235
238
|
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
236
239
|
});
|
|
237
240
|
};
|
|
@@ -64,17 +64,18 @@ var Watermark = /** @class */ (function () {
|
|
|
64
64
|
return [2 /*return*/];
|
|
65
65
|
}
|
|
66
66
|
this.isCreating = true;
|
|
67
|
+
_h.label = 1;
|
|
68
|
+
case 1:
|
|
69
|
+
_h.trys.push([1, , 3, 4]);
|
|
67
70
|
if (!this.validateUnique()) {
|
|
68
|
-
this.isCreating = false;
|
|
69
71
|
return [2 /*return*/];
|
|
70
72
|
}
|
|
71
73
|
if (!this.validateContent()) {
|
|
72
|
-
this.isCreating = false;
|
|
73
74
|
return [2 /*return*/];
|
|
74
75
|
}
|
|
75
76
|
firstDraw = isUndefined(this.watermarkDom);
|
|
76
77
|
return [4 /*yield*/, ((_a = this.watermarkCanvas) === null || _a === void 0 ? void 0 : _a.draw())];
|
|
77
|
-
case
|
|
78
|
+
case 2:
|
|
78
79
|
_h.sent();
|
|
79
80
|
this.layoutCanvas = renderLayout(this.options, (_b = this.watermarkCanvas) === null || _b === void 0 ? void 0 : _b.getCanvas());
|
|
80
81
|
image = convertImage(this.layoutCanvas);
|
|
@@ -84,22 +85,25 @@ var Watermark = /** @class */ (function () {
|
|
|
84
85
|
this.watermarkDom.__WATERMARK__ = 'watermark';
|
|
85
86
|
this.watermarkDom.__WATERMARK__INSTANCE__ = this;
|
|
86
87
|
parentElementType = this.checkParentElementType();
|
|
87
|
-
this.watermarkDom.style.cssText = "\n
|
|
88
|
+
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
89
|
backgroundSize = generateBackgroundSize(this.options);
|
|
89
|
-
watermarkInnerDom.style.cssText = "\n
|
|
90
|
+
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
91
|
this.watermarkDom.appendChild(watermarkInnerDom);
|
|
91
92
|
this.parentElement.appendChild(this.watermarkDom);
|
|
92
93
|
if (this.options.mutationObserve) {
|
|
93
94
|
try {
|
|
94
|
-
this.
|
|
95
|
+
this.bindMutationObserver();
|
|
95
96
|
}
|
|
96
97
|
catch (_j) {
|
|
97
98
|
(_e = (_d = this.options).onObserveError) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
firstDraw && ((_g = (_f = this.options).onSuccess) === null || _g === void 0 ? void 0 : _g.call(_f));
|
|
102
|
+
return [3 /*break*/, 4];
|
|
103
|
+
case 3:
|
|
101
104
|
this.isCreating = false;
|
|
102
|
-
return [
|
|
105
|
+
return [7 /*endfinally*/];
|
|
106
|
+
case 4: return [2 /*return*/];
|
|
103
107
|
}
|
|
104
108
|
});
|
|
105
109
|
});
|
|
@@ -122,7 +126,7 @@ var Watermark = /** @class */ (function () {
|
|
|
122
126
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
123
127
|
(_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
124
128
|
(_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
125
|
-
(_d = this.
|
|
129
|
+
(_d = this.parentObserver) === null || _d === void 0 ? void 0 : _d.disconnect();
|
|
126
130
|
(_f = (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.parentNode) === null || _f === void 0 ? void 0 : _f.removeChild(this.watermarkDom);
|
|
127
131
|
(_h = (_g = this.options).onDestroyed) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
128
132
|
};
|
|
@@ -182,56 +186,55 @@ var Watermark = /** @class */ (function () {
|
|
|
182
186
|
}
|
|
183
187
|
return 'custom';
|
|
184
188
|
};
|
|
185
|
-
Watermark.prototype.
|
|
186
|
-
|
|
187
|
-
|
|
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) {
|
|
189
|
+
Watermark.prototype.recreateOnMutation = function () {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
191
|
+
var _b, _c;
|
|
192
|
+
return __generator(this, function (_d) {
|
|
193
|
+
switch (_d.label) {
|
|
193
194
|
case 0:
|
|
194
|
-
|
|
195
|
+
_d.trys.push([0, 2, , 3]);
|
|
195
196
|
this.remove();
|
|
196
197
|
return [4 /*yield*/, this.create()];
|
|
197
198
|
case 1:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
case 2:
|
|
199
|
+
_d.sent();
|
|
200
|
+
return [3 /*break*/, 3];
|
|
201
|
+
case 2:
|
|
202
|
+
_d.sent();
|
|
203
|
+
(_c = (_b = this.options).onObserveError) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
204
|
+
return [3 /*break*/, 3];
|
|
205
|
+
case 3: return [2 /*return*/];
|
|
201
206
|
}
|
|
202
207
|
});
|
|
203
|
-
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
Watermark.prototype.bindMutationObserver = function () {
|
|
211
|
+
var _this = this;
|
|
212
|
+
if (!this.watermarkDom) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.observer = new MutationObserver(function (mutationsList) {
|
|
216
|
+
if (mutationsList.length > 0) {
|
|
217
|
+
void _this.recreateOnMutation();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
204
220
|
this.observer.observe(this.watermarkDom, {
|
|
205
221
|
attributes: true, // 属性的变动
|
|
222
|
+
attributeFilter: ['style', 'class', 'hidden', 'id'], // 仅监听会影响水印展示或标识的属性
|
|
206
223
|
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
207
224
|
subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
|
|
208
225
|
characterData: true, // 节点内容或节点文本的变动。
|
|
209
226
|
});
|
|
210
|
-
this.
|
|
211
|
-
var
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (!watermarkRemoved) return [3 /*break*/, 3];
|
|
222
|
-
this.remove();
|
|
223
|
-
return [4 /*yield*/, this.create()];
|
|
224
|
-
case 2:
|
|
225
|
-
_a.sent();
|
|
226
|
-
_a.label = 3;
|
|
227
|
-
case 3:
|
|
228
|
-
_i++;
|
|
229
|
-
return [3 /*break*/, 1];
|
|
230
|
-
case 4: return [2 /*return*/];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}); });
|
|
234
|
-
this.parentObserve.observe(this.parentElement, {
|
|
227
|
+
this.parentObserver = new MutationObserver(function (mutationsList) {
|
|
228
|
+
var watermarkDom = _this.watermarkDom;
|
|
229
|
+
if (!watermarkDom) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
var watermarkRemoved = mutationsList.some(function (item) { return Array.from(item.removedNodes).includes(watermarkDom); });
|
|
233
|
+
if (watermarkRemoved) {
|
|
234
|
+
void _this.recreateOnMutation();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
this.parentObserver.observe(this.parentElement, {
|
|
235
238
|
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
236
239
|
});
|
|
237
240
|
};
|
package/dist/ie/index.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* watermark-js-plus v1.6.
|
|
2
|
+
* watermark-js-plus v1.6.5
|
|
3
3
|
* (c) 2022-2024 Michael Sun
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -5277,17 +5277,18 @@ var Watermark = /** @class */ (function () {
|
|
|
5277
5277
|
return [2 /*return*/];
|
|
5278
5278
|
}
|
|
5279
5279
|
this.isCreating = true;
|
|
5280
|
+
_h.label = 1;
|
|
5281
|
+
case 1:
|
|
5282
|
+
_h.trys.push([1, , 3, 4]);
|
|
5280
5283
|
if (!this.validateUnique()) {
|
|
5281
|
-
this.isCreating = false;
|
|
5282
5284
|
return [2 /*return*/];
|
|
5283
5285
|
}
|
|
5284
5286
|
if (!this.validateContent()) {
|
|
5285
|
-
this.isCreating = false;
|
|
5286
5287
|
return [2 /*return*/];
|
|
5287
5288
|
}
|
|
5288
5289
|
firstDraw = isUndefined(this.watermarkDom);
|
|
5289
5290
|
return [4 /*yield*/, ((_a = this.watermarkCanvas) === null || _a === void 0 ? void 0 : _a.draw())];
|
|
5290
|
-
case
|
|
5291
|
+
case 2:
|
|
5291
5292
|
_h.sent();
|
|
5292
5293
|
this.layoutCanvas = renderLayout(this.options, (_b = this.watermarkCanvas) === null || _b === void 0 ? void 0 : _b.getCanvas());
|
|
5293
5294
|
image = convertImage(this.layoutCanvas);
|
|
@@ -5297,22 +5298,25 @@ var Watermark = /** @class */ (function () {
|
|
|
5297
5298
|
this.watermarkDom.__WATERMARK__ = 'watermark';
|
|
5298
5299
|
this.watermarkDom.__WATERMARK__INSTANCE__ = this;
|
|
5299
5300
|
parentElementType = this.checkParentElementType();
|
|
5300
|
-
this.watermarkDom.style.cssText = "\n
|
|
5301
|
+
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 ");
|
|
5301
5302
|
backgroundSize = generateBackgroundSize(this.options);
|
|
5302
|
-
watermarkInnerDom.style.cssText = "\n
|
|
5303
|
+
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 ");
|
|
5303
5304
|
this.watermarkDom.appendChild(watermarkInnerDom);
|
|
5304
5305
|
this.parentElement.appendChild(this.watermarkDom);
|
|
5305
5306
|
if (this.options.mutationObserve) {
|
|
5306
5307
|
try {
|
|
5307
|
-
this.
|
|
5308
|
+
this.bindMutationObserver();
|
|
5308
5309
|
}
|
|
5309
5310
|
catch (_j) {
|
|
5310
5311
|
(_e = (_d = this.options).onObserveError) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
5311
5312
|
}
|
|
5312
5313
|
}
|
|
5313
5314
|
firstDraw && ((_g = (_f = this.options).onSuccess) === null || _g === void 0 ? void 0 : _g.call(_f));
|
|
5315
|
+
return [3 /*break*/, 4];
|
|
5316
|
+
case 3:
|
|
5314
5317
|
this.isCreating = false;
|
|
5315
|
-
return [
|
|
5318
|
+
return [7 /*endfinally*/];
|
|
5319
|
+
case 4: return [2 /*return*/];
|
|
5316
5320
|
}
|
|
5317
5321
|
});
|
|
5318
5322
|
});
|
|
@@ -5335,7 +5339,7 @@ var Watermark = /** @class */ (function () {
|
|
|
5335
5339
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5336
5340
|
(_b = (_a = this.options).onBeforeDestroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
5337
5341
|
(_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
5338
|
-
(_d = this.
|
|
5342
|
+
(_d = this.parentObserver) === null || _d === void 0 ? void 0 : _d.disconnect();
|
|
5339
5343
|
(_f = (_e = this.watermarkDom) === null || _e === void 0 ? void 0 : _e.parentNode) === null || _f === void 0 ? void 0 : _f.removeChild(this.watermarkDom);
|
|
5340
5344
|
(_h = (_g = this.options).onDestroyed) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
5341
5345
|
};
|
|
@@ -5395,56 +5399,55 @@ var Watermark = /** @class */ (function () {
|
|
|
5395
5399
|
}
|
|
5396
5400
|
return 'custom';
|
|
5397
5401
|
};
|
|
5398
|
-
Watermark.prototype.
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
return
|
|
5402
|
-
|
|
5403
|
-
this.observer = new MutationObserver(function (mutationsList) { return __awaiter(_this, void 0, void 0, function () {
|
|
5404
|
-
return __generator(this, function (_a) {
|
|
5405
|
-
switch (_a.label) {
|
|
5402
|
+
Watermark.prototype.recreateOnMutation = function () {
|
|
5403
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5404
|
+
var _b, _c;
|
|
5405
|
+
return __generator(this, function (_d) {
|
|
5406
|
+
switch (_d.label) {
|
|
5406
5407
|
case 0:
|
|
5407
|
-
|
|
5408
|
+
_d.trys.push([0, 2, , 3]);
|
|
5408
5409
|
this.remove();
|
|
5409
5410
|
return [4 /*yield*/, this.create()];
|
|
5410
5411
|
case 1:
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
case 2:
|
|
5412
|
+
_d.sent();
|
|
5413
|
+
return [3 /*break*/, 3];
|
|
5414
|
+
case 2:
|
|
5415
|
+
_d.sent();
|
|
5416
|
+
(_c = (_b = this.options).onObserveError) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
5417
|
+
return [3 /*break*/, 3];
|
|
5418
|
+
case 3: return [2 /*return*/];
|
|
5414
5419
|
}
|
|
5415
5420
|
});
|
|
5416
|
-
});
|
|
5421
|
+
});
|
|
5422
|
+
};
|
|
5423
|
+
Watermark.prototype.bindMutationObserver = function () {
|
|
5424
|
+
var _this = this;
|
|
5425
|
+
if (!this.watermarkDom) {
|
|
5426
|
+
return;
|
|
5427
|
+
}
|
|
5428
|
+
this.observer = new MutationObserver(function (mutationsList) {
|
|
5429
|
+
if (mutationsList.length > 0) {
|
|
5430
|
+
void _this.recreateOnMutation();
|
|
5431
|
+
}
|
|
5432
|
+
});
|
|
5417
5433
|
this.observer.observe(this.watermarkDom, {
|
|
5418
5434
|
attributes: true, // 属性的变动
|
|
5435
|
+
attributeFilter: ['style', 'class', 'hidden', 'id'], // 仅监听会影响水印展示或标识的属性
|
|
5419
5436
|
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
5420
5437
|
subtree: true, // 布尔值,表示是否将该观察器应用于该节点的所有后代节点。
|
|
5421
5438
|
characterData: true, // 节点内容或节点文本的变动。
|
|
5422
5439
|
});
|
|
5423
|
-
this.
|
|
5424
|
-
var
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
if (!watermarkRemoved) return [3 /*break*/, 3];
|
|
5435
|
-
this.remove();
|
|
5436
|
-
return [4 /*yield*/, this.create()];
|
|
5437
|
-
case 2:
|
|
5438
|
-
_a.sent();
|
|
5439
|
-
_a.label = 3;
|
|
5440
|
-
case 3:
|
|
5441
|
-
_i++;
|
|
5442
|
-
return [3 /*break*/, 1];
|
|
5443
|
-
case 4: return [2 /*return*/];
|
|
5444
|
-
}
|
|
5445
|
-
});
|
|
5446
|
-
}); });
|
|
5447
|
-
this.parentObserve.observe(this.parentElement, {
|
|
5440
|
+
this.parentObserver = new MutationObserver(function (mutationsList) {
|
|
5441
|
+
var watermarkDom = _this.watermarkDom;
|
|
5442
|
+
if (!watermarkDom) {
|
|
5443
|
+
return;
|
|
5444
|
+
}
|
|
5445
|
+
var watermarkRemoved = mutationsList.some(function (item) { return Array.from(item.removedNodes).includes(watermarkDom); });
|
|
5446
|
+
if (watermarkRemoved) {
|
|
5447
|
+
void _this.recreateOnMutation();
|
|
5448
|
+
}
|
|
5449
|
+
});
|
|
5450
|
+
this.parentObserver.observe(this.parentElement, {
|
|
5448
5451
|
childList: true, // 子节点的变动(指新增,删除或者更改)
|
|
5449
5452
|
});
|
|
5450
5453
|
};
|