@scarlett-player/watermark 1.8.0 → 1.8.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/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @scarlett-player/watermark
2
+
3
+ Anti-piracy watermark plugin for [Scarlett Player](https://scarlettplayer.com). Overlays text (typically the viewer's email or account id) or an image on the player, at a fixed corner or moving to a random position on a timer, with an optional delay before it first appears. The overlay is shown on play and hidden on pause and ended, so it never sits on the poster.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @scarlett-player/watermark @scarlett-player/core
9
+ ```
10
+
11
+ `@scarlett-player/core` is a peer dependency.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { createPlayer } from '@scarlett-player/core';
17
+ import { createHLSPlugin } from '@scarlett-player/hls';
18
+ import { createWatermarkPlugin } from '@scarlett-player/watermark';
19
+
20
+ const player = await createPlayer({
21
+ container: '#player',
22
+ src: 'https://example.com/video.m3u8',
23
+ plugins: [
24
+ createHLSPlugin(),
25
+ createWatermarkPlugin({
26
+ text: 'user@example.com',
27
+ position: 'bottom-right',
28
+ opacity: 0.4,
29
+ dynamic: true,
30
+ dynamicInterval: 15000,
31
+ showDelay: 20000,
32
+ }),
33
+ ],
34
+ });
35
+ ```
36
+
37
+ Pass `imageUrl` instead of `text` to render a logo. When both are set the image wins.
38
+
39
+ ## Configuration
40
+
41
+ | Option | Type | Default | Description |
42
+ |---|---|---|---|
43
+ | `text` | `string` | `undefined` | Text to render. Ignored when `imageUrl` is set |
44
+ | `imageUrl` | `string` | `undefined` | Image to render instead of text |
45
+ | `position` | `'top-left' \| 'top-right' \| 'bottom-left' \| 'bottom-right' \| 'center'` | `'bottom-right'` | Starting position |
46
+ | `opacity` | `number` | `0.5` | Opacity from 0 to 1 |
47
+ | `fontSize` | `number` | `14` | Font size in px for text watermarks |
48
+ | `imageHeight` | `number` | `40` | Maximum image height in px. Only applies with `imageUrl` |
49
+ | `padding` | `number` | `10` (top and sides), `40` (bottom) | Distance from the edges in px. The larger bottom default keeps the mark clear of the control bar. Setting a value applies it to every edge |
50
+ | `dynamic` | `boolean` | `false` | Move to a different random position on a timer |
51
+ | `dynamicInterval` | `number` | `10000` | Milliseconds between moves when `dynamic` is on |
52
+ | `showDelay` | `number` | `0` | Milliseconds to wait after play before the mark first appears. A pause during the delay cancels it |
53
+
54
+ The `dynamic` timer starts when the mark is shown and stops on pause and ended, so a paused player never keeps a timer alive.
55
+
56
+ ## Plugin API
57
+
58
+ The plugin is registered under the id `watermark`:
59
+
60
+ ```ts
61
+ import type { IWatermarkPlugin } from '@scarlett-player/watermark';
62
+
63
+ const watermark = player.getPlugin<IWatermarkPlugin>('watermark');
64
+
65
+ watermark?.setText('session 8f3a');
66
+ watermark?.setImage('/logo.png');
67
+ watermark?.setPosition('top-left');
68
+ watermark?.setOpacity(0.3);
69
+ watermark?.setImageHeight(60);
70
+ watermark?.setPadding(24);
71
+ watermark?.hide();
72
+ watermark?.show();
73
+ watermark?.getConfig();
74
+ ```
75
+
76
+ | Method | Description |
77
+ |---|---|
78
+ | `setText(text)` | Replace the content with text |
79
+ | `setImage(imageUrl)` | Replace the content with an image |
80
+ | `setPosition(position)` | Move to one of the five positions |
81
+ | `setOpacity(opacity)` | Set opacity, clamped to 0 to 1 |
82
+ | `setImageHeight(height)` | Set the maximum image height in px |
83
+ | `setPadding(padding)` | Set the edge padding in px for every edge and re-apply the current position |
84
+ | `show()` / `hide()` | Toggle visibility without touching the timers |
85
+ | `getConfig()` | The original config merged with the current position, opacity, image height and padding |
86
+
87
+ ## Per-track watermarks
88
+
89
+ When `@scarlett-player/playlist` is present the plugin listens for `playlist:change` and reads `metadata.watermarkUrl` or `metadata.watermarkText` from the new track. If either is set the content is replaced for that track; tracks without them keep the current content.
90
+
91
+ ```ts
92
+ { id: '2', src: '/episode-2.mp4', metadata: { watermarkText: 'Screener: press only' } }
93
+ ```
94
+
95
+ ## Styling
96
+
97
+ The overlay is a single `div` appended to the player container with inline positioning, `pointer-events: none`, white text with a subtle shadow, and a 0.5s transition. It carries these classes for your own CSS:
98
+
99
+ | Class | When |
100
+ |---|---|
101
+ | `sp-watermark` | Always |
102
+ | `sp-watermark--visible` / `sp-watermark--hidden` | Current visibility |
103
+ | `sp-watermark--top-left`, `sp-watermark--top-right`, `sp-watermark--bottom-left`, `sp-watermark--bottom-right`, `sp-watermark--center` | Current position, applied after the first `setPosition()` or dynamic move |
104
+ | `sp-watermark--dynamic` | Present when `dynamic` is on, applied after the first position change |
105
+
106
+ The element also has a `data-position` attribute holding the current position. No CSS custom properties are used.
107
+
108
+ ## Events
109
+
110
+ The plugin emits no events. It listens to `playback:play`, `playback:pause`, `playback:ended` and `playlist:change`.
111
+
112
+ ## License
113
+
114
+ MIT
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.7.1" : "0.0.0-dev";
29
+ var PKG_VERSION = true ? "1.8.1" : "0.0.0-dev";
30
30
 
31
31
  // src/index.ts
32
32
  var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var PKG_VERSION = true ? "1.7.1" : "0.0.0-dev";
2
+ var PKG_VERSION = true ? "1.8.1" : "0.0.0-dev";
3
3
 
4
4
  // src/index.ts
5
5
  var POSITIONS = ["top-left", "top-right", "bottom-left", "bottom-right", "center"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scarlett-player/watermark",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Watermark Plugin for Scarlett Player - anti-piracy text/image overlay",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@scarlett-player/core": "^1.7.0"
25
+ "@scarlett-player/core": "^1.8.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@vitest/coverage-v8": "^1.6.0",
@@ -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.8.0"
33
+ "@scarlett-player/core": "1.8.1"
34
34
  },
35
35
  "keywords": [
36
36
  "video",