Некодим логотипНекодим
МодификацииПубликацииНекодИИмЦены
Некодим логотипНекодим

© 2020-2026 Некодим

Готовые модификации для вашего сайта. Улучшайте функциональность и дизайн без программирования.

Компания

  • Контакты
  • Публичная оферта
  • Политика конфиденциальности
  • Согласие на обработку данных
  • Лицензионное соглашение
  • Реферальная программа

Полезное

  • Модификации
  • Публикации
  • Каталог блоков Tilda
  • MCP для агентов
  • Журнал изменений
  • Доска почёта

Личный кабинет

  • Вход
  • Регистрация
  • Цены
Журнал измененийИстория GitФайлыTilda MCP
Каталог файлов

tilda-animation-sbs-1.0.js

Код файла
Версия от 05.12.2026, 07:01:09 МСК
Оригинал на CDNСнимок 56c3b845Полный текст
3701 */3702function t_animationSBS__parseGradientStop(token) {3703	const color = t_animationSBS__parseColor(token);3704	if (color) return { color, pos: null };3705	const stop = token.match(/^(.+?)\s+(-?[\d.]+)%$/);3706	const stopColor = stop && t_animationSBS__parseColor(stop[1]);3707	return stopColor ? { color: stopColor, pos: parseFloat(stop[2]) } : null;3708}3709 3710/**3711 * Проставляет позиции стопам без позиции так же, как браузер: крайние - 0% и 100%,3712
История файла и сравнение версий
  • 05.12.2026, 07:01:09 · 56c3b845
* остальные - равномерно между соседними стопами с позицией
3713 *
3714 * @param {{color: sbsRGBA, pos: number | null}[]} stops
3715 * @returns {{color: sbsRGBA, pos: number}[]}
3716 */
3717function t_animationSBS__fillStopPositions(stops) {
3718 const positions = stops.map(stop => stop.pos);
3719 if (positions[0] === null) positions[0] = 0;
3720 if (positions[positions.length - 1] === null) positions[positions.length - 1] = 100;
3721 positions.forEach((pos, i) => {
3722 if (pos !== null) return;
3723 const prevIndex = i - 1;
3724 const nextIndex = positions.findIndex((nextPos, j) => j > i && nextPos !== null);
3725 const step = (positions[nextIndex] - positions[prevIndex]) / (nextIndex - prevIndex);
3726 positions[i] = positions[prevIndex] + step;
3727 });
3728 return stops.map((stop, i) => {
3729 return { color: stop.color, pos: positions[i] };
3730 });
3731}
3732
3733/**
3734 * Дополняет стопы до count копиями последнего стопа: так у всех шагов одинаковое число стопов
3735 * и переменные слоя интерполируются попарно
3736 *
3737 * @param {{color: sbsRGBA, pos: number}[]} stops
3738 * @param {number} count
3739 * @returns {{color: sbsRGBA, pos: number}[]}
3740 */
3741function t_animationSBS__normalizeStops(stops, count) {
3742 const lastStop = stops[stops.length - 1];
3743 return Array.from({ length: count }, (item, i) => stops[i] || lastStop);
3744}
3745
3746/**
3747 * Режим градиента для свойства color или bgColor элемента. Если хоть в одном шаге градиент, все шаги свойства
3748 * рисуются слоями градиента на переменных (см. t_animationSBS__getColorLayersCss), по слою на каждый вид
3749 * градиента из шагов (см. t_animationSBS__parseGradientSettings):
3750 * - сплошной цвет - градиент из одинаковых стопов слоя solidKind, поэтому сплошной <-> градиент интерполируется;
3751 * - внутри одного вида (linear <-> linear с разным углом и числом стопов, radial с другим центром или размером-длиной,
3752 * conic с другим поворотом и центром) - интерполяция переменных;
3753 * - между видами (linear <-> radial <-> conic, circle <-> ellipse, смена размера-ключевого слова radial) -
3754 * кроссфейд: стопы ушедшего слоя становятся прозрачными, нового - проявляются.
3755 * Угол, центр, размер и позиции стопов («геометрия») у шага без слоя этого вида берутся у ближайшего шага с ним:
3756 * пока слой прозрачный, его геометрия не видна, а при проявлении слой не поворачивается и не сдвигается.
3757 * Угол linear и поворот conic между соседними шагами меняются по кратчайшему пути
3758 *
3759 * @param {AnimatedHTML} animatedHTML
3760 * @param {'color' | 'bgColor'} prop
3761 * @returns {sbsPaintMeta | null} - null, если градиента в шагах нет
3762 */
3763function t_animationSBS__createPaintMeta(animatedHTML, prop) {
3764 const values = animatedHTML.steps.map(step => step.styles[prop]);
3765 const gradients = values.filter(t_animationSBS__isGradientPaint);
3766 if (!gradients.length) return null;
3767
3768 const gradientKinds = gradients.map(gradient => gradient.kind);
3769 const radialKinds = gradientKinds.filter(
3770 (kind, i) => kind.startsWith('radial') && gradientKinds.indexOf(kind) === i
3771 );
3772 const kinds = ['linear', 'conic'].filter(kind => gradientKinds.includes(kind)).concat(radialKinds);
3773 const stops = {};
3774 const varIds = {};
3775 kinds.forEach(kind => {
3776 const counts = gradients.filter(gradient => gradient.kind === kind).map(gradient => gradient.stops.length);
3777 stops[kind] = Math.max(...counts);
3778 varIds[kind] = kind.startsWith('radial') ? `r${radialKinds.indexOf(kind)}` : kind[0];
3779 });
3780
3781 const prevAngles = {};
3782 const ownGeometry = values.map(value => {
3783 if (!t_animationSBS__isGradientPaint(value)) return {};
3784 let angle = value.angle;
3785 const prevAngle = prevAngles[value.kind];
3786 if (angle !== undefined && prevAngle !== undefined) {
3787 while (angle - prevAngle > 180) angle -= 360;
3788 while (prevAngle - angle > 180) angle += 360;
3789 }
3790 prevAngles[value.kind] = angle;
3791 const positions = t_animationSBS__normalizeStops(value.stops, stops[value.kind]).map(stop => stop.pos);
3792 return { [value.kind]: { angle, center: value.center, size: value.size, positions } };
3793 });
3794
3795 const getNearestGeometry = (index, kind) => {
3796 for (let i = index; i >= 0; i--) if (ownGeometry[i][kind]) return ownGeometry[i][kind];
3797 return ownGeometry.slice(index).find(geometry => geometry[kind])[kind];
3798 };
3799 const geometry = new Map();
3800 animatedHTML.steps.forEach((step, i) => {
Предыдущие 100 строкСледующие 100 строк