shiveshnavin commited on
Commit
af625b4
·
1 Parent(s): 6461470
remotion/components/bubble/RawHtmlRenderer.tsx ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react';
2
+ import {
3
+ AbsoluteFill,
4
+ Easing,
5
+ IFrame,
6
+ interpolate,
7
+ staticFile,
8
+ useCurrentFrame,
9
+ useVideoConfig,
10
+ } from 'remotion';
11
+ import {
12
+ Bubble,
13
+ BubbleHtml,
14
+ } from '../../../common-utils/models/media/OriginalManuscriptModel';
15
+
16
+ export interface RawHtmlRendererProps {
17
+ /** The manuscript Bubble model containing bubbleHtml, fromSec, toSec, durationSec */
18
+ bubble?: Bubble;
19
+ /** Direct BubbleHtml model (precedence: bubble.bubbleHtml ?? bubbleHtml) */
20
+ bubbleHtml?: BubbleHtml;
21
+ /** Frame at which the HTML bubble becomes visible (default: derived from fromSec or 0) */
22
+ startFrame?: number;
23
+ /** Duration in frames the HTML bubble stays visible (default: derived from toSec/durationSec) */
24
+ durationInFrames?: number;
25
+ /** Optional custom styling for the fullscreen container */
26
+ style?: React.CSSProperties;
27
+ /** Optional custom styling for the IFrame */
28
+ iframeStyle?: React.CSSProperties;
29
+ }
30
+
31
+ /**
32
+ * Resolves static URL for HTML path (supports Windows backslashes and public/ prefixes).
33
+ */
34
+ export const resolveHtmlSrc = (path?: string): string => {
35
+ if (!path) return '';
36
+ if (
37
+ path.startsWith('http://') ||
38
+ path.startsWith('https://') ||
39
+ path.startsWith('data:') ||
40
+ path.startsWith('blob:')
41
+ ) {
42
+ return path;
43
+ }
44
+
45
+ // Normalize Windows backslashes and strip leading public/
46
+ const cleanPath = path
47
+ .replace(/\\/g, '/')
48
+ .replace(/^\/?public\//i, '')
49
+ .replace(/^\/+/, '');
50
+
51
+ try {
52
+ return staticFile(cleanPath);
53
+ } catch (err) {
54
+ return `/${cleanPath}`;
55
+ }
56
+ };
57
+
58
+ /**
59
+ * RawHtmlRenderer / HtmlBubble
60
+ * Renders an HTML bubble completely fullscreen without any margin or padding,
61
+ * allowing the full background/visuals to be driven directly by the HTML markup.
62
+ */
63
+ export const RawHtmlRenderer: React.FC<RawHtmlRendererProps> = ({
64
+ bubble,
65
+ bubbleHtml: directBubbleHtml,
66
+ startFrame: customStartFrame,
67
+ durationInFrames: customDurationInFrames,
68
+ style,
69
+ iframeStyle,
70
+ }) => {
71
+ const frame = useCurrentFrame();
72
+ const { fps } = useVideoConfig();
73
+
74
+ const effectiveHtml: BubbleHtml | undefined =
75
+ bubble?.bubbleHtml ?? directBubbleHtml;
76
+
77
+ if (!effectiveHtml || (!effectiveHtml.text && !effectiveHtml.path)) {
78
+ return null;
79
+ }
80
+
81
+ const fromSec = bubble?.fromSec ?? 0;
82
+ const toSec = bubble?.toSec;
83
+ const durationSec = bubble?.durationSec ?? effectiveHtml.durationSec;
84
+
85
+ const startFrame = customStartFrame ?? Math.round(fromSec * fps);
86
+ const totalDurationFrames = customDurationInFrames ?? (
87
+ toSec !== undefined && toSec > fromSec
88
+ ? Math.round((toSec - fromSec) * fps)
89
+ : durationSec !== undefined && durationSec > 0
90
+ ? Math.round(durationSec * fps)
91
+ : undefined
92
+ );
93
+
94
+ const endFrame = totalDurationFrames !== undefined ? startFrame + totalDurationFrames : undefined;
95
+
96
+ // Active time window gating
97
+ if (frame < startFrame) {
98
+ return null;
99
+ }
100
+ if (endFrame !== undefined && frame >= endFrame) {
101
+ return null;
102
+ }
103
+
104
+ // Precedence: bubbleHtml.text (first precedence) then bubbleHtml.path (second precedence)
105
+ const htmlContent = effectiveHtml.text;
106
+ const resolvedSrc = !htmlContent && effectiveHtml.path ? resolveHtmlSrc(effectiveHtml.path) : undefined;
107
+
108
+ // Smooth entrance & exit opacity
109
+ const localFrame = frame - startFrame;
110
+ const enterOpacity = interpolate(localFrame, [0, 10], [0, 1], {
111
+ extrapolateLeft: 'clamp',
112
+ extrapolateRight: 'clamp',
113
+ });
114
+
115
+ const exitOpacity = endFrame
116
+ ? interpolate(frame, [endFrame - 10, endFrame], [1, 0], {
117
+ extrapolateLeft: 'clamp',
118
+ extrapolateRight: 'clamp',
119
+ })
120
+ : 1;
121
+
122
+ const opacity = Math.min(enterOpacity, exitOpacity);
123
+
124
+ return (
125
+ <AbsoluteFill
126
+ style={{
127
+ position: 'absolute',
128
+ top: 0,
129
+ left: 0,
130
+ right: 0,
131
+ bottom: 0,
132
+ width: '100%',
133
+ height: '100%',
134
+ margin: 0,
135
+ padding: 0,
136
+ overflow: 'hidden',
137
+ border: 'none',
138
+ zIndex: 5,
139
+ opacity,
140
+ ...style,
141
+ }}
142
+ >
143
+ {htmlContent ? (
144
+ <IFrame
145
+ srcDoc={htmlContent}
146
+ style={{
147
+ width: '100%',
148
+ height: '100%',
149
+ border: 'none',
150
+ margin: 0,
151
+ padding: 0,
152
+ display: 'block',
153
+ overflow: 'hidden',
154
+ backgroundColor: 'transparent',
155
+ ...iframeStyle,
156
+ }}
157
+ />
158
+ ) : resolvedSrc ? (
159
+ <IFrame
160
+ src={resolvedSrc}
161
+ style={{
162
+ width: '100%',
163
+ height: '100%',
164
+ border: 'none',
165
+ margin: 0,
166
+ padding: 0,
167
+ display: 'block',
168
+ overflow: 'hidden',
169
+ backgroundColor: 'transparent',
170
+ ...iframeStyle,
171
+ }}
172
+ />
173
+ ) : null}
174
+ </AbsoluteFill>
175
+ );
176
+ };
177
+
178
+ export const HtmlBubble = RawHtmlRenderer;
179
+ export default RawHtmlRenderer;
remotion/components/bubble/index.tsx CHANGED
@@ -16,6 +16,14 @@ import {
16
  Bubble,
17
  BubbleExtra,
18
  } from '../../../common-utils/models/media/OriginalManuscriptModel';
 
 
 
 
 
 
 
 
19
 
20
  export interface ParsedSegment {
21
  type: 'text' | 'highlight';
@@ -168,6 +176,10 @@ export const TextBubble: React.FC<TextBubbleProps> = ({ bubble, style }) => {
168
  const frame = useCurrentFrame();
169
  const { fps } = useVideoConfig();
170
 
 
 
 
 
171
  if (!bubble || !bubble.bubbleText || !bubble.bubbleText.text) {
172
  return null;
173
  }
 
16
  Bubble,
17
  BubbleExtra,
18
  } from '../../../common-utils/models/media/OriginalManuscriptModel';
19
+ import {
20
+ HtmlBubble,
21
+ RawHtmlRenderer,
22
+ RawHtmlRendererProps,
23
+ resolveHtmlSrc,
24
+ } from './RawHtmlRenderer';
25
+
26
+ export { HtmlBubble, RawHtmlRenderer, RawHtmlRendererProps, resolveHtmlSrc };
27
 
28
  export interface ParsedSegment {
29
  type: 'text' | 'highlight';
 
176
  const frame = useCurrentFrame();
177
  const { fps } = useVideoConfig();
178
 
179
+ if (bubble?.bubbleHtml) {
180
+ return <RawHtmlRenderer bubble={bubble} style={style} />;
181
+ }
182
+
183
  if (!bubble || !bubble.bubbleText || !bubble.bubbleText.text) {
184
  return null;
185
  }
remotion/compositions/hello-world/HelloWorld.tsx CHANGED
@@ -424,7 +424,7 @@ export const HelloWorldComposition: React.FC = () => {
424
  },
425
  volume: 1,
426
  captionGroup: defaultSampleGroup,
427
- captionType: 'word-highlight',
428
  showPip: true,
429
  pipMedia: defaultSamplePipMedia,
430
  pipPosition: 'bottom-right',
 
424
  },
425
  volume: 1,
426
  captionGroup: defaultSampleGroup,
427
+ captionType: 'moving-pill',
428
  showPip: true,
429
  pipMedia: defaultSamplePipMedia,
430
  pipPosition: 'bottom-right',