Некодим© 2020-2026 Некодим
Готовые модификации для вашего сайта. Улучшайте функциональность и дизайн без программирования.
Журнал изменений История Git Файлы Tilda MCP Каталог файловtilda-animation-sbs-1.0.js Следить за файлом 2301 const elType = animatedHTML.getAttribute('data-elem-type');2302 // в редакторе у группы data-elem-type="group", на сайте атрибута нет, только класс tn-group2303 const isGroup = elType === 'group' || (!elType && animatedHTML.classList.contains('tn-group'));2304 if (!isGroup) return elType;2305 2306 // в редакторе тип группы лежит в атрибуте, на опубликованной странице - в объекте tn2307 let groupType = animatedHTML.getAttribute('data-field-type-value');2308 if (!groupType && typeof window.t396_group__getFieldValue === 'function') {2309 groupType = window.t396_group__getFieldValue(animatedHTML, 'type');2310 }2311 История файла и сравнение версий return groupType === 'physical' ? 'physicalGroup' : 'group';
2315 * Находит узлы для анимации color/background-color и кеширует их собственные цвета.2316 * Функция вызывается при каждом пересчете данных (в том числе на ресайз), поэтому сначала2317 * убирает все, что поставила в прошлый раз, чтобы прочитать исходные стили узлов2319 * @param {AnimatedHTML} animatedHTML2320 * @param {boolean} isEditMode2322 function t_animationSBS__setColorTargets(animatedHTML, isEditMode) {2323 const prevTargets = animatedHTML.colorTargets || [];2324 t_animationSBS__clearColorTargets(animatedHTML);2325 // разметку редактора менять нельзя, там id градиентов уникальны внутри блока2326 if (!isEditMode) t_animationSBS__setUniqueGradientIds(animatedHTML);2328 const colorTargets = t_animationSBS__collectColorTargets(animatedHTML);2329 // у текста слои цвета и фона лежат на одном узле, поэтому правило слоев ставится, когда все свойства собраны2330 colorTargets.forEach(target => {2331 if (t_animationSBS__hasColorLayers(target)) t_animationSBS__setBgColorLayer(target, animatedHTML, isEditMode);2333 t_animationSBS__setColorTargetsBase(animatedHTML, colorTargets, prevTargets);2335 animatedHTML.colorTargets = colorTargets.filter(target => target.props.length);2336 t_animationSBS__setShapeScrollColorRule(animatedHTML, isEditMode);2340 * Делает id градиентов в svg вектора уникальными на странице и переписывает ссылки на них внутри этого svg2341 * (url(#id) в атрибутах, style и <style>, href и xlink:href). Копия вектора сохраняет id градиентов, а url(#id)2342 * резолвится в первый элемент документа: без этого стопы анимировались бы у градиента другой копии.2343 * Нужна только вектору с цветом в шагах, выполняется один раз на svg2345 * @param {AnimatedHTML} animatedHTML2347 function t_animationSBS__setUniqueGradientIds(animatedHTML) {2348 const wrapperEl = animatedHTML.wrapperEl;2349 if (!wrapperEl || !animatedHTML.uniqueID || t_animationSBS__getColorElType(animatedHTML) !== 'vector') return;2350 if (!animatedHTML.steps.some(step => step.styles.fill || step.styles.stroke)) return;2352 wrapperEl.querySelectorAll('svg').forEach(svg => {2353 if (svg.sbsUniqueGradientIds) return;2354 svg.sbsUniqueGradientIds = true;2356 const ids = new Map();2357 svg.querySelectorAll('[id]').forEach(node => {2358 if (!t_animationSBS__isGradientNode(node)) return;2359 const newId = `${node.id}-${animatedHTML.uniqueID}`;2360 ids.set(node.id, newId);2363 if (!ids.size) return;2365 const replaceUrls = value =>2366 value.replace(/url\(\s*(['"]?)#([^'")]+)\1\s*\)/g, (match, quote, id) =>2367 ids.has(id) ? `url(${quote}#${ids.get(id)}${quote})` : match2369 // NodeList без spread: сборка разворачивает его в concat2370 [svg].concat(Array.from(svg.querySelectorAll('*'))).forEach(node => {2371 if (node.localName === 'style') node.textContent = replaceUrls(node.textContent);2372 Array.from(node.attributes).forEach(attr => {2373 let value = attr.value;2374 if (attr.localName === 'href' && value.startsWith('#') && ids.has(value.slice(1))) {2375 value = `#${ids.get(value.slice(1))}`;2376 } else if (value.includes('url(')) {2377 value = replaceUrls(value);2379 if (value !== attr.value) attr.value = value;2386 * @param {Element} node2387 * @returns {boolean} - узел - linearGradient или radialGradient2389 function t_animationSBS__isGradientNode(node) {2390 const name = node.localName.toLowerCase();2391 return name === 'lineargradient' || name === 'radialgradient';2395 * Возвращает узлам исходные инлайн-стили и удаляет слои фона. Вызывается и для элементов,2396 * у которых анимации нет, иначе правило слоя с !important осталось бы на узле2398 * @param {AnimatedHTML} animatedHTML2400 function t_animationSBS__clearColorTargets(animatedHTML) {