polotno 4.0.0-beta.47 → 4.0.0-beta.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno",
3
- "version": "4.0.0-beta.47",
3
+ "version": "4.0.0-beta.48",
4
4
  "description": "Design Editor Framework",
5
5
  "author": "Anton Lavrenov",
6
6
  "keywords": [
package/polotno.bundle.js CHANGED
@@ -48,10 +48,10 @@ For more info see: https://github.com/konvajs/react-konva/issues/194
48
48
  `],{type:`application/javascript`}))})}var Zg=`https://api.polotno.com`;`${Zg}`;var Qg=()=>`https://api.polotno.com/api`,$g={},e_=(e,t)=>{$g[e]||($g[e]=!0,console.error(t))},Mee=(e,t,n)=>e.replace(new RegExp(t,`g`),n),t_=`API for iconscout is provided as a demonstration.
49
49
  For production usage you have to use your own API endpoint.
50
50
  https://iconscout.com/developers, https://iconscout.com/legal/api-license-development-agreement
51
- https://polotno.com/docs/server-api`,n_={unsplashList:({query:e,page:t=1})=>`${Qg()}/get-unsplash?query=${e}&per_page=20&page=${t}&KEY=${x_()}`,unsplashDownload:e=>`${Qg()}/download-unsplash?id=${e}&KEY=${x_()}`,svgapiList:({query:e,page:t=0})=>`${Qg()}/get-svgapi?query=${e}&page=${t}&per_page=20&KEY=${x_()}`,svgapiDownload:e=>`${Qg()}/download-svgapi?path=${e}&KEY=${x_()}`,iconscoutList:({query:e,page:t=1})=>(e_(`iconscout`,t_),`${Qg()}/get-iconscout?query=${e}&page=${t}&KEY=${x_()}`),iconscoutDownload:e=>(e_(`iconscout`,t_),`${Qg()}/download-iconscout?uuid=${e}&KEY=${x_()}`),nounProjectList:({query:e,page:t=1})=>`${Qg()}/get-nounproject?query=${e}&page=${t}&KEY=${x_()}`,nounProjectDownload:e=>`${Qg()}/download-nounproject?id=${e}&KEY=${x_()}`,templateList:({query:e,page:t=1,sizeQuery:n})=>`${Qg()}/get-templates?${n}&query=${e}&per_page=30&page=${t}&KEY=${x_()}`,googleFontsList:()=>`${Qg()}/get-google-fonts?KEY=${x_()}`,googleFontImage:e=>`${Zg}/google-fonts-previews/black/${Mee(e,` `,`-`)}.png`,textTemplateList:()=>`${Qg()}/get-text-templates?KEY=${x_()}`,removeBackground:()=>`${Qg()}/remove-image-background?KEY=${x_()}`,aiText:()=>`${Qg()}/ai/text?KEY=${x_()}`},r_=()=>n_.googleFontsList(),i_=e=>n_.googleFontImage(e),Nee=()=>n_.removeBackground(),Pee=e=>n_.templateList(e),Fee=()=>n_.textTemplateList(),a_=e=>n_.unsplashList(e),o_=e=>n_.unsplashDownload(e),Iee=(e,t)=>{n_[e]=t},s_=Ht({imageDownScalingEnabled:!0,removeBackgroundEnabled:!1,htmlRenderEnabled:!1,renderTagTextEnabled:!0,forceTextFitEnabled:!1,textVerticalResizeEnabled:!1,textOverflow:`resize`,textSplitAllowed:!1,animationsEnabled:!1,aiTextEnabled:!1,autoDeleteEmptyText:!0}),c_=typeof window<`u`&&window.location.hostname===`localhost`||typeof process<`u`&&!1,l_=ir(e=>{s_.textVerticalResizeEnabled=e}),u_=ir(e=>{s_.removeBackgroundEnabled=e}),Lee=ir(e=>{c_&&console.warn(`useRemoveBackground is deprecated. Use setRemoveBackgroundEnabled instead.`),u_(e)}),Ree=ir(e=>{s_.aiTextEnabled=e}),zee=ir(e=>{c_&&console.warn(`useHtmlTextRender is deprecated. Use setRichTextEnabled instead.`),s_.htmlRenderEnabled=e}),d_=e=>ir(t=>{c_&&console.warn(`${e}() is a no-op: the new text rendering engine is enabled by default.`)}),Bee=e=>{or(()=>{s_.htmlRenderEnabled=!0,s_.renderTagTextEnabled=!1})},Vee=d_(`setRichTextEnabled`);d_(`setRenderTagTextEnabled`);var f_=ir(e=>{s_.imageDownScalingEnabled=e}),Hee=ir(e=>{console.warn(`useDownScaling is deprecated. Use setDownScalingEnabled instead.`),f_(e)}),Uee=ir(e=>{console.warn(`setForceTextFit is deprecated. Use setTextOverflow instead.`),s_.textOverflow=`change-font-size`}),p_=ir(e=>{s_.textOverflow=e}),m_=ir(e=>{s_.textSplitAllowed=e}),h_=ir(e=>{s_.animationsEnabled=e}),Wee=ir(e=>{s_.autoDeleteEmptyText=e}),g_=Ht({value:!1}),__=Ht({value:`v1`}),Gee=()=>__.value,v_=Ht({value:0}),y_=()=>v_.value,Kee=()=>g_.value,qee=ir(()=>{g_.value=!0}),b_=``,x_=()=>b_||``,Jee=5,S_=3e3,Yee=`Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet`,Xee=`Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet`,Zee=`Can not validate Polotno API key. Please report to anton@polotno.com immediately.`,Qee=`%cPolotno Free Version. For development usage only. https://polotno.com/`,C_=typeof window<`u`?window.location.origin:``,$ee=typeof navigator<`u`?navigator.userAgent.indexOf(`Headless`)>-1:!1,ete=typeof navigator<`u`?navigator.userAgent.indexOf(`Electron`)>-1:!1;C_===`file://`&&$ee&&(C_=`headless`),C_===`file://`&&ete&&(C_=`electron`);var tte=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${C_}" here: https://polotno.com/cabinet`,nte=fetch;async function rte(e){for(let t=0;t<Jee;t++)try{let t=await nte(Qg()+`/validate-key`,{method:`POST`,body:JSON.stringify({key:e,site:location.host,skdVersion:`SDK_VERSION`})});if(or(()=>{__.value=t.headers.get(`x-api-version`)||``}),!e)return console.error(Yee),or(()=>{v_.value=1}),!1;if(t.status!==200){await new Promise(e=>setTimeout(e,S_));continue}let n=await t.json();return n.is_valid||(console.error(Xee),or(()=>{v_.value=1})),n.is_paid||(console.log(Qee,`background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;`),or(()=>{v_.value===0&&(v_.value=2)})),n.is_domain_valid||console.log(tte,`background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;`),u_(n.remove_background_enabled),n.is_paid||!1}catch{await new Promise(e=>setTimeout(e,S_))}return console.error(Zee),!0}async function ite(e,t){b_=e,(!await rte(e)||t)&&qee()}var w_=!1,ate=(e=!w_)=>{w_=e},T_=()=>w_;function E_(e,t){let n=x.useRef();x.useLayoutEffect(()=>{n.current&&n.current.destroy()},[t]),x.useLayoutEffect(()=>{if(!w_)return;let t=e.current.opacity();if(t)return e.current.opacity(0),n.current=new Xu.Tween({node:e.current,opacity:t,onFinish:()=>{n.current?.destroy()}}),n.current.play(),()=>{n.current?.destroy()}},[])}var D_=0,O_=[],k_=3e4,A_=e=>{k_=e},j_=6e3,ote=e=>{j_=e},ste=()=>j_;function M_(e){D_+=1;let t=!1,n=!1,r=setTimeout(()=>{t||(L_(`Timeout loading asset ${e}`),console.error(`Timeout triggered for loader. Some assets may not have loaded.`,e),t=!0,N_())},k_);return()=>{if(n){console.error(`Finish called twice! That is not expected. id: `,e);return}n=!0,!t&&(clearTimeout(r),N_())}}function N_(){--D_,D_===0&&(O_.forEach(e=>e()),O_=[])}function cte(e){D_===0?e():O_.push(e)}function P_(){return new Promise(e=>cte(()=>{T_()?setTimeout(e,300):e(!0)}))}var F_=[];function I_(e){F_.push(e)}function L_(e){F_.forEach(t=>t(e))}var R_={"ql-font-serif":`Georgia, Times New Roman, serif`,"ql-font-monospace":`Monaco, Courier New, monospace`,"ql-font-sans":`system-ui, -apple-system, BlinkMacSystemFont, sans-serif`},lte={"ql-size-small":.75,"ql-size-large":1.5,"ql-size-huge":2.5};function z_(e){return e.replace(/^ql-font-/,``).split(`-`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `)}function B_(e){return e.replace(/&quot;/g,`"`).replace(/&amp;/g,`&`).split(`,`)[0].trim().replace(/^["']|["']$/g,``)||null}function V_(e,t){if(!e)return;let n=e.trim(),r=n.match(/^(\d+(?:\.\d+)?)px$/i);if(r)return parseFloat(r[1]);let i=n.match(/^(\d+(?:\.\d+)?)em$/i);if(i)return t*parseFloat(i[1]);let a=n.match(/^(\d+(?:\.\d+)?)rem$/i);if(a)return t*parseFloat(a[1])}function H_(e){return new DOMParser().parseFromString(`<div id="polotno-rich-root">${e}</div>`,`text/html`).getElementById(`polotno-rich-root`)}function U_(e){for(let t of Array.from(e.classList))if(t.startsWith(`ql-indent-`)){let e=parseInt(t.slice(10),10);if(e>0)return e}return 0}function W_(e){for(let t of Array.from(e.querySelectorAll(`span.ql-ui`)))t.remove();let t=e.ownerDocument,n=e=>{let t=e.children;for(let e=t.length-1;e>=0;e--)if(t[e].tagName.toLowerCase()===`li`)return t[e];return null};for(let r of Array.from(e.querySelectorAll(`ol, ul`))){let e=r.tagName.toLowerCase(),i=Array.from(r.children).filter(e=>e.tagName.toLowerCase()===`li`);if(i.length===0||!i.some(e=>e.hasAttribute(`data-list`)||U_(e)>0))continue;let a=t=>{let n=t.getAttribute(`data-list`);return n===`ordered`?`ol`:n===`bullet`||n===`checked`||n===`unchecked`?`ul`:e===`ol`?`ol`:`ul`},o=t.createDocumentFragment(),s=[{list:o,level:-1,type:``}];for(let e of i){let r=U_(e),i=a(e);e.removeAttribute(`data-list`);for(let t of Array.from(e.classList))t.startsWith(`ql-indent-`)&&e.classList.remove(t);for(e.getAttribute(`class`)||e.removeAttribute(`class`);s.length>1&&s[s.length-1].level>r;)s.pop();if(s[s.length-1].level===r&&s[s.length-1].type!==i&&s.pop(),s[s.length-1].level<r){let e=s[s.length-1],a=n(e.list)||e.list,o=t.createElement(i);a.appendChild(o),s.push({list:o,level:r,type:i})}s[s.length-1].list.appendChild(e)}r.replaceWith(o)}for(let t of Array.from(e.querySelectorAll(`ul, ol`))){let e=Array.from(t.children).filter(e=>e.tagName.toLowerCase()===`li`);e.length>0&&e.every(e=>e.style.direction===`rtl`||e.getAttribute(`dir`)===`rtl`)&&t.style.direction!==`rtl`&&(t.style.direction=`rtl`)}}var G_=new Set([`SPAN`,`STRONG`,`B`,`EM`,`I`,`U`,`S`,`DEL`,`SUB`,`SUP`]);function K_(e){if(e.tagName!==`SPAN`)return!1;for(let t of Array.from(e.attributes))if(t.value.trim())return!1;return!0}function q_(e,t){if(e.attributes.length!==t.attributes.length)return!1;for(let n of Array.from(e.attributes))if(t.getAttribute(n.name)!==n.value)return!1;return!0}function J_(e){let t=e=>{for(let n of Array.from(e.children))t(n);if(K_(e)&&e.parentNode){let t=e.parentNode;for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}};for(let n of Array.from(e.children))t(n);let n=e=>{for(let t of Array.from(e.children))n(t);let t=e.firstElementChild;for(;t;){let e=t.nextElementSibling;if(e&&t.nextSibling===e&&G_.has(t.tagName)&&t.tagName===e.tagName&&q_(t,e)){for(;e.firstChild;)t.appendChild(e.firstChild);e.remove(),n(t);continue}t=e}};n(e)}function Y_(e,t){if(!e||!e.includes(`<`))return e;let n=H_(e);if(!n)return e;let r=e=>{for(let t of Array.from(e.children))r(t);let n=e.getAttribute(`class`);if(n){let r=n.split(/\s+/).filter(Boolean),i=[];for(let n of r){if(n.startsWith(`ql-font-`)){if(!e.style.fontFamily){let t=R_[n]||z_(n);e.style.fontFamily=t}continue}let r=lte[n];if(r!=null){e.style.fontSize||(e.style.fontSize=`${t.fontSize*r}px`);continue}if(n.startsWith(`ql-align-`)){let t=n.slice(9);t&&!e.style.textAlign&&(e.style.textAlign=t);continue}if(n.startsWith(`ql-indent-`)){if(e.tagName===`LI`){i.push(n);continue}let t=parseInt(n.slice(10),10);t>0&&!e.style.getPropertyValue(`margin-inline-start`)&&e.style.setProperty(`margin-inline-start`,`${t*.5}em`);continue}if(n===`ql-direction-rtl`){e.style.direction||(e.style.direction=`rtl`);continue}i.push(n)}i.length?e.setAttribute(`class`,i.join(` `)):e.removeAttribute(`class`)}let i=e.style.fontSize;if(i){let n=V_(i,t.fontSize);n!=null&&(e.style.fontSize=`${n}px`)}};r(n),J_(n),W_(n);for(let e of Array.from(n.querySelectorAll(`p`))){let t=e,n=``,r=``,i=``;for(;t.childNodes.length===1&&t.firstChild!=null&&t.firstChild.nodeType===1;){let e=t.firstChild;e.style.fontFamily&&(n=e.style.fontFamily),e.style.fontWeight&&(r=e.style.fontWeight),(e.tagName===`STRONG`||e.tagName===`B`)&&(r=`bold`),(e.tagName===`EM`||e.tagName===`I`||e.style?.fontStyle===`italic`)&&(i=`italic`),t=e}n&&(e.style.fontFamily=n),r&&(e.style.fontWeight=r),i&&(e.style.fontStyle=i)}return n.innerHTML}function X_(e){if(!e||!e.includes(`<p`))return e;let t=H_(e);if(!t)return e;for(let e of Array.from(t.querySelectorAll(`p`))){let n=!1,r=[],i=t.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),a=i.nextNode();for(;a;){if((a.textContent||``).length>0){let t=a.parentElement,i=null;for(;t&&t!==e;){let e=t.style?.fontSize;if(e){let t=parseFloat(e);if(!Number.isNaN(t)){i=t;break}}t=t.parentElement}if(i==null){n=!0;break}r.push(i)}a=i.nextNode()}!n&&r.length>0&&(e.style.fontSize=`${Math.min(...r)}px`)}return t.innerHTML}function Z_(e){let t=new Set;if(!e||!e.includes(`<`))return[];let n=H_(e);if(n){let e=n.querySelectorAll(`[style]`);for(let n of e)if(n.style.fontFamily){let e=B_(n.style.fontFamily);e&&t.add(e)}}for(let n of e.matchAll(/\bfont-family="([^"]+)"/g)){let e=B_(n[1]);e&&t.add(e)}for(let n of e.matchAll(/\bql-font-([a-z0-9_-]+)\b/gi)){let e=`ql-font-${n[1]}`,r=B_(R_[e]||z_(e));r&&t.add(r)}return[...t]}function Q_(e,t){if(!e||t===1||t<=0||!Number.isFinite(t))return e;let n=H_(e);if(!n)return e;let r=e=>{let n=e.style.fontSize;if(n){let r=n.match(/^(\d+(?:\.\d+)?)(px|em|rem)$/i);if(r){let n=Math.round(parseFloat(r[1])*t*1e3)/1e3;e.style.fontSize=`${n}${r[2].toLowerCase()}`}}for(let t of Array.from(e.children))r(t)};return r(n),n.innerHTML}var $_={bold:[`STRONG`,`B`],italic:[`EM`,`I`],underline:[`U`],strike:[`S`,`DEL`]},ev={bold:e=>e.style.removeProperty(`font-weight`),italic:e=>e.style.removeProperty(`font-style`),color:e=>e.style.removeProperty(`color`),underline:e=>{let t=e.style.textDecoration.replace(/\bunderline\b/g,``).trim();t?e.style.textDecoration=t:e.style.removeProperty(`text-decoration`)},strike:e=>{let t=e.style.textDecoration.replace(/\bline-through\b/g,``).trim();t?e.style.textDecoration=t:e.style.removeProperty(`text-decoration`)}};function tv(e,t){if(!e||!e.includes(`<`))return e;let n=H_(e);if(!n)return e;let r=$_[t]||[],i=ev[t];for(let e of r){let t;for(;t=n.querySelector(e);){let e=t.parentNode;for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t)}}if(i)for(let e of Array.from(n.querySelectorAll(`[style]`)))i(e),e.getAttribute(`style`)?.trim()||e.removeAttribute(`style`);return J_(n),n.innerHTML}var nv=Symbol(`unset`);function ute(e,t){let n=nv;for(let r of e.ops){if(typeof r.insert!=`string`||r.insert===`
51
+ https://polotno.com/docs/server-api`,n_={unsplashList:({query:e,page:t=1})=>`${Qg()}/get-unsplash?query=${e}&per_page=20&page=${t}&KEY=${x_()}`,unsplashDownload:e=>`${Qg()}/download-unsplash?id=${e}&KEY=${x_()}`,svgapiList:({query:e,page:t=0})=>`${Qg()}/get-svgapi?query=${e}&page=${t}&per_page=20&KEY=${x_()}`,svgapiDownload:e=>`${Qg()}/download-svgapi?path=${e}&KEY=${x_()}`,iconscoutList:({query:e,page:t=1})=>(e_(`iconscout`,t_),`${Qg()}/get-iconscout?query=${e}&page=${t}&KEY=${x_()}`),iconscoutDownload:e=>(e_(`iconscout`,t_),`${Qg()}/download-iconscout?uuid=${e}&KEY=${x_()}`),nounProjectList:({query:e,page:t=1})=>`${Qg()}/get-nounproject?query=${e}&page=${t}&KEY=${x_()}`,nounProjectDownload:e=>`${Qg()}/download-nounproject?id=${e}&KEY=${x_()}`,templateList:({query:e,page:t=1,sizeQuery:n})=>`${Qg()}/get-templates?${n}&query=${e}&per_page=30&page=${t}&KEY=${x_()}`,googleFontsList:()=>`${Qg()}/get-google-fonts?KEY=${x_()}`,googleFontImage:e=>`${Zg}/google-fonts-previews/black/${Mee(e,` `,`-`)}.png`,textTemplateList:()=>`${Qg()}/get-text-templates?KEY=${x_()}`,removeBackground:()=>`${Qg()}/remove-image-background?KEY=${x_()}`,aiText:()=>`${Qg()}/ai/text?KEY=${x_()}`},r_=()=>n_.googleFontsList(),i_=e=>n_.googleFontImage(e),Nee=()=>n_.removeBackground(),Pee=e=>n_.templateList(e),Fee=()=>n_.textTemplateList(),a_=e=>n_.unsplashList(e),o_=e=>n_.unsplashDownload(e),Iee=(e,t)=>{n_[e]=t},s_=Ht({imageDownScalingEnabled:!0,removeBackgroundEnabled:!1,htmlRenderEnabled:!1,renderTagTextEnabled:!0,forceTextFitEnabled:!1,textVerticalResizeEnabled:!1,textOverflow:`resize`,textSplitAllowed:!1,animationsEnabled:!1,aiTextEnabled:!1,autoDeleteEmptyText:!0}),c_=typeof window<`u`&&window.location.hostname===`localhost`||typeof process<`u`&&!1,l_=ir(e=>{s_.textVerticalResizeEnabled=e}),u_=ir(e=>{s_.removeBackgroundEnabled=e}),Lee=ir(e=>{c_&&console.warn(`useRemoveBackground is deprecated. Use setRemoveBackgroundEnabled instead.`),u_(e)}),Ree=ir(e=>{s_.aiTextEnabled=e}),zee=ir(e=>{c_&&console.warn(`useHtmlTextRender is deprecated. Use setRichTextEnabled instead.`),s_.htmlRenderEnabled=e}),d_=e=>ir(t=>{c_&&console.warn(`${e}() is a no-op: the new text rendering engine is enabled by default.`)}),Bee=e=>{or(()=>{s_.htmlRenderEnabled=!0,s_.renderTagTextEnabled=!1})},Vee=d_(`setRichTextEnabled`);d_(`setRenderTagTextEnabled`);var f_=ir(e=>{s_.imageDownScalingEnabled=e}),Hee=ir(e=>{console.warn(`useDownScaling is deprecated. Use setDownScalingEnabled instead.`),f_(e)}),Uee=ir(e=>{console.warn(`setForceTextFit is deprecated. Use setTextOverflow instead.`),s_.textOverflow=`change-font-size`}),p_=ir(e=>{s_.textOverflow=e}),m_=ir(e=>{s_.textSplitAllowed=e}),h_=ir(e=>{s_.animationsEnabled=e}),Wee=ir(e=>{s_.autoDeleteEmptyText=e}),g_=Ht({value:!1}),__=Ht({value:`v1`}),Gee=()=>__.value,v_=Ht({value:0}),y_=()=>v_.value,Kee=()=>g_.value,qee=ir(()=>{g_.value=!0}),b_=``,x_=()=>b_||``,Jee=5,S_=3e3,Yee=`Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet`,Xee=`Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet`,Zee=`Can not validate Polotno API key. Please report to anton@polotno.com immediately.`,Qee=`%cPolotno Free Version. For development usage only. https://polotno.com/`,C_=typeof window<`u`?window.location.origin:``,$ee=typeof navigator<`u`?navigator.userAgent.indexOf(`Headless`)>-1:!1,ete=typeof navigator<`u`?navigator.userAgent.indexOf(`Electron`)>-1:!1;C_===`file://`&&$ee&&(C_=`headless`),C_===`file://`&&ete&&(C_=`electron`);var tte=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${C_}" here: https://polotno.com/cabinet`,nte=fetch;async function rte(e){for(let t=0;t<Jee;t++)try{let t=await nte(Qg()+`/validate-key`,{method:`POST`,body:JSON.stringify({key:e,site:location.host,skdVersion:`SDK_VERSION`})});if(or(()=>{__.value=t.headers.get(`x-api-version`)||``}),!e)return console.error(Yee),or(()=>{v_.value=1}),!1;if(t.status!==200){await new Promise(e=>setTimeout(e,S_));continue}let n=await t.json();return n.is_valid||(console.error(Xee),or(()=>{v_.value=1})),n.is_paid||(console.log(Qee,`background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;`),or(()=>{v_.value===0&&(v_.value=2)})),n.is_domain_valid||console.log(tte,`background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;`),u_(n.remove_background_enabled),n.is_paid||!1}catch{await new Promise(e=>setTimeout(e,S_))}return console.error(Zee),!0}async function ite(e,t){b_=e,(!await rte(e)||t)&&qee()}var w_=!1,ate=(e=!w_)=>{w_=e},T_=()=>w_;function E_(e,t){let n=x.useRef();x.useLayoutEffect(()=>{n.current&&n.current.destroy()},[t]),x.useLayoutEffect(()=>{if(!w_)return;let t=e.current.opacity();if(t)return e.current.opacity(0),n.current=new Xu.Tween({node:e.current,opacity:t,onFinish:()=>{n.current?.destroy()}}),n.current.play(),()=>{n.current?.destroy()}},[])}var D_=0,O_=[],k_=3e4,A_=e=>{k_=e},j_=6e3,ote=e=>{j_=e},ste=()=>j_;function M_(e){D_+=1;let t=!1,n=!1,r=setTimeout(()=>{t||(L_(`Timeout loading asset ${e}`),console.error(`Timeout triggered for loader. Some assets may not have loaded.`,e),t=!0,N_())},k_);return()=>{if(n){console.error(`Finish called twice! That is not expected. id: `,e);return}n=!0,!t&&(clearTimeout(r),N_())}}function N_(){--D_,D_===0&&(O_.forEach(e=>e()),O_=[])}function cte(e){D_===0?e():O_.push(e)}function P_(){return new Promise(e=>cte(()=>{T_()?setTimeout(e,300):e(!0)}))}var F_=[];function I_(e){F_.push(e)}function L_(e){F_.forEach(t=>t(e))}var R_={"ql-font-serif":`Georgia, Times New Roman, serif`,"ql-font-monospace":`Monaco, Courier New, monospace`,"ql-font-sans":`system-ui, -apple-system, BlinkMacSystemFont, sans-serif`},lte={"ql-size-small":.75,"ql-size-large":1.5,"ql-size-huge":2.5};function z_(e){return e.replace(/^ql-font-/,``).split(`-`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `)}function B_(e){return e.replace(/&quot;/g,`"`).replace(/&amp;/g,`&`).split(`,`)[0].trim().replace(/^["']|["']$/g,``)||null}function V_(e,t){if(!e)return;let n=e.trim(),r=n.match(/^(\d+(?:\.\d+)?)px$/i);if(r)return parseFloat(r[1]);let i=n.match(/^(\d+(?:\.\d+)?)em$/i);if(i)return t*parseFloat(i[1]);let a=n.match(/^(\d+(?:\.\d+)?)rem$/i);if(a)return t*parseFloat(a[1])}function H_(e){return new DOMParser().parseFromString(`<div id="polotno-rich-root">${e}</div>`,`text/html`).getElementById(`polotno-rich-root`)}function U_(e){for(let t of Array.from(e.classList))if(t.startsWith(`ql-indent-`)){let e=parseInt(t.slice(10),10);if(e>0)return e}return 0}function W_(e){for(let t of Array.from(e.querySelectorAll(`span.ql-ui`)))t.remove();let t=e.ownerDocument,n=e=>{let t=e.children;for(let e=t.length-1;e>=0;e--)if(t[e].tagName.toLowerCase()===`li`)return t[e];return null};for(let r of Array.from(e.querySelectorAll(`ol, ul`))){let e=r.tagName.toLowerCase(),i=Array.from(r.children).filter(e=>e.tagName.toLowerCase()===`li`);if(i.length===0||!i.some(e=>e.hasAttribute(`data-list`)||U_(e)>0))continue;let a=t=>{let n=t.getAttribute(`data-list`);return n===`ordered`?`ol`:n===`bullet`||n===`checked`||n===`unchecked`?`ul`:e===`ol`?`ol`:`ul`},o=t.createDocumentFragment(),s=[{list:o,level:-1,type:``}];for(let e of i){let r=U_(e),i=a(e);e.removeAttribute(`data-list`);for(let t of Array.from(e.classList))t.startsWith(`ql-indent-`)&&e.classList.remove(t);for(e.getAttribute(`class`)||e.removeAttribute(`class`);s.length>1&&s[s.length-1].level>r;)s.pop();if(s[s.length-1].level===r&&s[s.length-1].type!==i&&s.pop(),s[s.length-1].level<r){let e=s[s.length-1],a=n(e.list)||e.list,o=t.createElement(i);a.appendChild(o),s.push({list:o,level:r,type:i})}s[s.length-1].list.appendChild(e)}r.replaceWith(o)}for(let t of Array.from(e.querySelectorAll(`ul, ol`))){let e=Array.from(t.children).filter(e=>e.tagName.toLowerCase()===`li`);e.length>0&&e.every(e=>e.style.direction===`rtl`||e.getAttribute(`dir`)===`rtl`)&&t.style.direction!==`rtl`&&(t.style.direction=`rtl`)}}var G_=new Set([`SPAN`,`STRONG`,`B`,`EM`,`I`,`U`,`S`,`DEL`,`SUB`,`SUP`]);function K_(e){if(e.tagName!==`SPAN`)return!1;for(let t of Array.from(e.attributes))if(t.value.trim())return!1;return!0}function q_(e,t){if(e.attributes.length!==t.attributes.length)return!1;for(let n of Array.from(e.attributes))if(t.getAttribute(n.name)!==n.value)return!1;return!0}function J_(e){let t=e=>{for(let n of Array.from(e.children))t(n);if(K_(e)&&e.parentNode){let t=e.parentNode;for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}};for(let n of Array.from(e.children))t(n);let n=e=>{for(let t of Array.from(e.children))n(t);let t=e.firstElementChild;for(;t;){let e=t.nextElementSibling;if(e&&t.nextSibling===e&&G_.has(t.tagName)&&t.tagName===e.tagName&&q_(t,e)){for(;e.firstChild;)t.appendChild(e.firstChild);e.remove(),n(t);continue}t=e}};n(e)}function Y_(e,t){if(!e||!e.includes(`<`))return e;let n=H_(e);if(!n)return e;let r=e=>{for(let t of Array.from(e.children))r(t);let n=e.getAttribute(`class`);if(n){let r=n.split(/\s+/).filter(Boolean),i=[];for(let n of r){if(n.startsWith(`ql-font-`)){if(!e.style.fontFamily){let t=R_[n]||z_(n);e.style.fontFamily=t}continue}let r=lte[n];if(r!=null){e.style.fontSize||(e.style.fontSize=`${t.fontSize*r}px`);continue}if(!n.startsWith(`ql-align-`)){if(n.startsWith(`ql-indent-`)){if(e.tagName===`LI`){i.push(n);continue}let t=parseInt(n.slice(10),10);t>0&&!e.style.getPropertyValue(`margin-inline-start`)&&e.style.setProperty(`margin-inline-start`,`${t*.5}em`);continue}if(n===`ql-direction-rtl`){e.style.direction||(e.style.direction=`rtl`);continue}i.push(n)}}i.length?e.setAttribute(`class`,i.join(` `)):e.removeAttribute(`class`)}let i=e.style.fontSize;if(i){let n=V_(i,t.fontSize);n!=null&&(e.style.fontSize=`${n}px`)}};r(n),J_(n),W_(n);for(let e of Array.from(n.querySelectorAll(`p`))){let t=e,n=``,r=``,i=``;for(;t.childNodes.length===1&&t.firstChild!=null&&t.firstChild.nodeType===1;){let e=t.firstChild;e.style.fontFamily&&(n=e.style.fontFamily),e.style.fontWeight&&(r=e.style.fontWeight),(e.tagName===`STRONG`||e.tagName===`B`)&&(r=`bold`),(e.tagName===`EM`||e.tagName===`I`||e.style?.fontStyle===`italic`)&&(i=`italic`),t=e}n&&(e.style.fontFamily=n),r&&(e.style.fontWeight=r),i&&(e.style.fontStyle=i)}return n.innerHTML}function X_(e){if(!e||!e.includes(`<p`))return e;let t=H_(e);if(!t)return e;for(let e of Array.from(t.querySelectorAll(`p`))){let n=!1,r=[],i=t.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),a=i.nextNode();for(;a;){if((a.textContent||``).length>0){let t=a.parentElement,i=null;for(;t&&t!==e;){let e=t.style?.fontSize;if(e){let t=parseFloat(e);if(!Number.isNaN(t)){i=t;break}}t=t.parentElement}if(i==null){n=!0;break}r.push(i)}a=i.nextNode()}!n&&r.length>0&&(e.style.fontSize=`${Math.min(...r)}px`)}return t.innerHTML}function Z_(e){let t=new Set;if(!e||!e.includes(`<`))return[];let n=H_(e);if(n){let e=n.querySelectorAll(`[style]`);for(let n of e)if(n.style.fontFamily){let e=B_(n.style.fontFamily);e&&t.add(e)}}for(let n of e.matchAll(/\bfont-family="([^"]+)"/g)){let e=B_(n[1]);e&&t.add(e)}for(let n of e.matchAll(/\bql-font-([a-z0-9_-]+)\b/gi)){let e=`ql-font-${n[1]}`,r=B_(R_[e]||z_(e));r&&t.add(r)}return[...t]}function Q_(e,t){if(!e||t===1||t<=0||!Number.isFinite(t))return e;let n=H_(e);if(!n)return e;let r=e=>{let n=e.style.fontSize;if(n){let r=n.match(/^(\d+(?:\.\d+)?)(px|em|rem)$/i);if(r){let n=Math.round(parseFloat(r[1])*t*1e3)/1e3;e.style.fontSize=`${n}${r[2].toLowerCase()}`}}for(let t of Array.from(e.children))r(t)};return r(n),n.innerHTML}var $_={bold:[`STRONG`,`B`],italic:[`EM`,`I`],underline:[`U`],strike:[`S`,`DEL`]},ev={bold:e=>e.style.removeProperty(`font-weight`),italic:e=>e.style.removeProperty(`font-style`),color:e=>e.style.removeProperty(`color`),underline:e=>{let t=e.style.textDecoration.replace(/\bunderline\b/g,``).trim();t?e.style.textDecoration=t:e.style.removeProperty(`text-decoration`)},strike:e=>{let t=e.style.textDecoration.replace(/\bline-through\b/g,``).trim();t?e.style.textDecoration=t:e.style.removeProperty(`text-decoration`)}};function tv(e,t){if(!e||!e.includes(`<`))return e;let n=H_(e);if(!n)return e;let r=$_[t]||[],i=ev[t];for(let e of r){let t;for(;t=n.querySelector(e);){let e=t.parentNode;for(;t.firstChild;)e.insertBefore(t.firstChild,t);e.removeChild(t)}}if(i)for(let e of Array.from(n.querySelectorAll(`[style]`)))i(e),e.getAttribute(`style`)?.trim()||e.removeAttribute(`style`);return J_(n),n.innerHTML}var nv=Symbol(`unset`);function ute(e,t){let n=nv;for(let r of e.ops){if(typeof r.insert!=`string`||r.insert===`
52
52
  `)continue;let e=r.attributes?.[t];if(n===nv)n=e;else if(e!==n)return!0}return!1}function dte(e){if(!e||!e.includes(`font-size`))return e;let t=H_(e);if(!t)return e;let n=t.querySelectorAll(`[style]`);for(let e=0;e<n.length;e++){let t=n[e];t.style.fontSize&&(t.style.removeProperty(`font-size`),t.getAttribute(`style`)?.trim()||t.removeAttribute(`style`))}return J_(t),t.innerHTML}function fte(e){if(!e||!e.includes(`font-family`)&&!e.includes(`ql-font-`))return e;let t=H_(e);if(!t)return e;for(let e of Array.from(t.querySelectorAll(`[style]`)))e.style.fontFamily&&(e.style.removeProperty(`font-family`),e.getAttribute(`style`)?.trim()||e.removeAttribute(`style`));for(let e of Array.from(t.querySelectorAll(`[class]`))){let t=e.getAttribute(`class`)||``,n=t.split(/\s+/).filter(e=>e&&!e.startsWith(`ql-font-`));n.length!==t.split(/\s+/).filter(Boolean).length&&(n.length?e.setAttribute(`class`,n.join(` `)):e.removeAttribute(`class`))}return J_(t),t.innerHTML}function pte(e){if(!e||!e.includes(`<`))return!1;let t=H_(e);if(!t)return!1;for(let e of t.querySelectorAll(`[style]`))if(e.style.fontSize)return!0;return!1}function mte(e,t){let n=[],r=t?B_(t)||t:``;r&&n.push(r);for(let t of Z_(e||``)){let e=B_(t)||t;e&&n.push(e)}let i=new Set,a=[];for(let e of n)i.has(e)||(i.add(e),a.push(e));return a.sort((e,t)=>e.localeCompare(t,void 0,{sensitivity:`base`})),a}function rv(e=``){return(e.match(/<\/p>/gi)||[]).length>1&&(e=e.replace(/<\/p>/gi,(e,t,n)=>(n.slice(t+e.length).match(/<\/p>/gi)||[]).length>0?`
53
53
  `:e)),e.replace(/(<([^>]+)>)/gi,``).replace(/&amp;/g,`&`).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&apos;/g,`'`).replace(/&nbsp;/g,` `)}function hte(e,t){return!!e.bold==!!t.bold&&!!e.italic==!!t.italic&&!!e.underline==!!t.underline&&!!e.strike==!!t.strike&&(e.color||``)===(t.color||``)&&(e.fontFamily||``)===(t.fontFamily||``)&&(e.fontSize??-1)===(t.fontSize??-1)}function iv(e,t){let n={text:e};return t.bold&&(n.bold=!0),t.italic&&(n.italic=!0),t.underline&&(n.underline=!0),t.strike&&(n.strike=!0),t.color&&(n.color=t.color),t.fontFamily&&(n.fontFamily=t.fontFamily),t.fontSize!=null&&(n.fontSize=t.fontSize),n}function av(e,t){if(!e)return[];let n=new DOMParser().parseFromString(e,`text/html`),r=[],i=n.body.querySelectorAll(`p`),a=t?.fontSize??14;function o(e,t){if(e.nodeType===Node.TEXT_NODE){let n=e.textContent||``;n&&r.push(iv(n,t));return}if(e.nodeType!==Node.ELEMENT_NODE)return;let n=e,i=n.tagName.toLowerCase(),s={...t};(i===`strong`||i===`b`)&&(s.bold=!0),(i===`em`||i===`i`)&&(s.italic=!0),i===`u`&&(s.underline=!0),i===`s`&&(s.strike=!0);let c=n.style;c.color&&(s.color=c.color),(c.fontWeight===`bold`||parseInt(c.fontWeight)>=700)&&(s.bold=!0),c.fontStyle===`italic`&&(s.italic=!0);let l=c.textDecoration||c.textDecorationLine||``;if(l.includes(`underline`)&&(s.underline=!0),l.includes(`line-through`)&&(s.strike=!0),c.fontFamily){let e=B_(c.fontFamily);e&&(s.fontFamily=e)}if(c.fontSize){let e=t.fontSize??a,n=V_(c.fontSize,e);n!=null&&(s.fontSize=n)}for(let e of Array.from(n.childNodes))o(e,s)}i.length>0?i.forEach((e,t)=>{o(e,{}),t<i.length-1&&r.push({text:`
54
- `})}):o(n.body,{});let s=[];for(let e of r){if(!e.text)continue;let t=s[s.length-1];t&&hte(t,e)?t.text+=e.text:s.push(e)}return s}function ov(e){return e?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(e)?(e=e.replace(/<(?![a-z/!])/gi,`&lt;`),e=e.replace(/([^a-z0-9"'\s/])>/gi,`$1&gt;`),e):e.replace(/</g,`&lt;`).replace(/>/g,`&gt;`):``}var sv=Ht([`Roboto`,`Amatic SC`,`Press Start 2P`,`Marck Script`,`Rubik Mono One`]),cv=Ht({value:!1});function lv(){return cv.value}function uv(e){if(e==="default"){cv.value=!1;return}cv.value=!0,sv.splice(0,sv.length),sv.push(...e)}function dv(){return sv}var fv=Ht([]);function pv(e){fv.push(e)}function mv(e){let t=fv.findIndex(t=>t.fontFamily===e);t!==-1&&fv.splice(t,1)}function hv(e){fv.replace(e)}var gv=`BESbswy 0123456789 Il1Ww`,_v=10,vv=[`sans-serif`,`serif`,`monospace`],yv=60,bv=6e3;function xv(e=``){let t=rv(e).replace(/\s+/g,` `).trim();return t?Array.from(t).slice(0,_v).join(``):``}function Sv(e){let t=xv(e);return t?`${gv} ${t}`:gv}var Cv;function wv(e){return{width:e.width,actualBoundingBoxLeft:e.actualBoundingBoxLeft||0,actualBoundingBoxRight:e.actualBoundingBoxRight||0,actualBoundingBoxAscent:e.actualBoundingBoxAscent||0,actualBoundingBoxDescent:e.actualBoundingBoxDescent||0}}function Tv(e,t,n=.01){return Math.abs(e.width-t.width)>n||Math.abs(e.actualBoundingBoxLeft-t.actualBoundingBoxLeft)>n||Math.abs(e.actualBoundingBoxRight-t.actualBoundingBoxRight)>n||Math.abs(e.actualBoundingBoxAscent-t.actualBoundingBoxAscent)>n||Math.abs(e.actualBoundingBoxDescent-t.actualBoundingBoxDescent)>n}function Ev(e,t=`sans-serif`,n=`normal`,r=`normal`,i=gv){Cv||=document.createElement(`canvas`);let a=Cv.getContext(`2d`);return a.font=`${n} ${r} 40px '${e}', ${t}`,wv(a.measureText(i))}function Dv(e=`sans-serif`,t=`normal`,n=`normal`,r=gv){Cv||=document.createElement(`canvas`);let i=Cv.getContext(`2d`);return i.font=`${t} ${n} 40px ${e}`,wv(i.measureText(r))}function Ov(e,t,n,r,i){return vv.some(a=>Tv(Ev(e,a,t,n,r),i[a]))}var kv={Arial:!0},Av=(e,t,n)=>t&&n?!!kv[`${e}_${t}_${n}`]:Object.keys(kv).some(t=>t.startsWith(e+`_`))||!!kv[e];async function gte(e,t,n,r){let i=`${e}_${t}_${n}`;if(kv[i])return;let a=!!document.fonts?.load,o=Sv(r),s={"sans-serif":Dv(`sans-serif`,t,n,o),serif:Dv(`serif`,t,n,o),monospace:Dv(`monospace`,t,n,o)};if(a)try{if(await document.fonts.load(`${t} ${n} 16px '${e}'`,o),Ov(e,t,n,o,s)){kv[i]=!0;return}}catch{}let c=Math.min(bv,ste())/yv;for(let r=0;r<c;r++){if(Ov(e,t,n,o,s)){kv[i]=!0;return}await new Promise(e=>setTimeout(e,yv))}console.warn(`Timeout for loading font "${e}". Looks like polotno can't load it. Is it a correct font family?`),L_(`Timeout for loading font "${e}"`)}var jv={},Mv=`400,400italic,700,700italic`;function _te(e){Mv=e}function vte(){return Mv}function Nv(e){return`https://fonts.googleapis.com/css?family=${e.replace(/ /g,`+`)}:${Mv}`}function yte(e){if(jv[e])return;let t=Nv(e),n=document.createElement(`link`);n.type=`text/css`,n.href=t,n.rel=`stylesheet`,document.getElementsByTagName(`head`)[0].appendChild(n),jv[e]=!0}var Pv={},Fv;function bte(){return Fv||(Fv=document.getElementById(`polotno-font-style`),Fv||(Fv=document.createElement(`style`),Fv.id=`polotno-font-style`,document.head.appendChild(Fv)),Fv)}function xte(e){let t=e.fontFamily;if(Pv[t]||!e.url&&!e.styles)return;let n=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),r=bte().sheet;n.forEach(e=>{r.insertRule(`
54
+ `})}):o(n.body,{});let s=[];for(let e of r){if(!e.text)continue;let t=s[s.length-1];t&&hte(t,e)?t.text+=e.text:s.push(e)}return s}function ov(e){return e?/<[a-z][a-z0-9]*(\s[^>]*)?>[^<]*<\/[a-z][a-z0-9]*>/i.test(e)?(e=e.replace(/<(?![a-z/!])/gi,`&lt;`),e=e.replace(/([^a-z0-9"'\s/])>/gi,`$1&gt;`),e):e.replace(/</g,`&lt;`).replace(/>/g,`&gt;`):``}var sv=Ht([`Roboto`,`Amatic SC`,`Press Start 2P`,`Marck Script`,`Rubik Mono One`]),cv=Ht({value:!1});function lv(){return cv.value}function uv(e){if(e==="default"){cv.value=!1;return}cv.value=!0,sv.splice(0,sv.length),sv.push(...e)}function dv(){return sv}var fv=Ht([]);function pv(e){fv.push(e)}function mv(e){let t=fv.findIndex(t=>t.fontFamily===e);t!==-1&&fv.splice(t,1)}function hv(e){fv.replace(e)}var gv=`BESbswy 0123456789 Il1Ww`,_v=10,vv=[`sans-serif`,`serif`,`monospace`],yv=60,bv=6e3;function xv(e=``){let t=rv(e).replace(/\s+/g,` `).trim();return t?Array.from(t).slice(0,_v).join(``):``}function Sv(e){let t=xv(e);return t?`${gv} ${t}`:gv}var Cv;function wv(e){return{width:e.width,actualBoundingBoxLeft:e.actualBoundingBoxLeft||0,actualBoundingBoxRight:e.actualBoundingBoxRight||0,actualBoundingBoxAscent:e.actualBoundingBoxAscent||0,actualBoundingBoxDescent:e.actualBoundingBoxDescent||0}}function Tv(e,t,n=.01){return Math.abs(e.width-t.width)>n||Math.abs(e.actualBoundingBoxLeft-t.actualBoundingBoxLeft)>n||Math.abs(e.actualBoundingBoxRight-t.actualBoundingBoxRight)>n||Math.abs(e.actualBoundingBoxAscent-t.actualBoundingBoxAscent)>n||Math.abs(e.actualBoundingBoxDescent-t.actualBoundingBoxDescent)>n}function Ev(e,t=`sans-serif`,n=`normal`,r=`normal`,i=gv){Cv||=document.createElement(`canvas`);let a=Cv.getContext(`2d`);return a.font=`${n} ${r} 40px '${e}', ${t}`,wv(a.measureText(i))}function Dv(e=`sans-serif`,t=`normal`,n=`normal`,r=gv){Cv||=document.createElement(`canvas`);let i=Cv.getContext(`2d`);return i.font=`${t} ${n} 40px ${e}`,wv(i.measureText(r))}function Ov(e,t,n,r,i){return vv.some(a=>Tv(Ev(e,a,t,n,r),i[a]))}var kv={Arial:!0},Av=(e,t,n)=>t&&n?!!kv[`${e}_${t}_${n}`]:Object.keys(kv).some(t=>t.startsWith(e+`_`))||!!kv[e];async function gte(e,t,n,r){let i=`${e}_${t}_${n}`;if(kv[i])return;let a=!!document.fonts?.load,o=Sv(r),s={"sans-serif":Dv(`sans-serif`,t,n,o),serif:Dv(`serif`,t,n,o),monospace:Dv(`monospace`,t,n,o)};if(a)try{if(await document.fonts.load(`${t} ${n} 16px '${e}'`,o),Ov(e,t,n,o,s)){kv[i]=!0;return}}catch{}let c=Math.min(bv,ste())/yv;for(let r=0;r<c;r++){if(a)try{await document.fonts.load(`${t} ${n} 16px '${e}'`,o)}catch{}if(Ov(e,t,n,o,s)){kv[i]=!0;return}await new Promise(e=>setTimeout(e,yv))}console.warn(`Timeout for loading font "${e}". Looks like polotno can't load it. Is it a correct font family?`),L_(`Timeout for loading font "${e}"`)}var jv={},Mv=`400,400italic,700,700italic`;function _te(e){Mv=e}function vte(){return Mv}function Nv(e){return`https://fonts.googleapis.com/css?family=${e.replace(/ /g,`+`)}:${Mv}`}function yte(e){if(jv[e])return;let t=Nv(e),n=document.createElement(`link`);n.type=`text/css`,n.href=t,n.rel=`stylesheet`,document.getElementsByTagName(`head`)[0].appendChild(n),jv[e]=!0}var Pv={},Fv;function bte(){return Fv||(Fv=document.getElementById(`polotno-font-style`),Fv||(Fv=document.createElement(`style`),Fv.id=`polotno-font-style`,document.head.appendChild(Fv)),Fv)}function xte(e){let t=e.fontFamily;if(Pv[t]||!e.url&&!e.styles)return;let n=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),r=bte().sheet;n.forEach(e=>{r.insertRule(`
55
55
  @font-face{
56
56
  font-family:'${t}';
57
57
  src:${e.src};
package/utils/fonts.js CHANGED
@@ -1 +1 @@
1
- import*as t from"mobx";import{triggerLoadError as n,getFontLoadTimeout as o}from"./loader.js";import{removeTags as e}from"./text.js";let a=t.observable(["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"]),s=t.observable({value:!1});export function isGoogleFontChanged(){return s.value}export function setGoogleFonts(t){"default"!==t?(s.value=!0,a.splice(0,a.length),a.push(...t)):s.value=!1}export function getFontsList(){return a}export const globalFonts=t.observable([]);export function addGlobalFont(t){globalFonts.push(t)}export function removeGlobalFont(t){const n=globalFonts.findIndex(n=>n.fontFamily===t);-1!==n&&globalFonts.splice(n,1)}export function replaceGlobalFonts(t){globalFonts.replace(t)}const r="BESbswy 0123456789 Il1Ww",i=["sans-serif","serif","monospace"];function l(t){const n=function(t=""){const n=e(t).replace(/\s+/g," ").trim();return n?Array.from(n).slice(0,10).join(""):""}(t);return n?`${r} ${n}`:r}export function _getFontProbeTextForTesting(t){return l(t)}let c;function u(t){return{width:t.width,actualBoundingBoxLeft:t.actualBoundingBoxLeft||0,actualBoundingBoxRight:t.actualBoundingBoxRight||0,actualBoundingBoxAscent:t.actualBoundingBoxAscent||0,actualBoundingBoxDescent:t.actualBoundingBoxDescent||0}}function f(t="sans-serif",n="normal",o="normal",e=r){c||(c=document.createElement("canvas"));const a=c.getContext("2d");return a.font=`${n} ${o} 40px ${t}`,u(a.measureText(e))}function d(t,n,o,e,a){return i.some(s=>{const i=function(t,n="sans-serif",o="normal",e="normal",a=r){c||(c=document.createElement("canvas"));const s=c.getContext("2d");return s.font=`${o} ${e} 40px '${t}', ${n}`,u(s.measureText(a))}(t,s,n,o,e);return function(t,n,o=.01){return Math.abs(t.width-n.width)>o||Math.abs(t.actualBoundingBoxLeft-n.actualBoundingBoxLeft)>o||Math.abs(t.actualBoundingBoxRight-n.actualBoundingBoxRight)>o||Math.abs(t.actualBoundingBoxAscent-n.actualBoundingBoxAscent)>o||Math.abs(t.actualBoundingBoxDescent-n.actualBoundingBoxDescent)>o}(i,a[s])})}export function measureFontDom(t,n="sans-serif",o="normal",e="normal",a=r){if("undefined"==typeof document||!document.body){return 0}const s=document.createElement("span");s.textContent=a,s.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${o} ${e} 90px '${t}', ${n};\n `,document.body.appendChild(s);const i=s.getBoundingClientRect().width;return s.remove(),i}const m={Arial:!0};export const isFontLoaded=(t,n,o)=>n&&o?!!m[`${t}_${n}_${o}`]:Object.keys(m).some(n=>n.startsWith(t+"_"))||!!m[t];export function _setFontLoadedForTesting(t,n){n?m[t]=!0:delete m[t]}export async function loadFont(t,e,a,s){var r;const i=`${t}_${e}_${a}`;if(m[i]){return}const c=!!(null===(r=document.fonts)||void 0===r?void 0:r.load),u=l(s),p={"sans-serif":f("sans-serif",e,a,u),serif:f("serif",e,a,u),monospace:f("monospace",e,a,u)};if(c){try{if(await document.fonts.load(`${e} ${a} 16px '${t}'`,u),d(t,e,a,u,p)){return void(m[i]=!0)}}catch(x){}}const g=Math.min(6e3,o())/60;for(let n=0;n<g;n++){if(d(t,e,a,u,p)){return void(m[i]=!0)}await new Promise(t=>setTimeout(t,60))}console.warn(`Timeout for loading font "${t}". Looks like polotno can't load it. Is it a correct font family?`),n(`Timeout for loading font "${t}"`)}const p={};let g="400,400italic,700,700italic";export function setGoogleFontsVariants(t){g=t}export function getGoogleFontsVariants(){return g}export function getGoogleFontsUrl(t){return`https://fonts.googleapis.com/css?family=${t.replace(/ /g,"+")}:${g}`}export function injectGoogleFont(t){if(p[t]){return}const n=getGoogleFontsUrl(t),o=document.createElement("link");o.type="text/css",o.href=n,o.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(o),p[t]=!0}const x={};let h;export function injectCustomFont(t){const n=t.fontFamily;if(x[n]){return}if(!t.url&&!t.styles){return}const o=t.styles||(t.url?[{src:`url("${t.url}")`}]:[]),e=(h||(h=document.getElementById("polotno-font-style"),h||(h=document.createElement("style"),h.id="polotno-font-style",document.head.appendChild(h)),h)).sheet;o.forEach(t=>{e.insertRule(`\n @font-face{\n font-family:'${n}';\n src:${t.src};\n font-style:${t.fontStyle||"normal"};\n font-weight:${t.fontWeight||"normal"};\n font-display:swap; /* optional but recommended */\n }`,e.cssRules.length)}),x[t.fontFamily]=!0}
1
+ import*as t from"mobx";import{triggerLoadError as n,getFontLoadTimeout as o}from"./loader.js";import{removeTags as e}from"./text.js";let a=t.observable(["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"]),s=t.observable({value:!1});export function isGoogleFontChanged(){return s.value}export function setGoogleFonts(t){"default"!==t?(s.value=!0,a.splice(0,a.length),a.push(...t)):s.value=!1}export function getFontsList(){return a}export const globalFonts=t.observable([]);export function addGlobalFont(t){globalFonts.push(t)}export function removeGlobalFont(t){const n=globalFonts.findIndex(n=>n.fontFamily===t);-1!==n&&globalFonts.splice(n,1)}export function replaceGlobalFonts(t){globalFonts.replace(t)}const r="BESbswy 0123456789 Il1Ww",i=["sans-serif","serif","monospace"];function l(t){const n=function(t=""){const n=e(t).replace(/\s+/g," ").trim();return n?Array.from(n).slice(0,10).join(""):""}(t);return n?`${r} ${n}`:r}export function _getFontProbeTextForTesting(t){return l(t)}let c;function u(t){return{width:t.width,actualBoundingBoxLeft:t.actualBoundingBoxLeft||0,actualBoundingBoxRight:t.actualBoundingBoxRight||0,actualBoundingBoxAscent:t.actualBoundingBoxAscent||0,actualBoundingBoxDescent:t.actualBoundingBoxDescent||0}}function f(t="sans-serif",n="normal",o="normal",e=r){c||(c=document.createElement("canvas"));const a=c.getContext("2d");return a.font=`${n} ${o} 40px ${t}`,u(a.measureText(e))}function d(t,n,o,e,a){return i.some(s=>{const i=function(t,n="sans-serif",o="normal",e="normal",a=r){c||(c=document.createElement("canvas"));const s=c.getContext("2d");return s.font=`${o} ${e} 40px '${t}', ${n}`,u(s.measureText(a))}(t,s,n,o,e);return function(t,n,o=.01){return Math.abs(t.width-n.width)>o||Math.abs(t.actualBoundingBoxLeft-n.actualBoundingBoxLeft)>o||Math.abs(t.actualBoundingBoxRight-n.actualBoundingBoxRight)>o||Math.abs(t.actualBoundingBoxAscent-n.actualBoundingBoxAscent)>o||Math.abs(t.actualBoundingBoxDescent-n.actualBoundingBoxDescent)>o}(i,a[s])})}export function measureFontDom(t,n="sans-serif",o="normal",e="normal",a=r){if("undefined"==typeof document||!document.body){return 0}const s=document.createElement("span");s.textContent=a,s.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${o} ${e} 90px '${t}', ${n};\n `,document.body.appendChild(s);const i=s.getBoundingClientRect().width;return s.remove(),i}const m={Arial:!0};export const isFontLoaded=(t,n,o)=>n&&o?!!m[`${t}_${n}_${o}`]:Object.keys(m).some(n=>n.startsWith(t+"_"))||!!m[t];export function _setFontLoadedForTesting(t,n){n?m[t]=!0:delete m[t]}export async function loadFont(t,e,a,s){var r;const i=`${t}_${e}_${a}`;if(m[i]){return}const c=!!(null===(r=document.fonts)||void 0===r?void 0:r.load),u=l(s),p={"sans-serif":f("sans-serif",e,a,u),serif:f("serif",e,a,u),monospace:f("monospace",e,a,u)};if(c){try{if(await document.fonts.load(`${e} ${a} 16px '${t}'`,u),d(t,e,a,u,p)){return void(m[i]=!0)}}catch(x){}}const g=Math.min(6e3,o())/60;for(let n=0;n<g;n++){if(c){try{await document.fonts.load(`${e} ${a} 16px '${t}'`,u)}catch(h){}}if(d(t,e,a,u,p)){return void(m[i]=!0)}await new Promise(t=>setTimeout(t,60))}console.warn(`Timeout for loading font "${t}". Looks like polotno can't load it. Is it a correct font family?`),n(`Timeout for loading font "${t}"`)}const p={};let g="400,400italic,700,700italic";export function setGoogleFontsVariants(t){g=t}export function getGoogleFontsVariants(){return g}export function getGoogleFontsUrl(t){return`https://fonts.googleapis.com/css?family=${t.replace(/ /g,"+")}:${g}`}export function injectGoogleFont(t){if(p[t]){return}const n=getGoogleFontsUrl(t),o=document.createElement("link");o.type="text/css",o.href=n,o.rel="stylesheet",document.getElementsByTagName("head")[0].appendChild(o),p[t]=!0}const x={};let h;export function injectCustomFont(t){const n=t.fontFamily;if(x[n]){return}if(!t.url&&!t.styles){return}const o=t.styles||(t.url?[{src:`url("${t.url}")`}]:[]),e=(h||(h=document.getElementById("polotno-font-style"),h||(h=document.createElement("style"),h.id="polotno-font-style",document.head.appendChild(h)),h)).sheet;o.forEach(t=>{e.insertRule(`\n @font-face{\n font-family:'${n}';\n src:${t.src};\n font-style:${t.fontStyle||"normal"};\n font-weight:${t.fontWeight||"normal"};\n font-display:swap; /* optional but recommended */\n }`,e.cssRules.length)}),x[t.fontFamily]=!0}
@@ -1 +1 @@
1
- export const QUILL_FONT_CLASS_TO_FAMILY={"ql-font-serif":"Georgia, Times New Roman, serif","ql-font-monospace":"Monaco, Courier New, monospace","ql-font-sans":"system-ui, -apple-system, BlinkMacSystemFont, sans-serif"};export const QUILL_SIZE_CLASS_TO_EM={"ql-size-small":.75,"ql-size-large":1.5,"ql-size-huge":2.5};export function guessFontFamilyFromQlClass(t){return t.replace(/^ql-font-/,"").split("-").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}export function parsePrimaryFontFamily(t){return t.replace(/&quot;/g,'"').replace(/&amp;/g,"&").split(",")[0].trim().replace(/^["']|["']$/g,"")||null}export function parseFontSizeToPx(t,e){if(!t){return}const r=t.trim(),o=r.match(/^(\d+(?:\.\d+)?)px$/i);if(o){return parseFloat(o[1])}const n=r.match(/^(\d+(?:\.\d+)?)em$/i);if(n){return e*parseFloat(n[1])}const l=r.match(/^(\d+(?:\.\d+)?)rem$/i);return l?e*parseFloat(l[1]):void 0}export function parseHtmlRoot(t){return(new DOMParser).parseFromString(`<div id="polotno-rich-root">${t}</div>`,"text/html").getElementById("polotno-rich-root")}function t(t){for(const e of Array.from(t.classList)){if(e.startsWith("ql-indent-")){const t=parseInt(e.slice(10),10);if(t>0){return t}}}return 0}const e=new Set(["SPAN","STRONG","B","EM","I","U","S","DEL","SUB","SUP"]);function r(t,e){if(t.attributes.length!==e.attributes.length){return!1}for(const r of Array.from(t.attributes)){if(e.getAttribute(r.name)!==r.value){return!1}}return!0}export function cleanupInlineWrappers(t){const o=t=>{for(const e of Array.from(t.children)){o(e)}if(function(t){if("SPAN"!==t.tagName){return!1}for(const e of Array.from(t.attributes)){if(e.value.trim()){return!1}}return!0}(t)&&t.parentNode){const e=t.parentNode;for(;t.firstChild;){e.insertBefore(t.firstChild,t)}e.removeChild(t)}};for(const e of Array.from(t.children)){o(e)}const n=t=>{for(const e of Array.from(t.children)){n(e)}let o=t.firstElementChild;for(;o;){const t=o.nextElementSibling;if(t&&o.nextSibling===t&&e.has(o.tagName)&&o.tagName===t.tagName&&r(o,t)){for(;t.firstChild;){o.appendChild(t.firstChild)}t.remove(),n(o)}else{o=t}}};n(t)}export function normalizeRichTextHtml(e,r){var o;if(!e||!e.includes("<")){return e}const n=parseHtmlRoot(e);if(!n){return e}const l=t=>{for(const r of Array.from(t.children)){l(r)}const e=t.getAttribute("class");if(e){const o=e.split(/\s+/).filter(Boolean),n=[];for(const e of o){if(e.startsWith("ql-font-")){if(!t.style.fontFamily){const r=QUILL_FONT_CLASS_TO_FAMILY[e]||guessFontFamilyFromQlClass(e);t.style.fontFamily=r}continue}const o=QUILL_SIZE_CLASS_TO_EM[e];if(null==o){if(e.startsWith("ql-align-")){const r=e.slice(9);r&&!t.style.textAlign&&(t.style.textAlign=r);continue}if(e.startsWith("ql-indent-")){if("LI"===t.tagName){n.push(e);continue}const r=parseInt(e.slice(10),10);r>0&&!t.style.getPropertyValue("margin-inline-start")&&t.style.setProperty("margin-inline-start",.5*r+"em");continue}"ql-direction-rtl"!==e?n.push(e):t.style.direction||(t.style.direction="rtl")}else{t.style.fontSize||(t.style.fontSize=r.fontSize*o+"px")}}n.length?t.setAttribute("class",n.join(" ")):t.removeAttribute("class")}const o=t.style.fontSize;if(o){const e=parseFontSizeToPx(o,r.fontSize);null!=e&&(t.style.fontSize=`${e}px`)}};l(n),cleanupInlineWrappers(n),function(e){for(const t of Array.from(e.querySelectorAll("span.ql-ui"))){t.remove()}const r=e.ownerDocument,o=t=>{const e=t.children;for(let r=e.length-1;r>=0;r--){if("li"===e[r].tagName.toLowerCase()){return e[r]}}return null};for(const n of Array.from(e.querySelectorAll("ol, ul"))){const e=n.tagName.toLowerCase(),l=Array.from(n.children).filter(t=>"li"===t.tagName.toLowerCase());if(0===l.length){continue}if(!l.some(e=>e.hasAttribute("data-list")||t(e)>0)){continue}const i=t=>{const r=t.getAttribute("data-list");return"ordered"===r?"ol":"bullet"===r||"checked"===r||"unchecked"===r?"ul":"ol"===e?"ol":"ul"},s=r.createDocumentFragment(),a=[{list:s,level:-1,type:""}];for(const n of l){const e=t(n),l=i(n);n.removeAttribute("data-list");for(const t of Array.from(n.classList)){t.startsWith("ql-indent-")&&n.classList.remove(t)}for(n.getAttribute("class")||n.removeAttribute("class");a.length>1&&a[a.length-1].level>e;){a.pop()}if(a[a.length-1].level===e&&a[a.length-1].type!==l&&a.pop(),a[a.length-1].level<e){const t=a[a.length-1],n=o(t.list)||t.list,i=r.createElement(l);n.appendChild(i),a.push({list:i,level:e,type:l})}a[a.length-1].list.appendChild(n)}n.replaceWith(s)}for(const t of Array.from(e.querySelectorAll("ul, ol"))){const e=Array.from(t.children).filter(t=>"li"===t.tagName.toLowerCase());e.length>0&&e.every(t=>"rtl"===t.style.direction||"rtl"===t.getAttribute("dir"))&&"rtl"!==t.style.direction&&(t.style.direction="rtl")}}(n);for(const t of Array.from(n.querySelectorAll("p"))){let e=t,r="",n="",l="";for(;1===e.childNodes.length&&null!=e.firstChild&&1===e.firstChild.nodeType;){const t=e.firstChild;t.style.fontFamily&&(r=t.style.fontFamily),t.style.fontWeight&&(n=t.style.fontWeight),"STRONG"!==t.tagName&&"B"!==t.tagName||(n="bold"),"EM"!==t.tagName&&"I"!==t.tagName&&"italic"!==(null===(o=t.style)||void 0===o?void 0:o.fontStyle)||(l="italic"),e=t}r&&(t.style.fontFamily=r),n&&(t.style.fontWeight=n),l&&(t.style.fontStyle=l)}return n.innerHTML}export function shrinkParagraphStrutForRaster(t){var e;if(!t||!t.includes("<p")){return t}const r=parseHtmlRoot(t);if(!r){return t}for(const o of Array.from(r.querySelectorAll("p"))){let t=!1;const n=[],l=r.ownerDocument.createTreeWalker(o,NodeFilter.SHOW_TEXT);let i=l.nextNode();for(;i;){if((i.textContent||"").length>0){let r=i.parentElement,l=null;for(;r&&r!==o;){const t=null===(e=r.style)||void 0===e?void 0:e.fontSize;if(t){const e=parseFloat(t);if(!Number.isNaN(e)){l=e;break}}r=r.parentElement}if(null==l){t=!0;break}n.push(l)}i=l.nextNode()}!t&&n.length>0&&(o.style.fontSize=`${Math.min(...n)}px`)}return r.innerHTML}export function extractFontFamiliesFromHtml(t){const e=new Set;if(!t||!t.includes("<")){return[]}const r=parseHtmlRoot(t);if(r){const t=r.querySelectorAll("[style]");for(const r of t){if(r.style.fontFamily){const t=parsePrimaryFontFamily(r.style.fontFamily);t&&e.add(t)}}}for(const o of t.matchAll(/\bfont-family="([^"]+)"/g)){const t=parsePrimaryFontFamily(o[1]);t&&e.add(t)}for(const o of t.matchAll(/\bql-font-([a-z0-9_-]+)\b/gi)){const t=`ql-font-${o[1]}`,r=parsePrimaryFontFamily(QUILL_FONT_CLASS_TO_FAMILY[t]||guessFontFamilyFromQlClass(t));r&&e.add(r)}return[...e]}export function scaleRichTextFontSizesInHtml(t,e){if(!t||1===e||e<=0||!Number.isFinite(e)){return t}const r=parseHtmlRoot(t);if(!r){return t}const o=t=>{const r=t.style.fontSize;if(r){const o=r.match(/^(\d+(?:\.\d+)?)(px|em|rem)$/i);if(o){const r=Math.round(parseFloat(o[1])*e*1e3)/1e3;t.style.fontSize=`${r}${o[2].toLowerCase()}`}}for(const e of Array.from(t.children)){o(e)}};return o(r),r.innerHTML}const o={bold:["STRONG","B"],italic:["EM","I"],underline:["U"],strike:["S","DEL"]},n={bold:t=>t.style.removeProperty("font-weight"),italic:t=>t.style.removeProperty("font-style"),color:t=>t.style.removeProperty("color"),underline:t=>{const e=t.style.textDecoration.replace(/\bunderline\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},strike:t=>{const e=t.style.textDecoration.replace(/\bline-through\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")}};export function stripInlineFormat(t,e){var r;if(!t||!t.includes("<")){return t}const l=parseHtmlRoot(t);if(!l){return t}const i=o[e]||[],s=n[e];for(const o of i){let t;for(;t=l.querySelector(o);){const e=t.parentNode;for(;t.firstChild;){e.insertBefore(t.firstChild,t)}e.removeChild(t)}}if(s){for(const o of Array.from(l.querySelectorAll("[style]"))){s(o),(null===(r=o.getAttribute("style"))||void 0===r?void 0:r.trim())||o.removeAttribute("style")}}return cleanupInlineWrappers(l),l.innerHTML}const l=Symbol("unset");export function isQuillFormatMixed(t,e){var r;let o=l;for(const n of t.ops){if("string"!=typeof n.insert||"\n"===n.insert){continue}const t=null===(r=n.attributes)||void 0===r?void 0:r[e];if(o===l){o=t}else if(t!==o){return!0}}return!1}export function stripInlineFontSizes(t){var e;if(!t||!t.includes("font-size")){return t}const r=parseHtmlRoot(t);if(!r){return t}const o=r.querySelectorAll("[style]");for(let n=0;n<o.length;n++){const t=o[n];t.style.fontSize&&(t.style.removeProperty("font-size"),(null===(e=t.getAttribute("style"))||void 0===e?void 0:e.trim())||t.removeAttribute("style"))}return cleanupInlineWrappers(r),r.innerHTML}export function stripInlineFontFamilies(t){var e;if(!t||!t.includes("font-family")&&!t.includes("ql-font-")){return t}const r=parseHtmlRoot(t);if(!r){return t}for(const o of Array.from(r.querySelectorAll("[style]"))){o.style.fontFamily&&(o.style.removeProperty("font-family"),(null===(e=o.getAttribute("style"))||void 0===e?void 0:e.trim())||o.removeAttribute("style"))}for(const o of Array.from(r.querySelectorAll("[class]"))){const t=o.getAttribute("class")||"",e=t.split(/\s+/).filter(t=>t&&!t.startsWith("ql-font-"));e.length!==t.split(/\s+/).filter(Boolean).length&&(e.length?o.setAttribute("class",e.join(" ")):o.removeAttribute("class"))}return cleanupInlineWrappers(r),r.innerHTML}export function hasMultipleDistinctInlineFontSizes(t){if(!t||!t.includes("<")){return!1}const e=parseHtmlRoot(t);if(!e){return!1}const r=new Set;for(const o of e.querySelectorAll("[style]")){const t=o.style.fontSize;if(t){const e=t.match(/^(\d+(?:\.\d+)?)px$/i);if(e&&(r.add(parseFloat(e[1])),r.size>1)){return!0}}}return!1}export function hasAnyInlineFontSize(t){if(!t||!t.includes("<")){return!1}const e=parseHtmlRoot(t);if(!e){return!1}for(const r of e.querySelectorAll("[style]")){if(r.style.fontSize){return!0}}return!1}export function listEffectiveFontFamilies(t,e){const r=[],o=e?parsePrimaryFontFamily(e)||e:"";o&&r.push(o);for(const i of extractFontFamiliesFromHtml(t||"")){const t=parsePrimaryFontFamily(i)||i;t&&r.push(t)}const n=new Set,l=[];for(const i of r){n.has(i)||(n.add(i),l.push(i))}return l.sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})),l}
1
+ export const QUILL_FONT_CLASS_TO_FAMILY={"ql-font-serif":"Georgia, Times New Roman, serif","ql-font-monospace":"Monaco, Courier New, monospace","ql-font-sans":"system-ui, -apple-system, BlinkMacSystemFont, sans-serif"};export const QUILL_SIZE_CLASS_TO_EM={"ql-size-small":.75,"ql-size-large":1.5,"ql-size-huge":2.5};export function guessFontFamilyFromQlClass(t){return t.replace(/^ql-font-/,"").split("-").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" ")}export function parsePrimaryFontFamily(t){return t.replace(/&quot;/g,'"').replace(/&amp;/g,"&").split(",")[0].trim().replace(/^["']|["']$/g,"")||null}export function parseFontSizeToPx(t,e){if(!t){return}const r=t.trim(),o=r.match(/^(\d+(?:\.\d+)?)px$/i);if(o){return parseFloat(o[1])}const n=r.match(/^(\d+(?:\.\d+)?)em$/i);if(n){return e*parseFloat(n[1])}const l=r.match(/^(\d+(?:\.\d+)?)rem$/i);return l?e*parseFloat(l[1]):void 0}export function parseHtmlRoot(t){return(new DOMParser).parseFromString(`<div id="polotno-rich-root">${t}</div>`,"text/html").getElementById("polotno-rich-root")}function t(t){for(const e of Array.from(t.classList)){if(e.startsWith("ql-indent-")){const t=parseInt(e.slice(10),10);if(t>0){return t}}}return 0}const e=new Set(["SPAN","STRONG","B","EM","I","U","S","DEL","SUB","SUP"]);function r(t,e){if(t.attributes.length!==e.attributes.length){return!1}for(const r of Array.from(t.attributes)){if(e.getAttribute(r.name)!==r.value){return!1}}return!0}export function cleanupInlineWrappers(t){const o=t=>{for(const e of Array.from(t.children)){o(e)}if(function(t){if("SPAN"!==t.tagName){return!1}for(const e of Array.from(t.attributes)){if(e.value.trim()){return!1}}return!0}(t)&&t.parentNode){const e=t.parentNode;for(;t.firstChild;){e.insertBefore(t.firstChild,t)}e.removeChild(t)}};for(const e of Array.from(t.children)){o(e)}const n=t=>{for(const e of Array.from(t.children)){n(e)}let o=t.firstElementChild;for(;o;){const t=o.nextElementSibling;if(t&&o.nextSibling===t&&e.has(o.tagName)&&o.tagName===t.tagName&&r(o,t)){for(;t.firstChild;){o.appendChild(t.firstChild)}t.remove(),n(o)}else{o=t}}};n(t)}export function normalizeRichTextHtml(e,r){var o;if(!e||!e.includes("<")){return e}const n=parseHtmlRoot(e);if(!n){return e}const l=t=>{for(const r of Array.from(t.children)){l(r)}const e=t.getAttribute("class");if(e){const o=e.split(/\s+/).filter(Boolean),n=[];for(const e of o){if(e.startsWith("ql-font-")){if(!t.style.fontFamily){const r=QUILL_FONT_CLASS_TO_FAMILY[e]||guessFontFamilyFromQlClass(e);t.style.fontFamily=r}continue}const o=QUILL_SIZE_CLASS_TO_EM[e];if(null==o){if(!e.startsWith("ql-align-")){if(e.startsWith("ql-indent-")){if("LI"===t.tagName){n.push(e);continue}const r=parseInt(e.slice(10),10);r>0&&!t.style.getPropertyValue("margin-inline-start")&&t.style.setProperty("margin-inline-start",.5*r+"em");continue}"ql-direction-rtl"!==e?n.push(e):t.style.direction||(t.style.direction="rtl")}}else{t.style.fontSize||(t.style.fontSize=r.fontSize*o+"px")}}n.length?t.setAttribute("class",n.join(" ")):t.removeAttribute("class")}const o=t.style.fontSize;if(o){const e=parseFontSizeToPx(o,r.fontSize);null!=e&&(t.style.fontSize=`${e}px`)}};l(n),cleanupInlineWrappers(n),function(e){for(const t of Array.from(e.querySelectorAll("span.ql-ui"))){t.remove()}const r=e.ownerDocument,o=t=>{const e=t.children;for(let r=e.length-1;r>=0;r--){if("li"===e[r].tagName.toLowerCase()){return e[r]}}return null};for(const n of Array.from(e.querySelectorAll("ol, ul"))){const e=n.tagName.toLowerCase(),l=Array.from(n.children).filter(t=>"li"===t.tagName.toLowerCase());if(0===l.length){continue}if(!l.some(e=>e.hasAttribute("data-list")||t(e)>0)){continue}const i=t=>{const r=t.getAttribute("data-list");return"ordered"===r?"ol":"bullet"===r||"checked"===r||"unchecked"===r?"ul":"ol"===e?"ol":"ul"},s=r.createDocumentFragment(),a=[{list:s,level:-1,type:""}];for(const n of l){const e=t(n),l=i(n);n.removeAttribute("data-list");for(const t of Array.from(n.classList)){t.startsWith("ql-indent-")&&n.classList.remove(t)}for(n.getAttribute("class")||n.removeAttribute("class");a.length>1&&a[a.length-1].level>e;){a.pop()}if(a[a.length-1].level===e&&a[a.length-1].type!==l&&a.pop(),a[a.length-1].level<e){const t=a[a.length-1],n=o(t.list)||t.list,i=r.createElement(l);n.appendChild(i),a.push({list:i,level:e,type:l})}a[a.length-1].list.appendChild(n)}n.replaceWith(s)}for(const t of Array.from(e.querySelectorAll("ul, ol"))){const e=Array.from(t.children).filter(t=>"li"===t.tagName.toLowerCase());e.length>0&&e.every(t=>"rtl"===t.style.direction||"rtl"===t.getAttribute("dir"))&&"rtl"!==t.style.direction&&(t.style.direction="rtl")}}(n);for(const t of Array.from(n.querySelectorAll("p"))){let e=t,r="",n="",l="";for(;1===e.childNodes.length&&null!=e.firstChild&&1===e.firstChild.nodeType;){const t=e.firstChild;t.style.fontFamily&&(r=t.style.fontFamily),t.style.fontWeight&&(n=t.style.fontWeight),"STRONG"!==t.tagName&&"B"!==t.tagName||(n="bold"),"EM"!==t.tagName&&"I"!==t.tagName&&"italic"!==(null===(o=t.style)||void 0===o?void 0:o.fontStyle)||(l="italic"),e=t}r&&(t.style.fontFamily=r),n&&(t.style.fontWeight=n),l&&(t.style.fontStyle=l)}return n.innerHTML}export function shrinkParagraphStrutForRaster(t){var e;if(!t||!t.includes("<p")){return t}const r=parseHtmlRoot(t);if(!r){return t}for(const o of Array.from(r.querySelectorAll("p"))){let t=!1;const n=[],l=r.ownerDocument.createTreeWalker(o,NodeFilter.SHOW_TEXT);let i=l.nextNode();for(;i;){if((i.textContent||"").length>0){let r=i.parentElement,l=null;for(;r&&r!==o;){const t=null===(e=r.style)||void 0===e?void 0:e.fontSize;if(t){const e=parseFloat(t);if(!Number.isNaN(e)){l=e;break}}r=r.parentElement}if(null==l){t=!0;break}n.push(l)}i=l.nextNode()}!t&&n.length>0&&(o.style.fontSize=`${Math.min(...n)}px`)}return r.innerHTML}export function extractFontFamiliesFromHtml(t){const e=new Set;if(!t||!t.includes("<")){return[]}const r=parseHtmlRoot(t);if(r){const t=r.querySelectorAll("[style]");for(const r of t){if(r.style.fontFamily){const t=parsePrimaryFontFamily(r.style.fontFamily);t&&e.add(t)}}}for(const o of t.matchAll(/\bfont-family="([^"]+)"/g)){const t=parsePrimaryFontFamily(o[1]);t&&e.add(t)}for(const o of t.matchAll(/\bql-font-([a-z0-9_-]+)\b/gi)){const t=`ql-font-${o[1]}`,r=parsePrimaryFontFamily(QUILL_FONT_CLASS_TO_FAMILY[t]||guessFontFamilyFromQlClass(t));r&&e.add(r)}return[...e]}export function scaleRichTextFontSizesInHtml(t,e){if(!t||1===e||e<=0||!Number.isFinite(e)){return t}const r=parseHtmlRoot(t);if(!r){return t}const o=t=>{const r=t.style.fontSize;if(r){const o=r.match(/^(\d+(?:\.\d+)?)(px|em|rem)$/i);if(o){const r=Math.round(parseFloat(o[1])*e*1e3)/1e3;t.style.fontSize=`${r}${o[2].toLowerCase()}`}}for(const e of Array.from(t.children)){o(e)}};return o(r),r.innerHTML}const o={bold:["STRONG","B"],italic:["EM","I"],underline:["U"],strike:["S","DEL"]},n={bold:t=>t.style.removeProperty("font-weight"),italic:t=>t.style.removeProperty("font-style"),color:t=>t.style.removeProperty("color"),underline:t=>{const e=t.style.textDecoration.replace(/\bunderline\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},strike:t=>{const e=t.style.textDecoration.replace(/\bline-through\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")}};export function stripInlineFormat(t,e){var r;if(!t||!t.includes("<")){return t}const l=parseHtmlRoot(t);if(!l){return t}const i=o[e]||[],s=n[e];for(const o of i){let t;for(;t=l.querySelector(o);){const e=t.parentNode;for(;t.firstChild;){e.insertBefore(t.firstChild,t)}e.removeChild(t)}}if(s){for(const o of Array.from(l.querySelectorAll("[style]"))){s(o),(null===(r=o.getAttribute("style"))||void 0===r?void 0:r.trim())||o.removeAttribute("style")}}return cleanupInlineWrappers(l),l.innerHTML}const l=Symbol("unset");export function isQuillFormatMixed(t,e){var r;let o=l;for(const n of t.ops){if("string"!=typeof n.insert||"\n"===n.insert){continue}const t=null===(r=n.attributes)||void 0===r?void 0:r[e];if(o===l){o=t}else if(t!==o){return!0}}return!1}export function stripInlineFontSizes(t){var e;if(!t||!t.includes("font-size")){return t}const r=parseHtmlRoot(t);if(!r){return t}const o=r.querySelectorAll("[style]");for(let n=0;n<o.length;n++){const t=o[n];t.style.fontSize&&(t.style.removeProperty("font-size"),(null===(e=t.getAttribute("style"))||void 0===e?void 0:e.trim())||t.removeAttribute("style"))}return cleanupInlineWrappers(r),r.innerHTML}export function stripInlineFontFamilies(t){var e;if(!t||!t.includes("font-family")&&!t.includes("ql-font-")){return t}const r=parseHtmlRoot(t);if(!r){return t}for(const o of Array.from(r.querySelectorAll("[style]"))){o.style.fontFamily&&(o.style.removeProperty("font-family"),(null===(e=o.getAttribute("style"))||void 0===e?void 0:e.trim())||o.removeAttribute("style"))}for(const o of Array.from(r.querySelectorAll("[class]"))){const t=o.getAttribute("class")||"",e=t.split(/\s+/).filter(t=>t&&!t.startsWith("ql-font-"));e.length!==t.split(/\s+/).filter(Boolean).length&&(e.length?o.setAttribute("class",e.join(" ")):o.removeAttribute("class"))}return cleanupInlineWrappers(r),r.innerHTML}export function hasMultipleDistinctInlineFontSizes(t){if(!t||!t.includes("<")){return!1}const e=parseHtmlRoot(t);if(!e){return!1}const r=new Set;for(const o of e.querySelectorAll("[style]")){const t=o.style.fontSize;if(t){const e=t.match(/^(\d+(?:\.\d+)?)px$/i);if(e&&(r.add(parseFloat(e[1])),r.size>1)){return!0}}}return!1}export function hasAnyInlineFontSize(t){if(!t||!t.includes("<")){return!1}const e=parseHtmlRoot(t);if(!e){return!1}for(const r of e.querySelectorAll("[style]")){if(r.style.fontSize){return!0}}return!1}export function listEffectiveFontFamilies(t,e){const r=[],o=e?parsePrimaryFontFamily(e)||e:"";o&&r.push(o);for(const i of extractFontFamiliesFromHtml(t||"")){const t=parsePrimaryFontFamily(i)||i;t&&r.push(t)}const n=new Set,l=[];for(const i of r){n.has(i)||(n.add(i),l.push(i))}return l.sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})),l}
@@ -1 +1 @@
1
- import*as e from"mobx";import{getAPI as o}from"./api.js";import{setRemoveBackgroundEnabled as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const p=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let u=fetch;export const __=e=>{u=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await u(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"4.0.0-beta.47"})});if(e.runInAction(()=>{a.value=r.headers.get("x-api-version")||""}),!n){return console.error("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1}),!1}if(200!==r.status){await new Promise(e=>setTimeout(e,3e3));continue}const s=await r.json();return s.is_valid||(console.error("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1})),s.is_paid||(console.log("%cPolotno Free Version. For development usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{0===i.value&&(i.value=2)})),s.is_domain_valid||console.log(p,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),t(s.remove_background_enabled),s.is_paid||!1}catch(r){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e,o){s=e,await isKeyPaid(e)&&!o||r()}
1
+ import*as e from"mobx";import{getAPI as o}from"./api.js";import{setRemoveBackgroundEnabled as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const p=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let u=fetch;export const __=e=>{u=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await u(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"4.0.0-beta.48"})});if(e.runInAction(()=>{a.value=r.headers.get("x-api-version")||""}),!n){return console.error("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1}),!1}if(200!==r.status){await new Promise(e=>setTimeout(e,3e3));continue}const s=await r.json();return s.is_valid||(console.error("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1})),s.is_paid||(console.log("%cPolotno Free Version. For development usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{0===i.value&&(i.value=2)})),s.is_domain_valid||console.log(p,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),t(s.remove_background_enabled),s.is_paid||!1}catch(r){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e,o){s=e,await isKeyPaid(e)&&!o||r()}