@bendyline/squisq-react 2.12.2 → 2.12.4

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.
@@ -2,7 +2,7 @@ import {
2
2
  renderMermaidSvg,
3
3
  useMediaProvider,
4
4
  useResourcePolicy
5
- } from "./chunk-HCKL2AFN.js";
5
+ } from "./chunk-JP2VHB5H.js";
6
6
 
7
7
  // src/hooks/useMediaSchedule.ts
8
8
  import { useMemo } from "react";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  MermaidDiagram
3
- } from "./chunk-Z7OW6RGR.js";
3
+ } from "./chunk-EY3DUCK7.js";
4
4
  import {
5
5
  useMediaUrl,
6
6
  useResourcePolicy
7
- } from "./chunk-HCKL2AFN.js";
7
+ } from "./chunk-JP2VHB5H.js";
8
8
 
9
9
  // src/utils/animationUtils.ts
10
10
  import {
@@ -51,7 +51,8 @@ function ImageLayer({
51
51
  basePath,
52
52
  viewport,
53
53
  blockTime,
54
- animationsEnabled = true
54
+ animationsEnabled = true,
55
+ isStatic = false
55
56
  }) {
56
57
  const { content, position, animation } = layer;
57
58
  const x = resolveValue(position.x, viewport.width);
@@ -61,7 +62,7 @@ function ImageLayer({
61
62
  const offset = getAnchorOffset(position.anchor, width, height);
62
63
  const finalX = x + offset.x;
63
64
  const finalY = y + offset.y;
64
- const src = useMediaUrl(content.src, basePath);
65
+ const src = useMediaUrl(content.src, basePath, { staticSvg: isStatic });
65
66
  const animStyle = getAnimationStyle(animation, blockTime);
66
67
  const filter = cssFilterForTreatment(content.treatment, content.blur);
67
68
  const preserveAspectRatio = getPreserveAspectRatio(content.fit);
@@ -444,7 +445,12 @@ function IconTextLayer({ layer, viewport, blockTime, textScale = 1 }) {
444
445
  "div",
445
446
  {
446
447
  "data-squisq-text-content": "true",
447
- style: { width: "100%", whiteSpace: "pre-wrap", wordBreak: "break-word" },
448
+ style: {
449
+ width: "100%",
450
+ whiteSpace: "pre-wrap",
451
+ wordBreak: "break-word",
452
+ ...baselineShiftStyle(style.baselineShift)
453
+ },
448
454
  dangerouslySetInnerHTML: { __html: html }
449
455
  }
450
456
  )
@@ -490,6 +496,7 @@ function PlainTextLayer({ layer, viewport, blockTime, textScale = 1 }) {
490
496
  const shrinkToFit = style.shrinkToFit === true;
491
497
  const centerBlock = shrinkToFit && dominantBaseline === "middle";
492
498
  const firstLineDy = centerBlock ? -((lines.length - 1) / 2) * lineHeightPx : 0;
499
+ const baselineShiftPx = (style.baselineShift ?? 0) * style.fontSize;
493
500
  const textRef = useRef(null);
494
501
  const [fit, setFit] = useState(null);
495
502
  const linesKey = lines.join("\n");
@@ -606,7 +613,7 @@ function PlainTextLayer({ layer, viewport, blockTime, textScale = 1 }) {
606
613
  style: textStyles,
607
614
  filter: filterId ? `url(#${filterId})` : void 0,
608
615
  transform: fitTransform,
609
- children: lines.map((line, i) => /* @__PURE__ */ jsxs2("tspan", { x, dy: i === 0 ? firstLineDy : lineHeightPx, children: [
616
+ children: lines.map((line, i) => /* @__PURE__ */ jsxs2("tspan", { x, dy: i === 0 ? firstLineDy + baselineShiftPx : lineHeightPx, children: [
610
617
  renderLine(line),
611
618
  " "
612
619
  ] }, i))
@@ -703,7 +710,8 @@ function RichTextLayer({ layer, viewport, blockTime, textScale = 1 }) {
703
710
  width: "100%",
704
711
  color: style.color,
705
712
  whiteSpace: "pre-wrap",
706
- wordBreak: "break-word"
713
+ wordBreak: "break-word",
714
+ ...baselineShiftStyle(style.baselineShift)
707
715
  },
708
716
  dangerouslySetInnerHTML: { __html: safeHtml }
709
717
  }
@@ -757,6 +765,9 @@ function getTextAnchor(align, anchor) {
757
765
  if (anchor === "center") return "middle";
758
766
  return "start";
759
767
  }
768
+ function baselineShiftStyle(shift) {
769
+ return shift ? { position: "relative", top: `${shift}em` } : {};
770
+ }
760
771
  function getDominantBaseline(verticalAlign, anchor) {
761
772
  if (verticalAlign === "top") return "text-before-edge";
762
773
  if (verticalAlign === "middle") return "middle";
@@ -2061,6 +2072,80 @@ function MermaidLayer({ layer, viewport, blockTime, theme }) {
2061
2072
  );
2062
2073
  }
2063
2074
 
2075
+ // src/layers/SvgLayer.tsx
2076
+ import { useMemo as useMemo2 } from "react";
2077
+ import { parseSvgIsland, svgIslandDataUrl } from "@bendyline/squisq/markdown";
2078
+ import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
2079
+ function SvgLayer({ layer, viewport, blockTime, isStatic = false }) {
2080
+ const { position, content, animation } = layer;
2081
+ const width = resolveValue(position.width ?? viewport.width, viewport.width);
2082
+ const height = resolveValue(position.height ?? viewport.height, viewport.height);
2083
+ const offset = getAnchorOffset(position.anchor, width, height);
2084
+ const x = resolveValue(position.x, viewport.width) + offset.x;
2085
+ const y = resolveValue(position.y, viewport.height) + offset.y;
2086
+ const result = useMemo2(
2087
+ () => parseSvgIsland(content.source, { static: isStatic }),
2088
+ [content.source, isStatic]
2089
+ );
2090
+ const href = useMemo2(
2091
+ () => result.ok ? svgIslandDataUrl(result.island, { color: content.color }) : null,
2092
+ [result, content.color]
2093
+ );
2094
+ const animStyle = getAnimationStyle(animation, blockTime);
2095
+ const label = content.alt ?? (result.ok ? result.island.title : void 0) ?? "Illustration";
2096
+ return /* @__PURE__ */ jsx11(
2097
+ "g",
2098
+ {
2099
+ className: `block-layer block-layer--svg ${animStyle.className}`,
2100
+ "data-layer-id": layer.id,
2101
+ style: animStyle.style,
2102
+ children: href ? /* @__PURE__ */ jsx11(
2103
+ "image",
2104
+ {
2105
+ href,
2106
+ x,
2107
+ y,
2108
+ width,
2109
+ height,
2110
+ preserveAspectRatio: "xMidYMid meet",
2111
+ role: "img",
2112
+ "aria-label": label,
2113
+ style: { pointerEvents: "none" }
2114
+ }
2115
+ ) : /* @__PURE__ */ jsxs8("g", { role: "img", "aria-label": "SVG that could not be rendered", children: [
2116
+ /* @__PURE__ */ jsx11(
2117
+ "rect",
2118
+ {
2119
+ x,
2120
+ y,
2121
+ width,
2122
+ height,
2123
+ rx: Math.min(width, height) * 0.04,
2124
+ fill: "none",
2125
+ stroke: content.color ?? "currentColor",
2126
+ strokeOpacity: 0.35,
2127
+ strokeWidth: 2,
2128
+ strokeDasharray: "8 6"
2129
+ }
2130
+ ),
2131
+ /* @__PURE__ */ jsx11(
2132
+ "text",
2133
+ {
2134
+ x: x + width / 2,
2135
+ y: y + height / 2,
2136
+ textAnchor: "middle",
2137
+ dominantBaseline: "middle",
2138
+ fill: content.color ?? "currentColor",
2139
+ fillOpacity: 0.6,
2140
+ fontSize: Math.max(12, Math.min(width, height) * 0.06),
2141
+ children: "Couldn\u2019t render this SVG"
2142
+ }
2143
+ )
2144
+ ] })
2145
+ }
2146
+ );
2147
+ }
2148
+
2064
2149
  export {
2065
2150
  isCaptureDrivenVideo,
2066
2151
  seekVideoToFrame,
@@ -2076,5 +2161,6 @@ export {
2076
2161
  VideoLayer,
2077
2162
  TableLayer,
2078
2163
  TreeLayer,
2079
- MermaidLayer
2164
+ MermaidLayer,
2165
+ SvgLayer
2080
2166
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LinearDocView
3
- } from "./chunk-2K74UJ4T.js";
3
+ } from "./chunk-MGFMKGZY.js";
4
4
 
5
5
  // src/PaginatedDocView.tsx
6
6
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  mermaidRenderErrorMessage,
3
3
  renderMermaidSvg
4
- } from "./chunk-HCKL2AFN.js";
4
+ } from "./chunk-JP2VHB5H.js";
5
5
 
6
6
  // src/mermaid/MermaidDiagram.tsx
7
7
  import { useEffect, useState } from "react";