@scarlett-player/watermark 1.8.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +47 -5
- package/dist/index.js +47 -5
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/version.ts
|
|
29
|
-
var PKG_VERSION = true ? "1.
|
|
29
|
+
var PKG_VERSION = true ? "1.10.0" : "0.0.0-dev";
|
|
30
30
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
|
|
@@ -53,6 +53,9 @@ function createWatermarkPlugin(config = {}) {
|
|
|
53
53
|
const dynamic = config.dynamic ?? false;
|
|
54
54
|
const dynamicInterval = config.dynamicInterval ?? 1e4;
|
|
55
55
|
const showDelay = config.showDelay ?? 0;
|
|
56
|
+
let currentImageUrl = config.imageUrl;
|
|
57
|
+
let currentText = config.text;
|
|
58
|
+
let mutationObserver = null;
|
|
56
59
|
let positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
|
|
57
60
|
const createElement = () => {
|
|
58
61
|
const el = document.createElement("div");
|
|
@@ -63,8 +66,16 @@ function createWatermarkPlugin(config = {}) {
|
|
|
63
66
|
return el;
|
|
64
67
|
};
|
|
65
68
|
const updateContent = (el, imageUrl, text) => {
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
if (imageUrl !== void 0) {
|
|
70
|
+
currentImageUrl = imageUrl;
|
|
71
|
+
currentText = void 0;
|
|
72
|
+
}
|
|
73
|
+
if (text !== void 0) {
|
|
74
|
+
currentText = text;
|
|
75
|
+
currentImageUrl = void 0;
|
|
76
|
+
}
|
|
77
|
+
const img = currentImageUrl;
|
|
78
|
+
const txt = currentText;
|
|
68
79
|
el.innerHTML = "";
|
|
69
80
|
if (img) {
|
|
70
81
|
const imgEl = document.createElement("img");
|
|
@@ -130,6 +141,10 @@ function createWatermarkPlugin(config = {}) {
|
|
|
130
141
|
clearTimeout(showDelayTimer);
|
|
131
142
|
showDelayTimer = null;
|
|
132
143
|
}
|
|
144
|
+
if (mutationObserver) {
|
|
145
|
+
mutationObserver.disconnect();
|
|
146
|
+
mutationObserver = null;
|
|
147
|
+
}
|
|
133
148
|
if (element?.parentNode) {
|
|
134
149
|
element.parentNode.removeChild(element);
|
|
135
150
|
}
|
|
@@ -146,7 +161,35 @@ function createWatermarkPlugin(config = {}) {
|
|
|
146
161
|
api.logger.debug("Watermark plugin initialized");
|
|
147
162
|
element = createElement();
|
|
148
163
|
api.container.appendChild(element);
|
|
164
|
+
mutationObserver = new MutationObserver((mutations) => {
|
|
165
|
+
if (!element || !api) return;
|
|
166
|
+
for (const mutation of mutations) {
|
|
167
|
+
if (mutation.type === "childList") {
|
|
168
|
+
if (mutation.removedNodes.length > 0) {
|
|
169
|
+
let wasRemoved = false;
|
|
170
|
+
mutation.removedNodes.forEach((node) => {
|
|
171
|
+
if (node === element) wasRemoved = true;
|
|
172
|
+
});
|
|
173
|
+
if (wasRemoved && api) {
|
|
174
|
+
api.container.appendChild(element);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} else if (mutation.type === "attributes" && mutation.attributeName === "style") {
|
|
178
|
+
if (element) {
|
|
179
|
+
element.style.opacity = String(opacity);
|
|
180
|
+
element.style.pointerEvents = "none";
|
|
181
|
+
element.style.position = "absolute";
|
|
182
|
+
element.style.zIndex = "10";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
mutationObserver.observe(api.container, { childList: true, subtree: true, attributes: true, attributeFilter: ["style"] });
|
|
149
188
|
const unsubPlay = api.on("playback:play", () => {
|
|
189
|
+
if (showDelayTimer) {
|
|
190
|
+
clearTimeout(showDelayTimer);
|
|
191
|
+
showDelayTimer = null;
|
|
192
|
+
}
|
|
150
193
|
if (showDelay > 0) {
|
|
151
194
|
showDelayTimer = setTimeout(() => {
|
|
152
195
|
show();
|
|
@@ -158,7 +201,6 @@ function createWatermarkPlugin(config = {}) {
|
|
|
158
201
|
}
|
|
159
202
|
});
|
|
160
203
|
const unsubPause = api.on("playback:pause", () => {
|
|
161
|
-
hide();
|
|
162
204
|
stopDynamic();
|
|
163
205
|
if (showDelayTimer) {
|
|
164
206
|
clearTimeout(showDelayTimer);
|
|
@@ -212,7 +254,7 @@ function createWatermarkPlugin(config = {}) {
|
|
|
212
254
|
},
|
|
213
255
|
setPadding(value) {
|
|
214
256
|
currentPadding = Math.max(0, value);
|
|
215
|
-
currentBottomPadding =
|
|
257
|
+
currentBottomPadding = Math.max(value, config.padding ?? 40);
|
|
216
258
|
positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
|
|
217
259
|
setPosition(currentPosition);
|
|
218
260
|
},
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var PKG_VERSION = true ? "1.
|
|
2
|
+
var PKG_VERSION = true ? "1.10.0" : "0.0.0-dev";
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
|
|
@@ -26,6 +26,9 @@ function createWatermarkPlugin(config = {}) {
|
|
|
26
26
|
const dynamic = config.dynamic ?? false;
|
|
27
27
|
const dynamicInterval = config.dynamicInterval ?? 1e4;
|
|
28
28
|
const showDelay = config.showDelay ?? 0;
|
|
29
|
+
let currentImageUrl = config.imageUrl;
|
|
30
|
+
let currentText = config.text;
|
|
31
|
+
let mutationObserver = null;
|
|
29
32
|
let positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
|
|
30
33
|
const createElement = () => {
|
|
31
34
|
const el = document.createElement("div");
|
|
@@ -36,8 +39,16 @@ function createWatermarkPlugin(config = {}) {
|
|
|
36
39
|
return el;
|
|
37
40
|
};
|
|
38
41
|
const updateContent = (el, imageUrl, text) => {
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
if (imageUrl !== void 0) {
|
|
43
|
+
currentImageUrl = imageUrl;
|
|
44
|
+
currentText = void 0;
|
|
45
|
+
}
|
|
46
|
+
if (text !== void 0) {
|
|
47
|
+
currentText = text;
|
|
48
|
+
currentImageUrl = void 0;
|
|
49
|
+
}
|
|
50
|
+
const img = currentImageUrl;
|
|
51
|
+
const txt = currentText;
|
|
41
52
|
el.innerHTML = "";
|
|
42
53
|
if (img) {
|
|
43
54
|
const imgEl = document.createElement("img");
|
|
@@ -103,6 +114,10 @@ function createWatermarkPlugin(config = {}) {
|
|
|
103
114
|
clearTimeout(showDelayTimer);
|
|
104
115
|
showDelayTimer = null;
|
|
105
116
|
}
|
|
117
|
+
if (mutationObserver) {
|
|
118
|
+
mutationObserver.disconnect();
|
|
119
|
+
mutationObserver = null;
|
|
120
|
+
}
|
|
106
121
|
if (element?.parentNode) {
|
|
107
122
|
element.parentNode.removeChild(element);
|
|
108
123
|
}
|
|
@@ -119,7 +134,35 @@ function createWatermarkPlugin(config = {}) {
|
|
|
119
134
|
api.logger.debug("Watermark plugin initialized");
|
|
120
135
|
element = createElement();
|
|
121
136
|
api.container.appendChild(element);
|
|
137
|
+
mutationObserver = new MutationObserver((mutations) => {
|
|
138
|
+
if (!element || !api) return;
|
|
139
|
+
for (const mutation of mutations) {
|
|
140
|
+
if (mutation.type === "childList") {
|
|
141
|
+
if (mutation.removedNodes.length > 0) {
|
|
142
|
+
let wasRemoved = false;
|
|
143
|
+
mutation.removedNodes.forEach((node) => {
|
|
144
|
+
if (node === element) wasRemoved = true;
|
|
145
|
+
});
|
|
146
|
+
if (wasRemoved && api) {
|
|
147
|
+
api.container.appendChild(element);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} else if (mutation.type === "attributes" && mutation.attributeName === "style") {
|
|
151
|
+
if (element) {
|
|
152
|
+
element.style.opacity = String(opacity);
|
|
153
|
+
element.style.pointerEvents = "none";
|
|
154
|
+
element.style.position = "absolute";
|
|
155
|
+
element.style.zIndex = "10";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
mutationObserver.observe(api.container, { childList: true, subtree: true, attributes: true, attributeFilter: ["style"] });
|
|
122
161
|
const unsubPlay = api.on("playback:play", () => {
|
|
162
|
+
if (showDelayTimer) {
|
|
163
|
+
clearTimeout(showDelayTimer);
|
|
164
|
+
showDelayTimer = null;
|
|
165
|
+
}
|
|
123
166
|
if (showDelay > 0) {
|
|
124
167
|
showDelayTimer = setTimeout(() => {
|
|
125
168
|
show();
|
|
@@ -131,7 +174,6 @@ function createWatermarkPlugin(config = {}) {
|
|
|
131
174
|
}
|
|
132
175
|
});
|
|
133
176
|
const unsubPause = api.on("playback:pause", () => {
|
|
134
|
-
hide();
|
|
135
177
|
stopDynamic();
|
|
136
178
|
if (showDelayTimer) {
|
|
137
179
|
clearTimeout(showDelayTimer);
|
|
@@ -185,7 +227,7 @@ function createWatermarkPlugin(config = {}) {
|
|
|
185
227
|
},
|
|
186
228
|
setPadding(value) {
|
|
187
229
|
currentPadding = Math.max(0, value);
|
|
188
|
-
currentBottomPadding =
|
|
230
|
+
currentBottomPadding = Math.max(value, config.padding ?? 40);
|
|
189
231
|
positionStyles = getPositionStyles(currentPadding, currentBottomPadding);
|
|
190
232
|
setPosition(currentPosition);
|
|
191
233
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scarlett-player/watermark",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Watermark Plugin for Scarlett Player - anti-piracy text/image overlay",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsup": "^8.5.1",
|
|
31
31
|
"typescript": "^5.3.0",
|
|
32
32
|
"vitest": "^1.6.0",
|
|
33
|
-
"@scarlett-player/core": "1.
|
|
33
|
+
"@scarlett-player/core": "1.10.0"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"video",
|