301*302* @param {string | number} price303* @param {TmstCurrencyFormat} [currencyParams]304* @returns {string}305*/306function tmst__formatPriceAmount(price, currencyParams) {307const n = typeof price === 'number' ? price : parseFloat(price);308const safe = Number.isFinite(n) ? n : 0;309310if (!currencyParams || typeof currencyParams.dec !== 'string') {311return tmst__prettifyNumber(tmst__roundMoney(safe));312
} const digits = currencyParams.dec.length; const sep = typeof currencyParams.sep === 'string' && currencyParams.sep !== '' ? currencyParams.sep : '.'; const tho = typeof currencyParams.tho === 'string' ? currencyParams.tho : ' '; const [integerPart, fraction] = safe.toFixed(digits).split('.'); // replace считает $ в строке замены служебным символом, поэтому разделитель передаём функцией. const grouped = tho ? integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, () => tho) : integerPart; return fraction ? `${grouped}${sep}${fraction}` : grouped;}/** * Форматирует цену с учетом десятичного формата и пользовательского символа валюты. * Оба значения берутся из `window.currency_params` и `window.project_currency`. * * @param {string | number} price * @param {string} [currency] * @returns {string} Отформатированная и HTML-экранированная цена с валютой */function tmst__formatPrice(price, currency) { const currencyParams = window.currency_params; const currentPrice = tmst__formatPriceAmount(price, currencyParams); const projectCurrency = window.project_currency; const displayCurrency = currency === projectCurrency && currencyParams && currencyParams.txt ? currencyParams.txt : currency; if (!displayCurrency) return `${currentPrice}`; if (displayCurrency === 'RUB') return `${currentPrice} р.`; return tma__escapeHTML(`${currentPrice} ${displayCurrency}`);}/** * Создаёт SVG-иконку для отсутствующего изображения товара * * @returns {string} разметка */function tmst__createNoImageHtml(className) { return ` <svg class="${className}" width="51" height="51" viewBox="0 0 51 51" fill="none" xmlns="http://www.w3.org/2000/svg"> <rect width="50" height="50" rx="2" fill="#F5F5F5" /> <path d="M41.3528 33.5581L36.3023 21.7468C35.3826 19.5846 34.0111 18.3583 32.4459 18.2776C30.8969 18.197 29.3963 19.2781 28.2507 21.3434L25.185 26.8457C24.5395 28.0074 23.6198 28.7013 22.6194 28.7819C21.6028 28.8787 20.5863 28.3463 19.7634 27.2975L19.4084 26.8457C18.2628 25.4096 16.8428 24.7158 15.3906 24.861C13.9384 25.0062 12.696 26.0066 11.8731 27.6363L9.08163 33.2031C8.08123 35.22 8.17804 37.5597 9.35594 39.4637C10.5338 41.3677 12.583 42.5133 14.8259 42.5133H35.4149C37.577 42.5133 39.594 41.4322 40.788 39.625C42.0143 37.8178 42.2079 35.5427 41.3528 33.5581Z" fill="#CBCBCB" /> <path d="M17.0705 19.9389C20.0826 19.9389 22.5243 17.4971 22.5243 14.4851C22.5243 11.473 20.0826 9.03125 17.0705 9.03125C14.0585 9.03125 11.6167 11.473 11.6167 14.4851C11.6167 17.4971 14.0585 19.9389 17.0705 19.9389Z" fill="#CBCBCB" /> </svg> `;}/** * Получает текущий язык * * @returns {string} Код языка (например, 'RU' или 'EN') */function tmst__getCurrentLanguage() { if (window.lang) return window.lang; if (window.tildaMembers.userLang) return window.tildaMembers.userLang; const allRecords = document.getElementById('allrecords'); if (allRecords) { const projectLang = allRecords.getAttribute('data-tilda-project-lang'); if (projectLang) return projectLang; } const browserLang = (window.navigator.userLanguage || window.navigator.language).toUpperCase().slice(0, 2); if (browserLang) return browserLang; return 'EN';}/** * Создает SVG-иконку стрелки слево * * @returns {SVGSVGElement} Элемент стрелки слево */function tmst__createArrowIconElement() { const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); icon.setAttribute('width', '11'); icon.setAttribute('height', '8'); icon.setAttribute('viewBox', '0 0 11 8'); icon.innerHTML = ` <path d="M3.82843 7.53556L0.646447 4.35358C0.451185 4.15832 0.451185 3.84173 0.646447 3.64647L3.82843 0.464492C4.02369 0.269229 4.34027 0.269229 4.53553 0.464492C4.7308 0.659754 4.7308 0.976337 4.53553 1.1716L2.20711 3.50003L11 3.50003L11 4.50003L2.20711 4.50003L4.53553 6.82845C4.7308 7.02372 4.7308 7.3403 4.53553 7.53556C4.34027 7.73082 4.02369 7.73082 3.82843 7.53556Z" fill="currentColor"></path> `; return icon;}/**