/** * Copyright since 2007 PrestaShop SA and Contributors * PrestaShop is an International Registered Trademark & Property of PrestaShop SA * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.md. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to https://devdocs.prestashop.com/ for more information. * * @author PrestaShop SA and Contributors * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ var y=Object.defineProperty;var m=(s,t,e)=>t in s?y(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var a=(s,t,e)=>(m(s,typeof t!="symbol"?t+"":t,e),e);import{b as c}from"./dom-utils-d77254b8.js";const F="https://fonts.googleapis.com",g="https://fonts.gstatic.com";class I{constructor(){this.autoDiscover()}autoDiscover(){const t=document.querySelectorAll(".text-editor");t.length!==0&&(c(F,"preconnect",!0),c(g,"preconnect"),t.forEach(e=>{new V({el:e})}))}}class V{constructor(t){a(this,"el");a(this,"fontList");a(this,"fontVariantsList");a(this,"fontFamilySelect");a(this,"fontVariantSelect");a(this,"fontSizeInput");a(this,"fontColorInput");a(this,"textarea");a(this,"form");var e;this.el=t.el,this.fontList=t.el.dataset.fontList!==null&&t.el.dataset.fontList!==void 0?JSON.parse(t.el.dataset.fontList):[],this.fontVariantsList=t.el.dataset.fontVariants!==null&&t.el.dataset.fontVariants!==void 0?JSON.parse(t.el.dataset.fontVariants):{},this.fontFamilySelect=this.el.querySelector(".text-editor__font-family-select"),this.fontVariantSelect=this.el.querySelector(".text-editor__font-variant-select"),this.fontSizeInput=this.el.querySelector(".text-editor__font-size-input"),this.fontColorInput=this.el.querySelector(".text-editor__font-color-input"),this.textarea=this.el.querySelector(".text-editor__textarea"),this.form=((e=this.fontFamilySelect)==null?void 0:e.form)??null,this.init()}init(){this.initTextArea(),this.initFontFamilySelect(),this.initFontVariantSelect(),this.initFontSizeInput(),this.initFontColorInput(),this.addFormListener()}initFontFamilySelect(){this.fontFamilySelect!==null&&(this.fontList.forEach(t=>{c(this.getGoogleFontUrl(t,!1),"stylesheet")}),this.updateFontFamily(),this.fontFamilySelect.addEventListener("change",t=>{this.updateFontFamily(t)}))}initFontVariantSelect(){this.fontVariantSelect!=null&&(this.updateFontVariant(),this.fontVariantSelect.addEventListener("change",t=>{this.updateFontVariant(t)}))}initFontSizeInput(){this.fontSizeInput!=null&&(this.updateFontSize(),this.fontSizeInput.addEventListener("change",t=>{this.updateFontSize(t)}))}initFontColorInput(){this.fontColorInput!=null&&(this.updateFontColor(),this.fontColorInput.addEventListener("change",t=>{this.updateFontColor(t)}))}initTextArea(){this.textarea!=null&&this.textarea.rows===1&&this.textarea.addEventListener("input",t=>{const e=t.target;e.value=e.value.replace(/(\r\n|\n|\r)/gm,"")})}updateFontFamily(t){let e;t!=null?e=t.target.value:e=this.fontFamilySelect!==null?this.fontFamilySelect.value:"";const i=this.getFontByCode(e);if(i==null)return;const n=this.getGoogleFontUrl(i,!0);c(n,"stylesheet"),this.fontFamilySelect!=null&&(this.fontFamilySelect.style.fontFamily=i.name),this.textarea!=null&&(this.textarea.style.fontFamily=i.name),this.fontVariantSelect!=null&&(this.fontVariantSelect.style.fontFamily=i.name),this.updateFontVariantOptions(i)}updateFontVariantOptions(t){var S;if(this.fontVariantSelect==null||this.fontVariantsList==null)return;const e=this.fontVariantSelect.value;Array.from(this.fontVariantSelect.options).forEach(o=>{o.hidden=!1});for(const[o,r]of Object.entries(this.fontVariantsList))for(const[u]of Object.entries(r))if(!((S=t.variants)!=null&&S[o].includes(u))){const d=[...this.fontVariantSelect.options].find(f=>f.value===`${o}-${u}`);d!=null&&(d.hidden=!0)}const i=Object.keys(t.variants),n=e.split("-")[0],l=i.indexOf(n);l!==0&&(i.splice(l,1),i.splice(0,0,n));for(let o=0;oNumber(h)).reduce((h,p)=>Math.abs(p-u)e&&(e=Number(this.fontSizeInput.min)),e!==0&&Number(this.fontSizeInput.max){i+=`0,${l};`}),n.italic.forEach(l=>{i+=`1,${l};`}),i=i.slice(0,-1)}else i=`0,400&text=${t.name.replace(" ","%20")}`;return`${F}/css2?family=${t.code}:ital,wght@${i}&display=swap`}getFontByCode(t){return this.fontList.find(e=>e.code===t)}addFormListener(){var t;(t=this.form)==null||t.addEventListener("reset",()=>{setTimeout(()=>{this.updateFontFamily(),this.updateFontSize()},1)})}}export{I};