/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/scene/text-html/__tests__/textStyleToCSS.test.ts
73 строки
2 KB
Zyie
fix: improve html text measurement (#11862)
03 фев 2026, 16:24
Не верифицирован
03 фев 2026, 16:24
09c020f
Код
Авторство
О чём код?
import { HTMLTextStyle } from '../HTMLTextStyle'; import { textStyleToCSS } from '../utils/textStyleToCSS'; function formatCSSString(cssString: string) { return cssString .replace(/\s+/g, ' ') // Replace multiple white spaces with a single space .replace(/\s*;\s*/g, '; ') // Normalize spaces around semicolons .replace(/\s*:\s*/g, ': ') // Normalize spaces around colons .trim(); // Remove leading and trailing white spaces } describe('textStyleToCSS', () => { it('should extract css correctly', async () => { const css = textStyleToCSS(new HTMLTextStyle({ fontFamily: 'Arial', fontStyle: 'normal', fontWeight: 'normal', })); const expected = `div { color: #000000ff; font-size: 26px; font-family: Arial; font-weight: normal; font-style: normal; font-variant: normal; letter-spacing: 0px; text-align: left;padding: 0px; white-space: pre }`; expect(formatCSSString(css)).toBe(formatCSSString(expected)); }); it('should extract css correctly if there are tagStyles', async () => { const css = textStyleToCSS(new HTMLTextStyle({ fontFamily: 'Cargo', fontStyle: 'normal', fontWeight: 'normal', tagStyles: { comic: { fontFamily: 'Comic Sans', fontSize: 20, }, } })); const expected = `div { color: #000000ff; font-size: 26px; font-family: Cargo; font-weight: normal; font-style: normal; font-variant: normal; letter-spacing: 0px; text-align: left; padding: 0px; white-space: pre } comic { font-family: Comic Sans; font-size: 20px }`; expect(formatCSSString(css)).toBe(formatCSSString(expected)); }); });