|
|
import * as d3 from 'd3'; |
|
|
import { calculatePositions as calculateVoronoiPositions } from './voronoiDilation'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getFontSymbolId = (fontName) => { |
|
|
if (!fontName) return 'fallback_a'; |
|
|
|
|
|
|
|
|
|
|
|
return fontName.toLowerCase() + '_a'; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const matchesSearch = (font, searchTerm) => { |
|
|
if (!searchTerm) return true; |
|
|
const searchLower = searchTerm.toLowerCase(); |
|
|
return font.name.toLowerCase().includes(searchLower) || |
|
|
font.family.toLowerCase().includes(searchLower); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const generateGoogleFontsUrl = (fontName) => { |
|
|
if (!fontName) return null; |
|
|
|
|
|
|
|
|
const formattedName = fontName |
|
|
.trim() |
|
|
.replace(/\s+/g, '+') |
|
|
.replace(/[^\w\s+]/g, '') |
|
|
.replace(/\s+/g, '+'); |
|
|
|
|
|
return `https://fonts.google.com/specimen/${formattedName}`; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const filterFonts = (fonts, filter, searchTerm) => { |
|
|
return fonts.filter(font => { |
|
|
|
|
|
const familyMatch = filter === 'all' || font.family === filter; |
|
|
|
|
|
|
|
|
const searchMatch = matchesSearch(font, searchTerm); |
|
|
|
|
|
return familyMatch && searchMatch; |
|
|
}); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const calculatePositions = (fonts, width, height, dilationFactor) => { |
|
|
return calculateVoronoiPositions(fonts, width, height, dilationFactor); |
|
|
}; |
|
|
|