import type {Instruction} from '@remotion/paths'; import React, {useMemo} from 'react'; import {version} from 'react-dom'; import { HtmlInCanvas, Freeze, Sequence, Internals, type EffectsProp, type EffectsOutputSize, type HtmlInCanvasPixelDensity, type HtmlInCanvasProps, type InteractiveBaseProps, type InteractivePremountProps, type SequenceControls, } from 'remotion'; import {doesReactSupportTransformOriginProperty} from '../utils/does-react-support-canary'; type ShapeSequenceProps = InteractiveBaseProps & InteractivePremountProps & { readonly controls?: SequenceControls; }; const HtmlInCanvasWithPrivateProps = HtmlInCanvas as React.ComponentType< HtmlInCanvasProps & { readonly controls?: SequenceControls; readonly ref?: React.Ref; } >; export type AllShapesProps = Omit< React.SVGProps, 'width' | 'height' | 'd' | 'hidden' | 'name' > & ShapeSequenceProps & { readonly debug?: boolean; readonly effects?: EffectsProp; readonly effectsOutputSize?: EffectsOutputSize; readonly pathStyle?: React.CSSProperties; readonly pixelDensity?: HtmlInCanvasPixelDensity; }; const RenderSvgWithTiming = ({ premountFor, postmountFor, styleWhilePremounted, styleWhilePostmounted, from, trimBefore, playbackRate, loop, freeze, hidden, showInTimeline, controls, durationInFrames, name, defaultName, documentationLink, memoizedEffectDefinitions, content, actualStyle, }: ShapeSequenceProps & { readonly defaultName: string; readonly documentationLink: string; readonly content: React.ReactElement>; readonly actualStyle: React.CSSProperties; readonly memoizedEffectDefinitions: ReturnType< typeof Internals.useMemoizedEffectDefinitions >; }) => { const { effectivePremountFor, effectivePostmountFor, freezeFrame, isPremountingOrPostmounting, premountingActive, postmountingActive, premountingStyle, } = Internals.usePremounting({ from: from ?? 0, durationInFrames: Internals.resolveSequenceDuration({ durationInFrames, playbackRate, loop, }), premountFor: premountFor ?? null, postmountFor: postmountFor ?? null, style: actualStyle, styleWhilePremounted: styleWhilePremounted ?? null, styleWhilePostmounted: styleWhilePostmounted ?? null, hideWhilePremounted: 'opacity', }); return ( ); }; export const RenderSvg = ({ pathRef, defaultName, documentationLink, width, height, path, style, pathStyle, transformOrigin, debug, effects = [], effectsOutputSize, instructions, pixelDensity, durationInFrames, from, premountFor, postmountFor, styleWhilePremounted, styleWhilePostmounted, trimBefore, playbackRate, loop, freeze, hidden, name, showInTimeline, controls, ...props }: { readonly pathRef: React.Ref; readonly defaultName: string; readonly documentationLink: string; readonly width: number; readonly height: number; readonly path: string; readonly instructions: Instruction[]; readonly transformOrigin: string; } & Omit) => { const actualStyle = useMemo((): React.CSSProperties => { return { overflow: 'visible', ...(style ?? {}), }; }, [style]); const actualPathStyle = useMemo((): React.CSSProperties => { return { transformBox: 'fill-box', ...(pathStyle ?? {}), }; }, [pathStyle]); const memoizedEffectDefinitions = Internals.useMemoizedEffectDefinitions(effects); const videoConfig = Internals.useUnsafeVideoConfig(); const reactSupportsTransformOrigin = doesReactSupportTransformOriginProperty(version); const svg = ( {debug ? instructions.map((i, index) => { if (i.type === 'C') { const prevInstruction = index === 0 ? instructions[instructions.length - 1] : instructions[index - 1]; if ( prevInstruction.type === 'V' || prevInstruction.type === 'H' || prevInstruction.type === 'a' || prevInstruction.type === 'Z' || prevInstruction.type === 't' || prevInstruction.type === 'q' || prevInstruction.type === 'l' || prevInstruction.type === 'c' || prevInstruction.type === 'm' || prevInstruction.type === 'h' || prevInstruction.type === 's' || prevInstruction.type === 'v' ) { return null; } const prevX = prevInstruction.x; const prevY = prevInstruction.y; return ( // eslint-disable-next-line react/no-array-index-key ); } return null; }) : null} ); const content = effects.length === 0 ? ( svg ) : ( {svg} ); if (!videoConfig) { return svg; } return (