File size: 4,262 Bytes
6256e8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8bdc503
 
 
 
6256e8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { AbsoluteFill, Img, staticFile } from 'remotion';
import React from 'react'
import * as Montserrat from "@remotion/google-fonts/Montserrat";
import { Group, PosterSingleTextWithBGExtra, Transcript, Word } from 'common-utils';

function adjustFontSize(text: string, fullFont?: number): number {
    if (!fullFont) {
        fullFont = 160
    }
    const wordCount = text.split(' ').length;
    return fullFont - (wordCount * (wordCount > 5 ? 4.5 : 1));
}

function splitSentence(sentence: string): [string, string] {
    const words = sentence.trim().split(' ');
    const lastWord = words[words.length - 1];
    const lastWordIndex = sentence.lastIndexOf(lastWord);
    const firstPart = sentence.slice(0, lastWordIndex).trim();
    const secondPart = sentence.slice(lastWordIndex).trim();
    return [firstPart, secondPart];
}

export const PosterSingleTextWithBG: React.FC<Transcript> = (item) => {
    const { audioCaption, text = "No Text" } = item;
    const bgImagePath = item.mediaAbsPaths?.[0]?.path
    const {
        textBgColor,
    } = item.extras as PosterSingleTextWithBGExtra

    const baseStyle = {
        textAlign: 'center',
        borderColor: "transparent",
        borderRadius: "2rem",
        borderLeftWidth: "4px",
        borderRightWidth: "4px",
        color: "#fff",
        textShadow: "0px 0px 50px #000, 0px 0px 50px #000",
        padding: "0.2rem 1.5rem",
    };

    const { fontFamily } = Montserrat.loadFont("normal", {
        weights: ["400"],
        ignoreTooManyRequestsWarning: true
    });
    let curZoom = 1.5
    let lines = audioCaption?.words || [{
        word: text
    } as Word]
    return (
        <AbsoluteFill>

            {
                bgImagePath && <Img
                    style={{
                        transform: `scale(${(curZoom)})  translateX(${0}px)`,
                    }}
                    src={staticFile(bgImagePath)} />
            }


            <AbsoluteFill
                style={{
                    flex: 1,
                    justifyContent: 'center',
                    alignItems: 'center',
                    flexDirection: 'column',
                    background: textBgColor
                }}
            >
                <h1
                    style={{
                        overflow: 'hidden',
                        fontFamily: fontFamily,
                        fontWeight: 'bold',
                        textAlign: 'left',
                        position: 'absolute',
                    }}
                >
                    <div
                        className="p-6 rounded-lg"
                        style={{
                            width: "100%",
                            height: "100%",
                            display: "flex",
                            flexDirection: "column",
                            justifyContent: "center",
                            alignItems: "center",
                            alignContent: "center",
                            flex: 1,
                        }}
                    >
                        {
                            lines.map(line => {

                                return (
                                    <span
                                        style={{
                                            ...baseStyle,
                                            fontFamily,
                                            fontSize: 42,
                                            ...line.textStyle
                                        } as any}
                                    >
                                        {line.word}
                                    </span>
                                )
                            })
                        }

                    </div>
                </h1>
            </AbsoluteFill>
        </AbsoluteFill >

    );
};




function ColoredCircleFunction({ color, size, radius, transform }: any) {
    const circleStyle = {
        width: size,
        height: size,
        borderRadius: radius,
        backgroundColor: color,
        transform: transform
    };

    return (
        <div style={circleStyle}></div>
    );
}

export const ColoredCircle = ColoredCircleFunction;