@arraypress/waveform-sounds 0.3.1 → 2.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 +1 -1
- package/README.md +43 -3
- package/dist/waveform-sounds-no-autoinit.esm.js +607 -178
- package/dist/waveform-sounds-render.esm.js +79 -15
- package/dist/waveform-sounds.css +136 -79
- package/dist/waveform-sounds.esm.js +611 -181
- package/dist/waveform-sounds.js +608 -181
- package/dist/waveform-sounds.min.css +1 -1
- package/dist/waveform-sounds.min.js +3 -3
- package/package.json +36 -33
- package/src/css/waveform-sounds.css +136 -79
- package/src/js/core/WaveformSounds.ts +1366 -0
- package/src/js/core/element.ts +208 -0
- package/src/js/core/engine.ts +107 -0
- package/src/js/core/{options.js → options.ts} +28 -28
- package/src/js/data/{bpm.js → bpm.ts} +27 -17
- package/src/js/data/{navigation.js → navigation.ts} +31 -18
- package/src/js/data/{sounds.js → sounds.ts} +97 -66
- package/src/js/data/url-state.ts +130 -0
- package/src/js/dom/colors.ts +86 -0
- package/src/js/dom/{draw.js → draw.ts} +16 -17
- package/src/js/dom/{menus.js → menus.ts} +70 -55
- package/src/js/dom/{rows.js → rows.ts} +15 -17
- package/src/js/entry.ts +60 -0
- package/src/js/{index.js → index.ts} +7 -3
- package/src/js/render/{html.js → html.ts} +16 -12
- package/src/js/render/{icons.js → icons.ts} +3 -4
- package/src/js/render/{markup.js → markup.ts} +114 -64
- package/src/js/render/options.ts +118 -0
- package/src/js/render/{strings.js → strings.ts} +18 -16
- package/src/js/{render-entry.js → render-entry.ts} +2 -1
- package/src/js/shared/{utils.js → utils.ts} +24 -24
- package/{index.d.ts → src/js/types.ts} +40 -88
- package/types/core/WaveformSounds.d.ts +175 -0
- package/types/core/WaveformSounds.d.ts.map +1 -0
- package/types/core/element.d.ts +84 -0
- package/types/core/element.d.ts.map +1 -0
- package/types/core/engine.d.ts +72 -0
- package/types/core/engine.d.ts.map +1 -0
- package/types/core/options.d.ts +71 -0
- package/types/core/options.d.ts.map +1 -0
- package/types/data/bpm.d.ts +80 -0
- package/types/data/bpm.d.ts.map +1 -0
- package/types/data/navigation.d.ts +62 -0
- package/types/data/navigation.d.ts.map +1 -0
- package/types/data/sounds.d.ts +168 -0
- package/types/data/sounds.d.ts.map +1 -0
- package/types/data/url-state.d.ts +109 -0
- package/types/data/url-state.d.ts.map +1 -0
- package/types/dom/colors.d.ts +48 -0
- package/types/dom/colors.d.ts.map +1 -0
- package/types/dom/draw.d.ts +72 -0
- package/types/dom/draw.d.ts.map +1 -0
- package/types/dom/menus.d.ts +75 -0
- package/types/dom/menus.d.ts.map +1 -0
- package/types/dom/rows.d.ts +39 -0
- package/types/dom/rows.d.ts.map +1 -0
- package/types/entry.d.ts +28 -0
- package/types/entry.d.ts.map +1 -0
- package/types/index.d.ts +16 -0
- package/types/index.d.ts.map +1 -0
- package/types/render/html.d.ts +37 -0
- package/types/render/html.d.ts.map +1 -0
- package/types/render/icons.d.ts +17 -0
- package/types/render/icons.d.ts.map +1 -0
- package/types/render/markup.d.ts +141 -0
- package/types/render/markup.d.ts.map +1 -0
- package/types/render/options.d.ts +69 -0
- package/types/render/options.d.ts.map +1 -0
- package/types/render/strings.d.ts +43 -0
- package/types/render/strings.d.ts.map +1 -0
- package/types/render-entry.d.ts +8 -0
- package/types/render-entry.d.ts.map +1 -0
- package/types/shared/utils.d.ts +57 -0
- package/types/shared/utils.d.ts.map +1 -0
- package/types/types.d.ts +280 -0
- package/types/types.d.ts.map +1 -0
- package/types/vendor/arraypress-text.d.ts +250 -0
- package/dist/waveform-sounds-no-autoinit.cjs +0 -2159
- package/dist/waveform-sounds-render.cjs +0 -614
- package/dist/waveform-sounds.cjs +0 -2181
- package/no-autoinit.d.ts +0 -2
- package/render.d.ts +0 -5
- package/src/js/core/WaveformSounds.js +0 -993
- package/src/js/core/engine.js +0 -57
- package/src/js/data/url-state.js +0 -106
- package/src/js/dom/colors.js +0 -59
- package/src/js/entry.js +0 -25
- package/src/js/render/options.js +0 -90
|
@@ -1,614 +0,0 @@
|
|
|
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
|
-
// node_modules/@arraypress/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
|
-
if (s > 0 && s < 0.95) return `${Math.max(0.1, Math.round(s * 10) / 10).toFixed(1)}s`;
|
|
95
|
-
const total = s < 1 ? Math.ceil(s) : Math.floor(s);
|
|
96
|
-
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
|
|
97
|
-
}
|
|
98
|
-
function parseDuration(value) {
|
|
99
|
-
if (value == null || value === "") return null;
|
|
100
|
-
if (typeof value === "number") return Number.isFinite(value) && value >= 0 ? value : null;
|
|
101
|
-
const str = String(value).trim();
|
|
102
|
-
if (/^\d+(\.\d+)?$/.test(str)) return Number(str);
|
|
103
|
-
const parts = str.split(":").map(Number);
|
|
104
|
-
if (parts.length < 2 || parts.some((n) => !Number.isFinite(n))) return null;
|
|
105
|
-
return parts.reduce((acc, n) => acc * 60 + n, 0);
|
|
106
|
-
}
|
|
107
|
-
function titleFromUrl(url) {
|
|
108
|
-
const file = String(url || "").split(/[?#]/)[0].split("/").pop() || "";
|
|
109
|
-
let name = file.replace(/\.[a-z0-9]+$/i, "");
|
|
110
|
-
try {
|
|
111
|
-
name = decodeURIComponent(name);
|
|
112
|
-
} catch {
|
|
113
|
-
}
|
|
114
|
-
return name.replace(/[_]+/g, " ").replace(/\s+/g, " ").trim();
|
|
115
|
-
}
|
|
116
|
-
function normalizeSound(input, index, peakScale = 1) {
|
|
117
|
-
if (!input || typeof input !== "object" || !input.url) return null;
|
|
118
|
-
const bpm = Number(input.bpm);
|
|
119
|
-
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) : [];
|
|
120
|
-
return {
|
|
121
|
-
id: input.id != null && input.id !== "" ? String(input.id) : `sound-${index + 1}`,
|
|
122
|
-
url: String(input.url),
|
|
123
|
-
title: input.title ? String(input.title) : titleFromUrl(input.url),
|
|
124
|
-
type: input.type ? String(input.type) : "",
|
|
125
|
-
bpm: Number.isFinite(bpm) && bpm > 0 ? Math.round(bpm * 100) / 100 : null,
|
|
126
|
-
key: normalizeKey(input.key),
|
|
127
|
-
duration: parseDuration(input.duration),
|
|
128
|
-
tags,
|
|
129
|
-
peaks: decodePeaks(input.peaks, peakScale),
|
|
130
|
-
waveform: input.waveform ? String(input.waveform) : null,
|
|
131
|
-
download: input.download ? String(input.download) : null,
|
|
132
|
-
loop: isLoop(input.loop)
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function isLoop(value) {
|
|
136
|
-
return value === true || value === 1 || value === "true" || value === "1";
|
|
137
|
-
}
|
|
138
|
-
function parseManifest(manifest) {
|
|
139
|
-
const list = Array.isArray(manifest) ? manifest : Array.isArray(manifest?.sounds) ? manifest.sounds : [];
|
|
140
|
-
const scale = Array.isArray(manifest) ? 1 : Number(manifest?.peakScale) || 1;
|
|
141
|
-
return normalizeSounds(list, scale);
|
|
142
|
-
}
|
|
143
|
-
function normalizeSounds(list, peakScale = 1) {
|
|
144
|
-
const seen = /* @__PURE__ */ new Set();
|
|
145
|
-
const out = [];
|
|
146
|
-
(Array.isArray(list) ? list : []).forEach((item, i) => {
|
|
147
|
-
const s = normalizeSound(item, i, peakScale);
|
|
148
|
-
if (!s) return;
|
|
149
|
-
let id = s.id, n = 2;
|
|
150
|
-
while (seen.has(id)) id = `${s.id}-${n++}`;
|
|
151
|
-
s.id = id;
|
|
152
|
-
seen.add(id);
|
|
153
|
-
out.push(s);
|
|
154
|
-
});
|
|
155
|
-
return out;
|
|
156
|
-
}
|
|
157
|
-
function facets(sounds) {
|
|
158
|
-
const types = /* @__PURE__ */ new Map();
|
|
159
|
-
const keys = /* @__PURE__ */ new Set();
|
|
160
|
-
let min = Infinity, max = -Infinity, hasDuration = false, loops = 0;
|
|
161
|
-
for (const s of sounds) {
|
|
162
|
-
if (s.type) types.set(s.type, (types.get(s.type) || 0) + 1);
|
|
163
|
-
if (s.key) keys.add(s.key);
|
|
164
|
-
if (s.bpm != null) {
|
|
165
|
-
min = Math.min(min, s.bpm);
|
|
166
|
-
max = Math.max(max, s.bpm);
|
|
167
|
-
}
|
|
168
|
-
if (s.duration != null) hasDuration = true;
|
|
169
|
-
if (s.loop) loops++;
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
types: [...types].map(([name, count]) => ({ name, count })),
|
|
173
|
-
keys: [...keys].sort((a, b) => keyRank(a) - keyRank(b) || a.localeCompare(b)),
|
|
174
|
-
bpm: min === Infinity ? null : { min, max },
|
|
175
|
-
hasDuration,
|
|
176
|
-
loops,
|
|
177
|
-
oneShots: sounds.length - loops
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
var SORTS = ["default", "title", "bpm", "key", "duration"];
|
|
181
|
-
var SORT_NEEDS = {
|
|
182
|
-
default: () => true,
|
|
183
|
-
title: () => true,
|
|
184
|
-
bpm: (f) => f.bpm !== null,
|
|
185
|
-
key: (f) => f.keys.length > 0,
|
|
186
|
-
duration: (f) => f.hasDuration
|
|
187
|
-
};
|
|
188
|
-
function availableSorts(sorts, f) {
|
|
189
|
-
return sorts.filter((sort) => SORT_NEEDS[sort]?.(f));
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// src/js/render/html.js
|
|
193
|
-
var VOID = /* @__PURE__ */ new Set(["input", "br", "img"]);
|
|
194
|
-
function text(value) {
|
|
195
|
-
return escapeHtml(value ?? "");
|
|
196
|
-
}
|
|
197
|
-
function attrs(map = {}) {
|
|
198
|
-
let out = "";
|
|
199
|
-
for (const [name, value] of Object.entries(map)) {
|
|
200
|
-
if (value === true) out += ` ${name}`;
|
|
201
|
-
else if (value !== false && value != null) out += ` ${name}="${escapeHtml(value)}"`;
|
|
202
|
-
}
|
|
203
|
-
return out;
|
|
204
|
-
}
|
|
205
|
-
function h(tag, attributes = {}, ...children) {
|
|
206
|
-
const open = `<${tag}${attrs(attributes)}>`;
|
|
207
|
-
if (VOID.has(tag)) return open;
|
|
208
|
-
return open + children.flat(Infinity).filter((c) => c != null && c !== false && c !== "").join("") + `</${tag}>`;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/js/render/icons.js
|
|
212
|
-
function icon(path, extraClass = "") {
|
|
213
|
-
const cls = extraClass ? `ws-icon ${extraClass}` : "ws-icon";
|
|
214
|
-
return `<svg class="${cls}" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${path}"/></svg>`;
|
|
215
|
-
}
|
|
216
|
-
var ICONS = {
|
|
217
|
-
play: icon("M8 5.5v13l11-6.5z", "ws-icon-play"),
|
|
218
|
-
pause: icon("M7 5h3.5v14H7zM13.5 5H17v14h-3.5z", "ws-icon-pause"),
|
|
219
|
-
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"),
|
|
220
|
-
chevron: icon("M6.4 8.6 12 14.2l5.6-5.6L19 10l-7 7-7-7z", "ws-menu-chevron"),
|
|
221
|
-
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"),
|
|
222
|
-
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"),
|
|
223
|
-
loop: icon("M17 4l3 3-3 3V8H8a3 3 0 0 0-3 3v1H3v-1a5 5 0 0 1 5-5h9V4zM7 20l-3-3 3-3v2h9a3 3 0 0 0 3-3v-1h2v1a5 5 0 0 1-5 5H7v2z")
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
// src/js/data/bpm.js
|
|
227
|
-
function bpmRangeFromFilter(filter, extent) {
|
|
228
|
-
const read = (v, fallback) => {
|
|
229
|
-
const n = Number(v);
|
|
230
|
-
return v === "" || v == null || !Number.isFinite(n) ? fallback : Math.min(Math.max(n, extent.min), extent.max);
|
|
231
|
-
};
|
|
232
|
-
const lo = read(filter.bpmMin, extent.min);
|
|
233
|
-
const hi = read(filter.bpmMax, extent.max);
|
|
234
|
-
return lo <= hi ? { lo, hi } : { lo: hi, hi: lo };
|
|
235
|
-
}
|
|
236
|
-
function hasBpmFilter(filter) {
|
|
237
|
-
return filter.bpmMin != null && filter.bpmMin !== "" || filter.bpmMax != null && filter.bpmMax !== "";
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// src/js/render/strings.js
|
|
241
|
-
var DEFAULT_STRINGS = {
|
|
242
|
-
search: "Search sounds",
|
|
243
|
-
searchPlaceholder: "Search sounds\u2026",
|
|
244
|
-
all: "All",
|
|
245
|
-
types: "Type",
|
|
246
|
-
key: "Key",
|
|
247
|
-
anyKey: "Any key",
|
|
248
|
-
allTypes: "All types",
|
|
249
|
-
findType: "Find a type\u2026",
|
|
250
|
-
findKey: "Find a key\u2026",
|
|
251
|
-
noMatches: "No matches",
|
|
252
|
-
bpm: "BPM",
|
|
253
|
-
bpmMin: "Min BPM",
|
|
254
|
-
bpmMax: "Max BPM",
|
|
255
|
-
anyBpm: "Any BPM",
|
|
256
|
-
bpmRange: "{min}\u2013{max} BPM",
|
|
257
|
-
sort: "Sort",
|
|
258
|
-
sortBy: "Sort by",
|
|
259
|
-
sortDefault: "Default",
|
|
260
|
-
sortTitle: "Name",
|
|
261
|
-
sortBpm: "BPM",
|
|
262
|
-
sortKey: "Key",
|
|
263
|
-
sortDuration: "Length",
|
|
264
|
-
loop: "Loop",
|
|
265
|
-
loopFilter: "Loops or one-shots",
|
|
266
|
-
loops: "Loops",
|
|
267
|
-
oneShots: "One-shots",
|
|
268
|
-
isLoop: "Loop",
|
|
269
|
-
play: "Play {title}",
|
|
270
|
-
pause: "Pause {title}",
|
|
271
|
-
seek: "Seek {title}",
|
|
272
|
-
download: "Download {title}",
|
|
273
|
-
count: "{count} sounds",
|
|
274
|
-
countOne: "1 sound",
|
|
275
|
-
countFiltered: "{count} of {total} sounds",
|
|
276
|
-
showMore: "Show {count} more",
|
|
277
|
-
empty: "No sounds match.",
|
|
278
|
-
clear: "Clear filters",
|
|
279
|
-
nowPlaying: "Playing {title}"
|
|
280
|
-
};
|
|
281
|
-
var SORT_LABEL_KEYS = {
|
|
282
|
-
default: "sortDefault",
|
|
283
|
-
title: "sortTitle",
|
|
284
|
-
bpm: "sortBpm",
|
|
285
|
-
key: "sortKey",
|
|
286
|
-
duration: "sortDuration"
|
|
287
|
-
};
|
|
288
|
-
function fill(template, vars = {}) {
|
|
289
|
-
return String(template).replace(/\{(\w+)\}/g, (match, name) => name in vars ? String(vars[name]) : match);
|
|
290
|
-
}
|
|
291
|
-
function bpmLabel(filter, extent, strings = DEFAULT_STRINGS) {
|
|
292
|
-
if (!hasBpmFilter(filter)) return strings.anyBpm;
|
|
293
|
-
const { lo, hi } = bpmRangeFromFilter(filter, extent);
|
|
294
|
-
return fill(strings.bpmRange, { min: lo, max: hi });
|
|
295
|
-
}
|
|
296
|
-
function countText(shown, total, strings = DEFAULT_STRINGS) {
|
|
297
|
-
if (shown !== total) return fill(strings.countFiltered, { count: shown, total });
|
|
298
|
-
return total === 1 ? strings.countOne : fill(strings.count, { count: total });
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// src/js/render/options.js
|
|
302
|
-
var FILTERS = ["type", "key", "bpm", "loop"];
|
|
303
|
-
var COLUMNS = ["type", "bpm", "key", "duration"];
|
|
304
|
-
var RENDER_DEFAULTS = {
|
|
305
|
-
player: "inline",
|
|
306
|
-
search: true,
|
|
307
|
-
filters: [...FILTERS],
|
|
308
|
-
sorts: [...SORTS],
|
|
309
|
-
loopToggle: true,
|
|
310
|
-
showCount: true,
|
|
311
|
-
menuSearch: 8,
|
|
312
|
-
pageSize: 50,
|
|
313
|
-
columns: [...COLUMNS],
|
|
314
|
-
maxTypeChips: 10
|
|
315
|
-
};
|
|
316
|
-
function defined(obj) {
|
|
317
|
-
const out = {};
|
|
318
|
-
for (const k in obj ?? {}) if (obj[k] !== void 0) out[k] = obj[k];
|
|
319
|
-
return out;
|
|
320
|
-
}
|
|
321
|
-
function allowedList(values, allowed, fallback) {
|
|
322
|
-
return Array.isArray(values) ? values.filter((v) => allowed.includes(v)) : fallback;
|
|
323
|
-
}
|
|
324
|
-
function wholeNumber(value, fallback) {
|
|
325
|
-
const n = Number(value);
|
|
326
|
-
return Number.isFinite(n) && n >= 0 ? Math.floor(n) : fallback;
|
|
327
|
-
}
|
|
328
|
-
function resolveRenderOptions(options = {}) {
|
|
329
|
-
const o = { ...RENDER_DEFAULTS, ...defined(options) };
|
|
330
|
-
return {
|
|
331
|
-
...o,
|
|
332
|
-
player: o.player === "strip" ? "strip" : "inline",
|
|
333
|
-
filters: allowedList(o.filters, FILTERS, RENDER_DEFAULTS.filters),
|
|
334
|
-
sorts: allowedList(o.sorts, SORTS, RENDER_DEFAULTS.sorts),
|
|
335
|
-
columns: allowedList(o.columns, COLUMNS, RENDER_DEFAULTS.columns),
|
|
336
|
-
menuSearch: wholeNumber(o.menuSearch, RENDER_DEFAULTS.menuSearch),
|
|
337
|
-
maxTypeChips: wholeNumber(o.maxTypeChips, RENDER_DEFAULTS.maxTypeChips),
|
|
338
|
-
pageSize: wholeNumber(o.pageSize, RENDER_DEFAULTS.pageSize),
|
|
339
|
-
strings: { ...DEFAULT_STRINGS, ...defined(options.strings) }
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// src/js/shared/utils.js
|
|
344
|
-
function hashString(str) {
|
|
345
|
-
let hash = 5381;
|
|
346
|
-
for (const char of str) hash = hash * 33 + char.codePointAt(0) >>> 0;
|
|
347
|
-
return hash;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// src/js/render/markup.js
|
|
351
|
-
function idBase(sounds) {
|
|
352
|
-
const signature = [sounds.length, ...sounds.map((s) => s.url)].join("|");
|
|
353
|
-
return `ws${hashString(signature).toString(36)}`;
|
|
354
|
-
}
|
|
355
|
-
function toolbarPlan(f, o) {
|
|
356
|
-
const typed = o.filters.includes("type") && f.types.length > 1;
|
|
357
|
-
const sorts = availableSorts(o.sorts, f);
|
|
358
|
-
return {
|
|
359
|
-
types: !typed ? null : f.types.length > o.maxTypeChips ? "menu" : "chips",
|
|
360
|
-
key: o.filters.includes("key") && f.keys.length > 1,
|
|
361
|
-
bpm: o.filters.includes("bpm") && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
362
|
-
loops: o.filters.includes("loop") && f.loops > 0 && f.oneShots > 0,
|
|
363
|
-
sorts: sorts.length > 1 ? sorts : [],
|
|
364
|
-
search: !!o.search,
|
|
365
|
-
loop: !!o.loopToggle,
|
|
366
|
-
count: !!o.showCount
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
function loopsByDefault(loop, f) {
|
|
370
|
-
return loop == null ? f.loops > 0 : !!loop;
|
|
371
|
-
}
|
|
372
|
-
function renderSearch(s) {
|
|
373
|
-
return h(
|
|
374
|
-
"label",
|
|
375
|
-
{ class: "ws-search" },
|
|
376
|
-
ICONS.search,
|
|
377
|
-
h("span", { class: "ws-sr" }, text(s.search)),
|
|
378
|
-
h("input", { type: "search", class: "ws-search-input", "data-ws-search": true, placeholder: s.searchPlaceholder, autocomplete: "off", spellcheck: "false" })
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
function renderMenu(name, m) {
|
|
382
|
-
const listId = `${m.id}-${name}-list`;
|
|
383
|
-
const current = m.options.find((o) => o.value === m.value) ?? m.options[0];
|
|
384
|
-
const searchable = m.placeholder && m.options.length > m.searchFrom;
|
|
385
|
-
const button = h(
|
|
386
|
-
"button",
|
|
387
|
-
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "listbox", "aria-expanded": "false", "aria-controls": listId },
|
|
388
|
-
m.prefix ? h("span", { class: "ws-menu-prefix" }, text(m.prefix)) : h("span", { class: "ws-sr" }, text(`${m.label}: `)),
|
|
389
|
-
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(current.label)),
|
|
390
|
-
ICONS.chevron
|
|
391
|
-
);
|
|
392
|
-
const search = searchable && h("input", {
|
|
393
|
-
type: "search",
|
|
394
|
-
class: "ws-menu-search",
|
|
395
|
-
"data-ws-menu-search": true,
|
|
396
|
-
role: "combobox",
|
|
397
|
-
"aria-expanded": "true",
|
|
398
|
-
"aria-controls": listId,
|
|
399
|
-
"aria-autocomplete": "list",
|
|
400
|
-
"aria-label": m.placeholder,
|
|
401
|
-
placeholder: m.placeholder,
|
|
402
|
-
autocomplete: "off",
|
|
403
|
-
spellcheck: "false"
|
|
404
|
-
});
|
|
405
|
-
const options = m.options.map((o, i) => h(
|
|
406
|
-
"li",
|
|
407
|
-
{ role: "option", id: `${m.id}-${name}-${i}`, class: "ws-menu-option", "data-value": o.value, "aria-selected": String(o === current) },
|
|
408
|
-
ICONS.check,
|
|
409
|
-
h("span", { class: "ws-menu-text" }, text(o.label)),
|
|
410
|
-
o.count != null && h("span", { class: "ws-menu-count" }, text(o.count))
|
|
411
|
-
));
|
|
412
|
-
return h(
|
|
413
|
-
"div",
|
|
414
|
-
{ class: "ws-menu", "data-ws-menu": name },
|
|
415
|
-
button,
|
|
416
|
-
h(
|
|
417
|
-
"div",
|
|
418
|
-
{ class: "ws-menu-pop", "data-ws-menu-pop": true, hidden: true },
|
|
419
|
-
search,
|
|
420
|
-
h("ul", { class: "ws-menu-list", role: "listbox", id: listId, "aria-label": m.label, tabindex: "-1", "data-ws-menu-list": true }, options),
|
|
421
|
-
h("p", { class: "ws-menu-none", "data-ws-menu-none": true, hidden: true }, text(m.noMatches))
|
|
422
|
-
)
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
function renderBpmMenu({ id, s, range }) {
|
|
426
|
-
const popId = `${id}-bpm-pop`;
|
|
427
|
-
const handle = (attr, label, value) => h("input", {
|
|
428
|
-
type: "range",
|
|
429
|
-
class: "ws-range-input",
|
|
430
|
-
[attr]: true,
|
|
431
|
-
"aria-label": label,
|
|
432
|
-
min: range.min,
|
|
433
|
-
max: range.max,
|
|
434
|
-
step: "1",
|
|
435
|
-
value
|
|
436
|
-
});
|
|
437
|
-
return h(
|
|
438
|
-
"div",
|
|
439
|
-
{ class: "ws-menu ws-menu--bpm", "data-ws-menu": "bpm" },
|
|
440
|
-
h(
|
|
441
|
-
"button",
|
|
442
|
-
{ type: "button", class: "ws-menu-btn", "data-ws-menu-btn": true, "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": popId },
|
|
443
|
-
h("span", { class: "ws-sr" }, text(`${s.bpm}: `)),
|
|
444
|
-
h("span", { class: "ws-menu-value", "data-ws-menu-value": true }, text(bpmLabel({}, range, s))),
|
|
445
|
-
ICONS.chevron
|
|
446
|
-
),
|
|
447
|
-
h(
|
|
448
|
-
"div",
|
|
449
|
-
{ class: "ws-menu-pop ws-bpm-pop", id: popId, role: "dialog", "aria-label": s.bpm, "data-ws-menu-pop": true, hidden: true },
|
|
450
|
-
h(
|
|
451
|
-
"div",
|
|
452
|
-
{ class: "ws-bpm-head" },
|
|
453
|
-
h("span", { class: "ws-bpm-readout", "data-ws-bpm-readout": true, "aria-live": "polite" }, text(fill(s.bpmRange, range))),
|
|
454
|
-
h("button", { type: "button", class: "ws-bpm-clear", "data-ws-bpm-clear": true }, text(s.anyBpm))
|
|
455
|
-
),
|
|
456
|
-
h(
|
|
457
|
-
"div",
|
|
458
|
-
{ class: "ws-range", "data-ws-bpm-range": true },
|
|
459
|
-
handle("data-ws-bpm-min", s.bpmMin, range.min),
|
|
460
|
-
handle("data-ws-bpm-max", s.bpmMax, range.max)
|
|
461
|
-
),
|
|
462
|
-
h("div", { class: "ws-range-ends", "aria-hidden": "true" }, h("span", {}, text(range.min)), h("span", {}, text(range.max)))
|
|
463
|
-
)
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
function renderLoopFilter(s) {
|
|
467
|
-
const button = (value, label) => h(
|
|
468
|
-
"button",
|
|
469
|
-
{ type: "button", class: "ws-seg-btn", "data-ws-loop-filter": value, "aria-pressed": String(value === "") },
|
|
470
|
-
h("span", {}, text(label))
|
|
471
|
-
);
|
|
472
|
-
return h(
|
|
473
|
-
"div",
|
|
474
|
-
{ class: "ws-seg", role: "group", "aria-label": s.loopFilter },
|
|
475
|
-
button("", s.all),
|
|
476
|
-
button("loop", s.loops),
|
|
477
|
-
button("one-shot", s.oneShots)
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
function renderLoopToggle(s, pressed) {
|
|
481
|
-
return h("button", { type: "button", class: "ws-loop", "data-ws-loop": true, "aria-pressed": String(pressed) }, ICONS.loop, h("span", {}, text(s.loop)));
|
|
482
|
-
}
|
|
483
|
-
function renderChip(value, label, count, pressed) {
|
|
484
|
-
return h(
|
|
485
|
-
"button",
|
|
486
|
-
{ type: "button", class: "ws-chip", "data-ws-type": value, "aria-pressed": String(pressed) },
|
|
487
|
-
h("span", { class: "ws-chip-label" }, text(label)),
|
|
488
|
-
" ",
|
|
489
|
-
h("span", { class: "ws-chip-count" }, text(count))
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
function renderToolbar(plan, { o, s, f, total, id }) {
|
|
493
|
-
const menu = (name, m) => renderMenu(name, { id, searchFrom: o.menuSearch, noMatches: s.noMatches, ...m });
|
|
494
|
-
const controls = [
|
|
495
|
-
plan.types === "menu" && menu("type", {
|
|
496
|
-
label: s.types,
|
|
497
|
-
value: "",
|
|
498
|
-
placeholder: s.findType,
|
|
499
|
-
options: [{ value: "", label: s.allTypes, count: total }, ...f.types.map((t) => ({ value: t.name, label: t.name, count: t.count }))]
|
|
500
|
-
}),
|
|
501
|
-
plan.key && menu("key", {
|
|
502
|
-
label: s.key,
|
|
503
|
-
value: "",
|
|
504
|
-
placeholder: s.findKey,
|
|
505
|
-
options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
|
|
506
|
-
}),
|
|
507
|
-
plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
|
|
508
|
-
plan.loops && renderLoopFilter(s),
|
|
509
|
-
plan.sorts.length > 0 && menu("sort", {
|
|
510
|
-
label: s.sort,
|
|
511
|
-
prefix: s.sortBy,
|
|
512
|
-
value: plan.sorts[0],
|
|
513
|
-
options: plan.sorts.map((k) => ({ value: k, label: s[SORT_LABEL_KEYS[k]] }))
|
|
514
|
-
}),
|
|
515
|
-
plan.loop && renderLoopToggle(s, loopsByDefault(o.loop, f))
|
|
516
|
-
].filter(Boolean);
|
|
517
|
-
const chips = plan.types === "chips" && h(
|
|
518
|
-
"div",
|
|
519
|
-
{ class: "ws-types", role: "group", "aria-label": s.types },
|
|
520
|
-
renderChip("", s.all, total, true),
|
|
521
|
-
f.types.map((t) => renderChip(t.name, t.name, t.count, false))
|
|
522
|
-
);
|
|
523
|
-
const count = plan.count && h("p", { class: "ws-count", "data-ws-count": true, "aria-live": "polite" }, text(countText(total, total, s)));
|
|
524
|
-
return h(
|
|
525
|
-
"div",
|
|
526
|
-
{ class: "ws-toolbar" },
|
|
527
|
-
plan.search && renderSearch(s),
|
|
528
|
-
controls.length > 0 && h("div", { class: "ws-controls" }, controls),
|
|
529
|
-
// The chips and the count share a row (the count alone without chips).
|
|
530
|
-
(chips || count) && h("div", { class: "ws-meta" }, chips, count)
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
var CELLS = {
|
|
534
|
-
type: (sound) => text(sound.type),
|
|
535
|
-
bpm: (sound) => text(sound.bpm ?? ""),
|
|
536
|
-
key: (sound) => text(sound.key),
|
|
537
|
-
duration: (sound) => text(formatDuration(sound.duration))
|
|
538
|
-
};
|
|
539
|
-
function renderRow(sound, index, o, hidden = false) {
|
|
540
|
-
const s = o.strings;
|
|
541
|
-
const vars = { title: sound.title };
|
|
542
|
-
const cells = o.columns.map((c) => h("span", { class: `ws-cell ws-${c}` }, CELLS[c](sound)));
|
|
543
|
-
return h(
|
|
544
|
-
"li",
|
|
545
|
-
{
|
|
546
|
-
class: "ws-row",
|
|
547
|
-
"data-ws-index": index,
|
|
548
|
-
"data-ws-id": sound.id,
|
|
549
|
-
"data-url": sound.url,
|
|
550
|
-
"data-title": sound.title,
|
|
551
|
-
"data-type": sound.type || null,
|
|
552
|
-
"data-bpm": sound.bpm,
|
|
553
|
-
"data-key": sound.key || null,
|
|
554
|
-
"data-duration": sound.duration,
|
|
555
|
-
"data-tags": sound.tags?.length ? sound.tags.join(",") : null,
|
|
556
|
-
"data-peaks": sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
557
|
-
"data-waveform": sound.waveform,
|
|
558
|
-
"data-download": sound.download,
|
|
559
|
-
"data-loop": sound.loop ? "true" : null,
|
|
560
|
-
hidden
|
|
561
|
-
},
|
|
562
|
-
h("button", { type: "button", class: "ws-play", "aria-pressed": "false", "aria-label": fill(s.play, vars) }, ICONS.play, ICONS.pause),
|
|
563
|
-
h(
|
|
564
|
-
"span",
|
|
565
|
-
{ class: "ws-cell ws-title" },
|
|
566
|
-
h("span", { class: "ws-title-text" }, text(sound.title)),
|
|
567
|
-
// A loop says so beside its name; a one-shot carries nothing.
|
|
568
|
-
sound.loop && h("span", { class: "ws-loop-mark", title: s.isLoop }, ICONS.loop, h("span", { class: "ws-sr" }, text(s.isLoop)))
|
|
569
|
-
),
|
|
570
|
-
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
571
|
-
// rows: one line under the title.
|
|
572
|
-
cells.length > 0 && h("span", { class: "ws-cells" }, cells),
|
|
573
|
-
o.player === "inline" && h(
|
|
574
|
-
"span",
|
|
575
|
-
{ class: "ws-wave", role: "slider", "aria-label": fill(s.seek, vars), "aria-valuemin": "0", "aria-valuemax": "100", "aria-valuenow": "0", tabindex: "-1" },
|
|
576
|
-
h("canvas", { class: "ws-canvas", "aria-hidden": "true" })
|
|
577
|
-
),
|
|
578
|
-
// Optional, per sound: a plain link. Rows without one carry nothing.
|
|
579
|
-
sound.download && h("a", { class: "ws-download", href: sound.download, download: true, "aria-label": fill(s.download, vars) }, ICONS.download)
|
|
580
|
-
);
|
|
581
|
-
}
|
|
582
|
-
function renderFooter({ o, s, total }) {
|
|
583
|
-
const page = o.pageSize > 0 ? o.pageSize : total;
|
|
584
|
-
const more = Math.max(0, total - page);
|
|
585
|
-
const strip = o.player === "strip";
|
|
586
|
-
return [
|
|
587
|
-
h(
|
|
588
|
-
"p",
|
|
589
|
-
{ class: "ws-empty", "data-ws-empty": true, hidden: true },
|
|
590
|
-
text(s.empty),
|
|
591
|
-
" ",
|
|
592
|
-
h("button", { type: "button", class: "ws-clear", "data-ws-clear": true }, text(s.clear))
|
|
593
|
-
),
|
|
594
|
-
h("button", { type: "button", class: "ws-more", "data-ws-more": true, hidden: more === 0 }, text(fill(s.showMore, { count: Math.min(more, page) }))),
|
|
595
|
-
h("div", { class: strip ? "ws-engine ws-engine--strip" : "ws-engine", "data-ws-engine": true, hidden: !strip }),
|
|
596
|
-
h("p", { class: "ws-sr", "data-ws-status": true, "aria-live": "polite" })
|
|
597
|
-
].join("");
|
|
598
|
-
}
|
|
599
|
-
function renderSounds(sounds, options = {}) {
|
|
600
|
-
const o = resolveRenderOptions(options);
|
|
601
|
-
const list = normalizeSounds(sounds);
|
|
602
|
-
const ctx = { o, s: o.strings, f: facets(list), total: list.length, id: o.idPrefix || idBase(list) };
|
|
603
|
-
const page = o.pageSize > 0 ? o.pageSize : Infinity;
|
|
604
|
-
return renderToolbar(toolbarPlan(ctx.f, o), ctx) + h(
|
|
605
|
-
"ul",
|
|
606
|
-
{ class: `ws-list ws-list--${o.player}`, role: "list", "data-ws-list": true },
|
|
607
|
-
list.map((sound, i) => renderRow(sound, i, o, i >= page))
|
|
608
|
-
) + renderFooter(ctx);
|
|
609
|
-
}
|
|
610
|
-
function renderSoundsElement(sounds, options = {}, className = "") {
|
|
611
|
-
const o = resolveRenderOptions(options);
|
|
612
|
-
const cls = ["waveform-sounds", `waveform-sounds--${o.player}`, className].filter(Boolean).join(" ");
|
|
613
|
-
return h("div", { class: cls, "data-waveform-sounds": true, "data-player": o.player }, renderSounds(sounds, options));
|
|
614
|
-
}
|