Каталог файловtilda-members-store-other.js
401 * Создаёт SVG-иконку с домом402 *403 * @returns {Element} Элемент дома404 */405function tmst__createHomeIconElement() {406 const iconHtml = `407 <svg width="14" height="15" viewBox="0 0 14 15" fill="none" xmlns="http://www.w3.org/2000/svg">408 <path fill-rule="evenodd" clip-rule="evenodd" d="M13.9056 8.27544L7.07838 0.765625L0.251221 8.27544H1.99001V14.4198H12.192V8.27544H13.9056ZM5.70228 10.3234H8.48464V14.4197H5.70228V10.3234Z" fill="currentColor"/>409 </svg>410 `;411 412
История файла и сравнение версий
return tmst__createElementFromString(iconHtml);
416 * Создает разметку статуса оплаты заказа 418 * @param {OrderPayStatus} paystatus 419 * @param {OrderStatus} status 421function tmst__createPaymentStatusHtml(paystatus, status) { 422 const isNeedToShowPayedStatus = 423 paystatus === 'paid' || (paystatus === 'unpaid' && status.name !== 'cancelled' && status.name !== 'canceled'); 424 if (!isNeedToShowPayedStatus) return ''; 426 /** @type {Record<OrderPayStatus, string>} */ 427 const paystatusToColor = { 432 return tmst__createStatusHtml({ 433 title: tma__translate(`{{status_${paystatus}}}`, 'store_dict'), 436 color: paystatusToColor[paystatus], 442 * Создает разметку статуса заказа 444 * @param {OrderStatus} status - Статус заказа 445 * @returns {string} HTML разметка статуса 448function tmst__createStatusHtml(status) { 449 if (!status) return ''; 450 const { name, title = '', params = {} } = status; 452 if (!name) return ''; 454 // Не показываем статус 'created' 455 // 'booked' - легаси статус 456 if (['created', 'booked'].includes(name)) return ''; 458 const statusText = title ? title : tma__translate(`{{status_${name}}}`, 'store_dict'); 459 const styles = params.color 460 ? `style="background-color: ${params.color}; color: ${tmst__getFontColor(params.color)}"` 463 return `<span class="tmst-status" title="${statusText}" ${styles}>${statusText}</span>`; 469 * Получает цвет в зависимости от яркости переданного 471 * @param {string} background - цвет в HEX 472 * @returns {string} цвет в HEX 474function tmst__getFontColor(background) { 475 if (!background || background[0] !== '#') return '#000000'; 477 const rgbArr = tmst__hexToRgb(background); 478 // Яркость рассчитывается по формуле, которая учитывает вклад каждого из каналов RGB 479 // (красный, зеленый, синий) в восприятие яркости человеческим глазом. 480 // Коэффициенты 0.299, 0.587 и 0.114 отражают чувствительность глаза к разным цветам. 481 const brightness = (0.299 * rgbArr[0] + 0.587 * rgbArr[1] + 0.114 * rgbArr[2]) / 255; 483 if (brightness <= 0.5) { 491 * Преобразует HEX в RGB 493 * @param {string} background - HEX код цвета 494 * @returns {number[]} массив с кодами цветоа Red, Green, Blue 496function tmst__hexToRgb(background) { 497 const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(background); 498 return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : [0, 0, 0];