polotno 2.23.13 → 2.23.14

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/model/store.js CHANGED
@@ -1 +1 @@
1
- var e,t=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,o)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var o={};if(null!=n){for(var a=e(n),s=0;s<a.length;s++){"default"!==a[s]&&t(o,n,a[s])}}return i(o,n),o}),o=this&&this.__rest||function(e,t){var i={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}}return i},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Store=exports.Font=void 0,exports.createStore=k;const s=require("mobx-state-tree"),r=require("./history"),l=require("nanoid"),d=a(require("konva")),c=require("mobx"),p=require("../utils/download"),u=require("../utils/pdf"),g=require("../utils/gif-lib"),m=require("../utils/validate-key"),h=n(require("../utils/fonts")),f=require("../utils/flags"),y=require("../utils/loader"),b=require("../utils/unit"),v=require("../utils/deep-equal"),w=require("../utils/wait"),P=require("../utils/to-html"),x=require("../utils/to-svg"),E=require("./page-model"),_=require("./group-model"),O=require("./audio-model");function k({key:e,showCredit:t}={key:"",showCredit:!1}){return exports.Store.create({_forceShowCredit:t,_key:e})}(0,s.setLivelinessChecking)("ignore"),exports.Font=s.types.model("Font",{fontFamily:s.types.string,url:s.types.optional(s.types.string,""),styles:s.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=s.types.model("Store",{role:"",pages:s.types.array(E.Page),fonts:s.types.array(exports.Font),audios:s.types.array(O.Audio),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:2,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:s.types.frozen(),selectedElementsIds:s.types.array(s.types.string),animatedElementsIds:s.types.array(s.types.string),history:s.types.optional(r.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views((e=>{const t=(0,c.computed)((()=>{const t={};return(0,_.forEveryChild)({children:e.pages},(e=>(t[e.id]=e,!1))),t}),{keepAlive:!0});return{get _idsMap(){return t.get()}}})).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const i of e.pages){for(const e of i.children){if(e.id===t){return e}}}})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,_.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let i;return(0,_.forEveryChild)({children:e.pages},(e=>{if(!i&&t(e)){return i=e,!0}})),i},getElementById:t=>e._idsMap[t]}))).actions((e=>{let t=0,i=null,n=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:o=[],startTime:a=0,currentTime:r=0,endTime:l=e.duration,repeat:d=!1}={}){r&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),a=r),e.animatedElementsIds=(0,s.cast)(o),e.currentTime=a,e.isPlaying=!0,t=Date.now(),i=l,n=d,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const i of e.pages){if(e.currentTime>=i.startTime&&e.currentTime<i.startTime+i.duration){e.selectPage(i.id);break}t+=i.duration}},seek(){if(!e.isPlaying){return}const o=Date.now(),a=o-t;t=o,e.currentTime+=a,e.checkActivePage();const s=i||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(e.seek):e.isPlaying&&n?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,s.cast)([]),e.checkActivePage()}}})).actions((e=>({__(){e._validated||((0,m.validateKey)(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:i}){e.unit=t||e.unit,e.dpi=i||e.dpi},setRole(t){e.role=t},addPage(t){const i=E.Page.create(Object.assign({id:(0,l.nanoid)(10)},t));return e.pages.push(i),e._activePageId=i.id,i},selectPage(t){e._activePageId=t},selectElements(t){const i=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,s.cast)(i)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,i,n){e.pages.forEach((e=>{e.setSize({width:t,height:i,useMagic:n,softChange:!0})})),e.width=t,e.height=i},setPageZIndex(t,i){const n=e.pages.find((e=>e.id===t));n&&((0,s.detach)(n),e.pages.remove(n),e.pages.splice(i,0,n))},deletePages(t){const i=e.pages.indexOf(e.activePage);t.forEach((t=>{const i=e.pages.find((e=>e.id===t));(0,s.destroy)(i)}));const n=Math.min(e.pages.length-1,i),o=e.pages[n];o&&(e._activePageId=o.id),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t,i={}){const n=t.map((t=>e.getElementById(t))),o=n[0].page;if(n.forEach((e=>{e&&(0,s.detach)(e)})),!n.length){return}const a=Object.assign({id:(0,l.nanoid)(10),children:n,type:"group"},i);return o.children.push(a),e.selectedElementsIds=(0,s.cast)([a.id]),o.children.find((e=>e.id===a.id))},ungroupElements(t){const i=t.map((t=>e.getElementById(t))),n=[];i.forEach((e=>{if(e&&"group"===e.type){const t=e.page,i=t.children.indexOf(e);e.children.forEach((e=>{n.push(e.id)})),e.children.forEach((e=>{(0,s.detach)(e),t.children.push(e)})),t.children.splice(i,1)}})),e.selectedElementsIds=(0,s.cast)(n)},deleteElements(t){const i=[];e.find((e=>(t.includes(e.id)&&i.push(e),!1))),i.forEach((e=>{(0,s.destroy)(e)})),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,i){if("change"===t){let t=e.toJSON();return(0,s.onSnapshot)(e,(n=>{const o=e.toJSON();!(0,v.deepEqual)(t,o)&&(t=o,i(o))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:i,pageId:n,mimeType:o,includeBleed:a,_skipTimeout:s,quickMode:r=!1}={}){var l;const c=t||1;n=n||(null===(l=e.pages[0])||void 0===l?void 0:l.id);const p=e.pages.find((e=>e.id===n));if(!p){throw new Error(`No page for export with id ${n}`)}const u=e._elementsPixelRatio;c>e._elementsPixelRatio&&e.setElementsPixelRatio(c),r?null==p||p.set({_forceMount:!0}):null==p||p.set({_exporting:!0});const g=await(0,w.waitTillAvailable)((()=>d.default.stages.find((e=>e.getAttr("pageId")===n))));if(!g){throw null==p||p.set({_forceMount:!1,_exporting:!1}),e.setElementsPixelRatio(u),new Error(`Export is failed. Can not find stage for page ${n}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`)}await e.waitLoading({_skipTimeout:s});const m=g.findOne(".page-container");if(!m){throw e.setElementsPixelRatio(u),null==p||p.set({_forceMount:!1,_exporting:!1}),new Error("Export is failed. Canvas was unmounted.")}const h=g.position();g.position({x:0,y:0}),g.find("Transformer").forEach((e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)})),m.find(".page-background").forEach((e=>e.shadowEnabled(!1))),m.find(".page-background").forEach((e=>e.strokeEnabled(!1))),m.find(".highlighter").forEach((e=>e.visible(!1)));const f=m.findOne(".page-background-group"),y=f.clip();f.clip({x:null,y:null,width:null,height:null});const b=m.findOne(".elements-container"),v=b.clip();b.clip({x:null,y:null,width:null,height:null});const P=m.find((e=>e.getAttr("hideInExport")));P.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const x=m.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));x.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),i&&m.find(".page-background").forEach((e=>e.hide()));const E=a?p.bleed:0;let _=E;!e.bleedVisible&&a||(e.bleedVisible||a?e.bleedVisible&&a?_=0:e.bleedVisible&&!a&&(_=-p.bleed):_=0);const O=document.createElement("canvas");O.width=Math.round((p.computedWidth+2*E)*c),O.height=Math.round((p.computedHeight+2*E)*c);const k=O.getContext("2d");"image/jpeg"===o&&(k.fillStyle="white",k.fillRect(0,0,O.width,O.height));const S=m.scale();m.scale({x:1,y:1});const I=m.toCanvas({x:m.x()-_,y:m.y()-_,width:p.computedWidth+2*E,height:p.computedHeight+2*E,pixelRatio:c});return m.scale(S),k.drawImage(I,0,0,O.width,O.height),d.default.Util.releaseCanvas(I),i&&m.find(".page-background").forEach((e=>e.show())),P.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),x.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),m.find(".page-background").forEach((e=>e.shadowEnabled(!0))),m.find(".page-background").forEach((e=>e.strokeEnabled(!0))),g.find("Transformer").forEach((e=>{e.visible(e.getAttr("oldVisible"))})),m.find(".highlighter").forEach((e=>e.visible(!0))),f.clip(y),b.clip(v),g.position(h),null==p||p.set({_exporting:!1,_forceMount:!1}),await new Promise((e=>setTimeout(e))),e.setElementsPixelRatio(u),O},async toDataURL(t={}){var{mimeType:i,quality:n}=t,a=o(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=s.toDataURL(i,n);return d.default.Util.releaseCanvas(s),r},async toBlob(t={}){var{mimeType:i,quality:n}=t,a=o(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=await new Promise((e=>{s.toBlob(e,i,n)}));return d.default.Util.releaseCanvas(s),r},async saveAsImage(t={}){var{fileName:i}=t,n=o(t,["fileName"]);const a=n.mimeType||"image/png",s=a.split("/")[1];(0,p.downloadFile)(await e.toDataURL(n),i||"polotno."+s,a)},async _toPDF(t){const i=t.dpi||e.dpi,n=t.parallel||1,o=t.unit||("px"===e.unit?"mm":e.unit),a=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,u.getJsPDF)(),d=e=>(0,b.pxToUnit)({px:e,unit:o,dpi:i}),c=t.cropMarkSize||0,p=d(c),g=r[0]||{},m=t.includeBleed?g.bleed:0,h=d(g.computedWidth+2*m+2*p),f=d(g.computedHeight+2*m+2*p);var y=new l({unit:o,orientation:h>f?"landscape":"portrait",format:[h,f],compress:!0,putOnlyUsedFonts:!0});y.deletePage(1);const v=((e,t)=>{for(var i=[],n=0;n<e.length;n+=t){i.push(e.slice(n,n+t))}return i})(r,n);let w=0;for(const u of v){const i=u.map((async i=>{const n=t.includeBleed?i.bleed:0,o=i.computedWidth+2*n+2*c,r=i.computedHeight+2*n+2*c,l=d(o),p=d(r);let u=0,g=a;for(;u<10;){u+=1,2===u&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const n=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:i.id,pixelRatio:g}));if(n.length>20){return t.onProgress&&t.onProgress(++w/s.length*.9),{url:n,width:l,height:p,widthPx:o,heightPx:r}}g*=.8}}));(await Promise.all(i)).forEach((({url:e,width:t,height:i,widthPx:n,heightPx:a})=>{y.addPage([t,i],t>i?"landscape":"portrait");const s=y.getCurrentPageInfo();var r;switch(o){case"pt":r=1;break;case"mm":r=72/25.4;break;case"cm":r=72/2.54;break;case"in":r=72;break;case"px":r=.75;break;case"pc":case"em":r=12;break;case"ex":r=6;break;default:throw"Invalid unit: "+o}if(s.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*r,topRightY:i*r},s.pageContext.artBox={bottomLeftX:d(c+m)*r,bottomLeftY:d(c+m)*r,topRightX:d(n-c-m)*r,topRightY:d(a-c-m)*r},s.pageContext.bleedBox={bottomLeftX:d(c+m)*r,bottomLeftY:d(c+m)*r,topRightX:d(n-c-m)*r,topRightY:d(a-c-m)*r},p){y.setLineWidth(d(1));const e=p+d(m);y.line(e,0,e,p),y.line(0,e,p,e),y.line(t-e,0,t-e,p),y.line(t,e,t-p,e),y.line(0,i-e,p,i-e),y.line(e,i,e,i-p),y.line(t,i-e,t-p,i-e),y.line(t-e,i,t-e,i-p)}y.addImage(e,p,p,t-2*p,i-2*p,void 0,"FAST")}))}return y},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const i=t.pixelRatio||1,n=await(0,g.createGIF)({width:e.width*i,height:e.height*i}),o=1e3/(t.fps||10),a=e.duration/o;for(let s=0;s<a-1;s++){const t=s*o||1;e.setCurrentTime(t);let a=0,r="";for(const i of e.pages){if(a+=i.duration,i.set({_rendering:a>t}),a>t){r=i.id;break}}const l=await e._toCanvas({pixelRatio:i,pageId:r,_skipTimeout:!0});n.addFrame(l.getContext("2d"),{delay:o,copy:!0})}for(const s of e.pages){s.set({_rendering:!1})}return e.stop(),n.render(),new Promise((e=>{n.on("finished",(function(t){!function(e,t){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:i}=t,n=o(t,["fileName"]);const a=await e.toGIFDataURL(n);(0,p.downloadFile)(a,i||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const i=e.toJSON();return(0,P.jsonToHTML)({json:i,elementHook:t})},async saveAsHTML({fileName:t}={}){const i=await e.toHTML(),n="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(i)));(0,p.downloadFile)(n,t||"polotno.html")},async toSVG({elementHook:t,pageId:i}={elementHook:void 0,pageId:void 0}){var n;const o=e.toJSON();i=i||(null===(n=o.pages[0])||void 0===n?void 0:n.id);const a=o.pages.find((e=>e.id===i));return(0,x.jsonToSVG)({json:Object.assign(Object.assign({},o),{pages:a?[a]:[]}),elementHook:t})},async saveAsSVG({fileName:t,elementHook:i,pageId:n}={}){const o=await e.toSVG({elementHook:i,pageId:n}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(o)));(0,p.downloadFile)(a,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:i}=t,n=o(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},n))).save(i||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise((e=>setTimeout(e,50))),await(0,y.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,s.getSnapshot)(e.fonts),pages:(0,s.getSnapshot)(e.pages),audios:(0,s.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,i=!1){var n;const o=Object.assign({},t),a=o.schemaVersion||0;a<1&&f.flags.htmlRenderEnabled&&(0,_.forEveryChild)({children:o.pages},(e=>{if("text"===e.type){const t=16,i=e.letterSpacing*t;e.letterSpacing=i/e.fontSize}})),a<2&&(0,_.forEveryChild)({children:o.pages},(e=>{e.filters&&Object.keys(e.filters).forEach((t=>{if(["warm","cold","natural"].includes(t)){return}const i=e.filters[t];i&&"number"==typeof i.intensity&&(i.intensity=i.intensity/100)}))})),delete o.schemaVersion;const r=e.pages.indexOf(e.activePage);let l=null===(n=o.pages[r]||o.pages[0])||void 0===n?void 0:n.id;o._activePageId=l;const d=Object.assign({},(0,s.getSnapshot)(e));Object.assign(d,o),d.history=i?e.history.toJSON():{history:[],undoIdx:-1},(0,s.applySnapshot)(e,d)},clear({keepHistory:t=!1}={}){const i=e.pages.map((e=>e.id));e.deletePages(i),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,s.destroy)(e)))},addAudio(t){const i=O.Audio.create(Object.assign({id:(0,l.nanoid)(10)},t));e.audios.push(i)},removeAudio(t){const i=e.audios.find((e=>e.id===t));i&&e.audios.remove(i)},async loadFont(t){const i=e.fonts.find((e=>e.fontFamily===t))||h.globalFonts.find((e=>e.fontFamily===t));let n=[{fontStyle:"normal",fontWeight:"normal"}];return i?(i.styles&&(n=i.styles.map((e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"})))),h.injectCustomFont(i)):h.injectGoogleFont(t),Promise.all(n.map((e=>h.loadFont(t,e.fontStyle,e.fontWeight))))},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.default=k;
1
+ var e,t=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,o)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var o={};if(null!=n){for(var a=e(n),s=0;s<a.length;s++){"default"!==a[s]&&t(o,n,a[s])}}return i(o,n),o}),o=this&&this.__rest||function(e,t){var i={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}}return i},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Store=exports.Font=void 0,exports.createStore=S;const s=require("mobx-state-tree"),r=require("./history"),l=require("nanoid"),d=a(require("konva")),c=require("mobx"),p=require("../utils/download"),u=require("../utils/pdf"),g=require("../utils/gif-lib"),m=require("../utils/validate-key"),h=n(require("../utils/fonts")),f=require("../utils/flags"),y=require("../utils/loader"),b=require("../utils/unit"),v=require("../utils/deep-equal"),w=require("../utils/wait"),P=require("../utils/to-html"),x=require("../utils/to-svg"),E=require("./page-model"),_=require("./group-model"),O=require("./audio-model");function S({key:e,showCredit:t}={key:"",showCredit:!1}){return exports.Store.create({_forceShowCredit:t,_key:e})}(0,s.setLivelinessChecking)("ignore"),exports.Font=s.types.model("Font",{fontFamily:s.types.string,url:s.types.optional(s.types.string,""),styles:s.types.frozen()}).preProcessSnapshot((e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}))),exports.Store=s.types.model("Store",{role:"",pages:s.types.array(E.Page),fonts:s.types.array(exports.Font),audios:s.types.array(O.Audio),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:2,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:s.types.frozen(),selectedElementsIds:s.types.array(s.types.string),animatedElementsIds:s.types.array(s.types.string),history:s.types.optional(r.UndoManager,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views((e=>{const t=(0,c.computed)((()=>{const t={};return(0,_.forEveryChild)({children:e.pages},(e=>(t[e.id]=e,!1))),t}),{keepAlive:!0});return{get _idsMap(){return t.get()}}})).views((e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map((t=>{for(const i of e.pages){for(const e of i.children){if(e.id===t){return e}}}})).filter((e=>!!e))},get children(){return e.pages},get selectedShapes(){const t=[];return(0,_.forEveryChild)({children:e.selectedElements},(e=>{"group"!==e.type&&t.push(e)})),t},get activePage(){return e.pages.slice().find((t=>t.id===e._activePageId))||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach((e=>{t+=e.duration})),t},get _hasCroppedImages(){return e.find((e=>"image"===e.type&&e._cropModeEnabled))},find(t){let i;return(0,_.forEveryChild)({children:e.pages},(e=>{if(!i&&t(e)){return i=e,!0}})),i},getElementById:t=>e._idsMap[t]}))).actions((e=>{let t=0,i=null,n=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:o=[],startTime:a=0,currentTime:r=0,endTime:l=e.duration,repeat:d=!1}={}){r&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),a=r),e.animatedElementsIds=(0,s.cast)(o),e.currentTime=a,e.isPlaying=!0,t=Date.now(),i=l,n=d,requestAnimationFrame(e.seek)},checkActivePage(){let t=0;for(const i of e.pages){if(e.currentTime>=i.startTime&&e.currentTime<i.startTime+i.duration){e.selectPage(i.id);break}t+=i.duration}},seek(){if(!e.isPlaying){return}const o=Date.now(),a=o-t;t=o,e.currentTime+=a,e.checkActivePage();const s=i||e.duration;e.isPlaying&&e.currentTime<s?requestAnimationFrame(e.seek):e.isPlaying&&n?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,s.cast)([]),e.checkActivePage()}}})).actions((e=>({__(){e._validated||((0,m.validateKey)(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:i}){e.unit=t||e.unit,e.dpi=i||e.dpi},setRole(t){e.role=t},addPage(t){const i=E.Page.create(Object.assign({id:(0,l.nanoid)(10)},t));return e.pages.push(i),e._activePageId=i.id,i},selectPage(t){e._activePageId=t},selectElements(t){const i=t.map((t=>e.getElementById(t))).sort(((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t))).filter((e=>!!e)).map((e=>e.id));e.selectedElementsIds=(0,s.cast)(i)},toggleBleed(t){e.bleedVisible=null!=t?t:!e.bleedVisible},toggleRulers(t){e.rulesVisible=null!=t?t:!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,i,n){e.pages.forEach((e=>{e.setSize({width:t,height:i,useMagic:n,softChange:!0})})),e.width=t,e.height=i},setPageZIndex(t,i){const n=e.pages.find((e=>e.id===t));n&&((0,s.detach)(n),e.pages.remove(n),e.pages.splice(i,0,n))},deletePages(t){const i=e.pages.indexOf(e.activePage);t.forEach((t=>{const i=e.pages.find((e=>e.id===t));(0,s.destroy)(i)}));const n=Math.min(e.pages.length-1,i),o=e.pages[n];o&&(e._activePageId=o.id),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},groupElements(t,i={}){const n=t.map((t=>e.getElementById(t))),o=n[0].page;if(n.forEach((e=>{e&&(0,s.detach)(e)})),!n.length){return}const a=Object.assign({id:(0,l.nanoid)(10),children:n,type:"group"},i);return o.children.push(a),e.selectedElementsIds=(0,s.cast)([a.id]),o.children.find((e=>e.id===a.id))},ungroupElements(t){const i=t.map((t=>e.getElementById(t))),n=[];i.forEach((e=>{if(e&&"group"===e.type){const t=e.page,i=t.children.indexOf(e);e.children.forEach((e=>{n.push(e.id)})),e.children.forEach((e=>{(0,s.detach)(e),t.children.push(e)})),t.children.splice(i,1)}})),e.selectedElementsIds=(0,s.cast)(n)},deleteElements(t){const i=[];e.find((e=>(t.includes(e.id)&&i.push(e),!1))),i.forEach((e=>{(0,s.destroy)(e)})),e.selectedElementsIds=(0,s.cast)(e.selectedElementsIds.filter((t=>e.getElementById(t))))},on(t,i){if("change"===t){let t=e.toJSON();return(0,s.onSnapshot)(e,(n=>{const o=e.toJSON();!(0,v.deepEqual)(t,o)&&(t=o,i(o))}))}},async _toCanvas({pixelRatio:t,ignoreBackground:i,pageId:n,mimeType:o,includeBleed:a,_skipTimeout:s,quickMode:r=!1}={}){var l;const c=t||1;n=n||(null===(l=e.pages[0])||void 0===l?void 0:l.id);const p=e.pages.find((e=>e.id===n));if(!p){throw new Error(`No page for export with id ${n}`)}const u=e._elementsPixelRatio;c>e._elementsPixelRatio&&e.setElementsPixelRatio(c),r?null==p||p.set({_forceMount:!0}):null==p||p.set({_exporting:!0});const g=await(0,w.waitTillAvailable)((()=>d.default.stages.find((e=>e.getAttr("pageId")===n))));if(!g){throw null==p||p.set({_forceMount:!1,_exporting:!1}),e.setElementsPixelRatio(u),new Error(`Export is failed. Can not find stage for page ${n}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`)}await e.waitLoading({_skipTimeout:s});const m=g.findOne(".page-container");if(!m){throw e.setElementsPixelRatio(u),null==p||p.set({_forceMount:!1,_exporting:!1}),new Error("Export is failed. Canvas was unmounted.")}const h=g.position();g.position({x:0,y:0}),g.find("Transformer").forEach((e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)})),m.find(".page-background").forEach((e=>e.shadowEnabled(!1))),m.find(".page-background").forEach((e=>e.strokeEnabled(!1))),m.find(".highlighter").forEach((e=>e.visible(!1)));const f=m.findOne(".page-background-group"),y=f.clip();f.clip({x:null,y:null,width:null,height:null});const b=m.findOne(".elements-container"),v=b.clip();b.clip({x:null,y:null,width:null,height:null});const P=m.find((e=>e.getAttr("hideInExport")));P.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.hide()}));const x=m.find((e=>!e.visible()&&e.getAttr("editModeEnabled")));x.forEach((e=>{e.setAttr("oldVisible",e.visible()),e.show()})),i&&m.find(".page-background").forEach((e=>e.hide()));const E=a?p.bleed:0;let _=E;!e.bleedVisible&&a||(e.bleedVisible||a?e.bleedVisible&&a?_=0:e.bleedVisible&&!a&&(_=-p.bleed):_=0);const O=document.createElement("canvas");O.width=Math.round((p.computedWidth+2*E)*c),O.height=Math.round((p.computedHeight+2*E)*c);const S=O.getContext("2d");"image/jpeg"===o&&(S.fillStyle="white",S.fillRect(0,0,O.width,O.height));const k=m.scale();m.scale({x:1,y:1});const I=m.toCanvas({x:m.x()-_,y:m.y()-_,width:p.computedWidth+2*E,height:p.computedHeight+2*E,pixelRatio:c});return m.scale(k),S.drawImage(I,0,0,O.width,O.height),d.default.Util.releaseCanvas(I),i&&m.find(".page-background").forEach((e=>e.show())),P.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),x.forEach((e=>{e.visible(e.getAttr("oldVisible"))})),m.find(".page-background").forEach((e=>e.shadowEnabled(!0))),m.find(".page-background").forEach((e=>e.strokeEnabled(!0))),g.find("Transformer").forEach((e=>{e.visible(e.getAttr("oldVisible"))})),m.find(".highlighter").forEach((e=>e.visible(!0))),f.clip(y),b.clip(v),g.position(h),null==p||p.set({_exporting:!1,_forceMount:!1}),await new Promise((e=>setTimeout(e))),e.setElementsPixelRatio(u),O},async toDataURL(t={}){var{mimeType:i,quality:n}=t,a=o(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=s.toDataURL(i,n);return d.default.Util.releaseCanvas(s),r},async toBlob(t={}){var{mimeType:i,quality:n}=t,a=o(t,["mimeType","quality"]);const s=await e._toCanvas(Object.assign({mimeType:i},a)),r=await new Promise((e=>{s.toBlob(e,i,n)}));return d.default.Util.releaseCanvas(s),r},async saveAsImage(t={}){var{fileName:i}=t,n=o(t,["fileName"]);const a=n.mimeType||"image/png",s=a.split("/")[1];(0,p.downloadFile)(await e.toDataURL(n),i||"polotno."+s,a)},async _toPDF(t){const i=t.dpi||e.dpi,n=t.parallel||1,o=t.unit||("px"===e.unit?"mm":e.unit),a=t.pixelRatio||1,s=t.pageIds||e.pages.map((e=>e.id)),r=e.pages.filter((e=>s.includes(e.id))),l=await(0,u.getJsPDF)(),d=e=>(0,b.pxToUnit)({px:e,unit:o,dpi:i}),c=t.cropMarkSize||0,p=d(c),g=r[0]||{},m=t.includeBleed?g.bleed:0,h=d(g.computedWidth+2*m+2*p),f=d(g.computedHeight+2*m+2*p);var y=new l({unit:o,orientation:h>f?"landscape":"portrait",format:[h,f],compress:!0,putOnlyUsedFonts:!0});y.deletePage(1);const v=((e,t)=>{for(var i=[],n=0;n<e.length;n+=t){i.push(e.slice(n,n+t))}return i})(r,n);let w=0;for(const u of v){const i=u.map((async i=>{const n=t.includeBleed?i.bleed:0,o=i.computedWidth+2*n+2*c,r=i.computedHeight+2*n+2*c,l=d(o),p=d(r);let u=0,g=a;for(;u<10;){u+=1,2===u&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");const n=await e.toDataURL(Object.assign(Object.assign({},t),{pageId:i.id,pixelRatio:g}));if(n.length>20){return t.onProgress&&t.onProgress(++w/s.length*.9),{url:n,width:l,height:p,widthPx:o,heightPx:r}}g*=.8}}));(await Promise.all(i)).forEach((({url:e,width:t,height:i,widthPx:n,heightPx:a})=>{y.addPage([t,i],t>i?"landscape":"portrait");const s=y.getCurrentPageInfo();var r;switch(o){case"pt":r=1;break;case"mm":r=72/25.4;break;case"cm":r=72/2.54;break;case"in":r=72;break;case"px":r=.75;break;case"pc":case"em":r=12;break;case"ex":r=6;break;default:throw"Invalid unit: "+o}if(s.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*r,topRightY:i*r},s.pageContext.artBox={bottomLeftX:d(c+m)*r,bottomLeftY:d(c+m)*r,topRightX:d(n-c-m)*r,topRightY:d(a-c-m)*r},s.pageContext.bleedBox={bottomLeftX:d(c+m)*r,bottomLeftY:d(c+m)*r,topRightX:d(n-c-m)*r,topRightY:d(a-c-m)*r},p){y.setLineWidth(d(1));const e=p+d(m);y.line(e,0,e,p),y.line(0,e,p,e),y.line(t-e,0,t-e,p),y.line(t,e,t-p,e),y.line(0,i-e,p,i-e),y.line(e,i,e,i-p),y.line(t,i-e,t-p,i-e),y.line(t-e,i,t-e,i-p)}y.addImage(e,p,p,t-2*p,i-2*p,void 0,"FAST")}))}return y},toPDFDataURL:async t=>(await e._toPDF(Object.assign({mimeType:"image/jpeg"},t))).output("datauristring"),async toGIFDataURL(t={}){const i=t.pixelRatio||1,n=await(0,g.createGIF)({width:e.width*i,height:e.height*i}),o=1e3/(t.fps||10),a=e.duration/o;for(let s=0;s<a-1;s++){const t=s*o||1;e.setCurrentTime(t);let a=0,r="";for(const i of e.pages){if(a+=i.duration,i.set({_rendering:a>t}),a>t){r=i.id;break}}const l=await e._toCanvas({pixelRatio:i,pageId:r,_skipTimeout:!0});n.addFrame(l.getContext("2d"),{delay:o,copy:!0})}for(const s of e.pages){s.set({_rendering:!1})}return e.stop(),n.render(),new Promise((e=>{n.on("finished",(function(t){!function(e,t){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.readAsDataURL(e)}(t,e)}))}))},async saveAsGIF(t={}){var{fileName:i}=t,n=o(t,["fileName"]);const a=await e.toGIFDataURL(n);(0,p.downloadFile)(a,i||"polotno.gif")},async toHTML({elementHook:t}={elementHook:void 0}){const i=e.toJSON();return(0,P.jsonToHTML)({json:i,elementHook:t})},async saveAsHTML({fileName:t}={}){const i=await e.toHTML(),n="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(i)));(0,p.downloadFile)(n,t||"polotno.html")},async toSVG({elementHook:t,pageId:i}={elementHook:void 0,pageId:void 0}){var n;const o=e.toJSON();i=i||(null===(n=o.pages[0])||void 0===n?void 0:n.id);const a=o.pages.find((e=>e.id===i));return(0,x.jsonToSVG)({json:Object.assign(Object.assign({},o),{pages:a?[a]:[]}),elementHook:t})},async saveAsSVG({fileName:t,elementHook:i,pageId:n}={}){const o=await e.toSVG({elementHook:i,pageId:n}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(o)));(0,p.downloadFile)(a,t||"polotno.svg")},async saveAsPDF(t={}){var{fileName:i}=t,n=o(t,["fileName"]);(await e._toPDF(Object.assign({mimeType:"image/jpeg"},n))).save(i||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise((e=>setTimeout(e,50))),await(0,y.whenLoaded)()},toJSON:()=>({width:e.width,height:e.height,fonts:(0,s.getSnapshot)(e.fonts),pages:(0,s.getSnapshot)(e.pages),audios:(0,s.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,i=!1){var n;const o=JSON.parse(JSON.stringify(t)),a=o.schemaVersion||0;a<1&&f.flags.htmlRenderEnabled&&(0,_.forEveryChild)({children:o.pages},(e=>{if("text"===e.type){const t=16,i=e.letterSpacing*t;e.letterSpacing=i/e.fontSize}})),a<2&&(0,_.forEveryChild)({children:o.pages},(e=>{e.filters&&Object.keys(e.filters).forEach((t=>{if(["warm","cold","natural"].includes(t)){return}const i=e.filters[t];i&&"number"==typeof i.intensity&&(i.intensity=i.intensity/100)}))})),delete o.schemaVersion;const r=e.pages.indexOf(e.activePage);let l=null===(n=o.pages[r]||o.pages[0])||void 0===n?void 0:n.id;o._activePageId=l;const d=Object.assign({},(0,s.getSnapshot)(e));Object.assign(d,o),d.history=i?e.history.toJSON():{history:[],undoIdx:-1},(0,s.applySnapshot)(e,d)},clear({keepHistory:t=!1}={}){const i=e.pages.map((e=>e.id));e.deletePages(i),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter((e=>e.fontFamily===t)).forEach((e=>(0,s.destroy)(e)))},addAudio(t){const i=O.Audio.create(Object.assign({id:(0,l.nanoid)(10)},t));e.audios.push(i)},removeAudio(t){const i=e.audios.find((e=>e.id===t));i&&e.audios.remove(i)},async loadFont(t){const i=e.fonts.find((e=>e.fontFamily===t))||h.globalFonts.find((e=>e.fontFamily===t));let n=[{fontStyle:"normal",fontWeight:"normal"}];return i?(i.styles&&(n=i.styles.map((e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"})))),h.injectCustomFont(i)):h.injectGoogleFont(t),Promise.all(n.map((e=>h.loadFont(t,e.fontStyle,e.fontWeight))))},validate:e=>exports.Store.validate(e,[{path:"",type:exports.Store}]).map((e=>({path:"store"+e.context.map((e=>e.path)).join("."),message:e.message})))}))),exports.default=S;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno",
3
- "version": "2.23.13",
3
+ "version": "2.23.14",
4
4
  "description": "Design Editor Framework",
5
5
  "author": "Anton Lavrenov",
6
6
  "keywords": [
package/polotno.bundle.js CHANGED
@@ -240,7 +240,7 @@ https://polotno.com/docs/server-api`,lF={unsplashList:({query:e,page:t=1})=>`${l
240
240
  font-weight: ${l};
241
241
  src: url(${n});
242
242
  }`}));return s_("style",{},o.join("\n"))}catch(e){return console.error("Error embedding Google Font:",e),s_("defs",{},s_("style",{type:"text/css",innerHTML:`@import url('${t}');`.replace(/&/g,"&amp;")}))}}}))}async function sN({json:e,elementHook:t}){let n=await Promise.all(e.pages.map(n=>sT({page:n,store:e,elementHook:t}))),r=[];sC({children:e.pages},e=>{"text"===e.type&&-1===r.indexOf(e.fontFamily)&&r.push(e.fontFamily)});let i=await sj(r,e.fonts);return s_("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:`0 0 ${e.width} ${e.height}`,width:e.width,height:e.height},...i,...n)}let sR=(e,t)=>"object"==typeof t?`${e}="${Object.keys(t).map(e=>`${e}:${t[e]};`).join(" ")}"`:null==t||""===t?"":`${e}="${t}"`,sL=({dom:e,nestLevel:t=0})=>{if("string"==typeof e)return e;if(!e)return"";let{innerHTML:n,...r}=e.props,i=" ".repeat(t);return`${i}<${e.type} ${Object.keys(r).map(e=>sR(e,r[e])).join(" ")}>${n||"\n"+e.children.map(e=>sL({dom:e,nestLevel:t+1})).join("")}${i}</${e.type}>
243
- `};async function sM({json:e,elementHook:t}){return sL({dom:await sN({json:e,elementHook:t})})}var i$=b("58B0H");let sI=(0,i$.types).model("Page",{id:i$.types.identifier,children:(0,i$.types).array((0,i$.types).late(()=>s8)),width:(0,i$.types).optional((0,i$.types).union(i$.types.number,(0,i$.types).literal("auto")),"auto"),height:(0,i$.types).optional((0,i$.types).union(i$.types.number,(0,i$.types).literal("auto")),"auto"),background:"white",bleed:0,custom:(0,i$.types).frozen(),duration:5e3,_exporting:!1,_rendering:!1,_forceMount:!1}).postProcessSnapshot(e=>{let t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n}).views(e=>({get store(){return(0,i$.getParentOfType)(e,sF)}})).views(e=>({get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)break;t+=n.duration}return t},get _exportingOrRendering(){return e._exporting||e._rendering}})).views(e=>({get computedWidth(){if("auto"===e.width)return e.store.width;return e.width},get computedHeight(){if("auto"===e.height)return e.store.height;return e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify((0,i$.getSnapshot)(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>t.index-e.index),r)){if(-1==i)continue;let r=i<e.children.length-1&&e.children[i+1],o=t.indexOf(r?.id)>=0;i===e.children.length-1||o||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>e.index-t.index),r)){if(-1==i)continue;let r=i>0&&e.children[i-1],o=t.indexOf(r?.id)>=0;0===i||o||n(i)}return!1}})).actions(e=>({clone(t={}){let n=e.toJSON();n.children.forEach(e=>{e.id=lO(10),s3(e,e=>{e.id=lO(10)})});let r={...n,id:lO(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);return i.setZIndex(o+1),i.select(),i},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=s9[t.type];if(!r){console.error("Can not find model with type "+t.type);return}"children"in t&&Array.isArray(t.children)&&s3(t,e=>{e.id=e.id||lO(10)});let i=r.create({id:lO(10),...t});return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n=n||!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];(0,i$.detach)(n),e.children.splice(t+1,0,n)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n=n||!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];(0,i$.detach)(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&((0,i$.detach)(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=[],i=t=>"image"===t.type&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2;s3(e,e=>{"group"!==e.type&&(i(e)||r.push(e))});let o=r.length?aV(r):{x:0,y:0,width:e.computedWidth,height:e.computedHeight},a=1/4,l=Math.max(0,Math.max(0,Math.min(o.x,e.computedWidth-o.x-o.width))-e.computedWidth*a),s=Math.max(0,Math.max(0,Math.min(o.y,e.computedHeight-o.y-o.height))-e.computedHeight*a),u=e.computedWidth-2*l,c=e.computedHeight-2*s,d=t/u,h=n/c,f=Math.min(d,h),p=(t-u*f)/2-l*f,g=(n-c*f)/2-s*f;s3(e,e=>{"group"!==e.type&&(i(e)?e.set({x:e.x*f,y:e.y*f,width:e.width*d,height:e.height*h,cropX:0,cropY:0,cropWidth:1,cropHeight:1}):(e.set({x:p+e.x*f,y:g+e.y*f,width:e.width*f,height:e.height*f}),"text"===e.type?e.set({fontSize:e.fontSize*f}):"figure"===e.type&&e.set({strokeWidth:e.strokeWidth*f})))})}i||(e.width=t),i||(e.height=n)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}}));var i$=b("58B0H");let sD=(0,i$.types).model("Audio",{id:i$.types.identifier,src:"",duration:0,startTime:0,endTime:1,volume:1,delay:0}).actions(e=>({toJSON:()=>({...(0,i$.getSnapshot)(e)})})).actions(e=>({set(t){Object.assign(e,t)}}));(0,i$.setLivelinessChecking)("ignore");let sz=(0,i$.types).model("Font",{fontFamily:i$.types.string,url:(0,i$.types).optional(i$.types.string,""),styles:(0,i$.types).frozen()}).preProcessSnapshot(e=>({...e,fontFamily:e.fontFamily||e.name})),sF=(0,i$.types).model("Store",{role:"",pages:(0,i$.types).array(sI),fonts:(0,i$.types).array(sz),audios:(0,i$.types).array(sD),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:2,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:(0,i$.types).frozen(),selectedElementsIds:(0,i$.types).array(i$.types.string),animatedElementsIds:(0,i$.types).array(i$.types.string),history:(0,i$.types).optional(lT,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views(e=>{let t=(0,E.computed)(()=>{let t={};return s3({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let t=[];return s3({children:e.selectedElements},e=>{"group"!==e.type&&t.push(e)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return e.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let n;return s3({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e._idsMap[t]})).actions(e=>{let t=0,n=null,r=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:i=[],startTime:o=0,currentTime:a=0,endTime:l=e.duration,repeat:s=!1}={}){a&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),o=a),e.animatedElementsIds=(0,i$.cast)(i),e.currentTime=o,e.isPlaying=!0,t=Date.now(),n=l,r=s,requestAnimationFrame(e.seek)},checkActivePage(){for(let t of e.pages){if(e.currentTime>=t.startTime&&e.currentTime<t.startTime+t.duration){e.selectPage(t.id);break}t.duration}},seek(){if(!e.isPlaying)return;let i=Date.now(),o=i-t;t=i,e.currentTime+=o,e.checkActivePage();let a=n||e.duration;e.isPlaying&&e.currentTime<a?requestAnimationFrame(e.seek):e.isPlaying&&r?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,i$.cast)([]),e.checkActivePage()}}}).actions(e=>({__(){e._validated||(l6(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},addPage(t){let n=sI.create({id:lO(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){let n=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,i$.cast)(n)},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&((0,i$.detach)(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{let n=e.pages.find(e=>e.id===t);(0,i$.destroy)(n)});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,i$.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t,n={}){let r=t.map(t=>e.getElementById(t)),i=r[0].page;if(r.forEach(e=>{e&&(0,i$.detach)(e)}),!r.length)return;let o={id:lO(10),children:r,type:"group",...n};return i.children.push(o),e.selectedElementsIds=(0,i$.cast)([o.id]),i.children.find(e=>e.id===o.id)},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&"group"===e.type){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{(0,i$.detach)(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=(0,i$.cast)(r)},deleteElements(t){let n=[];e.find(e=>(t.includes(e.id)&&n.push(e),!1)),n.forEach(e=>{(0,i$.destroy)(e)}),e.selectedElementsIds=(0,i$.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if("change"===t){let t=e.toJSON();return(0,i$.onSnapshot)(e,r=>{let i=e.toJSON();lP(t,i)||(t=i,n(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,_skipTimeout:a,quickMode:l=!1}={}){let s=t||1;r=r||e.pages[0]?.id;let u=e.pages.find(e=>e.id===r);if(!u)throw Error(`No page for export with id ${r}`);let c=e._elementsPixelRatio;s>e._elementsPixelRatio&&e.setElementsPixelRatio(s),l?u?.set({_forceMount:!0}):u?.set({_exporting:!0});let d=await st(()=>p(D).stages.find(e=>e.getAttr("pageId")===r));if(!d)throw u?.set({_forceMount:!1,_exporting:!1}),e.setElementsPixelRatio(c),Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);await e.waitLoading({_skipTimeout:a});let h=d.findOne(".page-container");if(!h)throw e.setElementsPixelRatio(c),u?.set({_forceMount:!1,_exporting:!1}),Error("Export is failed. Canvas was unmounted.");let f=d.position();d.position({x:0,y:0}),d.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),h.find(".page-background").forEach(e=>e.shadowEnabled(!1)),h.find(".page-background").forEach(e=>e.strokeEnabled(!1)),h.find(".highlighter").forEach(e=>e.visible(!1));let g=h.findOne(".page-background-group"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});let v=h.findOne(".elements-container"),y=v.clip();v.clip({x:null,y:null,width:null,height:null});let b=h.find(e=>e.getAttr("hideInExport"));b.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});let x=h.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));x.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),n&&h.find(".page-background").forEach(e=>e.hide());let w=o?u.bleed:0,C=w;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?C=0:e.bleedVisible&&!o&&(C=-u.bleed):C=0);let _=document.createElement("canvas");_.width=Math.round((u.computedWidth+2*w)*s),_.height=Math.round((u.computedHeight+2*w)*s);let S=_.getContext("2d");"image/jpeg"===i&&(S.fillStyle="white",S.fillRect(0,0,_.width,_.height));let E=h.scale();h.scale({x:1,y:1});let k=h.toCanvas({x:h.x()-C,y:h.y()-C,width:u.computedWidth+2*w,height:u.computedHeight+2*w,pixelRatio:s});return h.scale(E),S.drawImage(k,0,0,_.width,_.height),p(D).Util.releaseCanvas(k),n&&h.find(".page-background").forEach(e=>e.show()),b.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),x.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),h.find(".page-background").forEach(e=>e.shadowEnabled(!0)),h.find(".page-background").forEach(e=>e.strokeEnabled(!0)),d.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),h.find(".highlighter").forEach(e=>e.visible(!0)),g.clip(m),v.clip(y),d.position(f),u?.set({_exporting:!1,_forceMount:!1}),await new Promise(e=>setTimeout(e)),e.setElementsPixelRatio(c),_},async toDataURL({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=i.toDataURL(t,n);return p(D).Util.releaseCanvas(i),o},async toBlob({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=await new Promise(e=>{i.toBlob(e,t,n)});return p(D).Util.releaseCanvas(i),o},async saveAsImage({fileName:t,...n}={}){let r=n.mimeType||"image/png",i=r.split("/")[1];lA(await e.toDataURL(n),t||"polotno."+i,r)},async _toPDF(t){let n=t.dpi||e.dpi,r=t.parallel||1,i=t.unit||("px"===e.unit?"mm":e.unit),o=t.pixelRatio||1,a=t.pageIds||e.pages.map(e=>e.id),l=e.pages.filter(e=>a.includes(e.id)),s=await (window.jspdf?.jsPDF?Promise.resolve(window.jspdf.jsPDF):lj||(lj=new Promise(e=>{var t=document.createElement("script");t.onload=function(){e(window.jspdf.jsPDF)},t.src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.1/jspdf.umd.min.js",document.head.appendChild(t)}))),u=e=>l5({px:e,unit:i,dpi:n}),c=t.cropMarkSize||0,d=u(c),h=l[0]||{},f=t.includeBleed?h.bleed:0,p=u(h.computedWidth+2*f+2*d),g=u(h.computedHeight+2*f+2*d);var m=new s({unit:i,orientation:p>g?"landscape":"portrait",format:[p,g],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);let v=((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(l,r),y=0;for(let n of v){let r=n.map(async n=>{let r=t.includeBleed?n.bleed:0,i=n.computedWidth+2*r+2*c,l=n.computedHeight+2*r+2*c,s=u(i),d=u(l),h=0,f=o;for(;h<10;){2===(h+=1)&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");let r=await e.toDataURL({...t,pageId:n.id,pixelRatio:f});if(r.length>20)return t.onProgress&&t.onProgress(++y/a.length*.9),{url:r,width:s,height:d,widthPx:i,heightPx:l};f*=.8}});(await Promise.all(r)).forEach(({url:e,width:t,height:n,widthPx:r,heightPx:o})=>{var a;m.addPage([t,n],t>n?"landscape":"portrait");let l=m.getCurrentPageInfo();switch(i){case"pt":a=1;break;case"mm":a=72/25.4;break;case"cm":a=72/2.54;break;case"in":a=72;break;case"px":a=.75;break;case"pc":case"em":a=12;break;case"ex":a=6;break;default:throw"Invalid unit: "+i}if(l.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*a,topRightY:n*a},l.pageContext.artBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},l.pageContext.bleedBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},d){m.setLineWidth(u(1));let e=d+u(f);m.line(e,0,e,d),m.line(0,e,d,e),m.line(t-e,0,t-e,d),m.line(t,e,t-d,e),m.line(0,n-e,d,n-e),m.line(e,n,e,n-d),m.line(t,n-e,t-d,n-e),m.line(t-e,n,t-e,n-d)}m.addImage(e,d,d,t-2*d,n-2*d,void 0,"FAST")})}return m},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await lN({width:e.width*n,height:e.height*n}),i=1e3/(t.fps||10),o=e.duration/i;for(let t=0;t<o-1;t++){let o=t*i||1;e.setCurrentTime(o);let a=0,l="";for(let t of e.pages)if(a+=t.duration,t.set({_rendering:a>o}),a>o){l=t.id;break}let s=await e._toCanvas({pixelRatio:n,pageId:l,_skipTimeout:!0});r.addFrame(s.getContext("2d"),{delay:i,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return e.stop(),r.render(),new Promise(e=>{r.on("finished",function(t){var n;(n=new FileReader).onload=function(t){e(t.target.result)},n.readAsDataURL(t)})})},async saveAsGIF({fileName:t,...n}={}){lA(await e.toGIFDataURL(n),t||"polotno.gif")},toHTML:async({elementHook:t}={elementHook:void 0})=>sw({json:e.toJSON(),elementHook:t}),async saveAsHTML({fileName:t}={}){let n=await e.toHTML();lA("data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.html")},async toSVG({elementHook:t,pageId:n}={elementHook:void 0,pageId:void 0}){let r=e.toJSON();n=n||r.pages[0]?.id;let i=r.pages.find(e=>e.id===n);return sM({json:{...r,pages:i?[i]:[]},elementHook:t})},async saveAsSVG({fileName:t,elementHook:n,pageId:r}={}){let i=await e.toSVG({elementHook:n,pageId:r});lA("data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(i))),t||"polotno.svg")},async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await new Promise(e=>{var t;return t=()=>{ig()?setTimeout(e,300):e(!0)},void(0===iv?t():iy.push(t))})},toJSON:()=>({width:e.width,height:e.height,fonts:(0,i$.getSnapshot)(e.fonts),pages:(0,i$.getSnapshot)(e.pages),audios:(0,i$.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,n=!1){let r={...t},i=r.schemaVersion||0;i<1&&iD.htmlRenderEnabled&&s3({children:r.pages},e=>{if("text"===e.type){let t=16*e.letterSpacing;e.letterSpacing=t/e.fontSize}}),i<2&&s3({children:r.pages},e=>{e.filters&&Object.keys(e.filters).forEach(t=>{if(["warm","cold","natural"].includes(t))return;let n=e.filters[t];n&&"number"==typeof n.intensity&&(n.intensity=n.intensity/100)})}),delete r.schemaVersion;let o=e.pages.indexOf(e.activePage),a=(r.pages[o]||r.pages[0])?.id;r._activePageId=a;let l={...(0,i$.getSnapshot)(e)};Object.assign(l,r),n?l.history=e.history.toJSON():l.history={history:[],undoIdx:-1},(0,i$.applySnapshot)(e,l)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);e.deletePages(n),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,i$.destroy)(e))},addAudio(t){let n=sD.create({id:lO(10),...t});e.audios.push(n)},removeAudio(t){let n=e.audios.find(e=>e.id===t);n&&e.audios.remove(n)},async loadFont(t){let n=e.fonts.find(e=>e.fontFamily===t)||iO.find(e=>e.fontFamily===t),i=[{fontStyle:"normal",fontWeight:"normal"}];return n?(n.styles&&(i=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),function(e){let t=e.fontFamily;if(iI[t]||!e.url&&!e.styles)return;let n=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),i="";n.forEach(e=>{i+=`
243
+ `};async function sM({json:e,elementHook:t}){return sL({dom:await sN({json:e,elementHook:t})})}var i$=b("58B0H");let sI=(0,i$.types).model("Page",{id:i$.types.identifier,children:(0,i$.types).array((0,i$.types).late(()=>s8)),width:(0,i$.types).optional((0,i$.types).union(i$.types.number,(0,i$.types).literal("auto")),"auto"),height:(0,i$.types).optional((0,i$.types).union(i$.types.number,(0,i$.types).literal("auto")),"auto"),background:"white",bleed:0,custom:(0,i$.types).frozen(),duration:5e3,_exporting:!1,_rendering:!1,_forceMount:!1}).postProcessSnapshot(e=>{let t={...e},n={};for(var r in t)"_"!==r[0]&&(n[r]=e[r]);return n}).views(e=>({get store(){return(0,i$.getParentOfType)(e,sF)}})).views(e=>({get startTime(){let t=0;for(let n of e.store.pages){if(n.id===e.id)break;t+=n.duration}return t},get _exportingOrRendering(){return e._exporting||e._rendering}})).views(e=>({get computedWidth(){if("auto"===e.width)return e.store.width;return e.width},get computedHeight(){if("auto"===e.height)return e.store.height;return e.height}})).actions(e=>({toJSON:()=>JSON.parse(JSON.stringify((0,i$.getSnapshot)(e))),_forEachElementUp(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>t.index-e.index),r)){if(-1==i)continue;let r=i<e.children.length-1&&e.children[i+1],o=t.indexOf(r?.id)>=0;i===e.children.length-1||o||n(i)}},_forEachElementDown(t,n){let r=t.map(t=>({id:t,index:e.children.findIndex(e=>e.id===t)}));for(let{index:i}of(r.sort((e,t)=>e.index-t.index),r)){if(-1==i)continue;let r=i>0&&e.children[i-1],o=t.indexOf(r?.id)>=0;0===i||o||n(i)}return!1}})).actions(e=>({clone(t={}){let n=e.toJSON();n.children.forEach(e=>{e.id=lO(10),s3(e,e=>{e.id=lO(10)})});let r={...n,id:lO(10),...t},i=e.store.addPage(r),o=e.store.pages.indexOf(e);return i.setZIndex(o+1),i.select(),i},setZIndex(t){e.store.setPageZIndex(e.id,t)},set(t){Object.assign(e,t)},select(){e.store.selectPage(e.id)},addElement(t,{skipSelect:n=!1}={}){let r=s9[t.type];if(!r){console.error("Can not find model with type "+t.type);return}"children"in t&&Array.isArray(t.children)&&s3(t,e=>{e.id=e.id||lO(10)});let i=r.create({id:lO(10),...t});return e.children.push(i),i.selectable&&!n&&e.store.selectElements([i.id]),i},canMoveElementsUp(t){let n=!1;return e._forEachElementUp(t,()=>{n=n||!0}),n},moveElementsUp(t){e._forEachElementUp(t,t=>{let n=e.children[t];(0,i$.detach)(n),e.children.splice(t+1,0,n)})},canMoveElementsTop(e){return this.canMoveElementsUp(e)},moveElementsTop(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(r.concat(n))},canMoveElementsDown(t){let n=!1;return e._forEachElementDown(t,()=>{n=n||!0}),n},moveElementsDown(t){e._forEachElementDown(t,t=>{let n=e.children[t];(0,i$.detach)(n),e.children.splice(t-1,0,n)})},canMoveElementsBottom(e){return this.canMoveElementsDown(e)},moveElementsBottom(t){let n=[],r=[];e.children.forEach(e=>{t.indexOf(e.id)>=0?n.push(e):r.push(e)}),e.children.replace(n.concat(r))},setElementZIndex(t,n){let r=e.children.find(e=>e.id===t);r&&((0,i$.detach)(r),e.children.remove(r),e.children.splice(n,0,r))},setSize({width:t,height:n,useMagic:r,softChange:i}){if(r){let r=[],i=t=>"image"===t.type&&t.x<1&&t.y<1&&t.width>=e.computedWidth-2&&t.height>=e.computedHeight-2;s3(e,e=>{"group"!==e.type&&(i(e)||r.push(e))});let o=r.length?aV(r):{x:0,y:0,width:e.computedWidth,height:e.computedHeight},a=1/4,l=Math.max(0,Math.max(0,Math.min(o.x,e.computedWidth-o.x-o.width))-e.computedWidth*a),s=Math.max(0,Math.max(0,Math.min(o.y,e.computedHeight-o.y-o.height))-e.computedHeight*a),u=e.computedWidth-2*l,c=e.computedHeight-2*s,d=t/u,h=n/c,f=Math.min(d,h),p=(t-u*f)/2-l*f,g=(n-c*f)/2-s*f;s3(e,e=>{"group"!==e.type&&(i(e)?e.set({x:e.x*f,y:e.y*f,width:e.width*d,height:e.height*h,cropX:0,cropY:0,cropWidth:1,cropHeight:1}):(e.set({x:p+e.x*f,y:g+e.y*f,width:e.width*f,height:e.height*f}),"text"===e.type?e.set({fontSize:e.fontSize*f}):"figure"===e.type&&e.set({strokeWidth:e.strokeWidth*f})))})}i||(e.width=t),i||(e.height=n)}})).actions(e=>({moveElementUp(t){console.warn("page.moveElementUp(id) is deprecated. Please use page.moveElementsUp([id1, id2]) instead."),e.moveElementsUp([t])},moveElementDown(t){console.warn("page.moveElementDown(id) is deprecated. Please use page.moveElementsDown([id1, id2]) instead."),e.moveElementsDown([t])},moveElementTop(t){console.warn("page.moveElementTop(id) is deprecated. Please use page.moveElementsTop([id1, id2]) instead."),e.moveElementsTop([t])},moveElementBottom(t){console.warn("page.moveElementBottom(id) is deprecated. Please use page.moveElementsBottom([id1, id2]) instead."),e.moveElementsBottom([t])},play(){e.store.play({startTime:e.startTime,endTime:e.startTime+e.duration})}}));var i$=b("58B0H");let sD=(0,i$.types).model("Audio",{id:i$.types.identifier,src:"",duration:0,startTime:0,endTime:1,volume:1,delay:0}).actions(e=>({toJSON:()=>({...(0,i$.getSnapshot)(e)})})).actions(e=>({set(t){Object.assign(e,t)}}));(0,i$.setLivelinessChecking)("ignore");let sz=(0,i$.types).model("Font",{fontFamily:i$.types.string,url:(0,i$.types).optional(i$.types.string,""),styles:(0,i$.types).frozen()}).preProcessSnapshot(e=>({...e,fontFamily:e.fontFamily||e.name})),sF=(0,i$.types).model("Store",{role:"",pages:(0,i$.types).array(sI),fonts:(0,i$.types).array(sz),audios:(0,i$.types).array(sD),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:"px",dpi:72,schemaVersion:2,bleedVisible:!1,rulesVisible:!1,openedSidePanel:"",previousOpenedSidePanel:"",custom:(0,i$.types).frozen(),selectedElementsIds:(0,i$.types).array(i$.types.string),animatedElementsIds:(0,i$.types).array(i$.types.string),history:(0,i$.types).optional(lT,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,window.devicePixelRatio||1),_activePageId:"",_forceShowCredit:!1,_key:"",_validated:!1}).views(e=>{let t=(0,E.computed)(()=>{let t={};return s3({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>{for(let n of e.pages)for(let e of n.children)if(e.id===t)return e}).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){let t=[];return s3({children:e.selectedElements},e=>{"group"!==e.type&&t.push(e)}),t},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},get _hasCroppedImages(){return e.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let n;return s3({children:e.pages},e=>{if(!n&&t(e))return n=e,!0}),n},getElementById:t=>e._idsMap[t]})).actions(e=>{let t=0,n=null,r=!1;return{afterCreate(){e.history.canUndo},setCurrentTime(t){e.currentTime=t},_togglePlaying(t=!e.isPlaying){e.isPlaying=t},play({animatedElementsIds:i=[],startTime:o=0,currentTime:a=0,endTime:l=e.duration,repeat:s=!1}={}){a&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),o=a),e.animatedElementsIds=(0,i$.cast)(i),e.currentTime=o,e.isPlaying=!0,t=Date.now(),n=l,r=s,requestAnimationFrame(e.seek)},checkActivePage(){for(let t of e.pages){if(e.currentTime>=t.startTime&&e.currentTime<t.startTime+t.duration){e.selectPage(t.id);break}t.duration}},seek(){if(!e.isPlaying)return;let i=Date.now(),o=i-t;t=i,e.currentTime+=o,e.checkActivePage();let a=n||e.duration;e.isPlaying&&e.currentTime<a?requestAnimationFrame(e.seek):e.isPlaying&&r?(e.currentTime=0,requestAnimationFrame(e.seek)):e.stop()},stop(){e.isPlaying=!1,e.currentTime=0,e.animatedElementsIds=(0,i$.cast)([]),e.checkActivePage()}}}).actions(e=>({__(){e._validated||(l6(e._key,e._forceShowCredit),e._validated=!0)},set(t){Object.assign(e,t)},setUnit({unit:t,dpi:n}){e.unit=t||e.unit,e.dpi=n||e.dpi},setRole(t){e.role=t},addPage(t){let n=sI.create({id:lO(10),...t});return e.pages.push(n),e._activePageId=n.id,n},selectPage(t){e._activePageId=t},selectElements(t){let n=t.map(t=>e.getElementById(t)).sort((e,t)=>e.page.children.indexOf(e)-e.page.children.indexOf(t)).filter(e=>!!e).map(e=>e.id);e.selectedElementsIds=(0,i$.cast)(n)},toggleBleed(t){e.bleedVisible=t??!e.bleedVisible},toggleRulers(t){e.rulesVisible=t??!e.rulesVisible},openSidePanel(t){e.openedSidePanel!==t&&(e.previousOpenedSidePanel=e.openedSidePanel,e.openedSidePanel=t)},setScale(t){e.scale=t},_setScaleToFit(t){e.scaleToFit=t},setElementsPixelRatio(t){e._elementsPixelRatio=t},setSize(t,n,r){e.pages.forEach(e=>{e.setSize({width:t,height:n,useMagic:r,softChange:!0})}),e.width=t,e.height=n},setPageZIndex(t,n){let r=e.pages.find(e=>e.id===t);r&&((0,i$.detach)(r),e.pages.remove(r),e.pages.splice(n,0,r))},deletePages(t){let n=e.pages.indexOf(e.activePage);t.forEach(t=>{let n=e.pages.find(e=>e.id===t);(0,i$.destroy)(n)});let r=Math.min(e.pages.length-1,n),i=e.pages[r];i&&(e._activePageId=i.id),e.selectedElementsIds=(0,i$.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},groupElements(t,n={}){let r=t.map(t=>e.getElementById(t)),i=r[0].page;if(r.forEach(e=>{e&&(0,i$.detach)(e)}),!r.length)return;let o={id:lO(10),children:r,type:"group",...n};return i.children.push(o),e.selectedElementsIds=(0,i$.cast)([o.id]),i.children.find(e=>e.id===o.id)},ungroupElements(t){let n=t.map(t=>e.getElementById(t)),r=[];n.forEach(e=>{if(e&&"group"===e.type){let t=e.page,n=t.children.indexOf(e);e.children.forEach(e=>{r.push(e.id)}),e.children.forEach(e=>{(0,i$.detach)(e),t.children.push(e)}),t.children.splice(n,1)}}),e.selectedElementsIds=(0,i$.cast)(r)},deleteElements(t){let n=[];e.find(e=>(t.includes(e.id)&&n.push(e),!1)),n.forEach(e=>{(0,i$.destroy)(e)}),e.selectedElementsIds=(0,i$.cast)(e.selectedElementsIds.filter(t=>e.getElementById(t)))},on(t,n){if("change"===t){let t=e.toJSON();return(0,i$.onSnapshot)(e,r=>{let i=e.toJSON();lP(t,i)||(t=i,n(i))})}},async _toCanvas({pixelRatio:t,ignoreBackground:n,pageId:r,mimeType:i,includeBleed:o,_skipTimeout:a,quickMode:l=!1}={}){let s=t||1;r=r||e.pages[0]?.id;let u=e.pages.find(e=>e.id===r);if(!u)throw Error(`No page for export with id ${r}`);let c=e._elementsPixelRatio;s>e._elementsPixelRatio&&e.setElementsPixelRatio(s),l?u?.set({_forceMount:!0}):u?.set({_exporting:!0});let d=await st(()=>p(D).stages.find(e=>e.getAttr("pageId")===r));if(!d)throw u?.set({_forceMount:!1,_exporting:!1}),e.setElementsPixelRatio(c),Error(`Export is failed. Can not find stage for page ${r}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`);await e.waitLoading({_skipTimeout:a});let h=d.findOne(".page-container");if(!h)throw e.setElementsPixelRatio(c),u?.set({_forceMount:!1,_exporting:!1}),Error("Export is failed. Canvas was unmounted.");let f=d.position();d.position({x:0,y:0}),d.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),h.find(".page-background").forEach(e=>e.shadowEnabled(!1)),h.find(".page-background").forEach(e=>e.strokeEnabled(!1)),h.find(".highlighter").forEach(e=>e.visible(!1));let g=h.findOne(".page-background-group"),m=g.clip();g.clip({x:null,y:null,width:null,height:null});let v=h.findOne(".elements-container"),y=v.clip();v.clip({x:null,y:null,width:null,height:null});let b=h.find(e=>e.getAttr("hideInExport"));b.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()});let x=h.find(e=>!e.visible()&&e.getAttr("editModeEnabled"));x.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()}),n&&h.find(".page-background").forEach(e=>e.hide());let w=o?u.bleed:0,C=w;!e.bleedVisible&&o||(e.bleedVisible||o?e.bleedVisible&&o?C=0:e.bleedVisible&&!o&&(C=-u.bleed):C=0);let _=document.createElement("canvas");_.width=Math.round((u.computedWidth+2*w)*s),_.height=Math.round((u.computedHeight+2*w)*s);let S=_.getContext("2d");"image/jpeg"===i&&(S.fillStyle="white",S.fillRect(0,0,_.width,_.height));let E=h.scale();h.scale({x:1,y:1});let k=h.toCanvas({x:h.x()-C,y:h.y()-C,width:u.computedWidth+2*w,height:u.computedHeight+2*w,pixelRatio:s});return h.scale(E),S.drawImage(k,0,0,_.width,_.height),p(D).Util.releaseCanvas(k),n&&h.find(".page-background").forEach(e=>e.show()),b.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),x.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),h.find(".page-background").forEach(e=>e.shadowEnabled(!0)),h.find(".page-background").forEach(e=>e.strokeEnabled(!0)),d.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),h.find(".highlighter").forEach(e=>e.visible(!0)),g.clip(m),v.clip(y),d.position(f),u?.set({_exporting:!1,_forceMount:!1}),await new Promise(e=>setTimeout(e)),e.setElementsPixelRatio(c),_},async toDataURL({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=i.toDataURL(t,n);return p(D).Util.releaseCanvas(i),o},async toBlob({mimeType:t,quality:n,...r}={}){let i=await e._toCanvas({mimeType:t,...r}),o=await new Promise(e=>{i.toBlob(e,t,n)});return p(D).Util.releaseCanvas(i),o},async saveAsImage({fileName:t,...n}={}){let r=n.mimeType||"image/png",i=r.split("/")[1];lA(await e.toDataURL(n),t||"polotno."+i,r)},async _toPDF(t){let n=t.dpi||e.dpi,r=t.parallel||1,i=t.unit||("px"===e.unit?"mm":e.unit),o=t.pixelRatio||1,a=t.pageIds||e.pages.map(e=>e.id),l=e.pages.filter(e=>a.includes(e.id)),s=await (window.jspdf?.jsPDF?Promise.resolve(window.jspdf.jsPDF):lj||(lj=new Promise(e=>{var t=document.createElement("script");t.onload=function(){e(window.jspdf.jsPDF)},t.src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.1/jspdf.umd.min.js",document.head.appendChild(t)}))),u=e=>l5({px:e,unit:i,dpi:n}),c=t.cropMarkSize||0,d=u(c),h=l[0]||{},f=t.includeBleed?h.bleed:0,p=u(h.computedWidth+2*f+2*d),g=u(h.computedHeight+2*f+2*d);var m=new s({unit:i,orientation:p>g?"landscape":"portrait",format:[p,g],compress:!0,putOnlyUsedFonts:!0});m.deletePage(1);let v=((e,t)=>{for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n})(l,r),y=0;for(let n of v){let r=n.map(async n=>{let r=t.includeBleed?n.bleed:0,i=n.computedWidth+2*r+2*c,l=n.computedHeight+2*r+2*c,s=u(i),d=u(l),h=0,f=o;for(;h<10;){2===(h+=1)&&console.error("Polotno can not export PDF with current settings. Quality is automatically reduced.");let r=await e.toDataURL({...t,pageId:n.id,pixelRatio:f});if(r.length>20)return t.onProgress&&t.onProgress(++y/a.length*.9),{url:r,width:s,height:d,widthPx:i,heightPx:l};f*=.8}});(await Promise.all(r)).forEach(({url:e,width:t,height:n,widthPx:r,heightPx:o})=>{var a;m.addPage([t,n],t>n?"landscape":"portrait");let l=m.getCurrentPageInfo();switch(i){case"pt":a=1;break;case"mm":a=72/25.4;break;case"cm":a=72/2.54;break;case"in":a=72;break;case"px":a=.75;break;case"pc":case"em":a=12;break;case"ex":a=6;break;default:throw"Invalid unit: "+i}if(l.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*a,topRightY:n*a},l.pageContext.artBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},l.pageContext.bleedBox={bottomLeftX:u(c+f)*a,bottomLeftY:u(c+f)*a,topRightX:u(r-c-f)*a,topRightY:u(o-c-f)*a},d){m.setLineWidth(u(1));let e=d+u(f);m.line(e,0,e,d),m.line(0,e,d,e),m.line(t-e,0,t-e,d),m.line(t,e,t-d,e),m.line(0,n-e,d,n-e),m.line(e,n,e,n-d),m.line(t,n-e,t-d,n-e),m.line(t-e,n,t-e,n-d)}m.addImage(e,d,d,t-2*d,n-2*d,void 0,"FAST")})}return m},toPDFDataURL:async t=>(await e._toPDF({mimeType:"image/jpeg",...t})).output("datauristring"),async toGIFDataURL(t={}){let n=t.pixelRatio||1,r=await lN({width:e.width*n,height:e.height*n}),i=1e3/(t.fps||10),o=e.duration/i;for(let t=0;t<o-1;t++){let o=t*i||1;e.setCurrentTime(o);let a=0,l="";for(let t of e.pages)if(a+=t.duration,t.set({_rendering:a>o}),a>o){l=t.id;break}let s=await e._toCanvas({pixelRatio:n,pageId:l,_skipTimeout:!0});r.addFrame(s.getContext("2d"),{delay:i,copy:!0})}for(let t of e.pages)t.set({_rendering:!1});return e.stop(),r.render(),new Promise(e=>{r.on("finished",function(t){var n;(n=new FileReader).onload=function(t){e(t.target.result)},n.readAsDataURL(t)})})},async saveAsGIF({fileName:t,...n}={}){lA(await e.toGIFDataURL(n),t||"polotno.gif")},toHTML:async({elementHook:t}={elementHook:void 0})=>sw({json:e.toJSON(),elementHook:t}),async saveAsHTML({fileName:t}={}){let n=await e.toHTML();lA("data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(n))),t||"polotno.html")},async toSVG({elementHook:t,pageId:n}={elementHook:void 0,pageId:void 0}){let r=e.toJSON();n=n||r.pages[0]?.id;let i=r.pages.find(e=>e.id===n);return sM({json:{...r,pages:i?[i]:[]},elementHook:t})},async saveAsSVG({fileName:t,elementHook:n,pageId:r}={}){let i=await e.toSVG({elementHook:n,pageId:r});lA("data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(i))),t||"polotno.svg")},async saveAsPDF({fileName:t,...n}={}){(await e._toPDF({mimeType:"image/jpeg",...n})).save(t||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await new Promise(e=>{var t;return t=()=>{ig()?setTimeout(e,300):e(!0)},void(0===iv?t():iy.push(t))})},toJSON:()=>({width:e.width,height:e.height,fonts:(0,i$.getSnapshot)(e.fonts),pages:(0,i$.getSnapshot)(e.pages),audios:(0,i$.getSnapshot)(e.audios),unit:e.unit,dpi:e.dpi,custom:e.custom,schemaVersion:e.schemaVersion}),loadJSON(t,n=!1){let r=JSON.parse(JSON.stringify(t)),i=r.schemaVersion||0;i<1&&iD.htmlRenderEnabled&&s3({children:r.pages},e=>{if("text"===e.type){let t=16*e.letterSpacing;e.letterSpacing=t/e.fontSize}}),i<2&&s3({children:r.pages},e=>{e.filters&&Object.keys(e.filters).forEach(t=>{if(["warm","cold","natural"].includes(t))return;let n=e.filters[t];n&&"number"==typeof n.intensity&&(n.intensity=n.intensity/100)})}),delete r.schemaVersion;let o=e.pages.indexOf(e.activePage),a=(r.pages[o]||r.pages[0])?.id;r._activePageId=a;let l={...(0,i$.getSnapshot)(e)};Object.assign(l,r),n?l.history=e.history.toJSON():l.history={history:[],undoIdx:-1},(0,i$.applySnapshot)(e,l)},clear({keepHistory:t=!1}={}){let n=e.pages.map(e=>e.id);e.deletePages(n),e.custom=null,t||e.history.clear()},addFont(t){e.removeFont(t.fontFamily),e.fonts.push(t),e.loadFont(t.fontFamily)},removeFont(t){e.fonts.filter(e=>e.fontFamily===t).forEach(e=>(0,i$.destroy)(e))},addAudio(t){let n=sD.create({id:lO(10),...t});e.audios.push(n)},removeAudio(t){let n=e.audios.find(e=>e.id===t);n&&e.audios.remove(n)},async loadFont(t){let n=e.fonts.find(e=>e.fontFamily===t)||iO.find(e=>e.fontFamily===t),i=[{fontStyle:"normal",fontWeight:"normal"}];return n?(n.styles&&(i=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),function(e){let t=e.fontFamily;if(iI[t]||!e.url&&!e.styles)return;let n=e.styles||(e.url?[{src:`url("${e.url}")`}]:[]),i="";n.forEach(e=>{i+=`
244
244
  @font-face {
245
245
  font-family: '${t}';
246
246
  src: ${e.src};
@@ -1 +1 @@
1
- var e,t=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var r={};if(null!=n){for(var i=e(n),a=0;a<i.length;a++){"default"!==i[a]&&t(r,n,i[a])}}return o(r,n),r});Object.defineProperty(exports,"__esModule",{value:!0}),exports.__=exports.getKey=exports.isCreditVisible=exports.___=void 0,exports.isKeyPaid=w,exports.validateKey=async function(e,t){u=e,await w(e)&&!t||c()};const r=n(require("mobx")),i=require("./api"),a=require("./flags"),s=r.observable({value:!1}),l=r.observable({value:"v1"});exports.___=()=>l.value,exports.isCreditVisible=()=>s.value;const c=r.action((()=>{s.value=!0}));let u="";exports.getKey=()=>u||"";const d=5,p=3e3,g="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",v="Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet",f="Can not validate Polotno API key. Please report to anton@polotno.com immediately.",b="%cPolotno Free Version. Development or non-commercial usage only. https://polotno.com/";let _=window.location.origin;const m=navigator.userAgent.indexOf("Headless")>-1,h=navigator.userAgent.indexOf("Electron")>-1;"file://"===_&&m&&(_="headless"),"file://"===_&&h&&(_="electron");const y=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${_}" here: https://polotno.com/cabinet`;let P=fetch;async function w(e){for(let o=0;o<d;o++){try{const t=await P((0,i.getAPI)()+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host,skdVersion:"2.23.13"})});if(r.runInAction((()=>{l.value=t.headers.get("x-api-version")})),!e){return console.warn(g),!1}if(200!==t.status){await new Promise((e=>setTimeout(e,p)));continue}const o=await t.json();return o.is_valid||console.warn(v),o.is_paid||console.log(b,"background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),o.is_domain_valid||console.log(y,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),(0,a.useRemoveBackground)(o.remove_background_enabled),o.is_paid||!1}catch(t){await new Promise((e=>setTimeout(e,p)))}}return console.error(f),!0}exports.__=e=>{P=e};
1
+ var e,t=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&(t[t.length]=o)}return t},e(t)},function(n){if(n&&n.__esModule){return n}var r={};if(null!=n){for(var i=e(n),a=0;a<i.length;a++){"default"!==i[a]&&t(r,n,i[a])}}return o(r,n),r});Object.defineProperty(exports,"__esModule",{value:!0}),exports.__=exports.getKey=exports.isCreditVisible=exports.___=void 0,exports.isKeyPaid=w,exports.validateKey=async function(e,t){u=e,await w(e)&&!t||c()};const r=n(require("mobx")),i=require("./api"),a=require("./flags"),s=r.observable({value:!1}),l=r.observable({value:"v1"});exports.___=()=>l.value,exports.isCreditVisible=()=>s.value;const c=r.action((()=>{s.value=!0}));let u="";exports.getKey=()=>u||"";const d=5,p=3e3,g="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",v="Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet",f="Can not validate Polotno API key. Please report to anton@polotno.com immediately.",b="%cPolotno Free Version. Development or non-commercial usage only. https://polotno.com/";let _=window.location.origin;const m=navigator.userAgent.indexOf("Headless")>-1,h=navigator.userAgent.indexOf("Electron")>-1;"file://"===_&&m&&(_="headless"),"file://"===_&&h&&(_="electron");const y=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${_}" here: https://polotno.com/cabinet`;let P=fetch;async function w(e){for(let o=0;o<d;o++){try{const t=await P((0,i.getAPI)()+"/validate-key",{method:"POST",body:JSON.stringify({key:e,site:location.host,skdVersion:"2.23.14"})});if(r.runInAction((()=>{l.value=t.headers.get("x-api-version")})),!e){return console.warn(g),!1}if(200!==t.status){await new Promise((e=>setTimeout(e,p)));continue}const o=await t.json();return o.is_valid||console.warn(v),o.is_paid||console.log(b,"background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),o.is_domain_valid||console.log(y,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),(0,a.useRemoveBackground)(o.remove_background_enabled),o.is_paid||!1}catch(t){await new Promise((e=>setTimeout(e,p)))}}return console.error(f),!0}exports.__=e=>{P=e};