@arraypress/waveform-player-react 0.1.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.js ADDED
@@ -0,0 +1,197 @@
1
+ import { forwardRef, useRef, useEffect, useImperativeHandle } from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ // src/WaveformPlayer.tsx
5
+ function buildLibraryOptions(props) {
6
+ const opts = {};
7
+ if (props.url !== void 0) opts.url = props.url;
8
+ if (props.audioMode !== void 0) opts.audioMode = props.audioMode;
9
+ if (props.preload !== void 0) opts.preload = props.preload;
10
+ if (props.waveformStyle !== void 0) opts.waveformStyle = props.waveformStyle;
11
+ if (props.height !== void 0) opts.height = props.height;
12
+ if (props.samples !== void 0) opts.samples = props.samples;
13
+ if (props.barWidth !== void 0) opts.barWidth = props.barWidth;
14
+ if (props.barSpacing !== void 0) opts.barSpacing = props.barSpacing;
15
+ if (props.waveform !== void 0 && props.waveform !== null) {
16
+ opts.waveform = props.waveform;
17
+ }
18
+ if (props.colorPreset !== void 0) opts.colorPreset = props.colorPreset;
19
+ if (props.waveformColor !== void 0) opts.waveformColor = props.waveformColor;
20
+ if (props.progressColor !== void 0) opts.progressColor = props.progressColor;
21
+ if (props.buttonColor !== void 0) opts.buttonColor = props.buttonColor;
22
+ if (props.buttonHoverColor !== void 0) opts.buttonHoverColor = props.buttonHoverColor;
23
+ if (props.textColor !== void 0) opts.textColor = props.textColor;
24
+ if (props.textSecondaryColor !== void 0) opts.textSecondaryColor = props.textSecondaryColor;
25
+ if (props.backgroundColor !== void 0) opts.backgroundColor = props.backgroundColor;
26
+ if (props.borderColor !== void 0) opts.borderColor = props.borderColor;
27
+ if (props.playbackRate !== void 0) opts.playbackRate = props.playbackRate;
28
+ if (props.showPlaybackSpeed !== void 0) opts.showPlaybackSpeed = props.showPlaybackSpeed;
29
+ if (props.playbackRates !== void 0) opts.playbackRates = props.playbackRates;
30
+ if (props.showControls !== void 0) opts.showControls = props.showControls;
31
+ if (props.showInfo !== void 0) opts.showInfo = props.showInfo;
32
+ if (props.showTime !== void 0) opts.showTime = props.showTime;
33
+ if (props.showHoverTime !== void 0) opts.showHoverTime = props.showHoverTime;
34
+ if (props.showBPM !== void 0) opts.showBPM = props.showBPM;
35
+ if (props.buttonAlign !== void 0) opts.buttonAlign = props.buttonAlign;
36
+ if (props.markers !== void 0) opts.markers = props.markers;
37
+ if (props.showMarkers !== void 0) opts.showMarkers = props.showMarkers;
38
+ if (props.title !== void 0) opts.title = props.title;
39
+ if (props.subtitle !== void 0) opts.subtitle = props.subtitle;
40
+ if (props.artwork !== void 0) opts.artwork = props.artwork;
41
+ if (props.album !== void 0) opts.album = props.album;
42
+ if (props.autoplay !== void 0) opts.autoplay = props.autoplay;
43
+ if (props.singlePlay !== void 0) opts.singlePlay = props.singlePlay;
44
+ if (props.playOnSeek !== void 0) opts.playOnSeek = props.playOnSeek;
45
+ if (props.enableMediaSession !== void 0) opts.enableMediaSession = props.enableMediaSession;
46
+ if (props.playIcon !== void 0) opts.playIcon = props.playIcon;
47
+ if (props.pauseIcon !== void 0) opts.pauseIcon = props.pauseIcon;
48
+ if (props.onLoad) opts.onLoad = props.onLoad;
49
+ if (props.onPlay) opts.onPlay = props.onPlay;
50
+ if (props.onPause) opts.onPause = props.onPause;
51
+ if (props.onEnd) opts.onEnd = props.onEnd;
52
+ if (props.onTimeUpdate) opts.onTimeUpdate = props.onTimeUpdate;
53
+ if (props.onError) opts.onError = props.onError;
54
+ return opts;
55
+ }
56
+ var WaveformPlayer = forwardRef(
57
+ function WaveformPlayer2(props, ref) {
58
+ const containerRef = useRef(null);
59
+ const instanceRef = useRef(null);
60
+ useEffect(() => {
61
+ let cancelled = false;
62
+ let localInstance = null;
63
+ void import('@arraypress/waveform-player').then((mod) => {
64
+ if (cancelled) return;
65
+ const container = containerRef.current;
66
+ if (!container) return;
67
+ const WaveformPlayerClass = mod.default ?? mod.WaveformPlayer;
68
+ if (typeof WaveformPlayerClass !== "function") {
69
+ console.error(
70
+ "[waveform-player-react] Failed to resolve WaveformPlayer constructor from module."
71
+ );
72
+ return;
73
+ }
74
+ const opts = buildLibraryOptions(props);
75
+ localInstance = new WaveformPlayerClass(container, opts);
76
+ instanceRef.current = localInstance;
77
+ }).catch((err) => {
78
+ console.error("[waveform-player-react] Failed to load library:", err);
79
+ });
80
+ return () => {
81
+ cancelled = true;
82
+ const current = localInstance ?? instanceRef.current;
83
+ if (current && typeof current.destroy === "function") {
84
+ try {
85
+ current.destroy();
86
+ } catch (err) {
87
+ console.warn("[waveform-player-react] destroy() threw:", err);
88
+ }
89
+ }
90
+ instanceRef.current = null;
91
+ };
92
+ }, [
93
+ props.url,
94
+ props.audioMode,
95
+ props.preload,
96
+ props.waveformStyle,
97
+ props.height,
98
+ props.samples,
99
+ props.barWidth,
100
+ props.barSpacing,
101
+ props.waveform,
102
+ props.colorPreset,
103
+ props.waveformColor,
104
+ props.progressColor,
105
+ props.buttonColor,
106
+ props.buttonHoverColor,
107
+ props.textColor,
108
+ props.textSecondaryColor,
109
+ props.backgroundColor,
110
+ props.borderColor,
111
+ props.playbackRate,
112
+ props.showPlaybackSpeed,
113
+ props.playbackRates,
114
+ props.showControls,
115
+ props.showInfo,
116
+ props.showTime,
117
+ props.showHoverTime,
118
+ props.showBPM,
119
+ props.buttonAlign,
120
+ props.markers,
121
+ props.showMarkers,
122
+ props.title,
123
+ props.subtitle,
124
+ props.artwork,
125
+ props.album,
126
+ props.autoplay,
127
+ props.singlePlay,
128
+ props.playOnSeek,
129
+ props.enableMediaSession,
130
+ props.playIcon,
131
+ props.pauseIcon
132
+ ]);
133
+ useImperativeHandle(
134
+ ref,
135
+ () => ({
136
+ play() {
137
+ const inst = instanceRef.current;
138
+ return inst?.play?.();
139
+ },
140
+ pause() {
141
+ const inst = instanceRef.current;
142
+ inst?.pause?.();
143
+ },
144
+ togglePlay() {
145
+ const inst = instanceRef.current;
146
+ inst?.togglePlay?.();
147
+ },
148
+ seekTo(seconds) {
149
+ const inst = instanceRef.current;
150
+ inst?.seekTo?.(seconds);
151
+ },
152
+ seekToPercent(percent) {
153
+ const inst = instanceRef.current;
154
+ inst?.seekToPercent?.(percent);
155
+ },
156
+ setVolume(volume) {
157
+ const inst = instanceRef.current;
158
+ inst?.setVolume?.(volume);
159
+ },
160
+ setPlaybackRate(rate) {
161
+ const inst = instanceRef.current;
162
+ inst?.setPlaybackRate?.(rate);
163
+ },
164
+ setPlayingState(playing) {
165
+ const inst = instanceRef.current;
166
+ inst?.setPlayingState?.(playing);
167
+ },
168
+ setProgress(currentTime, duration) {
169
+ const inst = instanceRef.current;
170
+ inst?.setProgress?.(currentTime, duration);
171
+ },
172
+ async loadTrack(url, title, subtitle, options) {
173
+ const inst = instanceRef.current;
174
+ if (!inst?.loadTrack) return;
175
+ await inst.loadTrack(url, title, subtitle, options);
176
+ },
177
+ get instance() {
178
+ return instanceRef.current;
179
+ }
180
+ }),
181
+ []
182
+ );
183
+ return /* @__PURE__ */ jsx(
184
+ "div",
185
+ {
186
+ ref: containerRef,
187
+ id: props.id,
188
+ className: ["wfp-host", props.className].filter(Boolean).join(" "),
189
+ style: props.style
190
+ }
191
+ );
192
+ }
193
+ );
194
+
195
+ export { WaveformPlayer, WaveformPlayer as default };
196
+ //# sourceMappingURL=index.js.map
197
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/WaveformPlayer.tsx"],"names":["WaveformPlayer"],"mappings":";;;;AAqEA,SAAS,oBAAoB,KAAA,EAAqD;AACjF,EAAA,MAAM,OAAgC,EAAC;AAGvC,EAAA,IAAI,KAAA,CAAM,GAAA,KAAQ,MAAA,EAAW,IAAA,CAAK,MAAM,KAAA,CAAM,GAAA;AAC9C,EAAA,IAAI,KAAA,CAAM,SAAA,KAAc,MAAA,EAAW,IAAA,CAAK,YAAY,KAAA,CAAM,SAAA;AAC1D,EAAA,IAAI,KAAA,CAAM,OAAA,KAAY,MAAA,EAAW,I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UAAA,IAAA,EAAM,kBAAkB,IAAI,CAAA;AAAA,QAC7B,CAAA;AAAA,QACA,gBAAgB,OAAA,EAAS;AACxB,UAAA,MAAM,OAAO,WAAA,CAAY,OAAA;AACzB,UAAA,IAAA,EAAM,kBAAkB,OAAO,CAAA;AAAA,QAChC,CAAA;AAAA,QACA,WAAA,CAAY,aAAa,QAAA,EAAU;AAClC,UAAA,MAAM,OAAO,WAAA,CAAY,OAAA;AAGzB,UAAA,IAAA,EAAM,WAAA,GAAc,aAAa,QAAQ,CAAA;AAAA,QAC1C,CAAA;AAAA,QACA,MAAM,SAAA,CAAU,GAAA,EAAK,KAAA,EAAO,UAAU,OAAA,EAAS;AAC9C,UAAA,MAAM,OAAO,WAAA,CAAY,OAAA;AAQzB,UAAA,IAAI,CAAC,MAAM,SAAA,EAAW;AACtB,UAAA,MAAM,IAAA,CAAK,SAAA,CAAU,GAAA,EAAK,KAAA,EAAO,UAAU,OAAO,CAAA;AAAA,QACnD,CAAA;AAAA,QACA,IAAI,QAAA,GAAW;AACd,UAAA,OAAO,WAAA,CAAY,OAAA;AAAA,QACpB;AAAA,OACD,CAAA;AAAA,MACA;AAAC,KACF;AAEA,IAAA,uBACC,GAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACA,GAAA,EAAK,YAAA;AAAA,QACL,IAAI,KAAA,CAAM,EAAA;AAAA,QACV,SAAA,EAAW,CAAC,UAAA,EAAY,KAAA,CAAM,SAAS,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAAA,QACjE,OAAO,KAAA,CAAM;AAAA;AAAA,KACd;AAAA,EAEF;AACD","file":"index.js","sourcesContent":["/**\n * WaveformPlayer.tsx\n * ------------------\n *\n * React wrapper around `@arraypress/waveform-player`. Mounts a player\n * instance into a `<div>` on first render, tears it down on unmount,\n * and re-mounts when any \"identity\" prop changes (the props whose\n * change requires the library to start over from scratch — `url`,\n * `audioMode`).\n *\n * For non-identity props, this component currently re-creates the\n * instance as well, which is simpler than diffing every option and\n * calling the right granular updater. The trade-off is acceptable\n * because:\n *\n * - The library re-uses any cached waveform data keyed by URL, so\n * re-mounts on the same URL are cheap.\n * - Per-render churn on a player widget is rare in practice.\n *\n * If you need finer control — imperative `loadTrack()`, `seekTo()`,\n * `setVolume()`, etc. — grab the instance through a `ref`:\n *\n * ```tsx\n * import { useRef, useEffect } from 'react';\n * import { WaveformPlayer, type WaveformPlayerHandle } from '@arraypress/waveform-player-react';\n *\n * function MyPlayer() {\n * const ref = useRef<WaveformPlayerHandle>(null);\n * return (\n * <>\n * <WaveformPlayer ref={ref} url=\"/audio/track.mp3\" />\n * <button onClick={() => ref.current?.seekTo(60)}>Jump to 1:00</button>\n * </>\n * );\n * }\n * ```\n *\n * ## Library setup\n *\n * This component does **not** load the core library's CSS for you.\n * Import it once at your app entry:\n *\n * ```ts\n * import '@arraypress/waveform-player/dist/waveform-player.css';\n * ```\n *\n * The library's JS is imported dynamically inside `useEffect` so it\n * only loads on the client (SSR-safe).\n *\n * @module WaveformPlayer\n */\nimport {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n\ttype ForwardedRef,\n} from 'react';\nimport type { WaveformPlayerHandle, WaveformPlayerProps } from './types';\n\n/**\n * Convert a `WaveformPlayerProps` object into the option shape the\n * core library accepts. Most fields pass straight through; this\n * helper exists so the option-building logic is testable on its own\n * and the component body stays focused on lifecycle.\n *\n * @param props - The component's resolved props.\n * @returns An options object to pass into `new WaveformPlayer(el, …)`.\n */\nfunction buildLibraryOptions(props: WaveformPlayerProps): Record<string, unknown> {\n\tconst opts: Record<string, unknown> = {};\n\n\t/* Audio source */\n\tif (props.url !== undefined) opts.url = props.url;\n\tif (props.audioMode !== undefined) opts.audioMode = props.audioMode;\n\tif (props.preload !== undefined) opts.preload = props.preload;\n\n\t/* Waveform visualisation */\n\tif (props.waveformStyle !== undefined) opts.waveformStyle = props.waveformStyle;\n\tif (props.height !== undefined) opts.height = props.height;\n\tif (props.samples !== undefined) opts.samples = props.samples;\n\tif (props.barWidth !== undefined) opts.barWidth = props.barWidth;\n\tif (props.barSpacing !== undefined) opts.barSpacing = props.barSpacing;\n\tif (props.waveform !== undefined && props.waveform !== null) {\n\t\topts.waveform = props.waveform;\n\t}\n\n\t/* Colours */\n\tif (props.colorPreset !== undefined) opts.colorPreset = props.colorPreset;\n\tif (props.waveformColor !== undefined) opts.waveformColor = props.waveformColor;\n\tif (props.progressColor !== undefined) opts.progressColor = props.progressColor;\n\tif (props.buttonColor !== undefined) opts.buttonColor = props.buttonColor;\n\tif (props.buttonHoverColor !== undefined) opts.buttonHoverColor = props.buttonHoverColor;\n\tif (props.textColor !== undefined) opts.textColor = props.textColor;\n\tif (props.textSecondaryColor !== undefined) opts.textSecondaryColor = props.textSecondaryColor;\n\tif (props.backgroundColor !== undefined) opts.backgroundColor = props.backgroundColor;\n\tif (props.borderColor !== undefined) opts.borderColor = props.borderColor;\n\n\t/* Playback controls */\n\tif (props.playbackRate !== undefined) opts.playbackRate = props.playbackRate;\n\tif (props.showPlaybackSpeed !== undefined) opts.showPlaybackSpeed = props.showPlaybackSpeed;\n\tif (props.playbackRates !== undefined) opts.playbackRates = props.playbackRates;\n\n\t/* UI toggles */\n\tif (props.showControls !== undefined) opts.showControls = props.showControls;\n\tif (props.showInfo !== undefined) opts.showInfo = props.showInfo;\n\tif (props.showTime !== undefined) opts.showTime = props.showTime;\n\tif (props.showHoverTime !== undefined) opts.showHoverTime = props.showHoverTime;\n\tif (props.showBPM !== undefined) opts.showBPM = props.showBPM;\n\tif (props.buttonAlign !== undefined) opts.buttonAlign = props.buttonAlign;\n\n\t/* Markers */\n\tif (props.markers !== undefined) opts.markers = props.markers;\n\tif (props.showMarkers !== undefined) opts.showMarkers = props.showMarkers;\n\n\t/* Content metadata */\n\tif (props.title !== undefined) opts.title = props.title;\n\tif (props.subtitle !== undefined) opts.subtitle = props.subtitle;\n\tif (props.artwork !== undefined) opts.artwork = props.artwork;\n\tif (props.album !== undefined) opts.album = props.album;\n\n\t/* Behaviour */\n\tif (props.autoplay !== undefined) opts.autoplay = props.autoplay;\n\tif (props.singlePlay !== undefined) opts.singlePlay = props.singlePlay;\n\tif (props.playOnSeek !== undefined) opts.playOnSeek = props.playOnSeek;\n\tif (props.enableMediaSession !== undefined) opts.enableMediaSession = props.enableMediaSession;\n\n\t/* Icons */\n\tif (props.playIcon !== undefined) opts.playIcon = props.playIcon;\n\tif (props.pauseIcon !== undefined) opts.pauseIcon = props.pauseIcon;\n\n\t/* Callbacks — wired into the library's option-level callbacks\n\t * rather than custom-event listeners. The library invokes\n\t * these synchronously on the respective state change. */\n\tif (props.onLoad) opts.onLoad = props.onLoad;\n\tif (props.onPlay) opts.onPlay = props.onPlay;\n\tif (props.onPause) opts.onPause = props.onPause;\n\tif (props.onEnd) opts.onEnd = props.onEnd;\n\tif (props.onTimeUpdate) opts.onTimeUpdate = props.onTimeUpdate;\n\tif (props.onError) opts.onError = props.onError;\n\n\treturn opts;\n}\n\n/**\n * `WaveformPlayer` — React component wrapping\n * `@arraypress/waveform-player`.\n *\n * Render at the spot you want a waveform-driven audio player to\n * appear. The container `<div>` is rendered immediately for layout;\n * the actual player UI hydrates in once the library loads\n * client-side.\n *\n * @example Basic\n * <WaveformPlayer url=\"/audio/track.mp3\" title=\"My Track\" />\n *\n * @example With ref for imperative control\n * const ref = useRef<WaveformPlayerHandle>(null);\n * <WaveformPlayer ref={ref} url={url} />\n * <button onClick={() => ref.current?.togglePlay()}>Play/Pause</button>\n */\nexport const WaveformPlayer = forwardRef<WaveformPlayerHandle, WaveformPlayerProps>(\n\tfunction WaveformPlayer(props, ref: ForwardedRef<WaveformPlayerHandle>) {\n\t\tconst containerRef = useRef<HTMLDivElement | null>(null);\n\t\tconst instanceRef = useRef<unknown>(null);\n\n\t\t/**\n\t\t * Mount / re-mount lifecycle.\n\t\t *\n\t\t * The dep array intentionally contains EVERY prop the library\n\t\t * uses at construction time. When any of them change, this\n\t\t * effect tears down the old instance and creates a new one\n\t\t * with the updated options. That's simpler and more correct\n\t\t * than trying to partial-update the live instance, and the\n\t\t * library has built-in caches (waveform peaks keyed by URL)\n\t\t * that make same-URL re-mounts cheap.\n\t\t */\n\t\tuseEffect(() => {\n\t\t\tlet cancelled = false;\n\t\t\tlet localInstance: { destroy?: () => void } | null = null;\n\n\t\t\t/* The library is browser-only. Defer the import until we're\n\t\t\t * actually mounting client-side so SSR / RSC don't try to\n\t\t\t * evaluate the audio + canvas + fetch surface on the server.\n\t\t\t */\n\t\t\tvoid import('@arraypress/waveform-player')\n\t\t\t\t.then((mod) => {\n\t\t\t\t\tif (cancelled) return;\n\t\t\t\t\tconst container = containerRef.current;\n\t\t\t\t\tif (!container) return;\n\n\t\t\t\t\tconst WaveformPlayerClass = (mod.default ?? (mod as { WaveformPlayer?: unknown }).WaveformPlayer) as {\n\t\t\t\t\t\tnew (el: HTMLElement, opts: Record<string, unknown>): { destroy?: () => void };\n\t\t\t\t\t};\n\n\t\t\t\t\tif (typeof WaveformPlayerClass !== 'function') {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t'[waveform-player-react] Failed to resolve WaveformPlayer constructor from module.'\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst opts = buildLibraryOptions(props);\n\t\t\t\t\tlocalInstance = new WaveformPlayerClass(container, opts);\n\t\t\t\t\tinstanceRef.current = localInstance;\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tconsole.error('[waveform-player-react] Failed to load library:', err);\n\t\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tcancelled = true;\n\t\t\t\tconst current = localInstance ?? (instanceRef.current as { destroy?: () => void } | null);\n\t\t\t\tif (current && typeof current.destroy === 'function') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcurrent.destroy();\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tconsole.warn('[waveform-player-react] destroy() threw:', err);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tinstanceRef.current = null;\n\t\t\t};\n\t\t\t/* Re-mount on any prop change. Listed exhaustively rather\n\t\t\t * than spread to make the intent explicit and to keep the\n\t\t\t * lint rule happy. Callbacks intentionally NOT in deps:\n\t\t\t * a parent re-rendering with a fresh inline function\n\t\t\t * shouldn't tear the player down. */\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t}, [\n\t\t\tprops.url,\n\t\t\tprops.audioMode,\n\t\t\tprops.preload,\n\t\t\tprops.waveformStyle,\n\t\t\tprops.height,\n\t\t\tprops.samples,\n\t\t\tprops.barWidth,\n\t\t\tprops.barSpacing,\n\t\t\tprops.waveform,\n\t\t\tprops.colorPreset,\n\t\t\tprops.waveformColor,\n\t\t\tprops.progressColor,\n\t\t\tprops.buttonColor,\n\t\t\tprops.buttonHoverColor,\n\t\t\tprops.textColor,\n\t\t\tprops.textSecondaryColor,\n\t\t\tprops.backgroundColor,\n\t\t\tprops.borderColor,\n\t\t\tprops.playbackRate,\n\t\t\tprops.showPlaybackSpeed,\n\t\t\tprops.playbackRates,\n\t\t\tprops.showControls,\n\t\t\tprops.showInfo,\n\t\t\tprops.showTime,\n\t\t\tprops.showHoverTime,\n\t\t\tprops.showBPM,\n\t\t\tprops.buttonAlign,\n\t\t\tprops.markers,\n\t\t\tprops.showMarkers,\n\t\t\tprops.title,\n\t\t\tprops.subtitle,\n\t\t\tprops.artwork,\n\t\t\tprops.album,\n\t\t\tprops.autoplay,\n\t\t\tprops.singlePlay,\n\t\t\tprops.playOnSeek,\n\t\t\tprops.enableMediaSession,\n\t\t\tprops.playIcon,\n\t\t\tprops.pauseIcon,\n\t\t]);\n\n\t\t/**\n\t\t * Expose an imperative handle on the forwarded ref. Each\n\t\t * method is a thin pass-through to the live instance — if the\n\t\t * instance hasn't mounted yet (still loading async), calls are\n\t\t * no-ops (`pause`, `seekTo`, etc. return `undefined`).\n\t\t */\n\t\tuseImperativeHandle(\n\t\t\tref,\n\t\t\t() => ({\n\t\t\t\tplay() {\n\t\t\t\t\tconst inst = instanceRef.current as { play?: () => Promise<void> | undefined } | null;\n\t\t\t\t\treturn inst?.play?.();\n\t\t\t\t},\n\t\t\t\tpause() {\n\t\t\t\t\tconst inst = instanceRef.current as { pause?: () => void } | null;\n\t\t\t\t\tinst?.pause?.();\n\t\t\t\t},\n\t\t\t\ttogglePlay() {\n\t\t\t\t\tconst inst = instanceRef.current as { togglePlay?: () => void } | null;\n\t\t\t\t\tinst?.togglePlay?.();\n\t\t\t\t},\n\t\t\t\tseekTo(seconds) {\n\t\t\t\t\tconst inst = instanceRef.current as { seekTo?: (s: number) => void } | null;\n\t\t\t\t\tinst?.seekTo?.(seconds);\n\t\t\t\t},\n\t\t\t\tseekToPercent(percent) {\n\t\t\t\t\tconst inst = instanceRef.current as { seekToPercent?: (p: number) => void } | null;\n\t\t\t\t\tinst?.seekToPercent?.(percent);\n\t\t\t\t},\n\t\t\t\tsetVolume(volume) {\n\t\t\t\t\tconst inst = instanceRef.current as { setVolume?: (v: number) => void } | null;\n\t\t\t\t\tinst?.setVolume?.(volume);\n\t\t\t\t},\n\t\t\t\tsetPlaybackRate(rate) {\n\t\t\t\t\tconst inst = instanceRef.current as { setPlaybackRate?: (r: number) => void } | null;\n\t\t\t\t\tinst?.setPlaybackRate?.(rate);\n\t\t\t\t},\n\t\t\t\tsetPlayingState(playing) {\n\t\t\t\t\tconst inst = instanceRef.current as { setPlayingState?: (p: boolean) => void } | null;\n\t\t\t\t\tinst?.setPlayingState?.(playing);\n\t\t\t\t},\n\t\t\t\tsetProgress(currentTime, duration) {\n\t\t\t\t\tconst inst = instanceRef.current as {\n\t\t\t\t\t\tsetProgress?: (c: number, d: number) => void;\n\t\t\t\t\t} | null;\n\t\t\t\t\tinst?.setProgress?.(currentTime, duration);\n\t\t\t\t},\n\t\t\t\tasync loadTrack(url, title, subtitle, options) {\n\t\t\t\t\tconst inst = instanceRef.current as {\n\t\t\t\t\t\tloadTrack?: (\n\t\t\t\t\t\t\tu: string,\n\t\t\t\t\t\t\tt?: string,\n\t\t\t\t\t\t\ts?: string,\n\t\t\t\t\t\t\to?: Record<string, unknown>\n\t\t\t\t\t\t) => Promise<void>;\n\t\t\t\t\t} | null;\n\t\t\t\t\tif (!inst?.loadTrack) return;\n\t\t\t\t\tawait inst.loadTrack(url, title, subtitle, options);\n\t\t\t\t},\n\t\t\t\tget instance() {\n\t\t\t\t\treturn instanceRef.current;\n\t\t\t\t},\n\t\t\t}),\n\t\t\t[]\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={containerRef}\n\t\t\t\tid={props.id}\n\t\t\t\tclassName={['wfp-host', props.className].filter(Boolean).join(' ')}\n\t\t\t\tstyle={props.style}\n\t\t\t/>\n\t\t);\n\t}\n);\n"]}
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@arraypress/waveform-player-react",
3
+ "version": "0.1.0",
4
+ "description": "React component wrapper for @arraypress/waveform-player — forwardRef-friendly, useEffect lifecycle, typed props for every library option.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist/",
19
+ "README.md",
20
+ "CHANGELOG.md",
21
+ "LICENSE"
22
+ ],
23
+ "keywords": [
24
+ "react",
25
+ "react-component",
26
+ "audio",
27
+ "player",
28
+ "waveform",
29
+ "visualization",
30
+ "music",
31
+ "sound",
32
+ "html5",
33
+ "web-audio",
34
+ "media-session",
35
+ "audio-player",
36
+ "waveform-visualization",
37
+ "podcast-player"
38
+ ],
39
+ "author": "ArrayPress",
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/arraypress/waveform-player-react.git"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/arraypress/waveform-player-react/issues"
47
+ },
48
+ "homepage": "https://waveformplayer.com",
49
+ "funding": {
50
+ "type": "github",
51
+ "url": "https://github.com/sponsors/arraypress"
52
+ },
53
+ "engines": {
54
+ "node": ">=18.0.0"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "registry": "https://registry.npmjs.org/"
59
+ },
60
+ "sideEffects": false,
61
+ "peerDependencies": {
62
+ "@arraypress/waveform-player": "^1.6.0",
63
+ "react": "^18.0.0 || ^19.0.0"
64
+ },
65
+ "scripts": {
66
+ "build": "tsup",
67
+ "dev": "tsup --watch",
68
+ "test": "vitest run",
69
+ "test:watch": "vitest",
70
+ "typecheck": "tsc --noEmit",
71
+ "prepublishOnly": "npm run build"
72
+ },
73
+ "devDependencies": {
74
+ "@arraypress/waveform-player": "^1.6.0",
75
+ "@testing-library/jest-dom": "^6.9.1",
76
+ "@testing-library/react": "^16.3.2",
77
+ "@types/react": "^19.2.15",
78
+ "@types/react-dom": "^19.2.3",
79
+ "jsdom": "^29.1.1",
80
+ "react": "^19.2.6",
81
+ "react-dom": "^19.2.6",
82
+ "tsup": "^8.5.1",
83
+ "typescript": "^6.0.3",
84
+ "vitest": "^4.1.7"
85
+ }
86
+ }