polotno 2.36.10 → 2.37.1

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/to-svg.js CHANGED
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,e){var i={};for(var n in t){Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++){e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(i[n[r]]=t[n[r]])}}return i};import{cropImage as e,getCrop as i,loadImage as n}from"./image.js";import*as r from"./svg.js";import{figureToSvg as o}from"./figure-to-svg.js";import{Effects as a,shapeFilterToCSS as s}from"./filters.js";import{removeTags as l}from"./text.js";import{getCurvePath as h}from"../canvas/text-element.js";import*as c from"./gradient.js";export const forEveryChild=(t,e)=>{if(t.children){for(const i of t.children){if(!0===e(i)){break}forEveryChild(i,e)}}};const g=(t,e,...i)=>({type:t,props:e,children:i||[]});function d(t,e){if(!c.isGradient(t)){return null}const{stops:i,rotation:n}=c.parseColor(t),r=n*Math.PI/180,o=.5-.5*Math.sin(r),a=.5+.5*Math.cos(r),s=.5+.5*Math.sin(r),l=.5-.5*Math.cos(r),h=i.map(({offset:t,color:e})=>g("stop",{offset:100*t+"%","stop-color":e}));return g("linearGradient",{id:e,x1:100*o+"%",y1:100*a+"%",x2:100*s+"%",y2:100*l+"%"},...h)}export function fixRatio(t){var e=(new DOMParser).parseFromString(t,"image/svg+xml");return e.documentElement.setAttribute("preserveAspectRatio","none"),(new XMLSerializer).serializeToString(e)}const f=async t=>{try{const e=await fetch(t);if("undefined"!=typeof Buffer){const t=await e.arrayBuffer(),i=Buffer.from(t).toString("base64");return`data:${e.headers.get("content-type")||"image/png"};base64,${i}`}{const t=await e.blob();return new Promise((e,i)=>{const n=new FileReader;n.onloadend=()=>e(n.result),n.onerror=i,n.readAsDataURL(t)})}}catch(e){return console.error("Error converting URL to data URL:",e),t}},p=async({element:t,page:e,store:i})=>{let{src:o}=t;if("svg"===t.type){const e=await r.urlToString(o);o=r.replaceColors(e,new Map(Object.entries(t.colorsReplace)))}else{o=await f(o)}let a,s,l,h,p="";if(t.flipX||t.flipY){const e=t.flipX?-1:1,i=t.flipY?-1:1,n=t.width/2,r=t.height/2;p=`translate(${n}, ${r}) scale(${e}, ${i}) translate(${-n}, ${-r})`}t.clipSrc&&(a=`clip-img-mask-${t.id}`,s=await f(t.clipSrc)),t.maskSrc&&(l=`mask-img-${t.id}`,h=await f(t.maskSrc));const u=await n(o),m=u.width*t.cropWidth,y=u.height*t.cropHeight,w=t.width/t.height;let b,k;const $=m/y,x="boolean"==typeof t.stretchEnabled&&t.stretchEnabled||"svg"===t.type;x?(b=m,k=y):w>=$?(b=m,k=m/w):(b=y*w,k=y);const v=b/u.width,j=k/u.height,O=b/k>t.width/t.height?t.height/k:t.width/b,S=x?t.width/b:O,H=x?t.height/k:O,E=b*S/v,M=k*H/j;let W=t.cropX*u.width*S,C=t.cropY*u.height*H;t.flipX&&(W=(1-t.cropX-t.cropWidth)*u.width*S),t.flipY&&(C=(1-t.cropY-t.cropHeight)*u.height*H);const R=`clip-${t.id}`,L=t.cornerRadius||0,P=o.replace(/&/g,"&amp;"),T={x:-W,y:-C,width:E,height:M,preserveAspectRatio:"none","clip-path":`url(#${R})`},z=[g("clipPath",{id:R},g("rect",{x:0,y:0,width:t.width,height:t.height,rx:L||void 0,ry:L||void 0}))];a&&s&&z.push(g("mask",{id:a,maskUnits:"userSpaceOnUse","mask-type":"alpha"},g("image",{href:s.replace(/&/g,"&amp;"),x:0,y:0,width:t.width,height:t.height,preserveAspectRatio:"none"}))),l&&z.push(g("mask",{id:l,maskUnits:"userSpaceOnUse","mask-type":"alpha"},g("image",Object.assign({href:P},T))));let F=P;const A={};l&&h&&(F=h.replace(/&/g,"&amp;"),A.mask=`url(#${l})`);const B={};a&&(B.mask=`url(#${a})`);const G=t.borderSize||0,U=G>0&&c.isGradient(t.borderColor),D=U?`border-grad-${t.id}`:null;if(U){const e=d(t.borderColor,D);e&&z.push(e)}const X=G>0?g("rect",{x:G/2,y:G/2,width:Math.max(0,t.width-G),height:Math.max(0,t.height-G),fill:"none",stroke:U?`url(#${D})`:t.borderColor,"stroke-width":G,rx:Math.max(0,L-G)||void 0,ry:Math.max(0,L-G)||void 0}):null,Y=g("g",{},g("defs",{},...z),g("image",Object.assign(Object.assign({href:F},T),A)),X);return g("g",B,p?g("g",{transform:p},Y):Y)},u=({element:t,type:e})=>{const i={"stroke-width":t.height,stroke:t.color,"stroke-linecap":"round","stroke-linejoin":"round"},n=Object.assign(Object.assign({},i),{fill:t.color}),r=Object.assign(Object.assign({},i),{fill:"none"});return"arrow"===e?g("polyline",Object.assign({points:`${3*t.height},${2*-t.height} 0,0 ${3*t.height},${2*t.height}`},r)):"triangle"===e?g("polygon",Object.assign({points:`${3*t.height},${2*-t.height} 0,0 ${3*t.height},${2*t.height}`},n)):"bar"===e?g("polyline",Object.assign({points:`0,${2*-t.height} 0,${2*t.height}`},r)):"circle"===e?g("circle",Object.assign({cx:2*t.height,cy:0,r:2*t.height},n)):"square"===e?g("polygon",Object.assign({points:`0,${2*-t.height} ${4*t.height},${2*-t.height} ${4*t.height},${2*t.height} 0,${2*t.height}`},n)):null},m={image:p,svg:p,text:async({element:t,page:e,store:i})=>{const n=c.isGradient(t.fill),r=c.isGradient(t.stroke);if(t.curveEnabled){const e=h(t.width,t.height,t.curvePower,t.fontSize),i=`curve-path-${t.id}`,o=l(t.text).replace(/\n/g," "),a=t.backgroundPadding*(t.fontSize*t.lineHeight*.5),s=t.backgroundEnabled?g("rect",{x:-a,y:-a,width:t.width+2*a,height:t.height+2*a,fill:t.backgroundColor,opacity:t.backgroundOpacity,rx:t.backgroundCornerRadius*(t.fontSize*t.lineHeight*.5),ry:t.backgroundCornerRadius*(t.fontSize*t.lineHeight*.5)}):null,c=[g("path",{id:i,d:e,fill:"none"})],f=t.strokeWidth&&(r||n&&!r);if(n){const e=`curve-fill-grad-${t.id}`,i=d(t.fill,e);i&&c.push(i)}if(r&&t.strokeWidth){const e=`curve-stroke-grad-${t.id}`,i=d(t.stroke,e);i&&c.push(i)}if(f){const e={"font-size":t.fontSize+"px","text-anchor":"middle","dominant-baseline":"central","font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration||void 0,"letter-spacing":t.letterSpacing*t.fontSize+"px"},a=r?`url(#curve-stroke-grad-${t.id})`:t.stroke,l=g("text",Object.assign(Object.assign({},e),{fill:a,"stroke-width":t.strokeWidth,stroke:a}),g("textPath",{href:`#${i}`,startOffset:"50%",innerHTML:o})),h=n?`url(#curve-fill-grad-${t.id})`:t.fill,d=g("text",Object.assign(Object.assign({},e),{fill:h}),g("textPath",{href:`#${i}`,startOffset:"50%",innerHTML:o}));return g("g",{},s,g("defs",{},...c),l,d)}return g("g",{},s,g("defs",{},...c),g("text",{fill:n?`url(#curve-fill-grad-${t.id})`:t.fill,"font-size":t.fontSize+"px","text-anchor":"middle","dominant-baseline":"central","font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration||void 0,"letter-spacing":t.letterSpacing*t.fontSize+"px","stroke-width":t.strokeWidth||void 0,stroke:t.strokeWidth?r?`url(#curve-stroke-grad-${t.id})`:t.stroke:void 0,"paint-order":t.strokeWidth?"stroke fill":void 0},g("textPath",{href:`#${i}`,startOffset:"50%",innerHTML:o})))}const o=(t,e,i,n,r,o=0)=>{const a=document.createElement("canvas").getContext("2d");return a.font=`${r} ${n} ${e}px ${i}`,a.measureText(t).width+Math.max(0,(t?t.length:0)-1)*o*e},a=(t,e,i,n,r,a,s=0)=>{const l=[];return t.split("\n").forEach(t=>{const h=t.split(" ");let c="";for(let g=0;g<h.length;g++){const t=c+h[g]+" ";o(t,i,n,r,a,s)>e+.5&&g>0?(l.push(c.trim()),c=h[g]+" "):c=t}l.push(c.trim())}),l};let s=l(t.text);"uppercase"==t.textTransform&&(s=s.toUpperCase());let f=t.fontSize,p=[];for(;;){p=a(s,t.width,f,t.fontFamily,t.fontWeight,t.fontStyle,t.letterSpacing);const e=Math.max(...p.map(e=>o(e,f,t.fontFamily,t.fontWeight,t.fontStyle,t.letterSpacing))),i=p.length*f*t.lineHeight;if(e<=t.width&&i<=t.height){break}if(f-=1,f<4){break}}const u=f*t.lineHeight,m=p.length*u;let y=f;"middle"===t.verticalAlign?y=(t.height-m)/2+f:"bottom"===t.verticalAlign&&(y=t.height-m+f);const w="center"===t.align?"middle":"right"===t.align?"end":"start",b=p.map((e,i)=>g("tspan",{x:"center"===t.align?t.width/2:"right"===t.align?t.width:0,dy:0===i?0:u,innerHTML:e})),k=t.backgroundPadding*(f*t.lineHeight*.5),$=t.backgroundEnabled?g("rect",{x:-k,y:-k,width:t.width+2*k,height:t.height+2*k,fill:t.backgroundColor,opacity:t.backgroundOpacity,rx:t.backgroundCornerRadius*(f*t.lineHeight*.5),ry:t.backgroundCornerRadius*(f*t.lineHeight*.5)}):null,x=[],v=t.strokeWidth&&(r||n&&!r);if(n){const e=`text-fill-grad-${t.id}`,i=d(t.fill,e);i&&x.push(i)}if(r&&t.strokeWidth){const e=`text-stroke-grad-${t.id}`,i=d(t.stroke,e);i&&x.push(i)}if(v){const e={y,"font-size":f+"px","text-anchor":w,"font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration,"line-height":t.lineHeight,"letter-spacing":t.letterSpacing*f+"px"},i=r?`url(#text-stroke-grad-${t.id})`:t.stroke,o=g("text",Object.assign(Object.assign({},e),{fill:i,"stroke-width":t.strokeWidth,stroke:i}),...b.map(t=>g("tspan",t.props,t.props.innerHTML))),a=n?`url(#text-fill-grad-${t.id})`:t.fill,s=g("text",Object.assign(Object.assign({},e),{fill:a}),...b.map(t=>g("tspan",t.props,t.props.innerHTML)));return g("g",{},$,x.length>0?g("defs",{},...x):null,o,s)}return g("g",{},$,x.length>0?g("defs",{},...x):null,g("text",{fill:n?`url(#text-fill-grad-${t.id})`:t.fill,y,"font-size":f+"px","text-anchor":w,"font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration,"line-height":t.lineHeight,"letter-spacing":t.letterSpacing*f+"px","stroke-width":t.strokeWidth||void 0,stroke:t.strokeWidth?t.stroke:void 0,"paint-order":t.strokeWidth?"stroke fill":void 0},...b))},line:async({element:t,page:e,store:i})=>g("g",{},g("line",{x1:0,y1:t.height/2,x2:t.width,y2:t.height/2,stroke:t.color,"stroke-width":t.height,"stroke-dasharray":t.dash&&t.dash.length?t.dash.map(e=>e*t.height).join(" "):void 0}),g("g",{transform:`translate(0 ${t.height/2})`},u({element:t,type:t.startHead})),g("g",{transform:`translate(${t.width} ${t.height/2}) rotate(180)`},u({element:t,type:t.endHead}))),figure:async({element:t,page:e,store:i,elementHook:n})=>{let r=function(t){let e=t.replace(/<svg[^>]*>/,"");return e=e.replace(/<\/svg>/,""),e}(o(t));const a=[];if(t.strokeWidth&&c.isGradient(t.stroke)){const e=`figure-stroke-grad-${t.id}`,i=d(t.stroke,e);if(i){a.push(i);const n=t.stroke.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");r=r.replace(new RegExp(`stroke="${n}"`,"g"),`stroke="url(#${e})"`)}}if(c.isGradient(t.fill)){const e=`figure-fill-grad-${t.id}`,i=d(t.fill,e);if(i){a.push(i);const n=t.fill.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");r=r.replace(new RegExp(`fill="${n}"`,"g"),`fill="url(#${e})"`)}}if(a.length>0){const e=g("g",{},g("defs",{},...a),g("g",{innerHTML:r}));return n&&n({dom:e,element:t})||e}const s=g("g",{innerHTML:r});return n&&n({dom:s,element:t})||s},group:async({element:t,page:e,store:i,elementHook:n})=>{const r=await Promise.all(t.children.map(t=>y({element:t,page:e,store:i,elementHook:n}))),o=g("g",{style:{"transform-origin":"top left"}},...r);return n&&n({dom:o,element:t})||o},gif:p};async function y({element:t,page:e,store:i,elementHook:n}){var r;let o=await m[t.type];o||(o=()=>g("g",{}),console.error(`SVG export does not support ${t.type} type...`));const l=await o({element:t,page:e,store:i}),h=[],c=[];if(t.blurEnabled&&h.push(`blur(${t.blurRadius/2}px)`),t.brightnessEnabled&&h.push(`brightness(${100*t.brightness+100}%)`),t.sepiaEnabled&&h.push("sepia()"),t.grayscaleEnabled&&h.push("grayscale()"),t.shadowEnabled&&h.push(`drop-shadow(${t.shadowOffsetX}px ${t.shadowOffsetY}px ${t.shadowBlur}px ${t.shadowColor})`),t.filters){for(const[g,f]of Object.entries(t.filters)){const t=s(a[g],f.intensity);if(t&&(h.push(t.filter),t.html)){const e=t.html.replace(/<svg([^>]*)>/,"<g$1>").replace(/<\/svg>/,"</g>");c.push(e)}}}const d=g("g",{className:"element",id:t.id,transform:"group"!==t.type?`translate(${t.x}, ${t.y}) rotate(${t.rotation})`:void 0,display:null===(r=t.visible)||void 0===r||r?void 0:"none",opacity:t.opacity,style:{"transform-origin":"top left",filter:h.join(" ")}},l,...c);return n&&n({dom:d,element:t})||d}async function w(t){try{const e=await fetch(t),i=e.headers.get("content-type")||"font/ttf",n=await e.arrayBuffer();return`data:${i};base64,${"undefined"!=typeof Buffer?Buffer.from(n).toString("base64"):function(t){const e=new Uint8Array(t);let i="";for(let n=0;n<e.length;n+=32768){const t=e.subarray(n,n+32768);i+=String.fromCharCode(...t)}if("undefined"!=typeof btoa){return btoa(i)}if("undefined"!=typeof Buffer){return Buffer.from(e).toString("base64")}throw new Error("No base64 encoder available in this environment")}(n)}`}catch(e){return console.error("Error embedding font:",e),t}}export async function jsonToDOM({json:t,elementHook:r,fontEmbedding:o="inline"}){const a=[];forEveryChild({children:t.pages},t=>{"text"===t.type&&-1===a.indexOf(t.fontFamily)&&a.push(t.fontFamily)});const s="inline"===o?await async function(t,e){return await Promise.all(t.map(async t=>{var i,n;if("Arial"===t){return null}const r=e.find(e=>e.fontFamily===t);if(r){const e=await w(r.url);return g("style",{},`@font-face { font-family: ${t}; src: url(${e}); }`)}{const e=`https://fonts.googleapis.com/css?family=${t}:bi,normal,i,b`;try{const r=await fetch(e),o=await r.text(),a=null===(n=null===(i=o.match(/url\((.*?)\)/g))||void 0===i?void 0:i.map(t=>t.replace(/url\((.*?)\)/,"$1")))||void 0===n?void 0:n.filter(t=>t.startsWith("https"));if(!(null==a?void 0:a.length)){throw new Error("No font URLs found")}const s=await Promise.all(a.map(async e=>{const i=await w(e),n=o.match(/font-style:\s*(.*?);/),r=o.match(/font-weight:\s*(.*?);/),a=n?n[1]:"normal",s=r?r[1]:"normal";return`@font-face {\n font-family: ${t};\n font-style: ${a};\n font-weight: ${s};\n src: url(${i});\n }`}));return g("style",{},s.join("\n"))}catch(o){return console.error("Error embedding Google Font:",o),g("defs",{},g("style",{type:"text/css",innerHTML:`@import url('${e}');`.replace(/&/g,"&amp;")}))}}}))}(a,t.fonts):[],l=await Promise.all(t.pages.map(o=>async function({page:t,store:r,elementHook:o}){const a=await Promise.all(t.children.map(e=>y({element:e,page:t,store:r,elementHook:o}))),s=t.background.indexOf("url")>=0||t.background.indexOf("http")>=0||t.background.indexOf(".jpg")>=0||t.background.indexOf(".png")>=0||t.background.indexOf(".jpeg")>=0;let l;if(s){const o=await n(t.background);l=await e(t.background,Object.assign({width:r.width,height:r.height,x:0,y:0},i({width:r.width,height:r.height},{width:o.width,height:o.height})))}return g("g",{className:"page",style:{}},s?g("image",{"xlink:href":l,x:0,y:0,width:r.width,height:r.height,preserveAspectRatio:"none"}):g("rect",{x:0,y:0,width:r.width,height:r.height,fill:s?void 0:t.background}),...a)}({page:o,store:t,elementHook:r})));return g("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:`0 0 ${t.width} ${t.height}`,width:t.width,height:t.height},...s,...l)}const b=({dom:e,nestLevel:i=0})=>{if("string"==typeof e){return e}if(!e){return""}const n=e.props,{innerHTML:r}=n,o=t(n,["innerHTML"]),a=Object.keys(o).map(t=>((t,e)=>"object"==typeof e?`${t}="${Object.keys(e).map(t=>`${t}:${e[t]};`).join(" ")}"`:null==e||""===e?"":`${t}="${e}"`)(t,o[t])).filter(t=>t&&t.trim().length>0).join(" "),s=" ".repeat(i);return`${s}<${e.type}${a?" "+a:""}>${r||"\n"+e.children.map(t=>b({dom:t,nestLevel:i+1})).join("")}${s}</${e.type}>\n`};export async function jsonToSVG({json:t,elementHook:e,fontEmbedding:i="inline"}){const n=await jsonToDOM({json:t,elementHook:e,fontEmbedding:i});return b({dom:n})}
1
+ var t=this&&this.__rest||function(t,e){var i={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(i[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++){e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(i[o[n]]=t[o[n]])}}return i};import{cropImage as e,getCrop as i,loadImage as o}from"./image.js";import*as n from"./svg.js";import{figureToSvg as r}from"./figure-to-svg.js";import{Effects as l,shapeFilterToCSS as s}from"./filters.js";import{removeTags as a}from"./text.js";import{getCurvePath as h}from"../canvas/text-element.js";import*as c from"./gradient.js";export const forEveryNode=(t,e)=>{if(t.children){for(const i of t.children){if(!0===e(i)){break}forEveryNode(i,e)}}if(t.cells){for(const i of t.cells){if(!0===e(i)){break}}}};const d=(t,e,...i)=>({type:t,props:e,children:i||[]});function g(t,e){if(!c.isGradient(t)){return null}const{stops:i,rotation:o}=c.parseColor(t),n=o*Math.PI/180,r=.5-.5*Math.sin(n),l=.5+.5*Math.cos(n),s=.5+.5*Math.sin(n),a=.5-.5*Math.cos(n),h=i.map(({offset:t,color:e})=>d("stop",{offset:100*t+"%","stop-color":e}));return d("linearGradient",{id:e,x1:100*r+"%",y1:100*l+"%",x2:100*s+"%",y2:100*a+"%"},...h)}export function fixRatio(t){var e=(new DOMParser).parseFromString(t,"image/svg+xml");return e.documentElement.setAttribute("preserveAspectRatio","none"),(new XMLSerializer).serializeToString(e)}const f=async t=>{try{const e=await fetch(t);if("undefined"!=typeof Buffer){const t=await e.arrayBuffer(),i=Buffer.from(t).toString("base64");return`data:${e.headers.get("content-type")||"image/png"};base64,${i}`}{const t=await e.blob();return new Promise((e,i)=>{const o=new FileReader;o.onloadend=()=>e(o.result),o.onerror=i,o.readAsDataURL(t)})}}catch(e){return console.error("Error converting URL to data URL:",e),t}},p=async({element:t,page:e,store:i})=>{let{src:r}=t;if("svg"===t.type){const e=await n.urlToString(r);r=n.replaceColors(e,new Map(Object.entries(t.colorsReplace)))}else{r=await f(r)}let l,s,a,h,p="";if(t.flipX||t.flipY){const e=t.flipX?-1:1,i=t.flipY?-1:1,o=t.width/2,n=t.height/2;p=`translate(${o}, ${n}) scale(${e}, ${i}) translate(${-o}, ${-n})`}t.clipSrc&&(l=`clip-img-mask-${t.id}`,s=await f(t.clipSrc)),t.maskSrc&&(a=`mask-img-${t.id}`,h=await f(t.maskSrc));const u=await o(r),m=u.width*t.cropWidth,y=u.height*t.cropHeight,w=t.width/t.height;let x,k;const b=m/y,$="boolean"==typeof t.stretchEnabled&&t.stretchEnabled||"svg"===t.type;$?(x=m,k=y):w>=b?(x=m,k=m/w):(x=y*w,k=y);const v=x/u.width,j=k/u.height,O=x/k>t.width/t.height?t.height/k:t.width/x,S=$?t.width/x:O,H=$?t.height/k:O,M=x*S/v,E=k*H/j;let W=t.cropX*u.width*S,P=t.cropY*u.height*H;t.flipX&&(W=(1-t.cropX-t.cropWidth)*u.width*S),t.flipY&&(P=(1-t.cropY-t.cropHeight)*u.height*H);const R=`clip-${t.id}`,T=t.cornerRadius||0,z=r.replace(/&/g,"&amp;"),C={x:-W,y:-P,width:M,height:E,preserveAspectRatio:"none","clip-path":`url(#${R})`},L=[d("clipPath",{id:R},d("rect",{x:0,y:0,width:t.width,height:t.height,rx:T||void 0,ry:T||void 0}))];l&&s&&L.push(d("mask",{id:l,maskUnits:"userSpaceOnUse","mask-type":"alpha"},d("image",{href:s.replace(/&/g,"&amp;"),x:0,y:0,width:t.width,height:t.height,preserveAspectRatio:"none"}))),a&&L.push(d("mask",{id:a,maskUnits:"userSpaceOnUse","mask-type":"alpha"},d("image",Object.assign({href:z},C))));let F=z;const B={};a&&h&&(F=h.replace(/&/g,"&amp;"),B.mask=`url(#${a})`);const A={};l&&(A.mask=`url(#${l})`);const U=t.borderSize||0,D=U>0&&c.isGradient(t.borderColor),G=D?`border-grad-${t.id}`:null;if(D){const e=g(t.borderColor,G);e&&L.push(e)}const N=U>0?d("rect",{x:U/2,y:U/2,width:Math.max(0,t.width-U),height:Math.max(0,t.height-U),fill:"none",stroke:D?`url(#${G})`:t.borderColor,"stroke-width":U,rx:Math.max(0,T-U)||void 0,ry:Math.max(0,T-U)||void 0}):null,X=d("g",{},d("defs",{},...L),d("image",Object.assign(Object.assign({href:F},C),B)),N);return d("g",A,p?d("g",{transform:p},X):X)},u=({element:t,type:e})=>{const i={"stroke-width":t.height,stroke:t.color,"stroke-linecap":"round","stroke-linejoin":"round"},o=Object.assign(Object.assign({},i),{fill:t.color}),n=Object.assign(Object.assign({},i),{fill:"none"});return"arrow"===e?d("polyline",Object.assign({points:`${3*t.height},${2*-t.height} 0,0 ${3*t.height},${2*t.height}`},n)):"triangle"===e?d("polygon",Object.assign({points:`${3*t.height},${2*-t.height} 0,0 ${3*t.height},${2*t.height}`},o)):"bar"===e?d("polyline",Object.assign({points:`0,${2*-t.height} 0,${2*t.height}`},n)):"circle"===e?d("circle",Object.assign({cx:2*t.height,cy:0,r:2*t.height},o)):"square"===e?d("polygon",Object.assign({points:`0,${2*-t.height} ${4*t.height},${2*-t.height} ${4*t.height},${2*t.height} 0,${2*t.height}`},o)):null},m={image:p,svg:p,text:async({element:t,page:e,store:i})=>{const o=c.isGradient(t.fill),n=c.isGradient(t.stroke);if(t.curveEnabled){const e=h(t.width,t.height,t.curvePower,t.fontSize),i=`curve-path-${t.id}`,r=a(t.text).replace(/\n/g," "),l=t.backgroundPadding*(t.fontSize*t.lineHeight*.5),s=t.backgroundEnabled?d("rect",{x:-l,y:-l,width:t.width+2*l,height:t.height+2*l,fill:t.backgroundColor,opacity:t.backgroundOpacity,rx:t.backgroundCornerRadius*(t.fontSize*t.lineHeight*.5),ry:t.backgroundCornerRadius*(t.fontSize*t.lineHeight*.5)}):null,c=[d("path",{id:i,d:e,fill:"none"})],f=t.strokeWidth&&(n||o&&!n);if(o){const e=`curve-fill-grad-${t.id}`,i=g(t.fill,e);i&&c.push(i)}if(n&&t.strokeWidth){const e=`curve-stroke-grad-${t.id}`,i=g(t.stroke,e);i&&c.push(i)}if(f){const e={"font-size":t.fontSize+"px","text-anchor":"middle","dominant-baseline":"central","font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration||void 0,"letter-spacing":t.letterSpacing*t.fontSize+"px"},l=n?`url(#curve-stroke-grad-${t.id})`:t.stroke,a=d("text",Object.assign(Object.assign({},e),{fill:l,"stroke-width":t.strokeWidth,stroke:l}),d("textPath",{href:`#${i}`,startOffset:"50%",innerHTML:r})),h=o?`url(#curve-fill-grad-${t.id})`:t.fill,g=d("text",Object.assign(Object.assign({},e),{fill:h}),d("textPath",{href:`#${i}`,startOffset:"50%",innerHTML:r}));return d("g",{},s,d("defs",{},...c),a,g)}return d("g",{},s,d("defs",{},...c),d("text",{fill:o?`url(#curve-fill-grad-${t.id})`:t.fill,"font-size":t.fontSize+"px","text-anchor":"middle","dominant-baseline":"central","font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration||void 0,"letter-spacing":t.letterSpacing*t.fontSize+"px","stroke-width":t.strokeWidth||void 0,stroke:t.strokeWidth?n?`url(#curve-stroke-grad-${t.id})`:t.stroke:void 0,"paint-order":t.strokeWidth?"stroke fill":void 0},d("textPath",{href:`#${i}`,startOffset:"50%",innerHTML:r})))}const r=(t,e,i,o,n,r=0)=>{const l=document.createElement("canvas").getContext("2d");return l.font=`${n} ${o} ${e}px ${i}`,l.measureText(t).width+Math.max(0,(t?t.length:0)-1)*r*e},l=(t,e,i,o,n,l,s=0)=>{const a=[];return t.split("\n").forEach(t=>{const h=t.split(" ");let c="";for(let d=0;d<h.length;d++){const t=c+h[d]+" ";r(t,i,o,n,l,s)>e+.5&&d>0?(a.push(c.trim()),c=h[d]+" "):c=t}a.push(c.trim())}),a};let s=a(t.text);"uppercase"==t.textTransform&&(s=s.toUpperCase());let f=t.fontSize,p=[];for(;;){p=l(s,t.width,f,t.fontFamily,t.fontWeight,t.fontStyle,t.letterSpacing);const e=Math.max(...p.map(e=>r(e,f,t.fontFamily,t.fontWeight,t.fontStyle,t.letterSpacing))),i=p.length*f*t.lineHeight;if(e<=t.width&&i<=t.height){break}if(f-=1,f<4){break}}const u=f*t.lineHeight,m=p.length*u;let y=f;"middle"===t.verticalAlign?y=(t.height-m)/2+f:"bottom"===t.verticalAlign&&(y=t.height-m+f);const w="center"===t.align?"middle":"right"===t.align?"end":"start",x=p.map((e,i)=>d("tspan",{x:"center"===t.align?t.width/2:"right"===t.align?t.width:0,dy:0===i?0:u,innerHTML:e})),k=t.backgroundPadding*(f*t.lineHeight*.5),b=t.backgroundEnabled?d("rect",{x:-k,y:-k,width:t.width+2*k,height:t.height+2*k,fill:t.backgroundColor,opacity:t.backgroundOpacity,rx:t.backgroundCornerRadius*(f*t.lineHeight*.5),ry:t.backgroundCornerRadius*(f*t.lineHeight*.5)}):null,$=[],v=t.strokeWidth&&(n||o&&!n);if(o){const e=`text-fill-grad-${t.id}`,i=g(t.fill,e);i&&$.push(i)}if(n&&t.strokeWidth){const e=`text-stroke-grad-${t.id}`,i=g(t.stroke,e);i&&$.push(i)}if(v){const e={y,"font-size":f+"px","text-anchor":w,"font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration,"line-height":t.lineHeight,"letter-spacing":t.letterSpacing*f+"px"},i=n?`url(#text-stroke-grad-${t.id})`:t.stroke,r=d("text",Object.assign(Object.assign({},e),{fill:i,"stroke-width":t.strokeWidth,stroke:i}),...x.map(t=>d("tspan",t.props,t.props.innerHTML))),l=o?`url(#text-fill-grad-${t.id})`:t.fill,s=d("text",Object.assign(Object.assign({},e),{fill:l}),...x.map(t=>d("tspan",t.props,t.props.innerHTML)));return d("g",{},b,$.length>0?d("defs",{},...$):null,r,s)}return d("g",{},b,$.length>0?d("defs",{},...$):null,d("text",{fill:o?`url(#text-fill-grad-${t.id})`:t.fill,y,"font-size":f+"px","text-anchor":w,"font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration,"line-height":t.lineHeight,"letter-spacing":t.letterSpacing*f+"px","stroke-width":t.strokeWidth||void 0,stroke:t.strokeWidth?t.stroke:void 0,"paint-order":t.strokeWidth?"stroke fill":void 0},...x))},line:async({element:t,page:e,store:i})=>d("g",{},d("line",{x1:0,y1:t.height/2,x2:t.width,y2:t.height/2,stroke:t.color,"stroke-width":t.height,"stroke-dasharray":t.dash&&t.dash.length?t.dash.map(e=>e*t.height).join(" "):void 0}),d("g",{transform:`translate(0 ${t.height/2})`},u({element:t,type:t.startHead})),d("g",{transform:`translate(${t.width} ${t.height/2}) rotate(180)`},u({element:t,type:t.endHead}))),figure:async({element:t,page:e,store:i,elementHook:o})=>{let n=function(t){let e=t.replace(/<svg[^>]*>/,"");return e=e.replace(/<\/svg>/,""),e}(r(t));const l=[];if(t.strokeWidth&&c.isGradient(t.stroke)){const e=`figure-stroke-grad-${t.id}`,i=g(t.stroke,e);if(i){l.push(i);const o=t.stroke.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");n=n.replace(new RegExp(`stroke="${o}"`,"g"),`stroke="url(#${e})"`)}}if(c.isGradient(t.fill)){const e=`figure-fill-grad-${t.id}`,i=g(t.fill,e);if(i){l.push(i);const o=t.fill.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");n=n.replace(new RegExp(`fill="${o}"`,"g"),`fill="url(#${e})"`)}}if(l.length>0){const e=d("g",{},d("defs",{},...l),d("g",{innerHTML:n}));return o&&o({dom:e,element:t})||e}const s=d("g",{innerHTML:n});return o&&o({dom:s,element:t})||s},group:async({element:t,page:e,store:i,elementHook:o})=>{const n=await Promise.all(t.children.map(t=>y({element:t,page:e,store:i,elementHook:o}))),r=d("g",{style:{"transform-origin":"top left"}},...n);return o&&o({dom:r,element:t})||r},gif:p,table:async({element:t})=>{t.rows;const e=t.cols,i=t.colWidths,o=t.rowHeights,n=["fontSize","fontFamily","fontWeight","fontStyle","textDecoration","textTransform","fill","align","verticalAlign","lineHeight","letterSpacing","strokeWidth","stroke","cellBackground","cellPadding"],r=(t.cells||[]).map((i,o)=>{const r=Object.assign(Object.assign({},i),{row:Math.floor(o/e),col:o%e});for(const e of n){void 0===r[e]&&(r[e]=t[e])}return r}),l=[],s=(e,n,r,l)=>{let s=0;for(let o=0;o<n;o++){s+=i[o]*t.width}let a=0;for(let i=0;i<e;i++){a+=o[i]*t.height}let h=0;for(let o=n;o<n+l;o++){h+=(i[o]||0)*t.width}let c=0;for(let i=e;i<e+r;i++){c+=(o[i]||0)*t.height}return{x:s,y:a,width:h,height:c}};for(const a of r){if(!a.mergedInto&&a.cellBackground&&"transparent"!==a.cellBackground){s(a.row,a.col,a.colSpan||1,a.colSpan||1);const{x:t,y:e,width:i,height:o}=s(a.row,a.col,a.rowSpan||1,a.colSpan||1);l.push(d("rect",{x:t,y:e,width:i,height:o,fill:a.cellBackground}))}}const h=(t,e)=>"dashed"===t?`${4*e},${2*e}`:"dotted"===t?`${e},${e}`:void 0,c=(e,i)=>{var o,n,r,l,s;const a=null===(o=e.borders)||void 0===o?void 0:o[i];return{width:null!==(n=null==a?void 0:a.width)&&void 0!==n?n:t.borderWidth,style:null!==(l=null!==(r=null==a?void 0:a.style)&&void 0!==r?r:t.borderStyle)&&void 0!==l?l:"solid",color:null!==(s=null==a?void 0:a.color)&&void 0!==s?s:t.borderColor}};for(const a of r){if(a.mergedInto){continue}const t=s(a.row,a.col,a.rowSpan||1,a.colSpan||1);if(0===a.row){const e=c(a,"top");"none"!==e.style&&e.width>0&&l.push(d("line",{x1:t.x,y1:t.y+e.width/2,x2:t.x+t.width,y2:t.y+e.width/2,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":h(e.style,e.width)}))}if(0===a.col){const e=c(a,"left");"none"!==e.style&&e.width>0&&l.push(d("line",{x1:t.x+e.width/2,y1:t.y,x2:t.x+e.width/2,y2:t.y+t.height,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":h(e.style,e.width)}))}{const e=c(a,"bottom");"none"!==e.style&&e.width>0&&l.push(d("line",{x1:t.x,y1:t.y+t.height-e.width/2,x2:t.x+t.width,y2:t.y+t.height-e.width/2,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":h(e.style,e.width)}))}{const e=c(a,"right");"none"!==e.style&&e.width>0&&l.push(d("line",{x1:t.x+t.width-e.width/2,y1:t.y,x2:t.x+t.width-e.width/2,y2:t.y+t.height,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":h(e.style,e.width)}))}}for(const g of r){if(g.mergedInto){continue}let e=a(g.text||"");if(!e){continue}"uppercase"===g.textTransform&&(e=e.toUpperCase());const n=g.cellPadding||4;let r=0;for(let o=0;o<g.col;o++){r+=i[o]*t.width}let s=0;for(let i=0;i<g.row;i++){s+=o[i]*t.height}const h=i[g.col]*t.width,c=o[g.row]*t.height,f=g.fontSize||12,p=g.align||"left";let u=r+n,m="start";"center"===p?(u=r+h/2,m="middle"):"right"===p&&(u=r+h-n,m="end");let y=s+n+f;const w=g.verticalAlign||"top";"middle"===w?y=s+c/2+f/3:"bottom"===w&&(y=s+c-n),l.push(d("text",{x:u,y,"font-size":f,"font-family":g.fontFamily||"Roboto","font-weight":g.fontWeight||"normal","font-style":g.fontStyle||"normal",fill:g.fill||"black","text-anchor":m,"text-decoration":g.textDecoration||"none","letter-spacing":g.letterSpacing?g.letterSpacing*f+"px":void 0},e))}return d("g",{},...l)}};async function y({element:t,page:e,store:i,elementHook:o}){var n;let r=await m[t.type];r||(r=()=>d("g",{}),console.error(`SVG export does not support ${t.type} type...`));const a=await r({element:t,page:e,store:i}),h=[],c=[];if(t.blurEnabled&&h.push(`blur(${t.blurRadius/2}px)`),t.brightnessEnabled&&h.push(`brightness(${100*t.brightness+100}%)`),t.sepiaEnabled&&h.push("sepia()"),t.grayscaleEnabled&&h.push("grayscale()"),t.shadowEnabled&&h.push(`drop-shadow(${t.shadowOffsetX}px ${t.shadowOffsetY}px ${t.shadowBlur}px ${t.shadowColor})`),t.filters){for(const[d,f]of Object.entries(t.filters)){const t=s(l[d],f.intensity);if(t&&(h.push(t.filter),t.html)){const e=t.html.replace(/<svg([^>]*)>/,"<g$1>").replace(/<\/svg>/,"</g>");c.push(e)}}}const g=d("g",{className:"element",id:t.id,transform:"group"!==t.type?`translate(${t.x}, ${t.y}) rotate(${t.rotation})`:void 0,display:null===(n=t.visible)||void 0===n||n?void 0:"none",opacity:t.opacity,style:{"transform-origin":"top left",filter:h.join(" ")}},a,...c);return o&&o({dom:g,element:t})||g}async function w(t){try{const e=await fetch(t),i=e.headers.get("content-type")||"font/ttf",o=await e.arrayBuffer();return`data:${i};base64,${"undefined"!=typeof Buffer?Buffer.from(o).toString("base64"):function(t){const e=new Uint8Array(t);let i="";for(let o=0;o<e.length;o+=32768){const t=e.subarray(o,o+32768);i+=String.fromCharCode(...t)}if("undefined"!=typeof btoa){return btoa(i)}if("undefined"!=typeof Buffer){return Buffer.from(e).toString("base64")}throw new Error("No base64 encoder available in this environment")}(o)}`}catch(e){return console.error("Error embedding font:",e),t}}export async function jsonToDOM({json:t,elementHook:n,fontEmbedding:r="inline"}){const l=[];forEveryNode({children:t.pages},t=>{"text"!==t.type&&"tablecell"!==t.type&&"table"!==t.type||!t.fontFamily||-1!==l.indexOf(t.fontFamily)||l.push(t.fontFamily)});const s="inline"===r?await async function(t,e){return await Promise.all(t.map(async t=>{var i,o;if("Arial"===t){return null}const n=e.find(e=>e.fontFamily===t);if(n){const e=await w(n.url);return d("style",{},`@font-face { font-family: ${t}; src: url(${e}); }`)}{const e=`https://fonts.googleapis.com/css?family=${t}:bi,normal,i,b`;try{const n=await fetch(e),r=await n.text(),l=null===(o=null===(i=r.match(/url\((.*?)\)/g))||void 0===i?void 0:i.map(t=>t.replace(/url\((.*?)\)/,"$1")))||void 0===o?void 0:o.filter(t=>t.startsWith("https"));if(!(null==l?void 0:l.length)){throw new Error("No font URLs found")}const s=await Promise.all(l.map(async e=>{const i=await w(e),o=r.match(/font-style:\s*(.*?);/),n=r.match(/font-weight:\s*(.*?);/),l=o?o[1]:"normal",s=n?n[1]:"normal";return`@font-face {\n font-family: ${t};\n font-style: ${l};\n font-weight: ${s};\n src: url(${i});\n }`}));return d("style",{},s.join("\n"))}catch(r){return console.error("Error embedding Google Font:",r),d("defs",{},d("style",{type:"text/css",innerHTML:`@import url('${e}');`.replace(/&/g,"&amp;")}))}}}))}(l,t.fonts):[],a=await Promise.all(t.pages.map(r=>async function({page:t,store:n,elementHook:r}){const l=await Promise.all(t.children.map(e=>y({element:e,page:t,store:n,elementHook:r}))),s=t.background.indexOf("url")>=0||t.background.indexOf("http")>=0||t.background.indexOf(".jpg")>=0||t.background.indexOf(".png")>=0||t.background.indexOf(".jpeg")>=0;let a;if(s){const r=await o(t.background);a=await e(t.background,Object.assign({width:n.width,height:n.height,x:0,y:0},i({width:n.width,height:n.height},{width:r.width,height:r.height})))}return d("g",{className:"page",style:{}},s?d("image",{"xlink:href":a,x:0,y:0,width:n.width,height:n.height,preserveAspectRatio:"none"}):d("rect",{x:0,y:0,width:n.width,height:n.height,fill:s?void 0:t.background}),...l)}({page:r,store:t,elementHook:n})));return d("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:`0 0 ${t.width} ${t.height}`,width:t.width,height:t.height},...s,...a)}const x=({dom:e,nestLevel:i=0})=>{if("string"==typeof e){return e}if(!e){return""}const o=e.props,{innerHTML:n}=o,r=t(o,["innerHTML"]),l=Object.keys(r).map(t=>((t,e)=>"object"==typeof e?`${t}="${Object.keys(e).map(t=>`${t}:${e[t]};`).join(" ")}"`:null==e||""===e?"":`${t}="${e}"`)(t,r[t])).filter(t=>t&&t.trim().length>0).join(" "),s=" ".repeat(i);return`${s}<${e.type}${l?" "+l:""}>${n||"\n"+e.children.map(t=>x({dom:t,nestLevel:i+1})).join("")}${s}</${e.type}>\n`};export async function jsonToSVG({json:t,elementHook:e,fontEmbedding:i="inline"}){const o=await jsonToDOM({json:t,elementHook:e,fontEmbedding:i});return x({dom:o})}
@@ -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:"2.36.10"})});if(e.runInAction(()=>{a.value=r.headers.get("x-api-version")||""}),!n){return console.error("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1}),!1}if(200!==r.status){await new Promise(e=>setTimeout(e,3e3));continue}const s=await r.json();return s.is_valid||(console.error("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1})),s.is_paid||(console.log("%cPolotno Free Version. For development usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{0===i.value&&(i.value=2)})),s.is_domain_valid||console.log(p,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),t(s.remove_background_enabled),s.is_paid||!1}catch(r){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e,o){s=e,await isKeyPaid(e)&&!o||r()}
1
+ import*as e from"mobx";import{getAPI as o}from"./api.js";import{setRemoveBackgroundEnabled as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const p=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let u=fetch;export const __=e=>{u=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await u(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"2.37.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(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()}