@arraypress/waveform-sounds 0.2.0 → 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.
@@ -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;
@@ -406,7 +492,9 @@
406
492
  @media (pointer: coarse) {
407
493
  .ws-play, .ws-download { width: 2.75rem; height: 2.75rem; }
408
494
  .ws-chip { height: 2.5rem; }
409
- .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); }
410
498
  .ws-menu-option { padding: 0.75rem 0.6rem; }
411
499
  }
412
500
 
@@ -33,9 +33,10 @@ import {Menus} from '../dom/menus.js';
33
33
  import {limitToReveal, pageWindow, rowTarget, seekTarget} from '../data/navigation.js';
34
34
  import {DEFAULT_OPTIONS, mergeOptions, readDataOptions} from './options.js';
35
35
  import {resolveRenderOptions} from '../render/options.js';
36
- import {renderSounds} from '../render/markup.js';
36
+ import {loopsByDefault, renderSounds} from '../render/markup.js';
37
37
  import {indexRows, orderRows, readRows, visibleRows} from '../dom/rows.js';
38
- import {countText, DEFAULT_STRINGS, fill} from '../render/strings.js';
38
+ import {bpmLabel, countText, DEFAULT_STRINGS, fill} from '../render/strings.js';
39
+ import {bpmFilterFromRange, bpmFraction, bpmRangeFromFilter} from '../data/bpm.js';
39
40
  import {pageSurface, resolveCssColor} from '../dom/colors.js';
40
41
  import {readUrlState, urlKeys, writeUrlState} from '../data/url-state.js';
41
42
  import {emit, isTyping, LOG, pointerFraction} from '../shared/utils.js';
@@ -131,7 +132,11 @@ export class WaveformSounds {
131
132
  this._bind();
132
133
  this._observe();
133
134
  this._resolveColors();
135
+ // Unless set (option or an early setLoop()), Loop starts on exactly
136
+ // when the list marks loops — only those repeat.
137
+ if (!this._loopSet) this.loop = loopsByDefault(this.options.loop, facets(this.sounds));
134
138
  this._setLoop(this.loop);
139
+ this._bpmExtent = facets(this.sounds).bpm;
135
140
 
136
141
  // The starting order is the first one offered, unless setSort()
137
142
  // already chose one; then the address may override both.
@@ -176,6 +181,10 @@ export class WaveformSounds {
176
181
  search: q('[data-ws-search]'),
177
182
  bpmMin: q('[data-ws-bpm-min]'),
178
183
  bpmMax: q('[data-ws-bpm-max]'),
184
+ bpmRange: q('[data-ws-bpm-range]'),
185
+ bpmReadout: q('[data-ws-bpm-readout]'),
186
+ bpmClear: q('[data-ws-bpm-clear]'),
187
+ bpmLabel: q('[data-ws-menu="bpm"] [data-ws-menu-value]'),
179
188
  loop: q('[data-ws-loop]'),
180
189
  count: q('[data-ws-count]'),
181
190
  empty: q('[data-ws-empty]'),
@@ -211,12 +220,22 @@ export class WaveformSounds {
211
220
  if (e.key === 'ArrowDown') { e.preventDefault(); this._focusRow(visibleRows($.list)[0]); }
212
221
  if (e.key === 'Escape' && $.search.value) { e.preventDefault(); $.search.value = ''; this.setFilter({query: ''}); }
213
222
  }, sig);
214
- const onBpm = () => {
223
+ // The BPM handles: the label and the track follow the drag at once;
224
+ // the list re-filters once it settles. A handle can't pass the other.
225
+ const onBpm = (moved) => {
226
+ const lo = Number($.bpmMin.value), hi = Number($.bpmMax.value);
227
+ if (lo > hi) moved.value = String(moved === $.bpmMin ? hi : lo);
228
+ const f = bpmFilterFromRange(Number($.bpmMin.value), Number($.bpmMax.value), this._bpmExtent);
229
+ this._showBpm(f);
215
230
  clearTimeout(bpmTimer);
216
- bpmTimer = setTimeout(() => this.setFilter({bpmMin: $.bpmMin?.value ?? '', bpmMax: $.bpmMax?.value ?? ''}), BPM_DELAY);
231
+ bpmTimer = setTimeout(() => this.setFilter(f), BPM_DELAY);
217
232
  };
218
- $.bpmMin?.addEventListener('input', onBpm, sig);
219
- $.bpmMax?.addEventListener('input', onBpm, sig);
233
+ $.bpmMin?.addEventListener('input', () => onBpm($.bpmMin), sig);
234
+ $.bpmMax?.addEventListener('input', () => onBpm($.bpmMax), sig);
235
+ $.bpmClear?.addEventListener('click', () => {
236
+ clearTimeout(bpmTimer);
237
+ this.setFilter({bpmMin: '', bpmMax: ''});
238
+ }, sig);
220
239
 
221
240
  this.menus = new Menus(root, {
222
241
  signal: this._ctl.signal,
@@ -516,12 +535,35 @@ export class WaveformSounds {
516
535
  this.menus?.setValue('type', f.type || '');
517
536
  this.menus?.setValue('key', f.key || '');
518
537
  this.menus?.setValue('sort', this.sortBy);
519
- if ($.bpmMin && $.bpmMin.value !== String(f.bpmMin)) $.bpmMin.value = f.bpmMin;
520
- if ($.bpmMax && $.bpmMax.value !== String(f.bpmMax)) $.bpmMax.value = f.bpmMax;
538
+ if ($.bpmMin && $.bpmMax && this._bpmExtent) {
539
+ const {lo, hi} = bpmRangeFromFilter(f, this._bpmExtent);
540
+ $.bpmMin.value = String(lo);
541
+ $.bpmMax.value = String(hi);
542
+ this._showBpm(f);
543
+ }
521
544
  $.chips.forEach((c) => c.setAttribute('aria-pressed', String(c.dataset.wsType === (f.type || ''))));
522
545
  $.loopFilter.forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.wsLoopFilter === (f.loop || ''))));
523
546
  }
524
547
 
548
+ /**
549
+ * Show a BPM filter in its menu: the button label, the panel's readout,
550
+ * the filled part of the track, and which handle sits on top (the one
551
+ * that can still move, when they meet).
552
+ * @private
553
+ */
554
+ _showBpm(f) {
555
+ const $ = this.$, extent = this._bpmExtent;
556
+ if (!$?.bpmRange || !extent) return;
557
+ const {lo, hi} = bpmRangeFromFilter(f, extent);
558
+ if ($.bpmLabel) $.bpmLabel.textContent = bpmLabel(f, extent, this.strings);
559
+ if ($.bpmReadout) $.bpmReadout.textContent = fill(this.strings.bpmRange, {min: lo, max: hi});
560
+ // CSSOM, not a style attribute: works under a strict CSP.
561
+ $.bpmRange.style.setProperty('--ws-lo', String(bpmFraction(lo, extent)));
562
+ $.bpmRange.style.setProperty('--ws-hi', String(bpmFraction(hi, extent)));
563
+ $.bpmRange.classList.toggle('is-min-top', lo >= hi && lo > extent.min);
564
+ $.bpmRange.classList.toggle('is-active', lo > extent.min || hi < extent.max);
565
+ }
566
+
525
567
  /**
526
568
  * Lay the rows out for the current filter, sort and page: order, hide,
527
569
  * "Show more", the empty state and the count. Then report it.
@@ -696,6 +738,7 @@ export class WaveformSounds {
696
738
  * @param {boolean} on
697
739
  */
698
740
  setLoop(on) {
741
+ this._loopSet = true;
699
742
  this.loop = !!on;
700
743
  this._setLoop(this.loop);
701
744
  }
@@ -25,7 +25,7 @@ export const DEFAULT_OPTIONS = {
25
25
  progressColor: null,
26
26
  barWidth: 2,
27
27
  barGap: 1,
28
- loop: false,
28
+ loop: null,
29
29
  autoAdvance: false,
30
30
  arrowAudition: true,
31
31
  idPrefix: null,
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The BPM range control's arithmetic: between the two slider handles and the
3
+ * filter, and the label its menu button shows. Pure, so the server renderer
4
+ * and the runtime agree.
5
+ *
6
+ * A handle resting at an END of the pack's range is "no limit on that side",
7
+ * not a limit at that value: sounds with no BPM are hidden by any BPM filter,
8
+ * so a slider left wide open must not filter at all.
9
+ *
10
+ * @module bpm
11
+ */
12
+
13
+ /**
14
+ * The filter for a pair of handle positions.
15
+ *
16
+ * @param {number} lo - The lower handle.
17
+ * @param {number} hi - The upper handle.
18
+ * @param {{min: number, max: number}} extent - The pack's BPM range (`facets().bpm`).
19
+ * @returns {{bpmMin: string, bpmMax: string}} `''` for an open end.
20
+ */
21
+ export function bpmFilterFromRange(lo, hi, extent) {
22
+ const a = Math.min(lo, hi), b = Math.max(lo, hi);
23
+ return {
24
+ bpmMin: a > extent.min ? String(a) : '',
25
+ bpmMax: b < extent.max ? String(b) : '',
26
+ };
27
+ }
28
+
29
+ /**
30
+ * Where the handles sit for a filter: an open end at the pack's own end, a
31
+ * set one at its value (clamped into the pack's range, so a link with
32
+ * `?bpm=60-300` still shows sensible handles).
33
+ *
34
+ * @param {{bpmMin?: string|number, bpmMax?: string|number}} filter
35
+ * @param {{min: number, max: number}} extent
36
+ * @returns {{lo: number, hi: number}}
37
+ */
38
+ export function bpmRangeFromFilter(filter, extent) {
39
+ const read = (v, fallback) => {
40
+ const n = Number(v);
41
+ return v === '' || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
42
+ };
43
+ const lo = read(filter.bpmMin, extent.min);
44
+ const hi = read(filter.bpmMax, extent.max);
45
+ return lo <= hi ? {lo, hi} : {lo: hi, hi: lo};
46
+ }
47
+
48
+ /**
49
+ * A handle's position along the track, 0..1.
50
+ *
51
+ * @param {number} value
52
+ * @param {{min: number, max: number}} extent
53
+ * @returns {number}
54
+ */
55
+ export function bpmFraction(value, extent) {
56
+ const span = extent.max - extent.min;
57
+ return span > 0 ? Math.min(Math.max((value - extent.min) / span, 0), 1) : 0;
58
+ }
59
+
60
+ /**
61
+ * Is a BPM limit set on either side?
62
+ *
63
+ * @param {{bpmMin?: string|number, bpmMax?: string|number}} filter
64
+ * @returns {boolean}
65
+ */
66
+ export function hasBpmFilter(filter) {
67
+ return (filter.bpmMin != null && filter.bpmMin !== '') || (filter.bpmMax != null && filter.bpmMax !== '');
68
+ }
@@ -5,6 +5,10 @@
5
5
  * the active option is `aria-activedescendant`, ↑/↓ move, Enter picks,
6
6
  * Esc closes and returns focus to the button.
7
7
  *
8
+ * A menu without a listbox is a PANEL (the BPM range): a button and a popup
9
+ * dialog of its own controls. It shares the opening, closing, outside-press
10
+ * and Esc handling; what's inside it reports its own changes.
11
+ *
8
12
  * The markup comes from `renderMenu()` (server or client); this module
9
13
  * only adds behaviour.
10
14
  *
@@ -50,8 +54,8 @@ function partsOf(menu) {
50
54
  };
51
55
  }
52
56
 
53
- /** The element that owns focus while a menu is open. */
54
- const focusOwner = (p) => p.search || p.list;
57
+ /** The element that owns focus while a menu is open (a panel: its first field, else its first button). */
58
+ const focusOwner = (p) => p.search || p.list || p.pop.querySelector('input') || p.pop.querySelector('button');
55
59
 
56
60
  /** A menu's options, optionally only the ones not filtered out. */
57
61
  const optionsOf = (p, visibleOnly = false) => [...p.list.querySelectorAll('[role="option"]')].filter((o) => !visibleOnly || !o.hidden);
@@ -89,6 +93,16 @@ export class Menus {
89
93
  p.button.addEventListener('keydown', (e) => {
90
94
  if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); this.open(menu); }
91
95
  }, sig);
96
+ if (!p.list) {
97
+ // A panel: Esc anywhere inside it closes it.
98
+ p.pop.addEventListener('keydown', (e) => {
99
+ if (e.key !== 'Escape') return;
100
+ e.preventDefault();
101
+ e.stopPropagation();
102
+ this.close(true);
103
+ }, sig);
104
+ continue;
105
+ }
92
106
  p.list.addEventListener('click', (e) => {
93
107
  const opt = e.target.closest('[role="option"]');
94
108
  if (opt) this._pick(name, opt.dataset.value);
@@ -122,8 +136,8 @@ export class Menus {
122
136
  if (p.search) { p.search.value = ''; this._filter(menu, ''); }
123
137
  menu.classList.remove('ws-menu--end');
124
138
  if (p.pop.getBoundingClientRect().right > this.container.getBoundingClientRect().right + 1) menu.classList.add('ws-menu--end');
125
- this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
126
- focusOwner(p).focus();
139
+ if (p.list) this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
140
+ focusOwner(p)?.focus();
127
141
  }
128
142
 
129
143
  /**
@@ -153,6 +167,7 @@ export class Menus {
153
167
  const menu = this.menus[name];
154
168
  if (!menu) return;
155
169
  const p = partsOf(menu);
170
+ if (!p.list) return; // a panel shows its own value
156
171
  let label = null;
157
172
  for (const opt of optionsOf(p)) {
158
173
  const on = opt.dataset.value === String(value ?? '');
@@ -20,7 +20,7 @@ import {availableSorts, encodePeaks, facets, formatDuration, normalizeSounds} fr
20
20
  import {h, text} from './html.js';
21
21
  import {ICONS} from './icons.js';
22
22
  import {RENDER_DEFAULTS, resolveRenderOptions} from './options.js';
23
- import {countText, DEFAULT_STRINGS, fill, SORT_LABEL_KEYS} from './strings.js';
23
+ import {bpmLabel, countText, DEFAULT_STRINGS, fill, SORT_LABEL_KEYS} from './strings.js';
24
24
  import {hashString} from '../shared/utils.js';
25
25
 
26
26
  export {escapeHtml, RENDER_DEFAULTS, resolveRenderOptions, DEFAULT_STRINGS, countText, fill, availableSorts};
@@ -65,6 +65,19 @@ export function toolbarPlan(f, o) {
65
65
  };
66
66
  }
67
67
 
68
+ /**
69
+ * Does the Loop toggle start on? An explicit `loop` option decides; left
70
+ * unset, it's on exactly when the list marks loops (only those repeat, so
71
+ * a one-shot still plays once).
72
+ *
73
+ * @param {boolean|null|undefined} loop - The `loop` option.
74
+ * @param {{loops: number}} f - The sounds' facets.
75
+ * @returns {boolean}
76
+ */
77
+ export function loopsByDefault(loop, f) {
78
+ return loop == null ? f.loops > 0 : !!loop;
79
+ }
80
+
68
81
  /* ── Controls ───────────────────────────────────────────────────────── */
69
82
 
70
83
  /** The search field. */
@@ -126,14 +139,41 @@ export function renderMenu(name, m) {
126
139
  );
127
140
  }
128
141
 
129
- /** The BPM range: two number fields, with the data's range as placeholders. */
130
- function renderBpmRange(s, range) {
131
- const field = (attr, label, placeholder) => h('input', {type: 'number', inputmode: 'numeric', [attr]: true, 'aria-label': label, placeholder, min: '0', step: '1'});
132
- return h('span', {class: 'ws-bpm-range', role: 'group', 'aria-label': s.bpm},
133
- field('data-ws-bpm-min', s.bpmMin, range.min),
134
- h('span', {'aria-hidden': 'true'}, '–'),
135
- field('data-ws-bpm-max', s.bpmMax, range.max),
136
- h('span', {class: 'ws-bpm-unit', 'aria-hidden': 'true'}, text(s.bpm)),
142
+ /**
143
+ * The BPM menu: a button ("Any BPM" / "120–128 BPM") opening a panel with a
144
+ * two-handle range across the pack's own tempos. Each handle is a native
145
+ * range input (keyboard, screen readers and touch for free); the two share
146
+ * one track. The runtime (`menus.js` + the core) wires it.
147
+ *
148
+ * @param {Object} m
149
+ * @param {string} m.id - Id prefix for this list.
150
+ * @param {typeof DEFAULT_STRINGS} m.s
151
+ * @param {{min: number, max: number}} m.range - The pack's BPM range.
152
+ * @returns {string}
153
+ */
154
+ function renderBpmMenu({id, s, range}) {
155
+ const popId = `${id}-bpm-pop`;
156
+ const handle = (attr, label, value) => h('input', {
157
+ type: 'range', class: 'ws-range-input', [attr]: true, 'aria-label': label,
158
+ min: range.min, max: range.max, step: '1', value,
159
+ });
160
+ return h('div', {class: 'ws-menu ws-menu--bpm', 'data-ws-menu': 'bpm'},
161
+ h('button', {type: 'button', class: 'ws-menu-btn', 'data-ws-menu-btn': true, 'aria-haspopup': 'dialog', 'aria-expanded': 'false', 'aria-controls': popId},
162
+ h('span', {class: 'ws-sr'}, text(`${s.bpm}: `)),
163
+ h('span', {class: 'ws-menu-value', 'data-ws-menu-value': true}, text(bpmLabel({}, range, s))),
164
+ ICONS.chevron,
165
+ ),
166
+ h('div', {class: 'ws-menu-pop ws-bpm-pop', id: popId, role: 'dialog', 'aria-label': s.bpm, 'data-ws-menu-pop': true, hidden: true},
167
+ h('div', {class: 'ws-bpm-head'},
168
+ h('span', {class: 'ws-bpm-readout', 'data-ws-bpm-readout': true, 'aria-live': 'polite'}, text(fill(s.bpmRange, range))),
169
+ h('button', {type: 'button', class: 'ws-bpm-clear', 'data-ws-bpm-clear': true}, text(s.anyBpm)),
170
+ ),
171
+ h('div', {class: 'ws-range', 'data-ws-bpm-range': true},
172
+ handle('data-ws-bpm-min', s.bpmMin, range.min),
173
+ handle('data-ws-bpm-max', s.bpmMax, range.max),
174
+ ),
175
+ h('div', {class: 'ws-range-ends', 'aria-hidden': 'true'}, h('span', {}, text(range.min)), h('span', {}, text(range.max))),
176
+ ),
137
177
  );
138
178
  }
139
179
 
@@ -147,9 +187,9 @@ function renderLoopFilter(s) {
147
187
  button('', s.all), button('loop', s.loops), button('one-shot', s.oneShots));
148
188
  }
149
189
 
150
- /** The Loop toggle. */
151
- function renderLoopToggle(s) {
152
- return h('button', {type: 'button', class: 'ws-loop', 'data-ws-loop': true, 'aria-pressed': 'false'}, ICONS.loop, h('span', {}, text(s.loop)));
190
+ /** The Loop toggle, pressed or not. */
191
+ function renderLoopToggle(s, pressed) {
192
+ return h('button', {type: 'button', class: 'ws-loop', 'data-ws-loop': true, 'aria-pressed': String(pressed)}, ICONS.loop, h('span', {}, text(s.loop)));
153
193
  }
154
194
 
155
195
  /** One type chip ('' = all). */
@@ -177,13 +217,13 @@ function renderToolbar(plan, {o, s, f, total, id}) {
177
217
  label: s.key, value: '', placeholder: s.findKey,
178
218
  options: [{value: '', label: s.anyKey}, ...f.keys.map((k) => ({value: k, label: k}))],
179
219
  }),
180
- plan.bpm && renderBpmRange(s, f.bpm),
220
+ plan.bpm && renderBpmMenu({id, s, range: f.bpm}),
181
221
  plan.loops && renderLoopFilter(s),
182
222
  plan.sorts.length > 0 && menu('sort', {
183
223
  label: s.sort, prefix: s.sortBy, value: plan.sorts[0],
184
224
  options: plan.sorts.map((k) => ({value: k, label: s[SORT_LABEL_KEYS[k]]})),
185
225
  }),
186
- plan.loop && renderLoopToggle(s),
226
+ plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f)),
187
227
  ].filter(Boolean);
188
228
 
189
229
  const chips = plan.types === 'chips' && h('div', {class: 'ws-types', role: 'group', 'aria-label': s.types},
@@ -6,6 +6,8 @@
6
6
  * @module strings
7
7
  */
8
8
 
9
+ import {bpmRangeFromFilter, hasBpmFilter} from '../data/bpm.js';
10
+
9
11
  /** The English defaults. */
10
12
  export const DEFAULT_STRINGS = {
11
13
  search: 'Search sounds',
@@ -21,6 +23,8 @@ export const DEFAULT_STRINGS = {
21
23
  bpm: 'BPM',
22
24
  bpmMin: 'Min BPM',
23
25
  bpmMax: 'Max BPM',
26
+ anyBpm: 'Any BPM',
27
+ bpmRange: '{min}–{max} BPM',
24
28
  sort: 'Sort',
25
29
  sortBy: 'Sort by',
26
30
  sortDefault: 'Default',
@@ -66,6 +70,21 @@ export function fill(template, vars = {}) {
66
70
  return String(template).replace(/\{(\w+)\}/g, (match, name) => (name in vars ? String(vars[name]) : match));
67
71
  }
68
72
 
73
+ /**
74
+ * The BPM menu's label: "Any BPM", or the range the handles hold
75
+ * ("120–128 BPM"; an open end shows the pack's own end).
76
+ *
77
+ * @param {{bpmMin?: string|number, bpmMax?: string|number}} filter
78
+ * @param {{min: number, max: number}} extent - The pack's BPM range.
79
+ * @param {typeof DEFAULT_STRINGS} [strings]
80
+ * @returns {string}
81
+ */
82
+ export function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
83
+ if (!hasBpmFilter(filter)) return strings.anyBpm;
84
+ const {lo, hi} = bpmRangeFromFilter(filter, extent);
85
+ return fill(strings.bpmRange, {min: lo, max: hi});
86
+ }
87
+
69
88
  /**
70
89
  * The count line: "300 sounds", "1 sound", "12 of 300 sounds".
71
90
  *