Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/hooks/useFontManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Handles font file uploads, validation, and registration.
*/

import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { validateFontFile, extractFontName, detectDuplicateFonts } from "@/utils/fontValidation";
import {
registerCustomFont,
Expand Down Expand Up @@ -46,6 +46,7 @@ interface UseFontManagerReturn {
*/
export function useFontManager(): UseFontManagerReturn {
const [customFonts, setCustomFonts] = useState<CustomFont[]>([]);
const customFontsRef = useRef(customFonts);
const [errors, setErrors] = useState<string[]>([]);

// Initialize font registry on mount
Expand Down Expand Up @@ -80,7 +81,7 @@ export function useFontManager(): UseFontManagerReturn {
const fontName = extractFontName(file.name);

// Check for duplicate name
if (customFonts.some((f) => f.name === fontName)) {
if (customFontsRef.current.some((f) => f.name === fontName)) {
newErrors.push(`${file.name}: Font "${fontName}" already uploaded`);
continue;
}
Expand Down Expand Up @@ -130,7 +131,7 @@ export function useFontManager(): UseFontManagerReturn {
errors: newErrors,
};
},
[customFonts]
[]
);

/**
Expand All @@ -154,6 +155,8 @@ export function useFontManager(): UseFontManagerReturn {
setErrors([]);
}, []);

customFontsRef.current = customFonts;

return {
customFonts,
addFonts,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/frame-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export async function captureFrameAsPng(
video.videoHeight
);

if (width === 0 || height === 0 || !isFinite(scale) || scale <= 0) {
throw new Error("Invalid output dimensions computed for frame export.");
}

const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
Expand Down
1 change: 1 addition & 0 deletions src/lib/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export function validateMultiTrackState(state: MultiTrackEditorState): {

if (!Array.isArray(state.timelineTracks)) {
errors.push("timelineTracks must be an array");
return { valid: false, errors };
}

const videoTracks = state.timelineTracks.filter(t => t.type === "video");
Expand Down