@arraypress/waveform-sounds 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -1
- package/dist/waveform-sounds-no-autoinit.esm.js +445 -144
- package/dist/waveform-sounds-render.esm.js +220 -78
- package/dist/waveform-sounds.css +4 -0
- package/dist/waveform-sounds.esm.js +445 -144
- package/dist/waveform-sounds.js +445 -144
- package/dist/waveform-sounds.min.css +1 -1
- package/dist/waveform-sounds.min.js +1 -1
- package/package.json +1 -1
- package/src/css/waveform-sounds.css +4 -0
- package/src/js/core/WaveformSounds.ts +224 -67
- package/src/js/core/element.ts +1 -1
- package/src/js/core/options.ts +1 -0
- package/src/js/data/keys.ts +156 -0
- package/src/js/data/navigation.ts +35 -8
- package/src/js/data/sounds.ts +29 -22
- package/src/js/data/url-state.ts +7 -3
- package/src/js/dom/draw.ts +16 -2
- package/src/js/dom/menus.ts +2 -1
- package/src/js/dom/rows.ts +38 -12
- package/src/js/render/icons.ts +59 -16
- package/src/js/render/markup.ts +115 -49
- package/src/js/render/options.ts +3 -1
- package/src/js/render/strings.ts +53 -1
- package/src/js/types.ts +24 -0
- package/types/core/WaveformSounds.d.ts +3 -3
- package/types/core/WaveformSounds.d.ts.map +1 -1
- package/types/core/options.d.ts.map +1 -1
- package/types/data/keys.d.ts +88 -0
- package/types/data/keys.d.ts.map +1 -0
- package/types/data/navigation.d.ts +27 -9
- package/types/data/navigation.d.ts.map +1 -1
- package/types/data/sounds.d.ts +20 -5
- package/types/data/sounds.d.ts.map +1 -1
- package/types/data/url-state.d.ts +6 -1
- package/types/data/url-state.d.ts.map +1 -1
- package/types/dom/draw.d.ts +5 -2
- package/types/dom/draw.d.ts.map +1 -1
- package/types/dom/menus.d.ts.map +1 -1
- package/types/dom/rows.d.ts +19 -8
- package/types/dom/rows.d.ts.map +1 -1
- package/types/render/icons.d.ts +41 -3
- package/types/render/icons.d.ts.map +1 -1
- package/types/render/markup.d.ts +27 -4
- package/types/render/markup.d.ts.map +1 -1
- package/types/render/options.d.ts +1 -1
- package/types/render/options.d.ts.map +1 -1
- package/types/render/strings.d.ts +22 -1
- package/types/render/strings.d.ts.map +1 -1
- package/types/types.d.ts +24 -0
- package/types/types.d.ts.map +1 -1
|
@@ -25,6 +25,76 @@ var ACCENTS = Object.freeze([
|
|
|
25
25
|
[65056, 65071]
|
|
26
26
|
]);
|
|
27
27
|
|
|
28
|
+
// src/js/data/keys.ts
|
|
29
|
+
var KEY_PITCH = {
|
|
30
|
+
C: 0,
|
|
31
|
+
"B#": 0,
|
|
32
|
+
"C#": 1,
|
|
33
|
+
Db: 1,
|
|
34
|
+
D: 2,
|
|
35
|
+
"D#": 3,
|
|
36
|
+
Eb: 3,
|
|
37
|
+
E: 4,
|
|
38
|
+
Fb: 4,
|
|
39
|
+
"E#": 5,
|
|
40
|
+
F: 5,
|
|
41
|
+
"F#": 6,
|
|
42
|
+
Gb: 6,
|
|
43
|
+
G: 7,
|
|
44
|
+
"G#": 8,
|
|
45
|
+
Ab: 8,
|
|
46
|
+
A: 9,
|
|
47
|
+
"A#": 10,
|
|
48
|
+
Bb: 10,
|
|
49
|
+
B: 11,
|
|
50
|
+
Cb: 11
|
|
51
|
+
};
|
|
52
|
+
var CONVENTIONAL_MAJOR = ["C", "Db", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"];
|
|
53
|
+
var CONVENTIONAL_MINOR = ["Cm", "C#m", "Dm", "Ebm", "Em", "Fm", "F#m", "Gm", "G#m", "Am", "Bbm", "Bm"];
|
|
54
|
+
function parseKey(key) {
|
|
55
|
+
const m = /^([A-G][#b]?)(m?)$/.exec(String(key ?? ""));
|
|
56
|
+
if (!m || KEY_PITCH[m[1]] === void 0) return null;
|
|
57
|
+
return { root: m[1], pitch: KEY_PITCH[m[1]], minor: m[2] === "m" };
|
|
58
|
+
}
|
|
59
|
+
function keyClass(key) {
|
|
60
|
+
const k = parseKey(key);
|
|
61
|
+
return k ? `${k.pitch}${k.minor ? "m" : ""}` : key;
|
|
62
|
+
}
|
|
63
|
+
function keyRank(key) {
|
|
64
|
+
if (!key) return Infinity;
|
|
65
|
+
const k = parseKey(key);
|
|
66
|
+
return k ? k.pitch * 2 + (k.minor ? 1 : 0) : 1e3;
|
|
67
|
+
}
|
|
68
|
+
function canonicalSpelling(counts) {
|
|
69
|
+
let best = 0;
|
|
70
|
+
for (const n of counts.values()) if (n > best) best = n;
|
|
71
|
+
const tied = [...counts].filter(([, n]) => n === best).map(([k2]) => k2).sort();
|
|
72
|
+
if (tied.length === 1) return tied[0];
|
|
73
|
+
const k = parseKey(tied[0]);
|
|
74
|
+
const conventional = k ? (k.minor ? CONVENTIONAL_MINOR : CONVENTIONAL_MAJOR)[k.pitch] : "";
|
|
75
|
+
return tied.includes(conventional) ? conventional : tied[0];
|
|
76
|
+
}
|
|
77
|
+
function keyEntries(keys, merge = true) {
|
|
78
|
+
const groups = /* @__PURE__ */ new Map();
|
|
79
|
+
for (const key of keys) {
|
|
80
|
+
if (!key) continue;
|
|
81
|
+
const cls = merge ? keyClass(key) : key;
|
|
82
|
+
const g = groups.get(cls) ?? /* @__PURE__ */ new Map();
|
|
83
|
+
groups.set(cls, g);
|
|
84
|
+
g.set(key, (g.get(key) || 0) + 1);
|
|
85
|
+
}
|
|
86
|
+
const out = [];
|
|
87
|
+
const aliases = {};
|
|
88
|
+
for (const g of groups.values()) {
|
|
89
|
+
const entry = canonicalSpelling(g);
|
|
90
|
+
out.push(entry);
|
|
91
|
+
const others = [...g.keys()].filter((k) => k !== entry).sort();
|
|
92
|
+
if (others.length) aliases[entry] = others;
|
|
93
|
+
}
|
|
94
|
+
out.sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b));
|
|
95
|
+
return { keys: out, aliases };
|
|
96
|
+
}
|
|
97
|
+
|
|
28
98
|
// src/js/data/sounds.ts
|
|
29
99
|
function encodePeaks(peaks) {
|
|
30
100
|
if (!Array.isArray(peaks)) return "";
|
|
@@ -71,14 +141,6 @@ function normalizeKey(key) {
|
|
|
71
141
|
const minor = m[3] && /^m(in(or)?)?$/i.test(m[3]) && m[3] !== "M";
|
|
72
142
|
return root + acc + (minor ? "m" : "");
|
|
73
143
|
}
|
|
74
|
-
var KEY_PITCH = { C: 0, "C#": 1, Db: 1, D: 2, "D#": 3, Eb: 3, E: 4, F: 5, "F#": 6, Gb: 6, G: 7, "G#": 8, Ab: 8, A: 9, "A#": 10, Bb: 10, B: 11 };
|
|
75
|
-
function keyRank(key) {
|
|
76
|
-
if (!key) return Infinity;
|
|
77
|
-
const minor = key.endsWith("m");
|
|
78
|
-
const root = minor ? key.slice(0, -1) : key;
|
|
79
|
-
const p = KEY_PITCH[root];
|
|
80
|
-
return p === void 0 ? 1e3 : p * 2 + (minor ? 1 : 0);
|
|
81
|
-
}
|
|
82
144
|
function formatDuration(seconds) {
|
|
83
145
|
if (seconds == null || seconds === "") return "";
|
|
84
146
|
const s = Number(seconds);
|
|
@@ -146,13 +208,13 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
146
208
|
});
|
|
147
209
|
return out;
|
|
148
210
|
}
|
|
149
|
-
function facets(sounds) {
|
|
211
|
+
function facets(sounds, options = {}) {
|
|
150
212
|
const types = /* @__PURE__ */ new Map();
|
|
151
|
-
const keys =
|
|
213
|
+
const keys = [];
|
|
152
214
|
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
153
215
|
for (const s of sounds) {
|
|
154
216
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
155
|
-
if (s.key) keys.
|
|
217
|
+
if (s.key) keys.push(s.key);
|
|
156
218
|
if (s.bpm != null) {
|
|
157
219
|
min = Math.min(min, s.bpm);
|
|
158
220
|
max = Math.max(max, s.bpm);
|
|
@@ -160,9 +222,11 @@ function facets(sounds) {
|
|
|
160
222
|
if (s.duration != null) hasDuration = true;
|
|
161
223
|
if (s.loop) loops++;
|
|
162
224
|
}
|
|
225
|
+
const entries = keyEntries(keys, options.mergeEnharmonicKeys !== false);
|
|
163
226
|
return {
|
|
164
227
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
165
|
-
keys:
|
|
228
|
+
keys: entries.keys,
|
|
229
|
+
keyAliases: entries.aliases,
|
|
166
230
|
bpm: min === Infinity ? null : { min, max },
|
|
167
231
|
hasDuration,
|
|
168
232
|
loops,
|
|
@@ -180,6 +244,31 @@ var SORT_NEEDS = {
|
|
|
180
244
|
function availableSorts(sorts, f) {
|
|
181
245
|
return sorts.filter((sort) => SORT_NEEDS[sort]?.(f));
|
|
182
246
|
}
|
|
247
|
+
function sortSounds(sounds, by = "default") {
|
|
248
|
+
const list = sounds.map((s, i) => ({ s, i }));
|
|
249
|
+
const last = (v) => v == null ? Infinity : v;
|
|
250
|
+
const cmp = {
|
|
251
|
+
title: (a, b) => a.s.title.localeCompare(b.s.title, void 0, { numeric: true, sensitivity: "base" }),
|
|
252
|
+
bpm: (a, b) => last(a.s.bpm) - last(b.s.bpm),
|
|
253
|
+
key: (a, b) => keyRank(a.s.key) - keyRank(b.s.key),
|
|
254
|
+
duration: (a, b) => last(a.s.duration) - last(b.s.duration)
|
|
255
|
+
}[by];
|
|
256
|
+
if (cmp) list.sort((a, b) => cmp(a, b) || a.i - b.i);
|
|
257
|
+
return list.map((x) => x.s);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// src/js/shared/utils.ts
|
|
261
|
+
function hashString(str) {
|
|
262
|
+
let hash = 5381;
|
|
263
|
+
for (const char of str) hash = hash * 33 + char.codePointAt(0) >>> 0;
|
|
264
|
+
return hash;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/js/data/navigation.ts
|
|
268
|
+
var RENDER_CHUNK = 50;
|
|
269
|
+
function firstRender(pageSize) {
|
|
270
|
+
return pageSize > 0 ? pageSize : RENDER_CHUNK;
|
|
271
|
+
}
|
|
183
272
|
|
|
184
273
|
// src/js/render/html.ts
|
|
185
274
|
var VOID = /* @__PURE__ */ new Set(["input", "br", "img"]);
|
|
@@ -201,19 +290,27 @@ function h(tag, attributes = {}, ...children) {
|
|
|
201
290
|
}
|
|
202
291
|
|
|
203
292
|
// src/js/render/icons.ts
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
chevron: icon("M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z", "ws-menu-chevron"),
|
|
213
|
-
check: icon("M9.5 16.2 5.3 12l-1.4 1.4 5.6 5.6 11-11-1.4-1.4z", "ws-menu-check"),
|
|
214
|
-
download: icon("M11 4h2v8.6l3.3-3.3 1.4 1.4L12 16.4l-5.7-5.7 1.4-1.4 3.3 3.3zM5 18h14v2H5z"),
|
|
215
|
-
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")
|
|
293
|
+
var ICON_PATHS = {
|
|
294
|
+
play: "M8 5.5v13l11-6.5z",
|
|
295
|
+
pause: "M7 5h3.5v14H7zM13.5 5H17v14h-3.5z",
|
|
296
|
+
search: "M10.5 4a6.5 6.5 0 1 0 4.03 11.6l4.43 4.43 1.41-1.41-4.43-4.43A6.5 6.5 0 0 0 10.5 4zm0 2a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9z",
|
|
297
|
+
chevron: "M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z",
|
|
298
|
+
check: "M9.5 16.2 5.3 12l-1.4 1.4 5.6 5.6 11-11-1.4-1.4z",
|
|
299
|
+
download: "M11 4h2v8.6l3.3-3.3 1.4 1.4L12 16.4l-5.7-5.7 1.4-1.4 3.3 3.3zM5 18h14v2H5z",
|
|
300
|
+
loop: "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"
|
|
216
301
|
};
|
|
302
|
+
var ICON_NAMES = Object.keys(ICON_PATHS);
|
|
303
|
+
function iconId(id, name) {
|
|
304
|
+
return `${id}-i-${name}`;
|
|
305
|
+
}
|
|
306
|
+
function iconSprite(id, names) {
|
|
307
|
+
const symbols = ICON_NAMES.filter((n) => names.includes(n)).map((n) => `<symbol id="${escapeHtml(iconId(id, n))}" viewBox="0 0 24 24"><path d="${ICON_PATHS[n]}"/></symbol>`).join("");
|
|
308
|
+
return `<svg class="ws-sprite" data-ws-sprite="${escapeHtml(id)}" width="0" height="0" aria-hidden="true" focusable="false">${symbols}</svg>`;
|
|
309
|
+
}
|
|
310
|
+
function icon(id, name, extraClass = "") {
|
|
311
|
+
const cls = extraClass ? `ws-icon ${extraClass}` : "ws-icon";
|
|
312
|
+
return `<svg class="${cls}" aria-hidden="true" focusable="false"><use href="#${escapeHtml(iconId(id, name))}"/></svg>`;
|
|
313
|
+
}
|
|
217
314
|
|
|
218
315
|
// src/js/data/bpm.ts
|
|
219
316
|
function bpmExtent(range) {
|
|
@@ -275,7 +372,15 @@ var DEFAULT_STRINGS = {
|
|
|
275
372
|
nowPlaying: "Playing {title}",
|
|
276
373
|
playError: "Could not play {title}",
|
|
277
374
|
loadError: "Could not load the sounds.",
|
|
278
|
-
noSounds: "No sounds."
|
|
375
|
+
noSounds: "No sounds.",
|
|
376
|
+
rowBpm: "{bpm} BPM",
|
|
377
|
+
rowKey: "key {key}",
|
|
378
|
+
rowDuration: "{duration}",
|
|
379
|
+
keyMajor: "{note} major",
|
|
380
|
+
keyMinor: "{note} minor",
|
|
381
|
+
noteSharp: "{note} sharp",
|
|
382
|
+
noteFlat: "{note} flat",
|
|
383
|
+
listSeparator: ", "
|
|
279
384
|
};
|
|
280
385
|
var SORT_LABEL_KEYS = {
|
|
281
386
|
default: "sortDefault",
|
|
@@ -296,6 +401,27 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
|
296
401
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
297
402
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
298
403
|
}
|
|
404
|
+
function spokenKey(key, strings = DEFAULT_STRINGS) {
|
|
405
|
+
const k = parseKey(key);
|
|
406
|
+
if (!k) return key;
|
|
407
|
+
const letter = k.root[0], acc = k.root.slice(1);
|
|
408
|
+
const note = acc === "#" ? fill(strings.noteSharp, { note: letter }) : acc === "b" ? fill(strings.noteFlat, { note: letter }) : letter;
|
|
409
|
+
return fill(k.minor ? strings.keyMinor : strings.keyMajor, { note });
|
|
410
|
+
}
|
|
411
|
+
function rowSummary(sound, columns, strings = DEFAULT_STRINGS) {
|
|
412
|
+
const parts = [];
|
|
413
|
+
for (const c of columns) {
|
|
414
|
+
if (c === "type" && sound.type) parts.push(sound.type);
|
|
415
|
+
else if (c === "bpm" && sound.bpm != null) parts.push(fill(strings.rowBpm, { bpm: sound.bpm }));
|
|
416
|
+
else if (c === "key" && sound.key) parts.push(fill(strings.rowKey, { key: spokenKey(sound.key, strings) }));
|
|
417
|
+
else if (c === "duration") {
|
|
418
|
+
const d = formatDuration(sound.duration);
|
|
419
|
+
if (d) parts.push(fill(strings.rowDuration, { duration: d }));
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (sound.loop) parts.push(strings.isLoop);
|
|
423
|
+
return parts.join(strings.listSeparator);
|
|
424
|
+
}
|
|
299
425
|
|
|
300
426
|
// src/js/render/options.ts
|
|
301
427
|
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
@@ -310,7 +436,8 @@ var RENDER_DEFAULTS = {
|
|
|
310
436
|
menuSearch: 8,
|
|
311
437
|
pageSize: 50,
|
|
312
438
|
columns: [...COLUMNS],
|
|
313
|
-
maxTypeChips: 10
|
|
439
|
+
maxTypeChips: 10,
|
|
440
|
+
mergeEnharmonicKeys: true
|
|
314
441
|
};
|
|
315
442
|
var RENDER_OPTION_KEYS = [...Object.keys(RENDER_DEFAULTS), "idPrefix", "loop", "strings"];
|
|
316
443
|
function pickRenderOptions(options) {
|
|
@@ -344,17 +471,11 @@ function resolveRenderOptions(options = {}) {
|
|
|
344
471
|
menuSearch: wholeNumber(o.menuSearch, RENDER_DEFAULTS.menuSearch),
|
|
345
472
|
maxTypeChips: wholeNumber(o.maxTypeChips, RENDER_DEFAULTS.maxTypeChips),
|
|
346
473
|
pageSize: wholeNumber(o.pageSize, RENDER_DEFAULTS.pageSize),
|
|
474
|
+
mergeEnharmonicKeys: o.mergeEnharmonicKeys !== false,
|
|
347
475
|
strings: { ...DEFAULT_STRINGS, ...defined(options.strings) }
|
|
348
476
|
};
|
|
349
477
|
}
|
|
350
478
|
|
|
351
|
-
// src/js/shared/utils.ts
|
|
352
|
-
function hashString(str) {
|
|
353
|
-
let hash = 5381;
|
|
354
|
-
for (const char of str) hash = hash * 33 + char.codePointAt(0) >>> 0;
|
|
355
|
-
return hash;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
479
|
// src/js/render/markup.ts
|
|
359
480
|
function idBase(sounds) {
|
|
360
481
|
const signature = [sounds.length, ...sounds.map((s) => s.url)].join("|");
|
|
@@ -377,11 +498,11 @@ function toolbarPlan(f, o) {
|
|
|
377
498
|
function loopsByDefault(loop, f) {
|
|
378
499
|
return loop == null ? f.loops > 0 : !!loop;
|
|
379
500
|
}
|
|
380
|
-
function renderSearch(s) {
|
|
501
|
+
function renderSearch(s, id) {
|
|
381
502
|
return h(
|
|
382
503
|
"label",
|
|
383
504
|
{ class: "ws-search" },
|
|
384
|
-
|
|
505
|
+
icon(id, "search"),
|
|
385
506
|
h("span", { class: "ws-sr" }, text(s.search)),
|
|
386
507
|
h("input", { type: "search", class: "ws-search-input", "data-ws-search": true, placeholder: s.searchPlaceholder, autocomplete: "off", spellcheck: "false" })
|
|
387
508
|
);
|
|
@@ -395,7 +516,7 @@ function renderMenu(name, m) {
|
|
|
395
516
|
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "listbox", "aria-expanded": "false", "aria-controls": listId },
|
|
396
517
|
m.prefix ? h("span", { class: "ws-menu-prefix" }, text(m.prefix)) : h("span", { class: "ws-sr" }, text(`${m.label}: `)),
|
|
397
518
|
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(current.label)),
|
|
398
|
-
|
|
519
|
+
icon(m.id, "chevron", "ws-menu-chevron")
|
|
399
520
|
);
|
|
400
521
|
const search = searchable && h("input", {
|
|
401
522
|
type: "search",
|
|
@@ -412,8 +533,8 @@ function renderMenu(name, m) {
|
|
|
412
533
|
});
|
|
413
534
|
const options = m.options.map((o, i) => h(
|
|
414
535
|
"li",
|
|
415
|
-
{ role: "option", id: `${m.id}-${name}-${i}`, class: "ws-menu-option", "data-value": o.value, "aria-selected": String(o === current) },
|
|
416
|
-
|
|
536
|
+
{ role: "option", id: `${m.id}-${name}-${i}`, class: "ws-menu-option", "data-value": o.value, "data-alt": o.alt, "aria-selected": String(o === current) },
|
|
537
|
+
icon(m.id, "check", "ws-menu-check"),
|
|
417
538
|
h("span", { class: "ws-menu-text" }, text(o.label)),
|
|
418
539
|
o.count != null && h("span", { class: "ws-menu-count" }, text(o.count))
|
|
419
540
|
));
|
|
@@ -450,7 +571,7 @@ function renderBpmMenu({ id, s, range }) {
|
|
|
450
571
|
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
451
572
|
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
452
573
|
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
453
|
-
|
|
574
|
+
icon(id, "chevron", "ws-menu-chevron")
|
|
454
575
|
),
|
|
455
576
|
h(
|
|
456
577
|
"div",
|
|
@@ -485,8 +606,8 @@ function renderLoopFilter(s) {
|
|
|
485
606
|
button("one-shot", s.oneShots)
|
|
486
607
|
);
|
|
487
608
|
}
|
|
488
|
-
function renderLoopToggle(s, pressed) {
|
|
489
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) },
|
|
609
|
+
function renderLoopToggle(s, pressed, id) {
|
|
610
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, icon(id, "loop"), h("span", {}, text(s.loop)));
|
|
490
611
|
}
|
|
491
612
|
function renderChip(value, label, count, pressed) {
|
|
492
613
|
return h(
|
|
@@ -510,7 +631,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
510
631
|
label: s.key,
|
|
511
632
|
value: "",
|
|
512
633
|
placeholder: s.findKey,
|
|
513
|
-
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
634
|
+
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k, alt: f.keyAliases[k]?.join(" ") }))]
|
|
514
635
|
}),
|
|
515
636
|
plan.bpm && renderBpmMenu({ id, s, range: bpmExtent(f.bpm) }),
|
|
516
637
|
plan.loops && renderLoopFilter(s),
|
|
@@ -520,7 +641,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
520
641
|
value: plan.sorts[0],
|
|
521
642
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
522
643
|
}),
|
|
523
|
-
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
644
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f), id)
|
|
524
645
|
].filter(Boolean);
|
|
525
646
|
const chips = plan.types === "chips" && h(
|
|
526
647
|
"div",
|
|
@@ -532,7 +653,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
532
653
|
return h(
|
|
533
654
|
"div",
|
|
534
655
|
{ class: "ws-toolbar" },
|
|
535
|
-
plan.search && renderSearch(s),
|
|
656
|
+
plan.search && renderSearch(s, id),
|
|
536
657
|
controls.length > 0 && h("div", { class: "ws-controls" }, controls),
|
|
537
658
|
// The chips and the count share a row (the count alone without chips).
|
|
538
659
|
(chips || count) && h("div", { class: "ws-meta" }, chips, count)
|
|
@@ -544,49 +665,66 @@ var CELLS = {
|
|
|
544
665
|
key: (sound) => text(sound.key),
|
|
545
666
|
duration: (sound) => text(formatDuration(sound.duration))
|
|
546
667
|
};
|
|
547
|
-
function renderRow(sound, index, o,
|
|
668
|
+
function renderRow(sound, index, o, id) {
|
|
548
669
|
const s = o.strings;
|
|
549
670
|
const vars = { title: sound.title };
|
|
550
671
|
const cells = o.columns.map((c) => h("span", { class: `ws-cell ws-${c}` }, CELLS[c](sound)));
|
|
672
|
+
const summary = rowSummary(sound, o.columns, s);
|
|
673
|
+
const described = summary ? `${id}-d${index}` : null;
|
|
551
674
|
return h(
|
|
552
675
|
"li",
|
|
553
|
-
{
|
|
554
|
-
|
|
555
|
-
"
|
|
556
|
-
"
|
|
557
|
-
"
|
|
558
|
-
"
|
|
559
|
-
|
|
560
|
-
"data-bpm": sound.bpm,
|
|
561
|
-
"data-key": sound.key || null,
|
|
562
|
-
"data-duration": sound.duration,
|
|
563
|
-
"data-tags": sound.tags?.length ? sound.tags.join(",") : null,
|
|
564
|
-
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
565
|
-
"data-waveform": sound.waveform,
|
|
566
|
-
"data-download": sound.download,
|
|
567
|
-
"data-loop": sound.loop ? "true" : null,
|
|
568
|
-
hidden
|
|
569
|
-
},
|
|
570
|
-
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
676
|
+
{ class: "ws-row", "data-ws-index": index },
|
|
677
|
+
h(
|
|
678
|
+
"button",
|
|
679
|
+
{ type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars), "aria-describedby": described },
|
|
680
|
+
icon(id, "play", "ws-icon-play"),
|
|
681
|
+
icon(id, "pause", "ws-icon-pause")
|
|
682
|
+
),
|
|
571
683
|
h(
|
|
572
684
|
"span",
|
|
573
685
|
{ class: "ws-cell ws-title" },
|
|
574
686
|
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
575
|
-
// A loop says so beside its name; a one-shot carries nothing.
|
|
576
|
-
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop
|
|
687
|
+
// A loop says so beside its name (and in the read-out); a one-shot carries nothing.
|
|
688
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop, "aria-hidden": "true" }, icon(id, "loop"))
|
|
577
689
|
),
|
|
578
690
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
579
691
|
// rows: one line under the title.
|
|
580
|
-
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
{ class: "ws-wave", role: "slider", "aria-label": fill(s.seek, vars), "aria-valuemin": "0", "aria-valuemax": "100", "aria-valuenow": "0", tabindex: "-1" },
|
|
584
|
-
h("canvas", { class: "ws-canvas", "aria-hidden": "true" })
|
|
585
|
-
),
|
|
692
|
+
cells.length > 0 && h("span", { class: "ws-cells", "aria-hidden": "true" }, cells),
|
|
693
|
+
summary && h("span", { class: "ws-sr", id: described }, text(summary)),
|
|
694
|
+
o.player === "inline" && h("span", { class: "ws-wave", "aria-hidden": "true" }, h("canvas", { class: "ws-canvas" })),
|
|
586
695
|
// Optional, per sound: a plain link. Rows without one carry nothing.
|
|
587
|
-
sound.download && h("a", { class: "ws-download", href: sound.download, download: true, "aria-label": fill(s.download, vars) },
|
|
696
|
+
sound.download && h("a", { class: "ws-download", href: sound.download, download: true, "aria-label": fill(s.download, vars) }, icon(id, "download"))
|
|
588
697
|
);
|
|
589
698
|
}
|
|
699
|
+
function renderSoundsData(list) {
|
|
700
|
+
const data = list.map((s, i) => {
|
|
701
|
+
const d = {};
|
|
702
|
+
if (s.id !== `sound-${i + 1}`) d.id = s.id;
|
|
703
|
+
d.url = s.url;
|
|
704
|
+
d.title = s.title;
|
|
705
|
+
if (s.type) d.type = s.type;
|
|
706
|
+
if (s.bpm != null) d.bpm = s.bpm;
|
|
707
|
+
if (s.key) d.key = s.key;
|
|
708
|
+
if (s.duration != null) d.duration = s.duration;
|
|
709
|
+
if (s.tags.length) d.tags = s.tags;
|
|
710
|
+
if (s.peaks) d.peaks = encodePeaks(s.peaks);
|
|
711
|
+
if (s.waveform) d.waveform = s.waveform;
|
|
712
|
+
if (s.download) d.download = s.download;
|
|
713
|
+
if (s.loop) d.loop = true;
|
|
714
|
+
return d;
|
|
715
|
+
});
|
|
716
|
+
return `<script type="application/json" data-ws-sounds>${JSON.stringify(data).replace(/</g, "\\u003c")}<\/script>`;
|
|
717
|
+
}
|
|
718
|
+
function iconsUsed(plan, list) {
|
|
719
|
+
const names = [];
|
|
720
|
+
if (list.length) names.push("play", "pause");
|
|
721
|
+
if (plan.search) names.push("search");
|
|
722
|
+
if (plan.types === "menu" || plan.key || plan.sorts.length) names.push("chevron", "check");
|
|
723
|
+
else if (plan.bpm) names.push("chevron");
|
|
724
|
+
if (plan.loop || list.some((s) => s.loop)) names.push("loop");
|
|
725
|
+
if (list.some((s) => s.download)) names.push("download");
|
|
726
|
+
return names;
|
|
727
|
+
}
|
|
590
728
|
function renderFooter({ o, s, total }) {
|
|
591
729
|
const page = o.pageSize > 0 ? o.pageSize : total;
|
|
592
730
|
const more = Math.max(0, total - page);
|
|
@@ -605,15 +743,19 @@ function renderFooter({ o, s, total }) {
|
|
|
605
743
|
].join("");
|
|
606
744
|
}
|
|
607
745
|
function renderSounds(sounds, options = {}) {
|
|
746
|
+
return renderList(normalizeSounds(sounds), options, true);
|
|
747
|
+
}
|
|
748
|
+
function renderList(list, options, withData) {
|
|
608
749
|
const o = resolveRenderOptions(options);
|
|
609
|
-
const
|
|
610
|
-
const
|
|
611
|
-
const
|
|
612
|
-
|
|
750
|
+
const ctx = { o, s: o.strings, f: facets(list, o), total: list.length, id: o.idPrefix || idBase(list) };
|
|
751
|
+
const plan = toolbarPlan(ctx.f, o);
|
|
752
|
+
const index = new Map(list.map((sound, i) => [sound, i]));
|
|
753
|
+
const first = sortSounds(list, availableSorts(o.sorts, ctx.f)[0] || "default").slice(0, firstRender(o.pageSize));
|
|
754
|
+
return iconSprite(ctx.id, iconsUsed(plan, list)) + renderToolbar(plan, ctx) + h(
|
|
613
755
|
"ul",
|
|
614
756
|
{ class: `ws-list ws-list--${o.player}`, role: "list", "data-ws-list": true },
|
|
615
|
-
|
|
616
|
-
) + renderFooter(ctx);
|
|
757
|
+
first.map((sound) => renderRow(sound, index.get(sound), o, ctx.id))
|
|
758
|
+
) + renderFooter(ctx) + (withData ? renderSoundsData(list) : "");
|
|
617
759
|
}
|
|
618
760
|
function renderOptionAttributes(options = {}) {
|
|
619
761
|
const set = pickRenderOptions(options);
|
package/dist/waveform-sounds.css
CHANGED
|
@@ -84,6 +84,10 @@ waveform-sounds:not(:defined):empty { min-height: var(--ws-element-height, 0); }
|
|
|
84
84
|
border: 0;
|
|
85
85
|
}
|
|
86
86
|
.ws-icon { width: 1em; height: 1em; fill: currentColor; flex: none; }
|
|
87
|
+
/* The icons' one definition per list (each icon is a <use> of it): out of
|
|
88
|
+
* the flow, so its empty line box adds no height. Not display: none, which
|
|
89
|
+
* some engines treat as removing what it defines. */
|
|
90
|
+
.ws-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
|
|
87
91
|
|
|
88
92
|
/* ── Controls: shared ────────────────────────────────────────────────── */
|
|
89
93
|
/* The pill-shaped controls share one frame... */
|