polotno 4.0.0-beta.46 → 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 +2 -2
- package/polotno.bundle.js +3 -3
- package/utils/fonts.js +1 -1
- package/utils/rich-text-html.js +1 -1
- package/utils/validate-key.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.48",
|
|
4
4
|
"description": "Design Editor Framework",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"keywords": [
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"react-konva-utils": "^2.0.0",
|
|
115
115
|
"react-sortablejs": "6.1.4",
|
|
116
116
|
"react-window": "^1.8.11",
|
|
117
|
-
"render-tag": "^0.1.
|
|
117
|
+
"render-tag": "^0.1.15",
|
|
118
118
|
"sortablejs": "^1.15.7",
|
|
119
119
|
"svg-round-corners": "^0.4.3",
|
|
120
120
|
"swr": "^2.4.1",
|
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(/"/g,`"`).replace(/&/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(/"/g,`"`).replace(/&/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(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`).replace(/ /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,`<`),e=e.replace(/([^a-z0-9"'\s/])>/gi,`$1>`),e):e.replace(/</g,`<`).replace(/>/g,`>`):``}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,`<`),e=e.replace(/([^a-z0-9"'\s/])>/gi,`$1>`),e):e.replace(/</g,`<`).replace(/>/g,`>`):``}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};
|
|
@@ -510,7 +510,7 @@ https://polotno.com/docs/server-api`,n_={unsplashList:({query:e,page:t=1})=>`${Q
|
|
|
510
510
|
`);for(let t=0;t<a.length;t++)if(t>0&&n.push({text:`
|
|
511
511
|
`,width:0,style:r.style,isSpace:!1,boxStyle:r.boxStyle}),a[t]){let o=n.length;oM(e,a[t],r,n),i(o)}}else{let a=n.length;oM(e,t,r,n),i(a)}}return n}function cM(e){let t=e.codePointAt(0)||0;return t>=19968&&t<=40959||t>=13312&&t<=19903||t>=12288&&t<=12351||t>=12352&&t<=12447||t>=12448&&t<=12543||t>=44032&&t<=55215||t>=65280&&t<=65519||t>=131072&&t<=173791}var lM;function uM(){return lM||(typeof Intl<`u`&&Intl.Segmenter?(lM=new Intl.Segmenter(void 0,{granularity:`grapheme`}),lM):null)}var dM=/\p{Extended_Pictographic}/u;function fM(e){for(let t of e)if(t.codePointAt(0)>=126976)return!0;return e.includes(``)||e.includes(`️`)?dM.test(e):!1}function pM(e,t,n,r){let i=[...t.text].some(cM),a=dM.test(t.text)&&!!uM(),o=t.width>n&&(t.style.overflowWrap===`break-word`||t.style.wordBreak===`break-all`);if(!i&&!a&&!o)return[t];if(o&&t.style.wordBreak!==`break-all`&&t.style.overflowWrap===`break-word`){let r=t.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/).filter(e=>e.length);if(r.length>1){e.font=Fj(t.style),e.letterSpacing=Nj(t.style.letterSpacing);let i=[];for(let a of r){let r=jj(e,a);r<=n?i.push({...t,text:a,width:r}):i.push(...pM(e,{...t,text:a,width:r},n,0))}return i}}e.font=Fj(t.style),e.letterSpacing=Nj(t.style.letterSpacing);let s=a?uM():null,c=s?[...s.segment(t.text)].map(e=>e.segment):[...t.text],l=[],u=``,d=0;for(let r of c){if(a&&fM(r)){u&&(l.push({...t,text:u,width:d}),u=``,d=0),l.push({...t,text:r,width:jj(e,r)});continue}if(cM(r)){u&&(l.push({...t,text:u,width:d}),u=``,d=0);let n=jj(e,r);l.push({...t,text:r,width:n});continue}let i=u+r,s=jj(e,i);if(o&&s>n&&u){l.push({...t,text:u,width:d}),u=r,d=jj(e,r);continue}u=i,d=s}return u&&l.push({...t,text:u,width:d}),l}var mM=/^[,.\;:!?\)\]\}'"»›]+$/;function hM(e,t,n,r,i=!1,a=0){let o=[],s={words:[],totalWidth:0,lineHeight:0},c=r===`nowrap`||r===`pre`,l=()=>n-(o.length===0?a:0),u=r===`pre-wrap`||r===`pre`||r===`pre-line`,d=r===`pre`||r===`pre-wrap`||r===`break-spaces`;function f(t=!1){let i=s.words.length>0;if(!(r===`break-spaces`||d&&!t))for(;s.words.length>0&&s.words[s.words.length-1].isSpace;)s.totalWidth-=s.words[s.words.length-1].width,s.words.pop();if(t&&s.words.length>0){let t=s.words[s.words.length-1];if(t.isSoftHyphenBreak){Mj(e,t.style);let n=jj(e,`-`);s.words.push({text:`-`,width:n,style:t.style,isSpace:!1}),s.totalWidth+=n}}if(s.words.length>0||i&&u){if(Oj){let e=s.words.map(e=>e.text).join(``);Oj({type:`line-commit`,message:`Line ${o.length}: "${e}" width=${s.totalWidth.toFixed(2)} / ${n}`,data:{lineIndex:o.length,text:e,totalWidth:s.totalWidth,contentWidth:n}})}o.push(s)}s={words:[],totalWidth:0,lineHeight:0}}let p=!0;for(let r=0;r<t.length;r++){let a=t[r],u=Hj(e,a.style,i);if(a.boxStyle&&a.boxStyle.display===`inline-block`){let e=a.boxStyle;u=Math.max(u,u+e.paddingTop+e.paddingBottom+e.marginTop+e.marginBottom+e.borderTopWidth+e.borderBottomWidth)}if(a.text===`
|
|
512
512
|
`){s.words.length===0?(s.lineHeight=u,s.endedByHardBreak=!0,o.push(s),s={words:[],totalWidth:0,lineHeight:0}):(s.endedByHardBreak=!0,f()),p=!0;continue}if(c){s.words.push(a),s.totalWidth+=a.width,s.lineHeight=Math.max(s.lineHeight,u);continue}if(!a.isSpace&&a.text&&!a.noBreakBefore&&!a.boxOpen&&!a.boxClose){let n=r;for(;n+1<t.length;){let e=t[n+1];if(!e.text||e.isSpace||e.boxOpen||e.boxClose||!e.noBreakBefore)break;n++}if(n>r){let o=a.style.overflowWrap===`break-word`||a.style.wordBreak===`break-all`,c=0;for(let e=r;e<=n;e++)c+=t[e].width;let u=[];for(let e=r;e<=n;e++)for(let n of[...t[e].text])u.push({ch:n,style:t[e].style});let d=u.map(e=>e.ch).join(``).split(/(?<=-)(?!\d)|(?<=[^\d]-)/).filter(e=>e.length),m=d.length>1;if(!(s.totalWidth+c<=l())&&(m||o&&c>l())){let t=[],a=0;for(let e of d){let n=[...e].length;t.push(u.slice(a,a+n)),a+=n}let c=(t,n)=>{let r=0;for(;r<t.length;){let a=t[r].style;Mj(e,a),e.letterSpacing=Nj(a.letterSpacing);let o=Hj(e,a,i),c=``,u=0;for(;r<t.length&&t[r].style===a;){let i=t[r].ch,d=jj(e,c+i);n&&s.totalWidth+d>l()&&(s.words.length>0||c)?(c&&(s.words.push({text:c,width:u,style:a,isSpace:!1}),s.totalWidth+=u,s.lineHeight=Math.max(s.lineHeight,o)),f(!0),p=!1,c=i,u=jj(e,i)):(c+=i,u=d),r++}c&&(s.words.push({text:c,width:u,style:a,isSpace:!1}),s.totalWidth+=u,s.lineHeight=Math.max(s.lineHeight,o),p=!1)}},h=t=>{let n=0,r=0;for(;r<t.length;){let i=t[r].style,a=``;for(;r<t.length&&t[r].style===i;)a+=t[r].ch,r++;Mj(e,i),e.letterSpacing=Nj(i.letterSpacing),n+=jj(e,a)}return n};!m&&s.words.length>0&&(f(!0),p=!1);for(let e of t){let t=h(e);s.words.length>0&&s.totalWidth+t>l()&&(f(!0),p=!1),c(e,o&&t>l())}r=n;continue}}}let m=!a.isSpace&&a.text.length>1?pM(e,a,l(),s.totalWidth):[a],h=0;for(let e=r+1;e<t.length;e++){let n=t[e];if(n.isSpace||n.text===`
|
|
513
|
-
`)break;let r=!!n.text&&mM.test(n.text),i=!n.text&&!!n.boxClose,a=!!n.text&&!!n.noBreakBefore;if(r||i||a){h+=n.width;continue}break}for(let i of m){let a=i===m[m.length-1]?h:0,o=!i.isSpace&&i.text.length>0&&mM.test(i.text)&&s.words.length>0&&!s.words[s.words.length-1].isSpace,c=i===m[0]&&i.noBreakBefore&&s.words.length>0&&!s.words[s.words.length-1].isSpace,g=0;if(!i.text&&i.boxOpen){let n=t[r+1];n&&!n.isSpace&&n.text&&(g=(n.text.length>1?pM(e,n,l(),0):[n])[0].width)}let _=0;if(i.isSoftHyphenBreak&&(Mj(e,i.style),e.letterSpacing=Nj(i.style.letterSpacing),_=jj(e,`-`)),!i.isSpace&&!o&&!c&&s.words.length>0&&s.totalWidth+i.width+_+a+g>l()){let t=s.totalWidth+i.width+_+a+g-l(),r=!0;if(t<1&&!dse([...s.words,i])){Mj(e,i.style);let t=s.words.map(e=>e.text).join(``)+i.text+(i.isSoftHyphenBreak?`-`:``),n=0;for(let e of s.words)e.text||(n+=e.width);i.text||(n+=i.width),jj(e,t)+n+a+g<=l()+.02&&(r=!1)}if(r&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){Mj(e,i.style);let n=``,r=0,a=0,o=l()-s.totalWidth;for(;a<t.length;a++){let i=n+t[a],s=jj(e,i);if(s>o)break;n=i,r=s}if(a>0&&a<t.length){s.words.push({...i,text:n,width:r}),s.totalWidth+=r,s.lineHeight=Math.max(s.lineHeight,u),f(!0),p=!1;let o=t.slice(a).join(``),c=jj(e,o);s.words.push({...i,text:o,width:c}),s.totalWidth+=c,s.lineHeight=Math.max(s.lineHeight,u);continue}}}if(r){if(Oj){let e=s.words.map(e=>e.text).join(``);Oj({type:`line-wrap`,message:`"${i.text}" overflow=${t.toFixed(2)} wrap=true lineWidth=${s.totalWidth.toFixed(2)} pieceWidth=${i.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:i.text,overflow:t,lineWidth:s.totalWidth,pieceWidth:i.width,contentWidth:n,lineText:e}})}f(!0),p=!1}}if(i.isSpace&&s.words.length===0&&(!p||!d))continue;let v=i.width;if(i.isTab){let e=i.width,t=s.totalWidth;v=Math.ceil((t+.1)/e)*e-t,i.width=v}if(s.words.length===0&&v>l()&&!i.isSpace&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){Mj(e,i.style);let n=t.filter(e=>e).map(t=>({...i,text:t,width:jj(e,t)})),r=!0;for(let e of n)r?(r=!1,s.words.push(e),s.totalWidth+=e.width,s.lineHeight=Math.max(s.lineHeight,u)):s.totalWidth+e.width>l()?(f(!0),p=!1,s.words.push(e),s.totalWidth+=e.width,s.lineHeight=Math.max(s.lineHeight,u)):(s.words.push(e),s.totalWidth+=e.width,s.lineHeight=Math.max(s.lineHeight,u));continue}}s.words.push(i),s.totalWidth+=v,s.lineHeight=Math.max(s.lineHeight,u),i.isSpace||(p=!1)}}return f(),o}function gM(e,t,n,r,i,a=!1){let o=[],s=nM(t);if(s.length===0)return{nodes:o,height:0};let c=sM(e,s),l=t.style.textIndent||0,u=hM(e,c,i,t.style.whiteSpace,a,l),d=t.style.lineClamp;if(d>0&&u.length>d){u.length=d;let t=u[d-1];tM(e,t,i-(d===1?l:0)),t.endedByHardBreak=!0}let f=t.style.direction===`rtl`,p=e=>e===`start`?f?`right`:`left`:e===`end`?f?`left`:`right`:e,m=p(t.style.textAlign),h=t.style.textAlignLast||`auto`;h=h===`auto`?t.style.textAlign===`justify`?f?`right`:`left`:m:p(h);let g=r;for(let t=0;t<u.length;t++){let r=u[t];if(r.words.length===0){g+=r.lineHeight;continue}let a=r.lineHeight,s=t===u.length-1,c=t===0,d=s||r.endedByHardBreak?h:m,p=c?l:0,_=i-p,v=0;if(d===`justify`&&r.totalWidth<_){let e=r.words.filter(e=>e.isSpace).length;e>0&&(v=(_-r.totalWidth)/e)}let y=r.totalWidth>_+.5,b=n+p;y?b=f?n+_-r.totalWidth:n+p:d===`center`?b=n+p+(_-r.totalWidth)/2:d===`right`?b=(f?n+_:n+p+_)-r.totalWidth:d===`justify`&&f&&(b=n+_-r.totalWidth);let x=b,S=0,C=0;for(let t of r.words){if(t.text===``||Zj(t.style.verticalAlign))continue;let{ascent:n,descent:r}=Yj(e,t.style);n>S&&(S=n),r>C&&(C=r)}if(S===0)for(let t of r.words){if(t.text===``)continue;let{ascent:n,descent:r}=Yj(e,t.style);S=n,C=r;break}let w=S+C,T=g+(a-w)/2+S,E=r.words.filter(e=>e.text!==``&&!Zj(e.style.verticalAlign)),D=E.length>0?Math.max(...E.map(e=>e.style.fontSize)):0,O=g,k=g+a;for(let t of r.words){if(t.text===``)continue;let n=t.style.verticalAlign;if(!Zj(n))continue;if(D===0)break;let{ascent:r,descent:i}=Yj(e,t.style),o=T+Xj(n,r,i,D,S,C,a),s=o-r,c=o+i;s<O&&(O=s),c>k&&(k=c)}let A=k-O,j=(t,n,r)=>{let{ascent:i,descent:a}=Yj(e,t),s=t.paddingTop+t.borderTopWidth,c=t.paddingBottom+t.borderBottomWidth,l=i+a+s+c,u;u=t.display===`inline-block`?g+t.marginTop:T-i-s,o.push({type:`box`,style:t,x:n,y:u,width:r,height:l,tagName:`span`,children:[]})};if(!f){let e=b,t=e,n,i=!1;for(let a of r.words){if(a.boxOpen&&a.boxClose&&a.text){n&&(i&&j(n,t,e-t),n=void 0,i=!1);let r=a.style,o=a.width-r.marginLeft-r.borderLeftWidth-r.paddingLeft-r.paddingRight-r.borderRightWidth-r.marginRight;j(r,e+r.marginLeft,r.borderLeftWidth+r.paddingLeft+o+r.paddingRight+r.borderRightWidth),i=!1,e+=a.width;continue}a.boxStyle!==n&&(n&&i&&j(n,t,e-t),n=a.boxStyle,t=e,i=!1),a.text&&!a.isSpace&&(i=!0),e+=a.width+(a.isSpace?v:0)}n&&i&&j(n,t,e-t)}let M=r.words.filter(e=>e.text!==``),ee=M.length>0&&M.every(e=>Qj(e.style,M[0].style));if(f){let t=[],n=null,i=0;for(let e of r.words){if(e.text===``){n&&=(t.push(n),null),i+=e.width;continue}if(e.isSpace&&v>0){n&&=(t.push(n),null),i+=e.width+v;continue}n&&Qj(n.style,e.style)?(n.text+=e.text,n.width+=e.width):(n&&t.push(n),n={text:e.text,style:e.style,width:e.width,boxStyle:e.boxStyle,x:0,padBefore:i},i=0)}n&&t.push(n);let a=b+r.totalWidth;for(let n of t){a-=n.padBefore,Mj(e,n.style);let t=jj(e,n.text);a-=t,n.x=a,n.width=t}for(let e of t)if(e.boxStyle&&$j(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;j(t,e.x-n,e.width+n+r)}for(let e of t)o.push({type:`text`,text:e.text,x:e.x+e.width,y:T,width:e.width,style:{...e.style,direction:`rtl`}})}else{let t=r.words.map(e=>e.text).join(``);if(ee&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!r.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){Mj(e,M[0].style);let n=jj(e,t);o.push({type:`text`,text:t,x:b,y:T,width:n,style:{...M[0].style,direction:`ltr`}})}else for(let t of r.words){if(t.text===``){b+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=b+n.marginLeft+n.borderLeftWidth+n.paddingLeft;o.push({type:`text`,text:t.text,x:r,y:T,width:jj(e,t.text),style:t.style}),b+=t.width;continue}let n=T,r=t.style.verticalAlign;if(Zj(r)){let i=D||t.style.fontSize,{ascent:o,descent:s}=Yj(e,t.style);n+=Xj(r,o,s,i,S,C,a)}let i=t.width+(t.isSpace?v:0);o.push({type:`text`,text:t.text,x:b,y:n,width:i,style:t.style}),b+=i}}let N=d===`justify`&&v>0?_:r.totalWidth;kj.push({y:Math.round(T),text:r.words.map(e=>e.text).join(``),bounds:{x,y:O,width:N,height:A}}),g+=A}return{nodes:o,height:g-r}}function _M(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function vM(e,t,n,r,i){let a=t.style,o=a.marginLeft,s=a.marginRight,c=a.borderLeftWidth,l=a.borderRightWidth,u=a.borderTopWidth,d=a.borderBottomWidth,f=a.paddingLeft,p=a.paddingRight,m=a.paddingTop,h=a.paddingBottom,g=n+o,_=a.width>0?a.width:i-o-s,v=g+c+f,y=Math.max(0,_-c-l-f-p),b=r,x=b+u+m,S={type:`box`,style:a,x:g,y:b,width:_,height:0,tagName:t.tagName,children:[],listMarker:t.listMarker};if(a.display===`flex`){let n=bM(e,t,v,x,y);return S.children=n.children,S.height=u+m+n.height+h+d,{box:S,height:S.height,marginBottomOut:a.marginBottom}}if(a.display===`table`){let n=yM(e,t,v,x,y);return S.children=n.children,S.height=u+m+n.height+h+d,{box:S,height:S.height,marginBottomOut:a.marginBottom}}if(t.children.length===0)return S.height=u+m+h+d,a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:a.marginBottom};if(Kj(t)){let{nodes:n,height:r}=gM(e,t,v,x,y,t.tagName===`li`&&Bj.has(a.listStyleType));S.children=n,S.height=u+m+r+h+d}else{let n=x,r=0,i=!1,o=t.tagName===`li`||t.tagName===`ul`||t.tagName===`ol`||t.tagName===`dd`||t.tagName===`dt`;for(let s=0;s<t.children.length;s++){let c=t.children[s];if(c.tagName===`#text`||Gj(c)){let o=[c];for(;s+1<t.children.length;){let e=t.children[s+1];if(e.tagName===`#text`||Gj(e))o.push(e),s++;else break}r>0&&(n+=r,r=0);let l={element:null,tagName:`div`,style:{...t.style,display:`block`,marginTop:0,marginBottom:0,paddingTop:0,paddingBottom:0,borderTopWidth:0,borderBottomWidth:0},children:o,textContent:null},u=t.tagName===`li`&&Bj.has(a.listStyleType),{nodes:d,height:f}=gM(e,l,v,n,y,u);S.children.push(...d),n+=f,r=0,i=!0;continue}let l=c.style.marginTop;if(!(!i&&m===0&&u===0&&o)){let e=_M(r,l);n+=e}let{box:d,height:f,marginBottomOut:p}=vM(e,c,v,n,y);S.children.push(d),n+=f,r=p,i=!0}let s=a.marginBottom,c=h===0&&d===0&&o;c&&r>0&&(s=Math.max(a.marginBottom,r));let l=n-x;return!c&&r>0&&(l+=r),S.height=u+m+l+h+d,a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:s}}return a.minHeight>0&&(S.height=Math.max(S.height,a.minHeight)),{box:S,height:S.height,marginBottomOut:a.marginBottom}}function yM(e,t,n,r,i){let a=[],o=[];for(let e of t.children)if(e.tagName===`tr`)o.push(e);else if([`thead`,`tbody`,`tfoot`].includes(e.tagName))for(let t of e.children)t.tagName===`tr`&&o.push(t);if(o.length===0)return{children:a,height:0};let s=Math.max(...o.map(e=>e.children.filter(e=>e.tagName===`td`||e.tagName===`th`).length));if(s===0)return{children:a,height:0};let c=i/s,l=r;for(let t of o){let r=t.children.filter(e=>e.tagName===`td`||e.tagName===`th`),i=0,o=[];for(let t=0;t<r.length;t++){let a=r[t],{box:s,height:u}=vM(e,a,n+t*c,l,c);o.push(s),i=Math.max(i,u)}for(let e of o)e.height=i,a.push(e);l+=i}return{children:a,height:l-r}}function bM(e,t,n,r,i){let a=t.style,o=a.gap,s=[],c=t.children.filter(e=>e.tagName!==`#text`||e.textContent?.trim());if(c.length===0)return{children:s,height:0};if(a.flexDirection===`row`||a.flexDirection===``){let t=o*(c.length-1),a=c.reduce((e,t)=>e+(t.style.flexGrow||0),0),l=(i-t)/(a||c.length),u=n,d=0;for(let t of c){if(t.tagName===`#text`)continue;let n=l*(t.style.flexGrow||+(a===0)),{box:i,height:c}=vM(e,t,u,r,n);s.push(i),d=Math.max(d,c),u+=n+o}return{children:s,height:d}}let l=r;for(let t of c){if(t.tagName===`#text`)continue;let{box:r,height:a}=vM(e,t,n,l,i);s.push(r),l+=a+o}return{children:s,height:l-r}}function xM(e,t,n){if(!n.listMarker||n.markerHidden)return;let r=n.style,i=n.markerStyle,a=i?{...r,...i}:r;e.font=Fj(a);let o=Hj(e,r),s=t.y+r.borderTopWidth+r.paddingTop+Uj(e,r,o),c=jj(e,n.listMarker),l=r.direction===`rtl`,u=Bj.has(r.listStyleType),d=l?i?.paddingLeft:i?.paddingRight,f,p=s,m=`ltr`,h=t.x+r.borderLeftWidth+r.paddingLeft,g=t.x+t.width;if(u){let{ascent:t}=Yj(e,a),r=e.measureText(n.listMarker),i=d===void 0?7+t/3:d;f=l?g+i+(r.actualBoundingBoxLeft??0):h-i-(r.actualBoundingBoxRight??c);let o=((r.actualBoundingBoxAscent??0)-(r.actualBoundingBoxDescent??0))/2;p=s-t/3+o}else{let t=d===void 0?jj(e,` `):d;l?/\d/.test(n.listMarker)?(m=`rtl`,f=g+t+c):f=g+t:f=h-c-t}t.children.unshift({type:`text`,text:n.listMarker,x:f,y:p,width:c,style:{...a,textDecorationLine:`none`,fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:m}});let _=m===`rtl`?f-c:f;kj.push({y:Math.round(s),text:n.listMarker,bounds:{x:_,y:t.y+r.borderTopWidth+r.paddingTop,width:c,height:o}})}function SM(e,t,n,r=!0,i){Dj=r,Oj=i,Ij.clear(),Jj.clear(),Pj.clear(),Aj.clear(),kj=[];let{box:a,height:o}=vM(e,t,0,0,n);CM(e,a,t);let s=kj.slice().sort((e,t)=>e.y-t.y||e.bounds.x-t.bounds.x),c=[];for(let e of s){let t=c[c.length-1],n=e.bounds.height*.5;if(t&&Math.abs(e.y-t.y)<n){let n=t.text.length>0&&e.text.length>0&&!/\s$/.test(t.text)&&!/^\s/.test(e.text);t.text+=(n?` `:``)+e.text,t.y=Math.max(t.y,e.y);let r=Math.min(t.bounds.x,e.bounds.x),i=Math.min(t.bounds.y,e.bounds.y),a=Math.max(t.bounds.x+t.bounds.width,e.bounds.x+e.bounds.width),o=Math.max(t.bounds.y+t.bounds.height,e.bounds.y+e.bounds.height);t.bounds={x:r,y:i,width:a-r,height:o-i}}else c.push({y:e.y,text:e.text,bounds:{...e.bounds}})}return{root:a,height:o,lines:c}}function CM(e,t,n){xM(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||Gj(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){CM(e,n,i),r++;break}r++}}function wM(e){if(!e||e===`none`)return[];let t=[],n=e.split(/,(?![^(]*\))/);for(let e of n){let n=e.trim(),r=n.match(/(rgb[a]?\([^)]+\)|#[0-9a-fA-F]+|\b[a-z]+\b)(?:\s|$)/i),i=n.match(/-?[\d.]+px/g);if(i&&i.length>=2){let e=i.map(e=>parseFloat(e));t.push({offsetX:e[0],offsetY:e[1],blur:e[2]||0,color:r?r[1]:`rgba(0,0,0,1)`})}}return t}function TM(e,t){return e[`border${t}Width`]>0&&e[`border${t}Style`]!==`none`}function EM(e,t,n,r,i,a,o){if(e.save(),e.strokeStyle=o,e.lineWidth=i,a===`double`){let a=Math.max(i,2);e.lineWidth=Math.max(.5,i*.5),e.beginPath(),e.moveTo(t,n-a/2),e.lineTo(t+r,n-a/2),e.moveTo(t,n+a/2),e.lineTo(t+r,n+a/2),e.stroke()}else if(a===`wavy`){let a=Math.max(1.5,i),o=a*4;e.beginPath(),e.moveTo(t,n);for(let i=t;i<t+r;i+=o)e.quadraticCurveTo(i+o/4,n-a,i+o/2,n),e.quadraticCurveTo(i+o*3/4,n+a,i+o,n);e.stroke()}else a===`dotted`?e.setLineDash([i,i*2]):a===`dashed`&&e.setLineDash([i*3,i*2]),e.beginPath(),e.moveTo(t,n),e.lineTo(t+r,n),e.stroke();e.setLineDash([]),e.restore()}function DM(e,t,n,r,i,a){let o=t.indexOf(`linear-gradient(`);if(o===-1)return null;let s=0,c=-1;for(let e=o+16;e<t.length;e++)if(t[e]===`(`)s++;else if(t[e]===`)`){if(s===0){c=e;break}s--}if(c===-1)return null;let l=t.slice(o+16,c),u=[];s=0;let d=0,f=l;for(let e=0;e<f.length;e++)f[e]===`(`?s++:f[e]===`)`?s--:f[e]===`,`&&s===0&&(u.push(f.slice(d,e).trim()),d=e+1);u.push(f.slice(d).trim());let p=180,m=0,h=u[0];h.endsWith(`deg`)?(p=parseFloat(h),m=1):h===`to right`?(p=90,m=1):h===`to left`?(p=270,m=1):h===`to bottom`?(p=180,m=1):h===`to top`&&(p=0,m=1);let g=(p-90)*Math.PI/180,_=n+r/2,v=i+a/2,y=Math.abs(r*Math.cos(g))+Math.abs(a*Math.sin(g)),b=Math.cos(g)*y/2,x=Math.sin(g)*y/2,S=e.createLinearGradient(_-b,v-x,_+b,v+x),C=u.slice(m);for(let e=0;e<C.length;e++){let t=C[e].trim(),n=t,r=e/Math.max(1,C.length-1),i=t.match(/\s+([\d.]+%)\s*$/);i&&(r=parseFloat(i[1])/100,n=t.slice(0,t.length-i[0].length).trim());try{S.addColorStop(r,n)}catch{}}return S}function OM(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}function kM(e,t){e.strokeStyle=t.webkitTextStrokeColor||t.color,e.lineWidth=t.webkitTextStrokeWidth,e.lineJoin=`round`}function AM(e,t,n){let{style:r}=t;e.save(),e.font=Fj(r),e.textBaseline=`alphabetic`,e.fontKerning=r.fontKerning===`none`?`none`:`normal`,Number.isFinite(r.letterSpacing)&&r.letterSpacing!==0&&(e.letterSpacing=`${r.letterSpacing}px`),r.wordSpacing&&(e.wordSpacing=`${r.wordSpacing}px`),r.direction===`rtl`&&(e.direction=`rtl`,e.textAlign=`right`);let i=r.webkitBackgroundClip===`text`&&r.backgroundImage&&r.backgroundImage!==`none`,a=r.webkitTextStrokeWidth>0,o=r.webkitTextFillColor===`transparent`||r.color===`transparent`,s=wM(r.textShadow);if(s.length>0){let c=i||!o;for(let o of s)e.save(),e.shadowOffsetX=o.offsetX,e.shadowOffsetY=o.offsetY,e.shadowBlur=o.blur,e.shadowColor=o.color,c&&(e.fillStyle=i&&n?n:OM(r),e.fillText(t.text,t.x,t.y)),a&&(kM(e,r),e.strokeText(t.text,t.x,t.y)),e.restore()}let c=()=>{if(i){if(e.save(),n)e.fillStyle=n;else{let{ascent:n,descent:i}=Yj(e,r);e.fillStyle=DM(e,r.backgroundImage,t.x,t.width,t.y-n,n+i)||r.color}e.fillText(t.text,t.x,t.y),e.restore()}else (!o||!a)&&(e.fillStyle=OM(r),e.fillText(t.text,t.x,t.y))},l=()=>{a&&(e.save(),kM(e,r),e.strokeText(t.text,t.x,t.y),e.restore())};yj(r.paintOrder)?(l(),c()):(c(),l());let u=t.width,d=r.fontSize,f=r.textDecorationColor||r.color,p=r.textDecorationStyle||`solid`,m=Math.max(1,d/15),h=r.direction===`rtl`?t.x-u:t.x;if(r.textDecorationLine!==`none`){let{ascent:n}=Yj(e,r);e.font=Fj(r);let i=e.measureText(`x`).actualBoundingBoxAscent;if(r.textDecorationLine.includes(`underline`)){let n=d*.1;EM(e,h,t.y+n,u,m,p,f)}if(r.textDecorationLine.includes(`line-through`)){let n=-(i*.5);EM(e,h,t.y+n,u,m,p,f)}r.textDecorationLine.includes(`overline`)&&EM(e,h,t.y-n,u,m,p,f)}e.restore()}function jM(e,t){let{style:n}=t;qj(n.backgroundColor)||(e.fillStyle=n.backgroundColor,e.fillRect(t.x,t.y,t.width,t.height));let r=[[`Top`,t.x,t.y+n.borderTopWidth/2,t.x+t.width,t.y+n.borderTopWidth/2],[`Right`,t.x+t.width-n.borderRightWidth/2,t.y,t.x+t.width-n.borderRightWidth/2,t.y+t.height],[`Bottom`,t.x,t.y+t.height-n.borderBottomWidth/2,t.x+t.width,t.y+t.height-n.borderBottomWidth/2],[`Left`,t.x+n.borderLeftWidth/2,t.y,t.x+n.borderLeftWidth/2,t.y+t.height]];for(let[t,i,a,o,s]of r)TM(n,t)&&(e.strokeStyle=n[`border${t}Color`],e.lineWidth=n[`border${t}Width`],e.beginPath(),e.moveTo(i,a),e.lineTo(o,s),e.stroke());let i=null;n.webkitBackgroundClip===`text`&&n.backgroundImage&&n.backgroundImage!==`none`&&(i=DM(e,n.backgroundImage,t.x,t.width,t.y,t.height));for(let n of t.children)MM(e,n,i)}function MM(e,t,n){t.type===`text`?AM(e,t,n):jM(e,t)}function NM(e){let{html:t,width:n,height:r,accuracy:i=`performance`,debug:a}=e;if(!n||n<=0||Number.isNaN(n))throw TypeError(`layout: width must be a positive number, got ${n}`);let o=i===`balanced`,{fragment:s,css:c}=mj(t),{tree:l,cleanup:u}=Ej(s,c,n),d=document.createElement(`canvas`).getContext(`2d`);d.fontKerning=`normal`;let{root:f,height:p,lines:m}=SM(d,l,n,o,a),h=r||p;return u(),{layoutRoot:f,height:h,lines:m}}function PM(e){let{layout:t,width:n,pixelRatio:r=globalThis.devicePixelRatio??1}=e;if(e.ctx&&e.canvas)throw TypeError(`drawLayout: ctx and canvas are mutually exclusive — provide one or neither`);let i=t.height,a,o;return e.ctx?(o=e.ctx,a=e.ctx.canvas):(a=e.canvas??document.createElement(`canvas`),a.width=Math.ceil(n*r),a.height=Math.ceil(i*r),`style`in a&&(a.style.width=`${n}px`,a.style.height=`${i}px`),o=a.getContext(`2d`),o.scale(r,r)),MM(o,t.layoutRoot),{canvas:a}}var FM=/[MmLlHhVvCcSsQqTtAaZz]/,IM=/-?(?:\d+\.\d+|\d+\.|\.\d+|\d+)(?:[eE][-+]?\d+)?/g;function LM(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(FM.test(r)){let i=n+1;for(;i<e.length&&!FM.test(e[i]);)i++;let a=e.slice(n+1,i),o=[],s;for(IM.lastIndex=0;s=IM.exec(a);)o.push(Number(s[0]));t.push({cmd:r,args:o}),n=i}else n++}return t}function RM(e){let t=LM(e),n=[],r=0,i=0,a=0,o=0,s=null,c=null;for(let e of t){let t=e.cmd,l=t.toUpperCase(),u=t!==l,d=e.args,f=e=>u?r+e:e,p=e=>u?i+e:e,m=!0,h=!0;switch(l){case`M`:for(let e=0;e<d.length;e+=2){let t=u&&e>0?r+d[e]:f(d[e]),s=u&&e>0?i+d[e+1]:p(d[e+1]);e===0?(r=t,i=s,a=t,o=s):(n.push({type:`L`,x0:r,y0:i,x1:t,y1:s}),r=t,i=s)}break;case`L`:for(let e=0;e<d.length;e+=2){let t=f(d[e]),a=p(d[e+1]);n.push({type:`L`,x0:r,y0:i,x1:t,y1:a}),r=t,i=a}break;case`H`:for(let e=0;e<d.length;e++){let t=u?r+d[e]:d[e];n.push({type:`L`,x0:r,y0:i,x1:t,y1:i}),r=t}break;case`V`:for(let e=0;e<d.length;e++){let t=u?i+d[e]:d[e];n.push({type:`L`,x0:r,y0:i,x1:r,y1:t}),i=t}break;case`C`:for(let e=0;e<d.length;e+=6){let t=f(d[e]),a=p(d[e+1]),o=f(d[e+2]),c=p(d[e+3]),l=f(d[e+4]),u=p(d[e+5]);n.push({type:`C`,x0:r,y0:i,c1x:t,c1y:a,c2x:o,c2y:c,x1:l,y1:u}),s={x:o,y:c},r=l,i=u}m=!1;break;case`S`:for(let e=0;e<d.length;e+=4){let t=s?2*r-s.x:r,a=s?2*i-s.y:i,o=f(d[e]),c=p(d[e+1]),l=f(d[e+2]),u=p(d[e+3]);n.push({type:`C`,x0:r,y0:i,c1x:t,c1y:a,c2x:o,c2y:c,x1:l,y1:u}),s={x:o,y:c},r=l,i=u}m=!1;break;case`Q`:for(let e=0;e<d.length;e+=4){let t=f(d[e]),a=p(d[e+1]),o=f(d[e+2]),s=p(d[e+3]);n.push({type:`Q`,x0:r,y0:i,cx:t,cy:a,x1:o,y1:s}),c={x:t,y:a},r=o,i=s}h=!1;break;case`T`:for(let e=0;e<d.length;e+=2){let t=c?2*r-c.x:r,a=c?2*i-c.y:i,o=f(d[e]),s=p(d[e+1]);n.push({type:`Q`,x0:r,y0:i,cx:t,cy:a,x1:o,y1:s}),c={x:t,y:a},r=o,i=s}h=!1;break;case`A`:for(let e=0;e<d.length;e+=7){let t=d[e],a=d[e+1],o=d[e+2],s=d[e+3]!==0,c=d[e+4]!==0,l=f(d[e+5]),u=p(d[e+6]);t===0||a===0?(r!==l||i!==u)&&n.push({type:`L`,x0:r,y0:i,x1:l,y1:u}):r===l&&i===u||n.push({type:`A`,x0:r,y0:i,rx:t,ry:a,xAxisRotation:o,largeArc:s,sweep:c,x1:l,y1:u}),r=l,i=u}break;case`Z`:(r!==a||i!==o)&&n.push({type:`L`,x0:r,y0:i,x1:a,y1:o}),r=a,i=o;break;default:break}m&&(s=null),h&&(c=null)}return n}function zM(e,t){let n=1-t,r=n*n,i=t*t;return{x:n*r*e.x0+3*r*t*e.c1x+3*n*i*e.c2x+i*t*e.x1,y:n*r*e.y0+3*r*t*e.c1y+3*n*i*e.c2y+i*t*e.y1}}function BM(e,t){let n=1-t;return{x:n*n*e.x0+2*n*t*e.cx+t*t*e.x1,y:n*n*e.y0+2*n*t*e.cy+t*t*e.y1}}function VM(e){let t=Math.abs(e.rx),n=Math.abs(e.ry),r=e.xAxisRotation*Math.PI/180,i=Math.cos(r),a=Math.sin(r),o=(e.x0-e.x1)/2,s=(e.y0-e.y1)/2,c=i*o+a*s,l=-a*o+i*s,u=c*c/(t*t)+l*l/(n*n);if(u>1){let e=Math.sqrt(u);t*=e,n*=e}let d=e.largeArc===e.sweep?-1:1,f=t*t*n*n-t*t*l*l-n*n*c*c,p=t*t*l*l+n*n*c*c,m=Math.sqrt(Math.max(0,f/p)),h=d*m*(t*l/n),g=d*m*(-(n*c)/t),_=i*h-a*g+(e.x0+e.x1)/2,v=a*h+i*g+(e.y0+e.y1)/2,y=(e,t,n,r)=>{let i=e*n+t*r,a=Math.sqrt((e*e+t*t)*(n*n+r*r)),o=Math.acos(Math.min(1,Math.max(-1,i/a)));return e*r-t*n<0&&(o=-o),o},b=y(1,0,(c-h)/t,(l-g)/n),x=y((c-h)/t,(l-g)/n,(-c-h)/t,(-l-g)/n);return x%=2*Math.PI,!e.sweep&&x>0?x-=2*Math.PI:e.sweep&&x<0&&(x+=2*Math.PI),{cx:_,cy:v,rx:t,ry:n,phi:r,theta1:b,deltaTheta:x,cosPhi:i,sinPhi:a}}function HM(e,t){let{cx:n,cy:r,rx:i,ry:a,cosPhi:o,sinPhi:s,theta1:c,deltaTheta:l}=VM(e),u=c+t*l,d=i*Math.cos(u),f=a*Math.sin(u);return{x:o*d-s*f+n,y:s*d+o*f+r}}var UM=40;function WM(e){let t=[],n=0;for(let r of e){if(r.type===`L`){let e=Math.hypot(r.x1-r.x0,r.y1-r.y0);t.push({startLen:n,length:e,seg:r}),n+=e;continue}let e=[],i=0,a;a=r.type===`C`||r.type===`Q`?{x:r.x0,y:r.y0}:HM(r,0),e.push({t:0,len:0});for(let t=1;t<=UM;t++){let n=t/UM,o;o=r.type===`C`?zM(r,n):r.type===`Q`?BM(r,n):HM(r,n),i+=Math.hypot(o.x-a.x,o.y-a.y),e.push({t:n,len:i}),a=o}t.push({startLen:n,length:i,seg:r,samples:e}),n+=i}function r(e){if(!Number.isFinite(e)||e<0||e>n+1e-6)return null;if(e===0&&t.length>0){let e=t[0].seg;return e.type===`L`||e.type===`C`||e.type===`Q`?{x:e.x0,y:e.y0}:HM(e,0)}for(let n=0;n<t.length;n++){let r=t[n];if(e>r.startLen+r.length+1e-6)continue;let i=e-r.startLen;if(r.seg.type===`L`){let e=r.length===0?0:Math.max(0,Math.min(1,i/r.length));return{x:r.seg.x0+(r.seg.x1-r.seg.x0)*e,y:r.seg.y0+(r.seg.y1-r.seg.y0)*e}}let a=r.samples,o=0,s=a.length-1;for(;s-o>1;){let e=o+s>>1;a[e].len<=i?o=e:s=e}let c=a[o],l=a[s],u=l.len-c.len,d=u===0?0:(i-c.len)/u,f=Math.max(0,Math.min(1,c.t+(l.t-c.t)*d));return r.seg.type===`C`?zM(r.seg,f):r.seg.type===`Q`?BM(r.seg,f):HM(r.seg,f)}return null}return{length:n,getPointAtLength:r}}function GM(e){return WM(RM(e))}var KM;function qM(){if(KM!==void 0)return KM;if(typeof Intl<`u`&&typeof Intl.Segmenter==`function`)try{KM=new Intl.Segmenter(void 0,{granularity:`grapheme`})}catch{KM=null}else KM=null;return KM}function JM(e){if(!e)return[];let t=qM();if(t){let n=[];for(let r of t.segment(e))n.push(r.segment);return n}return Array.from(e)}function YM(e,t,n){switch(e){case`alphabetic`:return 0;case`middle`:return(t-n)/2;case`top`:return t;case`bottom`:return-n;case`hanging`:return t*.8;case`ideographic`:return-n*.5}}function XM(e){let t=[];function n(e,r){let i=e.style.direction===`rtl`||r;if(e.tagName===`#text`&&e.textContent){t.push({text:e.textContent,style:e.style,rtl:i});return}for(let t of e.children)n(t,i)}return n(e,!1),t}var ZM=RegExp(`[\\u0590-\\u05FF\\u0600-\\u06FF\\u0700-\\u074F\\u0750-\\u077F\\u0780-\\u07BF\\u07C0-\\u07FF\\u0800-\\u083F\\u0840-\\u085F\\u0860-\\u086F\\u08A0-\\u08FF\\u0900-\\u097F\\u0980-\\u09FF\\u0A00-\\u0A7F\\u0A80-\\u0AFF\\u0B00-\\u0B7F\\u0B80-\\u0BFF\\u0C00-\\u0C7F\\u0C80-\\u0CFF\\u0D00-\\u0D7F\\u0D80-\\u0DFF\\u0E00-\\u0E7F\\u0E80-\\u0EFF\\u0F00-\\u0FFF\\u1000-\\u109F\\u1780-\\u17FF\\u1800-\\u18AF\\uFB1D-\\uFB4F\\uFB50-\\uFDFF\\uFE70-\\uFEFF]`);function QM(e){return ZM.test(e)}function $M(e,t){let n=JM(t.text);if(n.length===0)return[];Mj(e,t.style),e.letterSpacing=`${t.style.letterSpacing||0}px`;let{ascent:r,descent:i}=Yj(e,t.style),a=[],o=``;for(let e of n){let t=e===` `;QM(e)&&!t?o+=e:(o&&=(a.push({text:o,shaped:!0,isSpace:!1}),``),a.push({text:e,shaped:!1,isSpace:t}))}o&&a.push({text:o,shaped:!0,isSpace:!1}),t.rtl&&a.reverse();let s=[];for(let n of a){let a=e.measureText(n.text).width;s.push({text:n.text,width:a,style:t.style,isSpace:n.isSpace,ascent:r,descent:i,shaped:n.shaped})}return s}function eN(e){let{segments:t,path:n,ctx:r,align:i,textBaseline:a}=e,o=[],s=0,c=0;for(let e of t){if(!e.text)continue;let t=e.style.lineHeight>0?e.style.lineHeight:e.style.fontSize;t>c&&(c=t);let n=$M(r,e);n.length!==0&&(o.push(...n),s+=r.measureText(e.text).width)}let l=0;for(let e of o)l+=e.width+(e.style.letterSpacing||0);o.length>0&&(l-=o[o.length-1].style.letterSpacing||0);let u=Math.max(0,l-s),d=n.length,f=0,p=0;if(i===`center`)f=Math.max(0,(d-l)/2);else if(i===`right`)f=Math.max(0,d-l);else if(i===`justify`){let e=o.filter(e=>e.isSpace).length;e>0&&d>l&&(p=(d-l)/e)}let m=[],h=f,g=0;for(let e=0;e<o.length;e++){let t=o[e],r=t.width+(t.isSpace?p:0),i=n.getPointAtLength(h);if(!i)break;let a=h+r,s;if(a>d)if(a-d<=u+.5)s=n.getPointAtLength(d);else break;else s=n.getPointAtLength(a);if(!s)break;let c=Math.atan2(s.y-i.y,s.x-i.x);m.push({char:t.text,x:i.x,y:i.y,rotation:c,width:t.width,style:t.style,ascent:t.ascent,descent:t.descent,pathOffset:g,shaped:t.shaped}),h=a+(t.style.letterSpacing||0),g+=t.width+(t.style.letterSpacing||0)}let _=tN(m,a);return{glyphs:m,textWidth:l,pathLength:d,lineHeight:c,bounds:_,textBaseline:a}}function tN(e,t){if(e.length===0)return{x:0,y:0,width:0,height:0};let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let o of e){let e=o.style.lineHeight>0?o.style.lineHeight:o.style.fontSize,s=o.ascent+o.descent,c=s>0?o.ascent/s:.75,l=e*c,u=e*(1-c),d=YM(t,o.ascent,o.descent),f=d-l,p=d+u,m=Math.cos(o.rotation),h=Math.sin(o.rotation),g=[{x:o.x+-h*f,y:o.y+m*f},{x:o.x+m*o.width+-h*f,y:o.y+h*o.width+m*f},{x:o.x+m*o.width+-h*p,y:o.y+h*o.width+m*p},{x:o.x+-h*p,y:o.y+m*p}];for(let e of g)e.x<n&&(n=e.x),e.y<r&&(r=e.y),e.x>i&&(i=e.x),e.y>a&&(a=e.y)}return{x:n,y:r,width:i-n,height:a-r}}function nN(e){let{html:t,align:n=`left`,textBaseline:r=`alphabetic`}=e,i=typeof e.path==`string`?GM(e.path):e.path,a=e.ctx??iN(),o=e.ctx===void 0,{fragment:s,css:c}=mj(t),{tree:l,cleanup:u}=Ej(s,c,2**53-1);o||a.save();try{return eN({segments:XM(l),path:i,ctx:a,align:n,textBaseline:r})}finally{o||a.restore(),u()}}function rN(e){let{layout:t,ctx:n}=e;if(t.glyphs.length===0)return;let r=t.textBaseline;n.save();try{sN(n,t.glyphs,r),uN(n,t.glyphs,t.textWidth,r),pN(n,t.glyphs,r)}finally{n.restore()}}function iN(){return(typeof OffscreenCanvas<`u`?new OffscreenCanvas(1,1):document.createElement(`canvas`)).getContext(`2d`)}var aN=new WeakMap;function oN(e,t){if(!t)return``;let n=aN.get(e);n||(n=new Map,aN.set(e,n));let r=n.get(t);if(r!==void 0)return r;let i=e.fillStyle;try{e.fillStyle=t;let r=typeof e.fillStyle==`string`?e.fillStyle:t;return n.set(t,r),r}catch{return n.set(t,t),t}finally{e.fillStyle=i}}function sN(e,t,n){let r=0;for(;r<t.length;){let i=t[r].style.backgroundColor;if(!i||qj(i)){r++;continue}let a=oN(e,i),o=r+1;for(;o<t.length&&oN(e,t[o].style.backgroundColor)===a;)o++;lN(e,t.slice(r,o),i,n),r=o}}function cN(e,t){let n=Math.cos(e.rotation),r=Math.sin(e.rotation),i=YM(t,e.ascent,e.descent),a=i-e.ascent,o=i+e.descent,s=e.width;return{tl:{x:e.x+-r*a,y:e.y+n*a},tr:{x:e.x+n*s+-r*a,y:e.y+r*s+n*a},br:{x:e.x+n*s+-r*o,y:e.y+r*s+n*o},bl:{x:e.x+-r*o,y:e.y+n*o}}}function lN(e,t,n,r){if(t.length===0)return;e.save(),e.fillStyle=n,e.beginPath();let i=cN(t[0],r);e.moveTo(i.tl.x,i.tl.y);for(let n=0;n<t.length;n++){let i=cN(t[n],r);e.lineTo(i.tl.x,i.tl.y),e.lineTo(i.tr.x,i.tr.y)}for(let n=t.length-1;n>=0;n--){let i=cN(t[n],r);e.lineTo(i.br.x,i.br.y),e.lineTo(i.bl.x,i.bl.y)}e.closePath(),e.fill(),e.restore()}function uN(e,t,n,r){for(let i of t){e.save(),e.translate(i.x,i.y),e.rotate(i.rotation),Mj(e,i.style),e.textBaseline=`alphabetic`,e.letterSpacing=`${i.style.letterSpacing||0}px`;let t=YM(r,i.ascent,i.descent),a=wM(i.style.textShadow);if(a.length>0)for(let n=a.length-1;n>=0;n--){let r=a[n];e.save(),e.shadowOffsetX=r.offsetX,e.shadowOffsetY=r.offsetY,e.shadowBlur=r.blur,e.shadowColor=r.color,e.fillStyle=hN(i.style),e.fillText(i.char,0,t),e.restore()}dN(e,i,n,t),e.restore()}}function dN(e,t,n,r){let{style:i}=t,a=i.webkitTextFillColor===`transparent`||i.color===`transparent`||qj(hN(i)),o=i.webkitTextStrokeWidth>0,s=i.webkitBackgroundClip===`text`&&i.backgroundImage&&i.backgroundImage!==`none`,c=yj(i.paintOrder||``),l=()=>{if(s){fN(e,t,n,r);return}if(a){if(o)return;e.fillStyle=`transparent`,e.fillText(t.char,0,r);return}e.fillStyle=hN(i),e.fillText(t.char,0,r)},u=()=>{o&&(e.save(),e.lineJoin=`round`,e.lineWidth=i.webkitTextStrokeWidth,e.strokeStyle=i.webkitTextStrokeColor||i.color,e.strokeText(t.char,0,r),e.restore())};c?(u(),l()):(l(),u())}function fN(e,t,n,r){let i=DM(e,t.style.backgroundImage,-t.pathOffset,n,r-t.ascent,t.ascent+t.descent);if(!i){e.fillStyle=hN(t.style),e.fillText(t.char,0,r);return}e.fillStyle=i,e.fillText(t.char,0,r)}function pN(e,t,n){for(let r of[`underline`,`line-through`,`overline`]){let i=0;for(;i<t.length;){let a=t[i].style;if(!a.textDecorationLine||!a.textDecorationLine.includes(r)){i++;continue}let o=a.textDecorationColor||a.color,s=a.textDecorationStyle||`solid`,c=oN(e,o),l=i+1;for(;l<t.length&&t[l].style.textDecorationLine&&t[l].style.textDecorationLine.includes(r)&&oN(e,t[l].style.textDecorationColor||t[l].style.color)===c&&(t[l].style.textDecorationStyle||`solid`)===s;)l++;mN(e,t.slice(i,l),r,s,o,n),i=l}}}function mN(e,t,n,r,i,a){if(t.length===0)return;let o=Math.max(1,t[0].style.fontSize/15),s=e=>{let t=YM(a,e.ascent,e.descent);return n===`underline`?t+e.descent*.5:n===`line-through`?t-e.ascent*.3:t-e.ascent*.9};if(r===`double`||r===`wavy`){for(let n of t)e.save(),e.translate(n.x,n.y),e.rotate(n.rotation),EM(e,0,s(n),n.width,o,r,i),e.restore();return}e.save(),e.strokeStyle=i,e.lineWidth=o,r===`dotted`?e.setLineDash([o,o*2]):r===`dashed`&&e.setLineDash([o*3,o*2]),e.beginPath();for(let n=0;n<t.length;n++){let r=t[n],i=s(r),a=Math.cos(r.rotation),o=Math.sin(r.rotation),c={x:r.x+-o*i,y:r.y+a*i},l={x:r.x+a*r.width+-o*i,y:r.y+o*r.width+a*i};n===0?e.moveTo(c.x,c.y):e.lineTo(c.x,c.y),e.lineTo(l.x,l.y)}e.stroke(),e.setLineDash([]),e.restore()}function hN(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}var gN=`<style>${Py}
|
|
513
|
+
`)break;let r=!!n.text&&mM.test(n.text),i=!n.text&&!!n.boxClose,a=!!n.text&&!!n.noBreakBefore;if(r||i||a){h+=n.width;continue}break}for(let i of m){let a=i===m[m.length-1]?h:0,o=!i.isSpace&&i.text.length>0&&mM.test(i.text)&&s.words.length>0&&!s.words[s.words.length-1].isSpace,c=i===m[0]&&i.noBreakBefore&&s.words.length>0&&!s.words[s.words.length-1].isSpace,g=0;if(!i.text&&i.boxOpen){let n=t[r+1];n&&!n.isSpace&&n.text&&(g=(n.text.length>1?pM(e,n,l(),0):[n])[0].width)}let _=0;if(i.isSoftHyphenBreak&&(Mj(e,i.style),e.letterSpacing=Nj(i.style.letterSpacing),_=jj(e,`-`)),!i.isSpace&&!o&&!c&&s.words.length>0&&s.totalWidth+i.width+_+a+g>l()){let t=s.totalWidth+i.width+_+a+g-l(),r=!0;if(t<1&&!dse([...s.words,i])){Mj(e,i.style);let t=s.words.map(e=>e.text).join(``)+i.text+(i.isSoftHyphenBreak?`-`:``),n=0;for(let e of s.words)e.text||(n+=e.width);i.text||(n+=i.width),jj(e,t)+n+a+g<=l()+.02&&(r=!1)}if(r&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){Mj(e,i.style);let n=``,r=0,a=0,o=l()-s.totalWidth;for(;a<t.length;a++){let i=n+t[a],s=jj(e,i);if(s>o)break;n=i,r=s}if(a>0&&a<t.length){s.words.push({...i,text:n,width:r}),s.totalWidth+=r,s.lineHeight=Math.max(s.lineHeight,u),f(!0),p=!1;let o=t.slice(a).join(``),c=jj(e,o);s.words.push({...i,text:o,width:c}),s.totalWidth+=c,s.lineHeight=Math.max(s.lineHeight,u);continue}}}if(r){if(Oj){let e=s.words.map(e=>e.text).join(``);Oj({type:`line-wrap`,message:`"${i.text}" overflow=${t.toFixed(2)} wrap=true lineWidth=${s.totalWidth.toFixed(2)} pieceWidth=${i.width.toFixed(2)} contentWidth=${n} line="${e}"`,data:{text:i.text,overflow:t,lineWidth:s.totalWidth,pieceWidth:i.width,contentWidth:n,lineText:e}})}f(!0),p=!1}}if(i.isSpace&&s.words.length===0&&(!p||!d))continue;let v=i.width;if(i.isTab){let e=i.width,t=s.totalWidth;v=Math.ceil((t+.1)/e)*e-t,i.width=v}if(s.words.length===0&&v>l()&&!i.isSpace&&i.text.includes(`-`)){let t=i.text.split(/(?<=-)(?!\d)|(?<=[^\d]-)/);if(t.length>1){Mj(e,i.style);let n=t.filter(e=>e).map(t=>({...i,text:t,width:jj(e,t)})),r=!0;for(let e of n)r?(r=!1,s.words.push(e),s.totalWidth+=e.width,s.lineHeight=Math.max(s.lineHeight,u)):s.totalWidth+e.width>l()?(f(!0),p=!1,s.words.push(e),s.totalWidth+=e.width,s.lineHeight=Math.max(s.lineHeight,u)):(s.words.push(e),s.totalWidth+=e.width,s.lineHeight=Math.max(s.lineHeight,u));continue}}s.words.push(i),s.totalWidth+=v,s.lineHeight=Math.max(s.lineHeight,u),i.isSpace||(p=!1)}}return f(),o}function gM(e,t,n,r,i,a=!1,o){let s=[];if(o&&(o.exhausted||o.remaining<=0))return o.exhausted=!0,{nodes:s,height:0};let c=nM(t);if(c.length===0)return{nodes:s,height:0};let l=sM(e,c),u=t.style.textIndent||0,d=hM(e,l,i,t.style.whiteSpace,a,u),f=o?o.remaining:t.style.lineClamp;if(f>0&&d.length>f){d.length=f;let t=d[f-1];tM(e,t,i-(f===1?u:0)),t.endedByHardBreak=!0,o&&(o.remaining=0,o.exhausted=!0)}else o&&(o.remaining-=d.length);let p=t.style.direction===`rtl`,m=e=>e===`start`?p?`right`:`left`:e===`end`?p?`left`:`right`:e,h=m(t.style.textAlign),g=t.style.textAlignLast||`auto`;g=g===`auto`?t.style.textAlign===`justify`?p?`right`:`left`:h:m(g);let _=r;for(let t=0;t<d.length;t++){let r=d[t];if(r.words.length===0){_+=r.lineHeight;continue}let a=r.lineHeight,o=t===d.length-1,c=t===0,l=o||r.endedByHardBreak?g:h,f=c?u:0,m=i-f,v=0;if(l===`justify`&&r.totalWidth<m){let e=r.words.filter(e=>e.isSpace).length;e>0&&(v=(m-r.totalWidth)/e)}let y=r.totalWidth>m+.5,b=n+f;y?b=p?n+m-r.totalWidth:n+f:l===`center`?b=n+f+(m-r.totalWidth)/2:l===`right`?b=(p?n+m:n+f+m)-r.totalWidth:l===`justify`&&p&&(b=n+m-r.totalWidth);let x=b,S=0,C=0;for(let t of r.words){if(t.text===``||Zj(t.style.verticalAlign))continue;let{ascent:n,descent:r}=Yj(e,t.style);n>S&&(S=n),r>C&&(C=r)}if(S===0)for(let t of r.words){if(t.text===``)continue;let{ascent:n,descent:r}=Yj(e,t.style);S=n,C=r;break}let w=S+C,T=_+(a-w)/2+S,E=r.words.filter(e=>e.text!==``&&!Zj(e.style.verticalAlign)),D=E.length>0?Math.max(...E.map(e=>e.style.fontSize)):0,O=_,k=_+a;for(let t of r.words){if(t.text===``)continue;let n=t.style.verticalAlign;if(!Zj(n))continue;if(D===0)break;let{ascent:r,descent:i}=Yj(e,t.style),o=T+Xj(n,r,i,D,S,C,a),s=o-r,c=o+i;s<O&&(O=s),c>k&&(k=c)}let A=k-O,j=(t,n,r)=>{let{ascent:i,descent:a}=Yj(e,t),o=t.paddingTop+t.borderTopWidth,c=t.paddingBottom+t.borderBottomWidth,l=i+a+o+c,u;u=t.display===`inline-block`?_+t.marginTop:T-i-o,s.push({type:`box`,style:t,x:n,y:u,width:r,height:l,tagName:`span`,children:[]})};if(!p){let e=b,t=e,n,i=!1;for(let a of r.words){if(a.boxOpen&&a.boxClose&&a.text){n&&(i&&j(n,t,e-t),n=void 0,i=!1);let r=a.style,o=a.width-r.marginLeft-r.borderLeftWidth-r.paddingLeft-r.paddingRight-r.borderRightWidth-r.marginRight;j(r,e+r.marginLeft,r.borderLeftWidth+r.paddingLeft+o+r.paddingRight+r.borderRightWidth),i=!1,e+=a.width;continue}a.boxStyle!==n&&(n&&i&&j(n,t,e-t),n=a.boxStyle,t=e,i=!1),a.text&&!a.isSpace&&(i=!0),e+=a.width+(a.isSpace?v:0)}n&&i&&j(n,t,e-t)}let M=r.words.filter(e=>e.text!==``),ee=M.length>0&&M.every(e=>Qj(e.style,M[0].style));if(p){let t=[],n=null,i=0;for(let e of r.words){if(e.text===``){n&&=(t.push(n),null),i+=e.width;continue}if(e.isSpace&&v>0){n&&=(t.push(n),null),i+=e.width+v;continue}n&&Qj(n.style,e.style)?(n.text+=e.text,n.width+=e.width):(n&&t.push(n),n={text:e.text,style:e.style,width:e.width,boxStyle:e.boxStyle,x:0,padBefore:i},i=0)}n&&t.push(n);let a=b+r.totalWidth;for(let n of t){a-=n.padBefore,Mj(e,n.style);let t=jj(e,n.text);a-=t,n.x=a,n.width=t}for(let e of t)if(e.boxStyle&&$j(e.boxStyle)){let t=e.boxStyle,n=t.paddingLeft+t.borderLeftWidth,r=t.paddingRight+t.borderRightWidth;j(t,e.x-n,e.width+n+r)}for(let e of t)s.push({type:`text`,text:e.text,x:e.x+e.width,y:T,width:e.width,style:{...e.style,direction:`rtl`}})}else{let t=r.words.map(e=>e.text).join(``);if(ee&&/[\u0590-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/.test(t)&&!r.words.some(e=>e.boxOpen||e.boxClose||e.style.verticalAlign===`super`||e.style.verticalAlign===`sub`)){Mj(e,M[0].style);let n=jj(e,t);s.push({type:`text`,text:t,x:b,y:T,width:n,style:{...M[0].style,direction:`ltr`}})}else for(let t of r.words){if(t.text===``){b+=t.width;continue}if(t.boxOpen&&t.boxClose){let n=t.style,r=b+n.marginLeft+n.borderLeftWidth+n.paddingLeft;s.push({type:`text`,text:t.text,x:r,y:T,width:jj(e,t.text),style:t.style}),b+=t.width;continue}let n=T,r=t.style.verticalAlign;if(Zj(r)){let i=D||t.style.fontSize,{ascent:o,descent:s}=Yj(e,t.style);n+=Xj(r,o,s,i,S,C,a)}let i=t.width+(t.isSpace?v:0);s.push({type:`text`,text:t.text,x:b,y:n,width:i,style:t.style}),b+=i}}let N=l===`justify`&&v>0?m:r.totalWidth;kj.push({y:Math.round(T),text:r.words.map(e=>e.text).join(``),bounds:{x,y:O,width:N,height:A}}),_+=A}return{nodes:s,height:_-r}}function _M(e,t){return e>=0&&t>=0?Math.max(e,t):e<0&&t<0?Math.min(e,t):e+t}function vM(e,t,n,r,i,a){let o=t.style;!a&&o.lineClamp>0&&(a={remaining:o.lineClamp,exhausted:!1});let s=o.marginLeft,c=o.marginRight,l=o.borderLeftWidth,u=o.borderRightWidth,d=o.borderTopWidth,f=o.borderBottomWidth,p=o.paddingLeft,m=o.paddingRight,h=o.paddingTop,g=o.paddingBottom,_=n+s,v=o.width>0?o.width:i-s-c,y=_+l+p,b=Math.max(0,v-l-u-p-m),x=r,S=x+d+h,C={type:`box`,style:o,x:_,y:x,width:v,height:0,tagName:t.tagName,children:[],listMarker:t.listMarker};if(o.display===`flex`){let n=bM(e,t,y,S,b);return C.children=n.children,C.height=d+h+n.height+g+f,{box:C,height:C.height,marginBottomOut:o.marginBottom}}if(o.display===`table`){let n=yM(e,t,y,S,b);return C.children=n.children,C.height=d+h+n.height+g+f,{box:C,height:C.height,marginBottomOut:o.marginBottom}}if(t.children.length===0)return C.height=d+h+g+f,o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:o.marginBottom};if(Kj(t)){let{nodes:n,height:r}=gM(e,t,y,S,b,t.tagName===`li`&&Bj.has(o.listStyleType),a);C.children=n,C.height=d+h+r+g+f}else{let n=S,r=0,i=!1,s=t.tagName===`li`||t.tagName===`ul`||t.tagName===`ol`||t.tagName===`dd`||t.tagName===`dt`;for(let c=0;c<t.children.length;c++){let l=t.children[c];if(a&&(a.exhausted||a.remaining<=0)){a.exhausted=!0,r=0;break}if(l.tagName===`#text`||Gj(l)){let s=[l];for(;c+1<t.children.length;){let e=t.children[c+1];if(e.tagName===`#text`||Gj(e))s.push(e),c++;else break}r>0&&(n+=r,r=0);let u={element:null,tagName:`div`,style:{...t.style,display:`block`,marginTop:0,marginBottom:0,paddingTop:0,paddingBottom:0,borderTopWidth:0,borderBottomWidth:0},children:s,textContent:null},d=t.tagName===`li`&&Bj.has(o.listStyleType),{nodes:f,height:p}=gM(e,u,y,n,b,d,a);C.children.push(...f),n+=p,r=0,i=!0;continue}let u=l.style.marginTop;if(!(!i&&h===0&&d===0&&s)){let e=_M(r,u);n+=e}let{box:f,height:p,marginBottomOut:m}=vM(e,l,y,n,b,a);C.children.push(f),n+=p,r=a?.exhausted?0:m,i=!0}let c=o.marginBottom,l=g===0&&f===0&&s;l&&r>0&&(c=Math.max(o.marginBottom,r));let u=n-S;return!l&&r>0&&(u+=r),C.height=d+h+u+g+f,o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:c}}return o.minHeight>0&&(C.height=Math.max(C.height,o.minHeight)),{box:C,height:C.height,marginBottomOut:o.marginBottom}}function yM(e,t,n,r,i){let a=[],o=[];for(let e of t.children)if(e.tagName===`tr`)o.push(e);else if([`thead`,`tbody`,`tfoot`].includes(e.tagName))for(let t of e.children)t.tagName===`tr`&&o.push(t);if(o.length===0)return{children:a,height:0};let s=Math.max(...o.map(e=>e.children.filter(e=>e.tagName===`td`||e.tagName===`th`).length));if(s===0)return{children:a,height:0};let c=i/s,l=r;for(let t of o){let r=t.children.filter(e=>e.tagName===`td`||e.tagName===`th`),i=0,o=[];for(let t=0;t<r.length;t++){let a=r[t],{box:s,height:u}=vM(e,a,n+t*c,l,c);o.push(s),i=Math.max(i,u)}for(let e of o)e.height=i,a.push(e);l+=i}return{children:a,height:l-r}}function bM(e,t,n,r,i){let a=t.style,o=a.gap,s=[],c=t.children.filter(e=>e.tagName!==`#text`||e.textContent?.trim());if(c.length===0)return{children:s,height:0};if(a.flexDirection===`row`||a.flexDirection===``){let t=o*(c.length-1),a=c.reduce((e,t)=>e+(t.style.flexGrow||0),0),l=(i-t)/(a||c.length),u=n,d=0;for(let t of c){if(t.tagName===`#text`)continue;let n=l*(t.style.flexGrow||+(a===0)),{box:i,height:c}=vM(e,t,u,r,n);s.push(i),d=Math.max(d,c),u+=n+o}return{children:s,height:d}}let l=r;for(let t of c){if(t.tagName===`#text`)continue;let{box:r,height:a}=vM(e,t,n,l,i);s.push(r),l+=a+o}return{children:s,height:l-r}}function xM(e,t,n){if(!n.listMarker||n.markerHidden)return;let r=n.style,i=n.markerStyle,a=i?{...r,...i}:r;e.font=Fj(a);let o=Hj(e,r),s=t.y+r.borderTopWidth+r.paddingTop+Uj(e,r,o),c=jj(e,n.listMarker),l=r.direction===`rtl`,u=Bj.has(r.listStyleType),d=l?i?.paddingLeft:i?.paddingRight,f,p=s,m=`ltr`,h=t.x+r.borderLeftWidth+r.paddingLeft,g=t.x+t.width;if(u){let{ascent:t}=Yj(e,a),r=e.measureText(n.listMarker),i=d===void 0?7+t/3:d;f=l?g+i+(r.actualBoundingBoxLeft??0):h-i-(r.actualBoundingBoxRight??c);let o=((r.actualBoundingBoxAscent??0)-(r.actualBoundingBoxDescent??0))/2;p=s-t/3+o}else{let t=d===void 0?jj(e,` `):d;l?/\d/.test(n.listMarker)?(m=`rtl`,f=g+t+c):f=g+t:f=h-c-t}t.children.unshift({type:`text`,text:n.listMarker,x:f,y:p,width:c,style:{...a,textDecorationLine:`none`,fontWeight:i?.fontWeight??400,fontStyle:i?.fontStyle??`normal`,direction:m}});let _=m===`rtl`?f-c:f;kj.push({y:Math.round(s),text:n.listMarker,bounds:{x:_,y:t.y+r.borderTopWidth+r.paddingTop,width:c,height:o}})}function SM(e,t,n,r=!0,i){Dj=r,Oj=i,Ij.clear(),Jj.clear(),Pj.clear(),Aj.clear(),kj=[];let{box:a,height:o}=vM(e,t,0,0,n);CM(e,a,t);let s=kj.slice().sort((e,t)=>e.y-t.y||e.bounds.x-t.bounds.x),c=[];for(let e of s){let t=c[c.length-1],n=e.bounds.height*.5;if(t&&Math.abs(e.y-t.y)<n){let n=t.text.length>0&&e.text.length>0&&!/\s$/.test(t.text)&&!/^\s/.test(e.text);t.text+=(n?` `:``)+e.text,t.y=Math.max(t.y,e.y);let r=Math.min(t.bounds.x,e.bounds.x),i=Math.min(t.bounds.y,e.bounds.y),a=Math.max(t.bounds.x+t.bounds.width,e.bounds.x+e.bounds.width),o=Math.max(t.bounds.y+t.bounds.height,e.bounds.y+e.bounds.height);t.bounds={x:r,y:i,width:a-r,height:o-i}}else c.push({y:e.y,text:e.text,bounds:{...e.bounds}})}return{root:a,height:o,lines:c}}function CM(e,t,n){xM(e,t,n);let r=0;for(let i of n.children)if(!(i.tagName===`#text`||Gj(i)))for(;r<t.children.length;){let n=t.children[r];if(n.type===`box`&&n.tagName===i.tagName){CM(e,n,i),r++;break}r++}}function wM(e){if(!e||e===`none`)return[];let t=[],n=e.split(/,(?![^(]*\))/);for(let e of n){let n=e.trim(),r=n.match(/(rgb[a]?\([^)]+\)|#[0-9a-fA-F]+|\b[a-z]+\b)(?:\s|$)/i),i=n.match(/-?[\d.]+px/g);if(i&&i.length>=2){let e=i.map(e=>parseFloat(e));t.push({offsetX:e[0],offsetY:e[1],blur:e[2]||0,color:r?r[1]:`rgba(0,0,0,1)`})}}return t}function TM(e,t){return e[`border${t}Width`]>0&&e[`border${t}Style`]!==`none`}function EM(e,t,n,r,i,a,o){if(e.save(),e.strokeStyle=o,e.lineWidth=i,a===`double`){let a=Math.max(i,2);e.lineWidth=Math.max(.5,i*.5),e.beginPath(),e.moveTo(t,n-a/2),e.lineTo(t+r,n-a/2),e.moveTo(t,n+a/2),e.lineTo(t+r,n+a/2),e.stroke()}else if(a===`wavy`){let a=Math.max(1.5,i),o=a*4;e.beginPath(),e.moveTo(t,n);for(let i=t;i<t+r;i+=o)e.quadraticCurveTo(i+o/4,n-a,i+o/2,n),e.quadraticCurveTo(i+o*3/4,n+a,i+o,n);e.stroke()}else a===`dotted`?e.setLineDash([i,i*2]):a===`dashed`&&e.setLineDash([i*3,i*2]),e.beginPath(),e.moveTo(t,n),e.lineTo(t+r,n),e.stroke();e.setLineDash([]),e.restore()}function DM(e,t,n,r,i,a){let o=t.indexOf(`linear-gradient(`);if(o===-1)return null;let s=0,c=-1;for(let e=o+16;e<t.length;e++)if(t[e]===`(`)s++;else if(t[e]===`)`){if(s===0){c=e;break}s--}if(c===-1)return null;let l=t.slice(o+16,c),u=[];s=0;let d=0,f=l;for(let e=0;e<f.length;e++)f[e]===`(`?s++:f[e]===`)`?s--:f[e]===`,`&&s===0&&(u.push(f.slice(d,e).trim()),d=e+1);u.push(f.slice(d).trim());let p=180,m=0,h=u[0];h.endsWith(`deg`)?(p=parseFloat(h),m=1):h===`to right`?(p=90,m=1):h===`to left`?(p=270,m=1):h===`to bottom`?(p=180,m=1):h===`to top`&&(p=0,m=1);let g=(p-90)*Math.PI/180,_=n+r/2,v=i+a/2,y=Math.abs(r*Math.cos(g))+Math.abs(a*Math.sin(g)),b=Math.cos(g)*y/2,x=Math.sin(g)*y/2,S=e.createLinearGradient(_-b,v-x,_+b,v+x),C=u.slice(m);for(let e=0;e<C.length;e++){let t=C[e].trim(),n=t,r=e/Math.max(1,C.length-1),i=t.match(/\s+([\d.]+%)\s*$/);i&&(r=parseFloat(i[1])/100,n=t.slice(0,t.length-i[0].length).trim());try{S.addColorStop(r,n)}catch{}}return S}function OM(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}function kM(e,t){e.strokeStyle=t.webkitTextStrokeColor||t.color,e.lineWidth=t.webkitTextStrokeWidth,e.lineJoin=`round`}function AM(e,t,n){let{style:r}=t;e.save(),e.font=Fj(r),e.textBaseline=`alphabetic`,e.fontKerning=r.fontKerning===`none`?`none`:`normal`,Number.isFinite(r.letterSpacing)&&r.letterSpacing!==0&&(e.letterSpacing=`${r.letterSpacing}px`),r.wordSpacing&&(e.wordSpacing=`${r.wordSpacing}px`),r.direction===`rtl`&&(e.direction=`rtl`,e.textAlign=`right`);let i=r.webkitBackgroundClip===`text`&&r.backgroundImage&&r.backgroundImage!==`none`,a=r.webkitTextStrokeWidth>0,o=r.webkitTextFillColor===`transparent`||r.color===`transparent`,s=wM(r.textShadow);if(s.length>0){let c=i||!o;for(let o of s)e.save(),e.shadowOffsetX=o.offsetX,e.shadowOffsetY=o.offsetY,e.shadowBlur=o.blur,e.shadowColor=o.color,c&&(e.fillStyle=i&&n?n:OM(r),e.fillText(t.text,t.x,t.y)),a&&(kM(e,r),e.strokeText(t.text,t.x,t.y)),e.restore()}let c=()=>{if(i){if(e.save(),n)e.fillStyle=n;else{let{ascent:n,descent:i}=Yj(e,r);e.fillStyle=DM(e,r.backgroundImage,t.x,t.width,t.y-n,n+i)||r.color}e.fillText(t.text,t.x,t.y),e.restore()}else (!o||!a)&&(e.fillStyle=OM(r),e.fillText(t.text,t.x,t.y))},l=()=>{a&&(e.save(),kM(e,r),e.strokeText(t.text,t.x,t.y),e.restore())};yj(r.paintOrder)?(l(),c()):(c(),l());let u=t.width,d=r.fontSize,f=r.textDecorationColor||r.color,p=r.textDecorationStyle||`solid`,m=Math.max(1,d/15),h=r.direction===`rtl`?t.x-u:t.x;if(r.textDecorationLine!==`none`){let{ascent:n}=Yj(e,r);e.font=Fj(r);let i=e.measureText(`x`).actualBoundingBoxAscent;if(r.textDecorationLine.includes(`underline`)){let n=d*.1;EM(e,h,t.y+n,u,m,p,f)}if(r.textDecorationLine.includes(`line-through`)){let n=-(i*.5);EM(e,h,t.y+n,u,m,p,f)}r.textDecorationLine.includes(`overline`)&&EM(e,h,t.y-n,u,m,p,f)}e.restore()}function jM(e,t){let{style:n}=t;qj(n.backgroundColor)||(e.fillStyle=n.backgroundColor,e.fillRect(t.x,t.y,t.width,t.height));let r=[[`Top`,t.x,t.y+n.borderTopWidth/2,t.x+t.width,t.y+n.borderTopWidth/2],[`Right`,t.x+t.width-n.borderRightWidth/2,t.y,t.x+t.width-n.borderRightWidth/2,t.y+t.height],[`Bottom`,t.x,t.y+t.height-n.borderBottomWidth/2,t.x+t.width,t.y+t.height-n.borderBottomWidth/2],[`Left`,t.x+n.borderLeftWidth/2,t.y,t.x+n.borderLeftWidth/2,t.y+t.height]];for(let[t,i,a,o,s]of r)TM(n,t)&&(e.strokeStyle=n[`border${t}Color`],e.lineWidth=n[`border${t}Width`],e.beginPath(),e.moveTo(i,a),e.lineTo(o,s),e.stroke());let i=null;n.webkitBackgroundClip===`text`&&n.backgroundImage&&n.backgroundImage!==`none`&&(i=DM(e,n.backgroundImage,t.x,t.width,t.y,t.height));for(let n of t.children)MM(e,n,i)}function MM(e,t,n){t.type===`text`?AM(e,t,n):jM(e,t)}function NM(e){let{html:t,width:n,height:r,accuracy:i=`performance`,debug:a}=e;if(!n||n<=0||Number.isNaN(n))throw TypeError(`layout: width must be a positive number, got ${n}`);let o=i===`balanced`,{fragment:s,css:c}=mj(t),{tree:l,cleanup:u}=Ej(s,c,n),d=document.createElement(`canvas`).getContext(`2d`);d.fontKerning=`normal`;let{root:f,height:p,lines:m}=SM(d,l,n,o,a),h=r||p;return u(),{layoutRoot:f,height:h,lines:m}}function PM(e){let{layout:t,width:n,pixelRatio:r=globalThis.devicePixelRatio??1}=e;if(e.ctx&&e.canvas)throw TypeError(`drawLayout: ctx and canvas are mutually exclusive — provide one or neither`);let i=t.height,a,o;return e.ctx?(o=e.ctx,a=e.ctx.canvas):(a=e.canvas??document.createElement(`canvas`),a.width=Math.ceil(n*r),a.height=Math.ceil(i*r),`style`in a&&(a.style.width=`${n}px`,a.style.height=`${i}px`),o=a.getContext(`2d`),o.scale(r,r)),MM(o,t.layoutRoot),{canvas:a}}var FM=/[MmLlHhVvCcSsQqTtAaZz]/,IM=/-?(?:\d+\.\d+|\d+\.|\.\d+|\d+)(?:[eE][-+]?\d+)?/g;function LM(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(FM.test(r)){let i=n+1;for(;i<e.length&&!FM.test(e[i]);)i++;let a=e.slice(n+1,i),o=[],s;for(IM.lastIndex=0;s=IM.exec(a);)o.push(Number(s[0]));t.push({cmd:r,args:o}),n=i}else n++}return t}function RM(e){let t=LM(e),n=[],r=0,i=0,a=0,o=0,s=null,c=null;for(let e of t){let t=e.cmd,l=t.toUpperCase(),u=t!==l,d=e.args,f=e=>u?r+e:e,p=e=>u?i+e:e,m=!0,h=!0;switch(l){case`M`:for(let e=0;e<d.length;e+=2){let t=u&&e>0?r+d[e]:f(d[e]),s=u&&e>0?i+d[e+1]:p(d[e+1]);e===0?(r=t,i=s,a=t,o=s):(n.push({type:`L`,x0:r,y0:i,x1:t,y1:s}),r=t,i=s)}break;case`L`:for(let e=0;e<d.length;e+=2){let t=f(d[e]),a=p(d[e+1]);n.push({type:`L`,x0:r,y0:i,x1:t,y1:a}),r=t,i=a}break;case`H`:for(let e=0;e<d.length;e++){let t=u?r+d[e]:d[e];n.push({type:`L`,x0:r,y0:i,x1:t,y1:i}),r=t}break;case`V`:for(let e=0;e<d.length;e++){let t=u?i+d[e]:d[e];n.push({type:`L`,x0:r,y0:i,x1:r,y1:t}),i=t}break;case`C`:for(let e=0;e<d.length;e+=6){let t=f(d[e]),a=p(d[e+1]),o=f(d[e+2]),c=p(d[e+3]),l=f(d[e+4]),u=p(d[e+5]);n.push({type:`C`,x0:r,y0:i,c1x:t,c1y:a,c2x:o,c2y:c,x1:l,y1:u}),s={x:o,y:c},r=l,i=u}m=!1;break;case`S`:for(let e=0;e<d.length;e+=4){let t=s?2*r-s.x:r,a=s?2*i-s.y:i,o=f(d[e]),c=p(d[e+1]),l=f(d[e+2]),u=p(d[e+3]);n.push({type:`C`,x0:r,y0:i,c1x:t,c1y:a,c2x:o,c2y:c,x1:l,y1:u}),s={x:o,y:c},r=l,i=u}m=!1;break;case`Q`:for(let e=0;e<d.length;e+=4){let t=f(d[e]),a=p(d[e+1]),o=f(d[e+2]),s=p(d[e+3]);n.push({type:`Q`,x0:r,y0:i,cx:t,cy:a,x1:o,y1:s}),c={x:t,y:a},r=o,i=s}h=!1;break;case`T`:for(let e=0;e<d.length;e+=2){let t=c?2*r-c.x:r,a=c?2*i-c.y:i,o=f(d[e]),s=p(d[e+1]);n.push({type:`Q`,x0:r,y0:i,cx:t,cy:a,x1:o,y1:s}),c={x:t,y:a},r=o,i=s}h=!1;break;case`A`:for(let e=0;e<d.length;e+=7){let t=d[e],a=d[e+1],o=d[e+2],s=d[e+3]!==0,c=d[e+4]!==0,l=f(d[e+5]),u=p(d[e+6]);t===0||a===0?(r!==l||i!==u)&&n.push({type:`L`,x0:r,y0:i,x1:l,y1:u}):r===l&&i===u||n.push({type:`A`,x0:r,y0:i,rx:t,ry:a,xAxisRotation:o,largeArc:s,sweep:c,x1:l,y1:u}),r=l,i=u}break;case`Z`:(r!==a||i!==o)&&n.push({type:`L`,x0:r,y0:i,x1:a,y1:o}),r=a,i=o;break;default:break}m&&(s=null),h&&(c=null)}return n}function zM(e,t){let n=1-t,r=n*n,i=t*t;return{x:n*r*e.x0+3*r*t*e.c1x+3*n*i*e.c2x+i*t*e.x1,y:n*r*e.y0+3*r*t*e.c1y+3*n*i*e.c2y+i*t*e.y1}}function BM(e,t){let n=1-t;return{x:n*n*e.x0+2*n*t*e.cx+t*t*e.x1,y:n*n*e.y0+2*n*t*e.cy+t*t*e.y1}}function VM(e){let t=Math.abs(e.rx),n=Math.abs(e.ry),r=e.xAxisRotation*Math.PI/180,i=Math.cos(r),a=Math.sin(r),o=(e.x0-e.x1)/2,s=(e.y0-e.y1)/2,c=i*o+a*s,l=-a*o+i*s,u=c*c/(t*t)+l*l/(n*n);if(u>1){let e=Math.sqrt(u);t*=e,n*=e}let d=e.largeArc===e.sweep?-1:1,f=t*t*n*n-t*t*l*l-n*n*c*c,p=t*t*l*l+n*n*c*c,m=Math.sqrt(Math.max(0,f/p)),h=d*m*(t*l/n),g=d*m*(-(n*c)/t),_=i*h-a*g+(e.x0+e.x1)/2,v=a*h+i*g+(e.y0+e.y1)/2,y=(e,t,n,r)=>{let i=e*n+t*r,a=Math.sqrt((e*e+t*t)*(n*n+r*r)),o=Math.acos(Math.min(1,Math.max(-1,i/a)));return e*r-t*n<0&&(o=-o),o},b=y(1,0,(c-h)/t,(l-g)/n),x=y((c-h)/t,(l-g)/n,(-c-h)/t,(-l-g)/n);return x%=2*Math.PI,!e.sweep&&x>0?x-=2*Math.PI:e.sweep&&x<0&&(x+=2*Math.PI),{cx:_,cy:v,rx:t,ry:n,phi:r,theta1:b,deltaTheta:x,cosPhi:i,sinPhi:a}}function HM(e,t){let{cx:n,cy:r,rx:i,ry:a,cosPhi:o,sinPhi:s,theta1:c,deltaTheta:l}=VM(e),u=c+t*l,d=i*Math.cos(u),f=a*Math.sin(u);return{x:o*d-s*f+n,y:s*d+o*f+r}}var UM=40;function WM(e){let t=[],n=0;for(let r of e){if(r.type===`L`){let e=Math.hypot(r.x1-r.x0,r.y1-r.y0);t.push({startLen:n,length:e,seg:r}),n+=e;continue}let e=[],i=0,a;a=r.type===`C`||r.type===`Q`?{x:r.x0,y:r.y0}:HM(r,0),e.push({t:0,len:0});for(let t=1;t<=UM;t++){let n=t/UM,o;o=r.type===`C`?zM(r,n):r.type===`Q`?BM(r,n):HM(r,n),i+=Math.hypot(o.x-a.x,o.y-a.y),e.push({t:n,len:i}),a=o}t.push({startLen:n,length:i,seg:r,samples:e}),n+=i}function r(e){if(!Number.isFinite(e)||e<0||e>n+1e-6)return null;if(e===0&&t.length>0){let e=t[0].seg;return e.type===`L`||e.type===`C`||e.type===`Q`?{x:e.x0,y:e.y0}:HM(e,0)}for(let n=0;n<t.length;n++){let r=t[n];if(e>r.startLen+r.length+1e-6)continue;let i=e-r.startLen;if(r.seg.type===`L`){let e=r.length===0?0:Math.max(0,Math.min(1,i/r.length));return{x:r.seg.x0+(r.seg.x1-r.seg.x0)*e,y:r.seg.y0+(r.seg.y1-r.seg.y0)*e}}let a=r.samples,o=0,s=a.length-1;for(;s-o>1;){let e=o+s>>1;a[e].len<=i?o=e:s=e}let c=a[o],l=a[s],u=l.len-c.len,d=u===0?0:(i-c.len)/u,f=Math.max(0,Math.min(1,c.t+(l.t-c.t)*d));return r.seg.type===`C`?zM(r.seg,f):r.seg.type===`Q`?BM(r.seg,f):HM(r.seg,f)}return null}return{length:n,getPointAtLength:r}}function GM(e){return WM(RM(e))}var KM;function qM(){if(KM!==void 0)return KM;if(typeof Intl<`u`&&typeof Intl.Segmenter==`function`)try{KM=new Intl.Segmenter(void 0,{granularity:`grapheme`})}catch{KM=null}else KM=null;return KM}function JM(e){if(!e)return[];let t=qM();if(t){let n=[];for(let r of t.segment(e))n.push(r.segment);return n}return Array.from(e)}function YM(e,t,n){switch(e){case`alphabetic`:return 0;case`middle`:return(t-n)/2;case`top`:return t;case`bottom`:return-n;case`hanging`:return t*.8;case`ideographic`:return-n*.5}}function XM(e){let t=[];function n(e,r){let i=e.style.direction===`rtl`||r;if(e.tagName===`#text`&&e.textContent){t.push({text:e.textContent,style:e.style,rtl:i});return}for(let t of e.children)n(t,i)}return n(e,!1),t}var ZM=RegExp(`[\\u0590-\\u05FF\\u0600-\\u06FF\\u0700-\\u074F\\u0750-\\u077F\\u0780-\\u07BF\\u07C0-\\u07FF\\u0800-\\u083F\\u0840-\\u085F\\u0860-\\u086F\\u08A0-\\u08FF\\u0900-\\u097F\\u0980-\\u09FF\\u0A00-\\u0A7F\\u0A80-\\u0AFF\\u0B00-\\u0B7F\\u0B80-\\u0BFF\\u0C00-\\u0C7F\\u0C80-\\u0CFF\\u0D00-\\u0D7F\\u0D80-\\u0DFF\\u0E00-\\u0E7F\\u0E80-\\u0EFF\\u0F00-\\u0FFF\\u1000-\\u109F\\u1780-\\u17FF\\u1800-\\u18AF\\uFB1D-\\uFB4F\\uFB50-\\uFDFF\\uFE70-\\uFEFF]`);function QM(e){return ZM.test(e)}function $M(e,t){let n=JM(t.text);if(n.length===0)return[];Mj(e,t.style),e.letterSpacing=`${t.style.letterSpacing||0}px`;let{ascent:r,descent:i}=Yj(e,t.style),a=[],o=``;for(let e of n){let t=e===` `;QM(e)&&!t?o+=e:(o&&=(a.push({text:o,shaped:!0,isSpace:!1}),``),a.push({text:e,shaped:!1,isSpace:t}))}o&&a.push({text:o,shaped:!0,isSpace:!1}),t.rtl&&a.reverse();let s=[];for(let n of a){let a=e.measureText(n.text).width;s.push({text:n.text,width:a,style:t.style,isSpace:n.isSpace,ascent:r,descent:i,shaped:n.shaped})}return s}function eN(e){let{segments:t,path:n,ctx:r,align:i,textBaseline:a}=e,o=[],s=0,c=0;for(let e of t){if(!e.text)continue;let t=e.style.lineHeight>0?e.style.lineHeight:e.style.fontSize;t>c&&(c=t);let n=$M(r,e);n.length!==0&&(o.push(...n),s+=r.measureText(e.text).width)}let l=0;for(let e of o)l+=e.width+(e.style.letterSpacing||0);o.length>0&&(l-=o[o.length-1].style.letterSpacing||0);let u=Math.max(0,l-s),d=n.length,f=0,p=0;if(i===`center`)f=Math.max(0,(d-l)/2);else if(i===`right`)f=Math.max(0,d-l);else if(i===`justify`){let e=o.filter(e=>e.isSpace).length;e>0&&d>l&&(p=(d-l)/e)}let m=[],h=f,g=0;for(let e=0;e<o.length;e++){let t=o[e],r=t.width+(t.isSpace?p:0),i=n.getPointAtLength(h);if(!i)break;let a=h+r,s;if(a>d)if(a-d<=u+.5)s=n.getPointAtLength(d);else break;else s=n.getPointAtLength(a);if(!s)break;let c=Math.atan2(s.y-i.y,s.x-i.x);m.push({char:t.text,x:i.x,y:i.y,rotation:c,width:t.width,style:t.style,ascent:t.ascent,descent:t.descent,pathOffset:g,shaped:t.shaped}),h=a+(t.style.letterSpacing||0),g+=t.width+(t.style.letterSpacing||0)}let _=tN(m,a);return{glyphs:m,textWidth:l,pathLength:d,lineHeight:c,bounds:_,textBaseline:a}}function tN(e,t){if(e.length===0)return{x:0,y:0,width:0,height:0};let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let o of e){let e=o.style.lineHeight>0?o.style.lineHeight:o.style.fontSize,s=o.ascent+o.descent,c=s>0?o.ascent/s:.75,l=e*c,u=e*(1-c),d=YM(t,o.ascent,o.descent),f=d-l,p=d+u,m=Math.cos(o.rotation),h=Math.sin(o.rotation),g=[{x:o.x+-h*f,y:o.y+m*f},{x:o.x+m*o.width+-h*f,y:o.y+h*o.width+m*f},{x:o.x+m*o.width+-h*p,y:o.y+h*o.width+m*p},{x:o.x+-h*p,y:o.y+m*p}];for(let e of g)e.x<n&&(n=e.x),e.y<r&&(r=e.y),e.x>i&&(i=e.x),e.y>a&&(a=e.y)}return{x:n,y:r,width:i-n,height:a-r}}function nN(e){let{html:t,align:n=`left`,textBaseline:r=`alphabetic`}=e,i=typeof e.path==`string`?GM(e.path):e.path,a=e.ctx??iN(),o=e.ctx===void 0,{fragment:s,css:c}=mj(t),{tree:l,cleanup:u}=Ej(s,c,2**53-1);o||a.save();try{return eN({segments:XM(l),path:i,ctx:a,align:n,textBaseline:r})}finally{o||a.restore(),u()}}function rN(e){let{layout:t,ctx:n}=e;if(t.glyphs.length===0)return;let r=t.textBaseline;n.save();try{sN(n,t.glyphs,r),uN(n,t.glyphs,t.textWidth,r),pN(n,t.glyphs,r)}finally{n.restore()}}function iN(){return(typeof OffscreenCanvas<`u`?new OffscreenCanvas(1,1):document.createElement(`canvas`)).getContext(`2d`)}var aN=new WeakMap;function oN(e,t){if(!t)return``;let n=aN.get(e);n||(n=new Map,aN.set(e,n));let r=n.get(t);if(r!==void 0)return r;let i=e.fillStyle;try{e.fillStyle=t;let r=typeof e.fillStyle==`string`?e.fillStyle:t;return n.set(t,r),r}catch{return n.set(t,t),t}finally{e.fillStyle=i}}function sN(e,t,n){let r=0;for(;r<t.length;){let i=t[r].style.backgroundColor;if(!i||qj(i)){r++;continue}let a=oN(e,i),o=r+1;for(;o<t.length&&oN(e,t[o].style.backgroundColor)===a;)o++;lN(e,t.slice(r,o),i,n),r=o}}function cN(e,t){let n=Math.cos(e.rotation),r=Math.sin(e.rotation),i=YM(t,e.ascent,e.descent),a=i-e.ascent,o=i+e.descent,s=e.width;return{tl:{x:e.x+-r*a,y:e.y+n*a},tr:{x:e.x+n*s+-r*a,y:e.y+r*s+n*a},br:{x:e.x+n*s+-r*o,y:e.y+r*s+n*o},bl:{x:e.x+-r*o,y:e.y+n*o}}}function lN(e,t,n,r){if(t.length===0)return;e.save(),e.fillStyle=n,e.beginPath();let i=cN(t[0],r);e.moveTo(i.tl.x,i.tl.y);for(let n=0;n<t.length;n++){let i=cN(t[n],r);e.lineTo(i.tl.x,i.tl.y),e.lineTo(i.tr.x,i.tr.y)}for(let n=t.length-1;n>=0;n--){let i=cN(t[n],r);e.lineTo(i.br.x,i.br.y),e.lineTo(i.bl.x,i.bl.y)}e.closePath(),e.fill(),e.restore()}function uN(e,t,n,r){for(let i of t){e.save(),e.translate(i.x,i.y),e.rotate(i.rotation),Mj(e,i.style),e.textBaseline=`alphabetic`,e.letterSpacing=`${i.style.letterSpacing||0}px`;let t=YM(r,i.ascent,i.descent),a=wM(i.style.textShadow);if(a.length>0)for(let n=a.length-1;n>=0;n--){let r=a[n];e.save(),e.shadowOffsetX=r.offsetX,e.shadowOffsetY=r.offsetY,e.shadowBlur=r.blur,e.shadowColor=r.color,e.fillStyle=hN(i.style),e.fillText(i.char,0,t),e.restore()}dN(e,i,n,t),e.restore()}}function dN(e,t,n,r){let{style:i}=t,a=i.webkitTextFillColor===`transparent`||i.color===`transparent`||qj(hN(i)),o=i.webkitTextStrokeWidth>0,s=i.webkitBackgroundClip===`text`&&i.backgroundImage&&i.backgroundImage!==`none`,c=yj(i.paintOrder||``),l=()=>{if(s){fN(e,t,n,r);return}if(a){if(o)return;e.fillStyle=`transparent`,e.fillText(t.char,0,r);return}e.fillStyle=hN(i),e.fillText(t.char,0,r)},u=()=>{o&&(e.save(),e.lineJoin=`round`,e.lineWidth=i.webkitTextStrokeWidth,e.strokeStyle=i.webkitTextStrokeColor||i.color,e.strokeText(t.char,0,r),e.restore())};c?(u(),l()):(l(),u())}function fN(e,t,n,r){let i=DM(e,t.style.backgroundImage,-t.pathOffset,n,r-t.ascent,t.ascent+t.descent);if(!i){e.fillStyle=hN(t.style),e.fillText(t.char,0,r);return}e.fillStyle=i,e.fillText(t.char,0,r)}function pN(e,t,n){for(let r of[`underline`,`line-through`,`overline`]){let i=0;for(;i<t.length;){let a=t[i].style;if(!a.textDecorationLine||!a.textDecorationLine.includes(r)){i++;continue}let o=a.textDecorationColor||a.color,s=a.textDecorationStyle||`solid`,c=oN(e,o),l=i+1;for(;l<t.length&&t[l].style.textDecorationLine&&t[l].style.textDecorationLine.includes(r)&&oN(e,t[l].style.textDecorationColor||t[l].style.color)===c&&(t[l].style.textDecorationStyle||`solid`)===s;)l++;mN(e,t.slice(i,l),r,s,o,n),i=l}}}function mN(e,t,n,r,i,a){if(t.length===0)return;let o=Math.max(1,t[0].style.fontSize/15),s=e=>{let t=YM(a,e.ascent,e.descent);return n===`underline`?t+e.descent*.5:n===`line-through`?t-e.ascent*.3:t-e.ascent*.9};if(r===`double`||r===`wavy`){for(let n of t)e.save(),e.translate(n.x,n.y),e.rotate(n.rotation),EM(e,0,s(n),n.width,o,r,i),e.restore();return}e.save(),e.strokeStyle=i,e.lineWidth=o,r===`dotted`?e.setLineDash([o,o*2]):r===`dashed`&&e.setLineDash([o*3,o*2]),e.beginPath();for(let n=0;n<t.length;n++){let r=t[n],i=s(r),a=Math.cos(r.rotation),o=Math.sin(r.rotation),c={x:r.x+-o*i,y:r.y+a*i},l={x:r.x+a*r.width+-o*i,y:r.y+o*r.width+a*i};n===0?e.moveTo(c.x,c.y):e.lineTo(c.x,c.y),e.lineTo(l.x,l.y)}e.stroke(),e.setLineDash([]),e.restore()}function hN(e){return e.webkitTextFillColor&&e.webkitTextFillColor!==`transparent`?e.webkitTextFillColor:e.color}var gN=`<style>${Py}
|
|
514
514
|
/* render-tag draws list markers natively from the <ol>/<ul> tag + tree position
|
|
515
515
|
(it ignores the polotno reset's ::before + counter() markers, which only work
|
|
516
516
|
in real DOM — the Quill editor and the foreignObject rasterizer). The shared
|
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}
|
package/utils/rich-text-html.js
CHANGED
|
@@ -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(/"/g,'"').replace(/&/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(/"/g,'"').replace(/&/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}
|
package/utils/validate-key.js
CHANGED
|
@@ -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.
|
|
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()}
|