diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx index 905e75d..11cb258 100644 --- a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx +++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx @@ -5,6 +5,7 @@ import { BGChyronDriver, BGChyronSubMode, OpenState } from "../../../../types/st import { Fraction } from "../../../../types/style"; import { clearChyrons } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice"; import { theme } from "../../../../shared/theme"; +import { outlineClipPath } from "../../../../utils/styling"; import { DriverNumber } from "../../Common/DriverNumber"; import { AngledFlag } from "../../Common/AngledFlag"; @@ -13,7 +14,7 @@ import { DriverPortrait } from "../../Common/DriverPortrait"; import { AnimatedBaseContainer, BaseLayout, - BaseOutline, + AnimatedBaseOutline, BaseBlack, BaseBackgroundColor, FirstName, @@ -46,6 +47,7 @@ export function ChyronDriver({ : [0, 0]; const { car, flagMode, showPosFlag, showDriverNumber, showPortrait } = chyronData; + const flagProps = flagMode === "country" ? { flagMode, flag: car.driver.nationality } : flagMode === "team" ? { flagMode, flag: car.driver.team.id } : undefined; @@ -63,6 +65,12 @@ export function ChyronDriver({ }, }); + const { outlineClipPathProgress } = useSpring({ + outlineClipPathProgress: openState !== 0 ? 1 : 0, + config: { duration: 500 * DDM }, + delay: 0, + }); + const teamColor = theme.colors.teams[car.driver.team.id]; return ( @@ -71,12 +79,27 @@ export function ChyronDriver({ height={baseHeight} style={containerFadeAwaySpring} > - { + const coordinates = outlineClipPath( + baseWidth, + baseHeight, + progress, + 5, + ); + return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`; + }), + }} /> ` +type AnimatedBaseOutlineProps = TransitionProps & { + startThickness: Px, + endThickness: Px, + startColor: string, + endColor: string, +}; +export const AnimatedBaseOutline = animated(styled(BaseShape)` width: 100%; opacity: ${({ open }) => open ? 1 : 0}; - outline: ${({ open }) => open - ? "2px solid #ffffff00" - : "5px solid #ffffffff"}; + outline: ${({ open, startThickness, endThickness, startColor, endColor }) => open + ? `${endThickness}px solid ${endColor}` + : `${startThickness}px solid ${startColor}`}; ${({ transitionProps }) => commonTransition(transitionProps)} -`; -BaseOutline.displayName = "BaseOutline"; +`); +AnimatedBaseOutline.displayName = "AnimatedBaseOutline"; export const BaseBlack = styled(BaseShape)` opacity: ${({ open }) => open ? 1 : 0.1}; diff --git a/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx b/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx index 6acd92c..759db5e 100644 --- a/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx +++ b/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx @@ -1,4 +1,4 @@ -import { useSpring, animated } from "@react-spring/web"; +import { useSpring, animated, easings } from "@react-spring/web"; import useMeasure from "react-use-measure"; import { AnimatedVenetianBlindsFilter, VenetianBlindsFilter } from "./styles"; @@ -52,7 +52,10 @@ export const VenetianBlindsTransition = ( const { wipe } = useSpring({ wipe: visible ? 1 : 0, - config: { duration: wipeDuration }, + config: { + duration: wipeDuration, + easing: easings.easeInOutQuint, + }, delay: 0 + delay, }); @@ -73,14 +76,14 @@ export const VenetianBlindsTransition = ( style={{ opacity, clipPath: wipe.to(wipeProgress => { - const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip( + const coordinates = wipeCustomDegClip( childWidth, childHeight, wipeProgress, wipeStartingCorner, wipeAngle, ); - return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`; + return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`; }), }} ref={childRef} diff --git a/src/utils/styling.ts b/src/utils/styling.ts index 15f3f60..8ddfcd3 100644 --- a/src/utils/styling.ts +++ b/src/utils/styling.ts @@ -30,33 +30,33 @@ export function wipeCustomDegClip( progress: Fraction, startingCorner: Corner, degrees: number, -): [Px, Px, Px, Px, Px, Px] { +): [[Px, Px], [Px, Px], [Px, Px]] { const tangent = Math.tan(clamp(degrees, 0.01, 90) * Math.PI / 180); switch (startingCorner) { case "topLeft": return [ - 0, 0, - (width + height / tangent) * progress, 0, - 0, (height + width * tangent) * progress , + [0, 0], + [(width + height / tangent) * progress, 0], + [0, (height + width * tangent) * progress ], ]; case "topRight": return [ - width, 0, - width, (height + width * tangent) * progress, - width - (width + height / tangent) * progress, 0, + [width, 0], + [width, (height + width * tangent) * progress], + [width - (width + height / tangent) * progress, 0], ]; case "bottomRight": return [ - width, height, - width, height - (height + width * tangent) * progress, - width - (width + height / tangent) * progress, height, + [width, height], + [width, height - (height + width * tangent) * progress], + [width - (width + height / tangent) * progress, height], ]; case "bottomLeft": return [ - 0, height, - 0, height - (height + width * tangent) * progress, - (width + height / tangent) * progress, height, + [0, height], + [0, height - (height + width * tangent) * progress], + [(width + height / tangent) * progress, height], ]; } } @@ -70,3 +70,56 @@ export function commonTransition(propsArray: TransitionArgs[]) { + ";" ); } + +export function outlineClipPath( + width: Px, + height: Px, + progress: Fraction, + outlineThickness: Px, +): [[Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px]] { + const travelDistance = width * 2 + height; + const pt1End = width / travelDistance; + const pt2End = (width + height) / travelDistance; + + // Part 1: Reveal the bottom line. + if (progress <= pt1End) { + const x = width * progress / pt1End; + return [ + [0, height], + [0, height], + [0, height], + [x, height], + [x, height + outlineThickness], + [0, height + outlineThickness], + ]; + + // Part 2: Reveal the right line. + } else if (progress > pt1End && progress <= pt2End) { + const y = height - (height + outlineThickness) * ((progress - pt1End) / (pt2End - pt1End)); + return [ + [0, height], + [width - 10, height], + [width, y], + [width + outlineThickness, y], + [width + outlineThickness, height + outlineThickness], + [0, height + outlineThickness], + ]; + + // Part 3: Reveal the top line. + } else { + const x = width - width * ((progress - pt2End) / (1 - pt2End)); + return [ + [0, height], + [x - 10, height], + [x, -outlineThickness], + [width + outlineThickness, -outlineThickness], + [width + outlineThickness, height + outlineThickness], + [0, height + outlineThickness], + ]; + } + + + // return [ + + // ] +}