Skip to content

🎥 Make videos programmatically with React

better now!

JonnyBurgerdfac35e4b8e4
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index d7fde5b74b..1d40619016 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -632,9 +632,9 @@ export const Index: React.FC = () => {
height={350}
schema={fitTextOnNLinesSchema}
defaultProps={{
- line: 'No matter how much text I am adding, the text always fits on 2 lines and there is corner rounding like on TikTok.',
+ line: 'No matter how much text I am adding, the text always fits on 2 lines and there is corner rounding like on TikT.',
maxLines: 2,
- textAlign: 'center',
+ textAlign: 'center' as const,
}}
/>
<Composition
diff --git a/packages/example/src/TikTokTextbox/TikTokTextBox.tsx b/packages/example/src/TikTokTextbox/TikTokTextBox.tsx
index c77345f284..3fea7adddb 100644
--- a/packages/example/src/TikTokTextbox/TikTokTextBox.tsx
+++ b/packages/example/src/TikTokTextbox/TikTokTextBox.tsx
@@ -191,39 +191,10 @@ const TikTokTextLine: React.FC<{
}) => {
return (
<div style={{position: 'relative'}}>
- {cornerRounding.cornerTopLeft && (
- <TopLeftCorner
- bgColor={bgColor}
- borderRadiusValue={borderRadiusValue}
- widthDifference={cornerRounding.widthDifferenceToPrevious}
- />
- )}
- {cornerRounding.cornerBottomLeft && (
- <BottomLeftCorner
- bgColor={bgColor}
- borderRadiusValue={borderRadiusValue}
- widthDifference={cornerRounding.widthDifferenceToNext}
- />
- )}
- {cornerRounding.cornerTopRight && (
- <TopRightCorner
- bgColor={bgColor}
- borderRadiusValue={borderRadiusValue}
- widthDifference={cornerRounding.widthDifferenceToPrevious}
- />
- )}
- {cornerRounding.cornerBottomRight && (
- <BottomRightCorner
- bgColor={bgColor}
- borderRadiusValue={borderRadiusValue}
- widthDifference={cornerRounding.widthDifferenceToNext}
- />
- )}
<div
style={
{
textAlign: align,
- backgroundColor: bgColor ?? 'white',
padding: `0px ${TIKTOK_TEXT_BOX_HORIZONTAL_PADDING}px`,
borderRadius: borderRadius,
...style,
@@ -279,10 +250,8 @@ export const TikTokTextBox: React.FC<TikTokTextBoxProps> = ({
textAlign: align,
fontFamily,
color: textColor ?? 'black',
- width: 'fit-content',
lineHeight: 1.5,
fontWeight,
- position: 'relative',
}}
>
{lines.map((line, i) => (
@@ -303,9 +272,15 @@ export const TikTokTextBox: React.FC<TikTokTextBoxProps> = ({
position: 'absolute',
width: boundingBox.width,
height: boundingBox.height,
+ overflow: 'visible',
}}
>
- <path d={svg} fill="rgba(255, 0, 0, 0.5)" />
+ <path
+ fill="none"
+ d={svg}
+ stroke="rgba(255, 0, 0, 0.8)"
+ strokeWidth={3}
+ />
</svg>
</div>
);
diff --git a/packages/example/src/TikTokTextbox/get-corner-roundings.ts b/packages/example/src/TikTokTextbox/get-corner-roundings.ts
index 1b78aa6078..9f3b2fcbce 100644
--- a/packages/example/src/TikTokTextbox/get-corner-roundings.ts
+++ b/packages/example/src/TikTokTextbox/get-corner-roundings.ts
@@ -68,25 +68,17 @@ export const getCornerRoundings = ({
// Determine rounded corners
let topLeft =
- isFirst ||
- (prevLen !== undefined &&
- currLen.width - 0 > prevLen.width &&
- align !== 'left');
+ prevLen === undefined ||
+ (currLen.width - 0 > prevLen.width && align !== 'left');
let topRight =
- isFirst ||
- (prevLen !== undefined &&
- currLen.width - 0 > prevLen.width &&
- align !== 'right');
+ prevLen === undefined ||
+ (currLen.width - 0 > prevLen.width && align !== 'right');
let bottomLeft =
- isLast ||
- (nextLen !== undefined &&
- currLen.width - 0 > nextLen.width &&
- align !== 'left');
+ nextLen === undefined ||
+ (currLen.width - 0 > nextLen.width && align !== 'left');
let bottomRight =
- isLast ||
- (nextLen !== undefined &&
- currLen.width - 0 > nextLen.width &&
- align !== 'right');
+ nextLen === undefined ||
+ (currLen.width - 0 > nextLen.width && align !== 'right');
if (!isFirst && !isLast) {
if (align === 'left') {
diff --git a/packages/example/src/TikTokTextbox/svg.ts b/packages/example/src/TikTokTextbox/svg.ts
index 85eb67b76b..921b14b9a7 100644
--- a/packages/example/src/TikTokTextbox/svg.ts
+++ b/packages/example/src/TikTokTextbox/svg.ts
@@ -1,7 +1,11 @@
import {Instruction, serializeInstructions} from '@remotion/paths';
import {CornerRounding} from './get-corner-roundings';
-const CORNER_RADIUS = 30;
+const CORNER_RADIUS = 10;
+
+const clamp = (val: number, min: number, max: number) => {
+ return Math.min(Math.max(val, min), max);
+};
export const makeSvg = ({
cornerRoundings,
@@ -22,7 +26,9 @@ export const makeSvg = ({
let yOffset = 0;
for (let i = 0; i < cornerRoundings.length; i++) {
+ const prevCornerRounding = cornerRoundings[i - 1];
const cornerRounding = cornerRoundings[i];
+ const nextCornerRounding = cornerRoundings[i + 1];
let xOffset = 0;
if (textAlign === 'center') {
xOffset = (maxWidth - (cornerRounding.width + horizontalPadding * 2)) / 2;
@@ -37,24 +43,36 @@ export const makeSvg = ({
y: yOffset,
});
}
- if (cornerRounding.topRight) {
+
+ const topRightWidthDifference = prevCornerRounding
+ ? prevCornerRounding.width - cornerRounding.width
+ : -Infinity;
+ const topRightCornerRadius = clamp(
+ topRightWidthDifference / 4,
+ -CORNER_RADIUS,
+ CORNER_RADIUS,
+ );
+ // Top Right Corner
+ if (topRightCornerRadius !== 0) {
instructions.push({
type: 'L',
x:
xOffset +
cornerRounding.width +
- horizontalPadding * 2 -
- CORNER_RADIUS,
+ horizontalPadding * 2 +
+ topRightCornerRadius,
y: yOffset,
});
+ // Arc for rounded corner (top right)
instructions.push({
- type: 'C',
- cp1x: xOffset + cornerRounding.width + horizontalPadding * 2,
- cp1y: yOffset,
- cp2x: xOffset + cornerRounding.width + horizontalPadding * 2,
- cp2y: yOffset,
+ type: 'A',
+ rx: Math.abs(topRightCornerRadius),
+ ry: Math.abs(topRightCornerRadius),
+ xAxisRotation: 0,
+ largeArcFlag: false,
+ sweepFlag: topRightCornerRadius < 0,
x: xOffset + cornerRounding.width + horizontalPadding * 2,
- y: yOffset + CORNER_RADIUS,
+ y: yOffset + Math.abs(topRightCornerRadius),
});
} else {
instructions.push({
@@ -63,23 +81,36 @@ export const makeSvg = ({
y: yOffset,
});
}
- if (cornerRounding.bottomRight) {
+
+ const bottomRightWidthDifference = nextCornerRounding
+ ? nextCornerRounding.width - cornerRounding.width
+ : -Infinity;
+ const bottomRightCornerRadius = clamp(
+ bottomRightWidthDifference / 4,
+ -CORNER_RADIUS,
+ CORNER_RADIUS,
+ );
+
+ // Bottom Right Corner
+ if (bottomRightCornerRadius !== 0) {
instructions.push({
type: 'L',
x: xOffset + cornerRounding.width + horizontalPadding * 2,
- y: yOffset + cornerRounding.height - CORNER_RADIUS,
+ y: yOffset + cornerRounding.height - Math.abs(bottomRightCornerRadius),
});
+ // Arc for rounded corner (bottom right)
instructions.push({
- type: 'C',
- cp1x: xOffset + cornerRounding.width + horizontalPadding * 2,
- cp1y: yOffset + cornerRounding.height,
- cp2x: xOffset + cornerRounding.width + horizontalPadding * 2,
- cp2y: yOffset + cornerRounding.height,
+ type: 'A',
+ rx: Math.abs(bottomRightCornerRadius),
+ ry: Math.abs(bottomRightCornerRadius),
+ xAxisRotation: 0,
+ largeArcFlag: false,
+ sweepFlag: bottomRightCornerRadius < 0,
x:
xOffset +
cornerRounding.width +
- horizontalPadding * 2 -
- CORNER_RADIUS,
+ horizontalPadding * 2 +
+ bottomRightCornerRadius,
y: yOffset + cornerRounding.height,
});
} else {
@@ -91,6 +122,7 @@ export const makeSvg = ({
}
yOffset += cornerRounding.height;
}
+
for (let i = cornerRoundings.length - 1; i >= 0; i--) {
const cornerRounding = cornerRoundings[i];
let xOffset = 0;
@@ -100,18 +132,23 @@ export const makeSvg = ({
xOffset = maxWidth - (cornerRounding.width + horizontalPadding * 2);
}
- if (cornerRounding.bottomLeft) {
+ const bottomLeft = i === cornerRoundings.length - 1;
+ const topLeft = i === 0;
+ // Bottom Left Corner
+ if (bottomLeft) {
instructions.push({
type: 'L',
x: xOffset + CORNER_RADIUS,
y: yOffset,
});
+ // Arc for rounded corner (bottom left)
instructions.push({
- type: 'C',
- cp1x: xOffset,
- cp1y: yOffset,
- cp2x: xOffset,
- cp2y: yOffset,
+ type: 'A',
+ rx: CORNER_RADIUS,
+ ry: CORNER_RADIUS,
+ xAxisRotation: 0,
+ largeArcFlag: false,
+ sweepFlag: true,
x: xOffset,
y: yOffset - CORNER_RADIUS,
});
@@ -123,18 +160,21 @@ export const makeSvg = ({
});
}
- if (cornerRounding.topLeft) {
+ // Top Left Corner
+ if (topLeft) {
instructions.push({
type: 'L',
x: xOffset,
y: yOffset - cornerRounding.height + CORNER_RADIUS,
});
+ // Arc for rounded corner (top left)
instructions.push({
- type: 'C',
- cp1x: xOffset,
- cp1y: yOffset - cornerRounding.height,
- cp2x: xOffset,
- cp2y: yOffset - cornerRounding.height,
+ type: 'A',
+ rx: CORNER_RADIUS,
+ ry: CORNER_RADIUS,
+ xAxisRotation: 0,
+ largeArcFlag: false,
+ sweepFlag: true,
x: xOffset + CORNER_RADIUS,
y: yOffset - cornerRounding.height,
});