Merge pull request #76 from TiE23/ISSUE-053

Issue 053
This commit is contained in:
Kyle Geib authored and GitHub committed 2022-03-17 08:15:11 -05:00
commit bf89bc96dc
20 files changed
+261 -103

No files matched your search

@@ -71,7 +71,6 @@ export function ChyronsDirectorControls() {
}
const newChyrons: BGChyrons = {
openState: 0,
relativePos: { top: "0", right: "0", bottom: "0", left: "0" },
mode: chyronMode,
subMode: chyronSubMode,
driver: {
+11 -6
View File
@@ -1,6 +1,10 @@
import { MockupBlock } from "../../Common/MockupBlock.styled";
import { PadBox } from "@bedrock-layout/padbox";
import VideoFeed from "../VideoFeed/VideoFeed";
import { MockupBlock } from "../../Common/MockupBlock.styled";
import { LayoutGrid, LayoutGridItem } from "../../Common/LayoutGrid.styled";
import { TimingTowerPrototypeControls } from "../../Workspaces/PrototypingControls/TimingTowerPrototype";
import { ChyronsDirectorControls } from "../BroadcastDirectorUI/Chyrons";
type LayoutProps = {
headerHeight?: number,
@@ -16,7 +20,7 @@ export function Layout({ headerHeight }: LayoutProps) {
>Timing Board UI</MockupBlock>
</LayoutGridItem>
<LayoutGridItem column={2} row={1} columnSpan={5} rowSpan={6} >
<LayoutGridItem column={2} row={1} columnSpan={5} rowSpan={8} >
<VideoFeed />
</LayoutGridItem>
@@ -32,10 +36,11 @@ export function Layout({ headerHeight }: LayoutProps) {
>Race Director UI</MockupBlock>
</LayoutGridItem>
<LayoutGridItem column={2} row={7} columnSpan={5} rowSpan={4}>
<MockupBlock
color="#4d828b"
>Broadcast Director UI</MockupBlock>
<LayoutGridItem column={2} row={9} columnSpan={5} rowSpan={2}>
<PadBox padding="lg">
<TimingTowerPrototypeControls />
<ChyronsDirectorControls />
</PadBox>
</LayoutGridItem>
</LayoutGrid>
);
@@ -1,9 +1,46 @@
import { VideoFeedFrame, BackgroundImageDiv } from "./styles";
import useMeasure from "react-use-measure";
import { calculateFitSize, calculateScale } from "../../../utils/styling";
import { theme } from "../../../shared/theme";
import { VideoFeedFrame, BackgroundImageDiv, DimensionsSpan, BroadcastLayout, Logo } from "./styles";
import { TimingBoard } from "../../BroadcastGraphics/TimingBoard";
import { ChyronContainer } from "../../BroadcastGraphics/Chyrons/Container";
import bg from "../../../public/images/misc/bg-standin.jpg";
import f1Logo from "../../../public/images/logos/f1-logo-white.svg";
export default function VideoFeed() {
return <VideoFeedFrame centered>
<BackgroundImageDiv src={bg} />
</VideoFeedFrame>;
const [frameRef, {
height: frameHeight,
width: frameWidth,
}] = useMeasure();
const {
dimensionsWidthPx: broadcastWidth,
dimensionsHeightPx: broadcastHeight,
logoHeightPx,
placement,
} = theme.broadcast;
const [layoutWidth, layoutHeight] = calculateFitSize(frameWidth, frameHeight,
[broadcastWidth, broadcastHeight]);
const layoutScale = calculateScale(layoutWidth, layoutHeight,
[broadcastWidth, broadcastHeight]);
return (
<VideoFeedFrame centered ref={frameRef}>
<DimensionsSpan>
Frame: {Math.floor(frameWidth)} x {Math.floor(frameHeight)}px
<br />
Scaled: {Math.floor(layoutWidth)} x {Math.floor(layoutHeight)}px ({(layoutScale * 100).toFixed(1)}%)
</DimensionsSpan>
<BackgroundImageDiv src={bg} />
<BroadcastLayout width={broadcastWidth} height={broadcastHeight} scale={layoutScale} >
<TimingBoard placement={placement.timingBoard} />
<ChyronContainer placement={placement.chyrons} />
<Logo height={logoHeightPx} placement={placement.logo} src={f1Logo} />
</BroadcastLayout>
</VideoFeedFrame>
);
}
@@ -1,9 +1,13 @@
import styled, { css } from "styled-components/macro";
import { Fraction, Placement, Px } from "../../../types/style";
import { placementStyleRules } from "../../../utils/styling";
type VideoFeedFrameProps = {
centered?: boolean,
};
export const VideoFeedFrame = styled.div<VideoFeedFrameProps>`
position: relative;
height: 100%;
width: 100%;
background-color: ${p => p.theme.colors.videoFrameBG};
@@ -20,6 +24,19 @@ export const VideoFeedFrame = styled.div<VideoFeedFrameProps>`
`}
`;
type BroadcastLayoutProps = {
height: Px,
width: Px,
scale: Fraction,
};
export const BroadcastLayout = styled.div.attrs<BroadcastLayoutProps>(({
height,
width,
scale,
}) => ({ style: { height, width, transform: `scale(${scale})` } }))<BroadcastLayoutProps>`
position: absolute;
`;
export const BackgroundImage = styled.img`
height: 100%;
max-width: 100%;
@@ -37,3 +54,21 @@ export const BackgroundImageDiv = styled.div<BackgroundImageDivProps>`
background-repeat: no-repeat;
background-position: 0% 50%;
`;
export const DimensionsSpan = styled.span`
position: absolute;
top: 5px;
right: 10px;
color: ${p => p.theme.colors.textWhite};
font-family: ${p => p.theme.fonts.f1Regular};
`;
type LogoProps = {
placement: Placement,
height: Px,
};
export const Logo = styled.img<LogoProps>`
position: absolute;
${({ placement }) => placementStyleRules(placement)}
height: ${({ height }) => height}px;
`;
@@ -2,14 +2,16 @@ import { useSelector } from "react-redux";
import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector";
import { workspaceSelector } from "../../../../features/workspace/workspaceSelector";
import { Placement } from "../../../../types/style";
import { ChyronDriver } from "../Driver";
import { DoubleChyronContainer } from "./styles";
import { ChyronPlacement, DoubleChyronContainer } from "./styles";
type ChyronContainerProps = {
debug?: boolean,
placement?: Placement,
};
export function ChyronContainer({ debug = false }: ChyronContainerProps) {
export function ChyronContainer({ debug = false, placement = {} }: ChyronContainerProps) {
const { chyrons } = useSelector(broadcastGraphicsSelector);
const { debugDurationMultiplier } = useSelector(workspaceSelector);
@@ -23,19 +25,20 @@ export function ChyronContainer({ debug = false }: ChyronContainerProps) {
debugDurationMultiplier={debug ? debugDurationMultiplier : 1}
/>
);
if (chyrons.subMode === "medium" && chyrons.driver.secondary) {
return (
<DoubleChyronContainer>
{primary}
<ChyronDriver
chyronData={chyrons.driver.secondary}
subMode={chyrons.subMode}
openState={chyrons.openState}
debugDurationMultiplier={debug ? debugDurationMultiplier : 1}
/>
</DoubleChyronContainer>
);
} else {
return primary;
}
return (
<ChyronPlacement placement={placement}>
{chyrons.subMode === "medium" && chyrons.driver.secondary ? (
<DoubleChyronContainer>
{primary}
<ChyronDriver
chyronData={chyrons.driver.secondary}
subMode={chyrons.subMode}
openState={chyrons.openState}
debugDurationMultiplier={debug ? debugDurationMultiplier : 1}
/>
</DoubleChyronContainer>
) : primary}
</ChyronPlacement>
);
}
@@ -1,7 +1,19 @@
import styled from "styled-components/macro";
import { Placement } from "../../../../types/style";
import { placementStyleRules } from "../../../../utils/styling";
export const DoubleChyronContainer = styled.div`
display: flex;
justify-content: space-between;
width: 1196px;
`;
type ChyronPlacementProps = {
placement: Placement,
};
export const ChyronPlacement = styled.div<ChyronPlacementProps>`
position: absolute;
${({ placement }) => placementStyleRules(placement)}
`;
@@ -1,7 +1,7 @@
import { useSpring } from "@react-spring/web";
import { useDispatch } from "react-redux";
import { BGChyronDriver, BGChyronSubMode, OpenState } from "../../../../types/state";
import { BGChyronDriver, BGChyronSubMode, CarStatus, OpenState } from "../../../../types/state";
import { DebugDurationProps } from "../../../../types/style";
import { clearChyrons } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice";
import { theme } from "../../../../shared/theme";
@@ -98,7 +98,7 @@ export function ChyronDriver({
progress,
5,
);
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
}),
}}
/>
@@ -133,7 +133,7 @@ export function ChyronDriver({
teamColor={teamColor}
/>
<Spacer width="6px" />
{showPosFlag && (
{showPosFlag && car.status !== CarStatus.Retired && (
<VenetianBlindsTransition
visible={openState !== 0}
delay={500 * DDM}
@@ -64,7 +64,7 @@ export function WipeTransition({
startingCorner,
angle,
);
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
}),
}}
ref={childRef}
@@ -1,6 +1,7 @@
import { useSelector } from "react-redux";
import { workspaceSelector } from "../../../features/workspace/workspaceSelector";
import { Placement } from "../../../types/style";
import { TimingBoardLayout } from "./styles";
import { TimingTower } from "./TimingTower";
@@ -8,11 +9,13 @@ import { StatusIndicator } from "./StatusIndicator";
type TimingBoardProps = {
debug?: boolean,
placement?: Placement,
};
export function TimingBoard({ debug = false }: TimingBoardProps) {
export function TimingBoard({ debug = false, placement = {} }: TimingBoardProps) {
const { debugDurationMultiplier } = useSelector(workspaceSelector);
return (
<TimingBoardLayout>
<TimingBoardLayout placement={placement}>
<StatusIndicator
debugDurationMultiplier={debug ? debugDurationMultiplier : 1}
/>
@@ -153,6 +153,13 @@ export function TimingTowerRow({
xScale = rightHalfContent.includes(":") ? 0.75 : 0.9;
yScale = rightHalfContent.includes("+") ? 1.1 : 1.0;
if (rightHalfContent.includes("LAPS") && rightHalfContent.length > 7) {
xScale = 0.85; // Extreme edge case where +10 laps or more behind.
}
if (rightHalfContent.length > 9) {
xScale = 0.7; // Extreme edge case where +10 minutes or more behind.
}
}
return (
@@ -305,7 +312,7 @@ export function TimingTowerRow({
3,
3,
);
return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`;
}),
}}
/>
@@ -221,6 +221,7 @@ export const TimeDiff = styled.span<TimeDiffProps>`
color: ${p => p.theme.colors.textWhite};
font-family: ${p => p.theme.fonts.f1Regular};
font-size: 20px;
white-space: nowrap;
text-align: end;
@@ -1,7 +1,14 @@
import styled from "styled-components/macro";
export const TimingBoardLayout = styled.div`
position: relative;
import { Placement } from "../../../types/style";
import { placementStyleRules } from "../../../utils/styling";
type TimingBoardLayoutProps = {
placement: Placement,
};
export const TimingBoardLayout = styled.div<TimingBoardLayoutProps>`
position: absolute;
${({ placement }) => placementStyleRules(placement)}
display: flex;
flex-direction: column;
+7 -5
View File
@@ -1,17 +1,19 @@
import { keys } from "lodash";
import { BGChyronSubMode, BGChyronMode, BGRelativePos, FlagMode } from "../../types/state";
import { BGChyronSubMode, BGChyronMode, FlagMode } from "../../types/state";
import { Placement } from "../../types/style";
// Chyrons Section
const chyronsData: {
[mode: BGChyronMode]: {
relativePos: BGRelativePos,
placement: Placement,
subModes: {
[subMode: BGChyronSubMode]: Record<string, unknown>,
},
},
} = {
driver: {
relativePos: { top: "0", right: "0", bottom: "0", left: "0" },
placement: { top: "0", right: "0", bottom: "0", left: "0" },
subModes: {
medium: { width: 582, height: 72 },
large: { width: 638, height: 98 },
@@ -25,8 +27,8 @@ export function getChyronModesList(): Array<BGChyronMode> {
return keys(chyronsData);
}
export function getChyronRelativePos(mode: BGChyronMode): BGRelativePos {
return chyronsData[mode]?.relativePos
export function getChyronRelativePos(mode: BGChyronMode): Placement {
return chyronsData[mode]?.placement
?? { top: "0", right: "0", bottom: "0", left: "0" };
}
@@ -13,13 +13,12 @@ import {
const initialState: RootState["broadcastGraphics"] = {
chyrons: null,
timingBoard: {
relativePos: {},
openState: 0,
openState: 1,
statusIndicator: {
mode: BGStatusIndicatorModes.LapNarrow,
},
timingTower: {
open: 1,
openState: 1,
displayMode: BGTimingTowerDisplayMode.LeftAndRight,
splitsMode: BGTimingTowerSplitsMode.Leader,
focusedCars: [],
+2 -2
View File
@@ -72,7 +72,7 @@ const initialState: RootState["event"] = {
},
{
position: 4,
status: CarStatus.Retired,
status: CarStatus.Normal,
tyre: DEFAULT_TYRE,
notices: [],
distance: POLE_TO_START - GRID_POSITION_GAP * 3,
@@ -88,7 +88,7 @@ const initialState: RootState["event"] = {
},
{
position: 6,
status: CarStatus.Retired,
status: CarStatus.Normal,
tyre: DEFAULT_TYRE,
notices: [],
distance: POLE_TO_START - GRID_POSITION_GAP * 5,
+1 -12
View File
@@ -1,12 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="100%" style="fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;" xmlnsXlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" xmlSpace="preserve" width="100%" version="1.1" viewBox="0 0 120 30">
<defs />
<g id="Logos-/-F1-logo-red">
<path
d="M101.087+30L101.712+30L101.712+27.1069L101.722+27.1069L102.762+30L103.302+30L104.342+27.1069L104.352+27.1069L104.352+30L104.977+30L104.977+26.2512L104.064+26.2512L103.056+29.1863L103.045+29.1863L102.011+26.2512L101.087+26.2512L101.087+30ZM97.6274+26.8181L98.8137+26.8181L98.8137+30L99.4699+30L99.4699+26.8181L100.662+26.8181L100.662+26.2512L97.6274+26.2512L97.6274+26.8181ZM89.9999+30L120+0L101.944+0L71.9443+30L89.9999+30ZM85.6987+13.065L49.3818+13.065C38.3137+13.065+36.3768+13.6519+31.6362+18.3925C27.2024+22.8263+20.0006+30+20.0006+30L35.7324+30L39.4856+26.2469C41.9531+23.7794+43.2256+23.5238+48.4068+23.5238L75.2406+23.5238L85.6987+13.065ZM31.1518+16.2531C27.8774+19.3425+20.7531+26.2631+16.9131+30L-6.25e-05+30C-6.25e-05+30+13.5524+16.4869+21.0849+9.0725C28.8456+1.685+32.7143+0+46.9487+0L98.7643+0L87.5449+11.2188L48.0012+11.2188C37.9993+11.2188+35.7518+11.9119+31.1518+16.2531Z"
opacity="1"
fill="#ee0000"
/>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 30" clip-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"><path d="M101.087 30h.625v-2.893h.01l1.04 2.893h.54l1.04-2.893h.01V30h.625v-3.749h-.913l-1.008 2.935h-.011l-1.034-2.935h-.924V30zm-3.46-3.182h1.187V30h.656v-3.182h1.192v-.567h-3.035v.567zM90 30l30-30h-18.056l-30 30H90zm-4.301-16.935H49.382c-11.068 0-13.005.587-17.746 5.327A10905.28 10905.28 0 0120.001 30h15.731l3.754-3.753c2.467-2.468 3.74-2.723 8.92-2.723h26.835l10.458-10.459zm-54.547 3.188C27.877 19.343 20.753 26.263 16.913 30H0S13.552 16.487 21.085 9.072C28.845 1.685 32.715 0 46.949 0h51.815l-11.22 11.219H48.002c-10.002 0-12.25.693-16.85 5.034z" fill="#e00"/></svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 702 B

+1
View File
@@ -0,0 +1 @@
<svg viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><path id="prefix__a" d="M101.09 30h.625v-2.893h.01l1.04 2.893h.54l1.04-2.893h.01V30h.626v-3.749h-.914l-1.008 2.935h-.01l-1.035-2.935h-.924V30zm-3.46-3.182h1.187V30h.656v-3.182h1.192v-.567h-3.034v.567zM90.004 30l30-30h-18.056L71.948 30h18.056zm-4.301-16.935H49.385c-11.068 0-13.005.587-17.746 5.328C27.205 22.826 20.003 30 20.003 30h15.732l3.753-3.754c2.468-2.467 3.74-2.723 8.921-2.723h26.834l10.458-10.459zm-54.547 3.188c-3.274 3.09-10.4 10.01-14.24 13.747H.004S13.555 16.487 21.088 9.072C28.848 1.685 32.717 0 46.952 0h51.816l-11.22 11.219H48.006c-10.002 0-12.25.693-16.85 5.034z"/></defs><use fill="#FFF" xlink:href="#prefix__a" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 769 B

+10
View File
@@ -102,6 +102,16 @@ export const theme = {
medRadius: "11px",
smRadius: "7px",
},
broadcast: {
dimensionsWidthPx: 1920,
dimensionsHeightPx: 1080,
logoHeightPx: 40,
placement: {
chyrons: { bottom: "52px", left: "378px" },
timingBoard: { top: "54px", left: "96px" },
logo: { left: "86px", bottom: "52px" },
},
},
};
export type MainThemeProps = ThemeProps<typeof theme>;
+2 -9
View File
@@ -1,5 +1,5 @@
import { Meters, Milliseconds, Optional } from "./util";
import { Corner, Fraction } from "./style";
import { Corner, Fraction, Placement } from "./style";
export interface RootState {
pageDimensions: PageDimensions;
@@ -253,14 +253,7 @@ export interface BroadcastDirector {
}
// Broadcast Graphics
export interface BGRelativePos {
top?: string;
right?: string;
bottom?: string;
left?: string;
}
export interface BGBaseState {
relativePos: BGRelativePos;
openState: OpenState;
}
/**
@@ -293,7 +286,7 @@ export enum BGStatusIndicatorModes {
// Timing Tower
export interface BGTimingTower {
open: OpenState;
openState: OpenState;
displayMode: BGTimingTowerDisplayMode;
splitsMode: BGTimingTowerSplitsMode,
focusedCars: Car[],
+90 -35
View File
@@ -1,7 +1,7 @@
import { css }from "styled-components/macro";
import { clamp } from "lodash";
import { Corner, Fraction, Placement, Px, TransitionArgs } from "../types/style";
import { Corner, Fraction, Percent, Placement, Px, TransitionArgs } from "../types/style";
import { Seconds } from "../types/util";
export function placementStyleRules(pos: Placement) {
@@ -14,6 +14,18 @@ export function placementStyleRules(pos: Placement) {
}
/**
* Call to create a function that can be re-used to generate a pair of percent
* values to use on a clip-path.
* This was necessary to deal with double-applied scaling issues when using
* element measurement hooks.
* @param width the width of the element to be clipped in pixels
* @param height the height of the element to be clipped in pixels
* @returns A function that can be used to convert pixel values into percent values
*/
const clipConvertToPercent = (width: Px, height: Px) =>
([x, y]: [Px, Px]): [Percent, Percent] => [x / width * 100, y / height * 100];
/**
* Provides the x, y coordinates of a three point polygon for use in a clip-path
* mask. By taking a fraction to indicate the progress through the animation it
@@ -23,7 +35,7 @@ export function placementStyleRules(pos: Placement) {
* @param progress fraction from 0 to 1
* @param startingCorner Which corner the wipe originates from
* @param degrees The angle in degrees of the wipe
* @returns Array of six numbers representing pixel values of the clip-path
* @returns Array of three pairs of percentages to the coordinates of the clip-path
*/
export function wipeCustomDegClip(
width: Px,
@@ -31,33 +43,34 @@ export function wipeCustomDegClip(
progress: Fraction,
startingCorner: Corner,
degrees: number,
): [[Px, Px], [Px, Px], [Px, Px]] {
): [[Percent, Percent], [Percent, Percent], [Percent, Percent]] {
const tangent = Math.tan(clamp(degrees, 0.01, 90) * Math.PI / 180);
const convert = clipConvertToPercent(width, height);
switch (startingCorner) {
case "topLeft":
return [
[0, 0],
[(width + height / tangent) * progress, 0],
[0, (height + width * tangent) * progress ],
convert([0, 0]),
convert([(width + height / tangent) * progress, 0]),
convert([0, (height + width * tangent) * progress ]),
];
case "topRight":
return [
[width, 0],
[width, (height + width * tangent) * progress],
[width - (width + height / tangent) * progress, 0],
convert([width, 0]),
convert([width, (height + width * tangent) * progress]),
convert([width - (width + height / tangent) * progress, 0]),
];
case "bottomRight":
return [
[width, height],
[width, height - (height + width * tangent) * progress],
[width - (width + height / tangent) * progress, height],
convert([width, height]),
convert([width, height - (height + width * tangent) * progress]),
convert([width - (width + height / tangent) * progress, height]),
];
case "bottomLeft":
return [
[0, height],
[0, height - (height + width * tangent) * progress],
[(width + height / tangent) * progress, height],
convert([0, height]),
convert([0, height - (height + width * tangent) * progress]),
convert([(width + height / tangent) * progress, height]),
];
}
}
@@ -114,7 +127,7 @@ export function commonDirectionalTransition(
* @param progress fraction from 0 to 1
* @param outlineThickness the expected max width of the outline
* @param interiorThickness the expected max width of the outline internally
* @returns
* @returns Array of six pairs of percentages to the coordinates of the clip-path
*/
export function outlineClipPath(
width: Px,
@@ -122,45 +135,53 @@ export function outlineClipPath(
progress: Fraction,
outlineThickness: Px,
interiorThickness: Px = 0,
): [[Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px]] {
): [
[Percent, Percent],
[Percent, Percent],
[Percent, Percent],
[Percent, Percent],
[Percent, Percent],
[Percent, Percent],
] {
const travelDistance = width * 2 + height;
const pt1End = width / travelDistance;
const pt2End = (width + height) / travelDistance;
const convert = clipConvertToPercent(width, height);
// Part 1: Reveal the bottom line.
if (progress <= pt1End) {
const x = width * progress / pt1End;
return [
[0, height - interiorThickness],
[0, height - interiorThickness],
[0, height - interiorThickness],
[x, height - interiorThickness],
[x, height + outlineThickness],
[0, height + outlineThickness],
convert([0, height - interiorThickness]),
convert([0, height - interiorThickness]),
convert([0, height - interiorThickness]),
convert([x, height - interiorThickness]),
convert([x, height + outlineThickness]),
convert([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 - interiorThickness],
[width - Math.max(10, interiorThickness), height - interiorThickness],
[width - interiorThickness, y],
[width + outlineThickness, y],
[width + outlineThickness, height + outlineThickness],
[0, height + outlineThickness],
convert([0, height - interiorThickness]),
convert([width - Math.max(10, interiorThickness), height - interiorThickness]),
convert([width - interiorThickness, y]),
convert([width + outlineThickness, y]),
convert([width + outlineThickness, height + outlineThickness]),
convert([0, height + outlineThickness]),
];
// Part 3: Reveal the top line.
} else {
const x = width - width * ((progress - pt2End) / (1 - pt2End));
return [
[0, height - interiorThickness],
[x - Math.max(10, interiorThickness), height - interiorThickness],
[x - interiorThickness, -outlineThickness],
[width + outlineThickness, -outlineThickness],
[width + outlineThickness, height + outlineThickness],
[0, height + outlineThickness],
convert([0, height - interiorThickness]),
convert([x - Math.max(10, interiorThickness), height - interiorThickness]),
convert([x - interiorThickness, -outlineThickness]),
convert([width + outlineThickness, -outlineThickness]),
convert([width + outlineThickness, height + outlineThickness]),
convert([0, height + outlineThickness]),
];
}
}
@@ -182,3 +203,37 @@ export function formatTime(time: Seconds, limit: Seconds) {
const seconds = time % 60;
return `${minutes}:${seconds.toFixed(3).padStart(6, "0")}`;
}
/**
* Given a frame to work within, this will return the dimensions of an element
* that will best fit into this given frame with a specific ratio.
* @param frameWidth Width of the working frame in pixels
* @param frameHeight Width of the working frame in pixels
* @param ratioWH Ratio in the form of [width, height]
* @returns Dimensions [width, height] of a fitted element in pixels
*/
export function calculateFitSize(frameWidth: Px, frameHeight: Px, ratioWH: [number, number]): [Px, Px] {
const [w, h] = ratioWH;
let scaledWidth = frameWidth;
let scaledHeight = frameHeight;
if ((frameWidth / frameHeight) > (w / h)) { // Wider frame.
scaledWidth = frameHeight / h * w;
} else if ((frameWidth / frameHeight) < (w / h)) { // Narrower frame.
scaledHeight = frameWidth / w * h;
}
return [scaledWidth, scaledHeight];
}
/**
* Given a fit element's dimensions in pixels this take the provided reference
* width and height defined in pixels and return the scale the fitted element
* is currently at.
* @param fitWidth Width of the fitted element in pixels
* @param fitHeight Height of the fitted element in pixels
* @param referenceWH Dimensions that we need to be scaled to [width, height] in pixels
* @returns Scale of the fitted element as a fraction
*/
export function calculateScale(fitWidth: Px, fitHeight: Px, referenceWH: [Px, Px]): Fraction {
return (fitWidth / referenceWH[0] + fitHeight / referenceWH[1]) / 2;
}