@bendyline/squisq-react 2.12.28 → 2.12.30

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.
@@ -12,7 +12,7 @@ import {
12
12
  getAnchorOffset,
13
13
  getTransitionClass,
14
14
  resolveValue
15
- } from "./chunk-DRPMS5JK.js";
15
+ } from "./chunk-755MBX5E.js";
16
16
 
17
17
  // src/BlockRenderer.tsx
18
18
  import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
@@ -170,6 +170,18 @@ function VideoEmbedLayer({ layer, viewport, mode = "poster" }) {
170
170
  }
171
171
 
172
172
  // src/utils/textFit.ts
173
+ var MIN_SHRUNK_TEXT_SCALE = 0.75;
174
+ function largestShrunkTextScale(fits, minimum = MIN_SHRUNK_TEXT_SCALE) {
175
+ if (minimum >= 1 || !fits(minimum)) return 1;
176
+ let low = minimum;
177
+ let high = 1;
178
+ for (let attempt = 0; attempt < 8; attempt += 1) {
179
+ const candidate = (low + high) / 2;
180
+ if (fits(candidate)) low = candidate;
181
+ else high = candidate;
182
+ }
183
+ return Math.max(minimum, Math.floor(low * 100) / 100);
184
+ }
173
185
  function largestFittingTextScale(fits, maximum = 2) {
174
186
  if (maximum <= 1 || !fits(1)) return 1;
175
187
  if (fits(maximum)) return maximum;
@@ -204,7 +216,13 @@ function cssPixels(value) {
204
216
  const parsed = parseFloat(value);
205
217
  return Number.isFinite(parsed) ? parsed : 0;
206
218
  }
207
- function htmlTargetFits(target) {
219
+ function htmlTextClipped(target) {
220
+ if (target.dataset.squisqTextFit !== "html") return false;
221
+ const content = target.querySelector('[data-squisq-text-content="true"]');
222
+ if (!content || content.scrollWidth <= 0 || content.scrollHeight <= 0) return false;
223
+ return !htmlTargetFits(target, false);
224
+ }
225
+ function htmlTargetFits(target, includeScrollRegions = true) {
208
226
  const content = target.querySelector('[data-squisq-text-content="true"]');
209
227
  if (!content || content.scrollWidth <= 0 || content.scrollHeight <= 0) return false;
210
228
  const view = target.ownerDocument.defaultView;
@@ -216,6 +234,7 @@ function htmlTargetFits(target) {
216
234
  if (content.scrollWidth > availableWidth + FIT_TOLERANCE_PX || content.scrollHeight > availableHeight + FIT_TOLERANCE_PX) {
217
235
  return false;
218
236
  }
237
+ if (!includeScrollRegions) return true;
219
238
  for (const scrollRegion of content.querySelectorAll("[data-squisq-table-scroll]")) {
220
239
  if (scrollRegion.clientWidth > 0 && scrollRegion.scrollWidth > scrollRegion.clientWidth + FIT_TOLERANCE_PX || scrollRegion.clientHeight > 0 && scrollRegion.scrollHeight > scrollRegion.clientHeight + FIT_TOLERANCE_PX) {
221
240
  return false;
@@ -280,6 +299,7 @@ function BlockRenderer({
280
299
  theme,
281
300
  tableContentRenderer,
282
301
  growTextToFit = false,
302
+ shrinkTextToFit = true,
283
303
  videoEmbeds = "poster",
284
304
  videoClips = "timed",
285
305
  staticMedia = false
@@ -385,7 +405,9 @@ function BlockRenderer({
385
405
  const delay = entranceDelays.get(layer.buildStep);
386
406
  return start === void 0 || delay === void 0 ? 0 : start - delay;
387
407
  };
388
- const growText = growTextToFit && !isGeometryBoundTemplate(block.template);
408
+ const fitsText = !isGeometryBoundTemplate(block.template);
409
+ const growText = growTextToFit && fitsText;
410
+ const shrinkText = shrinkTextToFit && fitsText;
389
411
  useLayoutEffect(() => {
390
412
  const svg = svgRef.current;
391
413
  let cancelled = false;
@@ -393,12 +415,24 @@ function BlockRenderer({
393
415
  const measure = () => {
394
416
  if (cancelled) return;
395
417
  const targets = Array.from(svg.querySelectorAll("[data-squisq-text-fit]"));
396
- if (!growText || targets.length === 0) {
397
- applyTextScale(targets, 1);
418
+ applyTextScale(targets, 1);
419
+ if (!growText && !shrinkText || targets.length === 0) {
420
+ setTextScale(1);
421
+ return;
422
+ }
423
+ if (shrinkText && targets.some(htmlTextClipped)) {
424
+ const shrunk = largestShrunkTextScale((scale) => {
425
+ applyTextScale(targets, scale);
426
+ return !targets.some(htmlTextClipped);
427
+ });
428
+ applyTextScale(targets, shrunk);
429
+ setTextScale((current) => current === shrunk ? current : shrunk);
430
+ return;
431
+ }
432
+ if (!growText) {
398
433
  setTextScale(1);
399
434
  return;
400
435
  }
401
- applyTextScale(targets, 1);
402
436
  const baselineOverlaps = overlapPairs(renderedTextRects(targets));
403
437
  const fits = (scale) => {
404
438
  applyTextScale(targets, scale);
@@ -420,10 +454,12 @@ function BlockRenderer({
420
454
  measure();
421
455
  const fonts = svg.ownerDocument?.fonts;
422
456
  if (fonts && fonts.status !== "loaded") void fonts.ready.then(measure);
457
+ fonts?.addEventListener?.("loadingdone", measure);
423
458
  return () => {
424
459
  cancelled = true;
460
+ fonts?.removeEventListener?.("loadingdone", measure);
425
461
  };
426
- }, [block.layers, growText, viewport.height, viewport.width]);
462
+ }, [block.layers, growText, shrinkText, viewport.height, viewport.width]);
427
463
  return /* @__PURE__ */ jsxs2(
428
464
  "svg",
429
465
  {
@@ -434,7 +470,7 @@ function BlockRenderer({
434
470
  preserveAspectRatio: "xMidYMid meet",
435
471
  overflow: "hidden",
436
472
  "data-block-id": block.id,
437
- "data-squisq-text-scale": growText ? textScale : void 0,
473
+ "data-squisq-text-scale": growText || textScale !== 1 ? textScale : void 0,
438
474
  children: [
439
475
  /* @__PURE__ */ jsx2("defs", { children: /* @__PURE__ */ jsx2("clipPath", { id: clipId, children: /* @__PURE__ */ jsx2("rect", { x: "0", y: "0", width: viewport.width, height: viewport.height }) }) }),
440
476
  /* @__PURE__ */ jsx2("g", { clipPath: `url(#${clipId})`, children: (block.layers ?? []).map((layer) => {
@@ -454,7 +490,8 @@ function BlockRenderer({
454
490
  textScale,
455
491
  videoEmbeds,
456
492
  videoClips,
457
- staticMedia: staticMedia || reducedMotion || !animationsEnabled
493
+ staticMedia: staticMedia || reducedMotion || !animationsEnabled,
494
+ capture: staticMedia
458
495
  },
459
496
  layer.id
460
497
  );
@@ -478,7 +515,8 @@ function LayerRenderer({
478
515
  textScale,
479
516
  videoEmbeds,
480
517
  videoClips,
481
- staticMedia
518
+ staticMedia,
519
+ capture
482
520
  }) {
483
521
  const renderedLayer = animationsEnabled || !layer.animation ? layer : { ...layer, animation: void 0 };
484
522
  switch (renderedLayer.type) {
@@ -528,7 +566,8 @@ function LayerRenderer({
528
566
  blockTime,
529
567
  isPlaying,
530
568
  muted,
531
- mode: videoClips
569
+ mode: videoClips,
570
+ capture
532
571
  }
533
572
  );
534
573
  case "videoEmbed":
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-CFJRBRRG.js";
9
9
  import {
10
10
  BlockRenderer
11
- } from "./chunk-3UITZDNL.js";
11
+ } from "./chunk-TCBV3WXF.js";
12
12
  import {
13
13
  svgDataImageSrc,
14
14
  useMediaUrl
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BlockRenderer
3
- } from "../chunk-3UITZDNL.js";
4
- import "../chunk-DRPMS5JK.js";
3
+ } from "../chunk-TCBV3WXF.js";
4
+ import "../chunk-755MBX5E.js";
5
5
  import "../chunk-FXAKS6KU.js";
6
6
  import {
7
7
  renderMermaidSvgForExport
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SquisqRenderAPI, V as VideoPresentation$1, P as PipSize, a as PipShape, b as PipPosition } from './player-B-2-utvs.js';
2
- export { B as BlockMarker, c as BlockRenderer, C as CaptionMode, d as CaptionOverlay, e as CaptionPosition, f as CaptionStyle, g as ControlsLayout, D as DisplayMode, h as DocControlsBottom, i as DocControlsOverlay, j as DocControlsSidebar, k as DocControlsSlideshow, l as DocPlayer, m as DocPlayerProps, n as DocPlayerWithSidebar, o as DocProgressBar, F as FlashcardFaceView, p as FlashcardFaceViewProps, q as FlashcardView, r as FlashcardViewProps, I as InlineAudioPlayer, s as InlineAudioPlayerProps, t as InlineVideoPlayer, u as InlineVideoPlayerProps, M as MediaClipLayer, v as MediaClipLayerProps, w as PlaybackActions, x as PlaybackState, R as RenderAudioSegmentInfo, y as RenderBlockInfo, z as RenderCaptionInfo, A as RenderChapterInfo, E as RenderVideoFrameSelector, G as SlideNavActions, H as SocialCaptionOverlay, J as formatTime } from './player-B-2-utvs.js';
1
+ import { S as SquisqRenderAPI, V as VideoPresentation$1, P as PipSize, a as PipShape, b as PipPosition } from './player-Wc6Nd4p5.js';
2
+ export { B as BlockMarker, c as BlockRenderer, C as CaptionMode, d as CaptionOverlay, e as CaptionPosition, f as CaptionStyle, g as ControlsLayout, D as DisplayMode, h as DocControlsBottom, i as DocControlsOverlay, j as DocControlsSidebar, k as DocControlsSlideshow, l as DocPlayer, m as DocPlayerProps, n as DocPlayerWithSidebar, o as DocProgressBar, F as FlashcardFaceView, p as FlashcardFaceViewProps, q as FlashcardView, r as FlashcardViewProps, I as InlineAudioPlayer, s as InlineAudioPlayerProps, t as InlineVideoPlayer, u as InlineVideoPlayerProps, M as MediaClipLayer, v as MediaClipLayerProps, w as PlaybackActions, x as PlaybackState, R as RenderAudioSegmentInfo, y as RenderBlockInfo, z as RenderCaptionInfo, A as RenderChapterInfo, E as RenderVideoFrameSelector, G as SlideNavActions, H as SocialCaptionOverlay, J as formatTime } from './player-Wc6Nd4p5.js';
3
3
  import { Theme, VideoPresentation, VideoPipSize, VideoPipShape, VideoPipPosition, MotionSpec, Doc, MediaProvider, ScheduledClip, Block, BuildCursor } from '@bendyline/squisq/schemas';
4
4
  import { DashboardStyleId, ViewportConfig, CoverSlideTemplate, CoverSlidePlayback } from '@bendyline/squisq/doc';
5
5
  export { getAnimationStyle, getTransitionClass } from '@bendyline/squisq/doc';
@@ -11,7 +11,7 @@ import * as react from 'react';
11
11
  import { ReactNode, RefObject, CSSProperties } from 'react';
12
12
  import { AnimatedImageInfo } from '@bendyline/squisq/imageEdit';
13
13
  export { ImageLayer, MapLayer, MermaidLayer, PathLayer, ShapeLayer, SvgLayer, TextLayer, TreeLayer } from './layers/index.js';
14
- export { T as TableLayer, a as TableLayerContentRenderer, b as TableLayerContentRendererProps, V as VideoLayer } from './VideoLayer-sT0mrnNQ.js';
14
+ export { T as TableLayer, a as TableLayerContentRenderer, b as TableLayerContentRendererProps, V as VideoLayer } from './VideoLayer-Bg3TRIOb.js';
15
15
  export { M as MediaContext, a as MediaScheduleController, b as ModalDialogOptions, P as ProcessedAudioContext, R as ResourcePolicyContext, U as UseDocPlaybackOptions, u as useAudioSync, c as useAutoSurface, d as useDocPlayback, e as useMediaProvider, f as useMediaSchedule, g as useMediaUrl, h as useModalDialog, i as useResourcePolicy, j as useViewportOrientation } from './hooks-Dxpfol0l.js';
16
16
  import { ResourcePolicy } from '@bendyline/squisq/markdown';
17
17
  import { MediaCrop, MediaCut, MediaTimeMap } from '@bendyline/squisq/mediaEdit';
package/dist/index.js CHANGED
@@ -20,17 +20,17 @@ import {
20
20
  useBuildNavigation,
21
21
  useMediaClipDurations,
22
22
  useVideoDurations
23
- } from "./chunk-NZHL2VKW.js";
23
+ } from "./chunk-4ZSAQ266.js";
24
24
  import {
25
25
  PaginatedDocView
26
- } from "./chunk-M4IUYVXU.js";
26
+ } from "./chunk-6IQ72M4Y.js";
27
27
  import {
28
28
  CanvasSection,
29
29
  LinearDocView,
30
30
  PageSectionView,
31
31
  PageViewContext,
32
32
  usePageView
33
- } from "./chunk-Q66DDGKP.js";
33
+ } from "./chunk-TWWZJWV4.js";
34
34
  import {
35
35
  useModalDialog
36
36
  } from "./chunk-JP457U6N.js";
@@ -60,7 +60,7 @@ import {
60
60
  } from "./chunk-CFJRBRRG.js";
61
61
  import {
62
62
  BlockRenderer
63
- } from "./chunk-3UITZDNL.js";
63
+ } from "./chunk-TCBV3WXF.js";
64
64
  import {
65
65
  ImageLayer,
66
66
  MapLayer,
@@ -74,7 +74,7 @@ import {
74
74
  VideoLayer,
75
75
  getAnimationStyle,
76
76
  getTransitionClass
77
- } from "./chunk-DRPMS5JK.js";
77
+ } from "./chunk-755MBX5E.js";
78
78
  import {
79
79
  MermaidDiagram,
80
80
  applyMediaLevel,
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ImageLayer as ImageLayer$1, TextLayer as TextLayer$1, ShapeLayer as ShapeLayer$1, PathLayer as PathLayer$1, TreeLayer as TreeLayer$1, MapLayer as MapLayer$1, MermaidLayer as MermaidLayer$1, Theme, SvgLayer as SvgLayer$1 } from '@bendyline/squisq/schemas';
3
- export { T as TableLayer, a as TableLayerContentRenderer, b as TableLayerContentRendererProps, V as VideoLayer } from '../VideoLayer-sT0mrnNQ.js';
3
+ export { T as TableLayer, a as TableLayerContentRenderer, b as TableLayerContentRendererProps, V as VideoLayer } from '../VideoLayer-Bg3TRIOb.js';
4
4
 
5
5
  interface ImageLayerProps {
6
6
  layer: ImageLayer$1;
@@ -9,7 +9,7 @@ import {
9
9
  TextLayer,
10
10
  TreeLayer,
11
11
  VideoLayer
12
- } from "../chunk-DRPMS5JK.js";
12
+ } from "../chunk-755MBX5E.js";
13
13
  import "../chunk-FXAKS6KU.js";
14
14
  import "../chunk-ZKMBIWAA.js";
15
15
  export {
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  PaginatedDocView
3
- } from "../chunk-M4IUYVXU.js";
3
+ } from "../chunk-6IQ72M4Y.js";
4
4
  import {
5
5
  CanvasSection,
6
6
  LinearDocView,
7
7
  PageSectionView,
8
8
  PageViewContext,
9
9
  usePageView
10
- } from "../chunk-Q66DDGKP.js";
10
+ } from "../chunk-TWWZJWV4.js";
11
11
  import "../chunk-TT6ENR6T.js";
12
12
  import "../chunk-CFJRBRRG.js";
13
- import "../chunk-3UITZDNL.js";
14
- import "../chunk-DRPMS5JK.js";
13
+ import "../chunk-TCBV3WXF.js";
14
+ import "../chunk-755MBX5E.js";
15
15
  import "../chunk-FXAKS6KU.js";
16
16
  import "../chunk-ZKMBIWAA.js";
17
17
  export {
@@ -1,9 +1,9 @@
1
- export { B as BlockMarker, c as BlockRenderer, C as CaptionMode, d as CaptionOverlay, f as CaptionStyle, g as ControlsLayout, D as DisplayMode, h as DocControlsBottom, i as DocControlsOverlay, j as DocControlsSidebar, k as DocControlsSlideshow, l as DocPlayer, m as DocPlayerProps, n as DocPlayerWithSidebar, o as DocProgressBar, F as FlashcardFaceView, p as FlashcardFaceViewProps, q as FlashcardView, r as FlashcardViewProps, I as InlineAudioPlayer, s as InlineAudioPlayerProps, t as InlineVideoPlayer, u as InlineVideoPlayerProps, M as MediaClipLayer, v as MediaClipLayerProps, b as PipPosition, a as PipShape, P as PipSize, w as PlaybackActions, x as PlaybackState, R as RenderAudioSegmentInfo, y as RenderBlockInfo, z as RenderCaptionInfo, A as RenderChapterInfo, G as SlideNavActions, H as SocialCaptionOverlay, S as SquisqRenderAPI, V as VideoPresentation, J as formatTime } from '../player-B-2-utvs.js';
1
+ export { B as BlockMarker, c as BlockRenderer, C as CaptionMode, d as CaptionOverlay, f as CaptionStyle, g as ControlsLayout, D as DisplayMode, h as DocControlsBottom, i as DocControlsOverlay, j as DocControlsSidebar, k as DocControlsSlideshow, l as DocPlayer, m as DocPlayerProps, n as DocPlayerWithSidebar, o as DocProgressBar, F as FlashcardFaceView, p as FlashcardFaceViewProps, q as FlashcardView, r as FlashcardViewProps, I as InlineAudioPlayer, s as InlineAudioPlayerProps, t as InlineVideoPlayer, u as InlineVideoPlayerProps, M as MediaClipLayer, v as MediaClipLayerProps, b as PipPosition, a as PipShape, P as PipSize, w as PlaybackActions, x as PlaybackState, R as RenderAudioSegmentInfo, y as RenderBlockInfo, z as RenderCaptionInfo, A as RenderChapterInfo, G as SlideNavActions, H as SocialCaptionOverlay, S as SquisqRenderAPI, V as VideoPresentation, J as formatTime } from '../player-Wc6Nd4p5.js';
2
2
  export { a as CodeBlockCopyContext, C as CodeBlockCopyHandler } from '../MarkdownRenderer-C63CQ9Ca.js';
3
3
  import 'react';
4
4
  import '@bendyline/squisq/schemas';
5
5
  import '@bendyline/squisq/doc';
6
6
  import '@bendyline/squisq/fence';
7
7
  import '../AudioController-DAwQyEM_.js';
8
- import '../VideoLayer-sT0mrnNQ.js';
8
+ import '../VideoLayer-Bg3TRIOb.js';
9
9
  import '@bendyline/squisq/markdown';
@@ -12,8 +12,8 @@ import {
12
12
  MediaClipLayer,
13
13
  SocialCaptionOverlay,
14
14
  formatTime
15
- } from "../chunk-NZHL2VKW.js";
16
- import "../chunk-Q66DDGKP.js";
15
+ } from "../chunk-4ZSAQ266.js";
16
+ import "../chunk-TWWZJWV4.js";
17
17
  import "../chunk-MNY6M5QG.js";
18
18
  import "../chunk-TT6ENR6T.js";
19
19
  import {
@@ -22,8 +22,8 @@ import {
22
22
  } from "../chunk-CFJRBRRG.js";
23
23
  import {
24
24
  BlockRenderer
25
- } from "../chunk-3UITZDNL.js";
26
- import "../chunk-DRPMS5JK.js";
25
+ } from "../chunk-TCBV3WXF.js";
26
+ import "../chunk-755MBX5E.js";
27
27
  import "../chunk-FXAKS6KU.js";
28
28
  import "../chunk-ZKMBIWAA.js";
29
29
  export {
@@ -5,7 +5,7 @@ import { ViewportConfig, DashboardStyleId, CoverSlideTemplate, CoverSlidePlaybac
5
5
  import { FenceRendererMap } from '@bendyline/squisq/fence';
6
6
  import { a as AudioController } from './AudioController-DAwQyEM_.js';
7
7
  import { C as CodeBlockCopyHandler } from './MarkdownRenderer-C63CQ9Ca.js';
8
- import { a as TableLayerContentRenderer, c as VideoClipMode } from './VideoLayer-sT0mrnNQ.js';
8
+ import { a as TableLayerContentRenderer, c as VideoClipMode } from './VideoLayer-Bg3TRIOb.js';
9
9
 
10
10
  /**
11
11
  * Doc Player Control Types
@@ -381,8 +381,19 @@ interface BlockRendererProps {
381
381
  theme?: Theme;
382
382
  /** Optional host renderer for interactive table content. */
383
383
  tableContentRenderer?: TableLayerContentRenderer;
384
- /** Grow all slide text by one shared factor without overflow or new overlap. */
384
+ /**
385
+ * Grow all slide text by one shared factor while it still fits without
386
+ * overflow or new overlap. For a slideshow's frame, which has room to fill.
387
+ */
385
388
  growTextToFit?: boolean;
389
+ /**
390
+ * When rich text would be clipped by its box — the real face wrapped to
391
+ * more lines than the template reserved — shrink all slide text by one
392
+ * shared factor just enough to show every line, no smaller than
393
+ * `MIN_SHRUNK_TEXT_SCALE` (default true). Every surface that draws a slide
394
+ * needs it: a video export clips the same way a slideshow does.
395
+ */
396
+ shrinkTextToFit?: boolean;
386
397
  /**
387
398
  * How hosted-video layers (YouTube, Vimeo, …) draw: a live `player`, a
388
399
  * `poster` (default — thumbnails and previews never load a player), or a
@@ -403,7 +414,7 @@ interface BlockRendererProps {
403
414
  */
404
415
  staticMedia?: boolean;
405
416
  }
406
- declare function BlockRenderer({ block, buildPlayback, respectReducedMotion, blockTime, basePath, isEntering, isExiting, transition, viewport, isPlaying, muted, animationsEnabled, theme, tableContentRenderer, growTextToFit, videoEmbeds, videoClips, staticMedia, }: BlockRendererProps): react.JSX.Element;
417
+ declare function BlockRenderer({ block, buildPlayback, respectReducedMotion, blockTime, basePath, isEntering, isExiting, transition, viewport, isPlaying, muted, animationsEnabled, theme, tableContentRenderer, growTextToFit, shrinkTextToFit, videoEmbeds, videoClips, staticMedia, }: BlockRendererProps): react.JSX.Element;
407
418
 
408
419
  interface CaptionOverlayProps {
409
420
  /** Caption track with timestamped phrases */