@arraypress/waveform-sounds 0.1.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/dist/waveform-sounds-no-autoinit.cjs +206 -35
- package/dist/waveform-sounds-no-autoinit.esm.js +206 -35
- package/dist/waveform-sounds-render.cjs +105 -17
- package/dist/waveform-sounds-render.esm.js +105 -17
- package/dist/waveform-sounds.cjs +206 -35
- package/dist/waveform-sounds.css +136 -15
- package/dist/waveform-sounds.esm.js +206 -35
- package/dist/waveform-sounds.js +206 -35
- package/dist/waveform-sounds.min.css +1 -1
- package/dist/waveform-sounds.min.js +1 -1
- package/index.d.ts +27 -6
- package/package.json +1 -1
- package/src/css/waveform-sounds.css +136 -15
- package/src/js/core/WaveformSounds.js +73 -13
- package/src/js/core/options.js +1 -1
- package/src/js/data/bpm.js +68 -0
- package/src/js/data/sounds.js +31 -6
- package/src/js/data/url-state.js +11 -7
- package/src/js/dom/menus.js +19 -4
- package/src/js/dom/rows.js +1 -1
- package/src/js/render/markup.js +77 -19
- package/src/js/render/options.js +1 -1
- package/src/js/render/strings.js +23 -0
|
@@ -128,9 +128,13 @@ function normalizeSound(input, index, peakScale = 1) {
|
|
|
128
128
|
tags,
|
|
129
129
|
peaks: decodePeaks(input.peaks, peakScale),
|
|
130
130
|
waveform: input.waveform ? String(input.waveform) : null,
|
|
131
|
-
download: input.download ? String(input.download) : null
|
|
131
|
+
download: input.download ? String(input.download) : null,
|
|
132
|
+
loop: isLoop(input.loop)
|
|
132
133
|
};
|
|
133
134
|
}
|
|
135
|
+
function isLoop(value) {
|
|
136
|
+
return value === true || value === 1 || value === "true" || value === "1";
|
|
137
|
+
}
|
|
134
138
|
function parseManifest(manifest) {
|
|
135
139
|
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
136
140
|
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
@@ -153,7 +157,7 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
153
157
|
function facets(sounds) {
|
|
154
158
|
const types = /* @__PURE__ */ new Map();
|
|
155
159
|
const keys = /* @__PURE__ */ new Set();
|
|
156
|
-
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
160
|
+
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
157
161
|
for (const s of sounds) {
|
|
158
162
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
159
163
|
if (s.key) keys.add(s.key);
|
|
@@ -162,12 +166,15 @@ function facets(sounds) {
|
|
|
162
166
|
max = Math.max(max, s.bpm);
|
|
163
167
|
}
|
|
164
168
|
if (s.duration != null) hasDuration = true;
|
|
169
|
+
if (s.loop) loops++;
|
|
165
170
|
}
|
|
166
171
|
return {
|
|
167
172
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
168
173
|
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
169
174
|
bpm: min === Infinity ? null : { min, max },
|
|
170
|
-
hasDuration
|
|
175
|
+
hasDuration,
|
|
176
|
+
loops,
|
|
177
|
+
oneShots: sounds.length - loops
|
|
171
178
|
};
|
|
172
179
|
}
|
|
173
180
|
var SORTS = ["default", "title", "bpm", "key", "duration"];
|
|
@@ -216,6 +223,20 @@ var ICONS = {
|
|
|
216
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")
|
|
217
224
|
};
|
|
218
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
|
+
|
|
219
240
|
// src/js/render/strings.js
|
|
220
241
|
var DEFAULT_STRINGS = {
|
|
221
242
|
search: "Search sounds",
|
|
@@ -231,6 +252,8 @@ var DEFAULT_STRINGS = {
|
|
|
231
252
|
bpm: "BPM",
|
|
232
253
|
bpmMin: "Min BPM",
|
|
233
254
|
bpmMax: "Max BPM",
|
|
255
|
+
anyBpm: "Any BPM",
|
|
256
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
234
257
|
sort: "Sort",
|
|
235
258
|
sortBy: "Sort by",
|
|
236
259
|
sortDefault: "Default",
|
|
@@ -239,6 +262,10 @@ var DEFAULT_STRINGS = {
|
|
|
239
262
|
sortKey: "Key",
|
|
240
263
|
sortDuration: "Length",
|
|
241
264
|
loop: "Loop",
|
|
265
|
+
loopFilter: "Loops or one-shots",
|
|
266
|
+
loops: "Loops",
|
|
267
|
+
oneShots: "One-shots",
|
|
268
|
+
isLoop: "Loop",
|
|
242
269
|
play: "Play {title}",
|
|
243
270
|
pause: "Pause {title}",
|
|
244
271
|
seek: "Seek {title}",
|
|
@@ -261,13 +288,18 @@ var SORT_LABEL_KEYS = {
|
|
|
261
288
|
function fill(template, vars = {}) {
|
|
262
289
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
263
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
|
+
}
|
|
264
296
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
265
297
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
266
298
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
267
299
|
}
|
|
268
300
|
|
|
269
301
|
// src/js/render/options.js
|
|
270
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
302
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
271
303
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
272
304
|
var RENDER_DEFAULTS = {
|
|
273
305
|
player: "inline",
|
|
@@ -327,12 +359,16 @@ function toolbarPlan(f, o) {
|
|
|
327
359
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
328
360
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
329
361
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
362
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
330
363
|
sorts: sorts.length > 1 ? sorts : [],
|
|
331
364
|
search: !!o.search,
|
|
332
365
|
loop: !!o.loopToggle,
|
|
333
366
|
count: !!o.showCount
|
|
334
367
|
};
|
|
335
368
|
}
|
|
369
|
+
function loopsByDefault(loop, f) {
|
|
370
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
371
|
+
}
|
|
336
372
|
function renderSearch(s) {
|
|
337
373
|
return h(
|
|
338
374
|
"label",
|
|
@@ -386,19 +422,63 @@ function renderMenu(name, m) {
|
|
|
386
422
|
)
|
|
387
423
|
);
|
|
388
424
|
}
|
|
389
|
-
function
|
|
390
|
-
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
|
+
});
|
|
391
437
|
return h(
|
|
392
|
-
"
|
|
393
|
-
{ class: "ws-bpm
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
+
)
|
|
398
464
|
);
|
|
399
465
|
}
|
|
400
|
-
function
|
|
401
|
-
|
|
466
|
+
function renderLoopFilter(s) {
|
|
467
|
+
const button = (value, label) => h(
|
|
468
|
+
"button",
|
|
469
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
470
|
+
h("span", {}, text(label))
|
|
471
|
+
);
|
|
472
|
+
return h(
|
|
473
|
+
"div",
|
|
474
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
475
|
+
button("", s.all),
|
|
476
|
+
button("loop", s.loops),
|
|
477
|
+
button("one-shot", s.oneShots)
|
|
478
|
+
);
|
|
479
|
+
}
|
|
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)));
|
|
402
482
|
}
|
|
403
483
|
function renderChip(value, label, count, pressed) {
|
|
404
484
|
return h(
|
|
@@ -424,14 +504,15 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
424
504
|
placeholder: s.findKey,
|
|
425
505
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
426
506
|
}),
|
|
427
|
-
plan.bpm &&
|
|
507
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
508
|
+
plan.loops && renderLoopFilter(s),
|
|
428
509
|
plan.sorts.length > 0 && menu("sort", {
|
|
429
510
|
label: s.sort,
|
|
430
511
|
prefix: s.sortBy,
|
|
431
512
|
value: plan.sorts[0],
|
|
432
513
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
433
514
|
}),
|
|
434
|
-
plan.loop && renderLoopToggle(s)
|
|
515
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
435
516
|
].filter(Boolean);
|
|
436
517
|
const chips = plan.types === "chips" && h(
|
|
437
518
|
"div",
|
|
@@ -475,10 +556,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
475
556
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
476
557
|
"data-waveform": sound.waveform,
|
|
477
558
|
"data-download": sound.download,
|
|
559
|
+
"data-loop": sound.loop ? "true" : null,
|
|
478
560
|
hidden
|
|
479
561
|
},
|
|
480
562
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
481
|
-
h(
|
|
563
|
+
h(
|
|
564
|
+
"span",
|
|
565
|
+
{ class: "ws-cell ws-title" },
|
|
566
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
567
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
568
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
569
|
+
),
|
|
482
570
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
483
571
|
// rows: one line under the title.
|
|
484
572
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
@@ -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"];
|
|
@@ -181,6 +188,20 @@ var ICONS = {
|
|
|
181
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")
|
|
182
189
|
};
|
|
183
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
|
+
|
|
184
205
|
// src/js/render/strings.js
|
|
185
206
|
var DEFAULT_STRINGS = {
|
|
186
207
|
search: "Search sounds",
|
|
@@ -196,6 +217,8 @@ var DEFAULT_STRINGS = {
|
|
|
196
217
|
bpm: "BPM",
|
|
197
218
|
bpmMin: "Min BPM",
|
|
198
219
|
bpmMax: "Max BPM",
|
|
220
|
+
anyBpm: "Any BPM",
|
|
221
|
+
bpmRange: "{min}\u2013{max} BPM",
|
|
199
222
|
sort: "Sort",
|
|
200
223
|
sortBy: "Sort by",
|
|
201
224
|
sortDefault: "Default",
|
|
@@ -204,6 +227,10 @@ var DEFAULT_STRINGS = {
|
|
|
204
227
|
sortKey: "Key",
|
|
205
228
|
sortDuration: "Length",
|
|
206
229
|
loop: "Loop",
|
|
230
|
+
loopFilter: "Loops or one-shots",
|
|
231
|
+
loops: "Loops",
|
|
232
|
+
oneShots: "One-shots",
|
|
233
|
+
isLoop: "Loop",
|
|
207
234
|
play: "Play {title}",
|
|
208
235
|
pause: "Pause {title}",
|
|
209
236
|
seek: "Seek {title}",
|
|
@@ -226,13 +253,18 @@ var SORT_LABEL_KEYS = {
|
|
|
226
253
|
function fill(template, vars = {}) {
|
|
227
254
|
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
228
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
|
+
}
|
|
229
261
|
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
230
262
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
231
263
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
232
264
|
}
|
|
233
265
|
|
|
234
266
|
// src/js/render/options.js
|
|
235
|
-
var FILTERS = ["type", "key", "bpm"];
|
|
267
|
+
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
236
268
|
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
237
269
|
var RENDER_DEFAULTS = {
|
|
238
270
|
player: "inline",
|
|
@@ -292,12 +324,16 @@ function toolbarPlan(f, o) {
|
|
|
292
324
|
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
293
325
|
key: o.filters.includes("key") && f.keys.length > 1,
|
|
294
326
|
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
327
|
+
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
295
328
|
sorts: sorts.length > 1 ? sorts : [],
|
|
296
329
|
search: !!o.search,
|
|
297
330
|
loop: !!o.loopToggle,
|
|
298
331
|
count: !!o.showCount
|
|
299
332
|
};
|
|
300
333
|
}
|
|
334
|
+
function loopsByDefault(loop, f) {
|
|
335
|
+
return loop == null ? f.loops > 0 : !!loop;
|
|
336
|
+
}
|
|
301
337
|
function renderSearch(s) {
|
|
302
338
|
return h(
|
|
303
339
|
"label",
|
|
@@ -351,19 +387,63 @@ function renderMenu(name, m) {
|
|
|
351
387
|
)
|
|
352
388
|
);
|
|
353
389
|
}
|
|
354
|
-
function
|
|
355
|
-
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
|
+
});
|
|
356
402
|
return h(
|
|
357
|
-
"
|
|
358
|
-
{ class: "ws-bpm
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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
|
+
)
|
|
363
429
|
);
|
|
364
430
|
}
|
|
365
|
-
function
|
|
366
|
-
|
|
431
|
+
function renderLoopFilter(s) {
|
|
432
|
+
const button = (value, label) => h(
|
|
433
|
+
"button",
|
|
434
|
+
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
435
|
+
h("span", {}, text(label))
|
|
436
|
+
);
|
|
437
|
+
return h(
|
|
438
|
+
"div",
|
|
439
|
+
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
440
|
+
button("", s.all),
|
|
441
|
+
button("loop", s.loops),
|
|
442
|
+
button("one-shot", s.oneShots)
|
|
443
|
+
);
|
|
444
|
+
}
|
|
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)));
|
|
367
447
|
}
|
|
368
448
|
function renderChip(value, label, count, pressed) {
|
|
369
449
|
return h(
|
|
@@ -389,14 +469,15 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
389
469
|
placeholder: s.findKey,
|
|
390
470
|
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
391
471
|
}),
|
|
392
|
-
plan.bpm &&
|
|
472
|
+
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
473
|
+
plan.loops && renderLoopFilter(s),
|
|
393
474
|
plan.sorts.length > 0 && menu("sort", {
|
|
394
475
|
label: s.sort,
|
|
395
476
|
prefix: s.sortBy,
|
|
396
477
|
value: plan.sorts[0],
|
|
397
478
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
398
479
|
}),
|
|
399
|
-
plan.loop && renderLoopToggle(s)
|
|
480
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
400
481
|
].filter(Boolean);
|
|
401
482
|
const chips = plan.types === "chips" && h(
|
|
402
483
|
"div",
|
|
@@ -440,10 +521,17 @@ function renderRow(sound, index, o, hidden = false) {
|
|
|
440
521
|
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
441
522
|
"data-waveform": sound.waveform,
|
|
442
523
|
"data-download": sound.download,
|
|
524
|
+
"data-loop": sound.loop ? "true" : null,
|
|
443
525
|
hidden
|
|
444
526
|
},
|
|
445
527
|
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
446
|
-
h(
|
|
528
|
+
h(
|
|
529
|
+
"span",
|
|
530
|
+
{ class: "ws-cell ws-title" },
|
|
531
|
+
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
532
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
533
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
534
|
+
),
|
|
447
535
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
448
536
|
// rows: one line under the title.
|
|
449
537
|
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|