@geekapps/silo-elements-nextjs 0.2.48 → 0.2.49

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/index.js CHANGED
@@ -1170,28 +1170,33 @@ function Video({
1170
1170
  const [captions, setCaptions] = useState([]);
1171
1171
  const [poster, setPoster] = useState(void 0);
1172
1172
  useEffect(() => {
1173
+ function applyResolved(data) {
1174
+ const resolved = data.map((c, i) => ({ ...c, default: c.default ?? i === 0 }));
1175
+ setCaptions(resolved);
1176
+ const defaultTrack = resolved.find((c) => c.default);
1177
+ if (defaultTrack) {
1178
+ setSubtitleMode(defaultTrack.srclang);
1179
+ setSubtitleStyle((st) => ({ ...st, track: defaultTrack.srclang }));
1180
+ }
1181
+ }
1182
+ if (parsed.captionsData) {
1183
+ applyResolved(parsed.captionsData);
1184
+ return;
1185
+ }
1173
1186
  if (!parsed.captionsSrc) {
1174
1187
  setCaptions([]);
1175
1188
  return;
1176
1189
  }
1177
1190
  let cancelled = false;
1178
1191
  fetch(parsed.captionsSrc, { cache: "no-store" }).then((r) => r.json()).then((data) => {
1179
- if (!cancelled && Array.isArray(data)) {
1180
- const resolved = data.map((c, i) => ({ ...c, default: i === 0 }));
1181
- setCaptions(resolved);
1182
- const defaultTrack = resolved.find((c) => c.default);
1183
- if (defaultTrack) {
1184
- setSubtitleMode(defaultTrack.srclang);
1185
- setSubtitleStyle((st) => ({ ...st, track: defaultTrack.srclang }));
1186
- }
1187
- }
1192
+ if (!cancelled && Array.isArray(data)) applyResolved(data);
1188
1193
  }).catch(() => {
1189
1194
  if (!cancelled) setCaptions([]);
1190
1195
  });
1191
1196
  return () => {
1192
1197
  cancelled = true;
1193
1198
  };
1194
- }, [parsed.captionsSrc]);
1199
+ }, [parsed.captionsSrc, parsed.captionsData]);
1195
1200
  useEffect(() => {
1196
1201
  if (!parsed.thumbnailSrc) {
1197
1202
  setPoster(void 0);
@@ -2757,7 +2762,11 @@ function parseVideoChildren(children) {
2757
2762
  }
2758
2763
  if (child.type === Captions || name === "SiloCaptions") {
2759
2764
  const element = child;
2760
- parsed.captionsSrc = element.props.src;
2765
+ if (element.props.data) {
2766
+ parsed.captionsData = element.props.data;
2767
+ } else if (element.props.src) {
2768
+ parsed.captionsSrc = element.props.src;
2769
+ }
2761
2770
  }
2762
2771
  if (child.type === VideoThumbnail || name === "SiloVideoThumbnail") {
2763
2772
  const element = child;