/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/global-styles-engine/src/utils/background.ts
54 строки
1 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import type { BackgroundStyle } from '../types'; export const BACKGROUND_BLOCK_DEFAULT_VALUES = { backgroundSize: 'cover', backgroundPosition: '50% 50%', // used only when backgroundSize is 'contain'. }; /** * Whether a background image resolves to a URL, as opposed to a reference or an * unresolved value. * * @param backgroundImage The background image value. * * @return Whether the value carries a URL. */ function hasImageUrl( backgroundImage: BackgroundStyle[ 'backgroundImage' ] ): backgroundImage is { url: string } { return ( typeof backgroundImage === 'object' && backgroundImage !== null && 'url' in backgroundImage && !! backgroundImage.url ); } export function setBackgroundStyleDefaults( backgroundStyle: BackgroundStyle ) { if ( ! backgroundStyle || ! hasImageUrl( backgroundStyle.backgroundImage ) ) { return; } let backgroundStylesWithDefaults; // Set block background defaults. if ( ! backgroundStyle?.backgroundSize ) { backgroundStylesWithDefaults = { backgroundSize: BACKGROUND_BLOCK_DEFAULT_VALUES.backgroundSize, }; } if ( 'contain' === backgroundStyle?.backgroundSize && ! backgroundStyle?.backgroundPosition ) { backgroundStylesWithDefaults = { backgroundPosition: BACKGROUND_BLOCK_DEFAULT_VALUES.backgroundPosition, }; } return backgroundStylesWithDefaults; }