@arraypress/waveform-sounds 0.1.0 → 0.1.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.
@@ -37,7 +37,7 @@ __export(entry_exports, {
37
37
  });
38
38
  module.exports = __toCommonJS(entry_exports);
39
39
 
40
- // ../../Core/text/src/index.js
40
+ // node_modules/@arraypress/text/src/index.js
41
41
  var HTML_ESCAPES = Object.freeze({
42
42
  "&": "&",
43
43
  "<": "&lt;",
@@ -280,6 +280,21 @@ function resample(peaks, count) {
280
280
  }
281
281
  return out;
282
282
  }
283
+ function barRects(peaks, width, height, o) {
284
+ const step = o.barWidth + o.barGap;
285
+ const bars = resample(peaks, Math.max(1, Math.floor((width + o.barGap) / step)));
286
+ const max = bars.reduce((m, b) => b > m ? b : m, 0);
287
+ const scale = max > 0 ? 1 / max : 1;
288
+ return bars.map((b, i) => {
289
+ const v = Math.max(b * scale, 0.04);
290
+ if (o.style === "bars") {
291
+ const h3 = Math.max(1, v * height);
292
+ return { x: i * step, y: height - h3, w: o.barWidth, h: h3 };
293
+ }
294
+ const h2 = Math.max(1, v * (height - 2));
295
+ return { x: i * step, y: height / 2 - h2 / 2, w: o.barWidth, h: h2 };
296
+ });
297
+ }
283
298
  function drawRowWaveform(canvas, peaks, progress, o) {
284
299
  const size = fitCanvas(canvas);
285
300
  const ctx = size && canvas.getContext && canvas.getContext("2d");
@@ -292,25 +307,19 @@ function drawRowWaveform(canvas, peaks, progress, o) {
292
307
  ctx.fillRect(0, Math.floor(height / 2), width, 1);
293
308
  return;
294
309
  }
295
- const step = o.barWidth + o.barGap;
296
- const count = Math.max(1, Math.floor((width + o.barGap) / step));
297
- const bars = resample(peaks, count);
298
- let max = 0;
299
- for (const b of bars) if (b > max) max = b;
300
- const scale = max > 0 ? 1 / max : 1;
301
- const split = progress * width;
302
- const mid = height / 2;
303
- for (let i = 0; i < bars.length; i++) {
304
- const x = i * step;
305
- const v = Math.max(bars[i] * scale, 0.04);
306
- ctx.fillStyle = x + o.barWidth / 2 <= split ? o.progressColor : o.color;
307
- if (o.style === "bars") {
308
- const h2 = Math.max(1, v * height);
309
- ctx.fillRect(x, height - h2, o.barWidth, h2);
310
- } else {
311
- const h2 = Math.max(1, v * (height - 2));
312
- ctx.fillRect(x, mid - h2 / 2, o.barWidth, h2);
313
- }
310
+ const path = new Path2D();
311
+ for (const r of barRects(peaks, width, height, o)) path.rect(r.x, r.y, r.w, r.h);
312
+ ctx.fillStyle = o.color;
313
+ ctx.fill(path);
314
+ const split = Math.min(Math.max(progress, 0), 1) * width;
315
+ if (split > 0) {
316
+ ctx.save();
317
+ ctx.beginPath();
318
+ ctx.rect(0, 0, split, height);
319
+ ctx.clip();
320
+ ctx.fillStyle = o.progressColor;
321
+ ctx.fill(path);
322
+ ctx.restore();
314
323
  }
315
324
  }
316
325
 
@@ -1,4 +1,4 @@
1
- // ../../Core/text/src/index.js
1
+ // node_modules/@arraypress/text/src/index.js
2
2
  var HTML_ESCAPES = Object.freeze({
3
3
  "&": "&amp;",
4
4
  "<": "&lt;",
@@ -241,6 +241,21 @@ function resample(peaks, count) {
241
241
  }
242
242
  return out;
243
243
  }
244
+ function barRects(peaks, width, height, o) {
245
+ const step = o.barWidth + o.barGap;
246
+ const bars = resample(peaks, Math.max(1, Math.floor((width + o.barGap) / step)));
247
+ const max = bars.reduce((m, b) => b > m ? b : m, 0);
248
+ const scale = max > 0 ? 1 / max : 1;
249
+ return bars.map((b, i) => {
250
+ const v = Math.max(b * scale, 0.04);
251
+ if (o.style === "bars") {
252
+ const h3 = Math.max(1, v * height);
253
+ return { x: i * step, y: height - h3, w: o.barWidth, h: h3 };
254
+ }
255
+ const h2 = Math.max(1, v * (height - 2));
256
+ return { x: i * step, y: height / 2 - h2 / 2, w: o.barWidth, h: h2 };
257
+ });
258
+ }
244
259
  function drawRowWaveform(canvas, peaks, progress, o) {
245
260
  const size = fitCanvas(canvas);
246
261
  const ctx = size && canvas.getContext && canvas.getContext("2d");
@@ -253,25 +268,19 @@ function drawRowWaveform(canvas, peaks, progress, o) {
253
268
  ctx.fillRect(0, Math.floor(height / 2), width, 1);
254
269
  return;
255
270
  }
256
- const step = o.barWidth + o.barGap;
257
- const count = Math.max(1, Math.floor((width + o.barGap) / step));
258
- const bars = resample(peaks, count);
259
- let max = 0;
260
- for (const b of bars) if (b > max) max = b;
261
- const scale = max > 0 ? 1 / max : 1;
262
- const split = progress * width;
263
- const mid = height / 2;
264
- for (let i = 0; i < bars.length; i++) {
265
- const x = i * step;
266
- const v = Math.max(bars[i] * scale, 0.04);
267
- ctx.fillStyle = x + o.barWidth / 2 <= split ? o.progressColor : o.color;
268
- if (o.style === "bars") {
269
- const h2 = Math.max(1, v * height);
270
- ctx.fillRect(x, height - h2, o.barWidth, h2);
271
- } else {
272
- const h2 = Math.max(1, v * (height - 2));
273
- ctx.fillRect(x, mid - h2 / 2, o.barWidth, h2);
274
- }
271
+ const path = new Path2D();
272
+ for (const r of barRects(peaks, width, height, o)) path.rect(r.x, r.y, r.w, r.h);
273
+ ctx.fillStyle = o.color;
274
+ ctx.fill(path);
275
+ const split = Math.min(Math.max(progress, 0), 1) * width;
276
+ if (split > 0) {
277
+ ctx.save();
278
+ ctx.beginPath();
279
+ ctx.rect(0, 0, split, height);
280
+ ctx.clip();
281
+ ctx.fillStyle = o.progressColor;
282
+ ctx.fill(path);
283
+ ctx.restore();
275
284
  }
276
285
  }
277
286
 
@@ -33,7 +33,7 @@ __export(render_entry_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(render_entry_exports);
35
35
 
36
- // ../../Core/text/src/index.js
36
+ // node_modules/@arraypress/text/src/index.js
37
37
  var HTML_ESCAPES = Object.freeze({
38
38
  "&": "&amp;",
39
39
  "<": "&lt;",
@@ -1,4 +1,4 @@
1
- // ../../Core/text/src/index.js
1
+ // node_modules/@arraypress/text/src/index.js
2
2
  var HTML_ESCAPES = Object.freeze({
3
3
  "&": "&amp;",
4
4
  "<": "&lt;",
@@ -37,7 +37,7 @@ __export(index_exports, {
37
37
  });
38
38
  module.exports = __toCommonJS(index_exports);
39
39
 
40
- // ../../Core/text/src/index.js
40
+ // node_modules/@arraypress/text/src/index.js
41
41
  var HTML_ESCAPES = Object.freeze({
42
42
  "&": "&amp;",
43
43
  "<": "&lt;",
@@ -280,6 +280,21 @@ function resample(peaks, count) {
280
280
  }
281
281
  return out;
282
282
  }
283
+ function barRects(peaks, width, height, o) {
284
+ const step = o.barWidth + o.barGap;
285
+ const bars = resample(peaks, Math.max(1, Math.floor((width + o.barGap) / step)));
286
+ const max = bars.reduce((m, b) => b > m ? b : m, 0);
287
+ const scale = max > 0 ? 1 / max : 1;
288
+ return bars.map((b, i) => {
289
+ const v = Math.max(b * scale, 0.04);
290
+ if (o.style === "bars") {
291
+ const h3 = Math.max(1, v * height);
292
+ return { x: i * step, y: height - h3, w: o.barWidth, h: h3 };
293
+ }
294
+ const h2 = Math.max(1, v * (height - 2));
295
+ return { x: i * step, y: height / 2 - h2 / 2, w: o.barWidth, h: h2 };
296
+ });
297
+ }
283
298
  function drawRowWaveform(canvas, peaks, progress, o) {
284
299
  const size = fitCanvas(canvas);
285
300
  const ctx = size && canvas.getContext && canvas.getContext("2d");
@@ -292,25 +307,19 @@ function drawRowWaveform(canvas, peaks, progress, o) {
292
307
  ctx.fillRect(0, Math.floor(height / 2), width, 1);
293
308
  return;
294
309
  }
295
- const step = o.barWidth + o.barGap;
296
- const count = Math.max(1, Math.floor((width + o.barGap) / step));
297
- const bars = resample(peaks, count);
298
- let max = 0;
299
- for (const b of bars) if (b > max) max = b;
300
- const scale = max > 0 ? 1 / max : 1;
301
- const split = progress * width;
302
- const mid = height / 2;
303
- for (let i = 0; i < bars.length; i++) {
304
- const x = i * step;
305
- const v = Math.max(bars[i] * scale, 0.04);
306
- ctx.fillStyle = x + o.barWidth / 2 <= split ? o.progressColor : o.color;
307
- if (o.style === "bars") {
308
- const h2 = Math.max(1, v * height);
309
- ctx.fillRect(x, height - h2, o.barWidth, h2);
310
- } else {
311
- const h2 = Math.max(1, v * (height - 2));
312
- ctx.fillRect(x, mid - h2 / 2, o.barWidth, h2);
313
- }
310
+ const path = new Path2D();
311
+ for (const r of barRects(peaks, width, height, o)) path.rect(r.x, r.y, r.w, r.h);
312
+ ctx.fillStyle = o.color;
313
+ ctx.fill(path);
314
+ const split = Math.min(Math.max(progress, 0), 1) * width;
315
+ if (split > 0) {
316
+ ctx.save();
317
+ ctx.beginPath();
318
+ ctx.rect(0, 0, split, height);
319
+ ctx.clip();
320
+ ctx.fillStyle = o.progressColor;
321
+ ctx.fill(path);
322
+ ctx.restore();
314
323
  }
315
324
  }
316
325
 
@@ -1,4 +1,4 @@
1
- // ../../Core/text/src/index.js
1
+ // node_modules/@arraypress/text/src/index.js
2
2
  var HTML_ESCAPES = Object.freeze({
3
3
  "&": "&amp;",
4
4
  "<": "&lt;",
@@ -241,6 +241,21 @@ function resample(peaks, count) {
241
241
  }
242
242
  return out;
243
243
  }
244
+ function barRects(peaks, width, height, o) {
245
+ const step = o.barWidth + o.barGap;
246
+ const bars = resample(peaks, Math.max(1, Math.floor((width + o.barGap) / step)));
247
+ const max = bars.reduce((m, b) => b > m ? b : m, 0);
248
+ const scale = max > 0 ? 1 / max : 1;
249
+ return bars.map((b, i) => {
250
+ const v = Math.max(b * scale, 0.04);
251
+ if (o.style === "bars") {
252
+ const h3 = Math.max(1, v * height);
253
+ return { x: i * step, y: height - h3, w: o.barWidth, h: h3 };
254
+ }
255
+ const h2 = Math.max(1, v * (height - 2));
256
+ return { x: i * step, y: height / 2 - h2 / 2, w: o.barWidth, h: h2 };
257
+ });
258
+ }
244
259
  function drawRowWaveform(canvas, peaks, progress, o) {
245
260
  const size = fitCanvas(canvas);
246
261
  const ctx = size && canvas.getContext && canvas.getContext("2d");
@@ -253,25 +268,19 @@ function drawRowWaveform(canvas, peaks, progress, o) {
253
268
  ctx.fillRect(0, Math.floor(height / 2), width, 1);
254
269
  return;
255
270
  }
256
- const step = o.barWidth + o.barGap;
257
- const count = Math.max(1, Math.floor((width + o.barGap) / step));
258
- const bars = resample(peaks, count);
259
- let max = 0;
260
- for (const b of bars) if (b > max) max = b;
261
- const scale = max > 0 ? 1 / max : 1;
262
- const split = progress * width;
263
- const mid = height / 2;
264
- for (let i = 0; i < bars.length; i++) {
265
- const x = i * step;
266
- const v = Math.max(bars[i] * scale, 0.04);
267
- ctx.fillStyle = x + o.barWidth / 2 <= split ? o.progressColor : o.color;
268
- if (o.style === "bars") {
269
- const h2 = Math.max(1, v * height);
270
- ctx.fillRect(x, height - h2, o.barWidth, h2);
271
- } else {
272
- const h2 = Math.max(1, v * (height - 2));
273
- ctx.fillRect(x, mid - h2 / 2, o.barWidth, h2);
274
- }
271
+ const path = new Path2D();
272
+ for (const r of barRects(peaks, width, height, o)) path.rect(r.x, r.y, r.w, r.h);
273
+ ctx.fillStyle = o.color;
274
+ ctx.fill(path);
275
+ const split = Math.min(Math.max(progress, 0), 1) * width;
276
+ if (split > 0) {
277
+ ctx.save();
278
+ ctx.beginPath();
279
+ ctx.rect(0, 0, split, height);
280
+ ctx.clip();
281
+ ctx.fillStyle = o.progressColor;
282
+ ctx.fill(path);
283
+ ctx.restore();
275
284
  }
276
285
  }
277
286
 
@@ -1,5 +1,5 @@
1
1
  (() => {
2
- // ../../Core/text/src/index.js
2
+ // node_modules/@arraypress/text/src/index.js
3
3
  var HTML_ESCAPES = Object.freeze({
4
4
  "&": "&amp;",
5
5
  "<": "&lt;",
@@ -242,6 +242,21 @@
242
242
  }
243
243
  return out;
244
244
  }
245
+ function barRects(peaks, width, height, o) {
246
+ const step = o.barWidth + o.barGap;
247
+ const bars = resample(peaks, Math.max(1, Math.floor((width + o.barGap) / step)));
248
+ const max = bars.reduce((m, b) => b > m ? b : m, 0);
249
+ const scale = max > 0 ? 1 / max : 1;
250
+ return bars.map((b, i) => {
251
+ const v = Math.max(b * scale, 0.04);
252
+ if (o.style === "bars") {
253
+ const h3 = Math.max(1, v * height);
254
+ return { x: i * step, y: height - h3, w: o.barWidth, h: h3 };
255
+ }
256
+ const h2 = Math.max(1, v * (height - 2));
257
+ return { x: i * step, y: height / 2 - h2 / 2, w: o.barWidth, h: h2 };
258
+ });
259
+ }
245
260
  function drawRowWaveform(canvas, peaks, progress, o) {
246
261
  const size = fitCanvas(canvas);
247
262
  const ctx = size && canvas.getContext && canvas.getContext("2d");
@@ -254,25 +269,19 @@
254
269
  ctx.fillRect(0, Math.floor(height / 2), width, 1);
255
270
  return;
256
271
  }
257
- const step = o.barWidth + o.barGap;
258
- const count = Math.max(1, Math.floor((width + o.barGap) / step));
259
- const bars = resample(peaks, count);
260
- let max = 0;
261
- for (const b of bars) if (b > max) max = b;
262
- const scale = max > 0 ? 1 / max : 1;
263
- const split = progress * width;
264
- const mid = height / 2;
265
- for (let i = 0; i < bars.length; i++) {
266
- const x = i * step;
267
- const v = Math.max(bars[i] * scale, 0.04);
268
- ctx.fillStyle = x + o.barWidth / 2 <= split ? o.progressColor : o.color;
269
- if (o.style === "bars") {
270
- const h2 = Math.max(1, v * height);
271
- ctx.fillRect(x, height - h2, o.barWidth, h2);
272
- } else {
273
- const h2 = Math.max(1, v * (height - 2));
274
- ctx.fillRect(x, mid - h2 / 2, o.barWidth, h2);
275
- }
272
+ const path = new Path2D();
273
+ for (const r of barRects(peaks, width, height, o)) path.rect(r.x, r.y, r.w, r.h);
274
+ ctx.fillStyle = o.color;
275
+ ctx.fill(path);
276
+ const split = Math.min(Math.max(progress, 0), 1) * width;
277
+ if (split > 0) {
278
+ ctx.save();
279
+ ctx.beginPath();
280
+ ctx.rect(0, 0, split, height);
281
+ ctx.clip();
282
+ ctx.fillStyle = o.progressColor;
283
+ ctx.fill(path);
284
+ ctx.restore();
276
285
  }
277
286
  }
278
287
 
@@ -1,4 +1,4 @@
1
- (()=>{var Bt=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function P(n){return n==null?"":String(n).replace(/[&<>"']/g,t=>Bt[t])}var Ut=/[^\p{L}\p{N}]+/u,Kt=/\p{Mn}+/gu;function S(n){return!n||typeof n!="string"?"":n.toLowerCase().normalize("NFD").replace(Kt,"")}function O(n){return S(n).split(Ut).filter(t=>t!=="")}function lt(n,t){let e=Array.from(n??""),s=Array.from(t??""),r=[],i=Array.from({length:s.length+1},(o,a)=>a);for(let o=1;o<=e.length;o++){let a=[o];for(let l=1;l<=s.length;l++){let d=e[o-1]===s[l-1]?0:1;a[l]=Math.min(i[l]+1,a[l-1]+1,i[l-1]+d),o>1&&l>1&&e[o-1]===s[l-2]&&e[o-2]===s[l-1]&&(a[l]=Math.min(a[l],r[l-2]+1))}r=i,i=a}return i[s.length]}function ut(n,t,e={}){let s=e.fuzzyFrom??4,r=S(n),i=O(n);return O(t).every(o=>{if(r.includes(o))return!0;let a=Array.from(o).length;return a<s?!1:i.some(l=>lt(o,l)<=1||lt(o,Array.from(l).slice(0,a).join(""))<=1)})}function F(n){if(!Array.isArray(n))return"";let t="";for(let e of n){let s=Math.round(Math.min(Math.max(Number(e)||0,0),1)*255);t+=(s<16?"0":"")+s.toString(16)}return t}function V(n,t=1){if(n==null||n==="")return null;if(typeof n=="string"){if(!/^[0-9a-f]+$/i.test(n)||n.length%2)return null;let r=new Array(n.length/2);for(let i=0;i<r.length;i++)r[i]=parseInt(n.substr(i*2,2),16)/255;return r}if(!Array.isArray(n))return null;let e=Number(t)>0?Number(t):1,s=n.map(r=>Math.min(Math.max((Number(r)||0)/e,0),1));return s.length?s:null}function k(n){if(n==null)return"";let t=String(n).trim(),e=t.match(/^([A-Ga-g])[\s_-]*([#♯b♭]?)[\s_-]*(m|min|minor|maj|major)?$/i);if(!e)return t;let s=e[1].toUpperCase(),r=e[2]==="\u266F"?"#":e[2]==="\u266D"?"b":e[2],i=e[3]&&/^m(in(or)?)?$/i.test(e[3])&&e[3]!=="M";return s+r+(i?"m":"")}var Ht={C:0,"C#":1,Db:1,D:2,"D#":3,Eb:3,E:4,F:5,"F#":6,Gb:6,G:7,"G#":8,Ab:8,A:9,"A#":10,Bb:10,B:11};function D(n){if(!n)return 1/0;let t=n.endsWith("m"),e=t?n.slice(0,-1):n,s=Ht[e];return s===void 0?1e3:s*2+(t?1:0)}function z(n){if(n==null||n==="")return"";let t=Number(n);if(!Number.isFinite(t)||t<0)return"";let e=Math.round(t);return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`}function jt(n){if(n==null||n==="")return null;if(typeof n=="number")return Number.isFinite(n)&&n>=0?n:null;let t=String(n).trim();if(/^\d+(\.\d+)?$/.test(t))return Number(t);let e=t.split(":").map(Number);return e.length<2||e.some(s=>!Number.isFinite(s))?null:e.reduce((s,r)=>s*60+r,0)}function Gt(n){let e=(String(n||"").split(/[?#]/)[0].split("/").pop()||"").replace(/\.[a-z0-9]+$/i,"");try{e=decodeURIComponent(e)}catch{}return e.replace(/[_]+/g," ").replace(/\s+/g," ").trim()}function Y(n,t,e=1){if(!n||typeof n!="object"||!n.url)return null;let s=Number(n.bpm),r=Array.isArray(n.tags)?n.tags.map(i=>String(i).trim()).filter(Boolean):typeof n.tags=="string"?n.tags.split(",").map(i=>i.trim()).filter(Boolean):[];return{id:n.id!=null&&n.id!==""?String(n.id):`sound-${t+1}`,url:String(n.url),title:n.title?String(n.title):Gt(n.url),type:n.type?String(n.type):"",bpm:Number.isFinite(s)&&s>0?Math.round(s*100)/100:null,key:k(n.key),duration:jt(n.duration),tags:r,peaks:V(n.peaks,e),waveform:n.waveform?String(n.waveform):null,download:n.download?String(n.download):null}}function q(n){let t=Array.isArray(n)?n:Array.isArray(n?.sounds)?n.sounds:[],e=Array.isArray(n)?1:Number(n?.peakScale)||1;return _(t,e)}function _(n,t=1){let e=new Set,s=[];return(Array.isArray(n)?n:[]).forEach((r,i)=>{let o=Y(r,i,t);if(!o)return;let a=o.id,l=2;for(;e.has(a);)a=`${o.id}-${l++}`;o.id=a,e.add(a),s.push(o)}),s}function v(n){let t=new Map,e=new Set,s=1/0,r=-1/0,i=!1;for(let o of n)o.type&&t.set(o.type,(t.get(o.type)||0)+1),o.key&&e.add(o.key),o.bpm!=null&&(s=Math.min(s,o.bpm),r=Math.max(r,o.bpm)),o.duration!=null&&(i=!0);return{types:[...t].map(([o,a])=>({name:o,count:a})),keys:[...e].sort((o,a)=>D(o)-D(a)||o.localeCompare(a)),bpm:s===1/0?null:{min:s,max:r},hasDuration:i}}function B(n,t={}){if(t.type&&n.type!==t.type||t.key&&n.key!==k(t.key))return!1;let e=Number(t.bpmMin),s=Number(t.bpmMax);if((t.bpmMin!=null&&t.bpmMin!==""&&Number.isFinite(e)||t.bpmMax!=null&&t.bpmMax!==""&&Number.isFinite(s))&&(n.bpm==null||t.bpmMin!=null&&t.bpmMin!==""&&n.bpm<e||t.bpmMax!=null&&t.bpmMax!==""&&n.bpm>s))return!1;let r=O(t.query||"");if(r.length){let i=[n.title,n.type,n.key,...n.tags||[]].join(" "),o=S(i),a=r.filter(l=>!(/^\d+$/.test(l)&&!o.includes(l)&&n.bpm!=null&&Math.round(n.bpm)===Number(l)));if(a.length&&!ut(i,a.join(" ")))return!1}return!0}var C=["default","title","bpm","key","duration"],Wt={default:()=>!0,title:()=>!0,bpm:n=>n.bpm!==null,key:n=>n.keys.length>0,duration:n=>n.hasDuration};function U(n,t){return n.filter(e=>Wt[e]?.(t))}function L(n,t="default"){let e=n.map((i,o)=>({s:i,i:o})),s=i=>i??1/0,r={title:(i,o)=>i.s.title.localeCompare(o.s.title,void 0,{numeric:!0,sensitivity:"base"}),bpm:(i,o)=>s(i.s.bpm)-s(o.s.bpm),key:(i,o)=>D(i.s.key)-D(o.s.key),duration:(i,o)=>s(i.s.duration)-s(o.s.duration)}[t];return r&&e.sort((i,o)=>r(i,o)||i.i-o.i),e.map(i=>i.s)}function Vt(n){let t=n.getBoundingClientRect();if(!t.width||!t.height)return null;let e=Math.min(window.devicePixelRatio||1,3),s=Math.round(t.width*e),r=Math.round(t.height*e);return n.width!==s&&(n.width=s),n.height!==r&&(n.height=r),{width:t.width,height:t.height,dpr:e}}function J(n,t){if(!n?.length||t<=0)return[];if(n.length===t)return n;let e=new Array(t),s=n.length/t;for(let r=0;r<t;r++){let i=Math.floor(r*s),o=Math.max(i+1,Math.floor((r+1)*s)),a=0;for(let l=i;l<o&&l<n.length;l++)n[l]>a&&(a=n[l]);e[r]=a}return e}function ct(n,t,e,s){let r=Vt(n),i=r&&n.getContext&&n.getContext("2d");if(!i)return;let{width:o,height:a,dpr:l}=r;if(i.setTransform(l,0,0,l,0,0),i.clearRect(0,0,o,a),!t?.length){i.fillStyle=s.color,i.fillRect(0,Math.floor(a/2),o,1);return}let d=s.barWidth+s.barGap,c=Math.max(1,Math.floor((o+s.barGap)/d)),b=J(t,c),N=0;for(let x of b)x>N&&(N=x);let Ft=N>0?1/N:1,zt=e*o,qt=a/2;for(let x=0;x<b.length;x++){let W=x*d,at=Math.max(b[x]*Ft,.04);if(i.fillStyle=W+s.barWidth/2<=zt?s.progressColor:s.color,s.style==="bars"){let E=Math.max(1,at*a);i.fillRect(W,a-E,s.barWidth,E)}else{let E=Math.max(1,at*(a-2));i.fillRect(W,qt-E/2,s.barWidth,E)}}}var Yt=["onLoad","onPlay","onPause","onEnd","onTimeUpdate","onError"];function pt(n,t,e){let s=n||{},r=t==="strip",i={height:r?48:32,waveformStyle:r?"mirror":"bars",preload:"metadata",singlePlay:!0,...s,audioMode:"self"};for(let o of Yt)i[o]=(...a)=>{e[o]?.(...a),typeof s[o]=="function"&&s[o](...a)};return i}function dt(n,t){return t==="strip"&&n.waveform||n.peaks||null}function Jt(n,t){let e=S(String(t??"")).trim();return!e||S(String(n??"")).includes(e)}function ht(n,t,e){return Math.max(0,Math.min(e-1,n+t))}function M(n){return{button:n.querySelector("[data-ws-menu-btn]"),pop:n.querySelector("[data-ws-menu-pop]"),search:n.querySelector("[data-ws-menu-search]"),list:n.querySelector("[data-ws-menu-list]"),none:n.querySelector("[data-ws-menu-none]"),value:n.querySelector("[data-ws-menu-value]")}}var Q=n=>n.search||n.list,X=(n,t=!1)=>[...n.list.querySelectorAll('[role="option"]')].filter(e=>!t||!e.hidden),K=class{constructor(t,{onPick:e,signal:s}){this.container=t,this.onPick=e,this.menus=Object.fromEntries([...t.querySelectorAll("[data-ws-menu]")].map(r=>[r.dataset.wsMenu,r])),this.openMenu=null,this._bind(s)}_bind(t){let e={signal:t};for(let[s,r]of Object.entries(this.menus)){let i=M(r);i.button.addEventListener("click",()=>this.openMenu===r?this.close(!0):this.open(r),e),i.button.addEventListener("keydown",o=>{(o.key==="ArrowDown"||o.key==="ArrowUp")&&(o.preventDefault(),this.open(r))},e),i.list.addEventListener("click",o=>{let a=o.target.closest('[role="option"]');a&&this._pick(s,a.dataset.value)},e),i.list.addEventListener("mousedown",o=>o.preventDefault(),e),i.search?.addEventListener("input",()=>this._filter(r,i.search.value),e),Q(i).addEventListener("keydown",o=>this._onKey(o,s,r),e)}document.addEventListener("pointerdown",s=>{this.openMenu&&!this.openMenu.contains(s.target)&&this.close(!1)},e),this.container.addEventListener("focusout",s=>{this.openMenu&&!this.openMenu.contains(s.relatedTarget)&&this.close(!1)},e)}open(t){this.openMenu&&this.openMenu!==t&&this.close(!1);let e=M(t);e.button.setAttribute("aria-expanded","true"),e.pop.hidden=!1,this.openMenu=t,e.search&&(e.search.value="",this._filter(t,"")),t.classList.remove("ws-menu--end"),e.pop.getBoundingClientRect().right>this.container.getBoundingClientRect().right+1&&t.classList.add("ws-menu--end"),this._activate(t,e.list.querySelector('[role="option"][aria-selected="true"]')),Q(e).focus()}close(t){let e=this.openMenu;if(!e)return;this.openMenu=null;let s=M(e);s.pop.hidden=!0,s.button.setAttribute("aria-expanded","false"),t&&s.button.focus()}setValue(t,e){let s=this.menus[t];if(!s)return;let r=M(s),i=null;for(let o of X(r)){let a=o.dataset.value===String(e??"");o.setAttribute("aria-selected",String(a)),a&&(i=o.querySelector(".ws-menu-text")?.textContent??"")}i!==null&&(r.value.textContent=i)}_filter(t,e){let s=M(t),r=null;for(let i of X(s))i.hidden=!Jt(i.textContent,e),i.hidden||(r??=i);s.none.hidden=r!==null,this._activate(t,r)}_activate(t,e){let s=M(t);for(let i of s.list.querySelectorAll(".is-active"))i.classList.remove("is-active");let r=Q(s);if(!e||e.hidden){r.removeAttribute("aria-activedescendant");return}e.classList.add("is-active"),r.setAttribute("aria-activedescendant",e.id),e.scrollIntoView?.({block:"nearest"})}_onKey(t,e,s){let r=M(s),i=X(r,!0),o=i.indexOf(r.list.querySelector(".is-active")),a=d=>{t.preventDefault(),this._activate(s,i[d])},l=t.target.matches("input");switch(t.key){case"ArrowDown":return a(ht(o,1,i.length));case"ArrowUp":return a(ht(o,-1,i.length));case"Home":return l?void 0:a(0);case"End":return l?void 0:a(i.length-1);case"Enter":t.preventDefault(),o>=0&&this._pick(e,i[o].dataset.value);return;case"Escape":return t.preventDefault(),t.stopPropagation(),this.close(!0);case"Tab":return this.close(!1);default:return}}_pick(t,e){this.close(!0),this.onPick(t,e)}};var m="[WaveformSounds]";function Z(n,t=0,e=1){return Math.min(Math.max(n,t),e)}function ft(n,t){return t&&t.width?Z((n-t.left)/t.width):0}function mt(n){return!!n&&(n.isContentEditable||/^(INPUT|SELECT|TEXTAREA)$/.test(n.tagName))}function yt(n,t,e){let s=new CustomEvent(`waveformsounds:${t}`,{bubbles:!0,detail:e});return n.dispatchEvent(s),s}function wt(n){let t=5381;for(let e of n)t=t*33+e.codePointAt(0)>>>0;return t}var gt=.1;function bt(n,t,e){if(!e)return null;switch(n){case"ArrowDown":return t+1<e?t+1:null;case"ArrowUp":return t>0?t-1:"search";case"Home":return 0;case"End":return e-1;default:return null}}function xt(n,t){return t!=="ArrowRight"&&t!=="ArrowLeft"?null:Z(n+(t==="ArrowRight"?gt:-gt),0,.999)}function St(n,t){let e=new Set(n.slice(0,t));return{visible:e,remaining:n.length-e.size}}function _t(n,t){return t>=n?t+1:n}var y={search:"Search sounds",searchPlaceholder:"Search sounds\u2026",all:"All",types:"Type",key:"Key",anyKey:"Any key",allTypes:"All types",findType:"Find a type\u2026",findKey:"Find a key\u2026",noMatches:"No matches",bpm:"BPM",bpmMin:"Min BPM",bpmMax:"Max BPM",sort:"Sort",sortBy:"Sort by",sortDefault:"Default",sortTitle:"Name",sortBpm:"BPM",sortKey:"Key",sortDuration:"Length",loop:"Loop",play:"Play {title}",pause:"Pause {title}",seek:"Seek {title}",download:"Download {title}",count:"{count} sounds",countOne:"1 sound",countFiltered:"{count} of {total} sounds",showMore:"Show {count} more",empty:"No sounds match.",clear:"Clear filters",nowPlaying:"Playing {title}"},vt={default:"sortDefault",title:"sortTitle",bpm:"sortBpm",key:"sortKey",duration:"sortDuration"};function h(n,t={}){return String(n).replace(/\{(\w+)\}/g,(e,s)=>s in t?String(t[s]):e)}function H(n,t,e=y){return n!==t?h(e.countFiltered,{count:n,total:t}):t===1?e.countOne:h(e.count,{count:t})}var At=["type","key","bpm"],Tt=["type","bpm","key","duration"],f={player:"inline",search:!0,filters:[...At],sorts:[...C],loopToggle:!0,showCount:!0,menuSearch:8,pageSize:50,columns:[...Tt],maxTypeChips:10};function Mt(n){let t={};for(let e in n??{})n[e]!==void 0&&(t[e]=n[e]);return t}function tt(n,t,e){return Array.isArray(n)?n.filter(s=>t.includes(s)):e}function et(n,t){let e=Number(n);return Number.isFinite(e)&&e>=0?Math.floor(e):t}function R(n={}){let t={...f,...Mt(n)};return{...t,player:t.player==="strip"?"strip":"inline",filters:tt(t.filters,At,f.filters),sorts:tt(t.sorts,C,f.sorts),columns:tt(t.columns,Tt,f.columns),menuSearch:et(t.menuSearch,f.menuSearch),maxTypeChips:et(t.maxTypeChips,f.maxTypeChips),pageSize:et(t.pageSize,f.pageSize),strings:{...y,...Mt(n.strings)}}}var j={...f,sounds:null,manifest:null,waveformStyle:"mirror",waveformColor:null,progressColor:null,barWidth:2,barGap:1,loop:!1,autoAdvance:!1,arrowAudition:!0,idPrefix:null,urlState:!1,playerOptions:null,playerClass:null,strings:null,onReady:null,onPlay:null,onPause:null,onEnd:null,onFilter:null,onError:null};function A(n){if(n===""||n==="true")return!0;if(n==="false")return!1}function nt(n){if(n!=null)return n.split(",").map(t=>t.trim()).filter(Boolean)}function I(n){return n===void 0||n===""?void 0:Number(n)}function Qt(n){if(n===void 0)return;let t=A(n);return t===void 0?n:t}function kt(n,t){if(n)try{return JSON.parse(n)}catch{console.warn(`${m} Ignoring invalid JSON in data-${t}`);return}}function Et(n){let t=n.dataset||{},e={player:t.player||void 0,manifest:t.manifest||void 0,search:A(t.search),filters:nt(t.filters),sorts:nt(t.sorts),showCount:A(t.showCount),menuSearch:I(t.menuSearch),idPrefix:t.idPrefix||void 0,urlState:Qt(t.urlState),loopToggle:A(t.loopToggle),pageSize:I(t.pageSize),maxTypeChips:I(t.maxTypeChips),columns:nt(t.columns),waveformStyle:t.waveformStyle||void 0,waveformColor:t.waveformColor||void 0,progressColor:t.progressColor||void 0,barWidth:I(t.barWidth),barGap:I(t.barGap),loop:A(t.loop),autoAdvance:A(t.autoAdvance),arrowAudition:A(t.arrowAudition),strings:kt(t.strings,"strings"),playerOptions:kt(t.playerOptions,"player-options")};for(let s of Object.keys(e))e[s]===void 0&&delete e[s];return e}function Ct(...n){let t={};for(let e of n)if(e)for(let s in e)e[s]!==null&&e[s]!==void 0&&(t[s]=e[s]);return t}var Xt=new Set(["input","br","img"]);function p(n){return P(n??"")}function Zt(n={}){let t="";for(let[e,s]of Object.entries(n))s===!0?t+=` ${e}`:s!==!1&&s!=null&&(t+=` ${e}="${P(s)}"`);return t}function u(n,t={},...e){let s=`<${n}${Zt(t)}>`;return Xt.has(n)?s:s+e.flat(1/0).filter(r=>r!=null&&r!==!1&&r!=="").join("")+`</${n}>`}function T(n,t=""){return`<svg class="${t?`ws-icon ${t}`:"ws-icon"}" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${n}"/></svg>`}var w={play:T("M8 5.5v13l11-6.5z","ws-icon-play"),pause:T("M7 5h3.5v14H7zM13.5 5H17v14h-3.5z","ws-icon-pause"),search:T("M10.5 4a6.5 6.5 0 1 0 4.03 11.6l4.43 4.43 1.41-1.41-4.43-4.43A6.5 6.5 0 0 0 10.5 4zm0 2a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9z"),chevron:T("M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z","ws-menu-chevron"),check:T("M9.5 16.2 5.3 12l-1.4 1.4 5.6 5.6 11-11-1.4-1.4z","ws-menu-check"),download:T("M11 4h2v8.6l3.3-3.3 1.4 1.4L12 16.4l-5.7-5.7 1.4-1.4 3.3 3.3zM5 18h14v2H5z"),loop:T("M17 4l3 3-3 3V8H8a3 3 0 0 0-3 3v1H3v-1a5 5 0 0 1 5-5h9V4zM7 20l-3-3 3-3v2h9a3 3 0 0 0 3-3v-1h2v1a5 5 0 0 1-5 5H7v2z")};function te(n){let t=[n.length,...n.map(e=>e.url)].join("|");return`ws${wt(t).toString(36)}`}function ee(n,t){let e=t.filters.includes("type")&&n.types.length>1,s=U(t.sorts,n);return{types:e?n.types.length>t.maxTypeChips?"menu":"chips":null,key:t.filters.includes("key")&&n.keys.length>1,bpm:t.filters.includes("bpm")&&n.bpm!==null&&n.bpm.max>n.bpm.min,sorts:s.length>1?s:[],search:!!t.search,loop:!!t.loopToggle,count:!!t.showCount}}function ne(n){return u("label",{class:"ws-search"},w.search,u("span",{class:"ws-sr"},p(n.search)),u("input",{type:"search",class:"ws-search-input","data-ws-search":!0,placeholder:n.searchPlaceholder,autocomplete:"off",spellcheck:"false"}))}function se(n,t){let e=`${t.id}-${n}-list`,s=t.options.find(l=>l.value===t.value)??t.options[0],r=t.placeholder&&t.options.length>t.searchFrom,i=u("button",{type:"button",class:"ws-menu-btn","data-ws-menu-btn":!0,"aria-haspopup":"listbox","aria-expanded":"false","aria-controls":e},t.prefix?u("span",{class:"ws-menu-prefix"},p(t.prefix)):u("span",{class:"ws-sr"},p(`${t.label}: `)),u("span",{class:"ws-menu-value","data-ws-menu-value":!0},p(s.label)),w.chevron),o=r&&u("input",{type:"search",class:"ws-menu-search","data-ws-menu-search":!0,role:"combobox","aria-expanded":"true","aria-controls":e,"aria-autocomplete":"list","aria-label":t.placeholder,placeholder:t.placeholder,autocomplete:"off",spellcheck:"false"}),a=t.options.map((l,d)=>u("li",{role:"option",id:`${t.id}-${n}-${d}`,class:"ws-menu-option","data-value":l.value,"aria-selected":String(l===s)},w.check,u("span",{class:"ws-menu-text"},p(l.label)),l.count!=null&&u("span",{class:"ws-menu-count"},p(l.count))));return u("div",{class:"ws-menu","data-ws-menu":n},i,u("div",{class:"ws-menu-pop","data-ws-menu-pop":!0,hidden:!0},o,u("ul",{class:"ws-menu-list",role:"listbox",id:e,"aria-label":t.label,tabindex:"-1","data-ws-menu-list":!0},a),u("p",{class:"ws-menu-none","data-ws-menu-none":!0,hidden:!0},p(t.noMatches))))}function re(n,t){let e=(s,r,i)=>u("input",{type:"number",inputmode:"numeric",[s]:!0,"aria-label":r,placeholder:i,min:"0",step:"1"});return u("span",{class:"ws-bpm-range",role:"group","aria-label":n.bpm},e("data-ws-bpm-min",n.bpmMin,t.min),u("span",{"aria-hidden":"true"},"\u2013"),e("data-ws-bpm-max",n.bpmMax,t.max),u("span",{class:"ws-bpm-unit","aria-hidden":"true"},p(n.bpm)))}function ie(n){return u("button",{type:"button",class:"ws-loop","data-ws-loop":!0,"aria-pressed":"false"},w.loop,u("span",{},p(n.loop)))}function Lt(n,t,e,s){return u("button",{type:"button",class:"ws-chip","data-ws-type":n,"aria-pressed":String(s)},u("span",{class:"ws-chip-label"},p(t))," ",u("span",{class:"ws-chip-count"},p(e)))}function oe(n,{o:t,s:e,f:s,total:r,id:i}){let o=(c,b)=>se(c,{id:i,searchFrom:t.menuSearch,noMatches:e.noMatches,...b}),a=[n.types==="menu"&&o("type",{label:e.types,value:"",placeholder:e.findType,options:[{value:"",label:e.allTypes,count:r},...s.types.map(c=>({value:c.name,label:c.name,count:c.count}))]}),n.key&&o("key",{label:e.key,value:"",placeholder:e.findKey,options:[{value:"",label:e.anyKey},...s.keys.map(c=>({value:c,label:c}))]}),n.bpm&&re(e,s.bpm),n.sorts.length>0&&o("sort",{label:e.sort,prefix:e.sortBy,value:n.sorts[0],options:n.sorts.map(c=>({value:c,label:e[vt[c]]}))}),n.loop&&ie(e)].filter(Boolean),l=n.types==="chips"&&u("div",{class:"ws-types",role:"group","aria-label":e.types},Lt("",e.all,r,!0),s.types.map(c=>Lt(c.name,c.name,c.count,!1))),d=n.count&&u("p",{class:"ws-count","data-ws-count":!0,"aria-live":"polite"},p(H(r,r,e)));return u("div",{class:"ws-toolbar"},n.search&&ne(e),a.length>0&&u("div",{class:"ws-controls"},a),(l||d)&&u("div",{class:"ws-meta"},l,d))}var ae={type:n=>p(n.type),bpm:n=>p(n.bpm??""),key:n=>p(n.key),duration:n=>p(z(n.duration))};function le(n,t,e,s=!1){let r=e.strings,i={title:n.title},o=e.columns.map(a=>u("span",{class:`ws-cell ws-${a}`},ae[a](n)));return u("li",{class:"ws-row","data-ws-index":t,"data-ws-id":n.id,"data-url":n.url,"data-title":n.title,"data-type":n.type||null,"data-bpm":n.bpm,"data-key":n.key||null,"data-duration":n.duration,"data-tags":n.tags?.length?n.tags.join(","):null,"data-peaks":n.peaks?F(n.peaks):null,"data-waveform":n.waveform,"data-download":n.download,hidden:s},u("button",{type:"button",class:"ws-play","aria-pressed":"false","aria-label":h(r.play,i)},w.play,w.pause),u("span",{class:"ws-cell ws-title"},p(n.title)),o.length>0&&u("span",{class:"ws-cells"},o),e.player==="inline"&&u("span",{class:"ws-wave",role:"slider","aria-label":h(r.seek,i),"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":"0",tabindex:"-1"},u("canvas",{class:"ws-canvas","aria-hidden":"true"})),n.download&&u("a",{class:"ws-download",href:n.download,download:!0,"aria-label":h(r.download,i)},w.download))}function ue({o:n,s:t,total:e}){let s=n.pageSize>0?n.pageSize:e,r=Math.max(0,e-s),i=n.player==="strip";return[u("p",{class:"ws-empty","data-ws-empty":!0,hidden:!0},p(t.empty)," ",u("button",{type:"button",class:"ws-clear","data-ws-clear":!0},p(t.clear))),u("button",{type:"button",class:"ws-more","data-ws-more":!0,hidden:r===0},p(h(t.showMore,{count:Math.min(r,s)}))),u("div",{class:i?"ws-engine ws-engine--strip":"ws-engine","data-ws-engine":!0,hidden:!i}),u("p",{class:"ws-sr","data-ws-status":!0,"aria-live":"polite"})].join("")}function $(n,t={}){let e=R(t),s=_(n),r={o:e,s:e.strings,f:v(s),total:s.length,id:e.idPrefix||te(s)},i=e.pageSize>0?e.pageSize:1/0;return oe(ee(r.f,e),r)+u("ul",{class:`ws-list ws-list--${e.player}`,role:"list","data-ws-list":!0},s.map((o,a)=>le(o,a,e,a>=i)))+ue(r)}function ce(n,t={},e=""){let s=R(t),r=["waveform-sounds",`waveform-sounds--${s.player}`,e].filter(Boolean).join(" ");return u("div",{class:r,"data-waveform-sounds":!0,"data-player":s.player},$(n,t))}var st=":scope > [data-ws-index]";function Rt(n){let t=[...n.querySelectorAll(st)].sort((s,r)=>Number(s.dataset.wsIndex)-Number(r.dataset.wsIndex)),e=[];for(let s of t){let r=s.dataset,i=Y({id:r.wsId,url:r.url,title:r.title,type:r.type,bpm:r.bpm,key:r.key,duration:r.duration,tags:r.tags,peaks:r.peaks,waveform:r.waveform,download:r.download},e.length);if(!i){s.remove();continue}s.dataset.wsIndex=String(e.length),e.push(i)}return e}function It(n){let t=[];return n.querySelectorAll(st).forEach(e=>{t[Number(e.dataset.wsIndex)]=e}),t}function rt(n){return[...n.querySelectorAll(st)].filter(t=>!t.hidden)}function $t(n,t){let e=document.createDocumentFragment();for(let s of t)s&&e.appendChild(s);n.appendChild(e)}function pe(n){let t=String(n??"").trim();if(!t||t==="transparent")return 0;let e=t.match(/\/\s*([\d.]+)(%?)\s*\)$/);if(e)return Number(e[1])/(e[2]?100:1);let s=t.match(/^rgba\(\s*[^,]+,[^,]+,[^,]+,\s*([\d.]+)\s*\)$/);return s?Number(s[1]):1}function Nt(n,t=.95){for(let e=n;e&&e.nodeType===1;e=e.parentElement||e.getRootNode?.().host){let s=getComputedStyle(e).backgroundColor;if(pe(s)>t)return s}return"#fff"}function it(n,t){let e=document.createElement("span");e.style.cssText="position:absolute;width:0;height:0;overflow:hidden;visibility:hidden",e.style.color=t,n.appendChild(e);let s=getComputedStyle(e).color;return e.remove(),s}function ot(n){if(!n)return null;let t=typeof n=="string"?`${n}-`:"";return{q:`${t}q`,type:`${t}type`,key:`${t}key`,bpm:`${t}bpm`,sort:`${t}sort`}}function de(n){let t=String(n??"").match(/^(\d*)-(\d*)$/);return t&&(t[1]||t[2])?{bpmMin:t[1],bpmMax:t[2]}:null}function he(n,t){let e=n??"",s=t??"";return e!==""||s!==""?`${e}-${s}`:""}function Ot(n,t,e,s){let r={filter:{},sort:null};if(!t)return r;let i=new URLSearchParams(n),o=i.get(t.q);o&&(r.filter.query=o);let a=i.get(t.type);a&&e.types.some(b=>b.name===a)&&(r.filter.type=a);let l=k(i.get(t.key));l&&e.keys.includes(l)&&(r.filter.key=l);let d=de(i.get(t.bpm));d&&Object.assign(r.filter,d);let c=i.get(t.sort);return c&&s.includes(c)&&(r.sort=c),r}function Pt(n,t,e,s,r){if(!t)return n;let i=new URL(n),o=(a,l)=>l?i.searchParams.set(a,l):i.searchParams.delete(a);return o(t.q,String(e.query??"").trim()),o(t.type,e.type),o(t.key,e.key),o(t.bpm,he(e.bpmMin,e.bpmMax)),o(t.sort,s!==r?s:""),i.href}var Dt=Object.freeze({query:"",type:"",key:"",bpmMin:"",bpmMax:""}),fe=120,me=200,ye=250,g=class n{static instances=new Map;constructor(t,e={}){let s=typeof t=="string"?document.querySelector(t):t;if(!s)throw new Error(`${m} Container not found: ${t}`);this.container=s,this.options=Ct(j,e,Et(s)),this.options.waveformStyle=this.options.waveformStyle==="bars"?"bars":"mirror",this.strings={...y,...this.options.strings||{}},this.render={...R(this.options),strings:this.strings},this.sounds=[],this.rows=[],this.filter={...Dt},this.sortBy="default",this.limit=this._pageSize(),this.currentIndex=null,this.playing=!1,this.progress=0,this.loop=!!this.options.loop,this.engine=null,this.menus=null,this.destroyed=!1,this._ctl=new AbortController,this._originalHTML=null,this._pendingSeek=null,this._raf=0,n.instances.set(s,this),s.dataset.wsInitialized="true",this.ready=Promise.resolve().then(()=>this._init()).catch(r=>{console.error(`${m} Failed to initialise:`,r),this._emit("error",{error:r}),this.options.onError?.(r,this)})}async _init(){let t=this.container,e=t.querySelector("[data-ws-list]");if(e)this.sounds=Rt(e);else{if(this._originalHTML=t.innerHTML,this.sounds=await this._loadSounds(),this.destroyed)return;t.innerHTML=$(this.sounds,{...this.render,idPrefix:this.options.idPrefix||t.id||void 0})}this.destroyed||(this._addedClasses=["waveform-sounds",`waveform-sounds--${this.render.player}`].filter(s=>!t.classList.contains(s)),t.classList.add(...this._addedClasses),this._cacheRefs(),this._bind(),this._observe(),this._resolveColors(),this._setLoop(this.loop),this._sorts=U(this.render.sorts,v(this.sounds)),this._sortSet||(this.sortBy=this._sorts[0]||"default"),this._readUrl(),this._syncControls(),this._apply({resort:this.sortBy!=="default"}),this._playerClass()&&this._ensureEngine(),this._emit("ready",{sounds:this.sounds.length}),this.options.onReady?.(this))}async _loadSounds(){if(this.options.sounds||!this.options.manifest)return _(this.options.sounds||[]);let t=await fetch(this.options.manifest);if(!t.ok)throw new Error(`${m} Manifest ${this.options.manifest}: HTTP ${t.status}`);return q(await t.json())}_cacheRefs(){let t=e=>this.container.querySelector(e);this.$={list:t("[data-ws-list]"),search:t("[data-ws-search]"),bpmMin:t("[data-ws-bpm-min]"),bpmMax:t("[data-ws-bpm-max]"),loop:t("[data-ws-loop]"),count:t("[data-ws-count]"),empty:t("[data-ws-empty]"),more:t("[data-ws-more]"),engine:t("[data-ws-engine]"),status:t("[data-ws-status]"),chips:[...this.container.querySelectorAll("[data-ws-type]")]},this.rows=It(this.$.list)}_bind(){let t={signal:this._ctl.signal},e=this.$,s=this.container;s.addEventListener("click",a=>this._onClick(a),t),s.addEventListener("pointerdown",a=>this._onPointerDown(a),t),s.addEventListener("keydown",a=>this._onKey(a),t);let r=0,i=0;e.search?.addEventListener("input",()=>{clearTimeout(r),r=setTimeout(()=>this.setFilter({query:e.search.value}),fe)},t),e.search?.addEventListener("keydown",a=>{a.key==="ArrowDown"&&(a.preventDefault(),this._focusRow(rt(e.list)[0])),a.key==="Escape"&&e.search.value&&(a.preventDefault(),e.search.value="",this.setFilter({query:""}))},t);let o=()=>{clearTimeout(i),i=setTimeout(()=>this.setFilter({bpmMin:e.bpmMin?.value??"",bpmMax:e.bpmMax?.value??""}),me)};e.bpmMin?.addEventListener("input",o,t),e.bpmMax?.addEventListener("input",o,t),this.menus=new K(s,{signal:this._ctl.signal,onPick:(a,l)=>a==="sort"?this.setSort(l):this.setFilter({[a]:l})}),document.addEventListener("waveformplayer:play",a=>{let l=a.detail?.player;l&&l!==this.engine&&this.playing&&this.pause()},t)}_onClick(t){let e=t.target,s=e.closest("[data-ws-type]");if(s){this.setFilter({type:s.dataset.wsType});return}if(e.closest("[data-ws-more]")){this.showMore();return}if(e.closest("[data-ws-clear]")){this.clearFilters();return}if(e.closest("[data-ws-loop]")){this.setLoop(!this.loop);return}let r=e.closest(".ws-wave");if(r){this._lastPointer==="touch"&&this._seekAt(r,t.clientX);return}let i=e.closest("[data-ws-index]");!i||e.closest(".ws-download")||(this.toggle(Number(i.dataset.wsIndex)),this._focusRowQuietly(i))}_onPointerDown(t){this._lastPointer=t.pointerType;let e=t.target.closest(".ws-wave");!e||t.button!==0||t.pointerType==="touch"||(t.preventDefault(),this._seekAt(e,t.clientX))}_seekAt(t,e){let s=t.closest("[data-ws-index]");this._seekRow(Number(s.dataset.wsIndex),ft(e,t.getBoundingClientRect())),this._focusRowQuietly(s)}_onKey(t){if(t.defaultPrevented||t.altKey||t.ctrlKey||t.metaKey)return;if(t.key==="/"&&!mt(t.target)&&this.$.search){t.preventDefault(),this.$.search.focus();return}let e=t.target.closest?.("[data-ws-index]");if(!e)return;let s=Number(e.dataset.wsIndex),r=xt(this.progress,t.key);if(r!==null){if(s!==this.currentIndex||!this.engine)return;t.preventDefault(),this._seekRow(s,r);return}let i=rt(this.$.list),o=bt(t.key,i.indexOf(e),i.length);if(o!==null){if(t.preventDefault(),o==="search"){this.$.search?.focus();return}this._focusRow(i[o]),this.options.arrowAudition&&this.playing&&this.play(Number(i[o].dataset.wsIndex))}}_focusRow(t){t?.querySelector(".ws-play")?.focus()}_focusRowQuietly(t){let e=t?.querySelector(".ws-play");e&&document.activeElement!==e&&e.focus({preventScroll:!0})}_observe(){if(this.render.player!=="inline"||typeof window>"u")return;if(this._drawn=new Set,"IntersectionObserver"in window?(this._io=new IntersectionObserver(s=>{for(let r of s){if(!r.isIntersecting)continue;let i=Number(r.target.dataset.wsIndex);this._drawn.add(i),this._drawRow(i)}},{rootMargin:"200px 0px"}),this.rows.forEach(s=>s&&this._io.observe(s))):this.rows.forEach((s,r)=>s&&this._drawn.add(r)),"ResizeObserver"in window){let s=0;this._ro=new ResizeObserver(([r])=>{let i=Math.round(r.contentRect.width);i!==s&&(s=i,this._redrawAll())}),this._ro.observe(this.$.list)}let t=()=>requestAnimationFrame(()=>{this._resolveColors(),this._redrawAll()});this._mo=new MutationObserver(t);let e={attributes:!0,attributeFilter:["class","data-theme","data-color-scheme","style"]};this._mo.observe(document.documentElement,e),document.body&&this._mo.observe(document.body,e);try{window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t,{signal:this._ctl.signal})}catch{}}_resolveColors(){(this._autoSurface||!getComputedStyle(this.container).getPropertyValue("--ws-surface").trim())&&(this._autoSurface=!0,this.container.style.removeProperty("--ws-surface"),this.container.style.setProperty("--ws-surface",Nt(this.container))),this.colors={wave:this.options.waveformColor||it(this.container,"var(--ws-wave-color)")||"rgba(128,128,128,.5)",progress:this.options.progressColor||it(this.container,"var(--ws-progress-color)")||"currentColor"}}_drawRow(t){if(this.render.player!=="inline"||t==null||!this._drawn?.has(t))return;let e=this.rows[t],s=e?.querySelector("canvas");if(!s||e.hidden)return;let r=Number(this.options.barGap);ct(s,this.sounds[t].peaks,t===this.currentIndex?this.progress:0,{style:this.options.waveformStyle,color:this.colors?.wave||"rgba(128,128,128,.5)",progressColor:this.colors?.progress||"currentColor",barWidth:Math.max(1,Number(this.options.barWidth)||2),barGap:Number.isFinite(r)?Math.max(0,r):1})}_redrawAll(){this._drawn?.forEach(t=>this._drawRow(t))}_readUrl(){let t=ot(this.options.urlState);if(!t||typeof location>"u")return;let{filter:e,sort:s}=Ot(location.search,t,v(this.sounds),this._sorts);this.filter={...this.filter,...e},s&&(this.sortBy=s,this._sortSet=!0)}_queueUrl(){let t=ot(this.options.urlState);!t||typeof location>"u"||(clearTimeout(this._urlTimer),this._urlTimer=setTimeout(()=>{if(this.destroyed)return;let e=Pt(location.href,t,this.filter,this.sortBy,this._sorts?.[0]||"default");e!==location.href&&history.replaceState(history.state,"",e)},ye))}get visible(){return L(this.sounds.filter(t=>B(t,this.filter)),this.sortBy)}setFilter(t={}){this.filter={...this.filter,...t},this.limit=this._pageSize(),this._syncControls(),this._apply({resort:!1})}clearFilters(){this.setFilter(Dt)}setSort(t){this._sortSet=!0,this.sortBy=C.includes(t)?t:"default",this.menus?.setValue("sort",this.sortBy),this._apply({resort:!0})}showMore(){this.limit!==1/0&&(this.limit+=this.render.pageSize,this._apply({resort:!1}))}_pageSize(){return this.render.pageSize>0?this.render.pageSize:1/0}_syncControls(){let t=this.$,e=this.filter;t&&(t.search&&t.search.value!==e.query&&(t.search.value=e.query),this.menus?.setValue("type",e.type||""),this.menus?.setValue("key",e.key||""),this.menus?.setValue("sort",this.sortBy),t.bpmMin&&t.bpmMin.value!==String(e.bpmMin)&&(t.bpmMin.value=e.bpmMin),t.bpmMax&&t.bpmMax.value!==String(e.bpmMax)&&(t.bpmMax.value=e.bpmMax),t.chips.forEach(s=>s.setAttribute("aria-pressed",String(s.dataset.wsType===(e.type||"")))))}_apply({resort:t}){let e=this.$;if(!e)return;(t||this.sortBy!==this._lastSort)&&($t(e.list,L(this.sounds,this.sortBy).map(o=>this.rows[this.sounds.indexOf(o)])),this._lastSort=this.sortBy);let s=this.visible,{visible:r,remaining:i}=St(s,this.limit);this.sounds.forEach((o,a)=>{this.rows[a]&&(this.rows[a].hidden=!r.has(o))}),e.more&&(e.more.hidden=i<=0,e.more.textContent=h(this.strings.showMore,{count:Math.min(i,this.render.pageSize||i)})),e.empty&&(e.empty.hidden=s.length>0),e.count&&(e.count.textContent=H(s.length,this.sounds.length,this.strings)),this._queueUrl(),this._emit("filter",{visible:s.length,total:this.sounds.length,filter:{...this.filter},sort:this.sortBy}),this.options.onFilter?.(s,this)}_indexOf(t){if(t==null)return this.currentIndex??(this.visible[0]?this.sounds.indexOf(this.visible[0]):null);if(typeof t=="number")return this.sounds[t]?t:null;let e=typeof t=="object"?this.sounds.indexOf(t):this.sounds.findIndex(s=>s.id===String(t));return e>=0?e:null}_playerClass(){return this.options.playerClass||(typeof window<"u"?window.WaveformPlayer:null)||null}_ensureEngine(){if(this.engine)return this.engine;let t=this._playerClass();return t?(this.engine=new t(this.$.engine,pt(this.options.playerOptions,this.render.player,{onLoad:()=>this._onEngineLoad(),onPlay:()=>this._setPlaying(!0),onPause:()=>this._setPlaying(!1),onEnd:()=>this._onEnd(),onTimeUpdate:(e,s)=>this._onTime(e,s),onError:e=>this._onEngineError(e)})),this.engine):(console.error(`${m} @arraypress/waveform-player is required: load it before playing (or pass playerClass).`),null)}play(t,e={}){if(!this.$){this.ready.then(()=>{this.destroyed||this.play(t,e)});return}let s=this._indexOf(t);if(s==null)return;let r=this._ensureEngine();if(!r)return;if(s===this.currentIndex&&r.audio?.src){e.at!=null&&this._seekRow(s,e.at),this.playing||r.play();return}let i=this.currentIndex;this.currentIndex=s,this.progress=0,this._pendingSeek=e.at??null,i!=null&&this._paintRow(i),this._paintRow(s);let o=this.sounds[s];r.loadTrack(o.url,o.title,o.type||null,{waveform:dt(o,this.render.player),autoplay:!0})}pause(){this.engine&&this.playing&&this.engine.pause()}toggle(t){let e=this._indexOf(t);e!=null&&(e===this.currentIndex&&this.playing?this.pause():this.play(e))}next(){this._step(1)}previous(){this._step(-1)}_step(t){let e=this.visible,s=this.currentIndex==null?-1:e.indexOf(this.sounds[this.currentIndex]),r=e[s+t];if(!r)return!1;let i=_t(this.limit,s+t);return i!==this.limit&&(this.limit=i,this._apply({resort:!1})),this.play(this.sounds.indexOf(r)),!0}setLoop(t){this.loop=!!t,this._setLoop(this.loop)}_setLoop(t){this.$?.loop?.setAttribute("aria-pressed",String(t)),this.engine?.audio&&(this.engine.audio.loop=t)}_seekRow(t,e){if(t!==this.currentIndex||!this.engine){this.play(t,{at:e});return}let s=this.engine.audio?.duration;if(!Number.isFinite(s)||s<=0){this._pendingSeek=e;return}this.engine.seekTo(e*s),this.progress=e,this._paintRow(t),this.playing||this.engine.play()}_onEngineLoad(){this.engine?.audio&&(this.engine.audio.loop=this.loop);let t=this.sounds[this.currentIndex];t&&!t.peaks&&this.engine?.waveformData?.length&&(t.peaks=J(this.engine.waveformData,96),this._drawRow(this.currentIndex));let e=this.engine?.audio?.duration;this._pendingSeek!=null&&Number.isFinite(e)&&e>0&&(this.engine.seekTo(this._pendingSeek*e),this.progress=this._pendingSeek,this._pendingSeek=null)}_onTime(t,e){if(!(this.currentIndex==null||!e)){if(this._pendingSeek!=null){let s=this._pendingSeek;this._pendingSeek=null,this.engine.seekTo(s*e);return}this.progress=Math.min(Math.max(t/e,0),1),!this._raf&&(this._raf=requestAnimationFrame(()=>{this._raf=0,this._drawRow(this.currentIndex),this.rows[this.currentIndex]?.querySelector(".ws-wave")?.setAttribute("aria-valuenow",String(Math.round(this.progress*100)))}))}}_onEnd(){let t=this.sounds[this.currentIndex];this._emit("end",{sound:t,index:this.currentIndex}),this.options.onEnd?.(t,this),!(this.options.autoAdvance&&this._step(1))&&(this.progress=0,this._setPlaying(!1))}_onEngineError(t){this.rows[this.currentIndex]?.classList.add("is-error"),this._emit("error",{error:t,sound:this.sounds[this.currentIndex],index:this.currentIndex}),this.options.onError?.(t,this)}_setPlaying(t){let e=this.playing!==t;this.playing=t;let s=this.currentIndex;if(s==null||(this._paintRow(s),!e))return;let r=this.sounds[s];t&&this.$.status&&(this.$.status.textContent=h(this.strings.nowPlaying,{title:r.title})),this._emit(t?"play":"pause",{sound:r,index:s}),(t?this.options.onPlay:this.options.onPause)?.(r,this)}_paintRow(t){let e=this.rows[t];if(!e)return;let s=t===this.currentIndex,r=s&&this.playing;e.classList.toggle("is-current",s),e.classList.toggle("is-playing",r);let i=e.querySelector(".ws-play");i&&(i.setAttribute("aria-pressed",String(r)),i.setAttribute("aria-label",h(r?this.strings.pause:this.strings.play,{title:this.sounds[t].title})));let o=e.querySelector(".ws-wave");o&&(o.tabIndex=s?0:-1,s||o.setAttribute("aria-valuenow","0")),this._drawRow(t)}_emit(t,e={}){yt(this.container,t,{...e,instance:this})}get current(){return this.currentIndex==null?null:this.sounds[this.currentIndex]}destroy(){if(!this.destroyed){this.destroyed=!0,this._ctl.abort(),this._io?.disconnect(),this._ro?.disconnect(),this._mo?.disconnect(),this._raf&&cancelAnimationFrame(this._raf),clearTimeout(this._urlTimer);try{this.engine?.destroy()}catch{}this.engine=null,this._originalHTML!=null&&(this.container.innerHTML=this._originalHTML),this._addedClasses?.length&&this.container.classList.remove(...this._addedClasses),this._autoSurface&&this.container.style.removeProperty("--ws-surface"),delete this.container.dataset.wsInitialized,n.instances.delete(this.container)}}static init(t=document){if(typeof document>"u")return[];let e=t||document,s=[...e.matches?.("[data-waveform-sounds]")?[e]:[],...e.querySelectorAll("[data-waveform-sounds]")],r=[];for(let i of s)if(!(i.dataset.wsInitialized==="true"||n.instances.has(i)))try{r.push(new n(i))}catch(o){console.error(`${m} Failed to initialise:`,o,i)}return r}static getInstance(t){let e=typeof t=="string"?document.querySelector(t):t;return e&&n.instances.get(e)||null}static prune(){for(let[t,e]of n.instances)t.isConnected||e.destroy()}};g.utils={encodePeaks:F,decodePeaks:V,normalizeKey:k,normalizeSounds:_,parseManifest:q,facets:v,matches:B,sortSounds:L,formatDuration:z,renderSounds:$};g.DEFAULT_OPTIONS=j;g.DEFAULT_STRINGS=y;typeof window<"u"&&(window.WaveformSounds=g);var G=g;var yn=G;typeof document<"u"&&document.documentElement?.dataset?.waveformAutoinit!=="false"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>G.init(),{once:!0}):G.init());})();
1
+ (()=>{var Pt=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function $(n){return n==null?"":String(n).replace(/[&<>"']/g,t=>Pt[t])}var Nt=/[^\p{L}\p{N}]+/u,Ot=/\p{Mn}+/gu;function x(n){return!n||typeof n!="string"?"":n.toLowerCase().normalize("NFD").replace(Ot,"")}function I(n){return x(n).split(Nt).filter(t=>t!=="")}function rt(n,t){let e=Array.from(n??""),s=Array.from(t??""),r=[],i=Array.from({length:s.length+1},(o,a)=>a);for(let o=1;o<=e.length;o++){let a=[o];for(let l=1;l<=s.length;l++){let p=e[o-1]===s[l-1]?0:1;a[l]=Math.min(i[l]+1,a[l-1]+1,i[l-1]+p),o>1&&l>1&&e[o-1]===s[l-2]&&e[o-2]===s[l-1]&&(a[l]=Math.min(a[l],r[l-2]+1))}r=i,i=a}return i[s.length]}function it(n,t,e={}){let s=e.fuzzyFrom??4,r=x(n),i=I(n);return I(t).every(o=>{if(r.includes(o))return!0;let a=Array.from(o).length;return a<s?!1:i.some(l=>rt(o,l)<=1||rt(o,Array.from(l).slice(0,a).join(""))<=1)})}function N(n){if(!Array.isArray(n))return"";let t="";for(let e of n){let s=Math.round(Math.min(Math.max(Number(e)||0,0),1)*255);t+=(s<16?"0":"")+s.toString(16)}return t}function H(n,t=1){if(n==null||n==="")return null;if(typeof n=="string"){if(!/^[0-9a-f]+$/i.test(n)||n.length%2)return null;let r=new Array(n.length/2);for(let i=0;i<r.length;i++)r[i]=parseInt(n.substr(i*2,2),16)/255;return r}if(!Array.isArray(n))return null;let e=Number(t)>0?Number(t):1,s=n.map(r=>Math.min(Math.max((Number(r)||0)/e,0),1));return s.length?s:null}function T(n){if(n==null)return"";let t=String(n).trim(),e=t.match(/^([A-Ga-g])[\s_-]*([#♯b♭]?)[\s_-]*(m|min|minor|maj|major)?$/i);if(!e)return t;let s=e[1].toUpperCase(),r=e[2]==="\u266F"?"#":e[2]==="\u266D"?"b":e[2],i=e[3]&&/^m(in(or)?)?$/i.test(e[3])&&e[3]!=="M";return s+r+(i?"m":"")}var Dt={C:0,"C#":1,Db:1,D:2,"D#":3,Eb:3,E:4,F:5,"F#":6,Gb:6,G:7,"G#":8,Ab:8,A:9,"A#":10,Bb:10,B:11};function P(n){if(!n)return 1/0;let t=n.endsWith("m"),e=t?n.slice(0,-1):n,s=Dt[e];return s===void 0?1e3:s*2+(t?1:0)}function O(n){if(n==null||n==="")return"";let t=Number(n);if(!Number.isFinite(t)||t<0)return"";let e=Math.round(t);return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`}function Ft(n){if(n==null||n==="")return null;if(typeof n=="number")return Number.isFinite(n)&&n>=0?n:null;let t=String(n).trim();if(/^\d+(\.\d+)?$/.test(t))return Number(t);let e=t.split(":").map(Number);return e.length<2||e.some(s=>!Number.isFinite(s))?null:e.reduce((s,r)=>s*60+r,0)}function zt(n){let e=(String(n||"").split(/[?#]/)[0].split("/").pop()||"").replace(/\.[a-z0-9]+$/i,"");try{e=decodeURIComponent(e)}catch{}return e.replace(/[_]+/g," ").replace(/\s+/g," ").trim()}function j(n,t,e=1){if(!n||typeof n!="object"||!n.url)return null;let s=Number(n.bpm),r=Array.isArray(n.tags)?n.tags.map(i=>String(i).trim()).filter(Boolean):typeof n.tags=="string"?n.tags.split(",").map(i=>i.trim()).filter(Boolean):[];return{id:n.id!=null&&n.id!==""?String(n.id):`sound-${t+1}`,url:String(n.url),title:n.title?String(n.title):zt(n.url),type:n.type?String(n.type):"",bpm:Number.isFinite(s)&&s>0?Math.round(s*100)/100:null,key:T(n.key),duration:Ft(n.duration),tags:r,peaks:H(n.peaks,e),waveform:n.waveform?String(n.waveform):null,download:n.download?String(n.download):null}}function D(n){let t=Array.isArray(n)?n:Array.isArray(n?.sounds)?n.sounds:[],e=Array.isArray(n)?1:Number(n?.peakScale)||1;return S(t,e)}function S(n,t=1){let e=new Set,s=[];return(Array.isArray(n)?n:[]).forEach((r,i)=>{let o=j(r,i,t);if(!o)return;let a=o.id,l=2;for(;e.has(a);)a=`${o.id}-${l++}`;o.id=a,e.add(a),s.push(o)}),s}function _(n){let t=new Map,e=new Set,s=1/0,r=-1/0,i=!1;for(let o of n)o.type&&t.set(o.type,(t.get(o.type)||0)+1),o.key&&e.add(o.key),o.bpm!=null&&(s=Math.min(s,o.bpm),r=Math.max(r,o.bpm)),o.duration!=null&&(i=!0);return{types:[...t].map(([o,a])=>({name:o,count:a})),keys:[...e].sort((o,a)=>P(o)-P(a)||o.localeCompare(a)),bpm:s===1/0?null:{min:s,max:r},hasDuration:i}}function F(n,t={}){if(t.type&&n.type!==t.type||t.key&&n.key!==T(t.key))return!1;let e=Number(t.bpmMin),s=Number(t.bpmMax);if((t.bpmMin!=null&&t.bpmMin!==""&&Number.isFinite(e)||t.bpmMax!=null&&t.bpmMax!==""&&Number.isFinite(s))&&(n.bpm==null||t.bpmMin!=null&&t.bpmMin!==""&&n.bpm<e||t.bpmMax!=null&&t.bpmMax!==""&&n.bpm>s))return!1;let r=I(t.query||"");if(r.length){let i=[n.title,n.type,n.key,...n.tags||[]].join(" "),o=x(i),a=r.filter(l=>!(/^\d+$/.test(l)&&!o.includes(l)&&n.bpm!=null&&Math.round(n.bpm)===Number(l)));if(a.length&&!it(i,a.join(" ")))return!1}return!0}var k=["default","title","bpm","key","duration"],qt={default:()=>!0,title:()=>!0,bpm:n=>n.bpm!==null,key:n=>n.keys.length>0,duration:n=>n.hasDuration};function z(n,t){return n.filter(e=>qt[e]?.(t))}function E(n,t="default"){let e=n.map((i,o)=>({s:i,i:o})),s=i=>i??1/0,r={title:(i,o)=>i.s.title.localeCompare(o.s.title,void 0,{numeric:!0,sensitivity:"base"}),bpm:(i,o)=>s(i.s.bpm)-s(o.s.bpm),key:(i,o)=>P(i.s.key)-P(o.s.key),duration:(i,o)=>s(i.s.duration)-s(o.s.duration)}[t];return r&&e.sort((i,o)=>r(i,o)||i.i-o.i),e.map(i=>i.s)}function Bt(n){let t=n.getBoundingClientRect();if(!t.width||!t.height)return null;let e=Math.min(window.devicePixelRatio||1,3),s=Math.round(t.width*e),r=Math.round(t.height*e);return n.width!==s&&(n.width=s),n.height!==r&&(n.height=r),{width:t.width,height:t.height,dpr:e}}function G(n,t){if(!n?.length||t<=0)return[];if(n.length===t)return n;let e=new Array(t),s=n.length/t;for(let r=0;r<t;r++){let i=Math.floor(r*s),o=Math.max(i+1,Math.floor((r+1)*s)),a=0;for(let l=i;l<o&&l<n.length;l++)n[l]>a&&(a=n[l]);e[r]=a}return e}function Ut(n,t,e,s){let r=s.barWidth+s.barGap,i=G(n,Math.max(1,Math.floor((t+s.barGap)/r))),o=i.reduce((l,p)=>p>l?p:l,0),a=o>0?1/o:1;return i.map((l,p)=>{let c=Math.max(l*a,.04);if(s.style==="bars"){let st=Math.max(1,c*e);return{x:p*r,y:e-st,w:s.barWidth,h:st}}let h=Math.max(1,c*(e-2));return{x:p*r,y:e/2-h/2,w:s.barWidth,h}})}function ot(n,t,e,s){let r=Bt(n),i=r&&n.getContext&&n.getContext("2d");if(!i)return;let{width:o,height:a,dpr:l}=r;if(i.setTransform(l,0,0,l,0,0),i.clearRect(0,0,o,a),!t?.length){i.fillStyle=s.color,i.fillRect(0,Math.floor(a/2),o,1);return}let p=new Path2D;for(let h of Ut(t,o,a,s))p.rect(h.x,h.y,h.w,h.h);i.fillStyle=s.color,i.fill(p);let c=Math.min(Math.max(e,0),1)*o;c>0&&(i.save(),i.beginPath(),i.rect(0,0,c,a),i.clip(),i.fillStyle=s.progressColor,i.fill(p),i.restore())}var Kt=["onLoad","onPlay","onPause","onEnd","onTimeUpdate","onError"];function at(n,t,e){let s=n||{},r=t==="strip",i={height:r?48:32,waveformStyle:r?"mirror":"bars",preload:"metadata",singlePlay:!0,...s,audioMode:"self"};for(let o of Kt)i[o]=(...a)=>{e[o]?.(...a),typeof s[o]=="function"&&s[o](...a)};return i}function lt(n,t){return t==="strip"&&n.waveform||n.peaks||null}function Ht(n,t){let e=x(String(t??"")).trim();return!e||x(String(n??"")).includes(e)}function ut(n,t,e){return Math.max(0,Math.min(e-1,n+t))}function v(n){return{button:n.querySelector("[data-ws-menu-btn]"),pop:n.querySelector("[data-ws-menu-pop]"),search:n.querySelector("[data-ws-menu-search]"),list:n.querySelector("[data-ws-menu-list]"),none:n.querySelector("[data-ws-menu-none]"),value:n.querySelector("[data-ws-menu-value]")}}var W=n=>n.search||n.list,V=(n,t=!1)=>[...n.list.querySelectorAll('[role="option"]')].filter(e=>!t||!e.hidden),q=class{constructor(t,{onPick:e,signal:s}){this.container=t,this.onPick=e,this.menus=Object.fromEntries([...t.querySelectorAll("[data-ws-menu]")].map(r=>[r.dataset.wsMenu,r])),this.openMenu=null,this._bind(s)}_bind(t){let e={signal:t};for(let[s,r]of Object.entries(this.menus)){let i=v(r);i.button.addEventListener("click",()=>this.openMenu===r?this.close(!0):this.open(r),e),i.button.addEventListener("keydown",o=>{(o.key==="ArrowDown"||o.key==="ArrowUp")&&(o.preventDefault(),this.open(r))},e),i.list.addEventListener("click",o=>{let a=o.target.closest('[role="option"]');a&&this._pick(s,a.dataset.value)},e),i.list.addEventListener("mousedown",o=>o.preventDefault(),e),i.search?.addEventListener("input",()=>this._filter(r,i.search.value),e),W(i).addEventListener("keydown",o=>this._onKey(o,s,r),e)}document.addEventListener("pointerdown",s=>{this.openMenu&&!this.openMenu.contains(s.target)&&this.close(!1)},e),this.container.addEventListener("focusout",s=>{this.openMenu&&!this.openMenu.contains(s.relatedTarget)&&this.close(!1)},e)}open(t){this.openMenu&&this.openMenu!==t&&this.close(!1);let e=v(t);e.button.setAttribute("aria-expanded","true"),e.pop.hidden=!1,this.openMenu=t,e.search&&(e.search.value="",this._filter(t,"")),t.classList.remove("ws-menu--end"),e.pop.getBoundingClientRect().right>this.container.getBoundingClientRect().right+1&&t.classList.add("ws-menu--end"),this._activate(t,e.list.querySelector('[role="option"][aria-selected="true"]')),W(e).focus()}close(t){let e=this.openMenu;if(!e)return;this.openMenu=null;let s=v(e);s.pop.hidden=!0,s.button.setAttribute("aria-expanded","false"),t&&s.button.focus()}setValue(t,e){let s=this.menus[t];if(!s)return;let r=v(s),i=null;for(let o of V(r)){let a=o.dataset.value===String(e??"");o.setAttribute("aria-selected",String(a)),a&&(i=o.querySelector(".ws-menu-text")?.textContent??"")}i!==null&&(r.value.textContent=i)}_filter(t,e){let s=v(t),r=null;for(let i of V(s))i.hidden=!Ht(i.textContent,e),i.hidden||(r??=i);s.none.hidden=r!==null,this._activate(t,r)}_activate(t,e){let s=v(t);for(let i of s.list.querySelectorAll(".is-active"))i.classList.remove("is-active");let r=W(s);if(!e||e.hidden){r.removeAttribute("aria-activedescendant");return}e.classList.add("is-active"),r.setAttribute("aria-activedescendant",e.id),e.scrollIntoView?.({block:"nearest"})}_onKey(t,e,s){let r=v(s),i=V(r,!0),o=i.indexOf(r.list.querySelector(".is-active")),a=p=>{t.preventDefault(),this._activate(s,i[p])},l=t.target.matches("input");switch(t.key){case"ArrowDown":return a(ut(o,1,i.length));case"ArrowUp":return a(ut(o,-1,i.length));case"Home":return l?void 0:a(0);case"End":return l?void 0:a(i.length-1);case"Enter":t.preventDefault(),o>=0&&this._pick(e,i[o].dataset.value);return;case"Escape":return t.preventDefault(),t.stopPropagation(),this.close(!0);case"Tab":return this.close(!1);default:return}}_pick(t,e){this.close(!0),this.onPick(t,e)}};var y="[WaveformSounds]";function Y(n,t=0,e=1){return Math.min(Math.max(n,t),e)}function ct(n,t){return t&&t.width?Y((n-t.left)/t.width):0}function pt(n){return!!n&&(n.isContentEditable||/^(INPUT|SELECT|TEXTAREA)$/.test(n.tagName))}function dt(n,t,e){let s=new CustomEvent(`waveformsounds:${t}`,{bubbles:!0,detail:e});return n.dispatchEvent(s),s}function ht(n){let t=5381;for(let e of n)t=t*33+e.codePointAt(0)>>>0;return t}var ft=.1;function mt(n,t,e){if(!e)return null;switch(n){case"ArrowDown":return t+1<e?t+1:null;case"ArrowUp":return t>0?t-1:"search";case"Home":return 0;case"End":return e-1;default:return null}}function yt(n,t){return t!=="ArrowRight"&&t!=="ArrowLeft"?null:Y(n+(t==="ArrowRight"?ft:-ft),0,.999)}function wt(n,t){let e=new Set(n.slice(0,t));return{visible:e,remaining:n.length-e.size}}function gt(n,t){return t>=n?t+1:n}var w={search:"Search sounds",searchPlaceholder:"Search sounds\u2026",all:"All",types:"Type",key:"Key",anyKey:"Any key",allTypes:"All types",findType:"Find a type\u2026",findKey:"Find a key\u2026",noMatches:"No matches",bpm:"BPM",bpmMin:"Min BPM",bpmMax:"Max BPM",sort:"Sort",sortBy:"Sort by",sortDefault:"Default",sortTitle:"Name",sortBpm:"BPM",sortKey:"Key",sortDuration:"Length",loop:"Loop",play:"Play {title}",pause:"Pause {title}",seek:"Seek {title}",download:"Download {title}",count:"{count} sounds",countOne:"1 sound",countFiltered:"{count} of {total} sounds",showMore:"Show {count} more",empty:"No sounds match.",clear:"Clear filters",nowPlaying:"Playing {title}"},bt={default:"sortDefault",title:"sortTitle",bpm:"sortBpm",key:"sortKey",duration:"sortDuration"};function f(n,t={}){return String(n).replace(/\{(\w+)\}/g,(e,s)=>s in t?String(t[s]):e)}function B(n,t,e=w){return n!==t?f(e.countFiltered,{count:n,total:t}):t===1?e.countOne:f(e.count,{count:t})}var St=["type","key","bpm"],_t=["type","bpm","key","duration"],m={player:"inline",search:!0,filters:[...St],sorts:[...k],loopToggle:!0,showCount:!0,menuSearch:8,pageSize:50,columns:[..._t],maxTypeChips:10};function xt(n){let t={};for(let e in n??{})n[e]!==void 0&&(t[e]=n[e]);return t}function J(n,t,e){return Array.isArray(n)?n.filter(s=>t.includes(s)):e}function Q(n,t){let e=Number(n);return Number.isFinite(e)&&e>=0?Math.floor(e):t}function C(n={}){let t={...m,...xt(n)};return{...t,player:t.player==="strip"?"strip":"inline",filters:J(t.filters,St,m.filters),sorts:J(t.sorts,k,m.sorts),columns:J(t.columns,_t,m.columns),menuSearch:Q(t.menuSearch,m.menuSearch),maxTypeChips:Q(t.maxTypeChips,m.maxTypeChips),pageSize:Q(t.pageSize,m.pageSize),strings:{...w,...xt(n.strings)}}}var U={...m,sounds:null,manifest:null,waveformStyle:"mirror",waveformColor:null,progressColor:null,barWidth:2,barGap:1,loop:!1,autoAdvance:!1,arrowAudition:!0,idPrefix:null,urlState:!1,playerOptions:null,playerClass:null,strings:null,onReady:null,onPlay:null,onPause:null,onEnd:null,onFilter:null,onError:null};function M(n){if(n===""||n==="true")return!0;if(n==="false")return!1}function X(n){if(n!=null)return n.split(",").map(t=>t.trim()).filter(Boolean)}function L(n){return n===void 0||n===""?void 0:Number(n)}function jt(n){if(n===void 0)return;let t=M(n);return t===void 0?n:t}function vt(n,t){if(n)try{return JSON.parse(n)}catch{console.warn(`${y} Ignoring invalid JSON in data-${t}`);return}}function Mt(n){let t=n.dataset||{},e={player:t.player||void 0,manifest:t.manifest||void 0,search:M(t.search),filters:X(t.filters),sorts:X(t.sorts),showCount:M(t.showCount),menuSearch:L(t.menuSearch),idPrefix:t.idPrefix||void 0,urlState:jt(t.urlState),loopToggle:M(t.loopToggle),pageSize:L(t.pageSize),maxTypeChips:L(t.maxTypeChips),columns:X(t.columns),waveformStyle:t.waveformStyle||void 0,waveformColor:t.waveformColor||void 0,progressColor:t.progressColor||void 0,barWidth:L(t.barWidth),barGap:L(t.barGap),loop:M(t.loop),autoAdvance:M(t.autoAdvance),arrowAudition:M(t.arrowAudition),strings:vt(t.strings,"strings"),playerOptions:vt(t.playerOptions,"player-options")};for(let s of Object.keys(e))e[s]===void 0&&delete e[s];return e}function At(...n){let t={};for(let e of n)if(e)for(let s in e)e[s]!==null&&e[s]!==void 0&&(t[s]=e[s]);return t}var Gt=new Set(["input","br","img"]);function d(n){return $(n??"")}function Wt(n={}){let t="";for(let[e,s]of Object.entries(n))s===!0?t+=` ${e}`:s!==!1&&s!=null&&(t+=` ${e}="${$(s)}"`);return t}function u(n,t={},...e){let s=`<${n}${Wt(t)}>`;return Gt.has(n)?s:s+e.flat(1/0).filter(r=>r!=null&&r!==!1&&r!=="").join("")+`</${n}>`}function A(n,t=""){return`<svg class="${t?`ws-icon ${t}`:"ws-icon"}" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${n}"/></svg>`}var g={play:A("M8 5.5v13l11-6.5z","ws-icon-play"),pause:A("M7 5h3.5v14H7zM13.5 5H17v14h-3.5z","ws-icon-pause"),search:A("M10.5 4a6.5 6.5 0 1 0 4.03 11.6l4.43 4.43 1.41-1.41-4.43-4.43A6.5 6.5 0 0 0 10.5 4zm0 2a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9z"),chevron:A("M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z","ws-menu-chevron"),check:A("M9.5 16.2 5.3 12l-1.4 1.4 5.6 5.6 11-11-1.4-1.4z","ws-menu-check"),download:A("M11 4h2v8.6l3.3-3.3 1.4 1.4L12 16.4l-5.7-5.7 1.4-1.4 3.3 3.3zM5 18h14v2H5z"),loop:A("M17 4l3 3-3 3V8H8a3 3 0 0 0-3 3v1H3v-1a5 5 0 0 1 5-5h9V4zM7 20l-3-3 3-3v2h9a3 3 0 0 0 3-3v-1h2v1a5 5 0 0 1-5 5H7v2z")};function Vt(n){let t=[n.length,...n.map(e=>e.url)].join("|");return`ws${ht(t).toString(36)}`}function Yt(n,t){let e=t.filters.includes("type")&&n.types.length>1,s=z(t.sorts,n);return{types:e?n.types.length>t.maxTypeChips?"menu":"chips":null,key:t.filters.includes("key")&&n.keys.length>1,bpm:t.filters.includes("bpm")&&n.bpm!==null&&n.bpm.max>n.bpm.min,sorts:s.length>1?s:[],search:!!t.search,loop:!!t.loopToggle,count:!!t.showCount}}function Jt(n){return u("label",{class:"ws-search"},g.search,u("span",{class:"ws-sr"},d(n.search)),u("input",{type:"search",class:"ws-search-input","data-ws-search":!0,placeholder:n.searchPlaceholder,autocomplete:"off",spellcheck:"false"}))}function Qt(n,t){let e=`${t.id}-${n}-list`,s=t.options.find(l=>l.value===t.value)??t.options[0],r=t.placeholder&&t.options.length>t.searchFrom,i=u("button",{type:"button",class:"ws-menu-btn","data-ws-menu-btn":!0,"aria-haspopup":"listbox","aria-expanded":"false","aria-controls":e},t.prefix?u("span",{class:"ws-menu-prefix"},d(t.prefix)):u("span",{class:"ws-sr"},d(`${t.label}: `)),u("span",{class:"ws-menu-value","data-ws-menu-value":!0},d(s.label)),g.chevron),o=r&&u("input",{type:"search",class:"ws-menu-search","data-ws-menu-search":!0,role:"combobox","aria-expanded":"true","aria-controls":e,"aria-autocomplete":"list","aria-label":t.placeholder,placeholder:t.placeholder,autocomplete:"off",spellcheck:"false"}),a=t.options.map((l,p)=>u("li",{role:"option",id:`${t.id}-${n}-${p}`,class:"ws-menu-option","data-value":l.value,"aria-selected":String(l===s)},g.check,u("span",{class:"ws-menu-text"},d(l.label)),l.count!=null&&u("span",{class:"ws-menu-count"},d(l.count))));return u("div",{class:"ws-menu","data-ws-menu":n},i,u("div",{class:"ws-menu-pop","data-ws-menu-pop":!0,hidden:!0},o,u("ul",{class:"ws-menu-list",role:"listbox",id:e,"aria-label":t.label,tabindex:"-1","data-ws-menu-list":!0},a),u("p",{class:"ws-menu-none","data-ws-menu-none":!0,hidden:!0},d(t.noMatches))))}function Xt(n,t){let e=(s,r,i)=>u("input",{type:"number",inputmode:"numeric",[s]:!0,"aria-label":r,placeholder:i,min:"0",step:"1"});return u("span",{class:"ws-bpm-range",role:"group","aria-label":n.bpm},e("data-ws-bpm-min",n.bpmMin,t.min),u("span",{"aria-hidden":"true"},"\u2013"),e("data-ws-bpm-max",n.bpmMax,t.max),u("span",{class:"ws-bpm-unit","aria-hidden":"true"},d(n.bpm)))}function Zt(n){return u("button",{type:"button",class:"ws-loop","data-ws-loop":!0,"aria-pressed":"false"},g.loop,u("span",{},d(n.loop)))}function Tt(n,t,e,s){return u("button",{type:"button",class:"ws-chip","data-ws-type":n,"aria-pressed":String(s)},u("span",{class:"ws-chip-label"},d(t))," ",u("span",{class:"ws-chip-count"},d(e)))}function te(n,{o:t,s:e,f:s,total:r,id:i}){let o=(c,h)=>Qt(c,{id:i,searchFrom:t.menuSearch,noMatches:e.noMatches,...h}),a=[n.types==="menu"&&o("type",{label:e.types,value:"",placeholder:e.findType,options:[{value:"",label:e.allTypes,count:r},...s.types.map(c=>({value:c.name,label:c.name,count:c.count}))]}),n.key&&o("key",{label:e.key,value:"",placeholder:e.findKey,options:[{value:"",label:e.anyKey},...s.keys.map(c=>({value:c,label:c}))]}),n.bpm&&Xt(e,s.bpm),n.sorts.length>0&&o("sort",{label:e.sort,prefix:e.sortBy,value:n.sorts[0],options:n.sorts.map(c=>({value:c,label:e[bt[c]]}))}),n.loop&&Zt(e)].filter(Boolean),l=n.types==="chips"&&u("div",{class:"ws-types",role:"group","aria-label":e.types},Tt("",e.all,r,!0),s.types.map(c=>Tt(c.name,c.name,c.count,!1))),p=n.count&&u("p",{class:"ws-count","data-ws-count":!0,"aria-live":"polite"},d(B(r,r,e)));return u("div",{class:"ws-toolbar"},n.search&&Jt(e),a.length>0&&u("div",{class:"ws-controls"},a),(l||p)&&u("div",{class:"ws-meta"},l,p))}var ee={type:n=>d(n.type),bpm:n=>d(n.bpm??""),key:n=>d(n.key),duration:n=>d(O(n.duration))};function ne(n,t,e,s=!1){let r=e.strings,i={title:n.title},o=e.columns.map(a=>u("span",{class:`ws-cell ws-${a}`},ee[a](n)));return u("li",{class:"ws-row","data-ws-index":t,"data-ws-id":n.id,"data-url":n.url,"data-title":n.title,"data-type":n.type||null,"data-bpm":n.bpm,"data-key":n.key||null,"data-duration":n.duration,"data-tags":n.tags?.length?n.tags.join(","):null,"data-peaks":n.peaks?N(n.peaks):null,"data-waveform":n.waveform,"data-download":n.download,hidden:s},u("button",{type:"button",class:"ws-play","aria-pressed":"false","aria-label":f(r.play,i)},g.play,g.pause),u("span",{class:"ws-cell ws-title"},d(n.title)),o.length>0&&u("span",{class:"ws-cells"},o),e.player==="inline"&&u("span",{class:"ws-wave",role:"slider","aria-label":f(r.seek,i),"aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":"0",tabindex:"-1"},u("canvas",{class:"ws-canvas","aria-hidden":"true"})),n.download&&u("a",{class:"ws-download",href:n.download,download:!0,"aria-label":f(r.download,i)},g.download))}function se({o:n,s:t,total:e}){let s=n.pageSize>0?n.pageSize:e,r=Math.max(0,e-s),i=n.player==="strip";return[u("p",{class:"ws-empty","data-ws-empty":!0,hidden:!0},d(t.empty)," ",u("button",{type:"button",class:"ws-clear","data-ws-clear":!0},d(t.clear))),u("button",{type:"button",class:"ws-more","data-ws-more":!0,hidden:r===0},d(f(t.showMore,{count:Math.min(r,s)}))),u("div",{class:i?"ws-engine ws-engine--strip":"ws-engine","data-ws-engine":!0,hidden:!i}),u("p",{class:"ws-sr","data-ws-status":!0,"aria-live":"polite"})].join("")}function R(n,t={}){let e=C(t),s=S(n),r={o:e,s:e.strings,f:_(s),total:s.length,id:e.idPrefix||Vt(s)},i=e.pageSize>0?e.pageSize:1/0;return te(Yt(r.f,e),r)+u("ul",{class:`ws-list ws-list--${e.player}`,role:"list","data-ws-list":!0},s.map((o,a)=>ne(o,a,e,a>=i)))+se(r)}function re(n,t={},e=""){let s=C(t),r=["waveform-sounds",`waveform-sounds--${s.player}`,e].filter(Boolean).join(" ");return u("div",{class:r,"data-waveform-sounds":!0,"data-player":s.player},R(n,t))}var Z=":scope > [data-ws-index]";function kt(n){let t=[...n.querySelectorAll(Z)].sort((s,r)=>Number(s.dataset.wsIndex)-Number(r.dataset.wsIndex)),e=[];for(let s of t){let r=s.dataset,i=j({id:r.wsId,url:r.url,title:r.title,type:r.type,bpm:r.bpm,key:r.key,duration:r.duration,tags:r.tags,peaks:r.peaks,waveform:r.waveform,download:r.download},e.length);if(!i){s.remove();continue}s.dataset.wsIndex=String(e.length),e.push(i)}return e}function Et(n){let t=[];return n.querySelectorAll(Z).forEach(e=>{t[Number(e.dataset.wsIndex)]=e}),t}function tt(n){return[...n.querySelectorAll(Z)].filter(t=>!t.hidden)}function Ct(n,t){let e=document.createDocumentFragment();for(let s of t)s&&e.appendChild(s);n.appendChild(e)}function ie(n){let t=String(n??"").trim();if(!t||t==="transparent")return 0;let e=t.match(/\/\s*([\d.]+)(%?)\s*\)$/);if(e)return Number(e[1])/(e[2]?100:1);let s=t.match(/^rgba\(\s*[^,]+,[^,]+,[^,]+,\s*([\d.]+)\s*\)$/);return s?Number(s[1]):1}function Lt(n,t=.95){for(let e=n;e&&e.nodeType===1;e=e.parentElement||e.getRootNode?.().host){let s=getComputedStyle(e).backgroundColor;if(ie(s)>t)return s}return"#fff"}function et(n,t){let e=document.createElement("span");e.style.cssText="position:absolute;width:0;height:0;overflow:hidden;visibility:hidden",e.style.color=t,n.appendChild(e);let s=getComputedStyle(e).color;return e.remove(),s}function nt(n){if(!n)return null;let t=typeof n=="string"?`${n}-`:"";return{q:`${t}q`,type:`${t}type`,key:`${t}key`,bpm:`${t}bpm`,sort:`${t}sort`}}function oe(n){let t=String(n??"").match(/^(\d*)-(\d*)$/);return t&&(t[1]||t[2])?{bpmMin:t[1],bpmMax:t[2]}:null}function ae(n,t){let e=n??"",s=t??"";return e!==""||s!==""?`${e}-${s}`:""}function Rt(n,t,e,s){let r={filter:{},sort:null};if(!t)return r;let i=new URLSearchParams(n),o=i.get(t.q);o&&(r.filter.query=o);let a=i.get(t.type);a&&e.types.some(h=>h.name===a)&&(r.filter.type=a);let l=T(i.get(t.key));l&&e.keys.includes(l)&&(r.filter.key=l);let p=oe(i.get(t.bpm));p&&Object.assign(r.filter,p);let c=i.get(t.sort);return c&&s.includes(c)&&(r.sort=c),r}function It(n,t,e,s,r){if(!t)return n;let i=new URL(n),o=(a,l)=>l?i.searchParams.set(a,l):i.searchParams.delete(a);return o(t.q,String(e.query??"").trim()),o(t.type,e.type),o(t.key,e.key),o(t.bpm,ae(e.bpmMin,e.bpmMax)),o(t.sort,s!==r?s:""),i.href}var $t=Object.freeze({query:"",type:"",key:"",bpmMin:"",bpmMax:""}),le=120,ue=200,ce=250,b=class n{static instances=new Map;constructor(t,e={}){let s=typeof t=="string"?document.querySelector(t):t;if(!s)throw new Error(`${y} Container not found: ${t}`);this.container=s,this.options=At(U,e,Mt(s)),this.options.waveformStyle=this.options.waveformStyle==="bars"?"bars":"mirror",this.strings={...w,...this.options.strings||{}},this.render={...C(this.options),strings:this.strings},this.sounds=[],this.rows=[],this.filter={...$t},this.sortBy="default",this.limit=this._pageSize(),this.currentIndex=null,this.playing=!1,this.progress=0,this.loop=!!this.options.loop,this.engine=null,this.menus=null,this.destroyed=!1,this._ctl=new AbortController,this._originalHTML=null,this._pendingSeek=null,this._raf=0,n.instances.set(s,this),s.dataset.wsInitialized="true",this.ready=Promise.resolve().then(()=>this._init()).catch(r=>{console.error(`${y} Failed to initialise:`,r),this._emit("error",{error:r}),this.options.onError?.(r,this)})}async _init(){let t=this.container,e=t.querySelector("[data-ws-list]");if(e)this.sounds=kt(e);else{if(this._originalHTML=t.innerHTML,this.sounds=await this._loadSounds(),this.destroyed)return;t.innerHTML=R(this.sounds,{...this.render,idPrefix:this.options.idPrefix||t.id||void 0})}this.destroyed||(this._addedClasses=["waveform-sounds",`waveform-sounds--${this.render.player}`].filter(s=>!t.classList.contains(s)),t.classList.add(...this._addedClasses),this._cacheRefs(),this._bind(),this._observe(),this._resolveColors(),this._setLoop(this.loop),this._sorts=z(this.render.sorts,_(this.sounds)),this._sortSet||(this.sortBy=this._sorts[0]||"default"),this._readUrl(),this._syncControls(),this._apply({resort:this.sortBy!=="default"}),this._playerClass()&&this._ensureEngine(),this._emit("ready",{sounds:this.sounds.length}),this.options.onReady?.(this))}async _loadSounds(){if(this.options.sounds||!this.options.manifest)return S(this.options.sounds||[]);let t=await fetch(this.options.manifest);if(!t.ok)throw new Error(`${y} Manifest ${this.options.manifest}: HTTP ${t.status}`);return D(await t.json())}_cacheRefs(){let t=e=>this.container.querySelector(e);this.$={list:t("[data-ws-list]"),search:t("[data-ws-search]"),bpmMin:t("[data-ws-bpm-min]"),bpmMax:t("[data-ws-bpm-max]"),loop:t("[data-ws-loop]"),count:t("[data-ws-count]"),empty:t("[data-ws-empty]"),more:t("[data-ws-more]"),engine:t("[data-ws-engine]"),status:t("[data-ws-status]"),chips:[...this.container.querySelectorAll("[data-ws-type]")]},this.rows=Et(this.$.list)}_bind(){let t={signal:this._ctl.signal},e=this.$,s=this.container;s.addEventListener("click",a=>this._onClick(a),t),s.addEventListener("pointerdown",a=>this._onPointerDown(a),t),s.addEventListener("keydown",a=>this._onKey(a),t);let r=0,i=0;e.search?.addEventListener("input",()=>{clearTimeout(r),r=setTimeout(()=>this.setFilter({query:e.search.value}),le)},t),e.search?.addEventListener("keydown",a=>{a.key==="ArrowDown"&&(a.preventDefault(),this._focusRow(tt(e.list)[0])),a.key==="Escape"&&e.search.value&&(a.preventDefault(),e.search.value="",this.setFilter({query:""}))},t);let o=()=>{clearTimeout(i),i=setTimeout(()=>this.setFilter({bpmMin:e.bpmMin?.value??"",bpmMax:e.bpmMax?.value??""}),ue)};e.bpmMin?.addEventListener("input",o,t),e.bpmMax?.addEventListener("input",o,t),this.menus=new q(s,{signal:this._ctl.signal,onPick:(a,l)=>a==="sort"?this.setSort(l):this.setFilter({[a]:l})}),document.addEventListener("waveformplayer:play",a=>{let l=a.detail?.player;l&&l!==this.engine&&this.playing&&this.pause()},t)}_onClick(t){let e=t.target,s=e.closest("[data-ws-type]");if(s){this.setFilter({type:s.dataset.wsType});return}if(e.closest("[data-ws-more]")){this.showMore();return}if(e.closest("[data-ws-clear]")){this.clearFilters();return}if(e.closest("[data-ws-loop]")){this.setLoop(!this.loop);return}let r=e.closest(".ws-wave");if(r){this._lastPointer==="touch"&&this._seekAt(r,t.clientX);return}let i=e.closest("[data-ws-index]");!i||e.closest(".ws-download")||(this.toggle(Number(i.dataset.wsIndex)),this._focusRowQuietly(i))}_onPointerDown(t){this._lastPointer=t.pointerType;let e=t.target.closest(".ws-wave");!e||t.button!==0||t.pointerType==="touch"||(t.preventDefault(),this._seekAt(e,t.clientX))}_seekAt(t,e){let s=t.closest("[data-ws-index]");this._seekRow(Number(s.dataset.wsIndex),ct(e,t.getBoundingClientRect())),this._focusRowQuietly(s)}_onKey(t){if(t.defaultPrevented||t.altKey||t.ctrlKey||t.metaKey)return;if(t.key==="/"&&!pt(t.target)&&this.$.search){t.preventDefault(),this.$.search.focus();return}let e=t.target.closest?.("[data-ws-index]");if(!e)return;let s=Number(e.dataset.wsIndex),r=yt(this.progress,t.key);if(r!==null){if(s!==this.currentIndex||!this.engine)return;t.preventDefault(),this._seekRow(s,r);return}let i=tt(this.$.list),o=mt(t.key,i.indexOf(e),i.length);if(o!==null){if(t.preventDefault(),o==="search"){this.$.search?.focus();return}this._focusRow(i[o]),this.options.arrowAudition&&this.playing&&this.play(Number(i[o].dataset.wsIndex))}}_focusRow(t){t?.querySelector(".ws-play")?.focus()}_focusRowQuietly(t){let e=t?.querySelector(".ws-play");e&&document.activeElement!==e&&e.focus({preventScroll:!0})}_observe(){if(this.render.player!=="inline"||typeof window>"u")return;if(this._drawn=new Set,"IntersectionObserver"in window?(this._io=new IntersectionObserver(s=>{for(let r of s){if(!r.isIntersecting)continue;let i=Number(r.target.dataset.wsIndex);this._drawn.add(i),this._drawRow(i)}},{rootMargin:"200px 0px"}),this.rows.forEach(s=>s&&this._io.observe(s))):this.rows.forEach((s,r)=>s&&this._drawn.add(r)),"ResizeObserver"in window){let s=0;this._ro=new ResizeObserver(([r])=>{let i=Math.round(r.contentRect.width);i!==s&&(s=i,this._redrawAll())}),this._ro.observe(this.$.list)}let t=()=>requestAnimationFrame(()=>{this._resolveColors(),this._redrawAll()});this._mo=new MutationObserver(t);let e={attributes:!0,attributeFilter:["class","data-theme","data-color-scheme","style"]};this._mo.observe(document.documentElement,e),document.body&&this._mo.observe(document.body,e);try{window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t,{signal:this._ctl.signal})}catch{}}_resolveColors(){(this._autoSurface||!getComputedStyle(this.container).getPropertyValue("--ws-surface").trim())&&(this._autoSurface=!0,this.container.style.removeProperty("--ws-surface"),this.container.style.setProperty("--ws-surface",Lt(this.container))),this.colors={wave:this.options.waveformColor||et(this.container,"var(--ws-wave-color)")||"rgba(128,128,128,.5)",progress:this.options.progressColor||et(this.container,"var(--ws-progress-color)")||"currentColor"}}_drawRow(t){if(this.render.player!=="inline"||t==null||!this._drawn?.has(t))return;let e=this.rows[t],s=e?.querySelector("canvas");if(!s||e.hidden)return;let r=Number(this.options.barGap);ot(s,this.sounds[t].peaks,t===this.currentIndex?this.progress:0,{style:this.options.waveformStyle,color:this.colors?.wave||"rgba(128,128,128,.5)",progressColor:this.colors?.progress||"currentColor",barWidth:Math.max(1,Number(this.options.barWidth)||2),barGap:Number.isFinite(r)?Math.max(0,r):1})}_redrawAll(){this._drawn?.forEach(t=>this._drawRow(t))}_readUrl(){let t=nt(this.options.urlState);if(!t||typeof location>"u")return;let{filter:e,sort:s}=Rt(location.search,t,_(this.sounds),this._sorts);this.filter={...this.filter,...e},s&&(this.sortBy=s,this._sortSet=!0)}_queueUrl(){let t=nt(this.options.urlState);!t||typeof location>"u"||(clearTimeout(this._urlTimer),this._urlTimer=setTimeout(()=>{if(this.destroyed)return;let e=It(location.href,t,this.filter,this.sortBy,this._sorts?.[0]||"default");e!==location.href&&history.replaceState(history.state,"",e)},ce))}get visible(){return E(this.sounds.filter(t=>F(t,this.filter)),this.sortBy)}setFilter(t={}){this.filter={...this.filter,...t},this.limit=this._pageSize(),this._syncControls(),this._apply({resort:!1})}clearFilters(){this.setFilter($t)}setSort(t){this._sortSet=!0,this.sortBy=k.includes(t)?t:"default",this.menus?.setValue("sort",this.sortBy),this._apply({resort:!0})}showMore(){this.limit!==1/0&&(this.limit+=this.render.pageSize,this._apply({resort:!1}))}_pageSize(){return this.render.pageSize>0?this.render.pageSize:1/0}_syncControls(){let t=this.$,e=this.filter;t&&(t.search&&t.search.value!==e.query&&(t.search.value=e.query),this.menus?.setValue("type",e.type||""),this.menus?.setValue("key",e.key||""),this.menus?.setValue("sort",this.sortBy),t.bpmMin&&t.bpmMin.value!==String(e.bpmMin)&&(t.bpmMin.value=e.bpmMin),t.bpmMax&&t.bpmMax.value!==String(e.bpmMax)&&(t.bpmMax.value=e.bpmMax),t.chips.forEach(s=>s.setAttribute("aria-pressed",String(s.dataset.wsType===(e.type||"")))))}_apply({resort:t}){let e=this.$;if(!e)return;(t||this.sortBy!==this._lastSort)&&(Ct(e.list,E(this.sounds,this.sortBy).map(o=>this.rows[this.sounds.indexOf(o)])),this._lastSort=this.sortBy);let s=this.visible,{visible:r,remaining:i}=wt(s,this.limit);this.sounds.forEach((o,a)=>{this.rows[a]&&(this.rows[a].hidden=!r.has(o))}),e.more&&(e.more.hidden=i<=0,e.more.textContent=f(this.strings.showMore,{count:Math.min(i,this.render.pageSize||i)})),e.empty&&(e.empty.hidden=s.length>0),e.count&&(e.count.textContent=B(s.length,this.sounds.length,this.strings)),this._queueUrl(),this._emit("filter",{visible:s.length,total:this.sounds.length,filter:{...this.filter},sort:this.sortBy}),this.options.onFilter?.(s,this)}_indexOf(t){if(t==null)return this.currentIndex??(this.visible[0]?this.sounds.indexOf(this.visible[0]):null);if(typeof t=="number")return this.sounds[t]?t:null;let e=typeof t=="object"?this.sounds.indexOf(t):this.sounds.findIndex(s=>s.id===String(t));return e>=0?e:null}_playerClass(){return this.options.playerClass||(typeof window<"u"?window.WaveformPlayer:null)||null}_ensureEngine(){if(this.engine)return this.engine;let t=this._playerClass();return t?(this.engine=new t(this.$.engine,at(this.options.playerOptions,this.render.player,{onLoad:()=>this._onEngineLoad(),onPlay:()=>this._setPlaying(!0),onPause:()=>this._setPlaying(!1),onEnd:()=>this._onEnd(),onTimeUpdate:(e,s)=>this._onTime(e,s),onError:e=>this._onEngineError(e)})),this.engine):(console.error(`${y} @arraypress/waveform-player is required: load it before playing (or pass playerClass).`),null)}play(t,e={}){if(!this.$){this.ready.then(()=>{this.destroyed||this.play(t,e)});return}let s=this._indexOf(t);if(s==null)return;let r=this._ensureEngine();if(!r)return;if(s===this.currentIndex&&r.audio?.src){e.at!=null&&this._seekRow(s,e.at),this.playing||r.play();return}let i=this.currentIndex;this.currentIndex=s,this.progress=0,this._pendingSeek=e.at??null,i!=null&&this._paintRow(i),this._paintRow(s);let o=this.sounds[s];r.loadTrack(o.url,o.title,o.type||null,{waveform:lt(o,this.render.player),autoplay:!0})}pause(){this.engine&&this.playing&&this.engine.pause()}toggle(t){let e=this._indexOf(t);e!=null&&(e===this.currentIndex&&this.playing?this.pause():this.play(e))}next(){this._step(1)}previous(){this._step(-1)}_step(t){let e=this.visible,s=this.currentIndex==null?-1:e.indexOf(this.sounds[this.currentIndex]),r=e[s+t];if(!r)return!1;let i=gt(this.limit,s+t);return i!==this.limit&&(this.limit=i,this._apply({resort:!1})),this.play(this.sounds.indexOf(r)),!0}setLoop(t){this.loop=!!t,this._setLoop(this.loop)}_setLoop(t){this.$?.loop?.setAttribute("aria-pressed",String(t)),this.engine?.audio&&(this.engine.audio.loop=t)}_seekRow(t,e){if(t!==this.currentIndex||!this.engine){this.play(t,{at:e});return}let s=this.engine.audio?.duration;if(!Number.isFinite(s)||s<=0){this._pendingSeek=e;return}this.engine.seekTo(e*s),this.progress=e,this._paintRow(t),this.playing||this.engine.play()}_onEngineLoad(){this.engine?.audio&&(this.engine.audio.loop=this.loop);let t=this.sounds[this.currentIndex];t&&!t.peaks&&this.engine?.waveformData?.length&&(t.peaks=G(this.engine.waveformData,96),this._drawRow(this.currentIndex));let e=this.engine?.audio?.duration;this._pendingSeek!=null&&Number.isFinite(e)&&e>0&&(this.engine.seekTo(this._pendingSeek*e),this.progress=this._pendingSeek,this._pendingSeek=null)}_onTime(t,e){if(!(this.currentIndex==null||!e)){if(this._pendingSeek!=null){let s=this._pendingSeek;this._pendingSeek=null,this.engine.seekTo(s*e);return}this.progress=Math.min(Math.max(t/e,0),1),!this._raf&&(this._raf=requestAnimationFrame(()=>{this._raf=0,this._drawRow(this.currentIndex),this.rows[this.currentIndex]?.querySelector(".ws-wave")?.setAttribute("aria-valuenow",String(Math.round(this.progress*100)))}))}}_onEnd(){let t=this.sounds[this.currentIndex];this._emit("end",{sound:t,index:this.currentIndex}),this.options.onEnd?.(t,this),!(this.options.autoAdvance&&this._step(1))&&(this.progress=0,this._setPlaying(!1))}_onEngineError(t){this.rows[this.currentIndex]?.classList.add("is-error"),this._emit("error",{error:t,sound:this.sounds[this.currentIndex],index:this.currentIndex}),this.options.onError?.(t,this)}_setPlaying(t){let e=this.playing!==t;this.playing=t;let s=this.currentIndex;if(s==null||(this._paintRow(s),!e))return;let r=this.sounds[s];t&&this.$.status&&(this.$.status.textContent=f(this.strings.nowPlaying,{title:r.title})),this._emit(t?"play":"pause",{sound:r,index:s}),(t?this.options.onPlay:this.options.onPause)?.(r,this)}_paintRow(t){let e=this.rows[t];if(!e)return;let s=t===this.currentIndex,r=s&&this.playing;e.classList.toggle("is-current",s),e.classList.toggle("is-playing",r);let i=e.querySelector(".ws-play");i&&(i.setAttribute("aria-pressed",String(r)),i.setAttribute("aria-label",f(r?this.strings.pause:this.strings.play,{title:this.sounds[t].title})));let o=e.querySelector(".ws-wave");o&&(o.tabIndex=s?0:-1,s||o.setAttribute("aria-valuenow","0")),this._drawRow(t)}_emit(t,e={}){dt(this.container,t,{...e,instance:this})}get current(){return this.currentIndex==null?null:this.sounds[this.currentIndex]}destroy(){if(!this.destroyed){this.destroyed=!0,this._ctl.abort(),this._io?.disconnect(),this._ro?.disconnect(),this._mo?.disconnect(),this._raf&&cancelAnimationFrame(this._raf),clearTimeout(this._urlTimer);try{this.engine?.destroy()}catch{}this.engine=null,this._originalHTML!=null&&(this.container.innerHTML=this._originalHTML),this._addedClasses?.length&&this.container.classList.remove(...this._addedClasses),this._autoSurface&&this.container.style.removeProperty("--ws-surface"),delete this.container.dataset.wsInitialized,n.instances.delete(this.container)}}static init(t=document){if(typeof document>"u")return[];let e=t||document,s=[...e.matches?.("[data-waveform-sounds]")?[e]:[],...e.querySelectorAll("[data-waveform-sounds]")],r=[];for(let i of s)if(!(i.dataset.wsInitialized==="true"||n.instances.has(i)))try{r.push(new n(i))}catch(o){console.error(`${y} Failed to initialise:`,o,i)}return r}static getInstance(t){let e=typeof t=="string"?document.querySelector(t):t;return e&&n.instances.get(e)||null}static prune(){for(let[t,e]of n.instances)t.isConnected||e.destroy()}};b.utils={encodePeaks:N,decodePeaks:H,normalizeKey:T,normalizeSounds:S,parseManifest:D,facets:_,matches:F,sortSounds:E,formatDuration:O,renderSounds:R};b.DEFAULT_OPTIONS=U;b.DEFAULT_STRINGS=w;typeof window<"u"&&(window.WaveformSounds=b);var K=b;var cn=K;typeof document<"u"&&document.documentElement?.dataset?.waveformAutoinit!=="false"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>K.init(),{once:!0}):K.init());})();
2
2
  /**
3
3
  * @arraypress/waveform-sounds
4
4
  * A searchable, filterable list of sounds for WaveformPlayer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/waveform-sounds",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Searchable, filterable sound list for WaveformPlayer: audition hundreds of sample previews with inline waveforms, keyboard navigation and one shared audio engine.",
5
5
  "type": "module",
6
6
  "main": "dist/waveform-sounds.cjs",
@@ -47,7 +47,42 @@ export function resample(peaks, count) {
47
47
  }
48
48
 
49
49
  /**
50
- * Draw a row waveform.
50
+ * The rectangles of a row waveform, in CSS pixels. Pure: the geometry is
51
+ * separate from the canvas so it can be tested (and reused for both
52
+ * passes of {@link drawRowWaveform}).
53
+ *
54
+ * Bars are normalised to the loudest one, so a quiet one-shot isn't a
55
+ * flat line, and never shorter than 4% of the height.
56
+ *
57
+ * @param {number[]} peaks - 0..1.
58
+ * @param {number} width - Canvas width (CSS px).
59
+ * @param {number} height - Canvas height (CSS px).
60
+ * @param {{style: 'mirror'|'bars', barWidth: number, barGap: number}} o
61
+ * @returns {{x: number, y: number, w: number, h: number}[]}
62
+ */
63
+ export function barRects(peaks, width, height, o) {
64
+ const step = o.barWidth + o.barGap;
65
+ const bars = resample(peaks, Math.max(1, Math.floor((width + o.barGap) / step)));
66
+ const max = bars.reduce((m, b) => (b > m ? b : m), 0);
67
+ const scale = max > 0 ? 1 / max : 1;
68
+ return bars.map((b, i) => {
69
+ const v = Math.max(b * scale, 0.04);
70
+ if (o.style === 'bars') {
71
+ const h = Math.max(1, v * height);
72
+ return {x: i * step, y: height - h, w: o.barWidth, h};
73
+ }
74
+ const h = Math.max(1, v * (height - 2));
75
+ return {x: i * step, y: height / 2 - h / 2, w: o.barWidth, h};
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Draw a row waveform: every bar in the waveform colour, then the same
81
+ * bars again in the progress colour, CLIPPED at the playhead. The played
82
+ * part grows by the pixel — through the middle of a bar — rather than a
83
+ * whole bar at a time, which on a short clip stepped visibly (an 8-second
84
+ * loop across ~120 bars moved in ~15 jumps a second however fast it was
85
+ * redrawn).
51
86
  *
52
87
  * @param {HTMLCanvasElement} canvas
53
88
  * @param {number[]|null} peaks - 0..1. Null draws a flat placeholder line.
@@ -68,26 +103,19 @@ export function drawRowWaveform(canvas, peaks, progress, o) {
68
103
  return;
69
104
  }
70
105
 
71
- const step = o.barWidth + o.barGap;
72
- const count = Math.max(1, Math.floor((width + o.barGap) / step));
73
- const bars = resample(peaks, count);
74
- // Normalise to the loudest bar so quiet one-shots aren't a flat line.
75
- let max = 0;
76
- for (const b of bars) if (b > max) max = b;
77
- const scale = max > 0 ? 1 / max : 1;
78
- const split = progress * width;
79
- const mid = height / 2;
106
+ const path = new Path2D();
107
+ for (const r of barRects(peaks, width, height, o)) path.rect(r.x, r.y, r.w, r.h);
80
108
 
81
- for (let i = 0; i < bars.length; i++) {
82
- const x = i * step;
83
- const v = Math.max(bars[i] * scale, 0.04);
84
- ctx.fillStyle = x + o.barWidth / 2 <= split ? o.progressColor : o.color;
85
- if (o.style === 'bars') {
86
- const h = Math.max(1, v * height);
87
- ctx.fillRect(x, height - h, o.barWidth, h);
88
- } else {
89
- const h = Math.max(1, v * (height - 2));
90
- ctx.fillRect(x, mid - h / 2, o.barWidth, h);
91
- }
109
+ ctx.fillStyle = o.color;
110
+ ctx.fill(path);
111
+ const split = Math.min(Math.max(progress, 0), 1) * width;
112
+ if (split > 0) {
113
+ ctx.save();
114
+ ctx.beginPath();
115
+ ctx.rect(0, 0, split, height);
116
+ ctx.clip();
117
+ ctx.fillStyle = o.progressColor;
118
+ ctx.fill(path);
119
+ ctx.restore();
92
120
  }
93
121
  }