@bendyline/squisq-react 2.4.4 → 2.4.5

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.
@@ -1545,6 +1545,14 @@ var VIDEO_TIME_TOLERANCE_SECONDS = 0.01;
1545
1545
  function formatMediaTime(time) {
1546
1546
  return Number.isFinite(time) ? `${time.toFixed(3)}s` : String(time);
1547
1547
  }
1548
+ function reachableMediaTime(video, targetTime) {
1549
+ const duration = video.duration;
1550
+ if (!Number.isFinite(duration)) return targetTime;
1551
+ return Math.max(0, Math.min(targetTime, duration));
1552
+ }
1553
+ function isAtReachableMediaTime(video, targetTime) {
1554
+ return Math.abs(video.currentTime - reachableMediaTime(video, targetTime)) <= VIDEO_TIME_TOLERANCE_SECONDS;
1555
+ }
1548
1556
  function isVisiblyPresented(video) {
1549
1557
  if (!video.isConnected) return false;
1550
1558
  const view = video.ownerDocument.defaultView;
@@ -1559,7 +1567,7 @@ function isVisiblyPresented(video) {
1559
1567
  }
1560
1568
  function seekVideoToFrame(video, targetTime, timeoutMs = DEFAULT_VIDEO_FRAME_TIMEOUT_MS) {
1561
1569
  video.pause();
1562
- const alreadyReady = !video.seeking && video.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && Math.abs(video.currentTime - targetTime) <= VIDEO_TIME_TOLERANCE_SECONDS;
1570
+ const alreadyReady = !video.seeking && video.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && isAtReachableMediaTime(video, targetTime);
1563
1571
  if (alreadyReady) return Promise.resolve();
1564
1572
  return new Promise((resolve, reject) => {
1565
1573
  let settled = false;
@@ -1586,12 +1594,12 @@ function seekVideoToFrame(video, targetTime, timeoutMs = DEFAULT_VIDEO_FRAME_TIM
1586
1594
  cleanup();
1587
1595
  reject(
1588
1596
  new Error(
1589
- `Video frame did not become ready at ${formatMediaTime(targetTime)} within ${timeoutMs}ms (currentTime=${formatMediaTime(video.currentTime)}, readyState=${video.readyState}, seeking=${String(video.seeking)}, visible=${String(isVisiblyPresented(video))}).`
1597
+ `Video frame did not become ready at ${formatMediaTime(targetTime)} within ${timeoutMs}ms (currentTime=${formatMediaTime(video.currentTime)}, reachableTime=${formatMediaTime(reachableMediaTime(video, targetTime))}, duration=${formatMediaTime(video.duration)}, readyState=${video.readyState}, seeking=${String(video.seeking)}, visible=${String(isVisiblyPresented(video))}).`
1590
1598
  )
1591
1599
  );
1592
1600
  };
1593
1601
  const requestPresentedFrame = () => {
1594
- if (settled || video.seeking || video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || Math.abs(video.currentTime - targetTime) > VIDEO_TIME_TOLERANCE_SECONDS) {
1602
+ if (settled || video.seeking || video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || !isAtReachableMediaTime(video, targetTime)) {
1595
1603
  return;
1596
1604
  }
1597
1605
  if (typeof video.requestVideoFrameCallback !== "function" || !isVisiblyPresented(video)) {
@@ -1613,7 +1621,7 @@ function seekVideoToFrame(video, targetTime, timeoutMs = DEFAULT_VIDEO_FRAME_TIM
1613
1621
  video.addEventListener("loadeddata", handleMediaReady);
1614
1622
  video.addEventListener("canplay", handleMediaReady);
1615
1623
  try {
1616
- video.currentTime = targetTime;
1624
+ video.currentTime = reachableMediaTime(video, targetTime);
1617
1625
  queueMicrotask(requestPresentedFrame);
1618
1626
  } catch (error) {
1619
1627
  settled = true;
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  formatTime,
13
13
  resolveDocPlayerAppearance,
14
14
  useMediaClipDurations
15
- } from "./chunk-AKPXDG4E.js";
15
+ } from "./chunk-A4VLH2US.js";
16
16
  import {
17
17
  BlockRenderer,
18
18
  CanvasSection,
@@ -10,7 +10,7 @@ import {
10
10
  MediaClipLayer,
11
11
  SocialCaptionOverlay,
12
12
  formatTime
13
- } from "../chunk-AKPXDG4E.js";
13
+ } from "../chunk-A4VLH2US.js";
14
14
  import {
15
15
  BlockRenderer
16
16
  } from "../chunk-EJMUO6VX.js";