@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
|
@@ -223,6 +223,20 @@ var ICONS = {
|
|
|
223
223
|
loop: icon("M17 4l3 3-3 3V8H8a3 3 0 0 0-3 3v1H3v-1a5 5 0 0 1 5-5h9V4zM7 20l-3-3 3-3v2h9a3 3 0 0 0 3-3v-1h2v1a5 5 0 0 1-5 5H7v2z")
|
|
224
224
|
};
|
|
225
225
|
|
|
226
|
+
// src/js/data/bpm.js
|
|
227
|
+
function bpmRangeFromFilter(filter, extent) {
|
|
228
|
+
const read = (v, fallback) => {
|
|
229
|
+
const n = Number(v);
|
|
230
|
+
return v === "" || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
|
|
231
|
+
};
|
|
232
|
+
const lo = read(filter.bpmMin, extent.min);
|
|
233
|
+
const hi = read(filter.bpmMax, extent.max);
|
|
234
|
+
return lo <= hi ? { lo, hi } : { lo: hi, hi: lo };
|
|
235
|
+
}
|
|
236
|
+
function hasBpmFilter(filter) {
|
|
237
|
+
return filter.bpmMin != null && filter.bpmMin !== "" || filter.bpmMax != null && filter.bpmMax !== "";
|
|
238
|
+
}
|
|
239
|
+
|
|
226
240
|
// src/js/render/strings.js
|
|
227
241
|
var DEFAULT_STRINGS = {
|
|
228
242
|
search: "Search sounds",
|
|
@@ -238,6 +252,8 @@ var DEFAULT_STRINGS = {
|
|
|
238
252
|
bpm: "BPM",
|
|
239
253
|
bpmMin: "Min BPM",
|
|
240
254
|
bpmMax: "Max BPM",
|
|
255
|
+
anyBpm: "Any BPM",
|
|
256
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
241
257
|
sort: "Sort",
|
|
242
258
|
sortBy: "Sort by",
|
|
243
259
|
sortDefault: "Default",
|
|
@@ -272,6 +288,11 @@ var SORT_LABEL_KEYS = {
|
|
|
272
288
|
function fill(template, vars = {}) {
|
|
273
289
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
274
290
|
}
|
|
291
|
+
function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
|
|
292
|
+
if (!hasBpmFilter(filter)) return strings.anyBpm;
|
|
293
|
+
const { lo, hi } = bpmRangeFromFilter(filter, extent);
|
|
294
|
+
return fill(strings.bpmRange, { min: lo, max: hi });
|
|
295
|
+
}
|
|
275
296
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
276
297
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
277
298
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
@@ -345,6 +366,9 @@ function toolbarPlan(f, o) {
|
|
|
345
366
|
count: !!o.showCount
|
|
346
367
|
};
|
|
347
368
|
}
|
|
369
|
+
function loopsByDefault(loop, f) {
|
|
370
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
371
|
+
}
|
|
348
372
|
function renderSearch(s) {
|
|
349
373
|
return h(
|
|
350
374
|
"label",
|
|
@@ -398,15 +422,45 @@ function renderMenu(name, m) {
|
|
|
398
422
|
)
|
|
399
423
|
);
|
|
400
424
|
}
|
|
401
|
-
function
|
|
402
|
-
const
|
|
425
|
+
function renderBpmMenu({ id, s, range }) {
|
|
426
|
+
const popId = `${id}-bpm-pop`;
|
|
427
|
+
const handle = (attr, label, value) => h("input", {
|
|
428
|
+
type: "range",
|
|
429
|
+
class: "ws-range-input",
|
|
430
|
+
[attr]: true,
|
|
431
|
+
"aria-label": label,
|
|
432
|
+
min: range.min,
|
|
433
|
+
max: range.max,
|
|
434
|
+
step: "1",
|
|
435
|
+
value
|
|
436
|
+
});
|
|
403
437
|
return h(
|
|
404
|
-
"
|
|
405
|
-
{ class: "ws-bpm
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
438
|
+
"div",
|
|
439
|
+
{ class: "ws-menu ws-menu--bpm", "data-ws-menu": "bpm" },
|
|
440
|
+
h(
|
|
441
|
+
"button",
|
|
442
|
+
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
443
|
+
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
444
|
+
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
445
|
+
ICONS.chevron
|
|
446
|
+
),
|
|
447
|
+
h(
|
|
448
|
+
"div",
|
|
449
|
+
{ class: "ws-menu-pop ws-bpm-pop", id: popId, role: "dialog", "aria-label": s.bpm, "data-ws-menu-pop": true, hidden: true },
|
|
450
|
+
h(
|
|
451
|
+
"div",
|
|
452
|
+
{ class: "ws-bpm-head" },
|
|
453
|
+
h("span", { class: "ws-bpm-readout", "data-ws-bpm-readout": true, "aria-live": "polite" }, text(fill(s.bpmRange, range))),
|
|
454
|
+
h("button", { type: "button", class: "ws-bpm-clear", "data-ws-bpm-clear": true }, text(s.anyBpm))
|
|
455
|
+
),
|
|
456
|
+
h(
|
|
457
|
+
"div",
|
|
458
|
+
{ class: "ws-range", "data-ws-bpm-range": true },
|
|
459
|
+
handle("data-ws-bpm-min", s.bpmMin, range.min),
|
|
460
|
+
handle("data-ws-bpm-max", s.bpmMax, range.max)
|
|
461
|
+
),
|
|
462
|
+
h("div", { class: "ws-range-ends", "aria-hidden": "true" }, h("span", {}, text(range.min)), h("span", {}, text(range.max)))
|
|
463
|
+
)
|
|
410
464
|
);
|
|
411
465
|
}
|
|
412
466
|
function renderLoopFilter(s) {
|
|
@@ -423,8 +477,8 @@ function renderLoopFilter(s) {
|
|
|
423
477
|
button("one-shot", s.oneShots)
|
|
424
478
|
);
|
|
425
479
|
}
|
|
426
|
-
function renderLoopToggle(s) {
|
|
427
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed":
|
|
480
|
+
function renderLoopToggle(s, pressed) {
|
|
481
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
428
482
|
}
|
|
429
483
|
function renderChip(value, label, count, pressed) {
|
|
430
484
|
return h(
|
|
@@ -450,7 +504,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
450
504
|
placeholder: s.findKey,
|
|
451
505
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
452
506
|
}),
|
|
453
|
-
plan.bpm &&
|
|
507
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
454
508
|
plan.loops && renderLoopFilter(s),
|
|
455
509
|
plan.sorts.length > 0 && menu("sort", {
|
|
456
510
|
label: s.sort,
|
|
@@ -458,7 +512,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
458
512
|
value: plan.sorts[0],
|
|
459
513
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
460
514
|
}),
|
|
461
|
-
plan.loop && renderLoopToggle(s)
|
|
515
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
462
516
|
].filter(Boolean);
|
|
463
517
|
const chips = plan.types === "chips" && h(
|
|
464
518
|
"div",
|
|
@@ -188,6 +188,20 @@ var ICONS = {
|
|
|
188
188
|
loop: icon("M17 4l3 3-3 3V8H8a3 3 0 0 0-3 3v1H3v-1a5 5 0 0 1 5-5h9V4zM7 20l-3-3 3-3v2h9a3 3 0 0 0 3-3v-1h2v1a5 5 0 0 1-5 5H7v2z")
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
+
// src/js/data/bpm.js
|
|
192
|
+
function bpmRangeFromFilter(filter, extent) {
|
|
193
|
+
const read = (v, fallback) => {
|
|
194
|
+
const n = Number(v);
|
|
195
|
+
return v === "" || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
|
|
196
|
+
};
|
|
197
|
+
const lo = read(filter.bpmMin, extent.min);
|
|
198
|
+
const hi = read(filter.bpmMax, extent.max);
|
|
199
|
+
return lo <= hi ? { lo, hi } : { lo: hi, hi: lo };
|
|
200
|
+
}
|
|
201
|
+
function hasBpmFilter(filter) {
|
|
202
|
+
return filter.bpmMin != null && filter.bpmMin !== "" || filter.bpmMax != null && filter.bpmMax !== "";
|
|
203
|
+
}
|
|
204
|
+
|
|
191
205
|
// src/js/render/strings.js
|
|
192
206
|
var DEFAULT_STRINGS = {
|
|
193
207
|
search: "Search sounds",
|
|
@@ -203,6 +217,8 @@ var DEFAULT_STRINGS = {
|
|
|
203
217
|
bpm: "BPM",
|
|
204
218
|
bpmMin: "Min BPM",
|
|
205
219
|
bpmMax: "Max BPM",
|
|
220
|
+
anyBpm: "Any BPM",
|
|
221
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
206
222
|
sort: "Sort",
|
|
207
223
|
sortBy: "Sort by",
|
|
208
224
|
sortDefault: "Default",
|
|
@@ -237,6 +253,11 @@ var SORT_LABEL_KEYS = {
|
|
|
237
253
|
function fill(template, vars = {}) {
|
|
238
254
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
239
255
|
}
|
|
256
|
+
function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
|
|
257
|
+
if (!hasBpmFilter(filter)) return strings.anyBpm;
|
|
258
|
+
const { lo, hi } = bpmRangeFromFilter(filter, extent);
|
|
259
|
+
return fill(strings.bpmRange, { min: lo, max: hi });
|
|
260
|
+
}
|
|
240
261
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
241
262
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
242
263
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
@@ -310,6 +331,9 @@ function toolbarPlan(f, o) {
|
|
|
310
331
|
count: !!o.showCount
|
|
311
332
|
};
|
|
312
333
|
}
|
|
334
|
+
function loopsByDefault(loop, f) {
|
|
335
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
336
|
+
}
|
|
313
337
|
function renderSearch(s) {
|
|
314
338
|
return h(
|
|
315
339
|
"label",
|
|
@@ -363,15 +387,45 @@ function renderMenu(name, m) {
|
|
|
363
387
|
)
|
|
364
388
|
);
|
|
365
389
|
}
|
|
366
|
-
function
|
|
367
|
-
const
|
|
390
|
+
function renderBpmMenu({ id, s, range }) {
|
|
391
|
+
const popId = `${id}-bpm-pop`;
|
|
392
|
+
const handle = (attr, label, value) => h("input", {
|
|
393
|
+
type: "range",
|
|
394
|
+
class: "ws-range-input",
|
|
395
|
+
[attr]: true,
|
|
396
|
+
"aria-label": label,
|
|
397
|
+
min: range.min,
|
|
398
|
+
max: range.max,
|
|
399
|
+
step: "1",
|
|
400
|
+
value
|
|
401
|
+
});
|
|
368
402
|
return h(
|
|
369
|
-
"
|
|
370
|
-
{ class: "ws-bpm
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
403
|
+
"div",
|
|
404
|
+
{ class: "ws-menu ws-menu--bpm", "data-ws-menu": "bpm" },
|
|
405
|
+
h(
|
|
406
|
+
"button",
|
|
407
|
+
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
408
|
+
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
409
|
+
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
410
|
+
ICONS.chevron
|
|
411
|
+
),
|
|
412
|
+
h(
|
|
413
|
+
"div",
|
|
414
|
+
{ class: "ws-menu-pop ws-bpm-pop", id: popId, role: "dialog", "aria-label": s.bpm, "data-ws-menu-pop": true, hidden: true },
|
|
415
|
+
h(
|
|
416
|
+
"div",
|
|
417
|
+
{ class: "ws-bpm-head" },
|
|
418
|
+
h("span", { class: "ws-bpm-readout", "data-ws-bpm-readout": true, "aria-live": "polite" }, text(fill(s.bpmRange, range))),
|
|
419
|
+
h("button", { type: "button", class: "ws-bpm-clear", "data-ws-bpm-clear": true }, text(s.anyBpm))
|
|
420
|
+
),
|
|
421
|
+
h(
|
|
422
|
+
"div",
|
|
423
|
+
{ class: "ws-range", "data-ws-bpm-range": true },
|
|
424
|
+
handle("data-ws-bpm-min", s.bpmMin, range.min),
|
|
425
|
+
handle("data-ws-bpm-max", s.bpmMax, range.max)
|
|
426
|
+
),
|
|
427
|
+
h("div", { class: "ws-range-ends", "aria-hidden": "true" }, h("span", {}, text(range.min)), h("span", {}, text(range.max)))
|
|
428
|
+
)
|
|
375
429
|
);
|
|
376
430
|
}
|
|
377
431
|
function renderLoopFilter(s) {
|
|
@@ -388,8 +442,8 @@ function renderLoopFilter(s) {
|
|
|
388
442
|
button("one-shot", s.oneShots)
|
|
389
443
|
);
|
|
390
444
|
}
|
|
391
|
-
function renderLoopToggle(s) {
|
|
392
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed":
|
|
445
|
+
function renderLoopToggle(s, pressed) {
|
|
446
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
393
447
|
}
|
|
394
448
|
function renderChip(value, label, count, pressed) {
|
|
395
449
|
return h(
|
|
@@ -415,7 +469,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
415
469
|
placeholder: s.findKey,
|
|
416
470
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
417
471
|
}),
|
|
418
|
-
plan.bpm &&
|
|
472
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
419
473
|
plan.loops && renderLoopFilter(s),
|
|
420
474
|
plan.sorts.length > 0 && menu("sort", {
|
|
421
475
|
label: s.sort,
|
|
@@ -423,7 +477,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
423
477
|
value: plan.sorts[0],
|
|
424
478
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
425
479
|
}),
|
|
426
|
-
plan.loop && renderLoopToggle(s)
|
|
480
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
427
481
|
].filter(Boolean);
|
|
428
482
|
const chips = plan.types === "chips" && h(
|
|
429
483
|
"div",
|
package/dist/waveform-sounds.cjs
CHANGED
|
@@ -377,7 +377,7 @@ function partsOf(menu) {
|
|
|
377
377
|
value: menu.querySelector("[data-ws-menu-value]")
|
|
378
378
|
};
|
|
379
379
|
}
|
|
380
|
-
var focusOwner = (p) => p.search || p.list;
|
|
380
|
+
var focusOwner = (p) => p.search || p.list || p.pop.querySelector("input") || p.pop.querySelector("button");
|
|
381
381
|
var optionsOf = (p, visibleOnly = false) => [...p.list.querySelectorAll('[role="option"]')].filter((o) => !visibleOnly || !o.hidden);
|
|
382
382
|
var Menus = class {
|
|
383
383
|
/**
|
|
@@ -409,6 +409,15 @@ var Menus = class {
|
|
|
409
409
|
this.open(menu);
|
|
410
410
|
}
|
|
411
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
|
+
}
|
|
412
421
|
p.list.addEventListener("click", (e) => {
|
|
413
422
|
const opt = e.target.closest('[role="option"]');
|
|
414
423
|
if (opt) this._pick(name, opt.dataset.value);
|
|
@@ -443,8 +452,8 @@ var Menus = class {
|
|
|
443
452
|
}
|
|
444
453
|
menu.classList.remove("ws-menu--end");
|
|
445
454
|
if (p.pop.getBoundingClientRect().right > this.container.getBoundingClientRect().right + 1) menu.classList.add("ws-menu--end");
|
|
446
|
-
this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
447
|
-
focusOwner(p)
|
|
455
|
+
if (p.list) this._activate(menu, p.list.querySelector('[role="option"][aria-selected="true"]'));
|
|
456
|
+
focusOwner(p)?.focus();
|
|
448
457
|
}
|
|
449
458
|
/**
|
|
450
459
|
* Close the open menu, if any.
|
|
@@ -472,6 +481,7 @@ var Menus = class {
|
|
|
472
481
|
const menu = this.menus[name];
|
|
473
482
|
if (!menu) return;
|
|
474
483
|
const p = partsOf(menu);
|
|
484
|
+
if (!p.list) return;
|
|
475
485
|
let label = null;
|
|
476
486
|
for (const opt of optionsOf(p)) {
|
|
477
487
|
const on = opt.dataset.value === String(value ?? "");
|
|
@@ -609,6 +619,31 @@ function limitToReveal(limit, pos) {
|
|
|
609
619
|
return pos >= limit ? pos + 1 : limit;
|
|
610
620
|
}
|
|
611
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
|
+
|
|
612
647
|
// src/js/render/strings.js
|
|
613
648
|
var DEFAULT_STRINGS = {
|
|
614
649
|
search: "Search sounds",
|
|
@@ -624,6 +659,8 @@ var DEFAULT_STRINGS = {
|
|
|
624
659
|
bpm: "BPM",
|
|
625
660
|
bpmMin: "Min BPM",
|
|
626
661
|
bpmMax: "Max BPM",
|
|
662
|
+
anyBpm: "Any BPM",
|
|
663
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
627
664
|
sort: "Sort",
|
|
628
665
|
sortBy: "Sort by",
|
|
629
666
|
sortDefault: "Default",
|
|
@@ -658,6 +695,11 @@ var SORT_LABEL_KEYS = {
|
|
|
658
695
|
function fill(template, vars = {}) {
|
|
659
696
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
660
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
|
+
}
|
|
661
703
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
662
704
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
663
705
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
@@ -715,7 +757,7 @@ var DEFAULT_OPTIONS = {
|
|
|
715
757
|
progressColor: null,
|
|
716
758
|
barWidth: 2,
|
|
717
759
|
barGap: 1,
|
|
718
|
-
loop:
|
|
760
|
+
loop: null,
|
|
719
761
|
autoAdvance: false,
|
|
720
762
|
arrowAudition: true,
|
|
721
763
|
idPrefix: null,
|
|
@@ -848,6 +890,9 @@ function toolbarPlan(f, o) {
|
|
|
848
890
|
count: !!o.showCount
|
|
849
891
|
};
|
|
850
892
|
}
|
|
893
|
+
function loopsByDefault(loop, f) {
|
|
894
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
895
|
+
}
|
|
851
896
|
function renderSearch(s) {
|
|
852
897
|
return h(
|
|
853
898
|
"label",
|
|
@@ -901,15 +946,45 @@ function renderMenu(name, m) {
|
|
|
901
946
|
)
|
|
902
947
|
);
|
|
903
948
|
}
|
|
904
|
-
function
|
|
905
|
-
const
|
|
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
|
+
});
|
|
906
961
|
return h(
|
|
907
|
-
"
|
|
908
|
-
{ class: "ws-bpm
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
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
|
+
)
|
|
913
988
|
);
|
|
914
989
|
}
|
|
915
990
|
function renderLoopFilter(s) {
|
|
@@ -926,8 +1001,8 @@ function renderLoopFilter(s) {
|
|
|
926
1001
|
button("one-shot", s.oneShots)
|
|
927
1002
|
);
|
|
928
1003
|
}
|
|
929
|
-
function renderLoopToggle(s) {
|
|
930
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed":
|
|
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)));
|
|
931
1006
|
}
|
|
932
1007
|
function renderChip(value, label, count, pressed) {
|
|
933
1008
|
return h(
|
|
@@ -953,7 +1028,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
953
1028
|
placeholder: s.findKey,
|
|
954
1029
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
955
1030
|
}),
|
|
956
|
-
plan.bpm &&
|
|
1031
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
957
1032
|
plan.loops && renderLoopFilter(s),
|
|
958
1033
|
plan.sorts.length > 0 && menu("sort", {
|
|
959
1034
|
label: s.sort,
|
|
@@ -961,7 +1036,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
961
1036
|
value: plan.sorts[0],
|
|
962
1037
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
963
1038
|
}),
|
|
964
|
-
plan.loop && renderLoopToggle(s)
|
|
1039
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
965
1040
|
].filter(Boolean);
|
|
966
1041
|
const chips = plan.types === "chips" && h(
|
|
967
1042
|
"div",
|
|
@@ -1248,7 +1323,9 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1248
1323
|
this._bind();
|
|
1249
1324
|
this._observe();
|
|
1250
1325
|
this._resolveColors();
|
|
1326
|
+
if (!this._loopSet) this.loop = loopsByDefault(this.options.loop, facets(this.sounds));
|
|
1251
1327
|
this._setLoop(this.loop);
|
|
1328
|
+
this._bpmExtent = facets(this.sounds).bpm;
|
|
1252
1329
|
this._sorts = availableSorts(this.render.sorts, facets(this.sounds));
|
|
1253
1330
|
if (!this._sortSet) this.sortBy = this._sorts[0] || "default";
|
|
1254
1331
|
this._readUrl();
|
|
@@ -1280,6 +1357,10 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1280
1357
|
search: q("[data-ws-search]"),
|
|
1281
1358
|
bpmMin: q("[data-ws-bpm-min]"),
|
|
1282
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]'),
|
|
1283
1364
|
loop: q("[data-ws-loop]"),
|
|
1284
1365
|
count: q("[data-ws-count]"),
|
|
1285
1366
|
empty: q("[data-ws-empty]"),
|
|
@@ -1319,12 +1400,20 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1319
1400
|
this.setFilter({ query: "" });
|
|
1320
1401
|
}
|
|
1321
1402
|
}, sig);
|
|
1322
|
-
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);
|
|
1323
1408
|
clearTimeout(bpmTimer);
|
|
1324
|
-
bpmTimer = setTimeout(() => this.setFilter(
|
|
1409
|
+
bpmTimer = setTimeout(() => this.setFilter(f), BPM_DELAY);
|
|
1325
1410
|
};
|
|
1326
|
-
$.bpmMin?.addEventListener("input", onBpm, sig);
|
|
1327
|
-
$.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);
|
|
1328
1417
|
this.menus = new Menus(root, {
|
|
1329
1418
|
signal: this._ctl.signal,
|
|
1330
1419
|
onPick: (name, value) => name === "sort" ? this.setSort(value) : this.setFilter({ [name]: value })
|
|
@@ -1616,11 +1705,32 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1616
1705
|
this.menus?.setValue("type", f.type || "");
|
|
1617
1706
|
this.menus?.setValue("key", f.key || "");
|
|
1618
1707
|
this.menus?.setValue("sort", this.sortBy);
|
|
1619
|
-
if ($.bpmMin && $.
|
|
1620
|
-
|
|
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
|
+
}
|
|
1621
1714
|
$.chips.forEach((c) => c.setAttribute("aria-pressed", String(c.dataset.wsType === (f.type || ""))));
|
|
1622
1715
|
$.loopFilter.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.wsLoopFilter === (f.loop || ""))));
|
|
1623
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);
|
|
1733
|
+
}
|
|
1624
1734
|
/**
|
|
1625
1735
|
* Lay the rows out for the current filter, sort and page: order, hide,
|
|
1626
1736
|
* "Show more", the empty state and the count. Then report it.
|
|
@@ -1797,6 +1907,7 @@ var WaveformSounds = class _WaveformSounds {
|
|
|
1797
1907
|
* @param {boolean} on
|
|
1798
1908
|
*/
|
|
1799
1909
|
setLoop(on) {
|
|
1910
|
+
this._loopSet = true;
|
|
1800
1911
|
this.loop = !!on;
|
|
1801
1912
|
this._setLoop(this.loop);
|
|
1802
1913
|
}
|