|
|
import { useMemo, useCallback } from 'react'; |
|
|
import { calculatePositions } from '../utils/fontUtils'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const usePositioning = (fonts, width, height, dilationFactor) => { |
|
|
|
|
|
const positions = useMemo(() => { |
|
|
if (!fonts.length || width <= 0 || height <= 0) { |
|
|
return []; |
|
|
} |
|
|
|
|
|
console.log('usePositioning: Calculating positions for', fonts.length, 'fonts'); |
|
|
return calculatePositions(fonts, width, height, dilationFactor); |
|
|
}, [fonts, width, height, dilationFactor]); |
|
|
|
|
|
|
|
|
const recalculatePositions = useCallback(() => { |
|
|
if (!fonts.length || width <= 0 || height <= 0) { |
|
|
return []; |
|
|
} |
|
|
return calculatePositions(fonts, width, height, dilationFactor); |
|
|
}, [fonts, width, height, dilationFactor]); |
|
|
|
|
|
|
|
|
const getFontPosition = useCallback((fontName) => { |
|
|
return positions.find(p => p.name === fontName); |
|
|
}, [positions]); |
|
|
|
|
|
return { |
|
|
positions, |
|
|
recalculatePositions, |
|
|
getFontPosition, |
|
|
hasPositions: positions.length > 0 |
|
|
}; |
|
|
}; |
|
|
|