@arraypress/waveform-sounds 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +21 -1
  2. package/dist/waveform-sounds-no-autoinit.esm.js +445 -144
  3. package/dist/waveform-sounds-render.esm.js +220 -78
  4. package/dist/waveform-sounds.css +4 -0
  5. package/dist/waveform-sounds.esm.js +445 -144
  6. package/dist/waveform-sounds.js +445 -144
  7. package/dist/waveform-sounds.min.css +1 -1
  8. package/dist/waveform-sounds.min.js +1 -1
  9. package/package.json +1 -1
  10. package/src/css/waveform-sounds.css +4 -0
  11. package/src/js/core/WaveformSounds.ts +224 -67
  12. package/src/js/core/element.ts +1 -1
  13. package/src/js/core/options.ts +1 -0
  14. package/src/js/data/keys.ts +156 -0
  15. package/src/js/data/navigation.ts +35 -8
  16. package/src/js/data/sounds.ts +29 -22
  17. package/src/js/data/url-state.ts +7 -3
  18. package/src/js/dom/draw.ts +16 -2
  19. package/src/js/dom/menus.ts +2 -1
  20. package/src/js/dom/rows.ts +38 -12
  21. package/src/js/render/icons.ts +59 -16
  22. package/src/js/render/markup.ts +115 -49
  23. package/src/js/render/options.ts +3 -1
  24. package/src/js/render/strings.ts +53 -1
  25. package/src/js/types.ts +24 -0
  26. package/types/core/WaveformSounds.d.ts +3 -3
  27. package/types/core/WaveformSounds.d.ts.map +1 -1
  28. package/types/core/options.d.ts.map +1 -1
  29. package/types/data/keys.d.ts +88 -0
  30. package/types/data/keys.d.ts.map +1 -0
  31. package/types/data/navigation.d.ts +27 -9
  32. package/types/data/navigation.d.ts.map +1 -1
  33. package/types/data/sounds.d.ts +20 -5
  34. package/types/data/sounds.d.ts.map +1 -1
  35. package/types/data/url-state.d.ts +6 -1
  36. package/types/data/url-state.d.ts.map +1 -1
  37. package/types/dom/draw.d.ts +5 -2
  38. package/types/dom/draw.d.ts.map +1 -1
  39. package/types/dom/menus.d.ts.map +1 -1
  40. package/types/dom/rows.d.ts +19 -8
  41. package/types/dom/rows.d.ts.map +1 -1
  42. package/types/render/icons.d.ts +41 -3
  43. package/types/render/icons.d.ts.map +1 -1
  44. package/types/render/markup.d.ts +27 -4
  45. package/types/render/markup.d.ts.map +1 -1
  46. package/types/render/options.d.ts +1 -1
  47. package/types/render/options.d.ts.map +1 -1
  48. package/types/render/strings.d.ts +22 -1
  49. package/types/render/strings.d.ts.map +1 -1
  50. package/types/types.d.ts +24 -0
  51. package/types/types.d.ts.map +1 -1
@@ -1 +1 @@
1
- waveform-sounds{display:block}waveform-sounds:not(:defined):empty{min-height:var(--ws-element-height, 0)}:is(.waveform-sounds,waveform-sounds){--ws-accent: currentColor;--ws-on-accent: var(--ws-surface, rgb(from currentColor calc(255 - r) calc(255 - g) calc(255 - b) ));--ws-muted: color-mix(in srgb, currentColor 62%, transparent);--ws-border: color-mix(in srgb, currentColor 12%, transparent);--ws-hover: color-mix(in srgb, currentColor 5%, transparent);--ws-current: color-mix(in srgb, var(--ws-accent) 7%, transparent);--ws-field: color-mix(in srgb, currentColor 5%, transparent);--ws-wave-color: color-mix(in srgb, currentColor 30%, transparent);--ws-progress-color: var(--ws-accent);--ws-radius: 10px;--ws-control-radius: 999px;--ws-row-height: 3.25rem;--ws-wave-height: 28px;--ws-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;container-type:inline-size;color:inherit;font:inherit}@supports (not (color: rgb(from currentColor r g b))) or ((-moz-appearance: none) and (not (letter-spacing: 1%))){:is(.waveform-sounds,waveform-sounds){--ws-on-accent: var(--ws-surface, Canvas)}:is(.waveform-sounds,waveform-sounds):where(:not([data-ws-initialized])){--ws-accent-fill: color-mix(in srgb, currentColor 22%, transparent);--ws-on-accent: currentColor}}:is(.waveform-sounds,waveform-sounds) *,:is(.waveform-sounds,waveform-sounds) *:before,:is(.waveform-sounds,waveform-sounds) *:after{box-sizing:border-box}:is(.waveform-sounds,waveform-sounds) [hidden]{display:none!important}.ws-sr{position:absolute!important;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}.ws-icon{width:1em;height:1em;fill:currentColor;flex:none}.ws-search,.ws-menu-btn,.ws-seg,.ws-loop,.ws-chip,.ws-clear,.ws-more{border:1px solid var(--ws-border);border-radius:var(--ws-control-radius)}.ws-menu-btn,.ws-bpm-clear,.ws-seg-btn,.ws-loop,.ws-chip,.ws-clear,.ws-more{background:none;color:inherit;font:inherit;cursor:pointer}.ws-toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;margin-bottom:1rem}.ws-search{flex:1 1 16rem;display:flex;align-items:center;gap:.6rem;min-width:0;height:2.75rem;padding:0 1rem;background:var(--ws-field);color:inherit;cursor:text}.ws-search:focus-within{border-color:var(--ws-accent);outline:2px solid var(--ws-accent);outline-offset:2px}.ws-search-input{flex:1;min-width:0;height:100%;border:0;background:none;color:inherit;font:inherit}.ws-search-input:focus{outline:none}.ws-search .ws-icon,.ws-search-input::placeholder{color:var(--ws-muted)}.ws-search-input::-webkit-search-cancel-button,.ws-menu-search::-webkit-search-cancel-button{appearance:none;width:.9em;height:.9em;background:currentColor;opacity:.55;cursor:pointer;-webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.4 5 5 6.4 10.6 12 5 17.6 6.4 19l5.6-5.6 5.6 5.6 1.4-1.4-5.6-5.6L19 6.4 17.6 5 12 10.6z'/%3E%3C/svg%3E") center / contain no-repeat}.ws-controls{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem}.ws-menu{position:relative}.ws-menu-btn{display:inline-flex;align-items:center;gap:.45rem;height:2.75rem;max-width:16rem;padding:0 .85rem 0 1rem;background:var(--ws-field);font-size:.9em}.ws-menu-btn:hover{background:var(--ws-hover)}.ws-menu-btn[aria-expanded=true]{border-color:var(--ws-accent)}.ws-menu-prefix{color:var(--ws-muted)}.ws-menu-value,.ws-menu-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ws-menu-chevron{font-size:1.1em;color:var(--ws-muted);transition:transform .15s}.ws-menu-btn[aria-expanded=true] .ws-menu-chevron{transform:rotate(180deg)}.ws-menu-pop{position:absolute;top:calc(100% + .4rem);left:0;z-index:20;width:max-content;min-width:max(100%,14rem);max-width:min(22rem,90vw);padding:.35rem;border:1px solid var(--ws-border);border-radius:var(--ws-radius);background:var(--ws-popover-bg, var(--ws-surface, Canvas));box-shadow:0 18px 40px -16px #00000073}.ws-menu--end .ws-menu-pop{left:auto;right:0}.ws-menu-search{display:block;width:100%;height:2.4rem;margin-bottom:.3rem;padding:0 .75rem;border:1px solid var(--ws-border);border-radius:calc(var(--ws-radius) * .7);background:var(--ws-field);color:inherit;font:inherit;font-size:.9em}.ws-menu-search:focus{border-color:var(--ws-accent)}.ws-menu-search:focus-visible{outline:2px solid var(--ws-accent);outline-offset:1px}.ws-menu-list{list-style:none;margin:0;padding:0;max-height:18rem;overflow-y:auto;outline:none}.ws-menu-option{display:flex;align-items:center;gap:.5rem;padding:.5rem .6rem;border-radius:calc(var(--ws-radius) * .6);font-size:.9em;cursor:pointer}.ws-menu-option:hover,.ws-menu-option.is-active{background:var(--ws-hover)}.ws-menu-option.is-active{outline:1px solid var(--ws-border)}.ws-menu-check{visibility:hidden;flex:none}.ws-menu-option[aria-selected=true]{font-weight:600}.ws-menu-option[aria-selected=true] .ws-menu-check{visibility:visible}.ws-menu-text{flex:1;min-width:0}.ws-menu-count{font-family:var(--ws-mono);font-size:.85em;color:var(--ws-muted)}.ws-menu-none{margin:0;padding:.6rem;color:var(--ws-muted);font-size:.9em}.ws-bpm-pop{width:17rem;padding:.85rem 1rem .7rem}.ws-bpm-head{display:flex;align-items:baseline;justify-content:space-between;gap:.75rem;margin-bottom:.6rem}.ws-bpm-readout{font-weight:600;font-variant-numeric:tabular-nums}.ws-bpm-clear{display:inline-flex;align-items:center;justify-content:center;min-width:24px;min-height:24px;margin:-2px -.3rem -2px 0;padding:0 .3rem;border:0;border-radius:4px;color:var(--ws-muted);font-size:.85em}.ws-bpm-clear:focus-visible{outline:2px solid var(--ws-accent);outline-offset:0}.ws-bpm-clear:hover{color:inherit;text-decoration:underline}.ws-range{--ws-thumb: 18px;--ws-lo: 0;--ws-hi: 1;position:relative;height:1.75rem}.ws-range:before,.ws-range:after{content:"";position:absolute;top:50%;height:4px;border-radius:2px;transform:translateY(-50%)}.ws-range:before{left:0;right:0;background:var(--ws-border)}.ws-range:after{left:calc(var(--ws-thumb) / 2 + var(--ws-lo) * (100% - var(--ws-thumb)));right:calc(var(--ws-thumb) / 2 + (1 - var(--ws-hi)) * (100% - var(--ws-thumb)));background:var(--ws-accent);opacity:.35}.ws-range.is-active:after{opacity:1}.ws-range-input{position:absolute;inset:0;z-index:1;width:100%;height:100%;margin:0;background:none;pointer-events:none;appearance:none}.ws-range.is-min-top [data-ws-bpm-min]{z-index:2}.ws-range-input::-webkit-slider-runnable-track{height:100%;background:none}.ws-range-input::-moz-range-track{background:none}.ws-range-input::-webkit-slider-thumb{width:var(--ws-thumb);height:var(--ws-thumb);margin-top:calc((1.75rem - var(--ws-thumb)) / 2);border:2px solid var(--ws-surface, Canvas);border-radius:50%;background:var(--ws-accent);box-shadow:0 0 0 1px var(--ws-border);cursor:grab;pointer-events:auto;appearance:none}.ws-range-input::-moz-range-thumb{width:var(--ws-thumb);height:var(--ws-thumb);box-sizing:border-box;border:2px solid var(--ws-surface, Canvas);border-radius:50%;background:var(--ws-accent);box-shadow:0 0 0 1px var(--ws-border);cursor:grab;pointer-events:auto}.ws-range-input:active::-webkit-slider-thumb{cursor:grabbing}.ws-range-input:focus-visible{outline:none}.ws-range-input:focus-visible::-webkit-slider-thumb{box-shadow:0 0 0 3px var(--ws-accent)}.ws-range-input:focus-visible::-moz-range-thumb{box-shadow:0 0 0 3px var(--ws-accent)}.ws-range-ends{display:flex;justify-content:space-between;margin-top:.15rem;color:var(--ws-muted);font-family:var(--ws-mono);font-size:.75em;font-variant-numeric:tabular-nums}.ws-seg{display:inline-flex;height:2.75rem;padding:.25rem;gap:.15rem}.ws-seg-btn{padding:0 .85rem;border:0;border-radius:var(--ws-control-radius);font-size:.88em;white-space:nowrap;transition:background .15s}.ws-seg-btn:hover{background:var(--ws-hover)}.ws-loop{display:inline-flex;align-items:center;gap:.45rem;height:2.75rem;padding:0 1rem;font-size:.9em}.ws-meta{flex-basis:100%;display:flex;flex-wrap:wrap;align-items:center;gap:.5rem 1rem}.ws-types{display:flex;flex-wrap:wrap;gap:.4rem;flex:1 1 auto;min-width:0}.ws-chip{display:inline-flex;align-items:center;gap:.4rem;height:2.25rem;padding:0 .9rem;font-size:.88em;transition:border-color .15s,background .15s}.ws-chip:hover{background:var(--ws-hover)}.ws-chip-count{font-family:var(--ws-mono);font-size:.85em;opacity:.7}.ws-count{margin:0 0 0 auto;color:var(--ws-muted);font-size:.88em;font-variant-numeric:tabular-nums}.ws-loop[aria-pressed=true],.ws-chip[aria-pressed=true]{border-color:var(--ws-accent);background:var(--ws-accent-fill, var(--ws-accent))}.ws-seg-btn[aria-pressed=true]{background:var(--ws-accent-fill, var(--ws-accent))}.ws-loop[aria-pressed=true]>*,.ws-seg-btn[aria-pressed=true]>*,.ws-chip[aria-pressed=true]>*{color:var(--ws-on-accent)}.ws-chip[aria-pressed=true] .ws-chip-count{opacity:1}.ws-list{list-style:none;margin:0;padding:0;border-top:1px solid var(--ws-border)}.ws-row{display:flex;align-items:center;gap:1rem;min-height:var(--ws-row-height);padding:.4rem .75rem .4rem .4rem;border-bottom:1px solid var(--ws-border);cursor:pointer;transition:background .12s}.ws-row:hover{background:var(--ws-hover)}.ws-row.is-current{background:var(--ws-current)}.ws-row.is-error .ws-title{text-decoration:line-through;opacity:.6}.ws-play,.ws-download{flex:none;display:grid;place-items:center;width:2.25rem;height:2.25rem;border-radius:999px}.ws-play{border:0;background:var(--ws-field);color:inherit;font-size:.95rem;cursor:pointer;transition:background .15s,color .15s}.ws-row:hover .ws-play{background:color-mix(in srgb,currentColor 12%,transparent)}.ws-row.is-current .ws-play{background:var(--ws-accent-fill, var(--ws-accent))}.ws-row.is-current .ws-play>*{color:var(--ws-on-accent)}.ws-play .ws-icon-pause,.ws-row.is-playing .ws-play .ws-icon-play{display:none}.ws-row.is-playing .ws-play .ws-icon-pause{display:block}.ws-play:focus-visible,.ws-chip:focus-visible,.ws-menu-btn:focus-visible,.ws-loop:focus-visible,.ws-seg-btn:focus-visible,.ws-more:focus-visible,.ws-clear:focus-visible,.ws-wave:focus-visible,.ws-download:focus-visible{outline:2px solid var(--ws-accent);outline-offset:2px}.ws-cell{min-width:0;font-size:.9em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ws-title{flex:1.4 1 9rem;display:flex;align-items:center;gap:.4rem;font-weight:500}.ws-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis}.ws-loop-mark{flex:none;display:inline-flex;color:var(--ws-muted)}.ws-loop-mark .ws-icon{width:.95em;height:.95em}.ws-type{flex:1 1 6rem;color:var(--ws-muted)}.ws-bpm,.ws-key,.ws-duration{flex:none;font-family:var(--ws-mono);font-size:.82em;color:var(--ws-muted);font-variant-numeric:tabular-nums}.ws-bpm{width:3.25ch;text-align:right}.ws-key{width:3.5ch}.ws-duration{width:4.5ch;text-align:right}.ws-wave{flex:2 1 8rem;position:relative;height:var(--ws-wave-height);min-width:6rem;cursor:pointer;touch-action:pan-y;border-radius:4px}.ws-canvas{display:block;width:100%;height:100%}.ws-download{color:var(--ws-muted);font-size:1.05rem;text-decoration:none;transition:color .15s,background .15s}.ws-download:hover{color:inherit;background:var(--ws-hover)}.ws-cells{display:contents}@container (max-width: 560px){.ws-row{display:grid;grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"play title dl" "play cells cells" "play wave wave";column-gap:.85rem;row-gap:.2rem;padding:.7rem .5rem}.ws-play{grid-area:play;align-self:center}.ws-title{grid-area:title;white-space:normal;overflow-wrap:anywhere}.ws-title-text{overflow:visible}.ws-cells{grid-area:cells;display:flex;flex-wrap:wrap;align-items:baseline;gap:0 .5rem;min-width:0}.ws-cells>.ws-cell{flex:none;width:auto;text-align:left;font-size:.78em}.ws-cells>.ws-cell:empty{display:none}.ws-cells>.ws-cell:not(:empty)~.ws-cell:not(:empty):before{content:"\b7";margin-right:.5rem;opacity:.6}.ws-wave{grid-area:wave;margin-top:.35rem;min-width:0}.ws-download{grid-area:dl;align-self:start}.ws-controls{position:relative}.ws-menu{position:static}.ws-menu-pop{min-width:min(14rem,100%);max-width:100%}.ws-bpm-pop{width:min(17rem,100%)}}.ws-empty{margin:1.5rem 0;color:var(--ws-muted)}.ws-clear{margin-left:.5rem;padding:.35rem .85rem;font-size:.88em}.ws-more{display:block;margin:1.25rem auto 0;padding:.7rem 1.4rem;font-size:.92em}.ws-more:hover,.ws-clear:hover{background:var(--ws-hover)}.ws-engine--strip{position:var(--ws-strip-position, static);bottom:0;margin-top:1rem;padding:.75rem;border:1px solid var(--ws-border);border-radius:var(--ws-radius);background:var(--ws-strip-bg, var(--ws-surface, Canvas));z-index:1}@media(pointer:coarse){.ws-play,.ws-download{width:2.75rem;height:2.75rem}.ws-chip{height:2.5rem}.ws-search-input,.ws-menu-search{font-size:16px}.ws-range{--ws-thumb: 24px;height:2.25rem}.ws-range-input::-webkit-slider-thumb{margin-top:calc((2.25rem - var(--ws-thumb)) / 2)}.ws-menu-option{padding:.75rem .6rem}}@media(forced-colors:active){.ws-loop[aria-pressed=true],.ws-chip[aria-pressed=true],.ws-seg-btn[aria-pressed=true],.ws-row.is-current .ws-play{forced-color-adjust:none;border-color:Highlight;background:Highlight;color:HighlightText}.ws-loop[aria-pressed=true]>*,.ws-seg-btn[aria-pressed=true]>*,.ws-chip[aria-pressed=true]>*,.ws-row.is-current .ws-play>*{color:HighlightText}.ws-range:before,.ws-range:after{forced-color-adjust:none}.ws-range:before{background:GrayText}.ws-range:after{background:Highlight}.ws-range-input:focus-visible{outline:2px solid Highlight;outline-offset:2px}.ws-menu-option.is-active{outline:2px solid Highlight}}@media(prefers-reduced-motion:reduce){.ws-row,.ws-chip,.ws-play,.ws-seg-btn,.ws-download,.ws-menu-chevron{transition:none}}
1
+ waveform-sounds{display:block}waveform-sounds:not(:defined):empty{min-height:var(--ws-element-height, 0)}:is(.waveform-sounds,waveform-sounds){--ws-accent: currentColor;--ws-on-accent: var(--ws-surface, rgb(from currentColor calc(255 - r) calc(255 - g) calc(255 - b) ));--ws-muted: color-mix(in srgb, currentColor 62%, transparent);--ws-border: color-mix(in srgb, currentColor 12%, transparent);--ws-hover: color-mix(in srgb, currentColor 5%, transparent);--ws-current: color-mix(in srgb, var(--ws-accent) 7%, transparent);--ws-field: color-mix(in srgb, currentColor 5%, transparent);--ws-wave-color: color-mix(in srgb, currentColor 30%, transparent);--ws-progress-color: var(--ws-accent);--ws-radius: 10px;--ws-control-radius: 999px;--ws-row-height: 3.25rem;--ws-wave-height: 28px;--ws-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;container-type:inline-size;color:inherit;font:inherit}@supports (not (color: rgb(from currentColor r g b))) or ((-moz-appearance: none) and (not (letter-spacing: 1%))){:is(.waveform-sounds,waveform-sounds){--ws-on-accent: var(--ws-surface, Canvas)}:is(.waveform-sounds,waveform-sounds):where(:not([data-ws-initialized])){--ws-accent-fill: color-mix(in srgb, currentColor 22%, transparent);--ws-on-accent: currentColor}}:is(.waveform-sounds,waveform-sounds) *,:is(.waveform-sounds,waveform-sounds) *:before,:is(.waveform-sounds,waveform-sounds) *:after{box-sizing:border-box}:is(.waveform-sounds,waveform-sounds) [hidden]{display:none!important}.ws-sr{position:absolute!important;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}.ws-icon{width:1em;height:1em;fill:currentColor;flex:none}.ws-sprite{position:absolute;width:0;height:0;overflow:hidden}.ws-search,.ws-menu-btn,.ws-seg,.ws-loop,.ws-chip,.ws-clear,.ws-more{border:1px solid var(--ws-border);border-radius:var(--ws-control-radius)}.ws-menu-btn,.ws-bpm-clear,.ws-seg-btn,.ws-loop,.ws-chip,.ws-clear,.ws-more{background:none;color:inherit;font:inherit;cursor:pointer}.ws-toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;margin-bottom:1rem}.ws-search{flex:1 1 16rem;display:flex;align-items:center;gap:.6rem;min-width:0;height:2.75rem;padding:0 1rem;background:var(--ws-field);color:inherit;cursor:text}.ws-search:focus-within{border-color:var(--ws-accent);outline:2px solid var(--ws-accent);outline-offset:2px}.ws-search-input{flex:1;min-width:0;height:100%;border:0;background:none;color:inherit;font:inherit}.ws-search-input:focus{outline:none}.ws-search .ws-icon,.ws-search-input::placeholder{color:var(--ws-muted)}.ws-search-input::-webkit-search-cancel-button,.ws-menu-search::-webkit-search-cancel-button{appearance:none;width:.9em;height:.9em;background:currentColor;opacity:.55;cursor:pointer;-webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.4 5 5 6.4 10.6 12 5 17.6 6.4 19l5.6-5.6 5.6 5.6 1.4-1.4-5.6-5.6L19 6.4 17.6 5 12 10.6z'/%3E%3C/svg%3E") center / contain no-repeat}.ws-controls{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem}.ws-menu{position:relative}.ws-menu-btn{display:inline-flex;align-items:center;gap:.45rem;height:2.75rem;max-width:16rem;padding:0 .85rem 0 1rem;background:var(--ws-field);font-size:.9em}.ws-menu-btn:hover{background:var(--ws-hover)}.ws-menu-btn[aria-expanded=true]{border-color:var(--ws-accent)}.ws-menu-prefix{color:var(--ws-muted)}.ws-menu-value,.ws-menu-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ws-menu-chevron{font-size:1.1em;color:var(--ws-muted);transition:transform .15s}.ws-menu-btn[aria-expanded=true] .ws-menu-chevron{transform:rotate(180deg)}.ws-menu-pop{position:absolute;top:calc(100% + .4rem);left:0;z-index:20;width:max-content;min-width:max(100%,14rem);max-width:min(22rem,90vw);padding:.35rem;border:1px solid var(--ws-border);border-radius:var(--ws-radius);background:var(--ws-popover-bg, var(--ws-surface, Canvas));box-shadow:0 18px 40px -16px #00000073}.ws-menu--end .ws-menu-pop{left:auto;right:0}.ws-menu-search{display:block;width:100%;height:2.4rem;margin-bottom:.3rem;padding:0 .75rem;border:1px solid var(--ws-border);border-radius:calc(var(--ws-radius) * .7);background:var(--ws-field);color:inherit;font:inherit;font-size:.9em}.ws-menu-search:focus{border-color:var(--ws-accent)}.ws-menu-search:focus-visible{outline:2px solid var(--ws-accent);outline-offset:1px}.ws-menu-list{list-style:none;margin:0;padding:0;max-height:18rem;overflow-y:auto;outline:none}.ws-menu-option{display:flex;align-items:center;gap:.5rem;padding:.5rem .6rem;border-radius:calc(var(--ws-radius) * .6);font-size:.9em;cursor:pointer}.ws-menu-option:hover,.ws-menu-option.is-active{background:var(--ws-hover)}.ws-menu-option.is-active{outline:1px solid var(--ws-border)}.ws-menu-check{visibility:hidden;flex:none}.ws-menu-option[aria-selected=true]{font-weight:600}.ws-menu-option[aria-selected=true] .ws-menu-check{visibility:visible}.ws-menu-text{flex:1;min-width:0}.ws-menu-count{font-family:var(--ws-mono);font-size:.85em;color:var(--ws-muted)}.ws-menu-none{margin:0;padding:.6rem;color:var(--ws-muted);font-size:.9em}.ws-bpm-pop{width:17rem;padding:.85rem 1rem .7rem}.ws-bpm-head{display:flex;align-items:baseline;justify-content:space-between;gap:.75rem;margin-bottom:.6rem}.ws-bpm-readout{font-weight:600;font-variant-numeric:tabular-nums}.ws-bpm-clear{display:inline-flex;align-items:center;justify-content:center;min-width:24px;min-height:24px;margin:-2px -.3rem -2px 0;padding:0 .3rem;border:0;border-radius:4px;color:var(--ws-muted);font-size:.85em}.ws-bpm-clear:focus-visible{outline:2px solid var(--ws-accent);outline-offset:0}.ws-bpm-clear:hover{color:inherit;text-decoration:underline}.ws-range{--ws-thumb: 18px;--ws-lo: 0;--ws-hi: 1;position:relative;height:1.75rem}.ws-range:before,.ws-range:after{content:"";position:absolute;top:50%;height:4px;border-radius:2px;transform:translateY(-50%)}.ws-range:before{left:0;right:0;background:var(--ws-border)}.ws-range:after{left:calc(var(--ws-thumb) / 2 + var(--ws-lo) * (100% - var(--ws-thumb)));right:calc(var(--ws-thumb) / 2 + (1 - var(--ws-hi)) * (100% - var(--ws-thumb)));background:var(--ws-accent);opacity:.35}.ws-range.is-active:after{opacity:1}.ws-range-input{position:absolute;inset:0;z-index:1;width:100%;height:100%;margin:0;background:none;pointer-events:none;appearance:none}.ws-range.is-min-top [data-ws-bpm-min]{z-index:2}.ws-range-input::-webkit-slider-runnable-track{height:100%;background:none}.ws-range-input::-moz-range-track{background:none}.ws-range-input::-webkit-slider-thumb{width:var(--ws-thumb);height:var(--ws-thumb);margin-top:calc((1.75rem - var(--ws-thumb)) / 2);border:2px solid var(--ws-surface, Canvas);border-radius:50%;background:var(--ws-accent);box-shadow:0 0 0 1px var(--ws-border);cursor:grab;pointer-events:auto;appearance:none}.ws-range-input::-moz-range-thumb{width:var(--ws-thumb);height:var(--ws-thumb);box-sizing:border-box;border:2px solid var(--ws-surface, Canvas);border-radius:50%;background:var(--ws-accent);box-shadow:0 0 0 1px var(--ws-border);cursor:grab;pointer-events:auto}.ws-range-input:active::-webkit-slider-thumb{cursor:grabbing}.ws-range-input:focus-visible{outline:none}.ws-range-input:focus-visible::-webkit-slider-thumb{box-shadow:0 0 0 3px var(--ws-accent)}.ws-range-input:focus-visible::-moz-range-thumb{box-shadow:0 0 0 3px var(--ws-accent)}.ws-range-ends{display:flex;justify-content:space-between;margin-top:.15rem;color:var(--ws-muted);font-family:var(--ws-mono);font-size:.75em;font-variant-numeric:tabular-nums}.ws-seg{display:inline-flex;height:2.75rem;padding:.25rem;gap:.15rem}.ws-seg-btn{padding:0 .85rem;border:0;border-radius:var(--ws-control-radius);font-size:.88em;white-space:nowrap;transition:background .15s}.ws-seg-btn:hover{background:var(--ws-hover)}.ws-loop{display:inline-flex;align-items:center;gap:.45rem;height:2.75rem;padding:0 1rem;font-size:.9em}.ws-meta{flex-basis:100%;display:flex;flex-wrap:wrap;align-items:center;gap:.5rem 1rem}.ws-types{display:flex;flex-wrap:wrap;gap:.4rem;flex:1 1 auto;min-width:0}.ws-chip{display:inline-flex;align-items:center;gap:.4rem;height:2.25rem;padding:0 .9rem;font-size:.88em;transition:border-color .15s,background .15s}.ws-chip:hover{background:var(--ws-hover)}.ws-chip-count{font-family:var(--ws-mono);font-size:.85em;opacity:.7}.ws-count{margin:0 0 0 auto;color:var(--ws-muted);font-size:.88em;font-variant-numeric:tabular-nums}.ws-loop[aria-pressed=true],.ws-chip[aria-pressed=true]{border-color:var(--ws-accent);background:var(--ws-accent-fill, var(--ws-accent))}.ws-seg-btn[aria-pressed=true]{background:var(--ws-accent-fill, var(--ws-accent))}.ws-loop[aria-pressed=true]>*,.ws-seg-btn[aria-pressed=true]>*,.ws-chip[aria-pressed=true]>*{color:var(--ws-on-accent)}.ws-chip[aria-pressed=true] .ws-chip-count{opacity:1}.ws-list{list-style:none;margin:0;padding:0;border-top:1px solid var(--ws-border)}.ws-row{display:flex;align-items:center;gap:1rem;min-height:var(--ws-row-height);padding:.4rem .75rem .4rem .4rem;border-bottom:1px solid var(--ws-border);cursor:pointer;transition:background .12s}.ws-row:hover{background:var(--ws-hover)}.ws-row.is-current{background:var(--ws-current)}.ws-row.is-error .ws-title{text-decoration:line-through;opacity:.6}.ws-play,.ws-download{flex:none;display:grid;place-items:center;width:2.25rem;height:2.25rem;border-radius:999px}.ws-play{border:0;background:var(--ws-field);color:inherit;font-size:.95rem;cursor:pointer;transition:background .15s,color .15s}.ws-row:hover .ws-play{background:color-mix(in srgb,currentColor 12%,transparent)}.ws-row.is-current .ws-play{background:var(--ws-accent-fill, var(--ws-accent))}.ws-row.is-current .ws-play>*{color:var(--ws-on-accent)}.ws-play .ws-icon-pause,.ws-row.is-playing .ws-play .ws-icon-play{display:none}.ws-row.is-playing .ws-play .ws-icon-pause{display:block}.ws-play:focus-visible,.ws-chip:focus-visible,.ws-menu-btn:focus-visible,.ws-loop:focus-visible,.ws-seg-btn:focus-visible,.ws-more:focus-visible,.ws-clear:focus-visible,.ws-wave:focus-visible,.ws-download:focus-visible{outline:2px solid var(--ws-accent);outline-offset:2px}.ws-cell{min-width:0;font-size:.9em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ws-title{flex:1.4 1 9rem;display:flex;align-items:center;gap:.4rem;font-weight:500}.ws-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis}.ws-loop-mark{flex:none;display:inline-flex;color:var(--ws-muted)}.ws-loop-mark .ws-icon{width:.95em;height:.95em}.ws-type{flex:1 1 6rem;color:var(--ws-muted)}.ws-bpm,.ws-key,.ws-duration{flex:none;font-family:var(--ws-mono);font-size:.82em;color:var(--ws-muted);font-variant-numeric:tabular-nums}.ws-bpm{width:3.25ch;text-align:right}.ws-key{width:3.5ch}.ws-duration{width:4.5ch;text-align:right}.ws-wave{flex:2 1 8rem;position:relative;height:var(--ws-wave-height);min-width:6rem;cursor:pointer;touch-action:pan-y;border-radius:4px}.ws-canvas{display:block;width:100%;height:100%}.ws-download{color:var(--ws-muted);font-size:1.05rem;text-decoration:none;transition:color .15s,background .15s}.ws-download:hover{color:inherit;background:var(--ws-hover)}.ws-cells{display:contents}@container (max-width: 560px){.ws-row{display:grid;grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"play title dl" "play cells cells" "play wave wave";column-gap:.85rem;row-gap:.2rem;padding:.7rem .5rem}.ws-play{grid-area:play;align-self:center}.ws-title{grid-area:title;white-space:normal;overflow-wrap:anywhere}.ws-title-text{overflow:visible}.ws-cells{grid-area:cells;display:flex;flex-wrap:wrap;align-items:baseline;gap:0 .5rem;min-width:0}.ws-cells>.ws-cell{flex:none;width:auto;text-align:left;font-size:.78em}.ws-cells>.ws-cell:empty{display:none}.ws-cells>.ws-cell:not(:empty)~.ws-cell:not(:empty):before{content:"\b7";margin-right:.5rem;opacity:.6}.ws-wave{grid-area:wave;margin-top:.35rem;min-width:0}.ws-download{grid-area:dl;align-self:start}.ws-controls{position:relative}.ws-menu{position:static}.ws-menu-pop{min-width:min(14rem,100%);max-width:100%}.ws-bpm-pop{width:min(17rem,100%)}}.ws-empty{margin:1.5rem 0;color:var(--ws-muted)}.ws-clear{margin-left:.5rem;padding:.35rem .85rem;font-size:.88em}.ws-more{display:block;margin:1.25rem auto 0;padding:.7rem 1.4rem;font-size:.92em}.ws-more:hover,.ws-clear:hover{background:var(--ws-hover)}.ws-engine--strip{position:var(--ws-strip-position, static);bottom:0;margin-top:1rem;padding:.75rem;border:1px solid var(--ws-border);border-radius:var(--ws-radius);background:var(--ws-strip-bg, var(--ws-surface, Canvas));z-index:1}@media(pointer:coarse){.ws-play,.ws-download{width:2.75rem;height:2.75rem}.ws-chip{height:2.5rem}.ws-search-input,.ws-menu-search{font-size:16px}.ws-range{--ws-thumb: 24px;height:2.25rem}.ws-range-input::-webkit-slider-thumb{margin-top:calc((2.25rem - var(--ws-thumb)) / 2)}.ws-menu-option{padding:.75rem .6rem}}@media(forced-colors:active){.ws-loop[aria-pressed=true],.ws-chip[aria-pressed=true],.ws-seg-btn[aria-pressed=true],.ws-row.is-current .ws-play{forced-color-adjust:none;border-color:Highlight;background:Highlight;color:HighlightText}.ws-loop[aria-pressed=true]>*,.ws-seg-btn[aria-pressed=true]>*,.ws-chip[aria-pressed=true]>*,.ws-row.is-current .ws-play>*{color:HighlightText}.ws-range:before,.ws-range:after{forced-color-adjust:none}.ws-range:before{background:GrayText}.ws-range:after{background:Highlight}.ws-range-input:focus-visible{outline:2px solid Highlight;outline-offset:2px}.ws-menu-option.is-active{outline:2px solid Highlight}}@media(prefers-reduced-motion:reduce){.ws-row,.ws-chip,.ws-play,.ws-seg-btn,.ws-download,.ws-menu-chevron{transition:none}}
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var tt=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function ee(n){return n==null?"":String(n).replace(/[&<>"']/g,e=>tt[e])}var nt=/[^\p{L}\p{N}\p{M}]+/u,rt=/\p{Mn}/gu,st=Object.freeze([[768,879],[1425,1479],[1552,1562],[1611,1631],[1648,1648],[6832,6911],[7616,7679],[8400,8447],[65056,65071]]);function ot(n){let e=n.codePointAt(0)??0;return st.some(([t,r])=>e>=t&&e<=r)}function v(n){return!n||typeof n!="string"?"":n.toLowerCase().normalize("NFD").replace(rt,e=>ot(e)?"":e).normalize("NFC")}function $(n){return v(n).split(nt).filter(e=>e!=="")}function be(n,e){let t=Array.from(n??""),r=Array.from(e??""),s=[],o=Array.from({length:r.length+1},(i,a)=>a);for(let i=1;i<=t.length;i++){let a=[i];for(let l=1;l<=r.length;l++){let p=t[i-1]===r[l-1]?0:1;a[l]=Math.min(o[l]+1,a[l-1]+1,o[l-1]+p),i>1&&l>1&&t[i-1]===r[l-2]&&t[i-2]===r[l-1]&&(a[l]=Math.min(a[l],s[l-2]+1))}s=o,o=a}return o[r.length]}function ye(n,e,t={}){let r=t.fuzzyFrom??4,s=v(n),o=$(n);return $(e).every(i=>{if(s.includes(i))return!0;let a=Array.from(i).length;return a<r?!1:o.some(l=>be(i,l)<=1||be(i,Array.from(l).slice(0,a).join(""))<=1)})}function D(n){if(!Array.isArray(n))return"";let e="";for(let t of n){let r=Math.round(Math.min(Math.max(Number(t)||0,0),1)*255);e+=(r<16?"0":"")+r.toString(16)}return e}var we="wp1:";function it(n){if(!n||!/^[\w-]+$/.test(n)||n.length%4===1)return null;try{let e=atob(n.replace(/-/g,"+").replace(/_/g,"/")),t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r)/255;return t}catch{return null}}function te(n,e=1){if(n==null||n==="")return null;if(typeof n=="string"){if(n.startsWith(we))return it(n.slice(we.length));if(!/^[0-9a-f]+$/i.test(n)||n.length%2)return null;let s=new Array(n.length/2);for(let o=0;o<s.length;o++)s[o]=parseInt(n.slice(o*2,o*2+2),16)/255;return s}if(!Array.isArray(n))return null;let t=Number(e)>0?Number(e):1,r=n.map(s=>Math.min(Math.max((Number(s)||0)/t,0),1));return r.length?r:null}function R(n){if(n==null)return"";let e=String(n).trim(),t=e.match(/^([A-Ga-g])[\s_-]*([#♯b♭]?)[\s_-]*(m|min|minor|maj|major)?$/i);if(!t)return e;let r=t[1].toUpperCase(),s=t[2]==="\u266F"?"#":t[2]==="\u266D"?"b":t[2],o=t[3]&&/^m(in(or)?)?$/i.test(t[3])&&t[3]!=="M";return r+s+(o?"m":"")}var at={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 N(n){if(!n)return 1/0;let e=n.endsWith("m"),t=e?n.slice(0,-1):n,r=at[t];return r===void 0?1e3:r*2+(e?1:0)}function k(n){if(n==null||n==="")return"";let e=Number(n);if(!Number.isFinite(e)||e<0)return"";if(e>0&&e<.95)return`${Math.max(.1,Math.round(e*10)/10).toFixed(1)}s`;let t=e<1?Math.ceil(e):Math.floor(e);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function Se(n){let e=Number.isFinite(n)&&n>0?Math.floor(n):0,t=Math.floor(e/3600),r=Math.floor(e%3600/60),s=String(e%60).padStart(2,"0");return t?`${t}:${String(r).padStart(2,"0")}:${s}`:`${r}:${s}`}function lt(n){if(n==null||n==="")return null;if(typeof n=="number")return Number.isFinite(n)&&n>=0?n:null;let e=String(n).trim();return/^\d+(\.\d+)?$/.test(e)?Number(e):/^\d+(\.\d+)?(:\d+(\.\d+)?)+$/.test(e)?e.split(":").map(Number).reduce((r,s)=>r*60+s,0):null}function ut(n){let t=(String(n||"").split(/[?#]/)[0].split("/").pop()||"").replace(/\.[a-z0-9]+$/i,"");try{t=decodeURIComponent(t)}catch{}return t.replace(/[_]+/g," ").replace(/\s+/g," ").trim()}function ne(n,e,t=1){if(!n||typeof n!="object"||!n.url)return null;let r=Number(n.bpm),s=Array.isArray(n.tags)?n.tags.map(o=>String(o).trim()).filter(Boolean):typeof n.tags=="string"?n.tags.split(",").map(o=>o.trim()).filter(Boolean):[];return{id:n.id!=null&&n.id!==""?String(n.id):`sound-${e+1}`,url:String(n.url),title:n.title?String(n.title):ut(n.url),type:n.type?String(n.type):"",bpm:Number.isFinite(r)&&r>0?Math.round(r*100)/100:null,key:R(n.key),duration:lt(n.duration),tags:s,peaks:te(n.peaks,t),waveform:n.waveform?String(n.waveform):null,download:n.download?String(n.download):null,loop:dt(n.loop)}}var ve=["loop","one-shot"];function dt(n){return n===!0||n===1||n==="true"||n==="1"}function q(n){let e=Array.isArray(n)?n:Array.isArray(n?.sounds)?n.sounds:[],t=Array.isArray(n)?1:Number(n?.peakScale)||1;return x(e,t)}function x(n,e=1){let t=new Set,r=[];return(Array.isArray(n)?n:[]).forEach((s,o)=>{let i=ne(s,o,e);if(!i)return;let a=i.id,l=2;for(;t.has(a);)a=`${i.id}-${l++}`;i.id=a,t.add(a),r.push(i)}),r}function w(n){let e=new Map,t=new Set,r=1/0,s=-1/0,o=!1,i=0;for(let a of n)a.type&&e.set(a.type,(e.get(a.type)||0)+1),a.key&&t.add(a.key),a.bpm!=null&&(r=Math.min(r,a.bpm),s=Math.max(s,a.bpm)),a.duration!=null&&(o=!0),a.loop&&i++;return{types:[...e].map(([a,l])=>({name:a,count:l})),keys:[...t].sort((a,l)=>N(a)-N(l)||a.localeCompare(l)),bpm:r===1/0?null:{min:r,max:s},hasDuration:o,loops:i,oneShots:n.length-i}}function z(n,e={}){if(e.type&&n.type!==e.type||e.key&&n.key!==R(e.key)||e.loop==="loop"&&!n.loop||e.loop==="one-shot"&&n.loop)return!1;let t=Number(e.bpmMin),r=Number(e.bpmMax);if((e.bpmMin!=null&&e.bpmMin!==""&&Number.isFinite(t)||e.bpmMax!=null&&e.bpmMax!==""&&Number.isFinite(r))&&(n.bpm==null||e.bpmMin!=null&&e.bpmMin!==""&&n.bpm<t||e.bpmMax!=null&&e.bpmMax!==""&&n.bpm>r))return!1;let s=$(e.query||"");if(s.length){let o=[n.title,n.type,n.key,...n.tags||[]].join(" "),i=v(o),a=s.filter(l=>!(/^\d+$/.test(l)&&!i.includes(l)&&n.bpm!=null&&Math.round(n.bpm)===Number(l)));if(a.length&&!ye(o,a.join(" ")))return!1}return!0}var A=["default","title","bpm","key","duration"],ct={default:()=>!0,title:()=>!0,bpm:n=>n.bpm!==null,key:n=>n.keys.length>0,duration:n=>n.hasDuration};function B(n,e){return n.filter(t=>ct[t]?.(e))}function H(n,e="default"){let t=n.map((o,i)=>({s:o,i})),r=o=>o??1/0,s={title:(o,i)=>o.s.title.localeCompare(i.s.title,void 0,{numeric:!0,sensitivity:"base"}),bpm:(o,i)=>r(o.s.bpm)-r(i.s.bpm),key:(o,i)=>N(o.s.key)-N(i.s.key),duration:(o,i)=>r(o.s.duration)-r(i.s.duration)}[e];return s&&t.sort((o,i)=>s(o,i)||o.i-i.i),t.map(o=>o.s)}function pt(n){let e=n.getBoundingClientRect();if(!e.width||!e.height)return null;let t=Math.min(window.devicePixelRatio||1,3),r=Math.round(e.width*t),s=Math.round(e.height*t);return n.width!==r&&(n.width=r),n.height!==s&&(n.height=s),{width:e.width,height:e.height,dpr:t}}function re(n,e){if(!n?.length||e<=0)return[];if(n.length===e)return n;let t=new Array(e),r=n.length/e;for(let s=0;s<e;s++){let o=Math.floor(s*r),i=Math.max(o+1,Math.floor((s+1)*r)),a=0;for(let l=o;l<i&&l<n.length;l++)n[l]>a&&(a=n[l]);t[s]=a}return t}function mt(n,e,t,r){let s=r.barWidth+r.barGap,o=re(n,Math.max(1,Math.floor((e+r.barGap)/s))),i=o.reduce((l,p)=>p>l?p:l,0),a=i>0?1/i:1;return o.map((l,p)=>{let c=Math.max(l*a,.04);if(r.style==="bars"){let L=Math.max(1,c*t);return{x:p*s,y:t-L,w:r.barWidth,h:L}}let f=Math.max(1,c*(t-2));return{x:p*s,y:t/2-f/2,w:r.barWidth,h:f}})}function xe(n,e,t,r){let s=pt(n),o=s&&n.getContext&&n.getContext("2d");if(!o)return;let{width:i,height:a,dpr:l}=s;if(o.setTransform(l,0,0,l,0,0),o.clearRect(0,0,i,a),!e?.length){o.fillStyle=r.color,o.fillRect(0,Math.floor(a/2),i,1);return}let p=new Path2D;for(let f of mt(e,i,a,r))p.rect(f.x,f.y,f.w,f.h);o.fillStyle=r.color,o.fill(p);let c=Math.min(Math.max(t,0),1)*i;c>0&&(o.save(),o.beginPath(),o.rect(0,0,c,a),o.clip(),o.fillStyle=r.progressColor,o.fill(p),o.restore())}var ft=["onLoad","onPlay","onPause","onEnd","onTimeUpdate","onError"],ht=["duration","downloadUrl","downloadName"];function _e(n,e,t){let r=n||{},s=e==="strip",o={height:s?48:32,waveformStyle:s?"mirror":"bars",preload:"metadata",singlePlay:!0,...r,audioMode:"self",loop:!1,showLoop:!1};for(let i of ht)delete o[i];for(let i of ft)o[i]=(...a)=>{t[i]?.(...a),typeof r[i]=="function"&&r[i](...a)};return o}function gt(n,e){return e==="strip"&&n.waveform||n.peaks||null}function se(n,e,t,r){let s={waveform:gt(n,e),autoplay:t};return r&&(s.preload=r),n.duration!=null&&n.duration>0&&(s.duration=n.duration),n.download&&(s.downloadUrl=n.download),s}function bt(n,e){let t=v(String(e??"")).trim();return!t||v(String(n??"")).includes(t)}function Me(n,e,t){return Math.max(0,Math.min(t-1,n+e))}function _(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 oe=n=>n.search||n.list||n.pop.querySelector("input")||n.pop.querySelector("button"),ie=(n,e=!1)=>[...n.list.querySelectorAll('[role="option"]')].filter(t=>!e||!t.hidden),K=class{constructor(e,{onPick:t,signal:r}){this.container=e,this.onPick=t,this.menus=Object.fromEntries([...e.querySelectorAll("[data-ws-menu]")].map(s=>[s.dataset.wsMenu,s])),this.openMenu=null,this._bind(r)}_bind(e){let t={signal:e};for(let[r,s]of Object.entries(this.menus)){let o=_(s);if(o.button.addEventListener("click",()=>this.openMenu===s?this.close(!0):this.open(s),t),o.button.addEventListener("keydown",i=>{(i.key==="ArrowDown"||i.key==="ArrowUp")&&(i.preventDefault(),this.open(s))},t),!o.list){o.pop.addEventListener("keydown",i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),this.close(!0))},t);continue}o.list.addEventListener("click",i=>{let a=i.target.closest('[role="option"]');a&&this._pick(r,a.dataset.value)},t),o.list.addEventListener("mousedown",i=>i.preventDefault(),t),o.search?.addEventListener("input",()=>this._filter(s,o.search.value),t),oe(o).addEventListener("keydown",i=>this._onKey(i,r,s),t)}document.addEventListener("pointerdown",r=>{this.openMenu&&!this.openMenu.contains(r.target)&&this.close(!1)},t),this.container.addEventListener("focusout",r=>{this.openMenu&&!this.openMenu.contains(r.relatedTarget)&&this.close(!1)},t)}open(e){this.openMenu&&this.openMenu!==e&&this.close(!1);let t=_(e);t.button.setAttribute("aria-expanded","true"),t.pop.hidden=!1,this.openMenu=e,t.search&&(t.search.value="",this._filter(e,"")),e.classList.remove("ws-menu--end"),t.pop.getBoundingClientRect().right>this.container.getBoundingClientRect().right+1&&e.classList.add("ws-menu--end"),t.list&&this._activate(e,t.list.querySelector('[role="option"][aria-selected="true"]')),oe(t)?.focus()}close(e){let t=this.openMenu;if(!t)return;this.openMenu=null;let r=_(t);r.pop.hidden=!0,r.button.setAttribute("aria-expanded","false"),e&&r.button.focus()}setValue(e,t){let r=this.menus[e];if(!r)return;let s=_(r);if(!s.list)return;let o=null;for(let i of ie(s)){let a=i.dataset.value===String(t??"");i.setAttribute("aria-selected",String(a)),a&&(o=i.querySelector(".ws-menu-text")?.textContent??"")}o!==null&&(s.value.textContent=o)}_filter(e,t){let r=_(e),s=null;for(let o of ie(r))o.hidden=!bt(o.textContent,t),o.hidden||(s??=o);r.none.hidden=s!==null,this._activate(e,s)}_activate(e,t){let r=_(e);for(let o of r.list.querySelectorAll(".is-active"))o.classList.remove("is-active");let s=oe(r);if(!t||t.hidden){s.removeAttribute("aria-activedescendant");return}t.classList.add("is-active"),s.setAttribute("aria-activedescendant",t.id),t.scrollIntoView?.({block:"nearest"})}_onKey(e,t,r){let s=_(r),o=ie(s,!0),i=o.indexOf(s.list.querySelector(".is-active")),a=p=>{e.preventDefault(),this._activate(r,o[p])},l=e.target.matches("input");switch(e.key){case"ArrowDown":return a(Me(i,1,o.length));case"ArrowUp":return a(Me(i,-1,o.length));case"Home":return l?void 0:a(0);case"End":return l?void 0:a(o.length-1);case"Enter":e.preventDefault(),i>=0&&this._pick(t,o[i].dataset.value);return;case"Escape":return e.preventDefault(),e.stopPropagation(),this.close(!0);case"Tab":return this.close(!1);default:return}}_pick(e,t){this.close(!0),this.onPick(e,t)}};var g="[WaveformSounds]";function ae(n,e=0,t=1){return Math.min(Math.max(n,e),t)}function Ee(n,e){return e&&e.width?ae((n-e.left)/e.width):0}function Te(n){return!!n&&(n.isContentEditable||/^(INPUT|SELECT|TEXTAREA)$/.test(n.tagName))}function Le(n,e,t){let r=new CustomEvent(`waveformsounds:${e}`,{bubbles:!0,composed:!0,detail:t});return n.dispatchEvent(r),r}function Re(n){let e=5381;for(let t of n)e=e*33+t.codePointAt(0)>>>0;return e}var ke=.1;function Ce(n,e,t){if(!t)return null;switch(n){case"ArrowDown":return e+1<t?e+1:null;case"ArrowUp":return e>0?e-1:"search";case"Home":return 0;case"End":return t-1;default:return null}}function Ae(n,e){return e!=="ArrowRight"&&e!=="ArrowLeft"?null:ae(n+(e==="ArrowRight"?ke:-ke),0,He)}var He=.999;function Oe(n){return n==="Home"?0:n==="End"?He:null}function Ie(n,e){let t=new Set(n.slice(0,e));return{visible:t,remaining:n.length-t.size}}function Fe(n,e){return e>=n?e+1:n}function O(n){return n?{min:Math.floor(n.min),max:Math.ceil(n.max)}:null}function Pe(n,e,t){let r=Math.min(n,e),s=Math.max(n,e);return{bpmMin:r>t.min?String(r):"",bpmMax:s<t.max?String(s):""}}function I(n,e){let t=(o,i)=>{let a=Number(o);return o===""||o==null||!Number.isFinite(a)?i:Math.min(Math.max(a,e.min),e.max)},r=t(n.bpmMin,e.min),s=t(n.bpmMax,e.max);return r<=s?{lo:r,hi:s}:{lo:s,hi:r}}function le(n,e){let t=e.max-e.min;return t>0?Math.min(Math.max((n-e.min)/t,0),1):0}function We(n){return n.bpmMin!=null&&n.bpmMin!==""||n.bpmMax!=null&&n.bpmMax!==""}var S={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",anyBpm:"Any BPM",bpmRange:"{min}\u2013{max} BPM",sort:"Sort",sortBy:"Sort by",sortDefault:"Default",sortTitle:"Name",sortBpm:"BPM",sortKey:"Key",sortDuration:"Length",loop:"Loop",loopFilter:"Loops or one-shots",loops:"Loops",oneShots:"One-shots",isLoop:"Loop",play:"Play {title}",pause:"Pause {title}",seek:"Seek {title}",seekValue:"{time} of {duration}",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}",playError:"Could not play {title}",loadError:"Could not load the sounds.",noSounds:"No sounds."},$e={default:"sortDefault",title:"sortTitle",bpm:"sortBpm",key:"sortKey",duration:"sortDuration"};function m(n,e={}){return String(n).replace(/\{(\w+)\}/g,(t,r)=>r in e?String(e[r]):t)}function U(n,e,t=S){if(!We(n))return t.anyBpm;let{lo:r,hi:s}=I(n,e);return m(t.bpmRange,{min:r,max:s})}function j(n,e,t=S){return n!==e?m(t.countFiltered,{count:n,total:e}):e===1?t.countOne:m(t.count,{count:e})}var Ne=["type","key","bpm","loop"],De=["type","bpm","key","duration"],b={player:"inline",search:!0,filters:[...Ne],sorts:[...A],loopToggle:!0,showCount:!0,menuSearch:8,pageSize:50,columns:[...De],maxTypeChips:10},V=[...Object.keys(b),"idPrefix","loop","strings"];function ce(n){let e={};for(let t of V){let r=n?.[t];r!=null&&(e[t]=r)}return e}function G(n){let e={};for(let t in n??{})n[t]!==void 0&&(e[t]=n[t]);return e}function ue(n,e,t){return Array.isArray(n)?n.filter(r=>e.includes(r)):t}function de(n,e){let t=Number(n);return Number.isFinite(t)&&t>=0?Math.floor(t):e}function C(n={}){let e={...b,...G(n)};return{...e,player:e.player==="strip"?"strip":"inline",filters:ue(e.filters,Ne,b.filters),sorts:ue(e.sorts,A,b.sorts),columns:ue(e.columns,De,b.columns),menuSearch:de(e.menuSearch,b.menuSearch),maxTypeChips:de(e.maxTypeChips,b.maxTypeChips),pageSize:de(e.pageSize,b.pageSize),strings:{...S,...G(n.strings)}}}var Y={...b,sounds:null,manifest:null,waveformStyle:"mirror",waveformColor:null,progressColor:null,barWidth:2,barGap:1,loop:null,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 pe(n){if(n!=null)return n.split(",").map(e=>e.trim()).filter(Boolean)}function F(n){return n===void 0||n===""?void 0:Number(n)}function yt(n){if(n===void 0)return;let e=M(n);return e===void 0?n:e}function qe(n,e){if(n)try{return JSON.parse(n)}catch{console.warn(`${g} Ignoring invalid JSON in data-${e}`);return}}function J(n){let e=n.dataset||{},t={player:e.player||void 0,manifest:e.manifest||void 0,search:M(e.search),filters:pe(e.filters),sorts:pe(e.sorts),showCount:M(e.showCount),menuSearch:F(e.menuSearch),idPrefix:e.idPrefix||void 0,urlState:yt(e.urlState),loopToggle:M(e.loopToggle),pageSize:F(e.pageSize),maxTypeChips:F(e.maxTypeChips),columns:pe(e.columns),waveformStyle:e.waveformStyle||void 0,waveformColor:e.waveformColor||void 0,progressColor:e.progressColor||void 0,barWidth:F(e.barWidth),barGap:F(e.barGap),loop:M(e.loop),autoAdvance:M(e.autoAdvance),arrowAudition:M(e.arrowAudition),strings:qe(e.strings,"strings"),playerOptions:qe(e.playerOptions,"player-options")};for(let r of Object.keys(t))t[r]===void 0&&delete t[r];return t}function ze(...n){let e={};for(let t of n)if(t)for(let r in t)t[r]!==null&&t[r]!==void 0&&(e[r]=t[r]);return e}var wt=new Set(["input","br","img"]);function d(n){return ee(n??"")}function St(n={}){let e="";for(let[t,r]of Object.entries(n))r===!0?e+=` ${t}`:r!==!1&&r!=null&&(e+=` ${t}="${ee(r)}"`);return e}function u(n,e={},...t){let r=`<${n}${St(e)}>`;return wt.has(n)?r:r+t.flat(1/0).filter(s=>s!=null&&s!==!1&&s!=="").join("")+`</${n}>`}function E(n,e=""){return`<svg class="${e?`ws-icon ${e}`:"ws-icon"}" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${n}"/></svg>`}var y={play:E("M8 5.5v13l11-6.5z","ws-icon-play"),pause:E("M7 5h3.5v14H7zM13.5 5H17v14h-3.5z","ws-icon-pause"),search:E("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:E("M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z","ws-menu-chevron"),check:E("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:E("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:E("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 e=[n.length,...n.map(t=>t.url)].join("|");return`ws${Re(e).toString(36)}`}function xt(n,e){let t=e.filters.includes("type")&&n.types.length>1,r=B(e.sorts,n);return{types:t?n.types.length>e.maxTypeChips?"menu":"chips":null,key:e.filters.includes("key")&&n.keys.length>1,bpm:e.filters.includes("bpm")&&n.bpm!==null&&n.bpm.max>n.bpm.min,loops:e.filters.includes("loop")&&n.loops>0&&n.oneShots>0,sorts:r.length>1?r:[],search:!!e.search,loop:!!e.loopToggle,count:!!e.showCount}}function me(n,e){return n==null?e.loops>0:!!n}function _t(n){return u("label",{class:"ws-search"},y.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 Mt(n,e){let t=`${e.id}-${n}-list`,r=e.options.find(l=>l.value===e.value)??e.options[0],s=e.placeholder&&e.options.length>e.searchFrom,o=u("button",{type:"button",class:"ws-menu-btn","data-ws-menu-btn":!0,"aria-haspopup":"listbox","aria-expanded":"false","aria-controls":t},e.prefix?u("span",{class:"ws-menu-prefix"},d(e.prefix)):u("span",{class:"ws-sr"},d(`${e.label}: `)),u("span",{class:"ws-menu-value","data-ws-menu-value":!0},d(r.label)),y.chevron),i=s&&u("input",{type:"search",class:"ws-menu-search","data-ws-menu-search":!0,role:"combobox","aria-expanded":"true","aria-controls":t,"aria-autocomplete":"list","aria-label":e.placeholder,placeholder:e.placeholder,autocomplete:"off",spellcheck:"false"}),a=e.options.map((l,p)=>u("li",{role:"option",id:`${e.id}-${n}-${p}`,class:"ws-menu-option","data-value":l.value,"aria-selected":String(l===r)},y.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},o,u("div",{class:"ws-menu-pop","data-ws-menu-pop":!0,hidden:!0},i,u("ul",{class:"ws-menu-list",role:"listbox",id:t,"aria-label":e.label,tabindex:"-1","data-ws-menu-list":!0},a),u("p",{class:"ws-menu-none","data-ws-menu-none":!0,hidden:!0},d(e.noMatches))))}function Et({id:n,s:e,range:t}){let r=`${n}-bpm-pop`,s=(o,i,a)=>u("input",{type:"range",class:"ws-range-input",[o]:!0,"aria-label":i,min:t.min,max:t.max,step:"1",value:a});return u("div",{class:"ws-menu ws-menu--bpm","data-ws-menu":"bpm"},u("button",{type:"button",class:"ws-menu-btn","data-ws-menu-btn":!0,"aria-haspopup":"dialog","aria-expanded":"false","aria-controls":r},u("span",{class:"ws-sr"},d(`${e.bpm}: `)),u("span",{class:"ws-menu-value","data-ws-menu-value":!0},d(U({},t,e))),y.chevron),u("div",{class:"ws-menu-pop ws-bpm-pop",id:r,role:"dialog","aria-label":e.bpm,"data-ws-menu-pop":!0,hidden:!0},u("div",{class:"ws-bpm-head"},u("span",{class:"ws-bpm-readout","data-ws-bpm-readout":!0,"aria-live":"polite"},d(m(e.bpmRange,t))),u("button",{type:"button",class:"ws-bpm-clear","data-ws-bpm-clear":!0},d(e.anyBpm))),u("div",{class:"ws-range","data-ws-bpm-range":!0},s("data-ws-bpm-min",e.bpmMin,t.min),s("data-ws-bpm-max",e.bpmMax,t.max)),u("div",{class:"ws-range-ends","aria-hidden":"true"},u("span",{},d(t.min)),u("span",{},d(t.max)))))}function Tt(n){let e=(t,r)=>u("button",{type:"button",class:"ws-seg-btn","data-ws-loop-filter":t,"aria-pressed":String(t==="")},u("span",{},d(r)));return u("div",{class:"ws-seg",role:"group","aria-label":n.loopFilter},e("",n.all),e("loop",n.loops),e("one-shot",n.oneShots))}function Lt(n,e){return u("button",{type:"button",class:"ws-loop","data-ws-loop":!0,"aria-pressed":String(e)},y.loop,u("span",{},d(n.loop)))}function Be(n,e,t,r){return u("button",{type:"button",class:"ws-chip","data-ws-type":n,"aria-pressed":String(r)},u("span",{class:"ws-chip-label"},d(e))," ",u("span",{class:"ws-chip-count"},d(t)))}function Rt(n,{o:e,s:t,f:r,total:s,id:o}){let i=(c,f)=>Mt(c,{id:o,searchFrom:e.menuSearch,noMatches:t.noMatches,...f}),a=[n.types==="menu"&&i("type",{label:t.types,value:"",placeholder:t.findType,options:[{value:"",label:t.allTypes,count:s},...r.types.map(c=>({value:c.name,label:c.name,count:c.count}))]}),n.key&&i("key",{label:t.key,value:"",placeholder:t.findKey,options:[{value:"",label:t.anyKey},...r.keys.map(c=>({value:c,label:c}))]}),n.bpm&&Et({id:o,s:t,range:O(r.bpm)}),n.loops&&Tt(t),n.sorts.length>0&&i("sort",{label:t.sort,prefix:t.sortBy,value:n.sorts[0],options:n.sorts.map(c=>({value:c,label:t[$e[c]]}))}),n.loop&&Lt(t,me(e.loop,r))].filter(Boolean),l=n.types==="chips"&&u("div",{class:"ws-types",role:"group","aria-label":t.types},Be("",t.all,s,!0),r.types.map(c=>Be(c.name,c.name,c.count,!1))),p=n.count&&u("p",{class:"ws-count","data-ws-count":!0,"aria-live":"polite"},d(j(s,s,t)));return u("div",{class:"ws-toolbar"},n.search&&_t(t),a.length>0&&u("div",{class:"ws-controls"},a),(l||p)&&u("div",{class:"ws-meta"},l,p))}var kt={type:n=>d(n.type),bpm:n=>d(n.bpm??""),key:n=>d(n.key),duration:n=>d(k(n.duration))};function Ct(n,e,t,r=!1){let s=t.strings,o={title:n.title},i=t.columns.map(a=>u("span",{class:`ws-cell ws-${a}`},kt[a](n)));return u("li",{class:"ws-row","data-ws-index":e,"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?D(n.peaks):null,"data-waveform":n.waveform,"data-download":n.download,"data-loop":n.loop?"true":null,hidden:r},u("button",{type:"button",class:"ws-play","aria-pressed":"false","aria-label":m(s.play,o)},y.play,y.pause),u("span",{class:"ws-cell ws-title"},u("span",{class:"ws-title-text"},d(n.title)),n.loop&&u("span",{class:"ws-loop-mark",title:s.isLoop},y.loop,u("span",{class:"ws-sr"},d(s.isLoop)))),i.length>0&&u("span",{class:"ws-cells"},i),t.player==="inline"&&u("span",{class:"ws-wave",role:"slider","aria-label":m(s.seek,o),"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":m(s.download,o)},y.download))}function At({o:n,s:e,total:t}){let r=n.pageSize>0?n.pageSize:t,s=Math.max(0,t-r),o=n.player==="strip";return[u("p",{class:"ws-empty","data-ws-empty":!0,hidden:!0},d(e.empty)," ",u("button",{type:"button",class:"ws-clear","data-ws-clear":!0},d(e.clear))),u("button",{type:"button",class:"ws-more","data-ws-more":!0,hidden:s===0},d(m(e.showMore,{count:Math.min(s,r)}))),u("div",{class:o?"ws-engine ws-engine--strip":"ws-engine","data-ws-engine":!0,hidden:!o}),u("p",{class:"ws-sr","data-ws-status":!0,"aria-live":"polite"})].join("")}function P(n,e={}){let t=C(e),r=x(n),s={o:t,s:t.strings,f:w(r),total:r.length,id:t.idPrefix||vt(r)},o=t.pageSize>0?t.pageSize:1/0;return Rt(xt(s.f,t),s)+u("ul",{class:`ws-list ws-list--${t.player}`,role:"list","data-ws-list":!0},r.map((i,a)=>Ct(i,a,t,a>=o)))+At(s)}function Ht(n={}){let e=ce(n),t=C(n),r={};for(let s of V){if(s==="player"||!(s in e))continue;let o=`data-${s.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`;if(s==="strings"){let i=G(e.strings);Object.keys(i).length&&(r[o]=JSON.stringify(i))}else if(s==="loop"||s==="idPrefix")r[o]=String(e[s]);else{let i=t[s];r[o]=Array.isArray(i)?i.join(","):String(i)}}return r}function Ot(n,e={},t=""){let r=C(e),s=["waveform-sounds",`waveform-sounds--${r.player}`,t].filter(Boolean).join(" ");return u("div",{class:s,"data-waveform-sounds":!0,"data-player":r.player,...Ht(e)},P(n,e))}var fe=":scope > [data-ws-index]";function Ke(n){let e=[...n.querySelectorAll(fe)].sort((r,s)=>Number(r.dataset.wsIndex)-Number(s.dataset.wsIndex)),t=[];for(let r of e){let s=r.dataset,o=ne({id:s.wsId,url:s.url,title:s.title,type:s.type,bpm:s.bpm,key:s.key,duration:s.duration,tags:s.tags,peaks:s.peaks,waveform:s.waveform,download:s.download,loop:s.loop},t.length);if(!o){r.remove();continue}r.dataset.wsIndex=String(t.length),t.push(o)}return t}function Ue(n){let e=[];return n.querySelectorAll(fe).forEach(t=>{e[Number(t.dataset.wsIndex)]=t}),e}function T(n){return[...n.querySelectorAll(fe)].filter(e=>!e.hidden)}function je(n,e){let t=document.createDocumentFragment();for(let r of e)r&&t.appendChild(r);n.appendChild(t)}function It(n){let e=String(n??"").trim();if(!e||e==="transparent")return 0;let t=e.match(/\/\s*([\d.]+)(%?)\s*\)$/);if(t)return Number(t[1])/(t[2]?100:1);let r=e.match(/^rgba\(\s*[^,]+,[^,]+,[^,]+,\s*([\d.]+)\s*\)$/);return r?Number(r[1]):1}function Ge(n,e=.95){for(let t=n;t&&t.nodeType===1;t=t.parentElement||t.getRootNode?.().host){let r=getComputedStyle(t).backgroundColor;if(It(r)>e)return r}return"#fff"}function Ve(){try{return typeof matchMedia=="function"&&matchMedia("(forced-colors: active)").matches}catch{return!1}}function Ye(n){let e=[];for(let t=n.parentElement||n.getRootNode?.()?.host;t;t=t.parentElement||t.getRootNode?.()?.host)e.push(t);return e}function W(n,e){let t=document.createElement("span");t.style.cssText="position:absolute;width:0;height:0;overflow:hidden;visibility:hidden;forced-color-adjust:none",t.style.color=e,n.appendChild(t);let r=getComputedStyle(t).color;return t.remove(),r}function he(n){if(!n)return null;let e=typeof n=="string"?`${n}-`:"";return{q:`${e}q`,type:`${e}type`,key:`${e}key`,bpm:`${e}bpm`,loop:`${e}loop`,sort:`${e}sort`}}function Ft(n){let e=String(n??"").match(/^(\d+(?:\.\d+)?)?-(\d+(?:\.\d+)?)?$/);if(!e||!(e[1]||e[2]))return null;let t=e[1]??"",r=e[2]??"";return t&&r&&Number(t)>Number(r)?{bpmMin:r,bpmMax:t}:{bpmMin:t,bpmMax:r}}function Pt(n,e){if(!e)return null;let t=s=>s!==""&&Number(s)>=e.min&&Number(s)<=e.max?s:"",r={bpmMin:t(n.bpmMin),bpmMax:t(n.bpmMax)};return r.bpmMin||r.bpmMax?r:null}function Wt(n,e){let t=n??"",r=e??"";return t!==""||r!==""?`${t}-${r}`:""}function Je(n,e,t,r){let s={filter:{},sort:null};if(!e)return s;let o=new URLSearchParams(n),i=o.get(e.q);i&&(s.filter.query=i);let a=o.get(e.type);a&&t.types.some(et=>et.name===a)&&(s.filter.type=a);let l=R(o.get(e.key));l&&t.keys.includes(l)&&(s.filter.key=l);let p=Ft(o.get(e.bpm)),c=p&&t.bpm!==void 0?Pt(p,t.bpm):p;c&&Object.assign(s.filter,c);let f=o.get(e.loop);ve.includes(f)&&t.loops>0&&t.oneShots>0&&(s.filter.loop=f);let L=o.get(e.sort);return L&&r.includes(L)&&(s.sort=L),s}function Qe(n,e,t,r,s){if(!e)return n;let o=new URL(n),i=(a,l)=>l?o.searchParams.set(a,l):o.searchParams.delete(a);return i(e.q,String(t.query??"").trim()),i(e.type,t.type),i(e.key,t.key),i(e.bpm,Wt(t.bpmMin,t.bpmMax)),i(e.loop,t.loop),i(e.sort,r!==s?r:""),o.href}var Xe=Object.freeze({query:"",type:"",key:"",bpmMin:"",bpmMax:"",loop:""}),$t=120,Nt=200,Dt=250,h=class n extends EventTarget{static instances=new Map;constructor(e,t={}){super();let r=typeof e=="string"?document.querySelector(e):e;if(!r)throw new Error(`${g} Container not found: ${e}`);this.container=r;let s=r._wsOptions?.()??J(r);this.options=ze(Y,t,s),this.options.waveformStyle=this.options.waveformStyle==="bars"?"bars":"mirror",this.strings={...S,...this.options.strings||{}},this.render={...C(this.options),strings:this.strings},this.sounds=[],this.rows=[],this.filter={...Xe},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(r,this),r.dataset.wsInitialized="true",this.ready=Promise.resolve().then(()=>this._init()).catch(o=>{this.destroyed||(console.error(`${g} Failed to initialise:`,o),this._showLoadError(),this._emit("error",{error:o}),this.options.onError?.(o,this))})}async _init(){let e=this.container,t=e.querySelector("[data-ws-list]");if(t)this._adoptedHTML=e.innerHTML,this.sounds=Ke(t);else{if(this._originalHTML=e.innerHTML,this.sounds=await this._loadSounds(),this.destroyed)return;e.innerHTML=P(this.sounds,{...this.render,idPrefix:this.options.idPrefix||e.id||void 0})}this.destroyed||(this._addedClasses=["waveform-sounds",`waveform-sounds--${this.render.player}`].filter(r=>!e.classList.contains(r)),e.classList.add(...this._addedClasses),this._cacheRefs(),this._bind(),this._observe(),this._resolveColors(),this._loopSet||(this.loop=me(this.options.loop,w(this.sounds))),this._setLoop(this.loop),this._bpmExtent=O(w(this.sounds).bpm),this._sorts=B(this.render.sorts,w(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.render.player==="strip"&&this.engine&&this.currentIndex==null&&this._cueFirst(),this._emit("ready",{sounds:this.sounds.length}),this.options.onReady?.(this))}async _loadSounds(){if(this.options.sounds||!this.options.manifest)return x(this.options.sounds||[]);let e=this.options.manifest,t=await fetch(e,{signal:this._ctl.signal});if(!t.ok)throw new Error(`${g} Manifest ${e}: HTTP ${t.status}`);let r=await t.json();if(!Array.isArray(r)&&!Array.isArray(r?.sounds))throw new Error(`${g} Manifest ${e}: no "sounds" list`);return q(r)}_showLoadError(){let e=this.container;this.$||e.querySelector("*")||(this._originalHTML??=e.innerHTML,e.innerHTML=u("p",{class:"ws-empty ws-load-error",role:"alert","data-ws-load-error":!0},d(this.strings.loadError)))}_cacheRefs(){let e=t=>this.container.querySelector(t);this.$={list:e("[data-ws-list]"),search:e("[data-ws-search]"),bpmMin:e("[data-ws-bpm-min]"),bpmMax:e("[data-ws-bpm-max]"),bpmRange:e("[data-ws-bpm-range]"),bpmReadout:e("[data-ws-bpm-readout]"),bpmClear:e("[data-ws-bpm-clear]"),bpmLabel:e('[data-ws-menu="bpm"] [data-ws-menu-value]'),loop:e("[data-ws-loop]"),count:e("[data-ws-count]"),empty:e("[data-ws-empty]"),more:e("[data-ws-more]"),engine:e("[data-ws-engine]"),status:e("[data-ws-status]"),chips:[...this.container.querySelectorAll("[data-ws-type]")],loopFilter:[...this.container.querySelectorAll("[data-ws-loop-filter]")]},this.rows=Ue(this.$.list),this._active=null;for(let t of this.rows)t&&this._rowStops(t,!1)}_rowStops(e,t){let r=e.querySelector(".ws-play");r&&(r.tabIndex=t?0:-1);let s=e.querySelector(".ws-download");s&&(s.tabIndex=t?0:-1);let o=e.querySelector(".ws-wave");o&&(o.tabIndex=t&&Number(e.dataset.wsIndex)===this.currentIndex?0:-1)}_rove(e){!e||e===this._active||(this._active&&this._rowStops(this._active,!1),this._active=e,this._rowStops(e,!0))}_bind(){let e={signal:this._ctl.signal},t=this.$,r=this.container;r.addEventListener("click",a=>this._onClick(a),e),r.addEventListener("pointerdown",a=>this._onPointerDown(a),e),r.addEventListener("keydown",a=>this._onKey(a),e),t.list.addEventListener("focusin",a=>this._rove(a.target.closest("[data-ws-index]")),e);let s=0,o=0;t.search?.addEventListener("input",()=>{clearTimeout(s),s=setTimeout(()=>this.setFilter({query:t.search.value}),$t)},e),t.search?.addEventListener("keydown",a=>{a.key==="ArrowDown"&&(a.preventDefault(),this._focusRow(T(t.list)[0])),a.key==="Escape"&&t.search.value&&(a.preventDefault(),t.search.value="",this.setFilter({query:""}))},e);let i=a=>{let l=Number(t.bpmMin.value),p=Number(t.bpmMax.value);l>p&&(a.value=String(a===t.bpmMin?p:l));let c=Pe(Number(t.bpmMin.value),Number(t.bpmMax.value),this._bpmExtent);this._showBpm(c),clearTimeout(o),o=setTimeout(()=>this.setFilter(c),Nt)};t.bpmMin?.addEventListener("input",()=>i(t.bpmMin),e),t.bpmMax?.addEventListener("input",()=>i(t.bpmMax),e),t.bpmClear?.addEventListener("click",()=>{clearTimeout(o),this.setFilter({bpmMin:"",bpmMax:""})},e),this.menus=new K(r,{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()},e)}_onClick(e){let t=e.target,r=t.closest("[data-ws-type]");if(r){this.setFilter({type:r.dataset.wsType});return}let s=t.closest("[data-ws-loop-filter]");if(s){this.setFilter({loop:s.dataset.wsLoopFilter});return}if(t.closest("[data-ws-more]")){this._showMoreFromButton();return}if(t.closest("[data-ws-clear]")){this.clearFilters(),this.$.search?this.$.search.focus():this._focusRow(T(this.$.list)[0]);return}if(t.closest("[data-ws-loop]")){this.setLoop(!this.loop);return}let o=t.closest(".ws-wave");if(o){this._lastPointer==="touch"&&this._seekAt(o,e.clientX);return}let i=t.closest("[data-ws-index]");!i||t.closest(".ws-download")||(this.toggle(Number(i.dataset.wsIndex)),this._focusRowQuietly(i))}_showMoreFromButton(){let e=new Set(T(this.$.list));this.showMore(),this.$.more?.hidden&&this._focusRow(T(this.$.list).find(t=>!e.has(t)))}_onPointerDown(e){this._lastPointer=e.pointerType;let t=e.target.closest(".ws-wave");!t||e.button!==0||e.pointerType==="touch"||(e.preventDefault(),this._seekAt(t,e.clientX))}_seekAt(e,t){let r=e.closest("[data-ws-index]");this._seekRow(Number(r.dataset.wsIndex),Ee(t,e.getBoundingClientRect())),this._focusRowQuietly(r)}_onKey(e){if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey)return;if(e.key==="/"&&!Te(e.target)&&this.$.search){e.preventDefault(),this.$.search.focus();return}let t=e.target.closest?.("[data-ws-index]");if(!t)return;let r=Number(t.dataset.wsIndex),o=(e.target.closest(".ws-wave")?Oe(e.key):null)??Ae(this.progress,e.key);if(o!==null){if(r!==this.currentIndex||!this.engine)return;e.preventDefault(),this._seekRow(r,o);return}let i=T(this.$.list),a=Ce(e.key,i.indexOf(t),i.length);if(a!==null){if(e.preventDefault(),a==="search"){this.$.search?.focus();return}this._focusRow(i[a]),this.options.arrowAudition&&this.playing&&this.play(Number(i[a].dataset.wsIndex))}}_focusRow(e){e?.querySelector(".ws-play")?.focus()}_focusRowQuietly(e){let t=e?.querySelector(".ws-play");t&&document.activeElement!==t&&t.focus({preventScroll:!0})}_observe(){if(this.render.player!=="inline"||typeof window>"u")return;if(this._drawn=new Set,this._dirty=new Set,"IntersectionObserver"in window?(this._onScreen=new Set,this._io=new IntersectionObserver(r=>{for(let s of r){let o=Number(s.target.dataset.wsIndex);if(!s.isIntersecting){this._onScreen.delete(o);continue}this._onScreen.add(o),!(this._drawn.has(o)&&!this._dirty.has(o))&&(this._drawn.add(o),this._drawRow(o))}},{rootMargin:"200px 0px"}),this.rows.forEach(r=>r&&this._io.observe(r))):this.rows.forEach((r,s)=>r&&this._drawn.add(s)),"ResizeObserver"in window){let r=0;this._ro=new ResizeObserver(([s])=>{let o=Math.round(s.contentRect.width);o!==r&&(r=o,this._redrawAll())}),this._ro.observe(this.$.list)}let e=0,t=()=>{e||(e=requestAnimationFrame(()=>{e=0,this._resolveColors()&&this._redrawAll()}))};this._mo=new MutationObserver(t),this._mo.observe(this.container,{attributes:!0,attributeFilter:["class","data-theme","data-color-scheme"]});for(let r of Ye(this.container))this._mo.observe(r,{attributes:!0,attributeFilter:["class","data-theme","data-color-scheme","style"]});for(let r of["(prefers-color-scheme: dark)","(forced-colors: active)"])try{window.matchMedia(r).addEventListener("change",t,{signal:this._ctl.signal})}catch{}}_resolveColors(){let e=this.colors;(this._autoSurface||!getComputedStyle(this.container).getPropertyValue("--ws-surface").trim())&&(this._autoSurface=!0,this.container.style.removeProperty("--ws-surface"),this.container.style.setProperty("--ws-surface",Ge(this.container)));let t=Ve();return this.colors={wave:(t?W(this.container,"CanvasText"):this.options.waveformColor||W(this.container,"var(--ws-wave-color)"))||"rgba(128,128,128,.5)",progress:(t?W(this.container,"Highlight"):this.options.progressColor||W(this.container,"var(--ws-progress-color)"))||"currentColor"},!e||e.wave!==this.colors.wave||e.progress!==this.colors.progress}_drawRow(e){if(this.render.player!=="inline"||e==null||!this._drawn?.has(e))return;let t=this.rows[e],r=t?.querySelector("canvas");if(!r)return;if(t.hidden){this._dirty?.add(e);return}this._dirty?.delete(e);let s=Number(this.options.barGap);xe(r,this.sounds[e].peaks,e===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(s)?Math.max(0,s):1})}_redrawAll(){this._drawn?.forEach(e=>{this._onScreen&&!this._onScreen.has(e)?this._dirty.add(e):this._drawRow(e)})}_readUrl(){let e=he(this.options.urlState);if(!e||typeof location>"u")return;let t=w(this.sounds),{filter:r,sort:s}=Je(location.search,e,{...t,bpm:O(t.bpm)},this._sorts);this.filter={...this.filter,...r},s&&(this.sortBy=s,this._sortSet=!0)}_queueUrl(){let e=he(this.options.urlState);!e||typeof location>"u"||(clearTimeout(this._urlTimer),this._urlTimer=setTimeout(()=>{if(this.destroyed)return;let t=Qe(location.href,e,this.filter,this.sortBy,this._sorts?.[0]||"default");t!==location.href&&history.replaceState(history.state,"",t)},Dt))}get visible(){return[...this._shown??this._match()]}_match(){return H(this.sounds.filter(e=>z(e,this.filter)),this.sortBy)}setFilter(e={}){this.filter={...this.filter,...e},this.limit=this._pageSize(),this._syncControls(),this._apply({resort:!1})}clearFilters(){this.setFilter(Xe)}setSort(e){this._sortSet=!0,this.sortBy=A.includes(e)?e:"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 e=this.$,t=this.filter;if(e){if(e.search&&e.search.value!==t.query&&(e.search.value=t.query),this.menus?.setValue("type",t.type||""),this.menus?.setValue("key",t.key||""),this.menus?.setValue("sort",this.sortBy),e.bpmMin&&e.bpmMax&&this._bpmExtent){let{lo:r,hi:s}=I(t,this._bpmExtent);e.bpmMin.value=String(r),e.bpmMax.value=String(s),this._showBpm(t)}e.chips.forEach(r=>r.setAttribute("aria-pressed",String(r.dataset.wsType===(t.type||"")))),e.loopFilter.forEach(r=>r.setAttribute("aria-pressed",String(r.dataset.wsLoopFilter===(t.loop||""))))}}_showBpm(e){let t=this.$,r=this._bpmExtent;if(!t?.bpmRange||!r)return;let{lo:s,hi:o}=I(e,r);t.bpmLabel&&(t.bpmLabel.textContent=U(e,r,this.strings)),t.bpmReadout&&(t.bpmReadout.textContent=m(this.strings.bpmRange,{min:s,max:o})),t.bpmRange.style.setProperty("--ws-lo",String(le(s,r))),t.bpmRange.style.setProperty("--ws-hi",String(le(o,r))),t.bpmRange.classList.toggle("is-min-top",s>=o&&s>r.min),t.bpmRange.classList.toggle("is-active",s>r.min||o<r.max)}_apply({resort:e}){let t=this.$;if(!t)return;if(e||this.sortBy!==this._lastSort){let i=new Map(this.sounds.map((a,l)=>[a,l]));je(t.list,H(this.sounds,this.sortBy).map(a=>this.rows[i.get(a)])),this._lastSort=this.sortBy}let r=this._match();this._shown=r;let{visible:s,remaining:o}=Ie(r,this.limit);if(this.sounds.forEach((i,a)=>{this.rows[a]&&(this.rows[a].hidden=!s.has(i))}),t.more&&(t.more.hidden=o<=0,t.more.textContent=m(this.strings.showMore,{count:Math.min(o,this.render.pageSize||o)})),t.empty&&(t.empty.hidden=r.length>0,!this.sounds.length&&t.empty.textContent!==this.strings.noSounds&&(t.empty.textContent=this.strings.noSounds)),t.count&&(t.count.textContent=j(r.length,this.sounds.length,this.strings)),!this._active||this._active.hidden){let i=!!this._active?.contains(document.activeElement),a=T(t.list)[0];a?(this._rove(a),i&&this._focusRowQuietly(a)):this._active&&(this._rowStops(this._active,!1),this._active=null)}this._cued&&!this.playing&&this._cueFirst(),this._queueUrl(),this._emit("filter",{visible:r.length,total:this.sounds.length,filter:{...this.filter},sort:this.sortBy}),this.options.onFilter?.(r,this)}_indexOf(e){if(e==null){if(this.currentIndex!=null)return this.currentIndex;let r=(this._shown??this._match())[0];return r?this.sounds.indexOf(r):null}if(typeof e=="number")return this.sounds[e]?e:null;let t=typeof e=="object"?this.sounds.indexOf(e):this.sounds.findIndex(r=>r.id===String(e));return t>=0?t:null}_playerClass(){return this.options.playerClass||(typeof window<"u"?window.WaveformPlayer:null)||null}_eng(){return this.engine}_engineMount(){let e=this.$.engine,t=e.querySelector(":scope > [data-ws-engine-mount]");return t||(t=document.createElement("div"),t.setAttribute("data-ws-engine-mount",""),e.appendChild(t)),t}_ensureEngine(){if(this.engine)return this._eng();let e=this._playerClass();if(!e)return console.error(`${g} @arraypress/waveform-player is required: load it before playing (or pass playerClass).`),null;let t=_e(this.options.playerOptions,this.render.player,{onLoad:()=>this._onEngineLoad(),onPlay:()=>this._setPlaying(!0),onPause:()=>this._setPlaying(!1),onEnd:()=>this._onEnd(),onTimeUpdate:(r,s)=>this._onTime(r,s),onError:r=>this._onEngineError(r)});return this._preload=t.preload,this.engine=new e(this._engineMount(),t),this._eng()}play(e,t={}){if(!this.$){this.ready.then(()=>{this.destroyed||this.play(e,t)});return}let r=this._indexOf(e);if(r==null)return;this._cued=!1;let s=this._ensureEngine();if(!s)return;if(r===this.currentIndex&&s.audio?.src){t.at!=null&&this._seekRow(r,t.at),this.playing||s.play();return}let o=this.currentIndex;this.currentIndex=r,this.progress=0,this._pendingSeek=t.at??null,o!=null&&this._paintRow(o),this._paintRow(r);let i=this.sounds[r];s.loadTrack(i.url,i.title,i.type||null,se(i,this.render.player,!0,this._preload))}_cueFirst(){let e=this._eng(),t=(this._shown??this._match())[0];if(!e||!t)return;let r=this.sounds.indexOf(t);if(r===this.currentIndex)return;this.currentIndex=r,this.progress=0,this._cued=!0;let s=e.audio,o=s&&typeof s.load=="function";o&&(s.load=()=>{});try{e.loadTrack(t.url,t.title,t.type||null,se(t,"strip",!1,"none"))}finally{o&&delete s.load}}pause(){this.engine&&this.playing&&this._eng().pause()}toggle(e){let t=this._indexOf(e);t!=null&&(t===this.currentIndex&&this.playing?this.pause():this.play(t))}next(){this._step(1)}previous(){this._step(-1)}_step(e){let t=this._shown??this._match(),r=this.currentIndex==null||this._cued?-1:t.indexOf(this.sounds[this.currentIndex]),s=t[r+e];if(!s)return!1;let o=Fe(this.limit,r+e);return o!==this.limit&&(this.limit=o,this._apply({resort:!1})),this.play(this.sounds.indexOf(s)),!0}setLoop(e){this._loopSet=!0,this.loop=!!e,this._setLoop(this.loop)}_setLoop(e){this.$?.loop?.setAttribute("aria-pressed",String(e)),this._eng()?.audio&&(this._eng().audio.loop=this._repeats())}_repeats(){return this.loop?!this.sounds.some(t=>t.loop)||!!this.sounds[this.currentIndex]?.loop:!1}_seekRow(e,t){if(e!==this.currentIndex||!this.engine){this.play(e,{at:t});return}let r=this._eng().audio?.duration;if(!Number.isFinite(r)||r<=0){this._pendingSeek=t;return}this._eng().seekTo(t*r),this.progress=t,this._paintRow(e),this._paintSlider(),this.playing||this._eng().play()}_onEngineLoad(){this.currentIndex!=null&&this.rows[this.currentIndex]?.classList.remove("is-error"),this._eng()?.audio&&(this._eng().audio.loop=this._repeats());let e=this.sounds[this.currentIndex];e&&!e.peaks&&this._eng()?.waveformData?.length&&(e.peaks=re(this._eng().waveformData,96),this._drawRow(this.currentIndex));let t=this._eng()?.audio?.duration;this._pendingSeek!=null&&Number.isFinite(t)&&t>0&&(this._eng().seekTo(this._pendingSeek*t),this.progress=this._pendingSeek,this._pendingSeek=null)}_onTime(e,t){if(!(this.currentIndex==null||!t)){if(this._pendingSeek!=null){let r=this._pendingSeek;this._pendingSeek=null,this._eng().seekTo(r*t);return}this.progress=Math.min(Math.max(e/t,0),1),!this._raf&&(this._raf=requestAnimationFrame(()=>{this._raf=0,this._drawRow(this.currentIndex),this._paintSlider()}))}}_onEnd(){let e=this.sounds[this.currentIndex];this._emit("end",{sound:e,index:this.currentIndex}),this.options.onEnd?.(e,this),!(this.options.autoAdvance&&this._step(1))&&(this.progress=0,this._setPlaying(!1))}_onEngineError(e){let t=this.currentIndex,r=t==null?void 0:this.sounds[t];t!=null&&this.rows[t]?.classList.add("is-error"),this._setPlaying(!1),r&&!this._cued&&this.$?.status&&(this.$.status.textContent=m(this.strings.playError,{title:r.title})),this._emit("error",{error:e,sound:r,index:t}),this.options.onError?.(e,this)}_setPlaying(e){this.playing=e,e&&(this._cued=!1);let t=this.currentIndex;if(t==null)return;e&&this.rows[t]?.classList.remove("is-error"),this._paintRow(t);let r=this._announced??null;if(e){if(r===t)return;r!=null&&this._announce("pause",r),this._announced=t,this._announce("play",t)}else r!=null&&(this._announced=null,this._announce("pause",r))}_announce(e,t){let r=this.sounds[t];r&&(e==="play"&&this.$?.status&&(this.$.status.textContent=m(this.strings.nowPlaying,{title:r.title})),this._emit(e,{sound:r,index:t}),(e==="play"?this.options.onPlay:this.options.onPause)?.(r,this))}_paintRow(e){let t=this.rows[e];if(!t)return;let r=e===this.currentIndex,s=r&&this.playing;t.classList.toggle("is-current",r),t.classList.toggle("is-playing",s);let o=t.querySelector(".ws-play");o&&(o.setAttribute("aria-pressed",String(s)),o.setAttribute("aria-label",m(s?this.strings.pause:this.strings.play,{title:this.sounds[e].title})));let i=t.querySelector(".ws-wave");i&&(i.tabIndex=r&&t===this._active?0:-1,r||(i.setAttribute("aria-valuenow","0"),i.removeAttribute("aria-valuetext"))),this._drawRow(e)}_paintSlider(){let e=this.currentIndex,t=e==null?null:this.rows[e]?.querySelector(".ws-wave");if(!t)return;t.setAttribute("aria-valuenow",String(Math.round(this.progress*100)));let r=this._eng()?.audio,s=Number.isFinite(r?.duration)&&r.duration>0?r.duration:this.sounds[e].duration;s&&t.setAttribute("aria-valuetext",m(this.strings.seekValue,{time:Se(this.progress*s),duration:k(s)}))}_emit(e,t={}){Le(this.container,e,{...t,instance:this}),this.dispatchEvent(new Event(e))}get current(){return this.currentIndex==null||this._cued?null:this.sounds[this.currentIndex]}destroy(e={}){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._eng()?.destroy()}catch{}this.engine=null,this.$?.engine?.querySelector(":scope > [data-ws-engine-mount]")?.remove(),this._originalHTML!=null?this.container.innerHTML=this._originalHTML:e.restore&&this._adoptedHTML!=null&&(this.container.innerHTML=this._adoptedHTML),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(e=document){if(typeof document>"u")return[];let t=e||document,r=[...t.matches?.("[data-waveform-sounds]")?[t]:[],...t.querySelectorAll("[data-waveform-sounds]")],s=[];for(let o of r)if(!(o.dataset.wsInitialized==="true"||n.instances.has(o)))try{s.push(new n(o))}catch(i){console.error(`${g} Failed to initialise:`,i,o)}return s}static getInstance(e){let t=typeof e=="string"?document.querySelector(e):e;return t&&n.instances.get(t)||null}static prune(){for(let[e,t]of n.instances)e.isConnected||t.destroy()}};var Ze=["player","manifest","search","filters","sorts","showCount","menuSearch","idPrefix","urlState","loopToggle","pageSize","maxTypeChips","columns","waveformStyle","waveformColor","progressColor","barWidth","barGap","loop","autoAdvance","arrowAudition","strings","playerOptions"],ge=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);function qt(n){let e={};for(let t of Ze){let r=ge(t),s=n.getAttribute(r)??n.getAttribute(`data-${r}`);s!=null&&(e[t]=s)}return J({dataset:e})}var zt=typeof HTMLElement>"u"?class{}:HTMLElement,Q=class extends zt{static get observedAttributes(){return Ze.flatMap(e=>[ge(e),`data-${ge(e)}`])}connectedCallback(){if(this._leaving!==void 0){clearTimeout(this._leaving),this._leaving=void 0;return}this.sounds||this._build()}disconnectedCallback(){clearTimeout(this._leaving),this._leaving=setTimeout(()=>{this._leaving=void 0,this.isConnected||this._teardown()},0)}attributeChangedCallback(e,t,r){if(!this.sounds||t===r)return;let s=e.replace(/^data-/,"")==="manifest"?"manifest":"rebuild";if(this._pending){s==="manifest"&&(this._pending=s);return}this._pending=s,queueMicrotask(()=>{let o=this._pending;this._pending=void 0,this.sounds&&this._rebuild(o==="manifest")})}_wsOptions(){return qt(this)}_build(e={}){h.getInstance(this)?.destroy({restore:!0});try{this.sounds=new h(this,e)}catch(t){this.sounds=null,console.error(`${g} Failed to initialise:`,t,this)}}_teardown(){this.sounds?.destroy({restore:!0}),this.sounds=null}_rebuild(e){let t=e||!this.sounds.$?void 0:this.sounds.sounds.slice();this._teardown(),this.innerHTML="",this._build(t?{sounds:t}:{})}};function X(n="waveform-sounds"){if(typeof customElements>"u")return;let e=customElements.get(n);if(e)return e;let t=class extends Q{};return customElements.define(n,t),t}h.utils={encodePeaks:D,decodePeaks:te,normalizeKey:R,normalizeSounds:x,parseManifest:q,facets:w,matches:z,sortSounds:H,formatDuration:k,renderSounds:P};h.DEFAULT_OPTIONS=Y;h.DEFAULT_STRINGS=S;h.defineElement=X;typeof window<"u"&&(window.WaveformSounds=h);var Z=h;var Zn=Z;typeof document<"u"&&document.documentElement?.dataset?.waveformAutoinit!=="false"&&(X(),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Z.init(),{once:!0}):Z.init());})();
1
+ "use strict";(()=>{var St=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function E(n){return n==null?"":String(n).replace(/[&<>"']/g,e=>St[e])}var vt=/[^\p{L}\p{N}\p{M}]+/u,_t=/\p{Mn}/gu,xt=Object.freeze([[768,879],[1425,1479],[1552,1562],[1611,1631],[1648,1648],[6832,6911],[7616,7679],[8400,8447],[65056,65071]]);function Et(n){let e=n.codePointAt(0)??0;return xt.some(([t,r])=>e>=t&&e<=r)}function M(n){return!n||typeof n!="string"?"":n.toLowerCase().normalize("NFD").replace(_t,e=>Et(e)?"":e).normalize("NFC")}function K(n){return M(n).split(vt).filter(e=>e!=="")}function Te(n,e){let t=Array.from(n??""),r=Array.from(e??""),s=[],o=Array.from({length:r.length+1},(i,a)=>a);for(let i=1;i<=t.length;i++){let a=[i];for(let l=1;l<=r.length;l++){let d=t[i-1]===r[l-1]?0:1;a[l]=Math.min(o[l]+1,a[l-1]+1,o[l-1]+d),i>1&&l>1&&t[i-1]===r[l-2]&&t[i-2]===r[l-1]&&(a[l]=Math.min(a[l],s[l-2]+1))}s=o,o=a}return o[r.length]}function Le(n,e,t={}){let r=t.fuzzyFrom??4,s=M(n),o=K(n);return K(e).every(i=>{if(s.includes(i))return!0;let a=Array.from(i).length;return a<r?!1:o.some(l=>Te(i,l)<=1||Te(i,Array.from(l).slice(0,a).join(""))<=1)})}var Re={C:0,"B#":0,"C#":1,Db:1,D:2,"D#":3,Eb:3,E:4,Fb:4,"E#":5,F:5,"F#":6,Gb:6,G:7,"G#":8,Ab:8,A:9,"A#":10,Bb:10,B:11,Cb:11},Mt=["C","Db","D","Eb","E","F","F#","G","Ab","A","Bb","B"],Tt=["Cm","C#m","Dm","Ebm","Em","Fm","F#m","Gm","G#m","Am","Bbm","Bm"],Lt=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],Rt=["C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"];function L(n){let e=/^([A-G][#b]?)(m?)$/.exec(String(n??""));return!e||Re[e[1]]===void 0?null:{root:e[1],pitch:Re[e[1]],minor:e[2]==="m"}}function I(n){let e=L(n);return e?`${e.pitch}${e.minor?"m":""}`:n}function ke(n,e,t=!0){return n===e||t&&!!n&&I(n)===I(e)}function O(n){if(!n)return 1/0;let e=L(n);return e?e.pitch*2+(e.minor?1:0):1e3}function Ae(n){let e=L(n);if(!e)return n?[n]:[];let t=e.minor?"m":"";return[...new Set([n,Lt[e.pitch]+t,Rt[e.pitch]+t])]}function kt(n){let e=0;for(let o of n.values())o>e&&(e=o);let t=[...n].filter(([,o])=>o===e).map(([o])=>o).sort();if(t.length===1)return t[0];let r=L(t[0]),s=r?(r.minor?Tt:Mt)[r.pitch]:"";return t.includes(s)?s:t[0]}function Ce(n,e=!0){let t=new Map;for(let o of n){if(!o)continue;let i=e?I(o):o,a=t.get(i)??new Map;t.set(i,a),a.set(o,(a.get(o)||0)+1)}let r=[],s={};for(let o of t.values()){let i=kt(o);r.push(i);let a=[...o.keys()].filter(l=>l!==i).sort();a.length&&(s[i]=a)}return r.sort((o,i)=>O(o)-O(i)||o.localeCompare(i)),{keys:r,aliases:s}}function q(n,e,t=!0){if(!n)return"";if(e.includes(n))return n;if(!t)return"";let r=I(n);return e.find(s=>I(s)===r)??""}function z(n){if(!Array.isArray(n))return"";let e="";for(let t of n){let r=Math.round(Math.min(Math.max(Number(t)||0,0),1)*255);e+=(r<16?"0":"")+r.toString(16)}return e}var He="wp1:";function At(n){if(!n||!/^[\w-]+$/.test(n)||n.length%4===1)return null;try{let e=atob(n.replace(/-/g,"+").replace(/_/g,"/")),t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r)/255;return t}catch{return null}}function oe(n,e=1){if(n==null||n==="")return null;if(typeof n=="string"){if(n.startsWith(He))return At(n.slice(He.length));if(!/^[0-9a-f]+$/i.test(n)||n.length%2)return null;let s=new Array(n.length/2);for(let o=0;o<s.length;o++)s[o]=parseInt(n.slice(o*2,o*2+2),16)/255;return s}if(!Array.isArray(n))return null;let t=Number(e)>0?Number(e):1,r=n.map(s=>Math.min(Math.max((Number(s)||0)/t,0),1));return r.length?r:null}function v(n){if(n==null)return"";let e=String(n).trim(),t=e.match(/^([A-Ga-g])[\s_-]*([#♯b♭]?)[\s_-]*(m|min|minor|maj|major)?$/i);if(!t)return e;let r=t[1].toUpperCase(),s=t[2]==="\u266F"?"#":t[2]==="\u266D"?"b":t[2],o=t[3]&&/^m(in(or)?)?$/i.test(t[3])&&t[3]!=="M";return r+s+(o?"m":"")}function _(n){if(n==null||n==="")return"";let e=Number(n);if(!Number.isFinite(e)||e<0)return"";if(e>0&&e<.95)return`${Math.max(.1,Math.round(e*10)/10).toFixed(1)}s`;let t=e<1?Math.ceil(e):Math.floor(e);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function Ie(n){let e=Number.isFinite(n)&&n>0?Math.floor(n):0,t=Math.floor(e/3600),r=Math.floor(e%3600/60),s=String(e%60).padStart(2,"0");return t?`${t}:${String(r).padStart(2,"0")}:${s}`:`${r}:${s}`}function Ct(n){if(n==null||n==="")return null;if(typeof n=="number")return Number.isFinite(n)&&n>=0?n:null;let e=String(n).trim();return/^\d+(\.\d+)?$/.test(e)?Number(e):/^\d+(\.\d+)?(:\d+(\.\d+)?)+$/.test(e)?e.split(":").map(Number).reduce((r,s)=>r*60+s,0):null}function Ht(n){let t=(String(n||"").split(/[?#]/)[0].split("/").pop()||"").replace(/\.[a-z0-9]+$/i,"");try{t=decodeURIComponent(t)}catch{}return t.replace(/[_]+/g," ").replace(/\s+/g," ").trim()}function ie(n,e,t=1){if(!n||typeof n!="object"||!n.url)return null;let r=Number(n.bpm),s=Array.isArray(n.tags)?n.tags.map(o=>String(o).trim()).filter(Boolean):typeof n.tags=="string"?n.tags.split(",").map(o=>o.trim()).filter(Boolean):[];return{id:n.id!=null&&n.id!==""?String(n.id):`sound-${e+1}`,url:String(n.url),title:n.title?String(n.title):Ht(n.url),type:n.type?String(n.type):"",bpm:Number.isFinite(r)&&r>0?Math.round(r*100)/100:null,key:v(n.key),duration:Ct(n.duration),tags:s,peaks:oe(n.peaks,t),waveform:n.waveform?String(n.waveform):null,download:n.download?String(n.download):null,loop:It(n.loop)}}var Oe=["loop","one-shot"];function It(n){return n===!0||n===1||n==="true"||n==="1"}function j(n){let e=Array.isArray(n)?n:Array.isArray(n?.sounds)?n.sounds:[],t=Array.isArray(n)?1:Number(n?.peakScale)||1;return S(e,t)}function S(n,e=1){let t=new Set,r=[];return(Array.isArray(n)?n:[]).forEach((s,o)=>{let i=ie(s,o,e);if(!i)return;let a=i.id,l=2;for(;t.has(a);)a=`${i.id}-${l++}`;i.id=a,t.add(a),r.push(i)}),r}function R(n,e={}){let t=new Map,r=[],s=1/0,o=-1/0,i=!1,a=0;for(let d of n)d.type&&t.set(d.type,(t.get(d.type)||0)+1),d.key&&r.push(d.key),d.bpm!=null&&(s=Math.min(s,d.bpm),o=Math.max(o,d.bpm)),d.duration!=null&&(i=!0),d.loop&&a++;let l=Ce(r,e.mergeEnharmonicKeys!==!1);return{types:[...t].map(([d,c])=>({name:d,count:c})),keys:l.keys,keyAliases:l.aliases,bpm:s===1/0?null:{min:s,max:o},hasDuration:i,loops:a,oneShots:n.length-a}}function U(n,e={},t={}){let r=t.mergeEnharmonicKeys!==!1;if(e.type&&n.type!==e.type||e.key&&!ke(n.key,v(e.key),r)||e.loop==="loop"&&!n.loop||e.loop==="one-shot"&&n.loop)return!1;let s=Number(e.bpmMin),o=Number(e.bpmMax);if((e.bpmMin!=null&&e.bpmMin!==""&&Number.isFinite(s)||e.bpmMax!=null&&e.bpmMax!==""&&Number.isFinite(o))&&(n.bpm==null||e.bpmMin!=null&&e.bpmMin!==""&&n.bpm<s||e.bpmMax!=null&&e.bpmMax!==""&&n.bpm>o))return!1;let i=K(e.query||"");if(i.length){let a=[n.title,n.type,...r?Ae(n.key):[n.key],...n.tags||[]].join(" "),l=M(a),d=i.filter(c=>!(/^\d+$/.test(c)&&!l.includes(c)&&n.bpm!=null&&Math.round(n.bpm)===Number(c)));if(d.length&&!Le(a,d.join(" ")))return!1}return!0}var F=["default","title","bpm","key","duration"],Ot={default:()=>!0,title:()=>!0,bpm:n=>n.bpm!==null,key:n=>n.keys.length>0,duration:n=>n.hasDuration};function N(n,e){return n.filter(t=>Ot[t]?.(e))}function k(n,e="default"){let t=n.map((o,i)=>({s:o,i})),r=o=>o??1/0,s={title:(o,i)=>o.s.title.localeCompare(i.s.title,void 0,{numeric:!0,sensitivity:"base"}),bpm:(o,i)=>r(o.s.bpm)-r(i.s.bpm),key:(o,i)=>O(o.s.key)-O(i.s.key),duration:(o,i)=>r(o.s.duration)-r(i.s.duration)}[e];return s&&t.sort((o,i)=>s(o,i)||o.i-i.i),t.map(o=>o.s)}function Ft(n){let e=n.getBoundingClientRect();if(!e.width||!e.height)return null;let t=Math.min(window.devicePixelRatio||1,3),r=Math.round(e.width*t),s=Math.round(e.height*t);return n.width!==r&&(n.width=r),n.height!==s&&(n.height=s),{width:e.width,height:e.height,dpr:t}}function ae(n,e){if(!n?.length||e<=0)return[];if(n.length===e)return n;let t=new Array(e);if(e>n.length){let s=n.length-1,o=n.length/e;for(let i=0;i<e;i++){let a=Math.min(Math.max((i+.5)*o-.5,0),s),l=Math.floor(a),d=a-l;t[i]=l>=s?n[s]:n[l]+(n[l+1]-n[l])*d}return t}let r=n.length/e;for(let s=0;s<e;s++){let o=Math.floor(s*r),i=Math.max(o+1,Math.floor((s+1)*r)),a=0;for(let l=o;l<i&&l<n.length;l++)n[l]>a&&(a=n[l]);t[s]=a}return t}function Nt(n,e,t,r){let s=r.barWidth+r.barGap,o=ae(n,Math.max(1,Math.floor((e+r.barGap)/s))),i=o.reduce((l,d)=>d>l?d:l,0),a=i>0?1/i:1;return o.map((l,d)=>{let c=Math.max(l*a,.04);if(r.style==="bars"){let H=Math.max(1,c*t);return{x:d*s,y:t-H,w:r.barWidth,h:H}}let h=Math.max(1,c*(t-2));return{x:d*s,y:t/2-h/2,w:r.barWidth,h}})}function Fe(n,e,t,r){let s=Ft(n),o=s&&n.getContext&&n.getContext("2d");if(!o)return;let{width:i,height:a,dpr:l}=s;if(o.setTransform(l,0,0,l,0,0),o.clearRect(0,0,i,a),!e?.length){o.fillStyle=r.color,o.fillRect(0,Math.floor(a/2),i,1);return}let d=new Path2D;for(let h of Nt(e,i,a,r))d.rect(h.x,h.y,h.w,h.h);o.fillStyle=r.color,o.fill(d);let c=Math.min(Math.max(t,0),1)*i;c>0&&(o.save(),o.beginPath(),o.rect(0,0,c,a),o.clip(),o.fillStyle=r.progressColor,o.fill(d),o.restore())}var $t=["onLoad","onPlay","onPause","onEnd","onTimeUpdate","onError"],Pt=["duration","downloadUrl","downloadName"];function Ne(n,e,t){let r=n||{},s=e==="strip",o={height:s?48:32,waveformStyle:s?"mirror":"bars",preload:"metadata",singlePlay:!0,...r,audioMode:"self",loop:!1,showLoop:!1};for(let i of Pt)delete o[i];for(let i of $t)o[i]=(...a)=>{t[i]?.(...a),typeof r[i]=="function"&&r[i](...a)};return o}function Wt(n,e){return e==="strip"&&n.waveform||n.peaks||null}function le(n,e,t,r){let s={waveform:Wt(n,e),autoplay:t};return r&&(s.preload=r),n.duration!=null&&n.duration>0&&(s.duration=n.duration),n.download&&(s.downloadUrl=n.download),s}function Dt(n,e){let t=M(String(e??"")).trim();return!t||M(String(n??"")).includes(t)}function $e(n,e,t){return Math.max(0,Math.min(t-1,n+e))}function T(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 ue=n=>n.search||n.list||n.pop.querySelector("input")||n.pop.querySelector("button"),de=(n,e=!1)=>[...n.list.querySelectorAll('[role="option"]')].filter(t=>!e||!t.hidden),G=class{constructor(e,{onPick:t,signal:r}){this.container=e,this.onPick=t,this.menus=Object.fromEntries([...e.querySelectorAll("[data-ws-menu]")].map(s=>[s.dataset.wsMenu,s])),this.openMenu=null,this._bind(r)}_bind(e){let t={signal:e};for(let[r,s]of Object.entries(this.menus)){let o=T(s);if(o.button.addEventListener("click",()=>this.openMenu===s?this.close(!0):this.open(s),t),o.button.addEventListener("keydown",i=>{(i.key==="ArrowDown"||i.key==="ArrowUp")&&(i.preventDefault(),this.open(s))},t),!o.list){o.pop.addEventListener("keydown",i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),this.close(!0))},t);continue}o.list.addEventListener("click",i=>{let a=i.target.closest('[role="option"]');a&&this._pick(r,a.dataset.value)},t),o.list.addEventListener("mousedown",i=>i.preventDefault(),t),o.search?.addEventListener("input",()=>this._filter(s,o.search.value),t),ue(o).addEventListener("keydown",i=>this._onKey(i,r,s),t)}document.addEventListener("pointerdown",r=>{this.openMenu&&!this.openMenu.contains(r.target)&&this.close(!1)},t),this.container.addEventListener("focusout",r=>{this.openMenu&&!this.openMenu.contains(r.relatedTarget)&&this.close(!1)},t)}open(e){this.openMenu&&this.openMenu!==e&&this.close(!1);let t=T(e);t.button.setAttribute("aria-expanded","true"),t.pop.hidden=!1,this.openMenu=e,t.search&&(t.search.value="",this._filter(e,"")),e.classList.remove("ws-menu--end"),t.pop.getBoundingClientRect().right>this.container.getBoundingClientRect().right+1&&e.classList.add("ws-menu--end"),t.list&&this._activate(e,t.list.querySelector('[role="option"][aria-selected="true"]')),ue(t)?.focus()}close(e){let t=this.openMenu;if(!t)return;this.openMenu=null;let r=T(t);r.pop.hidden=!0,r.button.setAttribute("aria-expanded","false"),e&&r.button.focus()}setValue(e,t){let r=this.menus[e];if(!r)return;let s=T(r);if(!s.list)return;let o=null;for(let i of de(s)){let a=i.dataset.value===String(t??"");i.setAttribute("aria-selected",String(a)),a&&(o=i.querySelector(".ws-menu-text")?.textContent??"")}o!==null&&(s.value.textContent=o)}_filter(e,t){let r=T(e),s=null;for(let o of de(r))o.hidden=!Dt(`${o.textContent} ${o.dataset.alt??""}`,t),o.hidden||(s??=o);r.none.hidden=s!==null,this._activate(e,s)}_activate(e,t){let r=T(e);for(let o of r.list.querySelectorAll(".is-active"))o.classList.remove("is-active");let s=ue(r);if(!t||t.hidden){s.removeAttribute("aria-activedescendant");return}t.classList.add("is-active"),s.setAttribute("aria-activedescendant",t.id),t.scrollIntoView?.({block:"nearest"})}_onKey(e,t,r){let s=T(r),o=de(s,!0),i=o.indexOf(s.list.querySelector(".is-active")),a=d=>{e.preventDefault(),this._activate(r,o[d])},l=e.target.matches("input");switch(e.key){case"ArrowDown":return a($e(i,1,o.length));case"ArrowUp":return a($e(i,-1,o.length));case"Home":return l?void 0:a(0);case"End":return l?void 0:a(o.length-1);case"Enter":e.preventDefault(),i>=0&&this._pick(t,o[i].dataset.value);return;case"Escape":return e.preventDefault(),e.stopPropagation(),this.close(!0);case"Tab":return this.close(!1);default:return}}_pick(e,t){this.close(!0),this.onPick(e,t)}};var f="[WaveformSounds]";function ce(n,e=0,t=1){return Math.min(Math.max(n,e),t)}function Pe(n,e){return e&&e.width?ce((n-e.left)/e.width):0}function We(n){return!!n&&(n.isContentEditable||/^(INPUT|SELECT|TEXTAREA)$/.test(n.tagName))}function De(n,e,t){let r=new CustomEvent(`waveformsounds:${e}`,{bubbles:!0,composed:!0,detail:t});return n.dispatchEvent(r),r}function Be(n){let e=5381;for(let t of n)e=e*33+t.codePointAt(0)>>>0;return e}var Ke=.1;function qe(n,e,t){if(!t)return null;switch(n){case"ArrowDown":return e+1<t?e+1:null;case"ArrowUp":return e>0?e-1:"search";case"Home":return 0;case"End":return t-1;default:return null}}function ze(n,e){return e!=="ArrowRight"&&e!=="ArrowLeft"?null:ce(n+(e==="ArrowRight"?Ke:-Ke),0,je)}var je=.999;function Ue(n){return n==="Home"?0:n==="End"?je:null}var A=50;function Ge(n,e,t){return Math.min(n,e===1/0?t:e)}function Ve(n){return n>0?n:A}function Ye(n,e){return e<n?n:Math.ceil((e+1)/A)*A}function Je(n,e){return e>=n?e+1:n}function $(n){return n?{min:Math.floor(n.min),max:Math.ceil(n.max)}:null}function Qe(n,e,t){let r=Math.min(n,e),s=Math.max(n,e);return{bpmMin:r>t.min?String(r):"",bpmMax:s<t.max?String(s):""}}function P(n,e){let t=(o,i)=>{let a=Number(o);return o===""||o==null||!Number.isFinite(a)?i:Math.min(Math.max(a,e.min),e.max)},r=t(n.bpmMin,e.min),s=t(n.bpmMax,e.max);return r<=s?{lo:r,hi:s}:{lo:s,hi:r}}function pe(n,e){let t=e.max-e.min;return t>0?Math.min(Math.max((n-e.min)/t,0),1):0}function Xe(n){return n.bpmMin!=null&&n.bpmMin!==""||n.bpmMax!=null&&n.bpmMax!==""}var b={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",anyBpm:"Any BPM",bpmRange:"{min}\u2013{max} BPM",sort:"Sort",sortBy:"Sort by",sortDefault:"Default",sortTitle:"Name",sortBpm:"BPM",sortKey:"Key",sortDuration:"Length",loop:"Loop",loopFilter:"Loops or one-shots",loops:"Loops",oneShots:"One-shots",isLoop:"Loop",play:"Play {title}",pause:"Pause {title}",seek:"Seek {title}",seekValue:"{time} of {duration}",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}",playError:"Could not play {title}",loadError:"Could not load the sounds.",noSounds:"No sounds.",rowBpm:"{bpm} BPM",rowKey:"key {key}",rowDuration:"{duration}",keyMajor:"{note} major",keyMinor:"{note} minor",noteSharp:"{note} sharp",noteFlat:"{note} flat",listSeparator:", "},Ze={default:"sortDefault",title:"sortTitle",bpm:"sortBpm",key:"sortKey",duration:"sortDuration"};function m(n,e={}){return String(n).replace(/\{(\w+)\}/g,(t,r)=>r in e?String(e[r]):t)}function V(n,e,t=b){if(!Xe(n))return t.anyBpm;let{lo:r,hi:s}=P(n,e);return m(t.bpmRange,{min:r,max:s})}function Y(n,e,t=b){return n!==e?m(t.countFiltered,{count:n,total:e}):e===1?t.countOne:m(t.count,{count:e})}function Bt(n,e=b){let t=L(n);if(!t)return n;let r=t.root[0],s=t.root.slice(1),o=s==="#"?m(e.noteSharp,{note:r}):s==="b"?m(e.noteFlat,{note:r}):r;return m(t.minor?e.keyMinor:e.keyMajor,{note:o})}function et(n,e,t=b){let r=[];for(let s of e)if(s==="type"&&n.type)r.push(n.type);else if(s==="bpm"&&n.bpm!=null)r.push(m(t.rowBpm,{bpm:n.bpm}));else if(s==="key"&&n.key)r.push(m(t.rowKey,{key:Bt(n.key,t)}));else if(s==="duration"){let o=_(n.duration);o&&r.push(m(t.rowDuration,{duration:o}))}return n.loop&&r.push(t.isLoop),r.join(t.listSeparator)}var tt=["type","key","bpm","loop"],nt=["type","bpm","key","duration"],y={player:"inline",search:!0,filters:[...tt],sorts:[...F],loopToggle:!0,showCount:!0,menuSearch:8,pageSize:50,columns:[...nt],maxTypeChips:10,mergeEnharmonicKeys:!0},Q=[...Object.keys(y),"idPrefix","loop","strings"];function he(n){let e={};for(let t of Q){let r=n?.[t];r!=null&&(e[t]=r)}return e}function J(n){let e={};for(let t in n??{})n[t]!==void 0&&(e[t]=n[t]);return e}function me(n,e,t){return Array.isArray(n)?n.filter(r=>e.includes(r)):t}function fe(n,e){let t=Number(n);return Number.isFinite(t)&&t>=0?Math.floor(t):e}function C(n={}){let e={...y,...J(n)};return{...e,player:e.player==="strip"?"strip":"inline",filters:me(e.filters,tt,y.filters),sorts:me(e.sorts,F,y.sorts),columns:me(e.columns,nt,y.columns),menuSearch:fe(e.menuSearch,y.menuSearch),maxTypeChips:fe(e.maxTypeChips,y.maxTypeChips),pageSize:fe(e.pageSize,y.pageSize),mergeEnharmonicKeys:e.mergeEnharmonicKeys!==!1,strings:{...b,...J(n.strings)}}}var X={...y,sounds:null,manifest:null,waveformStyle:"mirror",waveformColor:null,progressColor:null,barWidth:2,barGap:1,loop:null,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 x(n){if(n===""||n==="true")return!0;if(n==="false")return!1}function ge(n){if(n!=null)return n.split(",").map(e=>e.trim()).filter(Boolean)}function W(n){return n===void 0||n===""?void 0:Number(n)}function Kt(n){if(n===void 0)return;let e=x(n);return e===void 0?n:e}function rt(n,e){if(n)try{return JSON.parse(n)}catch{console.warn(`${f} Ignoring invalid JSON in data-${e}`);return}}function Z(n){let e=n.dataset||{},t={player:e.player||void 0,manifest:e.manifest||void 0,search:x(e.search),filters:ge(e.filters),sorts:ge(e.sorts),showCount:x(e.showCount),menuSearch:W(e.menuSearch),idPrefix:e.idPrefix||void 0,urlState:Kt(e.urlState),loopToggle:x(e.loopToggle),pageSize:W(e.pageSize),maxTypeChips:W(e.maxTypeChips),columns:ge(e.columns),mergeEnharmonicKeys:x(e.mergeEnharmonicKeys),waveformStyle:e.waveformStyle||void 0,waveformColor:e.waveformColor||void 0,progressColor:e.progressColor||void 0,barWidth:W(e.barWidth),barGap:W(e.barGap),loop:x(e.loop),autoAdvance:x(e.autoAdvance),arrowAudition:x(e.arrowAudition),strings:rt(e.strings,"strings"),playerOptions:rt(e.playerOptions,"player-options")};for(let r of Object.keys(t))t[r]===void 0&&delete t[r];return t}function st(...n){let e={};for(let t of n)if(t)for(let r in t)t[r]!==null&&t[r]!==void 0&&(e[r]=t[r]);return e}var qt=new Set(["input","br","img"]);function p(n){return E(n??"")}function zt(n={}){let e="";for(let[t,r]of Object.entries(n))r===!0?e+=` ${t}`:r!==!1&&r!=null&&(e+=` ${t}="${E(r)}"`);return e}function u(n,e={},...t){let r=`<${n}${zt(e)}>`;return qt.has(n)?r:r+t.flat(1/0).filter(s=>s!=null&&s!==!1&&s!=="").join("")+`</${n}>`}var ot={play:"M8 5.5v13l11-6.5z",pause:"M7 5h3.5v14H7zM13.5 5H17v14h-3.5z",search:"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:"M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z",check:"M9.5 16.2 5.3 12l-1.4 1.4 5.6 5.6 11-11-1.4-1.4z",download:"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:"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"},be=Object.keys(ot);function it(n,e){return`${n}-i-${e}`}function ee(n,e){let t=be.filter(r=>e.includes(r)).map(r=>`<symbol id="${E(it(n,r))}" viewBox="0 0 24 24"><path d="${ot[r]}"/></symbol>`).join("");return`<svg class="ws-sprite" data-ws-sprite="${E(n)}" width="0" height="0" aria-hidden="true" focusable="false">${t}</svg>`}function w(n,e,t=""){return`<svg class="${t?`ws-icon ${t}`:"ws-icon"}" aria-hidden="true" focusable="false"><use href="#${E(it(n,e))}"/></svg>`}function ye(n){let e=[n.length,...n.map(t=>t.url)].join("|");return`ws${Be(e).toString(36)}`}function jt(n,e){let t=e.filters.includes("type")&&n.types.length>1,r=N(e.sorts,n);return{types:t?n.types.length>e.maxTypeChips?"menu":"chips":null,key:e.filters.includes("key")&&n.keys.length>1,bpm:e.filters.includes("bpm")&&n.bpm!==null&&n.bpm.max>n.bpm.min,loops:e.filters.includes("loop")&&n.loops>0&&n.oneShots>0,sorts:r.length>1?r:[],search:!!e.search,loop:!!e.loopToggle,count:!!e.showCount}}function we(n,e){return n==null?e.loops>0:!!n}function Ut(n,e){return u("label",{class:"ws-search"},w(e,"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 Gt(n,e){let t=`${e.id}-${n}-list`,r=e.options.find(l=>l.value===e.value)??e.options[0],s=e.placeholder&&e.options.length>e.searchFrom,o=u("button",{type:"button",class:"ws-menu-btn","data-ws-menu-btn":!0,"aria-haspopup":"listbox","aria-expanded":"false","aria-controls":t},e.prefix?u("span",{class:"ws-menu-prefix"},p(e.prefix)):u("span",{class:"ws-sr"},p(`${e.label}: `)),u("span",{class:"ws-menu-value","data-ws-menu-value":!0},p(r.label)),w(e.id,"chevron","ws-menu-chevron")),i=s&&u("input",{type:"search",class:"ws-menu-search","data-ws-menu-search":!0,role:"combobox","aria-expanded":"true","aria-controls":t,"aria-autocomplete":"list","aria-label":e.placeholder,placeholder:e.placeholder,autocomplete:"off",spellcheck:"false"}),a=e.options.map((l,d)=>u("li",{role:"option",id:`${e.id}-${n}-${d}`,class:"ws-menu-option","data-value":l.value,"data-alt":l.alt,"aria-selected":String(l===r)},w(e.id,"check","ws-menu-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},o,u("div",{class:"ws-menu-pop","data-ws-menu-pop":!0,hidden:!0},i,u("ul",{class:"ws-menu-list",role:"listbox",id:t,"aria-label":e.label,tabindex:"-1","data-ws-menu-list":!0},a),u("p",{class:"ws-menu-none","data-ws-menu-none":!0,hidden:!0},p(e.noMatches))))}function Vt({id:n,s:e,range:t}){let r=`${n}-bpm-pop`,s=(o,i,a)=>u("input",{type:"range",class:"ws-range-input",[o]:!0,"aria-label":i,min:t.min,max:t.max,step:"1",value:a});return u("div",{class:"ws-menu ws-menu--bpm","data-ws-menu":"bpm"},u("button",{type:"button",class:"ws-menu-btn","data-ws-menu-btn":!0,"aria-haspopup":"dialog","aria-expanded":"false","aria-controls":r},u("span",{class:"ws-sr"},p(`${e.bpm}: `)),u("span",{class:"ws-menu-value","data-ws-menu-value":!0},p(V({},t,e))),w(n,"chevron","ws-menu-chevron")),u("div",{class:"ws-menu-pop ws-bpm-pop",id:r,role:"dialog","aria-label":e.bpm,"data-ws-menu-pop":!0,hidden:!0},u("div",{class:"ws-bpm-head"},u("span",{class:"ws-bpm-readout","data-ws-bpm-readout":!0,"aria-live":"polite"},p(m(e.bpmRange,t))),u("button",{type:"button",class:"ws-bpm-clear","data-ws-bpm-clear":!0},p(e.anyBpm))),u("div",{class:"ws-range","data-ws-bpm-range":!0},s("data-ws-bpm-min",e.bpmMin,t.min),s("data-ws-bpm-max",e.bpmMax,t.max)),u("div",{class:"ws-range-ends","aria-hidden":"true"},u("span",{},p(t.min)),u("span",{},p(t.max)))))}function Yt(n){let e=(t,r)=>u("button",{type:"button",class:"ws-seg-btn","data-ws-loop-filter":t,"aria-pressed":String(t==="")},u("span",{},p(r)));return u("div",{class:"ws-seg",role:"group","aria-label":n.loopFilter},e("",n.all),e("loop",n.loops),e("one-shot",n.oneShots))}function Jt(n,e,t){return u("button",{type:"button",class:"ws-loop","data-ws-loop":!0,"aria-pressed":String(e)},w(t,"loop"),u("span",{},p(n.loop)))}function at(n,e,t,r){return u("button",{type:"button",class:"ws-chip","data-ws-type":n,"aria-pressed":String(r)},u("span",{class:"ws-chip-label"},p(e))," ",u("span",{class:"ws-chip-count"},p(t)))}function Qt(n,{o:e,s:t,f:r,total:s,id:o}){let i=(c,h)=>Gt(c,{id:o,searchFrom:e.menuSearch,noMatches:t.noMatches,...h}),a=[n.types==="menu"&&i("type",{label:t.types,value:"",placeholder:t.findType,options:[{value:"",label:t.allTypes,count:s},...r.types.map(c=>({value:c.name,label:c.name,count:c.count}))]}),n.key&&i("key",{label:t.key,value:"",placeholder:t.findKey,options:[{value:"",label:t.anyKey},...r.keys.map(c=>({value:c,label:c,alt:r.keyAliases[c]?.join(" ")}))]}),n.bpm&&Vt({id:o,s:t,range:$(r.bpm)}),n.loops&&Yt(t),n.sorts.length>0&&i("sort",{label:t.sort,prefix:t.sortBy,value:n.sorts[0],options:n.sorts.map(c=>({value:c,label:t[Ze[c]]}))}),n.loop&&Jt(t,we(e.loop,r),o)].filter(Boolean),l=n.types==="chips"&&u("div",{class:"ws-types",role:"group","aria-label":t.types},at("",t.all,s,!0),r.types.map(c=>at(c.name,c.name,c.count,!1))),d=n.count&&u("p",{class:"ws-count","data-ws-count":!0,"aria-live":"polite"},p(Y(s,s,t)));return u("div",{class:"ws-toolbar"},n.search&&Ut(t,o),a.length>0&&u("div",{class:"ws-controls"},a),(l||d)&&u("div",{class:"ws-meta"},l,d))}var Xt={type:n=>p(n.type),bpm:n=>p(n.bpm??""),key:n=>p(n.key),duration:n=>p(_(n.duration))};function Se(n,e,t,r){let s=t.strings,o={title:n.title},i=t.columns.map(d=>u("span",{class:`ws-cell ws-${d}`},Xt[d](n))),a=et(n,t.columns,s),l=a?`${r}-d${e}`:null;return u("li",{class:"ws-row","data-ws-index":e},u("button",{type:"button",class:"ws-play","aria-pressed":"false","aria-label":m(s.play,o),"aria-describedby":l},w(r,"play","ws-icon-play"),w(r,"pause","ws-icon-pause")),u("span",{class:"ws-cell ws-title"},u("span",{class:"ws-title-text"},p(n.title)),n.loop&&u("span",{class:"ws-loop-mark",title:s.isLoop,"aria-hidden":"true"},w(r,"loop"))),i.length>0&&u("span",{class:"ws-cells","aria-hidden":"true"},i),a&&u("span",{class:"ws-sr",id:l},p(a)),t.player==="inline"&&u("span",{class:"ws-wave","aria-hidden":"true"},u("canvas",{class:"ws-canvas"})),n.download&&u("a",{class:"ws-download",href:n.download,download:!0,"aria-label":m(s.download,o)},w(r,"download")))}function Zt(n){let e=n.map((t,r)=>{let s={};return t.id!==`sound-${r+1}`&&(s.id=t.id),s.url=t.url,s.title=t.title,t.type&&(s.type=t.type),t.bpm!=null&&(s.bpm=t.bpm),t.key&&(s.key=t.key),t.duration!=null&&(s.duration=t.duration),t.tags.length&&(s.tags=t.tags),t.peaks&&(s.peaks=z(t.peaks)),t.waveform&&(s.waveform=t.waveform),t.download&&(s.download=t.download),t.loop&&(s.loop=!0),s});return`<script type="application/json" data-ws-sounds>${JSON.stringify(e).replace(/</g,"\\u003c")}<\/script>`}function en(n,e){let t=[];return e.length&&t.push("play","pause"),n.search&&t.push("search"),n.types==="menu"||n.key||n.sorts.length?t.push("chevron","check"):n.bpm&&t.push("chevron"),(n.loop||e.some(r=>r.loop))&&t.push("loop"),e.some(r=>r.download)&&t.push("download"),t}function tn({o:n,s:e,total:t}){let r=n.pageSize>0?n.pageSize:t,s=Math.max(0,t-r),o=n.player==="strip";return[u("p",{class:"ws-empty","data-ws-empty":!0,hidden:!0},p(e.empty)," ",u("button",{type:"button",class:"ws-clear","data-ws-clear":!0},p(e.clear))),u("button",{type:"button",class:"ws-more","data-ws-more":!0,hidden:s===0},p(m(e.showMore,{count:Math.min(s,r)}))),u("div",{class:o?"ws-engine ws-engine--strip":"ws-engine","data-ws-engine":!0,hidden:!o}),u("p",{class:"ws-sr","data-ws-status":!0,"aria-live":"polite"})].join("")}function ve(n,e={}){return _e(S(n),e,!0)}function _e(n,e,t){let r=C(e),s={o:r,s:r.strings,f:R(n,r),total:n.length,id:r.idPrefix||ye(n)},o=jt(s.f,r),i=new Map(n.map((l,d)=>[l,d])),a=k(n,N(r.sorts,s.f)[0]||"default").slice(0,Ve(r.pageSize));return ee(s.id,en(o,n))+Qt(o,s)+u("ul",{class:`ws-list ws-list--${r.player}`,role:"list","data-ws-list":!0},a.map(l=>Se(l,i.get(l),r,s.id)))+tn(s)+(t?Zt(n):"")}function nn(n={}){let e=he(n),t=C(n),r={};for(let s of Q){if(s==="player"||!(s in e))continue;let o=`data-${s.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`)}`;if(s==="strings"){let i=J(e.strings);Object.keys(i).length&&(r[o]=JSON.stringify(i))}else if(s==="loop"||s==="idPrefix")r[o]=String(e[s]);else{let i=t[s];r[o]=Array.isArray(i)?i.join(","):String(i)}}return r}function rn(n,e={},t=""){let r=C(e),s=["waveform-sounds",`waveform-sounds--${r.player}`,t].filter(Boolean).join(" ");return u("div",{class:s,"data-waveform-sounds":!0,"data-player":r.player,...nn(e)},ve(n,e))}var xe=":scope > [data-ws-index]";function lt(n){let e=n.querySelector(":scope > script[data-ws-sounds]");if(!e)return null;try{let t=JSON.parse(e.textContent||"");if(Array.isArray(t))return S(t)}catch{}return console.warn(`${f} Ignoring unreadable sounds JSON (data-ws-sounds)`),null}function ut(n){let e=[...n.querySelectorAll(xe)].sort((r,s)=>Number(r.dataset.wsIndex)-Number(s.dataset.wsIndex)),t=[];for(let r of e){let s=r.dataset,o=ie({id:s.wsId,url:s.url,title:s.title,type:s.type,bpm:s.bpm,key:s.key,duration:s.duration,tags:s.tags,peaks:s.peaks,waveform:s.waveform,download:s.download,loop:s.loop},t.length);if(!o){r.remove();continue}r.dataset.wsIndex=String(t.length),t.push(o)}return t}function dt(n){let e=[];return n.querySelectorAll(xe).forEach(t=>{e[Number(t.dataset.wsIndex)]=t}),e}function D(n){return[...n.querySelectorAll(xe)].filter(e=>!e.hidden)}function ct(n,e){let t=new Set(e);for(let s of[...n.children])t.has(s)||s.remove();let r=n.firstElementChild;for(let s of e)s===r?r=r.nextElementSibling:n.insertBefore(s,r)}function sn(n){let e=String(n??"").trim();if(!e||e==="transparent")return 0;let t=e.match(/\/\s*([\d.]+)(%?)\s*\)$/);if(t)return Number(t[1])/(t[2]?100:1);let r=e.match(/^rgba\(\s*[^,]+,[^,]+,[^,]+,\s*([\d.]+)\s*\)$/);return r?Number(r[1]):1}function pt(n,e=.95){for(let t=n;t&&t.nodeType===1;t=t.parentElement||t.getRootNode?.().host){let r=getComputedStyle(t).backgroundColor;if(sn(r)>e)return r}return"#fff"}function mt(){try{return typeof matchMedia=="function"&&matchMedia("(forced-colors: active)").matches}catch{return!1}}function ft(n){let e=[];for(let t=n.parentElement||n.getRootNode?.()?.host;t;t=t.parentElement||t.getRootNode?.()?.host)e.push(t);return e}function B(n,e){let t=document.createElement("span");t.style.cssText="position:absolute;width:0;height:0;overflow:hidden;visibility:hidden;forced-color-adjust:none",t.style.color=e,n.appendChild(t);let r=getComputedStyle(t).color;return t.remove(),r}function Ee(n){if(!n)return null;let e=typeof n=="string"?`${n}-`:"";return{q:`${e}q`,type:`${e}type`,key:`${e}key`,bpm:`${e}bpm`,loop:`${e}loop`,sort:`${e}sort`}}function on(n){let e=String(n??"").match(/^(\d+(?:\.\d+)?)?-(\d+(?:\.\d+)?)?$/);if(!e||!(e[1]||e[2]))return null;let t=e[1]??"",r=e[2]??"";return t&&r&&Number(t)>Number(r)?{bpmMin:r,bpmMax:t}:{bpmMin:t,bpmMax:r}}function an(n,e){if(!e)return null;let t=s=>s!==""&&Number(s)>=e.min&&Number(s)<=e.max?s:"",r={bpmMin:t(n.bpmMin),bpmMax:t(n.bpmMax)};return r.bpmMin||r.bpmMax?r:null}function ln(n,e){let t=n??"",r=e??"";return t!==""||r!==""?`${t}-${r}`:""}function ht(n,e,t,r,s={}){let o={filter:{},sort:null};if(!e)return o;let i=new URLSearchParams(n),a=i.get(e.q);a&&(o.filter.query=a);let l=i.get(e.type);l&&t.types.some(wt=>wt.name===l)&&(o.filter.type=l);let d=q(v(i.get(e.key)),t.keys,s.mergeEnharmonicKeys!==!1);d&&(o.filter.key=d);let c=on(i.get(e.bpm)),h=c&&t.bpm!==void 0?an(c,t.bpm):c;h&&Object.assign(o.filter,h);let H=i.get(e.loop);Oe.includes(H)&&t.loops>0&&t.oneShots>0&&(o.filter.loop=H);let se=i.get(e.sort);return se&&r.includes(se)&&(o.sort=se),o}function gt(n,e,t,r,s){if(!e)return n;let o=new URL(n),i=(a,l)=>l?o.searchParams.set(a,l):o.searchParams.delete(a);return i(e.q,String(t.query??"").trim()),i(e.type,t.type),i(e.key,t.key),i(e.bpm,ln(t.bpmMin,t.bpmMax)),i(e.loop,t.loop),i(e.sort,r!==s?r:""),o.href}var bt=Object.freeze({query:"",type:"",key:"",bpmMin:"",bpmMax:"",loop:""}),un=120,dn=200,cn=250,g=class n extends EventTarget{static instances=new Map;constructor(e,t={}){super();let r=typeof e=="string"?document.querySelector(e):e;if(!r)throw new Error(`${f} Container not found: ${e}`);this.container=r;let s=r._wsOptions?.()??Z(r);this.options=st(X,t,s),this.options.waveformStyle=this.options.waveformStyle==="bars"?"bars":"mirror",this.strings={...b,...this.options.strings||{}},this.render={...C(this.options),strings:this.strings},this.sounds=[],this.rows=[],this.filter={...bt},this.sortBy="default",this.limit=this._pageSize(),this._budget=this._firstBudget(),this._index=new Map,this._failed=new Set,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(r,this),r.dataset.wsInitialized="true",this.ready=Promise.resolve().then(()=>this._init()).catch(o=>{this.destroyed||(console.error(`${f} Failed to initialise:`,o),this._showLoadError(),this._emit("error",{error:o}),this.options.onError?.(o,this))})}async _init(){let e=this.container,t=e.querySelector("[data-ws-list]");if(t)this._adoptedHTML=e.innerHTML,this.sounds=lt(e)??ut(t);else{if(this._originalHTML=e.innerHTML,this.sounds=await this._loadSounds(),this.destroyed)return;e.innerHTML=_e(this.sounds,{...this.render,idPrefix:this.options.idPrefix||e.id||void 0},!1)}this.destroyed||(this._index=new Map(this.sounds.map((r,s)=>[r,s])),this._addedClasses=["waveform-sounds",`waveform-sounds--${this.render.player}`].filter(r=>!e.classList.contains(r)),e.classList.add(...this._addedClasses),this._facets=R(this.sounds,this.render),this._cacheRefs(),this._bind(),this._observe(),this._resolveColors(),this._loopSet||(this.loop=we(this.options.loop,this._facets)),this._setLoop(this.loop),this._bpmExtent=$(this._facets.bpm),this._sorts=N(this.render.sorts,this._facets),this._sortSet||(this.sortBy=this._sorts[0]||"default"),this._readUrl(),this.filter={...this.filter,key:this._keyEntry(this.filter.key)},this._syncControls(),this._apply(),this._playerClass()&&this._ensureEngine(),this.render.player==="strip"&&this.engine&&this.currentIndex==null&&this._cueFirst(),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 e=this.options.manifest,t=await fetch(e,{signal:this._ctl.signal});if(!t.ok)throw new Error(`${f} Manifest ${e}: HTTP ${t.status}`);let r=await t.json();if(!Array.isArray(r)&&!Array.isArray(r?.sounds))throw new Error(`${f} Manifest ${e}: no "sounds" list`);return j(r)}_showLoadError(){let e=this.container;this.$||e.querySelector("*")||(this._originalHTML??=e.innerHTML,e.innerHTML=u("p",{class:"ws-empty ws-load-error",role:"alert","data-ws-load-error":!0},p(this.strings.loadError)))}_cacheRefs(){let e=r=>this.container.querySelector(r);this.$={list:e("[data-ws-list]"),search:e("[data-ws-search]"),bpmMin:e("[data-ws-bpm-min]"),bpmMax:e("[data-ws-bpm-max]"),bpmRange:e("[data-ws-bpm-range]"),bpmReadout:e("[data-ws-bpm-readout]"),bpmClear:e("[data-ws-bpm-clear]"),bpmLabel:e('[data-ws-menu="bpm"] [data-ws-menu-value]'),loop:e("[data-ws-loop]"),count:e("[data-ws-count]"),empty:e("[data-ws-empty]"),more:e("[data-ws-more]"),engine:e("[data-ws-engine]"),status:e("[data-ws-status]"),chips:[...this.container.querySelectorAll("[data-ws-type]")],loopFilter:[...this.container.querySelectorAll("[data-ws-loop-filter]")]};let t=e("[data-ws-sprite]");this._iconId=t?.dataset.wsSprite??(this.options.idPrefix||this.container.id||ye(this.sounds)),t||this.$.list.insertAdjacentHTML("beforebegin",ee(this._iconId,be)),this.rows=[],this._active=null;for(let r of dt(this.$.list))r&&this._adoptRow(r)}_adoptRow(e){let t=Number(e.dataset.wsIndex);this.rows[t]=e,this._rowStops(e,!1);let r=e.querySelector(".ws-wave");(t===this.currentIndex||this._failed.has(t)||r?.hasAttribute("role"))&&this._paintRow(t),t===this.currentIndex&&this._paintSlider(),this._io?this._io.observe(e):this._drawn?.add(t)}_rowsFor(e){let t=e.filter(r=>!this.rows[r]);if(t.length){let r=document.createElement("template");r.innerHTML=t.map(s=>Se(this.sounds[s],s,this.render,this._iconId)).join("");for(let s of[...r.content.children])this._adoptRow(s)}return e.map(r=>this.rows[r])}_rowStops(e,t){let r=e.querySelector(".ws-play");r&&(r.tabIndex=t?0:-1);let s=e.querySelector(".ws-download");s&&(s.tabIndex=t?0:-1);let o=e.querySelector(".ws-wave");o&&Number(e.dataset.wsIndex)===this.currentIndex&&(o.tabIndex=t?0:-1)}_rove(e){!e||e===this._active||(this._active&&this._rowStops(this._active,!1),this._active=e,this._rowStops(e,!0))}_bind(){let e={signal:this._ctl.signal},t=this.$,r=this.container;r.addEventListener("click",a=>this._onClick(a),e),r.addEventListener("pointerdown",a=>this._onPointerDown(a),e),r.addEventListener("keydown",a=>this._onKey(a),e),t.list.addEventListener("focusin",a=>this._rove(a.target.closest("[data-ws-index]")),e);let s=0,o=0;t.search?.addEventListener("input",()=>{clearTimeout(s),s=setTimeout(()=>this.setFilter({query:t.search.value}),un)},e),t.search?.addEventListener("keydown",a=>{a.key==="ArrowDown"&&(a.preventDefault(),this._focusRow(D(t.list)[0])),a.key==="Escape"&&t.search.value&&(a.preventDefault(),t.search.value="",this.setFilter({query:""}))},e);let i=a=>{let l=Number(t.bpmMin.value),d=Number(t.bpmMax.value);l>d&&(a.value=String(a===t.bpmMin?d:l));let c=Qe(Number(t.bpmMin.value),Number(t.bpmMax.value),this._bpmExtent);this._showBpm(c),clearTimeout(o),o=setTimeout(()=>this.setFilter(c),dn)};t.bpmMin?.addEventListener("input",()=>i(t.bpmMin),e),t.bpmMax?.addEventListener("input",()=>i(t.bpmMax),e),t.bpmClear?.addEventListener("click",()=>{clearTimeout(o),this.setFilter({bpmMin:"",bpmMax:""})},e),this.menus=new G(r,{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()},e)}_onClick(e){let t=e.target,r=t.closest("[data-ws-type]");if(r){this.setFilter({type:r.dataset.wsType});return}let s=t.closest("[data-ws-loop-filter]");if(s){this.setFilter({loop:s.dataset.wsLoopFilter});return}if(t.closest("[data-ws-more]")){this._showMoreFromButton();return}if(t.closest("[data-ws-clear]")){this.clearFilters(),this.$.search?this.$.search.focus():this._focusRow(D(this.$.list)[0]);return}if(t.closest("[data-ws-loop]")){this.setLoop(!this.loop);return}let o=t.closest(".ws-wave");if(o){this._lastPointer==="touch"&&this._seekAt(o,e.clientX);return}let i=t.closest("[data-ws-index]");!i||t.closest(".ws-download")||(this.toggle(Number(i.dataset.wsIndex)),this._focusRowQuietly(i))}_showMoreFromButton(){let e=new Set(D(this.$.list));this.showMore(),this.$.more?.hidden&&this._focusRow(D(this.$.list).find(t=>!e.has(t)))}_onPointerDown(e){this._lastPointer=e.pointerType;let t=e.target.closest(".ws-wave");!t||e.button!==0||e.pointerType==="touch"||(e.preventDefault(),this._seekAt(t,e.clientX))}_seekAt(e,t){let r=e.closest("[data-ws-index]");this._seekRow(Number(r.dataset.wsIndex),Pe(t,e.getBoundingClientRect())),this._focusRowQuietly(r)}_onKey(e){if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey)return;if(e.key==="/"&&!We(e.target)&&this.$.search){e.preventDefault(),this.$.search.focus();return}let t=e.target.closest?.("[data-ws-index]");if(!t)return;let r=Number(t.dataset.wsIndex),o=(e.target.closest(".ws-wave")?Ue(e.key):null)??ze(this.progress,e.key);if(o!==null){if(r!==this.currentIndex||!this.engine)return;e.preventDefault(),this._seekRow(r,o);return}let i=this._shown??[],a=qe(e.key,i.indexOf(this.sounds[r]),Math.min(i.length,this.limit));if(a!==null){if(e.preventDefault(),a==="search"){this.$.search?.focus();return}this._focusRow(this._reveal(a)),this.options.arrowAudition&&this.playing&&this.play(this._index.get(i[a]))}}_reveal(e){let t=this._shown?.[e];if(!t)return;let r=Je(this.limit,e);return r!==this.limit?(this.limit=r,this._apply()):this.limit===1/0&&e>=this._budget&&(this._budget=Ye(this._budget,e),this._layout()),this.rows[this._index.get(t)]}_focusRow(e){e?.querySelector(".ws-play")?.focus()}_focusRowQuietly(e){let t=e?.querySelector(".ws-play");t&&document.activeElement!==t&&t.focus({preventScroll:!0})}_observe(){if(this.render.player!=="inline"||typeof window>"u")return;if(this._drawn=new Set,this._dirty=new Set,"IntersectionObserver"in window?(this._onScreen=new Set,this._io=new IntersectionObserver(r=>{for(let s of r){let o=Number(s.target.dataset.wsIndex);if(!s.isIntersecting){this._onScreen.delete(o);continue}this._onScreen.add(o),!(this._drawn.has(o)&&!this._dirty.has(o))&&(this._drawn.add(o),this._drawRow(o))}},{rootMargin:"200px 0px"}),this.rows.forEach(r=>r&&this._io.observe(r))):this.rows.forEach((r,s)=>r&&this._drawn.add(s)),"ResizeObserver"in window){let r=0;this._ro=new ResizeObserver(([s])=>{let o=Math.round(s.contentRect.width);o!==r&&(r=o,this._redrawAll())}),this._ro.observe(this.$.list)}let e=0,t=()=>{e||(e=requestAnimationFrame(()=>{e=0,this._resolveColors()&&this._redrawAll()}))};this._mo=new MutationObserver(t),this._mo.observe(this.container,{attributes:!0,attributeFilter:["class","data-theme","data-color-scheme"]});for(let r of ft(this.container))this._mo.observe(r,{attributes:!0,attributeFilter:["class","data-theme","data-color-scheme","style"]});for(let r of["(prefers-color-scheme: dark)","(forced-colors: active)"])try{window.matchMedia(r).addEventListener("change",t,{signal:this._ctl.signal})}catch{}}_resolveColors(){let e=this.colors;(this._autoSurface||!getComputedStyle(this.container).getPropertyValue("--ws-surface").trim())&&(this._autoSurface=!0,this.container.style.removeProperty("--ws-surface"),this.container.style.setProperty("--ws-surface",pt(this.container)));let t=mt();return this.colors={wave:(t?B(this.container,"CanvasText"):this.options.waveformColor||B(this.container,"var(--ws-wave-color)"))||"rgba(128,128,128,.5)",progress:(t?B(this.container,"Highlight"):this.options.progressColor||B(this.container,"var(--ws-progress-color)"))||"currentColor"},!e||e.wave!==this.colors.wave||e.progress!==this.colors.progress}_drawRow(e){if(this.render.player!=="inline"||e==null||!this._drawn?.has(e))return;let t=this.rows[e],r=t?.querySelector("canvas");if(!r)return;if(!t.isConnected){this._dirty?.add(e);return}this._dirty?.delete(e);let s=Number(this.options.barGap);Fe(r,this.sounds[e].peaks,e===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(s)?Math.max(0,s):1})}_redrawAll(){this._drawn?.forEach(e=>{this._onScreen&&!this._onScreen.has(e)?this._dirty.add(e):this._drawRow(e)})}_readUrl(){let e=Ee(this.options.urlState);if(!e||typeof location>"u")return;let t=this._facets,{filter:r,sort:s}=ht(location.search,e,{...t,bpm:$(t.bpm)},this._sorts,this.render);this.filter={...this.filter,...r},s&&(this.sortBy=s,this._sortSet=!0)}_queueUrl(){let e=Ee(this.options.urlState);!e||typeof location>"u"||(clearTimeout(this._urlTimer),this._urlTimer=setTimeout(()=>{if(this.destroyed)return;let t=gt(location.href,e,this.filter,this.sortBy,this._sorts?.[0]||"default");t!==location.href&&history.replaceState(history.state,"",t)},cn))}get visible(){return[...this._shown??this._match()]}_match(){return k(this.sounds.filter(e=>U(e,this.filter,this.render)),this.sortBy)}_keyEntry(e){let t=v(e);return this._facets&&q(t,this._facets.keys,this.render.mergeEnharmonicKeys)||t}setFilter(e={}){this.filter={...this.filter,...e},e.key&&(this.filter.key=this._keyEntry(e.key)),this.limit=this._pageSize(),this._budget=this._firstBudget(),this._syncControls(),this._apply()}clearFilters(){this.setFilter(bt)}setSort(e){this._sortSet=!0,this.sortBy=F.includes(e)?e:"default",this.menus?.setValue("sort",this.sortBy),this._apply()}showMore(){this.limit!==1/0&&(this.limit+=this.render.pageSize,this._apply())}_pageSize(){return this.render.pageSize>0?this.render.pageSize:1/0}_firstBudget(){return typeof IntersectionObserver>"u"?1/0:A}_syncControls(){let e=this.$,t=this.filter;if(e){if(e.search&&e.search.value!==t.query&&(e.search.value=t.query),this.menus?.setValue("type",t.type||""),this.menus?.setValue("key",t.key||""),this.menus?.setValue("sort",this.sortBy),e.bpmMin&&e.bpmMax&&this._bpmExtent){let{lo:r,hi:s}=P(t,this._bpmExtent);e.bpmMin.value=String(r),e.bpmMax.value=String(s),this._showBpm(t)}e.chips.forEach(r=>r.setAttribute("aria-pressed",String(r.dataset.wsType===(t.type||"")))),e.loopFilter.forEach(r=>r.setAttribute("aria-pressed",String(r.dataset.wsLoopFilter===(t.loop||""))))}}_showBpm(e){let t=this.$,r=this._bpmExtent;if(!t?.bpmRange||!r)return;let{lo:s,hi:o}=P(e,r);t.bpmLabel&&(t.bpmLabel.textContent=V(e,r,this.strings)),t.bpmReadout&&(t.bpmReadout.textContent=m(this.strings.bpmRange,{min:s,max:o})),t.bpmRange.style.setProperty("--ws-lo",String(pe(s,r))),t.bpmRange.style.setProperty("--ws-hi",String(pe(o,r))),t.bpmRange.classList.toggle("is-min-top",s>=o&&s>r.min),t.bpmRange.classList.toggle("is-active",s>r.min||o<r.max)}_apply(){let e=this.$;if(!e)return;let t=this._match();this._shown=t,this._layout();let r=t.length-Math.min(t.length,this.limit);e.more&&(e.more.hidden=r<=0,e.more.textContent=m(this.strings.showMore,{count:Math.min(r,this.render.pageSize||r)})),e.empty&&(e.empty.hidden=t.length>0,!this.sounds.length&&e.empty.textContent!==this.strings.noSounds&&(e.empty.textContent=this.strings.noSounds)),e.count&&(e.count.textContent=Y(t.length,this.sounds.length,this.strings)),this._cued&&!this.playing&&this._cueFirst(),this._queueUrl(),this._emit("filter",{visible:t.length,total:this.sounds.length,filter:{...this.filter},sort:this.sortBy}),this.options.onFilter?.(t,this)}_layout(){let e=this.$,t=this._shown,r=Ge(t.length,this.limit,this._budget),s=e.list.contains(document.activeElement)?document.activeElement:null,o=this._rowsFor(t.slice(0,r).map(i=>this._index.get(i)));if(ct(e.list,o),s?.isConnected&&document.activeElement!==s&&s.focus({preventScroll:!0}),!this._io&&this._drawn)for(let i of o)this._drawRow(Number(i.dataset.wsIndex));if(!this._active||!this._active.isConnected){let i=o[0];i?(this._rove(i),s&&!s.isConnected&&this._focusRowQuietly(i)):this._active&&(this._rowStops(this._active,!1),this._active=null)}this._watchEnd(r<Math.min(t.length,this.limit)?o[o.length-1]:null)}_watchEnd(e){this._endIo?.disconnect(),!(!e||typeof IntersectionObserver>"u")&&(this._endIo??=new IntersectionObserver(t=>{this.destroyed||!t.some(r=>r.isIntersecting)||(this._budget+=A,this._layout())},{rootMargin:"0px 0px 1200px 0px"}),this._endIo.observe(e))}_indexOf(e){if(e==null){if(this.currentIndex!=null)return this.currentIndex;let r=(this._shown??this._match())[0];return r?this.sounds.indexOf(r):null}if(typeof e=="number")return this.sounds[e]?e:null;let t=typeof e=="object"?this._index.get(e)??this.sounds.indexOf(e):this.sounds.findIndex(r=>r.id===String(e));return t>=0?t:null}_playerClass(){return this.options.playerClass||(typeof window<"u"?window.WaveformPlayer:null)||null}_eng(){return this.engine}_engineMount(){let e=this.$.engine,t=e.querySelector(":scope > [data-ws-engine-mount]");return t||(t=document.createElement("div"),t.setAttribute("data-ws-engine-mount",""),e.appendChild(t)),t}_ensureEngine(){if(this.engine)return this._eng();let e=this._playerClass();if(!e)return console.error(`${f} @arraypress/waveform-player is required: load it before playing (or pass playerClass).`),null;let t=Ne(this.options.playerOptions,this.render.player,{onLoad:()=>this._onEngineLoad(),onPlay:()=>this._setPlaying(!0),onPause:()=>this._setPlaying(!1),onEnd:()=>this._onEnd(),onTimeUpdate:(r,s)=>this._onTime(r,s),onError:r=>this._onEngineError(r)});return this._preload=t.preload,this.engine=new e(this._engineMount(),t),this._eng()}play(e,t={}){if(!this.$){this.ready.then(()=>{this.destroyed||this.play(e,t)});return}let r=this._indexOf(e);if(r==null)return;this._cued=!1;let s=this._ensureEngine();if(!s)return;if(r===this.currentIndex&&s.audio?.src){t.at!=null&&this._seekRow(r,t.at),this.playing||s.play();return}let o=this.currentIndex;this.currentIndex=r,this.progress=0,this._pendingSeek=t.at??null,o!=null&&this._paintRow(o),this._paintRow(r);let i=this.sounds[r];s.loadTrack(i.url,i.title,i.type||null,le(i,this.render.player,!0,this._preload))}_cueFirst(){let e=this._eng(),t=(this._shown??this._match())[0];if(!e||!t)return;let r=this.sounds.indexOf(t);if(r===this.currentIndex)return;this.currentIndex=r,this.progress=0,this._cued=!0;let s=e.audio,o=s&&typeof s.load=="function";o&&(s.load=()=>{});try{e.loadTrack(t.url,t.title,t.type||null,le(t,"strip",!1,"none"))}finally{o&&delete s.load}}pause(){this.engine&&this.playing&&this._eng().pause()}toggle(e){let t=this._indexOf(e);t!=null&&(t===this.currentIndex&&this.playing?this.pause():this.play(t))}next(){this._step(1)}previous(){this._step(-1)}_step(e){let t=this._shown??this._match(),r=this.currentIndex==null||this._cued?-1:t.indexOf(this.sounds[this.currentIndex]),s=t[r+e];return s?(this.$&&this._reveal(r+e),this.play(this.sounds.indexOf(s)),!0):!1}setLoop(e){this._loopSet=!0,this.loop=!!e,this._setLoop(this.loop)}_setLoop(e){this.$?.loop?.setAttribute("aria-pressed",String(e)),this._eng()?.audio&&(this._eng().audio.loop=this._repeats())}_repeats(){return this.loop?!this.sounds.some(t=>t.loop)||!!this.sounds[this.currentIndex]?.loop:!1}_seekRow(e,t){if(e!==this.currentIndex||!this.engine){this.play(e,{at:t});return}let r=this._eng().audio?.duration;if(!Number.isFinite(r)||r<=0){this._pendingSeek=t;return}this._eng().seekTo(t*r),this.progress=t,this._paintRow(e),this._paintSlider(),this.playing||this._eng().play()}_onEngineLoad(){this.currentIndex!=null&&this._markFailed(this.currentIndex,!1),this._eng()?.audio&&(this._eng().audio.loop=this._repeats());let e=this.sounds[this.currentIndex];e&&!e.peaks&&this._eng()?.waveformData?.length&&(e.peaks=ae(this._eng().waveformData,96),this._drawRow(this.currentIndex));let t=this._eng()?.audio?.duration;this._pendingSeek!=null&&Number.isFinite(t)&&t>0&&(this._eng().seekTo(this._pendingSeek*t),this.progress=this._pendingSeek,this._pendingSeek=null)}_onTime(e,t){if(!(this.currentIndex==null||!t)){if(this._pendingSeek!=null){let r=this._pendingSeek;this._pendingSeek=null,this._eng().seekTo(r*t);return}this.progress=Math.min(Math.max(e/t,0),1),!this._raf&&(this._raf=requestAnimationFrame(()=>{this._raf=0,this._drawRow(this.currentIndex),this._paintSlider()}))}}_onEnd(){let e=this.sounds[this.currentIndex];this._emit("end",{sound:e,index:this.currentIndex}),this.options.onEnd?.(e,this),!(this.options.autoAdvance&&this._step(1))&&(this.progress=0,this._setPlaying(!1))}_onEngineError(e){let t=this.currentIndex,r=t==null?void 0:this.sounds[t];t!=null&&this._markFailed(t,!0),this._setPlaying(!1),r&&!this._cued&&this.$?.status&&(this.$.status.textContent=m(this.strings.playError,{title:r.title})),this._emit("error",{error:e,sound:r,index:t}),this.options.onError?.(e,this)}_setPlaying(e){this.playing=e,e&&(this._cued=!1);let t=this.currentIndex;if(t==null)return;e&&this._markFailed(t,!1),this._paintRow(t);let r=this._announced??null;if(e){if(r===t)return;r!=null&&this._announce("pause",r),this._announced=t,this._announce("play",t)}else r!=null&&(this._announced=null,this._announce("pause",r))}_announce(e,t){let r=this.sounds[t];r&&(e==="play"&&this.$?.status&&(this.$.status.textContent=m(this.strings.nowPlaying,{title:r.title})),this._emit(e,{sound:r,index:t}),(e==="play"?this.options.onPlay:this.options.onPause)?.(r,this))}_paintRow(e){let t=this.rows[e];if(!t)return;let r=e===this.currentIndex,s=r&&this.playing;t.classList.toggle("is-current",r),t.classList.toggle("is-playing",s);let o=t.querySelector(".ws-play");o&&(o.setAttribute("aria-pressed",String(s)),o.setAttribute("aria-label",m(s?this.strings.pause:this.strings.play,{title:this.sounds[e].title}))),t.classList.toggle("is-error",this._failed.has(e));let i=t.querySelector(".ws-wave");i&&this._paintWave(i,r,t===this._active,this.sounds[e].title),this._drawRow(e)}_paintWave(e,t,r,s){if(!t){if(e.getAttribute("aria-hidden")==="true"&&!e.hasAttribute("role"))return;for(let o of["role","aria-label","aria-valuemin","aria-valuemax","aria-valuenow","aria-valuetext","tabindex"])e.removeAttribute(o);e.setAttribute("aria-hidden","true");return}e.removeAttribute("aria-hidden"),e.setAttribute("role","slider"),e.setAttribute("aria-label",m(this.strings.seek,{title:s})),e.setAttribute("aria-valuemin","0"),e.setAttribute("aria-valuemax","100"),e.hasAttribute("aria-valuenow")||e.setAttribute("aria-valuenow",String(Math.round(this.progress*100))),e.tabIndex=r?0:-1}_markFailed(e,t){t?this._failed.add(e):this._failed.delete(e),this.rows[e]?.classList.toggle("is-error",t)}_paintSlider(){let e=this.currentIndex,t=e==null?null:this.rows[e]?.querySelector(".ws-wave");if(!t)return;t.setAttribute("aria-valuenow",String(Math.round(this.progress*100)));let r=this._eng()?.audio,s=Number.isFinite(r?.duration)&&r.duration>0?r.duration:this.sounds[e].duration;s&&t.setAttribute("aria-valuetext",m(this.strings.seekValue,{time:Ie(this.progress*s),duration:_(s)}))}_emit(e,t={}){De(this.container,e,{...t,instance:this}),this.dispatchEvent(new Event(e))}get current(){return this.currentIndex==null||this._cued?null:this.sounds[this.currentIndex]}destroy(e={}){if(!this.destroyed){this.destroyed=!0,this._ctl.abort(),this._io?.disconnect(),this._endIo?.disconnect(),this._ro?.disconnect(),this._mo?.disconnect(),this._raf&&cancelAnimationFrame(this._raf),clearTimeout(this._urlTimer);try{this._eng()?.destroy()}catch{}this.engine=null,this.$?.engine?.querySelector(":scope > [data-ws-engine-mount]")?.remove(),this._originalHTML!=null?this.container.innerHTML=this._originalHTML:e.restore&&this._adoptedHTML!=null&&(this.container.innerHTML=this._adoptedHTML),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(e=document){if(typeof document>"u")return[];let t=e||document,r=[...t.matches?.("[data-waveform-sounds]")?[t]:[],...t.querySelectorAll("[data-waveform-sounds]")],s=[];for(let o of r)if(!(o.dataset.wsInitialized==="true"||n.instances.has(o)))try{s.push(new n(o))}catch(i){console.error(`${f} Failed to initialise:`,i,o)}return s}static getInstance(e){let t=typeof e=="string"?document.querySelector(e):e;return t&&n.instances.get(t)||null}static prune(){for(let[e,t]of n.instances)e.isConnected||t.destroy()}};var yt=["player","manifest","search","filters","sorts","showCount","menuSearch","idPrefix","urlState","loopToggle","pageSize","maxTypeChips","columns","waveformStyle","waveformColor","progressColor","barWidth","barGap","loop","autoAdvance","arrowAudition","strings","playerOptions","mergeEnharmonicKeys"],Me=n=>n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`);function pn(n){let e={};for(let t of yt){let r=Me(t),s=n.getAttribute(r)??n.getAttribute(`data-${r}`);s!=null&&(e[t]=s)}return Z({dataset:e})}var mn=typeof HTMLElement>"u"?class{}:HTMLElement,te=class extends mn{static get observedAttributes(){return yt.flatMap(e=>[Me(e),`data-${Me(e)}`])}connectedCallback(){if(this._leaving!==void 0){clearTimeout(this._leaving),this._leaving=void 0;return}this.sounds||this._build()}disconnectedCallback(){clearTimeout(this._leaving),this._leaving=setTimeout(()=>{this._leaving=void 0,this.isConnected||this._teardown()},0)}attributeChangedCallback(e,t,r){if(!this.sounds||t===r)return;let s=e.replace(/^data-/,"")==="manifest"?"manifest":"rebuild";if(this._pending){s==="manifest"&&(this._pending=s);return}this._pending=s,queueMicrotask(()=>{let o=this._pending;this._pending=void 0,this.sounds&&this._rebuild(o==="manifest")})}_wsOptions(){return pn(this)}_build(e={}){g.getInstance(this)?.destroy({restore:!0});try{this.sounds=new g(this,e)}catch(t){this.sounds=null,console.error(`${f} Failed to initialise:`,t,this)}}_teardown(){this.sounds?.destroy({restore:!0}),this.sounds=null}_rebuild(e){let t=e||!this.sounds.$?void 0:this.sounds.sounds.slice();this._teardown(),this.innerHTML="",this._build(t?{sounds:t}:{})}};function ne(n="waveform-sounds"){if(typeof customElements>"u")return;let e=customElements.get(n);if(e)return e;let t=class extends te{};return customElements.define(n,t),t}g.utils={encodePeaks:z,decodePeaks:oe,normalizeKey:v,normalizeSounds:S,parseManifest:j,facets:R,matches:U,sortSounds:k,formatDuration:_,renderSounds:ve};g.DEFAULT_OPTIONS=X;g.DEFAULT_STRINGS=b;g.defineElement=ne;typeof window<"u"&&(window.WaveformSounds=g);var re=g;var Ir=re;typeof document<"u"&&document.documentElement?.dataset?.waveformAutoinit!=="false"&&(ne(),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>re.init(),{once:!0}):re.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": "2.1.0",
3
+ "version": "2.2.0",
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.esm.js",
@@ -84,6 +84,10 @@ waveform-sounds:not(:defined):empty { min-height: var(--ws-element-height, 0); }
84
84
  border: 0;
85
85
  }
86
86
  .ws-icon { width: 1em; height: 1em; fill: currentColor; flex: none; }
87
+ /* The icons' one definition per list (each icon is a <use> of it): out of
88
+ * the flow, so its empty line box adds no height. Not display: none, which
89
+ * some engines treat as removing what it defines. */
90
+ .ws-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
87
91
 
88
92
  /* ── Controls: shared ────────────────────────────────────────────────── */
89
93
  /* The pill-shaped controls share one frame... */