@scalemule/nextjs 0.1.45 → 0.1.47

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
@@ -223,10 +223,3 @@
223
223
  flex-basis: 120px;
224
224
  }
225
225
  }
226
- ::highlight(sm-narration-sentence) {
227
- background-color: var(--sm-narration-sentence, rgba(36, 99, 70, 0.12));
228
- }
229
- ::highlight(sm-narration-word) {
230
- background-color: var(--sm-narration-word, rgba(36, 99, 70, 0.32));
231
- color: inherit;
232
- }
package/dist/audio.d.mts CHANGED
@@ -42,6 +42,11 @@ interface AudioPlayerProps {
42
42
  preload?: 'none' | 'metadata';
43
43
  /** Called at most once automatically per play attempt. Honor signal to cancel network work. */
44
44
  onRefresh?: (signal: AbortSignal) => Promise<AudioPlayerSource>;
45
+ /**
46
+ * @deprecated No-op. Players never show a manual Refresh control: expired
47
+ * URLs are refreshed silently through `onRefresh`. Kept so existing callers
48
+ * still compile.
49
+ */
45
50
  showRefreshButton?: boolean;
46
51
  onPlaybackError?: () => void;
47
52
  /** Shared with the existing ScaleMule blog player. Set null to disable persistence. */
@@ -60,12 +65,12 @@ declare function AudioPlayer(props: AudioPlayerProps): react_jsx_runtime.JSX.Ele
60
65
  * (the article's markdown rendered to plain text). The article body a
61
66
  * site renders is HTML from that same markdown, so the two word
62
67
  * sequences correspond nearly one-to-one; this module aligns them and
63
- * paints the spoken word and sentence with the CSS Custom Highlight
64
- * API — no DOM mutation, no per-word spans.
68
+ * paints the spoken word and sentence as boxes in an overlay layer
69
+ * behind the text — the article's own DOM is never rewritten.
65
70
  *
66
- * Everything degrades to nothing: unsupported browser (no
67
- * `CSS.highlights`), missing timings, or a body that no longer matches
68
- * the narration simply means no highlight.
71
+ * Everything degrades to nothing: no layout APIs (SSR), missing
72
+ * timings, or a body that no longer matches the narration simply means
73
+ * no highlight.
69
74
  */
70
75
  interface NarrationTimings {
71
76
  version: number;
@@ -79,16 +84,30 @@ declare function narrationHighlightSupported(): boolean;
79
84
  /**
80
85
  * Owns the live highlight for one narration player. Build once per
81
86
  * (timings, article body) pair; drive with `update(currentTimeMs)`.
87
+ *
88
+ * Paints into an overlay layer behind the article text (positioned boxes
89
+ * computed from the words' line rectangles) rather than the CSS Custom
90
+ * Highlight API: WebKit leaves stale ::highlight paint behind while the
91
+ * page scrolls, and per-word highlight ranges render as ragged, gapped
92
+ * boxes. Colors come from --sm-narration-sentence / --sm-narration-word
93
+ * on the article body (or any ancestor).
82
94
  */
83
95
  declare class NarrationHighlighter {
84
96
  private words;
85
97
  private ranges;
86
- private sentenceRanges;
98
+ private sentenceWords;
87
99
  private currentWord;
88
100
  private currentSentence;
89
101
  private follow;
90
102
  private detachUserScroll;
91
103
  private reducedMotion;
104
+ private root;
105
+ private layer;
106
+ private sentenceLayer;
107
+ private wordLayer;
108
+ private restoreRootStyle;
109
+ private resizeObserver;
110
+ private onWindowResize;
92
111
  constructor(root: Element, timings: NarrationTimings);
93
112
  /** Fraction of narration words found in the article body. A low
94
113
  * ratio means the body diverged from the script; callers may prefer
@@ -97,6 +116,13 @@ declare class NarrationHighlighter {
97
116
  private attachUserScroll;
98
117
  /** Re-engage auto-scroll (the reader pressed the toggle or sought). */
99
118
  resumeFollowing(): void;
119
+ /** Lazily creates the overlay layer behind the article text. */
120
+ private ensureLayer;
121
+ /** Line boxes for the given word indexes, in layer coordinates. */
122
+ private boxesFor;
123
+ private paint;
124
+ /** Re-lays out the current highlight (after resize / reflow). */
125
+ private repaint;
100
126
  update(timeMs: number): void;
101
127
  private scrollTo;
102
128
  clear(): void;
package/dist/audio.d.ts CHANGED
@@ -42,6 +42,11 @@ interface AudioPlayerProps {
42
42
  preload?: 'none' | 'metadata';
43
43
  /** Called at most once automatically per play attempt. Honor signal to cancel network work. */
44
44
  onRefresh?: (signal: AbortSignal) => Promise<AudioPlayerSource>;
45
+ /**
46
+ * @deprecated No-op. Players never show a manual Refresh control: expired
47
+ * URLs are refreshed silently through `onRefresh`. Kept so existing callers
48
+ * still compile.
49
+ */
45
50
  showRefreshButton?: boolean;
46
51
  onPlaybackError?: () => void;
47
52
  /** Shared with the existing ScaleMule blog player. Set null to disable persistence. */
@@ -60,12 +65,12 @@ declare function AudioPlayer(props: AudioPlayerProps): react_jsx_runtime.JSX.Ele
60
65
  * (the article's markdown rendered to plain text). The article body a
61
66
  * site renders is HTML from that same markdown, so the two word
62
67
  * sequences correspond nearly one-to-one; this module aligns them and
63
- * paints the spoken word and sentence with the CSS Custom Highlight
64
- * API — no DOM mutation, no per-word spans.
68
+ * paints the spoken word and sentence as boxes in an overlay layer
69
+ * behind the text — the article's own DOM is never rewritten.
65
70
  *
66
- * Everything degrades to nothing: unsupported browser (no
67
- * `CSS.highlights`), missing timings, or a body that no longer matches
68
- * the narration simply means no highlight.
71
+ * Everything degrades to nothing: no layout APIs (SSR), missing
72
+ * timings, or a body that no longer matches the narration simply means
73
+ * no highlight.
69
74
  */
70
75
  interface NarrationTimings {
71
76
  version: number;
@@ -79,16 +84,30 @@ declare function narrationHighlightSupported(): boolean;
79
84
  /**
80
85
  * Owns the live highlight for one narration player. Build once per
81
86
  * (timings, article body) pair; drive with `update(currentTimeMs)`.
87
+ *
88
+ * Paints into an overlay layer behind the article text (positioned boxes
89
+ * computed from the words' line rectangles) rather than the CSS Custom
90
+ * Highlight API: WebKit leaves stale ::highlight paint behind while the
91
+ * page scrolls, and per-word highlight ranges render as ragged, gapped
92
+ * boxes. Colors come from --sm-narration-sentence / --sm-narration-word
93
+ * on the article body (or any ancestor).
82
94
  */
83
95
  declare class NarrationHighlighter {
84
96
  private words;
85
97
  private ranges;
86
- private sentenceRanges;
98
+ private sentenceWords;
87
99
  private currentWord;
88
100
  private currentSentence;
89
101
  private follow;
90
102
  private detachUserScroll;
91
103
  private reducedMotion;
104
+ private root;
105
+ private layer;
106
+ private sentenceLayer;
107
+ private wordLayer;
108
+ private restoreRootStyle;
109
+ private resizeObserver;
110
+ private onWindowResize;
92
111
  constructor(root: Element, timings: NarrationTimings);
93
112
  /** Fraction of narration words found in the article body. A low
94
113
  * ratio means the body diverged from the script; callers may prefer
@@ -97,6 +116,13 @@ declare class NarrationHighlighter {
97
116
  private attachUserScroll;
98
117
  /** Re-engage auto-scroll (the reader pressed the toggle or sought). */
99
118
  resumeFollowing(): void;
119
+ /** Lazily creates the overlay layer behind the article text. */
120
+ private ensureLayer;
121
+ /** Line boxes for the given word indexes, in layer coordinates. */
122
+ private boxesFor;
123
+ private paint;
124
+ /** Re-lays out the current highlight (after resize / reflow). */
125
+ private repaint;
100
126
  update(timeMs: number): void;
101
127
  private scrollTo;
102
128
  clear(): void;
package/dist/audio.js CHANGED
@@ -99,15 +99,46 @@ function wordIndexAt(words, timeMs) {
99
99
  }
100
100
  return ans;
101
101
  }
102
+ function mergeLineBoxes(rects) {
103
+ const lines = [];
104
+ const sorted = rects.filter((r) => r.width > 0 && r.height > 0).sort((a, b) => a.top - b.top || a.left - b.left);
105
+ for (const r of sorted) {
106
+ const center = r.top + r.height / 2;
107
+ const line = lines.find((l) => {
108
+ const lc = l.top + l.height / 2;
109
+ return Math.abs(lc - center) < Math.min(l.height, r.height) / 2;
110
+ });
111
+ if (!line) {
112
+ lines.push({ ...r });
113
+ continue;
114
+ }
115
+ const right = Math.max(line.left + line.width, r.left + r.width);
116
+ const bottom = Math.max(line.top + line.height, r.top + r.height);
117
+ line.left = Math.min(line.left, r.left);
118
+ line.top = Math.min(line.top, r.top);
119
+ line.width = right - line.left;
120
+ line.height = bottom - line.top;
121
+ }
122
+ return lines;
123
+ }
102
124
  function narrationHighlightSupported() {
103
- return typeof window !== "undefined" && typeof CSS !== "undefined" && "highlights" in CSS && typeof globalThis.Highlight === "function";
125
+ return typeof window !== "undefined" && typeof document !== "undefined" && typeof Range !== "undefined" && typeof Range.prototype.getClientRects === "function";
104
126
  }
127
+ var PAD_X = 2;
128
+ var PAD_Y = 1;
105
129
  var NarrationHighlighter = class {
106
130
  constructor(root, timings) {
107
131
  this.currentWord = -2;
108
132
  this.currentSentence = -2;
109
133
  this.follow = true;
110
134
  this.detachUserScroll = null;
135
+ this.layer = null;
136
+ this.sentenceLayer = null;
137
+ this.wordLayer = null;
138
+ this.restoreRootStyle = null;
139
+ this.resizeObserver = null;
140
+ this.onWindowResize = null;
141
+ this.root = root;
111
142
  this.words = timings.words;
112
143
  const domWords = collectDomWords(root);
113
144
  const matches = alignWords(
@@ -127,13 +158,12 @@ var NarrationHighlighter = class {
127
158
  return null;
128
159
  }
129
160
  });
130
- this.sentenceRanges = /* @__PURE__ */ new Map();
161
+ this.sentenceWords = /* @__PURE__ */ new Map();
131
162
  this.words.forEach((w, i) => {
132
- const range = this.ranges[i];
133
- if (!range) return;
134
- const list = this.sentenceRanges.get(w[3]);
135
- if (list) list.push(range);
136
- else this.sentenceRanges.set(w[3], [range]);
163
+ if (!this.ranges[i]) return;
164
+ const list = this.sentenceWords.get(w[3]);
165
+ if (list) list.push(i);
166
+ else this.sentenceWords.set(w[3], [i]);
137
167
  });
138
168
  this.reducedMotion = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
139
169
  this.attachUserScroll(doc);
@@ -162,31 +192,109 @@ var NarrationHighlighter = class {
162
192
  this.follow = true;
163
193
  this.currentSentence = -2;
164
194
  }
195
+ /** Lazily creates the overlay layer behind the article text. */
196
+ ensureLayer() {
197
+ if (this.layer) return true;
198
+ const root = this.root;
199
+ const doc = root.ownerDocument;
200
+ if (!doc || typeof root.style === "undefined") return false;
201
+ const view = doc.defaultView;
202
+ const computed = view?.getComputedStyle(root);
203
+ const previous = { position: root.style.position, isolation: root.style.isolation };
204
+ if (!computed || computed.position === "static") root.style.position = "relative";
205
+ root.style.isolation = "isolate";
206
+ this.restoreRootStyle = () => {
207
+ root.style.position = previous.position;
208
+ root.style.isolation = previous.isolation;
209
+ };
210
+ const make = () => {
211
+ const el = doc.createElement("div");
212
+ el.style.position = "absolute";
213
+ el.style.inset = "0";
214
+ el.style.pointerEvents = "none";
215
+ return el;
216
+ };
217
+ this.layer = make();
218
+ this.layer.setAttribute("aria-hidden", "true");
219
+ this.layer.setAttribute("data-sm-narration-layer", "");
220
+ this.layer.style.zIndex = "-1";
221
+ this.sentenceLayer = make();
222
+ this.wordLayer = make();
223
+ this.layer.append(this.sentenceLayer, this.wordLayer);
224
+ root.prepend(this.layer);
225
+ if (typeof ResizeObserver !== "undefined") {
226
+ this.resizeObserver = new ResizeObserver(() => this.repaint());
227
+ this.resizeObserver.observe(root);
228
+ }
229
+ if (view) {
230
+ this.onWindowResize = () => this.repaint();
231
+ view.addEventListener("resize", this.onWindowResize, { passive: true });
232
+ }
233
+ return true;
234
+ }
235
+ /** Line boxes for the given word indexes, in layer coordinates. */
236
+ boxesFor(wordIndexes) {
237
+ const root = this.root;
238
+ const origin = root.getBoundingClientRect();
239
+ const rects = [];
240
+ for (const i of wordIndexes) {
241
+ const range = this.ranges[i];
242
+ if (!range || typeof range.getClientRects !== "function") continue;
243
+ for (const r of Array.from(range.getClientRects())) {
244
+ rects.push({
245
+ left: r.left - origin.left - root.clientLeft + root.scrollLeft,
246
+ top: r.top - origin.top - root.clientTop + root.scrollTop,
247
+ width: r.width,
248
+ height: r.height
249
+ });
250
+ }
251
+ }
252
+ return mergeLineBoxes(rects);
253
+ }
254
+ paint(target, boxes, kind) {
255
+ if (!target) return;
256
+ const doc = target.ownerDocument;
257
+ const color = kind === "word" ? "var(--sm-narration-word, rgba(36, 99, 70, 0.32))" : "var(--sm-narration-sentence, rgba(36, 99, 70, 0.12))";
258
+ const nodes = boxes.map((b) => {
259
+ const el = doc.createElement("div");
260
+ el.setAttribute("data-sm-narration", kind);
261
+ el.className = kind === "word" ? WORD_HIGHLIGHT : SENTENCE_HIGHLIGHT;
262
+ el.style.position = "absolute";
263
+ el.style.left = `${b.left - PAD_X}px`;
264
+ el.style.top = `${b.top - PAD_Y}px`;
265
+ el.style.width = `${b.width + PAD_X * 2}px`;
266
+ el.style.height = `${b.height + PAD_Y * 2}px`;
267
+ el.style.borderRadius = "4px";
268
+ el.style.background = color;
269
+ return el;
270
+ });
271
+ target.replaceChildren(...nodes);
272
+ }
273
+ /** Re-lays out the current highlight (after resize / reflow). */
274
+ repaint() {
275
+ if (this.currentWord < 0) return;
276
+ const sentence = this.words[this.currentWord]?.[3];
277
+ this.paint(this.sentenceLayer, this.boxesFor(this.sentenceWords.get(sentence) ?? []), "sentence");
278
+ this.paint(this.wordLayer, this.boxesFor([this.currentWord]), "word");
279
+ }
165
280
  update(timeMs) {
166
281
  if (!narrationHighlightSupported()) return;
167
282
  const idx = wordIndexAt(this.words, timeMs);
168
283
  if (idx === this.currentWord) return;
169
284
  this.currentWord = idx;
170
- const registry = CSS.highlights;
171
285
  if (idx < 0) {
172
- registry.delete(WORD_HIGHLIGHT);
173
- registry.delete(SENTENCE_HIGHLIGHT);
174
- this.currentSentence = -2;
286
+ this.clear();
175
287
  return;
176
288
  }
177
- const wordRange = this.ranges[idx];
178
- if (wordRange) registry.set(WORD_HIGHLIGHT, new Highlight(wordRange));
179
- else registry.delete(WORD_HIGHLIGHT);
289
+ if (!this.ensureLayer()) return;
290
+ this.paint(this.wordLayer, this.ranges[idx] ? this.boxesFor([idx]) : [], "word");
180
291
  const sentence = this.words[idx][3];
181
292
  if (sentence !== this.currentSentence) {
182
293
  this.currentSentence = sentence;
183
- const ranges = this.sentenceRanges.get(sentence) ?? [];
184
- if (ranges.length > 0) {
185
- registry.set(SENTENCE_HIGHLIGHT, new Highlight(...ranges));
186
- this.scrollTo(ranges[0]);
187
- } else {
188
- registry.delete(SENTENCE_HIGHLIGHT);
189
- }
294
+ const members = this.sentenceWords.get(sentence) ?? [];
295
+ this.paint(this.sentenceLayer, this.boxesFor(members), "sentence");
296
+ const first = members.length ? this.ranges[members[0]] : null;
297
+ if (first) this.scrollTo(first);
190
298
  }
191
299
  }
192
300
  scrollTo(range) {
@@ -202,15 +310,23 @@ var NarrationHighlighter = class {
202
310
  }
203
311
  }
204
312
  clear() {
205
- if (!narrationHighlightSupported()) return;
206
- const registry = CSS.highlights;
207
- registry.delete(WORD_HIGHLIGHT);
208
- registry.delete(SENTENCE_HIGHLIGHT);
313
+ this.sentenceLayer?.replaceChildren();
314
+ this.wordLayer?.replaceChildren();
209
315
  this.currentWord = -2;
210
316
  this.currentSentence = -2;
211
317
  }
212
318
  destroy() {
213
319
  this.clear();
320
+ this.resizeObserver?.disconnect();
321
+ this.resizeObserver = null;
322
+ if (this.onWindowResize) {
323
+ this.root.ownerDocument?.defaultView?.removeEventListener("resize", this.onWindowResize);
324
+ this.onWindowResize = null;
325
+ }
326
+ this.layer?.remove();
327
+ this.layer = this.sentenceLayer = this.wordLayer = null;
328
+ this.restoreRootStyle?.();
329
+ this.restoreRootStyle = null;
214
330
  this.detachUserScroll?.();
215
331
  this.detachUserScroll = null;
216
332
  }
@@ -248,7 +364,6 @@ function PlayerSession({
248
364
  style,
249
365
  preload = "none",
250
366
  onRefresh,
251
- showRefreshButton = false,
252
367
  onPlaybackError,
253
368
  playbackRateStorageKey = "scalemule:audio:playback-rate",
254
369
  exclusivePlayback = true,
@@ -664,19 +779,9 @@ function PlayerSession({
664
779
  "\xD7"
665
780
  ]
666
781
  }
667
- ),
668
- onRefresh && showRefreshButton && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
669
- "button",
670
- {
671
- type: "button",
672
- className: "sm-audio__refresh",
673
- disabled: busy,
674
- onClick: () => void recover(true),
675
- children: "Refresh"
676
- }
677
782
  )
678
783
  ] }),
679
- (busy || error) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "sm-audio__status", role: "status", children: busy ? "Refreshing audio\u2026" : error })
784
+ (busy || error) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "sm-audio__status", role: "status", children: busy ? "Loading audio\u2026" : error })
680
785
  ]
681
786
  }
682
787
  );
package/dist/audio.mjs CHANGED
@@ -75,15 +75,46 @@ function wordIndexAt(words, timeMs) {
75
75
  }
76
76
  return ans;
77
77
  }
78
+ function mergeLineBoxes(rects) {
79
+ const lines = [];
80
+ const sorted = rects.filter((r) => r.width > 0 && r.height > 0).sort((a, b) => a.top - b.top || a.left - b.left);
81
+ for (const r of sorted) {
82
+ const center = r.top + r.height / 2;
83
+ const line = lines.find((l) => {
84
+ const lc = l.top + l.height / 2;
85
+ return Math.abs(lc - center) < Math.min(l.height, r.height) / 2;
86
+ });
87
+ if (!line) {
88
+ lines.push({ ...r });
89
+ continue;
90
+ }
91
+ const right = Math.max(line.left + line.width, r.left + r.width);
92
+ const bottom = Math.max(line.top + line.height, r.top + r.height);
93
+ line.left = Math.min(line.left, r.left);
94
+ line.top = Math.min(line.top, r.top);
95
+ line.width = right - line.left;
96
+ line.height = bottom - line.top;
97
+ }
98
+ return lines;
99
+ }
78
100
  function narrationHighlightSupported() {
79
- return typeof window !== "undefined" && typeof CSS !== "undefined" && "highlights" in CSS && typeof globalThis.Highlight === "function";
101
+ return typeof window !== "undefined" && typeof document !== "undefined" && typeof Range !== "undefined" && typeof Range.prototype.getClientRects === "function";
80
102
  }
103
+ var PAD_X = 2;
104
+ var PAD_Y = 1;
81
105
  var NarrationHighlighter = class {
82
106
  constructor(root, timings) {
83
107
  this.currentWord = -2;
84
108
  this.currentSentence = -2;
85
109
  this.follow = true;
86
110
  this.detachUserScroll = null;
111
+ this.layer = null;
112
+ this.sentenceLayer = null;
113
+ this.wordLayer = null;
114
+ this.restoreRootStyle = null;
115
+ this.resizeObserver = null;
116
+ this.onWindowResize = null;
117
+ this.root = root;
87
118
  this.words = timings.words;
88
119
  const domWords = collectDomWords(root);
89
120
  const matches = alignWords(
@@ -103,13 +134,12 @@ var NarrationHighlighter = class {
103
134
  return null;
104
135
  }
105
136
  });
106
- this.sentenceRanges = /* @__PURE__ */ new Map();
137
+ this.sentenceWords = /* @__PURE__ */ new Map();
107
138
  this.words.forEach((w, i) => {
108
- const range = this.ranges[i];
109
- if (!range) return;
110
- const list = this.sentenceRanges.get(w[3]);
111
- if (list) list.push(range);
112
- else this.sentenceRanges.set(w[3], [range]);
139
+ if (!this.ranges[i]) return;
140
+ const list = this.sentenceWords.get(w[3]);
141
+ if (list) list.push(i);
142
+ else this.sentenceWords.set(w[3], [i]);
113
143
  });
114
144
  this.reducedMotion = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
115
145
  this.attachUserScroll(doc);
@@ -138,31 +168,109 @@ var NarrationHighlighter = class {
138
168
  this.follow = true;
139
169
  this.currentSentence = -2;
140
170
  }
171
+ /** Lazily creates the overlay layer behind the article text. */
172
+ ensureLayer() {
173
+ if (this.layer) return true;
174
+ const root = this.root;
175
+ const doc = root.ownerDocument;
176
+ if (!doc || typeof root.style === "undefined") return false;
177
+ const view = doc.defaultView;
178
+ const computed = view?.getComputedStyle(root);
179
+ const previous = { position: root.style.position, isolation: root.style.isolation };
180
+ if (!computed || computed.position === "static") root.style.position = "relative";
181
+ root.style.isolation = "isolate";
182
+ this.restoreRootStyle = () => {
183
+ root.style.position = previous.position;
184
+ root.style.isolation = previous.isolation;
185
+ };
186
+ const make = () => {
187
+ const el = doc.createElement("div");
188
+ el.style.position = "absolute";
189
+ el.style.inset = "0";
190
+ el.style.pointerEvents = "none";
191
+ return el;
192
+ };
193
+ this.layer = make();
194
+ this.layer.setAttribute("aria-hidden", "true");
195
+ this.layer.setAttribute("data-sm-narration-layer", "");
196
+ this.layer.style.zIndex = "-1";
197
+ this.sentenceLayer = make();
198
+ this.wordLayer = make();
199
+ this.layer.append(this.sentenceLayer, this.wordLayer);
200
+ root.prepend(this.layer);
201
+ if (typeof ResizeObserver !== "undefined") {
202
+ this.resizeObserver = new ResizeObserver(() => this.repaint());
203
+ this.resizeObserver.observe(root);
204
+ }
205
+ if (view) {
206
+ this.onWindowResize = () => this.repaint();
207
+ view.addEventListener("resize", this.onWindowResize, { passive: true });
208
+ }
209
+ return true;
210
+ }
211
+ /** Line boxes for the given word indexes, in layer coordinates. */
212
+ boxesFor(wordIndexes) {
213
+ const root = this.root;
214
+ const origin = root.getBoundingClientRect();
215
+ const rects = [];
216
+ for (const i of wordIndexes) {
217
+ const range = this.ranges[i];
218
+ if (!range || typeof range.getClientRects !== "function") continue;
219
+ for (const r of Array.from(range.getClientRects())) {
220
+ rects.push({
221
+ left: r.left - origin.left - root.clientLeft + root.scrollLeft,
222
+ top: r.top - origin.top - root.clientTop + root.scrollTop,
223
+ width: r.width,
224
+ height: r.height
225
+ });
226
+ }
227
+ }
228
+ return mergeLineBoxes(rects);
229
+ }
230
+ paint(target, boxes, kind) {
231
+ if (!target) return;
232
+ const doc = target.ownerDocument;
233
+ const color = kind === "word" ? "var(--sm-narration-word, rgba(36, 99, 70, 0.32))" : "var(--sm-narration-sentence, rgba(36, 99, 70, 0.12))";
234
+ const nodes = boxes.map((b) => {
235
+ const el = doc.createElement("div");
236
+ el.setAttribute("data-sm-narration", kind);
237
+ el.className = kind === "word" ? WORD_HIGHLIGHT : SENTENCE_HIGHLIGHT;
238
+ el.style.position = "absolute";
239
+ el.style.left = `${b.left - PAD_X}px`;
240
+ el.style.top = `${b.top - PAD_Y}px`;
241
+ el.style.width = `${b.width + PAD_X * 2}px`;
242
+ el.style.height = `${b.height + PAD_Y * 2}px`;
243
+ el.style.borderRadius = "4px";
244
+ el.style.background = color;
245
+ return el;
246
+ });
247
+ target.replaceChildren(...nodes);
248
+ }
249
+ /** Re-lays out the current highlight (after resize / reflow). */
250
+ repaint() {
251
+ if (this.currentWord < 0) return;
252
+ const sentence = this.words[this.currentWord]?.[3];
253
+ this.paint(this.sentenceLayer, this.boxesFor(this.sentenceWords.get(sentence) ?? []), "sentence");
254
+ this.paint(this.wordLayer, this.boxesFor([this.currentWord]), "word");
255
+ }
141
256
  update(timeMs) {
142
257
  if (!narrationHighlightSupported()) return;
143
258
  const idx = wordIndexAt(this.words, timeMs);
144
259
  if (idx === this.currentWord) return;
145
260
  this.currentWord = idx;
146
- const registry = CSS.highlights;
147
261
  if (idx < 0) {
148
- registry.delete(WORD_HIGHLIGHT);
149
- registry.delete(SENTENCE_HIGHLIGHT);
150
- this.currentSentence = -2;
262
+ this.clear();
151
263
  return;
152
264
  }
153
- const wordRange = this.ranges[idx];
154
- if (wordRange) registry.set(WORD_HIGHLIGHT, new Highlight(wordRange));
155
- else registry.delete(WORD_HIGHLIGHT);
265
+ if (!this.ensureLayer()) return;
266
+ this.paint(this.wordLayer, this.ranges[idx] ? this.boxesFor([idx]) : [], "word");
156
267
  const sentence = this.words[idx][3];
157
268
  if (sentence !== this.currentSentence) {
158
269
  this.currentSentence = sentence;
159
- const ranges = this.sentenceRanges.get(sentence) ?? [];
160
- if (ranges.length > 0) {
161
- registry.set(SENTENCE_HIGHLIGHT, new Highlight(...ranges));
162
- this.scrollTo(ranges[0]);
163
- } else {
164
- registry.delete(SENTENCE_HIGHLIGHT);
165
- }
270
+ const members = this.sentenceWords.get(sentence) ?? [];
271
+ this.paint(this.sentenceLayer, this.boxesFor(members), "sentence");
272
+ const first = members.length ? this.ranges[members[0]] : null;
273
+ if (first) this.scrollTo(first);
166
274
  }
167
275
  }
168
276
  scrollTo(range) {
@@ -178,15 +286,23 @@ var NarrationHighlighter = class {
178
286
  }
179
287
  }
180
288
  clear() {
181
- if (!narrationHighlightSupported()) return;
182
- const registry = CSS.highlights;
183
- registry.delete(WORD_HIGHLIGHT);
184
- registry.delete(SENTENCE_HIGHLIGHT);
289
+ this.sentenceLayer?.replaceChildren();
290
+ this.wordLayer?.replaceChildren();
185
291
  this.currentWord = -2;
186
292
  this.currentSentence = -2;
187
293
  }
188
294
  destroy() {
189
295
  this.clear();
296
+ this.resizeObserver?.disconnect();
297
+ this.resizeObserver = null;
298
+ if (this.onWindowResize) {
299
+ this.root.ownerDocument?.defaultView?.removeEventListener("resize", this.onWindowResize);
300
+ this.onWindowResize = null;
301
+ }
302
+ this.layer?.remove();
303
+ this.layer = this.sentenceLayer = this.wordLayer = null;
304
+ this.restoreRootStyle?.();
305
+ this.restoreRootStyle = null;
190
306
  this.detachUserScroll?.();
191
307
  this.detachUserScroll = null;
192
308
  }
@@ -224,7 +340,6 @@ function PlayerSession({
224
340
  style,
225
341
  preload = "none",
226
342
  onRefresh,
227
- showRefreshButton = false,
228
343
  onPlaybackError,
229
344
  playbackRateStorageKey = "scalemule:audio:playback-rate",
230
345
  exclusivePlayback = true,
@@ -640,19 +755,9 @@ function PlayerSession({
640
755
  "\xD7"
641
756
  ]
642
757
  }
643
- ),
644
- onRefresh && showRefreshButton && /* @__PURE__ */ jsx(
645
- "button",
646
- {
647
- type: "button",
648
- className: "sm-audio__refresh",
649
- disabled: busy,
650
- onClick: () => void recover(true),
651
- children: "Refresh"
652
- }
653
758
  )
654
759
  ] }),
655
- (busy || error) && /* @__PURE__ */ jsx("p", { className: "sm-audio__status", role: "status", children: busy ? "Refreshing audio\u2026" : error })
760
+ (busy || error) && /* @__PURE__ */ jsx("p", { className: "sm-audio__status", role: "status", children: busy ? "Loading audio\u2026" : error })
656
761
  ]
657
762
  }
658
763
  );
package/dist/index.d.mts CHANGED
@@ -486,10 +486,11 @@ interface NarrationPlayerProps {
486
486
  narrationLabel?: string;
487
487
  refreshing?: boolean;
488
488
  onRefresh?: () => void | Promise<void>;
489
+ /** @deprecated No-op: no manual Refresh control is ever shown. */
489
490
  showRefreshButton?: boolean;
490
491
  onPlaybackError?: () => void;
491
492
  }
492
- declare function NarrationPlayer({ audio, className, providerLabel, narrationLabel, refreshing, onRefresh, showRefreshButton, onPlaybackError, }: NarrationPlayerProps): react_jsx_runtime.JSX.Element | null;
493
+ declare function NarrationPlayer({ audio, className, providerLabel, narrationLabel, refreshing, onRefresh, onPlaybackError, }: NarrationPlayerProps): react_jsx_runtime.JSX.Element | null;
493
494
 
494
495
  /**
495
496
  * Conversation kinds recognized by the chat realtime channel naming scheme.
package/dist/index.d.ts CHANGED
@@ -486,10 +486,11 @@ interface NarrationPlayerProps {
486
486
  narrationLabel?: string;
487
487
  refreshing?: boolean;
488
488
  onRefresh?: () => void | Promise<void>;
489
+ /** @deprecated No-op: no manual Refresh control is ever shown. */
489
490
  showRefreshButton?: boolean;
490
491
  onPlaybackError?: () => void;
491
492
  }
492
- declare function NarrationPlayer({ audio, className, providerLabel, narrationLabel, refreshing, onRefresh, showRefreshButton, onPlaybackError, }: NarrationPlayerProps): react_jsx_runtime.JSX.Element | null;
493
+ declare function NarrationPlayer({ audio, className, providerLabel, narrationLabel, refreshing, onRefresh, onPlaybackError, }: NarrationPlayerProps): react_jsx_runtime.JSX.Element | null;
493
494
 
494
495
  /**
495
496
  * Conversation kinds recognized by the chat realtime channel naming scheme.
package/dist/index.js CHANGED
@@ -2979,19 +2979,7 @@ var styles = {
2979
2979
  color: "#334155",
2980
2980
  boxShadow: "0 1px 3px rgba(15, 23, 42, 0.08)",
2981
2981
  cursor: "pointer"
2982
- },
2983
- refreshButton: {
2984
- borderRadius: "9999px",
2985
- border: "1px solid #cad5e2",
2986
- backgroundColor: "rgba(255, 255, 255, 0.75)",
2987
- padding: "0.5rem 1rem",
2988
- fontSize: "0.875rem",
2989
- fontWeight: 600,
2990
- color: "#334155",
2991
- cursor: "pointer"
2992
- },
2993
- disabled: { cursor: "not-allowed", opacity: 0.6 }
2994
- };
2982
+ }};
2995
2983
  function NarrationPlayer({
2996
2984
  audio,
2997
2985
  className,
@@ -2999,7 +2987,6 @@ function NarrationPlayer({
2999
2987
  narrationLabel = "AI-Narrated",
3000
2988
  refreshing = false,
3001
2989
  onRefresh,
3002
- showRefreshButton = false,
3003
2990
  onPlaybackError
3004
2991
  }) {
3005
2992
  const audioRef = React.useRef(null);
@@ -3130,12 +3117,6 @@ function NarrationPlayer({
3130
3117
  break;
3131
3118
  }
3132
3119
  }
3133
- function handleManualRefresh() {
3134
- if (!onRefresh || refreshing) return;
3135
- Promise.resolve(onRefresh()).catch(() => {
3136
- onPlaybackError?.();
3137
- });
3138
- }
3139
3120
  const progress = duration > 0 ? Math.min(1, currentTime / duration) : 0;
3140
3121
  const expiresLabel = audio.expires_at ? new Date(audio.expires_at).toLocaleTimeString([], {
3141
3122
  hour: "numeric",
@@ -3258,30 +3239,18 @@ function NarrationPlayer({
3258
3239
  ] })
3259
3240
  ] })
3260
3241
  ] }),
3261
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: styles.controls, children: [
3262
- /* @__PURE__ */ jsxRuntime.jsxs(
3263
- "button",
3264
- {
3265
- type: "button",
3266
- onClick: () => setSpeed((currentSpeed) => getNextSpeed(currentSpeed)),
3267
- style: styles.secondaryButton,
3268
- children: [
3269
- speed,
3270
- "\xD7"
3271
- ]
3272
- }
3273
- ),
3274
- onRefresh && showRefreshButton && /* @__PURE__ */ jsxRuntime.jsx(
3275
- "button",
3276
- {
3277
- type: "button",
3278
- onClick: handleManualRefresh,
3279
- disabled: refreshing,
3280
- style: refreshing ? { ...styles.refreshButton, ...styles.disabled } : styles.refreshButton,
3281
- children: refreshing ? "Refreshing\u2026" : "Refresh"
3282
- }
3283
- )
3284
- ] })
3242
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: styles.controls, children: /* @__PURE__ */ jsxRuntime.jsxs(
3243
+ "button",
3244
+ {
3245
+ type: "button",
3246
+ onClick: () => setSpeed((currentSpeed) => getNextSpeed(currentSpeed)),
3247
+ style: styles.secondaryButton,
3248
+ children: [
3249
+ speed,
3250
+ "\xD7"
3251
+ ]
3252
+ }
3253
+ ) })
3285
3254
  ] })
3286
3255
  ] });
3287
3256
  }
package/dist/index.mjs CHANGED
@@ -2959,19 +2959,7 @@ var styles = {
2959
2959
  color: "#334155",
2960
2960
  boxShadow: "0 1px 3px rgba(15, 23, 42, 0.08)",
2961
2961
  cursor: "pointer"
2962
- },
2963
- refreshButton: {
2964
- borderRadius: "9999px",
2965
- border: "1px solid #cad5e2",
2966
- backgroundColor: "rgba(255, 255, 255, 0.75)",
2967
- padding: "0.5rem 1rem",
2968
- fontSize: "0.875rem",
2969
- fontWeight: 600,
2970
- color: "#334155",
2971
- cursor: "pointer"
2972
- },
2973
- disabled: { cursor: "not-allowed", opacity: 0.6 }
2974
- };
2962
+ }};
2975
2963
  function NarrationPlayer({
2976
2964
  audio,
2977
2965
  className,
@@ -2979,7 +2967,6 @@ function NarrationPlayer({
2979
2967
  narrationLabel = "AI-Narrated",
2980
2968
  refreshing = false,
2981
2969
  onRefresh,
2982
- showRefreshButton = false,
2983
2970
  onPlaybackError
2984
2971
  }) {
2985
2972
  const audioRef = useRef(null);
@@ -3110,12 +3097,6 @@ function NarrationPlayer({
3110
3097
  break;
3111
3098
  }
3112
3099
  }
3113
- function handleManualRefresh() {
3114
- if (!onRefresh || refreshing) return;
3115
- Promise.resolve(onRefresh()).catch(() => {
3116
- onPlaybackError?.();
3117
- });
3118
- }
3119
3100
  const progress = duration > 0 ? Math.min(1, currentTime / duration) : 0;
3120
3101
  const expiresLabel = audio.expires_at ? new Date(audio.expires_at).toLocaleTimeString([], {
3121
3102
  hour: "numeric",
@@ -3238,30 +3219,18 @@ function NarrationPlayer({
3238
3219
  ] })
3239
3220
  ] })
3240
3221
  ] }),
3241
- /* @__PURE__ */ jsxs("div", { style: styles.controls, children: [
3242
- /* @__PURE__ */ jsxs(
3243
- "button",
3244
- {
3245
- type: "button",
3246
- onClick: () => setSpeed((currentSpeed) => getNextSpeed(currentSpeed)),
3247
- style: styles.secondaryButton,
3248
- children: [
3249
- speed,
3250
- "\xD7"
3251
- ]
3252
- }
3253
- ),
3254
- onRefresh && showRefreshButton && /* @__PURE__ */ jsx(
3255
- "button",
3256
- {
3257
- type: "button",
3258
- onClick: handleManualRefresh,
3259
- disabled: refreshing,
3260
- style: refreshing ? { ...styles.refreshButton, ...styles.disabled } : styles.refreshButton,
3261
- children: refreshing ? "Refreshing\u2026" : "Refresh"
3262
- }
3263
- )
3264
- ] })
3222
+ /* @__PURE__ */ jsx("div", { style: styles.controls, children: /* @__PURE__ */ jsxs(
3223
+ "button",
3224
+ {
3225
+ type: "button",
3226
+ onClick: () => setSpeed((currentSpeed) => getNextSpeed(currentSpeed)),
3227
+ style: styles.secondaryButton,
3228
+ children: [
3229
+ speed,
3230
+ "\xD7"
3231
+ ]
3232
+ }
3233
+ ) })
3265
3234
  ] })
3266
3235
  ] });
3267
3236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.1.45",
3
+ "version": "0.1.47",
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",