Spaces:
Running
Running
File size: 7,669 Bytes
e1e42ea 9221bcd 9d9a493 9221bcd 961cc99 9221bcd 75aae0c 9221bcd ba31655 9221bcd ba31655 9221bcd 75aae0c 9221bcd ba31655 9221bcd 75aae0c 9221bcd 75aae0c 9221bcd 75aae0c 9221bcd ba31655 9221bcd ba31655 9221bcd e1e42ea 9221bcd 961cc99 9221bcd 961cc99 9221bcd e1e42ea | 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | import { AbsoluteFill, Img, staticFile } from 'remotion';
import React, { CSSProperties } from 'react'
import { PaperDrivePageExtras } from './types';
import { loadFont as loadMontserrat } from '@remotion/google-fonts/Montserrat';
import { OriginalManuscript, Transcript } from 'common-utils';
import { RenderUtils } from '../RenderUtils';
import { QRCode } from 'react-qrcode-logo';
export const PaperDriveHorizontalCoverComposition = (props: OriginalManuscript) => {
const data = props.transcript
.filter(v => ["front-cover", "back-cover"].includes(v.extras?.template))
const frontData = data[0]
const backData = data[1]
return (
<AbsoluteFill style={{
padding: 0,
margin: 0,
display: 'flex',
width: '100%',
height: '100%',
flexDirection: 'row',
}}>
{frontData && <PaperDriveBackCover transcript={backData} style={{
width: '50%',
height: '100%',
paddingRight: 50,
}} />}
{backData && <PaperDriveFrontCover transcript={frontData} style={{
width: '50%',
height: '100%',
paddingLeft: 50,
}} />}
</AbsoluteFill>
);
};
export function PaperDriveFrontCover({ transcript, style }: { transcript: Transcript, style?: CSSProperties }) {
const extras = transcript.extras as PaperDrivePageExtras
const { fontFamily: Montserrat } = loadMontserrat();
const qrImageBlend = extras?.qr?.logo
const defaultQrSize = RenderUtils.convertVHToPixels(extras?.marginTop ?? '10vh')
const logo = qrImageBlend ? staticFile(RenderUtils.getFileName(qrImageBlend)!) : undefined
let qrSize = defaultQrSize
if (extras?.qr?.size?.includes("vh")) {
qrSize = RenderUtils.convertVHToPixels(extras?.qr?.size)
} else if (extras?.qr?.size?.includes("vw")) {
qrSize = RenderUtils.convertVWToPixels(extras?.qr?.size)
} else if (extras?.qr?.size) {
qrSize = parseInt(extras?.qr?.size)
}
return (
<div style={{
backgroundSize: extras?.backgroundImage ? 'cover' : undefined,
backgroundPosition: extras?.backgroundImage ? 'center' : undefined,
backgroundRepeat: extras?.backgroundImage ? 'no-repeat' : undefined,
backgroundColor: extras?.backgroundColor ?? "black",
backgroundImage: extras?.backgroundImage ? `url(${staticFile(RenderUtils.getFileName(extras?.backgroundImage!)!)})` : undefined,
...style
}}>
<div style={{
height: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
color: 'white',
justifyContent: 'space-around'
}}>
<div style={{
...extras.header?.position
}}>
{(transcript.title || extras.header?.text_title) && <h1 style={{
color: extras?.header?.color ?? '#1a1a1c',
fontFamily: extras?.header?.fontFamily ?? Montserrat,
...extras?.header?.title_style
}}>{extras.header?.text_title || transcript.title}</h1>
}
{
transcript.text && <h1 style={{
fontFamily: extras?.header?.fontFamily ?? Montserrat,
...extras?.header?.text_style
}}>
{transcript.text}
</h1>
}
{
extras?.header?.graphic?.source && (
<Img
src={staticFile(RenderUtils.getFileName(extras?.header?.graphic?.source)!)}
style={{
...extras?.header?.graphic?.position
}} />
)
}
</div>
<center style={{
marginLeft: -50
}}>
<QRCode
style={extras?.qr?.position ?? {
zIndex: 1000,
position: 'absolute',
top: 50,
left: 40
}}
bgColor={extras?.qr?.backgroundColor ?? 'transparent'}
fgColor={extras?.qr?.color ?? 'black'}
size={qrSize ?? defaultQrSize}
value={extras?.qr?.url}
qrStyle={extras?.qr?.qrStyle ?? 'squares'}
logoImage={logo}
logoWidth={qrSize ?? defaultQrSize}
logoHeight={qrSize ?? defaultQrSize}
logoOpacity={extras?.qr?.logoOpacity ?? 0.1}
removeQrCodeBehindLogo={false}
/>
{
extras?.header?.text_sec && (
<span dangerouslySetInnerHTML={{ __html: extras?.header?.text_sec }} style={{
fontFamily: Montserrat
}} />
)
}
{
extras?.header?.text_ter &&
<div
style={{
fontFamily: Montserrat
}}
dangerouslySetInnerHTML={{ __html: extras?.header?.text_ter }}>
</div>
}
</center>
</div>
</div>
)
}
export function PaperDriveBackCover({ transcript, style }: { transcript: Transcript, style?: CSSProperties }) {
const extras = transcript.extras as PaperDrivePageExtras
const { fontFamily: Montserrat } = loadMontserrat();
return (
<div style={{
backgroundSize: extras?.backgroundImage ? 'cover' : undefined,
backgroundPosition: extras?.backgroundImage ? 'center' : undefined,
backgroundRepeat: extras?.backgroundImage ? 'no-repeat' : undefined,
backgroundColor: extras?.backgroundColor ?? "black",
backgroundImage: extras?.backgroundImage ? `url(${staticFile(RenderUtils.getFileName(extras?.backgroundImage!)!)})` : undefined,
...style
}}>
<div style={{
fontFamily: Montserrat,
padding: 50,
flex: 1,
height: '100%',
flexDirection: 'column',
justifyContent: 'space-between',
display: 'flex',
color: 'white'
}}>
<div style={{
...extras.header?.position
}}>
<h2 dangerouslySetInnerHTML={{ __html: transcript.title }} />
<span dangerouslySetInnerHTML={{ __html: transcript.text }} />
</div>
<div>
{
extras?.footer?.text && <h2
dangerouslySetInnerHTML={{ __html: extras?.footer?.text }}
style={{
...extras?.footer?.text_style
}}
/>
}
</div>
</div>
</div>
)
}
|