@arraypress/waveform-sounds 0.1.3 → 0.3.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.
@@ -173,9 +173,14 @@ function normalizeSound(input, index, peakScale = 1) {
173
173
  tags,
174
174
  peaks: decodePeaks(input.peaks, peakScale),
175
175
  waveform: input.waveform ? String(input.waveform) : null,
176
- download: input.download ? String(input.download) : null
176
+ download: input.download ? String(input.download) : null,
177
+ loop: isLoop(input.loop)
177
178
  };
178
179
  }
180
+ var LOOP_FILTERS = ["loop", "one-shot"];
181
+ function isLoop(value) {
182
+ return value === true || value === 1 || value === "true" || value === "1";
183
+ }
179
184
  function parseManifest(manifest) {
180
185
  const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
181
186
  const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
@@ -198,7 +203,7 @@ function normalizeSounds(list, peakScale = 1) {
198
203
  function facets(sounds) {
199
204
  const types = /* @__PURE__ */ new Map();
200
205
  const keys = /* @__PURE__ */ new Set();
201
- let min = Infinity, max = -Infinity, hasDuration = false;
206
+ let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
202
207
  for (const s of sounds) {
203
208
  if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
204
209
  if (s.key) keys.add(s.key);
@@ -207,17 +212,22 @@ function facets(sounds) {
207
212
  max = Math.max(max, s.bpm);
208
213
  }
209
214
  if (s.duration != null) hasDuration = true;
215
+ if (s.loop) loops++;
210
216
  }
211
217
  return {
212
218
  types: [...types].map(([name, count]) => ({ name, count })),
213
219
  keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
214
220
  bpm: min === Infinity ? null : { min, max },
215
- hasDuration
221
+ hasDuration,
222
+ loops,
223
+ oneShots: sounds.length - loops
216
224
  };
217
225
  }
218
226
  function matches(sound, filter = {}) {
219
227
  if (filter.type && sound.type !== filter.type) return false;
220
228
  if (filter.key && sound.key !== normalizeKey(filter.key)) return false;
229
+ if (filter.loop === "loop" && !sound.loop) return false;
230
+ if (filter.loop === "one-shot" && sound.loop) return false;
221
231
  const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
222
232
  if (filter.bpmMin != null && filter.bpmMin !== "" && Number.isFinite(lo) || filter.bpmMax != null && filter.bpmMax !== "" && Number.isFinite(hi)) {
223
233
  if (sound.bpm == null) return false;
@@ -367,7 +377,7 @@ function partsOf(menu) {
367
377
  value: menu.querySelector("[data-ws-menu-value]")
368
378
  };
369
379
  }
370
- var focusOwner = (p) => p.search || p.list;
380
+ var focusOwner = (p) => p.search || p.list || p.pop.querySelector("input") || p.pop.querySelector("button");
371
381
  var optionsOf = (p, visibleOnly = false) => [...p.list.querySelectorAll('[role="option"]')].filter((o) => !visibleOnly || !o.hidden);
372
382
  var Menus = class {
373
383
  /**
@@ -399,6 +409,15 @@ var Menus = class {
399
409
  this.open(menu);
400
410
  }
401
411
  }, sig);
412
+ if (!p.list) {
413
+ p.pop.addEventListener("keydown", (e) => {
414
+ if (e.key !== "Escape") return;
415
+ e.preventDefault();
416
+ e.stopPropagation();
417
+ this.close(true);
418
+ }, sig);
419
+ continue;
420
+ }
402
421
  p.list.addEventListener("click", (e) => {
403
422
  const opt = e.target.closest('[role="option"]');
404
423
  if (opt) this._pick(name, opt.dataset.value);
@@ -433,8 +452,8 @@ var Menus = class {
433
452
  }
434
453
  menu.classList.remove("ws-menu--end");
435
454
  if (p.pop.getBoundingClientRect().right > this.container.getBoundingClientRect().right + 1) menu.classList.add("ws-menu--end");
436
- this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
437
- focusOwner(p).focus();
455
+ if (p.list) this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
456
+ focusOwner(p)?.focus();
438
457
  }
439
458
  /**
440
459
  * Close the open menu, if any.
@@ -462,6 +481,7 @@ var Menus = class {
462
481
  const menu = this.menus[name];
463
482
  if (!menu) return;
464
483
  const p = partsOf(menu);
484
+ if (!p.list) return;
465
485
  let label = null;
466
486
  for (const opt of optionsOf(p)) {
467
487
  const on = opt.dataset.value === String(value ?? "");
@@ -599,6 +619,31 @@ function limitToReveal(limit, pos) {
599
619
  return pos >= limit ? pos + 1 : limit;
600
620
  }
601
621
 
622
+ // src/js/data/bpm.js
623
+ function bpmFilterFromRange(lo, hi, extent) {
624
+ const a = Math.min(lo, hi), b = Math.max(lo, hi);
625
+ return {
626
+ bpmMin: a > extent.min ? String(a) : "",
627
+ bpmMax: b < extent.max ? String(b) : ""
628
+ };
629
+ }
630
+ function bpmRangeFromFilter(filter, extent) {
631
+ const read = (v, fallback) => {
632
+ const n = Number(v);
633
+ return v === "" || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
634
+ };
635
+ const lo = read(filter.bpmMin, extent.min);
636
+ const hi = read(filter.bpmMax, extent.max);
637
+ return lo <= hi ? { lo, hi } : { lo: hi, hi: lo };
638
+ }
639
+ function bpmFraction(value, extent) {
640
+ const span = extent.max - extent.min;
641
+ return span > 0 ? Math.min(Math.max((value - extent.min) / span, 0), 1) : 0;
642
+ }
643
+ function hasBpmFilter(filter) {
644
+ return filter.bpmMin != null && filter.bpmMin !== "" || filter.bpmMax != null && filter.bpmMax !== "";
645
+ }
646
+
602
647
  // src/js/render/strings.js
603
648
  var DEFAULT_STRINGS = {
604
649
  search: "Search sounds",
@@ -614,6 +659,8 @@ var DEFAULT_STRINGS = {
614
659
  bpm: "BPM",
615
660
  bpmMin: "Min BPM",
616
661
  bpmMax: "Max BPM",
662
+ anyBpm: "Any BPM",
663
+ bpmRange: "{min}\u2013{max} BPM",
617
664
  sort: "Sort",
618
665
  sortBy: "Sort by",
619
666
  sortDefault: "Default",
@@ -622,6 +669,10 @@ var DEFAULT_STRINGS = {
622
669
  sortKey: "Key",
623
670
  sortDuration: "Length",
624
671
  loop: "Loop",
672
+ loopFilter: "Loops or one-shots",
673
+ loops: "Loops",
674
+ oneShots: "One-shots",
675
+ isLoop: "Loop",
625
676
  play: "Play {title}",
626
677
  pause: "Pause {title}",
627
678
  seek: "Seek {title}",
@@ -644,13 +695,18 @@ var SORT_LABEL_KEYS = {
644
695
  function fill(template, vars = {}) {
645
696
  return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
646
697
  }
698
+ function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
699
+ if (!hasBpmFilter(filter)) return strings.anyBpm;
700
+ const { lo, hi } = bpmRangeFromFilter(filter, extent);
701
+ return fill(strings.bpmRange, { min: lo, max: hi });
702
+ }
647
703
  function countText(shown, total, strings = DEFAULT_STRINGS) {
648
704
  if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
649
705
  return total === 1 ? strings.countOne : fill(strings.count, { count: total });
650
706
  }
651
707
 
652
708
  // src/js/render/options.js
653
- var FILTERS = ["type", "key", "bpm"];
709
+ var FILTERS = ["type", "key", "bpm", "loop"];
654
710
  var COLUMNS = ["type", "bpm", "key", "duration"];
655
711
  var RENDER_DEFAULTS = {
656
712
  player: "inline",
@@ -701,7 +757,7 @@ var DEFAULT_OPTIONS = {
701
757
  progressColor: null,
702
758
  barWidth: 2,
703
759
  barGap: 1,
704
- loop: false,
760
+ loop: null,
705
761
  autoAdvance: false,
706
762
  arrowAudition: true,
707
763
  idPrefix: null,
@@ -827,12 +883,16 @@ function toolbarPlan(f, o) {
827
883
  types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
828
884
  key: o.filters.includes("key") && f.keys.length > 1,
829
885
  bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
886
+ loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
830
887
  sorts: sorts.length > 1 ? sorts : [],
831
888
  search: !!o.search,
832
889
  loop: !!o.loopToggle,
833
890
  count: !!o.showCount
834
891
  };
835
892
  }
893
+ function loopsByDefault(loop, f) {
894
+ return loop == null ? f.loops > 0 : !!loop;
895
+ }
836
896
  function renderSearch(s) {
837
897
  return h(
838
898
  "label",
@@ -886,19 +946,63 @@ function renderMenu(name, m) {
886
946
  )
887
947
  );
888
948
  }
889
- function renderBpmRange(s, range) {
890
- const field = (attr, label, placeholder) => h("input", { type: "number", inputmode: "numeric", [attr]: true, "aria-label": label, placeholder, min: "0", step: "1" });
949
+ function renderBpmMenu({ id, s, range }) {
950
+ const popId = `${id}-bpm-pop`;
951
+ const handle = (attr, label, value) => h("input", {
952
+ type: "range",
953
+ class: "ws-range-input",
954
+ [attr]: true,
955
+ "aria-label": label,
956
+ min: range.min,
957
+ max: range.max,
958
+ step: "1",
959
+ value
960
+ });
961
+ return h(
962
+ "div",
963
+ { class: "ws-menu ws-menu--bpm", "data-ws-menu": "bpm" },
964
+ h(
965
+ "button",
966
+ { type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
967
+ h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
968
+ h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
969
+ ICONS.chevron
970
+ ),
971
+ h(
972
+ "div",
973
+ { class: "ws-menu-pop ws-bpm-pop", id: popId, role: "dialog", "aria-label": s.bpm, "data-ws-menu-pop": true, hidden: true },
974
+ h(
975
+ "div",
976
+ { class: "ws-bpm-head" },
977
+ h("span", { class: "ws-bpm-readout", "data-ws-bpm-readout": true, "aria-live": "polite" }, text(fill(s.bpmRange, range))),
978
+ h("button", { type: "button", class: "ws-bpm-clear", "data-ws-bpm-clear": true }, text(s.anyBpm))
979
+ ),
980
+ h(
981
+ "div",
982
+ { class: "ws-range", "data-ws-bpm-range": true },
983
+ handle("data-ws-bpm-min", s.bpmMin, range.min),
984
+ handle("data-ws-bpm-max", s.bpmMax, range.max)
985
+ ),
986
+ h("div", { class: "ws-range-ends", "aria-hidden": "true" }, h("span", {}, text(range.min)), h("span", {}, text(range.max)))
987
+ )
988
+ );
989
+ }
990
+ function renderLoopFilter(s) {
991
+ const button = (value, label) => h(
992
+ "button",
993
+ { type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
994
+ h("span", {}, text(label))
995
+ );
891
996
  return h(
892
- "span",
893
- { class: "ws-bpm-range", role: "group", "aria-label": s.bpm },
894
- field("data-ws-bpm-min", s.bpmMin, range.min),
895
- h("span", { "aria-hidden": "true" }, "\u2013"),
896
- field("data-ws-bpm-max", s.bpmMax, range.max),
897
- h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
997
+ "div",
998
+ { class: "ws-seg", role: "group", "aria-label": s.loopFilter },
999
+ button("", s.all),
1000
+ button("loop", s.loops),
1001
+ button("one-shot", s.oneShots)
898
1002
  );
899
1003
  }
900
- function renderLoopToggle(s) {
901
- return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
1004
+ function renderLoopToggle(s, pressed) {
1005
+ return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, ICONS.loop, h("span", {}, text(s.loop)));
902
1006
  }
903
1007
  function renderChip(value, label, count, pressed) {
904
1008
  return h(
@@ -924,14 +1028,15 @@ function renderToolbar(plan, { o, s, f, total, id }) {
924
1028
  placeholder: s.findKey,
925
1029
  options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
926
1030
  }),
927
- plan.bpm && renderBpmRange(s, f.bpm),
1031
+ plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
1032
+ plan.loops && renderLoopFilter(s),
928
1033
  plan.sorts.length > 0 && menu("sort", {
929
1034
  label: s.sort,
930
1035
  prefix: s.sortBy,
931
1036
  value: plan.sorts[0],
932
1037
  options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
933
1038
  }),
934
- plan.loop && renderLoopToggle(s)
1039
+ plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
935
1040
  ].filter(Boolean);
936
1041
  const chips = plan.types === "chips" && h(
937
1042
  "div",
@@ -975,10 +1080,17 @@ function renderRow(sound, index, o, hidden = false) {
975
1080
  "data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
976
1081
  "data-waveform": sound.waveform,
977
1082
  "data-download": sound.download,
1083
+ "data-loop": sound.loop ? "true" : null,
978
1084
  hidden
979
1085
  },
980
1086
  h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
981
- h("span", { class: "ws-cell ws-title" }, text(sound.title)),
1087
+ h(
1088
+ "span",
1089
+ { class: "ws-cell ws-title" },
1090
+ h("span", { class: "ws-title-text" }, text(sound.title)),
1091
+ // A loop says so beside its name; a one-shot carries nothing.
1092
+ sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
1093
+ ),
982
1094
  // Wide rows: `display: contents` makes each cell a column. Narrow
983
1095
  // rows: one line under the title.
984
1096
  cells.length > 0 && h("span", { class: "ws-cells" }, cells),
@@ -1043,7 +1155,8 @@ function readRows(list) {
1043
1155
  tags: d.tags,
1044
1156
  peaks: d.peaks,
1045
1157
  waveform: d.waveform,
1046
- download: d.download
1158
+ download: d.download,
1159
+ loop: d.loop
1047
1160
  }, sounds.length);
1048
1161
  if (!sound) {
1049
1162
  row.remove();
@@ -1101,7 +1214,7 @@ function resolveCssColor(container, value) {
1101
1214
  function urlKeys(urlState) {
1102
1215
  if (!urlState) return null;
1103
1216
  const p = typeof urlState === "string" ? `${urlState}-` : "";
1104
- return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort` };
1217
+ return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort` };
1105
1218
  }
1106
1219
  function parseBpmRange(value) {
1107
1220
  const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
@@ -1123,6 +1236,8 @@ function readUrlState(search, keys, available, sorts) {
1123
1236
  if (key && available.keys.includes(key)) out.filter.key = key;
1124
1237
  const bpm = parseBpmRange(sp.get(keys.bpm));
1125
1238
  if (bpm) Object.assign(out.filter, bpm);
1239
+ const loop = sp.get(keys.loop);
1240
+ if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
1126
1241
  const sort = sp.get(keys.sort);
1127
1242
  if (sort && sorts.includes(sort)) out.sort = sort;
1128
1243
  return out;
@@ -1135,12 +1250,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
1135
1250
  set(keys.type, filter.type);
1136
1251
  set(keys.key, filter.key);
1137
1252
  set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
1253
+ set(keys.loop, filter.loop);
1138
1254
  set(keys.sort, sort !== defaultSort ? sort : "");
1139
1255
  return url.href;
1140
1256
  }
1141
1257
 
1142
1258
  // src/js/core/WaveformSounds.js
1143
- var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
1259
+ var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
1144
1260
  var SEARCH_DELAY = 120;
1145
1261
  var BPM_DELAY = 200;
1146
1262
  var URL_DELAY = 250;
@@ -1207,7 +1323,9 @@ var WaveformSounds = class _WaveformSounds {
1207
1323
  this._bind();
1208
1324
  this._observe();
1209
1325
  this._resolveColors();
1326
+ if (!this._loopSet) this.loop = loopsByDefault(this.options.loop, facets(this.sounds));
1210
1327
  this._setLoop(this.loop);
1328
+ this._bpmExtent = facets(this.sounds).bpm;
1211
1329
  this._sorts = availableSorts(this.render.sorts, facets(this.sounds));
1212
1330
  if (!this._sortSet) this.sortBy = this._sorts[0] || "default";
1213
1331
  this._readUrl();
@@ -1239,13 +1357,18 @@ var WaveformSounds = class _WaveformSounds {
1239
1357
  search: q("[data-ws-search]"),
1240
1358
  bpmMin: q("[data-ws-bpm-min]"),
1241
1359
  bpmMax: q("[data-ws-bpm-max]"),
1360
+ bpmRange: q("[data-ws-bpm-range]"),
1361
+ bpmReadout: q("[data-ws-bpm-readout]"),
1362
+ bpmClear: q("[data-ws-bpm-clear]"),
1363
+ bpmLabel: q('[data-ws-menu="bpm"] [data-ws-menu-value]'),
1242
1364
  loop: q("[data-ws-loop]"),
1243
1365
  count: q("[data-ws-count]"),
1244
1366
  empty: q("[data-ws-empty]"),
1245
1367
  more: q("[data-ws-more]"),
1246
1368
  engine: q("[data-ws-engine]"),
1247
1369
  status: q("[data-ws-status]"),
1248
- chips: [...this.container.querySelectorAll("[data-ws-type]")]
1370
+ chips: [...this.container.querySelectorAll("[data-ws-type]")],
1371
+ loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
1249
1372
  };
1250
1373
  this.rows = indexRows(this.$.list);
1251
1374
  }
@@ -1277,12 +1400,20 @@ var WaveformSounds = class _WaveformSounds {
1277
1400
  this.setFilter({ query: "" });
1278
1401
  }
1279
1402
  }, sig);
1280
- const onBpm = () => {
1403
+ const onBpm = (moved) => {
1404
+ const lo = Number($.bpmMin.value), hi = Number($.bpmMax.value);
1405
+ if (lo > hi) moved.value = String(moved === $.bpmMin ? hi : lo);
1406
+ const f = bpmFilterFromRange(Number($.bpmMin.value), Number($.bpmMax.value), this._bpmExtent);
1407
+ this._showBpm(f);
1281
1408
  clearTimeout(bpmTimer);
1282
- bpmTimer = setTimeout(() => this.setFilter({ bpmMin: $.bpmMin?.value ?? "", bpmMax: $.bpmMax?.value ?? "" }), BPM_DELAY);
1409
+ bpmTimer = setTimeout(() => this.setFilter(f), BPM_DELAY);
1283
1410
  };
1284
- $.bpmMin?.addEventListener("input", onBpm, sig);
1285
- $.bpmMax?.addEventListener("input", onBpm, sig);
1411
+ $.bpmMin?.addEventListener("input", () => onBpm($.bpmMin), sig);
1412
+ $.bpmMax?.addEventListener("input", () => onBpm($.bpmMax), sig);
1413
+ $.bpmClear?.addEventListener("click", () => {
1414
+ clearTimeout(bpmTimer);
1415
+ this.setFilter({ bpmMin: "", bpmMax: "" });
1416
+ }, sig);
1286
1417
  this.menus = new Menus(root, {
1287
1418
  signal: this._ctl.signal,
1288
1419
  onPick: (name, value) => name === "sort" ? this.setSort(value) : this.setFilter({ [name]: value })
@@ -1294,7 +1425,7 @@ var WaveformSounds = class _WaveformSounds {
1294
1425
  }
1295
1426
  /* ── Input ────────────────────────────────────────────────────────── */
1296
1427
  /**
1297
- * Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
1428
+ * Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
1298
1429
  * (seek), and anywhere else on a row (play/pause).
1299
1430
  * @private
1300
1431
  */
@@ -1305,6 +1436,11 @@ var WaveformSounds = class _WaveformSounds {
1305
1436
  this.setFilter({ type: chip.dataset.wsType });
1306
1437
  return;
1307
1438
  }
1439
+ const seg = t.closest("[data-ws-loop-filter]");
1440
+ if (seg) {
1441
+ this.setFilter({ loop: seg.dataset.wsLoopFilter });
1442
+ return;
1443
+ }
1308
1444
  if (t.closest("[data-ws-more]")) {
1309
1445
  this.showMore();
1310
1446
  return;
@@ -1569,9 +1705,31 @@ var WaveformSounds = class _WaveformSounds {
1569
1705
  this.menus?.setValue("type", f.type || "");
1570
1706
  this.menus?.setValue("key", f.key || "");
1571
1707
  this.menus?.setValue("sort", this.sortBy);
1572
- if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
1573
- if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
1708
+ if ($.bpmMin && $.bpmMax && this._bpmExtent) {
1709
+ const { lo, hi } = bpmRangeFromFilter(f, this._bpmExtent);
1710
+ $.bpmMin.value = String(lo);
1711
+ $.bpmMax.value = String(hi);
1712
+ this._showBpm(f);
1713
+ }
1574
1714
  $.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
1715
+ $.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
1716
+ }
1717
+ /**
1718
+ * Show a BPM filter in its menu: the button label, the panel's readout,
1719
+ * the filled part of the track, and which handle sits on top (the one
1720
+ * that can still move, when they meet).
1721
+ * @private
1722
+ */
1723
+ _showBpm(f) {
1724
+ const $ = this.$, extent = this._bpmExtent;
1725
+ if (!$?.bpmRange || !extent) return;
1726
+ const { lo, hi } = bpmRangeFromFilter(f, extent);
1727
+ if ($.bpmLabel) $.bpmLabel.textContent = bpmLabel(f, extent, this.strings);
1728
+ if ($.bpmReadout) $.bpmReadout.textContent = fill(this.strings.bpmRange, { min: lo, max: hi });
1729
+ $.bpmRange.style.setProperty("--ws-lo", String(bpmFraction(lo, extent)));
1730
+ $.bpmRange.style.setProperty("--ws-hi", String(bpmFraction(hi, extent)));
1731
+ $.bpmRange.classList.toggle("is-min-top", lo >= hi && lo > extent.min);
1732
+ $.bpmRange.classList.toggle("is-active", lo > extent.min || hi < extent.max);
1575
1733
  }
1576
1734
  /**
1577
1735
  * Lay the rows out for the current filter, sort and page: order, hide,
@@ -1743,10 +1901,13 @@ var WaveformSounds = class _WaveformSounds {
1743
1901
  return true;
1744
1902
  }
1745
1903
  /**
1746
- * Loop the current sound (auditioning a loop is the common case).
1904
+ * Loop the current sound (auditioning a loop is the common case). When
1905
+ * the list marks its loops (`loop: true` on any sound), only those
1906
+ * repeat: a one-shot always plays once.
1747
1907
  * @param {boolean} on
1748
1908
  */
1749
1909
  setLoop(on) {
1910
+ this._loopSet = true;
1750
1911
  this.loop = !!on;
1751
1912
  this._setLoop(this.loop);
1752
1913
  }
@@ -1756,7 +1917,17 @@ var WaveformSounds = class _WaveformSounds {
1756
1917
  */
1757
1918
  _setLoop(on) {
1758
1919
  this.$?.loop?.setAttribute("aria-pressed", String(on));
1759
- if (this.engine?.audio) this.engine.audio.loop = on;
1920
+ if (this.engine?.audio) this.engine.audio.loop = this._repeats();
1921
+ }
1922
+ /**
1923
+ * Should the current sound repeat? The Loop toggle is on, and either
1924
+ * the list doesn't say which sounds are loops or this one is.
1925
+ * @private
1926
+ */
1927
+ _repeats() {
1928
+ if (!this.loop) return false;
1929
+ const marksLoops = this.sounds.some((s) => s.loop);
1930
+ return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
1760
1931
  }
1761
1932
  /**
1762
1933
  * Seek a row's sound to `fraction`; a row that isn't current starts
@@ -1784,7 +1955,7 @@ var WaveformSounds = class _WaveformSounds {
1784
1955
  * @private
1785
1956
  */
1786
1957
  _onEngineLoad() {
1787
- if (this.engine?.audio) this.engine.audio.loop = this.loop;
1958
+ if (this.engine?.audio) this.engine.audio.loop = this._repeats();
1788
1959
  const sound = this.sounds[this.currentIndex];
1789
1960
  if (sound && !sound.peaks && this.engine?.waveformData?.length) {
1790
1961
  sound.peaks = resample(this.engine.waveformData, 96);
@@ -104,16 +104,6 @@
104
104
  }
105
105
 
106
106
  .ws-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
107
- .ws-bpm-range input {
108
- height: 2.75rem;
109
- border: 1px solid var(--ws-border);
110
- border-radius: var(--ws-control-radius);
111
- background: var(--ws-field);
112
- color: inherit;
113
- font: inherit;
114
- font-size: 0.9em;
115
- }
116
-
117
107
  /* ── Dropdowns (type / key / sort) ──────────────────────────────────── */
118
108
  .ws-menu { position: relative; }
119
109
  .ws-menu-btn {
@@ -185,9 +175,105 @@
185
175
  .ws-menu-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
186
176
  .ws-menu-count { font-family: var(--ws-mono); font-size: 0.85em; color: var(--ws-muted); }
187
177
  .ws-menu-none { margin: 0; padding: 0.6rem; color: var(--ws-muted); font-size: 0.9em; }
188
- .ws-bpm-range { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--ws-muted); font-size: 0.9em; }
189
- .ws-bpm-range input { width: 5rem; padding: 0 0.85rem; -moz-appearance: textfield; }
190
- .ws-bpm-range input::-webkit-inner-spin-button { display: none; }
178
+
179
+ /* ── The BPM menu: a panel with a two-handle range ───────────────────── */
180
+ .ws-bpm-pop { width: 17rem; padding: 0.85rem 1rem 0.7rem; }
181
+ .ws-bpm-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.6rem; }
182
+ .ws-bpm-readout { font-weight: 600; font-variant-numeric: tabular-nums; }
183
+ .ws-bpm-clear {
184
+ padding: 0;
185
+ border: 0;
186
+ background: none;
187
+ color: var(--ws-muted);
188
+ font: inherit;
189
+ font-size: 0.85em;
190
+ cursor: pointer;
191
+ }
192
+ .ws-bpm-clear:hover { color: inherit; text-decoration: underline; }
193
+
194
+ /* Two native range inputs stacked on one track. The track and the filled
195
+ * span are drawn by the wrapper (--ws-lo / --ws-hi are the handles' 0..1
196
+ * positions, set by the runtime); the inputs contribute only their thumbs.
197
+ * A thumb's centre runs from half a thumb in from each end, hence the
198
+ * calc() on the fill. */
199
+ .ws-range {
200
+ --ws-thumb: 18px;
201
+ --ws-lo: 0;
202
+ --ws-hi: 1;
203
+ position: relative;
204
+ height: 1.75rem;
205
+ }
206
+ .ws-range::before,
207
+ .ws-range::after {
208
+ content: '';
209
+ position: absolute;
210
+ top: 50%;
211
+ height: 4px;
212
+ border-radius: 2px;
213
+ transform: translateY(-50%);
214
+ }
215
+ .ws-range::before { left: 0; right: 0; background: var(--ws-border); }
216
+ .ws-range::after {
217
+ left: calc(var(--ws-thumb) / 2 + var(--ws-lo) * (100% - var(--ws-thumb)));
218
+ right: calc(var(--ws-thumb) / 2 + (1 - var(--ws-hi)) * (100% - var(--ws-thumb)));
219
+ background: var(--ws-accent);
220
+ opacity: 0.35;
221
+ }
222
+ .ws-range.is-active::after { opacity: 1; }
223
+ .ws-range-input {
224
+ position: absolute;
225
+ inset: 0;
226
+ z-index: 1;
227
+ width: 100%;
228
+ height: 100%;
229
+ margin: 0;
230
+ background: none;
231
+ pointer-events: none;
232
+ -webkit-appearance: none;
233
+ appearance: none;
234
+ }
235
+ /* When the handles meet, the lower one goes on top (it's the one that can
236
+ * still move: left). */
237
+ .ws-range.is-min-top [data-ws-bpm-min] { z-index: 2; }
238
+ .ws-range-input::-webkit-slider-runnable-track { height: 100%; background: none; }
239
+ .ws-range-input::-moz-range-track { background: none; }
240
+ .ws-range-input::-webkit-slider-thumb {
241
+ width: var(--ws-thumb);
242
+ height: var(--ws-thumb);
243
+ margin-top: calc((1.75rem - var(--ws-thumb)) / 2);
244
+ border: 2px solid var(--ws-surface, Canvas);
245
+ border-radius: 50%;
246
+ background: var(--ws-accent);
247
+ box-shadow: 0 0 0 1px var(--ws-border);
248
+ cursor: grab;
249
+ pointer-events: auto;
250
+ -webkit-appearance: none;
251
+ appearance: none;
252
+ }
253
+ .ws-range-input::-moz-range-thumb {
254
+ width: var(--ws-thumb);
255
+ height: var(--ws-thumb);
256
+ box-sizing: border-box;
257
+ border: 2px solid var(--ws-surface, Canvas);
258
+ border-radius: 50%;
259
+ background: var(--ws-accent);
260
+ box-shadow: 0 0 0 1px var(--ws-border);
261
+ cursor: grab;
262
+ pointer-events: auto;
263
+ }
264
+ .ws-range-input:active::-webkit-slider-thumb { cursor: grabbing; }
265
+ .ws-range-input:focus-visible { outline: none; }
266
+ .ws-range-input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--ws-accent); }
267
+ .ws-range-input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--ws-accent); }
268
+ .ws-range-ends {
269
+ display: flex;
270
+ justify-content: space-between;
271
+ margin-top: 0.15rem;
272
+ color: var(--ws-muted);
273
+ font-family: var(--ws-mono);
274
+ font-size: 0.75em;
275
+ font-variant-numeric: tabular-nums;
276
+ }
191
277
  .ws-loop {
192
278
  display: inline-flex;
193
279
  align-items: center;
@@ -205,6 +291,33 @@
205
291
  .ws-loop[aria-pressed='true'] { border-color: var(--ws-accent); background: var(--ws-accent); }
206
292
  .ws-loop[aria-pressed='true'] > * { color: var(--ws-on-accent); }
207
293
 
294
+ /* Loops or one-shots: a segmented control, one button pressed. */
295
+ .ws-seg {
296
+ display: inline-flex;
297
+ height: 2.75rem;
298
+ padding: 0.25rem;
299
+ gap: 0.15rem;
300
+ border: 1px solid var(--ws-border);
301
+ border-radius: var(--ws-control-radius);
302
+ }
303
+ .ws-seg-btn {
304
+ padding: 0 0.85rem;
305
+ border: 0;
306
+ border-radius: var(--ws-control-radius);
307
+ background: none;
308
+ color: inherit;
309
+ font: inherit;
310
+ font-size: 0.88em;
311
+ white-space: nowrap;
312
+ cursor: pointer;
313
+ transition: background 0.15s;
314
+ }
315
+ .ws-seg-btn:hover { background: var(--ws-hover); }
316
+ /* On the accent the CHILD takes the inverted ink: the button itself never
317
+ * sets a colour (see the pause icon note at the top). */
318
+ .ws-seg-btn[aria-pressed='true'] { background: var(--ws-accent); }
319
+ .ws-seg-btn[aria-pressed='true'] > * { color: var(--ws-on-accent); }
320
+
208
321
  .ws-meta { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
209
322
  .ws-types { display: flex; flex-wrap: wrap; gap: 0.4rem; flex: 1 1 auto; min-width: 0; }
210
323
  .ws-chip {
@@ -276,13 +389,18 @@
276
389
  .ws-chip:focus-visible,
277
390
  .ws-menu-btn:focus-visible,
278
391
  .ws-loop:focus-visible,
392
+ .ws-seg-btn:focus-visible,
279
393
  .ws-more:focus-visible,
280
394
  .ws-clear:focus-visible,
281
395
  .ws-wave:focus-visible,
282
396
  .ws-download:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 2px; }
283
397
 
284
398
  .ws-cell { min-width: 0; font-size: 0.9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
285
- .ws-title { flex: 1.4 1 9rem; font-weight: 500; }
399
+ .ws-title { flex: 1.4 1 9rem; display: flex; align-items: center; gap: 0.4rem; font-weight: 500; }
400
+ .ws-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
401
+ /* A loop's mark: quiet, beside the name. */
402
+ .ws-loop-mark { flex: none; display: inline-flex; color: var(--ws-muted); }
403
+ .ws-loop-mark .ws-icon { width: 0.95em; height: 0.95em; }
286
404
  .ws-type { flex: 1 1 6rem; color: var(--ws-muted); }
287
405
  .ws-bpm, .ws-key, .ws-duration { flex: none; font-family: var(--ws-mono); font-size: 0.82em; color: var(--ws-muted); font-variant-numeric: tabular-nums; }
288
406
  .ws-bpm { width: 3.25ch; text-align: right; }
@@ -331,6 +449,7 @@
331
449
  }
332
450
  .ws-play { grid-area: play; align-self: center; }
333
451
  .ws-title { grid-area: title; white-space: normal; overflow-wrap: anywhere; }
452
+ .ws-title-text { overflow: visible; }
334
453
  .ws-cells { grid-area: cells; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.5rem; min-width: 0; }
335
454
  .ws-cells > .ws-cell { flex: none; width: auto; text-align: left; font-size: 0.78em; }
336
455
  .ws-cells > .ws-cell:empty { display: none; }
@@ -373,7 +492,9 @@
373
492
  @media (pointer: coarse) {
374
493
  .ws-play, .ws-download { width: 2.75rem; height: 2.75rem; }
375
494
  .ws-chip { height: 2.5rem; }
376
- .ws-search-input, .ws-menu-search, .ws-bpm-range input { font-size: 16px; }
495
+ .ws-search-input, .ws-menu-search { font-size: 16px; }
496
+ .ws-range { --ws-thumb: 24px; height: 2.25rem; }
497
+ .ws-range-input::-webkit-slider-thumb { margin-top: calc((2.25rem - var(--ws-thumb)) / 2); }
377
498
  .ws-menu-option { padding: 0.75rem 0.6rem; }
378
499
  }
379
500