@scarlett-player/watermark 1.0.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/LICENSE +21 -0
- package/dist/index.cjs +206 -0
- package/dist/index.d.cts +83 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +181 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hackney Enterprises Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createWatermarkPlugin: () => createWatermarkPlugin,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
|
|
28
|
+
var POSITION_STYLES = {
|
|
29
|
+
"top-left": "top:10px;left:10px;",
|
|
30
|
+
"top-right": "top:10px;right:10px;",
|
|
31
|
+
"bottom-left": "bottom:40px;left:10px;",
|
|
32
|
+
"bottom-right": "bottom:40px;right:10px;",
|
|
33
|
+
"center": "top:50%;left:50%;transform:translate(-50%,-50%);"
|
|
34
|
+
};
|
|
35
|
+
function createWatermarkPlugin(config = {}) {
|
|
36
|
+
let api = null;
|
|
37
|
+
let element = null;
|
|
38
|
+
let dynamicTimer = null;
|
|
39
|
+
let showDelayTimer = null;
|
|
40
|
+
let currentPosition = config.position || "bottom-right";
|
|
41
|
+
const opacity = config.opacity ?? 0.5;
|
|
42
|
+
const fontSize = config.fontSize ?? 14;
|
|
43
|
+
const dynamic = config.dynamic ?? false;
|
|
44
|
+
const dynamicInterval = config.dynamicInterval ?? 1e4;
|
|
45
|
+
const showDelay = config.showDelay ?? 0;
|
|
46
|
+
const createElement = () => {
|
|
47
|
+
const el = document.createElement("div");
|
|
48
|
+
el.className = "sp-watermark sp-watermark--hidden";
|
|
49
|
+
el.style.cssText = `position:absolute;z-index:10;pointer-events:none;opacity:${opacity};font-size:${fontSize}px;color:#fff;text-shadow:0 1px 2px rgba(0,0,0,0.6);font-family:sans-serif;transition:all 0.5s ease;${POSITION_STYLES[currentPosition]}`;
|
|
50
|
+
el.setAttribute("data-position", currentPosition);
|
|
51
|
+
updateContent(el);
|
|
52
|
+
return el;
|
|
53
|
+
};
|
|
54
|
+
const updateContent = (el, imageUrl, text) => {
|
|
55
|
+
const img = imageUrl || config.imageUrl;
|
|
56
|
+
const txt = text || config.text;
|
|
57
|
+
el.innerHTML = "";
|
|
58
|
+
if (img) {
|
|
59
|
+
const imgEl = document.createElement("img");
|
|
60
|
+
imgEl.src = img;
|
|
61
|
+
imgEl.style.cssText = `max-height:${fontSize * 2}px;opacity:inherit;display:block;`;
|
|
62
|
+
imgEl.alt = "";
|
|
63
|
+
el.appendChild(imgEl);
|
|
64
|
+
} else if (txt) {
|
|
65
|
+
el.textContent = txt;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const setPosition = (position) => {
|
|
69
|
+
if (!element) return;
|
|
70
|
+
currentPosition = position;
|
|
71
|
+
element.style.top = "";
|
|
72
|
+
element.style.right = "";
|
|
73
|
+
element.style.bottom = "";
|
|
74
|
+
element.style.left = "";
|
|
75
|
+
element.style.transform = "";
|
|
76
|
+
const styles = POSITION_STYLES[position];
|
|
77
|
+
styles.split(";").filter(Boolean).forEach((rule) => {
|
|
78
|
+
const colonIdx = rule.indexOf(":");
|
|
79
|
+
if (colonIdx === -1) return;
|
|
80
|
+
const prop = rule.slice(0, colonIdx).trim();
|
|
81
|
+
const val = rule.slice(colonIdx + 1).trim();
|
|
82
|
+
if (prop && val) {
|
|
83
|
+
element.style.setProperty(prop, val);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
element.setAttribute("data-position", position);
|
|
87
|
+
const isVisible = element.classList.contains("sp-watermark--visible");
|
|
88
|
+
const visClass = isVisible ? " sp-watermark--visible" : " sp-watermark--hidden";
|
|
89
|
+
element.className = `sp-watermark sp-watermark--${position}${visClass}${dynamic ? " sp-watermark--dynamic" : ""}`;
|
|
90
|
+
};
|
|
91
|
+
const randomizePosition = () => {
|
|
92
|
+
const available = POSITIONS.filter((p) => p !== currentPosition);
|
|
93
|
+
const next = available[Math.floor(Math.random() * available.length)];
|
|
94
|
+
setPosition(next);
|
|
95
|
+
};
|
|
96
|
+
const show = () => {
|
|
97
|
+
if (!element) return;
|
|
98
|
+
element.classList.remove("sp-watermark--hidden");
|
|
99
|
+
element.classList.add("sp-watermark--visible");
|
|
100
|
+
};
|
|
101
|
+
const hide = () => {
|
|
102
|
+
if (!element) return;
|
|
103
|
+
element.classList.remove("sp-watermark--visible");
|
|
104
|
+
element.classList.add("sp-watermark--hidden");
|
|
105
|
+
};
|
|
106
|
+
const startDynamic = () => {
|
|
107
|
+
if (!dynamic || dynamicTimer) return;
|
|
108
|
+
dynamicTimer = setInterval(randomizePosition, dynamicInterval);
|
|
109
|
+
};
|
|
110
|
+
const stopDynamic = () => {
|
|
111
|
+
if (dynamicTimer) {
|
|
112
|
+
clearInterval(dynamicTimer);
|
|
113
|
+
dynamicTimer = null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const cleanup = () => {
|
|
117
|
+
stopDynamic();
|
|
118
|
+
if (showDelayTimer) {
|
|
119
|
+
clearTimeout(showDelayTimer);
|
|
120
|
+
showDelayTimer = null;
|
|
121
|
+
}
|
|
122
|
+
if (element?.parentNode) {
|
|
123
|
+
element.parentNode.removeChild(element);
|
|
124
|
+
}
|
|
125
|
+
element = null;
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
id: "watermark",
|
|
129
|
+
name: "Watermark",
|
|
130
|
+
version: "1.0.0",
|
|
131
|
+
type: "feature",
|
|
132
|
+
description: "Anti-piracy watermark overlay with text/image support and dynamic repositioning",
|
|
133
|
+
init(pluginApi) {
|
|
134
|
+
api = pluginApi;
|
|
135
|
+
api.logger.debug("Watermark plugin initialized");
|
|
136
|
+
element = createElement();
|
|
137
|
+
api.container.appendChild(element);
|
|
138
|
+
const unsubPlay = api.on("playback:play", () => {
|
|
139
|
+
if (showDelay > 0) {
|
|
140
|
+
showDelayTimer = setTimeout(() => {
|
|
141
|
+
show();
|
|
142
|
+
startDynamic();
|
|
143
|
+
}, showDelay);
|
|
144
|
+
} else {
|
|
145
|
+
show();
|
|
146
|
+
startDynamic();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const unsubPause = api.on("playback:pause", () => {
|
|
150
|
+
hide();
|
|
151
|
+
stopDynamic();
|
|
152
|
+
if (showDelayTimer) {
|
|
153
|
+
clearTimeout(showDelayTimer);
|
|
154
|
+
showDelayTimer = null;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const unsubEnded = api.on("playback:ended", () => {
|
|
158
|
+
hide();
|
|
159
|
+
stopDynamic();
|
|
160
|
+
});
|
|
161
|
+
const unsubChange = api.on("playlist:change", ({ track }) => {
|
|
162
|
+
if (!element || !track) return;
|
|
163
|
+
const metadata = track.metadata;
|
|
164
|
+
if (metadata) {
|
|
165
|
+
const watermarkUrl = metadata.watermarkUrl;
|
|
166
|
+
const watermarkText = metadata.watermarkText;
|
|
167
|
+
if (watermarkUrl || watermarkText) {
|
|
168
|
+
updateContent(element, watermarkUrl, watermarkText);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
api.onDestroy(() => {
|
|
173
|
+
unsubPlay();
|
|
174
|
+
unsubPause();
|
|
175
|
+
unsubEnded();
|
|
176
|
+
unsubChange();
|
|
177
|
+
cleanup();
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
destroy() {
|
|
181
|
+
api?.logger.debug("Watermark plugin destroyed");
|
|
182
|
+
cleanup();
|
|
183
|
+
api = null;
|
|
184
|
+
},
|
|
185
|
+
setText(text) {
|
|
186
|
+
if (element) updateContent(element, void 0, text);
|
|
187
|
+
},
|
|
188
|
+
setImage(imageUrl) {
|
|
189
|
+
if (element) updateContent(element, imageUrl);
|
|
190
|
+
},
|
|
191
|
+
setPosition,
|
|
192
|
+
setOpacity(value) {
|
|
193
|
+
if (element) element.style.opacity = String(Math.max(0, Math.min(1, value)));
|
|
194
|
+
},
|
|
195
|
+
show,
|
|
196
|
+
hide,
|
|
197
|
+
getConfig() {
|
|
198
|
+
return { ...config, position: currentPosition, opacity: element ? parseFloat(element.style.opacity) || opacity : opacity };
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
var index_default = createWatermarkPlugin;
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
createWatermarkPlugin
|
|
206
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Plugin } from '@scarlett-player/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Watermark Plugin Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
type WatermarkPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'center';
|
|
8
|
+
interface WatermarkConfig {
|
|
9
|
+
/** Text content to display (ignored if imageUrl is set) */
|
|
10
|
+
text?: string;
|
|
11
|
+
/** Image URL to display instead of text */
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
/** Position on the player — default: 'bottom-right' */
|
|
14
|
+
position?: WatermarkPosition;
|
|
15
|
+
/** Opacity 0-1 — default: 0.5 */
|
|
16
|
+
opacity?: number;
|
|
17
|
+
/** Font size in px — default: 14 */
|
|
18
|
+
fontSize?: number;
|
|
19
|
+
/** Whether to periodically move the watermark to a random position — default: false */
|
|
20
|
+
dynamic?: boolean;
|
|
21
|
+
/** Interval in ms for dynamic repositioning — default: 10000 */
|
|
22
|
+
dynamicInterval?: number;
|
|
23
|
+
/** Delay in ms before showing watermark after play — default: 0 */
|
|
24
|
+
showDelay?: number;
|
|
25
|
+
/** Index signature for PluginConfig compatibility */
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface IWatermarkPlugin extends Plugin {
|
|
29
|
+
/** Update the watermark to display the given text */
|
|
30
|
+
setText(text: string): void;
|
|
31
|
+
/** Update the watermark to display the given image */
|
|
32
|
+
setImage(imageUrl: string): void;
|
|
33
|
+
/** Move the watermark to a new position */
|
|
34
|
+
setPosition(position: WatermarkPosition): void;
|
|
35
|
+
/** Set watermark opacity (0-1) */
|
|
36
|
+
setOpacity(opacity: number): void;
|
|
37
|
+
/** Show the watermark */
|
|
38
|
+
show(): void;
|
|
39
|
+
/** Hide the watermark */
|
|
40
|
+
hide(): void;
|
|
41
|
+
/** Get the current watermark configuration */
|
|
42
|
+
getConfig(): WatermarkConfig;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Watermark Plugin for Scarlett Player
|
|
47
|
+
*
|
|
48
|
+
* Provides anti-piracy watermark overlay with:
|
|
49
|
+
* - Text or image rendering
|
|
50
|
+
* - Configurable position and opacity
|
|
51
|
+
* - Dynamic repositioning mode (moves periodically)
|
|
52
|
+
* - Show delay
|
|
53
|
+
* - Per-track watermark updates via playlist:change metadata
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create a Watermark Plugin instance.
|
|
58
|
+
*
|
|
59
|
+
* @param config - Plugin configuration
|
|
60
|
+
* @returns Watermark Plugin instance
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { createWatermarkPlugin } from '@scarlett-player/watermark';
|
|
65
|
+
*
|
|
66
|
+
* const player = new ScarlettPlayer({
|
|
67
|
+
* container: '#player',
|
|
68
|
+
* plugins: [
|
|
69
|
+
* createWatermarkPlugin({
|
|
70
|
+
* text: 'user@example.com',
|
|
71
|
+
* position: 'bottom-right',
|
|
72
|
+
* opacity: 0.4,
|
|
73
|
+
* dynamic: true,
|
|
74
|
+
* dynamicInterval: 15000,
|
|
75
|
+
* showDelay: 20000,
|
|
76
|
+
* }),
|
|
77
|
+
* ],
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function createWatermarkPlugin(config?: WatermarkConfig): IWatermarkPlugin;
|
|
82
|
+
|
|
83
|
+
export { type IWatermarkPlugin, type WatermarkConfig, type WatermarkPosition, createWatermarkPlugin, createWatermarkPlugin as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Plugin } from '@scarlett-player/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Watermark Plugin Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
type WatermarkPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'center';
|
|
8
|
+
interface WatermarkConfig {
|
|
9
|
+
/** Text content to display (ignored if imageUrl is set) */
|
|
10
|
+
text?: string;
|
|
11
|
+
/** Image URL to display instead of text */
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
/** Position on the player — default: 'bottom-right' */
|
|
14
|
+
position?: WatermarkPosition;
|
|
15
|
+
/** Opacity 0-1 — default: 0.5 */
|
|
16
|
+
opacity?: number;
|
|
17
|
+
/** Font size in px — default: 14 */
|
|
18
|
+
fontSize?: number;
|
|
19
|
+
/** Whether to periodically move the watermark to a random position — default: false */
|
|
20
|
+
dynamic?: boolean;
|
|
21
|
+
/** Interval in ms for dynamic repositioning — default: 10000 */
|
|
22
|
+
dynamicInterval?: number;
|
|
23
|
+
/** Delay in ms before showing watermark after play — default: 0 */
|
|
24
|
+
showDelay?: number;
|
|
25
|
+
/** Index signature for PluginConfig compatibility */
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface IWatermarkPlugin extends Plugin {
|
|
29
|
+
/** Update the watermark to display the given text */
|
|
30
|
+
setText(text: string): void;
|
|
31
|
+
/** Update the watermark to display the given image */
|
|
32
|
+
setImage(imageUrl: string): void;
|
|
33
|
+
/** Move the watermark to a new position */
|
|
34
|
+
setPosition(position: WatermarkPosition): void;
|
|
35
|
+
/** Set watermark opacity (0-1) */
|
|
36
|
+
setOpacity(opacity: number): void;
|
|
37
|
+
/** Show the watermark */
|
|
38
|
+
show(): void;
|
|
39
|
+
/** Hide the watermark */
|
|
40
|
+
hide(): void;
|
|
41
|
+
/** Get the current watermark configuration */
|
|
42
|
+
getConfig(): WatermarkConfig;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Watermark Plugin for Scarlett Player
|
|
47
|
+
*
|
|
48
|
+
* Provides anti-piracy watermark overlay with:
|
|
49
|
+
* - Text or image rendering
|
|
50
|
+
* - Configurable position and opacity
|
|
51
|
+
* - Dynamic repositioning mode (moves periodically)
|
|
52
|
+
* - Show delay
|
|
53
|
+
* - Per-track watermark updates via playlist:change metadata
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create a Watermark Plugin instance.
|
|
58
|
+
*
|
|
59
|
+
* @param config - Plugin configuration
|
|
60
|
+
* @returns Watermark Plugin instance
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { createWatermarkPlugin } from '@scarlett-player/watermark';
|
|
65
|
+
*
|
|
66
|
+
* const player = new ScarlettPlayer({
|
|
67
|
+
* container: '#player',
|
|
68
|
+
* plugins: [
|
|
69
|
+
* createWatermarkPlugin({
|
|
70
|
+
* text: 'user@example.com',
|
|
71
|
+
* position: 'bottom-right',
|
|
72
|
+
* opacity: 0.4,
|
|
73
|
+
* dynamic: true,
|
|
74
|
+
* dynamicInterval: 15000,
|
|
75
|
+
* showDelay: 20000,
|
|
76
|
+
* }),
|
|
77
|
+
* ],
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function createWatermarkPlugin(config?: WatermarkConfig): IWatermarkPlugin;
|
|
82
|
+
|
|
83
|
+
export { type IWatermarkPlugin, type WatermarkConfig, type WatermarkPosition, createWatermarkPlugin, createWatermarkPlugin as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
|
|
3
|
+
var POSITION_STYLES = {
|
|
4
|
+
"top-left": "top:10px;left:10px;",
|
|
5
|
+
"top-right": "top:10px;right:10px;",
|
|
6
|
+
"bottom-left": "bottom:40px;left:10px;",
|
|
7
|
+
"bottom-right": "bottom:40px;right:10px;",
|
|
8
|
+
"center": "top:50%;left:50%;transform:translate(-50%,-50%);"
|
|
9
|
+
};
|
|
10
|
+
function createWatermarkPlugin(config = {}) {
|
|
11
|
+
let api = null;
|
|
12
|
+
let element = null;
|
|
13
|
+
let dynamicTimer = null;
|
|
14
|
+
let showDelayTimer = null;
|
|
15
|
+
let currentPosition = config.position || "bottom-right";
|
|
16
|
+
const opacity = config.opacity ?? 0.5;
|
|
17
|
+
const fontSize = config.fontSize ?? 14;
|
|
18
|
+
const dynamic = config.dynamic ?? false;
|
|
19
|
+
const dynamicInterval = config.dynamicInterval ?? 1e4;
|
|
20
|
+
const showDelay = config.showDelay ?? 0;
|
|
21
|
+
const createElement = () => {
|
|
22
|
+
const el = document.createElement("div");
|
|
23
|
+
el.className = "sp-watermark sp-watermark--hidden";
|
|
24
|
+
el.style.cssText = `position:absolute;z-index:10;pointer-events:none;opacity:${opacity};font-size:${fontSize}px;color:#fff;text-shadow:0 1px 2px rgba(0,0,0,0.6);font-family:sans-serif;transition:all 0.5s ease;${POSITION_STYLES[currentPosition]}`;
|
|
25
|
+
el.setAttribute("data-position", currentPosition);
|
|
26
|
+
updateContent(el);
|
|
27
|
+
return el;
|
|
28
|
+
};
|
|
29
|
+
const updateContent = (el, imageUrl, text) => {
|
|
30
|
+
const img = imageUrl || config.imageUrl;
|
|
31
|
+
const txt = text || config.text;
|
|
32
|
+
el.innerHTML = "";
|
|
33
|
+
if (img) {
|
|
34
|
+
const imgEl = document.createElement("img");
|
|
35
|
+
imgEl.src = img;
|
|
36
|
+
imgEl.style.cssText = `max-height:${fontSize * 2}px;opacity:inherit;display:block;`;
|
|
37
|
+
imgEl.alt = "";
|
|
38
|
+
el.appendChild(imgEl);
|
|
39
|
+
} else if (txt) {
|
|
40
|
+
el.textContent = txt;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const setPosition = (position) => {
|
|
44
|
+
if (!element) return;
|
|
45
|
+
currentPosition = position;
|
|
46
|
+
element.style.top = "";
|
|
47
|
+
element.style.right = "";
|
|
48
|
+
element.style.bottom = "";
|
|
49
|
+
element.style.left = "";
|
|
50
|
+
element.style.transform = "";
|
|
51
|
+
const styles = POSITION_STYLES[position];
|
|
52
|
+
styles.split(";").filter(Boolean).forEach((rule) => {
|
|
53
|
+
const colonIdx = rule.indexOf(":");
|
|
54
|
+
if (colonIdx === -1) return;
|
|
55
|
+
const prop = rule.slice(0, colonIdx).trim();
|
|
56
|
+
const val = rule.slice(colonIdx + 1).trim();
|
|
57
|
+
if (prop && val) {
|
|
58
|
+
element.style.setProperty(prop, val);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
element.setAttribute("data-position", position);
|
|
62
|
+
const isVisible = element.classList.contains("sp-watermark--visible");
|
|
63
|
+
const visClass = isVisible ? " sp-watermark--visible" : " sp-watermark--hidden";
|
|
64
|
+
element.className = `sp-watermark sp-watermark--${position}${visClass}${dynamic ? " sp-watermark--dynamic" : ""}`;
|
|
65
|
+
};
|
|
66
|
+
const randomizePosition = () => {
|
|
67
|
+
const available = POSITIONS.filter((p) => p !== currentPosition);
|
|
68
|
+
const next = available[Math.floor(Math.random() * available.length)];
|
|
69
|
+
setPosition(next);
|
|
70
|
+
};
|
|
71
|
+
const show = () => {
|
|
72
|
+
if (!element) return;
|
|
73
|
+
element.classList.remove("sp-watermark--hidden");
|
|
74
|
+
element.classList.add("sp-watermark--visible");
|
|
75
|
+
};
|
|
76
|
+
const hide = () => {
|
|
77
|
+
if (!element) return;
|
|
78
|
+
element.classList.remove("sp-watermark--visible");
|
|
79
|
+
element.classList.add("sp-watermark--hidden");
|
|
80
|
+
};
|
|
81
|
+
const startDynamic = () => {
|
|
82
|
+
if (!dynamic || dynamicTimer) return;
|
|
83
|
+
dynamicTimer = setInterval(randomizePosition, dynamicInterval);
|
|
84
|
+
};
|
|
85
|
+
const stopDynamic = () => {
|
|
86
|
+
if (dynamicTimer) {
|
|
87
|
+
clearInterval(dynamicTimer);
|
|
88
|
+
dynamicTimer = null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const cleanup = () => {
|
|
92
|
+
stopDynamic();
|
|
93
|
+
if (showDelayTimer) {
|
|
94
|
+
clearTimeout(showDelayTimer);
|
|
95
|
+
showDelayTimer = null;
|
|
96
|
+
}
|
|
97
|
+
if (element?.parentNode) {
|
|
98
|
+
element.parentNode.removeChild(element);
|
|
99
|
+
}
|
|
100
|
+
element = null;
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
id: "watermark",
|
|
104
|
+
name: "Watermark",
|
|
105
|
+
version: "1.0.0",
|
|
106
|
+
type: "feature",
|
|
107
|
+
description: "Anti-piracy watermark overlay with text/image support and dynamic repositioning",
|
|
108
|
+
init(pluginApi) {
|
|
109
|
+
api = pluginApi;
|
|
110
|
+
api.logger.debug("Watermark plugin initialized");
|
|
111
|
+
element = createElement();
|
|
112
|
+
api.container.appendChild(element);
|
|
113
|
+
const unsubPlay = api.on("playback:play", () => {
|
|
114
|
+
if (showDelay > 0) {
|
|
115
|
+
showDelayTimer = setTimeout(() => {
|
|
116
|
+
show();
|
|
117
|
+
startDynamic();
|
|
118
|
+
}, showDelay);
|
|
119
|
+
} else {
|
|
120
|
+
show();
|
|
121
|
+
startDynamic();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const unsubPause = api.on("playback:pause", () => {
|
|
125
|
+
hide();
|
|
126
|
+
stopDynamic();
|
|
127
|
+
if (showDelayTimer) {
|
|
128
|
+
clearTimeout(showDelayTimer);
|
|
129
|
+
showDelayTimer = null;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const unsubEnded = api.on("playback:ended", () => {
|
|
133
|
+
hide();
|
|
134
|
+
stopDynamic();
|
|
135
|
+
});
|
|
136
|
+
const unsubChange = api.on("playlist:change", ({ track }) => {
|
|
137
|
+
if (!element || !track) return;
|
|
138
|
+
const metadata = track.metadata;
|
|
139
|
+
if (metadata) {
|
|
140
|
+
const watermarkUrl = metadata.watermarkUrl;
|
|
141
|
+
const watermarkText = metadata.watermarkText;
|
|
142
|
+
if (watermarkUrl || watermarkText) {
|
|
143
|
+
updateContent(element, watermarkUrl, watermarkText);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
api.onDestroy(() => {
|
|
148
|
+
unsubPlay();
|
|
149
|
+
unsubPause();
|
|
150
|
+
unsubEnded();
|
|
151
|
+
unsubChange();
|
|
152
|
+
cleanup();
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
destroy() {
|
|
156
|
+
api?.logger.debug("Watermark plugin destroyed");
|
|
157
|
+
cleanup();
|
|
158
|
+
api = null;
|
|
159
|
+
},
|
|
160
|
+
setText(text) {
|
|
161
|
+
if (element) updateContent(element, void 0, text);
|
|
162
|
+
},
|
|
163
|
+
setImage(imageUrl) {
|
|
164
|
+
if (element) updateContent(element, imageUrl);
|
|
165
|
+
},
|
|
166
|
+
setPosition,
|
|
167
|
+
setOpacity(value) {
|
|
168
|
+
if (element) element.style.opacity = String(Math.max(0, Math.min(1, value)));
|
|
169
|
+
},
|
|
170
|
+
show,
|
|
171
|
+
hide,
|
|
172
|
+
getConfig() {
|
|
173
|
+
return { ...config, position: currentPosition, opacity: element ? parseFloat(element.style.opacity) || opacity : opacity };
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
var index_default = createWatermarkPlugin;
|
|
178
|
+
export {
|
|
179
|
+
createWatermarkPlugin,
|
|
180
|
+
index_default as default
|
|
181
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scarlett-player/watermark",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Watermark Plugin for Scarlett Player - anti-piracy text/image overlay",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@scarlett-player/core": "^1.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
29
|
+
"jsdom": "^24.0.0",
|
|
30
|
+
"tsup": "^8.5.1",
|
|
31
|
+
"typescript": "^5.3.0",
|
|
32
|
+
"vitest": "^1.6.0",
|
|
33
|
+
"@scarlett-player/core": "1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"video",
|
|
37
|
+
"player",
|
|
38
|
+
"watermark",
|
|
39
|
+
"anti-piracy",
|
|
40
|
+
"overlay",
|
|
41
|
+
"scarlett"
|
|
42
|
+
],
|
|
43
|
+
"author": "The Stream Platform",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/Hackney-Enterprises-Inc/scarlett-player.git",
|
|
48
|
+
"directory": "packages/plugins/watermark"
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/Hackney-Enterprises-Inc/scarlett-player/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://scarlettplayer.com",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
56
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
57
|
+
"test": "vitest --run",
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"test:coverage": "vitest --coverage"
|
|
60
|
+
}
|
|
61
|
+
}
|