@arraypress/waveform-sounds 2.0.0 → 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.
Files changed (75) hide show
  1. package/README.md +24 -2
  2. package/dist/waveform-sounds-no-autoinit.esm.js +495 -90
  3. package/dist/waveform-sounds-render.esm.js +55 -5
  4. package/dist/waveform-sounds.css +88 -17
  5. package/dist/waveform-sounds.esm.js +498 -92
  6. package/dist/waveform-sounds.js +494 -92
  7. package/dist/waveform-sounds.min.css +1 -1
  8. package/dist/waveform-sounds.min.js +3 -3
  9. package/package.json +1 -1
  10. package/src/css/waveform-sounds.css +88 -17
  11. package/src/js/core/WaveformSounds.ts +350 -87
  12. package/src/js/core/element.ts +208 -0
  13. package/src/js/core/engine.ts +9 -3
  14. package/src/js/core/options.ts +0 -5
  15. package/src/js/data/bpm.ts +14 -4
  16. package/src/js/data/navigation.ts +16 -3
  17. package/src/js/data/sounds.ts +44 -14
  18. package/src/js/data/url-state.ts +33 -10
  19. package/src/js/dom/colors.ts +28 -1
  20. package/src/js/dom/draw.ts +0 -1
  21. package/src/js/dom/menus.ts +0 -2
  22. package/src/js/dom/rows.ts +0 -3
  23. package/src/js/entry.ts +13 -3
  24. package/src/js/index.ts +7 -3
  25. package/src/js/render/html.ts +0 -2
  26. package/src/js/render/icons.ts +0 -1
  27. package/src/js/render/markup.ts +41 -13
  28. package/src/js/render/options.ts +26 -4
  29. package/src/js/render/strings.ts +4 -3
  30. package/src/js/render-entry.ts +1 -1
  31. package/src/js/shared/utils.ts +4 -4
  32. package/src/js/types.ts +30 -3
  33. package/types/core/WaveformSounds.d.ts +40 -10
  34. package/types/core/WaveformSounds.d.ts.map +1 -1
  35. package/types/core/element.d.ts +84 -0
  36. package/types/core/element.d.ts.map +1 -0
  37. package/types/core/engine.d.ts +8 -3
  38. package/types/core/engine.d.ts.map +1 -1
  39. package/types/core/options.d.ts +0 -5
  40. package/types/core/options.d.ts.map +1 -1
  41. package/types/data/bpm.d.ts +17 -4
  42. package/types/data/bpm.d.ts.map +1 -1
  43. package/types/data/navigation.d.ts +11 -2
  44. package/types/data/navigation.d.ts.map +1 -1
  45. package/types/data/sounds.d.ts +13 -12
  46. package/types/data/sounds.d.ts.map +1 -1
  47. package/types/data/url-state.d.ts +32 -6
  48. package/types/data/url-state.d.ts.map +1 -1
  49. package/types/dom/colors.d.ts +13 -0
  50. package/types/dom/colors.d.ts.map +1 -1
  51. package/types/dom/draw.d.ts +0 -1
  52. package/types/dom/draw.d.ts.map +1 -1
  53. package/types/dom/menus.d.ts +0 -2
  54. package/types/dom/menus.d.ts.map +1 -1
  55. package/types/dom/rows.d.ts +0 -3
  56. package/types/dom/rows.d.ts.map +1 -1
  57. package/types/entry.d.ts +10 -4
  58. package/types/entry.d.ts.map +1 -1
  59. package/types/index.d.ts +2 -2
  60. package/types/index.d.ts.map +1 -1
  61. package/types/render/html.d.ts +0 -2
  62. package/types/render/html.d.ts.map +1 -1
  63. package/types/render/icons.d.ts.map +1 -1
  64. package/types/render/markup.d.ts +17 -8
  65. package/types/render/markup.d.ts.map +1 -1
  66. package/types/render/options.d.ts +17 -4
  67. package/types/render/options.d.ts.map +1 -1
  68. package/types/render/strings.d.ts +0 -3
  69. package/types/render/strings.d.ts.map +1 -1
  70. package/types/render-entry.d.ts +1 -1
  71. package/types/render-entry.d.ts.map +1 -1
  72. package/types/shared/utils.d.ts +3 -3
  73. package/types/shared/utils.d.ts.map +1 -1
  74. package/types/types.d.ts +29 -3
  75. package/types/types.d.ts.map +1 -1
@@ -35,12 +35,25 @@ function encodePeaks(peaks) {
35
35
  }
36
36
  return out;
37
37
  }
38
+ var COMPACT_PREFIX = "wp1:";
39
+ function decodeCompact(body) {
40
+ if (!body || !/^[\w-]+$/.test(body) || body.length % 4 === 1) return null;
41
+ try {
42
+ const bytes = atob(body.replace(/-/g, "+").replace(/_/g, "/"));
43
+ const out = new Array(bytes.length);
44
+ for (let i = 0; i < bytes.length; i++) out[i] = bytes.charCodeAt(i) / 255;
45
+ return out;
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
38
50
  function decodePeaks(value, scale = 1) {
39
51
  if (value == null || value === "") return null;
40
52
  if (typeof value === "string") {
53
+ if (value.startsWith(COMPACT_PREFIX)) return decodeCompact(value.slice(COMPACT_PREFIX.length));
41
54
  if (!/^[0-9a-f]+$/i.test(value) || value.length % 2) return null;
42
55
  const out2 = new Array(value.length / 2);
43
- for (let i = 0; i < out2.length; i++) out2[i] = parseInt(value.substr(i * 2, 2), 16) / 255;
56
+ for (let i = 0; i < out2.length; i++) out2[i] = parseInt(value.slice(i * 2, i * 2 + 2), 16) / 255;
44
57
  return out2;
45
58
  }
46
59
  if (!Array.isArray(value)) return null;
@@ -79,8 +92,8 @@ function parseDuration(value) {
79
92
  if (typeof value === "number") return Number.isFinite(value) && value >= 0 ? value : null;
80
93
  const str = String(value).trim();
81
94
  if (/^\d+(\.\d+)?$/.test(str)) return Number(str);
95
+ if (!/^\d+(\.\d+)?(:\d+(\.\d+)?)+$/.test(str)) return null;
82
96
  const parts = str.split(":").map(Number);
83
- if (parts.length < 2 || parts.some((n) => !Number.isFinite(n))) return null;
84
97
  return parts.reduce((acc, n) => acc * 60 + n, 0);
85
98
  }
86
99
  function titleFromUrl(url) {
@@ -203,6 +216,9 @@ var ICONS = {
203
216
  };
204
217
 
205
218
  // src/js/data/bpm.ts
219
+ function bpmExtent(range) {
220
+ return range ? { min: Math.floor(range.min), max: Math.ceil(range.max) } : null;
221
+ }
206
222
  function bpmRangeFromFilter(filter, extent) {
207
223
  const read = (v, fallback) => {
208
224
  const n = Number(v);
@@ -248,6 +264,7 @@ var DEFAULT_STRINGS = {
248
264
  play: "Play {title}",
249
265
  pause: "Pause {title}",
250
266
  seek: "Seek {title}",
267
+ seekValue: "{time} of {duration}",
251
268
  download: "Download {title}",
252
269
  count: "{count} sounds",
253
270
  countOne: "1 sound",
@@ -255,7 +272,10 @@ var DEFAULT_STRINGS = {
255
272
  showMore: "Show {count} more",
256
273
  empty: "No sounds match.",
257
274
  clear: "Clear filters",
258
- nowPlaying: "Playing {title}"
275
+ nowPlaying: "Playing {title}",
276
+ playError: "Could not play {title}",
277
+ loadError: "Could not load the sounds.",
278
+ noSounds: "No sounds."
259
279
  };
260
280
  var SORT_LABEL_KEYS = {
261
281
  default: "sortDefault",
@@ -292,6 +312,15 @@ var RENDER_DEFAULTS = {
292
312
  columns: [...COLUMNS],
293
313
  maxTypeChips: 10
294
314
  };
315
+ var RENDER_OPTION_KEYS = [...Object.keys(RENDER_DEFAULTS), "idPrefix", "loop", "strings"];
316
+ function pickRenderOptions(options) {
317
+ const out = {};
318
+ for (const key of RENDER_OPTION_KEYS) {
319
+ const value = options?.[key];
320
+ if (value != null) out[key] = value;
321
+ }
322
+ return out;
323
+ }
295
324
  function defined(obj) {
296
325
  const out = {};
297
326
  for (const k in obj ?? {}) if (obj[k] !== void 0) out[k] = obj[k];
@@ -483,7 +512,7 @@ function renderToolbar(plan, { o, s, f, total, id }) {
483
512
  placeholder: s.findKey,
484
513
  options: [{ value: "", label: s.anyKey }, ...f.keys.map((k) => ({ value: k, label: k }))]
485
514
  }),
486
- plan.bpm && renderBpmMenu({ id, s, range: f.bpm }),
515
+ plan.bpm && renderBpmMenu({ id, s, range: bpmExtent(f.bpm) }),
487
516
  plan.loops && renderLoopFilter(s),
488
517
  plan.sorts.length > 0 && menu("sort", {
489
518
  label: s.sort,
@@ -586,13 +615,33 @@ function renderSounds(sounds, options = {}) {
586
615
  list.map((sound, i) => renderRow(sound, i, o, i >= page))
587
616
  ) + renderFooter(ctx);
588
617
  }
618
+ function renderOptionAttributes(options = {}) {
619
+ const set = pickRenderOptions(options);
620
+ const o = resolveRenderOptions(options);
621
+ const out = {};
622
+ for (const key of RENDER_OPTION_KEYS) {
623
+ if (key === "player" || !(key in set)) continue;
624
+ const name = `data-${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
625
+ if (key === "strings") {
626
+ const strings = defined(set.strings);
627
+ if (Object.keys(strings).length) out[name] = JSON.stringify(strings);
628
+ } else if (key === "loop" || key === "idPrefix") {
629
+ out[name] = String(set[key]);
630
+ } else {
631
+ const value = o[key];
632
+ out[name] = Array.isArray(value) ? value.join(",") : String(value);
633
+ }
634
+ }
635
+ return out;
636
+ }
589
637
  function renderSoundsElement(sounds, options = {}, className = "") {
590
638
  const o = resolveRenderOptions(options);
591
639
  const cls = ["waveform-sounds", `waveform-sounds--${o.player}`, className].filter(Boolean).join(" ");
592
- return h("div", { class: cls, "data-waveform-sounds": true, "data-player": o.player }, renderSounds(sounds, options));
640
+ return h("div", { class: cls, "data-waveform-sounds": true, "data-player": o.player, ...renderOptionAttributes(options) }, renderSounds(sounds, options));
593
641
  }
594
642
  export {
595
643
  DEFAULT_STRINGS,
644
+ RENDER_OPTION_KEYS,
596
645
  decodePeaks,
597
646
  encodePeaks,
598
647
  escapeHtml,
@@ -601,6 +650,7 @@ export {
601
650
  normalizeKey,
602
651
  normalizeSounds,
603
652
  parseManifest,
653
+ pickRenderOptions,
604
654
  renderSounds,
605
655
  renderSoundsElement
606
656
  };
@@ -15,12 +15,21 @@
15
15
  * canvas can't use CSS, so the runtime resolves them, and re-reads them
16
16
  * when the page theme flips).
17
17
  */
18
+ /* <waveform-sounds>: a block, like the <div data-waveform-sounds> form (a
19
+ * custom element is inline by default), and styled as one from the first
20
+ * paint: the container rules below name the tag as well as the class, so
21
+ * server-rendered markup inside it doesn't shift when it upgrades. Before
22
+ * the script defines it, an EMPTY element (a manifest still to load) holds
23
+ * --ws-element-height, if you set one. */
24
+ waveform-sounds { display: block; }
25
+ waveform-sounds:not(:defined):empty { min-height: var(--ws-element-height, 0); }
26
+
18
27
  /* THE ONE RULE for the inverted states: an element whose background is
19
28
  * `var(--ws-accent)` never sets its own `color` — its CHILDREN take the
20
29
  * ink. `--ws-accent` defaults to `currentColor`, which resolves where it's
21
30
  * used (even registered with @property: Chrome keeps the keyword), so a
22
31
  * button with `color: ink; background: currentColor` paints ink on ink. */
23
- .waveform-sounds {
32
+ :is(.waveform-sounds, waveform-sounds) {
24
33
  --ws-accent: currentColor;
25
34
  /* The ink on an inverted fill: the page surface (set by you, or
26
35
  * measured by the runtime), else the INVERSE of the text colour — right
@@ -43,16 +52,27 @@
43
52
  color: inherit;
44
53
  font: inherit;
45
54
  }
46
- /* The inverse above is relative colour: Chrome 122, Firefox 128, Safari 18,
47
- * all newer than the 2.0 floor. Where it's invalid, until the runtime
48
- * measures --ws-surface (a server-rendered first paint, or no script), the
49
- * ink would be the text colour on a text-colour fill: use the system
50
- * background instead, as the dropdowns do. */
51
- @supports not (color: rgb(from red calc(255 - r) calc(255 - g) calc(255 - b))) {
52
- .waveform-sounds { --ws-on-accent: var(--ws-surface, Canvas); }
55
+ /* The inverse above is relative colour FROM currentColor: Chrome 131,
56
+ * Firefox 133, Safari 18, all newer than the 2.0 floor. Chrome 119–130
57
+ * parse relative colour, but not from currentColor, so the guard names it;
58
+ * Firefox 128–132 parse it but resolve currentColor as black (white ink on
59
+ * a light fill), so they are named too: Firefox (-moz-appearance) without
60
+ * a feature of its 133 (letter-spacing in %). Where it's unusable the ink
61
+ * is the surface the runtime measures. Until it has
62
+ * (a server-rendered first paint, or no script — the runtime sets
63
+ * data-ws-initialized as it measures), there is no ink that is right on
64
+ * every page (the system Canvas is white on a dark page that doesn't declare
65
+ * color-scheme), so a pressed control is a TINT with text-colour ink
66
+ * instead of an inversion: readable on any page. */
67
+ @supports (not (color: rgb(from currentColor r g b))) or ((-moz-appearance: none) and (not (letter-spacing: 1%))) {
68
+ :is(.waveform-sounds, waveform-sounds) { --ws-on-accent: var(--ws-surface, Canvas); }
69
+ :is(.waveform-sounds, waveform-sounds):where(:not([data-ws-initialized])) {
70
+ --ws-accent-fill: color-mix(in srgb, currentColor 22%, transparent);
71
+ --ws-on-accent: currentColor;
72
+ }
53
73
  }
54
- .waveform-sounds *, .waveform-sounds *::before, .waveform-sounds *::after { box-sizing: border-box; }
55
- .waveform-sounds [hidden] { display: none !important; }
74
+ :is(.waveform-sounds, waveform-sounds) *, :is(.waveform-sounds, waveform-sounds) *::before, :is(.waveform-sounds, waveform-sounds) *::after { box-sizing: border-box; }
75
+ :is(.waveform-sounds, waveform-sounds) [hidden] { display: none !important; }
56
76
 
57
77
  .ws-sr {
58
78
  position: absolute !important;
@@ -99,7 +119,8 @@
99
119
  color: inherit;
100
120
  cursor: text;
101
121
  }
102
- .ws-search:focus-within { border-color: var(--ws-accent); }
122
+ /* The focus ring is the field's frame, not the bare input inside it. */
123
+ .ws-search:focus-within { border-color: var(--ws-accent); outline: 2px solid var(--ws-accent); outline-offset: 2px; }
103
124
  .ws-search-input {
104
125
  flex: 1;
105
126
  min-width: 0;
@@ -108,8 +129,8 @@
108
129
  background: none;
109
130
  color: inherit;
110
131
  font: inherit;
111
- outline: none;
112
132
  }
133
+ .ws-search-input:focus { outline: none; } /* the frame above carries the ring */
113
134
  .ws-search .ws-icon, .ws-search-input::placeholder { color: var(--ws-muted); }
114
135
  /* WebKit/Blink's clear button, redrawn in the text colour. The mask stays
115
136
  * prefixed: unprefixed `mask` is Chrome/Edge 120+. */
@@ -172,9 +193,9 @@
172
193
  color: inherit;
173
194
  font: inherit;
174
195
  font-size: 0.9em;
175
- outline: none;
176
196
  }
177
197
  .ws-menu-search:focus { border-color: var(--ws-accent); }
198
+ .ws-menu-search:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 1px; }
178
199
  .ws-menu-list { list-style: none; margin: 0; padding: 0; max-height: 18rem; overflow-y: auto; outline: none; }
179
200
  .ws-menu-option {
180
201
  display: flex;
@@ -198,7 +219,21 @@
198
219
  .ws-bpm-pop { width: 17rem; padding: 0.85rem 1rem 0.7rem; }
199
220
  .ws-bpm-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.6rem; }
200
221
  .ws-bpm-readout { font-weight: 600; font-variant-numeric: tabular-nums; }
201
- .ws-bpm-clear { padding: 0; border: 0; color: var(--ws-muted); font-size: 0.85em; }
222
+ .ws-bpm-clear {
223
+ /* A 24px target (WCAG 2.5.8) without growing the head. */
224
+ display: inline-flex;
225
+ align-items: center;
226
+ justify-content: center;
227
+ min-width: 24px;
228
+ min-height: 24px;
229
+ margin: -2px -0.3rem -2px 0;
230
+ padding: 0 0.3rem;
231
+ border: 0;
232
+ border-radius: 4px;
233
+ color: var(--ws-muted);
234
+ font-size: 0.85em;
235
+ }
236
+ .ws-bpm-clear:focus-visible { outline: 2px solid var(--ws-accent); outline-offset: 0; }
202
237
  .ws-bpm-clear:hover { color: inherit; text-decoration: underline; }
203
238
 
204
239
  /* Two native range inputs stacked on one track. The track and the filled
@@ -331,9 +366,11 @@
331
366
  /* ── The pressed controls: the accent fill, inverted ink ─────────────── */
332
367
  /* After the hovers, so a pressed control keeps its fill under the pointer.
333
368
  * The CHILDREN take the ink, never the button (THE ONE RULE, at the top). */
369
+ /* `--ws-accent-fill` is unset, except for a tint before the runtime has
370
+ * measured the surface in engines without relative colour (top of file). */
334
371
  .ws-loop[aria-pressed='true'],
335
- .ws-chip[aria-pressed='true'] { border-color: var(--ws-accent); background: var(--ws-accent); }
336
- .ws-seg-btn[aria-pressed='true'] { background: var(--ws-accent); }
372
+ .ws-chip[aria-pressed='true'] { border-color: var(--ws-accent); background: var(--ws-accent-fill, var(--ws-accent)); }
373
+ .ws-seg-btn[aria-pressed='true'] { background: var(--ws-accent-fill, var(--ws-accent)); }
337
374
  .ws-loop[aria-pressed='true'] > *,
338
375
  .ws-seg-btn[aria-pressed='true'] > *,
339
376
  .ws-chip[aria-pressed='true'] > * { color: var(--ws-on-accent); }
@@ -380,7 +417,7 @@
380
417
  transition: background 0.15s, color 0.15s;
381
418
  }
382
419
  .ws-row:hover .ws-play { background: color-mix(in srgb, currentColor 12%, transparent); }
383
- .ws-row.is-current .ws-play { background: var(--ws-accent); }
420
+ .ws-row.is-current .ws-play { background: var(--ws-accent-fill, var(--ws-accent)); }
384
421
  .ws-row.is-current .ws-play > * { color: var(--ws-on-accent); }
385
422
  .ws-play .ws-icon-pause { display: none; }
386
423
  .ws-row.is-playing .ws-play .ws-icon-play { display: none; }
@@ -452,6 +489,13 @@
452
489
  .ws-cells > .ws-cell:not(:empty) ~ .ws-cell:not(:empty)::before { content: '·'; margin-right: 0.5rem; opacity: 0.6; }
453
490
  .ws-wave { grid-area: wave; margin-top: 0.35rem; min-width: 0; }
454
491
  .ws-download { grid-area: dl; align-self: start; }
492
+ /* The menus open from the controls row, never wider than it: anchored
493
+ to their own button, a wide panel (the BPM range) near the end of a
494
+ phone-width row hung off the screen's edge. */
495
+ .ws-controls { position: relative; }
496
+ .ws-menu { position: static; }
497
+ .ws-menu-pop { min-width: min(14rem, 100%); max-width: 100%; }
498
+ .ws-bpm-pop { width: min(17rem, 100%); }
455
499
  }
456
500
 
457
501
  /* ── Footer bits ─────────────────────────────────────────────────────── */
@@ -486,6 +530,33 @@
486
530
  .ws-menu-option { padding: 0.75rem 0.6rem; }
487
531
  }
488
532
 
533
+ /* Forced colours (Windows High Contrast): the pressed states and the
534
+ * playing row's button are the system Highlight, with their icons in
535
+ * HighlightText (left to the system, the inverted ink vanished into the
536
+ * forced background); the BPM track and thumb are drawn in system colours,
537
+ * and focus is an outline, never only a box-shadow (which is dropped). The
538
+ * canvases follow too: the runtime draws them in CanvasText / Highlight. */
539
+ @media (forced-colors: active) {
540
+ .ws-loop[aria-pressed='true'],
541
+ .ws-chip[aria-pressed='true'],
542
+ .ws-seg-btn[aria-pressed='true'],
543
+ .ws-row.is-current .ws-play {
544
+ forced-color-adjust: none;
545
+ border-color: Highlight;
546
+ background: Highlight;
547
+ color: HighlightText;
548
+ }
549
+ .ws-loop[aria-pressed='true'] > *,
550
+ .ws-seg-btn[aria-pressed='true'] > *,
551
+ .ws-chip[aria-pressed='true'] > *,
552
+ .ws-row.is-current .ws-play > * { color: HighlightText; }
553
+ .ws-range::before, .ws-range::after { forced-color-adjust: none; }
554
+ .ws-range::before { background: GrayText; }
555
+ .ws-range::after { background: Highlight; }
556
+ .ws-range-input:focus-visible { outline: 2px solid Highlight; outline-offset: 2px; }
557
+ .ws-menu-option.is-active { outline: 2px solid Highlight; }
558
+ }
559
+
489
560
  @media (prefers-reduced-motion: reduce) {
490
561
  .ws-row, .ws-chip, .ws-play, .ws-seg-btn, .ws-download, .ws-menu-chevron { transition: none; }
491
562
  }