@scalemule/nextjs 0.1.54 → 0.1.56

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/dist/audio.css CHANGED
@@ -226,7 +226,8 @@
226
226
  }
227
227
 
228
228
  /* src/components/network-audio-player.css */
229
- .sm-network-player {
229
+ .sm-network-player,
230
+ .sm-network-article {
230
231
  --sm-player-paper: #fff;
231
232
  --sm-player-ink: #203b30;
232
233
  --sm-player-muted: #52675c;
@@ -235,57 +236,83 @@
235
236
  --sm-player-soft: #f2f6f3;
236
237
  box-sizing: border-box;
237
238
  color: var(--sm-player-ink);
238
- background: var(--sm-player-paper);
239
- border-top: 2px solid var(--sm-player-accent);
240
- padding: 16px max(20px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
241
- font: 400 14px/1.45 var(--font-inter, system-ui), sans-serif;
239
+ font: 400 14px/1.45 var(--sm-player-sans, var(--font-inter, system-ui)), sans-serif;
242
240
  color-scheme: light;
243
241
  }
244
242
  .sm-network-player *,
245
243
  .sm-network-article * {
246
244
  box-sizing: border-box;
247
245
  }
246
+ .sm-network-player {
247
+ background: var(--sm-player-paper);
248
+ border-top: 1px solid var(--sm-player-line);
249
+ padding: 16px max(20px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
250
+ }
248
251
  .sm-network-player--fixed {
249
252
  position: fixed;
250
253
  z-index: var(--sm-player-z-index, 100);
251
254
  inset: auto 0 0;
252
- box-shadow: 0 -5px 24px #203b3010;
255
+ box-shadow: 0 -8px 32px #203b3010;
253
256
  }
254
257
  .sm-network-player button,
255
258
  .sm-network-player select,
256
259
  .sm-network-article button {
260
+ display: inline-flex;
261
+ align-items: center;
262
+ justify-content: center;
263
+ gap: 8px;
257
264
  color: inherit;
258
265
  font: inherit;
259
- border: 1px solid var(--sm-player-line, #d4ddd6);
266
+ border: 1px solid var(--sm-player-line);
260
267
  background: transparent;
261
268
  min-height: 44px;
262
- border-radius: 6px;
269
+ border-radius: 10px;
263
270
  padding: 8px 12px;
264
271
  cursor: pointer;
265
272
  touch-action: manipulation;
273
+ transition:
274
+ background-color 160ms ease,
275
+ color 160ms ease,
276
+ border-color 160ms ease;
266
277
  }
267
278
  .sm-network-player button:disabled,
268
279
  .sm-network-article button:disabled {
269
- opacity: .5;
280
+ opacity: .45;
270
281
  cursor: default;
271
282
  }
272
283
  .sm-network-player :is(button, a, input, select):focus-visible,
273
284
  .sm-network-article button:focus-visible {
274
- outline: 3px solid var(--sm-player-accent, #246346);
285
+ outline: 3px solid var(--sm-player-accent);
275
286
  outline-offset: 3px;
276
287
  }
277
288
  .sm-network-player button:hover:not(:disabled),
278
289
  .sm-network-article button:hover:not(:disabled) {
279
- background: var(--sm-player-soft, #f2f6f3);
290
+ background: var(--sm-player-soft);
291
+ }
292
+ .sm-network-icon {
293
+ display: block;
294
+ width: 20px;
295
+ height: 20px;
296
+ flex: 0 0 20px;
280
297
  }
281
298
  .sm-network-player__row {
299
+ position: relative;
282
300
  display: flex;
283
301
  align-items: center;
284
- gap: 18px;
302
+ gap: 20px;
285
303
  max-width: 1320px;
286
304
  margin: auto;
287
305
  }
288
- .sm-network-player .sm-network-player__play {
306
+ .sm-network-player .sm-network-player__close {
307
+ flex: 0 0 44px;
308
+ width: 44px;
309
+ height: 44px;
310
+ padding: 0;
311
+ border-color: transparent;
312
+ color: var(--sm-player-muted);
313
+ }
314
+ .sm-network-player .sm-network-player__play,
315
+ .sm-network-article__disc {
289
316
  width: 48px;
290
317
  height: 48px;
291
318
  flex: 0 0 48px;
@@ -299,52 +326,148 @@
299
326
  .sm-network-player .sm-network-player__play:hover {
300
327
  background: var(--sm-player-ink);
301
328
  }
302
- .sm-network-player__play svg {
303
- width: 22px;
304
- height: 22px;
305
- fill: currentColor;
329
+ .sm-network-player__play .sm-network-icon,
330
+ .sm-network-article__disc .sm-network-icon {
331
+ width: 24px;
332
+ height: 24px;
306
333
  }
307
334
  .sm-network-player__story {
308
335
  min-width: 0;
309
- flex: 1 1 340px;
336
+ flex: 1 1 320px;
310
337
  }
311
338
  .sm-network-player__story a {
312
339
  display: block;
313
340
  overflow: hidden;
314
341
  text-overflow: ellipsis;
315
342
  white-space: nowrap;
316
- font: 600 19px/1.3 var(--font-editorial, Georgia), serif;
343
+ font: 600 18px/1.4 var(--sm-player-serif, var(--font-editorial, Georgia)), serif;
317
344
  color: inherit;
318
345
  text-decoration: none;
319
346
  }
320
347
  .sm-network-player__story a:hover {
321
348
  text-decoration: underline;
349
+ text-underline-offset: 3px;
322
350
  }
323
351
  .sm-network-player__story :is(span, small) {
352
+ display: block;
324
353
  color: var(--sm-player-muted);
325
- font-size: 12px;
354
+ font-size: 11px;
326
355
  }
327
356
  .sm-network-player__timeline {
328
- flex: 1 1 260px;
329
- min-width: 160px;
357
+ flex: 1 1 220px;
358
+ max-width: 300px;
359
+ min-width: 120px;
330
360
  }
331
361
  .sm-network-player input[type=range] {
332
362
  accent-color: var(--sm-player-accent);
333
363
  cursor: pointer;
334
364
  min-height: 24px;
335
365
  }
336
- .sm-network-player__timeline input {
366
+ .sm-network-player__timeline input[type=range] {
367
+ appearance: none;
337
368
  display: block;
338
369
  width: 100%;
370
+ height: 24px;
339
371
  margin: 0;
372
+ background: transparent;
373
+ }
374
+ .sm-network-player__timeline input::-webkit-slider-runnable-track {
375
+ height: 4px;
376
+ border-radius: 4px;
377
+ background:
378
+ linear-gradient(
379
+ to right,
380
+ var(--sm-player-accent) var(--sm-progress, 0%),
381
+ var(--sm-player-line) var(--sm-progress, 0%));
382
+ }
383
+ .sm-network-player__timeline input::-moz-range-track {
384
+ height: 4px;
385
+ border-radius: 4px;
386
+ background: var(--sm-player-line);
387
+ }
388
+ .sm-network-player__timeline input::-moz-range-progress {
389
+ height: 4px;
390
+ border-radius: 4px;
391
+ background: var(--sm-player-accent);
392
+ }
393
+ .sm-network-player__timeline input::-webkit-slider-thumb {
394
+ appearance: none;
395
+ width: 12px;
396
+ height: 12px;
397
+ border-radius: 50%;
398
+ border: 2px solid var(--sm-player-paper);
399
+ background: var(--sm-player-accent);
400
+ box-shadow: 0 0 0 1px var(--sm-player-accent);
401
+ margin-top: -4px;
402
+ }
403
+ .sm-network-player__timeline input::-moz-range-thumb {
404
+ width: 8px;
405
+ height: 8px;
406
+ border-radius: 50%;
407
+ border: 2px solid var(--sm-player-paper);
408
+ background: var(--sm-player-accent);
409
+ box-shadow: 0 0 0 1px var(--sm-player-accent);
340
410
  }
341
411
  .sm-network-player__timeline div {
342
412
  display: flex;
343
413
  justify-content: space-between;
414
+ gap: 8px;
344
415
  color: var(--sm-player-muted);
416
+ font-size: 11px;
417
+ font-variant-numeric: tabular-nums;
418
+ white-space: nowrap;
419
+ }
420
+ .sm-network-player__shortcuts {
421
+ display: flex;
422
+ align-items: center;
423
+ gap: 4px;
424
+ flex-shrink: 0;
425
+ }
426
+ .sm-network-player__shortcuts button {
427
+ border-color: transparent;
428
+ padding-inline: 10px;
429
+ white-space: nowrap;
430
+ }
431
+ .sm-network-player__shortcuts .sm-network-player__rate {
432
+ min-width: 52px;
433
+ gap: 1px;
434
+ font-weight: 650;
435
+ font-variant-numeric: tabular-nums;
436
+ background: var(--sm-player-soft);
437
+ }
438
+ .sm-network-player__rate span {
345
439
  font-size: 12px;
440
+ font-weight: 400;
441
+ }
442
+ .sm-network-player__shortcuts .sm-network-player__highlight[aria-pressed=true] {
443
+ color: var(--sm-player-accent);
444
+ background: var(--sm-player-soft);
445
+ box-shadow: inset 0 -2px var(--sm-player-accent);
446
+ }
447
+ .sm-network-player__shortcuts .sm-network-player__queue {
448
+ margin-left: 6px;
449
+ border-color: var(--sm-player-line);
450
+ }
451
+ .sm-network-player__count {
452
+ display: grid;
453
+ place-items: center;
454
+ min-width: 20px;
455
+ height: 20px;
456
+ padding-inline: 4px;
457
+ border-radius: 50%;
458
+ background: var(--sm-player-soft);
459
+ font-size: 11px;
346
460
  font-variant-numeric: tabular-nums;
347
461
  }
462
+ .sm-network-player__queue > .sm-network-icon:last-child {
463
+ width: 14px;
464
+ height: 14px;
465
+ flex-basis: 14px;
466
+ transition: transform 160ms ease;
467
+ }
468
+ .sm-network-player__queue[aria-expanded=true] > .sm-network-icon:last-child {
469
+ transform: rotate(180deg);
470
+ }
348
471
  .sm-network-player__details {
349
472
  max-height: min(60dvh, 600px);
350
473
  overflow: auto;
@@ -366,15 +489,35 @@
366
489
  .sm-network-player__tools input {
367
490
  width: 100px;
368
491
  }
492
+ .sm-network-player__select {
493
+ position: relative;
494
+ display: inline-flex;
495
+ }
496
+ .sm-network-player__select select {
497
+ appearance: none;
498
+ min-width: 88px;
499
+ padding-right: 32px;
500
+ background: var(--sm-player-paper);
501
+ }
502
+ .sm-network-player__select > .sm-network-icon {
503
+ position: absolute;
504
+ right: 10px;
505
+ top: 50%;
506
+ transform: translateY(-50%);
507
+ width: 16px;
508
+ height: 16px;
509
+ pointer-events: none;
510
+ color: var(--sm-player-muted);
511
+ }
369
512
  .sm-network-player__expanded {
370
513
  display: grid;
371
514
  grid-template-columns: minmax(0, 1fr) auto;
372
515
  gap: 32px;
373
516
  border-top: 1px solid var(--sm-player-line);
374
- padding-top: 16px;
517
+ padding-top: 20px;
375
518
  }
376
519
  .sm-network-player h2 {
377
- font: 600 22px/1.3 var(--font-editorial, Georgia), serif;
520
+ font: 600 22px/1.3 var(--sm-player-serif, var(--font-editorial, Georgia)), serif;
378
521
  margin: 0 0 12px;
379
522
  }
380
523
  .sm-network-player ol {
@@ -391,8 +534,10 @@
391
534
  }
392
535
  .sm-network-player li[aria-current=true] {
393
536
  background: var(--sm-player-soft);
537
+ border-radius: 10px;
394
538
  }
395
539
  .sm-network-player .sm-network-player__queue-title {
540
+ display: block;
396
541
  flex: 1;
397
542
  text-align: left;
398
543
  border: 0;
@@ -424,32 +569,193 @@
424
569
  display: flex;
425
570
  flex-wrap: wrap;
426
571
  align-items: center;
427
- gap: 10px;
572
+ gap: 12px 20px;
573
+ padding: 16px;
574
+ border: 1px solid var(--sm-player-line);
575
+ border-radius: 18px;
576
+ background: var(--sm-player-soft);
428
577
  }
429
- .sm-network-article button[aria-pressed=true] {
430
- background: var(--sm-player-accent, #246346);
431
- color: white;
578
+ .sm-network-article .sm-network-article__listen {
579
+ flex: 1 1 auto;
580
+ justify-content: flex-start;
581
+ gap: 14px;
582
+ padding: 0;
583
+ border: 0;
584
+ border-radius: 24px 8px 8px 24px;
585
+ text-align: left;
586
+ }
587
+ .sm-network-article__caption {
588
+ display: flex;
589
+ flex-direction: column;
590
+ gap: 3px;
591
+ }
592
+ .sm-network-article__caption > span:first-child {
593
+ font: 500 20px/1.2 var(--sm-player-serif, var(--font-editorial, Georgia)), serif;
594
+ }
595
+ .sm-network-article__duration {
596
+ font-size: 12px;
597
+ color: var(--sm-player-muted);
598
+ font-variant-numeric: tabular-nums;
599
+ }
600
+ .sm-network-article__listen:hover .sm-network-article__disc {
601
+ background: var(--sm-player-ink);
602
+ }
603
+ .sm-network-article__actions {
604
+ display: flex;
605
+ align-items: center;
606
+ gap: 4px;
607
+ flex-wrap: wrap;
608
+ }
609
+ .sm-network-article__actions button {
610
+ border-color: transparent;
611
+ font-size: 12px;
612
+ padding-inline: 10px;
613
+ }
614
+ .sm-network-article__actions button:hover:not(:disabled) {
615
+ background: var(--sm-player-paper);
616
+ }
617
+ .sm-network-article__actions .sm-network-article__queue:disabled {
618
+ opacity: 1;
619
+ color: var(--sm-player-muted);
620
+ }
621
+ .sm-network-article__actions button[aria-pressed=true] {
622
+ color: var(--sm-player-accent);
623
+ }
624
+ .sm-network-toggle {
625
+ flex-shrink: 0;
626
+ display: inline-flex;
627
+ align-items: center;
628
+ width: 26px;
629
+ height: 16px;
630
+ padding: 3px;
631
+ border-radius: 10px;
632
+ background: var(--sm-player-muted);
633
+ }
634
+ .sm-network-toggle::after {
635
+ content: "";
636
+ width: 10px;
637
+ height: 10px;
638
+ border-radius: 50%;
639
+ background: var(--sm-player-paper);
640
+ transition: transform 160ms ease;
641
+ }
642
+ [aria-pressed=true] > .sm-network-toggle {
643
+ background: var(--sm-player-accent);
644
+ }
645
+ [aria-pressed=true] > .sm-network-toggle::after {
646
+ transform: translateX(10px);
647
+ }
648
+ @media (max-width: 1100px) {
649
+ .sm-network-player__row {
650
+ gap: 14px;
651
+ }
652
+ .sm-network-player__highlight > span,
653
+ .sm-network-player__queue-label {
654
+ display: none;
655
+ }
432
656
  }
433
657
  @media (max-width: 700px) {
434
658
  .sm-network-player {
435
- padding-inline: max(12px, env(safe-area-inset-left));
659
+ padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
436
660
  }
437
661
  .sm-network-player__row {
438
- gap: 10px;
662
+ gap: 10px 12px;
439
663
  flex-wrap: wrap;
440
664
  }
441
665
  .sm-network-player__story {
442
666
  flex: 1 1 calc(100% - 60px);
667
+ padding-right: 56px;
668
+ }
669
+ .sm-network-player .sm-network-player__close {
670
+ position: absolute;
671
+ top: 2px;
672
+ right: 0;
443
673
  }
444
674
  .sm-network-player__story a {
445
675
  font-size: 17px;
446
676
  }
677
+ .sm-network-player__story > span {
678
+ display: none;
679
+ }
447
680
  .sm-network-player__timeline {
448
- flex: 1 1 120px;
449
- min-width: 100px;
681
+ flex: 1 1 80px;
682
+ min-width: 80px;
683
+ max-width: none;
684
+ }
685
+ .sm-network-player__timeline div {
686
+ font-size: 10px;
687
+ }
688
+ .sm-network-player__shortcuts {
689
+ gap: 2px;
690
+ }
691
+ .sm-network-player__shortcuts button {
692
+ min-width: 44px;
693
+ padding-inline: 8px;
694
+ }
695
+ .sm-network-player__shortcuts .sm-network-player__queue {
696
+ margin-left: 2px;
697
+ gap: 4px;
698
+ }
699
+ .sm-network-player__queue > .sm-network-icon:last-child {
700
+ display: none;
450
701
  }
451
702
  .sm-network-player__expanded {
452
703
  grid-template-columns: minmax(0, 1fr);
453
704
  gap: 20px;
454
705
  }
706
+ .sm-network-article {
707
+ gap: 10px;
708
+ padding: 14px;
709
+ }
710
+ .sm-network-article__actions {
711
+ flex: 1 1 100%;
712
+ padding-top: 8px;
713
+ border-top: 1px solid var(--sm-player-line);
714
+ }
715
+ .sm-network-article__actions button {
716
+ flex: 1 0 auto;
717
+ white-space: nowrap;
718
+ }
719
+ }
720
+ @media (max-width: 400px) {
721
+ .sm-network-player__row {
722
+ column-gap: 6px;
723
+ }
724
+ .sm-network-player__shortcuts button {
725
+ padding-inline: 5px;
726
+ }
727
+ .sm-network-player__shortcuts .sm-network-player__queue {
728
+ gap: 2px;
729
+ }
730
+ .sm-network-player__remaining-label {
731
+ display: none;
732
+ }
733
+ .sm-network-player__remaining::before {
734
+ content: "\2212";
735
+ }
736
+ }
737
+ @media (prefers-reduced-motion: reduce) {
738
+ .sm-network-player *,
739
+ .sm-network-article *,
740
+ .sm-network-toggle::after {
741
+ transition: none !important;
742
+ }
743
+ }
744
+ @media (forced-colors: active) {
745
+ .sm-network-player__timeline input[type=range] {
746
+ appearance: auto;
747
+ }
748
+ .sm-network-player__timeline input::-webkit-slider-thumb {
749
+ appearance: auto;
750
+ }
751
+ .sm-network-player__highlight[aria-pressed=true],
752
+ .sm-network-article button[aria-pressed=true] {
753
+ outline: 2px solid Highlight;
754
+ }
755
+ .sm-network-toggle {
756
+ border: 1px solid ButtonText;
757
+ }
758
+ .sm-network-toggle::after {
759
+ background: ButtonText;
760
+ }
455
761
  }
package/dist/audio.d.mts CHANGED
@@ -228,6 +228,7 @@ interface NetworkAudioContextValue {
228
228
  notice: string | null;
229
229
  command: (command: NetworkAudioCommand) => void;
230
230
  openNetworkPlayer?: () => void;
231
+ highlightAvailable: boolean;
231
232
  highlightEnabled: boolean;
232
233
  setHighlightEnabled: (enabled: boolean) => void;
233
234
  }
@@ -244,9 +245,11 @@ declare function useArticleNarration(track: NetworkAudioTrack, narration?: Audio
244
245
  interface ArticleAudioControlsProps {
245
246
  track: NetworkAudioTrack;
246
247
  narration?: AudioPlayerNarration;
248
+ /** Recording length shown before playback; resolved media supplies the live duration. */
249
+ durationMs?: number | null;
247
250
  className?: string;
248
251
  }
249
- declare function ArticleAudioControls({ track, narration, className }: ArticleAudioControlsProps): react_jsx_runtime.JSX.Element;
252
+ declare function ArticleAudioControls({ track, narration, durationMs, className }: ArticleAudioControlsProps): react_jsx_runtime.JSX.Element;
250
253
  interface NetworkAudioPlayerProps {
251
254
  networkName?: string;
252
255
  /** Render an actual ad or sponsor creative here. The expanded slot is labeled Advertisement. */
package/dist/audio.d.ts CHANGED
@@ -228,6 +228,7 @@ interface NetworkAudioContextValue {
228
228
  notice: string | null;
229
229
  command: (command: NetworkAudioCommand) => void;
230
230
  openNetworkPlayer?: () => void;
231
+ highlightAvailable: boolean;
231
232
  highlightEnabled: boolean;
232
233
  setHighlightEnabled: (enabled: boolean) => void;
233
234
  }
@@ -244,9 +245,11 @@ declare function useArticleNarration(track: NetworkAudioTrack, narration?: Audio
244
245
  interface ArticleAudioControlsProps {
245
246
  track: NetworkAudioTrack;
246
247
  narration?: AudioPlayerNarration;
248
+ /** Recording length shown before playback; resolved media supplies the live duration. */
249
+ durationMs?: number | null;
247
250
  className?: string;
248
251
  }
249
- declare function ArticleAudioControls({ track, narration, className }: ArticleAudioControlsProps): react_jsx_runtime.JSX.Element;
252
+ declare function ArticleAudioControls({ track, narration, durationMs, className }: ArticleAudioControlsProps): react_jsx_runtime.JSX.Element;
250
253
  interface NetworkAudioPlayerProps {
251
254
  networkName?: string;
252
255
  /** Render an actual ad or sponsor creative here. The expanded slot is labeled Advertisement. */
package/dist/audio.js CHANGED
@@ -1279,6 +1279,7 @@ var NetworkPlayerClient = class {
1279
1279
  // src/components/network-audio-player.tsx
1280
1280
  var import_jsx_runtime2 = require("react/jsx-runtime");
1281
1281
  var Context = (0, import_react2.createContext)(null);
1282
+ var NarrationRegistration = (0, import_react2.createContext)(null);
1282
1283
  var serverSnapshot = () => EMPTY_SNAPSHOT;
1283
1284
  function NetworkAudioProvider({ children, resolveAudio, connection, host, checkpointStorageKey }) {
1284
1285
  if (connection && host) throw new Error("Use connection on reader pages and host on the dedicated player route, not both.");
@@ -1287,6 +1288,16 @@ function NetworkAudioProvider({ children, resolveAudio, connection, host, checkp
1287
1288
  const [remoteSnapshot, setRemoteSnapshot] = (0, import_react2.useState)(null);
1288
1289
  const [notice, setNotice] = (0, import_react2.useState)(null);
1289
1290
  const [highlightEnabled, setHighlightEnabled] = (0, import_react2.useState)(false);
1291
+ const [narrationTracks, setNarrationTracks] = (0, import_react2.useState)(() => /* @__PURE__ */ new Map());
1292
+ const registerNarration = (0, import_react2.useCallback)((key) => {
1293
+ const id = /* @__PURE__ */ Symbol();
1294
+ setNarrationTracks((previous) => new Map(previous).set(id, key));
1295
+ return () => setNarrationTracks((previous) => {
1296
+ const next = new Map(previous);
1297
+ next.delete(id);
1298
+ return next;
1299
+ });
1300
+ }, []);
1290
1301
  const client = (0, import_react2.useRef)(null);
1291
1302
  (0, import_react2.useEffect)(() => {
1292
1303
  controller.setResolver(resolveAudio);
@@ -1350,19 +1361,22 @@ function NetworkAudioProvider({ children, resolveAudio, connection, host, checkp
1350
1361
  }, [controller]);
1351
1362
  const openNetworkPlayer = (0, import_react2.useCallback)(() => client.current?.open(), []);
1352
1363
  const activeSnapshot = remoteSnapshot ?? snapshot;
1353
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Context.Provider, { value: {
1364
+ const activeTrack = activeSnapshot.queue[activeSnapshot.index];
1365
+ const highlightAvailable = !!activeTrack && [...narrationTracks.values()].includes(trackKey(activeTrack));
1366
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Context.Provider, { value: {
1354
1367
  snapshot: activeSnapshot,
1355
1368
  remote: remoteSnapshot !== null,
1356
1369
  hosted: !!host,
1357
1370
  notice,
1358
1371
  command,
1359
1372
  openNetworkPlayer: connection ? openNetworkPlayer : void 0,
1373
+ highlightAvailable,
1360
1374
  highlightEnabled,
1361
1375
  setHighlightEnabled
1362
- }, children: [
1376
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(NarrationRegistration.Provider, { value: registerNarration, children: [
1363
1377
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NetworkMediaSession, {}),
1364
1378
  children
1365
- ] });
1379
+ ] }) });
1366
1380
  }
1367
1381
  function useNetworkAudio() {
1368
1382
  const context = (0, import_react2.useContext)(Context);
@@ -1421,6 +1435,12 @@ var subscribeCapabilities = () => () => {
1421
1435
  function useArticleNarration(track, narration) {
1422
1436
  const { snapshot, highlightEnabled, setHighlightEnabled } = useNetworkAudio();
1423
1437
  const supported = (0, import_react2.useSyncExternalStore)(subscribeCapabilities, narrationHighlightSupported, () => false);
1438
+ const registerNarration = (0, import_react2.useContext)(NarrationRegistration);
1439
+ const narrationKey = trackKey(track);
1440
+ const available = !!narration && supported;
1441
+ (0, import_react2.useEffect)(() => {
1442
+ if (available) return registerNarration?.(narrationKey);
1443
+ }, [available, narrationKey, registerNarration]);
1424
1444
  const active = snapshot.queue[snapshot.index];
1425
1445
  const matching = !!active && trackKey(active) === trackKey(track);
1426
1446
  const clock = (0, import_react2.useRef)({ snapshot, received: 0 });
@@ -1474,26 +1494,89 @@ function useArticleNarration(track, narration) {
1474
1494
  }, [matching, highlightEnabled, supported, narration?.targetId, narration?.timingsUrl, track.id, track.publicationId]);
1475
1495
  return { highlightAvailable: !!narration && supported, highlightEnabled, setHighlightEnabled, matching };
1476
1496
  }
1477
- function ArticleAudioControls({ track, narration, className = "" }) {
1497
+ function AudioIcon({ name }) {
1498
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { className: "sm-network-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: [
1499
+ name === "play" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m9 5 11 7-11 7Z", fill: "currentColor", stroke: "none" }),
1500
+ name === "pause" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M7 5h3v14H7zm7 0h3v14h-3z", fill: "currentColor", stroke: "none" }),
1501
+ name === "queue" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M4 6h16M4 12h10M4 18h8m7-5v8m-4-4h8" }) }),
1502
+ name === "check" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m5 12 4 4L19 6" }),
1503
+ name === "highlight" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m7 14 7-9 5 4-7 9-5-4Zm0 0-3 5h8M16 3l5 4M3 22h17" }) }),
1504
+ name === "next" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1505
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m6 5 10 7-10 7Z", fill: "currentColor", stroke: "none" }),
1506
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M19 5v14" })
1507
+ ] }),
1508
+ name === "chevron" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m7 10 5 5 5-5" }),
1509
+ name === "external" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M14 4h6v6m0-6L10 14m10 1v5H4V4h5" }),
1510
+ name === "close" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m6 6 12 12M18 6 6 18" })
1511
+ ] });
1512
+ }
1513
+ var formatTime = (seconds) => `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
1514
+ var PLAYBACK_RATES = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
1515
+ function ArticleAudioControls({ track, narration, durationMs, className = "" }) {
1478
1516
  const { snapshot, command } = useNetworkAudio();
1479
1517
  const { highlightAvailable, highlightEnabled, setHighlightEnabled, matching } = useArticleNarration(track, narration);
1480
1518
  const playing = matching && (snapshot.status === "playing" || snapshot.status === "loading");
1481
1519
  const queued = snapshot.queue.some((item) => trackKey(item) === trackKey(track));
1482
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `sm-network-article ${className}`, "aria-label": "Article audio", children: [
1483
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => command(playing ? { action: "pause" } : { action: "playTrack", track }), children: playing ? "Pause article" : "Listen to article" }),
1484
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", disabled: queued, onClick: () => command({ action: "enqueue", track }), children: queued ? "In your queue" : "Add to queue" }),
1485
- highlightAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "aria-pressed": highlightEnabled, onClick: () => setHighlightEnabled(!highlightEnabled), children: "Highlight words" })
1520
+ const duration = matching && snapshot.duration > 0 ? snapshot.duration : (durationMs ?? 0) / 1e3;
1521
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `sm-network-article ${className}`, role: "group", "aria-label": "Article audio", children: [
1522
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1523
+ "button",
1524
+ {
1525
+ type: "button",
1526
+ className: "sm-network-article__listen",
1527
+ "aria-label": playing ? "Pause this story" : "Listen to this story",
1528
+ onClick: () => command(playing ? { action: "pause" } : { action: "playTrack", track }),
1529
+ children: [
1530
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "sm-network-article__disc", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: playing ? "pause" : "play" }) }),
1531
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "sm-network-article__caption", children: [
1532
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: playing ? "Pause this story" : "Listen to this story" }),
1533
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "sm-network-article__duration", children: matching && snapshot.status === "loading" ? "Loading audio\u2026" : duration > 0 ? `${formatTime(duration)} listening time` : "Article audio" })
1534
+ ] })
1535
+ ]
1536
+ }
1537
+ ),
1538
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-article__actions", children: [
1539
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1540
+ "button",
1541
+ {
1542
+ type: "button",
1543
+ className: "sm-network-article__queue",
1544
+ "aria-label": queued ? "Queued" : "Add to queue",
1545
+ disabled: queued,
1546
+ onClick: () => command({ action: "enqueue", track }),
1547
+ children: [
1548
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: queued ? "check" : "queue" }),
1549
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: queued ? "Queued" : "Queue" })
1550
+ ]
1551
+ }
1552
+ ),
1553
+ highlightAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1554
+ "button",
1555
+ {
1556
+ type: "button",
1557
+ "aria-label": "Follow along: highlight words",
1558
+ "aria-pressed": highlightEnabled,
1559
+ title: "Highlight words as you listen",
1560
+ onClick: () => setHighlightEnabled(!highlightEnabled),
1561
+ children: [
1562
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "highlight" }),
1563
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Follow along" }),
1564
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "sm-network-toggle", "aria-hidden": "true" })
1565
+ ]
1566
+ }
1567
+ )
1568
+ ] })
1486
1569
  ] });
1487
1570
  }
1488
- var formatTime = (seconds) => `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
1489
1571
  function NetworkAudioPlayer({ networkName = "Your listening queue", advertisement, className = "", style, fixed = true, renderArticleLink }) {
1490
- const { snapshot, remote, hosted, notice, command, openNetworkPlayer } = useNetworkAudio();
1572
+ const { snapshot, remote, hosted, notice, command, openNetworkPlayer, highlightAvailable, highlightEnabled, setHighlightEnabled } = useNetworkAudio();
1491
1573
  const [expanded, setExpanded] = (0, import_react2.useState)(false);
1492
1574
  const [height, setHeight] = (0, import_react2.useState)(0);
1493
1575
  const bar = (0, import_react2.useRef)(null);
1494
1576
  const detailsId = (0, import_react2.useId)();
1495
1577
  const track = snapshot.queue[snapshot.index];
1496
1578
  const playing = snapshot.status === "playing" || snapshot.status === "loading";
1579
+ const nextRate = PLAYBACK_RATES.find((rate) => rate > snapshot.rate) ?? 1;
1497
1580
  (0, import_react2.useEffect)(() => {
1498
1581
  const element = bar.current;
1499
1582
  if (!fixed || !element) return;
@@ -1512,24 +1595,97 @@ function NetworkAudioPlayer({ networkName = "Your listening queue", advertisemen
1512
1595
  fixed && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "aria-hidden": "true", style: { height } }),
1513
1596
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { ref: bar, className: `sm-network-player ${fixed ? "sm-network-player--fixed" : ""} ${className}`, style, "aria-label": "Network audio player", children: [
1514
1597
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__row", children: [
1515
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "sm-network-player__play", "aria-label": playing ? "Pause playback" : "Play playback", onClick: () => command({ action: playing ? "pause" : "play" }), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: playing ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M6 4h4v16H6zm8 0h4v16h-4z" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M7 3v18l15-9z" }) }) }),
1598
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "sm-network-player__play", "aria-label": playing ? "Pause playback" : "Play playback", onClick: () => command({ action: playing ? "pause" : "play" }), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: playing ? "pause" : "play" }) }),
1516
1599
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__story", children: [
1517
1600
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: remote ? "Playing in network window" : networkName }),
1518
1601
  !hosted && renderArticleLink ? renderArticleLink(track) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: track.articleUrl, target: "_blank", rel: "noopener noreferrer", children: track.title }),
1519
1602
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: track.publicationName })
1520
1603
  ] }),
1521
1604
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__timeline", children: [
1522
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "range", min: "0", max: snapshot.duration || 0, step: "0.1", value: Math.min(snapshot.position, snapshot.duration), disabled: !snapshot.duration, "aria-label": "Seek article audio", onChange: (e) => command({ action: "seek", value: Number(e.target.value) }) }),
1605
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { style: { "--sm-progress": `${snapshot.duration ? Math.min(100, snapshot.position / snapshot.duration * 100) : 0}%` }, type: "range", min: "0", max: snapshot.duration || 0, step: "0.1", value: Math.min(snapshot.position, snapshot.duration), disabled: !snapshot.duration, "aria-label": "Seek article audio", onChange: (e) => command({ action: "seek", value: Number(e.target.value) }) }),
1523
1606
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
1524
1607
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: formatTime(snapshot.position) }),
1525
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
1608
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "sm-network-player__remaining", "aria-label": `${formatTime(Math.max(0, snapshot.duration - snapshot.position) / snapshot.rate)} remaining`, children: [
1526
1609
  formatTime(Math.max(0, snapshot.duration - snapshot.position) / snapshot.rate),
1527
- " remaining"
1610
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "sm-network-player__remaining-label", children: " remaining" })
1528
1611
  ] })
1529
1612
  ] })
1530
1613
  ] }),
1531
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", disabled: snapshot.index + 1 >= snapshot.queue.length, onClick: () => command({ action: "select", value: snapshot.index + 1 }), children: "Next" }),
1532
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "aria-expanded": expanded, "aria-controls": detailsId, onClick: () => setExpanded(!expanded), children: expanded ? "Collapse" : `Queue (${snapshot.queue.length})` })
1614
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__shortcuts", role: "group", "aria-label": "Playback shortcuts", children: [
1615
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1616
+ "button",
1617
+ {
1618
+ type: "button",
1619
+ className: "sm-network-player__rate",
1620
+ "aria-label": `Playback speed ${snapshot.rate}\xD7. ${nextRate > snapshot.rate ? "Speed up" : "Reset"} to ${nextRate}\xD7`,
1621
+ title: `Playback speed: ${snapshot.rate}\xD7. Click for ${nextRate}\xD7`,
1622
+ onClick: () => command({ action: "rate", value: nextRate }),
1623
+ children: [
1624
+ snapshot.rate,
1625
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "\xD7" })
1626
+ ]
1627
+ }
1628
+ ),
1629
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1630
+ "button",
1631
+ {
1632
+ type: "button",
1633
+ className: "sm-network-player__highlight",
1634
+ "aria-label": "Follow along: highlight article words",
1635
+ "aria-pressed": highlightAvailable && highlightEnabled,
1636
+ disabled: !highlightAvailable,
1637
+ title: highlightAvailable ? "Highlight words as you listen" : "Open the playing article to use word highlighting when available",
1638
+ onClick: () => setHighlightEnabled(!highlightEnabled),
1639
+ children: [
1640
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "highlight" }),
1641
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Follow along" })
1642
+ ]
1643
+ }
1644
+ ),
1645
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1646
+ "button",
1647
+ {
1648
+ type: "button",
1649
+ className: "sm-network-player__next",
1650
+ "aria-label": "Next article",
1651
+ title: "Next article",
1652
+ disabled: snapshot.index + 1 >= snapshot.queue.length,
1653
+ onClick: () => command({ action: "select", value: snapshot.index + 1 }),
1654
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "next" })
1655
+ }
1656
+ ),
1657
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1658
+ "button",
1659
+ {
1660
+ type: "button",
1661
+ className: "sm-network-player__queue",
1662
+ "aria-label": expanded ? "Close queue" : `Queue (${snapshot.queue.length})`,
1663
+ "aria-expanded": expanded,
1664
+ "aria-controls": detailsId,
1665
+ onClick: () => setExpanded(!expanded),
1666
+ children: [
1667
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "queue" }),
1668
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "sm-network-player__queue-label", children: expanded ? "Close queue" : "Queue" }),
1669
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "sm-network-player__count", children: snapshot.queue.length }),
1670
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "chevron" })
1671
+ ]
1672
+ }
1673
+ )
1674
+ ] }),
1675
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1676
+ "button",
1677
+ {
1678
+ type: "button",
1679
+ className: "sm-network-player__close",
1680
+ "aria-label": "Close player",
1681
+ title: "Stop playback, clear queue, and close player",
1682
+ onClick: () => {
1683
+ setExpanded(false);
1684
+ command({ action: "clear" });
1685
+ },
1686
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "close" })
1687
+ }
1688
+ )
1533
1689
  ] }),
1534
1690
  (notice || snapshot.error) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "status", className: "sm-network-player__notice", children: notice ?? snapshot.error }),
1535
1691
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { id: detailsId, hidden: !expanded, className: "sm-network-player__details", children: [
@@ -1538,16 +1694,22 @@ function NetworkAudioPlayer({ networkName = "Your listening queue", advertisemen
1538
1694
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => command({ action: "seek", value: snapshot.position + 30 }), children: "Forward 30 seconds" }),
1539
1695
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1540
1696
  "Speed ",
1541
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("select", { value: snapshot.rate, onChange: (e) => command({ action: "rate", value: Number(e.target.value) }), children: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3].map((rate) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: rate, children: [
1542
- rate,
1543
- "\xD7"
1544
- ] }, rate)) })
1697
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "sm-network-player__select", children: [
1698
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("select", { value: snapshot.rate, onChange: (e) => command({ action: "rate", value: Number(e.target.value) }), children: PLAYBACK_RATES.map((rate) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: rate, children: [
1699
+ rate,
1700
+ "\xD7"
1701
+ ] }, rate)) }),
1702
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "chevron" })
1703
+ ] })
1545
1704
  ] }),
1546
1705
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
1547
1706
  "Volume ",
1548
1707
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { type: "range", min: "0", max: "1", step: "0.05", value: snapshot.volume, onChange: (e) => command({ action: "volume", value: Number(e.target.value) }) })
1549
1708
  ] }),
1550
- openNetworkPlayer && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: openNetworkPlayer, children: remote ? "Open player window" : "Listen across sites \u2197" }),
1709
+ openNetworkPlayer && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", onClick: openNetworkPlayer, children: [
1710
+ remote ? "Open player window" : "Listen across sites",
1711
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AudioIcon, { name: "external" })
1712
+ ] }),
1551
1713
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: () => command({ action: "clear" }), children: "Stop and clear queue" })
1552
1714
  ] }),
1553
1715
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "sm-network-player__expanded", children: [
package/dist/audio.mjs CHANGED
@@ -1259,6 +1259,7 @@ var NetworkPlayerClient = class {
1259
1259
  // src/components/network-audio-player.tsx
1260
1260
  import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1261
1261
  var Context = createContext(null);
1262
+ var NarrationRegistration = createContext(null);
1262
1263
  var serverSnapshot = () => EMPTY_SNAPSHOT;
1263
1264
  function NetworkAudioProvider({ children, resolveAudio, connection, host, checkpointStorageKey }) {
1264
1265
  if (connection && host) throw new Error("Use connection on reader pages and host on the dedicated player route, not both.");
@@ -1267,6 +1268,16 @@ function NetworkAudioProvider({ children, resolveAudio, connection, host, checkp
1267
1268
  const [remoteSnapshot, setRemoteSnapshot] = useState2(null);
1268
1269
  const [notice, setNotice] = useState2(null);
1269
1270
  const [highlightEnabled, setHighlightEnabled] = useState2(false);
1271
+ const [narrationTracks, setNarrationTracks] = useState2(() => /* @__PURE__ */ new Map());
1272
+ const registerNarration = useCallback((key) => {
1273
+ const id = /* @__PURE__ */ Symbol();
1274
+ setNarrationTracks((previous) => new Map(previous).set(id, key));
1275
+ return () => setNarrationTracks((previous) => {
1276
+ const next = new Map(previous);
1277
+ next.delete(id);
1278
+ return next;
1279
+ });
1280
+ }, []);
1270
1281
  const client = useRef2(null);
1271
1282
  useEffect2(() => {
1272
1283
  controller.setResolver(resolveAudio);
@@ -1330,19 +1341,22 @@ function NetworkAudioProvider({ children, resolveAudio, connection, host, checkp
1330
1341
  }, [controller]);
1331
1342
  const openNetworkPlayer = useCallback(() => client.current?.open(), []);
1332
1343
  const activeSnapshot = remoteSnapshot ?? snapshot;
1333
- return /* @__PURE__ */ jsxs2(Context.Provider, { value: {
1344
+ const activeTrack = activeSnapshot.queue[activeSnapshot.index];
1345
+ const highlightAvailable = !!activeTrack && [...narrationTracks.values()].includes(trackKey(activeTrack));
1346
+ return /* @__PURE__ */ jsx2(Context.Provider, { value: {
1334
1347
  snapshot: activeSnapshot,
1335
1348
  remote: remoteSnapshot !== null,
1336
1349
  hosted: !!host,
1337
1350
  notice,
1338
1351
  command,
1339
1352
  openNetworkPlayer: connection ? openNetworkPlayer : void 0,
1353
+ highlightAvailable,
1340
1354
  highlightEnabled,
1341
1355
  setHighlightEnabled
1342
- }, children: [
1356
+ }, children: /* @__PURE__ */ jsxs2(NarrationRegistration.Provider, { value: registerNarration, children: [
1343
1357
  /* @__PURE__ */ jsx2(NetworkMediaSession, {}),
1344
1358
  children
1345
- ] });
1359
+ ] }) });
1346
1360
  }
1347
1361
  function useNetworkAudio() {
1348
1362
  const context = useContext(Context);
@@ -1401,6 +1415,12 @@ var subscribeCapabilities = () => () => {
1401
1415
  function useArticleNarration(track, narration) {
1402
1416
  const { snapshot, highlightEnabled, setHighlightEnabled } = useNetworkAudio();
1403
1417
  const supported = useSyncExternalStore2(subscribeCapabilities, narrationHighlightSupported, () => false);
1418
+ const registerNarration = useContext(NarrationRegistration);
1419
+ const narrationKey = trackKey(track);
1420
+ const available = !!narration && supported;
1421
+ useEffect2(() => {
1422
+ if (available) return registerNarration?.(narrationKey);
1423
+ }, [available, narrationKey, registerNarration]);
1404
1424
  const active = snapshot.queue[snapshot.index];
1405
1425
  const matching = !!active && trackKey(active) === trackKey(track);
1406
1426
  const clock = useRef2({ snapshot, received: 0 });
@@ -1454,26 +1474,89 @@ function useArticleNarration(track, narration) {
1454
1474
  }, [matching, highlightEnabled, supported, narration?.targetId, narration?.timingsUrl, track.id, track.publicationId]);
1455
1475
  return { highlightAvailable: !!narration && supported, highlightEnabled, setHighlightEnabled, matching };
1456
1476
  }
1457
- function ArticleAudioControls({ track, narration, className = "" }) {
1477
+ function AudioIcon({ name }) {
1478
+ return /* @__PURE__ */ jsxs2("svg", { className: "sm-network-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: [
1479
+ name === "play" && /* @__PURE__ */ jsx2("path", { d: "m9 5 11 7-11 7Z", fill: "currentColor", stroke: "none" }),
1480
+ name === "pause" && /* @__PURE__ */ jsx2("path", { d: "M7 5h3v14H7zm7 0h3v14h-3z", fill: "currentColor", stroke: "none" }),
1481
+ name === "queue" && /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2("path", { d: "M4 6h16M4 12h10M4 18h8m7-5v8m-4-4h8" }) }),
1482
+ name === "check" && /* @__PURE__ */ jsx2("path", { d: "m5 12 4 4L19 6" }),
1483
+ name === "highlight" && /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2("path", { d: "m7 14 7-9 5 4-7 9-5-4Zm0 0-3 5h8M16 3l5 4M3 22h17" }) }),
1484
+ name === "next" && /* @__PURE__ */ jsxs2(Fragment, { children: [
1485
+ /* @__PURE__ */ jsx2("path", { d: "m6 5 10 7-10 7Z", fill: "currentColor", stroke: "none" }),
1486
+ /* @__PURE__ */ jsx2("path", { d: "M19 5v14" })
1487
+ ] }),
1488
+ name === "chevron" && /* @__PURE__ */ jsx2("path", { d: "m7 10 5 5 5-5" }),
1489
+ name === "external" && /* @__PURE__ */ jsx2("path", { d: "M14 4h6v6m0-6L10 14m10 1v5H4V4h5" }),
1490
+ name === "close" && /* @__PURE__ */ jsx2("path", { d: "m6 6 12 12M18 6 6 18" })
1491
+ ] });
1492
+ }
1493
+ var formatTime = (seconds) => `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
1494
+ var PLAYBACK_RATES = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
1495
+ function ArticleAudioControls({ track, narration, durationMs, className = "" }) {
1458
1496
  const { snapshot, command } = useNetworkAudio();
1459
1497
  const { highlightAvailable, highlightEnabled, setHighlightEnabled, matching } = useArticleNarration(track, narration);
1460
1498
  const playing = matching && (snapshot.status === "playing" || snapshot.status === "loading");
1461
1499
  const queued = snapshot.queue.some((item) => trackKey(item) === trackKey(track));
1462
- return /* @__PURE__ */ jsxs2("div", { className: `sm-network-article ${className}`, "aria-label": "Article audio", children: [
1463
- /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => command(playing ? { action: "pause" } : { action: "playTrack", track }), children: playing ? "Pause article" : "Listen to article" }),
1464
- /* @__PURE__ */ jsx2("button", { type: "button", disabled: queued, onClick: () => command({ action: "enqueue", track }), children: queued ? "In your queue" : "Add to queue" }),
1465
- highlightAvailable && /* @__PURE__ */ jsx2("button", { type: "button", "aria-pressed": highlightEnabled, onClick: () => setHighlightEnabled(!highlightEnabled), children: "Highlight words" })
1500
+ const duration = matching && snapshot.duration > 0 ? snapshot.duration : (durationMs ?? 0) / 1e3;
1501
+ return /* @__PURE__ */ jsxs2("div", { className: `sm-network-article ${className}`, role: "group", "aria-label": "Article audio", children: [
1502
+ /* @__PURE__ */ jsxs2(
1503
+ "button",
1504
+ {
1505
+ type: "button",
1506
+ className: "sm-network-article__listen",
1507
+ "aria-label": playing ? "Pause this story" : "Listen to this story",
1508
+ onClick: () => command(playing ? { action: "pause" } : { action: "playTrack", track }),
1509
+ children: [
1510
+ /* @__PURE__ */ jsx2("span", { className: "sm-network-article__disc", children: /* @__PURE__ */ jsx2(AudioIcon, { name: playing ? "pause" : "play" }) }),
1511
+ /* @__PURE__ */ jsxs2("span", { className: "sm-network-article__caption", children: [
1512
+ /* @__PURE__ */ jsx2("span", { children: playing ? "Pause this story" : "Listen to this story" }),
1513
+ /* @__PURE__ */ jsx2("span", { className: "sm-network-article__duration", children: matching && snapshot.status === "loading" ? "Loading audio\u2026" : duration > 0 ? `${formatTime(duration)} listening time` : "Article audio" })
1514
+ ] })
1515
+ ]
1516
+ }
1517
+ ),
1518
+ /* @__PURE__ */ jsxs2("div", { className: "sm-network-article__actions", children: [
1519
+ /* @__PURE__ */ jsxs2(
1520
+ "button",
1521
+ {
1522
+ type: "button",
1523
+ className: "sm-network-article__queue",
1524
+ "aria-label": queued ? "Queued" : "Add to queue",
1525
+ disabled: queued,
1526
+ onClick: () => command({ action: "enqueue", track }),
1527
+ children: [
1528
+ /* @__PURE__ */ jsx2(AudioIcon, { name: queued ? "check" : "queue" }),
1529
+ /* @__PURE__ */ jsx2("span", { children: queued ? "Queued" : "Queue" })
1530
+ ]
1531
+ }
1532
+ ),
1533
+ highlightAvailable && /* @__PURE__ */ jsxs2(
1534
+ "button",
1535
+ {
1536
+ type: "button",
1537
+ "aria-label": "Follow along: highlight words",
1538
+ "aria-pressed": highlightEnabled,
1539
+ title: "Highlight words as you listen",
1540
+ onClick: () => setHighlightEnabled(!highlightEnabled),
1541
+ children: [
1542
+ /* @__PURE__ */ jsx2(AudioIcon, { name: "highlight" }),
1543
+ /* @__PURE__ */ jsx2("span", { children: "Follow along" }),
1544
+ /* @__PURE__ */ jsx2("span", { className: "sm-network-toggle", "aria-hidden": "true" })
1545
+ ]
1546
+ }
1547
+ )
1548
+ ] })
1466
1549
  ] });
1467
1550
  }
1468
- var formatTime = (seconds) => `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
1469
1551
  function NetworkAudioPlayer({ networkName = "Your listening queue", advertisement, className = "", style, fixed = true, renderArticleLink }) {
1470
- const { snapshot, remote, hosted, notice, command, openNetworkPlayer } = useNetworkAudio();
1552
+ const { snapshot, remote, hosted, notice, command, openNetworkPlayer, highlightAvailable, highlightEnabled, setHighlightEnabled } = useNetworkAudio();
1471
1553
  const [expanded, setExpanded] = useState2(false);
1472
1554
  const [height, setHeight] = useState2(0);
1473
1555
  const bar = useRef2(null);
1474
1556
  const detailsId = useId2();
1475
1557
  const track = snapshot.queue[snapshot.index];
1476
1558
  const playing = snapshot.status === "playing" || snapshot.status === "loading";
1559
+ const nextRate = PLAYBACK_RATES.find((rate) => rate > snapshot.rate) ?? 1;
1477
1560
  useEffect2(() => {
1478
1561
  const element = bar.current;
1479
1562
  if (!fixed || !element) return;
@@ -1492,24 +1575,97 @@ function NetworkAudioPlayer({ networkName = "Your listening queue", advertisemen
1492
1575
  fixed && /* @__PURE__ */ jsx2("div", { "aria-hidden": "true", style: { height } }),
1493
1576
  /* @__PURE__ */ jsxs2("section", { ref: bar, className: `sm-network-player ${fixed ? "sm-network-player--fixed" : ""} ${className}`, style, "aria-label": "Network audio player", children: [
1494
1577
  /* @__PURE__ */ jsxs2("div", { className: "sm-network-player__row", children: [
1495
- /* @__PURE__ */ jsx2("button", { type: "button", className: "sm-network-player__play", "aria-label": playing ? "Pause playback" : "Play playback", onClick: () => command({ action: playing ? "pause" : "play" }), children: /* @__PURE__ */ jsx2("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: playing ? /* @__PURE__ */ jsx2("path", { d: "M6 4h4v16H6zm8 0h4v16h-4z" }) : /* @__PURE__ */ jsx2("path", { d: "M7 3v18l15-9z" }) }) }),
1578
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "sm-network-player__play", "aria-label": playing ? "Pause playback" : "Play playback", onClick: () => command({ action: playing ? "pause" : "play" }), children: /* @__PURE__ */ jsx2(AudioIcon, { name: playing ? "pause" : "play" }) }),
1496
1579
  /* @__PURE__ */ jsxs2("div", { className: "sm-network-player__story", children: [
1497
1580
  /* @__PURE__ */ jsx2("span", { children: remote ? "Playing in network window" : networkName }),
1498
1581
  !hosted && renderArticleLink ? renderArticleLink(track) : /* @__PURE__ */ jsx2("a", { href: track.articleUrl, target: "_blank", rel: "noopener noreferrer", children: track.title }),
1499
1582
  /* @__PURE__ */ jsx2("small", { children: track.publicationName })
1500
1583
  ] }),
1501
1584
  /* @__PURE__ */ jsxs2("div", { className: "sm-network-player__timeline", children: [
1502
- /* @__PURE__ */ jsx2("input", { type: "range", min: "0", max: snapshot.duration || 0, step: "0.1", value: Math.min(snapshot.position, snapshot.duration), disabled: !snapshot.duration, "aria-label": "Seek article audio", onChange: (e) => command({ action: "seek", value: Number(e.target.value) }) }),
1585
+ /* @__PURE__ */ jsx2("input", { style: { "--sm-progress": `${snapshot.duration ? Math.min(100, snapshot.position / snapshot.duration * 100) : 0}%` }, type: "range", min: "0", max: snapshot.duration || 0, step: "0.1", value: Math.min(snapshot.position, snapshot.duration), disabled: !snapshot.duration, "aria-label": "Seek article audio", onChange: (e) => command({ action: "seek", value: Number(e.target.value) }) }),
1503
1586
  /* @__PURE__ */ jsxs2("div", { children: [
1504
1587
  /* @__PURE__ */ jsx2("span", { children: formatTime(snapshot.position) }),
1505
- /* @__PURE__ */ jsxs2("span", { children: [
1588
+ /* @__PURE__ */ jsxs2("span", { className: "sm-network-player__remaining", "aria-label": `${formatTime(Math.max(0, snapshot.duration - snapshot.position) / snapshot.rate)} remaining`, children: [
1506
1589
  formatTime(Math.max(0, snapshot.duration - snapshot.position) / snapshot.rate),
1507
- " remaining"
1590
+ /* @__PURE__ */ jsx2("span", { className: "sm-network-player__remaining-label", children: " remaining" })
1508
1591
  ] })
1509
1592
  ] })
1510
1593
  ] }),
1511
- /* @__PURE__ */ jsx2("button", { type: "button", disabled: snapshot.index + 1 >= snapshot.queue.length, onClick: () => command({ action: "select", value: snapshot.index + 1 }), children: "Next" }),
1512
- /* @__PURE__ */ jsx2("button", { type: "button", "aria-expanded": expanded, "aria-controls": detailsId, onClick: () => setExpanded(!expanded), children: expanded ? "Collapse" : `Queue (${snapshot.queue.length})` })
1594
+ /* @__PURE__ */ jsxs2("div", { className: "sm-network-player__shortcuts", role: "group", "aria-label": "Playback shortcuts", children: [
1595
+ /* @__PURE__ */ jsxs2(
1596
+ "button",
1597
+ {
1598
+ type: "button",
1599
+ className: "sm-network-player__rate",
1600
+ "aria-label": `Playback speed ${snapshot.rate}\xD7. ${nextRate > snapshot.rate ? "Speed up" : "Reset"} to ${nextRate}\xD7`,
1601
+ title: `Playback speed: ${snapshot.rate}\xD7. Click for ${nextRate}\xD7`,
1602
+ onClick: () => command({ action: "rate", value: nextRate }),
1603
+ children: [
1604
+ snapshot.rate,
1605
+ /* @__PURE__ */ jsx2("span", { children: "\xD7" })
1606
+ ]
1607
+ }
1608
+ ),
1609
+ /* @__PURE__ */ jsxs2(
1610
+ "button",
1611
+ {
1612
+ type: "button",
1613
+ className: "sm-network-player__highlight",
1614
+ "aria-label": "Follow along: highlight article words",
1615
+ "aria-pressed": highlightAvailable && highlightEnabled,
1616
+ disabled: !highlightAvailable,
1617
+ title: highlightAvailable ? "Highlight words as you listen" : "Open the playing article to use word highlighting when available",
1618
+ onClick: () => setHighlightEnabled(!highlightEnabled),
1619
+ children: [
1620
+ /* @__PURE__ */ jsx2(AudioIcon, { name: "highlight" }),
1621
+ /* @__PURE__ */ jsx2("span", { children: "Follow along" })
1622
+ ]
1623
+ }
1624
+ ),
1625
+ /* @__PURE__ */ jsx2(
1626
+ "button",
1627
+ {
1628
+ type: "button",
1629
+ className: "sm-network-player__next",
1630
+ "aria-label": "Next article",
1631
+ title: "Next article",
1632
+ disabled: snapshot.index + 1 >= snapshot.queue.length,
1633
+ onClick: () => command({ action: "select", value: snapshot.index + 1 }),
1634
+ children: /* @__PURE__ */ jsx2(AudioIcon, { name: "next" })
1635
+ }
1636
+ ),
1637
+ /* @__PURE__ */ jsxs2(
1638
+ "button",
1639
+ {
1640
+ type: "button",
1641
+ className: "sm-network-player__queue",
1642
+ "aria-label": expanded ? "Close queue" : `Queue (${snapshot.queue.length})`,
1643
+ "aria-expanded": expanded,
1644
+ "aria-controls": detailsId,
1645
+ onClick: () => setExpanded(!expanded),
1646
+ children: [
1647
+ /* @__PURE__ */ jsx2(AudioIcon, { name: "queue" }),
1648
+ /* @__PURE__ */ jsx2("span", { className: "sm-network-player__queue-label", children: expanded ? "Close queue" : "Queue" }),
1649
+ /* @__PURE__ */ jsx2("span", { className: "sm-network-player__count", children: snapshot.queue.length }),
1650
+ /* @__PURE__ */ jsx2(AudioIcon, { name: "chevron" })
1651
+ ]
1652
+ }
1653
+ )
1654
+ ] }),
1655
+ /* @__PURE__ */ jsx2(
1656
+ "button",
1657
+ {
1658
+ type: "button",
1659
+ className: "sm-network-player__close",
1660
+ "aria-label": "Close player",
1661
+ title: "Stop playback, clear queue, and close player",
1662
+ onClick: () => {
1663
+ setExpanded(false);
1664
+ command({ action: "clear" });
1665
+ },
1666
+ children: /* @__PURE__ */ jsx2(AudioIcon, { name: "close" })
1667
+ }
1668
+ )
1513
1669
  ] }),
1514
1670
  (notice || snapshot.error) && /* @__PURE__ */ jsx2("p", { role: "status", className: "sm-network-player__notice", children: notice ?? snapshot.error }),
1515
1671
  /* @__PURE__ */ jsxs2("div", { id: detailsId, hidden: !expanded, className: "sm-network-player__details", children: [
@@ -1518,16 +1674,22 @@ function NetworkAudioPlayer({ networkName = "Your listening queue", advertisemen
1518
1674
  /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => command({ action: "seek", value: snapshot.position + 30 }), children: "Forward 30 seconds" }),
1519
1675
  /* @__PURE__ */ jsxs2("label", { children: [
1520
1676
  "Speed ",
1521
- /* @__PURE__ */ jsx2("select", { value: snapshot.rate, onChange: (e) => command({ action: "rate", value: Number(e.target.value) }), children: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3].map((rate) => /* @__PURE__ */ jsxs2("option", { value: rate, children: [
1522
- rate,
1523
- "\xD7"
1524
- ] }, rate)) })
1677
+ /* @__PURE__ */ jsxs2("span", { className: "sm-network-player__select", children: [
1678
+ /* @__PURE__ */ jsx2("select", { value: snapshot.rate, onChange: (e) => command({ action: "rate", value: Number(e.target.value) }), children: PLAYBACK_RATES.map((rate) => /* @__PURE__ */ jsxs2("option", { value: rate, children: [
1679
+ rate,
1680
+ "\xD7"
1681
+ ] }, rate)) }),
1682
+ /* @__PURE__ */ jsx2(AudioIcon, { name: "chevron" })
1683
+ ] })
1525
1684
  ] }),
1526
1685
  /* @__PURE__ */ jsxs2("label", { children: [
1527
1686
  "Volume ",
1528
1687
  /* @__PURE__ */ jsx2("input", { type: "range", min: "0", max: "1", step: "0.05", value: snapshot.volume, onChange: (e) => command({ action: "volume", value: Number(e.target.value) }) })
1529
1688
  ] }),
1530
- openNetworkPlayer && /* @__PURE__ */ jsx2("button", { type: "button", onClick: openNetworkPlayer, children: remote ? "Open player window" : "Listen across sites \u2197" }),
1689
+ openNetworkPlayer && /* @__PURE__ */ jsxs2("button", { type: "button", onClick: openNetworkPlayer, children: [
1690
+ remote ? "Open player window" : "Listen across sites",
1691
+ /* @__PURE__ */ jsx2(AudioIcon, { name: "external" })
1692
+ ] }),
1531
1693
  /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => command({ action: "clear" }), children: "Stop and clear queue" })
1532
1694
  ] }),
1533
1695
  /* @__PURE__ */ jsxs2("div", { className: "sm-network-player__expanded", children: [
@@ -84,6 +84,7 @@ players for the same article.
84
84
  import { ArticleAudioControls } from '@scalemule/nextjs/audio'
85
85
 
86
86
  <ArticleAudioControls
87
+ durationMs={article.audio?.duration_ms}
87
88
  track={{
88
89
  id: article.id,
89
90
  publicationId,
@@ -105,6 +106,8 @@ in different publications do not collide. The queue deduplicates entries and
105
106
  holds up to 100 articles. Finishing an article advances to the next one.
106
107
  Unavailable audio stops with a retry/choose-another message.
107
108
 
109
+ The compact bar exposes a playback-speed shortcut (cycles upward through the available rates, then resets to 1×), a Follow along toggle, and a Close player button. Closing stops playback, clears the listening queue and active highlights, and dismisses the player. Readers can reopen it with any article’s Listen to this story control. The expanded Speed selector retains all rates, including 0.5× and 0.75×. The player highlighting shortcut is enabled only when the active article has mounted narration controls in this document; it shares the article toggle’s preference.
110
+
108
111
  `useArticleNarration(track, narration)` attaches the same behavior to custom
109
112
  controls. Highlighting is opt-in, applies only to the active article, clears
110
113
  while the reader document is hidden, and detaches on unmount. The preference
@@ -192,8 +195,8 @@ screens, keyboard controls, volume, speed, seek, skipping forward/backward,
192
195
  queue selection/removal and clearing the queue. Media Session play/pause/seek is
193
196
  registered where supported. Customize `--sm-player-paper`, `--sm-player-ink`,
194
197
  `--sm-player-muted`, `--sm-player-line`, `--sm-player-accent`, `--sm-player-soft`,
195
- and `--sm-player-z-index`. Typography inherits `--font-editorial` and
196
- `--font-inter`. Supply an appropriate palette for dark themes.
198
+ and `--sm-player-z-index`. Typography uses `--sm-player-serif` and `--sm-player-sans`, falling back to
199
+ `--font-editorial` and `--font-inter`. The article panel uses the same palette variables. Supply an appropriate palette for dark themes.
197
200
 
198
201
  Persistence is off by default. Where reader preferences permit it, set
199
202
  `checkpointStorageKey` to an application/network **and user-scoped** key.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.1.54",
3
+ "version": "0.1.56",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",