Каталог файловtilda-animation-sbs-1.0.js
1601 * @param {{ease: '' | '0' | 'easeIn' | 'easeOut' | 'easeInOut' | 'bounceFin' | string | undefined}} keyframe - объект keyframe1602 * @returns {string} - декларация animation-timing-function или пустая строка1603 */1604function t_animationSBS__generateKeyframes__getEaseChanges(keyframe) {1605 if (typeof keyframe.ease === 'undefined') return '';1606 const presets = {1607 easeIn: 'ease-in',1608 easeOut: 'ease-out',1609 easeInOut: 'ease-in-out',1610 bounceFin: 'cubic-bezier(0.34,1.61,0.7,1)',1611 };
История файла и сравнение версий
const ease = String(keyframe.ease).trim();
1613 // linear в редакторе - пустая строка, при публикации пустое значение сохраняется как '0' 1614 const isLinear = ease === '' || ease === '0'; 1615 return `animation-timing-function:${isLinear ? 'linear' : presets[ease] || ease};`; 1619 * Собирает css-декларации цветов цели для одного keyframe 1621 * @param {sbsColorTarget} target 1622 * @param {{styles: stepStyles}} keyframe - объект keyframe 1623 * @returns {string} - css-декларации 1625function t_animationSBS__generateKeyframes__getColorChanges(target, keyframe) { 1626 return target.props.reduce((changes, prop) => { 1627 if (!(prop in keyframe.styles)) return changes; 1628 const value = t_animationSBS__getTargetStepValue(target, keyframe.styles, prop); 1629 return changes + t_animationSBS__generateKeyframes__getColorDeclarations(target, prop, value); 1634 * @param {sbsColorTarget} target 1635 * @param {'color' | 'bgColor' | 'fill' | 'stroke'} prop 1636 * @param {sbsRGBA | sbsPaintState | sbsShapeUrlPaint} value - см. t_animationSBS__getTargetStepValue 1637 * @returns {string} - css-декларации значения цвета цели для keyframe 1639function t_animationSBS__generateKeyframes__getColorDeclarations(target, prop, value) { 1640 const declarations = t_animationSBS__getTargetColorDeclarations(target, prop, value, false); 1641 return declarations.map(([cssProp, cssValue]) => `${cssProp}:${cssValue};`).join(''); 1645 * Градиент фигуры (см. sbsShapeUrlPaint) и цвет между собой не интерполируются: без дополнительного кадра 1646 * браузер переключил бы их в середине шага. Кадр сразу после начала шага ставит значение конца шага только 1647 * тем свойствам, у которых градиент меняется на цвет или обратно, остальные свойства его не замечают 1649 * @param {sbsColorTarget} target 1650 * @param {{styles: stepStyles, percent: number}} keyframe - keyframe начала шага 1651 * @param {{styles: stepStyles, percent: number} | undefined} nextKeyframe - keyframe конца шага 1652 * @returns {string} - keyframe переключения или '' 1654function t_animationSBS__generateKeyframes__getShapeSwitchFrame(target, keyframe, nextKeyframe) { 1655 if (!target.shapeSelectors || !nextKeyframe) return ''; 1656 // проценты keyframes округлены до сотых, см. t_animationSBS__generateKeyframes__countPercent 1657 const switchPercent = parseFloat((keyframe.percent + 0.01).toFixed(2)); 1658 if (switchPercent >= nextKeyframe.percent) return ''; 1660 const changes = target.props.reduce((str, prop) => { 1661 if (!(prop in keyframe.styles) || !(prop in nextKeyframe.styles)) return str; 1662 const from = t_animationSBS__getTargetStepValue(target, keyframe.styles, prop); 1663 const to = t_animationSBS__getTargetStepValue(target, nextKeyframe.styles, prop); 1664 if (t_animationSBS__isShapeUrlPaint(from) === t_animationSBS__isShapeUrlPaint(to)) return str; 1665 return str + t_animationSBS__generateKeyframes__getColorDeclarations(target, prop, to); 1667 return changes ? `${switchPercent}% {${changes}}\n` : ''; 1671 * Анимация цвета задается узлам атома внутри wrapperEl, поэтому для каждого узла 1672 * генерируем отдельные @keyframes с теми же процентами и easing, что и у wrapperEl. 1673 * Имя анимации заканчивается на t_animationSBS__COLOR_ANIM_SUFFIX + индекс, см. t_animationSBS__isColorAnimationEvent 1675 * @param {AnimatedHTML} el - текущий элемент 1677 * styles: stepStyles, 1678 * ease: '' | 'easeIn' | 'easeOut' | 'easeInOut' | 'bounceFin' | undefined, 1679 * percent: number | undefined 1680 * }[]} keyframes - массив keyframes основной анимации 1681 * @param {{timeDuration:number}} keyframesOpts - опции 1682 * @returns {string} - css 1684function t_animationSBS__generateKeyframes__getColorsCss(el, keyframes, keyframesOpts) { 1685 // keyframe без процента пропущен в t_animationSBS__generateKeyframes__countPercent, как и в основной анимации 1686 const percentKeyframes = keyframes.filter(keyframe => typeof keyframe.percent === 'number'); 1687 return t_animationSBS__getColorAnimTargets(el).reduce((css, target, i) => { 1688 const keyframesStr = percentKeyframes.reduce((str, keyframe, j) => { 1689 const changes = t_animationSBS__generateKeyframes__getColorChanges(target, keyframe); 1690 const ease = t_animationSBS__generateKeyframes__getEaseChanges(keyframe); 1691 const switchFrame = t_animationSBS__generateKeyframes__getShapeSwitchFrame( 1694 percentKeyframes[j + 1] 1696 return `${str}${keyframe.percent}% {${changes}${ease}}\n${switchFrame}`; 1698 const colorAnimOpts = { 1699 selector: t_animationSBS__getColorTargetSelector(el, target, false), 1700 nameSuffix: `${window.t_animationSBS__COLOR_ANIM_SUFFIX}${i}`,