@arraypress/waveform-sounds 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +123 -2
- package/dist/waveform-sounds-no-autoinit.cjs +1935 -0
- package/dist/waveform-sounds-no-autoinit.esm.js +1913 -0
- package/dist/waveform-sounds-render.cjs +525 -0
- package/dist/waveform-sounds-render.esm.js +503 -0
- package/dist/waveform-sounds.cjs +1957 -0
- package/dist/waveform-sounds.css +378 -0
- package/dist/waveform-sounds.esm.js +1935 -0
- package/dist/waveform-sounds.js +1920 -0
- package/dist/waveform-sounds.min.css +1 -0
- package/dist/waveform-sounds.min.js +13 -0
- package/index.d.ts +291 -0
- package/no-autoinit.d.ts +2 -0
- package/package.json +96 -4
- package/render.d.ts +3 -0
- package/src/css/waveform-sounds.css +378 -0
- package/src/js/core/WaveformSounds.js +883 -0
- package/src/js/core/engine.js +57 -0
- package/src/js/core/options.js +163 -0
- package/src/js/data/navigation.js +73 -0
- package/src/js/data/sounds.js +306 -0
- package/src/js/data/url-state.js +102 -0
- package/src/js/dom/colors.js +59 -0
- package/src/js/dom/draw.js +93 -0
- package/src/js/dom/menus.js +232 -0
- package/src/js/dom/rows.js +74 -0
- package/src/js/entry.js +25 -0
- package/src/js/index.js +24 -0
- package/src/js/render/html.js +55 -0
- package/src/js/render/icons.js +29 -0
- package/src/js/render/markup.js +295 -0
- package/src/js/render/options.js +90 -0
- package/src/js/render/strings.js +76 -0
- package/src/js/render-entry.js +6 -0
- package/src/js/shared/utils.js +73 -0
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/js/render-entry.js
|
|
20
|
+
var render_entry_exports = {};
|
|
21
|
+
__export(render_entry_exports, {
|
|
22
|
+
DEFAULT_STRINGS: () => DEFAULT_STRINGS,
|
|
23
|
+
decodePeaks: () => decodePeaks,
|
|
24
|
+
encodePeaks: () => encodePeaks,
|
|
25
|
+
escapeHtml: () => escapeHtml,
|
|
26
|
+
facets: () => facets,
|
|
27
|
+
formatDuration: () => formatDuration,
|
|
28
|
+
normalizeKey: () => normalizeKey,
|
|
29
|
+
normalizeSounds: () => normalizeSounds,
|
|
30
|
+
parseManifest: () => parseManifest,
|
|
31
|
+
renderSounds: () => renderSounds,
|
|
32
|
+
renderSoundsElement: () => renderSoundsElement
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(render_entry_exports);
|
|
35
|
+
|
|
36
|
+
// ../../Core/text/src/index.js
|
|
37
|
+
var HTML_ESCAPES = Object.freeze({
|
|
38
|
+
"&": "&",
|
|
39
|
+
"<": "<",
|
|
40
|
+
">": ">",
|
|
41
|
+
'"': """,
|
|
42
|
+
"'": "'"
|
|
43
|
+
});
|
|
44
|
+
function escapeHtml(input) {
|
|
45
|
+
if (input === null || input === void 0) return "";
|
|
46
|
+
return String(input).replace(/[&<>"']/g, (c) => HTML_ESCAPES[c]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/js/data/sounds.js
|
|
50
|
+
function encodePeaks(peaks) {
|
|
51
|
+
if (!Array.isArray(peaks)) return "";
|
|
52
|
+
let out = "";
|
|
53
|
+
for (const p of peaks) {
|
|
54
|
+
const v = Math.round(Math.min(Math.max(Number(p) || 0, 0), 1) * 255);
|
|
55
|
+
out += (v < 16 ? "0" : "") + v.toString(16);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
function decodePeaks(value, scale = 1) {
|
|
60
|
+
if (value == null || value === "") return null;
|
|
61
|
+
if (typeof value === "string") {
|
|
62
|
+
if (!/^[0-9a-f]+$/i.test(value) || value.length % 2) return null;
|
|
63
|
+
const out2 = new Array(value.length / 2);
|
|
64
|
+
for (let i = 0; i < out2.length; i++) out2[i] = parseInt(value.substr(i * 2, 2), 16) / 255;
|
|
65
|
+
return out2;
|
|
66
|
+
}
|
|
67
|
+
if (!Array.isArray(value)) return null;
|
|
68
|
+
const s = Number(scale) > 0 ? Number(scale) : 1;
|
|
69
|
+
const out = value.map((v) => Math.min(Math.max((Number(v) || 0) / s, 0), 1));
|
|
70
|
+
return out.length ? out : null;
|
|
71
|
+
}
|
|
72
|
+
function normalizeKey(key) {
|
|
73
|
+
if (key == null) return "";
|
|
74
|
+
const raw = String(key).trim();
|
|
75
|
+
const m = raw.match(/^([A-Ga-g])[\s_-]*([#♯b♭]?)[\s_-]*(m|min|minor|maj|major)?$/i);
|
|
76
|
+
if (!m) return raw;
|
|
77
|
+
const root = m[1].toUpperCase();
|
|
78
|
+
const acc = m[2] === "\u266F" ? "#" : m[2] === "\u266D" ? "b" : m[2];
|
|
79
|
+
const minor = m[3] && /^m(in(or)?)?$/i.test(m[3]) && m[3] !== "M";
|
|
80
|
+
return root + acc + (minor ? "m" : "");
|
|
81
|
+
}
|
|
82
|
+
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 };
|
|
83
|
+
function keyRank(key) {
|
|
84
|
+
if (!key) return Infinity;
|
|
85
|
+
const minor = key.endsWith("m");
|
|
86
|
+
const root = minor ? key.slice(0, -1) : key;
|
|
87
|
+
const p = KEY_PITCH[root];
|
|
88
|
+
return p === void 0 ? 1e3 : p * 2 + (minor ? 1 : 0);
|
|
89
|
+
}
|
|
90
|
+
function formatDuration(seconds) {
|
|
91
|
+
if (seconds == null || seconds === "") return "";
|
|
92
|
+
const s = Number(seconds);
|
|
93
|
+
if (!Number.isFinite(s) || s < 0) return "";
|
|
94
|
+
const total = Math.round(s);
|
|
95
|
+
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
|
|
96
|
+
}
|
|
97
|
+
function parseDuration(value) {
|
|
98
|
+
if (value == null || value === "") return null;
|
|
99
|
+
if (typeof value === "number") return Number.isFinite(value) && value >= 0 ? value : null;
|
|
100
|
+
const str = String(value).trim();
|
|
101
|
+
if (/^\d+(\.\d+)?$/.test(str)) return Number(str);
|
|
102
|
+
const parts = str.split(":").map(Number);
|
|
103
|
+
if (parts.length < 2 || parts.some((n) => !Number.isFinite(n))) return null;
|
|
104
|
+
return parts.reduce((acc, n) => acc * 60 + n, 0);
|
|
105
|
+
}
|
|
106
|
+
function titleFromUrl(url) {
|
|
107
|
+
const file = String(url || "").split(/[?#]/)[0].split("/").pop() || "";
|
|
108
|
+
let name = file.replace(/\.[a-z0-9]+$/i, "");
|
|
109
|
+
try {
|
|
110
|
+
name = decodeURIComponent(name);
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
return name.replace(/[_]+/g, " ").replace(/\s+/g, " ").trim();
|
|
114
|
+
}
|
|
115
|
+
function normalizeSound(input, index, peakScale = 1) {
|
|
116
|
+
if (!input || typeof input !== "object" || !input.url) return null;
|
|
117
|
+
const bpm = Number(input.bpm);
|
|
118
|
+
const tags = Array.isArray(input.tags) ? input.tags.map((t) => String(t).trim()).filter(Boolean) : typeof input.tags === "string" ? input.tags.split(",").map((t) => t.trim()).filter(Boolean) : [];
|
|
119
|
+
return {
|
|
120
|
+
id: input.id != null && input.id !== "" ? String(input.id) : `sound-${index + 1}`,
|
|
121
|
+
url: String(input.url),
|
|
122
|
+
title: input.title ? String(input.title) : titleFromUrl(input.url),
|
|
123
|
+
type: input.type ? String(input.type) : "",
|
|
124
|
+
bpm: Number.isFinite(bpm) && bpm > 0 ? Math.round(bpm * 100) / 100 : null,
|
|
125
|
+
key: normalizeKey(input.key),
|
|
126
|
+
duration: parseDuration(input.duration),
|
|
127
|
+
tags,
|
|
128
|
+
peaks: decodePeaks(input.peaks, peakScale),
|
|
129
|
+
waveform: input.waveform ? String(input.waveform) : null,
|
|
130
|
+
download: input.download ? String(input.download) : null
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function parseManifest(manifest) {
|
|
134
|
+
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
135
|
+
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
136
|
+
return normalizeSounds(list, scale);
|
|
137
|
+
}
|
|
138
|
+
function normalizeSounds(list, peakScale = 1) {
|
|
139
|
+
const seen = /* @__PURE__ */ new Set();
|
|
140
|
+
const out = [];
|
|
141
|
+
(Array.isArray(list) ? list : []).forEach((item, i) => {
|
|
142
|
+
const s = normalizeSound(item, i, peakScale);
|
|
143
|
+
if (!s) return;
|
|
144
|
+
let id = s.id, n = 2;
|
|
145
|
+
while (seen.has(id)) id = `${s.id}-${n++}`;
|
|
146
|
+
s.id = id;
|
|
147
|
+
seen.add(id);
|
|
148
|
+
out.push(s);
|
|
149
|
+
});
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
function facets(sounds) {
|
|
153
|
+
const types = /* @__PURE__ */ new Map();
|
|
154
|
+
const keys = /* @__PURE__ */ new Set();
|
|
155
|
+
let min = Infinity, max = -Infinity, hasDuration = false;
|
|
156
|
+
for (const s of sounds) {
|
|
157
|
+
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
158
|
+
if (s.key) keys.add(s.key);
|
|
159
|
+
if (s.bpm != null) {
|
|
160
|
+
min = Math.min(min, s.bpm);
|
|
161
|
+
max = Math.max(max, s.bpm);
|
|
162
|
+
}
|
|
163
|
+
if (s.duration != null) hasDuration = true;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
types: [...types].map(([name, count]) => ({ name, count })),
|
|
167
|
+
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
168
|
+
bpm: min === Infinity ? null : { min, max },
|
|
169
|
+
hasDuration
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
var SORTS = ["default", "title", "bpm", "key", "duration"];
|
|
173
|
+
var SORT_NEEDS = {
|
|
174
|
+
default: () => true,
|
|
175
|
+
title: () => true,
|
|
176
|
+
bpm: (f) => f.bpm !== null,
|
|
177
|
+
key: (f) => f.keys.length > 0,
|
|
178
|
+
duration: (f) => f.hasDuration
|
|
179
|
+
};
|
|
180
|
+
function availableSorts(sorts, f) {
|
|
181
|
+
return sorts.filter((sort) => SORT_NEEDS[sort]?.(f));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/js/render/html.js
|
|
185
|
+
var VOID = /* @__PURE__ */ new Set(["input", "br", "img"]);
|
|
186
|
+
function text(value) {
|
|
187
|
+
return escapeHtml(value ?? "");
|
|
188
|
+
}
|
|
189
|
+
function attrs(map = {}) {
|
|
190
|
+
let out = "";
|
|
191
|
+
for (const [name, value] of Object.entries(map)) {
|
|
192
|
+
if (value === true) out += ` ${name}`;
|
|
193
|
+
else if (value !== false && value != null) out += ` ${name}="${escapeHtml(value)}"`;
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
function h(tag, attributes = {}, ...children) {
|
|
198
|
+
const open = `<${tag}${attrs(attributes)}>`;
|
|
199
|
+
if (VOID.has(tag)) return open;
|
|
200
|
+
return open + children.flat(Infinity).filter((c) => c != null && c !== false && c !== "").join("") + `</${tag}>`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/js/render/icons.js
|
|
204
|
+
function icon(path, extraClass = "") {
|
|
205
|
+
const cls = extraClass ? `ws-icon ${extraClass}` : "ws-icon";
|
|
206
|
+
return `<svg class="${cls}" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${path}"/></svg>`;
|
|
207
|
+
}
|
|
208
|
+
var ICONS = {
|
|
209
|
+
play: icon("M8 5.5v13l11-6.5z", "ws-icon-play"),
|
|
210
|
+
pause: icon("M7 5h3.5v14H7zM13.5 5H17v14h-3.5z", "ws-icon-pause"),
|
|
211
|
+
search: icon("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"),
|
|
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")
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/js/render/strings.js
|
|
219
|
+
var DEFAULT_STRINGS = {
|
|
220
|
+
search: "Search sounds",
|
|
221
|
+
searchPlaceholder: "Search sounds\u2026",
|
|
222
|
+
all: "All",
|
|
223
|
+
types: "Type",
|
|
224
|
+
key: "Key",
|
|
225
|
+
anyKey: "Any key",
|
|
226
|
+
allTypes: "All types",
|
|
227
|
+
findType: "Find a type\u2026",
|
|
228
|
+
findKey: "Find a key\u2026",
|
|
229
|
+
noMatches: "No matches",
|
|
230
|
+
bpm: "BPM",
|
|
231
|
+
bpmMin: "Min BPM",
|
|
232
|
+
bpmMax: "Max BPM",
|
|
233
|
+
sort: "Sort",
|
|
234
|
+
sortBy: "Sort by",
|
|
235
|
+
sortDefault: "Default",
|
|
236
|
+
sortTitle: "Name",
|
|
237
|
+
sortBpm: "BPM",
|
|
238
|
+
sortKey: "Key",
|
|
239
|
+
sortDuration: "Length",
|
|
240
|
+
loop: "Loop",
|
|
241
|
+
play: "Play {title}",
|
|
242
|
+
pause: "Pause {title}",
|
|
243
|
+
seek: "Seek {title}",
|
|
244
|
+
download: "Download {title}",
|
|
245
|
+
count: "{count} sounds",
|
|
246
|
+
countOne: "1 sound",
|
|
247
|
+
countFiltered: "{count} of {total} sounds",
|
|
248
|
+
showMore: "Show {count} more",
|
|
249
|
+
empty: "No sounds match.",
|
|
250
|
+
clear: "Clear filters",
|
|
251
|
+
nowPlaying: "Playing {title}"
|
|
252
|
+
};
|
|
253
|
+
var SORT_LABEL_KEYS = {
|
|
254
|
+
default: "sortDefault",
|
|
255
|
+
title: "sortTitle",
|
|
256
|
+
bpm: "sortBpm",
|
|
257
|
+
key: "sortKey",
|
|
258
|
+
duration: "sortDuration"
|
|
259
|
+
};
|
|
260
|
+
function fill(template, vars = {}) {
|
|
261
|
+
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
262
|
+
}
|
|
263
|
+
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
264
|
+
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
265
|
+
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/js/render/options.js
|
|
269
|
+
var FILTERS = ["type", "key", "bpm"];
|
|
270
|
+
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
271
|
+
var RENDER_DEFAULTS = {
|
|
272
|
+
player: "inline",
|
|
273
|
+
search: true,
|
|
274
|
+
filters: [...FILTERS],
|
|
275
|
+
sorts: [...SORTS],
|
|
276
|
+
loopToggle: true,
|
|
277
|
+
showCount: true,
|
|
278
|
+
menuSearch: 8,
|
|
279
|
+
pageSize: 50,
|
|
280
|
+
columns: [...COLUMNS],
|
|
281
|
+
maxTypeChips: 10
|
|
282
|
+
};
|
|
283
|
+
function defined(obj) {
|
|
284
|
+
const out = {};
|
|
285
|
+
for (const k in obj ?? {}) if (obj[k] !== void 0) out[k] = obj[k];
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
function allowedList(values, allowed, fallback) {
|
|
289
|
+
return Array.isArray(values) ? values.filter((v) => allowed.includes(v)) : fallback;
|
|
290
|
+
}
|
|
291
|
+
function wholeNumber(value, fallback) {
|
|
292
|
+
const n = Number(value);
|
|
293
|
+
return Number.isFinite(n) && n >= 0 ? Math.floor(n) : fallback;
|
|
294
|
+
}
|
|
295
|
+
function resolveRenderOptions(options = {}) {
|
|
296
|
+
const o = { ...RENDER_DEFAULTS, ...defined(options) };
|
|
297
|
+
return {
|
|
298
|
+
...o,
|
|
299
|
+
player: o.player === "strip" ? "strip" : "inline",
|
|
300
|
+
filters: allowedList(o.filters, FILTERS, RENDER_DEFAULTS.filters),
|
|
301
|
+
sorts: allowedList(o.sorts, SORTS, RENDER_DEFAULTS.sorts),
|
|
302
|
+
columns: allowedList(o.columns, COLUMNS, RENDER_DEFAULTS.columns),
|
|
303
|
+
menuSearch: wholeNumber(o.menuSearch, RENDER_DEFAULTS.menuSearch),
|
|
304
|
+
maxTypeChips: wholeNumber(o.maxTypeChips, RENDER_DEFAULTS.maxTypeChips),
|
|
305
|
+
pageSize: wholeNumber(o.pageSize, RENDER_DEFAULTS.pageSize),
|
|
306
|
+
strings: { ...DEFAULT_STRINGS, ...defined(options.strings) }
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/js/shared/utils.js
|
|
311
|
+
function hashString(str) {
|
|
312
|
+
let hash = 5381;
|
|
313
|
+
for (const char of str) hash = hash * 33 + char.codePointAt(0) >>> 0;
|
|
314
|
+
return hash;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/js/render/markup.js
|
|
318
|
+
function idBase(sounds) {
|
|
319
|
+
const signature = [sounds.length, ...sounds.map((s) => s.url)].join("|");
|
|
320
|
+
return `ws${hashString(signature).toString(36)}`;
|
|
321
|
+
}
|
|
322
|
+
function toolbarPlan(f, o) {
|
|
323
|
+
const typed = o.filters.includes("type") && f.types.length > 1;
|
|
324
|
+
const sorts = availableSorts(o.sorts, f);
|
|
325
|
+
return {
|
|
326
|
+
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
327
|
+
key: o.filters.includes("key") && f.keys.length > 1,
|
|
328
|
+
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
329
|
+
sorts: sorts.length > 1 ? sorts : [],
|
|
330
|
+
search: !!o.search,
|
|
331
|
+
loop: !!o.loopToggle,
|
|
332
|
+
count: !!o.showCount
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function renderSearch(s) {
|
|
336
|
+
return h(
|
|
337
|
+
"label",
|
|
338
|
+
{ class: "ws-search" },
|
|
339
|
+
ICONS.search,
|
|
340
|
+
h("span", { class: "ws-sr" }, text(s.search)),
|
|
341
|
+
h("input", { type: "search", class: "ws-search-input", "data-ws-search": true, placeholder: s.searchPlaceholder, autocomplete: "off", spellcheck: "false" })
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
function renderMenu(name, m) {
|
|
345
|
+
const listId = `${m.id}-${name}-list`;
|
|
346
|
+
const current = m.options.find((o) => o.value === m.value) ?? m.options[0];
|
|
347
|
+
const searchable = m.placeholder && m.options.length > m.searchFrom;
|
|
348
|
+
const button = h(
|
|
349
|
+
"button",
|
|
350
|
+
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "listbox", "aria-expanded": "false", "aria-controls": listId },
|
|
351
|
+
m.prefix ? h("span", { class: "ws-menu-prefix" }, text(m.prefix)) : h("span", { class: "ws-sr" }, text(`${m.label}: `)),
|
|
352
|
+
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(current.label)),
|
|
353
|
+
ICONS.chevron
|
|
354
|
+
);
|
|
355
|
+
const search = searchable && h("input", {
|
|
356
|
+
type: "search",
|
|
357
|
+
class: "ws-menu-search",
|
|
358
|
+
"data-ws-menu-search": true,
|
|
359
|
+
role: "combobox",
|
|
360
|
+
"aria-expanded": "true",
|
|
361
|
+
"aria-controls": listId,
|
|
362
|
+
"aria-autocomplete": "list",
|
|
363
|
+
"aria-label": m.placeholder,
|
|
364
|
+
placeholder: m.placeholder,
|
|
365
|
+
autocomplete: "off",
|
|
366
|
+
spellcheck: "false"
|
|
367
|
+
});
|
|
368
|
+
const options = m.options.map((o, i) => h(
|
|
369
|
+
"li",
|
|
370
|
+
{ role: "option", id: `${m.id}-${name}-${i}`, class: "ws-menu-option", "data-value": o.value, "aria-selected": String(o === current) },
|
|
371
|
+
ICONS.check,
|
|
372
|
+
h("span", { class: "ws-menu-text" }, text(o.label)),
|
|
373
|
+
o.count != null && h("span", { class: "ws-menu-count" }, text(o.count))
|
|
374
|
+
));
|
|
375
|
+
return h(
|
|
376
|
+
"div",
|
|
377
|
+
{ class: "ws-menu", "data-ws-menu": name },
|
|
378
|
+
button,
|
|
379
|
+
h(
|
|
380
|
+
"div",
|
|
381
|
+
{ class: "ws-menu-pop", "data-ws-menu-pop": true, hidden: true },
|
|
382
|
+
search,
|
|
383
|
+
h("ul", { class: "ws-menu-list", role: "listbox", id: listId, "aria-label": m.label, tabindex: "-1", "data-ws-menu-list": true }, options),
|
|
384
|
+
h("p", { class: "ws-menu-none", "data-ws-menu-none": true, hidden: true }, text(m.noMatches))
|
|
385
|
+
)
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
function renderBpmRange(s, range) {
|
|
389
|
+
const field = (attr, label, placeholder) => h("input", { type: "number", inputmode: "numeric", [attr]: true, "aria-label": label, placeholder, min: "0", step: "1" });
|
|
390
|
+
return h(
|
|
391
|
+
"span",
|
|
392
|
+
{ class: "ws-bpm-range", role: "group", "aria-label": s.bpm },
|
|
393
|
+
field("data-ws-bpm-min", s.bpmMin, range.min),
|
|
394
|
+
h("span", { "aria-hidden": "true" }, "\u2013"),
|
|
395
|
+
field("data-ws-bpm-max", s.bpmMax, range.max),
|
|
396
|
+
h("span", { class: "ws-bpm-unit", "aria-hidden": "true" }, text(s.bpm))
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
function renderLoopToggle(s) {
|
|
400
|
+
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": "false" }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
401
|
+
}
|
|
402
|
+
function renderChip(value, label, count, pressed) {
|
|
403
|
+
return h(
|
|
404
|
+
"button",
|
|
405
|
+
{ type: "button", class: "ws-chip", "data-ws-type": value, "aria-pressed": String(pressed) },
|
|
406
|
+
h("span", { class: "ws-chip-label" }, text(label)),
|
|
407
|
+
" ",
|
|
408
|
+
h("span", { class: "ws-chip-count" }, text(count))
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
function renderToolbar(plan, { o, s, f, total, id }) {
|
|
412
|
+
const menu = (name, m) => renderMenu(name, { id, searchFrom: o.menuSearch, noMatches: s.noMatches, ...m });
|
|
413
|
+
const controls = [
|
|
414
|
+
plan.types === "menu" && menu("type", {
|
|
415
|
+
label: s.types,
|
|
416
|
+
value: "",
|
|
417
|
+
placeholder: s.findType,
|
|
418
|
+
options: [{ value: "", label: s.allTypes, count: total }, ...f.types.map((t) => ({ value: t.name, label: t.name, count: t.count }))]
|
|
419
|
+
}),
|
|
420
|
+
plan.key && menu("key", {
|
|
421
|
+
label: s.key,
|
|
422
|
+
value: "",
|
|
423
|
+
placeholder: s.findKey,
|
|
424
|
+
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
425
|
+
}),
|
|
426
|
+
plan.bpm && renderBpmRange(s, f.bpm),
|
|
427
|
+
plan.sorts.length > 0 && menu("sort", {
|
|
428
|
+
label: s.sort,
|
|
429
|
+
prefix: s.sortBy,
|
|
430
|
+
value: plan.sorts[0],
|
|
431
|
+
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
432
|
+
}),
|
|
433
|
+
plan.loop && renderLoopToggle(s)
|
|
434
|
+
].filter(Boolean);
|
|
435
|
+
const chips = plan.types === "chips" && h(
|
|
436
|
+
"div",
|
|
437
|
+
{ class: "ws-types", role: "group", "aria-label": s.types },
|
|
438
|
+
renderChip("", s.all, total, true),
|
|
439
|
+
f.types.map((t) => renderChip(t.name, t.name, t.count, false))
|
|
440
|
+
);
|
|
441
|
+
const count = plan.count && h("p", { class: "ws-count", "data-ws-count": true, "aria-live": "polite" }, text(countText(total, total, s)));
|
|
442
|
+
return h(
|
|
443
|
+
"div",
|
|
444
|
+
{ class: "ws-toolbar" },
|
|
445
|
+
plan.search && renderSearch(s),
|
|
446
|
+
controls.length > 0 && h("div", { class: "ws-controls" }, controls),
|
|
447
|
+
// The chips and the count share a row (the count alone without chips).
|
|
448
|
+
(chips || count) && h("div", { class: "ws-meta" }, chips, count)
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
var CELLS = {
|
|
452
|
+
type: (sound) => text(sound.type),
|
|
453
|
+
bpm: (sound) => text(sound.bpm ?? ""),
|
|
454
|
+
key: (sound) => text(sound.key),
|
|
455
|
+
duration: (sound) => text(formatDuration(sound.duration))
|
|
456
|
+
};
|
|
457
|
+
function renderRow(sound, index, o, hidden = false) {
|
|
458
|
+
const s = o.strings;
|
|
459
|
+
const vars = { title: sound.title };
|
|
460
|
+
const cells = o.columns.map((c) => h("span", { class: `ws-cell ws-${c}` }, CELLS[c](sound)));
|
|
461
|
+
return h(
|
|
462
|
+
"li",
|
|
463
|
+
{
|
|
464
|
+
class: "ws-row",
|
|
465
|
+
"data-ws-index": index,
|
|
466
|
+
"data-ws-id": sound.id,
|
|
467
|
+
"data-url": sound.url,
|
|
468
|
+
"data-title": sound.title,
|
|
469
|
+
"data-type": sound.type || null,
|
|
470
|
+
"data-bpm": sound.bpm,
|
|
471
|
+
"data-key": sound.key || null,
|
|
472
|
+
"data-duration": sound.duration,
|
|
473
|
+
"data-tags": sound.tags?.length ? sound.tags.join(",") : null,
|
|
474
|
+
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
475
|
+
"data-waveform": sound.waveform,
|
|
476
|
+
"data-download": sound.download,
|
|
477
|
+
hidden
|
|
478
|
+
},
|
|
479
|
+
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
480
|
+
h("span", { class: "ws-cell ws-title" }, text(sound.title)),
|
|
481
|
+
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
482
|
+
// rows: one line under the title.
|
|
483
|
+
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
484
|
+
o.player === "inline" && h(
|
|
485
|
+
"span",
|
|
486
|
+
{ class: "ws-wave", role: "slider", "aria-label": fill(s.seek, vars), "aria-valuemin": "0", "aria-valuemax": "100", "aria-valuenow": "0", tabindex: "-1" },
|
|
487
|
+
h("canvas", { class: "ws-canvas", "aria-hidden": "true" })
|
|
488
|
+
),
|
|
489
|
+
// Optional, per sound: a plain link. Rows without one carry nothing.
|
|
490
|
+
sound.download && h("a", { class: "ws-download", href: sound.download, download: true, "aria-label": fill(s.download, vars) }, ICONS.download)
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
function renderFooter({ o, s, total }) {
|
|
494
|
+
const page = o.pageSize > 0 ? o.pageSize : total;
|
|
495
|
+
const more = Math.max(0, total - page);
|
|
496
|
+
const strip = o.player === "strip";
|
|
497
|
+
return [
|
|
498
|
+
h(
|
|
499
|
+
"p",
|
|
500
|
+
{ class: "ws-empty", "data-ws-empty": true, hidden: true },
|
|
501
|
+
text(s.empty),
|
|
502
|
+
" ",
|
|
503
|
+
h("button", { type: "button", class: "ws-clear", "data-ws-clear": true }, text(s.clear))
|
|
504
|
+
),
|
|
505
|
+
h("button", { type: "button", class: "ws-more", "data-ws-more": true, hidden: more === 0 }, text(fill(s.showMore, { count: Math.min(more, page) }))),
|
|
506
|
+
h("div", { class: strip ? "ws-engine ws-engine--strip" : "ws-engine", "data-ws-engine": true, hidden: !strip }),
|
|
507
|
+
h("p", { class: "ws-sr", "data-ws-status": true, "aria-live": "polite" })
|
|
508
|
+
].join("");
|
|
509
|
+
}
|
|
510
|
+
function renderSounds(sounds, options = {}) {
|
|
511
|
+
const o = resolveRenderOptions(options);
|
|
512
|
+
const list = normalizeSounds(sounds);
|
|
513
|
+
const ctx = { o, s: o.strings, f: facets(list), total: list.length, id: o.idPrefix || idBase(list) };
|
|
514
|
+
const page = o.pageSize > 0 ? o.pageSize : Infinity;
|
|
515
|
+
return renderToolbar(toolbarPlan(ctx.f, o), ctx) + h(
|
|
516
|
+
"ul",
|
|
517
|
+
{ class: `ws-list ws-list--${o.player}`, role: "list", "data-ws-list": true },
|
|
518
|
+
list.map((sound, i) => renderRow(sound, i, o, i >= page))
|
|
519
|
+
) + renderFooter(ctx);
|
|
520
|
+
}
|
|
521
|
+
function renderSoundsElement(sounds, options = {}, className = "") {
|
|
522
|
+
const o = resolveRenderOptions(options);
|
|
523
|
+
const cls = ["waveform-sounds", `waveform-sounds--${o.player}`, className].filter(Boolean).join(" ");
|
|
524
|
+
return h("div", { class: cls, "data-waveform-sounds": true, "data-player": o.player }, renderSounds(sounds, options));
|
|
525
|
+
}
|