@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
|
@@ -70,6 +70,94 @@ function matchesAll(name, query, options = {}) {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// src/js/data/keys.ts
|
|
74
|
+
var KEY_PITCH = {
|
|
75
|
+
C: 0,
|
|
76
|
+
"B#": 0,
|
|
77
|
+
"C#": 1,
|
|
78
|
+
Db: 1,
|
|
79
|
+
D: 2,
|
|
80
|
+
"D#": 3,
|
|
81
|
+
Eb: 3,
|
|
82
|
+
E: 4,
|
|
83
|
+
Fb: 4,
|
|
84
|
+
"E#": 5,
|
|
85
|
+
F: 5,
|
|
86
|
+
"F#": 6,
|
|
87
|
+
Gb: 6,
|
|
88
|
+
G: 7,
|
|
89
|
+
"G#": 8,
|
|
90
|
+
Ab: 8,
|
|
91
|
+
A: 9,
|
|
92
|
+
"A#": 10,
|
|
93
|
+
Bb: 10,
|
|
94
|
+
B: 11,
|
|
95
|
+
Cb: 11
|
|
96
|
+
};
|
|
97
|
+
var CONVENTIONAL_MAJOR = ["C", "Db", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"];
|
|
98
|
+
var CONVENTIONAL_MINOR = ["Cm", "C#m", "Dm", "Ebm", "Em", "Fm", "F#m", "Gm", "G#m", "Am", "Bbm", "Bm"];
|
|
99
|
+
var SHARPS = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];
|
|
100
|
+
var FLATS = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"];
|
|
101
|
+
function parseKey(key) {
|
|
102
|
+
const m = /^([A-G][#b]?)(m?)$/.exec(String(key ?? ""));
|
|
103
|
+
if (!m || KEY_PITCH[m[1]] === void 0) return null;
|
|
104
|
+
return { root: m[1], pitch: KEY_PITCH[m[1]], minor: m[2] === "m" };
|
|
105
|
+
}
|
|
106
|
+
function keyClass(key) {
|
|
107
|
+
const k = parseKey(key);
|
|
108
|
+
return k ? `${k.pitch}${k.minor ? "m" : ""}` : key;
|
|
109
|
+
}
|
|
110
|
+
function sameKey(a, b, merge = true) {
|
|
111
|
+
return a === b || merge && !!a && keyClass(a) === keyClass(b);
|
|
112
|
+
}
|
|
113
|
+
function keyRank(key) {
|
|
114
|
+
if (!key) return Infinity;
|
|
115
|
+
const k = parseKey(key);
|
|
116
|
+
return k ? k.pitch * 2 + (k.minor ? 1 : 0) : 1e3;
|
|
117
|
+
}
|
|
118
|
+
function enharmonics(key) {
|
|
119
|
+
const k = parseKey(key);
|
|
120
|
+
if (!k) return key ? [key] : [];
|
|
121
|
+
const mode = k.minor ? "m" : "";
|
|
122
|
+
return [.../* @__PURE__ */ new Set([key, SHARPS[k.pitch] + mode, FLATS[k.pitch] + mode])];
|
|
123
|
+
}
|
|
124
|
+
function canonicalSpelling(counts) {
|
|
125
|
+
let best = 0;
|
|
126
|
+
for (const n of counts.values()) if (n > best) best = n;
|
|
127
|
+
const tied = [...counts].filter(([, n]) => n === best).map(([k2]) => k2).sort();
|
|
128
|
+
if (tied.length === 1) return tied[0];
|
|
129
|
+
const k = parseKey(tied[0]);
|
|
130
|
+
const conventional = k ? (k.minor ? CONVENTIONAL_MINOR : CONVENTIONAL_MAJOR)[k.pitch] : "";
|
|
131
|
+
return tied.includes(conventional) ? conventional : tied[0];
|
|
132
|
+
}
|
|
133
|
+
function keyEntries(keys, merge = true) {
|
|
134
|
+
const groups = /* @__PURE__ */ new Map();
|
|
135
|
+
for (const key of keys) {
|
|
136
|
+
if (!key) continue;
|
|
137
|
+
const cls = merge ? keyClass(key) : key;
|
|
138
|
+
const g = groups.get(cls) ?? /* @__PURE__ */ new Map();
|
|
139
|
+
groups.set(cls, g);
|
|
140
|
+
g.set(key, (g.get(key) || 0) + 1);
|
|
141
|
+
}
|
|
142
|
+
const out = [];
|
|
143
|
+
const aliases = {};
|
|
144
|
+
for (const g of groups.values()) {
|
|
145
|
+
const entry = canonicalSpelling(g);
|
|
146
|
+
out.push(entry);
|
|
147
|
+
const others = [...g.keys()].filter((k) => k !== entry).sort();
|
|
148
|
+
if (others.length) aliases[entry] = others;
|
|
149
|
+
}
|
|
150
|
+
out.sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b));
|
|
151
|
+
return { keys: out, aliases };
|
|
152
|
+
}
|
|
153
|
+
function keyEntry(key, entries, merge = true) {
|
|
154
|
+
if (!key) return "";
|
|
155
|
+
if (entries.includes(key)) return key;
|
|
156
|
+
if (!merge) return "";
|
|
157
|
+
const cls = keyClass(key);
|
|
158
|
+
return entries.find((e) => keyClass(e) === cls) ?? "";
|
|
159
|
+
}
|
|
160
|
+
|
|
73
161
|
// src/js/data/sounds.ts
|
|
74
162
|
function encodePeaks(peaks) {
|
|
75
163
|
if (!Array.isArray(peaks)) return "";
|
|
@@ -116,14 +204,6 @@ function normalizeKey(key) {
|
|
|
116
204
|
const minor = m[3] && /^m(in(or)?)?$/i.test(m[3]) && m[3] !== "M";
|
|
117
205
|
return root + acc + (minor ? "m" : "");
|
|
118
206
|
}
|
|
119
|
-
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 };
|
|
120
|
-
function keyRank(key) {
|
|
121
|
-
if (!key) return Infinity;
|
|
122
|
-
const minor = key.endsWith("m");
|
|
123
|
-
const root = minor ? key.slice(0, -1) : key;
|
|
124
|
-
const p = KEY_PITCH[root];
|
|
125
|
-
return p === void 0 ? 1e3 : p * 2 + (minor ? 1 : 0);
|
|
126
|
-
}
|
|
127
207
|
function formatDuration(seconds) {
|
|
128
208
|
if (seconds == null || seconds === "") return "";
|
|
129
209
|
const s = Number(seconds);
|
|
@@ -197,13 +277,13 @@ function normalizeSounds(list, peakScale = 1) {
|
|
|
197
277
|
});
|
|
198
278
|
return out;
|
|
199
279
|
}
|
|
200
|
-
function facets(sounds) {
|
|
280
|
+
function facets(sounds, options = {}) {
|
|
201
281
|
const types = /* @__PURE__ */ new Map();
|
|
202
|
-
const keys =
|
|
282
|
+
const keys = [];
|
|
203
283
|
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
204
284
|
for (const s of sounds) {
|
|
205
285
|
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
206
|
-
if (s.key) keys.
|
|
286
|
+
if (s.key) keys.push(s.key);
|
|
207
287
|
if (s.bpm != null) {
|
|
208
288
|
min = Math.min(min, s.bpm);
|
|
209
289
|
max = Math.max(max, s.bpm);
|
|
@@ -211,18 +291,21 @@ function facets(sounds) {
|
|
|
211
291
|
if (s.duration != null) hasDuration = true;
|
|
212
292
|
if (s.loop) loops++;
|
|
213
293
|
}
|
|
294
|
+
const entries = keyEntries(keys, options.mergeEnharmonicKeys !== false);
|
|
214
295
|
return {
|
|
215
296
|
types: [...types].map(([name, count]) => ({ name, count })),
|
|
216
|
-
keys:
|
|
297
|
+
keys: entries.keys,
|
|
298
|
+
keyAliases: entries.aliases,
|
|
217
299
|
bpm: min === Infinity ? null : { min, max },
|
|
218
300
|
hasDuration,
|
|
219
301
|
loops,
|
|
220
302
|
oneShots: sounds.length - loops
|
|
221
303
|
};
|
|
222
304
|
}
|
|
223
|
-
function matches(sound, filter = {}) {
|
|
305
|
+
function matches(sound, filter = {}, options = {}) {
|
|
306
|
+
const merge = options.mergeEnharmonicKeys !== false;
|
|
224
307
|
if (filter.type && sound.type !== filter.type) return false;
|
|
225
|
-
if (filter.key && sound.key
|
|
308
|
+
if (filter.key && !sameKey(sound.key, normalizeKey(filter.key), merge)) return false;
|
|
226
309
|
if (filter.loop === "loop" && !sound.loop) return false;
|
|
227
310
|
if (filter.loop === "one-shot" && sound.loop) return false;
|
|
228
311
|
const lo = Number(filter.bpmMin), hi = Number(filter.bpmMax);
|
|
@@ -233,7 +316,7 @@ function matches(sound, filter = {}) {
|
|
|
233
316
|
}
|
|
234
317
|
const terms = words(filter.query || "");
|
|
235
318
|
if (terms.length) {
|
|
236
|
-
const hay = [sound.title, sound.type, sound.key, ...sound.tags || []].join(" ");
|
|
319
|
+
const hay = [sound.title, sound.type, ...merge ? enharmonics(sound.key) : [sound.key], ...sound.tags || []].join(" ");
|
|
237
320
|
const folded = fold(hay);
|
|
238
321
|
const rest = terms.filter((w) => !(/^\d+$/.test(w) && !folded.includes(w) && sound.bpm != null && Math.round(sound.bpm) === Number(w)));
|
|
239
322
|
if (rest.length && !matchesAll(hay, rest.join(" "))) return false;
|
|
@@ -278,6 +361,16 @@ function resample(peaks, count) {
|
|
|
278
361
|
if (!peaks?.length || count <= 0) return [];
|
|
279
362
|
if (peaks.length === count) return peaks;
|
|
280
363
|
const out = new Array(count);
|
|
364
|
+
if (count > peaks.length) {
|
|
365
|
+
const last = peaks.length - 1;
|
|
366
|
+
const ratio = peaks.length / count;
|
|
367
|
+
for (let i = 0; i < count; i++) {
|
|
368
|
+
const x = Math.min(Math.max((i + 0.5) * ratio - 0.5, 0), last);
|
|
369
|
+
const j = Math.floor(x), t = x - j;
|
|
370
|
+
out[i] = j >= last ? peaks[last] : peaks[j] + (peaks[j + 1] - peaks[j]) * t;
|
|
371
|
+
}
|
|
372
|
+
return out;
|
|
373
|
+
}
|
|
281
374
|
const step = peaks.length / count;
|
|
282
375
|
for (let i = 0; i < count; i++) {
|
|
283
376
|
const start = Math.floor(i * step);
|
|
@@ -507,7 +600,7 @@ var Menus = class {
|
|
|
507
600
|
const p = partsOf(menu);
|
|
508
601
|
let first = null;
|
|
509
602
|
for (const opt of optionsOf(p)) {
|
|
510
|
-
opt.hidden = !optionMatches(opt.textContent
|
|
603
|
+
opt.hidden = !optionMatches(`${opt.textContent} ${opt.dataset.alt ?? ""}`, query);
|
|
511
604
|
if (!opt.hidden) first ??= opt;
|
|
512
605
|
}
|
|
513
606
|
p.none.hidden = first !== null;
|
|
@@ -623,9 +716,15 @@ var SEEK_END = 0.999;
|
|
|
623
716
|
function sliderEdgeTarget(key) {
|
|
624
717
|
return key === "Home" ? 0 : key === "End" ? SEEK_END : null;
|
|
625
718
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
return
|
|
719
|
+
var RENDER_CHUNK = 50;
|
|
720
|
+
function renderedCount(matching, limit, budget) {
|
|
721
|
+
return Math.min(matching, limit === Infinity ? budget : limit);
|
|
722
|
+
}
|
|
723
|
+
function firstRender(pageSize) {
|
|
724
|
+
return pageSize > 0 ? pageSize : RENDER_CHUNK;
|
|
725
|
+
}
|
|
726
|
+
function budgetToReveal(budget, pos) {
|
|
727
|
+
return pos < budget ? budget : Math.ceil((pos + 1) / RENDER_CHUNK) * RENDER_CHUNK;
|
|
629
728
|
}
|
|
630
729
|
function limitToReveal(limit, pos) {
|
|
631
730
|
return pos >= limit ? pos + 1 : limit;
|
|
@@ -702,7 +801,15 @@ var DEFAULT_STRINGS = {
|
|
|
702
801
|
nowPlaying: "Playing {title}",
|
|
703
802
|
playError: "Could not play {title}",
|
|
704
803
|
loadError: "Could not load the sounds.",
|
|
705
|
-
noSounds: "No sounds."
|
|
804
|
+
noSounds: "No sounds.",
|
|
805
|
+
rowBpm: "{bpm} BPM",
|
|
806
|
+
rowKey: "key {key}",
|
|
807
|
+
rowDuration: "{duration}",
|
|
808
|
+
keyMajor: "{note} major",
|
|
809
|
+
keyMinor: "{note} minor",
|
|
810
|
+
noteSharp: "{note} sharp",
|
|
811
|
+
noteFlat: "{note} flat",
|
|
812
|
+
listSeparator: ", "
|
|
706
813
|
};
|
|
707
814
|
var SORT_LABEL_KEYS = {
|
|
708
815
|
default: "sortDefault",
|
|
@@ -723,6 +830,27 @@ function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
|
723
830
|
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
724
831
|
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
725
832
|
}
|
|
833
|
+
function spokenKey(key, strings = DEFAULT_STRINGS) {
|
|
834
|
+
const k = parseKey(key);
|
|
835
|
+
if (!k) return key;
|
|
836
|
+
const letter = k.root[0], acc = k.root.slice(1);
|
|
837
|
+
const note = acc === "#" ? fill(strings.noteSharp, { note: letter }) : acc === "b" ? fill(strings.noteFlat, { note: letter }) : letter;
|
|
838
|
+
return fill(k.minor ? strings.keyMinor : strings.keyMajor, { note });
|
|
839
|
+
}
|
|
840
|
+
function rowSummary(sound, columns, strings = DEFAULT_STRINGS) {
|
|
841
|
+
const parts = [];
|
|
842
|
+
for (const c of columns) {
|
|
843
|
+
if (c === "type" && sound.type) parts.push(sound.type);
|
|
844
|
+
else if (c === "bpm" && sound.bpm != null) parts.push(fill(strings.rowBpm, { bpm: sound.bpm }));
|
|
845
|
+
else if (c === "key" && sound.key) parts.push(fill(strings.rowKey, { key: spokenKey(sound.key, strings) }));
|
|
846
|
+
else if (c === "duration") {
|
|
847
|
+
const d = formatDuration(sound.duration);
|
|
848
|
+
if (d) parts.push(fill(strings.rowDuration, { duration: d }));
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
if (sound.loop) parts.push(strings.isLoop);
|
|
852
|
+
return parts.join(strings.listSeparator);
|
|
853
|
+
}
|
|
726
854
|
|
|
727
855
|
// src/js/render/options.ts
|
|
728
856
|
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
@@ -737,7 +865,8 @@ var RENDER_DEFAULTS = {
|
|
|
737
865
|
menuSearch: 8,
|
|
738
866
|
pageSize: 50,
|
|
739
867
|
columns: [...COLUMNS],
|
|
740
|
-
maxTypeChips: 10
|
|
868
|
+
maxTypeChips: 10,
|
|
869
|
+
mergeEnharmonicKeys: true
|
|
741
870
|
};
|
|
742
871
|
var RENDER_OPTION_KEYS = [...Object.keys(RENDER_DEFAULTS), "idPrefix", "loop", "strings"];
|
|
743
872
|
function pickRenderOptions(options) {
|
|
@@ -771,6 +900,7 @@ function resolveRenderOptions(options = {}) {
|
|
|
771
900
|
menuSearch: wholeNumber(o.menuSearch, RENDER_DEFAULTS.menuSearch),
|
|
772
901
|
maxTypeChips: wholeNumber(o.maxTypeChips, RENDER_DEFAULTS.maxTypeChips),
|
|
773
902
|
pageSize: wholeNumber(o.pageSize, RENDER_DEFAULTS.pageSize),
|
|
903
|
+
mergeEnharmonicKeys: o.mergeEnharmonicKeys !== false,
|
|
774
904
|
strings: { ...DEFAULT_STRINGS, ...defined(options.strings) }
|
|
775
905
|
};
|
|
776
906
|
}
|
|
@@ -844,6 +974,7 @@ function readDataOptions(el) {
|
|
|
844
974
|
pageSize: parseNumber(d.pageSize),
|
|
845
975
|
maxTypeChips: parseNumber(d.maxTypeChips),
|
|
846
976
|
columns: parseList(d.columns),
|
|
977
|
+
mergeEnharmonicKeys: parseBool(d.mergeEnharmonicKeys),
|
|
847
978
|
waveformStyle: d.waveformStyle || void 0,
|
|
848
979
|
waveformColor: d.waveformColor || void 0,
|
|
849
980
|
progressColor: d.progressColor || void 0,
|
|
@@ -887,19 +1018,27 @@ function h(tag, attributes = {}, ...children) {
|
|
|
887
1018
|
}
|
|
888
1019
|
|
|
889
1020
|
// src/js/render/icons.ts
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
chevron: icon("M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z", "ws-menu-chevron"),
|
|
899
|
-
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"),
|
|
900
|
-
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"),
|
|
901
|
-
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")
|
|
1021
|
+
var ICON_PATHS = {
|
|
1022
|
+
play: "M8 5.5v13l11-6.5z",
|
|
1023
|
+
pause: "M7 5h3.5v14H7zM13.5 5H17v14h-3.5z",
|
|
1024
|
+
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",
|
|
1025
|
+
chevron: "M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z",
|
|
1026
|
+
check: "M9.5 16.2 5.3 12l-1.4 1.4 5.6 5.6 11-11-1.4-1.4z",
|
|
1027
|
+
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",
|
|
1028
|
+
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"
|
|
902
1029
|
};
|
|
1030
|
+
var ICON_NAMES = Object.keys(ICON_PATHS);
|
|
1031
|
+
function iconId(id, name) {
|
|
1032
|
+
return `${id}-i-${name}`;
|
|
1033
|
+
}
|
|
1034
|
+
function iconSprite(id, names) {
|
|
1035
|
+
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("");
|
|
1036
|
+
return `<svg class="ws-sprite" data-ws-sprite="${escapeHtml(id)}" width="0" height="0" aria-hidden="true" focusable="false">${symbols}</svg>`;
|
|
1037
|
+
}
|
|
1038
|
+
function icon(id, name, extraClass = "") {
|
|
1039
|
+
const cls = extraClass ? `ws-icon ${extraClass}` : "ws-icon";
|
|
1040
|
+
return `<svg class="${cls}" aria-hidden="true" focusable="false"><use href="#${escapeHtml(iconId(id, name))}"/></svg>`;
|
|
1041
|
+
}
|
|
903
1042
|
|
|
904
1043
|
// src/js/render/markup.ts
|
|
905
1044
|
function idBase(sounds) {
|
|
@@ -923,11 +1062,11 @@ function toolbarPlan(f, o) {
|
|
|
923
1062
|
function loopsByDefault(loop, f) {
|
|
924
1063
|
return loop == null ? f.loops > 0 : !!loop;
|
|
925
1064
|
}
|
|
926
|
-
function renderSearch(s) {
|
|
1065
|
+
function renderSearch(s, id) {
|
|
927
1066
|
return h(
|
|
928
1067
|
"label",
|
|
929
1068
|
{ class: "ws-search" },
|
|
930
|
-
|
|
1069
|
+
icon(id, "search"),
|
|
931
1070
|
h("span", { class: "ws-sr" }, text(s.search)),
|
|
932
1071
|
h("input", { type: "search", class: "ws-search-input", "data-ws-search": true, placeholder: s.searchPlaceholder, autocomplete: "off", spellcheck: "false" })
|
|
933
1072
|
);
|
|
@@ -941,7 +1080,7 @@ function renderMenu(name, m) {
|
|
|
941
1080
|
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "listbox", "aria-expanded": "false", "aria-controls": listId },
|
|
942
1081
|
m.prefix ? h("span", { class: "ws-menu-prefix" }, text(m.prefix)) : h("span", { class: "ws-sr" }, text(`${m.label}: `)),
|
|
943
1082
|
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(current.label)),
|
|
944
|
-
|
|
1083
|
+
icon(m.id, "chevron", "ws-menu-chevron")
|
|
945
1084
|
);
|
|
946
1085
|
const search = searchable && h("input", {
|
|
947
1086
|
type: "search",
|
|
@@ -958,8 +1097,8 @@ function renderMenu(name, m) {
|
|
|
958
1097
|
});
|
|
959
1098
|
const options = m.options.map((o, i) => h(
|
|
960
1099
|
"li",
|
|
961
|
-
{ role: "option", id: `${m.id}-${name}-${i}`, class: "ws-menu-option", "data-value": o.value, "aria-selected": String(o === current) },
|
|
962
|
-
|
|
1100
|
+
{ role: "option", id: `${m.id}-${name}-${i}`, class: "ws-menu-option", "data-value": o.value, "data-alt": o.alt, "aria-selected": String(o === current) },
|
|
1101
|
+
icon(m.id, "check", "ws-menu-check"),
|
|
963
1102
|
h("span", { class: "ws-menu-text" }, text(o.label)),
|
|
964
1103
|
o.count != null && h("span", { class: "ws-menu-count" }, text(o.count))
|
|
965
1104
|
));
|
|
@@ -996,7 +1135,7 @@ function renderBpmMenu({ id, s, range }) {
|
|
|
996
1135
|
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
997
1136
|
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
998
1137
|
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
999
|
-
|
|
1138
|
+
icon(id, "chevron", "ws-menu-chevron")
|
|
1000
1139
|
),
|
|
1001
1140
|
h(
|
|
1002
1141
|
"div",
|
|
@@ -1031,8 +1170,8 @@ function renderLoopFilter(s) {
|
|
|
1031
1170
|
button("one-shot", s.oneShots)
|
|
1032
1171
|
);
|
|
1033
1172
|
}
|
|
1034
|
-
function renderLoopToggle(s, pressed) {
|
|
1035
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) },
|
|
1173
|
+
function renderLoopToggle(s, pressed, id) {
|
|
1174
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, icon(id, "loop"), h("span", {}, text(s.loop)));
|
|
1036
1175
|
}
|
|
1037
1176
|
function renderChip(value, label, count, pressed) {
|
|
1038
1177
|
return h(
|
|
@@ -1056,7 +1195,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
1056
1195
|
label: s.key,
|
|
1057
1196
|
value: "",
|
|
1058
1197
|
placeholder: s.findKey,
|
|
1059
|
-
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
1198
|
+
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k, alt: f.keyAliases[k]?.join(" ") }))]
|
|
1060
1199
|
}),
|
|
1061
1200
|
plan.bpm && renderBpmMenu({ id, s, range: bpmExtent(f.bpm) }),
|
|
1062
1201
|
plan.loops && renderLoopFilter(s),
|
|
@@ -1066,7 +1205,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
1066
1205
|
value: plan.sorts[0],
|
|
1067
1206
|
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
1068
1207
|
}),
|
|
1069
|
-
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
1208
|
+
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f), id)
|
|
1070
1209
|
].filter(Boolean);
|
|
1071
1210
|
const chips = plan.types === "chips" && h(
|
|
1072
1211
|
"div",
|
|
@@ -1078,7 +1217,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
|
|
|
1078
1217
|
return h(
|
|
1079
1218
|
"div",
|
|
1080
1219
|
{ class: "ws-toolbar" },
|
|
1081
|
-
plan.search && renderSearch(s),
|
|
1220
|
+
plan.search && renderSearch(s, id),
|
|
1082
1221
|
controls.length > 0 && h("div", { class: "ws-controls" }, controls),
|
|
1083
1222
|
// The chips and the count share a row (the count alone without chips).
|
|
1084
1223
|
(chips || count) && h("div", { class: "ws-meta" }, chips, count)
|
|
@@ -1090,49 +1229,66 @@ var CELLS = {
|
|
|
1090
1229
|
key: (sound) => text(sound.key),
|
|
1091
1230
|
duration: (sound) => text(formatDuration(sound.duration))
|
|
1092
1231
|
};
|
|
1093
|
-
function renderRow(sound, index, o,
|
|
1232
|
+
function renderRow(sound, index, o, id) {
|
|
1094
1233
|
const s = o.strings;
|
|
1095
1234
|
const vars = { title: sound.title };
|
|
1096
1235
|
const cells = o.columns.map((c) => h("span", { class: `ws-cell ws-${c}` }, CELLS[c](sound)));
|
|
1236
|
+
const summary = rowSummary(sound, o.columns, s);
|
|
1237
|
+
const described = summary ? `${id}-d${index}` : null;
|
|
1097
1238
|
return h(
|
|
1098
1239
|
"li",
|
|
1099
|
-
{
|
|
1100
|
-
|
|
1101
|
-
"
|
|
1102
|
-
"
|
|
1103
|
-
"
|
|
1104
|
-
"
|
|
1105
|
-
|
|
1106
|
-
"data-bpm": sound.bpm,
|
|
1107
|
-
"data-key": sound.key || null,
|
|
1108
|
-
"data-duration": sound.duration,
|
|
1109
|
-
"data-tags": sound.tags?.length ? sound.tags.join(",") : null,
|
|
1110
|
-
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
1111
|
-
"data-waveform": sound.waveform,
|
|
1112
|
-
"data-download": sound.download,
|
|
1113
|
-
"data-loop": sound.loop ? "true" : null,
|
|
1114
|
-
hidden
|
|
1115
|
-
},
|
|
1116
|
-
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
1240
|
+
{ class: "ws-row", "data-ws-index": index },
|
|
1241
|
+
h(
|
|
1242
|
+
"button",
|
|
1243
|
+
{ type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars), "aria-describedby": described },
|
|
1244
|
+
icon(id, "play", "ws-icon-play"),
|
|
1245
|
+
icon(id, "pause", "ws-icon-pause")
|
|
1246
|
+
),
|
|
1117
1247
|
h(
|
|
1118
1248
|
"span",
|
|
1119
1249
|
{ class: "ws-cell ws-title" },
|
|
1120
1250
|
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
1121
|
-
// A loop says so beside its name; a one-shot carries nothing.
|
|
1122
|
-
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop
|
|
1251
|
+
// A loop says so beside its name (and in the read-out); a one-shot carries nothing.
|
|
1252
|
+
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop, "aria-hidden": "true" }, icon(id, "loop"))
|
|
1123
1253
|
),
|
|
1124
1254
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
1125
1255
|
// rows: one line under the title.
|
|
1126
|
-
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
{ class: "ws-wave", role: "slider", "aria-label": fill(s.seek, vars), "aria-valuemin": "0", "aria-valuemax": "100", "aria-valuenow": "0", tabindex: "-1" },
|
|
1130
|
-
h("canvas", { class: "ws-canvas", "aria-hidden": "true" })
|
|
1131
|
-
),
|
|
1256
|
+
cells.length > 0 && h("span", { class: "ws-cells", "aria-hidden": "true" }, cells),
|
|
1257
|
+
summary && h("span", { class: "ws-sr", id: described }, text(summary)),
|
|
1258
|
+
o.player === "inline" && h("span", { class: "ws-wave", "aria-hidden": "true" }, h("canvas", { class: "ws-canvas" })),
|
|
1132
1259
|
// Optional, per sound: a plain link. Rows without one carry nothing.
|
|
1133
|
-
sound.download && h("a", { class: "ws-download", href: sound.download, download: true, "aria-label": fill(s.download, vars) },
|
|
1260
|
+
sound.download && h("a", { class: "ws-download", href: sound.download, download: true, "aria-label": fill(s.download, vars) }, icon(id, "download"))
|
|
1134
1261
|
);
|
|
1135
1262
|
}
|
|
1263
|
+
function renderSoundsData(list) {
|
|
1264
|
+
const data = list.map((s, i) => {
|
|
1265
|
+
const d = {};
|
|
1266
|
+
if (s.id !== `sound-${i + 1}`) d.id = s.id;
|
|
1267
|
+
d.url = s.url;
|
|
1268
|
+
d.title = s.title;
|
|
1269
|
+
if (s.type) d.type = s.type;
|
|
1270
|
+
if (s.bpm != null) d.bpm = s.bpm;
|
|
1271
|
+
if (s.key) d.key = s.key;
|
|
1272
|
+
if (s.duration != null) d.duration = s.duration;
|
|
1273
|
+
if (s.tags.length) d.tags = s.tags;
|
|
1274
|
+
if (s.peaks) d.peaks = encodePeaks(s.peaks);
|
|
1275
|
+
if (s.waveform) d.waveform = s.waveform;
|
|
1276
|
+
if (s.download) d.download = s.download;
|
|
1277
|
+
if (s.loop) d.loop = true;
|
|
1278
|
+
return d;
|
|
1279
|
+
});
|
|
1280
|
+
return `<script type="application/json" data-ws-sounds>${JSON.stringify(data).replace(/</g, "\\u003c")}<\/script>`;
|
|
1281
|
+
}
|
|
1282
|
+
function iconsUsed(plan, list) {
|
|
1283
|
+
const names = [];
|
|
1284
|
+
if (list.length) names.push("play", "pause");
|
|
1285
|
+
if (plan.search) names.push("search");
|
|
1286
|
+
if (plan.types === "menu" || plan.key || plan.sorts.length) names.push("chevron", "check");
|
|
1287
|
+
else if (plan.bpm) names.push("chevron");
|
|
1288
|
+
if (plan.loop || list.some((s) => s.loop)) names.push("loop");
|
|
1289
|
+
if (list.some((s) => s.download)) names.push("download");
|
|
1290
|
+
return names;
|
|
1291
|
+
}
|
|
1136
1292
|
function renderFooter({ o, s, total }) {
|
|
1137
1293
|
const page = o.pageSize > 0 ? o.pageSize : total;
|
|
1138
1294
|
const more = Math.max(0, total - page);
|
|
@@ -1151,15 +1307,19 @@ function renderFooter({ o, s, total }) {
|
|
|
1151
1307
|
].join("");
|
|
1152
1308
|
}
|
|
1153
1309
|
function renderSounds(sounds, options = {}) {
|
|
1310
|
+
return renderList(normalizeSounds(sounds), options, true);
|
|
1311
|
+
}
|
|
1312
|
+
function renderList(list, options, withData) {
|
|
1154
1313
|
const o = resolveRenderOptions(options);
|
|
1155
|
-
const
|
|
1156
|
-
const
|
|
1157
|
-
const
|
|
1158
|
-
|
|
1314
|
+
const ctx = { o, s: o.strings, f: facets(list, o), total: list.length, id: o.idPrefix || idBase(list) };
|
|
1315
|
+
const plan = toolbarPlan(ctx.f, o);
|
|
1316
|
+
const index = new Map(list.map((sound, i) => [sound, i]));
|
|
1317
|
+
const first = sortSounds(list, availableSorts(o.sorts, ctx.f)[0] || "default").slice(0, firstRender(o.pageSize));
|
|
1318
|
+
return iconSprite(ctx.id, iconsUsed(plan, list)) + renderToolbar(plan, ctx) + h(
|
|
1159
1319
|
"ul",
|
|
1160
1320
|
{ class: `ws-list ws-list--${o.player}`, role: "list", "data-ws-list": true },
|
|
1161
|
-
|
|
1162
|
-
) + renderFooter(ctx);
|
|
1321
|
+
first.map((sound) => renderRow(sound, index.get(sound), o, ctx.id))
|
|
1322
|
+
) + renderFooter(ctx) + (withData ? renderSoundsData(list) : "");
|
|
1163
1323
|
}
|
|
1164
1324
|
function renderOptionAttributes(options = {}) {
|
|
1165
1325
|
const set = pickRenderOptions(options);
|
|
@@ -1188,6 +1348,17 @@ function renderSoundsElement(sounds, options = {}, className = "") {
|
|
|
1188
1348
|
|
|
1189
1349
|
// src/js/dom/rows.ts
|
|
1190
1350
|
var ROW = ":scope > [data-ws-index]";
|
|
1351
|
+
function readSoundsData(root) {
|
|
1352
|
+
const script = root.querySelector(":scope > script[data-ws-sounds]");
|
|
1353
|
+
if (!script) return null;
|
|
1354
|
+
try {
|
|
1355
|
+
const list = JSON.parse(script.textContent || "");
|
|
1356
|
+
if (Array.isArray(list)) return normalizeSounds(list);
|
|
1357
|
+
} catch {
|
|
1358
|
+
}
|
|
1359
|
+
console.warn(`${LOG} Ignoring unreadable sounds JSON (data-ws-sounds)`);
|
|
1360
|
+
return null;
|
|
1361
|
+
}
|
|
1191
1362
|
function readRows(list) {
|
|
1192
1363
|
const rows = [...list.querySelectorAll(ROW)].sort((a, b) => Number(a.dataset.wsIndex) - Number(b.dataset.wsIndex));
|
|
1193
1364
|
const sounds = [];
|
|
@@ -1226,10 +1397,14 @@ function indexRows(list) {
|
|
|
1226
1397
|
function visibleRows(list) {
|
|
1227
1398
|
return [...list.querySelectorAll(ROW)].filter((r) => !r.hidden);
|
|
1228
1399
|
}
|
|
1229
|
-
function
|
|
1230
|
-
const
|
|
1231
|
-
for (const
|
|
1232
|
-
list.
|
|
1400
|
+
function layoutRows(list, rows) {
|
|
1401
|
+
const keep = new Set(rows);
|
|
1402
|
+
for (const el of [...list.children]) if (!keep.has(el)) el.remove();
|
|
1403
|
+
let cursor = list.firstElementChild;
|
|
1404
|
+
for (const row of rows) {
|
|
1405
|
+
if (row === cursor) cursor = cursor.nextElementSibling;
|
|
1406
|
+
else list.insertBefore(row, cursor);
|
|
1407
|
+
}
|
|
1233
1408
|
}
|
|
1234
1409
|
|
|
1235
1410
|
// src/js/dom/colors.ts
|
|
@@ -1293,7 +1468,7 @@ function formatBpmRange(min, max) {
|
|
|
1293
1468
|
const lo = min ?? "", hi = max ?? "";
|
|
1294
1469
|
return lo !== "" || hi !== "" ? `${lo}-${hi}` : "";
|
|
1295
1470
|
}
|
|
1296
|
-
function readUrlState(search, keys, available, sorts) {
|
|
1471
|
+
function readUrlState(search, keys, available, sorts, options = {}) {
|
|
1297
1472
|
const out = { filter: {}, sort: null };
|
|
1298
1473
|
if (!keys) return out;
|
|
1299
1474
|
const sp = new URLSearchParams(search);
|
|
@@ -1301,8 +1476,8 @@ function readUrlState(search, keys, available, sorts) {
|
|
|
1301
1476
|
if (q) out.filter.query = q;
|
|
1302
1477
|
const type = sp.get(keys.type);
|
|
1303
1478
|
if (type && available.types.some((t) => t.name === type)) out.filter.type = type;
|
|
1304
|
-
const key = normalizeKey(sp.get(keys.key));
|
|
1305
|
-
if (key
|
|
1479
|
+
const key = keyEntry(normalizeKey(sp.get(keys.key)), available.keys, options.mergeEnharmonicKeys !== false);
|
|
1480
|
+
if (key) out.filter.key = key;
|
|
1306
1481
|
const parsed = parseBpmRange(sp.get(keys.bpm));
|
|
1307
1482
|
const bpm = parsed && available.bpm !== void 0 ? bpmRangeWithin(parsed, available.bpm) : parsed;
|
|
1308
1483
|
if (bpm) Object.assign(out.filter, bpm);
|
|
@@ -1352,6 +1527,9 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1352
1527
|
this.filter = { ...NO_FILTER };
|
|
1353
1528
|
this.sortBy = "default";
|
|
1354
1529
|
this.limit = this._pageSize();
|
|
1530
|
+
this._budget = this._firstBudget();
|
|
1531
|
+
this._index = /* @__PURE__ */ new Map();
|
|
1532
|
+
this._failed = /* @__PURE__ */ new Set();
|
|
1355
1533
|
this.currentIndex = null;
|
|
1356
1534
|
this.playing = false;
|
|
1357
1535
|
this.progress = 0;
|
|
@@ -1384,28 +1562,31 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1384
1562
|
const adopted = el.querySelector("[data-ws-list]");
|
|
1385
1563
|
if (adopted) {
|
|
1386
1564
|
this._adoptedHTML = el.innerHTML;
|
|
1387
|
-
this.sounds = readRows(adopted);
|
|
1565
|
+
this.sounds = readSoundsData(el) ?? readRows(adopted);
|
|
1388
1566
|
} else {
|
|
1389
1567
|
this._originalHTML = el.innerHTML;
|
|
1390
1568
|
this.sounds = await this._loadSounds();
|
|
1391
1569
|
if (this.destroyed) return;
|
|
1392
|
-
el.innerHTML =
|
|
1570
|
+
el.innerHTML = renderList(this.sounds, { ...this.render, idPrefix: this.options.idPrefix || el.id || void 0 }, false);
|
|
1393
1571
|
}
|
|
1394
1572
|
if (this.destroyed) return;
|
|
1573
|
+
this._index = new Map(this.sounds.map((sound, i) => [sound, i]));
|
|
1395
1574
|
this._addedClasses = ["waveform-sounds", `waveform-sounds--${this.render.player}`].filter((c) => !el.classList.contains(c));
|
|
1396
1575
|
el.classList.add(...this._addedClasses);
|
|
1576
|
+
this._facets = facets(this.sounds, this.render);
|
|
1397
1577
|
this._cacheRefs();
|
|
1398
1578
|
this._bind();
|
|
1399
1579
|
this._observe();
|
|
1400
1580
|
this._resolveColors();
|
|
1401
|
-
if (!this._loopSet) this.loop = loopsByDefault(this.options.loop,
|
|
1581
|
+
if (!this._loopSet) this.loop = loopsByDefault(this.options.loop, this._facets);
|
|
1402
1582
|
this._setLoop(this.loop);
|
|
1403
|
-
this._bpmExtent = bpmExtent(
|
|
1404
|
-
this._sorts = availableSorts(this.render.sorts,
|
|
1583
|
+
this._bpmExtent = bpmExtent(this._facets.bpm);
|
|
1584
|
+
this._sorts = availableSorts(this.render.sorts, this._facets);
|
|
1405
1585
|
if (!this._sortSet) this.sortBy = this._sorts[0] || "default";
|
|
1406
1586
|
this._readUrl();
|
|
1587
|
+
this.filter = { ...this.filter, key: this._keyEntry(this.filter.key) };
|
|
1407
1588
|
this._syncControls();
|
|
1408
|
-
this._apply(
|
|
1589
|
+
this._apply();
|
|
1409
1590
|
if (this._playerClass()) this._ensureEngine();
|
|
1410
1591
|
if (this.render.player === "strip" && this.engine && this.currentIndex == null) this._cueFirst();
|
|
1411
1592
|
this._emit("ready", { sounds: this.sounds.length });
|
|
@@ -1460,9 +1641,42 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1460
1641
|
chips: [...this.container.querySelectorAll("[data-ws-type]")],
|
|
1461
1642
|
loopFilter: [...this.container.querySelectorAll("[data-ws-loop-filter]")]
|
|
1462
1643
|
};
|
|
1463
|
-
|
|
1644
|
+
const sprite = q("[data-ws-sprite]");
|
|
1645
|
+
this._iconId = sprite?.dataset.wsSprite ?? (this.options.idPrefix || this.container.id || idBase(this.sounds));
|
|
1646
|
+
if (!sprite) this.$.list.insertAdjacentHTML("beforebegin", iconSprite(this._iconId, ICON_NAMES));
|
|
1647
|
+
this.rows = [];
|
|
1464
1648
|
this._active = null;
|
|
1465
|
-
for (const row of this
|
|
1649
|
+
for (const row of indexRows(this.$.list)) if (row) this._adoptRow(row);
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* Take a row (server-rendered, or just rendered) into the list's
|
|
1653
|
+
* keeping: its index, its Tab stops off, the state of its sound (current,
|
|
1654
|
+
* failed), and the observer that draws it.
|
|
1655
|
+
* @internal
|
|
1656
|
+
*/
|
|
1657
|
+
_adoptRow(row) {
|
|
1658
|
+
const i = Number(row.dataset.wsIndex);
|
|
1659
|
+
this.rows[i] = row;
|
|
1660
|
+
this._rowStops(row, false);
|
|
1661
|
+
const wave = row.querySelector(".ws-wave");
|
|
1662
|
+
if (i === this.currentIndex || this._failed.has(i) || wave?.hasAttribute("role")) this._paintRow(i);
|
|
1663
|
+
if (i === this.currentIndex) this._paintSlider();
|
|
1664
|
+
if (this._io) this._io.observe(row);
|
|
1665
|
+
else this._drawn?.add(i);
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Rows for these sounds, rendered (in one pass) where they have none.
|
|
1669
|
+
* @returns The rows, in the order given.
|
|
1670
|
+
* @internal
|
|
1671
|
+
*/
|
|
1672
|
+
_rowsFor(indices) {
|
|
1673
|
+
const missing = indices.filter((i) => !this.rows[i]);
|
|
1674
|
+
if (missing.length) {
|
|
1675
|
+
const tpl = document.createElement("template");
|
|
1676
|
+
tpl.innerHTML = missing.map((i) => renderRow(this.sounds[i], i, this.render, this._iconId)).join("");
|
|
1677
|
+
for (const row of [...tpl.content.children]) this._adoptRow(row);
|
|
1678
|
+
}
|
|
1679
|
+
return indices.map((i) => this.rows[i]);
|
|
1466
1680
|
}
|
|
1467
1681
|
/**
|
|
1468
1682
|
* Make a row's own controls (play, download, and the seek slider when it
|
|
@@ -1475,7 +1689,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1475
1689
|
const dl = row.querySelector(".ws-download");
|
|
1476
1690
|
if (dl) dl.tabIndex = on ? 0 : -1;
|
|
1477
1691
|
const wave = row.querySelector(".ws-wave");
|
|
1478
|
-
if (wave
|
|
1692
|
+
if (wave && Number(row.dataset.wsIndex) === this.currentIndex) wave.tabIndex = on ? 0 : -1;
|
|
1479
1693
|
}
|
|
1480
1694
|
/**
|
|
1481
1695
|
* Move the list's Tab stop to `row` (roving tabindex).
|
|
@@ -1637,16 +1851,35 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1637
1851
|
this._seekRow(index, seek);
|
|
1638
1852
|
return;
|
|
1639
1853
|
}
|
|
1640
|
-
const
|
|
1641
|
-
const target = rowTarget(e.key,
|
|
1854
|
+
const shown = this._shown ?? [];
|
|
1855
|
+
const target = rowTarget(e.key, shown.indexOf(this.sounds[index]), Math.min(shown.length, this.limit));
|
|
1642
1856
|
if (target === null) return;
|
|
1643
1857
|
e.preventDefault();
|
|
1644
1858
|
if (target === "search") {
|
|
1645
1859
|
this.$.search?.focus();
|
|
1646
1860
|
return;
|
|
1647
1861
|
}
|
|
1648
|
-
this._focusRow(
|
|
1649
|
-
if (this.options.arrowAudition && this.playing) this.play(
|
|
1862
|
+
this._focusRow(this._reveal(target));
|
|
1863
|
+
if (this.options.arrowAudition && this.playing) this.play(this._index.get(shown[target]));
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* The row at position `pos` of the matching sounds, revealing it first:
|
|
1867
|
+
* past the page, the page grows to it (as `next()` always did); with
|
|
1868
|
+
* paging off, rows are rendered up to it.
|
|
1869
|
+
* @internal
|
|
1870
|
+
*/
|
|
1871
|
+
_reveal(pos) {
|
|
1872
|
+
const sound = this._shown?.[pos];
|
|
1873
|
+
if (!sound) return void 0;
|
|
1874
|
+
const limit = limitToReveal(this.limit, pos);
|
|
1875
|
+
if (limit !== this.limit) {
|
|
1876
|
+
this.limit = limit;
|
|
1877
|
+
this._apply();
|
|
1878
|
+
} else if (this.limit === Infinity && pos >= this._budget) {
|
|
1879
|
+
this._budget = budgetToReveal(this._budget, pos);
|
|
1880
|
+
this._layout();
|
|
1881
|
+
}
|
|
1882
|
+
return this.rows[this._index.get(sound)];
|
|
1650
1883
|
}
|
|
1651
1884
|
/**
|
|
1652
1885
|
* Focus a row's play button.
|
|
@@ -1756,7 +1989,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1756
1989
|
const row = this.rows[index];
|
|
1757
1990
|
const canvas = row?.querySelector("canvas");
|
|
1758
1991
|
if (!canvas) return;
|
|
1759
|
-
if (row.
|
|
1992
|
+
if (!row.isConnected) {
|
|
1760
1993
|
this._dirty?.add(index);
|
|
1761
1994
|
return;
|
|
1762
1995
|
}
|
|
@@ -1791,8 +2024,8 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1791
2024
|
_readUrl() {
|
|
1792
2025
|
const keys = urlKeys(this.options.urlState);
|
|
1793
2026
|
if (!keys || typeof location === "undefined") return;
|
|
1794
|
-
const f =
|
|
1795
|
-
const { filter, sort } = readUrlState(location.search, keys, { ...f, bpm: bpmExtent(f.bpm) }, this._sorts);
|
|
2027
|
+
const f = this._facets;
|
|
2028
|
+
const { filter, sort } = readUrlState(location.search, keys, { ...f, bpm: bpmExtent(f.bpm) }, this._sorts, this.render);
|
|
1796
2029
|
this.filter = { ...this.filter, ...filter };
|
|
1797
2030
|
if (sort) {
|
|
1798
2031
|
this.sortBy = sort;
|
|
@@ -1824,13 +2057,26 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1824
2057
|
* @internal
|
|
1825
2058
|
*/
|
|
1826
2059
|
_match() {
|
|
1827
|
-
return sortSounds(this.sounds.filter((s) => matches(s, this.filter)), this.sortBy);
|
|
2060
|
+
return sortSounds(this.sounds.filter((s) => matches(s, this.filter, this.render)), this.sortBy);
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* A key filter in the list's own spelling: with enharmonic keys merged,
|
|
2064
|
+
* `A#m` on a list whose entry is `Bbm` becomes `Bbm` (so the menu and
|
|
2065
|
+
* the address show the entry). A key the list doesn't have stays as
|
|
2066
|
+
* given (it matches nothing, as before).
|
|
2067
|
+
* @internal
|
|
2068
|
+
*/
|
|
2069
|
+
_keyEntry(key) {
|
|
2070
|
+
const k = normalizeKey(key);
|
|
2071
|
+
return this._facets && keyEntry(k, this._facets.keys, this.render.mergeEnharmonicKeys) || k;
|
|
1828
2072
|
}
|
|
1829
2073
|
setFilter(patch = {}) {
|
|
1830
2074
|
this.filter = { ...this.filter, ...patch };
|
|
2075
|
+
if (patch.key) this.filter.key = this._keyEntry(patch.key);
|
|
1831
2076
|
this.limit = this._pageSize();
|
|
2077
|
+
this._budget = this._firstBudget();
|
|
1832
2078
|
this._syncControls();
|
|
1833
|
-
this._apply(
|
|
2079
|
+
this._apply();
|
|
1834
2080
|
}
|
|
1835
2081
|
/** Reset every filter (the sort stays). */
|
|
1836
2082
|
clearFilters() {
|
|
@@ -1841,13 +2087,13 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1841
2087
|
this._sortSet = true;
|
|
1842
2088
|
this.sortBy = SORTS.includes(by) ? by : "default";
|
|
1843
2089
|
this.menus?.setValue("sort", this.sortBy);
|
|
1844
|
-
this._apply(
|
|
2090
|
+
this._apply();
|
|
1845
2091
|
}
|
|
1846
2092
|
/** Reveal the next page of results. */
|
|
1847
2093
|
showMore() {
|
|
1848
2094
|
if (this.limit === Infinity) return;
|
|
1849
2095
|
this.limit += this.render.pageSize;
|
|
1850
|
-
this._apply(
|
|
2096
|
+
this._apply();
|
|
1851
2097
|
}
|
|
1852
2098
|
/**
|
|
1853
2099
|
* Rows per page (Infinity when paging is off).
|
|
@@ -1856,6 +2102,15 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1856
2102
|
_pageSize() {
|
|
1857
2103
|
return this.render.pageSize > 0 ? this.render.pageSize : Infinity;
|
|
1858
2104
|
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Paging off: the rows a list (or a new filter) starts with — a chunk,
|
|
2107
|
+
* more as the list scrolls (see `_watchEnd`); all of them where nothing
|
|
2108
|
+
* can tell it scrolled (no IntersectionObserver).
|
|
2109
|
+
* @internal
|
|
2110
|
+
*/
|
|
2111
|
+
_firstBudget() {
|
|
2112
|
+
return typeof IntersectionObserver === "undefined" ? Infinity : RENDER_CHUNK;
|
|
2113
|
+
}
|
|
1859
2114
|
/**
|
|
1860
2115
|
* Show the current filter and sort in the controls (they can be set from
|
|
1861
2116
|
* code or the address, not only by the controls themselves).
|
|
@@ -1895,27 +2150,17 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1895
2150
|
$.bpmRange.classList.toggle("is-active", lo > extent.min || hi < extent.max);
|
|
1896
2151
|
}
|
|
1897
2152
|
/**
|
|
1898
|
-
* Lay the
|
|
2153
|
+
* Lay the list out for the current filter, sort and page: its rows,
|
|
1899
2154
|
* "Show more", the empty state and the count. Then report it.
|
|
1900
|
-
*
|
|
1901
|
-
* @param opts - Reorder the rows even if the sort
|
|
1902
|
-
* hasn't changed.
|
|
1903
2155
|
* @internal
|
|
1904
2156
|
*/
|
|
1905
|
-
_apply(
|
|
2157
|
+
_apply() {
|
|
1906
2158
|
const $ = this.$;
|
|
1907
2159
|
if (!$) return;
|
|
1908
|
-
if (resort || this.sortBy !== this._lastSort) {
|
|
1909
|
-
const index = new Map(this.sounds.map((s, i) => [s, i]));
|
|
1910
|
-
orderRows($.list, sortSounds(this.sounds, this.sortBy).map((s) => this.rows[index.get(s)]));
|
|
1911
|
-
this._lastSort = this.sortBy;
|
|
1912
|
-
}
|
|
1913
2160
|
const shown = this._match();
|
|
1914
2161
|
this._shown = shown;
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
if (this.rows[i]) this.rows[i].hidden = !visible.has(s);
|
|
1918
|
-
});
|
|
2162
|
+
this._layout();
|
|
2163
|
+
const remaining = shown.length - Math.min(shown.length, this.limit);
|
|
1919
2164
|
if ($.more) {
|
|
1920
2165
|
$.more.hidden = remaining <= 0;
|
|
1921
2166
|
$.more.textContent = fill(this.strings.showMore, { count: Math.min(remaining, this.render.pageSize || remaining) });
|
|
@@ -1925,21 +2170,52 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1925
2170
|
if (!this.sounds.length && $.empty.textContent !== this.strings.noSounds) $.empty.textContent = this.strings.noSounds;
|
|
1926
2171
|
}
|
|
1927
2172
|
if ($.count) $.count.textContent = countText(shown.length, this.sounds.length, this.strings);
|
|
1928
|
-
if (
|
|
1929
|
-
|
|
1930
|
-
|
|
2173
|
+
if (this._cued && !this.playing) this._cueFirst();
|
|
2174
|
+
this._queueUrl();
|
|
2175
|
+
this._emit("filter", { visible: shown.length, total: this.sounds.length, filter: { ...this.filter }, sort: this.sortBy });
|
|
2176
|
+
this.options.onFilter?.(shown, this);
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Put exactly the rows shown in the list, in order: the page (or with
|
|
2180
|
+
* paging off the rows rendered so far) of the matching sounds. Rows are
|
|
2181
|
+
* rendered the first time they are shown; rows that stop being shown
|
|
2182
|
+
* leave the DOM (kept, with their drawing, for when they come back).
|
|
2183
|
+
* @internal
|
|
2184
|
+
*/
|
|
2185
|
+
_layout() {
|
|
2186
|
+
const $ = this.$, shown = this._shown;
|
|
2187
|
+
const count = renderedCount(shown.length, this.limit, this._budget);
|
|
2188
|
+
const focused = $.list.contains(document.activeElement) ? document.activeElement : null;
|
|
2189
|
+
const rows = this._rowsFor(shown.slice(0, count).map((sound) => this._index.get(sound)));
|
|
2190
|
+
layoutRows($.list, rows);
|
|
2191
|
+
if (focused?.isConnected && document.activeElement !== focused) focused.focus({ preventScroll: true });
|
|
2192
|
+
if (!this._io && this._drawn) for (const row of rows) this._drawRow(Number(row.dataset.wsIndex));
|
|
2193
|
+
if (!this._active || !this._active.isConnected) {
|
|
2194
|
+
const first = rows[0];
|
|
1931
2195
|
if (first) {
|
|
1932
2196
|
this._rove(first);
|
|
1933
|
-
if (
|
|
2197
|
+
if (focused && !focused.isConnected) this._focusRowQuietly(first);
|
|
1934
2198
|
} else if (this._active) {
|
|
1935
2199
|
this._rowStops(this._active, false);
|
|
1936
2200
|
this._active = null;
|
|
1937
2201
|
}
|
|
1938
2202
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
2203
|
+
this._watchEnd(count < Math.min(shown.length, this.limit) ? rows[rows.length - 1] : null);
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* Render the next chunk of rows once `row` (the last one rendered) comes
|
|
2207
|
+
* within ~1200px of the viewport; nothing to watch for `null`.
|
|
2208
|
+
* @internal
|
|
2209
|
+
*/
|
|
2210
|
+
_watchEnd(row) {
|
|
2211
|
+
this._endIo?.disconnect();
|
|
2212
|
+
if (!row || typeof IntersectionObserver === "undefined") return;
|
|
2213
|
+
this._endIo ??= new IntersectionObserver((entries) => {
|
|
2214
|
+
if (this.destroyed || !entries.some((entry) => entry.isIntersecting)) return;
|
|
2215
|
+
this._budget += RENDER_CHUNK;
|
|
2216
|
+
this._layout();
|
|
2217
|
+
}, { rootMargin: "0px 0px 1200px 0px" });
|
|
2218
|
+
this._endIo.observe(row);
|
|
1943
2219
|
}
|
|
1944
2220
|
/* ── Playback ─────────────────────────────────────────────────────── */
|
|
1945
2221
|
/**
|
|
@@ -1956,7 +2232,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
1956
2232
|
return first ? this.sounds.indexOf(first) : null;
|
|
1957
2233
|
}
|
|
1958
2234
|
if (typeof target === "number") return this.sounds[target] ? target : null;
|
|
1959
|
-
const i = typeof target === "object" ? this.sounds.indexOf(target) : this.sounds.findIndex((s) => s.id === String(target));
|
|
2235
|
+
const i = typeof target === "object" ? this._index.get(target) ?? this.sounds.indexOf(target) : this.sounds.findIndex((s) => s.id === String(target));
|
|
1960
2236
|
return i >= 0 ? i : null;
|
|
1961
2237
|
}
|
|
1962
2238
|
/**
|
|
@@ -2112,11 +2388,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
2112
2388
|
const at = this.currentIndex == null || this._cued ? -1 : shown.indexOf(this.sounds[this.currentIndex]);
|
|
2113
2389
|
const target = shown[at + dir];
|
|
2114
2390
|
if (!target) return false;
|
|
2115
|
-
|
|
2116
|
-
if (limit !== this.limit) {
|
|
2117
|
-
this.limit = limit;
|
|
2118
|
-
this._apply({ resort: false });
|
|
2119
|
-
}
|
|
2391
|
+
if (this.$) this._reveal(at + dir);
|
|
2120
2392
|
this.play(this.sounds.indexOf(target));
|
|
2121
2393
|
return true;
|
|
2122
2394
|
}
|
|
@@ -2176,7 +2448,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
2176
2448
|
* @internal
|
|
2177
2449
|
*/
|
|
2178
2450
|
_onEngineLoad() {
|
|
2179
|
-
if (this.currentIndex != null) this.
|
|
2451
|
+
if (this.currentIndex != null) this._markFailed(this.currentIndex, false);
|
|
2180
2452
|
if (this._eng()?.audio) this._eng().audio.loop = this._repeats();
|
|
2181
2453
|
const sound = this.sounds[this.currentIndex];
|
|
2182
2454
|
if (sound && !sound.peaks && this._eng()?.waveformData?.length) {
|
|
@@ -2230,7 +2502,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
2230
2502
|
_onEngineError(err) {
|
|
2231
2503
|
const index = this.currentIndex;
|
|
2232
2504
|
const sound = index == null ? void 0 : this.sounds[index];
|
|
2233
|
-
if (index != null) this.
|
|
2505
|
+
if (index != null) this._markFailed(index, true);
|
|
2234
2506
|
this._setPlaying(false);
|
|
2235
2507
|
if (sound && !this._cued && this.$?.status) this.$.status.textContent = fill(this.strings.playError, { title: sound.title });
|
|
2236
2508
|
this._emit("error", { error: err, sound, index });
|
|
@@ -2252,7 +2524,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
2252
2524
|
if (on) this._cued = false;
|
|
2253
2525
|
const index = this.currentIndex;
|
|
2254
2526
|
if (index == null) return;
|
|
2255
|
-
if (on) this.
|
|
2527
|
+
if (on) this._markFailed(index, false);
|
|
2256
2528
|
this._paintRow(index);
|
|
2257
2529
|
const was = this._announced ?? null;
|
|
2258
2530
|
if (on) {
|
|
@@ -2294,16 +2566,43 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
2294
2566
|
btn.setAttribute("aria-pressed", String(on));
|
|
2295
2567
|
btn.setAttribute("aria-label", fill(on ? this.strings.pause : this.strings.play, { title: this.sounds[index].title }));
|
|
2296
2568
|
}
|
|
2569
|
+
row.classList.toggle("is-error", this._failed.has(index));
|
|
2297
2570
|
const wave = row.querySelector(".ws-wave");
|
|
2298
|
-
if (wave)
|
|
2299
|
-
wave.tabIndex = current && row === this._active ? 0 : -1;
|
|
2300
|
-
if (!current) {
|
|
2301
|
-
wave.setAttribute("aria-valuenow", "0");
|
|
2302
|
-
wave.removeAttribute("aria-valuetext");
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2571
|
+
if (wave) this._paintWave(wave, current, row === this._active, this.sounds[index].title);
|
|
2305
2572
|
this._drawRow(index);
|
|
2306
2573
|
}
|
|
2574
|
+
/**
|
|
2575
|
+
* A row's waveform: the current sound's is THE seek slider (focusable,
|
|
2576
|
+
* labelled, with a value); every other one is a picture, hidden from
|
|
2577
|
+
* assistive tech and out of the Tab order (a pointer still seeks on it).
|
|
2578
|
+
* So a screen reader meets one slider, not one per row. Since 2.2.0.
|
|
2579
|
+
* @internal
|
|
2580
|
+
*/
|
|
2581
|
+
_paintWave(wave, current, active, title) {
|
|
2582
|
+
if (!current) {
|
|
2583
|
+
if (wave.getAttribute("aria-hidden") === "true" && !wave.hasAttribute("role")) return;
|
|
2584
|
+
for (const name of ["role", "aria-label", "aria-valuemin", "aria-valuemax", "aria-valuenow", "aria-valuetext", "tabindex"]) wave.removeAttribute(name);
|
|
2585
|
+
wave.setAttribute("aria-hidden", "true");
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
wave.removeAttribute("aria-hidden");
|
|
2589
|
+
wave.setAttribute("role", "slider");
|
|
2590
|
+
wave.setAttribute("aria-label", fill(this.strings.seek, { title }));
|
|
2591
|
+
wave.setAttribute("aria-valuemin", "0");
|
|
2592
|
+
wave.setAttribute("aria-valuemax", "100");
|
|
2593
|
+
if (!wave.hasAttribute("aria-valuenow")) wave.setAttribute("aria-valuenow", String(Math.round(this.progress * 100)));
|
|
2594
|
+
wave.tabIndex = active ? 0 : -1;
|
|
2595
|
+
}
|
|
2596
|
+
/**
|
|
2597
|
+
* Record that a sound failed (or played after all), on its row if it
|
|
2598
|
+
* has one; a row rendered later picks it up from `_failed`.
|
|
2599
|
+
* @internal
|
|
2600
|
+
*/
|
|
2601
|
+
_markFailed(index, failed) {
|
|
2602
|
+
if (failed) this._failed.add(index);
|
|
2603
|
+
else this._failed.delete(index);
|
|
2604
|
+
this.rows[index]?.classList.toggle("is-error", failed);
|
|
2605
|
+
}
|
|
2307
2606
|
/**
|
|
2308
2607
|
* The current row's seek slider: its position (0–100) and, for a screen
|
|
2309
2608
|
* reader, the time ("0:12 of 0:30").
|
|
@@ -2350,6 +2649,7 @@ var WaveformSounds = class _WaveformSounds extends EventTarget {
|
|
|
2350
2649
|
this.destroyed = true;
|
|
2351
2650
|
this._ctl.abort();
|
|
2352
2651
|
this._io?.disconnect();
|
|
2652
|
+
this._endIo?.disconnect();
|
|
2353
2653
|
this._ro?.disconnect();
|
|
2354
2654
|
this._mo?.disconnect();
|
|
2355
2655
|
if (this._raf) cancelAnimationFrame(this._raf);
|
|
@@ -2427,7 +2727,8 @@ var ELEMENT_OPTION_KEYS = [
|
|
|
2427
2727
|
"autoAdvance",
|
|
2428
2728
|
"arrowAudition",
|
|
2429
2729
|
"strings",
|
|
2430
|
-
"playerOptions"
|
|
2730
|
+
"playerOptions",
|
|
2731
|
+
"mergeEnharmonicKeys"
|
|
2431
2732
|
];
|
|
2432
2733
|
var kebab = (key) => key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
2433
2734
|
function readElementOptions(el) {
|