@bendyline/squisq-react 2.12.23 → 2.12.25

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.
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  LinearDocView
3
- } from "./chunk-6LM6HDKH.js";
3
+ } from "./chunk-L3PODEKP.js";
4
4
  import {
5
5
  useAudioSync,
6
6
  useDocPlayback,
7
7
  useMediaSchedule,
8
8
  useViewportOrientation
9
- } from "./chunk-TVYZINUR.js";
9
+ } from "./chunk-UUGOEH5Q.js";
10
10
  import {
11
11
  useAutoSurface
12
12
  } from "./chunk-TT6ENR6T.js";
@@ -15,11 +15,11 @@ import {
15
15
  } from "./chunk-OWC7DNGJ.js";
16
16
  import {
17
17
  BlockRenderer
18
- } from "./chunk-4HVJHRL5.js";
18
+ } from "./chunk-HPABEDRG.js";
19
19
  import {
20
20
  isCaptureDrivenVideo,
21
21
  seekVideoToFrame
22
- } from "./chunk-IPB22WG3.js";
22
+ } from "./chunk-E7TEWUNF.js";
23
23
  import {
24
24
  useMediaProvider,
25
25
  useMediaUrl,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LinearDocView
3
- } from "./chunk-6LM6HDKH.js";
3
+ } from "./chunk-L3PODEKP.js";
4
4
 
5
5
  // src/PaginatedDocView.tsx
6
6
  import {
@@ -1842,13 +1842,15 @@ function TableLayer({
1842
1842
  return a ? { textAlign: a } : void 0;
1843
1843
  };
1844
1844
  const borderRadius = style.borderRadius ?? 8;
1845
+ const frame = `1px solid ${style.borderColor}`;
1845
1846
  const verticalCellPadding = style.fontSize * 0.6;
1846
1847
  const horizontalCellPadding = style.fontSize * 0.75;
1848
+ const cellWrap = content.wrap ? { whiteSpace: "pre-line", overflowWrap: "break-word", verticalAlign: "top" } : { whiteSpace: "nowrap" };
1847
1849
  const nativeTable = /* @__PURE__ */ jsxs6(
1848
1850
  "table",
1849
1851
  {
1850
1852
  style: {
1851
- width: "max-content",
1853
+ width: content.wrap ? "100%" : "max-content",
1852
1854
  minWidth: "100%",
1853
1855
  borderCollapse: "separate",
1854
1856
  borderSpacing: 0,
@@ -1869,7 +1871,7 @@ function TableLayer({
1869
1871
  position: "sticky",
1870
1872
  top: 0,
1871
1873
  zIndex: 1,
1872
- whiteSpace: "nowrap",
1874
+ ...cellWrap,
1873
1875
  borderBottom: `2px solid ${style.borderColor}`,
1874
1876
  borderRight: ci < headers.length - 1 ? `1px solid ${style.borderColor}` : void 0,
1875
1877
  ...cellAlign(ci)
@@ -1885,7 +1887,7 @@ function TableLayer({
1885
1887
  background: style.cellBackground,
1886
1888
  color: style.cellColor,
1887
1889
  padding: `${verticalCellPadding}px ${horizontalCellPadding}px`,
1888
- whiteSpace: "nowrap",
1890
+ ...cellWrap,
1889
1891
  borderBottom: ri < rows.length - 1 ? `1px solid ${style.borderColor}` : void 0,
1890
1892
  borderRight: ci < row.length - 1 ? `1px solid ${style.borderColor}` : void 0,
1891
1893
  ...cellAlign(ci)
@@ -1922,10 +1924,10 @@ function TableLayer({
1922
1924
  boxSizing: "border-box",
1923
1925
  overflow: ContentRenderer ? "hidden" : "auto",
1924
1926
  overscrollBehavior: "contain",
1925
- scrollbarGutter: "stable",
1926
- border: ContentRenderer ? void 0 : `1px solid ${style.borderColor}`,
1927
+ scrollbarGutter: content.wrap ? "auto" : "stable",
1928
+ border: ContentRenderer || content.wrap ? void 0 : frame,
1927
1929
  borderRadius: `${borderRadius}px`,
1928
- background: ContentRenderer ? "transparent" : style.cellBackground
1930
+ background: ContentRenderer || content.wrap ? "transparent" : style.cellBackground
1929
1931
  },
1930
1932
  children: ContentRenderer ? /* @__PURE__ */ jsx8(
1931
1933
  ContentRenderer,
@@ -1936,6 +1938,10 @@ function TableLayer({
1936
1938
  height,
1937
1939
  fallback: nativeTable
1938
1940
  }
1941
+ ) : content.wrap ? (
1942
+ // A fitted table is framed at its own height, so the spare room its
1943
+ // box keeps for the type estimate stays invisible.
1944
+ /* @__PURE__ */ jsx8("div", { style: { border: frame, borderRadius: `${borderRadius}px`, overflow: "hidden" }, children: nativeTable })
1939
1945
  ) : nativeTable
1940
1946
  }
1941
1947
  ) })
@@ -12,7 +12,7 @@ import {
12
12
  getAnchorOffset,
13
13
  getTransitionClass,
14
14
  resolveValue
15
- } from "./chunk-IPB22WG3.js";
15
+ } from "./chunk-E7TEWUNF.js";
16
16
 
17
17
  // src/BlockRenderer.tsx
18
18
  import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
@@ -253,6 +253,17 @@ function overlapPairs(rects) {
253
253
  }
254
254
  return pairs;
255
255
  }
256
+ function stepEntranceDelays(layers) {
257
+ const delays = /* @__PURE__ */ new Map();
258
+ for (const layer of layers ?? []) {
259
+ if (layer.buildStep === void 0 || !layer.animation || layer.animation.type === "none")
260
+ continue;
261
+ const delay = layer.animation.delay ?? 0;
262
+ const current = delays.get(layer.buildStep);
263
+ if (current === void 0 || delay < current) delays.set(layer.buildStep, delay);
264
+ }
265
+ return delays;
266
+ }
256
267
  function BlockRenderer({
257
268
  block,
258
269
  buildPlayback = "all",
@@ -292,6 +303,8 @@ function BlockRenderer({
292
303
  () => block.build ? resolveBuildTimeline(steps, block.build, block.duration, block.buildTiming) : void 0,
293
304
  [steps, block.build, block.duration, block.buildTiming]
294
305
  );
306
+ const entranceDelays = useMemo(() => stepEntranceDelays(block.layers), [block.layers]);
307
+ const shownSteps = useRef(null);
295
308
  const [reducedMotion, setReducedMotion] = useState(false);
296
309
  useEffect(() => {
297
310
  if (!respectReducedMotion) {
@@ -311,6 +324,9 @@ function BlockRenderer({
311
324
  const cursor = buildPlayback === "all" || !timeline ? { revealed: steps.length, progress: 1 } : buildPlayback === "timed" ? buildCursorAtTime(timeline, blockTime) : buildPlayback;
312
325
  svg.dataset.buildRevealed = String(cursor.revealed);
313
326
  svg.dataset.buildCount = String(steps.length);
327
+ const motion = animationsEnabled && !reducedMotion;
328
+ const shown = shownSteps.current?.block === block ? shownSteps.current.revealed : void 0;
329
+ shownSteps.current = { block, revealed: cursor.revealed };
314
330
  for (const target of svg.querySelectorAll("[data-squisq-build-step]")) {
315
331
  const index = Number(target.dataset.squisqBuildStep);
316
332
  if (!Number.isInteger(index) || index < 0 || index >= steps.length || !block.build) {
@@ -318,16 +334,19 @@ function BlockRenderer({
318
334
  target.style.opacity = "1";
319
335
  target.style.transform = "";
320
336
  target.style.pointerEvents = "";
337
+ target.style.removeProperty("--squisq-step-offset");
321
338
  target.removeAttribute("aria-hidden");
322
339
  target.removeAttribute("inert");
323
340
  continue;
324
341
  }
342
+ const delay = entranceDelays.get(index);
343
+ const spec = buildPlayback === "all" ? { ...block.build, previous: "keep" } : block.build;
325
344
  const state = buildTargetState(
326
345
  index,
327
346
  steps,
328
347
  cursor,
329
- buildPlayback === "all" ? { ...block.build, previous: "keep" } : block.build,
330
- animationsEnabled && !reducedMotion
348
+ delay === void 0 ? spec : { ...spec, effect: "appear" },
349
+ motion
331
350
  );
332
351
  target.style.visibility = state.hidden ? "hidden" : "visible";
333
352
  target.style.opacity = String(state.opacity);
@@ -335,8 +354,30 @@ function BlockRenderer({
335
354
  target.style.pointerEvents = state.hidden ? "none" : "";
336
355
  target.setAttribute("aria-hidden", String(state.hidden));
337
356
  target.toggleAttribute("inert", state.hidden);
357
+ if (delay === void 0) continue;
358
+ if (buildPlayback === "timed" && timeline)
359
+ target.style.setProperty(
360
+ "--squisq-step-offset",
361
+ `${Number((timeline.starts[index] - delay).toFixed(3))}s`
362
+ );
363
+ else target.style.removeProperty("--squisq-step-offset");
364
+ if (motion && typeof buildPlayback === "object" && shown !== void 0 && index >= shown && index < cursor.revealed) {
365
+ for (const animation of target.getAnimations?.({ subtree: true }) ?? []) {
366
+ animation.currentTime = delay * 1e3;
367
+ animation.play();
368
+ }
369
+ }
338
370
  }
339
- }, [block.build, steps, timeline, blockTime, buildPlayback, animationsEnabled, reducedMotion]);
371
+ }, [
372
+ block,
373
+ steps,
374
+ timeline,
375
+ entranceDelays,
376
+ blockTime,
377
+ buildPlayback,
378
+ animationsEnabled,
379
+ reducedMotion
380
+ ]);
340
381
  const growText = growTextToFit && !isGeometryBoundTemplate(block.template);
341
382
  useLayoutEffect(() => {
342
383
  const svg = svgRef.current;
@@ -389,26 +430,29 @@ function BlockRenderer({
389
430
  "data-squisq-text-scale": growText ? textScale : void 0,
390
431
  children: [
391
432
  /* @__PURE__ */ jsx2("defs", { children: /* @__PURE__ */ jsx2("clipPath", { id: clipId, children: /* @__PURE__ */ jsx2("rect", { x: "0", y: "0", width: viewport.width, height: viewport.height }) }) }),
392
- /* @__PURE__ */ jsx2("g", { clipPath: `url(#${clipId})`, children: (block.layers ?? []).map((layer) => /* @__PURE__ */ jsx2(
393
- LayerRenderer,
394
- {
395
- block,
396
- layer,
397
- basePath,
398
- viewport,
399
- blockTime,
400
- isPlaying,
401
- muted,
402
- animationsEnabled,
403
- theme,
404
- tableContentRenderer,
405
- textScale,
406
- videoEmbeds,
407
- videoClips,
408
- staticMedia: staticMedia || reducedMotion || !animationsEnabled
409
- },
410
- layer.id
411
- )) })
433
+ /* @__PURE__ */ jsx2("g", { clipPath: `url(#${clipId})`, children: (block.layers ?? []).map((layer) => {
434
+ const rendered = /* @__PURE__ */ jsx2(
435
+ LayerRenderer,
436
+ {
437
+ block,
438
+ layer,
439
+ basePath,
440
+ viewport,
441
+ blockTime,
442
+ isPlaying,
443
+ muted,
444
+ animationsEnabled,
445
+ theme,
446
+ tableContentRenderer,
447
+ textScale,
448
+ videoEmbeds,
449
+ videoClips,
450
+ staticMedia: staticMedia || reducedMotion || !animationsEnabled
451
+ },
452
+ layer.id
453
+ );
454
+ return layer.buildStep === void 0 ? rendered : /* @__PURE__ */ jsx2("g", { "data-squisq-build-step": layer.buildStep, children: rendered }, layer.id);
455
+ }) })
412
456
  ]
413
457
  }
414
458
  );
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-OWC7DNGJ.js";
9
9
  import {
10
10
  BlockRenderer
11
- } from "./chunk-4HVJHRL5.js";
11
+ } from "./chunk-HPABEDRG.js";
12
12
  import {
13
13
  svgDataImageSrc,
14
14
  useMediaUrl
@@ -64,6 +64,33 @@ function isBenignPlayRejection(error) {
64
64
  if (!(error instanceof Error)) return false;
65
65
  return error.name === "NotAllowedError" || error.name === "AbortError";
66
66
  }
67
+ var LOAD_RETRY_DELAYS_MS = [1e3, 3e3, 8e3];
68
+ function waitToRetry(delayMs, signal) {
69
+ return new Promise((resolve) => {
70
+ if (signal.aborted) {
71
+ resolve();
72
+ return;
73
+ }
74
+ let timer;
75
+ const hasDocument = typeof document !== "undefined";
76
+ const ready = () => (!hasDocument || document.visibilityState !== "hidden") && (typeof navigator === "undefined" || navigator.onLine !== false);
77
+ const finish = () => {
78
+ clearTimeout(timer);
79
+ if (hasDocument) document.removeEventListener("visibilitychange", check);
80
+ if (typeof window !== "undefined") window.removeEventListener("online", check);
81
+ signal.removeEventListener("abort", finish);
82
+ resolve();
83
+ };
84
+ function check() {
85
+ clearTimeout(timer);
86
+ timer = ready() ? setTimeout(finish, delayMs) : void 0;
87
+ }
88
+ signal.addEventListener("abort", finish);
89
+ if (hasDocument) document.addEventListener("visibilitychange", check);
90
+ if (typeof window !== "undefined") window.addEventListener("online", check);
91
+ check();
92
+ });
93
+ }
67
94
  function resolveAudioUrl(src, basePath) {
68
95
  if (!src || /^(?:[a-z][a-z0-9+.-]*:|\/\/|\/)/i.test(src)) return src;
69
96
  if (!basePath) return src;
@@ -284,6 +311,9 @@ function useAudioSync(audioRef, track, basePath = "", enabled = true, mode = "me
284
311
  const segment = audioTrack.segments[currentSegment];
285
312
  if (!segment) return;
286
313
  const applyPendingSeek = () => {
314
+ if (pendingSeekTime.current !== null && findSegmentAtTime(pendingSeekTime.current, audioTrack.segments, segmentStarts.current).segmentIndex !== currentSegment) {
315
+ return;
316
+ }
287
317
  if (pendingSeekTime.current !== null) {
288
318
  const segmentStart = segmentStarts.current[currentSegment] || 0;
289
319
  const segmentTime = pendingSeekTime.current - segmentStart;
@@ -314,10 +344,21 @@ function useAudioSync(audioRef, track, basePath = "", enabled = true, mode = "me
314
344
  const isSameSource = isBoundTo(audio, segment.src);
315
345
  let cancelled = false;
316
346
  let handleCanPlay = null;
347
+ const retryAbort = new AbortController();
317
348
  if (!isSameSource) {
318
349
  const loadAndPlay = async () => {
319
350
  loadingSegment.current = segment.src;
320
- const blobUrl = await preloadAudio(segment.src);
351
+ let blobUrl = await preloadAudio(segment.src);
352
+ const fetchable = isResourceUrlAllowed(
353
+ resolveAudioUrl(segment.src, basePath),
354
+ resourcePolicy
355
+ );
356
+ for (const delay of LOAD_RETRY_DELAYS_MS) {
357
+ if (blobUrl || cancelled || !fetchable) break;
358
+ await waitToRetry(delay, retryAbort.signal);
359
+ if (cancelled) return;
360
+ blobUrl = await preloadAudio(segment.src);
361
+ }
321
362
  if (cancelled) return;
322
363
  loadingSegment.current = null;
323
364
  if (!blobUrl) {
@@ -363,9 +404,20 @@ function useAudioSync(audioRef, track, basePath = "", enabled = true, mode = "me
363
404
  }
364
405
  return () => {
365
406
  cancelled = true;
407
+ retryAbort.abort();
366
408
  if (handleCanPlay) audio.removeEventListener("canplay", handleCanPlay);
367
409
  };
368
- }, [audioRef, currentSegment, audioTrack, preloadAudio, enabled, mode, isBoundTo]);
410
+ }, [
411
+ audioRef,
412
+ currentSegment,
413
+ audioTrack,
414
+ preloadAudio,
415
+ enabled,
416
+ mode,
417
+ isBoundTo,
418
+ basePath,
419
+ resourcePolicy
420
+ ]);
369
421
  const seekTo = useCallback(
370
422
  async (time) => {
371
423
  const audio = audioRef.current;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BlockRenderer
3
- } from "../chunk-4HVJHRL5.js";
4
- import "../chunk-IPB22WG3.js";
3
+ } from "../chunk-HPABEDRG.js";
4
+ import "../chunk-E7TEWUNF.js";
5
5
  import "../chunk-A65WPCGZ.js";
6
6
  import {
7
7
  renderMermaidSvgForExport
@@ -35,6 +35,11 @@ import { ResourcePolicy } from '@bendyline/squisq/markdown';
35
35
  * seeking after it crosses a chapter boundary), because the element still
36
36
  * holds the previous segment. The next segment is downloaded shortly before the
37
37
  * current one ends, so chapter boundaries do not stall on a fresh download.
38
+ *
39
+ * A segment whose download fails is retried a few times before the narration
40
+ * is reported unavailable, and the waits only count while the page is visible
41
+ * and online. A phone app in the background can lose its network; the segment
42
+ * that failed there now loads, and plays on, when the listener comes back.
38
43
  */
39
44
 
40
45
  type AudioSyncMode = 'media' | 'synthetic';
@@ -6,7 +6,7 @@ import {
6
6
  useDocPlayback,
7
7
  useMediaSchedule,
8
8
  useViewportOrientation
9
- } from "../chunk-TVYZINUR.js";
9
+ } from "../chunk-UUGOEH5Q.js";
10
10
  import {
11
11
  useAutoSurface
12
12
  } from "../chunk-TT6ENR6T.js";
package/dist/index.js CHANGED
@@ -17,17 +17,17 @@ import {
17
17
  resolveDocPlayerAppearance,
18
18
  useBuildNavigation,
19
19
  useMediaClipDurations
20
- } from "./chunk-2DUF6C7B.js";
20
+ } from "./chunk-2GNCILIQ.js";
21
21
  import {
22
22
  PaginatedDocView
23
- } from "./chunk-MIJNUVEL.js";
23
+ } from "./chunk-74MMSPTK.js";
24
24
  import {
25
25
  CanvasSection,
26
26
  LinearDocView,
27
27
  PageSectionView,
28
28
  PageViewContext,
29
29
  usePageView
30
- } from "./chunk-6LM6HDKH.js";
30
+ } from "./chunk-L3PODEKP.js";
31
31
  import {
32
32
  useModalDialog
33
33
  } from "./chunk-JP457U6N.js";
@@ -36,7 +36,7 @@ import {
36
36
  useDocPlayback,
37
37
  useMediaSchedule,
38
38
  useViewportOrientation
39
- } from "./chunk-TVYZINUR.js";
39
+ } from "./chunk-UUGOEH5Q.js";
40
40
  import {
41
41
  JsonView,
42
42
  createJsonFormFenceRenderer
@@ -57,7 +57,7 @@ import {
57
57
  } from "./chunk-OWC7DNGJ.js";
58
58
  import {
59
59
  BlockRenderer
60
- } from "./chunk-4HVJHRL5.js";
60
+ } from "./chunk-HPABEDRG.js";
61
61
  import {
62
62
  ImageLayer,
63
63
  MapLayer,
@@ -71,7 +71,7 @@ import {
71
71
  VideoLayer,
72
72
  getAnimationStyle,
73
73
  getTransitionClass
74
- } from "./chunk-IPB22WG3.js";
74
+ } from "./chunk-E7TEWUNF.js";
75
75
  import {
76
76
  MermaidDiagram
77
77
  } from "./chunk-A65WPCGZ.js";
@@ -9,7 +9,7 @@ import {
9
9
  TextLayer,
10
10
  TreeLayer,
11
11
  VideoLayer
12
- } from "../chunk-IPB22WG3.js";
12
+ } from "../chunk-E7TEWUNF.js";
13
13
  import "../chunk-A65WPCGZ.js";
14
14
  import "../chunk-OTYJ4MRH.js";
15
15
  export {
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  PaginatedDocView
3
- } from "../chunk-MIJNUVEL.js";
3
+ } from "../chunk-74MMSPTK.js";
4
4
  import {
5
5
  CanvasSection,
6
6
  LinearDocView,
7
7
  PageSectionView,
8
8
  PageViewContext,
9
9
  usePageView
10
- } from "../chunk-6LM6HDKH.js";
10
+ } from "../chunk-L3PODEKP.js";
11
11
  import "../chunk-TT6ENR6T.js";
12
12
  import "../chunk-OWC7DNGJ.js";
13
- import "../chunk-4HVJHRL5.js";
14
- import "../chunk-IPB22WG3.js";
13
+ import "../chunk-HPABEDRG.js";
14
+ import "../chunk-E7TEWUNF.js";
15
15
  import "../chunk-A65WPCGZ.js";
16
16
  import "../chunk-OTYJ4MRH.js";
17
17
  export {
@@ -12,9 +12,9 @@ import {
12
12
  MediaClipLayer,
13
13
  SocialCaptionOverlay,
14
14
  formatTime
15
- } from "../chunk-2DUF6C7B.js";
16
- import "../chunk-6LM6HDKH.js";
17
- import "../chunk-TVYZINUR.js";
15
+ } from "../chunk-2GNCILIQ.js";
16
+ import "../chunk-L3PODEKP.js";
17
+ import "../chunk-UUGOEH5Q.js";
18
18
  import "../chunk-TT6ENR6T.js";
19
19
  import {
20
20
  InlineAudioPlayer,
@@ -22,8 +22,8 @@ import {
22
22
  } from "../chunk-OWC7DNGJ.js";
23
23
  import {
24
24
  BlockRenderer
25
- } from "../chunk-4HVJHRL5.js";
26
- import "../chunk-IPB22WG3.js";
25
+ } from "../chunk-HPABEDRG.js";
26
+ import "../chunk-E7TEWUNF.js";
27
27
  import "../chunk-A65WPCGZ.js";
28
28
  import "../chunk-OTYJ4MRH.js";
29
29
  export {