polotno 3.15.1 → 3.15.2

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/utils/fonts.d.ts CHANGED
@@ -9,9 +9,11 @@ export declare function removeGlobalFont(fontFamily: string): void;
9
9
  export declare function replaceGlobalFonts(fonts: Array<FONT>): void;
10
10
  export declare function _getFontProbeTextForTesting(sampleText?: string): string;
11
11
  export declare function measureFontDom(fontName: string, fallback?: string, fontStyle?: string, fontWeight?: string, text?: string): number;
12
- export declare const isFontLoaded: (fontName: string, fontStyle?: string, fontWeight?: string) => boolean;
12
+ export declare const isFontLoaded: (fontName: string, fontStyle?: string, fontWeight?: string, text?: string) => boolean;
13
13
  export declare function _setFontLoadedForTesting(key: string, value: boolean): void;
14
14
  export declare function loadFont(fontName: string, fontStyle: string, fontWeight: string, sampleText?: string): Promise<void>;
15
+ export declare function textChars(text?: string): string;
16
+ export declare function loadFontFace(fontName: string, fontStyle: string, fontWeight: string, sampleText?: string): Promise<void>;
15
17
  export declare function injectGoogleFontVariant(fontName: string, fontStyle: string, fontWeight: string): void;
16
18
  export declare function injectGoogleFont(fontName: string): void;
17
19
  export type FONT = {
package/utils/fonts.js CHANGED
@@ -1 +1 @@
1
- import*as t from"mobx";import{triggerLoadError as o,getFontLoadTimeout as n}from"./loader.js";import{polotnoError as e}from"@polotno/core/errors";import{removeTags as r}from"@polotno/core/text";import{DEFAULT_RETRIES as s,retryDelayMs as i}from"@polotno/core/retry";import{getGoogleFontsUrl as a,getGoogleFontsVariants as c}from"@polotno/core/google-fonts-url";import{resolveFontFaceStyles as l,googleFontVariantUrl as u,cssFontFamily as f}from"@polotno/core/fonts";export{setGoogleFontsVariants,getGoogleFontsVariants,getGoogleFontsUrl}from"@polotno/core/google-fonts-url";const d=["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"];let m=t.observable([...d]),p=t.observable({value:!1});export function isGoogleFontChanged(){return p.value}export function setGoogleFonts(t){if("default"===t){return m.replace([...d]),void(p.value=!1)}p.value=!0,m.splice(0,m.length),m.push(...t)}export function getFontsList(){return m}export const globalFonts=t.observable([]);export function addGlobalFont(t){globalFonts.push(t)}export function removeGlobalFont(t){const o=globalFonts.findIndex(o=>o.fontFamily===t);-1!==o&&globalFonts.splice(o,1)}export function replaceGlobalFonts(t){globalFonts.replace(t)}const g="BESbswy 0123456789 Il1Ww",x=["sans-serif","serif","monospace"];function h(t){const o=function(t=""){const o=r(t).replace(/\s+/g," ").trim();return o?Array.from(o).slice(0,10).join(""):""}(t);return o?`${g} ${o}`:g}export function _getFontProbeTextForTesting(t){return h(t)}let F;function $(t){return{width:t.width,actualBoundingBoxLeft:t.actualBoundingBoxLeft||0,actualBoundingBoxRight:t.actualBoundingBoxRight||0,actualBoundingBoxAscent:t.actualBoundingBoxAscent||0,actualBoundingBoxDescent:t.actualBoundingBoxDescent||0}}function y(t="sans-serif",o="normal",n="normal",e=g){F||(F=document.createElement("canvas"));const r=F.getContext("2d");return r.font=`${o} ${n} 40px ${t}`,$(r.measureText(e))}function B(t,o,n,e,r){return x.some(s=>{const i=function(t,o="sans-serif",n="normal",e="normal",r=g){F||(F=document.createElement("canvas"));const s=F.getContext("2d");return s.font=`${n} ${e} 40px ${f(t)}, ${o}`,$(s.measureText(r))}(t,s,o,n,e);return function(t,o,n=.01){return Math.abs(t.width-o.width)>n||Math.abs(t.actualBoundingBoxLeft-o.actualBoundingBoxLeft)>n||Math.abs(t.actualBoundingBoxRight-o.actualBoundingBoxRight)>n||Math.abs(t.actualBoundingBoxAscent-o.actualBoundingBoxAscent)>n||Math.abs(t.actualBoundingBoxDescent-o.actualBoundingBoxDescent)>n}(i,r[s])})}export function measureFontDom(t,o="sans-serif",n="normal",e="normal",r=g){if("undefined"==typeof document||!document.body){return 0}const s=document.createElement("span");s.textContent=r,s.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${n} ${e} 90px ${f(t)}, ${o};\n `,document.body.appendChild(s);const i=s.getBoundingClientRect().width;return s.remove(),i}const b={Arial:!0};export const isFontLoaded=(t,o,n)=>o&&n?!!b[`${t}_${o}_${n}`]:Object.keys(b).some(o=>o.startsWith(t+"_"))||!!b[t];export function _setFontLoadedForTesting(t,o){o?b[t]=!0:delete b[t]}export async function loadFont(t,r,s,a){var c;const l=`${t}_${r}_${s}`;if(injectGoogleFontVariant(t,r,s),b[l]&&!A(t,r,s)){return}const u=!!(null===(c=document.fonts)||void 0===c?void 0:c.load),d=h(a),m={"sans-serif":y("sans-serif",r,s,d),serif:y("serif",r,s,d),monospace:y("monospace",r,s,d)};if(u){try{if(await document.fonts.load(`${r} ${s} 16px ${f(t)}`,d),B(t,r,s,d,m)&&!A(t,r,s)){return void G(l,t)}}catch(g){}}const p=n()/60;for(let n=0;n<p;n++){if(u){try{await document.fonts.load(`${r} ${s} 16px ${f(t)}`,d)}catch(x){}}if(B(t,r,s,d,m)&&!A(t,r,s)){return void G(l,t)}if("missing"===v[t]){if(E(t)){const n=`Font "${t}" not found: not registered and no matching Google Font.`;console.error(n),o(e("FONT_FAILED",n,{family:t,reason:"not-found"}))}return}if(t in w&&!w[t]&&"errored"===v[t]&&injectGoogleFont(t),D[t]&&N(t)){const r=L(t);if("wait"===r){await new Promise(t=>setTimeout(t,60));continue}if("spent"!==r){O(t);const o=i(r);await new Promise(t=>setTimeout(t,o)),n+=Math.ceil(o/60);continue}if(E(t)){const n=`Failed to load font "${t}": its font file could not be fetched.`;console.error(n),o(e("FONT_FAILED",n,{family:t,reason:"fetch-failed"}))}return}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?`),o(e("FONT_FAILED",`Timeout for loading font "${t}"`,{family:t,reason:"timeout"}))}const w={},v={},T=new Set;function E(t){return!T.has(t)&&(T.add(t),setTimeout(()=>T.delete(t),n()),!0)}function G(t,o){b[t]=!0,delete v[o],delete C[o]}const C={};function L(t){const o=C[t],e=!o||Date.now()-o.at>n()?0:o.spent;return e>=s-1?"spent":o&&e>0&&Date.now()-o.at<i(e)?"wait":(C[t]={spent:e+1,at:Date.now()},e+1)}const R={};function A(t,o,n){return"loading"===w[t]||"loading"===R[`${t}|${"italic"===o?1:0}|${parseInt(n,10)}`]}export function injectGoogleFontVariant(t,o,n){const e=parseInt(n,10);if(!Number.isFinite(e)){return}if(function(t){const o=new Set;for(const n of c().split(",")){const e=n.trim().match(/^(\d+)(italic|i)?$/);e&&!!e[2]===t&&o.add(parseInt(e[1],10))}return o}("italic"===o).has(e)){return}if(!(t in w)){return}const r="italic"===o,s=`${t}|${r?1:0}|${e}`;if(R[s]){return}R[s]="loading";const i=document.createElement("link");i.type="text/css",i.href=u(t,r,e),i.rel="stylesheet",i.onload=()=>{R[s]=!0},i.onerror=()=>{R[s]=!0,i.remove()},document.getElementsByTagName("head")[0].appendChild(i)}export function injectGoogleFont(t){if(w[t]){return}const o=a(t),n=document.createElement("link");n.type="text/css",n.href=o,n.rel="stylesheet",n.onload=()=>{w[t]=!0},n.onerror=()=>{n.remove(),w[t]=!1,"errored"===v[t]?function(t){v[t]="probing",fetch(a(t),{mode:"no-cors"}).then(()=>{v[t]="missing"}).catch(()=>{delete v[t]})}(t):v[t]||(v[t]="errored")},document.getElementsByTagName("head")[0].appendChild(n),w[t]="loading"}const D={};let _;function I(){return _||(_=document.getElementById("polotno-font-style"),_||(_=document.createElement("style"),_.id="polotno-font-style",document.head.appendChild(_)),_)}function j(t){const o=t.fontFamily,n=l(t),e=I().sheet;return n.map(t=>{const n=e.insertRule(`\n @font-face{\n font-family:${f(o)};\n src:${t.src};\n font-style:${t.fontStyle};\n font-weight:${t.fontWeight};\n font-display:swap; /* optional but recommended */\n }`,e.cssRules.length);return e.cssRules[n]})}export function injectCustomFont(t){const o=t.fontFamily;if(!t.url&&!t.styles){return}const n=JSON.stringify(l(t)),e=D[o];if(e){if(e.src===n){return}k(e.rules),M(o)}delete v[o],D[o]={font:t,src:n,rules:j(t)}}function k(t){const o=I().sheet;for(const n of t){const t=Array.prototype.indexOf.call(o.cssRules,n);t>=0&&o.deleteRule(t)}}export function removeCustomFont(t){const o=D[t];o&&(k(o.rules),delete D[t],M(t))}function M(t){delete C[t];for(const o of Object.keys(b)){(o===t||o.startsWith(t+"_"))&&delete b[o]}}function O(t){const o=D[t];o&&(k(o.rules),o.rules=j(o.font))}const S=t=>t.trim().replace(/^["']|["']$/g,"").toLowerCase();function N(t){const o=document.fonts;if(!o||"function"!=typeof o.forEach){return!1}const n=S(t);let e=!1;return o.forEach(t=>{"error"===t.status&&S(t.family)===n&&(e=!0)}),e}
1
+ import*as t from"mobx";import{triggerLoadError as o,getFontLoadTimeout as n}from"./loader.js";import{polotnoError as e}from"@polotno/core/errors";import{removeTags as r}from"@polotno/core/text";import{DEFAULT_RETRIES as s,retryDelayMs as i}from"@polotno/core/retry";import{getGoogleFontsUrl as a,getGoogleFontsVariants as c}from"@polotno/core/google-fonts-url";import{resolveFontFaceStyles as l,googleFontVariantUrl as u,cssFontFamily as f}from"@polotno/core/fonts";export{setGoogleFontsVariants,getGoogleFontsVariants,getGoogleFontsUrl}from"@polotno/core/google-fonts-url";const d=["Roboto","Amatic SC","Press Start 2P","Marck Script","Rubik Mono One"];let m=t.observable([...d]),p=t.observable({value:!1});export function isGoogleFontChanged(){return p.value}export function setGoogleFonts(t){if("default"===t){return m.replace([...d]),void(p.value=!1)}p.value=!0,m.splice(0,m.length),m.push(...t)}export function getFontsList(){return m}export const globalFonts=t.observable([]);export function addGlobalFont(t){globalFonts.push(t)}export function removeGlobalFont(t){const o=globalFonts.findIndex(o=>o.fontFamily===t);-1!==o&&globalFonts.splice(o,1)}export function replaceGlobalFonts(t){globalFonts.replace(t)}const g="BESbswy 0123456789 Il1Ww",h=["sans-serif","serif","monospace"];function x(t){const o=function(t=""){const o=r(t).replace(/\s+/g," ").trim();return o?Array.from(o).slice(0,10).join(""):""}(t);return o?`${g} ${o}`:g}export function _getFontProbeTextForTesting(t){return x(t)}let F;function y(t){return{width:t.width,actualBoundingBoxLeft:t.actualBoundingBoxLeft||0,actualBoundingBoxRight:t.actualBoundingBoxRight||0,actualBoundingBoxAscent:t.actualBoundingBoxAscent||0,actualBoundingBoxDescent:t.actualBoundingBoxDescent||0}}function $(t="sans-serif",o="normal",n="normal",e=g){F||(F=document.createElement("canvas"));const r=F.getContext("2d");return r.font=`${o} ${n} 40px ${t}`,y(r.measureText(e))}function B(t,o,n,e,r){return h.some(s=>{const i=function(t,o="sans-serif",n="normal",e="normal",r=g){F||(F=document.createElement("canvas"));const s=F.getContext("2d");return s.font=`${n} ${e} 40px ${f(t)}, ${o}`,y(s.measureText(r))}(t,s,o,n,e);return function(t,o,n=.01){return Math.abs(t.width-o.width)>n||Math.abs(t.actualBoundingBoxLeft-o.actualBoundingBoxLeft)>n||Math.abs(t.actualBoundingBoxRight-o.actualBoundingBoxRight)>n||Math.abs(t.actualBoundingBoxAscent-o.actualBoundingBoxAscent)>n||Math.abs(t.actualBoundingBoxDescent-o.actualBoundingBoxDescent)>n}(i,r[s])})}export function measureFontDom(t,o="sans-serif",n="normal",e="normal",r=g){if("undefined"==typeof document||!document.body){return 0}const s=document.createElement("span");s.textContent=r,s.style.cssText=`\n position:absolute;\n visibility:hidden;\n white-space:nowrap;\n top:-9999px;\n left:-9999px;\n font:${n} ${e} 90px ${f(t)}, ${o};\n `,document.body.appendChild(s);const i=s.getBoundingClientRect().width;return s.remove(),i}const w={Arial:!0},b={};export const isFontLoaded=(t,o,n,e)=>{var r;if(o&&n){const i=`${t}_${o}_${n}`;if(!w[i]){return!1}const a=textChars(e),c=b[i];if([...a].every(t=>null==c?void 0:c.has(t))){return!0}try{return!!(null===(r=document.fonts)||void 0===r?void 0:r.check(v(t,o,n),a))}catch(s){return!1}}return Object.keys(w).some(o=>o.startsWith(t+"_"))||!!w[t]};export function _setFontLoadedForTesting(t,o){o?w[t]=!0:delete w[t]}export async function loadFont(t,o,e,r){var s;const i=performance.now()+n();await loadFontFace(t,o,e,r);const a=textChars(r),c=()=>{var n,r;const s=null!==(n=b[r=`${t}_${o}_${e}`])&&void 0!==n?n:b[r]=new Set;for(const t of a){s.add(t)}};if(!a||!(null===(s=document.fonts)||void 0===s?void 0:s.load)){return c()}let l;await Promise.race([document.fonts.load(v(t,o,e),a).catch(()=>{}).then(c),new Promise(t=>{l=setTimeout(t,Math.max(0,i-performance.now()))})]),clearTimeout(l)}const v=(t,o,n)=>`${o} ${n} 16px ${f(t)}`;export function textChars(t){return[...new Set(r(null!=t?t:"").replace(/\s/g,""))].join("")}export async function loadFontFace(t,r,s,a){var c;const l=`${t}_${r}_${s}`;if(injectGoogleFontVariant(t,r,s),w[l]&&!D(t,r,s)){return}const u=!!(null===(c=document.fonts)||void 0===c?void 0:c.load),f=x(a),d={"sans-serif":$("sans-serif",r,s,f),serif:$("serif",r,s,f),monospace:$("monospace",r,s,f)};if(u){try{const o=!D(t,r,s);if(await document.fonts.load(v(t,r,s),f),B(t,r,s,f,d)&&o){return void _(l,t)}}catch(p){}}const m=n()/60;for(let n=0;n<m;n++){const a=!D(t,r,s);if(u){try{await document.fonts.load(v(t,r,s),f)}catch(g){}}if(B(t,r,s,f,d)&&a){return void _(l,t)}if("missing"===C[t]){if(G(t)){const n=`Font "${t}" not found: not registered and no matching Google Font.`;console.error(n),o(e("FONT_FAILED",n,{family:t,reason:"not-found"}))}return}if(t in T&&!T[t]&&"errored"===C[t]&&injectGoogleFont(t),j[t]&&V(t)){const r=R(t);if("wait"===r){await new Promise(t=>setTimeout(t,60));continue}if("spent"!==r){P(t);const o=i(r);await new Promise(t=>setTimeout(t,o)),n+=Math.ceil(o/60);continue}if(G(t)){const n=`Failed to load font "${t}": its font file could not be fetched.`;console.error(n),o(e("FONT_FAILED",n,{family:t,reason:"fetch-failed"}))}return}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?`),o(e("FONT_FAILED",`Timeout for loading font "${t}"`,{family:t,reason:"timeout"}))}const T={},C={},E=new Set;function G(t){return!E.has(t)&&(E.add(t),setTimeout(()=>E.delete(t),n()),!0)}function _(t,o){w[t]=!0,delete C[o],delete L[o]}const L={};function R(t){const o=L[t],e=!o||Date.now()-o.at>n()?0:o.spent;return e>=s-1?"spent":o&&e>0&&Date.now()-o.at<i(e)?"wait":(L[t]={spent:e+1,at:Date.now()},e+1)}const A={};function D(t,o,n){return"loading"===T[t]||"loading"===A[`${t}|${"italic"===o?1:0}|${parseInt(n,10)}`]}export function injectGoogleFontVariant(t,o,n){const e=parseInt(n,10);if(!Number.isFinite(e)){return}if(function(t){const o=new Set;for(const n of c().split(",")){const e=n.trim().match(/^(\d+)(italic|i)?$/);e&&!!e[2]===t&&o.add(parseInt(e[1],10))}return o}("italic"===o).has(e)){return}if(!(t in T)){return}const r="italic"===o,s=`${t}|${r?1:0}|${e}`;if(A[s]){return}A[s]="loading";const i=document.createElement("link");i.type="text/css",i.href=u(t,r,e),i.rel="stylesheet",i.onload=()=>{A[s]=!0},i.onerror=()=>{A[s]=!0,i.remove()},document.getElementsByTagName("head")[0].appendChild(i)}export function injectGoogleFont(t){if(T[t]){return}const o=a(t),n=document.createElement("link");n.type="text/css",n.href=o,n.rel="stylesheet",n.onload=()=>{T[t]=!0},n.onerror=()=>{n.remove(),T[t]=!1,"errored"===C[t]?function(t){C[t]="probing",fetch(a(t),{mode:"no-cors"}).then(()=>{C[t]="missing"}).catch(()=>{delete C[t]})}(t):C[t]||(C[t]="errored")},document.getElementsByTagName("head")[0].appendChild(n),T[t]="loading"}const j={};let I;function S(){return I||(I=document.getElementById("polotno-font-style"),I||(I=document.createElement("style"),I.id="polotno-font-style",document.head.appendChild(I)),I)}function k(t){const o=t.fontFamily,n=l(t),e=S().sheet;return n.map(t=>{const n=e.insertRule(`\n @font-face{\n font-family:${f(o)};\n src:${t.src};\n font-style:${t.fontStyle};\n font-weight:${t.fontWeight};\n font-display:swap; /* optional but recommended */\n }`,e.cssRules.length);return e.cssRules[n]})}export function injectCustomFont(t){const o=t.fontFamily;if(!t.url&&!t.styles){return}const n=JSON.stringify(l(t)),e=j[o];if(e){if(e.src===n){return}M(e.rules),O(o)}delete C[o],j[o]={font:t,src:n,rules:k(t)}}function M(t){const o=S().sheet;for(const n of t){const t=Array.prototype.indexOf.call(o.cssRules,n);t>=0&&o.deleteRule(t)}}export function removeCustomFont(t){const o=j[t];o&&(M(o.rules),delete j[t],O(t))}function O(t){delete L[t];for(const o of Object.keys(w)){(o===t||o.startsWith(t+"_"))&&(delete w[o],delete b[o])}}function P(t){const o=j[t];o&&(M(o.rules),o.rules=k(o.font))}const N=t=>t.trim().replace(/^["']|["']$/g,"").toLowerCase();function V(t){const o=document.fonts;if(!o||"function"!=typeof o.forEach){return!1}const n=N(t);let e=!1;return o.forEach(t=>{"error"===t.status&&N(t.family)===n&&(e=!0)}),e}
@@ -1 +1 @@
1
- import*as e from"mobx";import{getAPI as o}from"./api.js";import{removeBackgroundState 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||"";export const setKey=e=>{s=e||""};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 u=`%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 p=fetch;export const __=e=>{p=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await p(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"3.15.1"})});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(u,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{t.defaultEnabled=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){await isKeyPaid(s)&&!e||r()}
1
+ import*as e from"mobx";import{getAPI as o}from"./api.js";import{removeBackgroundState 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||"";export const setKey=e=>{s=e||""};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 u=`%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 p=fetch;export const __=e=>{p=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await p(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"3.15.2"})});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(u,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{t.defaultEnabled=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){await isKeyPaid(s)&&!e||r()}