@flowplayer/spins 0.1.0-rc.10

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,220 @@
1
+ # @flowplayer/spins
2
+
3
+ A TypeScript library for creating Flowplayer playlist components optimized for short-form video content like Reels and Shorts.
4
+
5
+ ```typescript
6
+ import { spins } from "@flowplayer/spins";
7
+
8
+ const spinsContainer = spins({
9
+ playlist: "your-playlist-id",
10
+ token: "your-token",
11
+ lang: "en",
12
+ ui: { theme: "minimal" }
13
+ });
14
+ document.body.appendChild(spinsContainer);
15
+ ```
16
+
17
+ ### React Usage
18
+
19
+ ```tsx
20
+ import { spins, type SpinsConfig } from "@flowplayer/spins";
21
+ import { useEffect, useRef } from "react";
22
+
23
+ function SpinsPlayer({ playlistId }: { playlistId: string }) {
24
+ const containerRef = useRef<HTMLDivElement>(null);
25
+
26
+ useEffect(() => {
27
+ if (containerRef.current) {
28
+ const spinsContainer = spins({
29
+ playlist: playlistId,
30
+ token: "your-token",
31
+ lang: "en",
32
+ ui: { theme: "minimal" }
33
+ });
34
+ containerRef.current.appendChild(spinsContainer);
35
+ }
36
+ }, [playlistId]);
37
+
38
+ return <div ref={containerRef} className="spins-container" />;
39
+ }
40
+ ```
41
+
42
+ ## Features
43
+
44
+ - 🎯 **Type-safe** - Built with TypeScript and Zod schema validation
45
+ - 🛡️ **Runtime validation** - Safely deserializes API responses
46
+ - 🎨 **Styled components** - Includes CSS for playlist styling
47
+ - 🔧 **Error handling** - Graceful fallbacks for network and validation errors
48
+ - 📦 **ESM ready** - Modern ES modules with tree-shaking support
49
+ - 📱 **Short-form optimized** - Designed for vertical video content like TikTok, Instagram Reels, and YouTube Shorts
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ npm install @flowplayer/spins
55
+ # or
56
+ bun add @flowplayer/spins
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ```typescript
62
+ import { spins, type SpinsConfig } from "@flowplayer/spins";
63
+
64
+ // Create a playlist component for short-form content
65
+ const config: SpinsConfig = {
66
+ playlist: "your-playlist-id", // or array of SpinConfig objects
67
+ token: "your-flowplayer-token",
68
+ lang: "en",
69
+ ui: { theme: "minimal" },
70
+ autoplay: 1
71
+ };
72
+
73
+ const spinsContainer = spins(config);
74
+ document.body.appendChild(spinsContainer);
75
+ ```
76
+
77
+ ## Short-Form Video Content
78
+
79
+ This library is specifically designed to handle short-form video playlists, making it easy to create engaging vertical video experiences similar to:
80
+
81
+ - **TikTok-style feeds** - Vertical scrolling through short videos
82
+ - **Instagram Reels** - Quick, engaging video content
83
+ - **YouTube Shorts** - Bite-sized video experiences
84
+
85
+ The component automatically handles playlist loading and provides the structure needed for smooth, mobile-optimized video playback.
86
+
87
+ ## API Reference
88
+
89
+ ### `spins(config: SpinsConfig): SpinsContainer`
90
+
91
+ Creates a Flowplayer playlist component container optimized for short-form video content.
92
+
93
+ #### Parameters
94
+
95
+ - `config.playlist: string | Array<SpinConfig>` - The playlist ID or array of spin configurations
96
+ - `config.token: string` - Your Flowplayer token
97
+ - `config.lang: string` - Language code (e.g., "en", "es")
98
+ - `config.ui: object` - UI configuration options
99
+ - `config.autoplay?: 0 | 1` - Enable/disable autoplay (optional)
100
+ - `config.hls?: HLSConfig` - HLS-specific configuration (optional)
101
+ - `config.ima?: PlayerIMAConfig` - IMA ads configuration (optional)
102
+
103
+ #### Returns
104
+
105
+ Returns a `SpinsContainer` (extends `HTMLDivElement`) with event handling capabilities:
106
+ - `on(event, handler)` - Subscribe to events
107
+ - `off(event, handler)` - Unsubscribe from events
108
+ - `emit(event, data)` - Emit custom events (internal use)
109
+
110
+ #### Events
111
+
112
+ - `SPIN_CREATED` - Fired when a new spin is created
113
+ - `SPIN_IN_VIEWPORT` - Fired when a spin enters the viewport
114
+
115
+ #### Error Handling
116
+
117
+ The function gracefully handles:
118
+ - Network errors (API unavailable, timeout, etc.)
119
+ - Invalid playlist configurations
120
+ - HTTP errors (404, 500, etc.)
121
+
122
+ ## TypeScript Support
123
+
124
+ The library exports TypeScript types for full type safety:
125
+
126
+ ```typescript
127
+ import { type SpinsConfig, type SpinConfig, type SpinsContainer } from "@flowplayer/spins";
128
+ ```
129
+
130
+ ### `SpinsConfig`
131
+
132
+ The main configuration interface:
133
+
134
+ ```typescript
135
+ interface SpinsConfig {
136
+ playlist: string | Array<SpinConfig>;
137
+ token: string;
138
+ lang: string;
139
+ ui: Config["ui"];
140
+ autoplay?: 0 | 1;
141
+ hls?: HLSConfig["hls"];
142
+ ima?: PlayerIMAConfig;
143
+ }
144
+ ```
145
+
146
+ ### `SpinConfig`
147
+
148
+ Individual spin configuration:
149
+
150
+ ```typescript
151
+ interface SpinConfig {
152
+ src: Config["src"];
153
+ title?: string;
154
+ poster?: string;
155
+ description?: string;
156
+ subtitles?: SubtitlesConfig["subtitles"];
157
+ thumbnails: ThumbnailsConfig["thumbnails"];
158
+ ima?: PlayerIMAConfig;
159
+ }
160
+ ```
161
+
162
+ ## CSS Styling
163
+
164
+ The component includes default CSS styling optimized for short-form video content. Styles are imported from:
165
+ - `@flowplayer/spins/dist/spins.css` - Component-specific styles
166
+ - Flowplayer CDN - Base player styles loaded automatically
167
+
168
+ You can override styles by targeting the spins container and its children:
169
+
170
+ ```css
171
+ .spins-container {
172
+ /* Base spins container styles */
173
+ }
174
+
175
+ flowplayer-spin {
176
+ /* Individual spin container styles */
177
+ }
178
+ ```
179
+
180
+ ## Development
181
+
182
+ ### Prerequisites
183
+
184
+ - [Bun](https://bun.sh/) runtime
185
+ - TypeScript 5+
186
+
187
+ ### Scripts
188
+
189
+ ```bash
190
+ # Development with Storybook
191
+ bun run dev
192
+
193
+ # Build the library
194
+ bun run build
195
+
196
+ # Build TypeScript declarations
197
+ bun run build:dts
198
+
199
+ # Run tests
200
+ bun run test
201
+
202
+ # Lint and format code
203
+ bun run lint
204
+
205
+ # Build Storybook for production
206
+ bun run build-storybook
207
+ ```
208
+
209
+ ## Contributing
210
+
211
+ This project uses:
212
+ - **Biome** for linting and formatting
213
+ - **Husky** for pre-commit hooks
214
+ - **Vitest** with **Playwright** for browser testing
215
+ - **Storybook** for component development and documentation
216
+ - **Lit** for custom web components
217
+
218
+ ## License
219
+
220
+ This is a paid feature of the Wowza Flowplayer platform. Usage requires a valid Flowplayer license.