wavesurfer.js 7.2.0-beta.1 → 7.2.0-beta.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const
|
|
1
|
+
"use strict";class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const h=s=>{s.preventDefault(),s.stopPropagation();const n=s.clientX,r=s.clientY;if(u||Math.abs(n-l)>=o||Math.abs(r-a)>=o){const{left:s,top:o}=t.getBoundingClientRect();u||(u=!0,null==i||i(l-s,a-o)),e(n-l,r-a,n-s,r-o),l=n,a=r}},d=t=>{u&&(t.preventDefault(),t.stopPropagation())},p=()=>{u&&(null==s||s()),n()};document.addEventListener("pointermove",h),document.addEventListener("pointerup",p),document.addEventListener("pointerleave",p),document.addEventListener("click",d,!0),n=()=>{document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",p),document.removeEventListener("pointerleave",p),setTimeout((()=>{document.removeEventListener("click",d,!0)}),10)}};return t.addEventListener("pointerdown",r),()=>{n(),t.removeEventListener("pointerdown",r)}}const s={points:[],lineWidth:4,lineColor:"rgba(0, 0, 255, 0.5)",dragPointSize:10,dragPointFill:"rgba(255, 255, 255, 0.8)",dragPointStroke:"rgba(255, 255, 255, 0.8)"};class o extends t{constructor(t,e){super(),this.options=t,this.polyPoints=new Map;const s=e.clientWidth,o=e.clientHeight,n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.setAttribute("viewBox",`0 0 ${s} ${o}`),n.setAttribute("preserveAspectRatio","none"),n.setAttribute("style","position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none;"),n.setAttribute("part","envelope"),this.svg=n;const r=document.createElementNS("http://www.w3.org/2000/svg","polyline");r.setAttribute("points",`0,${o} ${s},${o}`),r.setAttribute("stroke",t.lineColor),r.setAttribute("stroke-width",t.lineWidth),r.setAttribute("fill","none"),r.setAttribute("part","polyline"),r.setAttribute("style","cursor: row-resize; pointer-events: stroke;"),n.appendChild(r),e.appendChild(n),i(r,((t,e)=>{const{height:i}=n.viewBox.baseVal,{points:s}=r;for(let t=1;t<s.numberOfItems-1;t++){const o=s.getItem(t);o.y=Math.min(i,Math.max(0,o.y+e))}const o=n.querySelectorAll("ellipse");Array.from(o).forEach((t=>{const s=Math.min(i,Math.max(0,Number(t.getAttribute("cy"))+e));t.setAttribute("cy",s.toString())})),this.emit("line-move",e/i)})),n.addEventListener("dblclick",(t=>{const e=n.getBoundingClientRect(),i=t.clientX-e.left,s=t.clientY-e.top;this.emit("point-create",i/e.width,s/e.height)}))}makeDraggable(t,e){i(t,e,(()=>t.style.cursor="grabbing"),(()=>t.style.cursor="grab"))}createCircle(t,e){const i=document.createElementNS("http://www.w3.org/2000/svg","ellipse"),s=this.options.dragPointSize/2;return i.setAttribute("rx",s.toString()),i.setAttribute("ry",s.toString()),i.setAttribute("fill",this.options.dragPointFill),i.setAttribute("stroke",this.options.dragPointStroke||this.options.dragPointFill),i.setAttribute("stroke-width","2"),i.setAttribute("style","cursor: grab; pointer-events: all;"),i.setAttribute("part","envelope-circle"),i.setAttribute("cx",t.toString()),i.setAttribute("cy",e.toString()),this.svg.appendChild(i),i}removePolyPoint(t){const e=this.polyPoints.get(t);if(!e)return;const{polyPoint:i,circle:s}=e,{points:o}=this.svg.querySelector("polyline"),n=Array.from(o).findIndex((t=>t.x===i.x&&t.y===i.y));o.removeItem(n),s.remove(),this.polyPoints.delete(t)}addPolyPoint(t,e,i){const{svg:s}=this,{width:o,height:n}=s.viewBox.baseVal,r=t*o,l=n-e*n,a=this.options.dragPointSize/2,u=s.createSVGPoint();u.x=t*o,u.y=n-e*n;const h=this.createCircle(r,l),{points:d}=s.querySelector("polyline"),p=Array.from(d).findIndex((t=>t.x>=r));d.insertItemBefore(u,Math.max(p,1)),this.polyPoints.set(i,{polyPoint:u,circle:h}),this.makeDraggable(h,((t,e)=>{const s=u.x+t,r=u.y+e;if(s<-a||r<-a||s>o+a||r>n+a)return void this.emit("point-dragout",i);const l=Array.from(d).find((t=>t.x>u.x)),p=Array.from(d).findLast((t=>t.x<u.x));l&&s>=l.x||p&&s<=p.x||(u.x=s,u.y=r,h.setAttribute("cx",s.toString()),h.setAttribute("cy",r.toString()),this.emit("point-move",i,s/o,r/n))}))}update(){const{svg:t}=this,e=t.viewBox.baseVal.width/t.clientWidth,i=t.viewBox.baseVal.height/t.clientHeight;t.querySelectorAll("ellipse").forEach((t=>{const s=this.options.dragPointSize/2,o=s*e,n=s*i;t.setAttribute("rx",o.toString()),t.setAttribute("ry",n.toString())}))}destroy(){this.polyPoints.clear(),this.svg.remove()}}const n=()=>Math.random().toString(36).slice(2);class r extends e{constructor(t){super(t),this.polyline=null,this.throttleTimeout=null,this.points=t.points||[],this.options=Object.assign({},s,t),this.options.lineColor=this.options.lineColor||s.lineColor,this.options.dragPointFill=this.options.dragPointFill||s.dragPointFill,this.options.dragPointStroke=this.options.dragPointStroke||s.dragPointStroke}static create(t){return new r(t)}addPoint(t){var e;const i=Object.assign(Object.assign({},t),{id:t.id||n()}),s=this.points.findLastIndex((e=>e.time<t.time));this.points.splice(s+1,0,i),this.emitPoints();const o=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDuration();o&&this.addPolyPoint(i,o)}removePoint(t){var e;this.points.splice(this.points.indexOf(t),1),null===(e=this.polyline)||void 0===e||e.removePolyPoint(t),this.emitPoints()}getPoints(){return this.points.map((t=>Object.freeze(Object.assign({},t))))}setPoints(t){this.points.slice().forEach((t=>this.removePoint(t))),t.forEach((t=>this.addPoint(t)))}getCurrentVolume(){var t;return(null===(t=this.wavesurfer)||void 0===t?void 0:t.getVolume())||1}destroy(){var t;null===(t=this.polyline)||void 0===t||t.destroy(),super.destroy()}onInit(){if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");const{options:t}=this;t.volume&&this.wavesurfer.setVolume(t.volume),this.subscriptions.push(this.wavesurfer.on("decode",(t=>{this.initPolyline(),this.points.forEach((e=>{this.addPolyPoint(e,t)}))})),this.wavesurfer.on("redraw",(()=>{var t;null===(t=this.polyline)||void 0===t||t.update()})),this.wavesurfer.on("timeupdate",(t=>{this.onTimeUpdate(t)})))}emitPoints(){this.throttleTimeout&&clearTimeout(this.throttleTimeout),this.throttleTimeout=setTimeout((()=>{this.emit("points-change",this.points)}),200)}initPolyline(){if(this.polyline&&this.polyline.destroy(),!this.wavesurfer)return;const t=this.wavesurfer.getWrapper();this.polyline=new o(this.options,t),this.subscriptions.push(this.polyline.on("point-move",((t,e,i)=>{var s;const o=(null===(s=this.wavesurfer)||void 0===s?void 0:s.getDuration())||0;t.time=e*o,t.volume=1-i,this.emitPoints()})),this.polyline.on("point-dragout",(t=>{this.removePoint(t)})),this.polyline.on("point-create",((t,e)=>{var i;this.addPoint({time:t*((null===(i=this.wavesurfer)||void 0===i?void 0:i.getDuration())||0),volume:1-e})})),this.polyline.on("line-move",(t=>{this.points.forEach((e=>{e.volume=Math.min(1,Math.max(0,e.volume-t))})),this.emitPoints()})))}addPolyPoint(t,e){var i;null===(i=this.polyline)||void 0===i||i.addPolyPoint(t.time/e,t.volume,t)}onTimeUpdate(t){if(!this.wavesurfer)return;let e=this.points.find((e=>e.time>t));e||(e={time:this.wavesurfer.getDuration()||0,volume:0,id:n()});let i=this.points.findLast((e=>e.time<=t));i||(i={time:0,volume:0,id:n()});const s=e.time-i.time,o=e.volume-i.volume,r=i.volume+(t-i.time)*(o/s);this.wavesurfer.setVolume(Math.min(1,Math.max(0,r))),this.emit("volume-change",r)}setVolume(){console.warn("[wavesurfer.js envelope plugin] `setVolume` is deprecated, use `wavesurfer.setVolume` instead.")}setStartTime(){console.warn("[wavesurfer.js envelope plugin] `setStartTime` is deprecated, use `setPoints` instead.")}setEndTime(){console.warn("[wavesurfer.js envelope plugin] `setEndTime` is deprecated, use `setPoints` instead.")}setFadeInEnd(){console.warn("[wavesurfer.js envelope plugin] `setFadeInEnd` is deprecated, use `setPoints` instead.")}setFadeOutStart(){console.warn("[wavesurfer.js envelope plugin] `setFadeOutStart` is deprecated, use `setPoints` instead.")}}module.exports=r;
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import BasePlugin, { type BasePluginEvents } from '../base-plugin.js';
|
|
5
5
|
export type EnvelopePoint = {
|
|
6
|
+
id: string;
|
|
6
7
|
time: number;
|
|
7
8
|
volume: number;
|
|
8
9
|
};
|
|
10
|
+
type PartialEnvelopePoint = Omit<EnvelopePoint, 'id'> & {
|
|
11
|
+
id?: string;
|
|
12
|
+
};
|
|
9
13
|
export type EnvelopePluginOptions = {
|
|
10
14
|
points?: EnvelopePoint[];
|
|
11
15
|
volume?: number;
|
|
@@ -49,11 +53,15 @@ declare class EnvelopePlugin extends BasePlugin<EnvelopePluginEvents, EnvelopePl
|
|
|
49
53
|
/**
|
|
50
54
|
* Add an envelope point with a given time and volume.
|
|
51
55
|
*/
|
|
52
|
-
addPoint(point:
|
|
56
|
+
addPoint(point: PartialEnvelopePoint): void;
|
|
53
57
|
/**
|
|
54
58
|
* Remove an envelope point.
|
|
55
59
|
*/
|
|
56
60
|
removePoint(point: EnvelopePoint): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current state of envelope points. Cannot be modified directly.
|
|
63
|
+
*/
|
|
64
|
+
getPoints(): EnvelopePoint[];
|
|
57
65
|
/**
|
|
58
66
|
* Set new envelope points.
|
|
59
67
|
*/
|
|
@@ -72,6 +80,10 @@ declare class EnvelopePlugin extends BasePlugin<EnvelopePluginEvents, EnvelopePl
|
|
|
72
80
|
private initPolyline;
|
|
73
81
|
private addPolyPoint;
|
|
74
82
|
private onTimeUpdate;
|
|
83
|
+
/**
|
|
84
|
+
* Deprecated: use `wavesurfer.setVolume` instead.
|
|
85
|
+
*/
|
|
86
|
+
setVolume(): void;
|
|
75
87
|
/**
|
|
76
88
|
* Deprecated: use `setPoints` instead.
|
|
77
89
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const
|
|
1
|
+
class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const h=s=>{s.preventDefault(),s.stopPropagation();const n=s.clientX,r=s.clientY;if(u||Math.abs(n-l)>=o||Math.abs(r-a)>=o){const{left:s,top:o}=t.getBoundingClientRect();u||(u=!0,null==i||i(l-s,a-o)),e(n-l,r-a,n-s,r-o),l=n,a=r}},d=t=>{u&&(t.preventDefault(),t.stopPropagation())},p=()=>{u&&(null==s||s()),n()};document.addEventListener("pointermove",h),document.addEventListener("pointerup",p),document.addEventListener("pointerleave",p),document.addEventListener("click",d,!0),n=()=>{document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",p),document.removeEventListener("pointerleave",p),setTimeout((()=>{document.removeEventListener("click",d,!0)}),10)}};return t.addEventListener("pointerdown",r),()=>{n(),t.removeEventListener("pointerdown",r)}}const s={points:[],lineWidth:4,lineColor:"rgba(0, 0, 255, 0.5)",dragPointSize:10,dragPointFill:"rgba(255, 255, 255, 0.8)",dragPointStroke:"rgba(255, 255, 255, 0.8)"};class o extends t{constructor(t,e){super(),this.options=t,this.polyPoints=new Map;const s=e.clientWidth,o=e.clientHeight,n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.setAttribute("viewBox",`0 0 ${s} ${o}`),n.setAttribute("preserveAspectRatio","none"),n.setAttribute("style","position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none;"),n.setAttribute("part","envelope"),this.svg=n;const r=document.createElementNS("http://www.w3.org/2000/svg","polyline");r.setAttribute("points",`0,${o} ${s},${o}`),r.setAttribute("stroke",t.lineColor),r.setAttribute("stroke-width",t.lineWidth),r.setAttribute("fill","none"),r.setAttribute("part","polyline"),r.setAttribute("style","cursor: row-resize; pointer-events: stroke;"),n.appendChild(r),e.appendChild(n),i(r,((t,e)=>{const{height:i}=n.viewBox.baseVal,{points:s}=r;for(let t=1;t<s.numberOfItems-1;t++){const o=s.getItem(t);o.y=Math.min(i,Math.max(0,o.y+e))}const o=n.querySelectorAll("ellipse");Array.from(o).forEach((t=>{const s=Math.min(i,Math.max(0,Number(t.getAttribute("cy"))+e));t.setAttribute("cy",s.toString())})),this.emit("line-move",e/i)})),n.addEventListener("dblclick",(t=>{const e=n.getBoundingClientRect(),i=t.clientX-e.left,s=t.clientY-e.top;this.emit("point-create",i/e.width,s/e.height)}))}makeDraggable(t,e){i(t,e,(()=>t.style.cursor="grabbing"),(()=>t.style.cursor="grab"))}createCircle(t,e){const i=document.createElementNS("http://www.w3.org/2000/svg","ellipse"),s=this.options.dragPointSize/2;return i.setAttribute("rx",s.toString()),i.setAttribute("ry",s.toString()),i.setAttribute("fill",this.options.dragPointFill),i.setAttribute("stroke",this.options.dragPointStroke||this.options.dragPointFill),i.setAttribute("stroke-width","2"),i.setAttribute("style","cursor: grab; pointer-events: all;"),i.setAttribute("part","envelope-circle"),i.setAttribute("cx",t.toString()),i.setAttribute("cy",e.toString()),this.svg.appendChild(i),i}removePolyPoint(t){const e=this.polyPoints.get(t);if(!e)return;const{polyPoint:i,circle:s}=e,{points:o}=this.svg.querySelector("polyline"),n=Array.from(o).findIndex((t=>t.x===i.x&&t.y===i.y));o.removeItem(n),s.remove(),this.polyPoints.delete(t)}addPolyPoint(t,e,i){const{svg:s}=this,{width:o,height:n}=s.viewBox.baseVal,r=t*o,l=n-e*n,a=this.options.dragPointSize/2,u=s.createSVGPoint();u.x=t*o,u.y=n-e*n;const h=this.createCircle(r,l),{points:d}=s.querySelector("polyline"),p=Array.from(d).findIndex((t=>t.x>=r));d.insertItemBefore(u,Math.max(p,1)),this.polyPoints.set(i,{polyPoint:u,circle:h}),this.makeDraggable(h,((t,e)=>{const s=u.x+t,r=u.y+e;if(s<-a||r<-a||s>o+a||r>n+a)return void this.emit("point-dragout",i);const l=Array.from(d).find((t=>t.x>u.x)),p=Array.from(d).findLast((t=>t.x<u.x));l&&s>=l.x||p&&s<=p.x||(u.x=s,u.y=r,h.setAttribute("cx",s.toString()),h.setAttribute("cy",r.toString()),this.emit("point-move",i,s/o,r/n))}))}update(){const{svg:t}=this,e=t.viewBox.baseVal.width/t.clientWidth,i=t.viewBox.baseVal.height/t.clientHeight;t.querySelectorAll("ellipse").forEach((t=>{const s=this.options.dragPointSize/2,o=s*e,n=s*i;t.setAttribute("rx",o.toString()),t.setAttribute("ry",n.toString())}))}destroy(){this.polyPoints.clear(),this.svg.remove()}}const n=()=>Math.random().toString(36).slice(2);class r extends e{constructor(t){super(t),this.polyline=null,this.throttleTimeout=null,this.points=t.points||[],this.options=Object.assign({},s,t),this.options.lineColor=this.options.lineColor||s.lineColor,this.options.dragPointFill=this.options.dragPointFill||s.dragPointFill,this.options.dragPointStroke=this.options.dragPointStroke||s.dragPointStroke}static create(t){return new r(t)}addPoint(t){var e;const i=Object.assign(Object.assign({},t),{id:t.id||n()}),s=this.points.findLastIndex((e=>e.time<t.time));this.points.splice(s+1,0,i),this.emitPoints();const o=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDuration();o&&this.addPolyPoint(i,o)}removePoint(t){var e;this.points.splice(this.points.indexOf(t),1),null===(e=this.polyline)||void 0===e||e.removePolyPoint(t),this.emitPoints()}getPoints(){return this.points.map((t=>Object.freeze(Object.assign({},t))))}setPoints(t){this.points.slice().forEach((t=>this.removePoint(t))),t.forEach((t=>this.addPoint(t)))}getCurrentVolume(){var t;return(null===(t=this.wavesurfer)||void 0===t?void 0:t.getVolume())||1}destroy(){var t;null===(t=this.polyline)||void 0===t||t.destroy(),super.destroy()}onInit(){if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");const{options:t}=this;t.volume&&this.wavesurfer.setVolume(t.volume),this.subscriptions.push(this.wavesurfer.on("decode",(t=>{this.initPolyline(),this.points.forEach((e=>{this.addPolyPoint(e,t)}))})),this.wavesurfer.on("redraw",(()=>{var t;null===(t=this.polyline)||void 0===t||t.update()})),this.wavesurfer.on("timeupdate",(t=>{this.onTimeUpdate(t)})))}emitPoints(){this.throttleTimeout&&clearTimeout(this.throttleTimeout),this.throttleTimeout=setTimeout((()=>{this.emit("points-change",this.points)}),200)}initPolyline(){if(this.polyline&&this.polyline.destroy(),!this.wavesurfer)return;const t=this.wavesurfer.getWrapper();this.polyline=new o(this.options,t),this.subscriptions.push(this.polyline.on("point-move",((t,e,i)=>{var s;const o=(null===(s=this.wavesurfer)||void 0===s?void 0:s.getDuration())||0;t.time=e*o,t.volume=1-i,this.emitPoints()})),this.polyline.on("point-dragout",(t=>{this.removePoint(t)})),this.polyline.on("point-create",((t,e)=>{var i;this.addPoint({time:t*((null===(i=this.wavesurfer)||void 0===i?void 0:i.getDuration())||0),volume:1-e})})),this.polyline.on("line-move",(t=>{this.points.forEach((e=>{e.volume=Math.min(1,Math.max(0,e.volume-t))})),this.emitPoints()})))}addPolyPoint(t,e){var i;null===(i=this.polyline)||void 0===i||i.addPolyPoint(t.time/e,t.volume,t)}onTimeUpdate(t){if(!this.wavesurfer)return;let e=this.points.find((e=>e.time>t));e||(e={time:this.wavesurfer.getDuration()||0,volume:0,id:n()});let i=this.points.findLast((e=>e.time<=t));i||(i={time:0,volume:0,id:n()});const s=e.time-i.time,o=e.volume-i.volume,r=i.volume+(t-i.time)*(o/s);this.wavesurfer.setVolume(Math.min(1,Math.max(0,r))),this.emit("volume-change",r)}setVolume(){console.warn("[wavesurfer.js envelope plugin] `setVolume` is deprecated, use `wavesurfer.setVolume` instead.")}setStartTime(){console.warn("[wavesurfer.js envelope plugin] `setStartTime` is deprecated, use `setPoints` instead.")}setEndTime(){console.warn("[wavesurfer.js envelope plugin] `setEndTime` is deprecated, use `setPoints` instead.")}setFadeInEnd(){console.warn("[wavesurfer.js envelope plugin] `setFadeInEnd` is deprecated, use `setPoints` instead.")}setFadeOutStart(){console.warn("[wavesurfer.js envelope plugin] `setFadeOutStart` is deprecated, use `setPoints` instead.")}}export{r as default};
|
package/dist/plugins/envelope.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const
|
|
1
|
+
class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const h=s=>{s.preventDefault(),s.stopPropagation();const n=s.clientX,r=s.clientY;if(u||Math.abs(n-l)>=o||Math.abs(r-a)>=o){const{left:s,top:o}=t.getBoundingClientRect();u||(u=!0,null==i||i(l-s,a-o)),e(n-l,r-a,n-s,r-o),l=n,a=r}},d=t=>{u&&(t.preventDefault(),t.stopPropagation())},p=()=>{u&&(null==s||s()),n()};document.addEventListener("pointermove",h),document.addEventListener("pointerup",p),document.addEventListener("pointerleave",p),document.addEventListener("click",d,!0),n=()=>{document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",p),document.removeEventListener("pointerleave",p),setTimeout((()=>{document.removeEventListener("click",d,!0)}),10)}};return t.addEventListener("pointerdown",r),()=>{n(),t.removeEventListener("pointerdown",r)}}const s={points:[],lineWidth:4,lineColor:"rgba(0, 0, 255, 0.5)",dragPointSize:10,dragPointFill:"rgba(255, 255, 255, 0.8)",dragPointStroke:"rgba(255, 255, 255, 0.8)"};class o extends t{constructor(t,e){super(),this.options=t,this.polyPoints=new Map;const s=e.clientWidth,o=e.clientHeight,n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.setAttribute("viewBox",`0 0 ${s} ${o}`),n.setAttribute("preserveAspectRatio","none"),n.setAttribute("style","position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none;"),n.setAttribute("part","envelope"),this.svg=n;const r=document.createElementNS("http://www.w3.org/2000/svg","polyline");r.setAttribute("points",`0,${o} ${s},${o}`),r.setAttribute("stroke",t.lineColor),r.setAttribute("stroke-width",t.lineWidth),r.setAttribute("fill","none"),r.setAttribute("part","polyline"),r.setAttribute("style","cursor: row-resize; pointer-events: stroke;"),n.appendChild(r),e.appendChild(n),i(r,((t,e)=>{const{height:i}=n.viewBox.baseVal,{points:s}=r;for(let t=1;t<s.numberOfItems-1;t++){const o=s.getItem(t);o.y=Math.min(i,Math.max(0,o.y+e))}const o=n.querySelectorAll("ellipse");Array.from(o).forEach((t=>{const s=Math.min(i,Math.max(0,Number(t.getAttribute("cy"))+e));t.setAttribute("cy",s.toString())})),this.emit("line-move",e/i)})),n.addEventListener("dblclick",(t=>{const e=n.getBoundingClientRect(),i=t.clientX-e.left,s=t.clientY-e.top;this.emit("point-create",i/e.width,s/e.height)}))}makeDraggable(t,e){i(t,e,(()=>t.style.cursor="grabbing"),(()=>t.style.cursor="grab"))}createCircle(t,e){const i=document.createElementNS("http://www.w3.org/2000/svg","ellipse"),s=this.options.dragPointSize/2;return i.setAttribute("rx",s.toString()),i.setAttribute("ry",s.toString()),i.setAttribute("fill",this.options.dragPointFill),i.setAttribute("stroke",this.options.dragPointStroke||this.options.dragPointFill),i.setAttribute("stroke-width","2"),i.setAttribute("style","cursor: grab; pointer-events: all;"),i.setAttribute("part","envelope-circle"),i.setAttribute("cx",t.toString()),i.setAttribute("cy",e.toString()),this.svg.appendChild(i),i}removePolyPoint(t){const e=this.polyPoints.get(t);if(!e)return;const{polyPoint:i,circle:s}=e,{points:o}=this.svg.querySelector("polyline"),n=Array.from(o).findIndex((t=>t.x===i.x&&t.y===i.y));o.removeItem(n),s.remove(),this.polyPoints.delete(t)}addPolyPoint(t,e,i){const{svg:s}=this,{width:o,height:n}=s.viewBox.baseVal,r=t*o,l=n-e*n,a=this.options.dragPointSize/2,u=s.createSVGPoint();u.x=t*o,u.y=n-e*n;const h=this.createCircle(r,l),{points:d}=s.querySelector("polyline"),p=Array.from(d).findIndex((t=>t.x>=r));d.insertItemBefore(u,Math.max(p,1)),this.polyPoints.set(i,{polyPoint:u,circle:h}),this.makeDraggable(h,((t,e)=>{const s=u.x+t,r=u.y+e;if(s<-a||r<-a||s>o+a||r>n+a)return void this.emit("point-dragout",i);const l=Array.from(d).find((t=>t.x>u.x)),p=Array.from(d).findLast((t=>t.x<u.x));l&&s>=l.x||p&&s<=p.x||(u.x=s,u.y=r,h.setAttribute("cx",s.toString()),h.setAttribute("cy",r.toString()),this.emit("point-move",i,s/o,r/n))}))}update(){const{svg:t}=this,e=t.viewBox.baseVal.width/t.clientWidth,i=t.viewBox.baseVal.height/t.clientHeight;t.querySelectorAll("ellipse").forEach((t=>{const s=this.options.dragPointSize/2,o=s*e,n=s*i;t.setAttribute("rx",o.toString()),t.setAttribute("ry",n.toString())}))}destroy(){this.polyPoints.clear(),this.svg.remove()}}const n=()=>Math.random().toString(36).slice(2);class r extends e{constructor(t){super(t),this.polyline=null,this.throttleTimeout=null,this.points=t.points||[],this.options=Object.assign({},s,t),this.options.lineColor=this.options.lineColor||s.lineColor,this.options.dragPointFill=this.options.dragPointFill||s.dragPointFill,this.options.dragPointStroke=this.options.dragPointStroke||s.dragPointStroke}static create(t){return new r(t)}addPoint(t){var e;const i=Object.assign(Object.assign({},t),{id:t.id||n()}),s=this.points.findLastIndex((e=>e.time<t.time));this.points.splice(s+1,0,i),this.emitPoints();const o=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDuration();o&&this.addPolyPoint(i,o)}removePoint(t){var e;this.points.splice(this.points.indexOf(t),1),null===(e=this.polyline)||void 0===e||e.removePolyPoint(t),this.emitPoints()}getPoints(){return this.points.map((t=>Object.freeze(Object.assign({},t))))}setPoints(t){this.points.slice().forEach((t=>this.removePoint(t))),t.forEach((t=>this.addPoint(t)))}getCurrentVolume(){var t;return(null===(t=this.wavesurfer)||void 0===t?void 0:t.getVolume())||1}destroy(){var t;null===(t=this.polyline)||void 0===t||t.destroy(),super.destroy()}onInit(){if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");const{options:t}=this;t.volume&&this.wavesurfer.setVolume(t.volume),this.subscriptions.push(this.wavesurfer.on("decode",(t=>{this.initPolyline(),this.points.forEach((e=>{this.addPolyPoint(e,t)}))})),this.wavesurfer.on("redraw",(()=>{var t;null===(t=this.polyline)||void 0===t||t.update()})),this.wavesurfer.on("timeupdate",(t=>{this.onTimeUpdate(t)})))}emitPoints(){this.throttleTimeout&&clearTimeout(this.throttleTimeout),this.throttleTimeout=setTimeout((()=>{this.emit("points-change",this.points)}),200)}initPolyline(){if(this.polyline&&this.polyline.destroy(),!this.wavesurfer)return;const t=this.wavesurfer.getWrapper();this.polyline=new o(this.options,t),this.subscriptions.push(this.polyline.on("point-move",((t,e,i)=>{var s;const o=(null===(s=this.wavesurfer)||void 0===s?void 0:s.getDuration())||0;t.time=e*o,t.volume=1-i,this.emitPoints()})),this.polyline.on("point-dragout",(t=>{this.removePoint(t)})),this.polyline.on("point-create",((t,e)=>{var i;this.addPoint({time:t*((null===(i=this.wavesurfer)||void 0===i?void 0:i.getDuration())||0),volume:1-e})})),this.polyline.on("line-move",(t=>{this.points.forEach((e=>{e.volume=Math.min(1,Math.max(0,e.volume-t))})),this.emitPoints()})))}addPolyPoint(t,e){var i;null===(i=this.polyline)||void 0===i||i.addPolyPoint(t.time/e,t.volume,t)}onTimeUpdate(t){if(!this.wavesurfer)return;let e=this.points.find((e=>e.time>t));e||(e={time:this.wavesurfer.getDuration()||0,volume:0,id:n()});let i=this.points.findLast((e=>e.time<=t));i||(i={time:0,volume:0,id:n()});const s=e.time-i.time,o=e.volume-i.volume,r=i.volume+(t-i.time)*(o/s);this.wavesurfer.setVolume(Math.min(1,Math.max(0,r))),this.emit("volume-change",r)}setVolume(){console.warn("[wavesurfer.js envelope plugin] `setVolume` is deprecated, use `wavesurfer.setVolume` instead.")}setStartTime(){console.warn("[wavesurfer.js envelope plugin] `setStartTime` is deprecated, use `setPoints` instead.")}setEndTime(){console.warn("[wavesurfer.js envelope plugin] `setEndTime` is deprecated, use `setPoints` instead.")}setFadeInEnd(){console.warn("[wavesurfer.js envelope plugin] `setFadeInEnd` is deprecated, use `setPoints` instead.")}setFadeOutStart(){console.warn("[wavesurfer.js envelope plugin] `setFadeOutStart` is deprecated, use `setPoints` instead.")}}export{r as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).WaveSurfer=t.WaveSurfer||{},t.WaveSurfer.Envelope=e())}(this,(function(){"use strict";class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):((t="undefined"!=typeof globalThis?globalThis:t||self).WaveSurfer=t.WaveSurfer||{},t.WaveSurfer.Envelope=e())}(this,(function(){"use strict";class t{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),s=this.on(t,(()=>{i(),s()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}}class e extends t{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}}function i(t,e,i,s,o=5){let n=()=>{};if(!t)return n;const r=r=>{if(2===r.button)return;r.preventDefault(),r.stopPropagation();let l=r.clientX,a=r.clientY,u=!1;const h=s=>{s.preventDefault(),s.stopPropagation();const n=s.clientX,r=s.clientY;if(u||Math.abs(n-l)>=o||Math.abs(r-a)>=o){const{left:s,top:o}=t.getBoundingClientRect();u||(u=!0,null==i||i(l-s,a-o)),e(n-l,r-a,n-s,r-o),l=n,a=r}},d=t=>{u&&(t.preventDefault(),t.stopPropagation())},p=()=>{u&&(null==s||s()),n()};document.addEventListener("pointermove",h),document.addEventListener("pointerup",p),document.addEventListener("pointerleave",p),document.addEventListener("click",d,!0),n=()=>{document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",p),document.removeEventListener("pointerleave",p),setTimeout((()=>{document.removeEventListener("click",d,!0)}),10)}};return t.addEventListener("pointerdown",r),()=>{n(),t.removeEventListener("pointerdown",r)}}const s={points:[],lineWidth:4,lineColor:"rgba(0, 0, 255, 0.5)",dragPointSize:10,dragPointFill:"rgba(255, 255, 255, 0.8)",dragPointStroke:"rgba(255, 255, 255, 0.8)"};class o extends t{constructor(t,e){super(),this.options=t,this.polyPoints=new Map;const s=e.clientWidth,o=e.clientHeight,n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.setAttribute("viewBox",`0 0 ${s} ${o}`),n.setAttribute("preserveAspectRatio","none"),n.setAttribute("style","position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none;"),n.setAttribute("part","envelope"),this.svg=n;const r=document.createElementNS("http://www.w3.org/2000/svg","polyline");r.setAttribute("points",`0,${o} ${s},${o}`),r.setAttribute("stroke",t.lineColor),r.setAttribute("stroke-width",t.lineWidth),r.setAttribute("fill","none"),r.setAttribute("part","polyline"),r.setAttribute("style","cursor: row-resize; pointer-events: stroke;"),n.appendChild(r),e.appendChild(n),i(r,((t,e)=>{const{height:i}=n.viewBox.baseVal,{points:s}=r;for(let t=1;t<s.numberOfItems-1;t++){const o=s.getItem(t);o.y=Math.min(i,Math.max(0,o.y+e))}const o=n.querySelectorAll("ellipse");Array.from(o).forEach((t=>{const s=Math.min(i,Math.max(0,Number(t.getAttribute("cy"))+e));t.setAttribute("cy",s.toString())})),this.emit("line-move",e/i)})),n.addEventListener("dblclick",(t=>{const e=n.getBoundingClientRect(),i=t.clientX-e.left,s=t.clientY-e.top;this.emit("point-create",i/e.width,s/e.height)}))}makeDraggable(t,e){i(t,e,(()=>t.style.cursor="grabbing"),(()=>t.style.cursor="grab"))}createCircle(t,e){const i=document.createElementNS("http://www.w3.org/2000/svg","ellipse"),s=this.options.dragPointSize/2;return i.setAttribute("rx",s.toString()),i.setAttribute("ry",s.toString()),i.setAttribute("fill",this.options.dragPointFill),i.setAttribute("stroke",this.options.dragPointStroke||this.options.dragPointFill),i.setAttribute("stroke-width","2"),i.setAttribute("style","cursor: grab; pointer-events: all;"),i.setAttribute("part","envelope-circle"),i.setAttribute("cx",t.toString()),i.setAttribute("cy",e.toString()),this.svg.appendChild(i),i}removePolyPoint(t){const e=this.polyPoints.get(t);if(!e)return;const{polyPoint:i,circle:s}=e,{points:o}=this.svg.querySelector("polyline"),n=Array.from(o).findIndex((t=>t.x===i.x&&t.y===i.y));o.removeItem(n),s.remove(),this.polyPoints.delete(t)}addPolyPoint(t,e,i){const{svg:s}=this,{width:o,height:n}=s.viewBox.baseVal,r=t*o,l=n-e*n,a=this.options.dragPointSize/2,u=s.createSVGPoint();u.x=t*o,u.y=n-e*n;const h=this.createCircle(r,l),{points:d}=s.querySelector("polyline"),p=Array.from(d).findIndex((t=>t.x>=r));d.insertItemBefore(u,Math.max(p,1)),this.polyPoints.set(i,{polyPoint:u,circle:h}),this.makeDraggable(h,((t,e)=>{const s=u.x+t,r=u.y+e;if(s<-a||r<-a||s>o+a||r>n+a)return void this.emit("point-dragout",i);const l=Array.from(d).find((t=>t.x>u.x)),p=Array.from(d).findLast((t=>t.x<u.x));l&&s>=l.x||p&&s<=p.x||(u.x=s,u.y=r,h.setAttribute("cx",s.toString()),h.setAttribute("cy",r.toString()),this.emit("point-move",i,s/o,r/n))}))}update(){const{svg:t}=this,e=t.viewBox.baseVal.width/t.clientWidth,i=t.viewBox.baseVal.height/t.clientHeight;t.querySelectorAll("ellipse").forEach((t=>{const s=this.options.dragPointSize/2,o=s*e,n=s*i;t.setAttribute("rx",o.toString()),t.setAttribute("ry",n.toString())}))}destroy(){this.polyPoints.clear(),this.svg.remove()}}const n=()=>Math.random().toString(36).slice(2);class r extends e{constructor(t){super(t),this.polyline=null,this.throttleTimeout=null,this.points=t.points||[],this.options=Object.assign({},s,t),this.options.lineColor=this.options.lineColor||s.lineColor,this.options.dragPointFill=this.options.dragPointFill||s.dragPointFill,this.options.dragPointStroke=this.options.dragPointStroke||s.dragPointStroke}static create(t){return new r(t)}addPoint(t){var e;const i=Object.assign(Object.assign({},t),{id:t.id||n()}),s=this.points.findLastIndex((e=>e.time<t.time));this.points.splice(s+1,0,i),this.emitPoints();const o=null===(e=this.wavesurfer)||void 0===e?void 0:e.getDuration();o&&this.addPolyPoint(i,o)}removePoint(t){var e;this.points.splice(this.points.indexOf(t),1),null===(e=this.polyline)||void 0===e||e.removePolyPoint(t),this.emitPoints()}getPoints(){return this.points.map((t=>Object.freeze(Object.assign({},t))))}setPoints(t){this.points.slice().forEach((t=>this.removePoint(t))),t.forEach((t=>this.addPoint(t)))}getCurrentVolume(){var t;return(null===(t=this.wavesurfer)||void 0===t?void 0:t.getVolume())||1}destroy(){var t;null===(t=this.polyline)||void 0===t||t.destroy(),super.destroy()}onInit(){if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");const{options:t}=this;t.volume&&this.wavesurfer.setVolume(t.volume),this.subscriptions.push(this.wavesurfer.on("decode",(t=>{this.initPolyline(),this.points.forEach((e=>{this.addPolyPoint(e,t)}))})),this.wavesurfer.on("redraw",(()=>{var t;null===(t=this.polyline)||void 0===t||t.update()})),this.wavesurfer.on("timeupdate",(t=>{this.onTimeUpdate(t)})))}emitPoints(){this.throttleTimeout&&clearTimeout(this.throttleTimeout),this.throttleTimeout=setTimeout((()=>{this.emit("points-change",this.points)}),200)}initPolyline(){if(this.polyline&&this.polyline.destroy(),!this.wavesurfer)return;const t=this.wavesurfer.getWrapper();this.polyline=new o(this.options,t),this.subscriptions.push(this.polyline.on("point-move",((t,e,i)=>{var s;const o=(null===(s=this.wavesurfer)||void 0===s?void 0:s.getDuration())||0;t.time=e*o,t.volume=1-i,this.emitPoints()})),this.polyline.on("point-dragout",(t=>{this.removePoint(t)})),this.polyline.on("point-create",((t,e)=>{var i;this.addPoint({time:t*((null===(i=this.wavesurfer)||void 0===i?void 0:i.getDuration())||0),volume:1-e})})),this.polyline.on("line-move",(t=>{this.points.forEach((e=>{e.volume=Math.min(1,Math.max(0,e.volume-t))})),this.emitPoints()})))}addPolyPoint(t,e){var i;null===(i=this.polyline)||void 0===i||i.addPolyPoint(t.time/e,t.volume,t)}onTimeUpdate(t){if(!this.wavesurfer)return;let e=this.points.find((e=>e.time>t));e||(e={time:this.wavesurfer.getDuration()||0,volume:0,id:n()});let i=this.points.findLast((e=>e.time<=t));i||(i={time:0,volume:0,id:n()});const s=e.time-i.time,o=e.volume-i.volume,r=i.volume+(t-i.time)*(o/s);this.wavesurfer.setVolume(Math.min(1,Math.max(0,r))),this.emit("volume-change",r)}setVolume(){console.warn("[wavesurfer.js envelope plugin] `setVolume` is deprecated, use `wavesurfer.setVolume` instead.")}setStartTime(){console.warn("[wavesurfer.js envelope plugin] `setStartTime` is deprecated, use `setPoints` instead.")}setEndTime(){console.warn("[wavesurfer.js envelope plugin] `setEndTime` is deprecated, use `setPoints` instead.")}setFadeInEnd(){console.warn("[wavesurfer.js envelope plugin] `setFadeInEnd` is deprecated, use `setPoints` instead.")}setFadeOutStart(){console.warn("[wavesurfer.js envelope plugin] `setFadeOutStart` is deprecated, use `setPoints` instead.")}}return r}));
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import BasePlugin, { type BasePluginEvents } from '../base-plugin.js';
|
|
5
5
|
export type EnvelopePoint = {
|
|
6
|
+
id: string;
|
|
6
7
|
time: number;
|
|
7
8
|
volume: number;
|
|
8
9
|
};
|
|
10
|
+
type PartialEnvelopePoint = Omit<EnvelopePoint, 'id'> & {
|
|
11
|
+
id?: string;
|
|
12
|
+
};
|
|
9
13
|
export type EnvelopePluginOptions = {
|
|
10
14
|
points?: EnvelopePoint[];
|
|
11
15
|
volume?: number;
|
|
@@ -49,11 +53,15 @@ declare class EnvelopePlugin extends BasePlugin<EnvelopePluginEvents, EnvelopePl
|
|
|
49
53
|
/**
|
|
50
54
|
* Add an envelope point with a given time and volume.
|
|
51
55
|
*/
|
|
52
|
-
addPoint(point:
|
|
56
|
+
addPoint(point: PartialEnvelopePoint): void;
|
|
53
57
|
/**
|
|
54
58
|
* Remove an envelope point.
|
|
55
59
|
*/
|
|
56
60
|
removePoint(point: EnvelopePoint): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current state of envelope points. Cannot be modified directly.
|
|
63
|
+
*/
|
|
64
|
+
getPoints(): EnvelopePoint[];
|
|
57
65
|
/**
|
|
58
66
|
* Set new envelope points.
|
|
59
67
|
*/
|
|
@@ -72,6 +80,10 @@ declare class EnvelopePlugin extends BasePlugin<EnvelopePluginEvents, EnvelopePl
|
|
|
72
80
|
private initPolyline;
|
|
73
81
|
private addPolyPoint;
|
|
74
82
|
private onTimeUpdate;
|
|
83
|
+
/**
|
|
84
|
+
* Deprecated: use `wavesurfer.setVolume` instead.
|
|
85
|
+
*/
|
|
86
|
+
setVolume(): void;
|
|
75
87
|
/**
|
|
76
88
|
* Deprecated: use `setPoints` instead.
|
|
77
89
|
*/
|