@arraypress/waveform-sounds 0.1.2 → 0.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 +16 -1
- package/dist/waveform-sounds-no-autoinit.cjs +74 -13
- package/dist/waveform-sounds-no-autoinit.esm.js +74 -13
- package/dist/waveform-sounds-render.cjs +40 -5
- package/dist/waveform-sounds-render.esm.js +40 -5
- package/dist/waveform-sounds.cjs +74 -13
- package/dist/waveform-sounds.css +40 -3
- package/dist/waveform-sounds.esm.js +74 -13
- package/dist/waveform-sounds.js +74 -13
- package/dist/waveform-sounds.min.css +1 -1
- package/dist/waveform-sounds.min.js +1 -1
- package/index.d.ts +20 -4
- package/package.json +1 -1
- package/src/css/waveform-sounds.css +40 -3
- package/src/js/core/WaveformSounds.js +22 -5
- package/src/js/data/sounds.js +39 -8
- package/src/js/data/url-state.js +11 -7
- package/src/js/dom/rows.js +1 -1
- package/src/js/render/markup.js +23 -5
- package/src/js/render/options.js +1 -1
- package/src/js/render/strings.js +4 -0
package/src/js/data/url-state.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* the runtime passes `location.search` / `location.href` in and calls
|
|
5
5
|
* `history.replaceState` with what comes out.
|
|
6
6
|
*
|
|
7
|
-
* ?q=bass&type=Bass+loops&key=Fm&bpm=120-130&sort=bpm
|
|
7
|
+
* ?q=bass&type=Bass+loops&key=Fm&bpm=120-130&loop=one-shot&sort=bpm
|
|
8
8
|
*
|
|
9
9
|
* @module url-state
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {normalizeKey} from './sounds.js';
|
|
12
|
+
import {LOOP_FILTERS, normalizeKey} from './sounds.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The parameter names, or null when urlState is off. A string urlState
|
|
@@ -17,12 +17,12 @@ import {normalizeKey} from './sounds.js';
|
|
|
17
17
|
* page don't share a filter.
|
|
18
18
|
*
|
|
19
19
|
* @param {boolean|string|null|undefined} urlState
|
|
20
|
-
* @returns {{q: string, type: string, key: string, bpm: string, sort: string}|null}
|
|
20
|
+
* @returns {{q: string, type: string, key: string, bpm: string, loop: string, sort: string}|null}
|
|
21
21
|
*/
|
|
22
22
|
export function urlKeys(urlState) {
|
|
23
23
|
if (!urlState) return null;
|
|
24
24
|
const p = typeof urlState === 'string' ? `${urlState}-` : '';
|
|
25
|
-
return {q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, sort: `${p}sort`};
|
|
25
|
+
return {q: `${p}q`, type: `${p}type`, key: `${p}key`, bpm: `${p}bpm`, loop: `${p}loop`, sort: `${p}sort`};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -50,13 +50,14 @@ export function formatBpmRange(min, max) {
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Read the filter and sort from a query string. Values the list can't use
|
|
53
|
-
* (a type it doesn't have, a key no sound is in, a
|
|
53
|
+
* (a type it doesn't have, a key no sound is in, a loops filter on a list
|
|
54
|
+
* that isn't a mix of loops and one-shots, a sort it doesn't offer)
|
|
54
55
|
* are ignored, never applied: a stale link shows the whole list, not an
|
|
55
56
|
* empty one.
|
|
56
57
|
*
|
|
57
58
|
* @param {string} search - `location.search`.
|
|
58
59
|
* @param {ReturnType<typeof urlKeys>} keys
|
|
59
|
-
* @param {{types: {name: string}[], keys: string[]}} available - From `facets()`.
|
|
60
|
+
* @param {{types: {name: string}[], keys: string[], loops?: number, oneShots?: number}} available - From `facets()`.
|
|
60
61
|
* @param {string[]} sorts - The sort orders offered.
|
|
61
62
|
* @returns {{filter: Object, sort: string|null}} A filter patch, and the sort (or null).
|
|
62
63
|
*/
|
|
@@ -72,6 +73,8 @@ export function readUrlState(search, keys, available, sorts) {
|
|
|
72
73
|
if (key && available.keys.includes(key)) out.filter.key = key;
|
|
73
74
|
const bpm = parseBpmRange(sp.get(keys.bpm));
|
|
74
75
|
if (bpm) Object.assign(out.filter, bpm);
|
|
76
|
+
const loop = sp.get(keys.loop);
|
|
77
|
+
if (LOOP_FILTERS.includes(loop) && available.loops > 0 && available.oneShots > 0) out.filter.loop = loop;
|
|
75
78
|
const sort = sp.get(keys.sort);
|
|
76
79
|
if (sort && sorts.includes(sort)) out.sort = sort;
|
|
77
80
|
return out;
|
|
@@ -84,7 +87,7 @@ export function readUrlState(search, keys, available, sorts) {
|
|
|
84
87
|
*
|
|
85
88
|
* @param {string} href - `location.href`.
|
|
86
89
|
* @param {ReturnType<typeof urlKeys>} keys
|
|
87
|
-
* @param {{query: string, type: string, key: string, bpmMin: string, bpmMax: string}} filter
|
|
90
|
+
* @param {{query: string, type: string, key: string, bpmMin: string, bpmMax: string, loop?: string}} filter
|
|
88
91
|
* @param {string} sort
|
|
89
92
|
* @param {string} defaultSort - The starting order (not written).
|
|
90
93
|
* @returns {string} The new href (equal to `href` when nothing changed).
|
|
@@ -97,6 +100,7 @@ export function writeUrlState(href, keys, filter, sort, defaultSort) {
|
|
|
97
100
|
set(keys.type, filter.type);
|
|
98
101
|
set(keys.key, filter.key);
|
|
99
102
|
set(keys.bpm, formatBpmRange(filter.bpmMin, filter.bpmMax));
|
|
103
|
+
set(keys.loop, filter.loop);
|
|
100
104
|
set(keys.sort, sort !== defaultSort ? sort : '');
|
|
101
105
|
return url.href;
|
|
102
106
|
}
|
package/src/js/dom/rows.js
CHANGED
|
@@ -27,7 +27,7 @@ export function readRows(list) {
|
|
|
27
27
|
const d = row.dataset;
|
|
28
28
|
const sound = normalizeSound({
|
|
29
29
|
id: d.wsId, url: d.url, title: d.title, type: d.type, bpm: d.bpm, key: d.key,
|
|
30
|
-
duration: d.duration, tags: d.tags, peaks: d.peaks, waveform: d.waveform, download: d.download,
|
|
30
|
+
duration: d.duration, tags: d.tags, peaks: d.peaks, waveform: d.waveform, download: d.download, loop: d.loop,
|
|
31
31
|
}, sounds.length);
|
|
32
32
|
if (!sound) { row.remove(); continue; }
|
|
33
33
|
row.dataset.wsIndex = String(sounds.length);
|
package/src/js/render/markup.js
CHANGED
|
@@ -41,13 +41,14 @@ export function idBase(sounds) {
|
|
|
41
41
|
/**
|
|
42
42
|
* Which controls the toolbar shows. Each appears only when it's enabled
|
|
43
43
|
* AND the data gives it something to do: no type filter for one type, no
|
|
44
|
-
* key menu for one key, no BPM range without a spread of BPMs, no
|
|
45
|
-
*
|
|
44
|
+
* key menu for one key, no BPM range without a spread of BPMs, no loops
|
|
45
|
+
* filter unless the list has both loops and one-shots, no sort menu with
|
|
46
|
+
* one usable order. Types past `maxTypeChips` become a menu (a
|
|
46
47
|
* pack has a handful; a whole library can have fifty).
|
|
47
48
|
*
|
|
48
49
|
* @param {ReturnType<typeof facets>} f - The sounds' facets.
|
|
49
50
|
* @param {ReturnType<typeof resolveRenderOptions>} o - Resolved options.
|
|
50
|
-
* @returns {{types: 'chips'|'menu'|null, key: boolean, bpm: boolean, sorts: string[], search: boolean, loop: boolean, count: boolean}}
|
|
51
|
+
* @returns {{types: 'chips'|'menu'|null, key: boolean, bpm: boolean, loops: boolean, sorts: string[], search: boolean, loop: boolean, count: boolean}}
|
|
51
52
|
*/
|
|
52
53
|
export function toolbarPlan(f, o) {
|
|
53
54
|
const typed = o.filters.includes('type') && f.types.length > 1;
|
|
@@ -56,6 +57,7 @@ export function toolbarPlan(f, o) {
|
|
|
56
57
|
types: !typed ? null : f.types.length > o.maxTypeChips ? 'menu' : 'chips',
|
|
57
58
|
key: o.filters.includes('key') && f.keys.length > 1,
|
|
58
59
|
bpm: o.filters.includes('bpm') && f.bpm !== null && f.bpm.max > f.bpm.min,
|
|
60
|
+
loops: o.filters.includes('loop') && f.loops > 0 && f.oneShots > 0,
|
|
59
61
|
sorts: sorts.length > 1 ? sorts : [],
|
|
60
62
|
search: !!o.search,
|
|
61
63
|
loop: !!o.loopToggle,
|
|
@@ -135,6 +137,16 @@ function renderBpmRange(s, range) {
|
|
|
135
137
|
);
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Loops or one-shots: three buttons, one pressed ('' = both).
|
|
142
|
+
*/
|
|
143
|
+
function renderLoopFilter(s) {
|
|
144
|
+
const button = (value, label) => h('button', {type: 'button', class: 'ws-seg-btn', 'data-ws-loop-filter': value, 'aria-pressed': String(value === '')},
|
|
145
|
+
h('span', {}, text(label)));
|
|
146
|
+
return h('div', {class: 'ws-seg', role: 'group', 'aria-label': s.loopFilter},
|
|
147
|
+
button('', s.all), button('loop', s.loops), button('one-shot', s.oneShots));
|
|
148
|
+
}
|
|
149
|
+
|
|
138
150
|
/** The Loop toggle. */
|
|
139
151
|
function renderLoopToggle(s) {
|
|
140
152
|
return h('button', {type: 'button', class: 'ws-loop', 'data-ws-loop': true, 'aria-pressed': 'false'}, ICONS.loop, h('span', {}, text(s.loop)));
|
|
@@ -148,7 +160,7 @@ function renderChip(value, label, count, pressed) {
|
|
|
148
160
|
|
|
149
161
|
/**
|
|
150
162
|
* The toolbar: search, the controls row (type menu, key menu, BPM range,
|
|
151
|
-
* sort menu, Loop) and the meta row (type chips + the count).
|
|
163
|
+
* loops or one-shots, sort menu, Loop) and the meta row (type chips + the count).
|
|
152
164
|
*
|
|
153
165
|
* @param {ReturnType<typeof toolbarPlan>} plan
|
|
154
166
|
* @param {Object} ctx - `{o, s, f, total, id}` from {@link renderSounds}.
|
|
@@ -166,6 +178,7 @@ function renderToolbar(plan, {o, s, f, total, id}) {
|
|
|
166
178
|
options: [{value: '', label: s.anyKey}, ...f.keys.map((k) => ({value: k, label: k}))],
|
|
167
179
|
}),
|
|
168
180
|
plan.bpm && renderBpmRange(s, f.bpm),
|
|
181
|
+
plan.loops && renderLoopFilter(s),
|
|
169
182
|
plan.sorts.length > 0 && menu('sort', {
|
|
170
183
|
label: s.sort, prefix: s.sortBy, value: plan.sorts[0],
|
|
171
184
|
options: plan.sorts.map((k) => ({value: k, label: s[SORT_LABEL_KEYS[k]]})),
|
|
@@ -228,10 +241,15 @@ export function renderRow(sound, index, o, hidden = false) {
|
|
|
228
241
|
'data-peaks': sound.peaks ? encodePeaks(sound.peaks) : null,
|
|
229
242
|
'data-waveform': sound.waveform,
|
|
230
243
|
'data-download': sound.download,
|
|
244
|
+
'data-loop': sound.loop ? 'true' : null,
|
|
231
245
|
hidden,
|
|
232
246
|
},
|
|
233
247
|
h('button', {type: 'button', class: 'ws-play', 'aria-pressed': 'false', 'aria-label': fill(s.play, vars)}, ICONS.play, ICONS.pause),
|
|
234
|
-
h('span', {class: 'ws-cell ws-title'},
|
|
248
|
+
h('span', {class: 'ws-cell ws-title'},
|
|
249
|
+
h('span', {class: 'ws-title-text'}, text(sound.title)),
|
|
250
|
+
// A loop says so beside its name; a one-shot carries nothing.
|
|
251
|
+
sound.loop && h('span', {class: 'ws-loop-mark', title: s.isLoop}, ICONS.loop, h('span', {class: 'ws-sr'}, text(s.isLoop))),
|
|
252
|
+
),
|
|
235
253
|
// Wide rows: `display: contents` makes each cell a column. Narrow
|
|
236
254
|
// rows: one line under the title.
|
|
237
255
|
cells.length > 0 && h('span', {class: 'ws-cells'}, cells),
|
package/src/js/render/options.js
CHANGED
|
@@ -10,7 +10,7 @@ import {SORTS} from '../data/sounds.js';
|
|
|
10
10
|
import {DEFAULT_STRINGS} from './strings.js';
|
|
11
11
|
|
|
12
12
|
/** The filter controls a list can offer. */
|
|
13
|
-
export const FILTERS = ['type', 'key', 'bpm'];
|
|
13
|
+
export const FILTERS = ['type', 'key', 'bpm', 'loop'];
|
|
14
14
|
|
|
15
15
|
/** The columns a row can show after its title. */
|
|
16
16
|
export const COLUMNS = ['type', 'bpm', 'key', 'duration'];
|
package/src/js/render/strings.js
CHANGED
|
@@ -29,6 +29,10 @@ export const DEFAULT_STRINGS = {
|
|
|
29
29
|
sortKey: 'Key',
|
|
30
30
|
sortDuration: 'Length',
|
|
31
31
|
loop: 'Loop',
|
|
32
|
+
loopFilter: 'Loops or one-shots',
|
|
33
|
+
loops: 'Loops',
|
|
34
|
+
oneShots: 'One-shots',
|
|
35
|
+
isLoop: 'Loop',
|
|
32
36
|
play: 'Play {title}',
|
|
33
37
|
pause: 'Pause {title}',
|
|
34
38
|
seek: 'Seek {title}',
|