/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/scene/text/utils/generateTextStyleKey.ts
105 строк
3 KB
Zyie
feat: simplified caching for text (#11505)
02 сен 2025, 15:27
Не верифицирован
02 сен 2025, 15:27
e301117
Код
Авторство
О чём код?
import { Color } from '../../../color/Color'; import { type Filter } from '../../../filters/Filter'; import type { ConvertedFillStyle, ConvertedStrokeStyle } from '../../graphics/shared/FillTypes'; import type { HTMLTextStyle } from '../../text-html/HTMLTextStyle'; import type { TextStyle } from '../TextStyle'; const valuesToIterateForKeys: Partial<keyof TextStyle | keyof HTMLTextStyle>[] = [ 'align', 'breakWords', 'cssOverrides', 'fontVariant', 'fontWeight', 'leading', 'letterSpacing', 'lineHeight', 'padding', 'textBaseline', 'trim', 'whiteSpace', 'wordWrap', 'wordWrapWidth', 'fontFamily', 'fontStyle', 'fontSize', ] as const; /** * Generates a unique key for the text style. * @param style - The style to generate a key for. * @returns the key for the style. * @internal * @deprecated 8.12.0 */ export function generateTextStyleKey(style: TextStyle): string { const key = []; let index = 0; for (let i = 0; i < valuesToIterateForKeys.length; i++) { const prop = `_${valuesToIterateForKeys[i]}`; key[index++] = style[prop as keyof typeof style]; } index = addFillStyleKey(style._fill, key as string[], index); index = addStokeStyleKey(style._stroke, key as string[], index); index = addDropShadowKey(style.dropShadow, key as string[], index); index = addFiltersKey(style.filters as Filter[], key as string[], index); return key.join('-'); } function addFiltersKey(filters: Filter[], key: (number | string)[], index: number) { if (!filters) return index; for (const filter of filters) { key[index++] = filter.uid; } return index; } function addFillStyleKey(fillStyle: ConvertedFillStyle, key: (number | string)[], index: number) { if (!fillStyle) return index; key[index++] = fillStyle.color; key[index++] = fillStyle.alpha; key[index++] = fillStyle.fill?.styleKey; return index; } function addStokeStyleKey(strokeStyle: ConvertedStrokeStyle, key: (number | string)[], index: number) { if (!strokeStyle) return index; index = addFillStyleKey(strokeStyle, key, index); key[index++] = strokeStyle.width; key[index++] = strokeStyle.alignment; key[index++] = strokeStyle.cap; key[index++] = strokeStyle.join; key[index++] = strokeStyle.miterLimit; return index; } function addDropShadowKey(dropShadow: TextStyle['dropShadow'], key: (number | string)[], index: number) { if (!dropShadow) return index; key[index++] = dropShadow.alpha; key[index++] = dropShadow.angle; key[index++] = dropShadow.blur; key[index++] = dropShadow.distance; key[index++] = Color.shared.setValue(dropShadow.color).toNumber(); return index; }