@arraypress/waveform-sounds 0.1.3 → 0.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.
@@ -93,9 +93,13 @@ function normalizeSound(input, index, peakScale = 1) {
93
93
  tags,
94
94
  peaks: decodePeaks(input.peaks, peakScale),
95
95
  waveform: input.waveform ? String(input.waveform) : null,
96
- download: input.download ? String(input.download) : null
96
+ download: input.download ? String(input.download) : null,
97
+ loop: isLoop(input.loop)
97
98
  };
98
99
  }
100
+ function isLoop(value) {
101
+ return value === true || value === 1 || value === "true" || value === "1";
102
+ }
99
103
  function parseManifest(manifest) {
100
104
  const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
101
105
  const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
@@ -118,7 +122,7 @@ function normalizeSounds(list, peakScale = 1) {
118
122
  function facets(sounds) {
119
123
  const types = /* @__PURE__ */ new Map();
120
124
  const keys = /* @__PURE__ */ new Set();
121
- let min = Infinity, max = -Infinity, hasDuration = false;
125
+ let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
122
126
  for (const s of sounds) {
123
127
  if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
124
128
  if (s.key) keys.add(s.key);
@@ -127,12 +131,15 @@ function facets(sounds) {
127
131
  max = Math.max(max, s.bpm);
128
132
  }
129
133
  if (s.duration != null) hasDuration = true;
134
+ if (s.loop) loops++;
130
135
  }
131
136
  return {
132
137
  types: [...types].map(([name, count]) => ({ name, count })),
133
138
  keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
134
139
  bpm: min === Infinity ? null : { min, max },
135
- hasDuration
140
+ hasDuration,
141
+ loops,
142
+ oneShots: sounds.length - loops
136
143
  };
137
144
  }
138
145
  var SORTS = ["default", "title", "bpm", "key", "duration"];
@@ -204,6 +211,10 @@ var DEFAULT_STRINGS = {
204
211
  sortKey: "Key",
205
212
  sortDuration: "Length",
206
213
  loop: "Loop",
214
+ loopFilter: "Loops or one-shots",
215
+ loops: "Loops",
216
+ oneShots: "One-shots",
217
+ isLoop: "Loop",
207
218
  play: "Play {title}",
208
219
  pause: "Pause {title}",
209
220
  seek: "Seek {title}",
@@ -232,7 +243,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
232
243
  }
233
244
 
234
245
  // src/js/render/options.js
235
- var FILTERS = ["type", "key", "bpm"];
246
+ var FILTERS = ["type", "key", "bpm", "loop"];
236
247
  var COLUMNS = ["type", "bpm", "key", "duration"];
237
248
  var RENDER_DEFAULTS = {
238
249
  player: "inline",
@@ -292,6 +303,7 @@ function toolbarPlan(f, o) {
292
303
  types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
293
304
  key: o.filters.includes("key") && f.keys.length > 1,
294
305
  bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
306
+ loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
295
307
  sorts: sorts.length > 1 ? sorts : [],
296
308
  search: !!o.search,
297
309
  loop: !!o.loopToggle,
@@ -362,6 +374,20 @@ function renderBpmRange(s, range) {
362
374
  h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
363
375
  );
364
376
  }
377
+ function renderLoopFilter(s) {
378
+ const button = (value, label) => h(
379
+ "button",
380
+ { type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
381
+ h("span", {}, text(label))
382
+ );
383
+ return h(
384
+ "div",
385
+ { class: "ws-seg", role: "group", "aria-label": s.loopFilter },
386
+ button("", s.all),
387
+ button("loop", s.loops),
388
+ button("one-shot", s.oneShots)
389
+ );
390
+ }
365
391
  function renderLoopToggle(s) {
366
392
  return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
367
393
  }
@@ -390,6 +416,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
390
416
  options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
391
417
  }),
392
418
  plan.bpm && renderBpmRange(s, f.bpm),
419
+ plan.loops && renderLoopFilter(s),
393
420
  plan.sorts.length > 0 && menu("sort", {
394
421
  label: s.sort,
395
422
  prefix: s.sortBy,
@@ -440,10 +467,17 @@ function renderRow(sound, index, o, hidden = false) {
440
467
  "data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
441
468
  "data-waveform": sound.waveform,
442
469
  "data-download": sound.download,
470
+ "data-loop": sound.loop ? "true" : null,
443
471
  hidden
444
472
  },
445
473
  h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
446
- h("span", { class: "ws-cell ws-title" }, text(sound.title)),
474
+ h(
475
+ "span",
476
+ { class: "ws-cell ws-title" },
477
+ h("span", { class: "ws-title-text" }, text(sound.title)),
478
+ // A loop says so beside its name; a one-shot carries nothing.
479
+ sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
480
+ ),
447
481
  // Wide rows: `display: contents` makes each cell a column. Narrow
448
482
  // rows: one line under the title.
449
483
  cells.length > 0 && h("span", { class: "ws-cells" }, cells),
@@ -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;
@@ -622,6 +632,10 @@ var DEFAULT_STRINGS = {
622
632
  sortKey: "Key",
623
633
  sortDuration: "Length",
624
634
  loop: "Loop",
635
+ loopFilter: "Loops or one-shots",
636
+ loops: "Loops",
637
+ oneShots: "One-shots",
638
+ isLoop: "Loop",
625
639
  play: "Play {title}",
626
640
  pause: "Pause {title}",
627
641
  seek: "Seek {title}",
@@ -650,7 +664,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
650
664
  }
651
665
 
652
666
  // src/js/render/options.js
653
- var FILTERS = ["type", "key", "bpm"];
667
+ var FILTERS = ["type", "key", "bpm", "loop"];
654
668
  var COLUMNS = ["type", "bpm", "key", "duration"];
655
669
  var RENDER_DEFAULTS = {
656
670
  player: "inline",
@@ -827,6 +841,7 @@ function toolbarPlan(f, o) {
827
841
  types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
828
842
  key: o.filters.includes("key") && f.keys.length > 1,
829
843
  bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
844
+ loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
830
845
  sorts: sorts.length > 1 ? sorts : [],
831
846
  search: !!o.search,
832
847
  loop: !!o.loopToggle,
@@ -897,6 +912,20 @@ function renderBpmRange(s, range) {
897
912
  h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
898
913
  );
899
914
  }
915
+ function renderLoopFilter(s) {
916
+ const button = (value, label) => h(
917
+ "button",
918
+ { type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
919
+ h("span", {}, text(label))
920
+ );
921
+ return h(
922
+ "div",
923
+ { class: "ws-seg", role: "group", "aria-label": s.loopFilter },
924
+ button("", s.all),
925
+ button("loop", s.loops),
926
+ button("one-shot", s.oneShots)
927
+ );
928
+ }
900
929
  function renderLoopToggle(s) {
901
930
  return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
902
931
  }
@@ -925,6 +954,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
925
954
  options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
926
955
  }),
927
956
  plan.bpm && renderBpmRange(s, f.bpm),
957
+ plan.loops && renderLoopFilter(s),
928
958
  plan.sorts.length > 0 && menu("sort", {
929
959
  label: s.sort,
930
960
  prefix: s.sortBy,
@@ -975,10 +1005,17 @@ function renderRow(sound, index, o, hidden = false) {
975
1005
  "data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
976
1006
  "data-waveform": sound.waveform,
977
1007
  "data-download": sound.download,
1008
+ "data-loop": sound.loop ? "true" : null,
978
1009
  hidden
979
1010
  },
980
1011
  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)),
1012
+ h(
1013
+ "span",
1014
+ { class: "ws-cell ws-title" },
1015
+ h("span", { class: "ws-title-text" }, text(sound.title)),
1016
+ // A loop says so beside its name; a one-shot carries nothing.
1017
+ sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
1018
+ ),
982
1019
  // Wide rows: `display: contents` makes each cell a column. Narrow
983
1020
  // rows: one line under the title.
984
1021
  cells.length > 0 && h("span", { class: "ws-cells" }, cells),
@@ -1043,7 +1080,8 @@ function readRows(list) {
1043
1080
  tags: d.tags,
1044
1081
  peaks: d.peaks,
1045
1082
  waveform: d.waveform,
1046
- download: d.download
1083
+ download: d.download,
1084
+ loop: d.loop
1047
1085
  }, sounds.length);
1048
1086
  if (!sound) {
1049
1087
  row.remove();
@@ -1101,7 +1139,7 @@ function resolveCssColor(container, value) {
1101
1139
  function urlKeys(urlState) {
1102
1140
  if (!urlState) return null;
1103
1141
  const p = typeof urlState === "string" ? `${urlState}-` : "";
1104
- return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort` };
1142
+ return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort` };
1105
1143
  }
1106
1144
  function parseBpmRange(value) {
1107
1145
  const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
@@ -1123,6 +1161,8 @@ function readUrlState(search, keys, available, sorts) {
1123
1161
  if (key && available.keys.includes(key)) out.filter.key = key;
1124
1162
  const bpm = parseBpmRange(sp.get(keys.bpm));
1125
1163
  if (bpm) Object.assign(out.filter, bpm);
1164
+ const loop = sp.get(keys.loop);
1165
+ if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
1126
1166
  const sort = sp.get(keys.sort);
1127
1167
  if (sort && sorts.includes(sort)) out.sort = sort;
1128
1168
  return out;
@@ -1135,12 +1175,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
1135
1175
  set(keys.type, filter.type);
1136
1176
  set(keys.key, filter.key);
1137
1177
  set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
1178
+ set(keys.loop, filter.loop);
1138
1179
  set(keys.sort, sort !== defaultSort ? sort : "");
1139
1180
  return url.href;
1140
1181
  }
1141
1182
 
1142
1183
  // src/js/core/WaveformSounds.js
1143
- var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
1184
+ var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
1144
1185
  var SEARCH_DELAY = 120;
1145
1186
  var BPM_DELAY = 200;
1146
1187
  var URL_DELAY = 250;
@@ -1245,7 +1286,8 @@ var WaveformSounds = class _WaveformSounds {
1245
1286
  more: q("[data-ws-more]"),
1246
1287
  engine: q("[data-ws-engine]"),
1247
1288
  status: q("[data-ws-status]"),
1248
- chips: [...this.container.querySelectorAll("[data-ws-type]")]
1289
+ chips: [...this.container.querySelectorAll("[data-ws-type]")],
1290
+ loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
1249
1291
  };
1250
1292
  this.rows = indexRows(this.$.list);
1251
1293
  }
@@ -1294,7 +1336,7 @@ var WaveformSounds = class _WaveformSounds {
1294
1336
  }
1295
1337
  /* ── Input ────────────────────────────────────────────────────────── */
1296
1338
  /**
1297
- * Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
1339
+ * Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
1298
1340
  * (seek), and anywhere else on a row (play/pause).
1299
1341
  * @private
1300
1342
  */
@@ -1305,6 +1347,11 @@ var WaveformSounds = class _WaveformSounds {
1305
1347
  this.setFilter({ type: chip.dataset.wsType });
1306
1348
  return;
1307
1349
  }
1350
+ const seg = t.closest("[data-ws-loop-filter]");
1351
+ if (seg) {
1352
+ this.setFilter({ loop: seg.dataset.wsLoopFilter });
1353
+ return;
1354
+ }
1308
1355
  if (t.closest("[data-ws-more]")) {
1309
1356
  this.showMore();
1310
1357
  return;
@@ -1572,6 +1619,7 @@ var WaveformSounds = class _WaveformSounds {
1572
1619
  if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
1573
1620
  if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
1574
1621
  $.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
1622
+ $.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
1575
1623
  }
1576
1624
  /**
1577
1625
  * Lay the rows out for the current filter, sort and page: order, hide,
@@ -1743,7 +1791,9 @@ var WaveformSounds = class _WaveformSounds {
1743
1791
  return true;
1744
1792
  }
1745
1793
  /**
1746
- * Loop the current sound (auditioning a loop is the common case).
1794
+ * Loop the current sound (auditioning a loop is the common case). When
1795
+ * the list marks its loops (`loop: true` on any sound), only those
1796
+ * repeat: a one-shot always plays once.
1747
1797
  * @param {boolean} on
1748
1798
  */
1749
1799
  setLoop(on) {
@@ -1756,7 +1806,17 @@ var WaveformSounds = class _WaveformSounds {
1756
1806
  */
1757
1807
  _setLoop(on) {
1758
1808
  this.$?.loop?.setAttribute("aria-pressed", String(on));
1759
- if (this.engine?.audio) this.engine.audio.loop = on;
1809
+ if (this.engine?.audio) this.engine.audio.loop = this._repeats();
1810
+ }
1811
+ /**
1812
+ * Should the current sound repeat? The Loop toggle is on, and either
1813
+ * the list doesn't say which sounds are loops or this one is.
1814
+ * @private
1815
+ */
1816
+ _repeats() {
1817
+ if (!this.loop) return false;
1818
+ const marksLoops = this.sounds.some((s) => s.loop);
1819
+ return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
1760
1820
  }
1761
1821
  /**
1762
1822
  * Seek a row's sound to `fraction`; a row that isn't current starts
@@ -1784,7 +1844,7 @@ var WaveformSounds = class _WaveformSounds {
1784
1844
  * @private
1785
1845
  */
1786
1846
  _onEngineLoad() {
1787
- if (this.engine?.audio) this.engine.audio.loop = this.loop;
1847
+ if (this.engine?.audio) this.engine.audio.loop = this._repeats();
1788
1848
  const sound = this.sounds[this.currentIndex];
1789
1849
  if (sound && !sound.peaks && this.engine?.waveformData?.length) {
1790
1850
  sound.peaks = resample(this.engine.waveformData, 96);
@@ -205,6 +205,33 @@
205
205
  .ws-loop[aria-pressed='true'] { border-color: var(--ws-accent); background: var(--ws-accent); }
206
206
  .ws-loop[aria-pressed='true'] > * { color: var(--ws-on-accent); }
207
207
 
208
+ /* Loops or one-shots: a segmented control, one button pressed. */
209
+ .ws-seg {
210
+ display: inline-flex;
211
+ height: 2.75rem;
212
+ padding: 0.25rem;
213
+ gap: 0.15rem;
214
+ border: 1px solid var(--ws-border);
215
+ border-radius: var(--ws-control-radius);
216
+ }
217
+ .ws-seg-btn {
218
+ padding: 0 0.85rem;
219
+ border: 0;
220
+ border-radius: var(--ws-control-radius);
221
+ background: none;
222
+ color: inherit;
223
+ font: inherit;
224
+ font-size: 0.88em;
225
+ white-space: nowrap;
226
+ cursor: pointer;
227
+ transition: background 0.15s;
228
+ }
229
+ .ws-seg-btn:hover { background: var(--ws-hover); }
230
+ /* On the accent the CHILD takes the inverted ink: the button itself never
231
+ * sets a colour (see the pause icon note at the top). */
232
+ .ws-seg-btn[aria-pressed='true'] { background: var(--ws-accent); }
233
+ .ws-seg-btn[aria-pressed='true'] > * { color: var(--ws-on-accent); }
234
+
208
235
  .ws-meta { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
209
236
  .ws-types { display: flex; flex-wrap: wrap; gap: 0.4rem; flex: 1 1 auto; min-width: 0; }
210
237
  .ws-chip {
@@ -276,13 +303,18 @@
276
303
  .ws-chip:focus-visible,
277
304
  .ws-menu-btn:focus-visible,
278
305
  .ws-loop:focus-visible,
306
+ .ws-seg-btn:focus-visible,
279
307
  .ws-more:focus-visible,
280
308
  .ws-clear:focus-visible,
281
309
  .ws-wave:focus-visible,
282
310
  .ws-download:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 2px; }
283
311
 
284
312
  .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; }
313
+ .ws-title { flex: 1.4 1 9rem; display: flex; align-items: center; gap: 0.4rem; font-weight: 500; }
314
+ .ws-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
315
+ /* A loop's mark: quiet, beside the name. */
316
+ .ws-loop-mark { flex: none; display: inline-flex; color: var(--ws-muted); }
317
+ .ws-loop-mark .ws-icon { width: 0.95em; height: 0.95em; }
286
318
  .ws-type { flex: 1 1 6rem; color: var(--ws-muted); }
287
319
  .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
320
  .ws-bpm { width: 3.25ch; text-align: right; }
@@ -331,6 +363,7 @@
331
363
  }
332
364
  .ws-play { grid-area: play; align-self: center; }
333
365
  .ws-title { grid-area: title; white-space: normal; overflow-wrap: anywhere; }
366
+ .ws-title-text { overflow: visible; }
334
367
  .ws-cells { grid-area: cells; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.5rem; min-width: 0; }
335
368
  .ws-cells > .ws-cell { flex: none; width: auto; text-align: left; font-size: 0.78em; }
336
369
  .ws-cells > .ws-cell:empty { display: none; }
@@ -134,9 +134,14 @@ function normalizeSound(input, index, peakScale = 1) {
134
134
  tags,
135
135
  peaks: decodePeaks(input.peaks, peakScale),
136
136
  waveform: input.waveform ? String(input.waveform) : null,
137
- download: input.download ? String(input.download) : null
137
+ download: input.download ? String(input.download) : null,
138
+ loop: isLoop(input.loop)
138
139
  };
139
140
  }
141
+ var LOOP_FILTERS = ["loop", "one-shot"];
142
+ function isLoop(value) {
143
+ return value === true || value === 1 || value === "true" || value === "1";
144
+ }
140
145
  function parseManifest(manifest) {
141
146
  const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
142
147
  const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
@@ -159,7 +164,7 @@ function normalizeSounds(list, peakScale = 1) {
159
164
  function facets(sounds) {
160
165
  const types = /* @__PURE__ */ new Map();
161
166
  const keys = /* @__PURE__ */ new Set();
162
- let min = Infinity, max = -Infinity, hasDuration = false;
167
+ let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
163
168
  for (const s of sounds) {
164
169
  if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
165
170
  if (s.key) keys.add(s.key);
@@ -168,17 +173,22 @@ function facets(sounds) {
168
173
  max = Math.max(max, s.bpm);
169
174
  }
170
175
  if (s.duration != null) hasDuration = true;
176
+ if (s.loop) loops++;
171
177
  }
172
178
  return {
173
179
  types: [...types].map(([name, count]) => ({ name, count })),
174
180
  keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
175
181
  bpm: min === Infinity ? null : { min, max },
176
- hasDuration
182
+ hasDuration,
183
+ loops,
184
+ oneShots: sounds.length - loops
177
185
  };
178
186
  }
179
187
  function matches(sound, filter = {}) {
180
188
  if (filter.type && sound.type !== filter.type) return false;
181
189
  if (filter.key && sound.key !== normalizeKey(filter.key)) return false;
190
+ if (filter.loop === "loop" && !sound.loop) return false;
191
+ if (filter.loop === "one-shot" && sound.loop) return false;
182
192
  const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
183
193
  if (filter.bpmMin != null && filter.bpmMin !== "" && Number.isFinite(lo) || filter.bpmMax != null && filter.bpmMax !== "" && Number.isFinite(hi)) {
184
194
  if (sound.bpm == null) return false;
@@ -583,6 +593,10 @@ var DEFAULT_STRINGS = {
583
593
  sortKey: "Key",
584
594
  sortDuration: "Length",
585
595
  loop: "Loop",
596
+ loopFilter: "Loops or one-shots",
597
+ loops: "Loops",
598
+ oneShots: "One-shots",
599
+ isLoop: "Loop",
586
600
  play: "Play {title}",
587
601
  pause: "Pause {title}",
588
602
  seek: "Seek {title}",
@@ -611,7 +625,7 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
611
625
  }
612
626
 
613
627
  // src/js/render/options.js
614
- var FILTERS = ["type", "key", "bpm"];
628
+ var FILTERS = ["type", "key", "bpm", "loop"];
615
629
  var COLUMNS = ["type", "bpm", "key", "duration"];
616
630
  var RENDER_DEFAULTS = {
617
631
  player: "inline",
@@ -788,6 +802,7 @@ function toolbarPlan(f, o) {
788
802
  types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
789
803
  key: o.filters.includes("key") && f.keys.length > 1,
790
804
  bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
805
+ loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
791
806
  sorts: sorts.length > 1 ? sorts : [],
792
807
  search: !!o.search,
793
808
  loop: !!o.loopToggle,
@@ -858,6 +873,20 @@ function renderBpmRange(s, range) {
858
873
  h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
859
874
  );
860
875
  }
876
+ function renderLoopFilter(s) {
877
+ const button = (value, label) => h(
878
+ "button",
879
+ { type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
880
+ h("span", {}, text(label))
881
+ );
882
+ return h(
883
+ "div",
884
+ { class: "ws-seg", role: "group", "aria-label": s.loopFilter },
885
+ button("", s.all),
886
+ button("loop", s.loops),
887
+ button("one-shot", s.oneShots)
888
+ );
889
+ }
861
890
  function renderLoopToggle(s) {
862
891
  return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
863
892
  }
@@ -886,6 +915,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
886
915
  options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
887
916
  }),
888
917
  plan.bpm && renderBpmRange(s, f.bpm),
918
+ plan.loops && renderLoopFilter(s),
889
919
  plan.sorts.length > 0 && menu("sort", {
890
920
  label: s.sort,
891
921
  prefix: s.sortBy,
@@ -936,10 +966,17 @@ function renderRow(sound, index, o, hidden = false) {
936
966
  "data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
937
967
  "data-waveform": sound.waveform,
938
968
  "data-download": sound.download,
969
+ "data-loop": sound.loop ? "true" : null,
939
970
  hidden
940
971
  },
941
972
  h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
942
- h("span", { class: "ws-cell ws-title" }, text(sound.title)),
973
+ h(
974
+ "span",
975
+ { class: "ws-cell ws-title" },
976
+ h("span", { class: "ws-title-text" }, text(sound.title)),
977
+ // A loop says so beside its name; a one-shot carries nothing.
978
+ sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
979
+ ),
943
980
  // Wide rows: `display: contents` makes each cell a column. Narrow
944
981
  // rows: one line under the title.
945
982
  cells.length > 0 && h("span", { class: "ws-cells" }, cells),
@@ -1004,7 +1041,8 @@ function readRows(list) {
1004
1041
  tags: d.tags,
1005
1042
  peaks: d.peaks,
1006
1043
  waveform: d.waveform,
1007
- download: d.download
1044
+ download: d.download,
1045
+ loop: d.loop
1008
1046
  }, sounds.length);
1009
1047
  if (!sound) {
1010
1048
  row.remove();
@@ -1062,7 +1100,7 @@ function resolveCssColor(container, value) {
1062
1100
  function urlKeys(urlState) {
1063
1101
  if (!urlState) return null;
1064
1102
  const p = typeof urlState === "string" ? `${urlState}-` : "";
1065
- return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort` };
1103
+ return { q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort` };
1066
1104
  }
1067
1105
  function parseBpmRange(value) {
1068
1106
  const m = String(value ?? "").match(/^(\d*)-(\d*)$/);
@@ -1084,6 +1122,8 @@ function readUrlState(search, keys, available, sorts) {
1084
1122
  if (key && available.keys.includes(key)) out.filter.key = key;
1085
1123
  const bpm = parseBpmRange(sp.get(keys.bpm));
1086
1124
  if (bpm) Object.assign(out.filter, bpm);
1125
+ const loop = sp.get(keys.loop);
1126
+ if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
1087
1127
  const sort = sp.get(keys.sort);
1088
1128
  if (sort && sorts.includes(sort)) out.sort = sort;
1089
1129
  return out;
@@ -1096,12 +1136,13 @@ function writeUrlState(href, keys, filter, sort, defaultSort) {
1096
1136
  set(keys.type, filter.type);
1097
1137
  set(keys.key, filter.key);
1098
1138
  set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
1139
+ set(keys.loop, filter.loop);
1099
1140
  set(keys.sort, sort !== defaultSort ? sort : "");
1100
1141
  return url.href;
1101
1142
  }
1102
1143
 
1103
1144
  // src/js/core/WaveformSounds.js
1104
- var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "" });
1145
+ var NO_FILTER = Object.freeze({ query: "", type: "", key: "", bpmMin: "", bpmMax: "", loop: "" });
1105
1146
  var SEARCH_DELAY = 120;
1106
1147
  var BPM_DELAY = 200;
1107
1148
  var URL_DELAY = 250;
@@ -1206,7 +1247,8 @@ var WaveformSounds = class _WaveformSounds {
1206
1247
  more: q("[data-ws-more]"),
1207
1248
  engine: q("[data-ws-engine]"),
1208
1249
  status: q("[data-ws-status]"),
1209
- chips: [...this.container.querySelectorAll("[data-ws-type]")]
1250
+ chips: [...this.container.querySelectorAll("[data-ws-type]")],
1251
+ loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
1210
1252
  };
1211
1253
  this.rows = indexRows(this.$.list);
1212
1254
  }
@@ -1255,7 +1297,7 @@ var WaveformSounds = class _WaveformSounds {
1255
1297
  }
1256
1298
  /* ── Input ────────────────────────────────────────────────────────── */
1257
1299
  /**
1258
- * Clicks: type chips, Show more, Clear, Loop, a touch tap on a waveform
1300
+ * Clicks: type chips, loops or one-shots, Show more, Clear, Loop, a touch tap on a waveform
1259
1301
  * (seek), and anywhere else on a row (play/pause).
1260
1302
  * @private
1261
1303
  */
@@ -1266,6 +1308,11 @@ var WaveformSounds = class _WaveformSounds {
1266
1308
  this.setFilter({ type: chip.dataset.wsType });
1267
1309
  return;
1268
1310
  }
1311
+ const seg = t.closest("[data-ws-loop-filter]");
1312
+ if (seg) {
1313
+ this.setFilter({ loop: seg.dataset.wsLoopFilter });
1314
+ return;
1315
+ }
1269
1316
  if (t.closest("[data-ws-more]")) {
1270
1317
  this.showMore();
1271
1318
  return;
@@ -1533,6 +1580,7 @@ var WaveformSounds = class _WaveformSounds {
1533
1580
  if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
1534
1581
  if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
1535
1582
  $.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
1583
+ $.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
1536
1584
  }
1537
1585
  /**
1538
1586
  * Lay the rows out for the current filter, sort and page: order, hide,
@@ -1704,7 +1752,9 @@ var WaveformSounds = class _WaveformSounds {
1704
1752
  return true;
1705
1753
  }
1706
1754
  /**
1707
- * Loop the current sound (auditioning a loop is the common case).
1755
+ * Loop the current sound (auditioning a loop is the common case). When
1756
+ * the list marks its loops (`loop: true` on any sound), only those
1757
+ * repeat: a one-shot always plays once.
1708
1758
  * @param {boolean} on
1709
1759
  */
1710
1760
  setLoop(on) {
@@ -1717,7 +1767,17 @@ var WaveformSounds = class _WaveformSounds {
1717
1767
  */
1718
1768
  _setLoop(on) {
1719
1769
  this.$?.loop?.setAttribute("aria-pressed", String(on));
1720
- if (this.engine?.audio) this.engine.audio.loop = on;
1770
+ if (this.engine?.audio) this.engine.audio.loop = this._repeats();
1771
+ }
1772
+ /**
1773
+ * Should the current sound repeat? The Loop toggle is on, and either
1774
+ * the list doesn't say which sounds are loops or this one is.
1775
+ * @private
1776
+ */
1777
+ _repeats() {
1778
+ if (!this.loop) return false;
1779
+ const marksLoops = this.sounds.some((s) => s.loop);
1780
+ return !marksLoops || !!this.sounds[this.currentIndex]?.loop;
1721
1781
  }
1722
1782
  /**
1723
1783
  * Seek a row's sound to `fraction`; a row that isn't current starts
@@ -1745,7 +1805,7 @@ var WaveformSounds = class _WaveformSounds {
1745
1805
  * @private
1746
1806
  */
1747
1807
  _onEngineLoad() {
1748
- if (this.engine?.audio) this.engine.audio.loop = this.loop;
1808
+ if (this.engine?.audio) this.engine.audio.loop = this._repeats();
1749
1809
  const sound = this.sounds[this.currentIndex];
1750
1810
  if (sound && !sound.peaks && this.engine?.waveformData?.length) {
1751
1811
  sound.peaks = resample(this.engine.waveformData, 96);