3901function t_animationSBS__getPaintDeclarations(meta, state) {3902const round = number => parseFloat(number.toFixed(3));3903const declarations = [];3904if (state.color) declarations.push(['color', t_animationSBS__stringifyColor(state.color)]);3905meta.kinds.forEach(kind => {3906const layer = state[kind];3907const geometryValues = {3908a: () => `${round(layer.angle)}deg`,3909x: () => t_animationSBS__stringifyLength(layer.center.x),3910y: () => t_animationSBS__stringifyLength(layer.center.y),3911w: () => t_animationSBS__stringifyLength(layer.size.w),
h: () => t_animationSBS__stringifyLength(layer.size.h), }; t_animationSBS__getPaintGeometryRoles(kind).forEach(role => { declarations.push([t_animationSBS__getPaintVar(meta, kind, role), geometryValues[role]()]); }); layer.colors.forEach((color, i) => { declarations.push([t_animationSBS__getPaintVar(meta, kind, 'c', i), t_animationSBS__stringifyColor(color)]); declarations.push([t_animationSBS__getPaintVar(meta, kind, 'p', i), `${round(layer.positions[i])}%`]); }); }); return declarations;}/** * @param {sbsLength} length * @returns {string} - длина для css: проценты, пиксели или calc() из обоих */function t_animationSBS__stringifyLength(length) { const percent = parseFloat(length.p.toFixed(3)); const pixels = parseFloat(length.x.toFixed(3)); if (!pixels) return `${percent}%`; if (!percent) return `${pixels}px`; return `calc(${percent}% + ${pixels}px)`;}/** * Переменные геометрии слоя вида kind, кроме стопов: a - угол linear или поворот conic, x и y - центр, * w и h - размер radial, заданный длиной (у круга w и h равны, в слое используется только w) * * @param {string} kind * @returns {('a' | 'x' | 'y' | 'w' | 'h')[]} */function t_animationSBS__getPaintGeometryRoles(kind) { if (kind === 'linear') return ['a']; if (kind === 'conic') return ['a', 'x', 'y']; return kind.endsWith('-length') ? ['x', 'y', 'w', 'h'] : ['x', 'y'];}/** * Имя переменной слоя: --t-sbs-{bg|cl}-{l|c|r<N>}-{роль}, где l - linear, c - conic, r<N> - N-й вид radial * у этого свойства элемента. Роли: a, x, y, w, h - см. t_animationSBS__getPaintGeometryRoles, c{i} - цвет стопа, * p{i} - позиция стопа. Имена общие для всех элементов: значения задаются на самом узле в keyframes или инлайном * * @param {sbsPaintMeta} meta * @param {string} kind * @param {'a' | 'x' | 'y' | 'w' | 'h' | 'c' | 'p'} role * @param {number | undefined} index - номер стопа * @returns {string} */function t_animationSBS__getPaintVar(meta, kind, role, index) { return `--t-sbs-${meta.varPrefix}-${meta.varIds[kind]}-${role}${index === undefined ? '' : index}`;}/** * Слои градиента для правила слоев, по одному на вид. У каждой var() есть fallback: без поддержки @property * и до старта анимации переменные не заданы, без fallback весь background-image стал бы невалидным * * @param {sbsPaintMeta} meta * @returns {string[]} - слои в порядке meta.kinds: linear, conic, затем виды radial */function t_animationSBS__getPaintLayerImages(meta) { return meta.kinds.map(kind => { const paintVar = (role, fallback) => `var(${t_animationSBS__getPaintVar(meta, kind, role)}, ${fallback})`; const count = meta.stops[kind]; const stops = Array.from({ length: count }, (item, i) => { const color = `var(${t_animationSBS__getPaintVar(meta, kind, 'c', i)}, transparent)`; const pos = `var(${t_animationSBS__getPaintVar(meta, kind, 'p', i)}, ${parseFloat(((i / (count - 1)) * 100).toFixed(3))}%)`; return `${color} ${pos}`; }).join(', '); if (kind === 'linear') return `linear-gradient(${paintVar('a', '180deg')}, ${stops})`; const center = `at ${paintVar('x', '50%')} ${paintVar('y', '50%')}`; if (kind === 'conic') return `conic-gradient(from ${paintVar('a', '0deg')} ${center}, ${stops})`; const [, shape, ...sizeParts] = kind.split('-'); let size = sizeParts.join('-'); if (size === 'length') { size = shape === 'circle' ? paintVar('w', '0px') : `${paintVar('w', '0px')} ${paintVar('h', '0px')}`; } return `radial-gradient(${shape} ${size} ${center}, ${stops})`; });}/** * Регистрирует переменные слоев, чтобы браузер плавно интерполировал их в keyframes. * Без поддержки @property переменные меняются скачком, как и t_animationSBS__BG_LAYER_PROP * * @param {sbsPaintMeta} meta */