@geekapps/silo-elements-nextjs 0.2.43 → 0.2.44

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.d.ts CHANGED
@@ -2,7 +2,7 @@ export { ImageUploader } from './ImageUploader.js';
2
2
  export { VideoUploader } from './VideoUploader.js';
3
3
  export { FileUploader } from './FileUploader.js';
4
4
  export { MediaUploader } from './MediaUploader.js';
5
- export { Source, SourceProps, Sources, SourcesProps, Storyboard, StoryboardFrame, StoryboardFrameProps, StoryboardProps, Subtitle, SubtitleProps, Subtitles, SubtitlesProps, Video, VideoPlayer, VideoSourceType } from './VideoPlayer.js';
5
+ export { Captions, CaptionsProps, Source, SourceProps, Storyboard, StoryboardFrame, StoryboardFrameProps, StoryboardProps, Video, VideoPlayer, VideoSourceType, VideoThumbnail, ThumbnailProps as VideoThumbnailProps } from './VideoPlayer.js';
6
6
  export { DropZone } from './components/DropZone.js';
7
7
  export { ProgressBar } from './components/ProgressBar.js';
8
8
  import * as react from 'react';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { useMultipartUpload, useBatchUpload, useSignedUrl, useFileStatus } from
3
3
  export { SiloProvider, useBatchUpload, useFileStatus, useMultipartUpload, useSignedUrl, useSiloClient } from '@geekapps/silo-nextjs';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
5
  import gsap from 'gsap';
6
- import { Pause, Play, VolumeX, Volume2, Captions, Settings, Minimize, Maximize } from 'lucide-react';
6
+ import { Pause, Play, VolumeX, Volume2, Captions as Captions$1, Settings, Minimize, Maximize } from 'lucide-react';
7
7
 
8
8
  // src/ImageUploader.tsx
9
9
 
@@ -1136,22 +1136,18 @@ var AUTO_QUALITY = {
1136
1136
  type: "auto"
1137
1137
  };
1138
1138
  var PLAYBACK_SPEEDS = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2];
1139
- function Sources(_props) {
1140
- return null;
1141
- }
1142
- Sources.displayName = "SiloSources";
1143
1139
  function Source(_props) {
1144
1140
  return null;
1145
1141
  }
1146
1142
  Source.displayName = "SiloSource";
1147
- function Subtitles(_props) {
1143
+ function Captions(_props) {
1148
1144
  return null;
1149
1145
  }
1150
- Subtitles.displayName = "SiloSubtitles";
1151
- function Subtitle(_props) {
1146
+ Captions.displayName = "SiloCaptions";
1147
+ function VideoThumbnail(_props) {
1152
1148
  return null;
1153
1149
  }
1154
- Subtitle.displayName = "SiloSubtitle";
1150
+ VideoThumbnail.displayName = "SiloVideoThumbnail";
1155
1151
  function Storyboard(_props) {
1156
1152
  return null;
1157
1153
  }
@@ -1163,7 +1159,6 @@ StoryboardFrame.displayName = "SiloStoryboardFrame";
1163
1159
  function Video({
1164
1160
  title,
1165
1161
  description,
1166
- poster,
1167
1162
  children,
1168
1163
  className,
1169
1164
  autoHideControls = true,
@@ -1172,14 +1167,40 @@ function Video({
1172
1167
  fixedHeight
1173
1168
  }) {
1174
1169
  const parsed = useMemo(() => parseVideoChildren(children), [children]);
1170
+ const [captions, setCaptions] = useState([]);
1171
+ const [poster, setPoster] = useState(void 0);
1172
+ useEffect(() => {
1173
+ if (!parsed.captionsSrc) {
1174
+ setCaptions([]);
1175
+ return;
1176
+ }
1177
+ let cancelled = false;
1178
+ fetch(parsed.captionsSrc, { cache: "no-store" }).then((r) => r.json()).then((data) => {
1179
+ if (!cancelled && Array.isArray(data)) {
1180
+ setCaptions(data.map((c, i) => ({ ...c, default: i === 0 })));
1181
+ }
1182
+ }).catch(() => {
1183
+ if (!cancelled) setCaptions([]);
1184
+ });
1185
+ return () => {
1186
+ cancelled = true;
1187
+ };
1188
+ }, [parsed.captionsSrc]);
1189
+ useEffect(() => {
1190
+ if (!parsed.thumbnailSrc) {
1191
+ setPoster(void 0);
1192
+ return;
1193
+ }
1194
+ setPoster(parsed.thumbnailSrc);
1195
+ }, [parsed.thumbnailSrc]);
1175
1196
  const initialSourceIndex = useMemo(() => {
1176
1197
  const index = parsed.sources.findIndex((source) => source.default);
1177
1198
  return index >= 0 ? index : 0;
1178
1199
  }, [parsed.sources]);
1179
1200
  const initialSubtitleMode = useMemo(() => {
1180
- const track = parsed.subtitles.find((subtitle) => subtitle.default);
1201
+ const track = captions.find((c) => c.default);
1181
1202
  return track?.srclang ?? "off";
1182
- }, [parsed.subtitles]);
1203
+ }, [captions]);
1183
1204
  const containerRef = useRef(null);
1184
1205
  const chromeRef = useRef(null);
1185
1206
  const playerRef = useRef(null);
@@ -1284,10 +1305,10 @@ function Video({
1284
1305
  }
1285
1306
  }, [sourceIndex, parsed.sources.length, initialSourceIndex]);
1286
1307
  useEffect(() => {
1287
- if (subtitleMode !== "off" && !parsed.subtitles.some((subtitle) => subtitle.srclang === subtitleMode)) {
1308
+ if (subtitleMode !== "off" && !captions.some((subtitle) => subtitle.srclang === subtitleMode)) {
1288
1309
  setSubtitleMode(initialSubtitleMode);
1289
1310
  }
1290
- }, [subtitleMode, parsed.subtitles, initialSubtitleMode]);
1311
+ }, [subtitleMode, captions, initialSubtitleMode]);
1291
1312
  useEffect(() => {
1292
1313
  const video = videoRef.current;
1293
1314
  if (!video) return;
@@ -1911,7 +1932,7 @@ function Video({
1911
1932
  preload: "metadata",
1912
1933
  crossOrigin: "anonymous",
1913
1934
  children: [
1914
- parsed.subtitles.map((subtitle) => /* @__PURE__ */ jsx(
1935
+ captions.map((subtitle) => /* @__PURE__ */ jsx(
1915
1936
  "track",
1916
1937
  {
1917
1938
  kind: "subtitles",
@@ -2018,11 +2039,11 @@ function Video({
2018
2039
  label: "Qualidade",
2019
2040
  value: qualities.find((q) => q.id === selectedQuality)?.label ?? "Auto"
2020
2041
  },
2021
- ...parsed.subtitles.length > 0 ? [
2042
+ ...captions.length > 0 ? [
2022
2043
  {
2023
2044
  id: "subtitles",
2024
2045
  label: "Legendas",
2025
- value: subtitleStyle.track === "off" ? "Desligado" : parsed.subtitles.find(
2046
+ value: subtitleStyle.track === "off" ? "Desligado" : captions.find(
2026
2047
  (s) => s.srclang === subtitleStyle.track
2027
2048
  )?.label ?? subtitleStyle.track
2028
2049
  }
@@ -2179,7 +2200,7 @@ function Video({
2179
2200
  ),
2180
2201
  /* @__PURE__ */ jsx("div", { className: "py-1.5", children: [
2181
2202
  { srclang: "off", label: "Desligado" },
2182
- ...parsed.subtitles
2203
+ ...captions
2183
2204
  ].map((s) => /* @__PURE__ */ jsxs(
2184
2205
  "button",
2185
2206
  {
@@ -2579,16 +2600,16 @@ function Video({
2579
2600
  ) })
2580
2601
  ] }),
2581
2602
  /* @__PURE__ */ jsx("div", { className: "mx-0.5 h-4 w-px bg-white/20 @md:mx-1" }),
2582
- parsed.subtitles.length > 0 && /* @__PURE__ */ jsx(
2603
+ captions.length > 0 && /* @__PURE__ */ jsx(
2583
2604
  "button",
2584
2605
  {
2585
2606
  type: "button",
2586
2607
  onClick: () => setSubtitleMode(
2587
- (m) => m === "off" ? parsed.subtitles[0]?.srclang ?? "off" : "off"
2608
+ (m) => m === "off" ? captions[0]?.srclang ?? "off" : "off"
2588
2609
  ),
2589
2610
  className: `grid size-8 place-items-center rounded transition hover:text-white/80 @sm:size-10${subtitleMode !== "off" ? "text-white" : "text-white/60"}`,
2590
2611
  "aria-label": "Captions",
2591
- children: /* @__PURE__ */ jsx(Captions, { className: "size-4 @sm:size-5" })
2612
+ children: /* @__PURE__ */ jsx(Captions$1, { className: "size-4 @sm:size-5" })
2592
2613
  }
2593
2614
  ),
2594
2615
  /* @__PURE__ */ jsx("div", { className: "relative", children: /* @__PURE__ */ jsx(
@@ -2716,8 +2737,7 @@ function Video({
2716
2737
  var VideoPlayer = Video;
2717
2738
  function parseVideoChildren(children) {
2718
2739
  const parsed = {
2719
- sources: [],
2720
- subtitles: []
2740
+ sources: []
2721
2741
  };
2722
2742
  function dn(child) {
2723
2743
  return child.type?.displayName ?? child.type?.name ?? "";
@@ -2725,25 +2745,17 @@ function parseVideoChildren(children) {
2725
2745
  React.Children.forEach(children, (child) => {
2726
2746
  if (!React.isValidElement(child)) return;
2727
2747
  const name = dn(child);
2728
- if (child.type === Sources || name === "SiloSources") {
2748
+ if (child.type === Source || name === "SiloSource") {
2729
2749
  const element = child;
2730
- React.Children.forEach(element.props.children, (sourceChild) => {
2731
- if (!React.isValidElement(sourceChild)) return;
2732
- const sn = dn(sourceChild);
2733
- if (sourceChild.type !== Source && sn !== "SiloSource") return;
2734
- const sourceElement = sourceChild;
2735
- parsed.sources.push(sourceElement.props);
2736
- });
2750
+ parsed.sources.push(element.props);
2737
2751
  }
2738
- if (child.type === Subtitles || name === "SiloSubtitles") {
2752
+ if (child.type === Captions || name === "SiloCaptions") {
2739
2753
  const element = child;
2740
- React.Children.forEach(element.props.children, (subtitleChild) => {
2741
- if (!React.isValidElement(subtitleChild)) return;
2742
- const sn = dn(subtitleChild);
2743
- if (subtitleChild.type !== Subtitle && sn !== "SiloSubtitle") return;
2744
- const subtitleElement = subtitleChild;
2745
- parsed.subtitles.push(subtitleElement.props);
2746
- });
2754
+ parsed.captionsSrc = element.props.src;
2755
+ }
2756
+ if (child.type === VideoThumbnail || name === "SiloVideoThumbnail") {
2757
+ const element = child;
2758
+ parsed.thumbnailSrc = element.props.src;
2747
2759
  }
2748
2760
  if (child.type === Storyboard || name === "SiloStoryboard") {
2749
2761
  const element = child;
@@ -3303,6 +3315,6 @@ function Badge({ children, muted }) {
3303
3315
  );
3304
3316
  }
3305
3317
 
3306
- export { Avatar, Background, DropZone, FileCard, FileIcon, FilePreview, FileUploader, ImageOptions, ImageUploader, MediaUploader, ProgressBar, Source, Sources, Storyboard, StoryboardFrame, Subtitle, Subtitles, Thumbnail, Video, VideoOptions, VideoPlayer, VideoUploader, defaultTheme, resolveTheme };
3318
+ export { Avatar, Background, Captions, DropZone, FileCard, FileIcon, FilePreview, FileUploader, ImageOptions, ImageUploader, MediaUploader, ProgressBar, Source, Storyboard, StoryboardFrame, Thumbnail, Video, VideoOptions, VideoPlayer, VideoThumbnail, VideoUploader, defaultTheme, resolveTheme };
3307
3319
  //# sourceMappingURL=index.js.map
3308
3320
  //# sourceMappingURL=index.js.map