@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.
- package/README.md +3 -2
- package/dist/waveform-sounds-no-autoinit.cjs +133 -22
- package/dist/waveform-sounds-no-autoinit.esm.js +133 -22
- package/dist/waveform-sounds-render.cjs +66 -12
- package/dist/waveform-sounds-render.esm.js +66 -12
- package/dist/waveform-sounds.cjs +133 -22
- package/dist/waveform-sounds.css +102 -14
- package/dist/waveform-sounds.esm.js +133 -22
- package/dist/waveform-sounds.js +133 -22
- package/dist/waveform-sounds.min.css +1 -1
- package/dist/waveform-sounds.min.js +1 -1
- package/index.d.ts +7 -2
- package/package.json +1 -1
- package/src/css/waveform-sounds.css +102 -14
- package/src/js/core/WaveformSounds.js +51 -8
- package/src/js/core/options.js +1 -1
- package/src/js/data/bpm.js +68 -0
- package/src/js/dom/menus.js +19 -4
- package/src/js/render/markup.js +54 -14
- package/src/js/render/strings.js +19 -0
package/dist/waveform-sounds.css
CHANGED
|
@@ -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
|
-
|
|
189
|
-
|
|
190
|
-
.ws-bpm-
|
|
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
|
|
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
|
|
|
@@ -338,7 +338,7 @@ function partsOf(menu) {
|
|
|
338
338
|
value: menu.querySelector("[data-ws-menu-value]")
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
|
-
var focusOwner = (p) => p.search || p.list;
|
|
341
|
+
var focusOwner = (p) => p.search || p.list || p.pop.querySelector("input") || p.pop.querySelector("button");
|
|
342
342
|
var optionsOf = (p, visibleOnly = false) => [...p.list.querySelectorAll('[role="option"]')].filter((o) => !visibleOnly || !o.hidden);
|
|
343
343
|
var Menus = class {
|
|
344
344
|
/**
|
|
@@ -370,6 +370,15 @@ var Menus = class {
|
|
|
370
370
|
this.open(menu);
|
|
371
371
|
}
|
|
372
372
|
}, sig);
|
|
373
|
+
if (!p.list) {
|
|
374
|
+
p.pop.addEventListener("keydown", (e) => {
|
|
375
|
+
if (e.key !== "Escape") return;
|
|
376
|
+
e.preventDefault();
|
|
377
|
+
e.stopPropagation();
|
|
378
|
+
this.close(true);
|
|
379
|
+
}, sig);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
373
382
|
p.list.addEventListener("click", (e) => {
|
|
374
383
|
const opt = e.target.closest('[role="option"]');
|
|
375
384
|
if (opt) this._pick(name, opt.dataset.value);
|
|
@@ -404,8 +413,8 @@ var Menus = class {
|
|
|
404
413
|
}
|
|
405
414
|
menu.classList.remove("ws-menu--end");
|
|
406
415
|
if (p.pop.getBoundingClientRect().right > this.container.getBoundingClientRect().right + 1) menu.classList.add("ws-menu--end");
|
|
407
|
-
this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
408
|
-
focusOwner(p)
|
|
416
|
+
if (p.list) this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
417
|
+
focusOwner(p)?.focus();
|
|
409
418
|
}
|
|
410
419
|
/**
|
|
411
420
|
* Close the open menu, if any.
|
|
@@ -433,6 +442,7 @@ var Menus = class {
|
|
|
433
442
|
const menu = this.menus[name];
|
|
434
443
|
if (!menu) return;
|
|
435
444
|
const p = partsOf(menu);
|
|
445
|
+
if (!p.list) return;
|
|
436
446
|
let label = null;
|
|
437
447
|
for (const opt of optionsOf(p)) {
|
|
438
448
|
const on = opt.dataset.value === String(value ?? "");
|
|
@@ -570,6 +580,31 @@ function limitToReveal(limit, pos) {
|
|
|
570
580
|
return pos >= limit ? pos + 1 : limit;
|
|
571
581
|
}
|
|
572
582
|
|
|
583
|
+
// src/js/data/bpm.js
|
|
584
|
+
function bpmFilterFromRange(lo, hi, extent) {
|
|
585
|
+
const a = Math.min(lo, hi), b = Math.max(lo, hi);
|
|
586
|
+
return {
|
|
587
|
+
bpmMin: a > extent.min ? String(a) : "",
|
|
588
|
+
bpmMax: b < extent.max ? String(b) : ""
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
function bpmRangeFromFilter(filter, extent) {
|
|
592
|
+
const read = (v, fallback) => {
|
|
593
|
+
const n = Number(v);
|
|
594
|
+
return v === "" || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
|
|
595
|
+
};
|
|
596
|
+
const lo = read(filter.bpmMin, extent.min);
|
|
597
|
+
const hi = read(filter.bpmMax, extent.max);
|
|
598
|
+
return lo <= hi ? { lo, hi } : { lo: hi, hi: lo };
|
|
599
|
+
}
|
|
600
|
+
function bpmFraction(value, extent) {
|
|
601
|
+
const span = extent.max - extent.min;
|
|
602
|
+
return span > 0 ? Math.min(Math.max((value - extent.min) / span, 0), 1) : 0;
|
|
603
|
+
}
|
|
604
|
+
function hasBpmFilter(filter) {
|
|
605
|
+
return filter.bpmMin != null && filter.bpmMin !== "" || filter.bpmMax != null && filter.bpmMax !== "";
|
|
606
|
+
}
|
|
607
|
+
|
|
573
608
|
// src/js/render/strings.js
|
|
574
609
|
var DEFAULT_STRINGS = {
|
|
575
610
|
search: "Search sounds",
|
|
@@ -585,6 +620,8 @@ var DEFAULT_STRINGS = {
|
|
|
585
620
|
bpm: "BPM",
|
|
586
621
|
bpmMin: "Min BPM",
|
|
587
622
|
bpmMax: "Max BPM",
|
|
623
|
+
anyBpm: "Any BPM",
|
|
624
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
588
625
|
sort: "Sort",
|
|
589
626
|
sortBy: "Sort by",
|
|
590
627
|
sortDefault: "Default",
|
|
@@ -619,6 +656,11 @@ var SORT_LABEL_KEYS = {
|
|
|
619
656
|
function fill(template, vars = {}) {
|
|
620
657
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
621
658
|
}
|
|
659
|
+
function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
|
|
660
|
+
if (!hasBpmFilter(filter)) return strings.anyBpm;
|
|
661
|
+
const { lo, hi } = bpmRangeFromFilter(filter, extent);
|
|
662
|
+
return fill(strings.bpmRange, { min: lo, max: hi });
|
|
663
|
+
}
|
|
622
664
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
623
665
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
624
666
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
@@ -676,7 +718,7 @@ var DEFAULT_OPTIONS = {
|
|
|
676
718
|
progressColor: null,
|
|
677
719
|
barWidth: 2,
|
|
678
720
|
barGap: 1,
|
|
679
|
-
loop:
|
|
721
|
+
loop: null,
|
|
680
722
|
autoAdvance: false,
|
|
681
723
|
arrowAudition: true,
|
|
682
724
|
idPrefix: null,
|
|
@@ -809,6 +851,9 @@ function toolbarPlan(f, o) {
|
|
|
809
851
|
count: !!o.showCount
|
|
810
852
|
};
|
|
811
853
|
}
|
|
854
|
+
function loopsByDefault(loop, f) {
|
|
855
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
856
|
+
}
|
|
812
857
|
function renderSearch(s) {
|
|
813
858
|
return h(
|
|
814
859
|
"label",
|
|
@@ -862,15 +907,45 @@ function renderMenu(name, m) {
|
|
|
862
907
|
)
|
|
863
908
|
);
|
|
864
909
|
}
|
|
865
|
-
function
|
|
866
|
-
const
|
|
910
|
+
function renderBpmMenu({ id, s, range }) {
|
|
911
|
+
const popId = `${id}-bpm-pop`;
|
|
912
|
+
const handle = (attr, label, value) => h("input", {
|
|
913
|
+
type: "range",
|
|
914
|
+
class: "ws-range-input",
|
|
915
|
+
[attr]: true,
|
|
916
|
+
"aria-label": label,
|
|
917
|
+
min: range.min,
|
|
918
|
+
max: range.max,
|
|
919
|
+
step: "1",
|
|
920
|
+
value
|
|
921
|
+
});
|
|
867
922
|
return h(
|
|
868
|
-
"
|
|
869
|
-
{ class: "ws-bpm
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
923
|
+
"div",
|
|
924
|
+
{ class: "ws-menu ws-menu--bpm", "data-ws-menu": "bpm" },
|
|
925
|
+
h(
|
|
926
|
+
"button",
|
|
927
|
+
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
928
|
+
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
929
|
+
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
930
|
+
ICONS.chevron
|
|
931
|
+
),
|
|
932
|
+
h(
|
|
933
|
+
"div",
|
|
934
|
+
{ class: "ws-menu-pop ws-bpm-pop", id: popId, role: "dialog", "aria-label": s.bpm, "data-ws-menu-pop": true, hidden: true },
|
|
935
|
+
h(
|
|
936
|
+
"div",
|
|
937
|
+
{ class: "ws-bpm-head" },
|
|
938
|
+
h("span", { class: "ws-bpm-readout", "data-ws-bpm-readout": true, "aria-live": "polite" }, text(fill(s.bpmRange, range))),
|
|
939
|
+
h("button", { type: "button", class: "ws-bpm-clear", "data-ws-bpm-clear": true }, text(s.anyBpm))
|
|
940
|
+
),
|
|
941
|
+
h(
|
|
942
|
+
"div",
|
|
943
|
+
{ class: "ws-range", "data-ws-bpm-range": true },
|
|
944
|
+
handle("data-ws-bpm-min", s.bpmMin, range.min),
|
|
945
|
+
handle("data-ws-bpm-max", s.bpmMax, range.max)
|
|
946
|
+
),
|
|
947
|
+
h("div", { class: "ws-range-ends", "aria-hidden": "true" }, h("span", {}, text(range.min)), h("span", {}, text(range.max)))
|
|
948
|
+
)
|
|
874
949
|
);
|
|
875
950
|
}
|
|
876
951
|
function renderLoopFilter(s) {
|
|
@@ -887,8 +962,8 @@ function renderLoopFilter(s) {
|
|
|
887
962
|
button("one-shot", s.oneShots)
|
|
888
963
|
);
|
|
889
964
|
}
|
|
890
|
-
function renderLoopToggle(s) {
|
|
891
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed":
|
|
965
|
+
function renderLoopToggle(s, pressed) {
|
|
966
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
892
967
|
}
|
|
893
968
|
function renderChip(value, label, count, pressed) {
|
|
894
969
|
return h(
|
|
@@ -914,7 +989,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
914
989
|
placeholder: s.findKey,
|
|
915
990
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
916
991
|
}),
|
|
917
|
-
plan.bpm &&
|
|
992
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
918
993
|
plan.loops && renderLoopFilter(s),
|
|
919
994
|
plan.sorts.length > 0 && menu("sort", {
|
|
920
995
|
label: s.sort,
|
|
@@ -922,7 +997,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
922
997
|
value: plan.sorts[0],
|
|
923
998
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
924
999
|
}),
|
|
925
|
-
plan.loop && renderLoopToggle(s)
|
|
1000
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
926
1001
|
].filter(Boolean);
|
|
927
1002
|
const chips = plan.types === "chips" && h(
|
|
928
1003
|
"div",
|
|
@@ -1209,7 +1284,9 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1209
1284
|
this._bind();
|
|
1210
1285
|
this._observe();
|
|
1211
1286
|
this._resolveColors();
|
|
1287
|
+
if (!this._loopSet) this.loop = loopsByDefault(this.options.loop, facets(this.sounds));
|
|
1212
1288
|
this._setLoop(this.loop);
|
|
1289
|
+
this._bpmExtent = facets(this.sounds).bpm;
|
|
1213
1290
|
this._sorts = availableSorts(this.render.sorts, facets(this.sounds));
|
|
1214
1291
|
if (!this._sortSet) this.sortBy = this._sorts[0] || "default";
|
|
1215
1292
|
this._readUrl();
|
|
@@ -1241,6 +1318,10 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1241
1318
|
search: q("[data-ws-search]"),
|
|
1242
1319
|
bpmMin: q("[data-ws-bpm-min]"),
|
|
1243
1320
|
bpmMax: q("[data-ws-bpm-max]"),
|
|
1321
|
+
bpmRange: q("[data-ws-bpm-range]"),
|
|
1322
|
+
bpmReadout: q("[data-ws-bpm-readout]"),
|
|
1323
|
+
bpmClear: q("[data-ws-bpm-clear]"),
|
|
1324
|
+
bpmLabel: q('[data-ws-menu="bpm"] [data-ws-menu-value]'),
|
|
1244
1325
|
loop: q("[data-ws-loop]"),
|
|
1245
1326
|
count: q("[data-ws-count]"),
|
|
1246
1327
|
empty: q("[data-ws-empty]"),
|
|
@@ -1280,12 +1361,20 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1280
1361
|
this.setFilter({ query: "" });
|
|
1281
1362
|
}
|
|
1282
1363
|
}, sig);
|
|
1283
|
-
const onBpm = () => {
|
|
1364
|
+
const onBpm = (moved) => {
|
|
1365
|
+
const lo = Number($.bpmMin.value), hi = Number($.bpmMax.value);
|
|
1366
|
+
if (lo > hi) moved.value = String(moved === $.bpmMin ? hi : lo);
|
|
1367
|
+
const f = bpmFilterFromRange(Number($.bpmMin.value), Number($.bpmMax.value), this._bpmExtent);
|
|
1368
|
+
this._showBpm(f);
|
|
1284
1369
|
clearTimeout(bpmTimer);
|
|
1285
|
-
bpmTimer = setTimeout(() => this.setFilter(
|
|
1370
|
+
bpmTimer = setTimeout(() => this.setFilter(f), BPM_DELAY);
|
|
1286
1371
|
};
|
|
1287
|
-
$.bpmMin?.addEventListener("input", onBpm, sig);
|
|
1288
|
-
$.bpmMax?.addEventListener("input", onBpm, sig);
|
|
1372
|
+
$.bpmMin?.addEventListener("input", () => onBpm($.bpmMin), sig);
|
|
1373
|
+
$.bpmMax?.addEventListener("input", () => onBpm($.bpmMax), sig);
|
|
1374
|
+
$.bpmClear?.addEventListener("click", () => {
|
|
1375
|
+
clearTimeout(bpmTimer);
|
|
1376
|
+
this.setFilter({ bpmMin: "", bpmMax: "" });
|
|
1377
|
+
}, sig);
|
|
1289
1378
|
this.menus = new Menus(root, {
|
|
1290
1379
|
signal: this._ctl.signal,
|
|
1291
1380
|
onPick: (name, value) => name === "sort" ? this.setSort(value) : this.setFilter({ [name]: value })
|
|
@@ -1577,11 +1666,32 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1577
1666
|
this.menus?.setValue("type", f.type || "");
|
|
1578
1667
|
this.menus?.setValue("key", f.key || "");
|
|
1579
1668
|
this.menus?.setValue("sort", this.sortBy);
|
|
1580
|
-
if ($.bpmMin && $.
|
|
1581
|
-
|
|
1669
|
+
if ($.bpmMin && $.bpmMax && this._bpmExtent) {
|
|
1670
|
+
const { lo, hi } = bpmRangeFromFilter(f, this._bpmExtent);
|
|
1671
|
+
$.bpmMin.value = String(lo);
|
|
1672
|
+
$.bpmMax.value = String(hi);
|
|
1673
|
+
this._showBpm(f);
|
|
1674
|
+
}
|
|
1582
1675
|
$.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
|
|
1583
1676
|
$.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
|
|
1584
1677
|
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Show a BPM filter in its menu: the button label, the panel's readout,
|
|
1680
|
+
* the filled part of the track, and which handle sits on top (the one
|
|
1681
|
+
* that can still move, when they meet).
|
|
1682
|
+
* @private
|
|
1683
|
+
*/
|
|
1684
|
+
_showBpm(f) {
|
|
1685
|
+
const $ = this.$, extent = this._bpmExtent;
|
|
1686
|
+
if (!$?.bpmRange || !extent) return;
|
|
1687
|
+
const { lo, hi } = bpmRangeFromFilter(f, extent);
|
|
1688
|
+
if ($.bpmLabel) $.bpmLabel.textContent = bpmLabel(f, extent, this.strings);
|
|
1689
|
+
if ($.bpmReadout) $.bpmReadout.textContent = fill(this.strings.bpmRange, { min: lo, max: hi });
|
|
1690
|
+
$.bpmRange.style.setProperty("--ws-lo", String(bpmFraction(lo, extent)));
|
|
1691
|
+
$.bpmRange.style.setProperty("--ws-hi", String(bpmFraction(hi, extent)));
|
|
1692
|
+
$.bpmRange.classList.toggle("is-min-top", lo >= hi && lo > extent.min);
|
|
1693
|
+
$.bpmRange.classList.toggle("is-active", lo > extent.min || hi < extent.max);
|
|
1694
|
+
}
|
|
1585
1695
|
/**
|
|
1586
1696
|
* Lay the rows out for the current filter, sort and page: order, hide,
|
|
1587
1697
|
* "Show more", the empty state and the count. Then report it.
|
|
@@ -1758,6 +1868,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1758
1868
|
* @param {boolean} on
|
|
1759
1869
|
*/
|
|
1760
1870
|
setLoop(on) {
|
|
1871
|
+
this._loopSet = true;
|
|
1761
1872
|
this.loop = !!on;
|
|
1762
1873
|
this._setLoop(this.loop);
|
|
1763
1874
|
}
|