Skip to content

🎥 Make videos programmatically with React

`remotion`: Improve Tailwind class detection

Jonny Burgercf058965aeaf
diff --git a/packages/core/src/AbsoluteFill.tsx b/packages/core/src/AbsoluteFill.tsx
index 18d7544ff4..53747a0256 100644
--- a/packages/core/src/AbsoluteFill.tsx
+++ b/packages/core/src/AbsoluteFill.tsx
@@ -1,17 +1,36 @@
import React, {forwardRef, useMemo} from 'react';
-const hasTailwindClassName = (
- className: string | undefined,
- classPrefix: string[],
-) => {
+const hasTailwindClassName = ({
+ className,
+ classPrefix,
+ type,
+}: {
+ className: string | undefined;
+ classPrefix: string[];
+ type: 'prefix' | 'exact';
+}) => {
if (!className) {
return false;
}
+ if (type === 'exact') {
+ const split = className.split(' ');
+ return classPrefix.some((token) => {
+ return split.some((part) => {
+ return (
+ part.trim() === token ||
+ part.trim().endsWith(`:${token}`) ||
+ part.trim().endsWith(`!${token}`)
+ );
+ });
+ });
+ }
+
return classPrefix.some((prefix) => {
return (
className.startsWith(prefix) ||
className.includes(` ${prefix}`) ||
+ className.includes(`!${prefix}`) ||
className.includes(`:${prefix}`)
);
});
@@ -27,43 +46,77 @@ const AbsoluteFillRefForwarding: React.ForwardRefRenderFunction<
// Make TailwindCSS classes get accepted
return {
position: 'absolute',
- top: hasTailwindClassName(other.className, ['top-', 'inset-'])
+ top: hasTailwindClassName({
+ className: other.className,
+ classPrefix: ['top-', 'inset-'],
+ type: 'prefix',
+ })
? undefined
: 0,
- left: hasTailwindClassName(other.className, ['left-', 'inset-'])
+ left: hasTailwindClassName({
+ className: other.className,
+ classPrefix: ['left-', 'inset-'],
+ type: 'prefix',
+ })
? undefined
: 0,
- right: hasTailwindClassName(other.className, ['right-', 'inset-'])
+ right: hasTailwindClassName({
+ className: other.className,
+ classPrefix: ['right-', 'inset-'],
+ type: 'prefix',
+ })
? undefined
: 0,
- bottom: hasTailwindClassName(other.className, ['bottom-', 'inset-'])
+ bottom: hasTailwindClassName({
+ className: other.className,
+ classPrefix: ['bottom-', 'inset-'],
+ type: 'prefix',
+ })
? undefined
: 0,
- width: hasTailwindClassName(other.className, ['w-']) ? undefined : '100%',
- height: hasTailwindClassName(other.className, ['h-'])
+ width: hasTailwindClassName({
+ className: other.className,
+ classPrefix: ['w-'],
+ type: 'prefix',
+ })
+ ? undefined
+ : '100%',
+ height: hasTailwindClassName({
+ className: other.className,
+ classPrefix: ['h-'],
+ type: 'prefix',
+ })
? undefined
: '100%',
- display: hasTailwindClassName(other.className, [
- 'block',
- 'inline-block',
- 'inline',
- 'flex',
- 'inline-flex',
- 'flow-root',
- 'grid',
- 'inline-grid',
- 'contents',
- 'list-item',
- 'hidden',
- ])
+ display: hasTailwindClassName({
+ className: other.className,
+ classPrefix: [
+ 'block',
+ 'inline-block',
+ 'inline',
+ 'flex',
+ 'inline-flex',
+ 'flow-root',
+ 'grid',
+ 'inline-grid',
+ 'contents',
+ 'list-item',
+ 'hidden',
+ ],
+ type: 'exact',
+ })
? undefined
: 'flex',
- flexDirection: hasTailwindClassName(other.className, [
- 'flex-row',
- 'flex-col',
- 'flex-row-reverse',
- 'flex-col-reverse',
- ])
+ flexDirection: hasTailwindClassName({
+ className: other.className,
+ classPrefix: [
+ 'flex-row',
+ 'flex-col',
+ 'flex-row-reverse',
+ 'flex-col-reverse',
+ ],
+ type: 'exact',
+ })
? undefined
: 'column',
...style,